Source-Changes-HG archive

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

[src/trunk]: src/sys/miscfs/specfs specfs: Reorganize D_DISK tail of spec_ope...



details:   https://anonhg.NetBSD.org/src/rev/60c601c53d5c
branches:  trunk
changeset: 364504:60c601c53d5c
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Mar 28 12:35:35 2022 +0000

description:
specfs: Reorganize D_DISK tail of spec_open and explain what's up.

No functional change intended.

diffstat:

 sys/miscfs/specfs/spec_vnops.c |  28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)

diffs (52 lines):

diff -r 87f86bc37899 -r 60c601c53d5c sys/miscfs/specfs/spec_vnops.c
--- a/sys/miscfs/specfs/spec_vnops.c    Mon Mar 28 12:35:26 2022 +0000
+++ b/sys/miscfs/specfs/spec_vnops.c    Mon Mar 28 12:35:35 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: spec_vnops.c,v 1.193 2022/03/28 12:35:26 riastradh Exp $       */
+/*     $NetBSD: spec_vnops.c,v 1.194 2022/03/28 12:35:35 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.193 2022/03/28 12:35:26 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.194 2022/03/28 12:35:35 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -732,15 +732,27 @@
        }
        mutex_exit(&device_lock);
 
-       if (cdev_type(dev) != D_DISK || error != 0)
+       /* If anything went wrong, we're done.  */
+       if (error)
                return error;
 
-       
-       ioctl = vp->v_type == VCHR ? cdev_ioctl : bdev_ioctl;
-       error = (*ioctl)(vp->v_rdev, DIOCGPARTINFO, &pi, FREAD, curlwp);
-       if (error == 0)
-               uvm_vnp_setsize(vp, (voff_t)pi.pi_secsize * pi.pi_size);
+       /*
+        * For disk devices, automagically set the vnode size to the
+        * partition size, if we can.  This applies to block devices
+        * and character devices alike -- every block device must have
+        * a corresponding character device.  And if the module is
+        * loaded it will remain loaded until we're done here (it is
+        * forbidden to devsw_detach until closed).  So it is safe to
+        * query cdev_type unconditionally here.
+        */
+       if (cdev_type(dev) == D_DISK) {
+               ioctl = vp->v_type == VCHR ? cdev_ioctl : bdev_ioctl;
+               if ((*ioctl)(dev, DIOCGPARTINFO, &pi, FREAD, curlwp) == 0)
+                       uvm_vnp_setsize(vp,
+                           (voff_t)pi.pi_secsize * pi.pi_size);
+       }
 
+       /* Success!  */
        return 0;
 }
 



Home | Main Index | Thread Index | Old Index