qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
To: Public KVM Mailing List <qemu-devel@nongnu.org>
Cc: kwolf@redhat.com, dahi@linux.vnet.ibm.com,
	Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>,
	armbru@redhat.com, mihajlov@linux.vnet.ibm.com,
	borntraeger@de.ibm.com, stefanha@redhat.com,
	cornelia.huck@de.ibm.com, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH v3 2/5] raw-posix: Factor block size detection out of raw_probe_alignment()
Date: Fri,  5 Dec 2014 18:56:18 +0100	[thread overview]
Message-ID: <1417802181-20834-3-git-send-email-tumanova@linux.vnet.ibm.com> (raw)
In-Reply-To: <1417802181-20834-1-git-send-email-tumanova@linux.vnet.ibm.com>

Put it in new probe_logical_blocksize().

Signed-off-by: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
---
 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.
+ */
+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;
+}
+
 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);
 
-#ifdef BLKSSZGET
-    if (ioctl(fd, BLKSSZGET, &sector_size) >= 0) {
-        bs->request_alignment = sector_size;
-    }
-#endif
-#ifdef DKIOCGETBLOCKSIZE
-    if (ioctl(fd, DKIOCGETBLOCKSIZE, &sector_size) >= 0) {
-        bs->request_alignment = sector_size;
-    }
-#endif
-#ifdef DIOCGSECTORSIZE
-    if (ioctl(fd, DIOCGSECTORSIZE, &sector_size) >= 0) {
-        bs->request_alignment = sector_size;
-    }
-#endif
 #ifdef CONFIG_XFS
     if (s->is_xfs) {
         struct dioattr da;
-- 
1.8.5.5

  parent reply	other threads:[~2014-12-05 17:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-05 17:56 [Qemu-devel] [PATCH v3 0/5] Geometry and blocksize detection for backing devices Ekaterina Tumanova
2014-12-05 17:56 ` [Qemu-devel] [PATCH v3 1/5] block: add bdrv functions for geometry and blocksize Ekaterina Tumanova
2014-12-10 12:38   ` Thomas Huth
2014-12-15 13:00   ` Markus Armbruster
2014-12-05 17:56 ` Ekaterina Tumanova [this message]
2014-12-10 12:48   ` [Qemu-devel] [PATCH v3 2/5] raw-posix: Factor block size detection out of raw_probe_alignment() Thomas Huth
2014-12-15 13:07   ` Markus Armbruster
2014-12-05 17:56 ` [Qemu-devel] [PATCH v3 3/5] block: Add driver methods to probe blocksizes and geometry Ekaterina Tumanova
2014-12-10 13:14   ` Thomas Huth
2014-12-11 11:17     ` Ekaterina Tumanova
2014-12-11 14:22       ` Thomas Huth
2014-12-15 13:29   ` Markus Armbruster
2014-12-15 14:36     ` Ekaterina Tumanova
2014-12-05 17:56 ` [Qemu-devel] [PATCH v3 4/5] block-backend: Add wrappers for blocksizes and geometry probing Ekaterina Tumanova
2014-12-05 17:56 ` [Qemu-devel] [PATCH v3 5/5] BlockConf: Call backend functions to detect geometry and blocksizes Ekaterina Tumanova
2014-12-10 13:29   ` Thomas Huth
2014-12-15 13:50   ` Markus Armbruster
2014-12-15 14:40     ` Ekaterina Tumanova
2014-12-15 15:48       ` Markus Armbruster
2014-12-12 13:10 ` [Qemu-devel] [PATCH v3 0/5] Geometry and blocksize detection for backing devices Ekaterina Tumanova
2014-12-15 13:51 ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1417802181-20834-3-git-send-email-tumanova@linux.vnet.ibm.com \
    --to=tumanova@linux.vnet.ibm.com \
    --cc=armbru@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=dahi@linux.vnet.ibm.com \
    --cc=kwolf@redhat.com \
    --cc=mihajlov@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).