From: Trond Myklebust <trondmy@gmail.com>
To: steved@redhat.com
Cc: linux-nfs@vger.kernel.org
Subject: [RFC PATCH 3/5] Add a helper to write to a file through the chrooted thread
Date: Tue, 14 May 2019 16:41:51 -0400 [thread overview]
Message-ID: <20190514204153.79603-4-trond.myklebust@hammerspace.com> (raw)
In-Reply-To: <20190514204153.79603-3-trond.myklebust@hammerspace.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
support/include/misc.h | 2 ++
support/misc/workqueue.c | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/support/include/misc.h b/support/include/misc.h
index 40fb9a37621a..0632df101bbb 100644
--- a/support/include/misc.h
+++ b/support/include/misc.h
@@ -28,6 +28,8 @@ void xthread_work_run_sync(struct xthread_workqueue *wq,
void (*fn)(void *), void *data);
void xthread_workqueue_chroot(struct xthread_workqueue *wq,
const char *path);
+ssize_t xthread_write(struct xthread_workqueue *wq,
+ int fd, const char *buf, size_t len);
/* size of the file pointer buffers for rpc procfs files */
#define RPC_CHAN_BUF_SIZE 32768
diff --git a/support/misc/workqueue.c b/support/misc/workqueue.c
index 16e95e1f6c86..7af76a84e8dd 100644
--- a/support/misc/workqueue.c
+++ b/support/misc/workqueue.c
@@ -1,3 +1,4 @@
+#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
@@ -197,6 +198,39 @@ void xthread_workqueue_chroot(struct xthread_workqueue *wq,
xthread_work_run_sync(wq, xthread_workqueue_do_chroot, (void *)path);
}
+struct xthread_io_data {
+ int fd;
+ const char *buf;
+ size_t len;
+ ssize_t ret;
+ int err;
+};
+
+static void xthread_writefunc(void *data)
+{
+ struct xthread_io_data *d = data;
+
+ d->ret = write(d->fd, d->buf, d->len);
+ if (d->ret < 0)
+ d->err = errno;
+}
+
+ssize_t xthread_write(struct xthread_workqueue *wq,
+ int fd, const char *buf, size_t len)
+{
+ struct xthread_io_data data = {
+ fd,
+ buf,
+ len,
+ 0,
+ 0
+ };
+ xthread_work_run_sync(wq, xthread_writefunc, &data);
+ if (data.ret < 0)
+ errno = data.err;
+ return data.ret;
+}
+
#else
struct xthread_workqueue {
@@ -225,4 +259,9 @@ void xthread_workqueue_chroot(struct xthread_workqueue *wq,
xlog(L_FATAL, "Unable to run as chroot");
}
+ssize_t xthread_write(struct xthread_workqueue *wq,
+ int fd, const char *buf, size_t len)
+{
+ return write(fd, buf, len);
+}
#endif /* defined(HAVE_SCHED_H) && defined(HAVE_LIBPTHREAD) && defined(HAVE_UNSHARE) */
--
2.21.0
next prev parent reply other threads:[~2019-05-14 20:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-14 20:41 [RFC PATCH 0/5] Add a chroot option to nfs.conf Trond Myklebust
2019-05-14 20:41 ` [RFC PATCH 1/5] mountd: Ensure we don't share cache file descriptors among processes Trond Myklebust
2019-05-14 20:41 ` [RFC PATCH 2/5] Add a simple workqueue mechanism Trond Myklebust
2019-05-14 20:41 ` Trond Myklebust [this message]
2019-05-14 20:41 ` [RFC PATCH 4/5] Add support for chrooted exports Trond Myklebust
2019-05-14 20:41 ` [RFC PATCH 5/5] Add support for chroot in exportfs Trond Myklebust
2019-05-15 14:14 ` [RFC PATCH 4/5] Add support for chrooted exports J. Bruce Fields
2019-05-15 14:01 ` [RFC PATCH 0/5] Add a chroot option to nfs.conf J. Bruce Fields
2019-05-15 14:38 ` Trond Myklebust
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=20190514204153.79603-4-trond.myklebust@hammerspace.com \
--to=trondmy@gmail.com \
--cc=linux-nfs@vger.kernel.org \
--cc=steved@redhat.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).