From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAZcN-0003od-VN for qemu-devel@nongnu.org; Wed, 08 Jun 2016 05:17:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAZcG-0001Xh-G6 for qemu-devel@nongnu.org; Wed, 08 Jun 2016 05:17:43 -0400 From: Kevin Wolf Date: Wed, 8 Jun 2016 11:16:48 +0200 Message-Id: <1465377417-5012-23-git-send-email-kwolf@redhat.com> In-Reply-To: <1465377417-5012-1-git-send-email-kwolf@redhat.com> References: <1465377417-5012-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 22/31] raw-posix: Fetch max sectors for host block device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Fam Zheng This is sometimes a useful value we should count in. Signed-off-by: Fam Zheng Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/raw-posix.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/block/raw-posix.c b/block/raw-posix.c index ce1cf14..ce2e20f 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -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; -- 1.8.3.1