Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp785234ybi; Fri, 31 May 2019 08:52:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxdglOkJxoEE0xG8jX++bvKiG8/vIhzSvSinn+iPdoS1P0C5mbeNCwX5Frqj6Q5Ryrh8K9c X-Received: by 2002:a63:af44:: with SMTP id s4mr10040443pgo.411.1559317961604; Fri, 31 May 2019 08:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559317961; cv=none; d=google.com; s=arc-20160816; b=weNJYVFx2anxTSvZQDLlfFNjXM/0aKTmOwup8+tDEOfd39TIUOcQ1I3csqcs41ng/C rpWQ4s4a/sxU1foftZg1/TxvFh1VfD5pjGj4ECCKE7TAo59ac64vE7W0GU1KtQpSYtzV +zUu8+YTsPTLjla16FeRxIIQ5muau/Smg3X2HIp5ph0gQB09Brjwu2xPX+yzAurE8Ak9 F96FuAlTPjI/bwDWEGetHHqsl47JFEtW6ECRmDDKPFeoILVCOffOJZEPOu1pGvDlOF97 nXwkepU3zSz7OCBVKRU4Z8BRxZyOGwmiiBs0g+TnoCoL6Aao+4IESiTs7tCDoLjUt7dl U0vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:from:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date; bh=Fow8IKr5xpJH36VTAU5Xdr/4Pp8+bbnTbLLJ2XX6gcs=; b=P6gOYwximf/JBFQZ056GfH9yKJgcNuWkyG/MWM5/npnbzPdxLDK5Z5h0Gvu7RrG96M b/6J76KqYB7OFQo7PoS2VtkRrPRxMbli1Gn+LMo7FBfZQb1pJpq3uUFmMlbrxLPFO4y3 MqCpiFyQ1KVc6oLGW0SYWSygJtO1gTRYkvbdsUNOGcxlFXa22m8gEepVDqxscihKRteE vbRb+ixJurPUogGyPFLjXem56kRlWvRXSKmrHrjSgVOfsoYQFaAmnLBSgeX1aOjuA3h0 Ia98ma5OvvgOSVL5Iq65EsHIQwzc2R3umLdE3cv6tK+lgQ6ymjZxWriZ7YWFwFNqN5lp U2Ng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m189si6111395pgm.13.2019.05.31.08.52.20; Fri, 31 May 2019 08:52:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726563AbfEaPwS (ORCPT + 99 others); Fri, 31 May 2019 11:52:18 -0400 Received: from fieldses.org ([173.255.197.46]:42186 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726546AbfEaPwS (ORCPT ); Fri, 31 May 2019 11:52:18 -0400 Received: by fieldses.org (Postfix, from userid 2815) id 85E671CEA; Fri, 31 May 2019 11:52:17 -0400 (EDT) Date: Fri, 31 May 2019 11:52:17 -0400 To: Trond Myklebust Cc: SteveD@redhat.com, linux-nfs@vger.kernel.org Subject: Re: [PATCH v3 04/11] Add utilities for resolving nfsd paths and stat()ing them Message-ID: <20190531155217.GC1251@fieldses.org> References: <20190528203122.11401-1-trond.myklebust@hammerspace.com> <20190528203122.11401-2-trond.myklebust@hammerspace.com> <20190528203122.11401-3-trond.myklebust@hammerspace.com> <20190528203122.11401-4-trond.myklebust@hammerspace.com> <20190528203122.11401-5-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190528203122.11401-5-trond.myklebust@hammerspace.com> User-Agent: Mutt/1.5.21 (2010-09-15) From: bfields@fieldses.org (J. Bruce Fields) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Tue, May 28, 2019 at 04:31:15PM -0400, Trond Myklebust wrote: > +char * > +nfsd_path_strip_root(char *pathname) > +{ > + const char *dir = nfsd_path_nfsd_rootdir(); > + char *ret; > + > + ret = strstr(pathname, dir); > + if (!ret || ret != pathname) > + return pathname; Shouldn't we return NULL or an error or something here? It seems a little strange not to care if the path began with root or not. I guess I need to look at the caller.... --b. > + return pathname + strlen(dir); > +} > + > +char * > +nfsd_path_prepend_dir(const char *dir, const char *pathname) > +{ > + size_t len, dirlen; > + char *ret; > + > + dirlen = strlen(dir); > + while (dirlen > 0 && dir[dirlen - 1] == '/') > + dirlen--; > + if (!dirlen) > + return NULL; > + len = dirlen + strlen(pathname) + 1; > + ret = xmalloc(len + 1); > + snprintf(ret, len, "%.*s/%s", (int)dirlen, dir, pathname); > + return ret; > +} > + > +static void > +nfsd_setup_workqueue(void) > +{ > + const char *rootdir = nfsd_path_nfsd_rootdir(); > + > + if (!rootdir) > + return; > + nfsd_wq = xthread_workqueue_alloc(); > + if (!nfsd_wq) > + return; > + xthread_workqueue_chroot(nfsd_wq, rootdir); > +} > + > +void > +nfsd_path_init(void) > +{ > + nfsd_setup_workqueue(); > +} > + > +struct nfsd_stat_data { > + const char *pathname; > + struct stat *statbuf; > + int ret; > + int err; > +}; > + > +static void > +nfsd_statfunc(void *data) > +{ > + struct nfsd_stat_data *d = data; > + > + d->ret = xstat(d->pathname, d->statbuf); > + if (d->ret < 0) > + d->err = errno; > +} > + > +static void > +nfsd_lstatfunc(void *data) > +{ > + struct nfsd_stat_data *d = data; > + > + d->ret = xlstat(d->pathname, d->statbuf); > + if (d->ret < 0) > + d->err = errno; > +} > + > +static int > +nfsd_run_stat(struct xthread_workqueue *wq, > + void (*func)(void *), > + const char *pathname, > + struct stat *statbuf) > +{ > + struct nfsd_stat_data data = { > + pathname, > + statbuf, > + 0, > + 0 > + }; > + xthread_work_run_sync(wq, func, &data); > + if (data.ret < 0) > + errno = data.err; > + return data.ret; > +} > + > +int > +nfsd_path_stat(const char *pathname, struct stat *statbuf) > +{ > + if (!nfsd_wq) > + return xstat(pathname, statbuf); > + return nfsd_run_stat(nfsd_wq, nfsd_statfunc, pathname, statbuf); > +} > + > +int > +nfsd_path_lstat(const char *pathname, struct stat *statbuf) > +{ > + if (!nfsd_wq) > + return xlstat(pathname, statbuf); > + return nfsd_run_stat(nfsd_wq, nfsd_lstatfunc, pathname, statbuf); > +} > diff --git a/support/misc/xstat.c b/support/misc/xstat.c > new file mode 100644 > index 000000000000..d092f73dfd65 > --- /dev/null > +++ b/support/misc/xstat.c > @@ -0,0 +1,33 @@ > +#include > +#include > +#include > +#include > + > +#include "config.h" > +#include "xstat.h" > + > +#ifdef HAVE_FSTATAT > + > +int xlstat(const char *pathname, struct stat *statbuf) > +{ > + return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT | > + AT_SYMLINK_NOFOLLOW); > +} > + > +int xstat(const char *pathname, struct stat *statbuf) > +{ > + return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT); > +} > + > +#else > + > +int xlstat(const char *pathname, struct stat *statbuf) > +{ > + return lstat(pathname, statbuf); > +} > + > +int xstat(const char *pathname, struct stat *statbuf) > +{ > + return stat(pathname, statbuf); > +} > +#endif > -- > 2.21.0