From owner-svn-src-stable@freebsd.org Wed Oct 25 22:25:34 2017 Return-Path: Delivered-To: svn-src-stable@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 74F98E55999; Wed, 25 Oct 2017 22:25:34 +0000 (UTC) (envelope-from asomers@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 48BCE848F5; Wed, 25 Oct 2017 22:25:34 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v9PMPX0h096044; Wed, 25 Oct 2017 22:25:33 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v9PMPX1V096039; Wed, 25 Oct 2017 22:25:33 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201710252225.v9PMPX1V096039@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Wed, 25 Oct 2017 22:25:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r325003 - in stable/11: sys/geom sys/sys usr.sbin/diskinfo X-SVN-Group: stable-11 X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: in stable/11: sys/geom sys/sys usr.sbin/diskinfo X-SVN-Commit-Revision: 325003 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Oct 2017 22:25:34 -0000 Author: asomers Date: Wed Oct 25 22:25:32 2017 New Revision: 325003 URL: https://svnweb.freebsd.org/changeset/base/325003 Log: MFC r324281: Display rotation rate and TRIM/UNMAP support in diskinfo(8) Bump __FreeBSD_version due to the expansion of struct diocgattr_arg. Reviewed by: mav, allanjude, imp Relnotes: yes Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D12578 Modified: stable/11/sys/geom/geom_disk.h stable/11/sys/sys/disk.h stable/11/sys/sys/param.h stable/11/usr.sbin/diskinfo/diskinfo.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/geom/geom_disk.h ============================================================================== --- stable/11/sys/geom/geom_disk.h Wed Oct 25 21:46:39 2017 (r325002) +++ stable/11/sys/geom/geom_disk.h Wed Oct 25 22:25:32 2017 (r325003) @@ -37,6 +37,11 @@ #ifndef _GEOM_GEOM_DISK_H_ #define _GEOM_GEOM_DISK_H_ +#define DISK_RR_UNKNOWN 0 +#define DISK_RR_NON_ROTATING 1 +#define DISK_RR_MIN 0x0401 +#define DISK_RR_MAX 0xfffe + #ifdef _KERNEL #include @@ -118,11 +123,6 @@ struct disk { #define DISKFLAG_UNMAPPED_BIO 0x10 #define DISKFLAG_DIRECT_COMPLETION 0x20 #define DISKFLAG_CANZONE 0x80 - -#define DISK_RR_UNKNOWN 0 -#define DISK_RR_NON_ROTATING 1 -#define DISK_RR_MIN 0x0401 -#define DISK_RR_MAX 0xfffe struct disk *disk_alloc(void); void disk_create(struct disk *disk, int version); Modified: stable/11/sys/sys/disk.h ============================================================================== --- stable/11/sys/sys/disk.h Wed Oct 25 21:46:39 2017 (r325002) +++ stable/11/sys/sys/disk.h Wed Oct 25 22:25:32 2017 (r325003) @@ -133,6 +133,7 @@ struct diocgattr_arg { char str[DISK_IDENT_SIZE]; off_t off; int i; + uint16_t u16; } value; }; #define DIOCGATTR _IOWR('d', 142, struct diocgattr_arg) Modified: stable/11/sys/sys/param.h ============================================================================== --- stable/11/sys/sys/param.h Wed Oct 25 21:46:39 2017 (r325002) +++ stable/11/sys/sys/param.h Wed Oct 25 22:25:32 2017 (r325003) @@ -58,7 +58,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 1101505 /* Master, propagated to newvers */ +#define __FreeBSD_version 1101506 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD, Modified: stable/11/usr.sbin/diskinfo/diskinfo.c ============================================================================== --- stable/11/usr.sbin/diskinfo/diskinfo.c Wed Oct 25 21:46:39 2017 (r325002) +++ stable/11/usr.sbin/diskinfo/diskinfo.c Wed Oct 25 22:25:32 2017 (r325003) @@ -31,6 +31,7 @@ * $FreeBSD$ */ +#include #include #include #include @@ -42,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -62,9 +64,11 @@ usage(void) static int opt_c, opt_i, opt_p, opt_s, opt_S, opt_t, opt_v, opt_w; +static bool candelete(int fd); static void speeddisk(int fd, off_t mediasize, u_int sectorsize); static void commandtime(int fd, off_t mediasize, u_int sectorsize); static void iopsbench(int fd, off_t mediasize, u_int sectorsize); +static void rotationrate(int fd, char *buf, size_t buflen); static void slogbench(int fd, int isreg, off_t mediasize, u_int sectorsize); static int zonecheck(int fd, uint32_t *zone_mode, char *zone_str, size_t zone_str_len); @@ -78,6 +82,7 @@ main(int argc, char **argv) int i, ch, fd, error, exitval = 0; char tstr[BUFSIZ], ident[DISK_IDENT_SIZE], physpath[MAXPATHLEN]; char zone_desc[64]; + char rrate[64]; struct diocgattr_arg arg; off_t mediasize, stripesize, stripeoffset; u_int sectorsize, fwsectors, fwheads, zoned = 0, isreg; @@ -246,6 +251,10 @@ main(int argc, char **argv) printf("\t%-12s\t# Disk ident.\n", ident); if (ioctl(fd, DIOCGPHYSPATH, physpath) == 0) printf("\t%-12s\t# Physical path\n", physpath); + printf("\t%-12s\t# TRIM/UNMAP support\n", + candelete(fd) ? "Yes" : "No"); + rotationrate(fd, rrate, sizeof(rrate)); + printf("\t%-12s\t# Rotation rate in RPM\n", rrate); if (zoned != 0) printf("\t%-12s\t# Zone Mode\n", zone_desc); } @@ -263,6 +272,39 @@ out: } free(buf); exit (exitval); +} + +static bool +candelete(int fd) +{ + struct diocgattr_arg arg; + + strlcpy(arg.name, "GEOM::candelete", sizeof(arg.name)); + arg.len = sizeof(arg.value.i); + if (ioctl(fd, DIOCGATTR, &arg) == 0) + return (arg.value.i != 0); + else + return (false); +} + +static void +rotationrate(int fd, char *rate, size_t buflen) +{ + struct diocgattr_arg arg; + int ret; + + strlcpy(arg.name, "GEOM::rotation_rate", sizeof(arg.name)); + arg.len = sizeof(arg.value.u16); + + ret = ioctl(fd, DIOCGATTR, &arg); + if (ret < 0 || arg.value.u16 == DISK_RR_UNKNOWN) + snprintf(rate, buflen, "Unknown"); + else if (arg.value.u16 == DISK_RR_NON_ROTATING) + snprintf(rate, buflen, "%d", 0); + else if (arg.value.u16 >= DISK_RR_MIN && arg.value.u16 <= DISK_RR_MAX) + snprintf(rate, buflen, "%d", arg.value.u16); + else + snprintf(rate, buflen, "Invalid"); } static void