blkid: add -i option to print I/O limits

blkid -i /dev/sdb /dev/sda
/dev/sdb: MINIMUM_IO_SIZE="512" OPTIMAL_IO_SIZE="32768" PHYSICAL_SECTOR_SIZE="512" LOGICAL_SECTOR_SIZE="512"
/dev/sda: MINIMUM_IO_SIZE="512" PHYSICAL_SECTOR_SIZE="512" LOGICAL_SECTOR_SIZE="512"

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2010-05-13 22:26:27 +02:00
parent 25636f8263
commit 0979291016
2 changed files with 93 additions and 38 deletions

View File

@ -50,6 +50,18 @@ blkid \- command\-line utility to locate/print block device attributes
.IR list ] .IR list ]
.I device .I device
[\fIdevice\fR ...] [\fIdevice\fR ...]
.in -9
.B blkid
.RB -i
.RB [ \-s
.IR tag ]
.RB [ \-o
.IR format ]
.RB [ \-s
.IR tag ]
.I device
[\fIdevice\fR ...]
.SH DESCRIPTION .SH DESCRIPTION
The The
@ -85,6 +97,10 @@ devices which no longer exist.
.B \-h .B \-h
Display a usage message and exit. Display a usage message and exit.
.TP .TP
.B \-i
Display I/O Limits (aka I/O topology) information. This option could be used
together with \fB-p\fR option.
.TP
.B \-l .B \-l
Look up one device that matches the search parameter specified using Look up one device that matches the search parameter specified using
the the
@ -141,7 +157,7 @@ print the value of the tags
.TP .TP
.B list .B list
print the devices in a user-friendly format, this output format is unsupported print the devices in a user-friendly format, this output format is unsupported
for low-level probing (\fB-p\fR) for low-level probing (\fB-p\fR or \fB-i\fR)
.TP .TP
.B device .B device
print the device name only, this output format is always enabled for \fB-L\fR print the device name only, this output format is always enabled for \fB-L\fR
@ -152,10 +168,11 @@ vol_id compatible mode; usable in udev rules
.RE .RE
.TP .TP
.BI \-O " offset" .BI \-O " offset"
Probe at the given offset (only useful with \fB-p\fR). Probe at the given offset (only useful with \fB-p\fR). This option could be
used together with \fB-i\fR option.
.TP .TP
.BI \-p .BI \-p
Switch to low-level probing mode (bypass cache) Switch to low-level superblock probing mode (bypass cache).
.TP .TP
.BI \-s " tag" .BI \-s " tag"
For each (specified) device, show only the tags that match For each (specified) device, show only the tags that match

View File

@ -34,6 +34,9 @@ extern int optind;
#define OUTPUT_PRETTY_LIST 0x0004 #define OUTPUT_PRETTY_LIST 0x0004
#define OUTPUT_UDEV_LIST 0x0008 #define OUTPUT_UDEV_LIST 0x0008
#define LOWPROBE_TOPOLOGY 0x0001
#define LOWPROBE_SUPERBLOCKS 0x0002
#include <blkid.h> #include <blkid.h>
#include "ismounted.h" #include "ismounted.h"
@ -59,6 +62,7 @@ static void usage(int error)
" [-t <token>] [-w <file>] [dev ...]\n\n" " [-t <token>] [-w <file>] [dev ...]\n\n"
" %1$s -p [-s <tag>] [-O <offset>] [-S <size>] \n" " %1$s -p [-s <tag>] [-O <offset>] [-S <size>] \n"
" [-o format] <dev> [dev ...]\n\n" " [-o format] <dev> [dev ...]\n\n"
" %1$s -i [-s <tag>] [-o format] <dev> [dev ...]\n\n"
"Options:\n" "Options:\n"
" -c <file> cache file (default: /etc/blkid.tab, /dev/null = none)\n" " -c <file> cache file (default: /etc/blkid.tab, /dev/null = none)\n"
" -h print this usage message and exit\n" " -h print this usage message and exit\n"
@ -74,7 +78,8 @@ static void usage(int error)
" -w <file> write cache to different file (/dev/null = no write)\n" " -w <file> write cache to different file (/dev/null = no write)\n"
" <dev> specify device(s) to probe (default: all devices)\n\n" " <dev> specify device(s) to probe (default: all devices)\n\n"
"Low-level probing options:\n" "Low-level probing options:\n"
" -p switch to low-level mode (bypass cache)\n" " -p low-level superblocks probing (bypass cache)\n"
" -i gather information about I/O limits\n"
" -S <size> overwrite device size\n" " -S <size> overwrite device size\n"
" -O <offset> probe at the given offset\n" " -O <offset> probe at the given offset\n"
" -u <list> filter by \"usage\" (e.g. -u filesystem,raid)\n" " -u <list> filter by \"usage\" (e.g. -u filesystem,raid)\n"
@ -238,6 +243,7 @@ static void pretty_print_dev(blkid_dev dev)
static void print_udev_format(const char *name, const char *value, size_t sz) static void print_udev_format(const char *name, const char *value, size_t sz)
{ {
char enc[265], safe[256]; char enc[265], safe[256];
size_t namelen = strlen(name);
*safe = *enc = '\0'; *safe = *enc = '\0';
@ -270,6 +276,11 @@ static void print_udev_format(const char *name, const char *value, size_t sz)
} else if (!strncmp(name, "PART_ENTRY_", 11)) } else if (!strncmp(name, "PART_ENTRY_", 11))
printf("ID_%s=%s\n", name, value); printf("ID_%s=%s\n", name, value);
else if (namelen >= 15 && (
!strcmp(name + (namelen - 12), "_SECTOR_SIZE") ||
!strcmp(name + (namelen - 8), "_IO_SIZE") ||
!strcmp(name, "ALIGNMENT_OFFSET")))
printf("ID_IOLIMIT_%s=%s\n", name, value);
else else
printf("ID_FS_%s=%s\n", name, value); printf("ID_FS_%s=%s\n", name, value);
} }
@ -415,28 +426,13 @@ done:
return rc; return rc;
} }
static int lowprobe_device(blkid_probe pr, const char *devname, char *show[], static int lowprobe_superblocks(blkid_probe pr)
int output, blkid_loff_t offset, blkid_loff_t size)
{ {
const char *data;
const char *name;
int nvals = 0, n, num = 1;
size_t len;
int fd;
int rc = 0;
struct stat st; struct stat st;
static int first = 1; int rc;
fd = open(devname, O_RDONLY); if (fstat(blkid_probe_get_fd(pr), &st))
if (fd < 0) { return -1;
fprintf(stderr, "error: %s: %s\n", devname, strerror(errno));
return 2;
}
if (blkid_probe_set_device(pr, fd, offset, size))
goto done;
if (fstat(fd, &st))
goto done;
blkid_probe_enable_partitions(pr, 1); blkid_probe_enable_partitions(pr, 1);
blkid_probe_set_partitions_flags(pr, BLKID_PARTS_ENTRY_DETAILS); blkid_probe_set_partitions_flags(pr, BLKID_PARTS_ENTRY_DETAILS);
@ -450,11 +446,10 @@ static int lowprobe_device(blkid_probe pr, const char *devname, char *show[],
rc = blkid_do_fullprobe(pr); rc = blkid_do_fullprobe(pr);
if (rc < 0) if (rc < 0)
goto done; /* -1 = error, 1 = nothing, 0 = succes */ return rc; /* -1 = error, 1 = nothing, 0 = succes */
if (blkid_probe_lookup_value(pr, "PTTYPE", NULL, NULL) == 0) if (blkid_probe_lookup_value(pr, "PTTYPE", NULL, NULL) == 0)
/* partition table detected */ return 0; /* partition table detected */
goto print_vals;
/* small whole-disk is unpartitioned, probe for filesystems only */ /* small whole-disk is unpartitioned, probe for filesystems only */
blkid_probe_enable_partitions(pr, 0); blkid_probe_enable_partitions(pr, 0);
@ -462,10 +457,47 @@ static int lowprobe_device(blkid_probe pr, const char *devname, char *show[],
blkid_probe_enable_superblocks(pr, 1); blkid_probe_enable_superblocks(pr, 1);
rc = blkid_do_safeprobe(pr); return blkid_do_safeprobe(pr);
}
static int lowprobe_topology(blkid_probe pr)
{
/* enable topology probing only */
blkid_probe_enable_topology(pr, 1);
blkid_probe_enable_superblocks(pr, 0);
blkid_probe_enable_partitions(pr, 0);
return blkid_do_fullprobe(pr);
}
static int lowprobe_device(blkid_probe pr, const char *devname,
int chain, char *show[], int output,
blkid_loff_t offset, blkid_loff_t size)
{
const char *data;
const char *name;
int nvals = 0, n, num = 1;
size_t len;
int fd;
int rc = 0;
static int first = 1;
fd = open(devname, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "error: %s: %s\n", devname, strerror(errno));
return 2;
}
if (blkid_probe_set_device(pr, fd, offset, size))
goto done;
if (chain & LOWPROBE_TOPOLOGY)
rc = lowprobe_topology(pr);
if (rc >= 0 && (chain & LOWPROBE_SUPERBLOCKS))
rc = lowprobe_superblocks(pr);
if (rc < 0) if (rc < 0)
goto done; goto done;
print_vals:
nvals = blkid_probe_numof_values(pr); nvals = blkid_probe_numof_values(pr);
if (nvals && !first && output & OUTPUT_UDEV_LIST) if (nvals && !first && output & OUTPUT_UDEV_LIST)
@ -616,7 +648,7 @@ int main(int argc, char **argv)
show[0] = NULL; show[0] = NULL;
while ((c = getopt (argc, argv, "c:f:ghlL:n:o:O:ps:S:t:u:U:w:v")) != EOF) while ((c = getopt (argc, argv, "c:f:ghilL:n:o:O:ps:S:t:u:U:w:v")) != EOF)
switch (c) { switch (c) {
case 'c': case 'c':
if (optarg && !*optarg) if (optarg && !*optarg)
@ -650,6 +682,9 @@ int main(int argc, char **argv)
search_value = strdup(optarg); search_value = strdup(optarg);
search_type = strdup("UUID"); search_type = strdup("UUID");
break; break;
case 'i':
lowprobe |= LOWPROBE_TOPOLOGY;
break;
case 'l': case 'l':
lookup++; lookup++;
break; break;
@ -681,7 +716,7 @@ int main(int argc, char **argv)
optarg); optarg);
break; break;
case 'p': case 'p':
lowprobe++; lowprobe |= LOWPROBE_SUPERBLOCKS;
break; break;
case 's': case 's':
if (numtag + 1 >= sizeof(show) / sizeof(*show)) { if (numtag + 1 >= sizeof(show) / sizeof(*show)) {
@ -774,20 +809,23 @@ int main(int argc, char **argv)
if (!pr) if (!pr)
goto exit; goto exit;
blkid_probe_set_superblocks_flags(pr, if (lowprobe & LOWPROBE_SUPERBLOCKS) {
blkid_probe_set_superblocks_flags(pr,
BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE | BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION); BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION);
if (fltr_usage && if (fltr_usage && blkid_probe_filter_superblocks_usage(
blkid_probe_filter_superblocks_usage(pr, fltr_flag, fltr_usage)) pr, fltr_flag, fltr_usage))
goto exit; goto exit;
else if (fltr_type &&
blkid_probe_filter_superblocks_type(pr, fltr_flag, fltr_type)) else if (fltr_type && blkid_probe_filter_superblocks_type(
goto exit; pr, fltr_flag, fltr_type))
goto exit;
}
for (i = 0; i < numdev; i++) for (i = 0; i < numdev; i++)
err = lowprobe_device(pr, devices[i], show, err = lowprobe_device(pr, devices[i], lowprobe, show,
output_format, output_format,
(blkid_loff_t) offset, (blkid_loff_t) offset,
(blkid_loff_t) size); (blkid_loff_t) size);