From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DCD59A0613 for ; Fri, 27 Sep 2019 04:15:19 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4EF032BE5; Fri, 27 Sep 2019 04:15:18 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id C36CF1BE0 for ; Fri, 27 Sep 2019 04:15:15 +0200 (CEST) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Sep 2019 19:15:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,553,1559545200"; d="scan'208";a="183827093" Received: from dpdk-virtio-tbie-2.sh.intel.com (HELO ___) ([10.67.104.73]) by orsmga008.jf.intel.com with ESMTP; 26 Sep 2019 19:15:09 -0700 Date: Fri, 27 Sep 2019 10:12:22 +0800 From: Tiwei Bie To: "Yu, Jin" Cc: "dev@dpdk.org" , "Liu, Changpeng" , "maxime.coquelin@redhat.com" , "Wang, Zhihong" , Lin Li , Xun Ni , Yu Zhang Message-ID: <20190927021222.GA22032@___> References: <20190917145234.16951> <20190920120102.29828-1-jin.yu@intel.com> <20190920120102.29828-5-jin.yu@intel.com> <20190926073905.GA12440@___> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Subject: Re: [dpdk-dev] [PATCH v7 04/10] vhost: add two new messages to support a shared buffer X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Thu, Sep 26, 2019 at 11:06:22PM +0800, Yu, Jin wrote: > > > > > > +static int > > > +mem_create(const char *name, unsigned int flags) { #ifdef > > > +MEMFD_SUPPORTED > > > + return memfd_create(name, flags); > > > +#else > > > + RTE_LOG(ERR, VHOST_CONFIG, > > > + "doesn't support memfd--name:%s and flag:%x\n", > > > + name, flags); > > > > You probably don't want to always print an error when memfd isn't available. > I saw below error message from ci/Intel-compilation. > ../lib/librte_vhost/vhost_user.c:1202:24: error: unused parameter ‘name’ [-Werror=unused-parameter] > mem_create(const char *name, unsigned int flags) > ^~~~ > ../lib/librte_vhost/vhost_user.c:1202:43: error: unused parameter ‘flags’ [-Werror=unused-parameter] > mem_create(const char *name, unsigned int flags) > > That's why I add this print.Should I ignore this? Looks better to do it like this (compile test only): static void * inflight_mem_alloc(const char *name, size_t size, int *fd) { char fname[20] = "/tmp/memfd-XXXXXX"; int mfd = -1; void *addr; #ifdef MEMFD_SUPPORTED mfd = memfd_create(name, MFD_CLOEXEC); #else RTE_SET_USED(name); #endif if (mfd == -1) { mfd = mkstemp(fname); if (mfd == -1) { RTE_LOG(ERR, VHOST_CONFIG, "failed to create memory file for inflight buffer\n"); return NULL; } unlink(fname); } if (ftruncate(mfd, size) == -1) { RTE_LOG(ERR, VHOST_CONFIG, "failed to truncate memory file for inflight buffer\n"); close(mfd); return NULL; } addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0); if (addr == MAP_FAILED) { RTE_LOG(ERR, VHOST_CONFIG, "failed to map memory file for inflight buffer\n"); close(mfd); return NULL; } *fd = mfd; return addr; } And you don't need to define CLOEXEC by yourself. > Thanks. > > > > > > + return -1; > > > +#endif > > > +} > > > + > > > +static void * > > > +inflight_mem_alloc(const char *name, size_t size, int *fd) { > > > + void *ptr; > > > + int mfd = -1; > > > + char fname[20] = "/tmp/memfd-XXXXXX"; > > > + > > > + *fd = -1; > > > + mfd = mem_create(name, CLOEXEC); > > > + if (mfd != -1) { > > > + if (ftruncate(mfd, size) == -1) { > > > + RTE_LOG(ERR, VHOST_CONFIG, > > > + "ftruncate fail for alloc inflight buffer\n"); > > > + close(mfd); > > > + return NULL; > > > + } > > > + } else { > > > + mfd = mkstemp(fname); > > > + unlink(fname); > > > + > > > + if (mfd == -1) { > > > + RTE_LOG(ERR, VHOST_CONFIG, > > > + "mkstemp fail for alloc inflight buffer\n"); > > > + return NULL; > > > + } > > > + > > > + if (ftruncate(mfd, size) == -1) { > > > + RTE_LOG(ERR, VHOST_CONFIG, > > > + "ftruncate fail for alloc inflight buffer\n"); > > > + close(mfd); > > > + return NULL; > > > + } > > > + } > > > + > > > + ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0); > > > + if (ptr == MAP_FAILED) { > > > + RTE_LOG(ERR, VHOST_CONFIG, > > > + "mmap fail for alloc inflight buffer\n"); > > > + close(mfd); > > > + return NULL; > > > + } > > > + > > > + *fd = mfd; > > > + return ptr; > > > +}