btrfs-progs: remove unnecessary errno temp variables
We can read errno directly if it's not clobbered by any intermediate calls. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
374d67fdef
commit
633dc6f80f
|
@ -2822,9 +2822,8 @@ int main(int argc, char *argv[])
|
|||
OPEN_CTREE_PARTIAL |
|
||||
OPEN_CTREE_RESTORE);
|
||||
if (!info) {
|
||||
int e = errno;
|
||||
fprintf(stderr, "unable to open %s error = %s\n",
|
||||
target, strerror(e));
|
||||
target, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
26
btrfs-list.c
26
btrfs-list.c
|
@ -630,7 +630,7 @@ static int resolve_root(struct root_lookup *rl, struct root_info *ri,
|
|||
static int lookup_ino_path(int fd, struct root_info *ri)
|
||||
{
|
||||
struct btrfs_ioctl_ino_lookup_args args;
|
||||
int ret, e;
|
||||
int ret;
|
||||
|
||||
if (ri->path)
|
||||
return 0;
|
||||
|
@ -643,15 +643,14 @@ static int lookup_ino_path(int fd, struct root_info *ri)
|
|||
args.objectid = ri->dir_id;
|
||||
|
||||
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
|
||||
e = errno;
|
||||
if (ret) {
|
||||
if (e == ENOENT) {
|
||||
if (errno == ENOENT) {
|
||||
ri->ref_tree = 0;
|
||||
return -ENOENT;
|
||||
}
|
||||
fprintf(stderr, "ERROR: Failed to lookup path for root %llu - %s\n",
|
||||
(unsigned long long)ri->ref_tree,
|
||||
strerror(e));
|
||||
strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -694,18 +693,16 @@ static u64 find_root_gen(int fd)
|
|||
unsigned long off = 0;
|
||||
u64 max_found = 0;
|
||||
int i;
|
||||
int e;
|
||||
|
||||
memset(&ino_args, 0, sizeof(ino_args));
|
||||
ino_args.objectid = BTRFS_FIRST_FREE_OBJECTID;
|
||||
|
||||
/* this ioctl fills in ino_args->treeid */
|
||||
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &ino_args);
|
||||
e = errno;
|
||||
if (ret) {
|
||||
fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu - %s\n",
|
||||
(unsigned long long)BTRFS_FIRST_FREE_OBJECTID,
|
||||
strerror(e));
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -728,10 +725,9 @@ static u64 find_root_gen(int fd)
|
|||
|
||||
while (1) {
|
||||
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
|
||||
e = errno;
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ERROR: can't perform the search - %s\n",
|
||||
strerror(e));
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
/* the ioctl returns the number of item it found in nr_items */
|
||||
|
@ -785,16 +781,14 @@ static char *__ino_resolve(int fd, u64 dirid)
|
|||
struct btrfs_ioctl_ino_lookup_args args;
|
||||
int ret;
|
||||
char *full;
|
||||
int e;
|
||||
|
||||
memset(&args, 0, sizeof(args));
|
||||
args.objectid = dirid;
|
||||
|
||||
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
|
||||
e = errno;
|
||||
if (ret) {
|
||||
fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu - %s\n",
|
||||
(unsigned long long)dirid, strerror(e) );
|
||||
(unsigned long long)dirid, strerror(errno));
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
|
||||
|
@ -852,7 +846,6 @@ static char *ino_resolve(int fd, u64 ino, u64 *cache_dirid, char **cache_name)
|
|||
struct btrfs_ioctl_search_header *sh;
|
||||
unsigned long off = 0;
|
||||
int namelen;
|
||||
int e;
|
||||
|
||||
memset(&args, 0, sizeof(args));
|
||||
|
||||
|
@ -871,10 +864,9 @@ static char *ino_resolve(int fd, u64 ino, u64 *cache_dirid, char **cache_name)
|
|||
sk->nr_items = 1;
|
||||
|
||||
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
|
||||
e = errno;
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ERROR: can't perform the search - %s\n",
|
||||
strerror(e));
|
||||
strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
/* the ioctl returns the number of item it found in nr_items */
|
||||
|
@ -1686,7 +1678,6 @@ int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen)
|
|||
u64 found_gen;
|
||||
u64 max_found = 0;
|
||||
int i;
|
||||
int e;
|
||||
u64 cache_dirid = 0;
|
||||
u64 cache_ino = 0;
|
||||
char *cache_dir_name = NULL;
|
||||
|
@ -1713,10 +1704,9 @@ int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen)
|
|||
max_found = find_root_gen(fd);
|
||||
while(1) {
|
||||
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
|
||||
e = errno;
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ERROR: can't perform the search - %s\n",
|
||||
strerror(e));
|
||||
strerror(errno));
|
||||
break;
|
||||
}
|
||||
/* the ioctl returns the number of item it found in nr_items */
|
||||
|
|
|
@ -144,17 +144,15 @@ static int load_and_dump_sb(char *filename, int fd, u64 sb_bytenr, int full,
|
|||
|
||||
ret = pread64(fd, super_block_data, BTRFS_SUPER_INFO_SIZE, sb_bytenr);
|
||||
if (ret != BTRFS_SUPER_INFO_SIZE) {
|
||||
int e = errno;
|
||||
|
||||
/* check if the disk if too short for further superblock */
|
||||
if (ret == 0 && e == 0)
|
||||
if (ret == 0 && errno == 0)
|
||||
return 0;
|
||||
|
||||
fprintf(stderr,
|
||||
"ERROR: Failed to read the superblock on %s at %llu\n",
|
||||
filename, (unsigned long long)sb_bytenr);
|
||||
fprintf(stderr,
|
||||
"ERROR: error = '%s', errno = %d\n", strerror(e), e);
|
||||
"ERROR: error = '%s', errno = %d\n", strerror(errno), errno);
|
||||
return 1;
|
||||
}
|
||||
printf("superblock: bytenr=%llu, device=%s\n", sb_bytenr, filename);
|
||||
|
|
|
@ -49,7 +49,7 @@ static const char * const cmd_device_add_usage[] = {
|
|||
static int cmd_device_add(int argc, char **argv)
|
||||
{
|
||||
char *mntpnt;
|
||||
int i, fdmnt, ret=0, e;
|
||||
int i, fdmnt, ret = 0;
|
||||
DIR *dirstream = NULL;
|
||||
int discard = 1;
|
||||
int force = 0;
|
||||
|
@ -126,10 +126,9 @@ static int cmd_device_add(int argc, char **argv)
|
|||
memset(&ioctl_args, 0, sizeof(ioctl_args));
|
||||
strncpy_null(ioctl_args.name, path);
|
||||
res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
|
||||
e = errno;
|
||||
if (res < 0) {
|
||||
error("error adding device '%s': %s",
|
||||
path, strerror(e));
|
||||
path, strerror(errno));
|
||||
ret++;
|
||||
}
|
||||
free(path);
|
||||
|
@ -144,7 +143,7 @@ static int _cmd_device_remove(int argc, char **argv,
|
|||
const char * const *usagestr)
|
||||
{
|
||||
char *mntpnt;
|
||||
int i, fdmnt, ret=0, e;
|
||||
int i, fdmnt, ret = 0;
|
||||
DIR *dirstream = NULL;
|
||||
|
||||
if (check_argc_min(argc, 3))
|
||||
|
@ -168,14 +167,13 @@ static int _cmd_device_remove(int argc, char **argv,
|
|||
memset(&arg, 0, sizeof(arg));
|
||||
strncpy_null(arg.name, argv[i]);
|
||||
res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
|
||||
e = errno;
|
||||
if (res) {
|
||||
const char *msg;
|
||||
|
||||
if (res > 0)
|
||||
msg = btrfs_err_str(res);
|
||||
else
|
||||
msg = strerror(e);
|
||||
msg = strerror(errno);
|
||||
error("error removing device '%s': %s",
|
||||
argv[i], msg);
|
||||
ret++;
|
||||
|
|
|
@ -228,7 +228,7 @@ static int cmp_btrfs_ioctl_space_info(const void *a, const void *b)
|
|||
static struct btrfs_ioctl_space_args *load_space_info(int fd, char *path)
|
||||
{
|
||||
struct btrfs_ioctl_space_args *sargs = NULL, *sargs_orig = NULL;
|
||||
int e, ret, count;
|
||||
int ret, count;
|
||||
|
||||
sargs_orig = sargs = calloc(1, sizeof(struct btrfs_ioctl_space_args));
|
||||
if (!sargs) {
|
||||
|
@ -240,9 +240,9 @@ static struct btrfs_ioctl_space_args *load_space_info(int fd, char *path)
|
|||
sargs->total_spaces = 0;
|
||||
|
||||
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
|
||||
e = errno;
|
||||
if (ret) {
|
||||
error("cannot get space info on '%s': %s", path, strerror(e));
|
||||
error("cannot get space info on '%s': %s", path,
|
||||
strerror(errno));
|
||||
free(sargs);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -266,11 +266,9 @@ static struct btrfs_ioctl_space_args *load_space_info(int fd, char *path)
|
|||
sargs->total_spaces = 0;
|
||||
|
||||
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
|
||||
e = errno;
|
||||
|
||||
if (ret) {
|
||||
error("cannot get space info with %u slots: %s",
|
||||
count, strerror(e));
|
||||
count, strerror(errno));
|
||||
free(sargs);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ static const char * const cmd_filesystem_df_usage[] = {
|
|||
static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
|
||||
{
|
||||
u64 count = 0;
|
||||
int ret, e;
|
||||
int ret;
|
||||
struct btrfs_ioctl_space_args *sargs;
|
||||
|
||||
sargs = malloc(sizeof(struct btrfs_ioctl_space_args));
|
||||
|
@ -141,11 +141,10 @@ static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
|
|||
sargs->total_spaces = 0;
|
||||
|
||||
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
|
||||
e = errno;
|
||||
if (ret) {
|
||||
error("cannot get space info: %s\n", strerror(e));
|
||||
error("cannot get space info: %s\n", strerror(errno));
|
||||
free(sargs);
|
||||
return -e;
|
||||
return -errno;
|
||||
}
|
||||
/* This really should never happen */
|
||||
if (!sargs->total_spaces) {
|
||||
|
@ -163,12 +162,11 @@ static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
|
|||
sargs->space_slots = count;
|
||||
sargs->total_spaces = 0;
|
||||
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
|
||||
e = errno;
|
||||
if (ret) {
|
||||
error("cannot get space info with %llu slots: %s",
|
||||
count, strerror(e));
|
||||
count, strerror(errno));
|
||||
free(sargs);
|
||||
return -e;
|
||||
return -errno;
|
||||
}
|
||||
*sargs_ret = sargs;
|
||||
return 0;
|
||||
|
@ -995,7 +993,6 @@ static int defrag_callback(const char *fpath, const struct stat *sb,
|
|||
if (defrag_global_verbose)
|
||||
printf("%s\n", fpath);
|
||||
fd = open(fpath, O_RDWR);
|
||||
e = errno;
|
||||
if (fd < 0)
|
||||
goto error;
|
||||
ret = do_defrag(fd, defrag_global_fancy_ioctl, &defrag_global_range);
|
||||
|
|
|
@ -36,7 +36,6 @@ static int qgroup_assign(int assign, int argc, char **argv)
|
|||
{
|
||||
int ret = 0;
|
||||
int fd;
|
||||
int e;
|
||||
int rescan = 0;
|
||||
char *path;
|
||||
struct btrfs_ioctl_qgroup_assign_args args;
|
||||
|
@ -84,9 +83,8 @@ static int qgroup_assign(int assign, int argc, char **argv)
|
|||
return 1;
|
||||
|
||||
ret = ioctl(fd, BTRFS_IOC_QGROUP_ASSIGN, &args);
|
||||
e = errno;
|
||||
if (ret < 0) {
|
||||
error("unable to assign quota group: %s", strerror(e));
|
||||
error("unable to assign quota group: %s", strerror(errno));
|
||||
close_file_or_dir(fd, dirstream);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -539,13 +539,10 @@ static int set_file_xattrs(struct btrfs_root *root, u64 inode,
|
|||
len);
|
||||
data_len = len;
|
||||
|
||||
if (fsetxattr(fd, name, data, data_len, 0)) {
|
||||
int err = errno;
|
||||
|
||||
if (fsetxattr(fd, name, data, data_len, 0))
|
||||
fprintf(stderr,
|
||||
"Error setting extended attribute %s on file %s: %s\n",
|
||||
name, file_name, strerror(err));
|
||||
}
|
||||
name, file_name, strerror(errno));
|
||||
|
||||
len = sizeof(*di) + name_len + data_len;
|
||||
cur += len;
|
||||
|
|
|
@ -264,7 +264,7 @@ static const char * const cmd_subvol_delete_usage[] = {
|
|||
|
||||
static int cmd_subvol_delete(int argc, char **argv)
|
||||
{
|
||||
int res, e, ret = 0;
|
||||
int res, ret = 0;
|
||||
int cnt;
|
||||
int fd = -1;
|
||||
struct btrfs_ioctl_vol_args args;
|
||||
|
@ -355,10 +355,9 @@ again:
|
|||
memset(&args, 0, sizeof(args));
|
||||
strncpy_null(args.name, vname);
|
||||
res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
|
||||
e = errno;
|
||||
|
||||
if(res < 0 ){
|
||||
error("cannot delete '%s/%s': %s", dname, vname, strerror(e));
|
||||
error("cannot delete '%s/%s': %s", dname, vname,
|
||||
strerror(errno));
|
||||
ret = 1;
|
||||
goto out;
|
||||
}
|
||||
|
|
4
qgroup.c
4
qgroup.c
|
@ -1050,7 +1050,6 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup)
|
|||
struct btrfs_ioctl_search_header *sh;
|
||||
unsigned long off = 0;
|
||||
unsigned int i;
|
||||
int e;
|
||||
struct btrfs_qgroup_info_item *info;
|
||||
struct btrfs_qgroup_limit_item *limit;
|
||||
struct btrfs_qgroup *bq;
|
||||
|
@ -1075,11 +1074,10 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup)
|
|||
|
||||
while (1) {
|
||||
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
|
||||
e = errno;
|
||||
if (ret < 0) {
|
||||
fprintf(stderr,
|
||||
"ERROR: can't perform the search - %s\n",
|
||||
strerror(e));
|
||||
strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
/* the ioctl returns the number of item it found in nr_items */
|
||||
|
|
|
@ -545,7 +545,6 @@ int subvol_uuid_search_init(int mnt_fd, struct subvol_uuid_search *s)
|
|||
int root_item_valid = 0;
|
||||
unsigned long off = 0;
|
||||
int i;
|
||||
int e;
|
||||
char *path;
|
||||
|
||||
s->mnt_fd = mnt_fd;
|
||||
|
@ -579,10 +578,9 @@ int subvol_uuid_search_init(int mnt_fd, struct subvol_uuid_search *s)
|
|||
|
||||
while (1) {
|
||||
ret = ioctl(mnt_fd, BTRFS_IOC_TREE_SEARCH, &args);
|
||||
e = errno;
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ERROR: can't perform the search - %s\n",
|
||||
strerror(e));
|
||||
strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
if (sk->nr_items == 0)
|
||||
|
|
10
utils.c
10
utils.c
|
@ -1516,7 +1516,6 @@ int btrfs_register_one_device(const char *fname)
|
|||
struct btrfs_ioctl_vol_args args;
|
||||
int fd;
|
||||
int ret;
|
||||
int e;
|
||||
|
||||
fd = open("/dev/btrfs-control", O_RDWR);
|
||||
if (fd < 0) {
|
||||
|
@ -1528,11 +1527,10 @@ int btrfs_register_one_device(const char *fname)
|
|||
memset(&args, 0, sizeof(args));
|
||||
strncpy_null(args.name, fname);
|
||||
ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
|
||||
e = errno;
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ERROR: device scan failed '%s' - %s\n",
|
||||
fname, strerror(e));
|
||||
ret = -e;
|
||||
fname, strerror(errno));
|
||||
ret = -errno;
|
||||
}
|
||||
close(fd);
|
||||
return ret;
|
||||
|
@ -2696,17 +2694,15 @@ int lookup_ino_rootid(int fd, u64 *rootid)
|
|||
{
|
||||
struct btrfs_ioctl_ino_lookup_args args;
|
||||
int ret;
|
||||
int e;
|
||||
|
||||
memset(&args, 0, sizeof(args));
|
||||
args.treeid = 0;
|
||||
args.objectid = BTRFS_FIRST_FREE_OBJECTID;
|
||||
|
||||
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
|
||||
e = errno;
|
||||
if (ret) {
|
||||
fprintf(stderr, "ERROR: Failed to lookup root id - %s\n",
|
||||
strerror(e));
|
||||
strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue