libbtrfsutil: don't close fd on error in btrfs_util_subvolume_id_fd()
The caller owns the fd passed to btrfs_util_subvolume_id_fd(), so we shouldn't close it on error. Fix it, add a regression test, and bump the library patch version. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
5ca28fc25f
commit
cba6bae15d
|
@ -27,7 +27,7 @@
|
|||
|
||||
#define BTRFS_UTIL_VERSION_MAJOR 1
|
||||
#define BTRFS_UTIL_VERSION_MINOR 1
|
||||
#define BTRFS_UTIL_VERSION_PATCH 0
|
||||
#define BTRFS_UTIL_VERSION_PATCH 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -64,6 +64,18 @@ class TestSubvolume(BtrfsTestCase):
|
|||
with self.subTest(type=type(arg)):
|
||||
self.assertEqual(btrfsutil.subvolume_id(arg), 5)
|
||||
|
||||
def test_subvolume_id_error(self):
|
||||
fd = os.open('/dev/null', os.O_RDONLY)
|
||||
try:
|
||||
btrfsutil.subvolume_id(fd)
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
# btrfs_util_subvolume_id_fd() had a bug that would erroneously
|
||||
# close the provided file descriptor. In that case, this will fail
|
||||
# with EBADF.
|
||||
os.close(fd)
|
||||
|
||||
def test_subvolume_path(self):
|
||||
btrfsutil.create_subvolume(os.path.join(self.mountpoint, 'subvol1'))
|
||||
os.mkdir(os.path.join(self.mountpoint, 'dir1'))
|
||||
|
|
|
@ -122,10 +122,8 @@ PUBLIC enum btrfs_util_error btrfs_util_subvolume_id_fd(int fd,
|
|||
int ret;
|
||||
|
||||
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
|
||||
if (ret == -1) {
|
||||
close(fd);
|
||||
if (ret == -1)
|
||||
return BTRFS_UTIL_ERROR_INO_LOOKUP_FAILED;
|
||||
}
|
||||
|
||||
*id_ret = args.treeid;
|
||||
|
||||
|
|
Loading…
Reference in New Issue