Commit 6f607174 authored by Fam Zheng's avatar Fam Zheng Committed by Kevin Wolf

raw-posix: Fetch max sectors for host block device

This is sometimes a useful value we should count in.
Signed-off-by: 's avatarFam Zheng <famz@redhat.com>
Reviewed-by: 's avatarEric Blake <eblake@redhat.com>
Signed-off-by: 's avatarKevin Wolf <kwolf@redhat.com>
parent 107d433c
...@@ -729,9 +729,33 @@ static void raw_reopen_abort(BDRVReopenState *state) ...@@ -729,9 +729,33 @@ static void raw_reopen_abort(BDRVReopenState *state)
state->opaque = NULL; 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) static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
{ {
BDRVRawState *s = bs->opaque; 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); raw_probe_alignment(bs, s->fd, errp);
bs->bl.min_mem_alignment = s->buf_align; bs->bl.min_mem_alignment = s->buf_align;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment