From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1Z67-0006DU-SG for qemu-devel@nongnu.org; Thu, 18 Dec 2014 06:18:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y1Z5y-0003OP-H8 for qemu-devel@nongnu.org; Thu, 18 Dec 2014 06:18:23 -0500 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:56643) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1Z5y-0003NQ-8P for qemu-devel@nongnu.org; Thu, 18 Dec 2014 06:18:14 -0500 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 18 Dec 2014 11:18:12 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id B6D991B08069 for ; Thu, 18 Dec 2014 11:18:33 +0000 (GMT) Received: from d06av11.portsmouth.uk.ibm.com (d06av11.portsmouth.uk.ibm.com [9.149.37.252]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id sBIBI9M241156788 for ; Thu, 18 Dec 2014 11:18:09 GMT Received: from d06av11.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id sBIBI8uR020399 for ; Thu, 18 Dec 2014 04:18:09 -0700 From: Ekaterina Tumanova Date: Thu, 18 Dec 2014 12:18:01 +0100 Message-Id: <1418901484-12988-3-git-send-email-tumanova@linux.vnet.ibm.com> In-Reply-To: <1418901484-12988-1-git-send-email-tumanova@linux.vnet.ibm.com> References: <1418901484-12988-1-git-send-email-tumanova@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v5 2/5] raw-posix: Refactor logical block size detection. 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, pbonzini@redhat.com 1. Move block size detection into dedicated function. 2. Select exactly one IOCTL that detects blocksize, specific to the host OS. Signed-off-by: Ekaterina Tumanova Reviewed-by: Markus Armbruster --- block/raw-posix.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index e51293a..38172ca 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -217,11 +217,31 @@ static int raw_normalize_devicepath(const char **filename) } #endif +/* + * Get logical block size via ioctl. On success return 0. Otherwise -errno. + */ +static int probe_logical_blocksize(int fd, unsigned int *sector_size) +{ +#if defined(BLKSSZGET) +# define SECTOR_SIZE BLKSSZGET +#elif defined(DKIOCGETBLOCKSIZE) +# define SECTOR_SIZE DKIOCGETBLOCKSIZE +#elif defined(DIOCGSECTORSIZE) +# define SECTOR_SIZE DIOCGSECTORSIZE +#else + return -ENOTSUP +#endif + if (ioctl(fd, SECTOR_SIZE, sector_size) < 0) { + return -errno; + } + return 0; +#undef SECTOR_SIZE +} + static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp) { BDRVRawState *s = bs->opaque; char *buf; - unsigned int sector_size; /* For /dev/sg devices the alignment is not really used. With buffered I/O, we don't have any restrictions. */ @@ -231,25 +251,12 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp) return; } - /* 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; - } -#endif -#ifdef DKIOCGETBLOCKSIZE - if (ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) >= 0) { - bs->request_alignment = sector_size; + /* Let's try to use the logical blocksize for the alignment. */ + if (probe_logical_blocksize(fd, &bs->request_alignment) < 0) { + bs->request_alignment = 0; } -#endif -#ifdef DIOCGSECTORSIZE - if (ioctl(fd, DIOCGSECTORSIZE, §or_size) >= 0) { - bs->request_alignment = sector_size; - } -#endif #ifdef CONFIG_XFS if (s->is_xfs) { struct dioattr da; -- 1.8.5.5