From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43080) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtHiC-0006UI-56 for qemu-devel@nongnu.org; Mon, 02 Nov 2015 11:12:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZtHi8-0007Yy-Qs for qemu-devel@nongnu.org; Mon, 02 Nov 2015 11:12:00 -0500 Received: from relay.parallels.com ([195.214.232.42]:48087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtHi8-0007Yk-Ji for qemu-devel@nongnu.org; Mon, 02 Nov 2015 11:11:56 -0500 Message-ID: <56378B37.3000202@virtuozzo.com> Date: Mon, 2 Nov 2015 19:11:35 +0300 From: Vladimir Sementsov-Ogievskiy MIME-Version: 1.0 References: <1446455617-129562-1-git-send-email-guangrong.xiao@linux.intel.com> <1446455617-129562-13-git-send-email-guangrong.xiao@linux.intel.com> In-Reply-To: <1446455617-129562-13-git-send-email-guangrong.xiao@linux.intel.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v7 12/35] util: let qemu_fd_getlength support block device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Xiao Guangrong , pbonzini@redhat.com, imammedo@redhat.com Cc: ehabkost@redhat.com, kvm@vger.kernel.org, mst@redhat.com, gleb@kernel.org, mtosatti@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, dan.j.williams@intel.com, rth@twiddle.net On 02.11.2015 12:13, Xiao Guangrong wrote: > lseek can not work for all block devices as the man page says: > | Some devices are incapable of seeking and POSIX does not specify > | which devices must support lseek(). > > This patch tries to add the support on Linux by using BLKGETSIZE64 > ioctl > > Signed-off-by: Xiao Guangrong > --- > util/osdep.c | 20 ++++++++++++++++++++ > 1 file changed, 20 insertions(+) > > diff --git a/util/osdep.c b/util/osdep.c > index 5a61e19..b20c793 100644 > --- a/util/osdep.c > +++ b/util/osdep.c > @@ -45,6 +45,11 @@ > extern int madvise(caddr_t, size_t, int); > #endif > > +#ifdef CONFIG_LINUX > +#include > +#include > +#endif > + > #include "qemu-common.h" > #include "qemu/sockets.h" > #include "qemu/error-report.h" > @@ -433,6 +438,21 @@ int64_t qemu_fd_getlength(int fd) > { > int64_t size; > > +#ifdef CONFIG_LINUX > + struct stat stat_buf; > + if (fstat(fd, &stat_buf) < 0) { > + return -errno; > + } > + > + if ((S_ISBLK(stat_buf.st_mode)) && !ioctl(fd, BLKGETSIZE64, &size)) { > + /* The size of block device is larger than max int64_t? */ > + if (size < 0) { > + return -EOVERFLOW; > + } > + return size; > + } > +#endif > + > size = lseek(fd, 0, SEEK_END); > if (size < 0) { > return -errno; Reviewed-by: Vladimir Sementsov-Ogievskiy just a question: is there any use for stat.st_size ? Is it always worse then lseek? Does it work for blk? also, "This patch tries to add..". Hmm. It looks like this patch is not sure about will it success. I'd prefer "This patch adds", but this is not important -- Best regards, Vladimir * now, @virtuozzo.com instead of @parallels.com. Sorry for this inconvenience.