Merge remote-tracking branch 'wireless-next/master' into mac80211-next
[firefly-linux-kernel-4.4.55.git] / drivers / block / virtio_blk.c
index f751fc392ba97d7366a961bc79628976cf7747c2..c6a27d54ad620b5ea25ae674d6b9a358b0f312fa 100644 (file)
@@ -41,12 +41,6 @@ struct virtio_blk
        /* Process context for config space updates */
        struct work_struct config_work;
 
-       /* Lock for config space updates */
-       struct mutex config_lock;
-
-       /* enable config space updates */
-       bool config_enable;
-
        /* What host tells us, plus 2 for header & tailer. */
        unsigned int sg_elems;
 
@@ -349,10 +343,6 @@ static void virtblk_config_changed_work(struct work_struct *work)
        char *envp[] = { "RESIZE=1", NULL };
        u64 capacity, size;
 
-       mutex_lock(&vblk->config_lock);
-       if (!vblk->config_enable)
-               goto done;
-
        /* Host must always specify the capacity. */
        virtio_cread(vdev, struct virtio_blk_config, capacity, &capacity);
 
@@ -376,8 +366,6 @@ static void virtblk_config_changed_work(struct work_struct *work)
        set_capacity(vblk->disk, capacity);
        revalidate_disk(vblk->disk);
        kobject_uevent_env(&disk_to_dev(vblk->disk)->kobj, KOBJ_CHANGE, envp);
-done:
-       mutex_unlock(&vblk->config_lock);
 }
 
 static void virtblk_config_changed(struct virtio_device *vdev)
@@ -608,10 +596,8 @@ static int virtblk_probe(struct virtio_device *vdev)
 
        vblk->vdev = vdev;
        vblk->sg_elems = sg_elems;
-       mutex_init(&vblk->config_lock);
 
        INIT_WORK(&vblk->config_work, virtblk_config_changed_work);
-       vblk->config_enable = true;
 
        err = init_vq(vblk);
        if (err)
@@ -735,6 +721,8 @@ static int virtblk_probe(struct virtio_device *vdev)
        if (!err && opt_io_size)
                blk_queue_io_opt(q, blk_size * opt_io_size);
 
+       virtio_device_ready(vdev);
+
        add_disk(vblk->disk);
        err = device_create_file(disk_to_dev(vblk->disk), &dev_attr_serial);
        if (err)
@@ -773,10 +761,8 @@ static void virtblk_remove(struct virtio_device *vdev)
        int index = vblk->index;
        int refc;
 
-       /* Prevent config work handler from accessing the device. */
-       mutex_lock(&vblk->config_lock);
-       vblk->config_enable = false;
-       mutex_unlock(&vblk->config_lock);
+       /* Make sure no work handler is accessing the device. */
+       flush_work(&vblk->config_work);
 
        del_gendisk(vblk->disk);
        blk_cleanup_queue(vblk->disk->queue);
@@ -786,8 +772,6 @@ static void virtblk_remove(struct virtio_device *vdev)
        /* Stop all the virtqueues. */
        vdev->config->reset(vdev);
 
-       flush_work(&vblk->config_work);
-
        refc = atomic_read(&disk_to_dev(vblk->disk)->kobj.kref.refcount);
        put_disk(vblk->disk);
        vdev->config->del_vqs(vdev);
@@ -807,11 +791,7 @@ static int virtblk_freeze(struct virtio_device *vdev)
        /* Ensure we don't receive any more interrupts */
        vdev->config->reset(vdev);
 
-       /* Prevent config work handler from accessing the device. */
-       mutex_lock(&vblk->config_lock);
-       vblk->config_enable = false;
-       mutex_unlock(&vblk->config_lock);
-
+       /* Make sure no work handler is accessing the device. */
        flush_work(&vblk->config_work);
 
        blk_mq_stop_hw_queues(vblk->disk->queue);
@@ -825,12 +805,14 @@ static int virtblk_restore(struct virtio_device *vdev)
        struct virtio_blk *vblk = vdev->priv;
        int ret;
 
-       vblk->config_enable = true;
        ret = init_vq(vdev->priv);
-       if (!ret)
-               blk_mq_start_stopped_hw_queues(vblk->disk->queue, true);
+       if (ret)
+               return ret;
 
-       return ret;
+       virtio_device_ready(vdev);
+
+       blk_mq_start_stopped_hw_queues(vblk->disk->queue, true);
+       return 0;
 }
 #endif