mirror of
https://github.com/kdave/btrfs-progs
synced 2025-01-14 17:50:58 +00:00
btrfs-progs: zoned: make it work without kernel support
There's a report that a system with 4.19 kernel fails boot because device scan exits with error. This is because zoned support is compiled in btrfs-progs but not in kernel. To make new progs and old kernels work, do a fallback when the zoned ioctl is not available, as if it were a non-zoned device. There is no other option, but this is safe at least for the device scan that would not error out. Any unaligned writes to a zoned device will fail as expected. Issue: #376 Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
9527bc0649
commit
6134973527
@ -488,9 +488,14 @@ size_t btrfs_sb_io(int fd, void *buf, off_t offset, int rw)
|
||||
/* Do not call ioctl(BLKGETZONESZ) on a regular file. */
|
||||
if ((stat_buf.st_mode & S_IFMT) == S_IFBLK) {
|
||||
ret = ioctl(fd, BLKGETZONESZ, &zone_size_sector);
|
||||
if (ret) {
|
||||
error("zoned: ioctl BLKGETZONESZ failed (%m)");
|
||||
exit(1);
|
||||
if (ret < 0) {
|
||||
if (errno == ENOTTY) {
|
||||
/* No kernel support, assuming non-zoned device */
|
||||
zone_size_sector = 0;
|
||||
} else {
|
||||
error("zoned: ioctl BLKGETZONESZ failed: %m");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
zone_size_sector = 0;
|
||||
@ -528,7 +533,11 @@ size_t btrfs_sb_io(int fd, void *buf, off_t offset, int rw)
|
||||
|
||||
ret = ioctl(fd, BLKREPORTZONE, rep);
|
||||
if (ret) {
|
||||
error("zoned: ioctl BLKREPORTZONE failed (%m)");
|
||||
if (errno == ENOTTY) {
|
||||
error("zoned: BLKREPORTZONE failed but BLKGETZONESZ works: %m");
|
||||
exit(1);
|
||||
}
|
||||
error("zoned: ioctl BLKREPORTZONE failed: %m");
|
||||
exit(1);
|
||||
}
|
||||
if (rep->nr_zones != 2) {
|
||||
|
Loading…
Reference in New Issue
Block a user