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 <kreijack@libero.it>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Goffredo Baroncelli 2024-02-08 21:19:21 +01:00 committed by David Sterba
parent 372c79e7ad
commit 43dbe63dba
4 changed files with 8 additions and 14 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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;
}

View File

@ -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);