git: cca384d7e546 - stable/13 - geom_disk: use a preallocated geom_event for disk destruction.

Warner Losh imp at FreeBSD.org
Sun Sep 12 16:35:19 UTC 2021


The branch stable/13 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=cca384d7e546c4ff64214d37b4ad042cf726dcf6

commit cca384d7e546c4ff64214d37b4ad042cf726dcf6
Author:     Warner Losh <imp at FreeBSD.org>
AuthorDate: 2021-07-23 21:21:02 +0000
Commit:     Warner Losh <imp at FreeBSD.org>
CommitDate: 2021-09-12 15:56:14 +0000

    geom_disk: use a preallocated geom_event for disk destruction.
    
    Preallocate a geom_event (using the new geom_alloc_event) when we create
    a disk. When we create the disk, we're going to be in a sleepable
    context, so we can always allocate this extra bit of memory. Then use
    this preallocated memory to free the disk. CAM can try to free the disk
    from an unsleepable context if there was I/O outstanding when the disk
    was destroyted (say because the SIM said it had gone away). The I/O
    context isn't sleepable. Rather than trying to invent a retry mechanism
    and making sure all the other geom_disk consumers did it properly,
    preallocating the event ensure that the geom_disk will be properly torn
    down, even when there's memory pressure when the disk departs.
    
    Reviewd by:             jhb
    Sponsored by:           Netflix
    Differential Revision:  https://reviews.freebsd.org/D30544
    
    (cherry picked from commit 47aeda7b70555049eccd7f020365aec031f41c62)
---
 sys/geom/geom_disk.c | 5 ++++-
 sys/geom/geom_disk.h | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/sys/geom/geom_disk.c b/sys/geom/geom_disk.c
index 3ce203c33a73..2f0e72fad52d 100644
--- a/sys/geom/geom_disk.c
+++ b/sys/geom/geom_disk.c
@@ -885,6 +885,7 @@ disk_create(struct disk *dp, int version)
 		    dp->d_sectorsize, DEVSTAT_ALL_SUPPORTED,
 		    DEVSTAT_TYPE_DIRECT, DEVSTAT_PRIORITY_MAX);
 	dp->d_geom = NULL;
+	dp->d_event = g_alloc_event(M_WAITOK);
 
 	dp->d_init_level = DISK_INIT_NONE;
 
@@ -896,12 +897,14 @@ void
 disk_destroy(struct disk *dp)
 {
 
+	KASSERT(dp->d_event != NULL,
+	    ("Disk destroy for %p with event NULL", dp));
 	disk_gone(dp);
 	dp->d_destroyed = 1;
 	g_cancel_event(dp);
 	if (dp->d_devstat != NULL)
 		devstat_remove_entry(dp->d_devstat);
-	g_post_event(g_disk_destroy, dp, M_WAITOK, NULL);
+	g_post_event_ep(g_disk_destroy, dp, dp->d_event, NULL);
 }
 
 void
diff --git a/sys/geom/geom_disk.h b/sys/geom/geom_disk.h
index 8e2282a09a3a..7dd6e34c9ae2 100644
--- a/sys/geom/geom_disk.h
+++ b/sys/geom/geom_disk.h
@@ -125,6 +125,7 @@ struct disk {
 
 	/* Fields private to geom_disk, to be moved on next version bump */
 	LIST_HEAD(,disk_alias)	d_aliases;
+	void			*d_event;
 };
 
 #define	DISKFLAG_RESERVED		0x0001	/* Was NEEDSGIANT */


More information about the dev-commits-src-all mailing list