From patchwork Thu Jan 5 14:46:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 9499105 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 25744606B4 for ; Thu, 5 Jan 2017 14:46:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B7B428406 for ; Thu, 5 Jan 2017 14:46:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1013B2840A; Thu, 5 Jan 2017 14:46:47 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 F035828408 for ; Thu, 5 Jan 2017 14:46:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967759AbdAEOqm (ORCPT ); Thu, 5 Jan 2017 09:46:42 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:35894 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S969474AbdAEOqh (ORCPT ); Thu, 5 Jan 2017 09:46:37 -0500 Received: by mail-pg0-f68.google.com with SMTP id 75so2696725pgf.3 for ; Thu, 05 Jan 2017 06:46:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=Sich0JmDzUPloN0Gn3BheuyVwcgoMxKUOgz8VX/QPV0=; b=P39StTT44P4ZtnkNsKLX4OGUN0xzhzrxpPEU2FoDeixK4g+Iuf3XXc+MENULg/nWF6 NhgdUjHwkeludMg+pDIsscRJm8MMIWFws1koO4IsUG2Nuzo/icyw1GaY82WMCPNeZkgh cZFwDd//FRqaYXZmNNR9LVTxKN25Uv7X/jyXKsci6/lOIUBv0oS30gYVldHJJA4iuOrP fX6f0bn6ebXLSQEg7YdOkZMqj3of2n12rKnNXZVUbOKpB8Q40r4U1zeVMV2KFPYvybwY sfv+eeUhOFM4SWWvbazcwNVZ6Br/9Xp4K26Dl/E1+Krc3R0Aa7SH0DU6Km+r2VKQH4kf PRnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=Sich0JmDzUPloN0Gn3BheuyVwcgoMxKUOgz8VX/QPV0=; b=p/lhrLqV2GxbBMFHvJuARFRVRgFd8GfvNgYfzVBQ5rLrQWxH0rIMuZxtdP1KtHZuPv OtRnUGF/Zp2WJHas0B0J4x2lCmIUz5Cr7RuVGydcBH4FQ9ByEcPka+lPKC+QeCehotCV IYqsutJ0WBScZ69OobjP9ZrWUF8zPEL3JrVbAz+9oJSCJjVQpIbMosG0ADkKwUJDUBZd 4oktBsPVYJjwrpV3L7JYRlYm43G1W/0bz2Hhjl0oR+iGBjBRk9lsi+Gbh7OoZzHK1g8k TcCwbMhzxzBOlcQsqE3rLA2c1OAIPW8Vz2H6hIrczntheGfqV5hIsn80ooDs8DTy88uI ItpA== X-Gm-Message-State: AIkVDXInzGCGTHmUyHEcaTXHOwecPdIhptlpUOp3l7Qo5wen5l4QPgQJNf9NMM/8caN6dw== X-Received: by 10.99.209.81 with SMTP id c17mr133767545pgj.24.1483627594654; Thu, 05 Jan 2017 06:46:34 -0800 (PST) Received: from [192.168.0.102] ([183.228.33.226]) by smtp.googlemail.com with ESMTPSA id o77sm8658061pfk.7.2017.01.05.06.46.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jan 2017 06:46:34 -0800 (PST) Subject: [PATCH v2] NFSD: Only support readonly export for !fsync and readonly filesystem To: "J. Bruce Fields" , linux-nfs@vger.kernel.org References: <960d206f-3cb5-b60e-5245-d7282dabf664@gmail.com> Cc: Christoph Hellwig , Steve Dickson , kinglongmee@gmail.com From: Kinglong Mee Message-ID: Date: Thu, 5 Jan 2017 22:46:24 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: <960d206f-3cb5-b60e-5245-d7282dabf664@gmail.com> 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 Commit fae5096ad217 "nfsd: assume writeable exportabled filesystems have f_sync" have remove the checking of f_sync. Christoph Hellwig suggests, "Warn and refuse the writable export." I think just covert to a readonly export for !fsync filesystem and readonly filesystem is reasonable. For example, A test directory may be mounted many underlay filesystem (contain ISO9660, f2fs, etc) frequently. If refuse the writeable export, for ISO9660 the exports entry must be *(ro,...), but for f2fs may be *(rw,...). I don't think someone wants change it every time. Also, I let the message as a dprintk for, an export entry cache will be dropped without any use in some times, and created in the next use. If let the message as a warning, there will be many messages that users maybe think that's a noise or bug. v2, update the notice message advice from Bruce just pass svc_exoprt to check_export instead many parameters a path string for exporting entry is simply than d_path Signed-off-by: Kinglong Mee --- fs/nfsd/export.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c index 43e109c..5b9527b 100644 --- a/fs/nfsd/export.c +++ b/fs/nfsd/export.c @@ -339,8 +339,10 @@ static struct svc_export *svc_export_update(struct svc_export *new, struct svc_export *old); static struct svc_export *svc_export_lookup(struct svc_export *); -static int check_export(struct inode *inode, int *flags, unsigned char *uuid) +static int check_export(struct svc_export *exp, char *path_str) { + struct inode *inode = d_inode(exp->ex_path.dentry); + int *flags = &exp->ex_flags; /* * We currently export only dirs, regular files, and (for v4 @@ -358,6 +360,18 @@ static int check_export(struct inode *inode, int *flags, unsigned char *uuid) if (*flags & NFSEXP_V4ROOT) *flags |= NFSEXP_READONLY; + /* + * Convert to a readonly export for that, + * 1. not supported fsync filesystem, + * 2. readonly filesystem. + */ + if ((!inode->i_fop->fsync || IS_RDONLY(inode)) + && !(*flags & NFSEXP_READONLY)) { + dprintk("%s %s: exporting read-only.\n", path_str, + IS_RDONLY(inode) ? "is read-only" : "has no fsync method"); + *flags |= NFSEXP_READONLY; + } + /* There are two requirements on a filesystem to be exportable. * 1: We must be able to identify the filesystem from a number. * either a device number (so FS_REQUIRES_DEV needed) @@ -367,7 +381,7 @@ static int check_export(struct inode *inode, int *flags, unsigned char *uuid) */ if (!(inode->i_sb->s_type->fs_flags & FS_REQUIRES_DEV) && !(*flags & NFSEXP_FSID) && - uuid == NULL) { + exp->ex_uuid == NULL) { dprintk("exp_export: export of non-dev fs without fsid\n"); return -EINVAL; } @@ -509,7 +523,7 @@ uuid_parse(char **mesg, char *buf, unsigned char **puuid) static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen) { /* client path expiry [flags anonuid anongid fsid] */ - char *buf; + char *buf, *path_str = NULL; int len; int err; struct auth_domain *dom = NULL; @@ -544,6 +558,7 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen) if (err) goto out1; + path_str = kstrdup(buf, GFP_KERNEL); exp.ex_client = dom; exp.cd = cd; exp.ex_devid_map = NULL; @@ -599,8 +614,7 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen) goto out4; } - err = check_export(d_inode(exp.ex_path.dentry), &exp.ex_flags, - exp.ex_uuid); + err = check_export(&exp, path_str); if (err) goto out4; /* @@ -645,6 +659,7 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen) out1: auth_domain_put(dom); out: + kfree(path_str); kfree(buf); return err; }