Skip to content

Commit

Permalink
Add wrapper for Linux BLKFLSBUF ioctl
Browse files Browse the repository at this point in the history
FreeBSD has no analog. Buffered block devices were removed a decade
plus ago.

Reviewed-by: Igor Kozhukhov <igor@dilos.org>
Reviewed-by: Jorgen Lundman <lundman@lundman.net>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Matt Macy <mmacy@FreeBSD.org>
Closes #9508
  • Loading branch information
mattmacy authored and behlendorf committed Oct 28, 2019
1 parent 4a22ba5 commit d46f0de
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
1 change: 1 addition & 0 deletions include/libzutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

Expand Down
6 changes: 6 additions & 0 deletions lib/libzutil/os/linux/zutil_import_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit d46f0de

Please sign in to comment.