These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / fs / btrfs / dev-replace.c
index 0573848..1e668fb 100644 (file)
@@ -183,8 +183,7 @@ no_valid_dev_replace_entry_found:
        }
 
 out:
-       if (path)
-               btrfs_free_path(path);
+       btrfs_free_path(path);
        return ret;
 }
 
@@ -328,19 +327,6 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
            args->start.tgtdev_name[0] == '\0')
                return -EINVAL;
 
-       /*
-        * Here we commit the transaction to make sure commit_total_bytes
-        * of all the devices are updated.
-        */
-       trans = btrfs_attach_transaction(root);
-       if (!IS_ERR(trans)) {
-               ret = btrfs_commit_transaction(trans, root);
-               if (ret)
-                       return ret;
-       } else if (PTR_ERR(trans) != -ENOENT) {
-               return PTR_ERR(trans);
-       }
-
        /* the disk copy procedure reuses the scrub code */
        mutex_lock(&fs_info->volume_mutex);
        ret = btrfs_dev_replace_find_srcdev(root, args->start.srcdevid,
@@ -357,6 +343,19 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
        if (ret)
                return ret;
 
+       /*
+        * Here we commit the transaction to make sure commit_total_bytes
+        * of all the devices are updated.
+        */
+       trans = btrfs_attach_transaction(root);
+       if (!IS_ERR(trans)) {
+               ret = btrfs_commit_transaction(trans, root);
+               if (ret)
+                       return ret;
+       } else if (PTR_ERR(trans) != -ENOENT) {
+               return PTR_ERR(trans);
+       }
+
        btrfs_dev_replace_lock(dev_replace);
        switch (dev_replace->replace_state) {
        case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED:
@@ -376,8 +375,8 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
        WARN_ON(!tgt_device);
        dev_replace->tgtdev = tgt_device;
 
-       printk_in_rcu(KERN_INFO
-                     "BTRFS: dev_replace from %s (devid %llu) to %s started\n",
+       btrfs_info_in_rcu(root->fs_info,
+                     "dev_replace from %s (devid %llu) to %s started",
                      src_device->missing ? "<missing disk>" :
                        rcu_str_deref(src_device->name),
                      src_device->devid,
@@ -398,6 +397,10 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
        args->result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
        btrfs_dev_replace_unlock(dev_replace);
 
+       ret = btrfs_sysfs_add_device_link(tgt_device->fs_devices, tgt_device);
+       if (ret)
+               btrfs_err(root->fs_info, "kobj add dev failed %d\n", ret);
+
        btrfs_wait_ordered_roots(root->fs_info, -1);
 
        /* force writing the updated state information to disk */
@@ -451,8 +454,7 @@ static void btrfs_rm_dev_replace_blocked(struct btrfs_fs_info *fs_info)
 static void btrfs_rm_dev_replace_unblocked(struct btrfs_fs_info *fs_info)
 {
        clear_bit(BTRFS_FS_STATE_DEV_REPLACING, &fs_info->fs_state);
-       if (waitqueue_active(&fs_info->replace_wait))
-               wake_up(&fs_info->replace_wait);
+       wake_up(&fs_info->replace_wait);
 }
 
 static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
@@ -520,8 +522,8 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
                                                                src_device,
                                                                tgt_device);
        } else {
-               printk_in_rcu(KERN_ERR
-                             "BTRFS: btrfs_scrub_dev(%s, %llu, %s) failed %d\n",
+               btrfs_err_in_rcu(root->fs_info,
+                             "btrfs_scrub_dev(%s, %llu, %s) failed %d",
                              src_device->missing ? "<missing disk>" :
                                rcu_str_deref(src_device->name),
                              src_device->devid,
@@ -537,8 +539,8 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
                return scrub_ret;
        }
 
-       printk_in_rcu(KERN_INFO
-                     "BTRFS: dev_replace from %s (devid %llu) to %s finished\n",
+       btrfs_info_in_rcu(root->fs_info,
+                     "dev_replace from %s (devid %llu) to %s finished",
                      src_device->missing ? "<missing disk>" :
                        rcu_str_deref(src_device->name),
                      src_device->devid,
@@ -583,8 +585,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
        mutex_unlock(&uuid_mutex);
 
        /* replace the sysfs entry */
-       btrfs_kobj_rm_device(fs_info, src_device);
-       btrfs_kobj_add_device(fs_info, tgt_device);
+       btrfs_sysfs_rm_device_link(fs_info->fs_devices, src_device);
        btrfs_rm_dev_replace_free_srcdev(fs_info, src_device);
 
        /* write back the superblocks */
@@ -807,8 +808,8 @@ static int btrfs_dev_replace_kthread(void *data)
                progress = status_args->status.progress_1000;
                kfree(status_args);
                progress = div_u64(progress, 10);
-               printk_in_rcu(KERN_INFO
-                       "BTRFS: continuing dev_replace from %s (devid %llu) to %s @%u%%\n",
+               btrfs_info_in_rcu(fs_info,
+                       "continuing dev_replace from %s (devid %llu) to %s @%u%%",
                        dev_replace->srcdev->missing ? "<missing disk>" :
                        rcu_str_deref(dev_replace->srcdev->name),
                        dev_replace->srcdev->devid,