mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-11 03:31:17 +00:00
btrfs-progs: handle EINVAL when reading zone size on older kernels
A combination of new progs and old kernel may lead to problems with detecting zone size by ioctl. Fixed by #376 but still incomplete because old kernels may return EINVAL for unsupported ioctl. This should be ENOTTY but hasn't been like that until kernel 5.11. As we always pass valid arguments to the ioctl we can't conflate the two and can EINVAL the same way as ENOTTY. Issue: #399 Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
61e00694e7
commit
96a5cf0719
@ -504,8 +504,14 @@ size_t btrfs_sb_io(int fd, void *buf, off_t offset, int rw)
|
||||
if ((stat_buf.st_mode & S_IFMT) == S_IFBLK) {
|
||||
ret = ioctl(fd, BLKGETZONESZ, &zone_size_sector);
|
||||
if (ret < 0) {
|
||||
if (errno == ENOTTY) {
|
||||
/* No kernel support, assuming non-zoned device */
|
||||
if (errno == ENOTTY || errno == EINVAL) {
|
||||
/*
|
||||
* No kernel support, assuming non-zoned device.
|
||||
*
|
||||
* Note: older kernels before 5.11 could return
|
||||
* EINVAL in case the ioctl is not available,
|
||||
* which is wrong.
|
||||
*/
|
||||
zone_size_sector = 0;
|
||||
} else {
|
||||
error("zoned: ioctl BLKGETZONESZ failed: %m");
|
||||
@ -548,7 +554,11 @@ size_t btrfs_sb_io(int fd, void *buf, off_t offset, int rw)
|
||||
|
||||
ret = ioctl(fd, BLKREPORTZONE, rep);
|
||||
if (ret) {
|
||||
if (errno == ENOTTY) {
|
||||
if (errno == ENOTTY || errno == EINVAL) {
|
||||
/*
|
||||
* Note: older kernels before 5.11 could return EINVAL
|
||||
* in case the ioctl is not available, which is wrong.
|
||||
*/
|
||||
error("zoned: BLKREPORTZONE failed but BLKGETZONESZ works: %m");
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user