From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNK9w-0006HR-IA for qemu-devel@nongnu.org; Mon, 16 Feb 2015 06:48:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNK9o-0000Se-0p for qemu-devel@nongnu.org; Mon, 16 Feb 2015 06:48:16 -0500 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:33616) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNK9n-0000SJ-O0 for qemu-devel@nongnu.org; Mon, 16 Feb 2015 06:48:07 -0500 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 16 Feb 2015 11:48:07 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id D9D8617D805D for ; Mon, 16 Feb 2015 11:48:16 +0000 (GMT) Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t1GBm4918978816 for ; Mon, 16 Feb 2015 11:48:04 GMT Received: from d06av01.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t1GBm3N5013898 for ; Mon, 16 Feb 2015 04:48:03 -0700 From: Ekaterina Tumanova Date: Mon, 16 Feb 2015 12:47:55 +0100 Message-Id: <1424087278-49393-3-git-send-email-tumanova@linux.vnet.ibm.com> In-Reply-To: <1424087278-49393-1-git-send-email-tumanova@linux.vnet.ibm.com> References: <1424087278-49393-1-git-send-email-tumanova@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v7 2/5] raw-posix: Factor block size detection out of raw_probe_alignment() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Public KVM Mailing List Cc: kwolf@redhat.com, thuth@linux.vnet.ibm.com, dahi@linux.vnet.ibm.com, Ekaterina Tumanova , armbru@redhat.com, mihajlov@linux.vnet.ibm.com, borntraeger@de.ibm.com, stefanha@redhat.com, cornelia.huck@de.ibm.com Put it in new probe_logical_blocksize(). Signed-off-by: Ekaterina Tumanova Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi --- block/raw-posix.c | 51 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index e474c17..c306897 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -218,39 +218,58 @@ static int raw_normalize_devicepath(const char **filename) } #endif -static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp) +/* + * Get logical block size via ioctl. On success store it in @sector_size_p. + */ +static int probe_logical_blocksize(int fd, unsigned int *sector_size_p) { - BDRVRawState *s = bs->opaque; - char *buf; unsigned int sector_size; + bool success = false; - /* For /dev/sg devices the alignment is not really used. - With buffered I/O, we don't have any restrictions. */ - if (bs->sg || !s->needs_alignment) { - bs->request_alignment = 1; - s->buf_align = 1; - return; - } + errno = ENOTSUP; /* Try a few ioctls to get the right size */ - bs->request_alignment = 0; - s->buf_align = 0; - #ifdef BLKSSZGET if (ioctl(fd, BLKSSZGET, §or_size) >= 0) { - bs->request_alignment = sector_size; + *sector_size_p = sector_size; + success = true; } #endif #ifdef DKIOCGETBLOCKSIZE if (ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) >= 0) { - bs->request_alignment = sector_size; + *sector_size_p = sector_size; + success = true; } #endif #ifdef DIOCGSECTORSIZE if (ioctl(fd, DIOCGSECTORSIZE, §or_size) >= 0) { - bs->request_alignment = sector_size; + *sector_size_p = sector_size; + success = true; } #endif + + return success ? 0 : -errno; +} + +static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp) +{ + BDRVRawState *s = bs->opaque; + char *buf; + + /* For /dev/sg devices the alignment is not really used. + With buffered I/O, we don't have any restrictions. */ + if (bs->sg || !s->needs_alignment) { + bs->request_alignment = 1; + s->buf_align = 1; + return; + } + + bs->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; + } #ifdef CONFIG_XFS if (s->is_xfs) { struct dioattr da; -- 2.1.4