Add blkzonecmd and blkreport ZAC/ZBC drives
Subsystems (2)
PATCH 1/1 Add blkzonecmd and blkreport ZAC/ZBC drives
This patch adds:
- blkreset to issue Reset (Write Pointer) zone commands
- blkreport to retrieve drive zone information
---
Changes for v2:
- Configure changes to require linux/blkzoned.h [Linux v4.10]
- Cleanup of man pages
- Removed redundant fall-back for missing linux/blkzoned.h
- Removed unused report option (not yet implemented by Linux kernel.
- Change report length to be (maximum) number of zones returned.
--- .gitignore | 2 + configure.ac | 11 +++ include/strutils.h | 2 + lib/strutils.c | 7 +- sys-utils/Makemodule.am | 17 ++++ sys-utils/blkreport.8 | 68 ++++++++++++++ sys-utils/blkreport.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++ sys-utils/blkreset.8 | 61 ++++++++++++ sys-utils/blkreset.c | 192 +++++++++++++++++++++++++++++++++++++ 9 files changed, 600 insertions(+), 5 deletions(-) create mode 100644 sys-utils/blkreport.8 create mode 100644 sys-utils/blkreport.c create mode 100644 sys-utils/blkreset.8 create mode 100644 sys-utils/blkreset.c
.gitignore +2 -0
@@ -62,6 +62,8 @@ update.log /addpart /agetty /blkdiscard +/blkreport +/blkreset /blkid /blockdev /cal
configure.ac +11 -0
@@ -276,6 +276,8 @@ AC_CHECK_HEADERS([security/pam_misc.h], #endif ]) +AC_CHECK_HEADERS([linux/blkzoned.h]) + AC_CHECK_HEADERS([security/openpam.h], [], [], [ #ifdef HAVE_SECURITY_PAM_APPL_H #include <security/pam_appl.h>
@@ -288,6 +290,7 @@ AC_CHECK_HEADERS([langinfo.h], dnl Convert some ac_cv_header_* variables to have_* dnl +have_linux_blkzoned_h=$ac_cv_header_linux_blkzoned_h have_linux_btrfs_h=$ac_cv_header_linux_btrfs_h have_linux_raw_h=$ac_cv_header_linux_raw_h have_linux_securebits_h=$ac_cv_header_linux_securebits_h
@@ -1564,6 +1567,14 @@ UL_BUILD_INIT([blkdiscard], [check]) UL_REQUIRES_LINUX([blkdiscard]) AM_CONDITIONAL([BUILD_BLKDISCARD], [test "x$build_blkdiscard" = 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])
include/strutils.h +2 -0
@@ -26,10 +26,12 @@ extern uint16_t strtox16_or_err(const char *str, const char *errmesg);extern int32_t strtos32_or_err (const char *str,const char *errmesg);extern uint32_t strtou32_or_err (const char *str,const char *errmesg);extern uint32_t strtox32_or_err (const char *str,const char *errmesg); +extern uint32_t _strtou32_or_err (const char *str,const char *errmesg,int base);extern int64_t strtos64_or_err (const char *str,const char *errmesg);extern uint64_t strtou64_or_err (const char *str,const char *errmesg);extern uint64_t strtox64_or_err (const char *str,const char *errmesg); +extern uint64_t _strtou64_or_err (const char *str,const char *errmesg,int base);extern double strtod_or_err (const char *str,const char *errmesg);
lib/strutils.c +2 -5
@@ -264,9 +264,6 @@ char *strndup(const char *s, size_t n) }#endif -static uint32_t _strtou32_or_err (const char *str,const char *errmesg,int base); -static uint64_t _strtou64_or_err (const char *str,const char *errmesg,int base); -int16_t strtos16_or_err (const char *str,const char *errmesg) {int32_t num =strtos32_or_err (str, errmesg);
@@ -310,7 +307,7 @@ int32_t strtos32_or_err(const char *str, const char *errmesg)return num; } -static uint32_t _strtou32_or_err (const char *str,const char *errmesg,int base) +uint32_t _strtou32_or_err (const char *str,const char *errmesg,int base) {uint64_t num =_strtou64_or_err (str, errmesg, base);
@@ -352,7 +349,7 @@ err:errx (STRTOXX_EXIT_CODE ,"%s: '%s'" , errmesg, str); } -static uint64_t _strtou64_or_err (const char *str,const char *errmesg,int base) +uint64_t _strtou64_or_err (const char *str,const char *errmesg,int base) {uintmax_t num;char *end =NULL ;
sys-utils/Makemodule.am +17 -0
@@ -126,6 +126,23 @@ blkdiscard_SOURCES = sys-utils/blkdiscard.c lib/monotonic.c blkdiscard_LDADD = $(LDADD) libcommon.la $(REALTIME_LIBS) 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) +if HAVE_UDEV +blkreset_LDADD += -ludev +endif +endif + if BUILD_LDATTACH usrsbin_exec_PROGRAMS += ldattach dist_man_MANS += sys-utils/ldattach.8
sys-utils/blkreport.8 new file +68 -0
68 lines not on this page · raw message
sys-utils/blkreport.c new file +245 -0
245 lines not on this page · raw message
sys-utils/blkreset.8 new file +61 -0
61 lines not on this page · raw message
sys-utils/blkreset.c new file +192 -0
192 lines not on this page · raw message
Signature · 1 line
2.7.4
Shaun,
Quoted 3 lines · Shaun Tancheff
+++
b/sys-utils/blkreset.c(quoted diff) +1
-0@@ -0,0 +1,192 @@ +/*
[...]
sys-utils/blkreset.c line 170
Quoted 5 lines
sys-utils/blkreset.c new file +5
-0+ +if (ioctl (fd,BLKGETSIZE64 , &blksize)) +err (EXIT_FAILURE ,_ ("%s: BLKGETSIZE64 ioctl failed" ), path); + + blksectors = blksize <<9 ;
blksize being in bytes here, it looks like the shift is in the wrong direction here... i.e.
blksectors = blksize >> 9;
Quoted 13 lines
sys-utils/blkreset.c new file +12
-0+ +/* 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: zone %" PRIu64" is too large " +"for device %" PRIu64), path, zsector, blksectors); + + zlen = zcount * zsize; +if (zsector + zlen > blksectors) + zlen = blksectors - zsector;
sys-utils/blkreset.c line 192
Quoted 10 lines
sys-utils/blkreset.c new file +10
-0+ + 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 ; +}
Best regards.
Signature · 7 lines
Damien Le Moal, Ph.D. Sr Manager, System Software Research Group, Western Digital [email protected] Tel: (+81) 0466-98-3593 (Ext. 51-3593) 1 kirihara-cho, Fujisawa, Kanagawa, 252-0888 Japan www.wdc.com, www.hgst.com
Karel Zak
maintainerQuoted 16 lines · Damien Le Moal
Shaun,
Quoted 3 lines · Shaun Tancheff
+++
b/sys-utils/blkreset.c(quoted diff) +1
-0@@ -0,0 +1,192 @@ +/*[...]
sys-utils/blkreset.c line 170
Quoted 5 lines
sys-utils/blkreset.c new file +5
-0+ +if (ioctl (fd,BLKGETSIZE64 , &blksize)) +err (EXIT_FAILURE ,_ ("%s: BLKGETSIZE64 ioctl failed" ), path); + + blksectors = blksize <<9 ;blksize being in bytes here, it looks like the shift is in the wrong direction here... i.e.
Quoted 1 line
blksectors = blksize >> 9;
The ideal solution would be to avoid the ioctl and use blkdev_get_sectors() or blkdev_get_size() from include/blkdev.h
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
On Mon, Jan 23, 2017 at 2:38 PM, Damien Le Moal <[email protected]> wro= te:
Quoted 10 lines
Shaun,
Quoted 3 lines · Shaun Tancheff
+++
b/sys-utils/blkreset.c(quoted diff) +1
-0@@ -0,0 +1,192 @@ +/*[...]
Quoted 3 lines
sys-utils/blkreport.c new file +3
-0+ +if (ioctl (fd,BLKGETSIZE64 , &blksize)) + err(EXIT_FAILURE, _("%s: BLKGETSIZE64 ioctl failed"), path=
);
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + blksectors =3D blksize << 9;blksize being in bytes here, it looks like the shift is in the wrong direction here... i.e.
blksectors =3D blksize >> 9;
Good catch!
Reposting with Karel's suggestion to use blkdev_get_sectors().
Thanks!
Quoted 4 lines
sys-utils/blkreset.c
Quoted 4 lines
sys-utils/blkreset.c new file +4
-0+ +/* check offset alignment to the chunk size */ +if (zsector & (zsize -1 )) + errx(EXIT_FAILURE, _("%s: zone %" PRIu64 " is not aligned =
"
Quoted 4 lines
sys-utils/blkreset.c
Quoted 4 lines
sys-utils/blkreset.c new file +4
-0+ "to zone size %" PRIu64), path, zsector, zsize); +if (zsector > blksectors) +errx (EXIT_FAILURE ,_ ("%s: zone %" PRIu64" is too large " + "for device %" PRIu64), path, zsector, blksectors=
);
Quoted 10 lines
Review
Quoted 10 lines
(quoted diff) +10
-0+ + zlen =3D zcount * zsize; + if (zsector + zlen > blksectors) + zlen =3D blksectors - zsector; + + za.sector =3D zsector; + za.nr_sectors =3D zlen; + rc =3D ioctl(fd, BLKRESETZONE, &za); + if (rc =3D=3D -1) + err(EXIT_FAILURE, _("%s: BLKRESETZONE ioctl failed"), path=
);
Quoted 8 lines
sys-utils/blkreport.c line 245
Quoted 5 lines
sys-utils/blkreport.c new file +4
-0+ +close (fd); +return EXIT_SUCCESS ; +}Best regards.
Quoted 9 lines
--
Damien Le Moal, Ph.D.
Sr Manager, System Software Research Group,
Western Digital
[email protected]
Tel: (+81) 0466-98-3593 (Ext. 51-3593)
1 kirihara-cho, Fujisawa, Kanagawa, 252-0888 Japan www.wdc.com, www.hgst.com
Western Digital Corporation (and its subsidiaries) E-mail Confidentiality=
Notice & Disclaimer:
Quoted 2 lines
This e-mail and any files transmitted with it may contain confidential or=
legally privileged information of WDC and/or its affiliates, and are inten=
ded solely for the use of the individual or entity to which they are addres= sed. If you are not the intended recipient, any disclosure, copying, distri= bution or any action taken or omitted to be taken in reliance on it, is pro= hibited. If you have received this e-mail in error, please notify the sende= r immediately and delete the e-mail in its entirety from your system.