From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48255) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8MUo-0007CG-OB for qemu-devel@nongnu.org; Thu, 02 Jun 2016 02:52:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8MUn-0006i4-R2 for qemu-devel@nongnu.org; Thu, 02 Jun 2016 02:52:46 -0400 Date: Thu, 2 Jun 2016 14:52:34 +0800 From: Fam Zheng Message-ID: <20160602065234.GC7864@ad.usersys.redhat.com> References: <1464243305-10661-1-git-send-email-famz@redhat.com> <1464243305-10661-2-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1464243305-10661-2-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [PATCH 1/2] raw-posix: Fetch max sectors for host block device from sysfs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com Cc: qemu-block@nongnu.org On Thu, 05/26 14:15, Fam Zheng wrote: > This is sometimes a useful value we should count in. Kevin, Max, could you review this please? Fam > > Signed-off-by: Fam Zheng > --- > block/raw-posix.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 47 insertions(+) > > diff --git a/block/raw-posix.c b/block/raw-posix.c > index a4f5a1b..d3796ad 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -729,9 +729,56 @@ static void raw_reopen_abort(BDRVReopenState *state) > state->opaque = NULL; > } > > +static int hdev_get_max_transfer_length(dev_t dev) > +{ > + int ret; > + int fd; > + char *path; > + const char *end; > + char buf[32]; > + long len; > + > + path = g_strdup_printf("/sys/dev/block/%u:%u/queue/max_sectors_kb", > + major(dev), minor(dev)); > + fd = open(path, O_RDONLY); > + if (fd < 0) { > + ret = -errno; > + goto out; > + } > + ret = read(fd, buf, sizeof(buf)); > + if (ret < 0) { > + ret = -errno; > + goto out; > + } else if (ret == 0) { > + ret = -EIO; > + goto out; > + } > + buf[ret] = 0; > + /* The file is ended with '\n', pass 'end' to accept that. */ > + ret = qemu_strtol(buf, &end, 10, &len); > + if (ret == 0 && end && *end == '\n') { > + ret = len * 1024 / BDRV_SECTOR_SIZE; > + } > + > + close(fd); > +out: > + g_free(path); > + return ret; > +} > + > 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(st.st_rdev); > + if (ret >= 0) { > + bs->bl.max_transfer_length = ret; > + } > + } > + } > > raw_probe_alignment(bs, s->fd, errp); > bs->bl.min_mem_alignment = s->buf_align; > -- > 2.8.2 > >