From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcUXc-0007v6-Vu for qemu-devel@nongnu.org; Thu, 17 Sep 2015 04:27:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZcUXX-0002Z7-WD for qemu-devel@nongnu.org; Thu, 17 Sep 2015 04:27:40 -0400 Received: from mga09.intel.com ([134.134.136.24]:18126) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcUXX-0002Z0-Qo for qemu-devel@nongnu.org; Thu, 17 Sep 2015 04:27:35 -0400 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> <55F841EC.1060809@redhat.com> From: Xiao Guangrong Message-ID: <55FA780E.5020305@linux.intel.com> Date: Thu, 17 Sep 2015 16:21:34 +0800 MIME-Version: 1.0 In-Reply-To: <55F841EC.1060809@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 08/18] nvdimm: init backend memory mapping and config data area List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , Stefan Hajnoczi Cc: ehabkost@redhat.com, kvm@vger.kernel.org, mst@redhat.com, gleb@kernel.org, mtosatti@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, imammedo@redhat.com, rth@twiddle.net On 09/16/2015 12:06 AM, Paolo Bonzini wrote: > > > 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. > The function you pointed out is really complex - it mixed 9 platforms and each platform has its own specific implementation. It is hard for us to verify the change. I'd prefer to make it for Linux specific first then share it to other platforms if it's needed in the future.