* [PATCH 1/3] btrfs-progs: fix wrong data ratio for raid56 in btrfs-file-usage
@ 2014-07-24 3:21 Gui Hecheng
2014-07-24 3:21 ` [PATCH 2/3] btrfs-progs: output the correct path when fi-usage failed Gui Hecheng
2014-07-24 3:21 ` [PATCH 3/3] btrfs-progs: fix improper output msg for btrfs-fi-usage Gui Hecheng
0 siblings, 2 replies; 4+ messages in thread
From: Gui Hecheng @ 2014-07-24 3:21 UTC (permalink / raw)
To: linux-btrfs; +Cc: Gui Hecheng
When run btrfs-file-usage on a btrfs with data profile raid5/6,
the output message for "Free" & "Data to device ratio" seems wrong
as follows:
...
Device size: 100.00GiB
Device allocated: 2.04GiB
Device unallocated: 97.96GiB
Used: 1.12MiB
Free (Estimated): 197.89GiB <== Free > Device size
Data to device ratio: 198 % <== > 100%
Global reserve: 0.00B
...
It is because the function get_raid56_used() is not iterating the
chunk_info array correctly, it is just repeating adding the first
chunk_info statistics.
Just add a ptr to iterate over the array.
Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
cmds-fi-disk_usage.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/cmds-fi-disk_usage.c b/cmds-fi-disk_usage.c
index 453410f..78dc414 100644
--- a/cmds-fi-disk_usage.c
+++ b/cmds-fi-disk_usage.c
@@ -293,14 +293,16 @@ static struct btrfs_ioctl_space_args *load_space_info(int fd, char *path)
static void get_raid56_used(int fd, struct chunk_info *chunks, int chunkcount,
u64 *raid5_used, u64 *raid6_used)
{
+ struct chunk_info *info_ptr = chunks;
*raid5_used = 0;
*raid6_used = 0;
while (chunkcount-- > 0) {
- if (chunks->type & BTRFS_BLOCK_GROUP_RAID5)
- (*raid5_used) += chunks->size / (chunks->num_stripes - 1);
- if (chunks->type & BTRFS_BLOCK_GROUP_RAID6)
- (*raid6_used) += chunks->size / (chunks->num_stripes - 2);
+ if (info_ptr->type & BTRFS_BLOCK_GROUP_RAID5)
+ (*raid5_used) += info_ptr->size / (info_ptr->num_stripes - 1);
+ if (info_ptr->type & BTRFS_BLOCK_GROUP_RAID6)
+ (*raid6_used) += info_ptr->size / (info_ptr->num_stripes - 2);
+ info_ptr++;
}
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] btrfs-progs: output the correct path when fi-usage failed
2014-07-24 3:21 [PATCH 1/3] btrfs-progs: fix wrong data ratio for raid56 in btrfs-file-usage Gui Hecheng
@ 2014-07-24 3:21 ` Gui Hecheng
2014-07-24 3:27 ` [PATCH v2 " Gui Hecheng
2014-07-24 3:21 ` [PATCH 3/3] btrfs-progs: fix improper output msg for btrfs-fi-usage Gui Hecheng
1 sibling, 1 reply; 4+ messages in thread
From: Gui Hecheng @ 2014-07-24 3:21 UTC (permalink / raw)
To: linux-btrfs; +Cc: Gui Hecheng
When we exec the following cmd:
# btrfs file usage -t <path> <-- an invalid path
output:
# ERROR: can't access '-t'
should be:
# ERROR: can't access 'path'
Just replace the static 'argv[1]' with 'argv[i]'.
---
cmds-fi-disk_usage.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmds-fi-disk_usage.c b/cmds-fi-disk_usage.c
index 78dc414..1f4c88e 100644
--- a/cmds-fi-disk_usage.c
+++ b/cmds-fi-disk_usage.c
@@ -835,7 +835,7 @@ int cmd_filesystem_usage(int argc, char **argv)
fd = open_file_or_dir(argv[i], &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access '%s'\n",
- argv[1]);
+ argv[i]);
ret = 1;
goto out;
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] btrfs-progs: fix improper output msg for btrfs-fi-usage
2014-07-24 3:21 [PATCH 1/3] btrfs-progs: fix wrong data ratio for raid56 in btrfs-file-usage Gui Hecheng
2014-07-24 3:21 ` [PATCH 2/3] btrfs-progs: output the correct path when fi-usage failed Gui Hecheng
@ 2014-07-24 3:21 ` Gui Hecheng
1 sibling, 0 replies; 4+ messages in thread
From: Gui Hecheng @ 2014-07-24 3:21 UTC (permalink / raw)
To: linux-btrfs; +Cc: Gui Hecheng
Even if run as root:
# su
# btrfs file usage <path> <== path exits outside the mnt point
We get the output:
WARNING: ..., run as root
WARNING: ..., run as root
ERROR:...
It is because in load_chunk_info, the errno of ioctl is not judged
but rather the ret value of ioctl is judged. And the ret value of
ioctl is -1 which happens to match -EPERM exactly.
So the outer warning is printed.
Just judge the errno of ioctl and prevent the ret value of load_chunk_info
to be -1 in other error conditions.
For load_device_info, the problem and fix is the same.
After the fix, the 'run as root' WARNINGs will not show up in this condition.
Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
cmds-fi-disk_usage.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/cmds-fi-disk_usage.c b/cmds-fi-disk_usage.c
index 1f4c88e..7c5c0cc 100644
--- a/cmds-fi-disk_usage.c
+++ b/cmds-fi-disk_usage.c
@@ -156,14 +156,14 @@ static int load_chunk_info(int fd, struct chunk_info **info_ptr, int *info_count
while (1) {
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
e = errno;
- if (ret == -EPERM)
- return ret;
+ if (e == EPERM)
+ return -e;
if (ret < 0) {
fprintf(stderr,
"ERROR: can't perform the search - %s\n",
strerror(e));
- return ret;
+ return 1;
}
/* the ioctl returns the number of item it found in nr_items */
@@ -182,7 +182,7 @@ static int load_chunk_info(int fd, struct chunk_info **info_ptr, int *info_count
ret = add_info_to_list(info_ptr, info_count, item);
if (ret) {
*info_ptr = 0;
- return ret;
+ return 1;
}
off += sh->len;
@@ -442,7 +442,7 @@ static int cmp_device_info(const void *a, const void *b)
static int load_device_info(int fd, struct device_info **device_info_ptr,
int *device_info_count)
{
- int ret, i, ndevs;
+ int ret, i, ndevs, e;
struct btrfs_ioctl_fs_info_args fi_args;
struct btrfs_ioctl_dev_info_args dev_info;
struct device_info *info;
@@ -451,17 +451,19 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
*device_info_ptr = 0;
ret = ioctl(fd, BTRFS_IOC_FS_INFO, &fi_args);
- if (ret == -EPERM)
- return ret;
+ e = errno;
+ if (e == EPERM)
+ return -e;
if (ret < 0) {
- fprintf(stderr, "ERROR: cannot get filesystem info\n");
- return ret;
+ fprintf(stderr, "ERROR: cannot get filesystem info - %s\n",
+ strerror(e));
+ return 1;
}
info = calloc(fi_args.num_devices, sizeof(struct device_info));
if (!info) {
fprintf(stderr, "ERROR: not enough memory\n");
- return ret;
+ return 1;
}
for (i = 0, ndevs = 0 ; i <= fi_args.max_id ; i++) {
--
1.8.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] btrfs-progs: output the correct path when fi-usage failed
2014-07-24 3:21 ` [PATCH 2/3] btrfs-progs: output the correct path when fi-usage failed Gui Hecheng
@ 2014-07-24 3:27 ` Gui Hecheng
0 siblings, 0 replies; 4+ messages in thread
From: Gui Hecheng @ 2014-07-24 3:27 UTC (permalink / raw)
To: linux-btrfs; +Cc: Gui Hecheng
When we exec the following cmd:
# btrfs file usage -t <path> <-- an invalid path
output:
# ERROR: can't access '-t'
should be:
# ERROR: can't access 'path'
Just replace the static 'argv[1]' with 'argv[i]'.
Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
changelog
v1->v2: add missing signoff-by
---
cmds-fi-disk_usage.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmds-fi-disk_usage.c b/cmds-fi-disk_usage.c
index 78dc414..1f4c88e 100644
--- a/cmds-fi-disk_usage.c
+++ b/cmds-fi-disk_usage.c
@@ -835,7 +835,7 @@ int cmd_filesystem_usage(int argc, char **argv)
fd = open_file_or_dir(argv[i], &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access '%s'\n",
- argv[1]);
+ argv[i]);
ret = 1;
goto out;
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-24 3:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-24 3:21 [PATCH 1/3] btrfs-progs: fix wrong data ratio for raid56 in btrfs-file-usage Gui Hecheng
2014-07-24 3:21 ` [PATCH 2/3] btrfs-progs: output the correct path when fi-usage failed Gui Hecheng
2014-07-24 3:27 ` [PATCH v2 " Gui Hecheng
2014-07-24 3:21 ` [PATCH 3/3] btrfs-progs: fix improper output msg for btrfs-fi-usage Gui Hecheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).