aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Tomasz Napierala <trasz@FreeBSD.org>2019-11-09 17:30:19 +0000
committerEdward Tomasz Napierala <trasz@FreeBSD.org>2019-11-09 17:30:19 +0000
commitb5961be1ab74b2824ba79d511562aec5c81fe62b (patch)
treef0bd23d1cfd0e71eb7b9722227df69a6eb73748b
parent461587dc9b17d940a754f0feb015812600909984 (diff)
downloadsrc-b5961be1ab7.tar.gz
src-b5961be1ab7.zip
Add GEOM attribute to report physical device name, and report it
via 'diskinfo -v'. This avoids the need to track it down via CAM, and should also work for disks that don't use CAM. And since it's inherited thru the GEOM hierarchy, in most cases one doesn't need to walk the GEOM graph either, eg you can use it on a partition instead of disk itself. Reviewed by: allanjude, imp Sponsored by: Klara Inc Differential Revision: https://reviews.freebsd.org/D22249
Notes
Notes: svn path=/head/; revision=354571
-rw-r--r--sys/cam/ata/ata_da.c2
-rw-r--r--sys/cam/mmc/mmc_da.c2
-rw-r--r--sys/cam/nvme/nvme_da.c2
-rw-r--r--sys/cam/scsi/scsi_cd.c2
-rw-r--r--sys/cam/scsi/scsi_da.c2
-rw-r--r--sys/geom/geom_disk.c5
-rw-r--r--sys/geom/geom_disk.h1
-rw-r--r--usr.sbin/diskinfo/diskinfo.c4
8 files changed, 19 insertions, 1 deletions
diff --git a/sys/cam/ata/ata_da.c b/sys/cam/ata/ata_da.c
index 33f2c7319fbf..5077b7791426 100644
--- a/sys/cam/ata/ata_da.c
+++ b/sys/cam/ata/ata_da.c
@@ -3420,6 +3420,8 @@ adasetgeom(struct ada_softc *softc, struct ccb_getdev *cgd)
softc->disk->d_fwheads = softc->params.heads;
ata_disk_firmware_geom_adjust(softc->disk);
softc->disk->d_rotation_rate = cgd->ident_data.media_rotation_rate;
+ snprintf(softc->disk->d_attachment, sizeof(softc->disk->d_attachment),
+ "%s%d", softc->cpi.dev_name, softc->cpi.unit_number);
}
static void
diff --git a/sys/cam/mmc/mmc_da.c b/sys/cam/mmc/mmc_da.c
index 18cfcd290efb..d0a3b35c0b45 100644
--- a/sys/cam/mmc/mmc_da.c
+++ b/sys/cam/mmc/mmc_da.c
@@ -1532,6 +1532,8 @@ sdda_add_part(struct cam_periph *periph, u_int type, const char *name,
part->disk->d_hba_device = cpi.hba_device;
part->disk->d_hba_subvendor = cpi.hba_subvendor;
part->disk->d_hba_subdevice = cpi.hba_subdevice;
+ snprintf(part->disk->d_attachment, sizeof(part->disk->d_attachment),
+ "%s%d", cpi.dev_name, cpi.unit_number);
part->disk->d_sectorsize = mmc_get_sector_size(periph);
part->disk->d_mediasize = media_size;
diff --git a/sys/cam/nvme/nvme_da.c b/sys/cam/nvme/nvme_da.c
index 4988dbb5e1e3..b17983eff541 100644
--- a/sys/cam/nvme/nvme_da.c
+++ b/sys/cam/nvme/nvme_da.c
@@ -815,6 +815,8 @@ ndaregister(struct cam_periph *periph, void *arg)
disk->d_hba_device = cpi.hba_device;
disk->d_hba_subvendor = cpi.hba_subvendor;
disk->d_hba_subdevice = cpi.hba_subdevice;
+ snprintf(disk->d_attachment, sizeof(disk->d_attachment),
+ "%s%d", cpi.dev_name, cpi.unit_number);
disk->d_stripesize = disk->d_sectorsize;
disk->d_stripeoffset = 0;
disk->d_devstat = devstat_new_entry(periph->periph_name,
diff --git a/sys/cam/scsi/scsi_cd.c b/sys/cam/scsi/scsi_cd.c
index e3ec731102af..33f3743899ab 100644
--- a/sys/cam/scsi/scsi_cd.c
+++ b/sys/cam/scsi/scsi_cd.c
@@ -702,6 +702,8 @@ cdregister(struct cam_periph *periph, void *arg)
softc->disk->d_hba_device = cpi.hba_device;
softc->disk->d_hba_subvendor = cpi.hba_subvendor;
softc->disk->d_hba_subdevice = cpi.hba_subdevice;
+ snprintf(softc->disk->d_attachment, sizeof(softc->disk->d_attachment),
+ "%s%d", cpi.dev_name, cpi.unit_number);
/*
* Acquire a reference to the periph before we register with GEOM.
diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c
index 451af7a398f7..a36ab2d65255 100644
--- a/sys/cam/scsi/scsi_da.c
+++ b/sys/cam/scsi/scsi_da.c
@@ -2875,6 +2875,8 @@ daregister(struct cam_periph *periph, void *arg)
softc->disk->d_hba_device = cpi.hba_device;
softc->disk->d_hba_subvendor = cpi.hba_subvendor;
softc->disk->d_hba_subdevice = cpi.hba_subdevice;
+ snprintf(softc->disk->d_attachment, sizeof(softc->disk->d_attachment),
+ "%s%d", cpi.dev_name, cpi.unit_number);
/*
* Acquire a reference to the periph before we register with GEOM.
diff --git a/sys/geom/geom_disk.c b/sys/geom/geom_disk.c
index b13f007553ef..00bc98a656e4 100644
--- a/sys/geom/geom_disk.c
+++ b/sys/geom/geom_disk.c
@@ -528,7 +528,10 @@ g_disk_start(struct bio *bp)
else if (g_handleattr_uint16_t(bp, "GEOM::rotation_rate",
dp->d_rotation_rate))
break;
- else
+ else if (g_handleattr_str(bp, "GEOM::attachment",
+ dp->d_attachment))
+ break;
+ else
error = ENOIOCTL;
break;
case BIO_FLUSH:
diff --git a/sys/geom/geom_disk.h b/sys/geom/geom_disk.h
index fe5831a061c7..8e2282a09a3a 100644
--- a/sys/geom/geom_disk.h
+++ b/sys/geom/geom_disk.h
@@ -118,6 +118,7 @@ struct disk {
uint16_t d_hba_subvendor;
uint16_t d_hba_subdevice;
uint16_t d_rotation_rate;
+ char d_attachment[DISK_IDENT_SIZE];
/* Fields private to the driver */
void *d_drv1;
diff --git a/usr.sbin/diskinfo/diskinfo.c b/usr.sbin/diskinfo/diskinfo.c
index 56912afa844b..2f0ceb4ebd04 100644
--- a/usr.sbin/diskinfo/diskinfo.c
+++ b/usr.sbin/diskinfo/diskinfo.c
@@ -251,6 +251,10 @@ main(int argc, char **argv)
printf("\t%-12s\t# Disk descr.\n", arg.value.str);
if (ioctl(fd, DIOCGIDENT, ident) == 0)
printf("\t%-12s\t# Disk ident.\n", ident);
+ strlcpy(arg.name, "GEOM::attachment", sizeof(arg.name));
+ arg.len = sizeof(arg.value.str);
+ if (ioctl(fd, DIOCGATTR, &arg) == 0)
+ printf("\t%-12s\t# Attachment\n", arg.value.str);
if (ioctl(fd, DIOCGPHYSPATH, physpath) == 0)
printf("\t%-12s\t# Physical path\n", physpath);
printf("\t%-12s\t# TRIM/UNMAP support\n",