From patchwork Tue May 14 20:41:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10943721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 698FA1398 for ; Tue, 14 May 2019 20:45:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5941B28867 for ; Tue, 14 May 2019 20:45:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57573289A0; Tue, 14 May 2019 20:45:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF24E289A6 for ; Tue, 14 May 2019 20:45:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726211AbfENUpY (ORCPT ); Tue, 14 May 2019 16:45:24 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:54148 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbfENUpY (ORCPT ); Tue, 14 May 2019 16:45:24 -0400 Received: by mail-it1-f196.google.com with SMTP id m141so1140066ita.3 for ; Tue, 14 May 2019 13:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0106F+OIYuqVEg46cY8S9oFV/iyDhlYutv2OgfNUAlo=; b=tiCdkSQxIAHKjBLpNf2brYkBehQrE7qKRql2fvJbkxhezbkN5u1/8eMwXisCaHuocN eebBlCCOGdF8lLQRj8oQDpRVMyuYptoXBc5hxcv+5bHBvuVbY+f/nezyQZPpExEkKx6C WUl0/scGv/3VI0+VUHh1/WgJsyDu2hQs3oKs3i11mv71brk2QaH2rGKNurqBiirOyMIO Vl2tGtgPh7ygZnbIpev4gLWuxivqtMY7y7WFvPnH3e52APd2g4yHppbvMs8mvDhSSN5n tbVFLf2Oc6pIOQXqIwofgvImvoedOW2WHIHomdMigiRUHcj5dqVtIVF2dASdluKZXjOQ T5rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0106F+OIYuqVEg46cY8S9oFV/iyDhlYutv2OgfNUAlo=; b=dEsLZ9mU+eVU2y+nBOyo7vx3mg5vxII0JLkPLkndSvqKoD+wk1xWXGLKsNSdLvb3wu FdubzVSsnMufz6mwWq6awpDKwcXFcdO7vXKuQq5eRUsScYa2XFjMYdp/+8xAExV5YnwC MP2MBgmfYZsU9YrHCVTzHRCEXc/3oRShIiZ/al79yMFCtA4ys9n04tk+De/zBUmuAdzi OsXXS5to5ZxjQIm8jRc57yLoaPPRgBdErgKA9cgyT9Mi15AgAxUFKKXfS+LX6lQb5oYF lmetT2NMfPDqBxw3M3cgnBizb2fFDYEOi1due6SZs03KsTuG7kfkpoGmLCmu77rjP+u6 23uQ== X-Gm-Message-State: APjAAAXSIupSmA9Jrk4rFzUeTomN8BVyVKu7yY42KyecEt/3tiyxerxA 9YIHui94cZYNieJmtpSYvA== X-Google-Smtp-Source: APXvYqwemRpqtgDEJuTL36NgIoc4zI6W28S37cWk61q7uwiHuY3tcb/0qBaCknczSHFgUe7gBoz/sg== X-Received: by 2002:a05:660c:552:: with SMTP id w18mr4864150itk.26.1557866723189; Tue, 14 May 2019 13:45:23 -0700 (PDT) Received: from localhost.localdomain ([172.56.10.94]) by smtp.gmail.com with ESMTPSA id r139sm64943ita.22.2019.05.14.13.45.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 13:45:22 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: steved@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [RFC PATCH 1/5] mountd: Ensure we don't share cache file descriptors among processes. Date: Tue, 14 May 2019 16:41:49 -0400 Message-Id: <20190514204153.79603-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514204153.79603-1-trond.myklebust@hammerspace.com> References: <20190514204153.79603-1-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sharing cache descriptors without using locking can be very bad. Signed-off-by: Trond Myklebust --- utils/mountd/mountd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c index fb7bba4cd390..88a207b3a85a 100644 --- a/utils/mountd/mountd.c +++ b/utils/mountd/mountd.c @@ -836,8 +836,6 @@ main(int argc, char **argv) if (!foreground) closeall(3); - cache_open(); - unregister_services(); if (version2()) { listeners += nfs_svc_create("mountd", MOUNTPROG, @@ -888,6 +886,9 @@ main(int argc, char **argv) if (num_threads > 1) fork_workers(); + /* Open files now to avoid sharing descriptors among forked processes */ + cache_open(); + xlog(L_NOTICE, "Version " VERSION " starting"); my_svc_run(); From patchwork Tue May 14 20:41:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10943729 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 761C61398 for ; Tue, 14 May 2019 20:45:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6695D28938 for ; Tue, 14 May 2019 20:45:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 646C1289A9; Tue, 14 May 2019 20:45:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CBFE289A3 for ; Tue, 14 May 2019 20:45:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726265AbfENUp0 (ORCPT ); Tue, 14 May 2019 16:45:26 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:38714 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbfENUpZ (ORCPT ); Tue, 14 May 2019 16:45:25 -0400 Received: by mail-it1-f194.google.com with SMTP id i63so1021069ita.3 for ; Tue, 14 May 2019 13:45:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Eg7MpNFkzhEOUSAGGmk4fFCaObC0r4PIPOBA3yJuZPk=; b=f1q0CKCXpcH2EToT+VT2xquLmNF3+LpTAgdm3Wm+B32O+uaAqATf0qTaKgnlnqfE7y 5iN/NVPCo93c4qLJX7aIlqJLWtr7W8/hnudq+Xz0s4igT1MKWIAUF6HU+ClVSOiK1Nwo aGc/ZZlf//3SOh3oF4Kk9ADVC7RdrMcTXMROqf6F36J611qhj2zFSAUQGQNtlJH4eEfR PlIOd8m1CwwxaYGPXi+2bm0yB4Qw0njMrwHg20RGJvlmbGzy5EGJnXUqRKbDz+/QJ3PH cubgR8SAtxSTk8aCuZyD1gS5U6+plIMOarz1I8fcqX6Y0kGeBEaXOrZfGBhFZMvrAqei pZDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Eg7MpNFkzhEOUSAGGmk4fFCaObC0r4PIPOBA3yJuZPk=; b=VUt/MYMmokPSfqbFc/Ke2NqUp+KoZFh+cOn7Vb5eZU3nq2APEdiaKV40Z6+0jj7Vvn c/+BXlZHU6DFDzwH0d+FM/N88gGSuzUQyGDvOwwnYHe4KiD0f30sI/EVsdtkzbPpjnc0 kb7EcCqpybUxPgwb4gEsc7YEI9EiDzxUhAQZ3B5f+OKHD4BwNF/S5kn90feFjKDmHKU/ 4wSfZpoEUy5nmNWFtnfNs64AvTfACOqdO1I3saVZWePQYK3s6DZst8SO/JgLJnCHbw5g L9GMxAeILTG2Rtl3OjGfZGvBckyl+8VmVp6gA9zi3kGvxdS8pv1Yq7kZ6+X9pZCobwr1 uHAw== X-Gm-Message-State: APjAAAUwfTkqfDX8ofvbcFc5A1stjWv7PVktiqXVvJVyvGmGxfT8107i uNN9BD7dHS/AYiQNvrJaJfWB4tg= X-Google-Smtp-Source: APXvYqyajIK3CE8JuxrbGS3sFyp74p3tFNICN2JaNqdYD1Vwsp6voHWXUj1g1YDVOIp5Itoc1kwrJw== X-Received: by 2002:a24:9486:: with SMTP id j128mr5180042ite.94.1557866724299; Tue, 14 May 2019 13:45:24 -0700 (PDT) Received: from localhost.localdomain ([172.56.10.94]) by smtp.gmail.com with ESMTPSA id r139sm64943ita.22.2019.05.14.13.45.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 13:45:23 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: steved@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [RFC PATCH 2/5] Add a simple workqueue mechanism Date: Tue, 14 May 2019 16:41:50 -0400 Message-Id: <20190514204153.79603-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514204153.79603-2-trond.myklebust@hammerspace.com> References: <20190514204153.79603-1-trond.myklebust@hammerspace.com> <20190514204153.79603-2-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a simple workqueue mechanism to allow us to run threads that are subject to chroot(), and have them operate on the knfsd kernel daemon. Signed-off-by: Trond Myklebust --- aclocal/libpthread.m4 | 13 +-- configure.ac | 6 +- support/include/misc.h | 9 ++ support/misc/Makefile.am | 2 +- support/misc/workqueue.c | 228 +++++++++++++++++++++++++++++++++++++++ utils/mountd/Makefile.am | 3 +- 6 files changed, 252 insertions(+), 9 deletions(-) create mode 100644 support/misc/workqueue.c diff --git a/aclocal/libpthread.m4 b/aclocal/libpthread.m4 index e87d2a0c2dc5..55e046e38cd1 100644 --- a/aclocal/libpthread.m4 +++ b/aclocal/libpthread.m4 @@ -3,11 +3,12 @@ dnl AC_DEFUN([AC_LIBPTHREAD], [ dnl Check for library, but do not add -lpthreads to LIBS - AC_CHECK_LIB([pthread], [pthread_create], [LIBPTHREAD=-lpthread], - [AC_MSG_ERROR([libpthread not found.])]) - AC_SUBST(LIBPTHREAD) - - AC_CHECK_HEADERS([pthread.h], , - [AC_MSG_ERROR([libpthread headers not found.])]) + AC_CHECK_LIB([pthread], [pthread_create], + [AC_DEFINE([HAVE_LIBPTHREAD], [1], + [Define to 1 if you have libpthread.]) + AC_CHECK_HEADERS([pthread.h], [], + [AC_MSG_ERROR([libpthread headers not found.])]) + AC_SUBST([LIBPTHREAD],[-lpthread])], + [$1]) ])dnl diff --git a/configure.ac b/configure.ac index 4d7096193d0b..c6c2d73b06dd 100644 --- a/configure.ac +++ b/configure.ac @@ -320,6 +320,10 @@ AC_CHECK_FUNC([getservbyname], , AC_CHECK_LIB([crypt], [crypt], [LIBCRYPT="-lcrypt"]) +AC_CHECK_HEADERS([sched.h], [], []) +AC_CHECK_FUNCS([unshare], [] , []) +AC_LIBPTHREAD([]) + if test "$enable_nfsv4" = yes; then dnl check for libevent libraries and headers AC_LIBEVENT @@ -417,7 +421,7 @@ if test "$enable_gss" = yes; then AC_KERBEROS_V5 dnl Check for pthreads - AC_LIBPTHREAD + AC_LIBPTHREAD([AC_MSG_ERROR([libpthread not found.])]) dnl librpcsecgss already has a dependency on libgssapi, dnl but we need to make sure we get the right version diff --git a/support/include/misc.h b/support/include/misc.h index 06e2a0c7b061..40fb9a37621a 100644 --- a/support/include/misc.h +++ b/support/include/misc.h @@ -20,6 +20,15 @@ _Bool generic_setup_basedir(const char *, const char *, char *, const size_t); extern int is_mountpoint(char *path); +/* Naive stack implementation */ +struct xthread_workqueue; +struct xthread_workqueue *xthread_workqueue_alloc(void); +void xthread_workqueue_shutdown(struct xthread_workqueue *wq); +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); + /* size of the file pointer buffers for rpc procfs files */ #define RPC_CHAN_BUF_SIZE 32768 diff --git a/support/misc/Makefile.am b/support/misc/Makefile.am index 8936b0d64e45..d0bff8feb6ae 100644 --- a/support/misc/Makefile.am +++ b/support/misc/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in noinst_LIBRARIES = libmisc.a -libmisc_a_SOURCES = tcpwrapper.c from_local.c mountpoint.c file.c +libmisc_a_SOURCES = tcpwrapper.c from_local.c mountpoint.c file.c workqueue.c MAINTAINERCLEANFILES = Makefile.in diff --git a/support/misc/workqueue.c b/support/misc/workqueue.c new file mode 100644 index 000000000000..16e95e1f6c86 --- /dev/null +++ b/support/misc/workqueue.c @@ -0,0 +1,228 @@ +#include +#include + +#include "config.h" +#include "misc.h" +#include "xlog.h" + +#if defined(HAVE_SCHED_H) && defined(HAVE_LIBPTHREAD) && defined(HAVE_UNSHARE) +#include +#include + +struct xwork_struct { + struct xwork_struct *next; + void (*fn)(void *); + void *data; +}; + +struct xwork_queue { + struct xwork_struct *head; + struct xwork_struct **tail; + + unsigned char shutdown : 1; +}; + +static void xwork_queue_init(struct xwork_queue *queue) +{ + queue->head = NULL; + queue->tail = &queue->head; + queue->shutdown = 0; +} + +static void xwork_enqueue(struct xwork_queue *queue, + struct xwork_struct *entry) +{ + entry->next = NULL; + *queue->tail = entry; + queue->tail = &entry->next; +} + +static struct xwork_struct *xwork_dequeue(struct xwork_queue *queue) +{ + struct xwork_struct *entry = NULL; + if (queue->head) { + entry = queue->head; + queue->head = entry->next; + if (!queue->head) + queue->tail = &queue->head; + } + return entry; +} + +struct xthread_work { + struct xwork_struct work; + + pthread_cond_t cond; +}; + +struct xthread_workqueue { + struct xwork_queue queue; + + pthread_mutex_t mutex; + pthread_cond_t cond; +}; + +static void xthread_workqueue_init(struct xthread_workqueue *wq) +{ + xwork_queue_init(&wq->queue); + pthread_mutex_init(&wq->mutex, NULL); + pthread_cond_init(&wq->cond, NULL); +} + +static void xthread_workqueue_fini(struct xthread_workqueue *wq) +{ + pthread_cond_destroy(&wq->cond); + pthread_mutex_destroy(&wq->mutex); +} + +static int xthread_work_enqueue(struct xthread_workqueue *wq, + struct xthread_work *work) +{ + xwork_enqueue(&wq->queue, &work->work); + pthread_cond_signal(&wq->cond); + return 0; +} + +static struct xthread_work *xthread_work_dequeue(struct xthread_workqueue *wq) +{ + return (struct xthread_work *)xwork_dequeue(&wq->queue); +} + +static void xthread_workqueue_do_work(struct xthread_workqueue *wq) +{ + struct xthread_work *work; + + pthread_mutex_lock(&wq->mutex); + /* Signal the caller that we're up and running */ + pthread_cond_signal(&wq->cond); + for (;;) { + work = xthread_work_dequeue(wq); + if (work) { + work->work.fn(work->work.data); + pthread_cond_signal(&work->cond); + continue; + } + if (wq->queue.shutdown) + break; + pthread_cond_wait(&wq->cond, &wq->mutex); + } + pthread_mutex_unlock(&wq->mutex); +} + +void xthread_workqueue_shutdown(struct xthread_workqueue *wq) +{ + pthread_mutex_lock(&wq->mutex); + wq->queue.shutdown = 1; + pthread_cond_signal(&wq->cond); + pthread_mutex_unlock(&wq->mutex); +} + +static void xthread_workqueue_free(struct xthread_workqueue *wq) +{ + xthread_workqueue_fini(wq); + free(wq); +} + +static void xthread_workqueue_cleanup(void *data) +{ + xthread_workqueue_free(data); +} + +static void *xthread_workqueue_worker(void *data) +{ + pthread_cleanup_push(xthread_workqueue_cleanup, data); + xthread_workqueue_do_work(data); + pthread_cleanup_pop(1); + return NULL; +} + +struct xthread_workqueue *xthread_workqueue_alloc(void) +{ + struct xthread_workqueue *ret; + pthread_t thread; + + ret = malloc(sizeof(*ret)); + if (ret) { + xthread_workqueue_init(ret); + + pthread_mutex_lock(&ret->mutex); + if (pthread_create(&thread, NULL, + xthread_workqueue_worker, + ret) == 0) { + /* Wait for thread to start */ + pthread_cond_wait(&ret->cond, &ret->mutex); + pthread_mutex_unlock(&ret->mutex); + return ret; + } + pthread_mutex_unlock(&ret->mutex); + xthread_workqueue_free(ret); + ret = NULL; + } + return NULL; +} + +void xthread_work_run_sync(struct xthread_workqueue *wq, + void (*fn)(void *), void *data) +{ + struct xthread_work work = { + { + NULL, + fn, + data + }, + PTHREAD_COND_INITIALIZER, + }; + pthread_mutex_lock(&wq->mutex); + xthread_work_enqueue(wq, &work); + pthread_cond_wait(&work.cond, &wq->mutex); + pthread_mutex_unlock(&wq->mutex); + pthread_cond_destroy(&work.cond); +} + +static void xthread_workqueue_do_chroot(void *data) +{ + const char *path = data; + + if (unshare(CLONE_FS) != 0) { + xlog(L_FATAL, "unshare() failed: %m"); + return; + } + if (chroot(path) != 0) + xlog(L_FATAL, "chroot() failed: %m"); +} + +void xthread_workqueue_chroot(struct xthread_workqueue *wq, + const char *path) +{ + xthread_work_run_sync(wq, xthread_workqueue_do_chroot, (void *)path); +} + +#else + +struct xthread_workqueue { +}; + +static struct xthread_workqueue ret; + +struct xthread_workqueue *xthread_workqueue_alloc(void) +{ + return &ret; +} + +void xthread_workqueue_shutdown(struct xthread_workqueue *wq) +{ +} + +void xthread_work_run_sync(struct xthread_workqueue *wq, + void (*fn)(void *), void *data) +{ + fn(data); +} + +void xthread_workqueue_chroot(struct xthread_workqueue *wq, + const char *path) +{ + xlog(L_FATAL, "Unable to run as chroot"); +} + +#endif /* defined(HAVE_SCHED_H) && defined(HAVE_LIBPTHREAD) && defined(HAVE_UNSHARE) */ diff --git a/utils/mountd/Makefile.am b/utils/mountd/Makefile.am index 73eeb3f35070..18610f18238c 100644 --- a/utils/mountd/Makefile.am +++ b/utils/mountd/Makefile.am @@ -19,7 +19,8 @@ mountd_LDADD = ../../support/export/libexport.a \ ../../support/nfs/libnfs.la \ ../../support/misc/libmisc.a \ $(OPTLIBS) \ - $(LIBBSD) $(LIBWRAP) $(LIBNSL) $(LIBBLKID) $(LIBTIRPC) + $(LIBBSD) $(LIBWRAP) $(LIBNSL) $(LIBBLKID) $(LIBTIRPC) \ + $(LIBPTHREAD) mountd_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) \ -I$(top_builddir)/support/include \ -I$(top_srcdir)/support/export From patchwork Tue May 14 20:41:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10943723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0FA71112C for ; Tue, 14 May 2019 20:45:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC2F12896F for ; Tue, 14 May 2019 20:45:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E98D5289AD; Tue, 14 May 2019 20:45:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 903D628981 for ; Tue, 14 May 2019 20:45:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726283AbfENUp1 (ORCPT ); Tue, 14 May 2019 16:45:27 -0400 Received: from mail-it1-f193.google.com ([209.85.166.193]:54152 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbfENUp0 (ORCPT ); Tue, 14 May 2019 16:45:26 -0400 Received: by mail-it1-f193.google.com with SMTP id m141so1140216ita.3 for ; Tue, 14 May 2019 13:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KJ2oJu2m41mvtp0KSs8FygA0nY0SUxW3tOHlG6cKRUs=; b=usjUnB4FJraPl2tebMK1JCpObS7OGu0j98kCNt1KfSnNltXGq5aY0u0vuhI7j3CvAq nJ3EcMb25qC2fn4WCb2KvZjnr5uWbEBVdSFmuEL7uFGmm5TCStTq7jOUEU4YbnwVwHs6 sre5/rfM4RhMQUjGS3OtjZReJ55ODK8cG7mb2C5rWxVABv5d/0cEj7ET79AI2V4nCjU+ cEsC04wjD6mTX4q+9r2W72Zl3x0uLcmCgYEXnyJx3G0NEFqFUGCID2h+JAF9PwijZlsu GYYEqAcNudkuP1+4J0bk3TTFzawspH3icpuFdQ5rFviMMB2t7rpXYC0PVmUUR0YInguV FgKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KJ2oJu2m41mvtp0KSs8FygA0nY0SUxW3tOHlG6cKRUs=; b=t8ev+Am3WwJk1E1oYZvbxCqCYlzsHLlOvWk+LAuqQFOCE19JGliWOp120V9EZQnUMK XPRemq99xvom1ad7t7dnloOzSL/DDtH+PMUgh/AHwL/tTDaw55MHlZvfITTZzN2FevcT krG35o2rRjKwsaVF1v3LxFbMp7fLSmCzgA0mY2ZsOJRolHUGxjKXig9YvqNO4rentcqu oxO6uwcsVXvYGK/+UzvuCzpt3Bv2v9BbX0rFJoeF/+ZIs54xWDZqJPToQc1o3zdgiQCk aSVwwWF+1atwDAQzb/IKGOG+QFBnWzgQ2PWM120A858k1ALesS9CtcJ4poteINKwsPiw KU7w== X-Gm-Message-State: APjAAAUKdkFCxOFXMRaDs8bpziZqTZ3E0msNxhe9AbLkE50afhP8b1gs w+G9Z5srNbkcV2Jr84R+zQ== X-Google-Smtp-Source: APXvYqz9FSjiwriqOGlwwy+RHmnq0NEDA+oFYrSG0mT07ayaSCdKqpunIBVJxKoBYqCnAL6/ErtATg== X-Received: by 2002:a24:4585:: with SMTP id c5mr5490016itd.79.1557866725482; Tue, 14 May 2019 13:45:25 -0700 (PDT) Received: from localhost.localdomain ([172.56.10.94]) by smtp.gmail.com with ESMTPSA id r139sm64943ita.22.2019.05.14.13.45.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 13:45:24 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust 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 Message-Id: <20190514204153.79603-4-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514204153.79603-3-trond.myklebust@hammerspace.com> References: <20190514204153.79603-1-trond.myklebust@hammerspace.com> <20190514204153.79603-2-trond.myklebust@hammerspace.com> <20190514204153.79603-3-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Trond Myklebust --- 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 #include #include @@ -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) */ From patchwork Tue May 14 20:41:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10943727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 764851398 for ; Tue, 14 May 2019 20:45:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65EF32892C for ; Tue, 14 May 2019 20:45:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 638C92892E; Tue, 14 May 2019 20:45:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6DFE289AA for ; Tue, 14 May 2019 20:45:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726338AbfENUp2 (ORCPT ); Tue, 14 May 2019 16:45:28 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:41605 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbfENUp2 (ORCPT ); Tue, 14 May 2019 16:45:28 -0400 Received: by mail-io1-f67.google.com with SMTP id a17so382967iot.8 for ; Tue, 14 May 2019 13:45:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Og7oWbWWeKOcvPck2OBvAqHBM3lVUuH8Q7w6/EYUAu0=; b=ElDUkdj0RBtZZADV71OYu2VWFoQ5tHYZO93i8LS0g3iLt/fsdH5Vt3VPs9vXzDF0z1 6gG9/KGMOfDOHT8BUalpGzVMPcCwoIS/KSya3MtY7dzKUjl0lVWnPo+fxuW+p6nt9RE8 FEolWppluyFvw7gzdX66agADwcd34EAjfFprbc8lM6diFpGo9v6MD1lpdauTdz72FSKb jHLvLh5/rR1EsCL59rqx38gjBI97jsUrm2FQzCf1JLlbTmWjiZYWyMCzL0TKx6hqKW/G 8N6Js8tk1lIqGAjgzabwLRiVytXga/XtRPJG5CtpYnjX/s606bR6QVLTkV+w8Kg+zTnd cDuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Og7oWbWWeKOcvPck2OBvAqHBM3lVUuH8Q7w6/EYUAu0=; b=IrAKO5r3TVbDY6mjuu+rb/kMa08fryQBybdO9rQSn/QU22XXIo+SZAz4D2srrPDaHA fz/X8HEhJWZb9dk61dRGMQ93mg5lW5p2UAf3N54B8a67YR30sWcbhkzctzryv80DzDQW /IXaqIY8lWh5eWf9F1kdFIVXNef09SFrT5QA/biYNcpzhPPkZORYLGeOoUAoKo6PGRza v7Z1kfBHEp3bV9OxcTXBNUl7as0h9pSKjlYNOIsbrEwR9pPzCvszbk49P2G2RXvG1/Cb MFxSm08joRx0MkMRTZWrBaiyXF7kBUAYxEYJMrg7A8rHPXQNuxi31uYrsU7SPX6Ot04V /XjA== X-Gm-Message-State: APjAAAWRJVqNcC9SFEZ0YIYg+Pe6Hzfhh/zMD7FXvyobkhGtwfdYTDXj L2nqkUnsBLPFNz3yiI8gQkXcDyA= X-Google-Smtp-Source: APXvYqxF6V+94qVXd5Fv3tqDFTlhk6EqsSvKk9gUtNiVWOsCaGu+CZyfegnUW67vKXWhb7yvX6e0Bg== X-Received: by 2002:a5d:8055:: with SMTP id b21mr16760744ior.241.1557866726568; Tue, 14 May 2019 13:45:26 -0700 (PDT) Received: from localhost.localdomain ([172.56.10.94]) by smtp.gmail.com with ESMTPSA id r139sm64943ita.22.2019.05.14.13.45.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 13:45:26 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: steved@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [RFC PATCH 4/5] Add support for chrooted exports Date: Tue, 14 May 2019 16:41:52 -0400 Message-Id: <20190514204153.79603-5-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514204153.79603-4-trond.myklebust@hammerspace.com> References: <20190514204153.79603-1-trond.myklebust@hammerspace.com> <20190514204153.79603-2-trond.myklebust@hammerspace.com> <20190514204153.79603-3-trond.myklebust@hammerspace.com> <20190514204153.79603-4-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Trond Myklebust --- nfs.conf | 1 + systemd/nfs.conf.man | 3 ++- utils/mountd/cache.c | 39 +++++++++++++++++++++++++++++++++++---- utils/nfsd/nfsd.man | 4 ++++ 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/nfs.conf b/nfs.conf index 27e962c8a2a9..aad73035a466 100644 --- a/nfs.conf +++ b/nfs.conf @@ -60,6 +60,7 @@ # vers4.1=y # vers4.2=y # rdma=n +# chroot=/export # [statd] # debug=0 diff --git a/systemd/nfs.conf.man b/systemd/nfs.conf.man index e3654a3c2c2b..bd83e57dd6da 100644 --- a/systemd/nfs.conf.man +++ b/systemd/nfs.conf.man @@ -136,7 +136,8 @@ Recognized values: .BR vers4.0 , .BR vers4.1 , .BR vers4.2 , -.BR rdma . +.BR rdma , +.BR chroot . Version and protocol values are Boolean values as described above, and are also used by diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c index bdbd1904eb76..25b0fb84f753 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -33,11 +33,14 @@ #include "fsloc.h" #include "pseudoflavors.h" #include "xcommon.h" +#include "conffile.h" #ifdef USE_BLKID #include "blkid/blkid.h" #endif +static struct xthread_workqueue *cache_workqueue; + /* * Invoked by RPC service loop */ @@ -55,6 +58,32 @@ enum nfsd_fsid { FSID_UUID16_INUM, }; +static ssize_t cache_write(int fd, const char *buf, size_t len) +{ + if (cache_workqueue) + return xthread_write(cache_workqueue, fd, buf, len); + return write(fd, buf, len); +} + +static void +cache_setup_workqueue(void) +{ + const char *chroot; + + chroot = conf_get_str("nfsd", "chroot"); + if (!chroot || *chroot == '\0') + return; + /* Strip leading '/' */ + while (chroot[0] == '/' && chroot[1] == '/') + chroot++; + if (chroot[0] == '/' && chroot[1] == '\0') + return; + cache_workqueue = xthread_workqueue_alloc(); + if (!cache_workqueue) + return; + xthread_workqueue_chroot(cache_workqueue, chroot); +} + /* * Support routines for text-based upcalls. * Fields are separated by spaces. @@ -829,7 +858,7 @@ static void nfsd_fh(int f) if (found) qword_add(&bp, &blen, found_path); qword_addeol(&bp, &blen); - if (blen <= 0 || write(f, buf, bp - buf) != bp - buf) + if (blen <= 0 || cache_write(f, buf, bp - buf) != bp - buf) xlog(L_ERROR, "nfsd_fh: error writing reply"); out: if (found_path) @@ -921,7 +950,7 @@ static int dump_to_cache(int f, char *buf, int buflen, char *domain, qword_adduint(&bp, &blen, now + ttl); qword_addeol(&bp, &blen); if (blen <= 0) return -1; - if (write(f, buf, bp - buf) != bp - buf) return -1; + if (cache_write(f, buf, bp - buf) != bp - buf) return -1; return 0; } @@ -1381,6 +1410,8 @@ extern int manage_gids; void cache_open(void) { int i; + + cache_setup_workqueue(); for (i=0; cachelist[i].cache_name; i++ ) { char path[100]; if (!manage_gids && cachelist[i].cache_handle == auth_unix_gid) @@ -1508,7 +1539,7 @@ int cache_export(nfs_export *exp, char *path) qword_adduint(&bp, &blen, time(0) + exp->m_export.e_ttl); qword_add(&bp, &blen, exp->m_client->m_hostname); qword_addeol(&bp, &blen); - if (blen <= 0 || write(f, buf, bp - buf) != bp - buf) blen = -1; + if (blen <= 0 || cache_write(f, buf, bp - buf) != bp - buf) blen = -1; close(f); if (blen < 0) return -1; @@ -1546,7 +1577,7 @@ cache_get_filehandle(nfs_export *exp, int len, char *p) qword_add(&bp, &blen, p); qword_addint(&bp, &blen, len); qword_addeol(&bp, &blen); - if (blen <= 0 || write(f, buf, bp - buf) != bp - buf) { + if (blen <= 0 || cache_write(f, buf, bp - buf) != bp - buf) { close(f); return NULL; } diff --git a/utils/nfsd/nfsd.man b/utils/nfsd/nfsd.man index d83ef869d26e..8fb23721daf6 100644 --- a/utils/nfsd/nfsd.man +++ b/utils/nfsd/nfsd.man @@ -167,6 +167,10 @@ Setting these to "off" or similar will disable the selected minor versions. Setting to "on" will enable them. The default values are determined by the kernel, and usually minor versions default to being enabled once the implementation is sufficiently complete. +.B chroot +Setting this to a valid path causes the nfs server to act as if the +supplied path is being prefixed to all the exported entries. + .SH NOTES If the program is built with TI-RPC support, it will enable any protocol and From patchwork Tue May 14 20:41:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10943731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 77DBF1515 for ; Tue, 14 May 2019 20:45:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 670DB289A3 for ; Tue, 14 May 2019 20:45:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 652D0286AE; Tue, 14 May 2019 20:45:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 124AF286AE for ; Tue, 14 May 2019 20:45:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726339AbfENUp3 (ORCPT ); Tue, 14 May 2019 16:45:29 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:34431 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbfENUp3 (ORCPT ); Tue, 14 May 2019 16:45:29 -0400 Received: by mail-it1-f194.google.com with SMTP id p18so3688556itm.1 for ; Tue, 14 May 2019 13:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YLFiZF5mHp7zkvqSK8XIsompacTeyXE20QIyu2YrAIo=; b=DoOfqF786GUL1ijS9+7zrTwjHp9xY3dINqjdU8aSyD/kmaWytoSjaFm1OWSO9zBD+i 5w2ELBz96B5NtmLXH+GQMyDMEO8EejqScqOU7fxfjEGYSvlV63VfEtJB44ipSe/ldk/F ZMrER8J58JmV/dR6+GtfQQbOpm0kP1eMCbGe+yNs5A4avWtAT6Rmu4rmxbUgzdz4TVIn JPETN1sV+cB2dGJMv9/oZC8iMzNWfq0m1H7qMLU3Ic6fOa0Yz9Eh9VBe3zzGtVZDhaXC tgfzK4x7TYj5ZvcBQ9U1mo+UYAfTH14GV4a0vWbi48tTCx1+78gqx7h+8LXgc+4I0wne wDGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YLFiZF5mHp7zkvqSK8XIsompacTeyXE20QIyu2YrAIo=; b=YBYzQQzTNHaBesyfLQVECze6LUCgYrV5Fn6p+IbUe+61WZ1/SHbyDwyWVEAeGS/tG6 JwsFGeh+Rf6IUAF6apvwyAY1GjUTrSeN3UUW/R7BlpLLEbZpxFgrGYlkAfl89nduLVqp LdGx8Y2eU+alnfXo97e43JvL9JbjbmxBF/uFF6URRahYQLNBD1eCARpX/B5ZveIRhCSX UcJac3u/NA3RzsiaXp+6DJnmqNCpNjgreeXOIskkQpntYrTK83lzXjtRq4qS1PPARtBD 8Hfe1NKF2lkMSpMYNd7FBQ8OPeBzF/6Ulb3ljqyH7GvBU1Esv5K6xCqePgZZEpOgsZJ9 PauQ== X-Gm-Message-State: APjAAAUbbNfoiLACDeRTjGRaD1on5OZeZjhUplc3cl/mpshaLVRB2R7m +bS6x+8vRFyUYVM8urKlBtSGzfM= X-Google-Smtp-Source: APXvYqx880Srtnit6H8SSPSCRxKY4XXObZnD3gaMPi+oAGhakE52NOJBRoj0dkss2a11phyeBEDVDA== X-Received: by 2002:a24:fa42:: with SMTP id v63mr5055243ith.20.1557866727981; Tue, 14 May 2019 13:45:27 -0700 (PDT) Received: from localhost.localdomain ([172.56.10.94]) by smtp.gmail.com with ESMTPSA id r139sm64943ita.22.2019.05.14.13.45.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 13:45:27 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: steved@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [RFC PATCH 5/5] Add support for chroot in exportfs Date: Tue, 14 May 2019 16:41:53 -0400 Message-Id: <20190514204153.79603-6-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514204153.79603-5-trond.myklebust@hammerspace.com> References: <20190514204153.79603-1-trond.myklebust@hammerspace.com> <20190514204153.79603-2-trond.myklebust@hammerspace.com> <20190514204153.79603-3-trond.myklebust@hammerspace.com> <20190514204153.79603-4-trond.myklebust@hammerspace.com> <20190514204153.79603-5-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Trond Myklebust --- utils/exportfs/Makefile.am | 2 +- utils/exportfs/exportfs.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/utils/exportfs/Makefile.am b/utils/exportfs/Makefile.am index 4b291610d19b..96524c729359 100644 --- a/utils/exportfs/Makefile.am +++ b/utils/exportfs/Makefile.am @@ -10,6 +10,6 @@ exportfs_SOURCES = exportfs.c exportfs_LDADD = ../../support/export/libexport.a \ ../../support/nfs/libnfs.la \ ../../support/misc/libmisc.a \ - $(LIBWRAP) $(LIBNSL) + $(LIBWRAP) $(LIBNSL) $(LIBPTHREAD) MAINTAINERCLEANFILES = Makefile.in diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c index 333eadcd0228..bc87d7fe4ee1 100644 --- a/utils/exportfs/exportfs.c +++ b/utils/exportfs/exportfs.c @@ -52,6 +52,33 @@ static const char *lockfile = EXP_LOCKFILE; static int _lockfd = -1; struct state_paths etab; +static struct xthread_workqueue *exportfs_wq; + +static ssize_t exportfs_write(int fd, const char *buf, size_t len) +{ + if (exportfs_wq) + return xthread_write(exportfs_wq, fd, buf, len); + return write(fd, buf, len); +} + +static void +exportfs_setup_workqueue(void) +{ + const char *chroot; + + chroot = conf_get_str("nfsd", "chroot"); + if (!chroot || *chroot == '\0') + return; + /* Strip leading '/' */ + while (chroot[0] == '/' && chroot[1] == '/') + chroot++; + if (chroot[0] == '/' && chroot[1] == '\0') + return; + exportfs_wq = xthread_workqueue_alloc(); + if (!exportfs_wq) + return; + xthread_workqueue_chroot(exportfs_wq, chroot); +} /* * If we aren't careful, changes made by exportfs can be lost @@ -181,6 +208,8 @@ main(int argc, char **argv) } } + exportfs_setup_workqueue(); + /* * Serialize things as best we can */ @@ -505,7 +534,7 @@ static int test_export(nfs_export *exp, int with_fsid) fd = open("/proc/net/rpc/nfsd.export/channel", O_WRONLY); if (fd < 0) return 0; - n = write(fd, buf, strlen(buf)); + n = exportfs_write(fd, buf, strlen(buf)); close(fd); if (n < 0) return 0;