yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
34b321
From 52288902dd647cbcfa470a11867163a6e5983297 Mon Sep 17 00:00:00 2001
34b321
From: Fam Zheng <famz@redhat.com>
34b321
Date: Mon, 11 Jul 2016 05:33:38 +0200
34b321
Subject: [PATCH 5/7] raw-posix: Fetch max sectors for host block device
34b321
34b321
RH-Author: Fam Zheng <famz@redhat.com>
34b321
Message-id: <1468215219-30793-6-git-send-email-famz@redhat.com>
34b321
Patchwork-id: 71109
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH 5/6] raw-posix: Fetch max sectors for host block device
34b321
Bugzilla: 1318199
34b321
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
34b321
RH-Acked-by: John Snow <jsnow@redhat.com>
34b321
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
34b321
34b321
This is sometimes a useful value we should count in.
34b321
34b321
Signed-off-by: Fam Zheng <famz@redhat.com>
34b321
Reviewed-by: Eric Blake <eblake@redhat.com>
34b321
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
34b321
(cherry picked from commit 6f6071745bd0366221f5a0160ed7d18d0e38b9f7)
34b321
Signed-off-by: Fam Zheng <famz@redhat.com>
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
---
34b321
 block/raw-posix.c | 24 ++++++++++++++++++++++++
34b321
 1 file changed, 24 insertions(+)
34b321
34b321
diff --git a/block/raw-posix.c b/block/raw-posix.c
34b321
index 92fcb6c..ed97bd4 100644
34b321
--- a/block/raw-posix.c
34b321
+++ b/block/raw-posix.c
34b321
@@ -587,9 +587,33 @@ static void raw_reopen_abort(BDRVReopenState *state)
34b321
     state->opaque = NULL;
34b321
 }
34b321
 
34b321
+static int hdev_get_max_transfer_length(int fd)
34b321
+{
34b321
+#ifdef BLKSECTGET
34b321
+    int max_sectors = 0;
34b321
+    if (ioctl(fd, BLKSECTGET, &max_sectors) == 0) {
34b321
+        return max_sectors;
34b321
+    } else {
34b321
+        return -errno;
34b321
+    }
34b321
+#else
34b321
+    return -ENOSYS;
34b321
+#endif
34b321
+}
34b321
+
34b321
 static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
34b321
 {
34b321
     BDRVRawState *s = bs->opaque;
34b321
+    struct stat st;
34b321
+
34b321
+    if (!fstat(s->fd, &st)) {
34b321
+        if (S_ISBLK(st.st_mode)) {
34b321
+            int ret = hdev_get_max_transfer_length(s->fd);
34b321
+            if (ret >= 0) {
34b321
+                bs->bl.max_transfer_length = ret;
34b321
+            }
34b321
+        }
34b321
+    }
34b321
 
34b321
     raw_probe_alignment(bs, s->fd, errp);
34b321
     bs->bl.opt_mem_alignment = s->buf_align;
34b321
-- 
34b321
1.8.3.1
34b321