All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old libblkid cache
@ 2014-04-10  7:30 Qu Wenruo
  2014-04-10  7:37 ` Anand Jain
  2014-04-14 16:29 ` David Sterba
  0 siblings, 2 replies; 6+ messages in thread
From: Qu Wenruo @ 2014-04-10  7:30 UTC (permalink / raw)
  To: linux-btrfs

'btrfs scan' uses libblkid to scan devices by default, and libblkid uses
cache to reduce the probe.

But if operations below is done in less than 2 seconds(BLKID_PROBE_MIN),
'btrfs scan' will still use the uncorrect cache and scan on the deleted device.
0. /dev/sda[1-4] mounted on /mnt using single data/metadata
1. btrfs dev scan
2. btrfs dev del /dev/sda3 /mnt
3. btrfs dev scan

Since the cache made by step 1 is still validated, step 3 will use the
cache and consider /dev/sda3 as a btrfs filesystem and try to scan it.
But the superblock(at least the first one) is wiped and failed to scan,
a error message, which can be avoided and is unneeded, is output.

This patch will force scan_for_btrfs() not to use cache to avoid the
problem.

Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Singed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/utils.c b/utils.c
index 0bfb9d9..1cd1d28 100644
--- a/utils.c
+++ b/utils.c
@@ -2057,7 +2057,8 @@ int btrfs_scan_lblkid(int update_kernel)
 	blkid_cache cache = NULL;
 	char path[PATH_MAX];
 
-	if (blkid_get_cache(&cache, 0) < 0) {
+	/* No to use libblkid cache to avoid old data */
+	if (blkid_get_cache(&cache, "/dev/null") < 0) {
 		printf("ERROR: lblkid cache get failed\n");
 		return 1;
 	}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old libblkid cache
  2014-04-10  7:30 [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old libblkid cache Qu Wenruo
@ 2014-04-10  7:37 ` Anand Jain
  2014-04-14 16:29 ` David Sterba
  1 sibling, 0 replies; 6+ messages in thread
From: Anand Jain @ 2014-04-10  7:37 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs





On 04/10/2014 03:30 PM, Qu Wenruo wrote:
> 'btrfs scan' uses libblkid to scan devices by default, and libblkid uses
> cache to reduce the probe.
>
> But if operations below is done in less than 2 seconds(BLKID_PROBE_MIN),
> 'btrfs scan' will still use the uncorrect cache and scan on the deleted device.

  Great thanks for looking into this.

Anand


> 0. /dev/sda[1-4] mounted on /mnt using single data/metadata
> 1. btrfs dev scan
> 2. btrfs dev del /dev/sda3 /mnt
> 3. btrfs dev scan

> Since the cache made by step 1 is still validated, step 3 will use the
> cache and consider /dev/sda3 as a btrfs filesystem and try to scan it.
> But the superblock(at least the first one) is wiped and failed to scan,
> a error message, which can be avoided and is unneeded, is output.
>
> This patch will force scan_for_btrfs() not to use cache to avoid the
> problem.
>
> Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
> Singed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
> ---
>   utils.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/utils.c b/utils.c
> index 0bfb9d9..1cd1d28 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -2057,7 +2057,8 @@ int btrfs_scan_lblkid(int update_kernel)
>   	blkid_cache cache = NULL;
>   	char path[PATH_MAX];
>
> -	if (blkid_get_cache(&cache, 0) < 0) {
> +	/* No to use libblkid cache to avoid old data */
> +	if (blkid_get_cache(&cache, "/dev/null") < 0) {
>   		printf("ERROR: lblkid cache get failed\n");
>   		return 1;
>   	}
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old libblkid cache
  2014-04-10  7:30 [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old libblkid cache Qu Wenruo
  2014-04-10  7:37 ` Anand Jain
@ 2014-04-14 16:29 ` David Sterba
  2014-04-15  1:17   ` Qu Wenruo
  2014-04-16  1:24   ` Qu Wenruo
  1 sibling, 2 replies; 6+ messages in thread
From: David Sterba @ 2014-04-14 16:29 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Thu, Apr 10, 2014 at 03:30:21PM +0800, Qu Wenruo wrote:
> 'btrfs scan' uses libblkid to scan devices by default, and libblkid uses
> cache to reduce the probe.
> 
> But if operations below is done in less than 2 seconds(BLKID_PROBE_MIN),
> 'btrfs scan' will still use the uncorrect cache and scan on the deleted device.
> 0. /dev/sda[1-4] mounted on /mnt using single data/metadata
> 1. btrfs dev scan
> 2. btrfs dev del /dev/sda3 /mnt
> 3. btrfs dev scan
> 
> Since the cache made by step 1 is still validated, step 3 will use the
> cache and consider /dev/sda3 as a btrfs filesystem and try to scan it.
> But the superblock(at least the first one) is wiped and failed to scan,
> a error message, which can be avoided and is unneeded, is output.
> 
> This patch will force scan_for_btrfs() not to use cache to avoid the
> problem.

> --- a/utils.c
> +++ b/utils.c
> @@ -2057,7 +2057,8 @@ int btrfs_scan_lblkid(int update_kernel)
>  	blkid_cache cache = NULL;
>  	char path[PATH_MAX];
>  
> -	if (blkid_get_cache(&cache, 0) < 0) {
> +	/* No to use libblkid cache to avoid old data */
> +	if (blkid_get_cache(&cache, "/dev/null") < 0) {

This effectively avoid the blkid cache for all devices but the point of
blkid was to use it so repeated probes are not done.

I think it's not right to skip the whole cache because one entry may be
stale, more that we know which one and when.

We should rather explicitly invalidate the removed device after delete,
I don't what's the right way to do that. Maybe blkid_do_probe() or
blkid_gc_cache()

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old libblkid cache
  2014-04-14 16:29 ` David Sterba
@ 2014-04-15  1:17   ` Qu Wenruo
  2014-04-16  1:24   ` Qu Wenruo
  1 sibling, 0 replies; 6+ messages in thread
From: Qu Wenruo @ 2014-04-15  1:17 UTC (permalink / raw)
  To: dsterba, linux-btrfs


-------- Original Message --------
Subject: Re: [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old 
libblkid cache
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo@cn.fujitsu.com>
Date: 2014年04月15日 00:29
> On Thu, Apr 10, 2014 at 03:30:21PM +0800, Qu Wenruo wrote:
>> 'btrfs scan' uses libblkid to scan devices by default, and libblkid uses
>> cache to reduce the probe.
>>
>> But if operations below is done in less than 2 seconds(BLKID_PROBE_MIN),
>> 'btrfs scan' will still use the uncorrect cache and scan on the deleted device.
>> 0. /dev/sda[1-4] mounted on /mnt using single data/metadata
>> 1. btrfs dev scan
>> 2. btrfs dev del /dev/sda3 /mnt
>> 3. btrfs dev scan
>>
>> Since the cache made by step 1 is still validated, step 3 will use the
>> cache and consider /dev/sda3 as a btrfs filesystem and try to scan it.
>> But the superblock(at least the first one) is wiped and failed to scan,
>> a error message, which can be avoided and is unneeded, is output.
>>
>> This patch will force scan_for_btrfs() not to use cache to avoid the
>> problem.
>> --- a/utils.c
>> +++ b/utils.c
>> @@ -2057,7 +2057,8 @@ int btrfs_scan_lblkid(int update_kernel)
>>   	blkid_cache cache = NULL;
>>   	char path[PATH_MAX];
>>   
>> -	if (blkid_get_cache(&cache, 0) < 0) {
>> +	/* No to use libblkid cache to avoid old data */
>> +	if (blkid_get_cache(&cache, "/dev/null") < 0) {
> This effectively avoid the blkid cache for all devices but the point of
> blkid was to use it so repeated probes are not done.
>
> I think it's not right to skip the whole cache because one entry may be
> stale, more that we know which one and when.
I totally agree with that.
>
> We should rather explicitly invalidate the removed device after delete,
> I don't what's the right way to do that. Maybe blkid_do_probe() or
> blkid_gc_cache()
But the problem is, libblkid does not provide such API to invalidate one 
entry of cache.
blkid_gc_cache() will only remove non-exsist device cache, and 
blkid_do_probe() seems not using/update the cache,
so I used "/dev/null" as cache to avoid the cache completly.

I'll try to dig the libblkid codes deeper to find a method to invalidate 
an entry.

Thanks,
Qu.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old libblkid cache
  2014-04-14 16:29 ` David Sterba
  2014-04-15  1:17   ` Qu Wenruo
@ 2014-04-16  1:24   ` Qu Wenruo
  2014-04-16  2:09     ` Qu Wenruo
  1 sibling, 1 reply; 6+ messages in thread
From: Qu Wenruo @ 2014-04-16  1:24 UTC (permalink / raw)
  To: dsterba, linux-btrfs


-------- Original Message --------
Subject: Re: [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old 
libblkid cache
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo@cn.fujitsu.com>
Date: 2014年04月15日 00:29
> On Thu, Apr 10, 2014 at 03:30:21PM +0800, Qu Wenruo wrote:
>> 'btrfs scan' uses libblkid to scan devices by default, and libblkid uses
>> cache to reduce the probe.
>>
>> But if operations below is done in less than 2 seconds(BLKID_PROBE_MIN),
>> 'btrfs scan' will still use the uncorrect cache and scan on the deleted device.
>> 0. /dev/sda[1-4] mounted on /mnt using single data/metadata
>> 1. btrfs dev scan
>> 2. btrfs dev del /dev/sda3 /mnt
>> 3. btrfs dev scan
>>
>> Since the cache made by step 1 is still validated, step 3 will use the
>> cache and consider /dev/sda3 as a btrfs filesystem and try to scan it.
>> But the superblock(at least the first one) is wiped and failed to scan,
>> a error message, which can be avoided and is unneeded, is output.
>>
>> This patch will force scan_for_btrfs() not to use cache to avoid the
>> problem.
>> --- a/utils.c
>> +++ b/utils.c
>> @@ -2057,7 +2057,8 @@ int btrfs_scan_lblkid(int update_kernel)
>>   	blkid_cache cache = NULL;
>>   	char path[PATH_MAX];
>>   
>> -	if (blkid_get_cache(&cache, 0) < 0) {
>> +	/* No to use libblkid cache to avoid old data */
>> +	if (blkid_get_cache(&cache, "/dev/null") < 0) {
> This effectively avoid the blkid cache for all devices but the point of
> blkid was to use it so repeated probes are not done.
>
> I think it's not right to skip the whole cache because one entry may be
> stale, more that we know which one and when.
>
> We should rather explicitly invalidate the removed device after delete,
> I don't what's the right way to do that. Maybe blkid_do_probe() or
> blkid_gc_cache()
Please ignore this patch, since after consulting with libblkid mail 
list, the real problem is that btrfs ioctl for remove device
does not update the mtime/ctime for the device.

Libblkid will only use cache when the device's mtime/ctime stay 
unchanged, if mtime/ctime changed libblkid will do the lowprobe.

I'll try to fix it in kernel space.

Thanks,
Qu


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old libblkid cache
  2014-04-16  1:24   ` Qu Wenruo
@ 2014-04-16  2:09     ` Qu Wenruo
  0 siblings, 0 replies; 6+ messages in thread
From: Qu Wenruo @ 2014-04-16  2:09 UTC (permalink / raw)
  To: dsterba, linux-btrfs


-------- Original Message --------
Subject: Re: [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old 
libblkid cache
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: dsterba@suse.cz, linux-btrfs@vger.kernel.org
Date: 2014年04月16日 09:24
>
> -------- Original Message --------
> Subject: Re: [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old 
> libblkid cache
> From: David Sterba <dsterba@suse.cz>
> To: Qu Wenruo <quwenruo@cn.fujitsu.com>
> Date: 2014年04月15日 00:29
>> On Thu, Apr 10, 2014 at 03:30:21PM +0800, Qu Wenruo wrote:
>>> 'btrfs scan' uses libblkid to scan devices by default, and libblkid 
>>> uses
>>> cache to reduce the probe.
>>>
>>> But if operations below is done in less than 2 
>>> seconds(BLKID_PROBE_MIN),
>>> 'btrfs scan' will still use the uncorrect cache and scan on the 
>>> deleted device.
>>> 0. /dev/sda[1-4] mounted on /mnt using single data/metadata
>>> 1. btrfs dev scan
>>> 2. btrfs dev del /dev/sda3 /mnt
>>> 3. btrfs dev scan
>>>
>>> Since the cache made by step 1 is still validated, step 3 will use the
>>> cache and consider /dev/sda3 as a btrfs filesystem and try to scan it.
>>> But the superblock(at least the first one) is wiped and failed to scan,
>>> a error message, which can be avoided and is unneeded, is output.
>>>
>>> This patch will force scan_for_btrfs() not to use cache to avoid the
>>> problem.
>>> --- a/utils.c
>>> +++ b/utils.c
>>> @@ -2057,7 +2057,8 @@ int btrfs_scan_lblkid(int update_kernel)
>>>       blkid_cache cache = NULL;
>>>       char path[PATH_MAX];
>>>   -    if (blkid_get_cache(&cache, 0) < 0) {
>>> +    /* No to use libblkid cache to avoid old data */
>>> +    if (blkid_get_cache(&cache, "/dev/null") < 0) {
>> This effectively avoid the blkid cache for all devices but the point of
>> blkid was to use it so repeated probes are not done.
>>
>> I think it's not right to skip the whole cache because one entry may be
>> stale, more that we know which one and when.
>>
>> We should rather explicitly invalidate the removed device after delete,
>> I don't what's the right way to do that. Maybe blkid_do_probe() or
>> blkid_gc_cache()
> Please ignore this patch, since after consulting with libblkid mail 
> list, the real problem is that btrfs ioctl for remove device
> does not update the mtime/ctime for the device.
I'm sorry that kernel updates the mtime/ctime, but it seems there is 
some small latency, which caused libblkd fail to detect the
modification and use old cache.

Will go on investigation.
Thanks,
Qu
>
> Libblkid will only use cache when the device's mtime/ctime stay 
> unchanged, if mtime/ctime changed libblkid will do the lowprobe.
>
> I'll try to fix it in kernel space.
>
> Thanks,
> Qu
>
> -- 
> 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] 6+ messages in thread

end of thread, other threads:[~2014-04-16  2:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-10  7:30 [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old libblkid cache Qu Wenruo
2014-04-10  7:37 ` Anand Jain
2014-04-14 16:29 ` David Sterba
2014-04-15  1:17   ` Qu Wenruo
2014-04-16  1:24   ` Qu Wenruo
2014-04-16  2:09     ` Qu Wenruo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.