From patchwork Fri Jun 3 17:03:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9153757 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 62CFC60221 for ; Fri, 3 Jun 2016 17:04:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C96226E82 for ; Fri, 3 Jun 2016 17:04:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4100828304; Fri, 3 Jun 2016 17:04:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7123C26E82 for ; Fri, 3 Jun 2016 17:04:00 +0000 (UTC) Received: from localhost ([::1]:56755 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8sVr-0007Gz-J8 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 03 Jun 2016 13:03:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8sVF-0007G8-Jw for qemu-devel@nongnu.org; Fri, 03 Jun 2016 13:03:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8sVD-0003X0-Oh for qemu-devel@nongnu.org; Fri, 03 Jun 2016 13:03:21 -0400 Received: from resqmta-po-11v.sys.comcast.net ([2001:558:fe16:19:96:114:154:170]:38798 helo=resqmta-ch2-11v.sys.comcast.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8sVD-0003Ua-Hl for qemu-devel@nongnu.org; Fri, 03 Jun 2016 13:03:19 -0400 Received: from resomta-po-13v.sys.comcast.net ([96.114.154.237]) by comcast with SMTP id 8sVCbAh4SvJlg8sVDbb20n; Fri, 03 Jun 2016 17:03:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1464973399; bh=ab1+ITQUvWD5d1g0L7n2Qrs9pSFxU6u+Q906OrDr+oY=; h=Received:Received:From:To:Subject:Date:Message-Id; b=eSqw6km+q/5dxgGeLinFYQXTxpUce4rTs+f0dJoGYAol/xl/8EijNm2TYCWz+ijDY EBAw6lwwgOIZgpCRk/WvwviM5yHR9zu32WcNWD+4S6rDK8wJx81FLPhV69LD5F1n0F +j7/EIp90epo4MNUrA+xduZChItffysrYQvAP3dnXWX3ceBToGwBN9+7c9A9xngviN iiESoz+5/xIsk58O7FmswvJ3KI9Si9rz0Rj66+N8d+vy69OWZKUMQCOlIYi8mPfUem 4I1oK2Oube2uut4MDVx1TNGXpcyQlrnjBNh/zSdrktdFdBaBquQUpZW8XrLBvgcfDb 6O8LkEk9qHLPw== Received: from red.redhat.com ([24.10.254.122]) by resomta-po-13v.sys.comcast.net with comcast id 2H381t00U2fD5rL01H3J6i; Fri, 03 Jun 2016 17:03:19 +0000 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 3 Jun 2016 11:03:08 -0600 Message-Id: <1464973388-15821-6-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464973388-15821-1-git-send-email-eblake@redhat.com> References: <1464973388-15821-1-git-send-email-eblake@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:558:fe16:19:96:114:154:170 Subject: [Qemu-devel] [PATCH 5/5] block: Move request_alignment into BlockLimit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Fam Zheng , Stefan Hajnoczi , qemu-block@nongnu.org, Peter Lieven , mreitz@redhat.com, Ronnie Sahlberg , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP It makes more sense to have ALL block size limit constraints in the same struct. Improve the documentation while at it. Note that bdrv_refresh_limits() has to keep things alive across a memset() of BlockLimits. Signed-off-by: Eric Blake --- include/block/block_int.h | 12 ++++++++---- block.c | 4 ++-- block/blkdebug.c | 4 ++-- block/bochs.c | 2 +- block/cloop.c | 2 +- block/dmg.c | 2 +- block/io.c | 12 +++++++----- block/iscsi.c | 2 +- block/raw-posix.c | 16 ++++++++-------- block/raw-win32.c | 6 +++--- block/vvfat.c | 2 +- 11 files changed, 35 insertions(+), 29 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 9dc7af4..0bc7ff4 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -322,6 +322,12 @@ struct BlockDriver { }; typedef struct BlockLimits { + /* Alignment requirement, in bytes, for offset/length of I/O + * requests. Must be a power of 2, and should not exceed + * INT_MAX. For now, a value of 0 defaults to 512, but may change + * to default to 1. */ + uint32_t request_alignment; + /* maximum number of bytes that can be discarded at once (since it * is signed, it must be < 2G, if set), should be multiple of * pdiscard_alignment, but need not be power of 2. May be 0 if no @@ -353,10 +359,10 @@ typedef struct BlockLimits { * should be multiple of opt_transfer), or 0 for no 32-bit limit */ uint32_t max_transfer; - /* memory alignment so that no bounce buffer is needed */ + /* memory alignment, in bytes so that no bounce buffer is needed */ size_t min_mem_alignment; - /* memory alignment for bounce buffer */ + /* memory alignment, in bytes, for bounce buffer */ size_t opt_mem_alignment; /* maximum number of iovec elements */ @@ -463,8 +469,6 @@ struct BlockDriverState { /* Whether produces zeros when read beyond eof */ bool zero_beyond_eof; - /* Alignment requirement for offset/length of I/O requests */ - unsigned int request_alignment; /* Flags honored during pwrite (so far: BDRV_REQ_FUA) */ unsigned int supported_write_flags; /* Flags honored during pwrite_zeroes (so far: BDRV_REQ_FUA, diff --git a/block.c b/block.c index f54bc25..1b56161 100644 --- a/block.c +++ b/block.c @@ -937,7 +937,7 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file, goto fail_opts; } - bs->request_alignment = 512; + bs->bl.request_alignment = 512; bs->zero_beyond_eof = true; bs->read_only = !(bs->open_flags & BDRV_O_RDWR); @@ -1018,7 +1018,7 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file, assert(bdrv_opt_mem_align(bs) != 0); assert(bdrv_min_mem_align(bs) != 0); - assert(is_power_of_2(bs->request_alignment) || bdrv_is_sg(bs)); + assert(is_power_of_2(bs->bl.request_alignment) || bdrv_is_sg(bs)); qemu_opts_del(opts); return 0; diff --git a/block/blkdebug.c b/block/blkdebug.c index 20d25bd..d9bf3ff 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -382,9 +382,9 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags, } /* Set request alignment */ - align = qemu_opt_get_size(opts, "align", bs->request_alignment); + align = qemu_opt_get_size(opts, "align", bs->bl.request_alignment); if (align > 0 && align < INT_MAX && !(align & (align - 1))) { - bs->request_alignment = align; + bs->bl.request_alignment = align; } else { error_setg(errp, "Invalid alignment"); ret = -EINVAL; diff --git a/block/bochs.c b/block/bochs.c index 6c8d0f3..7bf20f5 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -105,7 +105,7 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, int ret; bs->read_only = 1; // no write support yet - bs->request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O supported */ + bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */ ret = bdrv_pread(bs->file->bs, 0, &bochs, sizeof(bochs)); if (ret < 0) { diff --git a/block/cloop.c b/block/cloop.c index ea5a92b..71237f7 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -67,7 +67,7 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, int ret; bs->read_only = 1; - bs->request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O supported */ + bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */ /* read header */ ret = bdrv_pread(bs->file->bs, 128, &s->block_size, 4); diff --git a/block/dmg.c b/block/dmg.c index 1ea5f22..ef2eeb4 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -440,7 +440,7 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, int ret; bs->read_only = 1; - bs->request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O supported */ + bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */ s->n_chunks = 0; s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL; diff --git a/block/io.c b/block/io.c index e845ef9..aaeedaa 100644 --- a/block/io.c +++ b/block/io.c @@ -71,8 +71,10 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp) { BlockDriver *drv = bs->drv; Error *local_err = NULL; + uint32_t request_alignment = bs->bl.request_alignment; memset(&bs->bl, 0, sizeof(bs->bl)); + bs->bl.request_alignment = request_alignment; if (!drv) { return; @@ -429,7 +431,7 @@ static int bdrv_get_cluster_size(BlockDriverState *bs) ret = bdrv_get_info(bs, &bdi); if (ret < 0 || bdi.cluster_size == 0) { - return bs->request_alignment; + return bs->bl.request_alignment; } else { return bdi.cluster_size; } @@ -1036,7 +1038,7 @@ int coroutine_fn bdrv_co_preadv(BlockDriverState *bs, BdrvTrackedRequest req; /* TODO Lift BDRV_SECTOR_SIZE restriction in BlockDriver interface */ - uint64_t align = MAX(BDRV_SECTOR_SIZE, bs->request_alignment); + uint64_t align = MAX(BDRV_SECTOR_SIZE, bs->bl.request_alignment); uint8_t *head_buf = NULL; uint8_t *tail_buf = NULL; QEMUIOVector local_qiov; @@ -1133,7 +1135,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int max_write_zeroes = MIN_NON_ZERO(bs->bl.max_pwrite_zeroes, INT_MAX); int alignment = MAX(bs->bl.pwrite_zeroes_alignment ?: 1, - bs->request_alignment); + bs->bl.request_alignment); assert(is_power_of_2(alignment)); head = offset & (alignment - 1); @@ -1291,7 +1293,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BlockDriverState *bs, uint8_t *buf = NULL; QEMUIOVector local_qiov; struct iovec iov; - uint64_t align = MAX(BDRV_SECTOR_SIZE, bs->request_alignment); + uint64_t align = MAX(BDRV_SECTOR_SIZE, bs->bl.request_alignment); unsigned int head_padding_bytes, tail_padding_bytes; int ret = 0; @@ -1379,7 +1381,7 @@ int coroutine_fn bdrv_co_pwritev(BlockDriverState *bs, { BdrvTrackedRequest req; /* TODO Lift BDRV_SECTOR_SIZE restriction in BlockDriver interface */ - uint64_t align = MAX(BDRV_SECTOR_SIZE, bs->request_alignment); + uint64_t align = MAX(BDRV_SECTOR_SIZE, bs->bl.request_alignment); uint8_t *head_buf = NULL; uint8_t *tail_buf = NULL; QEMUIOVector local_qiov; diff --git a/block/iscsi.c b/block/iscsi.c index 1486443..baa3e15 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -1590,7 +1590,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, goto out; } bs->total_sectors = sector_lun2qemu(iscsilun->num_blocks, iscsilun); - bs->request_alignment = iscsilun->block_size; + bs->bl.request_alignment = iscsilun->block_size; /* We don't have any emulation for devices other than disks and CD-ROMs, so * this must be sg ioctl compatible. We force it to be sg, otherwise qemu diff --git a/block/raw-posix.c b/block/raw-posix.c index f3bd5ef..10a3957 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -302,22 +302,22 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp) /* For SCSI generic devices the alignment is not really used. With buffered I/O, we don't have any restrictions. */ if (bdrv_is_sg(bs) || !s->needs_alignment) { - bs->request_alignment = 1; + bs->bl.request_alignment = 1; s->buf_align = 1; return; } - bs->request_alignment = 0; + bs->bl.request_alignment = 0; s->buf_align = 0; /* Let's try to use the logical blocksize for the alignment. */ - if (probe_logical_blocksize(fd, &bs->request_alignment) < 0) { - bs->request_alignment = 0; + if (probe_logical_blocksize(fd, &bs->bl.request_alignment) < 0) { + bs->bl.request_alignment = 0; } #ifdef CONFIG_XFS if (s->is_xfs) { struct dioattr da; if (xfsctl(NULL, fd, XFS_IOC_DIOINFO, &da) >= 0) { - bs->request_alignment = da.d_miniosz; + bs->bl.request_alignment = da.d_miniosz; /* The kernel returns wrong information for d_mem */ /* s->buf_align = da.d_mem; */ } @@ -337,19 +337,19 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp) qemu_vfree(buf); } - if (!bs->request_alignment) { + if (!bs->bl.request_alignment) { size_t align; buf = qemu_memalign(s->buf_align, max_align); for (align = 512; align <= max_align; align <<= 1) { if (raw_is_io_aligned(fd, buf, align)) { - bs->request_alignment = align; + bs->bl.request_alignment = align; break; } } qemu_vfree(buf); } - if (!s->buf_align || !bs->request_alignment) { + if (!s->buf_align || !bs->bl.request_alignment) { error_setg(errp, "Could not find working O_DIRECT alignment. " "Try cache.direct=off."); } diff --git a/block/raw-win32.c b/block/raw-win32.c index fd23891..7afdb10 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -230,14 +230,14 @@ static void raw_probe_alignment(BlockDriverState *bs) BOOL status; if (s->type == FTYPE_CD) { - bs->request_alignment = 2048; + bs->bl.request_alignment = 2048; return; } if (s->type == FTYPE_HARDDISK) { status = DeviceIoControl(s->hfile, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &dg, sizeof(dg), &count, NULL); if (status != 0) { - bs->request_alignment = dg.Geometry.BytesPerSector; + bs->bl.request_alignment = dg.Geometry.BytesPerSector; return; } /* try GetDiskFreeSpace too */ @@ -247,7 +247,7 @@ static void raw_probe_alignment(BlockDriverState *bs) GetDiskFreeSpace(s->drive_path, §orsPerCluster, &dg.Geometry.BytesPerSector, &freeClusters, &totalClusters); - bs->request_alignment = dg.Geometry.BytesPerSector; + bs->bl.request_alignment = dg.Geometry.BytesPerSector; } } diff --git a/block/vvfat.c b/block/vvfat.c index a39dbe6..aed186d 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1180,7 +1180,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, bs->read_only = 0; } - bs->request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O supported */ + bs->bl.request_alignment = BDRV_SECTOR_SIZE; /* No sub-sector I/O */ bs->total_sectors = cyls * heads * secs; if (init_directories(s, dirname, heads, secs, errp)) {