]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/miscfs/specfs/spec_vnops.c
xnu-344.21.73.tar.gz
[apple/xnu.git] / bsd / miscfs / specfs / spec_vnops.c
index 5391c20aacaad1ec8fe3b588422dc6d583eed749..d5efd260bfc8a3473aca78e8f27ddef72ef01588 100644 (file)
@@ -1,21 +1,24 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
@@ -73,6 +76,7 @@
 #include <miscfs/specfs/specdev.h>
 #include <vfs/vfs_support.h>
 
+#include <sys/kdebug.h>
 
 struct vnode *speclisth[SPECHSZ];
 
@@ -511,6 +515,7 @@ spec_select(ap)
                int  a_which;
                int  a_fflags;
                struct ucred *a_cred;
+               void * a_wql;
                struct proc *a_p;
        } */ *ap;
 {
@@ -523,7 +528,7 @@ spec_select(ap)
 
        case VCHR:
                dev = ap->a_vp->v_rdev;
-               return (*cdevsw[major(dev)].d_select)(dev, ap->a_which, ap->a_p);
+               return (*cdevsw[major(dev)].d_select)(dev, ap->a_which, ap->a_wql, ap->a_p);
        }
 }
 /*
@@ -553,7 +558,8 @@ loop:
        s = splbio();
        for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) {
                nbp = bp->b_vnbufs.le_next;
-               if ((bp->b_flags & B_BUSY))
+               // XXXdbg - don't flush locked blocks.  they may be journaled.
+               if ((bp->b_flags & B_BUSY) || (bp->b_flags & B_LOCKED))
                        continue;
                if ((bp->b_flags & B_DELWRI) == 0)
                        panic("spec_fsync: not dirty");
@@ -588,8 +594,28 @@ spec_strategy(ap)
                struct buf *a_bp;
        } */ *ap;
 {
-       (*bdevsw[major(ap->a_bp->b_dev)].d_strategy)(ap->a_bp);
-       return (0);
+        struct buf *bp;
+
+        bp = ap->a_bp;
+
+        if (kdebug_enable) {
+            int    code = 0;
+
+            if (bp->b_flags & B_READ)
+                code |= DKIO_READ;
+            if (bp->b_flags & B_ASYNC)
+                code |= DKIO_ASYNC;
+
+            if (bp->b_flags & B_META)
+                code |= DKIO_META;
+            else if (bp->b_flags & (B_PGIN | B_PAGEOUT))
+                code |= DKIO_PAGING;
+
+            KERNEL_DEBUG_CONSTANT(FSDBG_CODE(DBG_DKRW, code) | DBG_FUNC_NONE,
+                                bp, bp->b_dev, bp->b_blkno, bp->b_bcount, 0);
+        }
+        (*bdevsw[major(bp->b_dev)].d_strategy)(bp);
+        return (0);
 }
 
 /*
@@ -662,8 +688,8 @@ spec_close(ap)
                 */
                if (vcount(vp) == 2 && ap->a_p &&
                    vp == ap->a_p->p_session->s_ttyvp) {
-                       vrele(vp);
                        ap->a_p->p_session->s_ttyvp = NULL;
+                       vrele(vp);
                }
                /*
                 * If the vnode is locked, then we are in the midst
@@ -677,12 +703,16 @@ spec_close(ap)
                break;
 
        case VBLK:
+#ifdef DEVFS_IMPLEMENTS_LOCKING
                /*
                 * On last close of a block device (that isn't mounted)
                 * we must invalidate any in core blocks, so that
                 * we can, for instance, change floppy disks.
                 */
-               if (error = vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_p, 0, 0))
+               vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, ap->a_p);
+               error = vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_p, 0, 0);
+               VOP_UNLOCK(vp, 0, ap->a_p);
+               if (error)
                        return (error);
                /*
                 * We do not want to really close the device if it
@@ -695,6 +725,28 @@ spec_close(ap)
                 */
                if (vcount(vp) > 1 && (vp->v_flag & VXLOCK) == 0)
                        return (0);
+#else /* DEVFS_IMPLEMENTS_LOCKING */
+               /*
+                * We do not want to really close the device if it
+                * is still in use unless we are trying to close it
+                * forcibly. Since every use (buffer, vnode, swap, cmap)
+                * holds a reference to the vnode, and because we mark
+                * any other vnodes that alias this device, when the
+                * sum of the reference counts on all the aliased
+                * vnodes descends to one, we are on last close.
+                */
+               if (vcount(vp) > 1 && (vp->v_flag & VXLOCK) == 0)
+                       return (0);
+
+               /*
+                * On last close of a block device (that isn't mounted)
+                * we must invalidate any in core blocks, so that
+                * we can, for instance, change floppy disks.
+                */
+               error = vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_p, 0, 0);
+               if (error)
+                       return (error);
+#endif /* DEVFS_IMPLEMENTS_LOCKING */
                devclose = bdevsw[major(dev)].d_close;
                mode = S_IFBLK;
                break;