From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH v2 08/18] nvdimm: init backend memory mapping and config data area Date: Tue, 15 Sep 2015 18:06:04 +0200 Message-ID: <55F841EC.1060809@redhat.com> References: <1439563931-12352-1-git-send-email-guangrong.xiao@linux.intel.com> <1439563931-12352-9-git-send-email-guangrong.xiao@linux.intel.com> <20150825160353.GD8344@stefanha-thinkpad.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Cc: imammedo@redhat.com, gleb@kernel.org, mtosatti@redhat.com, stefanha@redhat.com, mst@redhat.com, rth@twiddle.net, ehabkost@redhat.com, kvm@vger.kernel.org, qemu-devel@nongnu.org To: Stefan Hajnoczi , Xiao Guangrong Return-path: Received: from mx1.redhat.com ([209.132.183.28]:40770 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753218AbbIOQGK (ORCPT ); Tue, 15 Sep 2015 12:06:10 -0400 In-Reply-To: <20150825160353.GD8344@stefanha-thinkpad.redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 25/08/2015 18:03, Stefan Hajnoczi wrote: >> > >> > +static uint64_t get_file_size(int fd) >> > +{ >> > + struct stat stat_buf; >> > + uint64_t size; >> > + >> > + if (fstat(fd, &stat_buf) < 0) { >> > + return 0; >> > + } >> > + >> > + if (S_ISREG(stat_buf.st_mode)) { >> > + return stat_buf.st_size; >> > + } >> > + >> > + if (S_ISBLK(stat_buf.st_mode) && !ioctl(fd, BLKGETSIZE64, &size)) { >> > + return size; >> > + } > #ifdef __linux__ for ioctl(fd, BLKGETSIZE64, &size)? > > There is nothing Linux-specific about emulating NVDIMMs so this code > should compile on all platforms. The code from block/raw-posix.c and block/raw-win32.c's raw_getlength should probably be extracted to a new function in utils/, and reused here. Paolo