All of lore.kernel.org
 help / color / mirror / Atom feed
From: Trond Myklebust <trondmy@gmail.com>
To: SteveD@redhat.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH v3 06/11] Add helpers to read/write to a file through the chrooted thread
Date: Tue, 28 May 2019 16:31:17 -0400	[thread overview]
Message-ID: <20190528203122.11401-7-trond.myklebust@hammerspace.com> (raw)
In-Reply-To: <20190528203122.11401-6-trond.myklebust@hammerspace.com>

Add helper functions to do synchronous I/O to a nfsd filesystem pseudofile
from inside the chrooted environment. This ensures that calls to kern_path()
in knfsd resolves to paths that are relative to the nfsd root directory.

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

diff --git a/support/include/nfsd_path.h b/support/include/nfsd_path.h
index db9b41a179ad..f4a7f0a4337f 100644
--- a/support/include/nfsd_path.h
+++ b/support/include/nfsd_path.h
@@ -13,4 +13,7 @@ char *		nfsd_path_prepend_dir(const char *dir, const char *pathname);
 int 		nfsd_path_stat(const char *pathname, struct stat *statbuf);
 int 		nfsd_path_lstat(const char *pathname, struct stat *statbuf);
 
+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);
+
 #endif
diff --git a/support/misc/nfsd_path.c b/support/misc/nfsd_path.c
index fe2c011b1521..55bca9bdf4bd 100644
--- a/support/misc/nfsd_path.c
+++ b/support/misc/nfsd_path.c
@@ -166,3 +166,87 @@ nfsd_path_lstat(const char *pathname, struct stat *statbuf)
 		return xlstat(pathname, statbuf);
 	return nfsd_run_stat(nfsd_wq, nfsd_lstatfunc, pathname, statbuf);
 }
+
+struct nfsd_read_data {
+	int fd;
+	char *buf;
+	size_t len;
+	ssize_t ret;
+	int err;
+};
+
+static void
+nfsd_readfunc(void *data)
+{
+	struct nfsd_read_data *d = data;
+
+	d->ret = read(d->fd, d->buf, d->len);
+	if (d->ret < 0)
+		d->err = errno;
+}
+
+static ssize_t
+nfsd_run_read(struct xthread_workqueue *wq, int fd, char *buf, size_t len)
+{
+	struct nfsd_read_data data = {
+		fd,
+		buf,
+		len,
+		0,
+		0
+	};
+	xthread_work_run_sync(wq, nfsd_readfunc, &data);
+	if (data.ret < 0)
+		errno = data.err;
+	return data.ret;
+}
+
+ssize_t
+nfsd_path_read(int fd, char *buf, size_t len)
+{
+	if (!nfsd_wq)
+		return read(fd, buf, len);
+	return nfsd_run_read(nfsd_wq, fd, buf, len);
+}
+
+struct nfsd_write_data {
+	int fd;
+	const char *buf;
+	size_t len;
+	ssize_t ret;
+	int err;
+};
+
+static void
+nfsd_writefunc(void *data)
+{
+	struct nfsd_write_data *d = data;
+
+	d->ret = write(d->fd, d->buf, d->len);
+	if (d->ret < 0)
+		d->err = errno;
+}
+
+static ssize_t
+nfsd_run_write(struct xthread_workqueue *wq, int fd, const char *buf, size_t len)
+{
+	struct nfsd_write_data data = {
+		fd,
+		buf,
+		len,
+		0,
+		0
+	};
+	xthread_work_run_sync(wq, nfsd_writefunc, &data);
+	if (data.ret < 0)
+		errno = data.err;
+	return data.ret;
+}
+
+ssize_t
+nfsd_path_write(int fd, const char *buf, size_t len)
+{
+	if (!nfsd_wq)
+		return write(fd, buf, len);
+	return nfsd_run_write(nfsd_wq, fd, buf, len);
+}
-- 
2.21.0


  reply	other threads:[~2019-05-28 20:33 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           ` Trond Myklebust [this message]
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         ` [PATCH v3 04/11] Add utilities for resolving nfsd paths and stat()ing them J. Bruce Fields
2019-06-03 14:21           ` 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=20190528203122.11401-7-trond.myklebust@hammerspace.com \
    --to=trondmy@gmail.com \
    --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.