Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Nov 2019 17:30:20 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r354571 - in head: sys/cam/ata sys/cam/mmc sys/cam/nvme sys/cam/scsi sys/geom usr.sbin/diskinfo
Message-ID:  <201911091730.xA9HUKGn091881@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Sat Nov  9 17:30:19 2019
New Revision: 354571
URL: https://svnweb.freebsd.org/changeset/base/354571

Log:
  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

Modified:
  head/sys/cam/ata/ata_da.c
  head/sys/cam/mmc/mmc_da.c
  head/sys/cam/nvme/nvme_da.c
  head/sys/cam/scsi/scsi_cd.c
  head/sys/cam/scsi/scsi_da.c
  head/sys/geom/geom_disk.c
  head/sys/geom/geom_disk.h
  head/usr.sbin/diskinfo/diskinfo.c

Modified: head/sys/cam/ata/ata_da.c
==============================================================================
--- head/sys/cam/ata/ata_da.c	Sat Nov  9 17:08:27 2019	(r354570)
+++ head/sys/cam/ata/ata_da.c	Sat Nov  9 17:30:19 2019	(r354571)
@@ -3420,6 +3420,8 @@ adasetgeom(struct ada_softc *softc, struct ccb_getdev 
 	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

Modified: head/sys/cam/mmc/mmc_da.c
==============================================================================
--- head/sys/cam/mmc/mmc_da.c	Sat Nov  9 17:08:27 2019	(r354570)
+++ head/sys/cam/mmc/mmc_da.c	Sat Nov  9 17:30:19 2019	(r354571)
@@ -1532,6 +1532,8 @@ sdda_add_part(struct cam_periph *periph, u_int type, c
 	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;

Modified: head/sys/cam/nvme/nvme_da.c
==============================================================================
--- head/sys/cam/nvme/nvme_da.c	Sat Nov  9 17:08:27 2019	(r354570)
+++ head/sys/cam/nvme/nvme_da.c	Sat Nov  9 17:30:19 2019	(r354571)
@@ -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,

Modified: head/sys/cam/scsi/scsi_cd.c
==============================================================================
--- head/sys/cam/scsi/scsi_cd.c	Sat Nov  9 17:08:27 2019	(r354570)
+++ head/sys/cam/scsi/scsi_cd.c	Sat Nov  9 17:30:19 2019	(r354571)
@@ -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.

Modified: head/sys/cam/scsi/scsi_da.c
==============================================================================
--- head/sys/cam/scsi/scsi_da.c	Sat Nov  9 17:08:27 2019	(r354570)
+++ head/sys/cam/scsi/scsi_da.c	Sat Nov  9 17:30:19 2019	(r354571)
@@ -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.

Modified: head/sys/geom/geom_disk.c
==============================================================================
--- head/sys/geom/geom_disk.c	Sat Nov  9 17:08:27 2019	(r354570)
+++ head/sys/geom/geom_disk.c	Sat Nov  9 17:30:19 2019	(r354571)
@@ -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:

Modified: head/sys/geom/geom_disk.h
==============================================================================
--- head/sys/geom/geom_disk.h	Sat Nov  9 17:08:27 2019	(r354570)
+++ head/sys/geom/geom_disk.h	Sat Nov  9 17:30:19 2019	(r354571)
@@ -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;

Modified: head/usr.sbin/diskinfo/diskinfo.c
==============================================================================
--- head/usr.sbin/diskinfo/diskinfo.c	Sat Nov  9 17:08:27 2019	(r354570)
+++ head/usr.sbin/diskinfo/diskinfo.c	Sat Nov  9 17:30:19 2019	(r354571)
@@ -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",



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201911091730.xA9HUKGn091881>