From 3c645dc6c54fffa45acb6e4ab366aa0d8a2fca91 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Fri, 8 Jul 2016 05:20:18 +0200 Subject: [PATCH 07/11] raw-posix: Fetch max sectors for host block device RH-Author: Fam Zheng Message-id: <1467955219-6507-3-git-send-email-famz@redhat.com> Patchwork-id: 71069 O-Subject: [RHEV-7.3 qemu-kvm-rhev PATCH v2 2/3] raw-posix: Fetch max sectors for host block device Bugzilla: 1353816 RH-Acked-by: John Snow RH-Acked-by: Paolo Bonzini RH-Acked-by: Stefan Hajnoczi This is sometimes a useful value we should count in. Signed-off-by: Fam Zheng Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf (cherry picked from commit 6f6071745bd0366221f5a0160ed7d18d0e38b9f7) Signed-off-by: Fam Zheng Signed-off-by: Miroslav Rezanina --- block/raw-posix.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/block/raw-posix.c b/block/raw-posix.c index 906d5c9..3f55c7d 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -728,9 +728,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; -- 1.8.3.1