From patchwork Mon Jan 6 18:40:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319815 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BEFD714DB for ; Mon, 6 Jan 2020 18:42:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E2A6208C4 for ; Mon, 6 Jan 2020 18:42:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VzzY4qIP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726722AbgAFSmt (ORCPT ); Mon, 6 Jan 2020 13:42:49 -0500 Received: from mail-yb1-f195.google.com ([209.85.219.195]:39235 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726612AbgAFSms (ORCPT ); Mon, 6 Jan 2020 13:42:48 -0500 Received: by mail-yb1-f195.google.com with SMTP id b12so137613ybg.6 for ; Mon, 06 Jan 2020 10:42:48 -0800 (PST) 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=kBM4GM4ScWgAI2ERG7Edy0voI9DiPcQQJ6qVFwzJ0jQ=; b=VzzY4qIPFi3m+IhfX0DE9QA/iIcZJN7jPWvU+v/IMOf0ZbwFpbS3Z/xa2tGzaMvDHq E2BCKYmjhhqkfb/Z58OWwtynUktJF0MTbS8bbCzq6S0KpvyW7ZekjPwjj9jP0qoa2aqz zcz7Llk3PhsV9dh6LGkpdgIdZ6N2riK2t3Js7ElaZ0scBVuY/TDSnffo/Kb6+YUPz7Cu MS1ihBAOrsAWFCzNSAUzYEyormazMR9vl0GG5UMBzzZvnx9Zjv1fs+z2gKYy+uyot/9Y w1id2k7oZFozqxx5iYJQhlo4uKChWisW8DodykVtGffssP/5ma7xirc9xuLGu/GFPjG+ jHnQ== 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=kBM4GM4ScWgAI2ERG7Edy0voI9DiPcQQJ6qVFwzJ0jQ=; b=j8c5ApEJqFwr5W4bE9V9GF0DRdMNeaFJMzn7iUtLAB+qt6cqSnTaviUBCAXu9w4lpP WMO2ektew+TaokjNybA5EaFp2dMo2bwcqS4vPUDAjJTzG0mJA8zCKNPrg6AkrH1pD25t GkNWuT3WaG8YPj/5jDtFkzL/Tr+tG3ABDjT/Rkv0c7zUrUn1nVat0F5lkTBqjKHfLeDG qPV0v8XN0SNODdTU6vcQTDy9jN6h93uQ3vPdIP02IN49Dv85YeyUMk1h/x0zireFtdhc VJ/Po4GPo6Ie3d/OmOTE+ih5buDHAhtSPdyqmoh4DMT8fQzwNumIvgkvCtzrqjZqduEO WAPA== X-Gm-Message-State: APjAAAVCoMIw5UQrnM1DpwHxhj7GHBjhJml6axabaqo5yVMCmiYmpKhX Y/+4jxjxu6yxRgS0f/cBPw== X-Google-Smtp-Source: APXvYqzb32iJtzoYK09EP1dekwqjnbpiZHupSI9I5YjYDiPfSiVK5nF75tCJLvgXlKkMLphOHPOEkg== X-Received: by 2002:a5b:bc2:: with SMTP id c2mr50625876ybr.372.1578336167632; Mon, 06 Jan 2020 10:42:47 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u136sm28223497ywf.101.2020.01.06.10.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:42:47 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 1/9] nfsd: Allow nfsd_vfs_write() to take the nfsd_file as an argument Date: Mon, 6 Jan 2020 13:40:29 -0500 Message-Id: <20200106184037.563557-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106184037.563557-1-trond.myklebust@hammerspace.com> References: <20200106184037.563557-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 Needed in order to fix stable writes. Signed-off-by: Trond Myklebust --- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/vfs.c | 5 +++-- fs/nfsd/vfs.h | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 4798667af647..3d4e78118e53 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1012,7 +1012,7 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, &write->wr_head, write->wr_buflen); WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec)); - status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf->nf_file, + status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf, write->wr_offset, rqstp->rq_vec, nvecs, &cnt, write->wr_how_written); nfsd_file_put(nf); diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 82cf80dde5c7..69cbdb62b262 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -947,10 +947,11 @@ static int wait_for_concurrent_writes(struct file *file) } __be32 -nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file, +nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, loff_t offset, struct kvec *vec, int vlen, unsigned long *cnt, int stable) { + struct file *file = nf->nf_file; struct svc_export *exp; struct iov_iter iter; __be32 nfserr; @@ -1057,7 +1058,7 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, if (err) goto out; - err = nfsd_vfs_write(rqstp, fhp, nf->nf_file, offset, vec, + err = nfsd_vfs_write(rqstp, fhp, nf, offset, vec, vlen, cnt, stable); nfsd_file_put(nf); out: diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h index cc110a10bfe8..fd779c3bb35b 100644 --- a/fs/nfsd/vfs.h +++ b/fs/nfsd/vfs.h @@ -34,6 +34,8 @@ #define NFSD_MAY_CREATE (NFSD_MAY_EXEC|NFSD_MAY_WRITE) #define NFSD_MAY_REMOVE (NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC) +struct nfsd_file; + /* * Callback function for readdir */ @@ -93,7 +95,7 @@ __be32 nfsd_read(struct svc_rqst *, struct svc_fh *, __be32 nfsd_write(struct svc_rqst *, struct svc_fh *, loff_t, struct kvec *, int, unsigned long *, int); __be32 nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, - struct file *file, loff_t offset, + struct nfsd_file *nf, loff_t offset, struct kvec *vec, int vlen, unsigned long *cnt, int stable); __be32 nfsd_readlink(struct svc_rqst *, struct svc_fh *, From patchwork Mon Jan 6 18:40:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319817 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B4E131395 for ; Mon, 6 Jan 2020 18:42:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 94B392146E for ; Mon, 6 Jan 2020 18:42:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W4xGHND0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726723AbgAFSmv (ORCPT ); Mon, 6 Jan 2020 13:42:51 -0500 Received: from mail-yw1-f67.google.com ([209.85.161.67]:40302 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726612AbgAFSmu (ORCPT ); Mon, 6 Jan 2020 13:42:50 -0500 Received: by mail-yw1-f67.google.com with SMTP id i126so22282143ywe.7 for ; Mon, 06 Jan 2020 10:42:50 -0800 (PST) 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=vACpPc0PMx+n43w6tqWR0yHmw949Y64vBySvDL6VgHY=; b=W4xGHND0YxPgCe+Y/DO5xJlY5ycb3sRBWIXqiYnJiStrArhJqVqw5TheeSj7D3tdgm G239WfP7oeOxuSMeZSEqcVZ/sQNUTCPMnE4SRdgTW8mV4ujChUQRLaRNeIenIyWQYv0N j4H3M11OUlPbY0v636WdmAltsblrbqT0PQ5fotBomIc9d8DNvPxuazrdUPAIpI2191Wk 1DHCGYA2uPIPLCfeZFobaj35GK38ogCOt9tX7tocWY8B4a/TbTtsW7cOf4ui0x5vgFMn CltKvNZbL/c8Esmz1njzf1YJGU+n71Eq4M7Mjh7VQPusxMTz9YAkFaqo5ha1FL31cdEq nMXA== 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=vACpPc0PMx+n43w6tqWR0yHmw949Y64vBySvDL6VgHY=; b=aZX4cIPjoyIP9r8zd7Kc2t8pgdy5UFSBYj8sHjc3Zi6mEELlajSQk3+xWoFvgiB4G1 SKAOgJjJggEOwkjThgyI20KTJwDE/FOFvnCNq9qJah0nAQK/HUH2oNXaOOEU0LtzFcio OTsWdXucN+OvSM5g9ZY9T5bsGaZmR8Q8XeGthyR+bSPSGwtkF9WqLzea+/MX2o1H918t KrKQiVU+ki3m7bTMBybcmXxN8T9MYrTKd6gpjGQiDYIAki9FUwUsa2BAdAJW1ucYSKIK 367Bo4WLIUah7smMcoV0MXh3kbh2Hk6yn0cJT8g2a4/jlkvY3ofjuPTuAMwRPAIo9WFa F27A== X-Gm-Message-State: APjAAAWY0VZzRg1x6dmJ8q/O7aqQIp6jMJidiGVujR3wOC3iPEJQAG3f OYxBUQw3geT2yAPcSB8v5g== X-Google-Smtp-Source: APXvYqzwwE5xnTRs8cB7Lea1o5ozQ2+ZwY+Ou3ujlBCY2wN6cxIyXEiRGo6OSGixsi1DQhbtxrtAAQ== X-Received: by 2002:a81:1b88:: with SMTP id b130mr79231322ywb.514.1578336169630; Mon, 06 Jan 2020 10:42:49 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u136sm28223497ywf.101.2020.01.06.10.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:42:48 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 2/9] nfsd: Fix stable writes Date: Mon, 6 Jan 2020 13:40:30 -0500 Message-Id: <20200106184037.563557-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106184037.563557-2-trond.myklebust@hammerspace.com> References: <20200106184037.563557-1-trond.myklebust@hammerspace.com> <20200106184037.563557-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 Strictly speaking, a stable write error needs to reflect the write + the commit of that write (and only that write). To ensure that we don't pick up the write errors from other writebacks, add a rw_semaphore to provide exclusion. Signed-off-by: Trond Myklebust --- fs/nfsd/filecache.c | 1 + fs/nfsd/filecache.h | 1 + fs/nfsd/vfs.c | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index f275c11c4e28..2fadf080ac42 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -195,6 +195,7 @@ nfsd_file_alloc(struct inode *inode, unsigned int may, unsigned int hashval, __set_bit(NFSD_FILE_BREAK_READ, &nf->nf_flags); } nf->nf_mark = NULL; + init_rwsem(&nf->nf_rwsem); trace_nfsd_file_alloc(nf); } return nf; diff --git a/fs/nfsd/filecache.h b/fs/nfsd/filecache.h index 79a7d6808d97..986c325a54bd 100644 --- a/fs/nfsd/filecache.h +++ b/fs/nfsd/filecache.h @@ -46,6 +46,7 @@ struct nfsd_file { atomic_t nf_ref; unsigned char nf_may; struct nfsd_file_mark *nf_mark; + struct rw_semaphore nf_rwsem; }; int nfsd_file_cache_init(void); diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 69cbdb62b262..218b8293c633 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -982,7 +982,18 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, flags |= RWF_SYNC; iov_iter_kvec(&iter, WRITE, vec, vlen, *cnt); - host_err = vfs_iter_write(file, &iter, &pos, flags); + if (flags & RWF_SYNC) { + down_write(&nf->nf_rwsem); + host_err = vfs_iter_write(file, &iter, &pos, flags); + if (host_err < 0) + nfsd_reset_boot_verifier(net_generic(SVC_NET(rqstp), + nfsd_net_id)); + up_write(&nf->nf_rwsem); + } else { + down_read(&nf->nf_rwsem); + host_err = vfs_iter_write(file, &iter, &pos, flags); + up_read(&nf->nf_rwsem); + } if (host_err < 0) goto out_nfserr; *cnt = host_err; @@ -1097,8 +1108,10 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, if (err) goto out; if (EX_ISSYNC(fhp->fh_export)) { - int err2 = vfs_fsync_range(nf->nf_file, offset, end, 0); + int err2; + down_write(&nf->nf_rwsem); + err2 = vfs_fsync_range(nf->nf_file, offset, end, 0); switch (err2) { case 0: break; @@ -1110,6 +1123,7 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, nfsd_reset_boot_verifier(net_generic(nf->nf_net, nfsd_net_id)); } + up_write(&nf->nf_rwsem); } nfsd_file_put(nf); From patchwork Mon Jan 6 18:40:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319819 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C61931395 for ; Mon, 6 Jan 2020 18:42:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A577D2146E for ; Mon, 6 Jan 2020 18:42:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="icoQlB+x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726725AbgAFSmw (ORCPT ); Mon, 6 Jan 2020 13:42:52 -0500 Received: from mail-yb1-f194.google.com ([209.85.219.194]:40317 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726612AbgAFSmv (ORCPT ); Mon, 6 Jan 2020 13:42:51 -0500 Received: by mail-yb1-f194.google.com with SMTP id a2so22482964ybr.7 for ; Mon, 06 Jan 2020 10:42:51 -0800 (PST) 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=5vonulXfr3czMCCV7WctXC4mLeKKqa+GGJ+EMXttiSE=; b=icoQlB+xq2Jia8PjloAxYIjpwSyg2TlssjHG/Z4lIBoV8qGxNEFD+yUu0XaCcfJF5S clwuZl8BSxo6FHvGfZ6vi1+WZe/1g/CNXWVOZQZBn5x/psA5rJkWBgBNHkhrvk2SKtSr awOYbSFrL3B2sORxEc0pvN8Xd1buycUBUpBS0NVwPWpVG3C60gnKyPLtP35B9MKsHZYy bBLfrW+WfdhKWVB129uWapnoEpyxV84JodgAZYPOcYELNMZAKWGsT/LXUTw2S90XkQyd 13PZTY2Nem4/wzU4cVHCyKOw/QO9gBnFqHsgdKk0uDFJ6uH4G0We1jeJ58t0/7RifOZ7 gOvg== 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=5vonulXfr3czMCCV7WctXC4mLeKKqa+GGJ+EMXttiSE=; b=m8g0fxjHGAJ6o7PlqQ9frafB0SyO/k1sbpKH4pLP7DQgK2QE2pXwkv3udTEWNoMe9a qfN5NO8shP9AhmBhEDzPWLl3p/aRaGRBB81PDmiN27SnX+0EFvHR5TnHU2/RRwdFXO8x 1fGcqisYoIrQByN7WGyJ+xNOEvT97Qi3ih0AU+AGx3iJf+HPeV0vrjGjItNOy0f3vd0q 5SAWs8L5wxtL65/R4o6TglTm/hIaSow5Zwuzb3dWKD/25pwjhr9yFCg99z4WYH/XxuaM 9g8bhVVzyFqDTlwpOilT/LgcvM3SNGoMSvBookcebAWxboMebnl69KG+59YlJOVnDr8o 1dZQ== X-Gm-Message-State: APjAAAWDqOfAwfCpLxb4IBVwGmWYWcynFFYJYtr0Eru6hS4qYCea67c2 i363eWlWfInPb4mxv0XZzm51uQrw5w== X-Google-Smtp-Source: APXvYqzFZsqAPjg7AZvuGCBR7YLuj74KkhMj1cQYuhf2j0w/VQOn99AwUmB4YQMO7YQSYmmi7Bl2aw== X-Received: by 2002:a25:6154:: with SMTP id v81mr42530434ybb.404.1578336170601; Mon, 06 Jan 2020 10:42:50 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u136sm28223497ywf.101.2020.01.06.10.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:42:50 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 3/9] nfsd: Update the boot verifier on stable writes too. Date: Mon, 6 Jan 2020 13:40:31 -0500 Message-Id: <20200106184037.563557-4-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106184037.563557-3-trond.myklebust@hammerspace.com> References: <20200106184037.563557-1-trond.myklebust@hammerspace.com> <20200106184037.563557-2-trond.myklebust@hammerspace.com> <20200106184037.563557-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 We don't know if the error returned by the fsync() call is exclusive to the data written by the stable write, so play it safe. Signed-off-by: Trond Myklebust --- fs/nfsd/vfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 218b8293c633..38db4a083375 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -994,8 +994,11 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, host_err = vfs_iter_write(file, &iter, &pos, flags); up_read(&nf->nf_rwsem); } - if (host_err < 0) + if (host_err < 0) { + nfsd_reset_boot_verifier(net_generic(SVC_NET(rqstp), + nfsd_net_id)); goto out_nfserr; + } *cnt = host_err; nfsdstats.io_write += *cnt; fsnotify_modify(file); From patchwork Mon Jan 6 18:40:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319821 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B3A613A0 for ; Mon, 6 Jan 2020 18:42:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB99E2146E for ; Mon, 6 Jan 2020 18:42:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Cg8K+b7p" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726731AbgAFSmx (ORCPT ); Mon, 6 Jan 2020 13:42:53 -0500 Received: from mail-yb1-f195.google.com ([209.85.219.195]:36002 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726612AbgAFSmw (ORCPT ); Mon, 6 Jan 2020 13:42:52 -0500 Received: by mail-yb1-f195.google.com with SMTP id w126so20580249yba.3 for ; Mon, 06 Jan 2020 10:42:52 -0800 (PST) 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=DnEWwYmni+ziqYug2P07l7EynLLIjlkk9quvtChv4k4=; b=Cg8K+b7p49qtrG4cMqxWApS+l6OOxCZO1YtFl3Lq8XD97aldv8/Pfg5XX9weUdm5BC KznhguRblexmyhCA7HjP+dD3GOeK2wVRo2E27m9IJY+98zI5L8yGfHg2ucaBTBh2u2vi E5xZiOjUIvtHqbOqN/5bb/M2MyGymiEpLpgPHTPNpnHzZHJdFw88BMVm/e9mj7KYeO1S hx0++NrsgzDmvt43aYLrKURXpqaJ0Sx1XFxcGa9NMO7LJcCPeksly9KEopYZscjX84Aw h4XgsNSbagwLmL8LVpbbpcWOT+h+gtJJ5Kp5hH8N3IsldPwWLt7xz5RZGc38GkE5SoJb 5VkA== 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=DnEWwYmni+ziqYug2P07l7EynLLIjlkk9quvtChv4k4=; b=jZVPoGvWDw5uyYDVALGtje2sAXMVqCxZf0Qvnnmc4PTMIUDWAadQVCEUDG9Pyfh71m iOyZw9T/vkT/hWpZY9PnucPCa33PU9jcrU0jdG1fOD2hfkxIllW5DP4NGtNcoeDPdXi2 j3+B34SpaPk7u/FuRK8UvvZa5iQt+Wvwf+yXJjL1tj5L/aBCV6AFadiXsB+kNgN0dqCu U1c3R9ASmcPIeUOogfuk2OHE7naVDnXbDcJ9D+rfZhIB5kC66sUnSh0B08RwckqjjFpm nkEVmn8WpbMSkpI2f0s5H0pKqBYoAlYlC6cYsV39GD5QqlFsX6dhtLwK7jPK0+e7+56w aaXA== X-Gm-Message-State: APjAAAXSvltOOIguGzI1ei7bQH0LOWuf7fWKTT6l8cypReOIulMLVGju ZODN1m+U/V7YxBiQg+iNu0//wXunIw== X-Google-Smtp-Source: APXvYqwsb998BZDP1X5auua/MHciHuUtfzNHD4wErxNCSkzkEzm2zmereOE2VImFsS15g+sPepBOlA== X-Received: by 2002:a25:3741:: with SMTP id e62mr74990165yba.414.1578336171595; Mon, 06 Jan 2020 10:42:51 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u136sm28223497ywf.101.2020.01.06.10.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:42:51 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 4/9] nfsd: Pass the nfsd_file as arguments to nfsd4_clone_file_range() Date: Mon, 6 Jan 2020 13:40:32 -0500 Message-Id: <20200106184037.563557-5-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106184037.563557-4-trond.myklebust@hammerspace.com> References: <20200106184037.563557-1-trond.myklebust@hammerspace.com> <20200106184037.563557-2-trond.myklebust@hammerspace.com> <20200106184037.563557-3-trond.myklebust@hammerspace.com> <20200106184037.563557-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 Needed in order to fix exclusion w.r.t. writes. Signed-off-by: Trond Myklebust --- fs/nfsd/nfs4proc.c | 4 ++-- fs/nfsd/vfs.c | 6 ++++-- fs/nfsd/vfs.h | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 3d4e78118e53..7fce319e5b85 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1076,8 +1076,8 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, if (status) goto out; - status = nfsd4_clone_file_range(src->nf_file, clone->cl_src_pos, - dst->nf_file, clone->cl_dst_pos, clone->cl_count, + status = nfsd4_clone_file_range(src, clone->cl_src_pos, + dst, clone->cl_dst_pos, clone->cl_count, EX_ISSYNC(cstate->current_fh.fh_export)); nfsd_file_put(dst); diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 38db4a083375..7e7e31dfc672 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -530,9 +530,11 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp, } #endif -__be32 nfsd4_clone_file_range(struct file *src, u64 src_pos, struct file *dst, - u64 dst_pos, u64 count, bool sync) +__be32 nfsd4_clone_file_range(struct nfsd_file *nf_src, u64 src_pos, + struct nfsd_file *nf_dst, u64 dst_pos, u64 count, bool sync) { + struct file *src = nf_src->nf_file; + struct file *dst = nf_dst->nf_file; loff_t cloned; cloned = vfs_clone_file_range(src, src_pos, dst, dst_pos, count, 0); diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h index fd779c3bb35b..69d23e9926cf 100644 --- a/fs/nfsd/vfs.h +++ b/fs/nfsd/vfs.h @@ -57,8 +57,9 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *, struct svc_fh *, struct xdr_netobj *); __be32 nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *, struct file *, loff_t, loff_t, int); -__be32 nfsd4_clone_file_range(struct file *, u64, struct file *, - u64, u64, bool); +__be32 nfsd4_clone_file_range(struct nfsd_file *nf_src, u64 src_pos, + struct nfsd_file *nf_dst, u64 dst_pos, + u64 count, bool sync); #endif /* CONFIG_NFSD_V4 */ __be32 nfsd_create_locked(struct svc_rqst *, struct svc_fh *, char *name, int len, struct iattr *attrs, From patchwork Mon Jan 6 18:40:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319823 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C89E13A0 for ; Mon, 6 Jan 2020 18:42:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF95F2146E for ; Mon, 6 Jan 2020 18:42:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="A0RVLw9U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726751AbgAFSmy (ORCPT ); Mon, 6 Jan 2020 13:42:54 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:32892 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726742AbgAFSmx (ORCPT ); Mon, 6 Jan 2020 13:42:53 -0500 Received: by mail-yb1-f193.google.com with SMTP id n66so22489640ybg.0 for ; Mon, 06 Jan 2020 10:42:53 -0800 (PST) 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=3gv2Uv5Vo9nayPlWr/mLsAQL4tqjnJ1W4jdHwtQk72w=; b=A0RVLw9UXvaoCqp5O7Z4MoKjy+n56Ui1CkGZfxChF8rkE00M5WIRJ52jppBAZL6X4X WrYYp6YRJ9n5e9pRaUYip3LuIAcCgAYYtNHGFKngztRnizt++suTFj08+o2t090WTHYg Qpd51hwnb25HgvXyDQD6O+Y6AfUn/OJSbv9d1+r4FCj1dy+t56kMbkypso2PJ0TtXzHc Wy2VBO1xeW/aMyK9YxgmT/KiOdzs6yMfcxLt0uuBU0KR/dNTbhpXVHvu4elQtQ0tGwYO 4pM/e9paC+al0X7/mYsNxOtFk8/2aubQXRtROuyWgo7JI9AIPqlJ4sFyvVTRu5JVHYL8 R6rg== 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=3gv2Uv5Vo9nayPlWr/mLsAQL4tqjnJ1W4jdHwtQk72w=; b=nGOFUAY8lmKSEh2MYc59PKDrO7xC2rQRG6jW4fvlgucCI81sAk4T32NYSx6mBG9hZ0 Qh+gbkPGXJ/vOlIqwxPj6hjtKBs6B67kKCElBD9vPZgOULQAnGLWajmi7w30D85lhkN1 D/ON5waWL/SA9pGhImH8SUp6MJXSzDYerMxWXlRGEk3iScsAGk7jZXWazvr9qHB6Ozy6 LvHDccGcLAsP7BQNdAQ5fL2MIJc54clVbZfABSdUGobYZaF5GZc8JC+i8HYJNQwNMHSL Y1bvGGKO/1eHUDUpMeb/FsZTNY7DAMp0vRIxcnqxgoecnZq+Cxmo34PoXiJVWvxA8Oft 52AA== X-Gm-Message-State: APjAAAVikiulf6TqsDnFtnbbTbqK5j2tcK8HfILoku5eOCcjn3KyMXdT 7TrmgNGDTB9tc784YLFfTA== X-Google-Smtp-Source: APXvYqwNIm+MJ6EVzyTCUEBZ5A2aSBqq57LgTzxTzGE6DmSvKDeLojDTF8FAErFvUjfQ8FCYg1SmFQ== X-Received: by 2002:a25:d88d:: with SMTP id p135mr79102374ybg.205.1578336172532; Mon, 06 Jan 2020 10:42:52 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u136sm28223497ywf.101.2020.01.06.10.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:42:52 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 5/9] nfsd: Ensure exclusion between CLONE and WRITE errors Date: Mon, 6 Jan 2020 13:40:33 -0500 Message-Id: <20200106184037.563557-6-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106184037.563557-5-trond.myklebust@hammerspace.com> References: <20200106184037.563557-1-trond.myklebust@hammerspace.com> <20200106184037.563557-2-trond.myklebust@hammerspace.com> <20200106184037.563557-3-trond.myklebust@hammerspace.com> <20200106184037.563557-4-trond.myklebust@hammerspace.com> <20200106184037.563557-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 Ensure that we can distinguish between synchronous CLONE and WRITE errors, and that we can assign them correctly. Signed-off-by: Trond Myklebust --- fs/nfsd/vfs.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 7e7e31dfc672..b2984a996ab8 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -536,22 +536,33 @@ __be32 nfsd4_clone_file_range(struct nfsd_file *nf_src, u64 src_pos, struct file *src = nf_src->nf_file; struct file *dst = nf_dst->nf_file; loff_t cloned; + __be32 ret = 0; + down_write(&nf_dst->nf_rwsem); cloned = vfs_clone_file_range(src, src_pos, dst, dst_pos, count, 0); - if (cloned < 0) - return nfserrno(cloned); - if (count && cloned != count) - return nfserrno(-EINVAL); + if (cloned < 0) { + ret = nfserrno(cloned); + goto out_err; + } + if (count && cloned != count) { + ret = nfserrno(-EINVAL); + goto out_err; + } if (sync) { loff_t dst_end = count ? dst_pos + count - 1 : LLONG_MAX; int status = vfs_fsync_range(dst, dst_pos, dst_end, 0); if (!status) status = commit_inode_metadata(file_inode(src)); - if (status < 0) - return nfserrno(status); + if (status < 0) { + nfsd_reset_boot_verifier(net_generic(nf_dst->nf_net, + nfsd_net_id)); + ret = nfserrno(status); + } } - return 0; +out_err: + up_write(&nf_dst->nf_rwsem); + return ret; } ssize_t nfsd_copy_file_range(struct file *src, u64 src_pos, struct file *dst, From patchwork Mon Jan 6 18:40:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319825 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 804DE1395 for ; Mon, 6 Jan 2020 18:42:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F67A2146E for ; Mon, 6 Jan 2020 18:42:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tbI88uEg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726742AbgAFSmy (ORCPT ); Mon, 6 Jan 2020 13:42:54 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:45625 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726612AbgAFSmy (ORCPT ); Mon, 6 Jan 2020 13:42:54 -0500 Received: by mail-yb1-f193.google.com with SMTP id y67so12802482yba.12 for ; Mon, 06 Jan 2020 10:42:54 -0800 (PST) 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=NF+1UccyPrLSTsC6NO843o3LdegAui/9wxtIWyWZc6E=; b=tbI88uEgwtSrN+3hlddr5BKBbpg7whwwmaMtwdJA4JFC6/4IW/ECEStEauO/O1M1hR P+btUxh4bBK8gw4Imbh0soDS5e95vvroZwLNFL0pHxRJDe8x+JYjxHoaD3D38WlDVUwc geFGT/u+ONBCGaGFEJYIFqggmtobRgYYQmW5sk4qBCSJmEVBzrtYfjudHKbT+dpm+iBP hFvmLyPf1PqIuAic3VlmiNT6EEbS5FnS/3pvzfRjlYuF+4Cz56nhe/MkApIU1BEPMA8s VVGbUacWu3ONVzGILolOU0Aa1aC8iFDLvdCgaLKQVwvXGpcqlDAZditKFITSz1lsPxoq p+Tg== 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=NF+1UccyPrLSTsC6NO843o3LdegAui/9wxtIWyWZc6E=; b=tfNtxlz92Yyh66uCZIhTcHiUyEx+Ym50VxvgzgJuEsENboEnXxSmYUfkrVCGgn4rPy qeOXLiZpZFR+FA7AfnRzGT1iCqgN3u/pleICjcQw1hDT0I4TW5lAxBzCvaqLs9OqpXl0 hjuH5FNz4PRExthNxM4oTE5WufVQ74VHzjo6nGm+1ndWPRqezvQ4Pc5AbHtMami0qtDv 0ecjqVMT/GcIyAMrH5+NIBK31+7mkd3n0meDyQxwJr9SVDTPSg5nDcFBCPkyfz++Wyp8 4cmJrFZwrFAvtuDIrjy5eqMZzaOYuQB6HWFgDjG2wQKIzw7q2yxHZVVJZ76l7KdjfNgP LHZQ== X-Gm-Message-State: APjAAAXuunt3StsWHeIGftdmlP+2oGGB+V50UC292S1oDlGXYz9dcmUO U5sxNyFle1cuQ0imd9q/VQ== X-Google-Smtp-Source: APXvYqxMH5jIgIMrf9dfcpK3C8DgRQy6PK1bHEqVp/Bsoki48NGVjuv8ETiKMhwJfkwGep9tipo8gQ== X-Received: by 2002:a25:ba8c:: with SMTP id s12mr29117038ybg.115.1578336173511; Mon, 06 Jan 2020 10:42:53 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u136sm28223497ywf.101.2020.01.06.10.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:42:52 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 6/9] sunrpc: Fix potential leaks in sunrpc_cache_unhash() Date: Mon, 6 Jan 2020 13:40:34 -0500 Message-Id: <20200106184037.563557-7-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106184037.563557-6-trond.myklebust@hammerspace.com> References: <20200106184037.563557-1-trond.myklebust@hammerspace.com> <20200106184037.563557-2-trond.myklebust@hammerspace.com> <20200106184037.563557-3-trond.myklebust@hammerspace.com> <20200106184037.563557-4-trond.myklebust@hammerspace.com> <20200106184037.563557-5-trond.myklebust@hammerspace.com> <20200106184037.563557-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 When we unhash the cache entry, we need to handle any pending upcalls by calling cache_fresh_unlocked(). Signed-off-by: Trond Myklebust --- net/sunrpc/cache.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index f740cb51802a..7ede1e52fd81 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -1888,7 +1888,9 @@ void sunrpc_cache_unhash(struct cache_detail *cd, struct cache_head *h) if (!hlist_unhashed(&h->cache_list)){ hlist_del_init_rcu(&h->cache_list); cd->entries--; + set_bit(CACHE_CLEANED, &h->flags); spin_unlock(&cd->hash_lock); + cache_fresh_unlocked(h, cd); cache_put(h, cd); } else spin_unlock(&cd->hash_lock); From patchwork Mon Jan 6 18:40:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319827 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2226113A0 for ; Mon, 6 Jan 2020 18:42:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F2A332146E for ; Mon, 6 Jan 2020 18:42:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jR/GCSxB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726767AbgAFSm4 (ORCPT ); Mon, 6 Jan 2020 13:42:56 -0500 Received: from mail-yb1-f194.google.com ([209.85.219.194]:43200 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726612AbgAFSm4 (ORCPT ); Mon, 6 Jan 2020 13:42:56 -0500 Received: by mail-yb1-f194.google.com with SMTP id v24so22469349ybd.10 for ; Mon, 06 Jan 2020 10:42:55 -0800 (PST) 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=TJwuCyagUq4PhK/D+Qm0Po/EkMJisggurTZpmx1TGTg=; b=jR/GCSxBxncz0hQolKp8umBNiMYehf+jrAPFGIjFDTZX7tq2ZYj4vm8sh1t8vhMOu6 n3j3Z37u//vH6+jH+81TSVu/prhXGNsHPadwcb2b0nIX9F5Frgs93J2LxsEnJYtSSkHa bUNv9sh/+fDcYFGDzjQ4xc99zvdKhBMzD79wPO2qKEq98WL6Kuvf+jpBAN+hep0cR/Qx wvKHwy/J7TrDmLXHIfIKVtY42f61bPEskF7uzGFNU8mu8tuUhdMIkaXlec0YYsycwPYT ZXRGODZwqCD3cKwRm0z9EqzY+cDBS9WKCaQxQKanWCH/mKfPpCP8r2Hf7nWBP1HgqPo2 ShqA== 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=TJwuCyagUq4PhK/D+Qm0Po/EkMJisggurTZpmx1TGTg=; b=PPo8+i8RfPiHBUCTe/fTNkU38iwu784W9KiozHk8nT61dALscyFAQQ3lax7BptFSEx 1Iasu/Ak8tSaTwVMti6ymFAHyb47yREGdpHtEHtuLIG1ZKbDFt43PFdGYkJt2fxyoLh/ blF+xkxhFdCdeeiAJEutu41dPkKHq/ymGgKxHFgTlCW+wSkTeYPFLwjMIHZXM5YlZHy3 7IbfhbYf4Hnz5FrQKq0+ZNYnGrBrjwkrBcF5QQUHqs/QBV86jVloFBY4S67JdhYGjgQs quuftUlwYp8POz+Pr7ws3t+l63FYGcTQ2PJ/O7FDuCe3/bQk236D7s/kRI4EqgDu2sKb du3Q== X-Gm-Message-State: APjAAAVX8FhWUDTnn8rOskBRe3BvOEo8Zlr5AIJLkXYHvYJc2YYJLCOF 4i8+Fosqgg7lLyF6SQ7UpxMY6CIq0A== X-Google-Smtp-Source: APXvYqzNTrsUAhJ0BJEGdNFQ1Wc591nufY/0hO0yBi9ixOLpNWbnRZQ3xMTYeeBZ/FMx0qhX/LOF9Q== X-Received: by 2002:a25:5543:: with SMTP id j64mr78005302ybb.252.1578336174584; Mon, 06 Jan 2020 10:42:54 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u136sm28223497ywf.101.2020.01.06.10.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:42:54 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 7/9] sunrpc: clean up cache entry add/remove from hashtable Date: Mon, 6 Jan 2020 13:40:35 -0500 Message-Id: <20200106184037.563557-8-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106184037.563557-7-trond.myklebust@hammerspace.com> References: <20200106184037.563557-1-trond.myklebust@hammerspace.com> <20200106184037.563557-2-trond.myklebust@hammerspace.com> <20200106184037.563557-3-trond.myklebust@hammerspace.com> <20200106184037.563557-4-trond.myklebust@hammerspace.com> <20200106184037.563557-5-trond.myklebust@hammerspace.com> <20200106184037.563557-6-trond.myklebust@hammerspace.com> <20200106184037.563557-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 Signed-off-by: Trond Myklebust --- net/sunrpc/cache.c | 50 ++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index 7ede1e52fd81..52d927210d32 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -77,6 +77,22 @@ static struct cache_head *sunrpc_cache_find_rcu(struct cache_detail *detail, return NULL; } +static void sunrpc_begin_cache_remove_entry(struct cache_head *ch, + struct cache_detail *cd) +{ + /* Must be called under cd->hash_lock */ + hlist_del_init_rcu(&ch->cache_list); + set_bit(CACHE_CLEANED, &ch->flags); + cd->entries --; +} + +static void sunrpc_end_cache_remove_entry(struct cache_head *ch, + struct cache_detail *cd) +{ + cache_fresh_unlocked(ch, cd); + cache_put(ch, cd); +} + static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, struct cache_head *key, int hash) @@ -100,8 +116,7 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, hlist_for_each_entry_rcu(tmp, head, cache_list) { if (detail->match(tmp, key)) { if (cache_is_expired(detail, tmp)) { - hlist_del_init_rcu(&tmp->cache_list); - detail->entries --; + sunrpc_begin_cache_remove_entry(tmp, detail); freeme = tmp; break; } @@ -117,10 +132,8 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, cache_get(new); spin_unlock(&detail->hash_lock); - if (freeme) { - cache_fresh_unlocked(freeme, detail); - cache_put(freeme, detail); - } + if (freeme) + sunrpc_end_cache_remove_entry(freeme, detail); return new; } @@ -454,8 +467,7 @@ static int cache_clean(void) if (!cache_is_expired(current_detail, ch)) continue; - hlist_del_init_rcu(&ch->cache_list); - current_detail->entries--; + sunrpc_begin_cache_remove_entry(ch, current_detail); rv = 1; break; } @@ -465,11 +477,8 @@ static int cache_clean(void) if (!ch) current_index ++; spin_unlock(&cache_list_lock); - if (ch) { - set_bit(CACHE_CLEANED, &ch->flags); - cache_fresh_unlocked(ch, d); - cache_put(ch, d); - } + if (ch) + sunrpc_end_cache_remove_entry(ch, d); } else spin_unlock(&cache_list_lock); @@ -525,13 +534,9 @@ void cache_purge(struct cache_detail *detail) for (i = 0; i < detail->hash_size; i++) { head = &detail->hash_table[i]; hlist_for_each_entry_safe(ch, tmp, head, cache_list) { - hlist_del_init_rcu(&ch->cache_list); - detail->entries--; - - set_bit(CACHE_CLEANED, &ch->flags); + sunrpc_begin_cache_remove_entry(ch, detail); spin_unlock(&detail->hash_lock); - cache_fresh_unlocked(ch, detail); - cache_put(ch, detail); + sunrpc_end_cache_remove_entry(ch, detail); spin_lock(&detail->hash_lock); } } @@ -1886,12 +1891,9 @@ void sunrpc_cache_unhash(struct cache_detail *cd, struct cache_head *h) { spin_lock(&cd->hash_lock); if (!hlist_unhashed(&h->cache_list)){ - hlist_del_init_rcu(&h->cache_list); - cd->entries--; - set_bit(CACHE_CLEANED, &h->flags); + sunrpc_begin_cache_remove_entry(h, cd); spin_unlock(&cd->hash_lock); - cache_fresh_unlocked(h, cd); - cache_put(h, cd); + sunrpc_end_cache_remove_entry(h, cd); } else spin_unlock(&cd->hash_lock); } From patchwork Mon Jan 6 18:40:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319829 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 58EFF13A0 for ; Mon, 6 Jan 2020 18:42:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 381E02146E for ; Mon, 6 Jan 2020 18:42:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WznSV9Im" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726770AbgAFSm5 (ORCPT ); Mon, 6 Jan 2020 13:42:57 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:32894 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726760AbgAFSm5 (ORCPT ); Mon, 6 Jan 2020 13:42:57 -0500 Received: by mail-yb1-f193.google.com with SMTP id n66so22489709ybg.0 for ; Mon, 06 Jan 2020 10:42:56 -0800 (PST) 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=ZzMvDGwLMIkB9C9Mnpqvof7jU4+XKEfowxtMHzq78MU=; b=WznSV9ImlTta1YRBvtek1rSlw9cJGey9zI4EsMg7KdGt3ESH/tkpJnYpCxTTFNwM/T GnjqFTuDlBXoA24fCCikg4emZo49AAFAM9FYTUVe74w7da04DAc0F/jr87+KL9uILUfS Lu6ZBvKUOV/ifsj5Fd8vxN3KMuvQRI0q8KxH47FGEJhKR7ue8A5Pl0lwIV8Ph6WFiDLS C1cfwDQ7Kk1ALkPiNeZ1DR1Z9h6L5bg0PK+/3EPoMHGQcvUgGYcVi73LdyAY5CmF8DPN +HzgMyNIXMkIn+EHtBOqsnRS2N8KRsujsym6kdl663vTr9JRHcT4pjI96dRyz8Flng1j K1WA== 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=ZzMvDGwLMIkB9C9Mnpqvof7jU4+XKEfowxtMHzq78MU=; b=uK3/9ZhuW8J1M2mKHe2lByRnmevZqIIq8pRg7B0o4Fu6UzQJYzmjLUa62XAFKPD/4u 86EreZvOH9RnfSsdcd1Ha8DK6IRTVK/226J+fPwRAdzJ1m1cyyJVh+1QQG/BJdCSrXXI IDjWGAwXyWyIzuM/PQiLWd+vAdRPXOqXGmcFDGqWz3InYlIHKGyJg9/+fBVyiB6D8feZ Ggb0aTN056oyLgC/pFMhozgkoXT1L6bzlbSTysysbcCPF4A9Zjd+Ibp+W2qxFhsvJjSh LjDSGaSGSpcp3alepiMfGz/qgXFUHYZvwap9lHdRNp77+me9/mLgSWl3OEx+MGXy1qX+ sqCA== X-Gm-Message-State: APjAAAWBPXLFzWl83qq4e1Mm7hWNtgGdiNOEoCTwjZq2cvO4zAeETIPF VcugGSHaIasRnTZWT0huhn4OKbh+og== X-Google-Smtp-Source: APXvYqxKbTJyCFIBZujXQaKEuB5jG/yAObmaCy/Rej/VZ0agv+IbcgjoqKprp0GQA10BtOp6bNA5+A== X-Received: by 2002:a5b:286:: with SMTP id x6mr75061895ybl.92.1578336175599; Mon, 06 Jan 2020 10:42:55 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u136sm28223497ywf.101.2020.01.06.10.42.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:42:55 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 8/9] nfsd: Ensure sampling of the commit verifier is atomic with the commit Date: Mon, 6 Jan 2020 13:40:36 -0500 Message-Id: <20200106184037.563557-9-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106184037.563557-8-trond.myklebust@hammerspace.com> References: <20200106184037.563557-1-trond.myklebust@hammerspace.com> <20200106184037.563557-2-trond.myklebust@hammerspace.com> <20200106184037.563557-3-trond.myklebust@hammerspace.com> <20200106184037.563557-4-trond.myklebust@hammerspace.com> <20200106184037.563557-5-trond.myklebust@hammerspace.com> <20200106184037.563557-6-trond.myklebust@hammerspace.com> <20200106184037.563557-7-trond.myklebust@hammerspace.com> <20200106184037.563557-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 When we have a successful commit, ensure we sample the commit verifier before releasing the lock. Signed-off-by: Trond Myklebust --- fs/nfsd/nfs3proc.c | 3 ++- fs/nfsd/nfs3xdr.c | 8 ++------ fs/nfsd/nfs4proc.c | 4 ++-- fs/nfsd/vfs.c | 8 ++++++-- fs/nfsd/vfs.h | 2 +- fs/nfsd/xdr3.h | 1 + 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/fs/nfsd/nfs3proc.c b/fs/nfsd/nfs3proc.c index cea68d8411ac..ffdc592868a6 100644 --- a/fs/nfsd/nfs3proc.c +++ b/fs/nfsd/nfs3proc.c @@ -683,7 +683,8 @@ nfsd3_proc_commit(struct svc_rqst *rqstp) RETURN_STATUS(nfserr_inval); fh_copy(&resp->fh, &argp->fh); - nfserr = nfsd_commit(rqstp, &resp->fh, argp->offset, argp->count); + nfserr = nfsd_commit(rqstp, &resp->fh, argp->offset, argp->count, + resp->verf); RETURN_STATUS(nfserr); } diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c index 195ab7a0fc89..4aaa85f42da2 100644 --- a/fs/nfsd/nfs3xdr.c +++ b/fs/nfsd/nfs3xdr.c @@ -1125,16 +1125,12 @@ int nfs3svc_encode_commitres(struct svc_rqst *rqstp, __be32 *p) { struct nfsd3_commitres *resp = rqstp->rq_resp; - struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); - __be32 verf[2]; p = encode_wcc_data(rqstp, p, &resp->fh); /* Write verifier */ if (resp->status == 0) { - /* unique identifier, y2038 overflow can be ignored */ - nfsd_copy_boot_verifier(verf, nn); - *p++ = verf[0]; - *p++ = verf[1]; + *p++ = resp->verf[0]; + *p++ = resp->verf[1]; } return xdr_ressize_check(rqstp, p); } diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 7fce319e5b85..c24a4f96c973 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -581,9 +581,9 @@ nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, { struct nfsd4_commit *commit = &u->commit; - gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp)); return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, - commit->co_count); + commit->co_count, + (__be32 *)commit->co_verf.data); } static __be32 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index b2984a996ab8..1d69a1e78b03 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -1105,7 +1105,7 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, */ __be32 nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, - loff_t offset, unsigned long count) + loff_t offset, unsigned long count, __be32 *verf) { struct nfsd_file *nf; loff_t end = LLONG_MAX; @@ -1130,6 +1130,8 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, err2 = vfs_fsync_range(nf->nf_file, offset, end, 0); switch (err2) { case 0: + nfsd_copy_boot_verifier(verf, net_generic(nf->nf_net, + nfsd_net_id)); break; case -EINVAL: err = nfserr_notsupp; @@ -1140,7 +1142,9 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, nfsd_net_id)); } up_write(&nf->nf_rwsem); - } + } else + nfsd_copy_boot_verifier(verf, net_generic(nf->nf_net, + nfsd_net_id)); nfsd_file_put(nf); out: diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h index 69d23e9926cf..29e30688ccfb 100644 --- a/fs/nfsd/vfs.h +++ b/fs/nfsd/vfs.h @@ -74,7 +74,7 @@ __be32 do_nfsd_create(struct svc_rqst *, struct svc_fh *, struct svc_fh *res, int createmode, u32 *verifier, bool *truncp, bool *created); __be32 nfsd_commit(struct svc_rqst *, struct svc_fh *, - loff_t, unsigned long); + loff_t, unsigned long, __be32 *verf); #endif /* CONFIG_NFSD_V3 */ int nfsd_open_break_lease(struct inode *, int); __be32 nfsd_open(struct svc_rqst *, struct svc_fh *, umode_t, diff --git a/fs/nfsd/xdr3.h b/fs/nfsd/xdr3.h index 99ff9f403ff1..21fc1f14bcad 100644 --- a/fs/nfsd/xdr3.h +++ b/fs/nfsd/xdr3.h @@ -223,6 +223,7 @@ struct nfsd3_pathconfres { struct nfsd3_commitres { __be32 status; struct svc_fh fh; + __be32 verf[2]; }; struct nfsd3_getaclres { From patchwork Mon Jan 6 18:40:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11319831 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D01861395 for ; Mon, 6 Jan 2020 18:42:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A5F9B2146E for ; Mon, 6 Jan 2020 18:42:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="frvkONYD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbgAFSm6 (ORCPT ); Mon, 6 Jan 2020 13:42:58 -0500 Received: from mail-yb1-f196.google.com ([209.85.219.196]:40322 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726612AbgAFSm5 (ORCPT ); Mon, 6 Jan 2020 13:42:57 -0500 Received: by mail-yb1-f196.google.com with SMTP id a2so22483109ybr.7 for ; Mon, 06 Jan 2020 10:42:57 -0800 (PST) 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=k0Mecl0wn/2ijPTPmzXjwP8L0u+EXy9SIn0iPg0tEoY=; b=frvkONYDvlipInfJm/4y4xOBEyEVUwRvD//YO90w1+tMfsE3vtT+2QMQ6pLSZ7PcgR TqYLkHIV6prdrABNl1/kwf6fQ+HSC9FcVbhiQvHz27lzjDdxnhtRVGj0lhO2XOchFcV6 7wXAcnCDWDewrU2MSqZD211cm0G/JjF0/mX7eUcdCefsb+6QiUxYfWCz6I0Zdx4ot815 FqRpT1XmdqCn0GfQd1K+4q/AFDpJ6fYhm7r4kIWyvAP4th/5UmSh9LxSqPmr2dx9dEY7 i5RxztuJYo9ku+focQLqPYOM/HydOgB51xEEl2ffMyQrLiw8shfagN0EPDKgJ/IGFNNe T7vQ== 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=k0Mecl0wn/2ijPTPmzXjwP8L0u+EXy9SIn0iPg0tEoY=; b=uMfg1xaqiL/h1Uxh+c0h8JVQRpxnEtsujaXs525y9ddyPJzywEPBSmfupbsXtA8jCy z7YjuCethAGcUL4W0rEWoC7ezdFtxc30k3Bmr1aPMd6YisQ7cg7FRnumanivdqL5S6dT Z+0b+0sVEkesd/wRzdMjJPueUq+skO9sqNwza5/w+u5Omik6FkPap0sZ2XyFZVrEf0j+ 92dqkyAbZ4aS+ACnPwO7h13vIwJ6d0IOPPYsKniTLnOkKCoUNFHGmqjjo/84ewFgkQ00 rUCcoOjoalgXbl8OLkNkGbWQqm0s5UQ+NZZKkUTPMHg5+4L2t8yqtbtb3jDx2BoZc4H/ Cd2w== X-Gm-Message-State: APjAAAWfQOIom51m7FQS4stbKgYvQ5jFEyvuPUaLh7M4KEk6GN1kbcKr XgengFfUDPAXDjGVF1SQ1A== X-Google-Smtp-Source: APXvYqwCbftuIoe/V78clr1PfLhTcsim16yE0/B+8ha6peKqjJPotpWACwb9ZN6MMArf6W3BZnSEHg== X-Received: by 2002:a25:2557:: with SMTP id l84mr77933296ybl.217.1578336176676; Mon, 06 Jan 2020 10:42:56 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u136sm28223497ywf.101.2020.01.06.10.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 10:42:56 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 9/9] nfsd: Ensure sampling of the write verifier is atomic with the write Date: Mon, 6 Jan 2020 13:40:37 -0500 Message-Id: <20200106184037.563557-10-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106184037.563557-9-trond.myklebust@hammerspace.com> References: <20200106184037.563557-1-trond.myklebust@hammerspace.com> <20200106184037.563557-2-trond.myklebust@hammerspace.com> <20200106184037.563557-3-trond.myklebust@hammerspace.com> <20200106184037.563557-4-trond.myklebust@hammerspace.com> <20200106184037.563557-5-trond.myklebust@hammerspace.com> <20200106184037.563557-6-trond.myklebust@hammerspace.com> <20200106184037.563557-7-trond.myklebust@hammerspace.com> <20200106184037.563557-8-trond.myklebust@hammerspace.com> <20200106184037.563557-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 When doing an unstable write, we need to ensure that we sample the write verifier before releasing the lock, and allowing a commit to the same file to proceed. Signed-off-by: Trond Myklebust --- fs/nfsd/nfs3proc.c | 2 +- fs/nfsd/nfs3xdr.c | 8 ++------ fs/nfsd/nfs4proc.c | 4 ++-- fs/nfsd/nfsproc.c | 2 +- fs/nfsd/vfs.c | 12 +++++++++--- fs/nfsd/vfs.h | 5 +++-- fs/nfsd/xdr3.h | 1 + 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/fs/nfsd/nfs3proc.c b/fs/nfsd/nfs3proc.c index ffdc592868a6..288bc76b4574 100644 --- a/fs/nfsd/nfs3proc.c +++ b/fs/nfsd/nfs3proc.c @@ -203,7 +203,7 @@ nfsd3_proc_write(struct svc_rqst *rqstp) RETURN_STATUS(nfserr_io); nfserr = nfsd_write(rqstp, &resp->fh, argp->offset, rqstp->rq_vec, nvecs, &cnt, - resp->committed); + resp->committed, resp->verf); resp->count = cnt; RETURN_STATUS(nfserr); } diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c index 4aaa85f42da2..e1f6c65049b3 100644 --- a/fs/nfsd/nfs3xdr.c +++ b/fs/nfsd/nfs3xdr.c @@ -751,17 +751,13 @@ int nfs3svc_encode_writeres(struct svc_rqst *rqstp, __be32 *p) { struct nfsd3_writeres *resp = rqstp->rq_resp; - struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); - __be32 verf[2]; p = encode_wcc_data(rqstp, p, &resp->fh); if (resp->status == 0) { *p++ = htonl(resp->count); *p++ = htonl(resp->committed); - /* unique identifier, y2038 overflow can be ignored */ - nfsd_copy_boot_verifier(verf, nn); - *p++ = verf[0]; - *p++ = verf[1]; + *p++ = resp->verf[0]; + *p++ = resp->verf[1]; } return xdr_ressize_check(rqstp, p); } diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index c24a4f96c973..af2cb7dcb74c 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1006,7 +1006,6 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, } write->wr_how_written = write->wr_stable_how; - gen_boot_verifier(&write->wr_verifier, SVC_NET(rqstp)); nvecs = svc_fill_write_vector(rqstp, write->wr_pagelist, &write->wr_head, write->wr_buflen); @@ -1014,7 +1013,8 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf, write->wr_offset, rqstp->rq_vec, nvecs, &cnt, - write->wr_how_written); + write->wr_how_written, + (__be32 *)write->wr_verifier.data); nfsd_file_put(nf); write->wr_bytes_written = cnt; diff --git a/fs/nfsd/nfsproc.c b/fs/nfsd/nfsproc.c index c83ddac22f38..bb1fbb67f697 100644 --- a/fs/nfsd/nfsproc.c +++ b/fs/nfsd/nfsproc.c @@ -226,7 +226,7 @@ nfsd_proc_write(struct svc_rqst *rqstp) return nfserr_io; nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), argp->offset, rqstp->rq_vec, nvecs, - &cnt, NFS_DATA_SYNC); + &cnt, NFS_DATA_SYNC, NULL); return nfsd_return_attrs(nfserr, resp); } diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 1d69a1e78b03..8beed0fbf93a 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -962,7 +962,8 @@ static int wait_for_concurrent_writes(struct file *file) __be32 nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, loff_t offset, struct kvec *vec, int vlen, - unsigned long *cnt, int stable) + unsigned long *cnt, int stable, + __be32 *verf) { struct file *file = nf->nf_file; struct svc_export *exp; @@ -1004,6 +1005,10 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, up_write(&nf->nf_rwsem); } else { down_read(&nf->nf_rwsem); + if (verf) + nfsd_copy_boot_verifier(verf, + net_generic(SVC_NET(rqstp), + nfsd_net_id)); host_err = vfs_iter_write(file, &iter, &pos, flags); up_read(&nf->nf_rwsem); } @@ -1074,7 +1079,8 @@ __be32 nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp, */ __be32 nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, - struct kvec *vec, int vlen, unsigned long *cnt, int stable) + struct kvec *vec, int vlen, unsigned long *cnt, int stable, + __be32 *verf) { struct nfsd_file *nf; __be32 err; @@ -1086,7 +1092,7 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, goto out; err = nfsd_vfs_write(rqstp, fhp, nf, offset, vec, - vlen, cnt, stable); + vlen, cnt, stable, verf); nfsd_file_put(nf); out: trace_nfsd_write_done(rqstp, fhp, offset, *cnt); diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h index 29e30688ccfb..11a112617e91 100644 --- a/fs/nfsd/vfs.h +++ b/fs/nfsd/vfs.h @@ -94,11 +94,12 @@ __be32 nfsd_read(struct svc_rqst *, struct svc_fh *, loff_t, struct kvec *, int, unsigned long *, u32 *eof); __be32 nfsd_write(struct svc_rqst *, struct svc_fh *, loff_t, - struct kvec *, int, unsigned long *, int); + struct kvec *, int, unsigned long *, + int stable, __be32 *verf); __be32 nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, loff_t offset, struct kvec *vec, int vlen, unsigned long *cnt, - int stable); + int stable, __be32 *verf); __be32 nfsd_readlink(struct svc_rqst *, struct svc_fh *, char *, int *); __be32 nfsd_symlink(struct svc_rqst *, struct svc_fh *, diff --git a/fs/nfsd/xdr3.h b/fs/nfsd/xdr3.h index 21fc1f14bcad..fed959a809e8 100644 --- a/fs/nfsd/xdr3.h +++ b/fs/nfsd/xdr3.h @@ -159,6 +159,7 @@ struct nfsd3_writeres { struct svc_fh fh; unsigned long count; int committed; + __be32 verf[2]; }; struct nfsd3_renameres {