History

Merge branch 'for-3.2/drivers' of git://git.kernel.dk/linux-block

* 'for-3.2/drivers' of git://git.kernel.dk/linux-block: (30 commits) virtio-blk: use ida to allocate disk index hpsa: add small delay when using PCI Power Management to reset for kump cciss: add small delay when using PCI Power Management to reset for kump xen/blkback: Fix two races in the handling of barrier requests. xen/blkback: Check for proper operation. xen/blkback: Fix the inhibition to map pages when discarding sector ranges. xen/blkback: Report VBD_WSECT (wr_sect) properly. xen/blkback: Support 'feature-barrier' aka old-style BARRIER requests. xen-blkfront: plug device number leak in xlblk_init() error path xen-blkfront: If no barrier or flush is supported, use invalid operation. xen-blkback: use kzalloc() in favor of kmalloc()+memset() xen-blkback: fixed indentation and comments xen-blkfront: fix a deadlock while handling discard response xen-blkfront: Handle discard requests. xen-blkback: Implement discard requests ('feature-discard') xen-blkfront: add BLKIF_OP_DISCARD and discard request struct drivers/block/loop.c: remove unnecessary bdev argument from loop_clr_fd() drivers/block/loop.c: emit uevent on auto release drivers/block/cpqarray.c: use pci_dev->revision loop: always allow userspace partitions and optionally support automatic scanning ... Fic up trivial header file includsion conflict in drivers/block/loop.c

Linus Torvalds committed 15 years ago

Commit 3d0a8d12 parents b4fdcb0 a0eda6218 files · +638 −123Browse files

Unified · Split

18 files
  1. Documentation/ABI/testing/sysfs-bus-pci-devices-cciss +7 −0
  2. Documentation/blockdev/cciss.txt +10 −0
  3. block/genhd.c +2 −2
  4. block/ioctl.c +1 −1
  5. drivers/block/cciss.c +65 −11
  6. drivers/block/cciss.h +1 −0
  7. drivers/block/cpqarray.c +1 −1
  8. drivers/block/loop.c +104 −7
  9. drivers/block/nbd.c +34 −35
  10. drivers/block/xen-blkback/blkback.c +109 −21
  11. drivers/block/xen-blkback/common.h +81 −17
  12. drivers/block/xen-blkback/xenbus.c +76 −0
  13. drivers/block/xen-blkfront.c +98 −25
  14. drivers/scsi/hpsa.c +7 −0
  15. fs/block_dev.c +1 −1
  16. include/linux/genhd.h +4 −2
  17. include/linux/loop.h +1 −0
  18. include/xen/interface/io/blkif.h +36 −0
Documentation/ABI/testing/sysfs-bus-pci-devices-cciss+7−0
@@ -71,3 +71,10 @@ Description: Value of 1 indicates the controller can honor the reset_devices · 70 unmodified lines
7171 a dump device, as kdump requires resetting the device in order
7272 to work reliably.
7373
74+Where: /sys/bus/pci/devices/<dev>/ccissX/transport_mode
75+Date: July 2011
76+Kernel Version: 3.0
77+Contact: iss_storagedev@hp.com
78+Description: Value of "simple" indicates that the controller has been placed
79+ in "simple mode". Value of "performant" indicates that the
80+ controller has been placed in "performant mode".
Documentation/blockdev/cciss.txt+10−0
@@ -78,6 +78,16 @@ The device naming scheme is: · 77 unmodified lines
7878 /dev/cciss/c1d1p2 Controller 1, disk 1, partition 2
7979 /dev/cciss/c1d1p3 Controller 1, disk 1, partition 3
8080
81+CCISS simple mode support
82+-------------------------
83+
84+The "cciss_simple_mode=1" boot parameter may be used to prevent the driver
85+from putting the controller into "performant" mode. The difference is that
86+with simple mode, each command completion requires an interrupt, while with
87+"performant mode" (the default, and ordinarily better performing) it is
88+possible to have multiple command completions indicated by a single
89+interrupt.
90+
8191 SCSI tape drive and medium changer support
8292 ------------------------------------------
8393
block/genhd.c+2−2
@@ -537,7 +537,7 @@ void register_disk(struct gendisk *disk) · 536 unmodified lines
537537 disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
538538
539539 /* No minors to use for partitions */
540− if (!disk_partitionable(disk))
540+ if (!disk_part_scan_enabled(disk))
541541 goto exit;
542542
543543 /* No such device (e.g., media were just removed) */
@@ -848,7 +848,7 @@ static int show_partition(struct seq_file *seqf, void *v) · 304 unmodified lines
848848 char buf[BDEVNAME_SIZE];
849849
850850 /* Don't show non-partitionable removeable devices or empty devices */
851− if (!get_capacity(sgp) || (!disk_partitionable(sgp) &&
851+ if (!get_capacity(sgp) || (!disk_max_parts(sgp) &&
852852 (sgp->flags & GENHD_FL_REMOVABLE)))
853853 return 0;
854854 if (sgp->flags & GENHD_FL_SUPPRESS_PARTITION_INFO)
block/ioctl.c+1−1
@@ -101,7 +101,7 @@ static int blkdev_reread_part(struct block_device *bdev) · 100 unmodified lines
101101 struct gendisk *disk = bdev->bd_disk;
102102 int res;
103103
104− if (!disk_partitionable(disk) || bdev != bdev->bd_contains)
104+ if (!disk_part_scan_enabled(disk) || bdev != bdev->bd_contains)
105105 return -EINVAL;
106106 if (!capable(CAP_SYS_ADMIN))
107107 return -EACCES;
drivers/block/cciss.c+65−11
@@ -68,6 +68,10 @@ static int cciss_tape_cmds = 6; · 67 unmodified lines
6868 module_param(cciss_tape_cmds, int, 0644);
6969 MODULE_PARM_DESC(cciss_tape_cmds,
7070 "number of commands to allocate for tape devices (default: 6)");
71+static int cciss_simple_mode;
72+module_param(cciss_simple_mode, int, S_IRUGO|S_IWUSR);
73+MODULE_PARM_DESC(cciss_simple_mode,
74+ "Use 'simple mode' rather than 'performant mode'");
7175
7276 static DEFINE_MUTEX(cciss_mutex);
7377 static struct proc_dir_entry *proc_cciss;
@@ -176,6 +180,7 @@ static void cciss_geometry_inquiry(ctlr_info_t *h, int logvol, · 102 unmodified lines
176180 unsigned int block_size, InquiryData_struct *inq_buff,
177181 drive_info_struct *drv);
178182 static void __devinit cciss_interrupt_mode(ctlr_info_t *);
183+static int __devinit cciss_enter_simple_mode(struct ctlr_info *h);
179184 static void start_io(ctlr_info_t *h);
180185 static int sendcmd_withirq(ctlr_info_t *h, __u8 cmd, void *buff, size_t size,
181186 __u8 page_code, unsigned char scsi3addr[],
@@ -388,7 +393,7 @@ static void cciss_seq_show_header(struct seq_file *seq) · 206 unmodified lines
388393 h->product_name,
389394 (unsigned long)h->board_id,
390395 h->firm_ver[0], h->firm_ver[1], h->firm_ver[2],
391− h->firm_ver[3], (unsigned int)h->intr[PERF_MODE_INT],
396+ h->firm_ver[3], (unsigned int)h->intr[h->intr_mode],
392397 h->num_luns,
393398 h->Qdepth, h->commands_outstanding,
394399 h->maxQsinceinit, h->max_outstanding, h->maxSG);
@@ -636,6 +641,18 @@ static ssize_t host_store_rescan(struct device *dev, · 241 unmodified lines
636641 }
637642 static DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan);
638643
644+static ssize_t host_show_transport_mode(struct device *dev,
645+ struct device_attribute *attr,
646+ char *buf)
647+{
648+ struct ctlr_info *h = to_hba(dev);
649+
650+ return snprintf(buf, 20, "%s\n",
651+ h->transMethod & CFGTBL_Trans_Performant ?
652+ "performant" : "simple");
653+}
654+static DEVICE_ATTR(transport_mode, S_IRUGO, host_show_transport_mode, NULL);
655+
639656 static ssize_t dev_show_unique_id(struct device *dev,
640657 struct device_attribute *attr,
641658 char *buf)
@@ -808,6 +825,7 @@ static DEVICE_ATTR(usage_count, S_IRUGO, cciss_show_usage_count, NULL); · 166 unmodified lines
808825 static struct attribute *cciss_host_attrs[] = {
809826 &dev_attr_rescan.attr,
810827 &dev_attr_resettable.attr,
828+ &dev_attr_transport_mode.attr,
811829 NULL
812830 };
813831
@@ -3984,6 +4002,9 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h) · 3170 unmodified lines
39844002 {
39854003 __u32 trans_support;
39864004
4005+ if (cciss_simple_mode)
4006+ return;
4007+
39874008 dev_dbg(&h->pdev->dev, "Trying to put board into Performant mode\n");
39884009 /* Attempt to put controller into performant mode if supported */
39894010 /* Does board support performant mode? */
@@ -4081,7 +4102,7 @@ static void __devinit cciss_interrupt_mode(ctlr_info_t *h) · 91 unmodified lines
40814102 default_int_mode:
40824103 #endif /* CONFIG_PCI_MSI */
40834104 /* if we get here we're going to use the default interrupt mode */
4084− h->intr[PERF_MODE_INT] = h->pdev->irq;
4105+ h->intr[h->intr_mode] = h->pdev->irq;
40854106 return;
40864107 }
40874108
@@ -4341,6 +4362,9 @@ static int __devinit cciss_pci_init(ctlr_info_t *h) · 253 unmodified lines
43414362 }
43424363 cciss_enable_scsi_prefetch(h);
43434364 cciss_p600_dma_prefetch_quirk(h);
4365+ err = cciss_enter_simple_mode(h);
4366+ if (err)
4367+ goto err_out_free_res;
43444368 cciss_put_controller_into_performant_mode(h);
43454369 return 0;
43464370
@@ -4533,6 +4557,13 @@ static int cciss_controller_hard_reset(struct pci_dev *pdev, · 186 unmodified lines
45334557 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
45344558 pmcsr |= PCI_D0;
45354559 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
4560+
4561+ /*
4562+ * The P600 requires a small delay when changing states.
4563+ * Otherwise we may think the board did not reset and we bail.
4564+ * This for kdump only and is particular to the P600.
4565+ */
4566+ msleep(500);
45364567 }
45374568 return 0;
45384569 }
@@ -4843,20 +4874,20 @@ static int cciss_request_irq(ctlr_info_t *h, · 304 unmodified lines
48434874 irqreturn_t (*intxhandler)(int, void *))
48444875 {
48454876 if (h->msix_vector || h->msi_vector) {
4846− if (!request_irq(h->intr[PERF_MODE_INT], msixhandler,
4877+ if (!request_irq(h->intr[h->intr_mode], msixhandler,
48474878 IRQF_DISABLED, h->devname, h))
48484879 return 0;
48494880 dev_err(&h->pdev->dev, "Unable to get msi irq %d"
4850− " for %s\n", h->intr[PERF_MODE_INT],
4881+ " for %s\n", h->intr[h->intr_mode],
48514882 h->devname);
48524883 return -1;
48534884 }
48544885
4855− if (!request_irq(h->intr[PERF_MODE_INT], intxhandler,
4886+ if (!request_irq(h->intr[h->intr_mode], intxhandler,
48564887 IRQF_DISABLED, h->devname, h))
48574888 return 0;
48584889 dev_err(&h->pdev->dev, "Unable to get irq %d for %s\n",
4859− h->intr[PERF_MODE_INT], h->devname);
4890+ h->intr[h->intr_mode], h->devname);
48604891 return -1;
48614892 }
48624893
@@ -4887,7 +4918,7 @@ static void cciss_undo_allocations_after_kdump_soft_reset(ctlr_info_t *h) · 24 unmodified lines
48874918 {
48884919 int ctlr = h->ctlr;
48894920
4890− free_irq(h->intr[PERF_MODE_INT], h);
4921+ free_irq(h->intr[h->intr_mode], h);
48914922 #ifdef CONFIG_PCI_MSI
48924923 if (h->msix_vector)
48934924 pci_disable_msix(h->pdev);
@@ -4953,6 +4984,7 @@ reinit_after_soft_reset: · 59 unmodified lines
49534984 h = hba[i];
49544985 h->pdev = pdev;
49554986 h->busy_initializing = 1;
4987+ h->intr_mode = cciss_simple_mode ? SIMPLE_MODE_INT : PERF_MODE_INT;
49564988 INIT_LIST_HEAD(&h->cmpQ);
49574989 INIT_LIST_HEAD(&h->reqQ);
49584990 mutex_init(&h->busy_shutting_down);
@@ -5009,7 +5041,7 @@ reinit_after_soft_reset: · 50 unmodified lines
50095041
50105042 dev_info(&h->pdev->dev, "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n",
50115043 h->devname, pdev->device, pci_name(pdev),
5012− h->intr[PERF_MODE_INT], dac ? "" : " not");
5044+ h->intr[h->intr_mode], dac ? "" : " not");
50135045
50145046 if (cciss_allocate_cmd_pool(h))
50155047 goto clean4;
@@ -5056,7 +5088,7 @@ reinit_after_soft_reset: · 40 unmodified lines
50565088 spin_lock_irqsave(&h->lock, flags);
50575089 h->access.set_intr_mask(h, CCISS_INTR_OFF);
50585090 spin_unlock_irqrestore(&h->lock, flags);
5059− free_irq(h->intr[PERF_MODE_INT], h);
5091+ free_irq(h->intr[h->intr_mode], h);
50605092 rc = cciss_request_irq(h, cciss_msix_discard_completions,
50615093 cciss_intx_discard_completions);
50625094 if (rc) {
@@ -5133,7 +5165,7 @@ clean4: · 70 unmodified lines
51335165 cciss_free_cmd_pool(h);
51345166 cciss_free_scatterlists(h);
51355167 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
5136− free_irq(h->intr[PERF_MODE_INT], h);
5168+ free_irq(h->intr[h->intr_mode], h);
51375169 clean2:
51385170 unregister_blkdev(h->major, h->devname);
51395171 clean1:
@@ -5172,9 +5204,31 @@ static void cciss_shutdown(struct pci_dev *pdev) · 32 unmodified lines
51725204 if (return_code != IO_OK)
51735205 dev_warn(&h->pdev->dev, "Error flushing cache\n");
51745206 h->access.set_intr_mask(h, CCISS_INTR_OFF);
5175− free_irq(h->intr[PERF_MODE_INT], h);
5207+ free_irq(h->intr[h->intr_mode], h);
5208+}
5209+
5210+static int __devinit cciss_enter_simple_mode(struct ctlr_info *h)
5211+{
5212+ u32 trans_support;
5213+
5214+ trans_support = readl(&(h->cfgtable->TransportSupport));
5215+ if (!(trans_support & SIMPLE_MODE))
5216+ return -ENOTSUPP;
5217+
5218+ h->max_commands = readl(&(h->cfgtable->CmdsOutMax));
5219+ writel(CFGTBL_Trans_Simple, &(h->cfgtable->HostWrite.TransportRequest));
5220+ writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
5221+ cciss_wait_for_mode_change_ack(h);
5222+ print_cfg_table(h);
5223+ if (!(readl(&(h->cfgtable->TransportActive)) & CFGTBL_Trans_Simple)) {
5224+ dev_warn(&h->pdev->dev, "unable to get board into simple mode\n");
5225+ return -ENODEV;
5226+ }
5227+ h->transMethod = CFGTBL_Trans_Simple;
5228+ return 0;
51765229 }
51775230
5231+
51785232 static void __devexit cciss_remove_one(struct pci_dev *pdev)
51795233 {
51805234 ctlr_info_t *h;
drivers/block/cciss.h+1−0
@@ -92,6 +92,7 @@ struct ctlr_info · 91 unmodified lines
9292 unsigned int intr[4];
9393 unsigned int msix_vector;
9494 unsigned int msi_vector;
95+ int intr_mode;
9596 int cciss_max_sectors;
9697 BYTE cciss_read;
9798 BYTE cciss_write;
drivers/block/cpqarray.c+1−1
@@ -620,6 +620,7 @@ static int cpqarray_pci_init(ctlr_info_t *c, struct pci_dev *pdev) · 619 unmodified lines
620620 }
621621 vendor_id = pdev->vendor;
622622 device_id = pdev->device;
623+ revision = pdev->revision;
623624 irq = pdev->irq;
624625
625626 for(i=0; i<6; i++)
@@ -632,7 +633,6 @@ static int cpqarray_pci_init(ctlr_info_t *c, struct pci_dev *pdev) · 6 unmodified lines
632633 }
633634
634635 pci_read_config_word(pdev, PCI_COMMAND, &command);
635− pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
636636 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &cache_line_size);
637637 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency_timer);
638638
drivers/block/loop.c+104−7
@@ -76,6 +76,8 @@ · 75 unmodified lines
7676 #include <linux/splice.h>
7777 #include <linux/sysfs.h>
7878 #include <linux/miscdevice.h>
79+#include <linux/falloc.h>
80+
7981 #include <asm/uaccess.h>
8082
8183 static DEFINE_IDR(loop_index_idr);
@@ -407,6 +409,29 @@ static int do_bio_filebacked(struct loop_device *lo, struct bio *bio) · 325 unmodified lines
407409 }
408410 }
409411
412+ /*
413+ * We use punch hole to reclaim the free space used by the
414+ * image a.k.a. discard. However we do support discard if
415+ * encryption is enabled, because it may give an attacker
416+ * useful information.
417+ */
418+ if (bio->bi_rw & REQ_DISCARD) {
419+ struct file *file = lo->lo_backing_file;
420+ int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
421+
422+ if ((!file->f_op->fallocate) ||
423+ lo->lo_encrypt_key_size) {
424+ ret = -EOPNOTSUPP;
425+ goto out;
426+ }
427+ ret = file->f_op->fallocate(file, mode, pos,
428+ bio->bi_size);
429+ if (unlikely(ret && ret != -EINVAL &&
430+ ret != -EOPNOTSUPP))
431+ ret = -EIO;
432+ goto out;
433+ }
434+
410435 ret = lo_send(lo, bio, pos);
411436
412437 if ((bio->bi_rw & REQ_FUA) && !ret) {
@@ -622,7 +647,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, · 209 unmodified lines
622647 goto out_putf;
623648
624649 fput(old_file);
625− if (max_part > 0)
650+ if (lo->lo_flags & LO_FLAGS_PARTSCAN)
626651 ioctl_by_bdev(bdev, BLKRRPART, 0);
627652 return 0;
628653
@@ -699,16 +724,25 @@ static ssize_t loop_attr_autoclear_show(struct loop_device *lo, char *buf) · 70 unmodified lines
699724 return sprintf(buf, "%s\n", autoclear ? "1" : "0");
700725 }
701726
727+static ssize_t loop_attr_partscan_show(struct loop_device *lo, char *buf)
728+{
729+ int partscan = (lo->lo_flags & LO_FLAGS_PARTSCAN);
730+
731+ return sprintf(buf, "%s\n", partscan ? "1" : "0");
732+}
733+
702734 LOOP_ATTR_RO(backing_file);
703735 LOOP_ATTR_RO(offset);
704736 LOOP_ATTR_RO(sizelimit);
705737 LOOP_ATTR_RO(autoclear);
738+LOOP_ATTR_RO(partscan);
706739
707740 static struct attribute *loop_attrs[] = {
708741 &loop_attr_backing_file.attr,
709742 &loop_attr_offset.attr,
710743 &loop_attr_sizelimit.attr,
711744 &loop_attr_autoclear.attr,
745+ &loop_attr_partscan.attr,
712746 NULL,
713747 };
714748
@@ -729,6 +763,35 @@ static void loop_sysfs_exit(struct loop_device *lo) · 14 unmodified lines
729763 &loop_attribute_group);
730764 }
731765
766+static void loop_config_discard(struct loop_device *lo)
767+{
768+ struct file *file = lo->lo_backing_file;
769+ struct inode *inode = file->f_mapping->host;
770+ struct request_queue *q = lo->lo_queue;
771+
772+ /*
773+ * We use punch hole to reclaim the free space used by the
774+ * image a.k.a. discard. However we do support discard if
775+ * encryption is enabled, because it may give an attacker
776+ * useful information.
777+ */
778+ if ((!file->f_op->fallocate) ||
779+ lo->lo_encrypt_key_size) {
780+ q->limits.discard_granularity = 0;
781+ q->limits.discard_alignment = 0;
782+ q->limits.max_discard_sectors = 0;
783+ q->limits.discard_zeroes_data = 0;
784+ queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, q);
785+ return;
786+ }
787+
788+ q->limits.discard_granularity = inode->i_sb->s_blocksize;
789+ q->limits.discard_alignment = inode->i_sb->s_blocksize;
790+ q->limits.max_discard_sectors = UINT_MAX >> 9;
791+ q->limits.discard_zeroes_data = 1;
792+ queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
793+}
794+
732795 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
733796 struct block_device *bdev, unsigned int arg)
734797 {
@@ -829,7 +892,9 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, · 94 unmodified lines
829892 }
830893 lo->lo_state = Lo_bound;
831894 wake_up_process(lo->lo_thread);
832− if (max_part > 0)
895+ if (part_shift)
896+ lo->lo_flags |= LO_FLAGS_PARTSCAN;
897+ if (lo->lo_flags & LO_FLAGS_PARTSCAN)
833898 ioctl_by_bdev(bdev, BLKRRPART, 0);
834899 return 0;
835900
@@ -890,10 +955,11 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer, · 54 unmodified lines
890955 return err;
891956 }
892957
893−static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev)
958+static int loop_clr_fd(struct loop_device *lo)
894959 {
895960 struct file *filp = lo->lo_backing_file;
896961 gfp_t gfp = lo->old_gfp_mask;
962+ struct block_device *bdev = lo->lo_device;
897963
898964 if (lo->lo_state != Lo_bound)
899965 return -ENXIO;
@@ -922,7 +988,6 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev) · 22 unmodified lines
922988 lo->lo_offset = 0;
923989 lo->lo_sizelimit = 0;
924990 lo->lo_encrypt_key_size = 0;
925− lo->lo_flags = 0;
926991 lo->lo_thread = NULL;
927992 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
928993 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
@@ -940,8 +1005,11 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev) · 11 unmodified lines
9401005 lo->lo_state = Lo_unbound;
9411006 /* This is safe: open() is still holding a reference. */
9421007 module_put(THIS_MODULE);
943− if (max_part > 0 && bdev)
1008+ if (lo->lo_flags & LO_FLAGS_PARTSCAN && bdev)
9441009 ioctl_by_bdev(bdev, BLKRRPART, 0);
1010+ lo->lo_flags = 0;
1011+ if (!part_shift)
1012+ lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN;
9451013 mutex_unlock(&lo->lo_ctl_mutex);
9461014 /*
9471015 * Need not hold lo_ctl_mutex to fput backing file.
@@ -995,6 +1063,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) · 47 unmodified lines
9951063 if (figure_loop_size(lo))
9961064 return -EFBIG;
9971065 }
1066+ loop_config_discard(lo);
9981067
9991068 memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE);
10001069 memcpy(lo->lo_crypt_name, info->lo_crypt_name, LO_NAME_SIZE);
@@ -1010,6 +1079,13 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) · 9 unmodified lines
10101079 (info->lo_flags & LO_FLAGS_AUTOCLEAR))
10111080 lo->lo_flags ^= LO_FLAGS_AUTOCLEAR;
10121081
1082+ if ((info->lo_flags & LO_FLAGS_PARTSCAN) &&
1083+ !(lo->lo_flags & LO_FLAGS_PARTSCAN)) {
1084+ lo->lo_flags |= LO_FLAGS_PARTSCAN;
1085+ lo->lo_disk->flags &= ~GENHD_FL_NO_PART_SCAN;
1086+ ioctl_by_bdev(lo->lo_device, BLKRRPART, 0);
1087+ }
1088+
10131089 lo->lo_encrypt_key_size = info->lo_encrypt_key_size;
10141090 lo->lo_init[0] = info->lo_init[0];
10151091 lo->lo_init[1] = info->lo_init[1];
@@ -1203,7 +1279,7 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode, · 187 unmodified lines
12031279 break;
12041280 case LOOP_CLR_FD:
12051281 /* loop_clr_fd would have unlocked lo_ctl_mutex on success */
1206− err = loop_clr_fd(lo, bdev);
1282+ err = loop_clr_fd(lo);
12071283 if (!err)
12081284 goto out_unlocked;
12091285 break;
@@ -1423,7 +1499,7 @@ static int lo_release(struct gendisk *disk, fmode_t mode) · 213 unmodified lines
14231499 * In autoclear mode, stop the loop thread
14241500 * and remove configuration after last close.
14251501 */
1426− err = loop_clr_fd(lo, NULL);
1502+ err = loop_clr_fd(lo);
14271503 if (!err)
14281504 goto out_unlocked;
14291505 } else {
@@ -1545,6 +1621,27 @@ static int loop_add(struct loop_device **l, int i) · 115 unmodified lines
15451621 if (!disk)
15461622 goto out_free_queue;
15471623
1624+ /*
1625+ * Disable partition scanning by default. The in-kernel partition
1626+ * scanning can be requested individually per-device during its
1627+ * setup. Userspace can always add and remove partitions from all
1628+ * devices. The needed partition minors are allocated from the
1629+ * extended minor space, the main loop device numbers will continue
1630+ * to match the loop minors, regardless of the number of partitions
1631+ * used.
1632+ *
1633+ * If max_part is given, partition scanning is globally enabled for
1634+ * all loop devices. The minors for the main loop devices will be
1635+ * multiples of max_part.
1636+ *
1637+ * Note: Global-for-all-devices, set-only-at-init, read-only module
1638+ * parameteters like 'max_loop' and 'max_part' make things needlessly
1639+ * complicated, are too static, inflexible and may surprise
1640+ * userspace tools. Parameters like this in general should be avoided.
1641+ */
1642+ if (!part_shift)
1643+ disk->flags |= GENHD_FL_NO_PART_SCAN;
1644+ disk->flags |= GENHD_FL_EXT_DEVT;
15481645 mutex_init(&lo->lo_ctl_mutex);
15491646 lo->lo_number = i;
15501647 lo->lo_thread = NULL;
drivers/block/nbd.c+34−35
@@ -127,8 +127,7 @@ static void sock_shutdown(struct nbd_device *lo, int lock) · 126 unmodified lines
127127 if (lock)
128128 mutex_lock(&lo->tx_lock);
129129 if (lo->sock) {
130− printk(KERN_WARNING "%s: shutting down socket\n",
131− lo->disk->disk_name);
130+ dev_warn(disk_to_dev(lo->disk), "shutting down socket\n");
132131 kernel_sock_shutdown(lo->sock, SHUT_RDWR);
133132 lo->sock = NULL;
134133 }
@@ -158,8 +157,9 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size, · 23 unmodified lines
158157 sigset_t blocked, oldset;
159158
160159 if (unlikely(!sock)) {
161− printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
162− lo->disk->disk_name, (send ? "send" : "recv"));
160+ dev_err(disk_to_dev(lo->disk),
161+ "Attempted %s on closed socket in sock_xmit\n",
162+ (send ? "send" : "recv"));
163163 return -EINVAL;
164164 }
165165
@@ -250,8 +250,8 @@ static int nbd_send_req(struct nbd_device *lo, struct request *req) · 84 unmodified lines
250250 result = sock_xmit(lo, 1, &request, sizeof(request),
251251 (nbd_cmd(req) == NBD_CMD_WRITE) ? MSG_MORE : 0);
252252 if (result <= 0) {
253− printk(KERN_ERR "%s: Send control failed (result %d)\n",
254− lo->disk->disk_name, result);
253+ dev_err(disk_to_dev(lo->disk),
254+ "Send control failed (result %d)\n", result);
255255 goto error_out;
256256 }
257257
@@ -270,8 +270,9 @@ static int nbd_send_req(struct nbd_device *lo, struct request *req) · 12 unmodified lines
270270 lo->disk->disk_name, req, bvec->bv_len);
271271 result = sock_send_bvec(lo, bvec, flags);
272272 if (result <= 0) {
273− printk(KERN_ERR "%s: Send data failed (result %d)\n",
274− lo->disk->disk_name, result);
273+ dev_err(disk_to_dev(lo->disk),
274+ "Send data failed (result %d)\n",
275+ result);
275276 goto error_out;
276277 }
277278 }
@@ -328,14 +329,13 @@ static struct request *nbd_read_stat(struct nbd_device *lo) · 50 unmodified lines
328329 reply.magic = 0;
329330 result = sock_xmit(lo, 0, &reply, sizeof(reply), MSG_WAITALL);
330331 if (result <= 0) {
331− printk(KERN_ERR "%s: Receive control failed (result %d)\n",
332− lo->disk->disk_name, result);
332+ dev_err(disk_to_dev(lo->disk),
333+ "Receive control failed (result %d)\n", result);
333334 goto harderror;
334335 }
335336
336337 if (ntohl(reply.magic) != NBD_REPLY_MAGIC) {
337− printk(KERN_ERR "%s: Wrong magic (0x%lx)\n",
338− lo->disk->disk_name,
338+ dev_err(disk_to_dev(lo->disk), "Wrong magic (0x%lx)\n",
339339 (unsigned long)ntohl(reply.magic));
340340 result = -EPROTO;
341341 goto harderror;
@@ -347,15 +347,15 @@ static struct request *nbd_read_stat(struct nbd_device *lo) · 5 unmodified lines
347347 if (result != -ENOENT)
348348 goto harderror;
349349
350− printk(KERN_ERR "%s: Unexpected reply (%p)\n",
351− lo->disk->disk_name, reply.handle);
350+ dev_err(disk_to_dev(lo->disk), "Unexpected reply (%p)\n",
351+ reply.handle);
352352 result = -EBADR;
353353 goto harderror;
354354 }
355355
356356 if (ntohl(reply.error)) {
357− printk(KERN_ERR "%s: Other side returned error (%d)\n",
358− lo->disk->disk_name, ntohl(reply.error));
357+ dev_err(disk_to_dev(lo->disk), "Other side returned error (%d)\n",
358+ ntohl(reply.error));
359359 req->errors++;
360360 return req;
361361 }
@@ -369,8 +369,8 @@ static struct request *nbd_read_stat(struct nbd_device *lo) · 7 unmodified lines
369369 rq_for_each_segment(bvec, req, iter) {
370370 result = sock_recv_bvec(lo, bvec);
371371 if (result <= 0) {
372− printk(KERN_ERR "%s: Receive data failed (result %d)\n",
373− lo->disk->disk_name, result);
372+ dev_err(disk_to_dev(lo->disk), "Receive data failed (result %d)\n",
373+ result);
374374 req->errors++;
375375 return req;
376376 }
@@ -405,10 +405,10 @@ static int nbd_do_it(struct nbd_device *lo) · 28 unmodified lines
405405
406406 BUG_ON(lo->magic != LO_MAGIC);
407407
408− lo->pid = current->pid;
409− ret = sysfs_create_file(&disk_to_dev(lo->disk)->kobj, &pid_attr.attr);
408+ lo->pid = task_pid_nr(current);
409+ ret = device_create_file(disk_to_dev(lo->disk), &pid_attr);
410410 if (ret) {
411− printk(KERN_ERR "nbd: sysfs_create_file failed!");
411+ dev_err(disk_to_dev(lo->disk), "device_create_file failed!\n");
412412 lo->pid = 0;
413413 return ret;
414414 }
@@ -416,7 +416,7 @@ static int nbd_do_it(struct nbd_device *lo) · 1 unmodified line
416416 while ((req = nbd_read_stat(lo)) != NULL)
417417 nbd_end_request(req);
418418
419− sysfs_remove_file(&disk_to_dev(lo->disk)->kobj, &pid_attr.attr);
419+ device_remove_file(disk_to_dev(lo->disk), &pid_attr);
420420 lo->pid = 0;
421421 return 0;
422422 }
@@ -457,8 +457,8 @@ static void nbd_handle_req(struct nbd_device *lo, struct request *req) · 34 unmodified lines
457457 if (rq_data_dir(req) == WRITE) {
458458 nbd_cmd(req) = NBD_CMD_WRITE;
459459 if (lo->flags & NBD_READ_ONLY) {
460− printk(KERN_ERR "%s: Write on read-only\n",
461− lo->disk->disk_name);
460+ dev_err(disk_to_dev(lo->disk),
461+ "Write on read-only\n");
462462 goto error_out;
463463 }
464464 }
@@ -468,16 +468,15 @@ static void nbd_handle_req(struct nbd_device *lo, struct request *req) · 3 unmodified lines
468468 mutex_lock(&lo->tx_lock);
469469 if (unlikely(!lo->sock)) {
470470 mutex_unlock(&lo->tx_lock);
471− printk(KERN_ERR "%s: Attempted send on closed socket\n",
472− lo->disk->disk_name);
471+ dev_err(disk_to_dev(lo->disk),
472+ "Attempted send on closed socket\n");
473473 goto error_out;
474474 }
475475
476476 lo->active_req = req;
477477
478478 if (nbd_send_req(lo, req) != 0) {
479− printk(KERN_ERR "%s: Request send failed\n",
480− lo->disk->disk_name);
479+ dev_err(disk_to_dev(lo->disk), "Request send failed\n");
481480 req->errors++;
482481 nbd_end_request(req);
483482 } else {
@@ -549,8 +548,8 @@ static void do_nbd_request(struct request_queue *q) · 65 unmodified lines
549548 BUG_ON(lo->magic != LO_MAGIC);
550549
551550 if (unlikely(!lo->sock)) {
552− printk(KERN_ERR "%s: Attempted send on closed socket\n",
553− lo->disk->disk_name);
551+ dev_err(disk_to_dev(lo->disk),
552+ "Attempted send on closed socket\n");
554553 req->errors++;
555554 nbd_end_request(req);
556555 spin_lock_irq(q->queue_lock);
@@ -576,7 +575,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo, · 19 unmodified lines
576575 case NBD_DISCONNECT: {
577576 struct request sreq;
578577
579− printk(KERN_INFO "%s: NBD_DISCONNECT\n", lo->disk->disk_name);
578+ dev_info(disk_to_dev(lo->disk), "NBD_DISCONNECT\n");
580579
581580 blk_rq_init(NULL, &sreq);
582581 sreq.cmd_type = REQ_TYPE_SPECIAL;
@@ -674,7 +673,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo, · 91 unmodified lines
674673 file = lo->file;
675674 lo->file = NULL;
676675 nbd_clear_que(lo);
677− printk(KERN_WARNING "%s: queue cleared\n", lo->disk->disk_name);
676+ dev_warn(disk_to_dev(lo->disk), "queue cleared\n");
678677 if (file)
679678 fput(file);
680679 lo->bytesize = 0;
@@ -694,8 +693,8 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo, · 13 unmodified lines
694693 return 0;
695694
696695 case NBD_PRINT_DEBUG:
697− printk(KERN_INFO "%s: next = %p, prev = %p, head = %p\n",
698− bdev->bd_disk->disk_name,
696+ dev_info(disk_to_dev(lo->disk),
697+ "next = %p, prev = %p, head = %p\n",
699698 lo->queue_head.next, lo->queue_head.prev,
700699 &lo->queue_head);
701700 return 0;
@@ -745,7 +744,7 @@ static int __init nbd_init(void) · 43 unmodified lines
745744 BUILD_BUG_ON(sizeof(struct nbd_request) != 28);
746745
747746 if (max_part < 0) {
748− printk(KERN_CRIT "nbd: max_part must be >= 0\n");
747+ printk(KERN_ERR "nbd: max_part must be >= 0\n");
749748 return -EINVAL;
750749 }
751750
drivers/block/xen-blkback/blkback.c+109−21
@@ -39,6 +39,9 @@ · 38 unmodified lines
3939 #include <linux/list.h>
4040 #include <linux/delay.h>
4141 #include <linux/freezer.h>
42+#include <linux/loop.h>
43+#include <linux/falloc.h>
44+#include <linux/fs.h>
4245
4346 #include <xen/events.h>
4447 #include <xen/page.h>
@@ -258,13 +261,16 @@ irqreturn_t xen_blkif_be_int(int irq, void *dev_id) · 213 unmodified lines
258261
259262 static void print_stats(struct xen_blkif *blkif)
260263 {
261− pr_info("xen-blkback (%s): oo %3d | rd %4d | wr %4d | f %4d\n",
264+ pr_info("xen-blkback (%s): oo %3d | rd %4d | wr %4d | f %4d"
265+ " | ds %4d\n",
262266 current->comm, blkif->st_oo_req,
263− blkif->st_rd_req, blkif->st_wr_req, blkif->st_f_req);
267+ blkif->st_rd_req, blkif->st_wr_req,
268+ blkif->st_f_req, blkif->st_ds_req);
264269 blkif->st_print = jiffies + msecs_to_jiffies(10 * 1000);
265270 blkif->st_rd_req = 0;
266271 blkif->st_wr_req = 0;
267272 blkif->st_oo_req = 0;
273+ blkif->st_ds_req = 0;
268274 }
269275
270276 int xen_blkif_schedule(void *arg)
@@ -410,6 +416,59 @@ static int xen_blkbk_map(struct blkif_request *req, · 139 unmodified lines
410416 return ret;
411417 }
412418
419+static void xen_blk_discard(struct xen_blkif *blkif, struct blkif_request *req)
420+{
421+ int err = 0;
422+ int status = BLKIF_RSP_OKAY;
423+ struct block_device *bdev = blkif->vbd.bdev;
424+
425+ if (blkif->blk_backend_type == BLKIF_BACKEND_PHY)
426+ /* just forward the discard request */
427+ err = blkdev_issue_discard(bdev,
428+ req->u.discard.sector_number,
429+ req->u.discard.nr_sectors,
430+ GFP_KERNEL, 0);
431+ else if (blkif->blk_backend_type == BLKIF_BACKEND_FILE) {
432+ /* punch a hole in the backing file */
433+ struct loop_device *lo = bdev->bd_disk->private_data;
434+ struct file *file = lo->lo_backing_file;
435+
436+ if (file->f_op->fallocate)
437+ err = file->f_op->fallocate(file,
438+ FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
439+ req->u.discard.sector_number << 9,
440+ req->u.discard.nr_sectors << 9);
441+ else
442+ err = -EOPNOTSUPP;
443+ } else
444+ err = -EOPNOTSUPP;
445+
446+ if (err == -EOPNOTSUPP) {
447+ pr_debug(DRV_PFX "discard op failed, not supported\n");
448+ status = BLKIF_RSP_EOPNOTSUPP;
449+ } else if (err)
450+ status = BLKIF_RSP_ERROR;
451+
452+ make_response(blkif, req->id, req->operation, status);
453+}
454+
455+static void xen_blk_drain_io(struct xen_blkif *blkif)
456+{
457+ atomic_set(&blkif->drain, 1);
458+ do {
459+ /* The initial value is one, and one refcnt taken at the
460+ * start of the xen_blkif_schedule thread. */
461+ if (atomic_read(&blkif->refcnt) <= 2)
462+ break;
463+ wait_for_completion_interruptible_timeout(
464+ &blkif->drain_complete, HZ);
465+
466+ if (!atomic_read(&blkif->drain))
467+ break;
468+ } while (!kthread_should_stop());
469+ atomic_set(&blkif->drain, 0);
470+}
471+
413472 /*
414473 * Completion callback on the bio's. Called as bh->b_end_io()
415474 */
@@ -422,6 +481,11 @@ static void __end_block_io_op(struct pending_req *pending_req, int error) · 6 unmodified lines
422481 pr_debug(DRV_PFX "flush diskcache op failed, not supported\n");
423482 xen_blkbk_flush_diskcache(XBT_NIL, pending_req->blkif->be, 0);
424483 pending_req->status = BLKIF_RSP_EOPNOTSUPP;
484+ } else if ((pending_req->operation == BLKIF_OP_WRITE_BARRIER) &&
485+ (error == -EOPNOTSUPP)) {
486+ pr_debug(DRV_PFX "write barrier op failed, not supported\n");
487+ xen_blkbk_barrier(XBT_NIL, pending_req->blkif->be, 0);
488+ pending_req->status = BLKIF_RSP_EOPNOTSUPP;
425489 } else if (error) {
426490 pr_debug(DRV_PFX "Buffer not up-to-date at end of operation,"
427491 " error=%d\n", error);
@@ -438,6 +502,10 @@ static void __end_block_io_op(struct pending_req *pending_req, int error) · 10 unmodified lines
438502 make_response(pending_req->blkif, pending_req->id,
439503 pending_req->operation, pending_req->status);
440504 xen_blkif_put(pending_req->blkif);
505+ if (atomic_read(&pending_req->blkif->refcnt) <= 2) {
506+ if (atomic_read(&pending_req->blkif->drain))
507+ complete(&pending_req->blkif->drain_complete);
508+ }
441509 free_req(pending_req);
442510 }
443511 }
@@ -532,7 +600,6 @@ do_block_io_op(struct xen_blkif *blkif) · 88 unmodified lines
532600
533601 return more_to_do;
534602 }
535−
536603 /*
537604 * Transmutation of the 'struct blkif_request' to a proper 'struct bio'
538605 * and call the 'submit_bio' to pass it to the underlying storage.
@@ -549,6 +616,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, · 10 unmodified lines
549616 int i, nbio = 0;
550617 int operation;
551618 struct blk_plug plug;
619+ bool drain = false;
552620
553621 switch (req->operation) {
554622 case BLKIF_OP_READ:
@@ -559,11 +627,16 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, · 4 unmodified lines
559627 blkif->st_wr_req++;
560628 operation = WRITE_ODIRECT;
561629 break;
630+ case BLKIF_OP_WRITE_BARRIER:
631+ drain = true;
562632 case BLKIF_OP_FLUSH_DISKCACHE:
563633 blkif->st_f_req++;
564634 operation = WRITE_FLUSH;
565635 break;
566− case BLKIF_OP_WRITE_BARRIER:
636+ case BLKIF_OP_DISCARD:
637+ blkif->st_ds_req++;
638+ operation = REQ_DISCARD;
639+ break;
567640 default:
568641 operation = 0; /* make gcc happy */
569642 goto fail_response;
@@ -572,7 +645,8 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, · 2 unmodified lines
572645
573646 /* Check that the number of segments is sane. */
574647 nseg = req->nr_segments;
575− if (unlikely(nseg == 0 && operation != WRITE_FLUSH) ||
648+ if (unlikely(nseg == 0 && operation != WRITE_FLUSH &&
649+ operation != REQ_DISCARD) ||
576650 unlikely(nseg > BLKIF_MAX_SEGMENTS_PER_REQUEST)) {
577651 pr_debug(DRV_PFX "Bad number of segments in request (%d)\n",
578652 nseg);
@@ -621,16 +695,25 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, · 42 unmodified lines
621695 }
622696 }
623697
698+ /* Wait on all outstanding I/O's and once that has been completed
699+ * issue the WRITE_FLUSH.
700+ */
701+ if (drain)
702+ xen_blk_drain_io(pending_req->blkif);
703+
624704 /*
625705 * If we have failed at this point, we need to undo the M2P override,
626706 * set gnttab_set_unmap_op on all of the grant references and perform
627707 * the hypercall to unmap the grants - that is all done in
628708 * xen_blkbk_unmap.
629709 */
630− if (xen_blkbk_map(req, pending_req, seg))
710+ if (operation != REQ_DISCARD && xen_blkbk_map(req, pending_req, seg))
631711 goto fail_flush;
632712
633− /* This corresponding xen_blkif_put is done in __end_block_io_op */
713+ /*
714+ * This corresponding xen_blkif_put is done in __end_block_io_op, or
715+ * below (in "!bio") if we are handling a BLKIF_OP_DISCARD.
716+ */
634717 xen_blkif_get(blkif);
635718
636719 for (i = 0; i < nseg; i++) {
@@ -654,18 +737,25 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, · 17 unmodified lines
654737 preq.sector_number += seg[i].nsec;
655738 }
656739
657− /* This will be hit if the operation was a flush. */
740+ /* This will be hit if the operation was a flush or discard. */
658741 if (!bio) {
659− BUG_ON(operation != WRITE_FLUSH);
742+ BUG_ON(operation != WRITE_FLUSH && operation != REQ_DISCARD);
660743
661− bio = bio_alloc(GFP_KERNEL, 0);
662− if (unlikely(bio == NULL))
663− goto fail_put_bio;
744+ if (operation == WRITE_FLUSH) {
745+ bio = bio_alloc(GFP_KERNEL, 0);
746+ if (unlikely(bio == NULL))
747+ goto fail_put_bio;
664748
665− biolist[nbio++] = bio;
666− bio->bi_bdev = preq.bdev;
667− bio->bi_private = pending_req;
668− bio->bi_end_io = end_block_io_op;
749+ biolist[nbio++] = bio;
750+ bio->bi_bdev = preq.bdev;
751+ bio->bi_private = pending_req;
752+ bio->bi_end_io = end_block_io_op;
753+ } else if (operation == REQ_DISCARD) {
754+ xen_blk_discard(blkif, req);
755+ xen_blkif_put(blkif);
756+ free_req(pending_req);
757+ return 0;
758+ }
669759 }
670760
671761 /*
@@ -685,7 +775,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, · 13 unmodified lines
685775
686776 if (operation == READ)
687777 blkif->st_rd_sect += preq.nr_sects;
688− else if (operation == WRITE || operation == WRITE_FLUSH)
778+ else if (operation & WRITE)
689779 blkif->st_wr_sect += preq.nr_sects;
690780
691781 return 0;
@@ -765,9 +855,9 @@ static int __init xen_blkif_init(void) · 73 unmodified lines
765855
766856 mmap_pages = xen_blkif_reqs * BLKIF_MAX_SEGMENTS_PER_REQUEST;
767857
768− blkbk->pending_reqs = kmalloc(sizeof(blkbk->pending_reqs[0]) *
858+ blkbk->pending_reqs = kzalloc(sizeof(blkbk->pending_reqs[0]) *
769859 xen_blkif_reqs, GFP_KERNEL);
770− blkbk->pending_grant_handles = kzalloc(sizeof(blkbk->pending_grant_handles[0]) *
860+ blkbk->pending_grant_handles = kmalloc(sizeof(blkbk->pending_grant_handles[0]) *
771861 mmap_pages, GFP_KERNEL);
772862 blkbk->pending_pages = kzalloc(sizeof(blkbk->pending_pages[0]) *
773863 mmap_pages, GFP_KERNEL);
@@ -790,8 +880,6 @@ static int __init xen_blkif_init(void) · 16 unmodified lines
790880 if (rc)
791881 goto failed_init;
792882
793− memset(blkbk->pending_reqs, 0, sizeof(blkbk->pending_reqs));
794−
795883 INIT_LIST_HEAD(&blkbk->pending_free);
796884 spin_lock_init(&blkbk->pending_free_lock);
797885 init_waitqueue_head(&blkbk->pending_free_wq);
drivers/block/xen-blkback/common.h+81−17
@@ -62,13 +62,26 @@ struct blkif_common_response { · 61 unmodified lines
6262
6363 /* i386 protocol version */
6464 #pragma pack(push, 4)
65+
66+struct blkif_x86_32_request_rw {
67+ blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
68+ struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
69+};
70+
71+struct blkif_x86_32_request_discard {
72+ blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
73+ uint64_t nr_sectors;
74+};
75+
6576 struct blkif_x86_32_request {
6677 uint8_t operation; /* BLKIF_OP_??? */
6778 uint8_t nr_segments; /* number of segments */
6879 blkif_vdev_t handle; /* only for read/write requests */
6980 uint64_t id; /* private guest value, echoed in resp */
70− blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
71− struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
81+ union {
82+ struct blkif_x86_32_request_rw rw;
83+ struct blkif_x86_32_request_discard discard;
84+ } u;
7285 };
7386 struct blkif_x86_32_response {
7487 uint64_t id; /* copied from request */
@@ -78,13 +91,26 @@ struct blkif_x86_32_response { · 3 unmodified lines
7891 #pragma pack(pop)
7992
8093 /* x86_64 protocol version */
94+
95+struct blkif_x86_64_request_rw {
96+ blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
97+ struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
98+};
99+
100+struct blkif_x86_64_request_discard {
101+ blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
102+ uint64_t nr_sectors;
103+};
104+
81105 struct blkif_x86_64_request {
82106 uint8_t operation; /* BLKIF_OP_??? */
83107 uint8_t nr_segments; /* number of segments */
84108 blkif_vdev_t handle; /* only for read/write requests */
85109 uint64_t __attribute__((__aligned__(8))) id;
86− blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
87− struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
110+ union {
111+ struct blkif_x86_64_request_rw rw;
112+ struct blkif_x86_64_request_discard discard;
113+ } u;
88114 };
89115 struct blkif_x86_64_response {
90116 uint64_t __attribute__((__aligned__(8))) id;
@@ -112,6 +138,11 @@ enum blkif_protocol { · 21 unmodified lines
112138 BLKIF_PROTOCOL_X86_64 = 3,
113139 };
114140
141+enum blkif_backend_type {
142+ BLKIF_BACKEND_PHY = 1,
143+ BLKIF_BACKEND_FILE = 2,
144+};
145+
115146 struct xen_vbd {
116147 /* What the domain refers to this vbd as. */
117148 blkif_vdev_t handle;
@@ -137,6 +168,7 @@ struct xen_blkif { · 19 unmodified lines
137168 unsigned int irq;
138169 /* Comms information. */
139170 enum blkif_protocol blk_protocol;
171+ enum blkif_backend_type blk_backend_type;
140172 union blkif_back_rings blk_rings;
141173 struct vm_struct *blk_ring_area;
142174 /* The VBD attached to this interface. */
@@ -148,6 +180,9 @@ struct xen_blkif { · 5 unmodified lines
148180 atomic_t refcnt;
149181
150182 wait_queue_head_t wq;
183+ /* for barrier (drain) requests */
184+ struct completion drain_complete;
185+ atomic_t drain;
151186 /* One thread per one blkif. */
152187 struct task_struct *xenblkd;
153188 unsigned int waiting_reqs;
@@ -158,6 +193,7 @@ struct xen_blkif { · 4 unmodified lines
158193 int st_wr_req;
159194 int st_oo_req;
160195 int st_f_req;
196+ int st_ds_req;
161197 int st_rd_sect;
162198 int st_wr_sect;
163199
@@ -181,7 +217,7 @@ struct xen_blkif { · 17 unmodified lines
181217
182218 struct phys_req {
183219 unsigned short dev;
184− unsigned short nr_sects;
220+ blkif_sector_t nr_sects;
185221 struct block_device *bdev;
186222 blkif_sector_t sector_number;
187223 };
@@ -195,6 +231,8 @@ int xen_blkif_schedule(void *arg); · 7 unmodified lines
195231 int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt,
196232 struct backend_info *be, int state);
197233
234+int xen_blkbk_barrier(struct xenbus_transaction xbt,
235+ struct backend_info *be, int state);
198236 struct xenbus_device *xen_blkbk_xenbus(struct backend_info *be);
199237
200238 static inline void blkif_get_x86_32_req(struct blkif_request *dst,
@@ -205,12 +243,25 @@ static inline void blkif_get_x86_32_req(struct blkif_request *dst, · 4 unmodified lines
205243 dst->nr_segments = src->nr_segments;
206244 dst->handle = src->handle;
207245 dst->id = src->id;
208− dst->u.rw.sector_number = src->sector_number;
209− barrier();
210− if (n > dst->nr_segments)
211− n = dst->nr_segments;
212− for (i = 0; i < n; i++)
213− dst->u.rw.seg[i] = src->seg[i];
246+ switch (src->operation) {
247+ case BLKIF_OP_READ:
248+ case BLKIF_OP_WRITE:
249+ case BLKIF_OP_WRITE_BARRIER:
250+ case BLKIF_OP_FLUSH_DISKCACHE:
251+ dst->u.rw.sector_number = src->u.rw.sector_number;
252+ barrier();
253+ if (n > dst->nr_segments)
254+ n = dst->nr_segments;
255+ for (i = 0; i < n; i++)
256+ dst->u.rw.seg[i] = src->u.rw.seg[i];
257+ break;
258+ case BLKIF_OP_DISCARD:
259+ dst->u.discard.sector_number = src->u.discard.sector_number;
260+ dst->u.discard.nr_sectors = src->u.discard.nr_sectors;
261+ break;
262+ default:
263+ break;
264+ }
214265 }
215266
216267 static inline void blkif_get_x86_64_req(struct blkif_request *dst,
@@ -221,12 +272,25 @@ static inline void blkif_get_x86_64_req(struct blkif_request *dst, · 4 unmodified lines
221272 dst->nr_segments = src->nr_segments;
222273 dst->handle = src->handle;
223274 dst->id = src->id;
224− dst->u.rw.sector_number = src->sector_number;
225− barrier();
226− if (n > dst->nr_segments)
227− n = dst->nr_segments;
228− for (i = 0; i < n; i++)
229− dst->u.rw.seg[i] = src->seg[i];
275+ switch (src->operation) {
276+ case BLKIF_OP_READ:
277+ case BLKIF_OP_WRITE:
278+ case BLKIF_OP_WRITE_BARRIER:
279+ case BLKIF_OP_FLUSH_DISKCACHE:
280+ dst->u.rw.sector_number = src->u.rw.sector_number;
281+ barrier();
282+ if (n > dst->nr_segments)
283+ n = dst->nr_segments;
284+ for (i = 0; i < n; i++)
285+ dst->u.rw.seg[i] = src->u.rw.seg[i];
286+ break;
287+ case BLKIF_OP_DISCARD:
288+ dst->u.discard.sector_number = src->u.discard.sector_number;
289+ dst->u.discard.nr_sectors = src->u.discard.nr_sectors;
290+ break;
291+ default:
292+ break;
293+ }
230294 }
231295
232296 #endif /* __XEN_BLKIF__BACKEND__COMMON_H__ */
drivers/block/xen-blkback/xenbus.c+76−0
@@ -114,6 +114,8 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid) · 113 unmodified lines
114114 spin_lock_init(&blkif->blk_ring_lock);
115115 atomic_set(&blkif->refcnt, 1);
116116 init_waitqueue_head(&blkif->wq);
117+ init_completion(&blkif->drain_complete);
118+ atomic_set(&blkif->drain, 0);
117119 blkif->st_print = jiffies;
118120 init_waitqueue_head(&blkif->waiting_to_free);
119121
@@ -272,6 +274,7 @@ VBD_SHOW(oo_req, "%d\n", be->blkif->st_oo_req); · 152 unmodified lines
272274 VBD_SHOW(rd_req, "%d\n", be->blkif->st_rd_req);
273275 VBD_SHOW(wr_req, "%d\n", be->blkif->st_wr_req);
274276 VBD_SHOW(f_req, "%d\n", be->blkif->st_f_req);
277+VBD_SHOW(ds_req, "%d\n", be->blkif->st_ds_req);
275278 VBD_SHOW(rd_sect, "%d\n", be->blkif->st_rd_sect);
276279 VBD_SHOW(wr_sect, "%d\n", be->blkif->st_wr_sect);
277280
@@ -280,6 +283,7 @@ static struct attribute *xen_vbdstat_attrs[] = { · 2 unmodified lines
280283 &dev_attr_rd_req.attr,
281284 &dev_attr_wr_req.attr,
282285 &dev_attr_f_req.attr,
286+ &dev_attr_ds_req.attr,
283287 &dev_attr_rd_sect.attr,
284288 &dev_attr_wr_sect.attr,
285289 NULL
@@ -419,6 +423,73 @@ int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt, · 133 unmodified lines
419423 return err;
420424 }
421425
426+int xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be)
427+{
428+ struct xenbus_device *dev = be->dev;
429+ struct xen_blkif *blkif = be->blkif;
430+ char *type;
431+ int err;
432+ int state = 0;
433+
434+ type = xenbus_read(XBT_NIL, dev->nodename, "type", NULL);
435+ if (!IS_ERR(type)) {
436+ if (strncmp(type, "file", 4) == 0) {
437+ state = 1;
438+ blkif->blk_backend_type = BLKIF_BACKEND_FILE;
439+ }
440+ if (strncmp(type, "phy", 3) == 0) {
441+ struct block_device *bdev = be->blkif->vbd.bdev;
442+ struct request_queue *q = bdev_get_queue(bdev);
443+ if (blk_queue_discard(q)) {
444+ err = xenbus_printf(xbt, dev->nodename,
445+ "discard-granularity", "%u",
446+ q->limits.discard_granularity);
447+ if (err) {
448+ xenbus_dev_fatal(dev, err,
449+ "writing discard-granularity");
450+ goto kfree;
451+ }
452+ err = xenbus_printf(xbt, dev->nodename,
453+ "discard-alignment", "%u",
454+ q->limits.discard_alignment);
455+ if (err) {
456+ xenbus_dev_fatal(dev, err,
457+ "writing discard-alignment");
458+ goto kfree;
459+ }
460+ state = 1;
461+ blkif->blk_backend_type = BLKIF_BACKEND_PHY;
462+ }
463+ }
464+ } else {
465+ err = PTR_ERR(type);
466+ xenbus_dev_fatal(dev, err, "reading type");
467+ goto out;
468+ }
469+
470+ err = xenbus_printf(xbt, dev->nodename, "feature-discard",
471+ "%d", state);
472+ if (err)
473+ xenbus_dev_fatal(dev, err, "writing feature-discard");
474+kfree:
475+ kfree(type);
476+out:
477+ return err;
478+}
479+int xen_blkbk_barrier(struct xenbus_transaction xbt,
480+ struct backend_info *be, int state)
481+{
482+ struct xenbus_device *dev = be->dev;
483+ int err;
484+
485+ err = xenbus_printf(xbt, dev->nodename, "feature-barrier",
486+ "%d", state);
487+ if (err)
488+ xenbus_dev_fatal(dev, err, "writing feature-barrier");
489+
490+ return err;
491+}
492+
422493 /*
423494 * Entry point to this code when a new device is created. Allocate the basic
424495 * structures, and watch the store waiting for the hotplug scripts to tell us
@@ -650,6 +721,11 @@ again: · 225 unmodified lines
650721 if (err)
651722 goto abort;
652723
724+ err = xen_blkbk_discard(xbt, be);
725+
726+ /* If we can't advertise it is OK. */
727+ err = xen_blkbk_barrier(xbt, be, be->blkif->vbd.flush_support);
728+
653729 err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu",
654730 (unsigned long long)vbd_sz(&be->blkif->vbd));
655731 if (err) {
drivers/block/xen-blkfront.c+98−25
@@ -98,6 +98,9 @@ struct blkfront_info · 97 unmodified lines
9898 unsigned long shadow_free;
9999 unsigned int feature_flush;
100100 unsigned int flush_op;
101+ unsigned int feature_discard;
102+ unsigned int discard_granularity;
103+ unsigned int discard_alignment;
101104 int is_ready;
102105 };
103106
@@ -302,29 +305,36 @@ static int blkif_queue_request(struct request *req) · 198 unmodified lines
302305 ring_req->operation = info->flush_op;
303306 }
304307
305− ring_req->nr_segments = blk_rq_map_sg(req->q, req, info->sg);
306− BUG_ON(ring_req->nr_segments > BLKIF_MAX_SEGMENTS_PER_REQUEST);
308+ if (unlikely(req->cmd_flags & REQ_DISCARD)) {
309+ /* id, sector_number and handle are set above. */
310+ ring_req->operation = BLKIF_OP_DISCARD;
311+ ring_req->nr_segments = 0;
312+ ring_req->u.discard.nr_sectors = blk_rq_sectors(req);
313+ } else {
314+ ring_req->nr_segments = blk_rq_map_sg(req->q, req, info->sg);
315+ BUG_ON(ring_req->nr_segments > BLKIF_MAX_SEGMENTS_PER_REQUEST);
307316
308− for_each_sg(info->sg, sg, ring_req->nr_segments, i) {
309− buffer_mfn = pfn_to_mfn(page_to_pfn(sg_page(sg)));
310− fsect = sg->offset >> 9;
311− lsect = fsect + (sg->length >> 9) - 1;
312− /* install a grant reference. */
313− ref = gnttab_claim_grant_reference(&gref_head);
314− BUG_ON(ref == -ENOSPC);
317+ for_each_sg(info->sg, sg, ring_req->nr_segments, i) {
318+ buffer_mfn = pfn_to_mfn(page_to_pfn(sg_page(sg)));
319+ fsect = sg->offset >> 9;
320+ lsect = fsect + (sg->length >> 9) - 1;
321+ /* install a grant reference. */
322+ ref = gnttab_claim_grant_reference(&gref_head);
323+ BUG_ON(ref == -ENOSPC);
315324
316− gnttab_grant_foreign_access_ref(
317− ref,
318− info->xbdev->otherend_id,
319− buffer_mfn,
320− rq_data_dir(req) );
321−
322− info->shadow[id].frame[i] = mfn_to_pfn(buffer_mfn);
323− ring_req->u.rw.seg[i] =
324− (struct blkif_request_segment) {
325− .gref = ref,
326− .first_sect = fsect,
327− .last_sect = lsect };
325+ gnttab_grant_foreign_access_ref(
326+ ref,
327+ info->xbdev->otherend_id,
328+ buffer_mfn,
329+ rq_data_dir(req));
330+
331+ info->shadow[id].frame[i] = mfn_to_pfn(buffer_mfn);
332+ ring_req->u.rw.seg[i] =
333+ (struct blkif_request_segment) {
334+ .gref = ref,
335+ .first_sect = fsect,
336+ .last_sect = lsect };
337+ }
328338 }
329339
330340 info->ring.req_prod_pvt++;
@@ -370,7 +380,9 @@ static void do_blkif_request(struct request_queue *rq) · 39 unmodified lines
370380
371381 blk_start_request(req);
372382
373− if (req->cmd_type != REQ_TYPE_FS) {
383+ if ((req->cmd_type != REQ_TYPE_FS) ||
384+ ((req->cmd_flags & (REQ_FLUSH | REQ_FUA)) &&
385+ !info->flush_op)) {
374386 __blk_end_request_all(req, -EIO);
375387 continue;
376388 }
@@ -399,6 +411,7 @@ wait: · 22 unmodified lines
399411 static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
400412 {
401413 struct request_queue *rq;
414+ struct blkfront_info *info = gd->private_data;
402415
403416 rq = blk_init_queue(do_blkif_request, &blkif_io_lock);
404417 if (rq == NULL)
@@ -406,6 +419,13 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size) · 1 unmodified line
406419
407420 queue_flag_set_unlocked(QUEUE_FLAG_VIRT, rq);
408421
422+ if (info->feature_discard) {
423+ queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, rq);
424+ blk_queue_max_discard_sectors(rq, get_capacity(gd));
425+ rq->limits.discard_granularity = info->discard_granularity;
426+ rq->limits.discard_alignment = info->discard_alignment;
427+ }
428+
409429 /* Hard sector size and max sectors impersonate the equiv. hardware. */
410430 blk_queue_logical_block_size(rq, sector_size);
411431 blk_queue_max_hw_sectors(rq, 512);
@@ -722,6 +742,17 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) · 310 unmodified lines
722742
723743 error = (bret->status == BLKIF_RSP_OKAY) ? 0 : -EIO;
724744 switch (bret->operation) {
745+ case BLKIF_OP_DISCARD:
746+ if (unlikely(bret->status == BLKIF_RSP_EOPNOTSUPP)) {
747+ struct request_queue *rq = info->rq;
748+ printk(KERN_WARNING "blkfront: %s: discard op failed\n",
749+ info->gd->disk_name);
750+ error = -EOPNOTSUPP;
751+ info->feature_discard = 0;
752+ queue_flag_clear(QUEUE_FLAG_DISCARD, rq);
753+ }
754+ __blk_end_request_all(req, error);
755+ break;
725756 case BLKIF_OP_FLUSH_DISKCACHE:
726757 case BLKIF_OP_WRITE_BARRIER:
727758 if (unlikely(bret->status == BLKIF_RSP_EOPNOTSUPP)) {
@@ -1098,6 +1129,33 @@ blkfront_closing(struct blkfront_info *info) · 370 unmodified lines
10981129 bdput(bdev);
10991130 }
11001131
1132+static void blkfront_setup_discard(struct blkfront_info *info)
1133+{
1134+ int err;
1135+ char *type;
1136+ unsigned int discard_granularity;
1137+ unsigned int discard_alignment;
1138+
1139+ type = xenbus_read(XBT_NIL, info->xbdev->otherend, "type", NULL);
1140+ if (IS_ERR(type))
1141+ return;
1142+
1143+ if (strncmp(type, "phy", 3) == 0) {
1144+ err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
1145+ "discard-granularity", "%u", &discard_granularity,
1146+ "discard-alignment", "%u", &discard_alignment,
1147+ NULL);
1148+ if (!err) {
1149+ info->feature_discard = 1;
1150+ info->discard_granularity = discard_granularity;
1151+ info->discard_alignment = discard_alignment;
1152+ }
1153+ } else if (strncmp(type, "file", 4) == 0)
1154+ info->feature_discard = 1;
1155+
1156+ kfree(type);
1157+}
1158+
11011159 /*
11021160 * Invoked when the backend is finally 'ready' (and has told produced
11031161 * the details about the physical device - #sectors, size, etc).
@@ -1108,7 +1166,7 @@ static void blkfront_connect(struct blkfront_info *info) · 4 unmodified lines
11081166 unsigned long sector_size;
11091167 unsigned int binfo;
11101168 int err;
1111− int barrier, flush;
1169+ int barrier, flush, discard;
11121170
11131171 switch (info->connected) {
11141172 case BLKIF_STATE_CONNECTED:
@@ -1178,7 +1236,14 @@ static void blkfront_connect(struct blkfront_info *info) · 63 unmodified lines
11781236 info->feature_flush = REQ_FLUSH;
11791237 info->flush_op = BLKIF_OP_FLUSH_DISKCACHE;
11801238 }
1181−
1239+
1240+ err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
1241+ "feature-discard", "%d", &discard,
1242+ NULL);
1243+
1244+ if (!err && discard)
1245+ blkfront_setup_discard(info);
1246+
11821247 err = xlvbd_alloc_gendisk(sectors, info, binfo, sector_size);
11831248 if (err) {
11841249 xenbus_dev_fatal(info->xbdev, err, "xlvbd_add at %s",
@@ -1385,6 +1450,8 @@ static struct xenbus_driver blkfront = { · 200 unmodified lines
13851450
13861451 static int __init xlblk_init(void)
13871452 {
1453+ int ret;
1454+
13881455 if (!xen_domain())
13891456 return -ENODEV;
13901457
@@ -1394,7 +1461,13 @@ static int __init xlblk_init(void) · 3 unmodified lines
13941461 return -ENODEV;
13951462 }
13961463
1397− return xenbus_register_frontend(&blkfront);
1464+ ret = xenbus_register_frontend(&blkfront);
1465+ if (ret) {
1466+ unregister_blkdev(XENVBD_MAJOR, DEV_NAME);
1467+ return ret;
1468+ }
1469+
1470+ return 0;
13981471 }
13991472 module_init(xlblk_init);
14001473
drivers/scsi/hpsa.c+7−0
@@ -3300,6 +3300,13 @@ static int hpsa_controller_hard_reset(struct pci_dev *pdev, · 3299 unmodified lines
33003300 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
33013301 pmcsr |= PCI_D0;
33023302 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
3303+
3304+ /*
3305+ * The P600 requires a small delay when changing states.
3306+ * Otherwise we may think the board did not reset and we bail.
3307+ * This for kdump only and is particular to the P600.
3308+ */
3309+ msleep(500);
33033310 }
33043311 return 0;
33053312 }
fs/block_dev.c+1−1
@@ -971,7 +971,7 @@ static void flush_disk(struct block_device *bdev, bool kill_dirty) · 970 unmodified lines
971971
972972 if (!bdev->bd_disk)
973973 return;
974− if (disk_partitionable(bdev->bd_disk))
974+ if (disk_part_scan_enabled(bdev->bd_disk))
975975 bdev->bd_invalidated = 1;
976976 }
977977
include/linux/genhd.h+4−2
@@ -131,6 +131,7 @@ struct hd_struct { · 130 unmodified lines
131131 #define GENHD_FL_EXT_DEVT 64 /* allow extended devt */
132132 #define GENHD_FL_NATIVE_CAPACITY 128
133133 #define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE 256
134+#define GENHD_FL_NO_PART_SCAN 512
134135
135136 enum {
136137 DISK_EVENT_MEDIA_CHANGE = 1 << 0, /* media changed */
@@ -238,9 +239,10 @@ static inline int disk_max_parts(struct gendisk *disk) · 101 unmodified lines
238239 return disk->minors;
239240 }
240241
241−static inline bool disk_partitionable(struct gendisk *disk)
242+static inline bool disk_part_scan_enabled(struct gendisk *disk)
242243 {
243− return disk_max_parts(disk) > 1;
244+ return disk_max_parts(disk) > 1 &&
245+ !(disk->flags & GENHD_FL_NO_PART_SCAN);
244246 }
245247
246248 static inline dev_t disk_devt(struct gendisk *disk)
include/linux/loop.h+1−0
@@ -74,6 +74,7 @@ struct loop_device { · 73 unmodified lines
7474 enum {
7575 LO_FLAGS_READ_ONLY = 1,
7676 LO_FLAGS_AUTOCLEAR = 4,
77+ LO_FLAGS_PARTSCAN = 8,
7778 };
7879
7980 #include <asm/posix_types.h> /* for __kernel_old_dev_t */
include/xen/interface/io/blkif.h+36−0
@@ -57,6 +57,36 @@ typedef uint64_t blkif_sector_t; · 56 unmodified lines
5757 * "feature-flush-cache" node!
5858 */
5959 #define BLKIF_OP_FLUSH_DISKCACHE 3
60+
61+/*
62+ * Recognised only if "feature-discard" is present in backend xenbus info.
63+ * The "feature-discard" node contains a boolean indicating whether trim
64+ * (ATA) or unmap (SCSI) - conviently called discard requests are likely
65+ * to succeed or fail. Either way, a discard request
66+ * may fail at any time with BLKIF_RSP_EOPNOTSUPP if it is unsupported by
67+ * the underlying block-device hardware. The boolean simply indicates whether
68+ * or not it is worthwhile for the frontend to attempt discard requests.
69+ * If a backend does not recognise BLKIF_OP_DISCARD, it should *not*
70+ * create the "feature-discard" node!
71+ *
72+ * Discard operation is a request for the underlying block device to mark
73+ * extents to be erased. However, discard does not guarantee that the blocks
74+ * will be erased from the device - it is just a hint to the device
75+ * controller that these blocks are no longer in use. What the device
76+ * controller does with that information is left to the controller.
77+ * Discard operations are passed with sector_number as the
78+ * sector index to begin discard operations at and nr_sectors as the number of
79+ * sectors to be discarded. The specified sectors should be discarded if the
80+ * underlying block device supports trim (ATA) or unmap (SCSI) operations,
81+ * or a BLKIF_RSP_EOPNOTSUPP should be returned.
82+ * More information about trim/unmap operations at:
83+ * http://t13.org/Documents/UploadedDocuments/docs2008/
84+ * e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc
85+ * http://www.seagate.com/staticfiles/support/disc/manuals/
86+ * Interface%20manuals/100293068c.pdf
87+ */
88+#define BLKIF_OP_DISCARD 5
89+
6090 /*
6191 * Maximum scatter/gather segments per request.
6292 * This is carefully chosen so that sizeof(struct blkif_ring) <= PAGE_SIZE.
@@ -74,6 +104,11 @@ struct blkif_request_rw { · 11 unmodified lines
74104 } seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
75105 };
76106
107+struct blkif_request_discard {
108+ blkif_sector_t sector_number;
109+ uint64_t nr_sectors;
110+};
111+
77112 struct blkif_request {
78113 uint8_t operation; /* BLKIF_OP_??? */
79114 uint8_t nr_segments; /* number of segments */
@@ -81,6 +116,7 @@ struct blkif_request { · 1 unmodified line
81116 uint64_t id; /* private guest value, echoed in resp */
82117 union {
83118 struct blkif_request_rw rw;
119+ struct blkif_request_discard discard;
84120 } u;
85121 };
86122