Skip to content

Commit 1dfc7fe

Browse files
committed
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.
1 parent bfa4759 commit 1dfc7fe

File tree

26 files changed

+63
-47
lines changed

26 files changed

+63
-47
lines changed

sys/contrib/openzfs/module/os/freebsd/zfs/vdev_geom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ vdev_geom_attach(struct g_provider *pp, vdev_t *vd, boolean_t sanity)
242242
break;
243243
}
244244
if (gp == NULL) {
245-
gp = g_new_geomf(&zfs_vdev_class, "zfs::vdev");
245+
gp = g_new_geom(&zfs_vdev_class, "zfs::vdev");
246246
gp->orphan = vdev_geom_orphan;
247247
gp->attrchanged = vdev_geom_attrchanged;
248248
gp->resize = vdev_geom_resize;

sys/geom/cache/g_cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ g_cache_create(struct g_class *mp, struct g_provider *pp,
504504
return (NULL);
505505
}
506506

507-
gp = g_new_geomf(mp, "%s", md->md_name);
507+
gp = g_new_geom(mp, md->md_name);
508508
sc = g_malloc(sizeof(*sc), M_WAITOK | M_ZERO);
509509
sc->sc_type = type;
510510
sc->sc_bshift = bshift;
@@ -665,7 +665,7 @@ g_cache_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
665665

666666
G_CACHE_DEBUG(3, "Tasting %s.", pp->name);
667667

668-
gp = g_new_geomf(mp, "cache:taste");
668+
gp = g_new_geom(mp, "cache:taste");
669669
gp->start = g_cache_start;
670670
gp->orphan = g_cache_orphan;
671671
gp->access = g_cache_access;

sys/geom/concat/g_concat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ g_concat_create(struct g_class *mp, const struct g_concat_metadata *md,
646646
return (NULL);
647647
}
648648
}
649-
gp = g_new_geomf(mp, "%s", md->md_name);
649+
gp = g_new_geom(mp, md->md_name);
650650
sc = malloc(sizeof(*sc), M_CONCAT, M_WAITOK | M_ZERO);
651651
gp->start = g_concat_start;
652652
gp->spoiled = g_concat_orphan;
@@ -753,7 +753,7 @@ g_concat_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
753753

754754
G_CONCAT_DEBUG(3, "Tasting %s.", pp->name);
755755

756-
gp = g_new_geomf(mp, "concat:taste");
756+
gp = g_new_geom(mp, "concat:taste");
757757
gp->start = g_concat_start;
758758
gp->access = g_concat_access;
759759
gp->orphan = g_concat_orphan;

sys/geom/eli/g_eli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ g_eli_read_metadata_offset(struct g_class *mp, struct g_provider *pp,
769769

770770
g_topology_assert();
771771

772-
gp = g_new_geomf(mp, "eli:taste");
772+
gp = g_new_geom(mp, "eli:taste");
773773
gp->start = g_eli_start;
774774
gp->access = g_std_access;
775775
/*

sys/geom/gate/g_gate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ g_gate_create(struct g_gate_ctl_create *ggio)
571571
}
572572
}
573573

574-
gp = g_new_geomf(&g_gate_class, "%s", name);
574+
gp = g_new_geom(&g_gate_class, name);
575575
gp->start = g_gate_start;
576576
gp->access = g_gate_access;
577577
gp->orphan = g_gate_orphan;

sys/geom/geom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ int g_handleattr_off_t(struct bio *bp, const char *attribute, off_t val);
290290
int g_handleattr_uint16_t(struct bio *bp, const char *attribute, uint16_t val);
291291
int g_handleattr_str(struct bio *bp, const char *attribute, const char *str);
292292
struct g_consumer * g_new_consumer(struct g_geom *gp);
293+
struct g_geom * g_new_geom(struct g_class *mp, const char *name);
293294
struct g_geom * g_new_geomf(struct g_class *mp, const char *fmt, ...)
294295
__printflike(2, 3);
295296
struct g_provider * g_new_providerf(struct g_geom *gp, const char *fmt, ...)

sys/geom/geom_dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused)
355355

356356
g_trace(G_T_TOPOLOGY, "dev_taste(%s,%s)", mp->name, pp->name);
357357
g_topology_assert();
358-
gp = g_new_geomf(mp, "%s", pp->name);
358+
gp = g_new_geom(mp, pp->name);
359359
sc = g_malloc(sizeof(*sc), M_WAITOK | M_ZERO);
360360
mtx_init(&sc->sc_mtx, "g_dev", NULL, MTX_DEF);
361361
cp = g_new_consumer(gp);

sys/geom/geom_slice.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ g_slice_new(struct g_class *mp, u_int slices, struct g_provider *pp, struct g_co
529529

530530
g_topology_assert();
531531
vp = (void **)extrap;
532-
gp = g_new_geomf(mp, "%s", pp->name);
532+
gp = g_new_geom(mp, pp->name);
533533
gsp = g_slice_alloc(slices, extra);
534534
gsp->start = start;
535535
gp->softc = gsp;

sys/geom/geom_subr.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -367,30 +367,22 @@ g_retaste(struct g_class *mp)
367367
return (error);
368368
}
369369

370-
struct g_geom *
371-
g_new_geomf(struct g_class *mp, const char *fmt, ...)
370+
static struct g_geom *
371+
_g_new_geom(struct g_class *mp, const char *name, int len)
372372
{
373373
struct g_geom *gp;
374-
va_list ap;
375-
struct sbuf *sb;
376374

377375
g_topology_assert();
378376
G_VALID_CLASS(mp);
379-
sb = sbuf_new_auto();
380-
va_start(ap, fmt);
381-
sbuf_vprintf(sb, fmt, ap);
382-
va_end(ap);
383-
sbuf_finish(sb);
384-
gp = g_malloc(sizeof *gp + sbuf_len(sb) + 1, M_WAITOK | M_ZERO);
377+
gp = g_malloc(sizeof *gp + len + 1, M_WAITOK | M_ZERO);
385378
gp->name = (char *)(gp + 1);
386379
gp->class = mp;
387380
gp->rank = 1;
388381
LIST_INIT(&gp->consumer);
389382
LIST_INIT(&gp->provider);
390383
LIST_INSERT_HEAD(&mp->geom, gp, geom);
391384
TAILQ_INSERT_HEAD(&geoms, gp, geoms);
392-
strcpy(gp->name, sbuf_data(sb));
393-
sbuf_delete(sb);
385+
memcpy(gp->name, name, len);
394386
/* Fill in defaults from class */
395387
gp->start = mp->start;
396388
gp->spoiled = mp->spoiled;
@@ -404,6 +396,29 @@ g_new_geomf(struct g_class *mp, const char *fmt, ...)
404396
return (gp);
405397
}
406398

399+
struct g_geom *
400+
g_new_geom(struct g_class *mp, const char *name)
401+
{
402+
return _g_new_geom(mp, name, strlen(name));
403+
}
404+
405+
struct g_geom *
406+
g_new_geomf(struct g_class *mp, const char *fmt, ...)
407+
{
408+
struct g_geom *gp;
409+
va_list ap;
410+
struct sbuf *sb;
411+
412+
sb = sbuf_new_auto();
413+
va_start(ap, fmt);
414+
sbuf_vprintf(sb, fmt, ap);
415+
va_end(ap);
416+
sbuf_finish(sb);
417+
gp = _g_new_geom(mp, sbuf_data(sb), sbuf_len(sb));
418+
sbuf_delete(sb);
419+
return (gp);
420+
}
421+
407422
void
408423
g_destroy_geom(struct g_geom *gp)
409424
{

sys/geom/journal/g_journal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,7 @@ g_journal_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
24772477
if (pp->geom->class == mp)
24782478
return (NULL);
24792479

2480-
gp = g_new_geomf(mp, "journal:taste");
2480+
gp = g_new_geom(mp, "journal:taste");
24812481
/* This orphan function should be never called. */
24822482
gp->orphan = g_journal_taste_orphan;
24832483
cp = g_new_consumer(gp);

0 commit comments

Comments
 (0)