From patchwork Tue Apr 16 11:17:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Kinsbursky X-Patchwork-Id: 2449081 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 014783FD40 for ; Tue, 16 Apr 2013 11:16:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753353Ab3DPLQa (ORCPT ); Tue, 16 Apr 2013 07:16:30 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:28606 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753823Ab3DPLQ3 (ORCPT ); Tue, 16 Apr 2013 07:16:29 -0400 Received: from localhost.localdomain ([10.30.16.179]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id r3GBG5O6027616; Tue, 16 Apr 2013 15:16:05 +0400 (MSK) Subject: [PATCH] nfsd: enable UMH client tracker in container To: bfields@fieldses.org From: Stanislav Kinsbursky Cc: linux-nfs@vger.kernel.org, devel@openvz.org, Trond.Myklebust@netapp.com, linux-kernel@vger.kernel.org, jlayton@redhat.com Date: Tue, 16 Apr 2013 15:17:44 +0400 Message-ID: <20130416111344.14621.56912.stgit@localhost.localdomain> User-Agent: StGit/0.16 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This patch adds support for UserModeHelper tracker in a container. The reason for this is that the only containerised tracker ("nfsdcld") is going to be removed in 3.10 kernel, thus at least one more tracker have to be containerised to replace the deprecated one. UMH tracker looks more preferable comparing to legacy since it's the latest one. To make UMH tracker work in a container, we have to make sure, that it executes right binary (i.e., this binary have to be taken from the container environment). But, UMH is a kernel thread, which works in global root environment by design (kernel thread's root is inherited from kthreadd, which in turn inherited it's root from global init). So, the root have to be swapped to the container's one before binary execution. This patch passes "init" callback and private "data" to UMH interface, which are used to swap root for spawned kernel thread. Note: container's root can be stored on stack, because UMH calls are synchronous. Signed-off-by: Stanislav Kinsbursky --- fs/nfsd/nfs4recover.c | 29 ++++++++++++++++++++++------- 1 files changed, 22 insertions(+), 7 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c index 899ca26..15f8de6 100644 --- a/fs/nfsd/nfs4recover.c +++ b/fs/nfsd/nfs4recover.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -1122,12 +1123,28 @@ nfsd4_cltrack_legacy_recdir(const struct xdr_netobj *name) return result; } +static int nfsd_swap_root(struct subprocess_info *info, struct cred *new) +{ + struct path *root = info->data; + struct fs_struct *fs = current->fs; + struct path current_root; + + spin_lock(&fs->lock); + current_root = fs->root; + fs->root = *root; + spin_unlock(&fs->lock); + if (current_root.dentry) + path_put(¤t_root); + return 0; +} + static int nfsd4_umh_cltrack_upcall(char *cmd, char *arg, char *legacy) { char *envp[2]; char *argv[4]; int ret; + struct path root; if (unlikely(!cltrack_prog[0])) { dprintk("%s: cltrack_prog is disabled\n", __func__); @@ -1146,7 +1163,11 @@ nfsd4_umh_cltrack_upcall(char *cmd, char *arg, char *legacy) argv[2] = arg; argv[3] = NULL; - ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC); + get_fs_root(current->fs, &root); + + ret = call_usermodehelper_fns(argv[0], argv, envp, UMH_WAIT_PROC, + nfsd_swap_root, NULL, &root); + /* * Disable the upcall mechanism if we're getting an ENOENT or EACCES * error. The admin can re-enable it on the fly by using sysfs @@ -1185,12 +1206,6 @@ bin_to_hex_dup(const unsigned char *src, int srclen) static int nfsd4_umh_cltrack_init(struct net __attribute__((unused)) *net) { - /* XXX: The usermode helper s not working in container yet. */ - if (net != &init_net) { - WARN(1, KERN_ERR "NFSD: attempt to initialize umh client " - "tracking in a container!\n"); - return -EINVAL; - } return nfsd4_umh_cltrack_upcall("init", NULL, NULL); }