Date: Fri, 5 Sep 2025 18:42:22 GMT From: Warner Losh <imp@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 1167a7d065f8 - main - GEOM: add a new function g_new_geom Message-ID: <202509051842.585IgMGY096372@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=1167a7d065f8a6265cc8e28025944a2f848e3a7e commit 1167a7d065f8a6265cc8e28025944a2f848e3a7e Author: Wuyang Chung <wy-chung@outlook.com> AuthorDate: 2025-07-23 09:41:34 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2025-09-05 18:42:21 +0000 GEOM: add a new function g_new_geom This function is a variant of g_new_geomf. It accepts a regular string instead of a format string as its input parameter. It can save the time wasted on unnecessary format string processing. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1786 --- share/man/man9/g_geom.9 | 15 ++++++++++++++- sys/geom/geom.h | 5 +++-- sys/geom/geom_subr.c | 33 ++++++++++++++++++++++----------- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/share/man/man9/g_geom.9 b/share/man/man9/g_geom.9 index 74c6979fceda..c5b0c0aded2d 100644 --- a/share/man/man9/g_geom.9 +++ b/share/man/man9/g_geom.9 @@ -27,12 +27,15 @@ .Os .Sh NAME .Nm g_new_geomf , +.Nm g_new_geom , .Nm g_destroy_geom .Nd "geom management" .Sh SYNOPSIS .In geom/geom.h .Ft "struct g_geom *" .Fn g_new_geomf "struct g_class *mp" "const char *fmt" ... +.Ft "struct g_geom *" +.Fn g_new_geom "struct g_class *mp" "const char *name" .Ft void .Fn g_destroy_geom "struct g_geom *gp" .Sh DESCRIPTION @@ -58,6 +61,14 @@ The geom's name is created in a -like way from the rest of the arguments. .Pp The +.Fn g_new_geom +function is very similar to +.Fn g_new_geomf +except that it accepts a regular string instead of a +.Xr printf 3 Ns +-like format strng as the geom's name. +.Pp +The .Fn g_destroy_geom function destroys the given geom immediately and cancels all related pending events. @@ -94,7 +105,9 @@ and .Va access for it. .Pp -.Fn g_new_geomf : +.Fn g_new_geomf +and +.Fn g_new_geom : .Bl -item -offset indent .It Class diff --git a/sys/geom/geom.h b/sys/geom/geom.h index 908ce86f03a6..50e6627b0157 100644 --- a/sys/geom/geom.h +++ b/sys/geom/geom.h @@ -289,8 +289,9 @@ int g_handleattr_int(struct bio *bp, const char *attribute, int val); int g_handleattr_off_t(struct bio *bp, const char *attribute, off_t val); int g_handleattr_uint16_t(struct bio *bp, const char *attribute, uint16_t val); int g_handleattr_str(struct bio *bp, const char *attribute, const char *str); -struct g_consumer * g_new_consumer(struct g_geom *gp); -struct g_geom * g_new_geomf(struct g_class *mp, const char *fmt, ...) +struct g_consumer *g_new_consumer(struct g_geom *gp); +struct g_geom *g_new_geom(struct g_class *mp, const char *name); +struct g_geom *g_new_geomf(struct g_class *mp, const char *fmt, ...) __printflike(2, 3); struct g_provider * g_new_providerf(struct g_geom *gp, const char *fmt, ...) __printflike(2, 3); diff --git a/sys/geom/geom_subr.c b/sys/geom/geom_subr.c index 1429c84942ed..2a6ce1ab6486 100644 --- a/sys/geom/geom_subr.c +++ b/sys/geom/geom_subr.c @@ -368,20 +368,15 @@ g_retaste(struct g_class *mp) } struct g_geom * -g_new_geomf(struct g_class *mp, const char *fmt, ...) +g_new_geom(struct g_class *mp, const char *name) { + int len; struct g_geom *gp; - va_list ap; - struct sbuf *sb; g_topology_assert(); G_VALID_CLASS(mp); - sb = sbuf_new_auto(); - va_start(ap, fmt); - sbuf_vprintf(sb, fmt, ap); - va_end(ap); - sbuf_finish(sb); - gp = g_malloc(sizeof(*gp) + sbuf_len(sb) + 1, M_WAITOK | M_ZERO); + len = strlen(name); + gp = g_malloc(sizeof(*gp) + len + 1, M_WAITOK | M_ZERO); gp->name = (char *)(gp + 1); gp->class = mp; gp->rank = 1; @@ -389,8 +384,7 @@ g_new_geomf(struct g_class *mp, const char *fmt, ...) LIST_INIT(&gp->provider); LIST_INSERT_HEAD(&mp->geom, gp, geom); TAILQ_INSERT_HEAD(&geoms, gp, geoms); - strcpy(gp->name, sbuf_data(sb)); - sbuf_delete(sb); + memcpy(gp->name, name, len); /* Fill in defaults from class */ gp->start = mp->start; gp->spoiled = mp->spoiled; @@ -404,6 +398,23 @@ g_new_geomf(struct g_class *mp, const char *fmt, ...) return (gp); } +struct g_geom * +g_new_geomf(struct g_class *mp, const char *fmt, ...) +{ + struct g_geom *gp; + va_list ap; + struct sbuf *sb; + + sb = sbuf_new_auto(); + va_start(ap, fmt); + sbuf_vprintf(sb, fmt, ap); + va_end(ap); + sbuf_finish(sb); + gp = g_new_geom(mp, sbuf_data(sb)); + sbuf_delete(sb); + return (gp); +} + void g_destroy_geom(struct g_geom *gp) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202509051842.585IgMGY096372>