Source-Changes-D archive

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

Re: CVS commit: src/sys/dev



On Tue, Nov 10, 2009 at 08:48:42AM +0000, Matthias Scheler wrote:
> > A LOCKDEBUG kernel will panic.  How can we avoid the stack
> > overflows and such in a different way?
> 
> I'll try to rewrite the code to use M_NOWAIT.

The attached diff changes the code to use M_NOWAIT. I have however
only compiled tested it so far.

        Kind regards

-- 
Matthias Scheler                                  http://zhadum.org.uk/
Index: sys/dev/cgd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/cgd.c,v
retrieving revision 1.60
diff -u -r1.60 cgd.c
--- sys/dev/cgd.c       11 Sep 2009 13:36:37 -0000      1.60
+++ sys/dev/cgd.c       10 Nov 2009 13:33:02 -0000
@@ -84,7 +84,7 @@
 static int     cgd_ioctl_clr(struct cgd_softc *, void *, struct lwp *);
 static int     cgdinit(struct cgd_softc *, const char *, struct vnode *,
                        struct lwp *);
-static void    cgd_cipher(struct cgd_softc *, void *, void *,
+static bool    cgd_cipher(struct cgd_softc *, void *, void *,
                           size_t, daddr_t, size_t, int);
 
 /* Pseudo-disk Interface */
@@ -318,8 +318,13 @@
                        disk_unbusy(&dksc->sc_dkdev, 0, (bp->b_flags & B_READ));
                        return -1;
                }
-               cgd_cipher(cs, newaddr, addr, bp->b_bcount, bn,
-                   DEV_BSIZE, CGD_CIPHER_ENCRYPT);
+               if (!cgd_cipher(cs, newaddr, addr, bp->b_bcount, bn,
+                   DEV_BSIZE, CGD_CIPHER_ENCRYPT)) {
+                       cgd_putdata(dksc, newaddr);
+                       putiobuf(nbp);
+                       disk_unbusy(&dksc->sc_dkdev, 0, (bp->b_flags & B_READ));
+                       return -1;
+               }
        }
 
        nbp->b_data = newaddr;
@@ -371,9 +376,12 @@
         *       we used to encrypt the blocks.
         */
 
-       if (nbp->b_flags & B_READ)
-               cgd_cipher(cs, obp->b_data, obp->b_data, obp->b_bcount,
-                   nbp->b_blkno, DEV_BSIZE, CGD_CIPHER_DECRYPT);
+       if (nbp->b_flags & B_READ) {
+               if (!cgd_cipher(cs, obp->b_data, obp->b_data, obp->b_bcount,
+                   nbp->b_blkno, DEV_BSIZE, CGD_CIPHER_DECRYPT)) {
+                       obp->b_error = ENOMEM;
+               }
+       }
 
        /* If we allocated memory, free it now... */
        if (nbp->b_data != obp->b_data)
@@ -763,7 +771,7 @@
        }
 }
 
-static void
+static bool
 cgd_cipher(struct cgd_softc *cs, void *dstv, void *srcv,
     size_t len, daddr_t blkno, size_t secsize, int dir)
 {
@@ -779,7 +787,9 @@
        char            *zero_iv;
        char            *blkno_buf;
 
-       sink = malloc(blocksize * 3, M_DEVBUF, M_WAITOK);
+       sink = malloc(blocksize * 3, M_DEVBUF, M_NOWAIT);
+       if (sink == NULL)
+               return false;
        zero_iv = &sink[blocksize];
        blkno_buf = &zero_iv[blocksize];
 
@@ -837,6 +847,7 @@
        }
 
        free(sink, M_DEVBUF);
+       return true;
 }
 
 #ifdef DEBUG


Home | Main Index | Thread Index | Old Index