blklimits: new command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Please, review. The 'blklimits' command is the command-line interface
 for I/O topology stuff in libblkid.

    Karel


>From 4167095502b88cb62b6e856956c74ea188cec415 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@xxxxxxxxxx>
Date: Thu, 13 May 2010 10:14:43 +0200
Subject: [PATCH] blklimits: new command (print I/O topology)

The  blklimits  program  is the command-line interface to working with
I/O topology support in the libblkid library. For example:

	# blklimits /dev/sdb
	alignment offset:          0
	minimum io size:        4096
	optimal io size:       32768
	logical sector size:     512
	physical sector size:   4096

CC: Christoph Hellwig <hch@xxxxxxxxxxxxx>
Signed-off-by: Karel Zak <kzak@xxxxxxxxxx>
---
 sys-utils/.gitignore                        |    1 +
 sys-utils/Makefile.am                       |    8 ++
 sys-utils/blklimits.8                       |   69 ++++++++++++++++++
 sys-utils/blklimits.c                       |  104 +++++++++++++++++++++++++++
 tests/commands.sh.in                        |    1 +
 tests/expected/blklimits/iolimits-512-4K-63 |    5 ++
 tests/ts/blklimits/iolimits-512-4K-63       |   41 +++++++++++
 7 files changed, 229 insertions(+), 0 deletions(-)
 create mode 100644 sys-utils/blklimits.8
 create mode 100644 sys-utils/blklimits.c
 create mode 100644 tests/expected/blklimits/iolimits-512-4K-63
 create mode 100755 tests/ts/blklimits/iolimits-512-4K-63

diff --git a/sys-utils/.gitignore b/sys-utils/.gitignore
index 7985d7a..7249430 100644
--- a/sys-utils/.gitignore
+++ b/sys-utils/.gitignore
@@ -1,4 +1,5 @@
 arch
+blklimits
 ctrlaltdel
 cytune
 dmesg
diff --git a/sys-utils/Makefile.am b/sys-utils/Makefile.am
index 76828cc..6e4c262 100644
--- a/sys-utils/Makefile.am
+++ b/sys-utils/Makefile.am
@@ -16,13 +16,21 @@ usrsbin_exec_PROGRAMS += ldattach tunelp rtcwake
 
 dist_man_MANS += dmesg.1 ctrlaltdel.8 cytune.8 setarch.8 \
 		ldattach.8 lscpu.1 tunelp.8 rtcwake.8
+
+if BUILD_LIBBLKID
+usrsbin_exec_PROGRAMS += blklimits
+dist_man_MANS += blklimits.8
+blklimits_LDADD = $(ul_libblkid_la)
+blklimits_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
 endif
+endif # linux
 
 cytune_SOURCES = cytune.c cyclades.h
 tunelp_SOURCES = tunelp.c lp.h
 
 info_TEXINFOS = ipc.texi
 
+
 if BUILD_FALLOCATE
 usrbin_exec_PROGRAMS += fallocate
 fallocate_SOURCES = fallocate.c ../lib/strtosize.c
diff --git a/sys-utils/blklimits.8 b/sys-utils/blklimits.8
new file mode 100644
index 0000000..a0fc4cf
--- /dev/null
+++ b/sys-utils/blklimits.8
@@ -0,0 +1,69 @@
+.\" -*- nroff -*-
+.TH BLKLIMITS 8 "May 2010" "Version 1.0"
+.SH NAME
+blklimits \- print block device I/O limits
+.SH SYNOPSIS
+.B blklimits
+.RB [ \-h ]
+.I devname
+.SH DESCRIPTION
+The
+.B blklimits
+program is the command-line interface to working with I/O topology support in
+the libblkid library.
+.PP
+The I/O limits information are exported to the userspace since kernel 2.6.31 by
+sys filesystem or ioclts. The libblkid library provides unified API for I/O
+limits. The library is also able to gather information from DM, MD, LVM and
+EVMS on systems with older kernels.
+.PP
+The exit code returned by
+.B blklimits
+is 0 on success and 1 on failure.
+.PP
+.SH OPTIONS
+.IP "\fB\-h, \-\-help\fP"
+Print help and exit.
+.SH I/O LIMITS INFORMATION
+.TP
+.I alignment offset
+Storage devices may report a physical block size that is bigger than the
+logical block size (for instance a drive with 4KiB physical sectors exposing
+512-byte logical blocks to the operating system).  This parameter indicates how
+many bytes the beginning of the device is offset from the disk's natural
+alignment.
+.TP
+.I logical sector size
+This is the smallest unit the storage device can address. It is typically 512
+bytes.
+.TP
+.I minimum io size
+Storage devices may report a granularity or preferred minimum I/O size which is
+the smallest request the device can perform without incurring a performance
+penalty.  For disk drives this is often the physical block size.  For RAID
+arrays it is often the stripe chunk size.  A properly aligned multiple of
+minimum_io_size is the preferred request size for workloads where a high number
+of I/O operations is desired.
+.TP
+.I optimal io size
+Storage devices may report an optimal I/O size, which is the device's preferred
+unit for sustained I/O.  This is rarely reported for disk drives.  For RAID
+arrays it is usually the stripe width or the internal track size.  A properly
+aligned multiple of optimal_io_size is the preferred request size for workloads
+where sustained throughput is desired.  If no optimal I/O size is reported this
+variable contains zero.
+.TP
+.I physical sector size
+This is the smallest unit a physical storage device can write atomically. It
+is usually the same as the logical block size but may be bigger. One example
+is SATA drives with 4KiB sectors that expose a 512-byte logical block size to
+the operating system.  For stacked block devices the physical sector size
+variable contains the maximum physical sector size of the component devices.
+.SH AUTHORS
+.nf
+Karel Zak <kzak@xxxxxxxxxx>
+.fi
+.SH AVAILABILITY
+The blklimits command is part of the util-linux-ng package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+
diff --git a/sys-utils/blklimits.c b/sys-utils/blklimits.c
new file mode 100644
index 0000000..2c06738
--- /dev/null
+++ b/sys-utils/blklimits.c
@@ -0,0 +1,104 @@
+/*
+ * blklimits - utility to print block device I/O limits (aka I/O topology)
+ *
+ * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ * Written by Karel Zak <kzak@xxxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <err.h>
+#include <errno.h>
+
+#include <blkid.h>
+
+#include "nls.h"
+
+static void __attribute__((__noreturn__)) usage(FILE *out)
+{
+	fprintf(out, _("Usage: %s [options] <device>\n\nOptions:\n"),
+			program_invocation_short_name);
+
+	fprintf(out, _(
+		" -h, --help          this help\n"));
+
+	fprintf(out, _("\nFor more information see blklimits(1).\n"));
+
+	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+int main(int argc, char **argv)
+{
+	blkid_probe pr = NULL;
+	blkid_topology tp;
+	char *devname;
+	int c, rc = EXIT_FAILURE;
+
+	struct option longopts[] = {
+	    { "help",      0, 0, 'h' },
+	    { NULL,        0, 0, 0 }
+	};
+
+	setlocale(LC_ALL, "");
+	bindtextdomain(PACKAGE, LOCALEDIR);
+	textdomain(PACKAGE);
+
+	while ((c = getopt_long(argc, argv, "h", longopts, NULL)) != -1) {
+		switch(c) {
+		case 'h':
+			usage(stdout);
+			break;
+		default:
+			usage(stderr);
+			break;
+		}
+	}
+
+	if (optind == argc)
+		errx(EXIT_FAILURE, _("no device specified."));
+
+	devname = argv[optind++];
+	pr = blkid_new_probe_from_filename(devname);
+	if (!pr) {
+		warn(_("%s: failed to create a new libblkid probe"), devname);
+		goto done;
+	}
+
+	tp = blkid_probe_get_topology(pr);
+	if (!tp) {
+		warnx(_("%s: failed to gather topology information"), devname);
+		goto done;
+	}
+
+	printf(_("alignment offset:     %6lu\n"),
+			blkid_topology_get_alignment_offset(tp));
+	printf(_("minimum io size:      %6lu\n"),
+			blkid_topology_get_minimum_io_size(tp));
+	printf(_("optimal io size:      %6lu\n"),
+			blkid_topology_get_optimal_io_size(tp));
+	printf(_("logical sector size:  %6lu\n"),
+			blkid_topology_get_logical_sector_size(tp));
+	printf(_("physical sector size: %6lu\n"),
+			blkid_topology_get_physical_sector_size(tp));
+
+	rc = EXIT_SUCCESS;
+done:
+	blkid_free_probe(pr);
+	return rc;
+}
+
diff --git a/tests/commands.sh.in b/tests/commands.sh.in
index f52a686..39e6028 100644
--- a/tests/commands.sh.in
+++ b/tests/commands.sh.in
@@ -48,5 +48,6 @@ TS_CMD_HWCLOCK=${TS_CMD_HWCLOCK-"$TOPDIR/hwclock/hwclock"}
 TS_CMD_LSCPU=${TS_CMD_LSCPU-"$TOPDIR/sys-utils/lscpu"}
 
 TS_CMD_BLKID=${TS_CMD_BLKID-"$TOPDIR/misc-utils/blkid"}
+TS_CMD_BLKLIMITS=${TS_CMD_BLKLIMITS-"$TOPDIR/sys-utils/blklimits"}
 
 TS_CMD_FDISK=${TS_CMD_FDISK-"$TOPDIR/fdisk/fdisk"}
diff --git a/tests/expected/blklimits/iolimits-512-4K-63 b/tests/expected/blklimits/iolimits-512-4K-63
new file mode 100644
index 0000000..c07b1aa
--- /dev/null
+++ b/tests/expected/blklimits/iolimits-512-4K-63
@@ -0,0 +1,5 @@
+alignment offset:       3584
+minimum io size:        4096
+optimal io size:       32768
+logical sector size:     512
+physical sector size:   4096
diff --git a/tests/ts/blklimits/iolimits-512-4K-63 b/tests/ts/blklimits/iolimits-512-4K-63
new file mode 100755
index 0000000..2b1d0d8
--- /dev/null
+++ b/tests/ts/blklimits/iolimits-512-4K-63
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+#
+# This file is part of util-linux-ng.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+
+TS_TOPDIR="$(dirname $0)/../.."
+TS_DESC="512/4K +alignment_offset"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+ts_skip_nonroot
+
+modprobe --dry-run --quiet scsi_debug
+[ "$?" == 0 ] || ts_skip "missing scsi_debug module"
+
+rmmod scsi_debug &> /dev/null
+modprobe scsi_debug dev_size_mb=50 sector_size=512 physblk_exp=3 lowest_aligned=7
+[ "$?" == 0 ] || ts_die "Cannot init device"
+
+sleep 1
+
+DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
+[ "x${DEVNAME}" == "x" ] && ts_die "Cannot found device"
+
+DEVICE="/dev/${DEVNAME}"
+
+$TS_CMD_BLKLIMITS $DEVICE >> $TS_OUTPUT 2>&1
+
+rmmod scsi_debug
+ts_finalize
-- 
1.6.6.1

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux