btrfs-progs: reserve < 0 return value for errnos
PATCH 1/1 btrfs-progs: reserve < 0 return value for errnos
btrfs_read_dev_super() returns -1 upon not finding a suitable SB, change that to return 1 instead, so that it can reserve the < 0 values for the errno communications.
---
An independent patch, not related to any recent patch sent to ML.
disk-io.c | 2 +- utils.c | 2 +- volumes.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
disk-io.c +1 -1
@@ -1491,7 +1491,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr, } } -return transid >0 ?0 :-1 ; +return transid >0 ?0 :1 ; } static int write_dev_supers(struct btrfs_fs_info *fs_info,
utils.c +1 -1
@@ -1678,7 +1678,7 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args, disk_super = (struct btrfs_super_block *)buf; ret =btrfs_read_dev_super (fd, disk_super,BTRFS_SUPER_INFO_OFFSET ,0 ); -if (ret <0 ) { +if (ret) { ret = -EIO ; goto out; }
volumes.c +1 -1
@@ -268,7 +268,7 @@ int btrfs_scan_one_device(int fd, const char *path, disk_super = (struct btrfs_super_block *)buf; ret =btrfs_read_dev_super (fd, disk_super, super_offset, sbflags); -if (ret <0 ) +if (ret)return -EIO ; devid =btrfs_stack_device_id (&disk_super->dev_item);if (btrfs_super_flags (disk_super) &BTRFS_SUPER_FLAG_METADUMP )
Signature · 1 line
2.13.1
Nikolay Borisov
NAKQuoted 5 lines · Anand Jain
btrfs_read_dev_super()returns -1 upon not finding a suitable SB, change that to return 1 instead, so that it can reserve the < 0 values for the errno communications.Signed-off-by Anand Jain <[email protected]>
I believe this is buggy since it will be masking errors. We call btrfs_read_dev_super in open_ctree_with_broken_chunk if the function returns 1 we eventually exit as: return ERR_PTR(ret); And then perform IS_ERR on the returned value. IS_ERR is essentially:
((x) >= (unsigned long)-MAX_ERRNO) where x could be 1 and MAX_ERRNO is 4095
So you just broke all functions which return the ret of btrfs_read_dev_super as ERR_PTR.
NAK
Quoted 48 lines
---
An independent patch, not related to any recent patch sent to ML.disk-io.c | 2 +- utils.c | 2 +- volumes.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)disk-io.c +1
-1@@ -1491,7 +1491,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr, } } -return transid >0 ?0 :-1 ; +return transid >0 ?0 :1 ; } static int write_dev_supers(struct btrfs_fs_info *fs_info,utils.c +1
-1@@ -1678,7 +1678,7 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args, disk_super = (struct btrfs_super_block *)buf; ret =btrfs_read_dev_super (fd, disk_super,BTRFS_SUPER_INFO_OFFSET ,0 ); -if (ret <0 ) { +if (ret) { ret = -EIO ; goto out; }volumes.c +1
-1@@ -268,7 +268,7 @@ int btrfs_scan_one_device(int fd, const char *path, disk_super = (struct btrfs_super_block *)buf; ret =btrfs_read_dev_super (fd, disk_super, super_offset, sbflags); -if (ret <0 ) +if (ret)return -EIO ; devid =btrfs_stack_device_id (&disk_super->dev_item);if (btrfs_super_flags (disk_super) &BTRFS_SUPER_FLAG_METADUMP )
Quoted 15 lines · Nikolay Borisov
Quoted 5 lines · Anand Jain
btrfs_read_dev_super()returns -1 upon not finding a suitable SB, change that to return 1 instead, so that it can reserve the < 0 values for the errno communications.Signed-off-by Anand Jain <[email protected]>I believe this is buggy since it will be masking errors. We call
btrfs_read_dev_superinopen_ctree_with_broken_chunkif the function returns 1 we eventually exit as: returnERR_PTR(ret); And then performIS_ERRon the returned value.IS_ERRis essentially:
((x) >= (unsigned long)-MAX_ERRNO) where x could be 1 andMAX_ERRNOis 4095
Quoted 5 lines
So you just broke all functions which return the ret of
btrfs_read_dev_superasERR_PTR.NAK
This doesn't looks good to me either.
No suitable superblock is already an error.
Why not just returning -ENOENT and let caller who really needs to distinguish this to catch that -ENOENT?
Thanks,
Qu
Quoted 54 lines
Quoted 41 lines
---
An independent patch, not related to any recent patch sent to ML.disk-io.c | 2 +- utils.c | 2 +- volumes.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)disk-io.c +1
-1@@ -1491,7 +1491,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr, } } -return transid >0 ?0 :-1 ; +return transid >0 ?0 :1 ; } static int write_dev_supers(struct btrfs_fs_info *fs_info,utils.c +1
-1@@ -1678,7 +1678,7 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args, disk_super = (struct btrfs_super_block *)buf; ret =btrfs_read_dev_super (fd, disk_super,BTRFS_SUPER_INFO_OFFSET ,0 ); -if (ret <0 ) { +if (ret) { ret = -EIO ; goto out; }volumes.c +0
-0volumes.c int btrfs_scan_one_device(int fd, const char *path, · line 274
Quoted 8 lines
volumes.c +1
-1@@ -268,7 +268,7 @@ int btrfs_scan_one_device(int fd, const char *path, disk_super = (struct btrfs_super_block *)buf; ret =btrfs_read_dev_super (fd, disk_super, super_offset, sbflags); -if (ret <0 ) +if (ret)return -EIO ; devid =btrfs_stack_device_id (&disk_super->dev_item);if (btrfs_super_flags (disk_super) &BTRFS_SUPER_FLAG_METADUMP )--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 22 lines · Qu Wenruo
Quoted 19 lines · Nikolay Borisov
Quoted 5 lines · Anand Jain
btrfs_read_dev_super()returns -1 upon not finding a suitable SB, change that to return 1 instead, so that it can reserve the < 0 values for the errno communications.Signed-off-by Anand Jain <[email protected]>I believe this is buggy since it will be masking errors. We call
btrfs_read_dev_superinopen_ctree_with_broken_chunkif the function returns 1 we eventually exit as: returnERR_PTR(ret); And then performIS_ERRon the returned value.IS_ERRis essentially:
((x) >= (unsigned long)-MAX_ERRNO) where x could be 1 andMAX_ERRNOis 4095So you just broke all functions which return the ret of
btrfs_read_dev_superasERR_PTR.
Quoted 7 lines
Quoted 1 line
NAK
This doesn't looks good to me either.
No suitable superblock is already an error.
Why not just returning-ENOENTand let caller who really needs to distinguish this to catch that-ENOENT?
Thanks for pointing out. Will fix it. IMO, -ENOENT is good for now.
(Though the actual cleanup would be to..
There are two parts in btrfs_read_dev_super() one to read only the BTRFS_SUPER_INFO_OFFSET SB. And the other to pick the latest SB by generation #. So splitting them two separate functions will let us know where do we use what in a much clearer way. And for 2nd pread64 we should probably use errno.)
Thanks, Anand
Quoted 58 lines
Thanks,
QuQuoted 54 lines
Quoted 41 lines
---
An independent patch, not related to any recent patch sent to ML.disk-io.c | 2 +- utils.c | 2 +- volumes.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)disk-io.c +1
-1@@ -1491,7 +1491,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr, } } -return transid >0 ?0 :-1 ; +return transid >0 ?0 :1 ; } static int write_dev_supers(struct btrfs_fs_info *fs_info,utils.c +1
-1@@ -1678,7 +1678,7 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args, disk_super = (struct btrfs_super_block *)buf; ret =btrfs_read_dev_super (fd, disk_super,BTRFS_SUPER_INFO_OFFSET ,0 ); -if (ret <0 ) { +if (ret) { ret = -EIO ; goto out; }volumes.c +0
-0volumes.c int btrfs_scan_one_device(int fd, const char *path, · line 274
Quoted 8 lines
volumes.c +1
-1@@ -268,7 +268,7 @@ int btrfs_scan_one_device(int fd, const char *path, disk_super = (struct btrfs_super_block *)buf; ret =btrfs_read_dev_super (fd, disk_super, super_offset, sbflags); -if (ret <0 ) +if (ret)return -EIO ; devid =btrfs_stack_device_id (&disk_super->dev_item);if (btrfs_super_flags (disk_super) &BTRFS_SUPER_FLAG_METADUMP )--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 1/1 btrfs-progs: reserve < 0 return value for errnos
In reply to Anand Jainbtrfs_read_dev_super() returns -1 / -EPERM upon not finding a suitable SB, change that to return -ENOENT instead, which is much closer to the actual possible errors.
---
v2: use -ENOENT instead of 1.
disk-io.c | 2 +- utils.c | 2 +- volumes.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
disk-io.c +1 -1
@@ -1491,7 +1491,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr, } } -return transid >0 ?0 :-1 ; +return transid >0 ?0 : -ENOENT ; } static int write_dev_supers(struct btrfs_fs_info *fs_info,
utils.c +1 -1
@@ -1678,7 +1678,7 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args, disk_super = (struct btrfs_super_block *)buf; ret =btrfs_read_dev_super (fd, disk_super,BTRFS_SUPER_INFO_OFFSET ,0 ); -if (ret <0 ) { +if (ret) { ret = -EIO ; goto out; }
volumes.c +1 -1
@@ -268,7 +268,7 @@ int btrfs_scan_one_device(int fd, const char *path, disk_super = (struct btrfs_super_block *)buf; ret =btrfs_read_dev_super (fd, disk_super, super_offset, sbflags); -if (ret <0 ) +if (ret)return -EIO ; devid =btrfs_stack_device_id (&disk_super->dev_item);if (btrfs_super_flags (disk_super) &BTRFS_SUPER_FLAG_METADUMP )
Signature · 1 line
2.13.1