mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-04 23:29:20 +00:00
btrfs-progs: fi usage: improved error handling in load_device_info
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
5b16054958
commit
7febbc9efe
@ -535,7 +535,11 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0, ndevs = 0 ; i <= fi_args.max_id ; i++) {
|
for (i = 0, ndevs = 0 ; i <= fi_args.max_id ; i++) {
|
||||||
BUG_ON(ndevs >= fi_args.num_devices);
|
if (ndevs >= fi_args.num_devices) {
|
||||||
|
error("unexpected number of devices: %d >= %llu", ndevs,
|
||||||
|
(unsigned long long)fi_args.num_devices);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
memset(&dev_info, 0, sizeof(dev_info));
|
memset(&dev_info, 0, sizeof(dev_info));
|
||||||
ret = get_device_info(fd, i, &dev_info);
|
ret = get_device_info(fd, i, &dev_info);
|
||||||
|
|
||||||
@ -543,8 +547,7 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
|
|||||||
continue;
|
continue;
|
||||||
if (ret) {
|
if (ret) {
|
||||||
error("cannot get info about device devid=%d", i);
|
error("cannot get info about device devid=%d", i);
|
||||||
free(info);
|
goto out;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info[ndevs].devid = dev_info.devid;
|
info[ndevs].devid = dev_info.devid;
|
||||||
@ -559,7 +562,12 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
|
|||||||
++ndevs;
|
++ndevs;
|
||||||
}
|
}
|
||||||
|
|
||||||
BUG_ON(ndevs != fi_args.num_devices);
|
if (ndevs != fi_args.num_devices) {
|
||||||
|
error("unexpected number of devices: %d != %llu", ndevs,
|
||||||
|
(unsigned long long)fi_args.num_devices);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
qsort(info, fi_args.num_devices,
|
qsort(info, fi_args.num_devices,
|
||||||
sizeof(struct device_info), cmp_device_info);
|
sizeof(struct device_info), cmp_device_info);
|
||||||
|
|
||||||
@ -567,6 +575,10 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
|
|||||||
*device_info_ptr = info;
|
*device_info_ptr = info;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
out:
|
||||||
|
free(info);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int load_chunk_and_device_info(int fd, struct chunk_info **chunkinfo,
|
int load_chunk_and_device_info(int fd, struct chunk_info **chunkinfo,
|
||||||
|
Loading…
Reference in New Issue
Block a user