return ret;
}
+/*
+ * On a single device filesystem, the source and the target of a device
+ * replace share the fsid and both say num_devices == 1, but they are one
+ * filesystem, not clones. The target has devid BTRFS_DEV_REPLACE_DEVID.
+ */
+static bool is_dev_replace_pair(struct btrfs_fs_devices *fs_devices,
+ const struct btrfs_super_block *disk_super)
+{
+ struct btrfs_device *device;
+
+ if (btrfs_stack_device_id(&disk_super->dev_item) == BTRFS_DEV_REPLACE_DEVID)
+ return true;
+
+ list_for_each_entry(device, &fs_devices->devices, dev_list) {
+ if (device->devid == BTRFS_DEV_REPLACE_DEVID)
+ return true;
+ }
+
+ return false;
+}
+
static struct btrfs_fs_devices *find_fsid_by_device(
struct btrfs_super_block *disk_super,
dev_t devt, bool *same_fsid_diff_dev)
/* New device. */
if (fsid_fs_devices == NULL) {
return NULL;
+ } else if (is_dev_replace_pair(fsid_fs_devices, disk_super)) {
+ return fsid_fs_devices;
} else {
/* sb::fsid is already used create a new temp_fsid. */
*same_fsid_diff_dev = true;
mutex_unlock(&fs_devices->device_list_mutex);
}
+ /*
+ * The target of a device replace is not counted in num_devices, so
+ * the source and the target of a replace on a single device filesystem
+ * both say num_devices == 1. The target must be registered, or the
+ * filesystem cannot be mounted while the replace is in progress.
+ */
if (!mount_arg_dev && btrfs_super_num_devices(disk_super) == 1 &&
- !(btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_SEEDING))
+ !(btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_SEEDING) &&
+ btrfs_stack_device_id(&disk_super->dev_item) != BTRFS_DEV_REPLACE_DEVID)
return true;
return false;