]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/block/xen-blkfront.c
block: kill QUEUE_ORDERED_BY_TAG
[mirror_ubuntu-bionic-kernel.git] / drivers / block / xen-blkfront.c
index c6727b5cefd6f255a57f09e68d58fce64c18a75d..50ec6f834996320208b5c2f11319b71e09cc7900 100644 (file)
@@ -49,6 +49,7 @@
 #include <xen/grant_table.h>
 #include <xen/events.h>
 #include <xen/page.h>
+#include <xen/platform_pci.h>
 
 #include <xen/interface/grant_table.h>
 #include <xen/interface/io/blkif.h>
@@ -420,16 +421,21 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
 static int xlvbd_barrier(struct blkfront_info *info)
 {
        int err;
+       const char *barrier;
 
-       err = blk_queue_ordered(info->rq,
-                               info->feature_barrier ? QUEUE_ORDERED_DRAIN : QUEUE_ORDERED_NONE);
+       switch (info->feature_barrier) {
+       case QUEUE_ORDERED_DRAIN:       barrier = "enabled"; break;
+       case QUEUE_ORDERED_NONE:        barrier = "disabled"; break;
+       default:                        return -EINVAL;
+       }
+
+       err = blk_queue_ordered(info->rq, info->feature_barrier);
 
        if (err)
                return err;
 
        printk(KERN_INFO "blkfront: %s: barriers %s\n",
-              info->gd->disk_name,
-              info->feature_barrier ? "enabled" : "disabled");
+              info->gd->disk_name, barrier);
        return 0;
 }
 
@@ -509,8 +515,7 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity,
        info->rq = gd->queue;
        info->gd = gd;
 
-       if (info->feature_barrier)
-               xlvbd_barrier(info);
+       xlvbd_barrier(info);
 
        if (vdisk_info & VDISK_READONLY)
                set_disk_ro(gd, 1);
@@ -656,7 +661,7 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
                                printk(KERN_WARNING "blkfront: %s: write barrier op failed\n",
                                       info->gd->disk_name);
                                error = -EOPNOTSUPP;
-                               info->feature_barrier = 0;
+                               info->feature_barrier = QUEUE_ORDERED_NONE;
                                xlvbd_barrier(info);
                        }
                        /* fall through */
@@ -824,6 +829,35 @@ static int blkfront_probe(struct xenbus_device *dev,
                }
        }
 
+       if (xen_hvm_domain()) {
+               char *type;
+               int len;
+               /* no unplug has been done: do not hook devices != xen vbds */
+               if (xen_platform_pci_unplug & XEN_UNPLUG_IGNORE) {
+                       int major;
+
+                       if (!VDEV_IS_EXTENDED(vdevice))
+                               major = BLKIF_MAJOR(vdevice);
+                       else
+                               major = XENVBD_MAJOR;
+
+                       if (major != XENVBD_MAJOR) {
+                               printk(KERN_INFO
+                                               "%s: HVM does not support vbd %d as xen block device\n",
+                                               __FUNCTION__, vdevice);
+                               return -ENODEV;
+                       }
+               }
+               /* do not create a PV cdrom device if we are an HVM guest */
+               type = xenbus_read(XBT_NIL, dev->nodename, "device-type", &len);
+               if (IS_ERR(type))
+                       return -ENODEV;
+               if (strncmp(type, "cdrom", 5) == 0) {
+                       kfree(type);
+                       return -ENODEV;
+               }
+               kfree(type);
+       }
        info = kzalloc(sizeof(*info), GFP_KERNEL);
        if (!info) {
                xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure");
@@ -994,6 +1028,7 @@ static void blkfront_connect(struct blkfront_info *info)
        unsigned long sector_size;
        unsigned int binfo;
        int err;
+       int barrier;
 
        switch (info->connected) {
        case BLKIF_STATE_CONNECTED:
@@ -1034,10 +1069,25 @@ static void blkfront_connect(struct blkfront_info *info)
        }
 
        err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
-                           "feature-barrier", "%lu", &info->feature_barrier,
+                           "feature-barrier", "%lu", &barrier,
                            NULL);
+
+       /*
+        * If there's no "feature-barrier" defined, then it means
+        * we're dealing with a very old backend which writes
+        * synchronously; draining will do what needs to get done.
+        *
+        * If there are barriers, then we use flush.
+        *
+        * If barriers are not supported, then there's no much we can
+        * do, so just set ordering to NONE.
+        */
        if (err)
-               info->feature_barrier = 0;
+               info->feature_barrier = QUEUE_ORDERED_DRAIN;
+       else if (barrier)
+               info->feature_barrier = QUEUE_ORDERED_DRAIN_FLUSH;
+       else
+               info->feature_barrier = QUEUE_ORDERED_NONE;
 
        err = xlvbd_alloc_gendisk(sectors, info, binfo, sector_size);
        if (err) {
@@ -1210,6 +1260,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode)
                kfree(info);
        }
 
+out:
        unlock_kernel();
        return 0;
 }