diff options
author | Trond Myklebust <trond.myklebust@hammerspace.com> | 2019-05-29 09:57:25 -0400 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2019-06-10 09:50:38 -0400 |
commit | dcd2c5fb686c22838fa8b07da66a7df7729388b4 (patch) | |
tree | de8e032703ef1982bb3d65591e573cb6ce290c0d /support/misc | |
parent | b513bdc31c526abcd2922ebad90209b7f9cfd310 (diff) | |
download | nfs-utils-dcd2c5fb686c22838fa8b07da66a7df7729388b4.tar.gz |
Add helpers to read/write to a file through the chrooted thread
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>
Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'support/misc')
-rw-r--r-- | support/misc/nfsd_path.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/support/misc/nfsd_path.c b/support/misc/nfsd_path.c index fe2c011..55bca9b 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); +} |