git: 47aeda7b7055 - main - geom_disk: use a preallocated geom_event for disk destruction.

Warner Losh imp at FreeBSD.org
Sat Jul 24 00:09:12 UTC 2021


The branch main has been updated by imp:

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

commit 47aeda7b70555049eccd7f020365aec031f41c62
Author:     Warner Losh <imp at FreeBSD.org>
AuthorDate: 2021-07-23 21:21:02 +0000
Commit:     Warner Losh <imp at FreeBSD.org>
CommitDate: 2021-07-24 00:08:52 +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
---
 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 fb215fb3dab5..83d570f7e445 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