All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Btrfs-progs: do not add stale device into fs_devices
@ 2017-10-11  0:28 Liu Bo
  2017-10-11  6:33 ` Anand Jain
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Liu Bo @ 2017-10-11  0:28 UTC (permalink / raw)
  To: linux-btrfs

If one of btrfs's devices was pulled out and we've replaced it with a
new one, then they have the same uuid.

If that device gets reconnected, 'btrfs filesystem show' will show the
stale one instead of the new one, but on kernel side btrfs has a fix
to not include the stale one, this could confuse users as people may
monitor btrfs by running that cli.

This does the similar thing to what kernel side has done.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 volumes.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/volumes.c b/volumes.c
index 2f3943d..c7b7a41 100644
--- a/volumes.c
+++ b/volumes.c
@@ -138,7 +138,20 @@ static int device_list_add(const char *path,
 		list_add(&device->dev_list, &fs_devices->devices);
 		device->fs_devices = fs_devices;
 	} else if (!device->name || strcmp(device->name, path)) {
-		char *name = strdup(path);
+		char *name;
+
+		/*
+		 * The existing device has newer generation, so this
+		 * one could be a stale one, don't add it.
+		 */
+		if (found_transid < device->generation) {
+			warning("adding device %s gen %llu but found a existing device %s gen %llu\n",
+				path, found_transid, device->name,
+				device->generation, found_transid);
+			return -EEXIST;
+		}
+
+		name = strdup(path);
                 if (!name)
                         return -ENOMEM;
                 kfree(device->name);
-- 
2.9.4


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

* Re: [PATCH] Btrfs-progs: do not add stale device into fs_devices
  2017-10-11  0:28 [PATCH] Btrfs-progs: do not add stale device into fs_devices Liu Bo
@ 2017-10-11  6:33 ` Anand Jain
  2017-10-11  9:33 ` Nikolay Borisov
  2017-10-11 17:57 ` [PATCH v2] " Liu Bo
  2 siblings, 0 replies; 7+ messages in thread
From: Anand Jain @ 2017-10-11  6:33 UTC (permalink / raw)
  To: Liu Bo, linux-btrfs, linux_lkml_grp



On 10/11/2017 08:28 AM, Liu Bo wrote:
> If one of btrfs's devices was pulled out and we've replaced it with a
> new one, then they have the same uuid.
> 
> If that device gets reconnected, 'btrfs filesystem show' will show the
> stale one instead of the new one, but on kernel side btrfs has a fix
> to not include the stale one, this could confuse users as people may
> monitor btrfs by running that cli.
> 
> This does the similar thing to what kernel side has done.

  Reviewed-by: Anand Jain <anand.jain@oracle.com>

Thanks, Anand


> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> ---
>   volumes.c | 15 ++++++++++++++-
>   1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/volumes.c b/volumes.c
> index 2f3943d..c7b7a41 100644
> --- a/volumes.c
> +++ b/volumes.c
> @@ -138,7 +138,20 @@ static int device_list_add(const char *path,
>   		list_add(&device->dev_list, &fs_devices->devices);
>   		device->fs_devices = fs_devices;
>   	} else if (!device->name || strcmp(device->name, path)) {
> -		char *name = strdup(path);
> +		char *name;
> +
> +		/*
> +		 * The existing device has newer generation, so this
> +		 * one could be a stale one, don't add it.
> +		 */
> +		if (found_transid < device->generation) {
> +			warning("adding device %s gen %llu but found a existing device %s gen %llu\n",
> +				path, found_transid, device->name,
> +				device->generation, found_transid);
> +			return -EEXIST;
> +		}
> +
> +		name = strdup(path);
>                   if (!name)
>                           return -ENOMEM;
>                   kfree(device->name);
> 

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

* Re: [PATCH] Btrfs-progs: do not add stale device into fs_devices
  2017-10-11  0:28 [PATCH] Btrfs-progs: do not add stale device into fs_devices Liu Bo
  2017-10-11  6:33 ` Anand Jain
@ 2017-10-11  9:33 ` Nikolay Borisov
  2017-10-11 13:45   ` Anand Jain
  2017-10-11 16:54   ` Liu Bo
  2017-10-11 17:57 ` [PATCH v2] " Liu Bo
  2 siblings, 2 replies; 7+ messages in thread
From: Nikolay Borisov @ 2017-10-11  9:33 UTC (permalink / raw)
  To: Liu Bo, linux-btrfs



On 11.10.2017 03:28, Liu Bo wrote:
> If one of btrfs's devices was pulled out and we've replaced it with a
> new one, then they have the same uuid.
> 
> If that device gets reconnected, 'btrfs filesystem show' will show the
> stale one instead of the new one, but on kernel side btrfs has a fix
> to not include the stale one, this could confuse users as people may
> monitor btrfs by running that cli.
> 
> This does the similar thing to what kernel side has done.
> 
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> ---
>  volumes.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/volumes.c b/volumes.c
> index 2f3943d..c7b7a41 100644
> --- a/volumes.c
> +++ b/volumes.c
> @@ -138,7 +138,20 @@ static int device_list_add(const char *path,
>  		list_add(&device->dev_list, &fs_devices->devices);
>  		device->fs_devices = fs_devices;
>  	} else if (!device->name || strcmp(device->name, path)) {
> -		char *name = strdup(path);
> +		char *name;
> +
> +		/*
> +		 * The existing device has newer generation, so this
> +		 * one could be a stale one, don't add it.
> +		 */
> +		if (found_transid < device->generation) {
> +			warning("adding device %s gen %llu but found a existing device %s gen %llu\n",
> +				path, found_transid, device->name,
> +				device->generation, found_transid);

You pass in 5 parameters but have only 4 formatting strings. I don't see
the same happening on other warning() invocations? Perhaps the last
found_transid is not necessary?

> +			return -EEXIST;
> +		}
> +
> +		name = strdup(path);
>                  if (!name)
>                          return -ENOMEM;
>                  kfree(device->name);
> 

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

* Re: [PATCH] Btrfs-progs: do not add stale device into fs_devices
  2017-10-11  9:33 ` Nikolay Borisov
@ 2017-10-11 13:45   ` Anand Jain
  2017-10-11 16:54   ` Liu Bo
  1 sibling, 0 replies; 7+ messages in thread
From: Anand Jain @ 2017-10-11 13:45 UTC (permalink / raw)
  To: Nikolay Borisov, Liu Bo, linux-btrfs, linux_lkml_grp



On 10/11/2017 05:33 PM, Nikolay Borisov wrote:
> 
> 
> On 11.10.2017 03:28, Liu Bo wrote:
>> If one of btrfs's devices was pulled out and we've replaced it with a
>> new one, then they have the same uuid.
>>
>> If that device gets reconnected, 'btrfs filesystem show' will show the
>> stale one instead of the new one, but on kernel side btrfs has a fix
>> to not include the stale one, this could confuse users as people may
>> monitor btrfs by running that cli.
>>
>> This does the similar thing to what kernel side has done.
>>
>> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
>> ---
>>   volumes.c | 15 ++++++++++++++-
>>   1 file changed, 14 insertions(+), 1 deletion(-)
>>
>> diff --git a/volumes.c b/volumes.c
>> index 2f3943d..c7b7a41 100644
>> --- a/volumes.c
>> +++ b/volumes.c
>> @@ -138,7 +138,20 @@ static int device_list_add(const char *path,
>>   		list_add(&device->dev_list, &fs_devices->devices);
>>   		device->fs_devices = fs_devices;
>>   	} else if (!device->name || strcmp(device->name, path)) {
>> -		char *name = strdup(path);
>> +		char *name;
>> +
>> +		/*
>> +		 * The existing device has newer generation, so this
>> +		 * one could be a stale one, don't add it.
>> +		 */
>> +		if (found_transid < device->generation) {
>> +			warning("adding device %s gen %llu but found a existing device %s gen %llu\n",
>> +				path, found_transid, device->name,
>> +				device->generation, found_transid);
> 
> You pass in 5 parameters but have only 4 formatting strings. I don't see
> the same happening on other warning() invocations? Perhaps the last
> found_transid is not necessary?

  I missed that. Sorry.

Thanks, Anand


>> +			return -EEXIST;
>> +		}
>> +
>> +		name = strdup(path);
>>                   if (!name)
>>                           return -ENOMEM;
>>                   kfree(device->name);
>>
> --
> 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] 7+ messages in thread

* Re: [PATCH] Btrfs-progs: do not add stale device into fs_devices
  2017-10-11  9:33 ` Nikolay Borisov
  2017-10-11 13:45   ` Anand Jain
@ 2017-10-11 16:54   ` Liu Bo
  1 sibling, 0 replies; 7+ messages in thread
From: Liu Bo @ 2017-10-11 16:54 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-btrfs

On Wed, Oct 11, 2017 at 12:33:15PM +0300, Nikolay Borisov wrote:
> 
> 
> On 11.10.2017 03:28, Liu Bo wrote:
> > If one of btrfs's devices was pulled out and we've replaced it with a
> > new one, then they have the same uuid.
> > 
> > If that device gets reconnected, 'btrfs filesystem show' will show the
> > stale one instead of the new one, but on kernel side btrfs has a fix
> > to not include the stale one, this could confuse users as people may
> > monitor btrfs by running that cli.
> > 
> > This does the similar thing to what kernel side has done.
> > 
> > Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> > ---
> >  volumes.c | 15 ++++++++++++++-
> >  1 file changed, 14 insertions(+), 1 deletion(-)
> > 
> > diff --git a/volumes.c b/volumes.c
> > index 2f3943d..c7b7a41 100644
> > --- a/volumes.c
> > +++ b/volumes.c
> > @@ -138,7 +138,20 @@ static int device_list_add(const char *path,
> >  		list_add(&device->dev_list, &fs_devices->devices);
> >  		device->fs_devices = fs_devices;
> >  	} else if (!device->name || strcmp(device->name, path)) {
> > -		char *name = strdup(path);
> > +		char *name;
> > +
> > +		/*
> > +		 * The existing device has newer generation, so this
> > +		 * one could be a stale one, don't add it.
> > +		 */
> > +		if (found_transid < device->generation) {
> > +			warning("adding device %s gen %llu but found a existing device %s gen %llu\n",
> > +				path, found_transid, device->name,
> > +				device->generation, found_transid);
> 
> You pass in 5 parameters but have only 4 formatting strings. I don't see
> the same happening on other warning() invocations? Perhaps the last
> found_transid is not necessary?
> 

Oh, thanks for the comments.

I messed it up again, what I was testing is warning("blabla",
device->name, device->generation, path, found_transid), but later I
updated the message but got the parameters wrong.

Will do a v2.

Thanks,

-liubo
> > +			return -EEXIST;
> > +		}
> > +
> > +		name = strdup(path);
> >                  if (!name)
> >                          return -ENOMEM;
> >                  kfree(device->name);
> > 

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

* [PATCH v2] Btrfs-progs: do not add stale device into fs_devices
  2017-10-11  0:28 [PATCH] Btrfs-progs: do not add stale device into fs_devices Liu Bo
  2017-10-11  6:33 ` Anand Jain
  2017-10-11  9:33 ` Nikolay Borisov
@ 2017-10-11 17:57 ` Liu Bo
  2017-10-17 16:38   ` David Sterba
  2 siblings, 1 reply; 7+ messages in thread
From: Liu Bo @ 2017-10-11 17:57 UTC (permalink / raw)
  To: linux-btrfs

If one of btrfs's devices was pulled out and we've replaced it with a
new one, then they have the same uuid.

If that device gets reconnected, 'btrfs filesystem show' will show the
stale one instead of the new one, but on kernel side btrfs has a fix
to not include the stale one, this could confuse users as people may
monitor btrfs by running that cli.

This does the similar thing to what kernel side has done.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
---
v2: remove a wrong parameter.

 volumes.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/volumes.c b/volumes.c
index 2f3943d..036c58d 100644
--- a/volumes.c
+++ b/volumes.c
@@ -138,7 +138,20 @@ static int device_list_add(const char *path,
 		list_add(&device->dev_list, &fs_devices->devices);
 		device->fs_devices = fs_devices;
 	} else if (!device->name || strcmp(device->name, path)) {
-		char *name = strdup(path);
+		char *name;
+
+		/*
+		 * The existing device has newer generation, so this
+		 * one could be a stale one, don't add it.
+		 */
+		if (found_transid < device->generation) {
+			warning("adding device %s gen %llu but found an existing device %s gen %llu\n",
+				path, found_transid, device->name,
+				device->generation);
+			return -EEXIST;
+		}
+
+		name = strdup(path);
                 if (!name)
                         return -ENOMEM;
                 kfree(device->name);
-- 
2.9.4


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

* Re: [PATCH v2] Btrfs-progs: do not add stale device into fs_devices
  2017-10-11 17:57 ` [PATCH v2] " Liu Bo
@ 2017-10-17 16:38   ` David Sterba
  0 siblings, 0 replies; 7+ messages in thread
From: David Sterba @ 2017-10-17 16:38 UTC (permalink / raw)
  To: Liu Bo; +Cc: linux-btrfs

On Wed, Oct 11, 2017 at 11:57:16AM -0600, Liu Bo wrote:
> If one of btrfs's devices was pulled out and we've replaced it with a
> new one, then they have the same uuid.
> 
> If that device gets reconnected, 'btrfs filesystem show' will show the
> stale one instead of the new one, but on kernel side btrfs has a fix
> to not include the stale one, this could confuse users as people may
> monitor btrfs by running that cli.
> 
> This does the similar thing to what kernel side has done.
> 
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> Reviewed-by: Anand Jain <anand.jain@oracle.com>

Applied with the following diff, thanks.

--- a/volumes.c
+++ b/volumes.c
@@ -141,11 +141,12 @@ static int device_list_add(const char *path,
                char *name;

                /*
-                * The existing device has newer generation, so this
-                * one could be a stale one, don't add it.
+                * The existing device has newer generation, so this one could
+                * be a stale one, don't add it.
                 */
                if (found_transid < device->generation) {
-                       warning("adding device %s gen %llu but found an existing device %s gen %llu\n",
+                       warning(
+       "adding device %s gen %llu but found an existing device %s gen %llu",
                                path, found_transid, device->name,
                                device->generation);
                        return -EEXIST;

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

end of thread, other threads:[~2017-10-17 16:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-11  0:28 [PATCH] Btrfs-progs: do not add stale device into fs_devices Liu Bo
2017-10-11  6:33 ` Anand Jain
2017-10-11  9:33 ` Nikolay Borisov
2017-10-11 13:45   ` Anand Jain
2017-10-11 16:54   ` Liu Bo
2017-10-11 17:57 ` [PATCH v2] " Liu Bo
2017-10-17 16:38   ` David Sterba

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.