Source-Changes-HG archive

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

[src/netbsd-9]: src Pull up following revision(s) (requested by mlelstv in ti...



details:   https://anonhg.NetBSD.org/src/rev/39878421b91f
branches:  netbsd-9
changeset: 940601:39878421b91f
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Oct 11 12:34:29 2020 +0000

description:
Pull up following revision(s) (requested by mlelstv in ticket #1110):

        sys/dev/dkwedge/dk.c: revision 1.102
        sys/dev/ccd.c: revision 1.185
        sbin/ccdconfig/ccdconfig.c: revision 1.58

Use raw device for configuring units. This is necessary as
having a block device opened prevents autodiscovery of wedges.

Fix ioctl locking. Add dkdriver.

Check dkdriver before calling a driver function.

diffstat:

 sbin/ccdconfig/ccdconfig.c |   41 +++++--
 sys/dev/ccd.c              |  222 ++++++++++++++++++++++++--------------------
 sys/dev/dkwedge/dk.c       |    9 +-
 3 files changed, 156 insertions(+), 116 deletions(-)

diffs (truncated from 409 to 300 lines):

diff -r 65b446a11090 -r 39878421b91f sbin/ccdconfig/ccdconfig.c
--- a/sbin/ccdconfig/ccdconfig.c        Sun Oct 11 11:26:24 2020 +0000
+++ b/sbin/ccdconfig/ccdconfig.c        Sun Oct 11 12:34:29 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ccdconfig.c,v 1.56 2014/12/07 10:44:34 mlelstv Exp $   */
+/*     $NetBSD: ccdconfig.c,v 1.56.18.1 2020/10/11 12:34:29 martin 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.56 2014/12/07 10:44:34 mlelstv Exp $");
+__RCSID("$NetBSD: ccdconfig.c,v 1.56.18.1 2020/10/11 12:34:29 martin Exp $");
 #endif
 
 #include <sys/param.h>
@@ -391,24 +391,38 @@
 static char *
 resolve_ccdname(char *name)
 {
-       char c, *path;
+       char *path, *buf;
+       const char *p;
+       char c;
        size_t len;
        int rawpart;
 
        if (name[0] == '/' || name[0] == '.') {
                /* Assume they gave the correct pathname. */
-               return estrdup(name);
+               path = estrdup(name);
+       } else {
+
+               len = strlen(name);
+               c = name[len - 1];
+
+               if (isdigit((unsigned char)c)) {
+                       if ((rawpart = getrawpartition()) < 0)
+                               return NULL;
+                       easprintf(&path, "/dev/%s%c", name, 'a' + rawpart);
+               } else
+                       easprintf(&path, "/dev/%s", name);
        }
 
-       len = strlen(name);
-       c = name[len - 1];
-
-       if (isdigit((unsigned char)c)) {
-               if ((rawpart = getrawpartition()) < 0)
-                       return NULL;
-               easprintf(&path, "/dev/%s%c", name, 'a' + rawpart);
-       } else
-               easprintf(&path, "/dev/%s", name);
+       /*
+        * Convert to raw device if possible.
+        */
+       buf = emalloc(MAXPATHLEN);
+       p = getdiskrawname(buf, MAXPATHLEN, path);
+       if (p) {
+               free(path);
+               path = estrdup(p);
+       }
+       free(buf);
 
        return path;
 }
@@ -562,6 +576,7 @@
                        continue;
                }
                errs += printccdinfo(i);
+               free(ccd);
        }
        return errs;
 }
diff -r 65b446a11090 -r 39878421b91f sys/dev/ccd.c
--- a/sys/dev/ccd.c     Sun Oct 11 11:26:24 2020 +0000
+++ b/sys/dev/ccd.c     Sun Oct 11 12:34:29 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ccd.c,v 1.179 2019/03/27 19:13:34 martin Exp $ */
+/*     $NetBSD: ccd.c,v 1.179.4.1 2020/10/11 12:34:29 martin Exp $     */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 1999, 2007, 2009 The NetBSD Foundation, Inc.
@@ -88,7 +88,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.179 2019/03/27 19:13:34 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.179.4.1 2020/10/11 12:34:29 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -209,6 +209,11 @@
        .d_flag = D_DISK | D_MPSAFE
 };
 
+static const struct dkdriver ccddkdriver = {
+       .d_strategy = ccdstrategy,
+       .d_minphys = minphys
+}; 
+
 #ifdef DEBUG
 static void printiinfo(struct ccdiinfo *);
 #endif
@@ -233,7 +238,7 @@
        sc->sc_iolock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
        cv_init(&sc->sc_stop, "ccdstop");
        cv_init(&sc->sc_push, "ccdthr");
-       disk_init(&sc->sc_dkdev, sc->sc_xname, NULL); /* XXX */
+       disk_init(&sc->sc_dkdev, sc->sc_xname, &ccddkdriver);
        return sc;
 }
 
@@ -1138,8 +1143,6 @@
                        return (EBADF);
        }
 
-       mutex_enter(&cs->sc_dvlock);
-
        /* Must be initialized for these... */
        switch (cmd) {
        case CCDIOCCLR:
@@ -1163,15 +1166,102 @@
        case ODIOCWDINFO:
        case ODIOCGDEFLABEL:
 #endif
-               if ((cs->sc_flags & CCDF_INITED) == 0) {
-                       error = ENXIO;
-                       goto out;
-               }
+               if ((cs->sc_flags & CCDF_INITED) == 0)
+                       return ENXIO;
        }
 
        error = disk_ioctl(&cs->sc_dkdev, dev, cmd, data, flag, l);
        if (error != EPASSTHROUGH)
-               goto out;
+               return error;
+
+       switch (cmd) {
+       case DIOCGSTRATEGY:
+           {
+               struct disk_strategy *dks = (void *)data;
+
+               mutex_enter(cs->sc_iolock);
+               if (cs->sc_bufq != NULL)
+                       strlcpy(dks->dks_name,
+                           bufq_getstrategyname(cs->sc_bufq),
+                           sizeof(dks->dks_name));
+               else
+                       error = EINVAL;
+               mutex_exit(cs->sc_iolock);
+               dks->dks_paramlen = 0;
+               break;
+           }
+
+       case DIOCWDINFO:
+       case DIOCSDINFO:
+#ifdef __HAVE_OLD_DISKLABEL
+       case ODIOCWDINFO:
+       case ODIOCSDINFO:
+#endif
+       {
+               struct disklabel *lp;
+#ifdef __HAVE_OLD_DISKLABEL
+               if (cmd == ODIOCSDINFO || cmd == ODIOCWDINFO) {
+                       memset(&newlabel, 0, sizeof newlabel);
+                       memcpy(&newlabel, data, sizeof (struct olddisklabel));
+                       lp = &newlabel;
+               } else
+#endif
+               lp = (struct disklabel *)data;
+
+               cs->sc_flags |= CCDF_LABELLING;
+
+               error = setdisklabel(cs->sc_dkdev.dk_label,
+                   lp, 0, cs->sc_dkdev.dk_cpulabel);
+               if (error == 0) {
+                       if (cmd == DIOCWDINFO
+#ifdef __HAVE_OLD_DISKLABEL
+                           || cmd == ODIOCWDINFO
+#endif
+                          )
+                               error = writedisklabel(CCDLABELDEV(dev),
+                                   ccdstrategy, cs->sc_dkdev.dk_label,
+                                   cs->sc_dkdev.dk_cpulabel);
+               }
+
+               cs->sc_flags &= ~CCDF_LABELLING;
+               break;
+       }
+
+       case DIOCKLABEL:
+               if (*(int *)data != 0)
+                       cs->sc_flags |= CCDF_KLABEL;
+               else
+                       cs->sc_flags &= ~CCDF_KLABEL;
+               break;
+
+       case DIOCWLABEL:
+               if (*(int *)data != 0)
+                       cs->sc_flags |= CCDF_WLABEL;
+               else
+                       cs->sc_flags &= ~CCDF_WLABEL;
+               break;
+
+       case DIOCGDEFLABEL:
+               ccdgetdefaultlabel(cs, (struct disklabel *)data);
+               break;
+
+#ifdef __HAVE_OLD_DISKLABEL
+       case ODIOCGDEFLABEL:
+               ccdgetdefaultlabel(cs, &newlabel);
+               if (newlabel.d_npartitions > OLDMAXPARTITIONS)
+                       return ENOTTY;
+               memcpy(data, &newlabel, sizeof (struct olddisklabel));
+               break;
+#endif
+       default:
+               error = ENOTTY;
+                       break;
+       }
+
+       if (error != ENOTTY)
+               return error;
+
+       mutex_enter(&cs->sc_dvlock);
 
        error = 0;
        switch (cmd) {
@@ -1237,6 +1327,12 @@
                                    sizeof(*vpp));
                                kmem_free(cpp, ccio->ccio_ndisks *
                                    sizeof(*cpp));
+
+                               /*
+                                * No component data is allocated,
+                                * nothing is to be freed.
+                               */
+                               cs->sc_nccdisks = 0;
                                goto out;
                        }
                        ++lookedup;
@@ -1336,43 +1432,31 @@
                            cs->sc_cinfo[i].ci_pathlen);
                }
 
-               /* Free interleave index. */
-               for (i = 0; cs->sc_itable[i].ii_ndisk; ++i) {
-                       kmem_free(cs->sc_itable[i].ii_index,
-                           cs->sc_itable[i].ii_indexsz);
+               if (cs->sc_nccdisks != 0) {
+                       /* Free interleave index. */
+                       for (i = 0; cs->sc_itable[i].ii_ndisk; ++i) {
+                               kmem_free(cs->sc_itable[i].ii_index,
+                                   cs->sc_itable[i].ii_indexsz);
+                       }
+                       /* Free component info and interleave table. */
+                       kmem_free(cs->sc_cinfo, cs->sc_nccdisks *
+                           sizeof(struct ccdcinfo));
+                       kmem_free(cs->sc_itable, (cs->sc_nccdisks + 1) *
+                           sizeof(struct ccdiinfo));
                }
 
-               /* Free component info and interleave table. */
-               kmem_free(cs->sc_cinfo, cs->sc_nccdisks *
-                   sizeof(struct ccdcinfo));
-               kmem_free(cs->sc_itable, (cs->sc_nccdisks + 1) *
-                   sizeof(struct ccdiinfo));
-
                aprint_normal("%s: detached\n", cs->sc_xname);
 
                /* Detach the disk. */
                disk_detach(&cs->sc_dkdev);
                bufq_free(cs->sc_bufq);
+
+               /* also releases dv_lock */
                ccdput(cs);
+
                /* Don't break, otherwise cs is read again. */
                return 0;
 
-       case DIOCGSTRATEGY:
-           {
-               struct disk_strategy *dks = (void *)data;
-
-               mutex_enter(cs->sc_iolock);
-               if (cs->sc_bufq != NULL)
-                       strlcpy(dks->dks_name,
-                           bufq_getstrategyname(cs->sc_bufq),
-                           sizeof(dks->dks_name));
-               else
-                       error = EINVAL;
-               mutex_exit(cs->sc_iolock);
-               dks->dks_paramlen = 0;
-               break;
-           }
-



Home | Main Index | Thread Index | Old Index