btrfs-progs: do not add stale device into fs_devices
If one of btrfs' 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 the kernel side btrfs has a fix not to include the stale one, this could confuse users as people may monitor btrfs by running that command. 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> [ format string adjustments ] Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
59e067ada7
commit
eebdf02321
16
volumes.c
16
volumes.c
|
@ -138,7 +138,21 @@ 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",
|
||||
path, found_transid, device->name,
|
||||
device->generation);
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
name = strdup(path);
|
||||
if (!name)
|
||||
return -ENOMEM;
|
||||
kfree(device->name);
|
||||
|
|
Loading…
Reference in New Issue