Index: share/man/man9/disk.9 =================================================================== --- share/man/man9/disk.9 +++ share/man/man9/disk.9 @@ -37,6 +37,8 @@ .In geom/geom_disk.h .Ft struct disk * .Fn disk_alloc void +.Ft struct disk * +.Fn disk_alloc_nowait void .Ft void .Fn disk_create "struct disk *disk" "int version" .Ft void @@ -67,12 +69,16 @@ .Pp GEOM has the ownership of .Vt "struct disk" , -and drivers must allocate storage for it with the +and drivers must allocate storage for it with one of the .Fn disk_alloc -function, +or +.Fn disk_alloc_nowait +functions, fill in the fields and call .Fn disk_create when the device is ready to service requests. +.Fn disk_alloc_nowait +must be used from contexts that cannot sleep. .Fn disk_free frees uninitialized disks from .Fn disk_alloc Index: sys/geom/geom_disk.h =================================================================== --- sys/geom/geom_disk.h +++ sys/geom/geom_disk.h @@ -137,6 +137,7 @@ #define DISKFLAG_WRITE_PROTECT 0x0100 struct disk *disk_alloc(void); +struct disk *disk_alloc_nowait(void); void disk_create(struct disk *disk, int version); void disk_destroy(struct disk *disk); void disk_free(struct disk *disk); Index: sys/geom/geom_disk.c =================================================================== --- sys/geom/geom_disk.c +++ sys/geom/geom_disk.c @@ -862,16 +862,30 @@ strlcpy(ident, newid, size); } -struct disk * -disk_alloc(void) +static struct disk * +disk_alloc_flags(int flags) { struct disk *dp; - dp = g_malloc(sizeof(struct disk), M_WAITOK | M_ZERO); + dp = g_malloc(sizeof(struct disk), flags | M_ZERO); + if (dp == NULL) + return (NULL); LIST_INIT(&dp->d_aliases); return (dp); } +struct disk * +disk_alloc(void) +{ + return (disk_alloc_flags(M_WAITOK)); +} + +struct disk * +disk_alloc_nowait(void) +{ + return (disk_alloc_flags(M_NOWAIT)); +} + void disk_create(struct disk *dp, int version) {