From patchwork Wed May 4 15:16:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Martin K. Petersen" X-Patchwork-Id: 754082 Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p44FIX50010718 for ; Wed, 4 May 2011 15:18:54 GMT Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p44FGkIF019143; Wed, 4 May 2011 11:16:46 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p44FGZZc026477; Wed, 4 May 2011 11:16:35 -0400 Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.16]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p44FGTmJ005007; Wed, 4 May 2011 11:16:30 -0400 Received: from rcsinet10.oracle.com (rcsinet10.oracle.com [148.87.113.121]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p44FGNZC005724; Wed, 4 May 2011 11:16:26 -0400 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id p44FGFh1010518 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 4 May 2011 15:16:17 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p44FGEox024490 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 4 May 2011 15:16:15 GMT Received: from abhmt015.oracle.com (abhmt015.oracle.com [141.146.116.24]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p44FG9Yv031318; Wed, 4 May 2011 10:16:09 -0500 Received: from groovelator.mkp.net (/209.217.122.111) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 04 May 2011 08:16:07 -0700 To: Lukas Czerner , Karel Zak From: "Martin K. Petersen" Organization: Oracle References: <20110413224025.GA18589@redhat.com> <20110413234854.GA19793@redhat.com> <20110426173213.GA19604@redhat.com> <20110428001912.GA14659@redhat.com> <20110428075355.GA2190@infradead.org> <20110428205935.GA24979@redhat.com> <20110429122454.GL32370@agk-dp.fab.redhat.com> <20110502081308.GC8642@agk-dp.fab.redhat.com> <20110502081925.GA11312@infradead.org> Date: Wed, 04 May 2011 11:16:05 -0400 In-Reply-To: (Lukas Czerner's message of "Tue, 3 May 2011 10:57:19 +0200 (CEST)") Message-ID: User-Agent: Gnus/5.110013 (No Gnus v0.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 X-Source-IP: acsinet21.oracle.com [141.146.126.237] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090202.4DC16DC2.00BD:SCFMA922111,ss=1,fgs=0 X-RedHat-Spam-Score: -102.309 (RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY, USER_IN_WHITELIST) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.16 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id p44FGZZc026477 Cc: sandeen@redhat.com, "Martin K. Petersen" , Mike Snitzer , Christoph Hellwig , device-mapper development , DarkNovaNick@gmail.com, linux-lvm@redhat.com, linux-ext4@vger.kernel.org, Alasdair G Kergon Subject: Re: [dm-devel] do not disable ext4 discards on first discard failure? [was: Re: dm snapshot: ignore discards issued to the snapshot-origin target] X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 04 May 2011 15:18:54 +0000 (UTC) X-MIME-Autoconverted: from base64 to 8bit by demeter2.kernel.org id p44FIX50010718 >>>>> "Lukas" == Lukas Czerner writes: I got tired of poking around in sysfs to find the discard topology. Here's a patch against lsblk that adds a -D option to present this information in a human-readable form: # lsblk -D NAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO sda 0 0B 0B 0 ??sda1 0 0B 0B 0 sdb 0 512B 2G 1 ??sdb1 0 512B 2G 1 Signed-off-by: Martin K. Petersen --- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel diff --git a/misc-utils/lsblk.8 b/misc-utils/lsblk.8 index 38ff48f..d7d7aa8 100644 --- a/misc-utils/lsblk.8 +++ b/misc-utils/lsblk.8 @@ -29,6 +29,8 @@ Print the SIZE column in bytes rather than in human-readable format. .IP "\fB\-d, \-\-nodeps\fP" Don't print device holders or slaves. For example "lsblk --nodeps /dev/sda" prints information about the sda device only. +.IP "\fB\-D, \-\-discard\fP" +Print information about the discard (TRIM, UNMAP) capabilities for each device. .IP "\fB\-e, \-\-exclude \fIlist\fP Exclude the devices specified by a comma-separated \fIlist\fR of major device numbers. Note that RAM disks (major=1) are excluded by default. diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 38326d0..671e690 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -77,6 +77,10 @@ enum { COL_ROTA, COL_SCHED, COL_TYPE, + COL_DALIGN, + COL_DGRAN, + COL_DMAX, + COL_DZERO, __NCOLUMNS }; @@ -112,8 +116,11 @@ static struct colinfo infos[__NCOLUMNS] = { [COL_PHYSEC] = { "PHY-SEC", 7, TT_FL_RIGHT, N_("physical sector size") }, [COL_LOGSEC] = { "LOG-SEC", 7, TT_FL_RIGHT, N_("logical sector size") }, [COL_SCHED] = { "SCHED", 0.1, 0, N_("I/O scheduler name") }, - [COL_TYPE] = { "TYPE", 4, 0, N_("device type") } - + [COL_TYPE] = { "TYPE", 4, 0, N_("device type") }, + [COL_DALIGN] = { "DISC-ALN", 6, TT_FL_RIGHT, N_("discard alignment offset") }, + [COL_DGRAN] = { "DISC-GRAN", 6, TT_FL_RIGHT, N_("discard granularity") }, + [COL_DMAX] = { "DISC-MAX", 6, TT_FL_RIGHT, N_("discard max bytes") }, + [COL_DZERO] = { "DISC-ZERO", 1, TT_FL_RIGHT, N_("discard zeroes data") }, }; struct lsblk { @@ -702,6 +709,33 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line if (p) tt_line_set_data(ln, col, p); break; + case COL_DALIGN: + p = sysfs_strdup(cxt, "discard_alignment"); + if (p) + tt_line_set_data(ln, col, p); + break; + case COL_DGRAN: + p = sysfs_strdup(cxt, "queue/discard_granularity"); + if (!lsblk->bytes) + p = size_to_human_string(atoi(p)); + + if (p) + tt_line_set_data(ln, col, p); + break; + case COL_DMAX: + p = sysfs_strdup(cxt, "queue/discard_max_bytes"); + + if (!lsblk->bytes) + p = size_to_human_string(atoi(p)); + + if (p) + tt_line_set_data(ln, col, p); + break; + case COL_DZERO: + p = sysfs_strdup(cxt, "queue/discard_zeroes_data"); + if (p) + tt_line_set_data(ln, col, p); + break; }; } @@ -930,6 +964,7 @@ static void __attribute__((__noreturn__)) help(FILE *out) " -a, --all print all devices\n" " -b, --bytes print SIZE in bytes rather than in human readable format\n" " -d, --nodeps don't print slaves or holders\n" + " -D, --discard print discard capabilities\n" " -e, --exclude exclude devices by major number (default: RAM disks)\n" " -f, --fs output info about filesystems\n" " -h, --help usage information (this)\n" @@ -967,6 +1002,7 @@ int main(int argc, char *argv[]) { "all", 0, 0, 'a' }, { "bytes", 0, 0, 'b' }, { "nodeps", 0, 0, 'd' }, + { "discard", 0, 0, 'D' }, { "help", 0, 0, 'h' }, { "output", 1, 0, 'o' }, { "perms", 0, 0, 'm' }, @@ -987,7 +1023,7 @@ int main(int argc, char *argv[]) lsblk = &_ls; memset(lsblk, 0, sizeof(*lsblk)); - while((c = getopt_long(argc, argv, "abde:fhlnmo:irt", longopts, NULL)) != -1) { + while((c = getopt_long(argc, argv, "abdDe:fhlnmo:irt", longopts, NULL)) != -1) { switch(c) { case 'a': lsblk->all_devices = 1; @@ -998,6 +1034,13 @@ int main(int argc, char *argv[]) case 'd': lsblk->nodeps = 1; break; + case 'D': + columns[ncolumns++] = COL_NAME; + columns[ncolumns++] = COL_DALIGN; + columns[ncolumns++] = COL_DGRAN; + columns[ncolumns++] = COL_DMAX; + columns[ncolumns++] = COL_DZERO; + break; case 'e': parse_excludes(optarg); break;