From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eduardo Habkost Subject: Re: [PATCH v7 11/35] util: introduce qemu_file_getlength() Date: Wed, 4 Nov 2015 12:44:10 -0200 Message-ID: <20151104144410.GJ4180@thinpad.lan.raisama.net> References: <1446455617-129562-1-git-send-email-guangrong.xiao@linux.intel.com> <1446455617-129562-12-git-send-email-guangrong.xiao@linux.intel.com> <20151103232151.GH4180@thinpad.lan.raisama.net> <563978B5.5070803@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: pbonzini@redhat.com, imammedo@redhat.com, gleb@kernel.org, mtosatti@redhat.com, stefanha@redhat.com, mst@redhat.com, rth@twiddle.net, dan.j.williams@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, vsementsov@virtuozzo.com, eblake@redhat.com To: Xiao Guangrong Return-path: Received: from mx1.redhat.com ([209.132.183.28]:46964 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932631AbbKDOoN (ORCPT ); Wed, 4 Nov 2015 09:44:13 -0500 Content-Disposition: inline In-Reply-To: <563978B5.5070803@linux.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Nov 04, 2015 at 11:17:09AM +0800, Xiao Guangrong wrote: > > > On 11/04/2015 07:21 AM, Eduardo Habkost wrote: > >On Mon, Nov 02, 2015 at 05:13:13PM +0800, Xiao Guangrong wrote: > >[...] > >>+size_t qemu_file_getlength(const char *file, Error **errp) > >>+{ > >>+ int64_t size; > >[...] > >>+ return size; > > > >Can you guarantee that SIZE_MAX >= INT64_MAX on all platforms supported > >by QEMU? > > > > Actually, this function is abstracted from the common function, raw_getlength(), > in raw-posix.c whose return value is int64_t. > > And i think int64_t is large enough for block devices. int64_t should be enough, but I don't know if size_t is large enough on all platforms. I believe it's going to be either one of those cases: * If you are absolutely sure SIZE_MAX >= INT64_MAX on all platforms, please explain why (and maybe add a QEMU_BUILD_BUG_ON?). (I don't think this will be the case) * If SIZE_MAX < INT64_MAX is possible but you believe size <= SIZE_MAX is always true here, please explain why (and maybe add an assert()). * Otherwise, we need to set an appropriate error if size > SIZE_MAX or change the type of qemu_file_getlength(). What about making it uint64_t? -- Eduardo From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtzIO-0005MG-So for qemu-devel@nongnu.org; Wed, 04 Nov 2015 09:44:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZtzIL-0001Xx-Oj for qemu-devel@nongnu.org; Wed, 04 Nov 2015 09:44:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44326) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtzIL-0001Xs-J5 for qemu-devel@nongnu.org; Wed, 04 Nov 2015 09:44:13 -0500 Date: Wed, 4 Nov 2015 12:44:10 -0200 From: Eduardo Habkost Message-ID: <20151104144410.GJ4180@thinpad.lan.raisama.net> References: <1446455617-129562-1-git-send-email-guangrong.xiao@linux.intel.com> <1446455617-129562-12-git-send-email-guangrong.xiao@linux.intel.com> <20151103232151.GH4180@thinpad.lan.raisama.net> <563978B5.5070803@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <563978B5.5070803@linux.intel.com> 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 Cc: vsementsov@virtuozzo.com, kvm@vger.kernel.org, mst@redhat.com, gleb@kernel.org, mtosatti@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, imammedo@redhat.com, pbonzini@redhat.com, dan.j.williams@intel.com, rth@twiddle.net On Wed, Nov 04, 2015 at 11:17:09AM +0800, Xiao Guangrong wrote: > > > On 11/04/2015 07:21 AM, Eduardo Habkost wrote: > >On Mon, Nov 02, 2015 at 05:13:13PM +0800, Xiao Guangrong wrote: > >[...] > >>+size_t qemu_file_getlength(const char *file, Error **errp) > >>+{ > >>+ int64_t size; > >[...] > >>+ return size; > > > >Can you guarantee that SIZE_MAX >= INT64_MAX on all platforms supported > >by QEMU? > > > > Actually, this function is abstracted from the common function, raw_getlength(), > in raw-posix.c whose return value is int64_t. > > And i think int64_t is large enough for block devices. int64_t should be enough, but I don't know if size_t is large enough on all platforms. I believe it's going to be either one of those cases: * If you are absolutely sure SIZE_MAX >= INT64_MAX on all platforms, please explain why (and maybe add a QEMU_BUILD_BUG_ON?). (I don't think this will be the case) * If SIZE_MAX < INT64_MAX is possible but you believe size <= SIZE_MAX is always true here, please explain why (and maybe add an assert()). * Otherwise, we need to set an appropriate error if size > SIZE_MAX or change the type of qemu_file_getlength(). What about making it uint64_t? -- Eduardo