All of lore.kernel.org
 help / color / mirror / Atom feed
From: trondmy@kernel.org
To: Steve Dickson <SteveD@redhat.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 2/7] nfsd: Support running nfsd_name_to_handle_at() in the root jail
Date: Thu, 16 Apr 2020 18:12:47 -0400	[thread overview]
Message-ID: <20200416221252.82102-3-trondmy@kernel.org> (raw)
In-Reply-To: <20200416221252.82102-2-trondmy@kernel.org>

From: Trond Myklebust <trond.myklebust@hammerspace.com>

When running nfsd_name_to_handle_at(), we usually want to see the same
namespace as knfsd, so add helpers.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 support/include/nfsd_path.h |  4 +++
 support/misc/nfsd_path.c    | 66 +++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)

diff --git a/support/include/nfsd_path.h b/support/include/nfsd_path.h
index 8331ff96a277..3b73aadd8af7 100644
--- a/support/include/nfsd_path.h
+++ b/support/include/nfsd_path.h
@@ -6,6 +6,7 @@
 
 #include <sys/stat.h>
 
+struct file_handle;
 struct statfs64;
 
 void 		nfsd_path_init(void);
@@ -25,4 +26,7 @@ char *		nfsd_realpath(const char *path, char *resolved_path);
 ssize_t		nfsd_path_read(int fd, char *buf, size_t len);
 ssize_t		nfsd_path_write(int fd, const char *buf, size_t len);
 
+int		nfsd_name_to_handle_at(int fd, const char *path,
+				       struct file_handle *fh,
+				       int *mount_id, int flags);
 #endif
diff --git a/support/misc/nfsd_path.c b/support/misc/nfsd_path.c
index ab6c98dbe395..1f6dfd4b642b 100644
--- a/support/misc/nfsd_path.c
+++ b/support/misc/nfsd_path.c
@@ -6,6 +6,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/vfs.h>
+#include <fcntl.h>
 #include <limits.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -14,6 +15,7 @@
 #include "xmalloc.h"
 #include "xlog.h"
 #include "xstat.h"
+#include "nfslib.h"
 #include "nfsd_path.h"
 #include "workqueue.h"
 
@@ -340,3 +342,67 @@ nfsd_path_write(int fd, const char *buf, size_t len)
 		return write(fd, buf, len);
 	return nfsd_run_write(nfsd_wq, fd, buf, len);
 }
+
+#if defined(HAVE_NAME_TO_HANDLE_AT)
+struct nfsd_handle_data {
+	int fd;
+	const char *path;
+	struct file_handle *fh;
+	int *mount_id;
+	int flags;
+	int ret;
+	int err;
+};
+
+static void
+nfsd_name_to_handle_func(void *data)
+{
+	struct nfsd_handle_data *d = data;
+
+	d->ret = name_to_handle_at(d->fd, d->path,
+			d->fh, d->mount_id, d->flags);
+	if (d->ret < 0)
+		d->err = errno;
+}
+
+static int
+nfsd_run_name_to_handle_at(struct xthread_workqueue *wq,
+		int fd, const char *path, struct file_handle *fh,
+		int *mount_id, int flags)
+{
+	struct nfsd_handle_data data = {
+		fd,
+		path,
+		fh,
+		mount_id,
+		flags,
+		0,
+		0
+	};
+
+	xthread_work_run_sync(wq, nfsd_name_to_handle_func, &data);
+	if (data.ret < 0)
+		errno = data.err;
+	return data.ret;
+}
+
+int
+nfsd_name_to_handle_at(int fd, const char *path, struct file_handle *fh,
+		int *mount_id, int flags)
+{
+	if (!nfsd_wq)
+		return name_to_handle_at(fd, path, fh, mount_id, flags);
+
+	return nfsd_run_name_to_handle_at(nfsd_wq, fd, path, fh,
+			mount_id, flags);
+}
+#else
+int
+nfsd_name_to_handle_at(int UNUSED(fd), const char *UNUSED(path),
+		struct file_handle *UNUSED(fh),
+		int *UNUSED(mount_id), int UNUSED(flags))
+{
+	errno = ENOSYS;
+	return -1;
+}
+#endif
-- 
2.25.2


  reply	other threads:[~2020-04-16 22:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-16 22:12 [PATCH 0/7] nfs-utils fixes trondmy
2020-04-16 22:12 ` [PATCH 1/7] mountd: Add a helper nfsd_path_statfs64() for uuid_by_path() trondmy
2020-04-16 22:12   ` trondmy [this message]
2020-04-16 22:12     ` [PATCH 3/7] mountd: Fix up path checking helper same_path() trondmy
2020-04-16 22:12       ` [PATCH 4/7] Fix autoconf probe for 'struct nfs_filehandle' trondmy
2020-04-16 22:12         ` [PATCH 5/7] mountd: Ensure dump_to_cache() sets errno appropriately trondmy
2020-04-16 22:12           ` [PATCH 6/7] mountd: Ignore transient and non-fatal filesystem errors in nfsd_fh() trondmy
2020-04-16 22:12             ` [PATCH 7/7] mountd: Check the stat() return values in match_fsid() trondmy
2020-04-27 18:38             ` [PATCH 6/7] mountd: Ignore transient and non-fatal filesystem errors in nfsd_fh() J. Bruce Fields
2020-04-27 18:39               ` J. Bruce Fields
2020-05-08 14:13 ` [PATCH 0/7] nfs-utils fixes 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=20200416221252.82102-3-trondmy@kernel.org \
    --to=trondmy@kernel.org \
    --cc=SteveD@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.