qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] scsi-disk: add non-zero MAX UNMAP LBA COUNT to block limits VPD page
@ 2013-12-20 14:58 Paolo Bonzini
  2013-12-21  4:10 ` Bharata B Rao
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Bonzini @ 2013-12-20 14:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bharata B Rao

Linux prefers WRITE SAME to UNMAP if the count is zero, and WRITE
SAME does not discard anything unless the device can guarantee that
the resulting block is zero.

This fixes thin provisioning on glusterfs.

Reported-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/scsi/scsi-disk.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 7653411..156c965 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -74,6 +74,7 @@ struct SCSIDiskState
     bool media_event;
     bool eject_request;
     uint64_t wwn;
+    uint64_t max_unmap_size;
     QEMUBH *bh;
     char *version;
     char *serial;
@@ -625,6 +626,8 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
                     s->qdev.conf.min_io_size / s->qdev.blocksize;
             unsigned int opt_io_size =
                     s->qdev.conf.opt_io_size / s->qdev.blocksize;
+	    unsigned int max_unmap_sectors =
+		    s->max_unmap_size / s->qdev.blocksize; /* 1 GB */
 
             if (s->qdev.type == TYPE_ROM) {
                 DPRINTF("Inquiry (EVPD[%02X] not supported for CDROM\n",
@@ -647,6 +650,12 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
             outbuf[14] = (opt_io_size >> 8) & 0xff;
             outbuf[15] = opt_io_size & 0xff;
 
+            /* maximum unmap LBA count, hardcoded to 1GB */
+            outbuf[20] = (max_unmap_sectors >> 24) & 0xff;
+            outbuf[21] = (max_unmap_sectors >> 16) & 0xff;
+            outbuf[22] = (max_unmap_sectors >> 8) & 0xff;
+            outbuf[23] = max_unmap_sectors & 0xff;
+
             /* optimal unmap granularity */
             outbuf[28] = (unmap_sectors >> 24) & 0xff;
             outbuf[29] = (unmap_sectors >> 16) & 0xff;
@@ -2519,6 +2528,7 @@ static Property scsi_hd_properties[] = {
     DEFINE_PROP_BIT("dpofua", SCSIDiskState, features,
                     SCSI_DISK_F_DPOFUA, false),
     DEFINE_PROP_HEX64("wwn", SCSIDiskState, wwn, 0),
+    DEFINE_PROP_UINT64("max_unmap_size", SCSIDiskState, max_unmap_size, 1 << 30),
     DEFINE_BLOCK_CHS_PROPERTIES(SCSIDiskState, qdev.conf),
     DEFINE_PROP_END_OF_LIST(),
 };
@@ -2628,6 +2638,7 @@ static Property scsi_disk_properties[] = {
     DEFINE_PROP_BIT("dpofua", SCSIDiskState, features,
                     SCSI_DISK_F_DPOFUA, false),
     DEFINE_PROP_HEX64("wwn", SCSIDiskState, wwn, 0),
+    DEFINE_PROP_UINT64("max_unmap_size", SCSIDiskState, max_unmap_size, 1 << 30),
     DEFINE_PROP_END_OF_LIST(),
 };
 
-- 
1.8.4.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] scsi-disk: add non-zero MAX UNMAP LBA COUNT to block limits VPD page
  2013-12-20 14:58 [Qemu-devel] [PATCH] scsi-disk: add non-zero MAX UNMAP LBA COUNT to block limits VPD page Paolo Bonzini
@ 2013-12-21  4:10 ` Bharata B Rao
  0 siblings, 0 replies; 2+ messages in thread
From: Bharata B Rao @ 2013-12-21  4:10 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Fri, Dec 20, 2013 at 03:58:08PM +0100, Paolo Bonzini wrote:
> Linux prefers WRITE SAME to UNMAP if the count is zero, and WRITE
> SAME does not discard anything unless the device can guarantee that
> the resulting block is zero.
> 
> This fixes thin provisioning on glusterfs.

I don't see discard requests reaching GlusterFS even after this patch.
bdrv_co_discard or bdrv_aio_discard isn't getting called for the gluster
drive.

Regards,
Bharata.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-12-21  4:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-20 14:58 [Qemu-devel] [PATCH] scsi-disk: add non-zero MAX UNMAP LBA COUNT to block limits VPD page Paolo Bonzini
2013-12-21  4:10 ` Bharata B Rao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).