From patchwork Tue May 28 20:31:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10965801 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 8EAB91398 for ; Tue, 28 May 2019 20:33:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D53228676 for ; Tue, 28 May 2019 20:33:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CE83286FF; Tue, 28 May 2019 20:33:33 +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 20B2528676 for ; Tue, 28 May 2019 20:33:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726511AbfE1Udc (ORCPT ); Tue, 28 May 2019 16:33:32 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:54336 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726812AbfE1Udc (ORCPT ); Tue, 28 May 2019 16:33:32 -0400 Received: by mail-it1-f196.google.com with SMTP id h20so6577528itk.4 for ; Tue, 28 May 2019 13:33:32 -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=RjGBVQz6NQpznw+aHfsqdPr9Xz9oHWvf3xvIyy2anhUJCWl1lE45KaD83Z1PvUDy6K W8VPN6IVx9CwhExI0TMC9M1vUu2TSko3HOApaIBKcXMsdaO9oy+1K32hI0Y6fsZpfypP wTOd9cWD2MJBeyGjTjEXlF/tKRGjTB+lVnvQ0adn6acdjy0d7iiGLq5Dk0NHN8/IvR04 tAOc0nQ5sN/ZMrn2lPQSChz2eZgkVJzwwaBSBOR3J3+IhgUmGqf8XKNhR+GOvZsNjnUd sAemyw1aqXSdY2faFV30St/ocUbMW87QBA5QK6xsmnwWiYqla3o7B9Mhb34za2F08Hr/ mM6Q== 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=cVkmvmZkJT0HajoNgLAxXPEX03reuK6yYELobf4Ptb3TTGhXFmzd1slXNBWC1Iixf4 dOAYEZZnHqROp/oBaKroIo6Gs1/rugn2wnpClr7qIn6wcEJZMj8HgRaulvRSh1tEHdBU WcPvZAam4DtmZXKQDvh8WjGqnLYXxAS2LCZve1/llvfv4Nq3sjOhWX+RYUiyGq0MXFVY 90KGgb0/pPJdd3SCxEoga1PkFIlVmoN78OYi5LatbGnYkBtXL0fw6KGK7shvwFUtLnEI vHxOzD8iaqQLSUS+3RRwlU7slJ0arGPWANEsgccZcbWQNvlOoedtG33zAVLdn4SaMNvZ wLWQ== X-Gm-Message-State: APjAAAX8paVGImEdpbG7FjdCdUcMcKzKse620Oxcugt7oFFQgXGFWAhl 9rsH5+qiqUPqmqYqa1zGoPgl+jg= X-Google-Smtp-Source: APXvYqwCQmDcMfqwTpYfJh9aJExL11azF+EB1WPCOKtpyriZx8b7cggxaq04OytGJvcrWrJxVzAsDw== X-Received: by 2002:a24:d405:: with SMTP id x5mr4460074itg.85.1559075611356; Tue, 28 May 2019 13:33:31 -0700 (PDT) Received: from localhost.localdomain (50-124-247-140.alma.mi.frontiernet.net. [50.124.247.140]) by smtp.gmail.com with ESMTPSA id i141sm53089ite.20.2019.05.28.13.33.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 13:33:30 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: SteveD@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 01/11] mountd: Ensure we don't share cache file descriptors among processes. Date: Tue, 28 May 2019 16:31:12 -0400 Message-Id: <20190528203122.11401-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190528203122.11401-1-trond.myklebust@hammerspace.com> References: <20190528203122.11401-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 28 20:31:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10965807 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 007A71398 for ; Tue, 28 May 2019 20:33:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6BF22866D for ; Tue, 28 May 2019 20:33:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB4D2286A1; Tue, 28 May 2019 20:33:35 +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 0B8902866D for ; Tue, 28 May 2019 20:33:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727146AbfE1Ude (ORCPT ); Tue, 28 May 2019 16:33:34 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:40367 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726812AbfE1Ude (ORCPT ); Tue, 28 May 2019 16:33:34 -0400 Received: by mail-io1-f65.google.com with SMTP id n5so10767088ioc.7 for ; Tue, 28 May 2019 13:33:33 -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=WTJIEF64GQ5WaLkZVqyDs/M6F2K2o7LdsId5gPgoX24=; b=GOGqf0dc+EiLh3kOA0ZdMppBUs7iVSudCTGNZAV+K5UTDY4h5GKcZxtx94w7abl7E3 a7i2OGTLIzpCw96AXguw4DpZ5qIJ22+G+Rf0vqqj2Dr3V61Qm5QcDJITv+GvPU1IQ7i3 beq5oego4xk+40LjqhiAs5gJd9zi3Hfs6aiP5ENmL6P8NvP4hQjSCzu+/lA3b94xq4oQ Pd6wOCOSOxR8Mj6ojSGJA8xjfUXDayJEIXmNt97mZkh5WGtlDMMlh6fVQ2pyiXDK4ONY IeUl6Sj8MEgXvVWGLHPmYIJpIm5pmg0uZ3Zu0xzE20jfo3mXwGiNoWsxOjBHHiGZ7efh tU6g== 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=WTJIEF64GQ5WaLkZVqyDs/M6F2K2o7LdsId5gPgoX24=; b=DRGfam5q8JpusxO/sF/8nR88dfc5RRGqgZNGXtqTenmM2QCCTlxDJkoYDvcG7H+lYJ /Pte+VuOoZjnwoDHvkRC1/6/fAIPOmIxnc/m90oslNXtN30XU8W+grqfTmhyJwlbaoQO a6pUfCsQ64s3Awrs8hT09r/C2AHQ90tLuqWIIBkjeiJKsFWS31QNA+1989Tx7kbrbaRd ghP3RdjDBqemP/yGXWQwR4i0ZUAhwjtNv0m7QzsDchkal/4fV9oZmv79oABgiyZpBUNP 4jUrpKCSZ5XVOXPqG7jzpf31z4yMKlturfFXunZlk4/Ayh0rqzySPIfeIE4cIr4Y+fGi 0LHw== X-Gm-Message-State: APjAAAUKhiYAirVF6HbCR3SO+Q752WdKPzOOGY7mPYEwV3+HKCLtTVZ2 Ud8jxEp991Zawj4vHGySQQ== X-Google-Smtp-Source: APXvYqzEN+PdZOBI8vhXTKA/UHcUJziAmxF8HB8PMFVCDx6VygaDXNuKJhHnbUMSRwQTUQ8AemXCeA== X-Received: by 2002:a5d:968e:: with SMTP id m14mr40478686ion.49.1559075612399; Tue, 28 May 2019 13:33:32 -0700 (PDT) Received: from localhost.localdomain (50-124-247-140.alma.mi.frontiernet.net. [50.124.247.140]) by smtp.gmail.com with ESMTPSA id i141sm53089ite.20.2019.05.28.13.33.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 13:33:31 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: SteveD@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 02/11] Add a simple workqueue mechanism Date: Tue, 28 May 2019 16:31:13 -0400 Message-Id: <20190528203122.11401-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190528203122.11401-2-trond.myklebust@hammerspace.com> References: <20190528203122.11401-1-trond.myklebust@hammerspace.com> <20190528203122.11401-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/Makefile.am | 1 + support/include/workqueue.h | 18 +++ support/misc/Makefile.am | 2 +- support/misc/workqueue.c | 228 ++++++++++++++++++++++++++++++++++++ utils/mountd/Makefile.am | 3 +- 7 files changed, 262 insertions(+), 9 deletions(-) create mode 100644 support/include/workqueue.h 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/Makefile.am b/support/include/Makefile.am index 599f500e2b40..df5e47836d29 100644 --- a/support/include/Makefile.am +++ b/support/include/Makefile.am @@ -19,6 +19,7 @@ noinst_HEADERS = \ sockaddr.h \ tcpwrapper.h \ v4root.h \ + workqueue.h \ xio.h \ xlog.h \ xmalloc.h \ diff --git a/support/include/workqueue.h b/support/include/workqueue.h new file mode 100644 index 000000000000..518be82f1b34 --- /dev/null +++ b/support/include/workqueue.h @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2019 Trond Myklebust + */ +#ifndef WORKQUEUE_H +#define WORKQUEUE_H + +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); + +#endif 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..b8d03446f2c7 --- /dev/null +++ b/support/misc/workqueue.c @@ -0,0 +1,228 @@ +#include +#include + +#include "config.h" +#include "workqueue.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_err("unshare() failed: %m"); + return; + } + if (chroot(path) != 0) + xlog_err("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_err("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 28 20:31:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10965805 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 B0B51933 for ; Tue, 28 May 2019 20:33:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4AAF28676 for ; Tue, 28 May 2019 20:33:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 976CA286FF; Tue, 28 May 2019 20:33:35 +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 430F328676 for ; Tue, 28 May 2019 20:33:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726812AbfE1Ude (ORCPT ); Tue, 28 May 2019 16:33:34 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:53446 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727075AbfE1Ude (ORCPT ); Tue, 28 May 2019 16:33:34 -0400 Received: by mail-it1-f194.google.com with SMTP id m141so6581279ita.3 for ; Tue, 28 May 2019 13:33:34 -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=5XCyxEssCkoFUZsF1Xsl+Bt7IoweXokZG+MQ8pRyU00=; b=iYWsyzTpesb37ABSyErBixcQaBLSmpgpRKwsTAsc9QS/V7xhiUXaC2YvHyCtnKfv44 713byh221DuRvCrxlYyybI7sgC5nfOpm9qukze53Ug/XmilrnmRico9EO1wVteozRrm0 jMaa0OtY3wvzZb/ibt1YjoXVmZJPJaf782H6Gi+vy5/aDYFaEwhuy2pNTNCdBKkQcRzB a2Z6r8eAKp56sz3jv6QrVL0iqrQwCXgP3PyGlLqhGR49am+GELAFd6aqE6mCRAZVvTmc QusXlujWNCSty+xyAwYVZig6QPnlSV0l4CtG3MCGg5FReAxGYAYslgCRWdcbgsUmq+W1 D9BA== 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=5XCyxEssCkoFUZsF1Xsl+Bt7IoweXokZG+MQ8pRyU00=; b=LFT9ZP4aCC0fYH+gy7ybrmmRi7iTYlVW5SfSbPkdeoRXouEHZefnoweFfPr1xxe6oV 7pf5Id2GeiFLu6OAYmRlsM/nyUbzbdYEb6cD36yKWIvJdkctKQJrMb5DLGzYTcUMPBho 6fv6Kq7HQqzBPV5ETLTKFepTZx5pZ+cXk0IOyosHPmzyptmEF4mMvtao4/DZOsAfgTan kBvVyjhJsKznZWac12WQj5EXU6HKJvwQupfb341QGWbhjNCNwT0b8R2oj2RLz2QR6SI5 La9YraahJS69PJ6P9ZPynK6S1Uyafowf/XUtCGZw4efnan3eb50TyCG8akRQeRMnIxqK rljQ== X-Gm-Message-State: APjAAAV5sJa9qNH14Zlfqyjjc2Guzg+5Jixb+IhQqa1cCp/7cQomhfr7 mtMIIraClskbLtpcrMMKbA== X-Google-Smtp-Source: APXvYqyVRTrlcTE9PIeFlSHADdgq0FGBprHLbKc/OSpEetB4WY+PDMJy/IHseSfhhXWkTffksTXB7w== X-Received: by 2002:a24:5fc2:: with SMTP id r185mr4444465itb.43.1559075613430; Tue, 28 May 2019 13:33:33 -0700 (PDT) Received: from localhost.localdomain (50-124-247-140.alma.mi.frontiernet.net. [50.124.247.140]) by smtp.gmail.com with ESMTPSA id i141sm53089ite.20.2019.05.28.13.33.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 13:33:32 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: SteveD@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 03/11] Allow callers to check mountpoint status using a custom lstat function Date: Tue, 28 May 2019 16:31:14 -0400 Message-Id: <20190528203122.11401-4-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190528203122.11401-3-trond.myklebust@hammerspace.com> References: <20190528203122.11401-1-trond.myklebust@hammerspace.com> <20190528203122.11401-2-trond.myklebust@hammerspace.com> <20190528203122.11401-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 | 7 ++++++- support/misc/mountpoint.c | 8 +++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/support/include/misc.h b/support/include/misc.h index 06e2a0c7b061..2b0fef26cb11 100644 --- a/support/include/misc.h +++ b/support/include/misc.h @@ -18,7 +18,12 @@ int weakrandomkey(unsigned char *keyout, int len); char *generic_make_pathname(const char *, const char *); _Bool generic_setup_basedir(const char *, const char *, char *, const size_t); -extern int is_mountpoint(char *path); +struct stat; + +extern int check_is_mountpoint(const char *path, + int (mystat)(const char *, struct stat *)); +#define is_mountpoint(path) \ + check_is_mountpoint(path, NULL) /* size of the file pointer buffers for rpc procfs files */ #define RPC_CHAN_BUF_SIZE 32768 diff --git a/support/misc/mountpoint.c b/support/misc/mountpoint.c index 9f9ce44ec1e3..c6217f2458d1 100644 --- a/support/misc/mountpoint.c +++ b/support/misc/mountpoint.c @@ -9,8 +9,10 @@ #include "misc.h" int -is_mountpoint(char *path) +check_is_mountpoint(const char *path, int (mystat)(const char *, struct stat *)) { + if (!mystat) + mystat = lstat; /* Check if 'path' is a current mountpoint. * Possibly we should also check it is the mountpoint of the * filesystem holding the target directory, but there doesn't @@ -26,8 +28,8 @@ is_mountpoint(char *path) dotdot = xmalloc(strlen(path)+4); strcat(strcpy(dotdot, path), "/.."); - if (lstat(path, &stb) != 0 || - lstat(dotdot, &pstb) != 0) + if (mystat(path, &stb) != 0 || + mystat(dotdot, &pstb) != 0) rv = 0; else if (stb.st_dev != pstb.st_dev || From patchwork Tue May 28 20:31:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10965809 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 693031398 for ; Tue, 28 May 2019 20:33:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BA102866D for ; Tue, 28 May 2019 20:33:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FE77286A1; Tue, 28 May 2019 20:33:37 +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 97BAB2866D for ; Tue, 28 May 2019 20:33:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727180AbfE1Udg (ORCPT ); Tue, 28 May 2019 16:33:36 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:42047 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727075AbfE1Udf (ORCPT ); Tue, 28 May 2019 16:33:35 -0400 Received: by mail-io1-f66.google.com with SMTP id g16so16904000iom.9 for ; Tue, 28 May 2019 13:33:35 -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=4XqEpVzB6pdIBPKKe3DYeMe1MU19xVZqtRve9/VfUHc=; b=iQ6I35QK3hPJCfSvb0yUaES4rKWOUrIb+vx2XV5zZTtmCptxKIo3INyGkHUKfZ5FQ8 mscTHJVCdHj+xbkYZ5RmWRtc7QWkLAO+fjlethW4ft8QfXMEap+oy3/ftpdhqHovEeZO /LuqKs1KGnNQ9qGnMqI6VZubcH4r45J7KYwNm8LvQeFHZLai61dmOEZ6olLrdUidydbX 6RQbGj0dRgwqKVM96JLUcQPXAhwzBNJQceEYhQpSh1DXdqc7GPErvK627LgTfxzM/zI5 Wl36QmuUF2cMM8C9WLdBM4vo185c0e08eIDDt13pctxDx01YmuGaSNfJ3iAJSwMgj3ul vmZw== 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=4XqEpVzB6pdIBPKKe3DYeMe1MU19xVZqtRve9/VfUHc=; b=lzDCIFxWzxjQLi8NnFpqIPnWLrKJ7OXFNMkiTTMtalcEXoXRrBW2zl3cUDxo1h1VHS +pIQuwUt3icSEdcdfG/vRmzZnR26PtJs96oJZAwAO9ZLeeZ2/EfFjp9hrZBL4uTzJCQM i7TXLpX1tk+XTNxVvNG1vq7KNCqvjVM2vr9QFAhqBzA5Ah+uvkzFmuzAD0Q50o9M7JaI lJM1SaMTGTsTgyXFfNPSF396mPBLiIoeCmveS9+9XTQ1t36257pZgh5lTz7ieH/OANhe uSCaGoOU0SLPweqGEg/QCsb9PrTcxxLcVbnvF55DLgUooBGvN52ecaIWzllPfCCNjTG0 My2A== X-Gm-Message-State: APjAAAURJ1n2qOlYsXhZdtb+B9zpCCoGlps/+IlRd6o1oGGwcsnAZGxm M6oi3vIn/hLWD01Bo41QbBWcSo4= X-Google-Smtp-Source: APXvYqwi7mklIZla9K+l5hI73gwd6F6x57dE08C05vnf2MWJUUVmlGbWL8T0sTOzmFfgV676Oket7Q== X-Received: by 2002:a6b:fb09:: with SMTP id h9mr8636285iog.19.1559075614547; Tue, 28 May 2019 13:33:34 -0700 (PDT) Received: from localhost.localdomain (50-124-247-140.alma.mi.frontiernet.net. [50.124.247.140]) by smtp.gmail.com with ESMTPSA id i141sm53089ite.20.2019.05.28.13.33.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 13:33:33 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: SteveD@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 04/11] Add utilities for resolving nfsd paths and stat()ing them Date: Tue, 28 May 2019 16:31:15 -0400 Message-Id: <20190528203122.11401-5-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190528203122.11401-4-trond.myklebust@hammerspace.com> References: <20190528203122.11401-1-trond.myklebust@hammerspace.com> <20190528203122.11401-2-trond.myklebust@hammerspace.com> <20190528203122.11401-3-trond.myklebust@hammerspace.com> <20190528203122.11401-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 Add helper functions that can resolve nfsd paths by prepending the necessary prefix if the admin has specified a root path in the nfs.conf file. Signed-off-by: Trond Myklebust --- configure.ac | 2 +- support/include/Makefile.am | 2 + support/include/nfsd_path.h | 16 ++++ support/include/xstat.h | 11 +++ support/misc/Makefile.am | 3 +- support/misc/nfsd_path.c | 168 ++++++++++++++++++++++++++++++++++++ support/misc/xstat.c | 33 +++++++ 7 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 support/include/nfsd_path.h create mode 100644 support/include/xstat.h create mode 100644 support/misc/nfsd_path.c create mode 100644 support/misc/xstat.c diff --git a/configure.ac b/configure.ac index c6c2d73b06dd..e870862a8abb 100644 --- a/configure.ac +++ b/configure.ac @@ -321,7 +321,7 @@ AC_CHECK_FUNC([getservbyname], , AC_CHECK_LIB([crypt], [crypt], [LIBCRYPT="-lcrypt"]) AC_CHECK_HEADERS([sched.h], [], []) -AC_CHECK_FUNCS([unshare], [] , []) +AC_CHECK_FUNCS([unshare fstatat], [] , []) AC_LIBPTHREAD([]) if test "$enable_nfsv4" = yes; then diff --git a/support/include/Makefile.am b/support/include/Makefile.am index df5e47836d29..1373891a7c76 100644 --- a/support/include/Makefile.am +++ b/support/include/Makefile.am @@ -10,6 +10,7 @@ noinst_HEADERS = \ misc.h \ nfs_mntent.h \ nfs_paths.h \ + nfsd_path.h \ nfslib.h \ nfsrpc.h \ nls.h \ @@ -24,6 +25,7 @@ noinst_HEADERS = \ xlog.h \ xmalloc.h \ xcommon.h \ + xstat.h \ conffile.h MAINTAINERCLEANFILES = Makefile.in diff --git a/support/include/nfsd_path.h b/support/include/nfsd_path.h new file mode 100644 index 000000000000..db9b41a179ad --- /dev/null +++ b/support/include/nfsd_path.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2019 Trond Myklebust + */ +#ifndef NFSD_PATH_H +#define NFSD_PATH_H + +void nfsd_path_init(void); + +const char * nfsd_path_nfsd_rootdir(void); +char * nfsd_path_strip_root(char *pathname); +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); + +#endif diff --git a/support/include/xstat.h b/support/include/xstat.h new file mode 100644 index 000000000000..f1241bbfdc0e --- /dev/null +++ b/support/include/xstat.h @@ -0,0 +1,11 @@ +/* + * Copyright (C) 2019 Trond Myklebust + */ +#ifndef XSTAT_H +#define XSTAT_H + +struct stat; + +int xlstat(const char *pathname, struct stat *statbuf); +int xstat(const char *pathname, struct stat *statbuf); +#endif diff --git a/support/misc/Makefile.am b/support/misc/Makefile.am index d0bff8feb6ae..f9993e3ac897 100644 --- a/support/misc/Makefile.am +++ b/support/misc/Makefile.am @@ -1,6 +1,7 @@ ## 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 workqueue.c +libmisc_a_SOURCES = tcpwrapper.c from_local.c mountpoint.c file.c \ + nfsd_path.c workqueue.c xstat.c MAINTAINERCLEANFILES = Makefile.in diff --git a/support/misc/nfsd_path.c b/support/misc/nfsd_path.c new file mode 100644 index 000000000000..fe2c011b1521 --- /dev/null +++ b/support/misc/nfsd_path.c @@ -0,0 +1,168 @@ +#include +#include +#include +#include + +#include "config.h" +#include "conffile.h" +#include "xmalloc.h" +#include "xlog.h" +#include "xstat.h" +#include "nfsd_path.h" +#include "workqueue.h" + +static struct xthread_workqueue *nfsd_wq; + +static int +nfsd_path_isslash(const char *path) +{ + return path[0] == '/' && path[1] == '/'; +} + +static int +nfsd_path_isdot(const char *path) +{ + return path[0] == '.' && path[1] == '/'; +} + +static const char * +nfsd_path_strip(const char *path) +{ + if (!path || *path == '\0') + goto out; + for (;;) { + if (nfsd_path_isslash(path)) { + path++; + continue; + } + if (nfsd_path_isdot(path)) { + path += 2; + continue; + } + break; + } +out: + return path; +} + +const char * +nfsd_path_nfsd_rootdir(void) +{ + const char *rootdir; + + rootdir = nfsd_path_strip(conf_get_str("exports", "rootdir")); + if (!rootdir || rootdir[0] == '\0') + return NULL; + if (rootdir[0] == '/' && rootdir[1] == '\0') + return NULL; + return rootdir; +} + +char * +nfsd_path_strip_root(char *pathname) +{ + const char *dir = nfsd_path_nfsd_rootdir(); + char *ret; + + ret = strstr(pathname, dir); + if (!ret || ret != pathname) + return pathname; + return pathname + strlen(dir); +} + +char * +nfsd_path_prepend_dir(const char *dir, const char *pathname) +{ + size_t len, dirlen; + char *ret; + + dirlen = strlen(dir); + while (dirlen > 0 && dir[dirlen - 1] == '/') + dirlen--; + if (!dirlen) + return NULL; + len = dirlen + strlen(pathname) + 1; + ret = xmalloc(len + 1); + snprintf(ret, len, "%.*s/%s", (int)dirlen, dir, pathname); + return ret; +} + +static void +nfsd_setup_workqueue(void) +{ + const char *rootdir = nfsd_path_nfsd_rootdir(); + + if (!rootdir) + return; + nfsd_wq = xthread_workqueue_alloc(); + if (!nfsd_wq) + return; + xthread_workqueue_chroot(nfsd_wq, rootdir); +} + +void +nfsd_path_init(void) +{ + nfsd_setup_workqueue(); +} + +struct nfsd_stat_data { + const char *pathname; + struct stat *statbuf; + int ret; + int err; +}; + +static void +nfsd_statfunc(void *data) +{ + struct nfsd_stat_data *d = data; + + d->ret = xstat(d->pathname, d->statbuf); + if (d->ret < 0) + d->err = errno; +} + +static void +nfsd_lstatfunc(void *data) +{ + struct nfsd_stat_data *d = data; + + d->ret = xlstat(d->pathname, d->statbuf); + if (d->ret < 0) + d->err = errno; +} + +static int +nfsd_run_stat(struct xthread_workqueue *wq, + void (*func)(void *), + const char *pathname, + struct stat *statbuf) +{ + struct nfsd_stat_data data = { + pathname, + statbuf, + 0, + 0 + }; + xthread_work_run_sync(wq, func, &data); + if (data.ret < 0) + errno = data.err; + return data.ret; +} + +int +nfsd_path_stat(const char *pathname, struct stat *statbuf) +{ + if (!nfsd_wq) + return xstat(pathname, statbuf); + return nfsd_run_stat(nfsd_wq, nfsd_statfunc, pathname, statbuf); +} + +int +nfsd_path_lstat(const char *pathname, struct stat *statbuf) +{ + if (!nfsd_wq) + return xlstat(pathname, statbuf); + return nfsd_run_stat(nfsd_wq, nfsd_lstatfunc, pathname, statbuf); +} diff --git a/support/misc/xstat.c b/support/misc/xstat.c new file mode 100644 index 000000000000..d092f73dfd65 --- /dev/null +++ b/support/misc/xstat.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +#include "config.h" +#include "xstat.h" + +#ifdef HAVE_FSTATAT + +int xlstat(const char *pathname, struct stat *statbuf) +{ + return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT | + AT_SYMLINK_NOFOLLOW); +} + +int xstat(const char *pathname, struct stat *statbuf) +{ + return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT); +} + +#else + +int xlstat(const char *pathname, struct stat *statbuf) +{ + return lstat(pathname, statbuf); +} + +int xstat(const char *pathname, struct stat *statbuf) +{ + return stat(pathname, statbuf); +} +#endif From patchwork Tue May 28 20:31:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10965811 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 DBE0715E6 for ; Tue, 28 May 2019 20:33:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF8572866D for ; Tue, 28 May 2019 20:33:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3D3628676; Tue, 28 May 2019 20:33:37 +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 5D84E28741 for ; Tue, 28 May 2019 20:33:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727274AbfE1Udg (ORCPT ); Tue, 28 May 2019 16:33:36 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:54342 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727075AbfE1Udg (ORCPT ); Tue, 28 May 2019 16:33:36 -0400 Received: by mail-it1-f195.google.com with SMTP id h20so6577788itk.4 for ; Tue, 28 May 2019 13:33:36 -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=D3/TxchU2n2gzIYFsg7JMYu+zzAMXglufU3zmYXuRPo=; b=W6Rif6RO7xt43y6PWH7P/ll2Lp2yUXIRb2NfC3F9gc656KzDaCGYJoYnZo3gE6yhPS UzLAQpG+PJmNLTOc6J19QJSJDIJoHSA0vatEG2ORML9xswcPrxasmdcJhrTGnQGaioUU ygCpybsoNc1EjlRlqvyum9dlM0YyPuvThN9Gpop+yGQffSHO43x/t/oVunTc4O2qIHCf kGmTJtlIZi2QFm1bUKUt1nmZugvmUUVbZ40uOO1qdqlV+kaTRHTF+eH3v5ds58XqciEX SBygKHzzndGQq/nKVNwP27Wc/6kimpZiLQ7pJhH/eu1aGT3MI9R9lTtAWJll48pT7Kja yxoQ== 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=D3/TxchU2n2gzIYFsg7JMYu+zzAMXglufU3zmYXuRPo=; b=oGyqAV23nR139CYwKjkFM78/VZieDAY4TybQRryrXLUeVLUmNC1rYVefiNJHg1eBoe 6AB6kJJpD4+hZqWKxVb8igUQQDO7ZJ4bpfH48cY5nnCsk4aX800M1VBNFIAwctZLv0qC Tbu8xkdMAMYEVj40B8L81teR/gDBBPSQwFvuS/dyGglxwdXNBj0JeCaHMTA1plgB5QgY w+G/x9Aw0UUS0yUrGD8gMC5SZHJQsuSUNKWp+6i4ZT8KJH2ZrviPY5OxdbrcFNhHz/EM yNmWjElEmPsbvLhmOfATWgvF62QjeDE0TEBTrZUMoFd+wpgha/aCQ7zW30xcLVKKIuuW eIEQ== X-Gm-Message-State: APjAAAWon41Ng4unnVMD7SKV3wqw2Jw11rqxDGe02+mxNSnKp962axzm RkRA7YWHQKLIz5CtHNNlQF2kX+Y= X-Google-Smtp-Source: APXvYqw3ZphSZBY82lzccLETPo+16wo1huFJ2UjRTE6Y+Mq8C5+aTslHBODOfVSZWG8hRNACFUYM+A== X-Received: by 2002:a05:660c:8a:: with SMTP id t10mr4611146itj.152.1559075615505; Tue, 28 May 2019 13:33:35 -0700 (PDT) Received: from localhost.localdomain (50-124-247-140.alma.mi.frontiernet.net. [50.124.247.140]) by smtp.gmail.com with ESMTPSA id i141sm53089ite.20.2019.05.28.13.33.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 13:33:34 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: SteveD@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 05/11] Use xstat() with no synchronisation if available Date: Tue, 28 May 2019 16:31:16 -0400 Message-Id: <20190528203122.11401-6-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190528203122.11401-5-trond.myklebust@hammerspace.com> References: <20190528203122.11401-1-trond.myklebust@hammerspace.com> <20190528203122.11401-2-trond.myklebust@hammerspace.com> <20190528203122.11401-3-trond.myklebust@hammerspace.com> <20190528203122.11401-4-trond.myklebust@hammerspace.com> <20190528203122.11401-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 We normally expect the exported system to be stable, so don't revalidate attributes. Signed-off-by: Trond Myklebust --- configure.ac | 2 +- support/misc/xstat.c | 72 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index e870862a8abb..50002b4a5677 100644 --- a/configure.ac +++ b/configure.ac @@ -321,7 +321,7 @@ AC_CHECK_FUNC([getservbyname], , AC_CHECK_LIB([crypt], [crypt], [LIBCRYPT="-lcrypt"]) AC_CHECK_HEADERS([sched.h], [], []) -AC_CHECK_FUNCS([unshare fstatat], [] , []) +AC_CHECK_FUNCS([unshare fstatat statx], [] , []) AC_LIBPTHREAD([]) if test "$enable_nfsv4" = yes; then diff --git a/support/misc/xstat.c b/support/misc/xstat.c index d092f73dfd65..fa047880cfd0 100644 --- a/support/misc/xstat.c +++ b/support/misc/xstat.c @@ -1,21 +1,93 @@ +#include #include #include #include +#include #include #include "config.h" #include "xstat.h" #ifdef HAVE_FSTATAT +#ifdef HAVE_STATX + +static void +statx_copy(struct stat *stbuf, const struct statx *stxbuf) +{ + stbuf->st_dev = makedev(stxbuf->stx_dev_major, stxbuf->stx_dev_minor); + stbuf->st_ino = stxbuf->stx_ino; + stbuf->st_mode = stxbuf->stx_mode; + stbuf->st_nlink = stxbuf->stx_nlink; + stbuf->st_uid = stxbuf->stx_uid; + stbuf->st_gid = stxbuf->stx_gid; + stbuf->st_rdev = makedev(stxbuf->stx_rdev_major, stxbuf->stx_rdev_minor); + stbuf->st_size = stxbuf->stx_size; + stbuf->st_blksize = stxbuf->stx_blksize; + stbuf->st_blocks = stxbuf->stx_blocks; + stbuf->st_atim.tv_sec = stxbuf->stx_atime.tv_sec; + stbuf->st_atim.tv_nsec = stxbuf->stx_atime.tv_nsec; + stbuf->st_mtim.tv_sec = stxbuf->stx_mtime.tv_sec; + stbuf->st_mtim.tv_nsec = stxbuf->stx_mtime.tv_nsec; + stbuf->st_ctim.tv_sec = stxbuf->stx_ctime.tv_sec; + stbuf->st_ctim.tv_nsec = stxbuf->stx_ctime.tv_nsec; +} + +static int +statx_do_stat(int fd, const char *pathname, struct stat *statbuf, int flags) +{ + static int statx_supported = 1; + struct statx stxbuf; + int ret; + + if (statx_supported) { + ret = statx(fd, pathname, flags, + STATX_BASIC_STATS, + &stxbuf); + if (ret == 0) { + statx_copy(statbuf, &stxbuf); + return 0; + } + if (errno == ENOSYS) + statx_supported = 0; + } else + errno = ENOSYS; + return -1; +} + +static int +statx_stat_nosync(int fd, const char *pathname, struct stat *statbuf, int flags) +{ + return statx_do_stat(fd, pathname, statbuf, flags | AT_STATX_DONT_SYNC); +} + +#else + +static int +statx_stat_nosync(int fd, const char *pathname, struct stat *statbuf, int flags) +{ + errno = ENOSYS; + return -1; +} + +#endif /* HAVE_STATX */ int xlstat(const char *pathname, struct stat *statbuf) { + if (statx_stat_nosync(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT| + AT_SYMLINK_NOFOLLOW) == 0) + return 0; + else if (errno != ENOSYS) + return -1; return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW); } int xstat(const char *pathname, struct stat *statbuf) { + if (statx_stat_nosync(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT) == 0) + return 0; + else if (errno != ENOSYS) + return -1; return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT); } From patchwork Tue May 28 20:31:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10965813 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 8F1FB933 for ; Tue, 28 May 2019 20:33:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 816DF2866D for ; Tue, 28 May 2019 20:33:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75BA3286A1; Tue, 28 May 2019 20:33:38 +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 14D9B2866D for ; Tue, 28 May 2019 20:33:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727075AbfE1Udh (ORCPT ); Tue, 28 May 2019 16:33:37 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:54344 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727326AbfE1Udh (ORCPT ); Tue, 28 May 2019 16:33:37 -0400 Received: by mail-it1-f196.google.com with SMTP id h20so6577822itk.4 for ; Tue, 28 May 2019 13:33:36 -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=jUmzQXFgosC7ztxN2DEYWeUIGWU2k+scoj1vllYXDW0=; b=O72yHaKNaySnpTiwioQ0RduqpXEgBZH2IZpKKwN3zBY4mLGNO5T5qvzLbajLe7RWe1 esLrI8GhX++oSS77f1AK76k3ig9+zkRlRH49pSUE3o7rEJe7AcQovk/LmpgQSXNorRhr vXGGch7FChamqx2t7U/NUM+finmGbqS7ost8h46y81XaMIJLJcr6qKchDuosb6p27zGT jMsRZPD7DOw5rkpopBPyFEJ1TAHXpyx3k0Nk3V7WsBO1jJLbc82efhxZo5A03tU3/K1o he8Da9jm8fmkfWv/NzZt6jpOVHB0P5RH8jmouBOh/PNPtvK4Qo5dIYAKl7IjF+AwkZte BCng== 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=jUmzQXFgosC7ztxN2DEYWeUIGWU2k+scoj1vllYXDW0=; b=M0m60wkgSDLYQ1JNZHXTXCq1lDPZeYRGoqnfXi4Sc3ILCQVw4sJiC8nk2mOaDak6Tk Bu3mgvSgUkNi39scxGY2pDP0R3rLXjIigvIm8wFtwqD5Tu75pks1Sv2GRMzo2APQkAGK S72atbkcgeipaD+0FEmo8CkjFMeKxgZF5ZtFJP0rmTvuYPHIJRgV50G68QKT4eK6ydTw BiewPT2J8YTyeEAfZSOnnb1JvwCsY3pVlleU1BCHRwzmEomoJtkkaUTsm3y/mY22CuUR +uyfNqPjUO+PgZxh3vdslwA9CfN3rIO+/KDLD2wMEb1ntMomusd+dN6FORLAH/YSwmVB VR2Q== X-Gm-Message-State: APjAAAVKnoaZo9QO7Pft9KLFn6EviHLg1Ykx9fCg5BtsWxrpc82p9wv4 Bqth9tiXBxVhTQQrfinH9UcRvn0= X-Google-Smtp-Source: APXvYqxdRXNnfFqbOwKmGlVo6yIMZmv7FVYDSHDf09v5UmN42cB0isA0h13uHs2ZqXyu2eRTHGxLUA== X-Received: by 2002:a24:2547:: with SMTP id g68mr4534763itg.109.1559075616273; Tue, 28 May 2019 13:33:36 -0700 (PDT) Received: from localhost.localdomain (50-124-247-140.alma.mi.frontiernet.net. [50.124.247.140]) by smtp.gmail.com with ESMTPSA id i141sm53089ite.20.2019.05.28.13.33.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 13:33:35 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust 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 Message-Id: <20190528203122.11401-7-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190528203122.11401-6-trond.myklebust@hammerspace.com> References: <20190528203122.11401-1-trond.myklebust@hammerspace.com> <20190528203122.11401-2-trond.myklebust@hammerspace.com> <20190528203122.11401-3-trond.myklebust@hammerspace.com> <20190528203122.11401-4-trond.myklebust@hammerspace.com> <20190528203122.11401-5-trond.myklebust@hammerspace.com> <20190528203122.11401-6-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 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 --- 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); +} From patchwork Tue May 28 20:31:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10965815 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 4B28A1398 for ; Tue, 28 May 2019 20:33:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D86F2866D for ; Tue, 28 May 2019 20:33:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31DFE286A1; Tue, 28 May 2019 20:33:40 +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 230262866D for ; Tue, 28 May 2019 20:33:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727327AbfE1Udi (ORCPT ); Tue, 28 May 2019 16:33:38 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:32919 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727326AbfE1Udi (ORCPT ); Tue, 28 May 2019 16:33:38 -0400 Received: by mail-io1-f67.google.com with SMTP id u13so8233114iop.0 for ; Tue, 28 May 2019 13:33:37 -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=Dr8LTDNKO45rO36gvIhPaB8D1XPrwcjls5cN6OG5laE=; b=fddSIUaKkpHK5usq50YhQOG0cKr07mx93O0D6bGhfHraewvpsVk+Db1rM/o7q+BI37 dSRtOjZ1RSMcddmV7Ebc/liNEFzEjx5488ArYF0C2fDQinsfTyYFe8QuwR5i2/TpIUD3 CSTHeUwcBSDf5/BNt/+1NLnlViMEAYkW4fbXDgsJuxgpROCMhpMrA1P1N1ziiHBPxAmb b5r9eoy/w4m74PlOM+J+/CJwwRlbtlO4PbpzoUqMDuqQ5OTV/Eu/tKcLWzlylNxju1Gm z706THHpBXXtR3oMvlLMDHyBP4d3roCzk+JBqR/bHg0D6B5HZdoG5WViwNOVDGEj0Ifv DN2A== 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=Dr8LTDNKO45rO36gvIhPaB8D1XPrwcjls5cN6OG5laE=; b=BeagZJZ9QWyXYen1W1U2fI5p+yUfSTOE2BcomqM9Q3eZNAkeNjo5bPrBR4Zk56ZoUq 8aRO8hCBDAl6dQ1HEDYZAE2fvef6tMYwYspKNQm+hhEuivL33SiGMzBVBSiqAAsTi0dU ES99FaX6aBljaaEt9lIl+Scxlsbd+c1vFWvHC4k5WNwaOGWo/DcEmnNmWBEEIbBN7Lyw Xjc23B3mC7jUSJfK3Q5BGjbNP3J1e7Sk4nqKIWHisfrVYsrHB3CpinkAzbX+uSK/KlSD TTc9Ad/V0QGzvAgle4t3pOI8zDGJgMBDoo13ZGRhLPW/09bOtWr8uP896scwl6ffYEjV HKsw== X-Gm-Message-State: APjAAAWtp34UVKs27giB2JwsTaxc+SlbmaDzM0uDul2coJyStExTF1vZ Ll6MWYmh8uHdVgYKPL9fAQ== X-Google-Smtp-Source: APXvYqyW97lSgHOP+axYT7ks4XMVNq/N52Pa2VDEsIxbQ5DcaVwQbOXgY3uvuvZnhgiM2m0SW66veQ== X-Received: by 2002:a5d:80d1:: with SMTP id h17mr22428882ior.58.1559075617002; Tue, 28 May 2019 13:33:37 -0700 (PDT) Received: from localhost.localdomain (50-124-247-140.alma.mi.frontiernet.net. [50.124.247.140]) by smtp.gmail.com with ESMTPSA id i141sm53089ite.20.2019.05.28.13.33.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 13:33:36 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: SteveD@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 07/11] Add a helper to return the real path given an export entry Date: Tue, 28 May 2019 16:31:18 -0400 Message-Id: <20190528203122.11401-8-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190528203122.11401-7-trond.myklebust@hammerspace.com> References: <20190528203122.11401-1-trond.myklebust@hammerspace.com> <20190528203122.11401-2-trond.myklebust@hammerspace.com> <20190528203122.11401-3-trond.myklebust@hammerspace.com> <20190528203122.11401-4-trond.myklebust@hammerspace.com> <20190528203122.11401-5-trond.myklebust@hammerspace.com> <20190528203122.11401-6-trond.myklebust@hammerspace.com> <20190528203122.11401-7-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 helper that can prepend the nfsd root directory path in order to allow mountd to perform its comparisons with mtab etc. Signed-off-by: Trond Myklebust --- support/export/export.c | 24 ++++++++++++++++++++++++ support/include/exportfs.h | 1 + support/include/nfslib.h | 1 + support/misc/nfsd_path.c | 4 +++- support/nfs/exports.c | 4 ++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/support/export/export.c b/support/export/export.c index fbe68e84e5b3..82bbb54c5e9e 100644 --- a/support/export/export.c +++ b/support/export/export.c @@ -20,6 +20,7 @@ #include "xmalloc.h" #include "nfslib.h" #include "exportfs.h" +#include "nfsd_path.h" exp_hash_table exportlist[MCL_MAXTYPES] = {{NULL, {{NULL,NULL}, }}, }; static int export_hash(char *); @@ -30,6 +31,28 @@ static void export_add(nfs_export *exp); static int export_check(const nfs_export *exp, const struct addrinfo *ai, const char *path); +/* Return a real path for the export. */ +static void +exportent_mkrealpath(struct exportent *eep) +{ + const char *chroot = nfsd_path_nfsd_rootdir(); + char *ret = NULL; + + if (chroot) + ret = nfsd_path_prepend_dir(chroot, eep->e_path); + if (!ret) + ret = xstrdup(eep->e_path); + eep->e_realpath = ret; +} + +char * +exportent_realpath(struct exportent *eep) +{ + if (!eep->e_realpath) + exportent_mkrealpath(eep); + return eep->e_realpath; +} + void exportent_release(struct exportent *eep) { @@ -39,6 +62,7 @@ exportent_release(struct exportent *eep) free(eep->e_fslocdata); free(eep->e_uuid); xfree(eep->e_hostname); + xfree(eep->e_realpath); } static void diff --git a/support/include/exportfs.h b/support/include/exportfs.h index 4e0d9d132b4c..daa7e2a06d82 100644 --- a/support/include/exportfs.h +++ b/support/include/exportfs.h @@ -171,5 +171,6 @@ struct export_features { struct export_features *get_export_features(void); void fix_pseudoflavor_flags(struct exportent *ep); +char *exportent_realpath(struct exportent *eep); #endif /* EXPORTFS_H */ diff --git a/support/include/nfslib.h b/support/include/nfslib.h index b09fce42e677..84d8270b330f 100644 --- a/support/include/nfslib.h +++ b/support/include/nfslib.h @@ -84,6 +84,7 @@ struct exportent { char * e_uuid; struct sec_entry e_secinfo[SECFLAVOR_COUNT+1]; unsigned int e_ttl; + char * e_realpath; }; struct rmtabent { diff --git a/support/misc/nfsd_path.c b/support/misc/nfsd_path.c index 55bca9bdf4bd..8ddafd65ab76 100644 --- a/support/misc/nfsd_path.c +++ b/support/misc/nfsd_path.c @@ -81,9 +81,11 @@ nfsd_path_prepend_dir(const char *dir, const char *pathname) dirlen--; if (!dirlen) return NULL; + while (pathname[0] == '/') + pathname++; len = dirlen + strlen(pathname) + 1; ret = xmalloc(len + 1); - snprintf(ret, len, "%.*s/%s", (int)dirlen, dir, pathname); + snprintf(ret, len+1, "%.*s/%s", (int)dirlen, dir, pathname); return ret; } diff --git a/support/nfs/exports.c b/support/nfs/exports.c index 5f4cb9568814..3ecfde797e3b 100644 --- a/support/nfs/exports.c +++ b/support/nfs/exports.c @@ -155,6 +155,7 @@ getexportent(int fromkernel, int fromexports) } xfree(ee.e_hostname); + xfree(ee.e_realpath); ee = def_ee; /* Check for default client */ @@ -358,6 +359,7 @@ dupexportent(struct exportent *dst, struct exportent *src) if (src->e_uuid) dst->e_uuid = strdup(src->e_uuid); dst->e_hostname = NULL; + dst->e_realpath = NULL; } struct exportent * @@ -369,6 +371,8 @@ mkexportent(char *hname, char *path, char *options) xfree(ee.e_hostname); ee.e_hostname = xstrdup(hname); + xfree(ee.e_realpath); + ee.e_realpath = NULL; if (strlen(path) >= sizeof(ee.e_path)) { xlog(L_ERROR, "path name %s too long", path); From patchwork Tue May 28 20:31:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10965819 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 2130A933 for ; Tue, 28 May 2019 20:33:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 138D22866D for ; Tue, 28 May 2019 20:33:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 081A3286A1; Tue, 28 May 2019 20:33:42 +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 4139C28676 for ; Tue, 28 May 2019 20:33:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726619AbfE1Udk (ORCPT ); Tue, 28 May 2019 16:33:40 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:32920 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727326AbfE1Udk (ORCPT ); Tue, 28 May 2019 16:33:40 -0400 Received: by mail-io1-f66.google.com with SMTP id u13so8233179iop.0 for ; Tue, 28 May 2019 13:33:39 -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=dN1Eq3TOZT1HBwM1BI5GuVgNd5bxjRFNIaTzj4gtaoQ=; b=kMYzL4iexvnEQbbnhD+NFUaCJA8H/C39q9yeBwfs7mP1iMgV1ehxqW4Jj5BmGEqEKI DTVLT0vjpA4schixXbwVkn3drAVAyD/vcV6mLRyGPJRQdzwkwDJvrfqv1ZQgmH/EI/rH Gxn0oROb4bhuzBIU4PNFR+k3xq3jfnAdQComETH/vk0Kt+9RsztiPjGJ6QYB1pQmQUAf uc9RMNtcNH0L7LtYNV1sileOp9400TaHu1xSm8PuzmP6vx7XS8KAYoU0BF2Ln6JLvYR2 etXWp7992+EG9S7oYrU94E9imGMrI/gPIK2iasE8MVfxP8pOzZLvd2zKoeYN7Sbsc3oD TXAA== 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=dN1Eq3TOZT1HBwM1BI5GuVgNd5bxjRFNIaTzj4gtaoQ=; b=G62aNhlOnLqhgcb91TGvT2si3gntOkrhO7CgniZSxQiE3BJxMPgH9LQxv4JYcb7NJk V/EYsl2fDq5aablQDUJwuAmG7X3ptebFiExJwL1ggQR7v2D4PoucbUFzuj5MSK4NZX2J AmncwyvTnVQYI8fRrANc4asuAaWf2VVcSYFRlWQCD5zPXe1SwKToO8qJi2AJyxM6tg4L OzsIFgeQZWPsFyy8Pi07VxGahbUh+Em1UPxCe1a8tN0lI9ZooiotXSM0Mx1D9eC8UK7u N7MRxEvvVMm6FdjS6Y1OldlNT7iXgJJQ/6z9++XKE7VN7cT1pvqz2WBtktjYhBl1ol+f RAUg== X-Gm-Message-State: APjAAAXTyndm9rg1f2TxSODSniryYEjuY+srQKTpoeeoI9lDtDMBlxK4 BPwSJBp+kN0eOuxgJwLOZzFsYKc= X-Google-Smtp-Source: APXvYqzqODSuDxHNK8X9uxFvUeXd9hAI/CX/HCHN9Bj8lcQFNroPI35GdEwB3eT0NNiXVfBtvu8fYQ== X-Received: by 2002:a6b:6e07:: with SMTP id d7mr49571757ioh.88.1559075618658; Tue, 28 May 2019 13:33:38 -0700 (PDT) Received: from localhost.localdomain (50-124-247-140.alma.mi.frontiernet.net. [50.124.247.140]) by smtp.gmail.com with ESMTPSA id i141sm53089ite.20.2019.05.28.13.33.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 13:33:38 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: SteveD@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 08/11] Add support for the "[exports] rootdir" nfs.conf option to rpc.mountd Date: Tue, 28 May 2019 16:31:19 -0400 Message-Id: <20190528203122.11401-9-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190528203122.11401-8-trond.myklebust@hammerspace.com> References: <20190528203122.11401-1-trond.myklebust@hammerspace.com> <20190528203122.11401-2-trond.myklebust@hammerspace.com> <20190528203122.11401-3-trond.myklebust@hammerspace.com> <20190528203122.11401-4-trond.myklebust@hammerspace.com> <20190528203122.11401-5-trond.myklebust@hammerspace.com> <20190528203122.11401-6-trond.myklebust@hammerspace.com> <20190528203122.11401-7-trond.myklebust@hammerspace.com> <20190528203122.11401-8-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 Ensure that I/O to those pseudo files that resolve filehandles and exports go through the chrooted threads, so that we can use paths that are relative to the nfsd root directory. Ensure that any stat() or lstat() calls go through their nfsd_path_* equivalent so that they too can be resolved correctly. Signed-off-by: Trond Myklebust --- nfs.conf | 3 +++ systemd/nfs.conf.man | 20 +++++++++++++- utils/mountd/cache.c | 63 ++++++++++++++++++++++++++++--------------- utils/mountd/mountd.c | 13 +++++---- 4 files changed, 71 insertions(+), 28 deletions(-) diff --git a/nfs.conf b/nfs.conf index 27e962c8a2a9..85097fd197c0 100644 --- a/nfs.conf +++ b/nfs.conf @@ -5,6 +5,9 @@ [general] # pipefs-directory=/var/lib/nfs/rpc_pipefs # +[exports] +# rootdir=/export +# [exportfs] # debug=0 # diff --git a/systemd/nfs.conf.man b/systemd/nfs.conf.man index e3654a3c2c2b..d375bcc1d5a7 100644 --- a/systemd/nfs.conf.man +++ b/systemd/nfs.conf.man @@ -107,6 +107,24 @@ and .BR rpc.gssd (8) for details. +.TP +.B exports +Recognized values: +.BR rootdir . + +Setting +.B rootdir +to a valid path causes the nfs server to act as if the +supplied path is being prefixed to all the exported entries. For +instance, if +.BR rootdir=/my/root , +and there is an entry in /etc/exports for +.BR /filesystem , +then the client will be able to mount the path as +.BR /filesystem , +but on the server, this will resolve to the path +.BR /my/root/filesystem . + .TP .B nfsdcltrack Recognized values: @@ -136,7 +154,7 @@ Recognized values: .BR vers4.0 , .BR vers4.1 , .BR vers4.2 , -.BR rdma . +.BR rdma , 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..d818c971bded 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -27,6 +27,7 @@ #include #include #include "misc.h" +#include "nfsd_path.h" #include "nfslib.h" #include "exportfs.h" #include "mountd.h" @@ -55,6 +56,22 @@ enum nfsd_fsid { FSID_UUID16_INUM, }; +#undef is_mountpoint +static int is_mountpoint(char *path) +{ + return check_is_mountpoint(path, nfsd_path_lstat); +} + +static ssize_t cache_read(int fd, char *buf, size_t len) +{ + return nfsd_path_read(fd, buf, len); +} + +static ssize_t cache_write(int fd, const char *buf, size_t len) +{ + return nfsd_path_write(fd, buf, len); +} + /* * Support routines for text-based upcalls. * Fields are separated by spaces. @@ -221,7 +238,7 @@ static const char *get_uuid_blkdev(char *path) if (cache == NULL) blkid_get_cache(&cache, NULL); - if (stat(path, &stb) != 0) + if (nfsd_path_stat(path, &stb) != 0) return NULL; devname = blkid_devno_to_devname(stb.st_dev); if (!devname) @@ -373,21 +390,22 @@ static char *next_mnt(void **v, char *p) FILE *f; struct mntent *me; size_t l = strlen(p); + char *mnt_dir = NULL; + if (*v == NULL) { f = setmntent("/etc/mtab", "r"); *v = f; } else f = *v; - while ((me = getmntent(f)) != NULL && l > 1 && - (strncmp(me->mnt_dir, p, l) != 0 || - me->mnt_dir[l] != '/')) - ; - if (me == NULL) { - endmntent(f); - *v = NULL; - return NULL; + while ((me = getmntent(f)) != NULL && l > 1) { + mnt_dir = nfsd_path_strip_root(me->mnt_dir); + + if (strncmp(mnt_dir, p, l) == 0 && mnt_dir[l] != '/') + return mnt_dir; } - return me->mnt_dir; + endmntent(f); + *v = NULL; + return NULL; } /* same_path() check is two paths refer to the same directory. @@ -458,9 +476,9 @@ fallback: * bind-mounted in two places and both are exported, it * could give a false positive */ - if (lstat(p, &sc) != 0) + if (nfsd_path_lstat(p, &sc) != 0) return 0; - if (lstat(parent, &sp) != 0) + if (nfsd_path_lstat(parent, &sp) != 0) return 0; if (sc.st_dev != sp.st_dev) return 0; @@ -610,7 +628,7 @@ static bool match_fsid(struct parsed_fsid *parsed, nfs_export *exp, char *path) int type; char u[16]; - if (stat(path, &stb) != 0) + if (nfsd_path_stat(path, &stb) != 0) return false; if (!S_ISDIR(stb.st_mode) && !S_ISREG(stb.st_mode)) return false; @@ -692,7 +710,7 @@ static void nfsd_fh(int f) char buf[RPC_CHAN_BUF_SIZE], *bp; int blen; - blen = read(f, buf, sizeof(buf)); + blen = cache_read(f, buf, sizeof(buf)); if (blen <= 0 || buf[blen-1] != '\n') return; buf[blen-1] = 0; @@ -829,7 +847,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 +939,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; } @@ -1298,7 +1316,7 @@ static void nfsd_export(int f) char buf[RPC_CHAN_BUF_SIZE], *bp; int blen; - blen = read(f, buf, sizeof(buf)); + blen = cache_read(f, buf, sizeof(buf)); if (blen <= 0 || buf[blen-1] != '\n') return; buf[blen-1] = 0; @@ -1381,6 +1399,7 @@ extern int manage_gids; void cache_open(void) { int i; + for (i=0; cachelist[i].cache_name; i++ ) { char path[100]; if (!manage_gids && cachelist[i].cache_handle == auth_unix_gid) @@ -1456,7 +1475,7 @@ static int cache_export_ent(char *buf, int buflen, char *domain, struct exporten if (strlen(path) <= l || path[l] != '/' || strncmp(exp->e_path, path, l) != 0) break; - if (stat(exp->e_path, &stb) != 0) + if (nfsd_path_stat(exp->e_path, &stb) != 0) break; dev = stb.st_dev; while(path[l] == '/') { @@ -1469,7 +1488,7 @@ static int cache_export_ent(char *buf, int buflen, char *domain, struct exporten l++; c = path[l]; path[l] = 0; - err2 = lstat(path, &stb); + err2 = nfsd_path_lstat(path, &stb); path[l] = c; if (err2 < 0) break; @@ -1508,7 +1527,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,12 +1565,12 @@ 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; } bp = buf; - blen = read(f, buf, sizeof(buf)); + blen = cache_read(f, buf, sizeof(buf)); close(f); if (blen <= 0 || buf[blen-1] != '\n') diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c index 88a207b3a85a..f062cac28be4 100644 --- a/utils/mountd/mountd.c +++ b/utils/mountd/mountd.c @@ -29,6 +29,7 @@ #include "mountd.h" #include "rpcmisc.h" #include "pseudoflavors.h" +#include "nfsd_path.h" #include "nfslib.h" extern void my_svc_run(void); @@ -374,7 +375,7 @@ mount_pathconf_2_svc(struct svc_req *rqstp, dirpath *path, ppathcnf *res) exp = auth_authenticate("pathconf", sap, p); if (exp == NULL) return 1; - else if (stat(p, &stb) < 0) { + else if (nfsd_path_stat(p, &stb) < 0) { xlog(L_WARNING, "can't stat exported dir %s: %s", p, strerror(errno)); return 1; @@ -483,7 +484,7 @@ get_rootfh(struct svc_req *rqstp, dirpath *path, nfs_export **expret, *error = MNT3ERR_ACCES; return NULL; } - if (stat(p, &stb) < 0) { + if (nfsd_path_stat(p, &stb) < 0) { xlog(L_WARNING, "can't stat exported dir %s: %s", p, strerror(errno)); if (errno == ENOENT) @@ -497,7 +498,7 @@ get_rootfh(struct svc_req *rqstp, dirpath *path, nfs_export **expret, *error = MNT3ERR_NOTDIR; return NULL; } - if (stat(exp->m_export.e_path, &estb) < 0) { + if (nfsd_path_stat(exp->m_export.e_path, &estb) < 0) { xlog(L_WARNING, "can't stat export point %s: %s", p, strerror(errno)); *error = MNT3ERR_NOENT; @@ -511,9 +512,10 @@ get_rootfh(struct svc_req *rqstp, dirpath *path, nfs_export **expret, return NULL; } if (exp->m_export.e_mountpoint && - !is_mountpoint(exp->m_export.e_mountpoint[0]? + !check_is_mountpoint(exp->m_export.e_mountpoint[0]? exp->m_export.e_mountpoint: - exp->m_export.e_path)) { + exp->m_export.e_path, + nfsd_path_lstat)) { xlog(L_WARNING, "request to export an unmounted filesystem: %s", p); *error = MNT3ERR_NOENT; @@ -886,6 +888,7 @@ main(int argc, char **argv) if (num_threads > 1) fork_workers(); + nfsd_path_init(); /* Open files now to avoid sharing descriptors among forked processes */ cache_open(); From patchwork Tue May 28 20:31:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10965817 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 8A2111398 for ; Tue, 28 May 2019 20:33:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D6942866D for ; Tue, 28 May 2019 20:33:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 722BD286FF; Tue, 28 May 2019 20:33:41 +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 103F02866D for ; Tue, 28 May 2019 20:33:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727406AbfE1Udk (ORCPT ); Tue, 28 May 2019 16:33:40 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:35818 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbfE1Udk (ORCPT ); Tue, 28 May 2019 16:33:40 -0400 Received: by mail-io1-f65.google.com with SMTP id p2so16942890iol.2 for ; Tue, 28 May 2019 13:33:40 -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=xBJi060n7RhVnSN6xyn5hT8UN0dOckFbLFyVF4AWmVI=; b=OFb+fG9ZVNketjNbWCXfMiTe0vlRtnHMVw0Fp4GpSxAPKqwzcW1ACe38I4qk9uJF4Y HnVIoE+iG03OJBbGR/PQtWKUC7hb3HIw3GXNx5J14jHerfbMC18+i5vUyz+iHiqxLSRE R8AM+AXDzEfCepzkWrcM0R234odckrM4L0PplVoRp+N5Z2k44hwCuZw788Mf7DEqrQd+ QafSffyIv9a4KQsd03QcxRFUkRkf69c+JukUl2g8lpwo9qqVPYxV5o5cx04LrylPXbFy JV2UPiuDmVlUxPTKYPHEoicyimZgDIMJSJRzCmbXfuKpXWBcvzyWlaLYvwKASWDeoWTQ 03Gw== 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=xBJi060n7RhVnSN6xyn5hT8UN0dOckFbLFyVF4AWmVI=; b=rO6+lLnc9Vmj5mqz7d9ghQqPDEUxS6fsw8cV0ehEM6xTjqzsNogBPj712JJE+c1nyr 0XJSRKSHD9zJTxd4JI2CrCpqhG6yVayBv6AeNn7CBjpnUpmjlqoyQVSvCKgYMthzUce7 MyyKGIoTRVe3x/ykaTeMuC2C+5lngM68iVWvQfMQHDTtXobBUmNYCEL8a9Z08QakdttE PBoCsQMTdP06BiRILyax27TYTDopzs6TmBBb7wpk4+zNYE1sItdFzwH5yS+hKO+FGmpp b2+2OPOU9Iusf7m3Epyy72fhFKilOsNOkLMat8+Wr2qlSy1qObd6uhYuisOcW0opRu+O b2Xw== X-Gm-Message-State: APjAAAXSCQQwU4bhW+ybivcpnGxB4RodDz94opW/n8cGy2cFJDo8QOPO fFKsl7778VwicKdmNM3lHg== X-Google-Smtp-Source: APXvYqz2boZ6yRYqFHtGQC2H1n5wmnqDKsFN/f/giY90ILNYg/23CvvQypqGi1Tlj8nyicoaW8MRqw== X-Received: by 2002:a5d:8783:: with SMTP id f3mr52298990ion.235.1559075619337; Tue, 28 May 2019 13:33:39 -0700 (PDT) Received: from localhost.localdomain (50-124-247-140.alma.mi.frontiernet.net. [50.124.247.140]) by smtp.gmail.com with ESMTPSA id i141sm53089ite.20.2019.05.28.13.33.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 13:33:38 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: SteveD@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 09/11] Add support for the "[exports] rootdir" nfs.conf option to exportfs Date: Tue, 28 May 2019 16:31:20 -0400 Message-Id: <20190528203122.11401-10-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190528203122.11401-9-trond.myklebust@hammerspace.com> References: <20190528203122.11401-1-trond.myklebust@hammerspace.com> <20190528203122.11401-2-trond.myklebust@hammerspace.com> <20190528203122.11401-3-trond.myklebust@hammerspace.com> <20190528203122.11401-4-trond.myklebust@hammerspace.com> <20190528203122.11401-5-trond.myklebust@hammerspace.com> <20190528203122.11401-6-trond.myklebust@hammerspace.com> <20190528203122.11401-7-trond.myklebust@hammerspace.com> <20190528203122.11401-8-trond.myklebust@hammerspace.com> <20190528203122.11401-9-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 Ensure that exportfs also resolves paths relative to the nfsd root directory Signed-off-by: Trond Myklebust --- utils/exportfs/Makefile.am | 2 +- utils/exportfs/exportfs.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 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..5cca4175e73a 100644 --- a/utils/exportfs/exportfs.c +++ b/utils/exportfs/exportfs.c @@ -33,6 +33,7 @@ #include "sockaddr.h" #include "misc.h" +#include "nfsd_path.h" #include "nfslib.h" #include "exportfs.h" #include "xlog.h" @@ -53,6 +54,11 @@ static int _lockfd = -1; struct state_paths etab; +static ssize_t exportfs_write(int fd, const char *buf, size_t len) +{ + return nfsd_path_write(fd, buf, len); +} + /* * If we aren't careful, changes made by exportfs can be lost * when multiple exports process run at once: @@ -109,6 +115,7 @@ main(int argc, char **argv) conf_init_file(NFS_CONFFILE); xlog_from_conffile("exportfs"); + nfsd_path_init(); /* NOTE: following uses "mountd" section of nfs.conf !!!! */ s = conf_get_str("mountd", "state-directory-path"); @@ -505,7 +512,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; @@ -521,7 +528,7 @@ validate_export(nfs_export *exp) * otherwise trial-export to '-test-client-' and check for failure. */ struct stat stb; - char *path = exp->m_export.e_path; + char *path = exportent_realpath(&exp->m_export); struct statfs64 stf; int fs_has_fsid = 0; From patchwork Tue May 28 20:31:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10965821 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 969E515E6 for ; Tue, 28 May 2019 20:33:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 893E42866D for ; Tue, 28 May 2019 20:33:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DB7D286A1; Tue, 28 May 2019 20:33:42 +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 24B7A28676 for ; Tue, 28 May 2019 20:33:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727326AbfE1Udl (ORCPT ); Tue, 28 May 2019 16:33:41 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:38942 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727529AbfE1Udl (ORCPT ); Tue, 28 May 2019 16:33:41 -0400 Received: by mail-it1-f195.google.com with SMTP id 9so6136667itf.4 for ; Tue, 28 May 2019 13:33:40 -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=643A/JXkc2fq/8damgxL6JCgtP0wyB1q+dhVeiGdlgE=; b=WwrrXhpHWqnxdeAFcjg7vGnP89MgU8IsU7sQJG2xDzEZtpc8v/FojypESYP+Oeu+W/ 4jAOAyNXDymL/WkkwjBMMrU5o4S5d+JUbFRe+QWz8/vXQiCUOddkrzh2nTXzP8/EpLyO 5bzexbhfmG1++svvXJXebARMmEI17VcRlYgw1S1yUSLt35cFT5d5Hw9ptjFLkMQj3EN2 n5WNdEymN0Vk+qNr2WCohubBh5tnvcRlT2FtoPxPfL4ah4Y9PjIk34bicDC36H1+yUwH SfKFma14iQmQIEMp0px5fnKVa+mirjnuAWtJpFScAUo5A58qu57J31DlL6yb2CaMgx7n +zug== 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=643A/JXkc2fq/8damgxL6JCgtP0wyB1q+dhVeiGdlgE=; b=KIEAY5aJ0TCVaHJ65vUsm/PRlSb3WBFZKXIuAgcVmDK/nX4S0Bkvp5VmaHDnX0SDX5 pjS2y4rslTy3FJmi0lFhQvwfDGw5rtA2Eiik/sIHVmpz77r/aK08op6U1ICZryxcxZqC dvZaXTHTnkfeNYqfmLK+aaFMeE2bligYHKKMCZhkgkWO/1ln4QVOKHuOCGi43sNZp7y+ MfbBXOiWvTgdZt10/Ntz8hPoLkxMZgPGc8tW4snDO/HkZ2mSjuR+pGlnp3JMBOVHxfj2 wHGDkM7qn8UmbYpmzb5kciP8/A8CV9NKF4m4idP2We4P1giKVNnIb1EReDTjELeJ02gL YJ2g== X-Gm-Message-State: APjAAAUYVOj20+9zUXaDWYMXXFanV1NB1v+YTRn8+Po3P04nLhBL605a gJBujNeCCVnKHg6f5gFGB4/MXec= X-Google-Smtp-Source: APXvYqxwtR2z0OP7qO0aTCWT3Z32GQXLlvUDzAR2tuo2kWTAVtSDfM6bxFhTcvbHNRDOu0v5E3iOng== X-Received: by 2002:a05:660c:6c1:: with SMTP id z1mr5057526itk.126.1559075620105; Tue, 28 May 2019 13:33:40 -0700 (PDT) Received: from localhost.localdomain (50-124-247-140.alma.mi.frontiernet.net. [50.124.247.140]) by smtp.gmail.com with ESMTPSA id i141sm53089ite.20.2019.05.28.13.33.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 13:33:39 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: SteveD@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 10/11] Add a helper for resolving symlinked nfsd paths via realpath() Date: Tue, 28 May 2019 16:31:21 -0400 Message-Id: <20190528203122.11401-11-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190528203122.11401-10-trond.myklebust@hammerspace.com> References: <20190528203122.11401-1-trond.myklebust@hammerspace.com> <20190528203122.11401-2-trond.myklebust@hammerspace.com> <20190528203122.11401-3-trond.myklebust@hammerspace.com> <20190528203122.11401-4-trond.myklebust@hammerspace.com> <20190528203122.11401-5-trond.myklebust@hammerspace.com> <20190528203122.11401-6-trond.myklebust@hammerspace.com> <20190528203122.11401-7-trond.myklebust@hammerspace.com> <20190528203122.11401-8-trond.myklebust@hammerspace.com> <20190528203122.11401-9-trond.myklebust@hammerspace.com> <20190528203122.11401-10-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 helper to resolve symlinked nfsd paths when the user has set the "[exports] rootdir" nfs.conf option. Signed-off-by: Trond Myklebust --- support/include/nfsd_path.h | 2 ++ support/misc/nfsd_path.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/support/include/nfsd_path.h b/support/include/nfsd_path.h index f4a7f0a4337f..ca2570a92e68 100644 --- a/support/include/nfsd_path.h +++ b/support/include/nfsd_path.h @@ -13,6 +13,8 @@ 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); +char * nfsd_realpath(const char *path, char *resolved_path); + 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); diff --git a/support/misc/nfsd_path.c b/support/misc/nfsd_path.c index 8ddafd65ab76..2f41a793c534 100644 --- a/support/misc/nfsd_path.c +++ b/support/misc/nfsd_path.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "config.h" @@ -169,6 +170,40 @@ nfsd_path_lstat(const char *pathname, struct stat *statbuf) return nfsd_run_stat(nfsd_wq, nfsd_lstatfunc, pathname, statbuf); } +struct nfsd_realpath_data { + const char *pathname; + char *resolved; + int err; +}; + +static void +nfsd_realpathfunc(void *data) +{ + struct nfsd_realpath_data *d = data; + + d->resolved = realpath(d->pathname, d->resolved); + if (!d->resolved) + d->err = errno; +} + +char * +nfsd_realpath(const char *path, char *resolved_path) +{ + struct nfsd_realpath_data data = { + path, + resolved_path, + 0 + }; + + if (!nfsd_wq) + return realpath(path, resolved_path); + + xthread_work_run_sync(nfsd_wq, nfsd_realpathfunc, &data); + if (!data.resolved) + errno = data.err; + return data.resolved; +} + struct nfsd_read_data { int fd; char *buf; From patchwork Tue May 28 20:31:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10965823 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 09DF8933 for ; Tue, 28 May 2019 20:33:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F08122866D for ; Tue, 28 May 2019 20:33:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E505528676; Tue, 28 May 2019 20:33:42 +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 98127286FF for ; Tue, 28 May 2019 20:33:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727529AbfE1Udm (ORCPT ); Tue, 28 May 2019 16:33:42 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:54348 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727532AbfE1Udl (ORCPT ); Tue, 28 May 2019 16:33:41 -0400 Received: by mail-it1-f194.google.com with SMTP id h20so6578105itk.4 for ; Tue, 28 May 2019 13:33:41 -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=Y/jOtEZptS2HutHiuHWWaXrtl1adLnn5zu2gxhvRHbc=; b=UP92vuAsjrwP1Ze2QJ/WWRRGV54b13RYUXblvLcm44HeIIRj4ffegqnnn98Toaveae 07H88pyV87xlp6GOGZrlDEdbug7/1bNPQ2OJhT6KaEkQvUQjWfeXaYTg66Su4YFASCiU 1fzh80+5XyHsCi3/NL1SROpytUEZ3Cj2Bw8ydn27vsQ2kWBOFJHHXNhXfzed9jbJZfsn hw4Vjh1QqE6kLZsIxivXZXp8+3RvERT+AQP6k8vsKszHtqMkZ6ISVaf4B6b9ubHFbxRB E1qLvZpjOpzuyIGYkderzuORR/lvyf5eW902z4+MQ602Y/wNJys+cKf59yM6lg/6v0cq hrzA== 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=Y/jOtEZptS2HutHiuHWWaXrtl1adLnn5zu2gxhvRHbc=; b=Ao2P+74SvUoUXH7rdWhwR5IVwIVOpXqzI94x5mdFW5j+xVTIkmBk5HBW9RZHFinZ+G /BBiO3Guse45Sm9G/m6vqmUa7azqv7K0W/VMbddsUIbOYCnw2OUReyfh/rxqj6NO4a4b 4CgHv1ovScyhpw+/B+6lnxRJ/hLG2pORn7bHAlZzvw2TpCioAKDrqc8jCwTF55AlNhK3 Hf9xftEc0qhbQA34AUgypOuWljVEcjT03gODdJuyf1K2KItK609sKCeR9fGwQNgeKPd+ B6oYl5WuxRZ/C3Os7bB772eVO5cZ7ug4P33eOgptMwheLExQXDswu9f7M87RJBpNIsFd AjWQ== X-Gm-Message-State: APjAAAX6qeLoZVcw3s18TjQwh5I8rbGL0AZqJlDaEwQb+wXz5AjycwWE eo9Jw21p8P2TXzATjAHSe15v5j4= X-Google-Smtp-Source: APXvYqxpPnn6D1aFZRpIGdr8jQTLgFBwrKlZb8Ojj5Xcsd46tsttpo7rt9jO8Fck0WAF6veDjuoFVg== X-Received: by 2002:a02:9143:: with SMTP id b3mr2002667jag.12.1559075620732; Tue, 28 May 2019 13:33:40 -0700 (PDT) Received: from localhost.localdomain (50-124-247-140.alma.mi.frontiernet.net. [50.124.247.140]) by smtp.gmail.com with ESMTPSA id i141sm53089ite.20.2019.05.28.13.33.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 May 2019 13:33:40 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: SteveD@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 11/11] Fix up symlinked mount path resolution when "[exports] rootdir" is set Date: Tue, 28 May 2019 16:31:22 -0400 Message-Id: <20190528203122.11401-12-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190528203122.11401-11-trond.myklebust@hammerspace.com> References: <20190528203122.11401-1-trond.myklebust@hammerspace.com> <20190528203122.11401-2-trond.myklebust@hammerspace.com> <20190528203122.11401-3-trond.myklebust@hammerspace.com> <20190528203122.11401-4-trond.myklebust@hammerspace.com> <20190528203122.11401-5-trond.myklebust@hammerspace.com> <20190528203122.11401-6-trond.myklebust@hammerspace.com> <20190528203122.11401-7-trond.myklebust@hammerspace.com> <20190528203122.11401-8-trond.myklebust@hammerspace.com> <20190528203122.11401-9-trond.myklebust@hammerspace.com> <20190528203122.11401-10-trond.myklebust@hammerspace.com> <20190528203122.11401-11-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/mountd/mountd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c index f062cac28be4..33571ecbd401 100644 --- a/utils/mountd/mountd.c +++ b/utils/mountd/mountd.c @@ -272,7 +272,7 @@ mount_umnt_1_svc(struct svc_req *rqstp, dirpath *argp, void *UNUSED(resp)) if (*p == '\0') p = "/"; - if (realpath(p, rpath) != NULL) { + if (nfsd_realpath(p, rpath) != NULL) { rpath[sizeof (rpath) - 1] = '\0'; p = rpath; } @@ -363,7 +363,7 @@ mount_pathconf_2_svc(struct svc_req *rqstp, dirpath *path, ppathcnf *res) auth_reload(); /* Resolve symlinks */ - if (realpath(p, rpath) != NULL) { + if (nfsd_realpath(p, rpath) != NULL) { rpath[sizeof (rpath) - 1] = '\0'; p = rpath; } @@ -473,7 +473,7 @@ get_rootfh(struct svc_req *rqstp, dirpath *path, nfs_export **expret, auth_reload(); /* Resolve symlinks */ - if (realpath(p, rpath) != NULL) { + if (nfsd_realpath(p, rpath) != NULL) { rpath[sizeof (rpath) - 1] = '\0'; p = rpath; }