From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by dpdk.org (Postfix) with ESMTP id 0B9838DED for ; Tue, 8 May 2018 15:09:54 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5951CF1205; Tue, 8 May 2018 13:09:54 +0000 (UTC) Received: from rhvm.imac (ovpn-117-68.ams2.redhat.com [10.36.117.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03C5B112D17C; Tue, 8 May 2018 13:09:49 +0000 (UTC) To: Aaron Conole , stable@dpdk.org Cc: Alejandro Lucero , Ferruh Yigit , Yuanhan Liu , Pablo Cascon , Kevin Traynor , Adrien Mazarguil References: <20180430172040.13506-1-aconole@redhat.com> <20180430172040.13506-3-aconole@redhat.com> From: Eelco Chaudron Organization: Red Hat Message-ID: <4d888fd4-0712-db8c-2f04-70d21680643c@redhat.com> Date: Tue, 8 May 2018 15:09:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180430172040.13506-3-aconole@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 08 May 2018 13:09:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 08 May 2018 13:09:54 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'echaudro@redhat.com' RCPT:'' Subject: Re: [dpdk-stable] [PATCH 2/2] nfp: allow for non-root user X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: echaudro@redhat.com List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 May 2018 13:09:55 -0000 On 30/04/18 19:20, Aaron Conole wrote: > Currently, the nfp lock files are taken from the global lock file > location, which will work when the user is running as root. However, > some distributions and applications (notably ovs 2.8+ on RHEL/Fedora) > run as a non-root user. > > Acked-by: Alejandro Lucero > Signed-off-by: Aaron Conole > --- > drivers/net/nfp/nfp_nfpu.c | 23 ++++++++++++++++++----- > 1 file changed, 18 insertions(+), 5 deletions(-) > > diff --git a/drivers/net/nfp/nfp_nfpu.c b/drivers/net/nfp/nfp_nfpu.c > index 2ed985ff4..ae2e07220 100644 > --- a/drivers/net/nfp/nfp_nfpu.c > +++ b/drivers/net/nfp/nfp_nfpu.c > @@ -18,6 +18,22 @@ > #define NFP_CFG_EXP_BAR 7 > > #define NFP_CFG_EXP_BAR_CFG_BASE 0x30000 > +#define NFP_LOCKFILE_PATH_FMT "%s/nfp%d" > + > +/* get nfp lock file path (/var/lock if root, $HOME otherwise) */ > +static void > +nspu_get_lockfile_path(char *buffer, int bufsz, nfpu_desc_t *desc) > +{ > + const char *dir = "/var/lock"; > + const char *home_dir = getenv("HOME"); > + > + if (getuid() != 0 && home_dir != NULL) > + dir = home_dir; > + > + /* use current prefix as file path */ > + snprintf(buffer, bufsz, NFP_LOCKFILE_PATH_FMT, dir, > + desc->nfp); > +} > > /* There could be other NFP userspace tools using the NSP interface. > * Make sure there is no other process using it and locking the access for > @@ -30,9 +46,7 @@ nspv_aquire_process_lock(nfpu_desc_t *desc) > struct flock lock; > char lockname[30]; > > - memset(&lock, 0, sizeof(lock)); > - > - snprintf(lockname, sizeof(lockname), "/var/lock/nfp%d", desc->nfp); > + nspu_get_lockfile_path(lockname, sizeof(lockname), desc); > > /* Using S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH */ > desc->lock = open(lockname, O_RDWR | O_CREAT, 0666); > @@ -106,7 +120,6 @@ nfpu_close(nfpu_desc_t *desc) > rte_free(desc->nspu); > close(desc->lock); > > - snprintf(lockname, sizeof(lockname), "/var/lock/nfp%d", desc->nfp); > - unlink(lockname); Sorry for being late, but was this unlink() removed by accident? And should be below nspu_get_lockfile_path() > + nspu_get_lockfile_path(lockname, sizeof(lockname), desc); > return 0; > }