Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Switch size_t to uint64_t in appropriate places to ensure th...



details:   https://anonhg.NetBSD.org/src/rev/82637ad59836
branches:  trunk
changeset: 331623:82637ad59836
user:      sborrill <sborrill%NetBSD.org@localhost>
date:      Sat Aug 16 19:27:27 2014 +0000

description:
Switch size_t to uint64_t in appropriate places to ensure that ccd(4) works
with component and total sizes of > 2TB.
Add COMPAT_60 code for platforms where this alters userland-accessible
structures.
Make kernel print device information when a ccd configured.
Fix some typos in comments.

diffstat:

 sbin/ccdconfig/ccdconfig.c |   6 +-
 sys/dev/ccd.c              |  81 ++++++++++++++++++++++++++++++++++++++++-----
 sys/dev/ccdvar.h           |  27 ++++++++++++--
 3 files changed, 97 insertions(+), 17 deletions(-)

diffs (231 lines):

diff -r 619b500eeba2 -r 82637ad59836 sbin/ccdconfig/ccdconfig.c
--- a/sbin/ccdconfig/ccdconfig.c        Sat Aug 16 17:57:37 2014 +0000
+++ b/sbin/ccdconfig/ccdconfig.c        Sat Aug 16 19:27:27 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ccdconfig.c,v 1.53 2013/05/03 00:01:15 christos Exp $  */
+/*     $NetBSD: ccdconfig.c,v 1.54 2014/08/16 19:27:27 sborrill Exp $  */
 
 /*-
  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1996, 1997\
  The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: ccdconfig.c,v 1.53 2013/05/03 00:01:15 christos Exp $");
+__RCSID("$NetBSD: ccdconfig.c,v 1.54 2014/08/16 19:27:27 sborrill Exp $");
 #endif
 
 #include <sys/param.h>
@@ -271,7 +271,7 @@
                            ui == 0 ? '(' : ' ', cp2,
                            ui == ccio.ccio_ndisks - 1 ? ')' : ',');
                }
-               printf(", %ld blocks ", (long)ccio.ccio_size);
+               printf(", %ju blocks ", (uintmax_t)ccio.ccio_size);
                if (ccio.ccio_ileave != 0)
                        printf("interleaved at %d blocks\n", ccio.ccio_ileave);
                else
diff -r 619b500eeba2 -r 82637ad59836 sys/dev/ccd.c
--- a/sys/dev/ccd.c     Sat Aug 16 17:57:37 2014 +0000
+++ b/sys/dev/ccd.c     Sat Aug 16 19:27:27 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ccd.c,v 1.151 2014/07/25 08:10:35 dholland Exp $       */
+/*     $NetBSD: ccd.c,v 1.152 2014/08/16 19:27:27 sborrill Exp $       */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 1999, 2007, 2009 The NetBSD Foundation, Inc.
@@ -88,7 +88,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.151 2014/07/25 08:10:35 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.152 2014/08/16 19:27:27 sborrill Exp $");
+
+#if defined(_KERNEL_OPT)
+#include "opt_compat_netbsd.h"
+#endif
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -426,6 +430,22 @@
        ccg->ccg_ntracks = 1;
        ccg->ccg_nsectors = 1024 * (1024 / ccg->ccg_secsize);
        ccg->ccg_ncylinders = cs->sc_size / ccg->ccg_nsectors;
+       
+       if (cs->sc_ileave > 0)
+               aprint_normal("%s: Interleaving %d component%s "
+                   "(%d block interleave)\n", cs->sc_xname,
+                   cs->sc_nccdisks, (cs->sc_nccdisks != 0 ? "s" : ""),
+                   cs->sc_ileave);
+       else
+               aprint_normal("%s: Concatenating %d component%s\n",
+                   cs->sc_xname,
+                   cs->sc_nccdisks, (cs->sc_nccdisks != 0 ? "s" : ""));
+       for (ix = 0; ix < cs->sc_nccdisks; ix++) {
+               ci = &cs->sc_cinfo[ix];
+               aprint_normal("%s: %s (%ju blocks)\n", cs->sc_xname,
+                   ci->ci_path, (uintmax_t)ci->ci_size);
+       }
+       aprint_normal("%s: total %ju blocks\n", cs->sc_xname, cs->sc_size);
 
        /*
         * Create thread to handle deferred I/O.
@@ -1053,6 +1073,46 @@
                return ENOENT;
        uc = kauth_cred_get();
 
+/*
+ * Compat code must not be called if on a platform where
+ * sizeof (size_t) == sizeof (uint64_t) as CCDIOCSET will
+ * be the same as CCDIOCSET_60
+ */
+#if defined(COMPAT_60) && !defined(_LP64)
+       switch (cmd) {
+       case CCDIOCSET_60: {
+               struct ccd_ioctl ccionew;
+                       struct ccd_ioctl_60 *ccio60 =
+                           (struct ccd_ioctl_60 *)data;
+               ccionew.ccio_disks = ccio->ccio_disks;
+               ccionew.ccio_ndisks = ccio->ccio_ndisks;
+               ccionew.ccio_ileave = ccio->ccio_ileave;
+               ccionew.ccio_flags = ccio->ccio_flags;
+               ccionew.ccio_unit = ccio->ccio_unit;
+               error = ccdioctl(dev, CCDIOCSET, &ccionew, flag, l);
+               if (!error) {
+                       /* Copy data back, adjust types if necessary */
+                       ccio60->ccio_disks = ccionew.ccio_disks;
+                       ccio60->ccio_ndisks = ccionew.ccio_ndisks;
+                       ccio60->ccio_ileave = ccionew.ccio_ileave;
+                       ccio60->ccio_flags = ccionew.ccio_flags;
+                       ccio60->ccio_unit = ccionew.ccio_unit;
+                       ccio60->ccio_size = (size_t)ccionew.ccio_size;
+               }
+               return error;
+               }
+               break;
+
+       case CCDIOCCLR_60:
+               /*
+                * ccio_size member not used, so existing struct OK
+                * drop through to existing non-compat version
+                */
+               cmd = CCDIOCCLR;
+               break;
+       }
+#endif /* COMPAT_60 && !_LP64*/
+
        /* Must be open for writes for these commands... */
        switch (cmd) {
        case CCDIOCSET:
@@ -1120,7 +1180,7 @@
 
                /*
                 * Allocate space for and copy in the array of
-                * componet pathnames and device numbers.
+                * component pathnames and device numbers.
                 */
                cpp = kmem_alloc(ccio->ccio_ndisks * sizeof(*cpp), KM_SLEEP);
                vpp = kmem_alloc(ccio->ccio_ndisks * sizeof(*vpp), KM_SLEEP);
@@ -1259,7 +1319,9 @@
                kmem_free(cs->sc_itable, (cs->sc_nccdisks + 1) *
                    sizeof(struct ccdiinfo));
 
-               /* Detatch the disk. */
+               aprint_normal("%s: detached\n", cs->sc_xname);
+
+               /* Detach the disk. */
                disk_detach(&cs->sc_dkdev);
                bufq_free(cs->sc_bufq);
                ccdput(cs);
@@ -1489,15 +1551,16 @@
                 */
                if (lp->d_secperunit != cs->sc_size)
                        printf("WARNING: %s: "
-                           "total sector size in disklabel (%d) != "
-                           "the size of ccd (%lu)\n", cs->sc_xname,
-                           lp->d_secperunit, (u_long)cs->sc_size);
+                           "total sector size in disklabel (%ju) != "
+                           "the size of ccd (%ju)\n", cs->sc_xname,
+                           (uintmax_t)lp->d_secperunit,
+                           (uintmax_t)cs->sc_size);
                for (i = 0; i < lp->d_npartitions; i++) {
                        pp = &lp->d_partitions[i];
                        if (pp->p_offset + pp->p_size > cs->sc_size)
                                printf("WARNING: %s: end of partition `%c' "
-                                   "exceeds the size of ccd (%lu)\n",
-                                   cs->sc_xname, 'a' + i, (u_long)cs->sc_size);
+                                   "exceeds the size of ccd (%ju)\n",
+                                   cs->sc_xname, 'a' + i, (uintmax_t)cs->sc_size);
                }
        }
 
diff -r 619b500eeba2 -r 82637ad59836 sys/dev/ccdvar.h
--- a/sys/dev/ccdvar.h  Sat Aug 16 17:57:37 2014 +0000
+++ b/sys/dev/ccdvar.h  Sat Aug 16 19:27:27 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ccdvar.h,v 1.33 2013/04/27 17:13:34 christos Exp $     */
+/*     $NetBSD: ccdvar.h,v 1.34 2014/08/16 19:27:27 sborrill Exp $     */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 1999, 2007, 2009 The NetBSD Foundation, Inc.
@@ -93,9 +93,10 @@
        int     ccio_ileave;            /* interleave (DEV_BSIZE blocks) */
        int     ccio_flags;             /* see sc_flags below */
        int     ccio_unit;              /* unit number: use varies */
-       size_t  ccio_size;              /* (returned) size of ccd */
+       uint64_t        ccio_size;      /* (returned) size of ccd */
 };
 
+
 /*
  * Component info table.
  * Describes a single component of a concatenated disk.
@@ -103,7 +104,7 @@
 struct ccdcinfo {
        struct vnode    *ci_vp;                 /* device's vnode */
        dev_t           ci_dev;                 /* XXX: device's dev_t */
-       size_t          ci_size;                /* size */
+       uint64_t        ci_size;                /* size */
        char            *ci_path;               /* path to component */
        size_t          ci_pathlen;             /* length of component path */
 };
@@ -160,7 +161,7 @@
 struct ccd_softc {
        int              sc_unit;
        int              sc_flags;              /* flags */
-       size_t           sc_size;               /* size of ccd */
+       uint64_t         sc_size;               /* size of ccd */
        int              sc_ileave;             /* interleave */
        u_int            sc_nccdisks;           /* number of components */
 #define        CCD_MAXNDISKS   65536
@@ -203,13 +204,29 @@
 #define CCDIOCSET      _IOWR('F', 16, struct ccd_ioctl)   /* enable ccd */
 #define CCDIOCCLR      _IOW('F', 17, struct ccd_ioctl)    /* disable ccd */
 
+#if defined(COMPAT_60) && !defined(_LP64)
+/*
+ * Old version with incorrect ccio_size
+ */
+struct ccd_ioctl_60 {
+       char    **ccio_disks;           /* pointer to component paths */
+       u_int   ccio_ndisks;            /* number of disks to concatenate */
+       int     ccio_ileave;            /* interleave (DEV_BSIZE blocks) */
+       int     ccio_flags;             /* see sc_flags below */
+       int     ccio_unit;              /* unit number: use varies */
+       size_t  ccio_size;              /* (returned) size of ccd */
+};
+
+#define CCDIOCSET_60   _IOWR('F', 16, struct ccd_ioctl_60)   /* enable ccd */
+#define CCDIOCCLR_60   _IOW('F', 17, struct ccd_ioctl_60)   /* disable ccd */
+#endif /* COMPAT_60 && !LP64*/
 /*
  * Sysctl information
  */
 struct ccddiskinfo {
        int ccd_ileave;
        u_int ccd_ndisks;
-       size_t ccd_size;
+       uint64_t ccd_size;
        int ccd_flags;
 };
 



Home | Main Index | Thread Index | Old Index