From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54137) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vujbv-00079F-FR for qemu-devel@nongnu.org; Sun, 22 Dec 2013 09:02:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vujbm-0005SN-6g for qemu-devel@nongnu.org; Sun, 22 Dec 2013 09:02:27 -0500 Received: from mail-qc0-x230.google.com ([2607:f8b0:400d:c01::230]:65491) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vujbm-0005Rj-0q for qemu-devel@nongnu.org; Sun, 22 Dec 2013 09:02:18 -0500 Received: by mail-qc0-f176.google.com with SMTP id i8so3927430qcq.21 for ; Sun, 22 Dec 2013 06:02:17 -0800 (PST) Received: from yakj.usersys.redhat.com (net-37-116-200-88.cust.dsl.vodafone.it. [37.116.200.88]) by mx.google.com with ESMTPSA id o5sm27625167qeg.2.2013.12.22.06.02.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Dec 2013 06:02:16 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Sun, 22 Dec 2013 15:02:06 +0100 Message-Id: <1387720926-11421-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1387720926-11421-1-git-send-email-pbonzini@redhat.com> References: <1387720926-11421-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL v2 2/2] scsi-disk: add UNMAP limits to block limits VPD page List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Linux prefers WRITE SAME to UNMAP if the limits are zero, and WRITE SAME does not discard anything unless the device can guarantee that the resulting block is zero. Setting the maximum unmap block and descriptor counts to non-zero makes Linux choose UNMAP and fixes thin provisioning on glusterfs. While the maximum unmap block count can have some effect on performance, the (suggested) maximum number of descriptors is not particularly important so I didn't add a customization option. SCSI drivers are used to online firmware updates so I'm not yet adding versioning support for SCSI, but we're probably getting close to the point when it's worth thinking about it. Reported-by: Bharata B Rao Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-disk.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 7653411..f6ccccc 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -47,6 +47,7 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0) #define SCSI_MAX_MODE_LEN 256 #define DEFAULT_DISCARD_GRANULARITY 4096 +#define DEFAULT_MAX_UNMAP_SIZE (1 << 30) /* 1 GB */ typedef struct SCSIDiskState SCSIDiskState; @@ -74,6 +75,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 +627,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; if (s->qdev.type == TYPE_ROM) { DPRINTF("Inquiry (EVPD[%02X] not supported for CDROM\n", @@ -647,6 +651,18 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) outbuf[14] = (opt_io_size >> 8) & 0xff; outbuf[15] = opt_io_size & 0xff; + /* max unmap LBA count, default is 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; + + /* max unmap descriptors, 255 fit in 4 kb with an 8-byte header. */ + outbuf[24] = 0; + outbuf[25] = 0; + outbuf[26] = 0; + outbuf[27] = 255; + /* optimal unmap granularity */ outbuf[28] = (unmap_sectors >> 24) & 0xff; outbuf[29] = (unmap_sectors >> 16) & 0xff; @@ -2519,6 +2535,8 @@ 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, + DEFAULT_MAX_UNMAP_SIZE), DEFINE_BLOCK_CHS_PROPERTIES(SCSIDiskState, qdev.conf), DEFINE_PROP_END_OF_LIST(), }; @@ -2628,6 +2646,8 @@ 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, + DEFAULT_MAX_UNMAP_SIZE), DEFINE_PROP_END_OF_LIST(), }; -- 1.8.4.2