@@ -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
@@ -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) */
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> --- support/include/misc.h | 2 ++ support/misc/workqueue.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)