linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
To: linux-block@vger.kernel.org, Omar Sandoval <osandov@fb.com>,
	Masato Suzuki <masato.suzuki@wdc.com>,
	Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Cc: Omar Sandoval <osandov@osandov.com>, Jens Axboe <axboe@kernel.dk>,
	Matias Bjorling <matias.bjorling@wdc.com>,
	Hannes Reinecke <hare@suse.de>, Mike Snitzer <snitzer@redhat.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Chaitanya Kulkarni <Chaitanya.Kulkarni@wdc.com>
Subject: [PATCH blktests v2 09/16] src: Introduce zbdioctl program
Date: Thu, 10 Jan 2019 18:37:18 +0900	[thread overview]
Message-ID: <20190110093725.32675-10-shinichiro.kawasaki@wdc.com> (raw)
In-Reply-To: <20190110093725.32675-1-shinichiro.kawasaki@wdc.com>

zbdioctl implements calls to zoned block devices ioctls that are not
supported currently by sys-utils blkzone utility, namely BLKGETZONESZ
and BLKGETNRZONES.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 src/.gitignore |  1 +
 src/Makefile   |  3 +-
 src/zbdioctl.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 src/zbdioctl.c

diff --git a/src/.gitignore b/src/.gitignore
index 8c95785..2108f56 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -6,3 +6,4 @@
 /nbdsetsize
 /sg/dxfer-from-dev
 /sg/syzkaller1
+/zbdioctl
diff --git a/src/Makefile b/src/Makefile
index c4094b4..5a0556f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -5,7 +5,8 @@ C_TARGETS := \
 	sg/dxfer-from-dev \
 	sg/syzkaller1 \
 	nbdsetsize \
-	loop_change_fd
+	loop_change_fd \
+	zbdioctl
 
 CXX_TARGETS := \
 	discontiguous-io
diff --git a/src/zbdioctl.c b/src/zbdioctl.c
new file mode 100644
index 0000000..1ea72e8
--- /dev/null
+++ b/src/zbdioctl.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-3.0+
+// Copyright (C) 2018 Western Digital Corporation or its affiliates.
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <linux/blkzoned.h>
+#include <linux/types.h>
+
+#if !defined(BLKGETZONESZ) || !defined(BLKGETNRZONES)
+
+int main(int argc, char **argv)
+{
+	return EXIT_FAILURE;
+}
+
+#else
+
+struct request {
+	const char *name;
+	unsigned long code;
+} requests[] = {
+	{ "-s", BLKGETZONESZ},
+	{ "-n", BLKGETNRZONES},
+	{ NULL, 0},
+};
+
+void usage(const char *progname)
+{
+	int i = 0;
+
+	fprintf(stderr, "usage: %s <request> <device file>\n", progname);
+	fprintf(stderr, "<request> can be:\n");
+	while (requests[i].name) {
+		fprintf(stderr, "\t%s\n", requests[i].name);
+		i++;
+	}
+	exit(EXIT_FAILURE);
+}
+
+int main(int argc, char **argv)
+{
+	int i = 0, fd, ret;
+	unsigned int val;
+	unsigned long code = 0;
+
+	if (argc != 3)
+		usage(argv[0]);
+
+	while (requests[i].name) {
+		if (strcmp(argv[1], requests[i].name) == 0) {
+			code = requests[i].code;
+			break;
+		}
+		i++;
+	}
+	if (code == 0)
+		usage(argv[0]);
+
+	fd = open(argv[2], O_RDWR);
+	if (fd < 0) {
+		perror("open");
+		return EXIT_FAILURE;
+	}
+
+	ret = ioctl(fd, code, &val);
+	if (ret < 0) {
+		perror("ioctl");
+		close(fd);
+		return EXIT_FAILURE;
+	}
+
+	printf("%u\n", val);
+
+	close(fd);
+
+	return EXIT_SUCCESS;
+}
+
+#endif
+
-- 
2.20.1


  parent reply	other threads:[~2019-01-10  9:38 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-10  9:37 [PATCH blktests v2 00/16] Implement zoned block device support Shin'ichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 01/16] config: Introduce ZONED variable Shin'ichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 02/16] common: Introduce _test_dev_is_zoned() helper function Shin'ichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 03/16] common: Move set_scheduler() function definition Shin'ichiro Kawasaki
2019-01-17  2:18   ` Omar Sandoval
2019-01-17  6:18     ` Shinichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 04/16] common: Introduce _have_fio_zbd_zonemode() helper function Shin'ichiro Kawasaki
2019-01-17  2:22   ` Omar Sandoval
2019-01-17  6:21     ` Shinichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 05/16] block/004: Adjust fio conditions for zoned block device Shin'ichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 06/16] block/013: Skip for zoned block devices Shin'ichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 07/16] block/018,024: Skip when ZONED is set Shin'ichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 08/16] check: Introduce group_exit() function Shin'ichiro Kawasaki
2019-01-10  9:37 ` Shin'ichiro Kawasaki [this message]
2019-01-10  9:37 ` [PATCH blktests v2 10/16] common: Introduce _dd() helper function Shin'ichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 11/16] tests: Introduce zbd test group Shin'ichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 12/16] zbd/001: sysfs and ioctl consistency test Shin'ichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 13/16] zbd/002: report zone test Shin'ichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 14/16] zbd/003: Test sequential zones reset Shin'ichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 15/16] zbd/004: Check write split accross sequential zones Shin'ichiro Kawasaki
2019-01-10  9:37 ` [PATCH blktests v2 16/16] zbd/005: Test write ordering Shin'ichiro Kawasaki
2019-01-17  2:16 ` [PATCH blktests v2 00/16] Implement zoned block device support Omar Sandoval
2019-01-17  5:15   ` Chaitanya Kulkarni
2019-01-17  6:06   ` Shinichiro Kawasaki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190110093725.32675-10-shinichiro.kawasaki@wdc.com \
    --to=shinichiro.kawasaki@wdc.com \
    --cc=Chaitanya.Kulkarni@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=linux-block@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=masato.suzuki@wdc.com \
    --cc=matias.bjorling@wdc.com \
    --cc=osandov@fb.com \
    --cc=osandov@osandov.com \
    --cc=snitzer@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).