diff mbox

Btrfs-progs: save us an unnecessary ioctl call

Message ID 1399971906-1237-1-git-send-email-wangsl.fnst@cn.fujitsu.com (mailing list archive)
State Rejected
Delegated to: David Sterba
Headers show

Commit Message

Wang Shilong May 13, 2014, 9:05 a.m. UTC
Btrfs device id start from 1, not 0.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
---
 utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefan Behrens May 13, 2014, 10:48 a.m. UTC | #1
On Tue, 13 May 2014 17:05:05 +0800, Wang Shilong wrote:
> Btrfs device id start from 1, not 0.
> 
> Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
> ---
>  utils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/utils.c b/utils.c
> index 560c557..d480353 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -1765,7 +1765,7 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
>  		goto out;
>  	}

You've not seen the two assignments in get_fs_info() above the lines
that you change:

        if (is_block_device(path)) {
                ...
                fi_args->max_id = devid;
                i = devid;

>  
> -	for (; i <= fi_args->max_id; ++i) {
> +	for (i = 1; i <= fi_args->max_id; ++i) {
>  		BUG_ON(ndevs >= fi_args->num_devices);
>  		ret = get_device_info(fd, i, &di_args[ndevs]);
>  		if (ret == -ENODEV)


--
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
Wang Shilong May 13, 2014, 11:26 a.m. UTC | #2
On 05/13/2014 06:48 PM, Stefan Behrens wrote:
> On Tue, 13 May 2014 17:05:05 +0800, Wang Shilong wrote:
>> Btrfs device id start from 1, not 0.
>>
>> Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
>> ---
>>   utils.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/utils.c b/utils.c
>> index 560c557..d480353 100644
>> --- a/utils.c
>> +++ b/utils.c
>> @@ -1765,7 +1765,7 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
>>   		goto out;
>>   	}
> You've not seen the two assignments in get_fs_info() above the lines
> that you change:
>
>          if (is_block_device(path)) {
>                  ...
>                  fi_args->max_id = devid;
>                  i = devid;
Oops, i did not see this one, but this condition may not meet, so
i guess the right fix is to set i=1 when declaration, something like:

int i = 1;

>
>>   
>> -	for (; i <= fi_args->max_id; ++i) {
>> +	for (i = 1; i <= fi_args->max_id; ++i) {
>>   		BUG_ON(ndevs >= fi_args->num_devices);
>>   		ret = get_device_info(fd, i, &di_args[ndevs]);
>>   		if (ret == -ENODEV)
>
> --
> 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
>

--
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
Anand Jain May 14, 2014, 5:32 a.m. UTC | #3
> Btrfs device id start from 1, not 0.

  That was an intentional change.

  50275ba btrfs-progs: there is devid 0 when replace is running




>
> Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
> ---
>   utils.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/utils.c b/utils.c
> index 560c557..d480353 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -1765,7 +1765,7 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
>   		goto out;
>   	}
>
> -	for (; i <= fi_args->max_id; ++i) {
> +	for (i = 1; i <= fi_args->max_id; ++i) {
>   		BUG_ON(ndevs >= fi_args->num_devices);
>   		ret = get_device_info(fd, i, &di_args[ndevs]);
>   		if (ret == -ENODEV)
>
--
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
David Sterba May 15, 2014, 5:06 p.m. UTC | #4
On Tue, May 13, 2014 at 05:05:05PM +0800, Wang Shilong wrote:
> Btrfs device id start from 1, not 0.

> --- a/utils.c
> +++ b/utils.c
> @@ -1765,7 +1765,7 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
>  		goto out;
>  	}
>  
> -	for (; i <= fi_args->max_id; ++i) {
> +	for (i = 1; i <= fi_args->max_id; ++i) {

You're right about the device id start, but forcing 1 here breaks the
case when get_fs_info is called with block device as an argument and 'i'
is set to the devid a few lines above.

Initializing i to 1 in the declaration block is the right fix IMO, and
as this is a trivial change I'll do that myself, no need to resend.

>  		BUG_ON(ndevs >= fi_args->num_devices);
>  		ret = get_device_info(fd, i, &di_args[ndevs]);
>  		if (ret == -ENODEV)
--
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
Anand Jain May 16, 2014, 4:32 a.m. UTC | #5
David,

  As mentioned, this patch will back-out the earlier patch

  50275bacab0f62b91453fbfa29e75c2bb77bf9b6

  I am confused on what I am missing ? Any comment?

Thanks, Anand


On 16/05/14 01:06, David Sterba wrote:
> On Tue, May 13, 2014 at 05:05:05PM +0800, Wang Shilong wrote:
>> Btrfs device id start from 1, not 0.
>
>> --- a/utils.c
>> +++ b/utils.c
>> @@ -1765,7 +1765,7 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
>>   		goto out;
>>   	}
>>
>> -	for (; i <= fi_args->max_id; ++i) {
>> +	for (i = 1; i <= fi_args->max_id; ++i) {
>
> You're right about the device id start, but forcing 1 here breaks the
> case when get_fs_info is called with block device as an argument and 'i'
> is set to the devid a few lines above.
>
> Initializing i to 1 in the declaration block is the right fix IMO, and
> as this is a trivial change I'll do that myself, no need to resend.
>
>>   		BUG_ON(ndevs >= fi_args->num_devices);
>>   		ret = get_device_info(fd, i, &di_args[ndevs]);
>>   		if (ret == -ENODEV)
> --
> 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
>
--
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
Wang Shilong May 16, 2014, 4:58 a.m. UTC | #6
Hi Anand,

On 05/16/2014 12:32 PM, Anand Jain wrote:
>
> David,
>
>  As mentioned, this patch will back-out the earlier patch
>
>  50275bacab0f62b91453fbfa29e75c2bb77bf9b6
>
>  I am confused on what I am missing ? Any comment?
You are right, i guess dave just missed your previous thread.:-)
dave, please ignore my patch, sorry for noise.

Thanks,
Wang
>
> Thanks, Anand
>
>
> On 16/05/14 01:06, David Sterba wrote:
>> On Tue, May 13, 2014 at 05:05:05PM +0800, Wang Shilong wrote:
>>> Btrfs device id start from 1, not 0.
>>
>>> --- a/utils.c
>>> +++ b/utils.c
>>> @@ -1765,7 +1765,7 @@ int get_fs_info(char *path, struct 
>>> btrfs_ioctl_fs_info_args *fi_args,
>>>           goto out;
>>>       }
>>>
>>> -    for (; i <= fi_args->max_id; ++i) {
>>> +    for (i = 1; i <= fi_args->max_id; ++i) {
>>
>> You're right about the device id start, but forcing 1 here breaks the
>> case when get_fs_info is called with block device as an argument and 'i'
>> is set to the devid a few lines above.
>>
>> Initializing i to 1 in the declaration block is the right fix IMO, and
>> as this is a trivial change I'll do that myself, no need to resend.
>>
>>>           BUG_ON(ndevs >= fi_args->num_devices);
>>>           ret = get_device_info(fd, i, &di_args[ndevs]);
>>>           if (ret == -ENODEV)
>> -- 
>> 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
>>
> .
>

--
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
David Sterba May 16, 2014, 12:14 p.m. UTC | #7
On Fri, May 16, 2014 at 12:58:46PM +0800, Wang Shilong wrote:
> Hi Anand,
> 
> On 05/16/2014 12:32 PM, Anand Jain wrote:
> >
> >David,
> >
> > As mentioned, this patch will back-out the earlier patch
> >
> > 50275bacab0f62b91453fbfa29e75c2bb77bf9b6
> >
> > I am confused on what I am missing ? Any comment?
> You are right, i guess dave just missed your previous thread.:-)

Oh I did, sorry.
--
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
diff mbox

Patch

diff --git a/utils.c b/utils.c
index 560c557..d480353 100644
--- a/utils.c
+++ b/utils.c
@@ -1765,7 +1765,7 @@  int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
 		goto out;
 	}
 
-	for (; i <= fi_args->max_id; ++i) {
+	for (i = 1; i <= fi_args->max_id; ++i) {
 		BUG_ON(ndevs >= fi_args->num_devices);
 		ret = get_device_info(fd, i, &di_args[ndevs]);
 		if (ret == -ENODEV)