* [PATCH] btrfs-progs: Fix the return value of btrfs_scan_kernel()
@ 2014-04-08 9:16 Qu Wenruo
2014-04-09 2:09 ` Anand Jain
0 siblings, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2014-04-08 9:16 UTC (permalink / raw)
To: linux-btrfs; +Cc: Anand Jain
btrfs_scan_kernel() is only used in 'btrfs fi show' but returns wrong
return value.
When search parameter is passed, it will never return 0 even the search
can be matched.
This patch will change the whatever strange logic to a more easy to
understand one using 'found' var.
Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Cc: Anand Jain <anand.jain@oracle.com>
---
cmds-filesystem.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index b81768b..49d3aa7 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -430,6 +430,7 @@ static int btrfs_scan_kernel_v2(void *search)
static int btrfs_scan_kernel(void *search)
{
int ret = 0, fd;
+ int found = 0;
FILE *f;
struct mntent *mnt;
struct btrfs_ioctl_fs_info_args fs_info_arg;
@@ -452,7 +453,6 @@ static int btrfs_scan_kernel(void *search)
if (get_label_mounted(mnt->mnt_dir, label)) {
kfree(dev_info_arg);
- ret = 1;
goto out;
}
if (search && !match_search_item_kernel(fs_info_arg.fsid,
@@ -467,19 +467,16 @@ static int btrfs_scan_kernel(void *search)
space_info_arg, label, mnt->mnt_dir);
kfree(space_info_arg);
memset(label, 0, sizeof(label));
+ found = 1;
}
if (fd != -1)
close(fd);
kfree(dev_info_arg);
- if (search)
- ret = 0;
}
- if (search)
- ret = 1;
out:
endmntent(f);
- return ret;
+ return !found;
}
static int dev_to_fsid(char *dev, __u8 *fsid)
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs-progs: Fix the return value of btrfs_scan_kernel()
2014-04-08 9:16 [PATCH] btrfs-progs: Fix the return value of btrfs_scan_kernel() Qu Wenruo
@ 2014-04-09 2:09 ` Anand Jain
2014-04-09 2:18 ` Qu Wenruo
0 siblings, 1 reply; 4+ messages in thread
From: Anand Jain @ 2014-04-09 2:09 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
I expect btrfs_scan_kernel() would go away in the long run,
however below fix has a problem - when there is no search item
you would return fail (1) always. Since btrfs_scan_kernel() has
limited usage as you mention as well. So I will leave it to David
to decide.
Thanks, Anand
On 08/04/2014 17:16, Qu Wenruo wrote:
> btrfs_scan_kernel() is only used in 'btrfs fi show' but returns wrong
> return value.
> When search parameter is passed, it will never return 0 even the search
> can be matched.
>
> This patch will change the whatever strange logic to a more easy to
> understand one using 'found' var.
>
> Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
> Cc: Anand Jain <anand.jain@oracle.com>
> ---
> cmds-filesystem.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
> index b81768b..49d3aa7 100644
> --- a/cmds-filesystem.c
> +++ b/cmds-filesystem.c
> @@ -430,6 +430,7 @@ static int btrfs_scan_kernel_v2(void *search)
> static int btrfs_scan_kernel(void *search)
> {
> int ret = 0, fd;
> + int found = 0;
> FILE *f;
> struct mntent *mnt;
> struct btrfs_ioctl_fs_info_args fs_info_arg;
> @@ -452,7 +453,6 @@ static int btrfs_scan_kernel(void *search)
>
> if (get_label_mounted(mnt->mnt_dir, label)) {
> kfree(dev_info_arg);
> - ret = 1;
> goto out;
> }
> if (search && !match_search_item_kernel(fs_info_arg.fsid,
> @@ -467,19 +467,16 @@ static int btrfs_scan_kernel(void *search)
> space_info_arg, label, mnt->mnt_dir);
> kfree(space_info_arg);
> memset(label, 0, sizeof(label));
> + found = 1;
> }
> if (fd != -1)
> close(fd);
> kfree(dev_info_arg);
> - if (search)
> - ret = 0;
> }
> - if (search)
> - ret = 1;
>
> out:
> endmntent(f);
> - return ret;
> + return !found;
> }
>
> static int dev_to_fsid(char *dev, __u8 *fsid)
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs-progs: Fix the return value of btrfs_scan_kernel()
2014-04-09 2:09 ` Anand Jain
@ 2014-04-09 2:18 ` Qu Wenruo
2014-04-09 3:19 ` Anand Jain
0 siblings, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2014-04-09 2:18 UTC (permalink / raw)
To: Anand Jain; +Cc: linux-btrfs
Nope, the fix can also deal with no search parameter.
If any btrfs filesystem can be found and printed, found will be set to 1
which considered as found,
then 0 will be returned.
Thanks,
Qu
于 2014年04月09日 10:09, Anand Jain 写道:
>
> I expect btrfs_scan_kernel() would go away in the long run,
> however below fix has a problem - when there is no search item
> you would return fail (1) always. Since btrfs_scan_kernel() has
> limited usage as you mention as well. So I will leave it to David
> to decide.
>
> Thanks, Anand
>
> On 08/04/2014 17:16, Qu Wenruo wrote:
>> btrfs_scan_kernel() is only used in 'btrfs fi show' but returns wrong
>> return value.
>> When search parameter is passed, it will never return 0 even the search
>> can be matched.
>>
>> This patch will change the whatever strange logic to a more easy to
>> understand one using 'found' var.
>>
>> Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
>> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
>> Cc: Anand Jain <anand.jain@oracle.com>
>> ---
>> cmds-filesystem.c | 9 +++------
>> 1 file changed, 3 insertions(+), 6 deletions(-)
>>
>> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
>> index b81768b..49d3aa7 100644
>> --- a/cmds-filesystem.c
>> +++ b/cmds-filesystem.c
>> @@ -430,6 +430,7 @@ static int btrfs_scan_kernel_v2(void *search)
>> static int btrfs_scan_kernel(void *search)
>> {
>> int ret = 0, fd;
>> + int found = 0;
>> FILE *f;
>> struct mntent *mnt;
>> struct btrfs_ioctl_fs_info_args fs_info_arg;
>> @@ -452,7 +453,6 @@ static int btrfs_scan_kernel(void *search)
>>
>> if (get_label_mounted(mnt->mnt_dir, label)) {
>> kfree(dev_info_arg);
>> - ret = 1;
>> goto out;
>> }
>> if (search && !match_search_item_kernel(fs_info_arg.fsid,
>> @@ -467,19 +467,16 @@ static int btrfs_scan_kernel(void *search)
>> space_info_arg, label, mnt->mnt_dir);
>> kfree(space_info_arg);
>> memset(label, 0, sizeof(label));
>> + found = 1;
>> }
>> if (fd != -1)
>> close(fd);
>> kfree(dev_info_arg);
>> - if (search)
>> - ret = 0;
>> }
>> - if (search)
>> - ret = 1;
>>
>> out:
>> endmntent(f);
>> - return ret;
>> + return !found;
>> }
>>
>> static int dev_to_fsid(char *dev, __u8 *fsid)
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs-progs: Fix the return value of btrfs_scan_kernel()
2014-04-09 2:18 ` Qu Wenruo
@ 2014-04-09 3:19 ` Anand Jain
0 siblings, 0 replies; 4+ messages in thread
From: Anand Jain @ 2014-04-09 3:19 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On 09/04/2014 10:18, Qu Wenruo wrote:
> Nope, the fix can also deal with no search parameter.
> If any btrfs filesystem can be found and printed, found will be set to 1
> which considered as found,
> then 0 will be returned.
Oh yes. You are right. Thanks, Anand
> Thanks,
> Qu
> 于 2014年04月09日 10:09, Anand Jain 写道:
>>
>> I expect btrfs_scan_kernel() would go away in the long run,
>> however below fix has a problem - when there is no search item
>> you would return fail (1) always. Since btrfs_scan_kernel() has
>> limited usage as you mention as well. So I will leave it to David
>> to decide.
>>
>> Thanks, Anand
>>
>> On 08/04/2014 17:16, Qu Wenruo wrote:
>>> btrfs_scan_kernel() is only used in 'btrfs fi show' but returns wrong
>>> return value.
>>> When search parameter is passed, it will never return 0 even the search
>>> can be matched.
>>>
>>> This patch will change the whatever strange logic to a more easy to
>>> understand one using 'found' var.
>>>
>>> Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
>>> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
>>> Cc: Anand Jain <anand.jain@oracle.com>
>>> ---
>>> cmds-filesystem.c | 9 +++------
>>> 1 file changed, 3 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
>>> index b81768b..49d3aa7 100644
>>> --- a/cmds-filesystem.c
>>> +++ b/cmds-filesystem.c
>>> @@ -430,6 +430,7 @@ static int btrfs_scan_kernel_v2(void *search)
>>> static int btrfs_scan_kernel(void *search)
>>> {
>>> int ret = 0, fd;
>>> + int found = 0;
>>> FILE *f;
>>> struct mntent *mnt;
>>> struct btrfs_ioctl_fs_info_args fs_info_arg;
>>> @@ -452,7 +453,6 @@ static int btrfs_scan_kernel(void *search)
>>>
>>> if (get_label_mounted(mnt->mnt_dir, label)) {
>>> kfree(dev_info_arg);
>>> - ret = 1;
>>> goto out;
>>> }
>>> if (search && !match_search_item_kernel(fs_info_arg.fsid,
>>> @@ -467,19 +467,16 @@ static int btrfs_scan_kernel(void *search)
>>> space_info_arg, label, mnt->mnt_dir);
>>> kfree(space_info_arg);
>>> memset(label, 0, sizeof(label));
>>> + found = 1;
>>> }
>>> if (fd != -1)
>>> close(fd);
>>> kfree(dev_info_arg);
>>> - if (search)
>>> - ret = 0;
>>> }
>>> - if (search)
>>> - ret = 1;
>>>
>>> out:
>>> endmntent(f);
>>> - return ret;
>>> + return !found;
>>> }
>>>
>>> static int dev_to_fsid(char *dev, __u8 *fsid)
>>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-04-09 3:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-08 9:16 [PATCH] btrfs-progs: Fix the return value of btrfs_scan_kernel() Qu Wenruo
2014-04-09 2:09 ` Anand Jain
2014-04-09 2:18 ` Qu Wenruo
2014-04-09 3:19 ` Anand Jain
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).