From d46f0deb035bd26840dc6284fc6e1bb392097c92 Mon Sep 17 00:00:00 2001 From: Matthew Macy Date: Mon, 28 Oct 2019 09:53:39 -0700 Subject: [PATCH] Add wrapper for Linux BLKFLSBUF ioctl FreeBSD has no analog. Buffered block devices were removed a decade plus ago. Reviewed-by: Igor Kozhukhov Reviewed-by: Jorgen Lundman Reviewed-by: Brian Behlendorf Signed-off-by: Matt Macy Closes #9508 --- cmd/zdb/zdb.c | 2 +- cmd/zpool/zpool_main.c | 2 +- include/libzutil.h | 1 + lib/libzutil/os/linux/zutil_import_os.c | 6 ++++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index dd8e652d9a..7c3ef3ef4b 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -3444,7 +3444,7 @@ dump_label(const char *dev) exit(1); } - if (S_ISBLK(statbuf.st_mode) && ioctl(fd, BLKFLSBUF) != 0) + if (S_ISBLK(statbuf.st_mode) && zfs_dev_flush(fd) != 0) (void) printf("failed to invalidate cache '%s' : %s\n", path, strerror(errno)); diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index 6071babfd0..0ac8c2a5e4 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -1178,7 +1178,7 @@ zpool_do_labelclear(int argc, char **argv) * fatal when the device does not support BLKFLSBUF as would be the * case for a file vdev. */ - if ((ioctl(fd, BLKFLSBUF) != 0) && (errno != ENOTTY)) + if ((zfs_dev_flush(fd) != 0) && (errno != ENOTTY)) (void) fprintf(stderr, gettext("failed to invalidate " "cache for %s: %s\n"), vdev, strerror(errno)); diff --git a/include/libzutil.h b/include/libzutil.h index 4a8df01324..e453e4feb6 100644 --- a/include/libzutil.h +++ b/include/libzutil.h @@ -103,6 +103,7 @@ extern int zfs_strcmp_pathname(const char *, const char *, int); extern boolean_t zfs_dev_is_dm(const char *); extern boolean_t zfs_dev_is_whole_disk(const char *); +extern int zfs_dev_flush(int); extern char *zfs_get_underlying_path(const char *); extern char *zfs_get_enclosure_sysfs_path(const char *); diff --git a/lib/libzutil/os/linux/zutil_import_os.c b/lib/libzutil/os/linux/zutil_import_os.c index e51004edc6..a4bf01749d 100644 --- a/lib/libzutil/os/linux/zutil_import_os.c +++ b/lib/libzutil/os/linux/zutil_import_os.c @@ -92,6 +92,12 @@ is_watchdog_dev(char *dev) return (B_FALSE); } +int +zfs_dev_flush(int fd) +{ + return (ioctl(fd, BLKFLSBUF)); +} + void zpool_open_func(void *arg) {