They cannot separate the two chunk classes and are outside the
tiering use case targeted by this feature.
- Device replace does not copy the allocation hint to the target
- device. Reapply the hint after replacing a device. Hint updates are
- also not serialized with chunk allocation, so a concurrent new chunk
- may use either the old or the new setting.
+ Device replace copies the allocation hint to the target device;
+ the target's hint cannot be changed until the replace finishes.
+ Hint updates are not serialized with chunk allocation, so a
+ concurrent new chunk may use either the old or the new setting.
You are advised to watch your free space closely with btrfs tools
instead of relying on df only.
btrfs_dev_name(tgt_device));
clear_bit(BTRFS_DEV_STATE_REPLACE_TGT, &tgt_device->dev_state);
tgt_device->devid = src_device->devid;
+ /*
+ * The target inherits the source's dev item, including the type
+ * field (allocation hints). Copy it, or the next btrfs_update_device()
+ * on the target writes type 0 over it.
+ */
+ tgt_device->type = src_device->type;
src_device->devid = BTRFS_DEV_REPLACE_DEVID;
memcpy(uuid_tmp, tgt_device->uuid, sizeof(uuid_tmp));
memcpy(tgt_device->uuid, src_device->uuid, sizeof(tgt_device->uuid));
if (!btrfs_dev_allocation_hint_valid(type))
return -EINVAL;
+ /*
+ * A replace target has no dev item of its own until the replace
+ * finishes and it takes over the source's dev item and type. After
+ * the finish, the source has the replace devid and no dev item. The
+ * source's type may change during the replace: the target inherits
+ * it at the finish.
+ */
+ if (test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state) ||
+ device->devid == BTRFS_DEV_REPLACE_DEVID)
+ return -EBUSY;
+
trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans))
return PTR_ERR(trans);
ret = btrfs_update_device(trans, device);
+ /*
+ * No dev item: the device is being removed, or lost its devid to a
+ * replace that finished after the checks above. Nothing was changed,
+ * so there is nothing to abort.
+ */
+ if (ret == -ENOENT) {
+ btrfs_end_transaction(trans);
+ ret = -ENODEV;
+ goto abort;
+ }
+
if (ret < 0) {
btrfs_abort_transaction(trans, ret);
btrfs_end_transaction(trans);