]> Git Repo - qemu.git/commitdiff
raw-posix: Fetch max sectors for host block device
authorFam Zheng <[email protected]>
Fri, 3 Jun 2016 02:07:02 +0000 (10:07 +0800)
committerKevin Wolf <[email protected]>
Wed, 8 Jun 2016 08:21:09 +0000 (10:21 +0200)
This is sometimes a useful value we should count in.

Signed-off-by: Fam Zheng <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
block/raw-posix.c

index ce1cf14f6658800b79b8aa9491c3589e71709e18..ce2e20f2033ff2afb37220fb3c1cbef599f975b2 100644 (file)
@@ -729,9 +729,33 @@ static void raw_reopen_abort(BDRVReopenState *state)
     state->opaque = NULL;
 }
 
+static int hdev_get_max_transfer_length(int fd)
+{
+#ifdef BLKSECTGET
+    int max_sectors = 0;
+    if (ioctl(fd, BLKSECTGET, &max_sectors) == 0) {
+        return max_sectors;
+    } else {
+        return -errno;
+    }
+#else
+    return -ENOSYS;
+#endif
+}
+
 static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
 {
     BDRVRawState *s = bs->opaque;
+    struct stat st;
+
+    if (!fstat(s->fd, &st)) {
+        if (S_ISBLK(st.st_mode)) {
+            int ret = hdev_get_max_transfer_length(s->fd);
+            if (ret >= 0) {
+                bs->bl.max_transfer_length = ret;
+            }
+        }
+    }
 
     raw_probe_alignment(bs, s->fd, errp);
     bs->bl.min_mem_alignment = s->buf_align;
This page took 0.026718 seconds and 4 git commands to generate.