diff options
author | Fam Zheng <famz@redhat.com> | 2016-06-03 10:07:02 +0800 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2016-06-08 10:21:09 +0200 |
commit | 6f6071745bd0366221f5a0160ed7d18d0e38b9f7 (patch) | |
tree | f104068ecf3c437561bc50b3e37cd7bc1f057cd8 /block | |
parent | 107d433cbbc347cdd140c0f2de4574ff3675bdbe (diff) |
raw-posix: Fetch max sectors for host block device
This is sometimes a useful value we should count in.
Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/raw-posix.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/block/raw-posix.c b/block/raw-posix.c index ce1cf14f66..ce2e20f203 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; |