From patchwork Thu Dec 6 15:34:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Kinsbursky X-Patchwork-Id: 1845321 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id EE411DF2F9 for ; Thu, 6 Dec 2012 15:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423589Ab2LFPeO (ORCPT ); Thu, 6 Dec 2012 10:34:14 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:17599 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965164Ab2LFPeN (ORCPT ); Thu, 6 Dec 2012 10:34:13 -0500 Received: from localhost.localdomain ([10.30.21.131]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id qB6FY7Gp012988; Thu, 6 Dec 2012 19:34:07 +0400 (MSK) Subject: [PATCH 2/6] nfsd: swap fs root in NFSd kthreads To: bfields@fieldses.org From: Stanislav Kinsbursky Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, devel@openvz.org Date: Thu, 06 Dec 2012 18:34:47 +0300 Message-ID: <20121206153447.30693.54128.stgit@localhost.localdomain> In-Reply-To: <20121206153204.30693.11408.stgit@localhost.localdomain> References: <20121206153204.30693.11408.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 NFSd does lookup. Lookup is done starting from current->fs->root. NFSd is a kthread, cloned by kthreadd, and thus have global (but luckely unshared) root. So we have to swap root to those, which process, started NFSd, has. Because that process can be in a container with it's own root. Signed-off-by: Stanislav Kinsbursky --- fs/nfsd/netns.h | 1 + fs/nfsd/nfssvc.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 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/netns.h b/fs/nfsd/netns.h index abfc97c..5c423c6 100644 --- a/fs/nfsd/netns.h +++ b/fs/nfsd/netns.h @@ -101,6 +101,7 @@ struct nfsd_net { struct timeval nfssvc_boot; struct svc_serv *nfsd_serv; + struct path root; }; extern int nfsd_net_id; diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index cee62ab..177bb60 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c @@ -392,6 +392,7 @@ int nfsd_create_serv(struct net *net) set_max_drc(); do_gettimeofday(&nn->nfssvc_boot); /* record boot time */ + get_fs_root(current->fs, &nn->root); return 0; } @@ -426,8 +427,10 @@ void nfsd_destroy(struct net *net) if (destroy) svc_shutdown_net(nn->nfsd_serv, net); svc_destroy(nn->nfsd_serv); - if (destroy) + if (destroy) { + path_put(&nn->root); nn->nfsd_serv = NULL; + } } int nfsd_set_nrthreads(int n, int *nthreads, struct net *net) @@ -533,6 +536,25 @@ out: return error; } +/* + * This function is actually slightly modified set_fs_root() + */ +static void nfsd_swap_root(struct net *net) +{ + struct nfsd_net *nn = net_generic(net, nfsd_net_id); + struct fs_struct *fs = current->fs; + struct path old_root; + + path_get(&nn->root); + spin_lock(&fs->lock); + write_seqcount_begin(&fs->seq); + old_root = fs->root; + fs->root = nn->root; + write_seqcount_end(&fs->seq); + spin_unlock(&fs->lock); + if (old_root.dentry) + path_put(&old_root); +} /* * This is the NFS server kernel thread @@ -559,6 +581,15 @@ nfsd(void *vrqstp) current->fs->umask = 0; /* + * We have to swap NFSd kthread's fs->root. + * Why so? Because NFSd can be started in container, which has it's own + * root. + * And so what? NFSd lookup files, and lookup start from + * current->fs->root. + */ + nfsd_swap_root(net); + + /* * thread is spawned with all signals set to SIG_IGN, re-enable * the ones that will bring down the thread */