From 43dbe63dba6614d59bbcd3dc526038bafdc86834 Mon Sep 17 00:00:00 2001 From: Goffredo Baroncelli Date: Thu, 8 Feb 2024 21:19:21 +0100 Subject: [PATCH] btrfs-progs: replace btrfs_open_dir with btrfs_open_dir_fd For historical reasons the helpers [btrfs_]open_dir... return also the 'DIR *dirstream' value when a directory is opened. However this is never used. So avoid calling diropen() and return only the fd. Replace the last btrfs_open_dir() call with btrfs_open_dir_fd() removing any reference to the unused/useless dirstream variables. Also update the add_seen_fsid() function removing any reference to dir stream (again this is never used). Signed-off-by: Goffredo Baroncelli Signed-off-by: David Sterba --- cmds/filesystem.c | 4 ++-- cmds/subvolume.c | 8 +++----- common/device-scan.c | 6 ++---- common/device-scan.h | 4 +--- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/cmds/filesystem.c b/cmds/filesystem.c index 9aea5b20..fc78c557 100644 --- a/cmds/filesystem.c +++ b/cmds/filesystem.c @@ -307,7 +307,7 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices, u64 devs_found = 0; u64 total; - if (add_seen_fsid(fs_devices->fsid, seen_fsid_hash, -1, NULL)) + if (add_seen_fsid(fs_devices->fsid, seen_fsid_hash, -1)) return; uuid_unparse(fs_devices->fsid, uuidbuf); @@ -352,7 +352,7 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, struct btrfs_ioctl_dev_info_args *tmp_dev_info; int ret; - ret = add_seen_fsid(fs_info->fsid, seen_fsid_hash, -1, NULL); + ret = add_seen_fsid(fs_info->fsid, seen_fsid_hash, -1); if (ret == -EEXIST) return 0; else if (ret) diff --git a/cmds/subvolume.c b/cmds/subvolume.c index cca73379..65582f67 100644 --- a/cmds/subvolume.c +++ b/cmds/subvolume.c @@ -374,7 +374,6 @@ static int cmd_subvolume_delete(const struct cmd_struct *cmd, int argc, char **a char *dupdname = NULL; char *dupvname = NULL; char *path = NULL; - DIR *dirstream = NULL; int commit_mode = 0; bool subvol_path_not_found = false; u8 fsid[BTRFS_FSID_SIZE]; @@ -498,7 +497,7 @@ again: if (subvolid > 0) dname = dupvname; - fd = btrfs_open_dir(dname, &dirstream, 1); + fd = btrfs_open_dir_fd(dname); if (fd < 0) { ret = 1; goto out; @@ -592,7 +591,7 @@ again: goto out; } - if (add_seen_fsid(fsid, seen_fsid_hash, fd, dirstream) == 0) { + if (add_seen_fsid(fsid, seen_fsid_hash, fd) == 0) { uuid_unparse(fsid, uuidbuf); pr_verbose(LOG_INFO, " new fs is found for '%s', fsid: %s\n", path, uuidbuf); @@ -606,10 +605,9 @@ again: } out: - close_file_or_dir(fd, dirstream); + close(fd); keep_fd: fd = -1; - dirstream = NULL; free(dupdname); free(dupvname); dupdname = NULL; diff --git a/common/device-scan.c b/common/device-scan.c index c1cd7266..c04c2388 100644 --- a/common/device-scan.c +++ b/common/device-scan.c @@ -313,8 +313,7 @@ int is_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[]) return 0; } -int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[], - int fd, DIR *dirstream) +int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[], int fd) { u8 hash = fsid[0]; int slot = hash % SEEN_FSID_HASH_SIZE; @@ -342,7 +341,6 @@ insert: alloc->next = NULL; memcpy(alloc->fsid, fsid, BTRFS_FSID_SIZE); alloc->fd = fd; - alloc->dirstream = dirstream; if (seen) seen->next = alloc; @@ -362,7 +360,7 @@ void free_seen_fsid(struct seen_fsid *seen_fsid_hash[]) seen = seen_fsid_hash[slot]; while (seen) { next = seen->next; - close_file_or_dir(seen->fd, seen->dirstream); + close(seen->fd); free(seen); seen = next; } diff --git a/common/device-scan.h b/common/device-scan.h index 1459ee36..1cc370b9 100644 --- a/common/device-scan.h +++ b/common/device-scan.h @@ -43,7 +43,6 @@ struct btrfs_trans_handle; struct seen_fsid { u8 fsid[BTRFS_FSID_SIZE]; struct seen_fsid *next; - DIR *dirstream; int fd; }; @@ -58,8 +57,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans, int btrfs_device_already_in_root(struct btrfs_root *root, int fd, int super_offset); int is_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[]); -int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[], - int fd, DIR *dirstream); +int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[], int fd); void free_seen_fsid(struct seen_fsid *seen_fsid_hash[]); int test_uuid_unique(const char *uuid_str);