diff mbox series

[3/9] Killing dirstream: replace btrfs_open_dir with btrfs_open_dir_fd

Message ID 9d7800b5c4b57f30333c0a93ff9d28dc8b387831.1707423567.git.kreijack@inwind.it (mailing list archive)
State New, archived
Headers show
Series Remove unused dirstream variable | expand

Commit Message

Goffredo Baroncelli Feb. 8, 2024, 8:19 p.m. UTC
From: Goffredo Baroncelli <kreijack@inwind.it>

For historical reason the helpers [btrfs_]open_dir... return also
the 'DIR *dirstream' value when a dir is opened.

However this is never used. So avoid calling diropen() and return
only the fd.

This patch replaces the last btrfs_open_dir() call with btrfs_open_dir_fd()
removing any reference to the unused/useless dirstream variables.

At the same time this patch updates the add_seen_fsid() function removing
any reference to dir stream (again this is never used).

Signed-off-by: Goffredo Baroncelli <kreijack@libero.it>
---
 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 mbox series

Patch

diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index 9867403f..d37b52a3 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 8a875832..90ec766d 100644
--- a/common/device-scan.h
+++ b/common/device-scan.h
@@ -41,7 +41,6 @@  struct btrfs_trans_handle;
 struct seen_fsid {
 	u8 fsid[BTRFS_FSID_SIZE];
 	struct seen_fsid *next;
-	DIR *dirstream;
 	int fd;
 };
 
@@ -56,8 +55,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);