From owner-svn-src-head@freebsd.org Sat Jul 1 21:34:58 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D8377D933C0; Sat, 1 Jul 2017 21:34:58 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AE9AA73834; Sat, 1 Jul 2017 21:34:58 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v61LYv5K026066; Sat, 1 Jul 2017 21:34:57 GMT (envelope-from allanjude@FreeBSD.org) Received: (from allanjude@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v61LYvFc026064; Sat, 1 Jul 2017 21:34:57 GMT (envelope-from allanjude@FreeBSD.org) Message-Id: <201707012134.v61LYvFc026064@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: allanjude set sender to allanjude@FreeBSD.org using -f From: Allan Jude Date: Sat, 1 Jul 2017 21:34:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r320555 - head/usr.sbin/diskinfo X-SVN-Group: head X-SVN-Commit-Author: allanjude X-SVN-Commit-Paths: head/usr.sbin/diskinfo X-SVN-Commit-Revision: 320555 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Jul 2017 21:34:59 -0000 Author: allanjude Date: Sat Jul 1 21:34:57 2017 New Revision: 320555 URL: https://svnweb.freebsd.org/changeset/base/320555 Log: Add -s (serial) and -p (physpath) to diskinfo Return the bare requested information, intended for scripting. The serial number of a SAS/SCSI device can be returned with 'camcontrol inquiry disk -S', but there is no similar switch for SATA. This provides a way to get this information from both SAS and SATA disks the -s and -p flags are mutually exclusive, and cannot be used with any other flags. Reviewed by: rpokala, wblock MFC after: 1 month Sponsored by: ScaleEngine Inc. Differential Revision: https://reviews.freebsd.org/D7828 Modified: head/usr.sbin/diskinfo/diskinfo.8 head/usr.sbin/diskinfo/diskinfo.c Modified: head/usr.sbin/diskinfo/diskinfo.8 ============================================================================== --- head/usr.sbin/diskinfo/diskinfo.8 Sat Jul 1 21:18:06 2017 (r320554) +++ head/usr.sbin/diskinfo/diskinfo.8 Sat Jul 1 21:34:57 2017 (r320555) @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 22, 2016 +.Dd July 1, 2017 .Dt DISKINFO 8 .Os .Sh NAME @@ -38,6 +38,12 @@ .Nm .Op Fl citv .Ar disk ... +.Nm +.Op Fl p +.Ar disk ... +.Nm +.Op Fl s +.Ar disk ... .Sh DESCRIPTION The .Nm @@ -52,6 +58,12 @@ Print fields one per line with a descriptive comment. Perform a simple measurement of the I/O read command overhead. .It Fl i Perform a simple IOPS benchmark. +.It Fl p +Return the physical path of the disk. +This is a string that identifies the physical path to the disk in the +storage enclsoure. +.It Fl s +Return the disk serial number .It Fl t Perform a simple and rather naive benchmark of the disks seek and transfer performance. @@ -62,6 +74,13 @@ with the following fields: device name, sectorsize, me media size in sectors, stripe size, stripe offset, firmware cylinders, firmware heads, and firmware sectors. The last three fields are only present if the information is available. +.It Fl i +Return the disk ident, usually the serial number. +.It Fl p +Return the physical path of the disk. +This is a string that identifies the physical path to the disk in the +storage enclsoure. +.El .Sh HISTORY The .Nm Modified: head/usr.sbin/diskinfo/diskinfo.c ============================================================================== --- head/usr.sbin/diskinfo/diskinfo.c Sat Jul 1 21:18:06 2017 (r320554) +++ head/usr.sbin/diskinfo/diskinfo.c Sat Jul 1 21:34:57 2017 (r320555) @@ -55,7 +55,7 @@ usage(void) exit (1); } -static int opt_c, opt_i, opt_t, opt_v; +static int opt_c, opt_i, opt_p, opt_s, opt_t, opt_v; static void speeddisk(int fd, off_t mediasize, u_int sectorsize); static void commandtime(int fd, off_t mediasize, u_int sectorsize); @@ -74,7 +74,7 @@ main(int argc, char **argv) u_int sectorsize, fwsectors, fwheads, zoned = 0; uint32_t zone_mode; - while ((ch = getopt(argc, argv, "citv")) != -1) { + while ((ch = getopt(argc, argv, "cipstv")) != -1) { switch (ch) { case 'c': opt_c = 1; @@ -84,6 +84,12 @@ main(int argc, char **argv) opt_i = 1; opt_v = 1; break; + case 'p': + opt_p = 1; + break; + case 's': + opt_s = 1; + break; case 't': opt_t = 1; opt_v = 1; @@ -101,6 +107,11 @@ main(int argc, char **argv) if (argc < 1) usage(); + if ((opt_p && opt_s) || ((opt_p || opt_s) && (opt_c || opt_i || opt_t || opt_v))) { + warnx("-p or -s cannot be used with other options"); + usage(); + } + for (i = 0; i < argc; i++) { fd = open(argv[i], O_RDONLY | O_DIRECT); if (fd < 0 && errno == ENOENT && *argv[i] != '/') { @@ -124,7 +135,27 @@ main(int argc, char **argv) fwheads = 0; stripesize = sb.st_blksize; stripeoffset = 0; + if (opt_p || opt_s) { + warnx("-p and -s only operate on physical devices: %s", argv[i]); + goto out; + } } else { + if (opt_p) { + if (ioctl(fd, DIOCGPHYSPATH, physpath) == 0) { + printf("%s\n", physpath); + } else { + warnx("Failed to determine physpath for: %s", argv[i]); + } + goto out; + } + if (opt_s) { + if (ioctl(fd, DIOCGIDENT, ident) == 0) { + printf("%s\n", ident); + } else { + warnx("Failed to determine serial number for: %s", argv[i]); + } + goto out; + } error = ioctl(fd, DIOCGMEDIASIZE, &mediasize); if (error) { warnx("%s: ioctl(DIOCGMEDIASIZE) failed, probably not a disk.", argv[i]);