aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorAnand Jain <anand.jain@oracle.com>2014-07-03 06:22:06 -0400
committerChris Mason <clm@fb.com>2014-08-19 11:36:30 -0400
commit77bdae4d136e167bab028cbec58b988f91cf73c0 (patch)
tree3c2477baa2f64cc00db475efc2f52d399f1a4beb /fs
parentb96de000bc8bc9688b3a2abea4332bd57648a49f (diff)
btrfs: check generation as replace duplicates devid+uuid
When FS in unmounted we need to check generation number as well since devid+uuid combination could match with the missing replaced disk when it reappears, and without this patch it might pair with the replaced disk again. device_list_add() function is called in the following threads, mount device option mount argument ioctl BTRFS_IOC_SCAN_DEV (btrfs dev scan) ioctl BTRFS_IOC_DEVICES_READY (btrfs dev ready <dev>) they have been unit tested to work fine with this patch. If the user knows what he is doing and really want to pair with replaced disk (which is not a standard operation), then he should first clear the kernel btrfs device list in the memory by doing the module unload/load and followed with the mount -o device option. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/volumes.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 7c538f65214b..5700ab03e84b 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -532,8 +532,19 @@ static noinline int device_list_add(const char *path,
532 * As of now don't allow update to btrfs_fs_device through 532 * As of now don't allow update to btrfs_fs_device through
533 * the btrfs dev scan cli, after FS has been mounted. 533 * the btrfs dev scan cli, after FS has been mounted.
534 */ 534 */
535 if (fs_devices->opened) 535 if (fs_devices->opened) {
536 return -EBUSY; 536 return -EBUSY;
537 } else {
538 /*
539 * That is if the FS is _not_ mounted and if you
540 * are here, that means there is more than one
541 * disk with same uuid and devid.We keep the one
542 * with larger generation number or the last-in if
543 * generation are equal.
544 */
545 if (found_transid < device->generation)
546 return -EEXIST;
547 }
537 548
538 name = rcu_string_strdup(path, GFP_NOFS); 549 name = rcu_string_strdup(path, GFP_NOFS);
539 if (!name) 550 if (!name)
@@ -546,6 +557,15 @@ static noinline int device_list_add(const char *path,
546 } 557 }
547 } 558 }
548 559
560 /*
561 * Unmount does not free the btrfs_device struct but would zero
562 * generation along with most of the other members. So just update
563 * it back. We need it to pick the disk with largest generation
564 * (as above).
565 */
566 if (!fs_devices->opened)
567 device->generation = found_transid;
568
549 if (found_transid > fs_devices->latest_trans) { 569 if (found_transid > fs_devices->latest_trans) {
550 fs_devices->latest_devid = devid; 570 fs_devices->latest_devid = devid;
551 fs_devices->latest_trans = found_transid; 571 fs_devices->latest_trans = found_transid;