]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
src: Introduce zbdioctl program
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Mon, 28 Jan 2019 13:14:49 +0000 (22:14 +0900)
committerOmar Sandoval <osandov@fb.com>
Tue, 5 Feb 2019 18:47:18 +0000 (10:47 -0800)
zbdioctl implements calls to zoned block devices ioctls that are not
supported currently by sys-utils blkzone utility, namely BLKGETZONESZ
and BLKGETNRZONES.

Reviewed-by: Chaitanya Kulkarni <Chaitanya.Kulkarni@wdc.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
src/.gitignore
src/Makefile
src/zbdioctl.c [new file with mode: 0644]

index 8c957859b171fd623e795c6409a04fd91a45194f..2108f56595d89ca892f8664e70e4443bb6d44111 100644 (file)
@@ -6,3 +6,4 @@
 /nbdsetsize
 /sg/dxfer-from-dev
 /sg/syzkaller1
+/zbdioctl
index c4094b4ec57dd436b3e01d2652b71231103aeda7..5a0556f2a37f26ff639b88045bfc873b35c995fe 100644 (file)
@@ -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 (file)
index 0000000..1ea72e8
--- /dev/null
@@ -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
+