Skip to contentSkip to conversation

raw-posix: Fetch max sectors for host block device

PATCH Applied Fam Zheng 3 participants 4 messages Jun 3, 2016 Block layer

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH v2 1/1 raw-posix: Fetch max sectors for host block device

This is sometimes a useful value we should count in.

---
 block/raw-posix.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
block/raw-posix.c +24 -0
index a4f5a1b..32f9596 100644
@@ -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;
Signature · 1 line
2.8.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Fam Zheng

This is sometimes a useful value we should count in.

---
 block/raw-posix.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Will conflict with patches I'm about to post to rework BlockLimits to be byte-based, rather than a mix of byte- and sector values. First one in gets to watch the other rebase :)

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#2 lore raw
Quoted 9 lines · Eric Blake
Quoted 7 lines · Fam Zheng

This is sometimes a useful value we should count in.

---
 block/raw-posix.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
Quoted 3 lines

Will conflict with patches I'm about to post to rework BlockLimits to be byte-based, rather than a mix of byte- and sector values. First one in gets to watch the other rebase :)

Thanks! I'm looking forward to a byte based BlockLimits!

Fam