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: Assert opencnt>0 on successful open.



details:   https://anonhg.NetBSD.org/src/rev/3e49b686b809
branches:  trunk
changeset: 368917:3e49b686b809
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Aug 12 17:05:49 2022 +0000

description:
specfs: Assert opencnt>0 on successful open.

diffstat:

 sys/miscfs/specfs/spec_vnops.c |  15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diffs (36 lines):

diff -r 11d4b234dff3 -r 3e49b686b809 sys/miscfs/specfs/spec_vnops.c
--- a/sys/miscfs/specfs/spec_vnops.c    Fri Aug 12 16:21:41 2022 +0000
+++ b/sys/miscfs/specfs/spec_vnops.c    Fri Aug 12 17:05:49 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: spec_vnops.c,v 1.211 2022/08/11 12:52:24 riastradh Exp $       */
+/*     $NetBSD: spec_vnops.c,v 1.212 2022/08/12 17:05:49 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.211 2022/08/11 12:52:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.212 2022/08/12 17:05:49 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -956,6 +956,17 @@
                if (error == 0)
                        error = EBADF;
        } else if (error == 0) {
+               /*
+                * Device has not been revoked, so our opencnt can't
+                * have gone away at this point -- transition to
+                * sn_gone=true happens before transition to
+                * sn_opencnt=0 in spec_node_revoke.
+                */
+               KASSERT(sd->sd_opencnt);
+               KASSERT(sn->sn_opencnt);
+               KASSERTMSG(sn->sn_opencnt <= sd->sd_opencnt,
+                   "sn_opencnt=%u > sd_opencnt=%u",
+                   sn->sn_opencnt, sd->sd_opencnt);
                sd->sd_opened = true;
        } else if (sd->sd_opencnt == 1 && sd->sd_opened) {
                /*



Home | Main Index | Thread Index | Old Index