Author: eugen
Date: Sat Oct 27 16:14:42 2018
New Revision: 339815
URL: https://svnweb.freebsd.org/changeset/base/339815

Log:
  Extend stripeoffset and stripesize of GEOMs from u_int to off_t
  
  GEOM's stripeoffset overflows at 4 gigabyte margin (2^32)
  because of its u_int type. This leads to incorrect data in the output
  generated by "sysctl kern.geom.confxml" command, "graid list" etc.
  when GEOM array has volumes larger than 4G, for example.
  
  This change does not affect ABI but changes KBI. No MFC planned.
  
  Differential Revision:        https://reviews.freebsd.org/D13426

Modified:
  head/sys/geom/geom.h
  head/sys/geom/geom_disk.h
  head/sys/geom/geom_dump.c
  head/sys/geom/geom_redboot.c
  head/sys/geom/geom_subr.c
  head/sys/geom/nop/g_nop.c
  head/sys/geom/part/g_part.c
  head/sys/geom/raid/g_raid.c
  head/sys/geom/stripe/g_stripe.c
  head/sys/geom/stripe/g_stripe.h
  head/sys/geom/uzip/g_uzip.c

Modified: head/sys/geom/geom.h
==============================================================================
--- head/sys/geom/geom.h        Sat Oct 27 15:09:35 2018        (r339814)
+++ head/sys/geom/geom.h        Sat Oct 27 16:14:42 2018        (r339815)
@@ -215,8 +215,8 @@ struct g_provider {
        TAILQ_ENTRY(g_provider) orphan;
        off_t                   mediasize;
        u_int                   sectorsize;
-       u_int                   stripesize;
-       u_int                   stripeoffset;
+       off_t                   stripesize;
+       off_t                   stripeoffset;
        struct devstat          *stat;
        u_int                   nstart, nend;
        u_int                   flags;

Modified: head/sys/geom/geom_disk.h
==============================================================================
--- head/sys/geom/geom_disk.h   Sat Oct 27 15:09:35 2018        (r339814)
+++ head/sys/geom/geom_disk.h   Sat Oct 27 16:14:42 2018        (r339815)
@@ -109,8 +109,8 @@ struct disk {
        u_int                   d_fwheads;
        u_int                   d_maxsize;
        off_t                   d_delmaxsize;
-       u_int                   d_stripeoffset;
-       u_int                   d_stripesize;
+       off_t                   d_stripeoffset;
+       off_t                   d_stripesize;
        char                    d_ident[DISK_IDENT_SIZE];
        char                    d_descr[DISK_IDENT_SIZE];
        uint16_t                d_hba_vendor;
@@ -151,7 +151,8 @@ void disk_add_alias(struct disk *disk, const char *);
 #define DISK_VERSION_03                0x5856105c
 #define DISK_VERSION_04                0x5856105d
 #define DISK_VERSION_05                0x5856105e
-#define DISK_VERSION           DISK_VERSION_05
+#define DISK_VERSION_06                0x5856105f
+#define DISK_VERSION           DISK_VERSION_06
 
 #endif /* _KERNEL */
 #endif /* _GEOM_GEOM_DISK_H_ */

Modified: head/sys/geom/geom_dump.c
==============================================================================
--- head/sys/geom/geom_dump.c   Sat Oct 27 15:09:35 2018        (r339814)
+++ head/sys/geom/geom_dump.c   Sat Oct 27 16:14:42 2018        (r339815)
@@ -64,8 +64,8 @@ g_confdot_provider(struct sbuf *sb, struct g_provider 
 {
 
        sbuf_printf(sb, "z%p [shape=hexagon,label=\"%s\\nr%dw%de%d\\nerr#%d\\n"
-           "sector=%u\\nstripe=%u\"];\n", pp, pp->name, pp->acr, pp->acw,
-           pp->ace, pp->error, pp->sectorsize, pp->stripesize);
+           "sector=%u\\nstripe=%ju\"];\n", pp, pp->name, pp->acr, pp->acw,
+           pp->ace, pp->error, pp->sectorsize, (uintmax_t)pp->stripesize);
 }
 
 static void
@@ -216,8 +216,8 @@ g_conf_provider(struct sbuf *sb, struct g_provider *pp
        sbuf_printf(sb, "\t  <mediasize>%jd</mediasize>\n",
            (intmax_t)pp->mediasize);
        sbuf_printf(sb, "\t  <sectorsize>%u</sectorsize>\n", pp->sectorsize);
-       sbuf_printf(sb, "\t  <stripesize>%u</stripesize>\n", pp->stripesize);
-       sbuf_printf(sb, "\t  <stripeoffset>%u</stripeoffset>\n", 
pp->stripeoffset);
+       sbuf_printf(sb, "\t  <stripesize>%ju</stripesize>\n", 
(uintmax_t)pp->stripesize);
+       sbuf_printf(sb, "\t  <stripeoffset>%ju</stripeoffset>\n", 
(uintmax_t)pp->stripeoffset);
        if (pp->flags & G_PF_WITHER)
                sbuf_printf(sb, "\t  <wither/>\n");
        else if (pp->geom->flags & G_GEOM_WITHER)

Modified: head/sys/geom/geom_redboot.c
==============================================================================
--- head/sys/geom/geom_redboot.c        Sat Oct 27 15:09:35 2018        
(r339814)
+++ head/sys/geom/geom_redboot.c        Sat Oct 27 16:14:42 2018        
(r339815)
@@ -246,7 +246,7 @@ g_redboot_taste(struct g_class *mp, struct g_provider 
        int error, sectorsize, i;
        struct fis_image_desc *fd, *head;
        uint32_t offmask;
-       u_int blksize;          /* NB: flash block size stored as stripesize */
+       off_t blksize;          /* NB: flash block size stored as stripesize */
        u_char *buf;
        off_t offset;
        const char *value;
@@ -283,9 +283,9 @@ g_redboot_taste(struct g_class *mp, struct g_provider 
        else
                offmask = 0xffffffff;           /* XXX */
        if (bootverbose)
-               printf("%s: mediasize %ld secsize %d blksize %d offmask 0x%x\n",
+               printf("%s: mediasize %ld secsize %d blksize %ju offmask 
0x%x\n",
                    __func__, (long) cp->provider->mediasize, sectorsize,
-                   blksize, offmask);
+                   (uintmax_t)blksize, offmask);
        if (sectorsize < sizeof(struct fis_image_desc) ||
            (sectorsize % sizeof(struct fis_image_desc)))
                return (NULL);

Modified: head/sys/geom/geom_subr.c
==============================================================================
--- head/sys/geom/geom_subr.c   Sat Oct 27 15:09:35 2018        (r339814)
+++ head/sys/geom/geom_subr.c   Sat Oct 27 16:14:42 2018        (r339815)
@@ -1409,8 +1409,8 @@ db_show_geom_provider(int indent, struct g_provider *p
                gprintln("  geom:         %s (%p)", pp->geom->name, pp->geom);
                gprintln("  mediasize:    %jd", (intmax_t)pp->mediasize);
                gprintln("  sectorsize:   %u", pp->sectorsize);
-               gprintln("  stripesize:   %u", pp->stripesize);
-               gprintln("  stripeoffset: %u", pp->stripeoffset);
+               gprintln("  stripesize:   %ju", (uintmax_t)pp->stripesize);
+               gprintln("  stripeoffset: %ju", (uintmax_t)pp->stripeoffset);
                gprintln("  access:       r%dw%de%d", pp->acr, pp->acw,
                    pp->ace);
                gprintln("  flags:        %s (0x%04x)",

Modified: head/sys/geom/nop/g_nop.c
==============================================================================
--- head/sys/geom/nop/g_nop.c   Sat Oct 27 15:09:35 2018        (r339814)
+++ head/sys/geom/nop/g_nop.c   Sat Oct 27 16:14:42 2018        (r339815)
@@ -187,7 +187,7 @@ g_nop_access(struct g_provider *pp, int dr, int dw, in
 static int
 g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
     int ioerror, u_int rfailprob, u_int wfailprob, off_t offset, off_t size,
-    u_int secsize, u_int stripesize, u_int stripeoffset, const char *physpath)
+    u_int secsize, off_t stripesize, off_t stripeoffset, const char *physpath)
 {
        struct g_nop_softc *sc;
        struct g_geom *gp;
@@ -464,7 +464,7 @@ g_nop_ctl_create(struct gctl_req *req, struct g_class 
                    *rfailprob == -1 ? 0 : (u_int)*rfailprob,
                    *wfailprob == -1 ? 0 : (u_int)*wfailprob,
                    (off_t)*offset, (off_t)*size, (u_int)*secsize,
-                   (u_int)*stripesize, (u_int)*stripeoffset,
+                   (off_t)*stripesize, (off_t)*stripeoffset,
                    physpath) != 0) {
                        return;
                }

Modified: head/sys/geom/part/g_part.c
==============================================================================
--- head/sys/geom/part/g_part.c Sat Oct 27 15:09:35 2018        (r339814)
+++ head/sys/geom/part/g_part.c Sat Oct 27 16:14:42 2018        (r339815)
@@ -367,9 +367,9 @@ g_part_check_integrity(struct g_part_table *table, str
                                offset = e1->gpe_offset;
                        if ((offset + pp->stripeoffset) % pp->stripesize) {
                                DPRINTF("partition %d on (%s, %s) is not "
-                                   "aligned on %u bytes\n", e1->gpe_index,
+                                   "aligned on %ju bytes\n", e1->gpe_index,
                                    pp->name, table->gpt_scheme->name,
-                                   pp->stripesize);
+                                   (uintmax_t)pp->stripesize);
                                /* Don't treat this as a critical failure */
                        }
                }
@@ -820,7 +820,7 @@ g_part_ctl_add(struct gctl_req *req, struct g_part_par
                G_PART_FULLNAME(table, entry, sb, gp->name);
                if (pp->stripesize > 0 && entry->gpe_pp->stripeoffset != 0)
                        sbuf_printf(sb, " added, but partition is not "
-                           "aligned on %u bytes\n", pp->stripesize);
+                           "aligned on %ju bytes\n", 
(uintmax_t)pp->stripesize);
                else
                        sbuf_cat(sb, " added\n");
                sbuf_finish(sb);

Modified: head/sys/geom/raid/g_raid.c
==============================================================================
--- head/sys/geom/raid/g_raid.c Sat Oct 27 15:09:35 2018        (r339814)
+++ head/sys/geom/raid/g_raid.c Sat Oct 27 16:14:42 2018        (r339815)
@@ -2423,7 +2423,7 @@ g_raid_dumpconf(struct sbuf *sb, const char *indent, s
                        sbuf_printf(sb, "r%d(%s):%d@%ju",
                            sd->sd_volume->v_global_id,
                            sd->sd_volume->v_name,
-                           sd->sd_pos, sd->sd_offset);
+                           sd->sd_pos, (uintmax_t)sd->sd_offset);
                        if (TAILQ_NEXT(sd, sd_next))
                                sbuf_printf(sb, ", ");
                }

Modified: head/sys/geom/stripe/g_stripe.c
==============================================================================
--- head/sys/geom/stripe/g_stripe.c     Sat Oct 27 15:09:35 2018        
(r339814)
+++ head/sys/geom/stripe/g_stripe.c     Sat Oct 27 16:14:42 2018        
(r339815)
@@ -249,7 +249,7 @@ static void
 g_stripe_copy(struct g_stripe_softc *sc, char *src, char *dst, off_t offset,
     off_t length, int mode)
 {
-       u_int stripesize;
+       off_t stripesize;
        size_t len;
 
        stripesize = sc->sc_stripesize;
@@ -265,8 +265,8 @@ g_stripe_copy(struct g_stripe_softc *sc, char *src, ch
                }
                length -= len;
                KASSERT(length >= 0,
-                   ("Length < 0 (stripesize=%zu, offset=%jd, length=%jd).",
-                   (size_t)stripesize, (intmax_t)offset, (intmax_t)length));
+                   ("Length < 0 (stripesize=%ju, offset=%ju, length=%jd).",
+                   (uintmax_t)stripesize, (uintmax_t)offset, 
(intmax_t)length));
                if (length > stripesize)
                        len = stripesize;
                else
@@ -307,10 +307,11 @@ static int
 g_stripe_start_fast(struct bio *bp, u_int no, off_t offset, off_t length)
 {
        TAILQ_HEAD(, bio) queue = TAILQ_HEAD_INITIALIZER(queue);
-       u_int nparts = 0, stripesize;
        struct g_stripe_softc *sc;
        char *addr, *data = NULL;
        struct bio *cbp;
+       off_t stripesize;
+       u_int nparts = 0;
        int error;
 
        sc = bp->bio_to->geom->softc;
@@ -436,7 +437,7 @@ g_stripe_start_economic(struct bio *bp, u_int no, off_
 {
        TAILQ_HEAD(, bio) queue = TAILQ_HEAD_INITIALIZER(queue);
        struct g_stripe_softc *sc;
-       uint32_t stripesize;
+       off_t stripesize;
        struct bio *cbp;
        char *addr;
        int error;
@@ -571,9 +572,9 @@ g_stripe_flush(struct g_stripe_softc *sc, struct bio *
 static void
 g_stripe_start(struct bio *bp)
 {
-       off_t offset, start, length, nstripe;
+       off_t offset, start, length, nstripe, stripesize;
        struct g_stripe_softc *sc;
-       u_int no, stripesize;
+       u_int no;
        int error, fast = 0;
 
        sc = bp->bio_to->geom->softc;
@@ -1044,7 +1045,7 @@ g_stripe_ctl_create(struct gctl_req *req, struct g_cla
        struct g_stripe_softc *sc;
        struct g_geom *gp;
        struct sbuf *sb;
-       intmax_t *stripesize;
+       off_t *stripesize;
        const char *name;
        char param[16];
        int *nargs;
@@ -1076,7 +1077,7 @@ g_stripe_ctl_create(struct gctl_req *req, struct g_cla
                gctl_error(req, "No '%s' argument.", "stripesize");
                return;
        }
-       md.md_stripesize = *stripesize;
+       md.md_stripesize = (uint32_t)*stripesize;
        bzero(md.md_provider, sizeof(md.md_provider));
        /* This field is not important here. */
        md.md_provsize = 0;
@@ -1243,8 +1244,8 @@ g_stripe_dumpconf(struct sbuf *sb, const char *indent,
                    (u_int)cp->index);
        } else {
                sbuf_printf(sb, "%s<ID>%u</ID>\n", indent, (u_int)sc->sc_id);
-               sbuf_printf(sb, "%s<Stripesize>%u</Stripesize>\n", indent,
-                   (u_int)sc->sc_stripesize);
+               sbuf_printf(sb, "%s<Stripesize>%ju</Stripesize>\n", indent,
+                   (uintmax_t)sc->sc_stripesize);
                sbuf_printf(sb, "%s<Type>", indent);
                switch (sc->sc_type) {
                case G_STRIPE_TYPE_AUTOMATIC:

Modified: head/sys/geom/stripe/g_stripe.h
==============================================================================
--- head/sys/geom/stripe/g_stripe.h     Sat Oct 27 15:09:35 2018        
(r339814)
+++ head/sys/geom/stripe/g_stripe.h     Sat Oct 27 16:14:42 2018        
(r339815)
@@ -76,7 +76,7 @@ struct g_stripe_softc {
        uint32_t         sc_id;         /* stripe unique ID */
        struct g_consumer **sc_disks;
        uint16_t         sc_ndisks;
-       uint32_t         sc_stripesize;
+       off_t            sc_stripesize;
        uint32_t         sc_stripebits;
        struct mtx       sc_lock;
 };

Modified: head/sys/geom/uzip/g_uzip.c
==============================================================================
--- head/sys/geom/uzip/g_uzip.c Sat Oct 27 15:09:35 2018        (r339814)
+++ head/sys/geom/uzip/g_uzip.c Sat Oct 27 16:14:42 2018        (r339815)
@@ -849,9 +849,9 @@ g_uzip_taste(struct g_class *mp, struct g_provider *pp
        g_error_provider(pp2, 0);
        g_access(cp, -1, 0, 0);
 
-       DPRINTF(GUZ_DBG_INFO, ("%s: taste ok (%d, %jd), (%d, %d), %x\n",
-           gp->name, pp2->sectorsize, (intmax_t)pp2->mediasize,
-           pp2->stripeoffset, pp2->stripesize, pp2->flags));
+       DPRINTF(GUZ_DBG_INFO, ("%s: taste ok (%d, %ju), (%ju, %ju), %x\n",
+           gp->name, pp2->sectorsize, (uintmax_t)pp2->mediasize,
+           (uintmax_t)pp2->stripeoffset, (uintmax_t)pp2->stripesize, 
pp2->flags));
        DPRINTF(GUZ_DBG_INFO, ("%s: %u x %u blocks\n", gp->name, sc->nblocks,
            sc->blksz));
        return (gp);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to