DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tiwei Bie <tiwei.bie@intel.com>
To: "Yu, Jin" <jin.yu@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>,
	"Liu, Changpeng" <changpeng.liu@intel.com>,
	"maxime.coquelin@redhat.com" <maxime.coquelin@redhat.com>,
	"Wang, Zhihong" <zhihong.wang@intel.com>,
	Lin Li <lilin24@baidu.com>, Xun Ni <nixun@baidu.com>,
	Yu Zhang <zhangyu31@baidu.com>
Subject: Re: [dpdk-dev] [PATCH v7 04/10] vhost: add two new messages to support a shared buffer
Date: Fri, 27 Sep 2019 10:12:22 +0800	[thread overview]
Message-ID: <20190927021222.GA22032@___> (raw)
In-Reply-To: <B9FBC361811A3D4DBB02350807E29F7B0B95B6B3@SHSMSX101.ccr.corp.intel.com>

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;
> > > +}

  reply	other threads:[~2019-09-27  2:15 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20190917145234.16951>
2019-09-20 12:00 ` [dpdk-dev] [PATCH v7 00/10] vhost: support inflight share memory protocol feature Jin Yu
2019-09-20 12:00   ` [dpdk-dev] [PATCH v7 01/10] vhost: add the inflight description Jin Yu
2019-09-20 12:00   ` [dpdk-dev] [PATCH v7 02/10] vhost: add packed ring Jin Yu
2019-09-20 12:00   ` [dpdk-dev] [PATCH v7 03/10] vhost: add the inflight structure Jin Yu
2019-09-20 12:00   ` [dpdk-dev] [PATCH v7 04/10] vhost: add two new messages to support a shared buffer Jin Yu
2019-09-26  7:39     ` Tiwei Bie
2019-09-26 15:06       ` Yu, Jin
2019-09-27  2:12         ` Tiwei Bie [this message]
2019-09-20 12:00   ` [dpdk-dev] [PATCH v7 05/10] vhost: checkout the resubmit inflight information Jin Yu
2019-09-26  8:04     ` Tiwei Bie
2019-09-26 15:52       ` Yu, Jin
2019-09-20 12:00   ` [dpdk-dev] [PATCH v7 06/10] vhost: add the APIs to operate inflight ring Jin Yu
2019-09-20 12:00   ` [dpdk-dev] [PATCH v7 07/10] vhost: add APIs for user getting " Jin Yu
2019-09-20 12:01   ` [dpdk-dev] [PATCH v7 08/10] vhost: add vring functions packed ring support Jin Yu
2019-09-20 12:01   ` [dpdk-dev] [PATCH v7 09/10] vhost: add an API for judging vq format Jin Yu
2019-09-20 12:01   ` [dpdk-dev] [PATCH v7 10/10] vhost: add vhost-user-blk example which support inflight Jin Yu
2019-09-25 14:45     ` Tiwei Bie
2019-09-26 14:29       ` Yu, Jin
2019-09-26 14:40         ` Tiwei Bie
2019-09-25 14:25   ` [dpdk-dev] [PATCH v7 00/10] vhost: support inflight share memory protocol feature Tiwei Bie
2019-09-26 14:00     ` Yu, Jin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190927021222.GA22032@___ \
    --to=tiwei.bie@intel.com \
    --cc=changpeng.liu@intel.com \
    --cc=dev@dpdk.org \
    --cc=jin.yu@intel.com \
    --cc=lilin24@baidu.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=nixun@baidu.com \
    --cc=zhangyu31@baidu.com \
    --cc=zhihong.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).