[1/3] fstests: btrfs: Use word mathcing for _btrfs_get_subvolid()
diff mbox series

Message ID 20200207015942.9079-2-wqu@suse.com
State New
Headers show
Series
  • fstests: btrfs/022 fixes
Related show

Commit Message

Qu Wenruo Feb. 7, 2020, 1:59 a.m. UTC
Current _btrfs_get_subvolid() can't handle the following case at all:
  # btrfs subvol list $SCRATCH_MNT
  ID 256 gen 9 top level 5 path subv1
  ID 257 gen 7 top level 256 path subv1/subv2
  ID 258 gen 8 top level 256 path subv1/subv3
  ID 259 gen 9 top level 256 path subv1/subv4

If we call "_btrfs_get_subvolid $SCRATCH_MNT subv1" we will get a list
of all subvolumes, not the subvolid of subv1.

To address this problem, we go egrep to match $name which starts with a
space, and at the end of a line.
So that all other subvolumes won't hit.

Suggested-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 common/btrfs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Josef Bacik Feb. 7, 2020, 2:09 a.m. UTC | #1
On 2/6/20 8:59 PM, Qu Wenruo wrote:
> Current _btrfs_get_subvolid() can't handle the following case at all:
>    # btrfs subvol list $SCRATCH_MNT
>    ID 256 gen 9 top level 5 path subv1
>    ID 257 gen 7 top level 256 path subv1/subv2
>    ID 258 gen 8 top level 256 path subv1/subv3
>    ID 259 gen 9 top level 256 path subv1/subv4
> 
> If we call "_btrfs_get_subvolid $SCRATCH_MNT subv1" we will get a list
> of all subvolumes, not the subvolid of subv1.
> 
> To address this problem, we go egrep to match $name which starts with a
> space, and at the end of a line.
> So that all other subvolumes won't hit.
> 
> Suggested-by: Josef Bacik <josef@toxicpanda.com>
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef
Nikolay Borisov Feb. 7, 2020, 9:41 a.m. UTC | #2
On 7.02.20 г. 3:59 ч., Qu Wenruo wrote:
> Current _btrfs_get_subvolid() can't handle the following case at all:
>   # btrfs subvol list $SCRATCH_MNT
>   ID 256 gen 9 top level 5 path subv1
>   ID 257 gen 7 top level 256 path subv1/subv2
>   ID 258 gen 8 top level 256 path subv1/subv3
>   ID 259 gen 9 top level 256 path subv1/subv4
> 
> If we call "_btrfs_get_subvolid $SCRATCH_MNT subv1" we will get a list
> of all subvolumes, not the subvolid of subv1.
> 
> To address this problem, we go egrep to match $name which starts with a
> space, and at the end of a line.
> So that all other subvolumes won't hit.
> 
> Suggested-by: Josef Bacik <josef@toxicpanda.com>
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
>  common/btrfs | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/btrfs b/common/btrfs
> index 19ac7cc4..85b33e4c 100644
> --- a/common/btrfs
> +++ b/common/btrfs
> @@ -7,7 +7,7 @@ _btrfs_get_subvolid()
>  	mnt=$1
>  	name=$2
>  
> -	$BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
> +	$BTRFS_UTIL_PROG sub list $mnt | egrep "\s$name$" | awk '{ print $2 }'

nit: But you don't even need egrep for this, you could have simply used
"grep $name$"

>  }
>  
>  # _require_btrfs_command <command> [<subcommand>|<option>]
>
Qu Wenruo Feb. 7, 2020, 10:02 a.m. UTC | #3
On 2020/2/7 下午5:41, Nikolay Borisov wrote:
> 
> 
> On 7.02.20 г. 3:59 ч., Qu Wenruo wrote:
>> Current _btrfs_get_subvolid() can't handle the following case at all:
>>   # btrfs subvol list $SCRATCH_MNT
>>   ID 256 gen 9 top level 5 path subv1
>>   ID 257 gen 7 top level 256 path subv1/subv2
>>   ID 258 gen 8 top level 256 path subv1/subv3
>>   ID 259 gen 9 top level 256 path subv1/subv4
>>
>> If we call "_btrfs_get_subvolid $SCRATCH_MNT subv1" we will get a list
>> of all subvolumes, not the subvolid of subv1.
>>
>> To address this problem, we go egrep to match $name which starts with a
>> space, and at the end of a line.
>> So that all other subvolumes won't hit.
>>
>> Suggested-by: Josef Bacik <josef@toxicpanda.com>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
> 
> Reviewed-by: Nikolay Borisov <nborisov@suse.com>
> 
>> ---
>>  common/btrfs | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/common/btrfs b/common/btrfs
>> index 19ac7cc4..85b33e4c 100644
>> --- a/common/btrfs
>> +++ b/common/btrfs
>> @@ -7,7 +7,7 @@ _btrfs_get_subvolid()
>>  	mnt=$1
>>  	name=$2
>>  
>> -	$BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
>> +	$BTRFS_UTIL_PROG sub list $mnt | egrep "\s$name$" | awk '{ print $2 }'
> 
> nit: But you don't even need egrep for this, you could have simply used
> "grep $name$"

That \s is needed. Or the following case can't be handled:

   ID 256 gen 9 top level 5 path subv1
   ID 257 gen 7 top level 256 path subv1/subv1

Thanks,
Qu

> 
>>  }
>>  
>>  # _require_btrfs_command <command> [<subcommand>|<option>]
>>
Nikolay Borisov Feb. 7, 2020, 11:07 a.m. UTC | #4
On 7.02.20 г. 12:02 ч., Qu Wenruo wrote:
> 
> 
> On 2020/2/7 下午5:41, Nikolay Borisov wrote:
>>
>>
>> On 7.02.20 г. 3:59 ч., Qu Wenruo wrote:
>>> Current _btrfs_get_subvolid() can't handle the following case at all:
>>>   # btrfs subvol list $SCRATCH_MNT
>>>   ID 256 gen 9 top level 5 path subv1
>>>   ID 257 gen 7 top level 256 path subv1/subv2
>>>   ID 258 gen 8 top level 256 path subv1/subv3
>>>   ID 259 gen 9 top level 256 path subv1/subv4
>>>
>>> If we call "_btrfs_get_subvolid $SCRATCH_MNT subv1" we will get a list
>>> of all subvolumes, not the subvolid of subv1.
>>>
>>> To address this problem, we go egrep to match $name which starts with a
>>> space, and at the end of a line.
>>> So that all other subvolumes won't hit.
>>>
>>> Suggested-by: Josef Bacik <josef@toxicpanda.com>
>>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>>
>> Reviewed-by: Nikolay Borisov <nborisov@suse.com>
>>
>>> ---
>>>  common/btrfs | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/common/btrfs b/common/btrfs
>>> index 19ac7cc4..85b33e4c 100644
>>> --- a/common/btrfs
>>> +++ b/common/btrfs
>>> @@ -7,7 +7,7 @@ _btrfs_get_subvolid()
>>>  	mnt=$1
>>>  	name=$2
>>>  
>>> -	$BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
>>> +	$BTRFS_UTIL_PROG sub list $mnt | egrep "\s$name$" | awk '{ print $2 }'
>>
>> nit: But you don't even need egrep for this, you could have simply used
>> "grep $name$"
> 
> That \s is needed. Or the following case can't be handled:
> 
>    ID 256 gen 9 top level 5 path subv1
>    ID 257 gen 7 top level 256 path subv1/subv1


Good point.

> 
> Thanks,
> Qu
> 
>>
>>>  }
>>>  
>>>  # _require_btrfs_command <command> [<subcommand>|<option>]
>>>

Patch
diff mbox series

diff --git a/common/btrfs b/common/btrfs
index 19ac7cc4..85b33e4c 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -7,7 +7,7 @@  _btrfs_get_subvolid()
 	mnt=$1
 	name=$2
 
-	$BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
+	$BTRFS_UTIL_PROG sub list $mnt | egrep "\s$name$" | awk '{ print $2 }'
 }
 
 # _require_btrfs_command <command> [<subcommand>|<option>]