Page MenuHomeFreeBSD
Paste P646

disk_alloc_dev
ActivePublic

Authored by jrtc27 on Aug 29 2024, 7:42 PM.
Tags
None
Referenced Files
F92315017: disk_alloc_dev
Aug 29 2024, 7:42 PM
Subscribers
None
diff --git a/share/man/man9/disk.9 b/share/man/man9/disk.9
index 41436427cbc2..14d777e26a31 100644
--- a/share/man/man9/disk.9
+++ b/share/man/man9/disk.9
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
.\" DAMAGE.
.\"
-.Dd April 30, 2020
+.Dd August 29, 2024
.Dt DISK 9
.Os
.Sh NAME
@@ -35,6 +35,8 @@
.In geom/geom_disk.h
.Ft struct disk *
.Fn disk_alloc void
+.Ft struct disk *
+.Fn disk_alloc_dev "device_t adev"
.Ft void
.Fn disk_create "struct disk *disk" "int version"
.Ft void
@@ -65,6 +67,8 @@ GEOM has the ownership of
.Vt "struct disk" ,
and drivers must allocate storage for it with the
.Fn disk_alloc
+or
+.Fn disk_alloc_dev
function,
fill in the fields and call
.Fn disk_create
@@ -230,6 +234,13 @@ the disk.
.It Vt uint16_t Va d_hba_subdevice
This field can be used to store the PCI subdevice ID for the HBA connected to
the disk.
+.It Vt char Va d_attachment[DISK_IDENT_SIZE]
+This field can and should be used to store the device to which this disk is
+attached.
+This field will be initialised by
+.Fn disk_alloc_dev
+using the name of the given device, but should be set manually when using
+.Fn disk_alloc .
.El
.Ss Driver Private Data
This field may be used by the device driver to store a pointer to
diff --git a/sys/dev/aac/aac_disk.c b/sys/dev/aac/aac_disk.c
index b20bbd1e4370..4313de281478 100644
--- a/sys/dev/aac/aac_disk.c
+++ b/sys/dev/aac/aac_disk.c
@@ -398,7 +398,7 @@ aac_disk_attach(device_t dev)
/* attach a generic disk device to ourselves */
sc->unit = device_get_unit(dev);
- sc->ad_disk = disk_alloc();
+ sc->ad_disk = disk_alloc_dev(dev);
sc->ad_disk->d_drv1 = sc;
sc->ad_disk->d_flags = DISKFLAG_UNMAPPED_BIO;
sc->ad_disk->d_name = "aacd";
diff --git a/sys/dev/altera/avgen/altera_avgen.c b/sys/dev/altera/avgen/altera_avgen.c
index 846167c649f8..ab3d4956b7de 100644
--- a/sys/dev/altera/avgen/altera_avgen.c
+++ b/sys/dev/altera/avgen/altera_avgen.c
@@ -491,7 +491,7 @@ altera_avgen_attach(struct altera_avgen_softc *sc, const char *str_fileio,
ALTERA_AVALON_FLAG_GEOM_WRITE)) {
mtx_init(&sc->avg_disk_mtx, "altera_avgen_disk", NULL,
MTX_DEF);
- sc->avg_disk = disk_alloc();
+ sc->avg_disk = disk_alloc_dev(dev);
sc->avg_disk->d_drv1 = sc;
sc->avg_disk->d_strategy = altera_avgen_disk_strategy;
if (devunit == -1)
diff --git a/sys/dev/altera/sdcard/altera_sdcard_disk.c b/sys/dev/altera/sdcard/altera_sdcard_disk.c
index 87fdfb2a6475..c9dfefb8960c 100644
--- a/sys/dev/altera/sdcard/altera_sdcard_disk.c
+++ b/sys/dev/altera/sdcard/altera_sdcard_disk.c
@@ -129,7 +129,7 @@ altera_sdcard_disk_insert(struct altera_sdcard_softc *sc)
* therefore safe to drop the lock here.
*/
ALTERA_SDCARD_UNLOCK(sc);
- disk = disk_alloc();
+ disk = disk_alloc_dev(sc->as_dev);
disk->d_drv1 = sc;
disk->d_name = "altera_sdcard";
disk->d_unit = sc->as_unit;
diff --git a/sys/dev/cfi/cfi_disk.c b/sys/dev/cfi/cfi_disk.c
index 4c3eae473fb6..becb87489dce 100644
--- a/sys/dev/cfi/cfi_disk.c
+++ b/sys/dev/cfi/cfi_disk.c
@@ -92,7 +92,7 @@ cfi_disk_attach(device_t dev)
sc->parent->sc_width != 4)
return EINVAL;
- sc->disk = disk_alloc();
+ sc->disk = disk_alloc_dev(dev);
if (sc->disk == NULL)
return ENOMEM;
sc->disk->d_name = "cfid";
diff --git a/sys/dev/flash/at45d.c b/sys/dev/flash/at45d.c
index bce23f467e2c..6afde3eb0290 100644
--- a/sys/dev/flash/at45d.c
+++ b/sys/dev/flash/at45d.c
@@ -365,7 +365,7 @@ at45d_delayed_attach(void *xsc)
sc->dummybuf = malloc(pagesize, M_DEVBUF, M_WAITOK | M_ZERO);
- sc->disk = disk_alloc();
+ sc->disk = disk_alloc_dev(sc->dev);
sc->disk->d_open = at45d_open;
sc->disk->d_close = at45d_close;
sc->disk->d_strategy = at45d_strategy;
diff --git a/sys/dev/flash/flexspi/flex_spi.c b/sys/dev/flash/flexspi/flex_spi.c
index 766a1cfaa332..a88710f4f6ca 100644
--- a/sys/dev/flash/flexspi/flex_spi.c
+++ b/sys/dev/flash/flexspi/flex_spi.c
@@ -788,7 +788,7 @@ flex_spi_attach(device_t dev)
}
/* Move it to per-flash */
- sc->disk = disk_alloc();
+ sc->disk = disk_alloc_dev(dev);
sc->disk->d_open = flex_spi_open;
sc->disk->d_close = flex_spi_close;
sc->disk->d_strategy = flex_spi_strategy;
diff --git a/sys/dev/flash/mx25l.c b/sys/dev/flash/mx25l.c
index 64e3e53d4291..80b7421a398d 100644
--- a/sys/dev/flash/mx25l.c
+++ b/sys/dev/flash/mx25l.c
@@ -508,7 +508,7 @@ mx25l_attach(device_t dev)
return (err);
}
- sc->sc_disk = disk_alloc();
+ sc->sc_disk = disk_alloc_dev(sc->sc_dev);
sc->sc_disk->d_open = mx25l_open;
sc->sc_disk->d_close = mx25l_close;
sc->sc_disk->d_strategy = mx25l_strategy;
diff --git a/sys/dev/flash/n25q.c b/sys/dev/flash/n25q.c
index 95d005125930..7cb21ab68242 100644
--- a/sys/dev/flash/n25q.c
+++ b/sys/dev/flash/n25q.c
@@ -290,7 +290,7 @@ n25q_attach(device_t dev)
n25q_wait_for_device_ready(sc->dev);
- sc->sc_disk = disk_alloc();
+ sc->sc_disk = disk_alloc_dev(sc->dev);
sc->sc_disk->d_open = n25q_open;
sc->sc_disk->d_close = n25q_close;
sc->sc_disk->d_strategy = n25q_strategy;
diff --git a/sys/dev/ida/ida_disk.c b/sys/dev/ida/ida_disk.c
index 1e3877652f8a..217830c7e72d 100644
--- a/sys/dev/ida/ida_disk.c
+++ b/sys/dev/ida/ida_disk.c
@@ -202,7 +202,7 @@ idad_attach(device_t dev)
drv->secperunit / ((1024 * 1024) / drv->secsize),
drv->secperunit, drv->secsize);
- drv->disk = disk_alloc();
+ drv->disk = disk_alloc_dev(dev);
drv->disk->d_strategy = idad_strategy;
drv->disk->d_name = "idad";
drv->disk->d_dump = idad_dump;
diff --git a/sys/dev/ips/ips_disk.c b/sys/dev/ips/ips_disk.c
index 09ab571d2734..6ae73fda7ebe 100644
--- a/sys/dev/ips/ips_disk.c
+++ b/sys/dev/ips/ips_disk.c
@@ -140,7 +140,7 @@ static int ipsd_attach(device_t dev)
dsc->sc = device_get_softc(adapter);
dsc->unit = device_get_unit(dev);
dsc->disk_number = (uintptr_t) device_get_ivars(dev);
- dsc->ipsd_disk = disk_alloc();
+ dsc->ipsd_disk = disk_alloc_dev(dev);
dsc->ipsd_disk->d_drv1 = dsc;
dsc->ipsd_disk->d_name = "ipsd";
dsc->ipsd_disk->d_maxsize = IPS_MAX_IO_SIZE;
diff --git a/sys/dev/mfi/mfi_disk.c b/sys/dev/mfi/mfi_disk.c
index 29c7bdc79aa1..88b3101361b2 100644
--- a/sys/dev/mfi/mfi_disk.c
+++ b/sys/dev/mfi/mfi_disk.c
@@ -150,7 +150,7 @@ mfi_disk_attach(device_t dev)
ld_info->ld_config.properties.name, state);
}
- sc->ld_disk = disk_alloc();
+ sc->ld_disk = disk_alloc_dev(dev);
sc->ld_disk->d_drv1 = sc;
sc->ld_disk->d_maxsize = min(sc->ld_controller->mfi_max_io * secsize,
(sc->ld_controller->mfi_max_sge - 1) * PAGE_SIZE);
diff --git a/sys/dev/mfi/mfi_syspd.c b/sys/dev/mfi/mfi_syspd.c
index 4353e2598f5c..9694fdfa716a 100644
--- a/sys/dev/mfi/mfi_syspd.c
+++ b/sys/dev/mfi/mfi_syspd.c
@@ -124,7 +124,7 @@ mfi_syspd_attach(device_t dev)
mtx_unlock(&sc->pd_controller->mfi_io_lock);
device_printf(dev, "%juMB (%ju sectors) SYSPD volume (deviceid: %d)\n",
sectors / (1024 * 1024 / secsize), sectors, sc->pd_id);
- sc->pd_disk = disk_alloc();
+ sc->pd_disk = disk_alloc_dev(dev);
sc->pd_disk->d_drv1 = sc;
sc->pd_disk->d_maxsize = min(sc->pd_controller->mfi_max_io * secsize,
(sc->pd_controller->mfi_max_sge - 1) * PAGE_SIZE);
diff --git a/sys/dev/mlx/mlx_disk.c b/sys/dev/mlx/mlx_disk.c
index 3f00dfd92f9c..4e1e8e7f53d6 100644
--- a/sys/dev/mlx/mlx_disk.c
+++ b/sys/dev/mlx/mlx_disk.c
@@ -238,7 +238,7 @@ mlxd_attach(device_t dev)
sc->mlxd_drive->ms_size / ((1024 * 1024) / MLX_BLKSIZE),
sc->mlxd_drive->ms_size, sc->mlxd_drive->ms_raidlevel, state);
- sc->mlxd_disk = disk_alloc();
+ sc->mlxd_disk = disk_alloc_dev(dev);
sc->mlxd_disk->d_open = mlxd_open;
sc->mlxd_disk->d_close = mlxd_close;
sc->mlxd_disk->d_ioctl = mlxd_ioctl;
diff --git a/sys/dev/mmc/mmcsd.c b/sys/dev/mmc/mmcsd.c
index cd973e53802c..b26aba811111 100644
--- a/sys/dev/mmc/mmcsd.c
+++ b/sys/dev/mmc/mmcsd.c
@@ -527,7 +527,7 @@ mmcsd_add_part(struct mmcsd_softc *sc, u_int type, const char *name, u_int cnt,
} else {
MMCSD_DISK_LOCK_INIT(part);
- d = part->disk = disk_alloc();
+ d = part->disk = disk_alloc_dev(dev);
d->d_close = mmcsd_close;
d->d_strategy = mmcsd_strategy;
d->d_ioctl = mmcsd_ioctl_disk;
diff --git a/sys/dev/nvd/nvd.c b/sys/dev/nvd/nvd.c
index 33b43efd24c1..e903e15c16f1 100644
--- a/sys/dev/nvd/nvd.c
+++ b/sys/dev/nvd/nvd.c
@@ -449,7 +449,7 @@ nvd_new_disk(struct nvme_namespace *ns, void *ctrlr_arg)
taskqueue_thread_enqueue, &ndisk->tq);
taskqueue_start_threads(&ndisk->tq, 1, PI_DISK, "nvd taskq");
- disk = ndisk->disk = disk_alloc();
+ disk = ndisk->disk = disk_alloc_dev(dev);
disk->d_strategy = nvd_strategy;
disk->d_ioctl = nvd_ioctl;
disk->d_dump = nvd_dump;
@@ -498,8 +498,6 @@ nvd_new_disk(struct nvme_namespace *ns, void *ctrlr_arg)
disk->d_hba_subvendor = pci_get_subvendor(dev);
disk->d_hba_subdevice = pci_get_subdevice(dev);
disk->d_rotation_rate = DISK_RR_NON_ROTATING;
- strlcpy(disk->d_attachment, device_get_nameunit(dev),
- sizeof(disk->d_attachment));
disk_create(disk, DISK_VERSION);
diff --git a/sys/dev/pst/pst-raid.c b/sys/dev/pst/pst-raid.c
index f1d66f7598ed..b0257358b589 100644
--- a/sys/dev/pst/pst-raid.c
+++ b/sys/dev/pst/pst-raid.c
@@ -152,7 +152,7 @@ pst_attach(device_t dev)
bioq_init(&psc->queue);
- psc->disk = disk_alloc();
+ psc->disk = disk_alloc_dev(dev);
psc->disk->d_name = "pst";
psc->disk->d_strategy = pststrategy;
psc->disk->d_maxsize = 64 * 1024; /*I2O_SGL_MAX_SEGS * PAGE_SIZE;*/
diff --git a/sys/dev/virtio/block/virtio_blk.c b/sys/dev/virtio/block/virtio_blk.c
index 76068c91df11..5329611cfe0d 100644
--- a/sys/dev/virtio/block/virtio_blk.c
+++ b/sys/dev/virtio/block/virtio_blk.c
@@ -742,7 +742,7 @@ vtblk_alloc_disk(struct vtblk_softc *sc, struct virtio_blk_config *blkcfg)
dev = sc->vtblk_dev;
- sc->vtblk_disk = dp = disk_alloc();
+ sc->vtblk_disk = dp = disk_alloc_dev(dev);
dp->d_open = vtblk_open;
dp->d_close = vtblk_close;
dp->d_ioctl = vtblk_ioctl;
@@ -755,8 +755,6 @@ vtblk_alloc_disk(struct vtblk_softc *sc, struct virtio_blk_config *blkcfg)
dp->d_hba_device = virtio_get_device(dev);
dp->d_hba_subvendor = virtio_get_subvendor(dev);
dp->d_hba_subdevice = virtio_get_subdevice(dev);
- strlcpy(dp->d_attachment, device_get_nameunit(dev),
- sizeof(dp->d_attachment));
if (virtio_with_feature(dev, VIRTIO_BLK_F_RO))
dp->d_flags |= DISKFLAG_WRITE_PROTECT;
diff --git a/sys/dev/xen/blkfront/blkfront.c b/sys/dev/xen/blkfront/blkfront.c
index b11972295a4b..5726086d48f9 100644
--- a/sys/dev/xen/blkfront/blkfront.c
+++ b/sys/dev/xen/blkfront/blkfront.c
@@ -1012,7 +1012,7 @@ xbd_instance_create(struct xbd_softc *sc, blkif_sector_t sectors,
features);
}
- sc->xbd_disk = disk_alloc();
+ sc->xbd_disk = disk_alloc_dev(sc->xbd_dev);
sc->xbd_disk->d_unit = sc->xbd_unit;
sc->xbd_disk->d_open = xbd_open;
sc->xbd_disk->d_close = xbd_close;
diff --git a/sys/geom/geom_disk.c b/sys/geom/geom_disk.c
index 6b8c4d32267c..75007bd1f5c3 100644
--- a/sys/geom/geom_disk.c
+++ b/sys/geom/geom_disk.c
@@ -43,6 +43,7 @@
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <sys/bio.h>
+#include <sys/bus.h>
#include <sys/ctype.h>
#include <sys/devctl.h>
#include <sys/fcntl.h>
@@ -881,6 +882,17 @@ disk_alloc(void)
return (dp);
}
+struct disk *
+disk_alloc_dev(device_t adev)
+{
+ struct disk *dp;
+
+ dp = disk_alloc();
+ strlcpy(dp->d_attachment, device_get_nameunit(adev),
+ sizeof(dp->d_attachment));
+ return (dp);
+}
+
void
disk_create(struct disk *dp, int version)
{
diff --git a/sys/geom/geom_disk.h b/sys/geom/geom_disk.h
index afb3f628f84c..9c3a0e21fd95 100644
--- a/sys/geom/geom_disk.h
+++ b/sys/geom/geom_disk.h
@@ -138,6 +138,7 @@ struct disk {
#define DISKFLAG_WRITE_PROTECT 0x0100
struct disk *disk_alloc(void);
+struct disk *disk_alloc_dev(device_t adev);
void disk_create(struct disk *disk, int version);
void disk_destroy(struct disk *disk);
void disk_gone(struct disk *disk);
diff --git a/sys/powerpc/mambo/mambo_disk.c b/sys/powerpc/mambo/mambo_disk.c
index d24652f15885..3499d2618874 100644
--- a/sys/powerpc/mambo/mambo_disk.c
+++ b/sys/powerpc/mambo/mambo_disk.c
@@ -106,7 +106,7 @@ mambodisk_attach(device_t dev)
sc->dev = dev;
MBODISK_LOCK_INIT(sc);
- d = sc->disk = disk_alloc();
+ d = sc->disk = disk_alloc_dev(dev);
d->d_open = mambodisk_open;
d->d_close = mambodisk_close;
d->d_strategy = mambodisk_strategy;
diff --git a/sys/powerpc/powernv/opal_flash.c b/sys/powerpc/powernv/opal_flash.c
index 144de20da5d3..76e3d7fe14eb 100644
--- a/sys/powerpc/powernv/opal_flash.c
+++ b/sys/powerpc/powernv/opal_flash.c
@@ -361,7 +361,7 @@ opalflash_attach(device_t dev)
return (ENXIO);
}
- sc->sc_disk = disk_alloc();
+ sc->sc_disk = disk_alloc_dev(dev);
sc->sc_disk->d_name = "opalflash";
sc->sc_disk->d_open = opalflash_open;
sc->sc_disk->d_close = opalflash_close;
diff --git a/sys/powerpc/ps3/ps3disk.c b/sys/powerpc/ps3/ps3disk.c
index 0931e6aad58b..5bab8f7663cc 100644
--- a/sys/powerpc/ps3/ps3disk.c
+++ b/sys/powerpc/ps3/ps3disk.c
@@ -233,7 +233,7 @@ ps3disk_attach(device_t dev)
for (i = 0; i < sc->sc_nregs; i++) {
struct ps3disk_region *rp = &sc->sc_reg[i];
- d = sc->sc_disk[i] = disk_alloc();
+ d = sc->sc_disk[i] = disk_alloc_dev(dev);
d->d_open = ps3disk_open;
d->d_close = ps3disk_close;
d->d_strategy = ps3disk_strategy;