From: bfields@fieldses.org (J. Bruce Fields)
To: Trond Myklebust <trondmy@gmail.com>
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
Date: Fri, 31 May 2019 11:52:17 -0400 [thread overview]
Message-ID: <20190531155217.GC1251@fieldses.org> (raw)
In-Reply-To: <20190528203122.11401-5-trond.myklebust@hammerspace.com>
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 <sys/types.h>
> +#include <fcntl.h>
> +#include <sys/stat.h>
> +#include <unistd.h>
> +
> +#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
next prev parent reply other threads:[~2019-05-31 15:52 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-28 20:31 [PATCH v3 00/11] Add the "[exports] rootdir" option to nfs.conf Trond Myklebust
2019-05-28 20:31 ` [PATCH v3 01/11] mountd: Ensure we don't share cache file descriptors among processes Trond Myklebust
2019-05-28 20:31 ` [PATCH v3 02/11] Add a simple workqueue mechanism Trond Myklebust
2019-05-28 20:31 ` [PATCH v3 03/11] Allow callers to check mountpoint status using a custom lstat function Trond Myklebust
2019-05-28 20:31 ` [PATCH v3 04/11] Add utilities for resolving nfsd paths and stat()ing them Trond Myklebust
2019-05-28 20:31 ` [PATCH v3 05/11] Use xstat() with no synchronisation if available Trond Myklebust
2019-05-28 20:31 ` [PATCH v3 06/11] Add helpers to read/write to a file through the chrooted thread Trond Myklebust
2019-05-28 20:31 ` [PATCH v3 07/11] Add a helper to return the real path given an export entry Trond Myklebust
2019-05-28 20:31 ` [PATCH v3 08/11] Add support for the "[exports] rootdir" nfs.conf option to rpc.mountd Trond Myklebust
2019-05-28 20:31 ` [PATCH v3 09/11] Add support for the "[exports] rootdir" nfs.conf option to exportfs Trond Myklebust
2019-05-28 20:31 ` [PATCH v3 10/11] Add a helper for resolving symlinked nfsd paths via realpath() Trond Myklebust
2019-05-28 20:31 ` [PATCH v3 11/11] Fix up symlinked mount path resolution when "[exports] rootdir" is set Trond Myklebust
2019-05-31 16:02 ` [PATCH v3 08/11] Add support for the "[exports] rootdir" nfs.conf option to rpc.mountd J. Bruce Fields
2019-06-03 14:18 ` Steve Dickson
2019-06-03 16:30 ` Trond Myklebust
2019-05-29 14:38 ` [PATCH v3 07/11] Add a helper to return the real path given an export entry Steve Dickson
2019-05-29 14:55 ` Trond Myklebust
2019-05-29 16:03 ` Steve Dickson
2019-05-29 16:12 ` Trond Myklebust
2019-05-29 17:17 ` Steve Dickson
2019-05-31 15:52 ` J. Bruce Fields [this message]
2019-06-03 14:21 ` [PATCH v3 04/11] Add utilities for resolving nfsd paths and stat()ing them Steve Dickson
2019-06-03 16:32 ` Trond Myklebust
2019-06-10 13:53 ` [PATCH v3 00/11] Add the "[exports] rootdir" option to nfs.conf Steve Dickson
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=20190531155217.GC1251@fieldses.org \
--to=bfields@fieldses.org \
--cc=SteveD@redhat.com \
--cc=linux-nfs@vger.kernel.org \
--cc=trondmy@gmail.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).