Received: from eggs.gnu.org ([2001:4830:134:3::10]:59023) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XyghT-0005bv-GM for qemu-devel@nongnu.org; Wed, 10 Dec 2014 07:49:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XyghH-0003wK-Ls for qemu-devel@nongnu.org; Wed, 10 Dec 2014 07:49:03 -0500 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:47251) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XyghH-0003w2-E0 for qemu-devel@nongnu.org; Wed, 10 Dec 2014 07:48:51 -0500 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 10 Dec 2014 12:48:49 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id CA6CF17D8043 for ; Wed, 10 Dec 2014 12:49:09 +0000 (GMT) Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id sBACmlHp58720354 for ; Wed, 10 Dec 2014 12:48:47 GMT Received: from d06av08.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id sBACml9r022110 for ; Wed, 10 Dec 2014 05:48:47 -0700 Date: Wed, 10 Dec 2014 13:48:45 +0100 From: Thomas Huth Message-ID: <20141210134845.568bafe3@oc7435384737.ibm.com> In-Reply-To: <1417802181-20834-3-git-send-email-tumanova@linux.vnet.ibm.com> References: <1417802181-20834-1-git-send-email-tumanova@linux.vnet.ibm.com> <1417802181-20834-3-git-send-email-tumanova@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 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: Ekaterina Tumanova Cc: kwolf@redhat.com, borntraeger@de.ibm.com, armbru@redhat.com, Public KVM Mailing List , mihajlov@linux.vnet.ibm.com, dahi@linux.vnet.ibm.com, stefanha@redhat.com, cornelia.huck@de.ibm.com, pbonzini@redhat.com On Fri, 5 Dec 2014 18:56:18 +0100 Ekaterina Tumanova wrote: > Put it in new probe_logical_blocksize(). > > Signed-off-by: Ekaterina Tumanova > --- > block/raw-posix.c | 44 +++++++++++++++++++++++++++----------------- > 1 file changed, 27 insertions(+), 17 deletions(-) > > diff --git a/block/raw-posix.c b/block/raw-posix.c > index b1af77e..633d5bc 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -217,11 +217,35 @@ static int raw_normalize_devicepath(const char **filename) > } > #endif > > +/* > + * Set logical block size via ioctl. On success return 0. Otherwise -errno. s/Set/Get/ > + */ > +static int probe_logical_blocksize(int fd, unsigned int *sector_size) > +{ > + /* Try a few ioctls to get the right size */ > +#ifdef BLKSSZGET > + if (ioctl(fd, BLKSSZGET, sector_size) < 0) { > + return -errno; > + } > +#endif > +#ifdef DKIOCGETBLOCKSIZE > + if (ioctl(fd, DKIOCGETBLOCKSIZE, sector_size) < 0) { > + return -errno; > + } > +#endif > +#ifdef DIOCGSECTORSIZE > + if (ioctl(fd, DIOCGSECTORSIZE, sector_size) < 0) { > + return -errno; > + } > +#endif > + > + return 0; Is "return 0" the right thing here? Or should this function rather return an error code if no ioctl was available? (I know you're not using the return value yet, but it might get important later) > +} > + > 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 +255,11 @@ 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; > + /* Let's try to use the logical blocksize for the alignment. */ > + probe_logical_blocksize(fd, &bs->request_alignment); Can we be sure that the &bs->request_alignment is not changed in case the ioctl failed? If not, it might be necessary to do something like this instead: if (probe_logical_blocksize(fd, &bs->request_alignment) != 0) { bs->request_alignment = 0; } Thomas