tech-kern archive

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

A small cgd(4) diff



Hi,

a small byproduct from debugging cgd(4); use mutex(9) instead of lock(9).

- Jukka.


Index: src/sys/dev/cgd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/cgd.c,v
retrieving revision 1.58
diff -u -p -r1.58 cgd.c
--- src/sys/dev/cgd.c   5 Jun 2009 19:21:02 -0000       1.58
+++ src/sys/dev/cgd.c   10 Jul 2009 09:27:10 -0000
@@ -165,9 +165,8 @@ cgdsoftc_init(struct cgd_softc *cs, int 
 {
        char    sbuf[DK_XNAME_SIZE];
 
-       memset(cs, 0x0, sizeof(*cs));
        snprintf(sbuf, DK_XNAME_SIZE, "cgd%d", num);
-       simple_lock_init(&cs->sc_slock);
+       mutex_init(&cs->sc_lock, MUTEX_DEFAULT, IPL_NONE);
        dk_sc_init(&cs->sc_dksc, cs, sbuf);
        disk_init(&cs->sc_dksc.sc_dkdev, cs->sc_dksc.sc_xname, &cgddkdriver);
 }
@@ -183,7 +182,9 @@ cgdattach(int num)
                return;
        }
 
-       cgd_softc = (void *)malloc(num * sizeof(*cgd_softc), M_DEVBUF, 
M_NOWAIT);
+       cgd_softc = malloc(num * sizeof(*cgd_softc),
+           M_DEVBUF, M_NOWAIT | M_ZERO);
+
        if (!cgd_softc) {
                printf("WARNING: unable to malloc(9) memory for crypt disks\n");
                DIAGPANIC(("cgdattach: cannot malloc(9) enough memory"));
@@ -247,17 +248,17 @@ cgdsize(dev_t dev)
  */
 
 static void *
-cgd_getdata(struct dk_softc *dksc, unsigned long size)
+cgd_getdata(struct dk_softc *dksc, size_t size)
 {
        struct  cgd_softc *cs =dksc->sc_osc;
        void *  data = NULL;
 
-       simple_lock(&cs->sc_slock);
+       mutex_enter(&cs->sc_lock);
        if (cs->sc_data_used == 0) {
                cs->sc_data_used = 1;
                data = cs->sc_data;
        }
-       simple_unlock(&cs->sc_slock);
+       mutex_exit(&cs->sc_lock);
 
        if (data)
                return data;
@@ -271,9 +272,9 @@ cgd_putdata(struct dk_softc *dksc, void 
        struct  cgd_softc *cs =dksc->sc_osc;
 
        if (data == cs->sc_data) {
-               simple_lock(&cs->sc_slock);
+               mutex_enter(&cs->sc_lock);
                cs->sc_data_used = 0;
-               simple_unlock(&cs->sc_slock);
+               mutex_exit(&cs->sc_lock);
        } else {
                free(data, M_DEVBUF);
        }
@@ -490,8 +491,8 @@ cgddump(dev_t dev, daddr_t blkno, void *
 {
        struct  cgd_softc *cs;
 
-       DPRINTF_FOLLOW(("cgddump(0x%"PRIx64", %" PRId64 ", %p, %lu)\n",
-           dev, blkno, va, (unsigned long)size));
+       DPRINTF_FOLLOW(("cgddump(0x%"PRIx64", %" PRId64 ", %p, %zu)\n",
+           dev, blkno, va, size));
        GETCGD_SOFTC(cs, dev);
        return dk_dump(di, &cs->sc_dksc, dev, blkno, va, size);
 }
Index: src/sys/dev/cgdvar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/cgdvar.h,v
retrieving revision 1.12
diff -u -p -r1.12 cgdvar.h
--- src/sys/dev/cgdvar.h        12 Sep 2008 16:51:55 -0000      1.12
+++ src/sys/dev/cgdvar.h        10 Jul 2009 09:27:10 -0000
@@ -32,7 +32,7 @@
 #ifndef _DEV_CGDVAR_H_
 #define        _DEV_CGDVAR_H_
 
-#include <sys/simplelock.h>
+#include <sys/mutex.h>
 
 /* ioctl(2) code */
 struct cgd_ioctl {
@@ -77,9 +77,9 @@ struct cgd_softc {
        void *                   sc_data;       /* emergency buffer */
        int                      sc_data_used;  /* Really lame, we'll change */
        size_t                   sc_tpathlen;   /* length of prior string */
+       kmutex_t                 sc_lock;       /* our lock */
        struct cryptdata         sc_cdata;      /* crypto data */
        struct cryptfuncs       *sc_cfuncs;     /* encryption functions */
-       struct simplelock        sc_slock;      /* our lock */
 };
 #endif
 


Home | Main Index | Thread Index | Old Index