From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id 158E81B675 for ; Fri, 13 Apr 2018 09:37:05 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id l16so2441637wmh.2 for ; Fri, 13 Apr 2018 00:37:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=7zh60+WSTJrVOkLjSwxNB+FynU3t9UeHEe3ET810Gf8=; b=Ojz7nxaytJY5ZSNWE4Mmd4m0GtTDxfTveXc7OWq5MA1qA6V/ugPL721805jxSMhkwF WYHvRj0AGDR/qcmv4nvNS0WMXRwSPQZteZcFl+1ztZFTKPkoCJLynaarHtuZQkwAdDVq L9eYHdSprf3N/Zi0V8O5m324vQXJnH7Ga0ToSFnuflVH3pXYrvF4aJvcB0s3/mVimDq2 WGEXlkWGZUUCKTpvSJiuA4Ea15ZN/3TVPpZLoNttWdltwf7tWiX6Ln37HSvwfggTCtWH V+9/mnkUZgKoJQe/cy45lkuTR6CO5dvsZ5h0oICBvsFMTNGI/1kAZUbwrt/SvMAgP0Bt M2CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=7zh60+WSTJrVOkLjSwxNB+FynU3t9UeHEe3ET810Gf8=; b=lHisYTwvsy0RZ8bxHdonF8LpNiMJs3CbfqSm3qhMnLxXAAGN0aATyfKx6WCp5XIDSv OmdV86ULEjmYcI9JXZgaZeBy6Hu+jrZS6sTX22naDRYRbYSliQfWPaIM6emHf0pohQjh jesMaLsuleSQM+TmAAO4lMOCoQ1Can22WNK9ZUNFf3oeUwRmMzTbnC2x3wFPQqXVlmik 37uCD9D61fk8qRFK1RYRp07xdeo24hVYX89jx51GxF5cuQC7zV6eBt460V7ZoqnnC+oU WQ7PT6x1OUWOweiUELyLls6YKBFMpDFOyQnIIubRis7FIdcmgKksZf1vHCIMpfkpfcpR /kcw== X-Gm-Message-State: ALQs6tBJod6Xu6BZeUZjlaUO15+xWpk0yjxH1HLsoS48Ve9/PCTHy/nq Sk8EtGFhanewa7IxIo1xaT5N7BnBNvO++p0LPZnoxw== X-Google-Smtp-Source: AIpwx4963JyirG5RMIDkCMQLJX0T6rllaMWy/nV6SBFGj+WgC8Y+RMG3ZEFthtApIqmcSOHuBmRb6UxxLe448Ho7ZGo= X-Received: by 10.80.173.196 with SMTP id b4mr19553393edd.168.1523605024885; Fri, 13 Apr 2018 00:37:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.80.203.69 with HTTP; Fri, 13 Apr 2018 00:37:04 -0700 (PDT) In-Reply-To: <20180412222208.11770-3-aconole@redhat.com> References: <20180412222208.11770-1-aconole@redhat.com> <20180412222208.11770-3-aconole@redhat.com> From: Alejandro Lucero Date: Fri, 13 Apr 2018 09:37:04 +0200 Message-ID: To: Aaron Conole Cc: dev Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [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: , X-List-Received-Date: Fri, 13 Apr 2018 07:37:05 -0000 Again, this patch is correct, but because NFP PMD needs to access /sys/bus/pci/devices/$DEVICE_PCI_STRING/resource$RESOURCE_ID, and these files have just read/write accesses for root, I do not know if this is really necessary. Being honest, I have not used a DPDK app with NFP PMD and not being root. Does it work with non-root users and other PMDs with same requirements regarding sysfs resource files? On Fri, Apr 13, 2018 at 12:22 AM, 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. > > 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); > + nspu_get_lockfile_path(lockname, sizeof(lockname), desc); > return 0; > } > -- > 2.14.3 > >