aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrond Myklebust <trond.myklebust@hammerspace.com>2020-05-08 09:49:07 -0400
committerSteve Dickson <steved@redhat.com>2020-05-08 10:07:19 -0400
commita536436d238814b4ec80f444fc9b234e264188e6 (patch)
tree4c4ca9463be11a0948b2157a1239cb677589d5bb
parent1b50e24c9db3c718395b03b8d069814c5d5ecbe9 (diff)
downloadnfs-utils-a536436d238814b4ec80f444fc9b234e264188e6.tar.gz
nfsd: Support running nfsd_name_to_handle_at() in the root jail
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> Signed-off-by: Steve Dickson <steved@redhat.com>
-rw-r--r--support/include/nfsd_path.h4
-rw-r--r--support/misc/nfsd_path.c66
2 files changed, 70 insertions, 0 deletions
diff --git a/support/include/nfsd_path.h b/support/include/nfsd_path.h
index 8331ff96..3b73aadd 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 ab6c98db..1f6dfd4b 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