From patchwork Tue Mar 27 21:11:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10311689 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 2C9F26037D for ; Tue, 27 Mar 2018 21:12:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27B7F29A75 for ; Tue, 27 Mar 2018 21:12:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B8F429A85; Tue, 27 Mar 2018 21:12:14 +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_SIGNED, 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 6364129A75 for ; Tue, 27 Mar 2018 21:12:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751220AbeC0VMM (ORCPT ); Tue, 27 Mar 2018 17:12:12 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:40951 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751063AbeC0VML (ORCPT ); Tue, 27 Mar 2018 17:12:11 -0400 Received: by mail-io0-f195.google.com with SMTP id e79so953747ioi.7 for ; Tue, 27 Mar 2018 14:12:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=my6XSgTzsJBag75YgUadZK460wSFhCye7T8Kj2PKjS4=; b=d90WKViH+LBreTds9pDpc69/6ctRSVI29GnGm7xIbIDSNS9EyoME8ym5AYb/ofoymJ gOarNmRZkjN9s9l12g6xAZLc23EfaDjOYjRnZNTvCl0Bevf01q1iSPBFkLUvM4KNtLOI QVIP3Au4Y+Y9uTvUqb+oPyod2vSeUagYrEx3+tN88+DrDKzxNjfTEWLJJZUJUWVFpW// /1WZ3JseR4kgP91c37buIky0m9x84o5Ajihw6M7PEsMEiF8EXgIRV9se2s6Nxkknd9Xc 4KiwCh7Nfaedubgdt+ebO9DE31+IekVZEdHUlAumntgEeW5mhPH7EG5bl0OPuxfSFF4a Cjgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=my6XSgTzsJBag75YgUadZK460wSFhCye7T8Kj2PKjS4=; b=Byl7+yxHMUKvnM8QZZHIozpeVodmA1i24GhpxY+JoZOlv3Yga11v/RV01sUPjfyD3c IRxg1G1A8oek0qoQXZI/C+o5v1hpdpfBwcYOg5VRhJJyMY9iX78ueeFKUp6l8rd2nWfO tVa2Xt2Os7psweIJ2yekZl5xp93EhQe7oXoL3nbRKY+pRwMEFyCOfkybgJVGQLyV/zqe OOitsdcGBg9mVFiepOuVwSiPX1ID1vlegLrHp9Xmnpdqm5s4eIDQVqZXCci2RdXaD28F 4CSChzjMSusROVjpzqSFwexJXpOkRN2aNZaNJuBg/rEToo3tRioN5oGzURCmUeohaBxO aslw== X-Gm-Message-State: AElRT7FcWHcE8+jvjo+S3giZ6spsErHKdBopOizFPuHo6hoMmoNqD4o4 cIovd66/63YLugXbQs1WTg== X-Google-Smtp-Source: AG47ELtnavRAceywxSVQgIPc+L/U24M1y0O4gUktUtnb7oZREJlsQCBYA7C4muUfN7yDH4YER+Ui+Q== X-Received: by 10.107.143.9 with SMTP id r9mr44607865iod.191.1522185130713; Tue, 27 Mar 2018 14:12:10 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (227.sub-174-230-11.myvzw.com. [174.230.11.227]) by smtp.gmail.com with ESMTPSA id 74-v6sm1657255ith.17.2018.03.27.14.12.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Mar 2018 14:12:10 -0700 (PDT) From: Trond Myklebust To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH] NFSv4.1: Fix exclusive create Date: Tue, 27 Mar 2018 17:11:37 -0400 Message-Id: <20180327211137.44171-1-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.14.3 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 When we use EXCLUSIVE4_1 mode, the server returns an attribute mask where all the bits indicate which attributes were set, and where the verifier was stored. In order to figure out which attribute we have to resend, we need to clear out the attributes that are set in exclcreat_bitmask. Signed-off-by: Trond Myklebust --- Should this be a stable patch? fs/nfs/nfs4proc.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 6933109fa30f..f73587f0fc57 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -2750,27 +2750,37 @@ static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st * fields corresponding to attributes that were used to store the verifier. * Make sure we clobber those fields in the later setattr call */ -static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, +static unsigned nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr, struct nfs4_label **label) { - const u32 *attrset = opendata->o_res.attrset; + const __u32 *bitmask = opendata->o_arg.server->exclcreat_bitmask; + __u32 attrset[3]; + unsigned ret = 0; + unsigned i; - if ((attrset[1] & FATTR4_WORD1_TIME_ACCESS) && - !(sattr->ia_valid & ATTR_ATIME_SET)) - sattr->ia_valid |= ATTR_ATIME; + for (i = 0; i < ARRAY_SIZE(attrset); i++) { + attrset[i] = opendata->o_res.attrset[i]; + if (opendata->o_arg.createmode == NFS4_CREATE_EXCLUSIVE4_1) + attrset[i] &= ~bitmask[i]; + } - if ((attrset[1] & FATTR4_WORD1_TIME_MODIFY) && - !(sattr->ia_valid & ATTR_MTIME_SET)) - sattr->ia_valid |= ATTR_MTIME; + if ((attrset[1] & (FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET))) { + if (sattr->ia_valid & ATTR_ATIME_SET) + ret |= ATTR_ATIME_SET; + else + ret |= ATTR_ATIME; + } - /* Except MODE, it seems harmless of setting twice. */ - if (opendata->o_arg.createmode != NFS4_CREATE_EXCLUSIVE && - (attrset[1] & FATTR4_WORD1_MODE || - attrset[2] & FATTR4_WORD2_MODE_UMASK)) - sattr->ia_valid &= ~ATTR_MODE; + if ((attrset[1] & (FATTR4_WORD1_TIME_MODIFY|FATTR4_WORD1_TIME_MODIFY_SET))) { + if (sattr->ia_valid & ATTR_MTIME_SET) + ret |= ATTR_MTIME_SET; + else + ret |= ATTR_MTIME; + } - if (attrset[2] & FATTR4_WORD2_SECURITY_LABEL) + if (!(attrset[2] & FATTR4_WORD2_SECURITY_LABEL)) *label = NULL; + return ret; } static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, @@ -2899,12 +2909,15 @@ static int _nfs4_do_open(struct inode *dir, if ((opendata->o_arg.open_flags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL) && (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) { - nfs4_exclusive_attrset(opendata, sattr, &label); + unsigned attrs = nfs4_exclusive_attrset(opendata, sattr, &label); /* * send create attributes which was not set by open * with an extra setattr. */ - if (sattr->ia_valid & NFS4_VALID_ATTRS) { + if (attrs || label) { + unsigned ia_old = sattr->ia_valid; + + sattr->ia_valid = attrs; nfs_fattr_init(opendata->o_res.f_attr); status = nfs4_do_setattr(state->inode, cred, opendata->o_res.f_attr, sattr, @@ -2914,6 +2927,7 @@ static int _nfs4_do_open(struct inode *dir, opendata->o_res.f_attr); nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel); } + sattr->ia_valid = ia_old; } } if (opened && opendata->file_created)