Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/dkwedge dk(4): Simplify dkwedge_delall by detaching ...



details:   https://anonhg.NetBSD.org/src/rev/b5c08454153a
branches:  trunk
changeset: 375930:b5c08454153a
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon May 22 14:58:59 2023 +0000

description:
dk(4): Simplify dkwedge_delall by detaching directly.

No need for O(n^2) algorithm and potentially racy lookups -- not that
n is large enough for n^2 to matter, but the mechanism is simpler
this way.

diffstat:

 sys/dev/dkwedge/dk.c |  22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diffs (60 lines):

diff -r 87724e6b7f8d -r b5c08454153a sys/dev/dkwedge/dk.c
--- a/sys/dev/dkwedge/dk.c      Mon May 22 14:58:50 2023 +0000
+++ b/sys/dev/dkwedge/dk.c      Mon May 22 14:58:59 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dk.c,v 1.161 2023/05/22 14:58:50 riastradh Exp $       */
+/*     $NetBSD: dk.c,v 1.162 2023/05/22 14:58:59 riastradh 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.161 2023/05/22 14:58:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.162 2023/05/22 14:58:59 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -781,7 +781,6 @@ dkwedge_delidle(struct disk *pdk)
 static void
 dkwedge_delall1(struct disk *pdk, bool idleonly)
 {
-       struct dkwedge_info dkw;
        struct dkwedge_softc *sc;
        int flags;
 
@@ -793,8 +792,18 @@ dkwedge_delall1(struct disk *pdk, bool i
                mutex_enter(&pdk->dk_rawlock); /* for sc->sc_dk.dk_openmask */
                mutex_enter(&pdk->dk_openlock);
                LIST_FOREACH(sc, &pdk->dk_wedges, sc_plink) {
-                       if (!idleonly || sc->sc_dk.dk_openmask == 0)
+                       /*
+                        * Wedge is not yet created.  This is a race --
+                        * it may as well have been added just after we
+                        * deleted all the wedges, so pretend it's not
+                        * here yet.
+                        */
+                       if (sc->sc_dev == NULL)
+                               continue;
+                       if (!idleonly || sc->sc_dk.dk_openmask == 0) {
+                               device_acquire(sc->sc_dev);
                                break;
+                       }
                }
                if (sc == NULL) {
                        KASSERT(idleonly || pdk->dk_nwedges == 0);
@@ -802,12 +811,9 @@ dkwedge_delall1(struct disk *pdk, bool i
                        mutex_exit(&pdk->dk_rawlock);
                        return;
                }
-               strlcpy(dkw.dkw_parent, pdk->dk_name, sizeof(dkw.dkw_parent));
-               strlcpy(dkw.dkw_devname, device_xname(sc->sc_dev),
-                   sizeof(dkw.dkw_devname));
                mutex_exit(&pdk->dk_openlock);
                mutex_exit(&pdk->dk_rawlock);
-               (void) dkwedge_del1(&dkw, flags);
+               (void)config_detach_release(sc->sc_dev, flags);
        }
 }
 



Home | Main Index | Thread Index | Old Index