From 22fae330d9b9b124e782a99c9daacdc5290cdf35 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 23 Feb 2017 17:03:26 +0100 Subject: blkreport, blkreset: remove in favour of blkzone Signed-off-by: Karel Zak --- .gitignore | 2 - bash-completion/blkreset | 34 ------- configure.ac | 8 -- sys-utils/Makemodule.am | 14 --- sys-utils/blkreport.8 | 92 ------------------- sys-utils/blkreport.c | 225 ----------------------------------------------- sys-utils/blkreset.8 | 62 ------------- sys-utils/blkreset.c | 190 --------------------------------------- 8 files changed, 627 deletions(-) delete mode 100755 bash-completion/blkreset delete mode 100644 sys-utils/blkreport.8 delete mode 100644 sys-utils/blkreport.c delete mode 100644 sys-utils/blkreset.8 delete mode 100644 sys-utils/blkreset.c diff --git a/.gitignore b/.gitignore index 2b1267cb0..8630feacf 100644 --- a/.gitignore +++ b/.gitignore @@ -63,8 +63,6 @@ update.log /agetty /blkdiscard /blkzone -/blkreport -/blkreset /blkid /blockdev /cal diff --git a/bash-completion/blkreset b/bash-completion/blkreset deleted file mode 100755 index 69c5f63c1..000000000 --- a/bash-completion/blkreset +++ /dev/null @@ -1,34 +0,0 @@ -_blkreset_module() -{ - local cur prev OPTS - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - case $prev in - '-z'|'--zone') - COMPREPLY=( $(compgen -W "offset" -- $cur) ) - return 0 - ;; - '-c'|'--count') - COMPREPLY=( $(compgen -W "length" -- $cur) ) - return 0 - ;; - '-h'|'--help'|'-V'|'--version') - return 0 - ;; - esac - case $cur in - -*) - OPTS="--zone --count --version --help" - if [ "$1" = 'blkreport' ]; then - OPTS+=' --verbose' - fi - COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) ) - return 0 - ;; - esac - COMPREPLY=( $(compgen -W "$(lsblk -pnro name)" -- $cur) ) - return 0 -} -complete -F _blkreset_module blkreset -complete -F _blkreset_module blkreport diff --git a/configure.ac b/configure.ac index b8a3e31be..8933afa6f 100644 --- a/configure.ac +++ b/configure.ac @@ -1602,14 +1602,6 @@ UL_REQUIRES_LINUX([blkzone]) UL_REQUIRES_HAVE([blkzone], [linux_blkzoned_h], [linux/blkzoned.h header]) AM_CONDITIONAL([BUILD_BLKZONE], [test "x$build_blkzone" = xyes]) -UL_BUILD_INIT([blkreport], [check]) -UL_REQUIRES_HAVE([blkreport], [linux_blkzoned_h], [linux/blkzoned.h header]) -AM_CONDITIONAL([BUILD_BLKREPORT], [test "x$build_blkreport" = xyes]) - -UL_BUILD_INIT([blkreset], [check]) -UL_REQUIRES_HAVE([blkreset], [linux_blkzoned_h], [linux/blkzoned.h header]) -AM_CONDITIONAL([BUILD_BLKRESET], [test "x$build_blkreset" = xyes]) - UL_BUILD_INIT([ldattach], [check]) UL_REQUIRES_LINUX([ldattach]) AM_CONDITIONAL([BUILD_LDATTACH], [test "x$build_ldattach" = xyes]) diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am index 7a42fd8da..c5651946b 100644 --- a/sys-utils/Makemodule.am +++ b/sys-utils/Makemodule.am @@ -133,20 +133,6 @@ blkzone_SOURCES = sys-utils/blkzone.c blkzone_LDADD = $(LDADD) libcommon.la endif -if BUILD_BLKREPORT -sbin_PROGRAMS += blkreport -dist_man_MANS += sys-utils/blkreport.8 -blkreport_SOURCES = sys-utils/blkreport.c -blkreport_LDADD = $(LDADD) libcommon.la $(REALTIME_LIBS) -endif - -if BUILD_BLKRESET -sbin_PROGRAMS += blkreset -dist_man_MANS += sys-utils/blkreset.8 -blkreset_SOURCES = sys-utils/blkreset.c -blkreset_LDADD = $(LDADD) libcommon.la $(REALTIME_LIBS) -endif - if BUILD_LDATTACH usrsbin_exec_PROGRAMS += ldattach dist_man_MANS += sys-utils/ldattach.8 diff --git a/sys-utils/blkreport.8 b/sys-utils/blkreport.8 deleted file mode 100644 index 1d00bfd24..000000000 --- a/sys-utils/blkreport.8 +++ /dev/null @@ -1,92 +0,0 @@ -.TH BLKREPORT 8 "February 2017" "util-linux" "System Administration" -.SH NAME -blkreport \- report zones on a device -.SH SYNOPSIS -.B blkreport -[options] -.RB [ \-z -.IR zone ] -.RB [ \-c -.IR count ] -.I device -.SH DESCRIPTION -.B blkreport -is used to report device zone information. This is useful for -devices that support the Zoned Block Commands (ZBC) or Zoned-device ATA -Commands (ZAC). -.PP -By default, -.B blkreport -will report on up to 4k zones from the start of the block device. -Options may be used to modify this behavior, changing the starting zone or -the size of the report, as explained below. -.PP -The -.I device -argument is the pathname of the block device. -.SH OPTIONS -The -.I offset -and -.I length -option arguments may be followed by the multiplicative suffixes KiB (=1024), -MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is -optional, e.g., "K" has the same meaning as "KiB") or the suffixes -KB (=1000), MB (=1000*1000), and so on for GB, TB, PB, EB, ZB and YB. -Additionally, the 0x prefix can be used to specify \fIoffset\fR and -\fIlength\fR in hex. -.TP -.BR \-z , " \-\-zone "\fIoffset\fP -The starting zone of the report specified as a sector offset. -The provided offset in sector units (512 bytes) should match the start of a zone. -The default value is zero. -.TP -.BR \-c , " \-\-count "\fIlength\fP -The maximum number of zones to be returned by the report. -The default is 4096, the maximum 65536. -.TP -.BR \-v , " \-\-verbose" -Display the number of zones returned in the report. -.TP -.BR \-V , " \-\-version" -Display version information and exit. -.TP -.BR \-h , " \-\-help" -Display help text and exit. -.SH REPORT OUTPUT -.TS -tab(:); -left l l. -start:Zone start sector -len:Zone length in number of sectors -wptr:Zone write pointer position -reset:Reset write pointer recommended -non-seq:Non-sequential write resources active -cond:Zone condition -type:Zone type -.TE -.SS Zone conditions -.TS -tab(:); -left l l. -Cl:closed -cv:conventional zone -e0:empty -fu:full -Oe:open explicit -Oi:open implicit -OL:offline -ro:read only -x?:reserved conditions (should not be reported) -.TE -.SH AUTHOR -.MT shaun@tancheff.com -Shaun Tancheff -.ME -.SH SEE ALSO -.BR sg_rep_zones (8) -.SH AVAILABILITY -The blkreport command is part of the util-linux package and is available from -.UR https://\:www.kernel.org\:/pub\:/linux\:/utils\:/util-linux/ -Linux Kernel Archive -.UE . diff --git a/sys-utils/blkreport.c b/sys-utils/blkreport.c deleted file mode 100644 index c8d0a63ac..000000000 --- a/sys-utils/blkreport.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * blkreport.c -- request a zone report on part (or all) of the block device. - * - * Copyright (C) 2015,2016 Seagate Technology PLC - * Written by Shaun Tancheff - * - * Copyright (C) 2017 Karel Zak - * - * 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 of the License, 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, see . - * - * This program uses BLKREPORT ioctl to query zone information about part of - * or a whole block device, if the device supports it. - * You can specify range (start and length) to be queried. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "nls.h" -#include "strutils.h" -#include "xalloc.h" -#include "c.h" -#include "closestream.h" -#include "blkdev.h" - -static const char *type_text[] = { - "RESERVED", - "CONVENTIONAL", - "SEQ_WRITE_REQUIRED", - "SEQ_WRITE_PREFERRED", -}; - -static const char *condition_str[] = { - "cv", /* conventional zone */ - "e0", /* empty */ - "Oi", /* open implicit */ - "Oe", /* open explicit */ - "Cl", /* closed */ - "x5", "x6", "x7", "x8", "x9", "xA", "xB", /* xN: reserved */ - "ro", /* read only */ - "fu", /* full */ - "OL" /* offline */ -}; - -static void print_zones(const struct blk_zone *info, const uint32_t count) -{ - uint32_t iter; - - printf(_("Zones returned: %u\n"), count); - - for (iter = 0; iter < count; iter++) { - const struct blk_zone *entry = &info[iter]; - unsigned int type = entry->type; - uint64_t start = entry->start; - uint64_t wp = entry->wp; - uint8_t cond = entry->cond; - uint64_t len = entry->len; - - if (!len) - break; - - printf(_(" start: %9lx, len %6lx, wptr %6lx" - " reset:%u non-seq:%u, zcond:%2u(%s) [type: %u(%s)]\n"), - start, len, wp - start, - entry->reset, entry->non_seq, - cond, condition_str[cond & ARRAY_SIZE(condition_str)], - type, type_text[type]); - } -} - -static int do_report(const int fd, const uint64_t lba, uint32_t len, const int verbose) -{ - int rc; - struct blk_zone_report *zi; - - zi = xmalloc(sizeof(struct blk_zone_report) + (len * sizeof(struct blk_zone))); - zi->nr_zones = len; - zi->sector = lba; /* maybe shift 4Kn -> 512e */ - rc = ioctl(fd, BLKREPORTZONE, zi); - if (rc != -1) { - if (verbose) - printf(_("Found %d zones\n"), zi->nr_zones); - print_zones(zi->zones, zi->nr_zones); - } - free(zi); - - return rc; -} - -static void __attribute__((__noreturn__)) usage(FILE *out) -{ - fputs(USAGE_HEADER, out); - fprintf(out, _(" %s [options] \n"), program_invocation_short_name); - - fputs(USAGE_SEPARATOR, out); - fputs(_("Report zone information about the given device.\n"), out); - - fputs(USAGE_OPTIONS, out); - fputs(_(" -z, --zone start sector of first zone (in 512-byte sectors)\n"), out); - fputs(_(" -c, --count maximum number of zones in the report\n"), out); - fputs(_(" -v, --verbose display the number of reported zones"), out); - fputs(USAGE_SEPARATOR, out); - fputs(USAGE_HELP, out); - fputs(USAGE_VERSION, out); - - fprintf(out, USAGE_MAN_TAIL("blkreport(8)")); - exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); -} - -#define DEF_REPORT_LEN (1 << 12) /* 4k zones (256k kzalloc) */ -#define MAX_REPORT_LEN (1 << 16) /* 64k zones */ - -int main(int argc, char **argv) -{ - char *path; - int c; - int fd; - int secsize; - uint64_t blksectors = 0; - struct stat sb; - int verbose = 0; - uint64_t offset = 0ul; - uint32_t length = DEF_REPORT_LEN; - static const struct option longopts[] = { - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'V' }, - { "zone", required_argument, NULL, 'z' }, /* starting LBA */ - { "count", required_argument, NULL, 'c' }, /* max #of zones (entries) for result */ - { "verbose", no_argument, NULL, 'v' }, - { NULL, 0, NULL, 0 } - }; - - setlocale(LC_ALL, ""); - bindtextdomain(PACKAGE, LOCALEDIR); - textdomain(PACKAGE); - atexit(close_stdout); - - while ((c = getopt_long(argc, argv, "hc:z:vV", longopts, NULL)) != -1) { - switch (c) { - case 'h': - usage(stdout); - break; - case 'c': - length = strtosize_or_err(optarg, - _("failed to parse number of zones")); - break; - case 'z': - offset = strtosize_or_err(optarg, - _("failed to parse zone offset")); - break; - case 'v': - verbose = 1; - break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; - default: - usage(stderr); - break; - } - } - - if (optind == argc) - errx(EXIT_FAILURE, _("no device specified")); - - path = argv[optind++]; - - if (optind != argc) { - warnx(_("unexpected number of arguments")); - usage(stderr); - } - - fd = open(path, O_RDONLY); - if (fd < 0) - err(EXIT_FAILURE, _("cannot open %s"), path); - - if (fstat(fd, &sb) == -1) - err(EXIT_FAILURE, _("stat of %s failed"), path); - if (!S_ISBLK(sb.st_mode)) - errx(EXIT_FAILURE, _("%s: not a block device"), path); - - if (blkdev_get_sectors(fd, (unsigned long long *) &blksectors)) - err(EXIT_FAILURE, _("%s: blkdev_get_sectors ioctl failed"), path); - if (blkdev_get_sector_size(fd, &secsize)) - err(EXIT_FAILURE, _("%s: BLKSSZGET ioctl failed"), path); - - if (offset > blksectors) - errx(EXIT_FAILURE, _("%s: offset is greater than device size"), path); - if (length < 1) - length = 1; - if (length > MAX_REPORT_LEN) { - length = MAX_REPORT_LEN; - warnx(_("limiting report to %u entries"), length); - } - - if (do_report(fd, offset, length, verbose)) - err(EXIT_FAILURE, _("%s: BLKREPORTZONE ioctl failed"), path); - - close(fd); - return EXIT_SUCCESS; -} diff --git a/sys-utils/blkreset.8 b/sys-utils/blkreset.8 deleted file mode 100644 index 250699196..000000000 --- a/sys-utils/blkreset.8 +++ /dev/null @@ -1,62 +0,0 @@ -.TH BLKRESET 5 "October 2016" "util-linux" "System Administration" -.SH NAME -blkreset \- Reset a range of zones -.SH SYNOPSIS -.B blkreset -[options] -.RB [ \-z -.IR zone ] -.RB [ \-c -.IR count ] -.SH DESCRIPTION -.B blkreset -is used to reset one or more zones. This is useful for devices that support -Zoned Block Commands (ZBC) or Zoned-device ATA Commands (ZAC). Unlike -.BR sg_reset_wp (8) , -this command operates from the block layer and can reset a range of zones. -.PP -By default, -.B blkreset -will operate on the zone at device logical sector 0. Options may be used to -modify this behavior as well as specify the operation to be performed on -the zone, as explained below. -.PP -The -.I device -argument is the pathname of the block device. -.PP -.SH OPTIONS -The -.I offset -and -.I length -arguments may be followed by the multiplicative suffixes KiB (=1024), -MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is -optional, e.g., "K" has the same meaning as "KiB") or the suffixes -KB (=1000), MB (=1000*1000), and so on for GB, TB, PB, EB, ZB and YB. -Additionally the common 0x prefix can be used to specify zone and length in hex. -.TP -.BR \-z , " \-\-zone "\fIoffset\fP -The starting zone to be operated upon specified as a sector offset. -The provided offset in sector units (512 bytes) should match the start of a zone. -The default value is zero. -.TP -.BR \-c , " \-\-count "\fIlength\fP -The number of zones to be reset starting from offset. Default is 1 zone. -.TP -.BR \-V , " \-\-version" -Display version information and exit. -.TP -.BR \-h , " \-\-help" -Display help text and exit. -.SH AUTHOR -.MT shaun@tancheff.com -Shaun Tancheff -.ME -.SH SEE ALSO -.BR sg_reset_wp (8) -.SH AVAILABILITY -The blkreset command is part of the util-linux package and is available from -.UR https://\:www.kernel.org\:/pub\:/linux\:/utils\:/util-linux/ -Linux Kernel Archive -.UE . diff --git a/sys-utils/blkreset.c b/sys-utils/blkreset.c deleted file mode 100644 index 9a19c33c7..000000000 --- a/sys-utils/blkreset.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * blkreset.c -- Reset the WP on a range of zones. - * - * Copyright (C) 2015,2016 Seagate Technology PLC - * Written by Shaun Tancheff - * - * Copyright (C) 2017 Karel Zak - * - * 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 of the License, 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, see . - * - * This program uses BLKREPORT ioctl to query zone information about part of - * or a whole block device, if the device supports it. - * You can specify range (start and length) to be queried. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "sysfs.h" -#include "nls.h" -#include "strutils.h" -#include "c.h" -#include "closestream.h" -#include "blkdev.h" - -static unsigned long blkdev_chunk_sectors(const char *dname) -{ - struct sysfs_cxt cxt = UL_SYSFSCXT_EMPTY; - dev_t devno = sysfs_devname_to_devno(dname, NULL); - int major_no = major(devno); - int block_no = minor(devno) & ~0x0f; - uint64_t sz; - - /* - * Mapping /dev/sdXn -> /sys/block/sdX to read the chunk_size entry. - * This method masks off the partition specified by the minor device - * component. - */ - devno = makedev(major_no, block_no); - if (sysfs_init(&cxt, devno, NULL)) - return 0; - - if (sysfs_read_u64(&cxt, "queue/chunk_sectors", &sz) != 0) - warnx(_("%s: failed to read chunk size"), dname); - - sysfs_deinit(&cxt); - return sz; -} - -static void __attribute__((__noreturn__)) usage(FILE *out) -{ - fputs(USAGE_HEADER, out); - fprintf(out, - _(" %s [options] \n"), program_invocation_short_name); - - fputs(USAGE_SEPARATOR, out); - fputs(_("Discard the content of sectors on a device.\n"), out); - - fputs(USAGE_OPTIONS, out); - fputs(_(" -z, --zone start sector of zone to act upon\n" - " (in 512-byte sectors, default is 0))\n" - " -c, --count number of zones to reset (default is 1)"), - out); - fputs(USAGE_SEPARATOR, out); - fputs(USAGE_HELP, out); - fputs(USAGE_VERSION, out); - fprintf(out, USAGE_MAN_TAIL("blkreset(8)")); - exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); -} - -int main(int argc, char **argv) -{ - char *path; - int c, fd; - uint64_t blksectors = 0; - struct stat sb; - struct blk_zone_range za; - uint64_t zsector = 0; - uint64_t zlen; - uint64_t zcount = 1; - unsigned long zsize; - int rc; - - static const struct option longopts[] = { - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'V' }, - { "zone", required_argument, NULL, 'z' }, - { "count", required_argument, NULL, 'c' }, - { NULL, 0, NULL, 0 } - }; - - setlocale(LC_ALL, ""); - bindtextdomain(PACKAGE, LOCALEDIR); - textdomain(PACKAGE); - atexit(close_stdout); - - while ((c = getopt_long(argc, argv, "hVz:c:", longopts, NULL)) != -1) { - switch (c) { - case 'h': - usage(stdout); - break; - case 'c': - zcount = strtosize_or_err(optarg, - _("failed to parse number of zones")); - break; - case 'z': - zsector = strtosize_or_err(optarg, - _("failed to parse zone offset")); - break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; - default: - usage(stderr); - break; - } - } - - if (optind == argc) - errx(EXIT_FAILURE, _("no device specified")); - - path = argv[optind++]; - - if (optind != argc) { - warnx(_("unexpected number of arguments")); - usage(stderr); - } - - zsize = blkdev_chunk_sectors(path); - if (zsize == 0) - err(EXIT_FAILURE, _("%s: Unable to determine zone size"), path); - - fd = open(path, O_WRONLY); - if (fd < 0) - err(EXIT_FAILURE, _("cannot open %s"), path); - - if (fstat(fd, &sb) == -1) - err(EXIT_FAILURE, _("stat of %s failed"), path); - if (!S_ISBLK(sb.st_mode)) - errx(EXIT_FAILURE, _("%s: not a block device"), path); - - if (blkdev_get_sectors(fd, (unsigned long long *) &blksectors)) - err(EXIT_FAILURE, _("%s: blkdev_get_sectors ioctl failed"), path); - - /* check offset alignment to the chunk size */ - if (zsector & (zsize - 1)) - errx(EXIT_FAILURE, _("%s: zone %" PRIu64 " is not aligned " - "to zone size %" PRIu64), path, zsector, zsize); - if (zsector > blksectors) - errx(EXIT_FAILURE, _("%s: offset is greater than device size"), path); - - zlen = zcount * zsize; - if (zsector + zlen > blksectors) - zlen = blksectors - zsector; - - za.sector = zsector; - za.nr_sectors = zlen; - rc = ioctl(fd, BLKRESETZONE, &za); - if (rc == -1) - err(EXIT_FAILURE, _("%s: BLKRESETZONE ioctl failed"), path); - - close(fd); - return EXIT_SUCCESS; -} -- cgit v1.2.3-55-g7522