Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/dkwedge when scanning for disklabels, close block de...



details:   https://anonhg.NetBSD.org/src/rev/9d98c7c78365
branches:  trunk
changeset: 810185:9d98c7c78365
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Thu Aug 20 23:08:33 2015 +0000

description:
when scanning for disklabels, close block device only when this was
the first open. The device driver doesn't do reference counting.

This is still subject to race conditions.

diffstat:

 sys/dev/dkwedge/dk.c |  15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diffs (50 lines):

diff -r fb9ed87b4df1 -r 9d98c7c78365 sys/dev/dkwedge/dk.c
--- a/sys/dev/dkwedge/dk.c      Thu Aug 20 22:27:49 2015 +0000
+++ b/sys/dev/dkwedge/dk.c      Thu Aug 20 23:08:33 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dk.c,v 1.79 2015/01/02 01:14:22 christos Exp $ */
+/*     $NetBSD: dk.c,v 1.80 2015/08/20 23:08:33 mlelstv Exp $  */
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.79 2015/01/02 01:14:22 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.80 2015/08/20 23:08:33 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -944,7 +944,7 @@
     void *tbuf, size_t len)
 {
        buf_t *bp;
-       int error;
+       int error, isopen;
 
        /*
         * The kernel cannot read from a character device vnode
@@ -964,6 +964,12 @@
        bp->b_cylinder = 0;
        bp->b_error = 0;
 
+       /*
+        * XXX Only the last user of a block device can close it.
+        * There is no reference counting in the driver.
+        */
+       isopen = pdk->dk_bopenmask & (1 << DISKPART(bp->b_dev));
+
        error = bdev_open(bp->b_dev, FREAD, S_IFBLK, curlwp);
        if (error)
                return error;
@@ -972,7 +978,8 @@
        error = biowait(bp);
        putiobuf(bp);
 
-       bdev_close(bp->b_dev, FREAD, S_IFBLK, curlwp);
+       if (!isopen)
+               bdev_close(bp->b_dev, FREAD, S_IFBLK, curlwp);
 
        return error;
 }



Home | Main Index | Thread Index | Old Index