From patchwork Thu Apr 12 22:22:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Conole X-Patchwork-Id: 37982 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 451841C0E6; Fri, 13 Apr 2018 00:22:15 +0200 (CEST) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by dpdk.org (Postfix) with ESMTP id BF0C71C090 for ; Fri, 13 Apr 2018 00:22:10 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3525D81A88BF; Thu, 12 Apr 2018 22:22:10 +0000 (UTC) Received: from dhcp-25.97.bos.redhat.com (unknown [10.18.25.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B68F215CDC8; Thu, 12 Apr 2018 22:22:10 +0000 (UTC) From: Aaron Conole To: dev@dpdk.org Cc: Alejandro Lucero Date: Thu, 12 Apr 2018 18:22:08 -0400 Message-Id: <20180412222208.11770-3-aconole@redhat.com> In-Reply-To: <20180412222208.11770-1-aconole@redhat.com> References: <20180412222208.11770-1-aconole@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 12 Apr 2018 22:22:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 12 Apr 2018 22:22:10 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'aconole@redhat.com' RCPT:'' Subject: [dpdk-dev] [RFC 2/2] nfp: allow for non-root user 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" 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. Signed-off-by: Aaron Conole Acked-by: Alejandro Lucero Acked-by: Alejandro Lucero --- 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); + nspu_get_lockfile_path(lockname, sizeof(lockname), desc); return 0; }