From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtH05-0001Td-QN for qemu-devel@nongnu.org; Mon, 02 Nov 2015 10:26:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZtH02-000501-In for qemu-devel@nongnu.org; Mon, 02 Nov 2015 10:26:25 -0500 Received: from relay.parallels.com ([195.214.232.42]:43091) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtH02-0004zk-Ae for qemu-devel@nongnu.org; Mon, 02 Nov 2015 10:26:22 -0500 Message-ID: <5637808A.8010804@virtuozzo.com> Date: Mon, 2 Nov 2015 18:26:02 +0300 From: Vladimir Sementsov-Ogievskiy MIME-Version: 1.0 References: <1446455617-129562-1-git-send-email-guangrong.xiao@linux.intel.com> <1446455617-129562-12-git-send-email-guangrong.xiao@linux.intel.com> In-Reply-To: <1446455617-129562-12-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 11/35] util: introduce qemu_file_getlength() 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: > It is used to get the size of the specified file, also qemu_fd_getlength() > is introduced to unify the code with raw_getlength() in block/raw-posix.c > > Signed-off-by: Xiao Guangrong > --- > block/raw-posix.c | 7 +------ > include/qemu/osdep.h | 2 ++ > util/osdep.c | 31 +++++++++++++++++++++++++++++++ > 3 files changed, 34 insertions(+), 6 deletions(-) > > diff --git a/block/raw-posix.c b/block/raw-posix.c > index 918c756..734e6dd 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -1592,18 +1592,13 @@ static int64_t raw_getlength(BlockDriverState *bs) > { > BDRVRawState *s = bs->opaque; > int ret; > - int64_t size; > > ret = fd_open(bs); > if (ret < 0) { > return ret; > } > > - size = lseek(s->fd, 0, SEEK_END); > - if (size < 0) { > - return -errno; > - } > - return size; > + return qemu_fd_getlength(s->fd); > } > #endif > > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h > index dbc17dc..ca4c3fa 100644 > --- a/include/qemu/osdep.h > +++ b/include/qemu/osdep.h > @@ -303,4 +303,6 @@ int qemu_read_password(char *buf, int buf_size); > pid_t qemu_fork(Error **errp); > > size_t qemu_file_get_page_size(const char *mem_path, Error **errp); > +int64_t qemu_fd_getlength(int fd); > +size_t qemu_file_getlength(const char *file, Error **errp); > #endif > diff --git a/util/osdep.c b/util/osdep.c > index 0092bb6..5a61e19 100644 > --- a/util/osdep.c > +++ b/util/osdep.c > @@ -428,3 +428,34 @@ writev(int fd, const struct iovec *iov, int iov_cnt) > return readv_writev(fd, iov, iov_cnt, true); > } > #endif > + > +int64_t qemu_fd_getlength(int fd) > +{ > + int64_t size; > + > + size = lseek(fd, 0, SEEK_END); > + if (size < 0) { > + return -errno; > + } > + return size; > +} > + > +size_t qemu_file_getlength(const char *file, Error **errp) > +{ > + int64_t size; > + int fd = qemu_open(file, O_RDONLY); > + > + if (fd < 0) { > + error_setg_file_open(errp, errno, file); > + return 0; > + } > + > + size = qemu_fd_getlength(fd); > + if (size < 0) { > + error_setg_errno(errp, -size, "can't get size of file %s", file); > + size = 0; > + } > + > + qemu_close(fd); > + return size; > +} Reviewed-by: Vladimir Sementsov-Ogievskiy -- Best regards, Vladimir * now, @virtuozzo.com instead of @parallels.com. Sorry for this inconvenience.