Merge branch 'linaro-android-3.10-lsk' of
[firefly-linux-kernel-4.4.55.git] / fs / btrfs / volumes.c
index b6c23c4abae273f09575b96f72fe3b98823d1a45..7fc774639a7879251ec32433d69b18d071d5e7fb 100644 (file)
@@ -1384,6 +1384,22 @@ out:
        return ret;
 }
 
+/*
+ * Function to update ctime/mtime for a given device path.
+ * Mainly used for ctime/mtime based probe like libblkid.
+ */
+static void update_dev_time(char *path_name)
+{
+       struct file *filp;
+
+       filp = filp_open(path_name, O_RDWR, 0);
+       if (!filp)
+               return;
+       file_update_time(filp);
+       filp_close(filp, NULL);
+       return;
+}
+
 static int btrfs_rm_dev_item(struct btrfs_root *root,
                             struct btrfs_device *device)
 {
@@ -1612,11 +1628,12 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
                struct btrfs_fs_devices *fs_devices;
                fs_devices = root->fs_info->fs_devices;
                while (fs_devices) {
-                       if (fs_devices->seed == cur_devices)
+                       if (fs_devices->seed == cur_devices) {
+                               fs_devices->seed = cur_devices->seed;
                                break;
+                       }
                        fs_devices = fs_devices->seed;
                }
-               fs_devices->seed = cur_devices->seed;
                cur_devices->seed = NULL;
                lock_chunks(root);
                __btrfs_close_devices(cur_devices);
@@ -1642,10 +1659,14 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
 
        ret = 0;
 
-       /* Notify udev that device has changed */
-       if (bdev)
+       if (bdev) {
+               /* Notify udev that device has changed */
                btrfs_kobject_uevent(bdev, KOBJ_CHANGE);
 
+               /* Update ctime/mtime for device path for libblkid */
+               update_dev_time(device_path);
+       }
+
 error_brelse:
        brelse(bh);
        if (bdev)
@@ -1817,7 +1838,6 @@ static int btrfs_prepare_sprout(struct btrfs_root *root)
        fs_devices->seeding = 0;
        fs_devices->num_devices = 0;
        fs_devices->open_devices = 0;
-       fs_devices->total_devices = 0;
        fs_devices->seed = seed_devices;
 
        generate_random_uuid(fs_devices->fsid);
@@ -2089,6 +2109,8 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
                ret = btrfs_commit_transaction(trans, root);
        }
 
+       /* Update ctime/mtime for libblkid */
+       update_dev_time(device_path);
        return ret;
 
 error_trans: