From patchwork Mon Sep 16 20:44:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11147783 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 0AD5314ED for ; Mon, 16 Sep 2019 20:46:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC6F5206A4 for ; Mon, 16 Sep 2019 20:46:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H/y+Kzrc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727307AbfIPUq3 (ORCPT ); Mon, 16 Sep 2019 16:46:29 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:37380 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733156AbfIPUq3 (ORCPT ); Mon, 16 Sep 2019 16:46:29 -0400 Received: by mail-io1-f68.google.com with SMTP id b19so2341787iob.4 for ; Mon, 16 Sep 2019 13:46:28 -0700 (PDT) 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=u+xAWTrh/Lsv4sQba0rlaTvUNAip8h2KHmmPmv3mJ88=; b=H/y+KzrcAVu4Qc8SRgF0TYfxefcCwUAPGrFLdQ/DjbtdfTAtKaRqdijbI4YoH328Yi UEjsWrgg62m6WShjxyKhkxK3E06M08Xhwf8eDMKx6RIeLBdV70TJHd+hfBNZILVJgYAq WMojnVcs2MWYMJCPfqPOVqH13oxffNryw/N0G1KF0Dhtvp6dYeErU+u4c3kQcBdWYd3q kpMT6XwjZmP6L2GXHQ/ZbiUHzAAYHLYtY/I1bbW8bdTGu3GBEL+fGqiWSzEQx8xsaAw+ dM5CVyl0Oayz/7kPt1Q7dMh3FHpsso0NjHDee8s4j3LwGUuSM/2kTX0mWD4QgJA4IQG6 0W1A== 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=u+xAWTrh/Lsv4sQba0rlaTvUNAip8h2KHmmPmv3mJ88=; b=rO3SCORPVa5VyfIFvsBZQhsNdGvwle5hIGjOu71OF8nWtAkTT7+B+sEGOQrCKuiZTK h2plJchJmV8B0LfypQ0qanQ6pHFYAafoJTyFcpPCJf+KEgNNTwxzLVbkoNW9hjQaWKW/ FZDt6yWLyH8wIsgLgQCpAXaCfj0y3YfqK+oltrAktlpzHBn1RuWOycF0Fdh4i35QRADN b3c+NaEdaO58HlS127+pK90EfM8okBgGIlvnxAtICFIUawzg0cvB2E8is7kBumks09VF rGoLqi/ryjDbA3hD3Dq8PvnJBqmuWT6bBe8n7sAqwQlLxdH+HXwiraDEKzdF3VHJLIi3 cWaA== X-Gm-Message-State: APjAAAUwZGIYKDhni4e14Yfl7hfLytvshtIQHFEHIzEKMEyh2mNzxz1c 5ssOH4hbC+FQR9FwHCkzdA== X-Google-Smtp-Source: APXvYqzvV71DKHmIU7Ns1BbkO99NQpPpiOVUfzlKX/0m6DYa298aadnCRKSN5qAdsf9z7bYMp1NTCw== X-Received: by 2002:a6b:f311:: with SMTP id m17mr280679ioh.0.1568666788118; Mon, 16 Sep 2019 13:46:28 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id c6sm3528iom.34.2019.09.16.13.46.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 13:46:27 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v2 1/9] pNFS: Ensure we do clear the return-on-close layout stateid on fatal errors Date: Mon, 16 Sep 2019 16:44:11 -0400 Message-Id: <20190916204419.21717-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916204419.21717-1-trond.myklebust@hammerspace.com> References: <20190916204419.21717-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 IF the server rejected our layout return with a state error such as NFS4ERR_BAD_STATEID, or even a stale inode error, then we do want to clear out all the remaining layout segments and mark that stateid as invalid. Fixes: 1c5bd76d17cca ("pNFS: Enable layoutreturn operation for...") Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 4525d5acae38..0418b198edd3 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1449,10 +1449,15 @@ void pnfs_roc_release(struct nfs4_layoutreturn_args *args, const nfs4_stateid *res_stateid = NULL; struct nfs4_xdr_opaque_data *ld_private = args->ld_private; - if (ret == 0) { - arg_stateid = &args->stateid; + switch (ret) { + case -NFS4ERR_NOMATCHING_LAYOUT: + break; + case 0: if (res->lrs_present) res_stateid = &res->stateid; + /* Fallthrough */ + default: + arg_stateid = &args->stateid; } pnfs_layoutreturn_free_lsegs(lo, arg_stateid, &args->range, res_stateid); From patchwork Mon Sep 16 20:44:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11147787 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 0326A1747 for ; Mon, 16 Sep 2019 20:46:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C9423206A4 for ; Mon, 16 Sep 2019 20:46:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MLaM254j" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387766AbfIPUqb (ORCPT ); Mon, 16 Sep 2019 16:46:31 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:46588 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387671AbfIPUqb (ORCPT ); Mon, 16 Sep 2019 16:46:31 -0400 Received: by mail-io1-f65.google.com with SMTP id d17so2176271ios.13 for ; Mon, 16 Sep 2019 13:46:29 -0700 (PDT) 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=NYN5Bd9Dd0vS7p9p+LtozvKO/VbaMtj9Dt0A4GBDoyM=; b=MLaM254jQ17Dzcgr86mdcoSvJtglWC2z7sj94p3TG3f8BsblOn3PzWOOpMGuO6Ghhp qMyvyxFvVWDVDZ6ifzfx0zIP6VxSni9pSH/CovogTBe3vG65rHSS/PMpnprh4K0f2qC2 cxcsE1OqBMssQcA/h/XNJKANaDwayz5WiUpOaogN1w+748ZvTv5RyDDXEtJgihitvqMJ jekD9BYHmzeY7pHOgnM5N9rI5iEMGnOcMSDq8NC+C7tUeK/eGotl0lrohVjYJh03p0IU e9UZoKNvqE/ZdCPzTfwlFM2AIIJdVGvrIJxb4w1oTkMhkIYd+QU5vdaI5Lz1TO9KxF/y G5Sw== 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=NYN5Bd9Dd0vS7p9p+LtozvKO/VbaMtj9Dt0A4GBDoyM=; b=CjXWSsJsOnKHIB7nBLezjKEOVqAc2lBT/RqpgHBfaPmxXG0nPtNwgudpAJsqrg3FxT TIL59VCBm7h4PsQNkPuEAwmp6DI4fJfBVnVA+83i45S3iajLIBltGJwFdI8dPZB6RZKA TNvWUtTf/qZTcrlRQ7OfpORnnipAd18+9cOR7WFkR8LXMxEYAzG0weDgxM0WScHY3pz7 2nFSjuJVXdebB7wMOj1UOe/O32kP2M0KCqhW7bOHBO5E+Cz5uROn0muxCuN5DGSt52o0 ssYz9DmpxgYvC2rlDc6qdpQUo82alteGqMwuUL/AAqXFJRIbIPKiPMUfSeVnr880O0dp yIZA== X-Gm-Message-State: APjAAAXBgJVTCIiHFycxR6WFz6NV7pot/6pYbksOIg/pxZpCrQ2S3ysu 5W1kRuV5IhXIWypEWOvL8dvM3iQrgg== X-Google-Smtp-Source: APXvYqz92hRHYarLCn/7E80V8a9oiRf/jYeco1EXQRitg4x4VSgfDIwRW7vP6LHu89p+QCFPa83mLA== X-Received: by 2002:a6b:b2c3:: with SMTP id b186mr261627iof.128.1568666788846; Mon, 16 Sep 2019 13:46:28 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id c6sm3528iom.34.2019.09.16.13.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 13:46:28 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v2 2/9] NFSv4: Clean up pNFS return-on-close error handling Date: Mon, 16 Sep 2019 16:44:12 -0400 Message-Id: <20190916204419.21717-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916204419.21717-2-trond.myklebust@hammerspace.com> References: <20190916204419.21717-1-trond.myklebust@hammerspace.com> <20190916204419.21717-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 Both close and delegreturn have identical code to handle pNFS return-on-close. This patch refactors that code and places it in pnfs.c Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 66 +++++++---------------------------------------- fs/nfs/pnfs.c | 27 +++++++++++++++++++ fs/nfs/pnfs.h | 13 ++++++++++ 3 files changed, 50 insertions(+), 56 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 1406858bae6c..fcdfddfd3ab4 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -3358,32 +3358,11 @@ static void nfs4_close_done(struct rpc_task *task, void *data) trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); /* Handle Layoutreturn errors */ - if (calldata->arg.lr_args && task->tk_status != 0) { - switch (calldata->res.lr_ret) { - default: - calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; - break; - case 0: - calldata->arg.lr_args = NULL; - calldata->res.lr_res = NULL; - break; - case -NFS4ERR_OLD_STATEID: - if (nfs4_layoutreturn_refresh_stateid(&calldata->arg.lr_args->stateid, - &calldata->arg.lr_args->range, - calldata->inode)) - goto lr_restart; - /* Fallthrough */ - case -NFS4ERR_ADMIN_REVOKED: - case -NFS4ERR_DELEG_REVOKED: - case -NFS4ERR_EXPIRED: - case -NFS4ERR_BAD_STATEID: - case -NFS4ERR_UNKNOWN_LAYOUTTYPE: - case -NFS4ERR_WRONG_CRED: - calldata->arg.lr_args = NULL; - calldata->res.lr_res = NULL; - goto lr_restart; - } - } + if (pnfs_roc_done(task, calldata->inode, + &calldata->arg.lr_args, + &calldata->res.lr_res, + &calldata->res.lr_ret) == -EAGAIN) + goto out_restart; /* hmm. we are done with the inode, and in the process of freeing * the state_owner. we keep this around to process errors @@ -3430,8 +3409,6 @@ static void nfs4_close_done(struct rpc_task *task, void *data) nfs_refresh_inode(calldata->inode, &calldata->fattr); dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); return; -lr_restart: - calldata->res.lr_ret = 0; out_restart: task->tk_status = 0; rpc_restart_call_prepare(task); @@ -6129,32 +6106,11 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); /* Handle Layoutreturn errors */ - if (data->args.lr_args && task->tk_status != 0) { - switch(data->res.lr_ret) { - default: - data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; - break; - case 0: - data->args.lr_args = NULL; - data->res.lr_res = NULL; - break; - case -NFS4ERR_OLD_STATEID: - if (nfs4_layoutreturn_refresh_stateid(&data->args.lr_args->stateid, - &data->args.lr_args->range, - data->inode)) - goto lr_restart; - /* Fallthrough */ - case -NFS4ERR_ADMIN_REVOKED: - case -NFS4ERR_DELEG_REVOKED: - case -NFS4ERR_EXPIRED: - case -NFS4ERR_BAD_STATEID: - case -NFS4ERR_UNKNOWN_LAYOUTTYPE: - case -NFS4ERR_WRONG_CRED: - data->args.lr_args = NULL; - data->res.lr_res = NULL; - goto lr_restart; - } - } + if (pnfs_roc_done(task, data->inode, + &data->args.lr_args, + &data->res.lr_res, + &data->res.lr_ret) == -EAGAIN) + goto out_restart; switch (task->tk_status) { case 0: @@ -6192,8 +6148,6 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) } data->rpc_status = task->tk_status; return; -lr_restart: - data->res.lr_ret = 0; out_restart: task->tk_status = 0; rpc_restart_call_prepare(task); diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 0418b198edd3..8769422a12f5 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1440,6 +1440,33 @@ bool pnfs_roc(struct inode *ino, return false; } +int pnfs_roc_done(struct rpc_task *task, struct inode *inode, + struct nfs4_layoutreturn_args **argpp, + struct nfs4_layoutreturn_res **respp, + int *ret) +{ + struct nfs4_layoutreturn_args *arg = *argpp; + int retval = -EAGAIN; + + if (!arg) + return 0; + /* Handle Layoutreturn errors */ + switch (*ret) { + case 0: + retval = 0; + break; + case -NFS4ERR_OLD_STATEID: + if (!nfs4_layoutreturn_refresh_stateid(&arg->stateid, + &arg->range, inode)) + break; + *ret = -NFS4ERR_NOMATCHING_LAYOUT; + return -EAGAIN; + } + *argpp = NULL; + *respp = NULL; + return retval; +} + void pnfs_roc_release(struct nfs4_layoutreturn_args *args, struct nfs4_layoutreturn_res *res, int ret) diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h index f15609c003d8..3ef3756d437c 100644 --- a/fs/nfs/pnfs.h +++ b/fs/nfs/pnfs.h @@ -282,6 +282,10 @@ bool pnfs_roc(struct inode *ino, struct nfs4_layoutreturn_args *args, struct nfs4_layoutreturn_res *res, const struct cred *cred); +int pnfs_roc_done(struct rpc_task *task, struct inode *inode, + struct nfs4_layoutreturn_args **argpp, + struct nfs4_layoutreturn_res **respp, + int *ret); void pnfs_roc_release(struct nfs4_layoutreturn_args *args, struct nfs4_layoutreturn_res *res, int ret); @@ -701,6 +705,15 @@ pnfs_roc(struct inode *ino, return false; } +static inline int +pnfs_roc_done(struct rpc_task *task, struct inode *inode, + struct nfs4_layoutreturn_args **argpp, + struct nfs4_layoutreturn_res **respp, + int *ret) +{ + return 0; +} + static inline void pnfs_roc_release(struct nfs4_layoutreturn_args *args, struct nfs4_layoutreturn_res *res, From patchwork Mon Sep 16 20:44:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11147785 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 7DB0314ED for ; Mon, 16 Sep 2019 20:46:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C302206A4 for ; Mon, 16 Sep 2019 20:46:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hQceF6fh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387682AbfIPUqa (ORCPT ); Mon, 16 Sep 2019 16:46:30 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:45443 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387596AbfIPUqa (ORCPT ); Mon, 16 Sep 2019 16:46:30 -0400 Received: by mail-io1-f67.google.com with SMTP id f12so2197679iog.12 for ; Mon, 16 Sep 2019 13:46:30 -0700 (PDT) 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=J/GVnqkPBoCv5U4dJF5GCvANtn9QnHDChOd9TrjN6yM=; b=hQceF6fhAx1xDuK/qwPYfUSsgcui+y/THlOsBNucaKBBVhJ5DmuoLAFqFcTXAbCNl3 hEo5NlLGpe6y+PE6IjgnyH+enwCN2JUKXXmD5WOXDCpFZCUy4Moj9Rf1/7D4fJOomeEN V77Z9LHgUVyZa4f7AHklCaeRSsgrVcwd/C/61Xe0Dj7kFnl154KEIGyKUho08Md08r/g LtIaKqTAO0r3fyza3TPFtsaFggt8EB+SuM+JyzCXAeaaxnMhF5nclTV0udArZKLfV/XX sjPDbbEMnSV5lK4153y7MM0Lo1juH2ep81GGZOhKwbacjPaAYj9mI+Lq6XMQ2PW0gAZ/ aeEA== 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=J/GVnqkPBoCv5U4dJF5GCvANtn9QnHDChOd9TrjN6yM=; b=jvOPq2PBBOJs4stX4BDc60EojWQgEScIscMG/QZS5/NxfH8YqY7LaF3m/I6xxu1D6f A/dTMUL2HE4LwajL2dKzf4IB7ZOOsOpJVurZOWwk6qvHQiLu107fEGZXCmj8Y6F6ZIP2 sBsp2QPhX8JpKOtuvRs5nPs2Pwfb1c7Gy4pBQbb0r8rzBADthF6X+5VUcVIGLOWfGBtl DVFPoU0b5MP+x4vnFQ5/R9wjRaMY0vpWGGg9pYSMX192z6kmIFVZ9uNawa815aMB2E8a hKg/5ym9YD5VCYgnk0jj5PCbh7d1DIaEAAmELz27fEwz/VEIuEGvy1oQ1AePTsgFhC3K TFRA== X-Gm-Message-State: APjAAAWm2gTq5gN6/zS0RTs8YB2U5lDQuSKUvSLVzhJ2n1f2sIlkEp3b jmECU5TPHwwyrX5nkjLqKw== X-Google-Smtp-Source: APXvYqwXxqI9I2I3BLVa9C4mLjWAUGW0PaQFmpeAL/7Bn9+12oNt5wSq5BA3pCi8eel3nCD8ExbH3g== X-Received: by 2002:a5d:861a:: with SMTP id f26mr212959iol.197.1568666789617; Mon, 16 Sep 2019 13:46:29 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id c6sm3528iom.34.2019.09.16.13.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 13:46:29 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v2 3/9] NFSv4: Handle NFS4ERR_DELAY correctly in return-on-close Date: Mon, 16 Sep 2019 16:44:13 -0400 Message-Id: <20190916204419.21717-4-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916204419.21717-3-trond.myklebust@hammerspace.com> References: <20190916204419.21717-1-trond.myklebust@hammerspace.com> <20190916204419.21717-2-trond.myklebust@hammerspace.com> <20190916204419.21717-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 If the server sends a NFS4ERR_DELAY, then allow the caller to retry. Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 8769422a12f5..6436047dc999 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1455,6 +1455,10 @@ int pnfs_roc_done(struct rpc_task *task, struct inode *inode, case 0: retval = 0; break; + case -NFS4ERR_DELAY: + /* Let the caller handle the retry */ + *ret = -NFS4ERR_NOMATCHING_LAYOUT; + return 0; case -NFS4ERR_OLD_STATEID: if (!nfs4_layoutreturn_refresh_stateid(&arg->stateid, &arg->range, inode)) From patchwork Mon Sep 16 20:44:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11147789 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 629BC14E5 for ; Mon, 16 Sep 2019 20:46:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 42C09206A4 for ; Mon, 16 Sep 2019 20:46:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ppE39HEE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387671AbfIPUqb (ORCPT ); Mon, 16 Sep 2019 16:46:31 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:39176 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387596AbfIPUqb (ORCPT ); Mon, 16 Sep 2019 16:46:31 -0400 Received: by mail-io1-f65.google.com with SMTP id a1so2296852ioc.6 for ; Mon, 16 Sep 2019 13:46:31 -0700 (PDT) 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=mT/Rzj/K1U6LEdiuCQ0lI11+dkVn7b9E0XXmRpME0Iw=; b=ppE39HEEXYbaQ/RycPKzxYIsPFUvcZx03OP1d2jxgYKzBDh71zVuXf9nrAnIqrG0ZP wsdnF/bosFRXssrP+MY22p52wpB3ut/t0zKalsfBVP3XvQfAPpWlNOidmsVKJj4HEN+c 89TIaRHGdFJHYw+0vKo0wsU78vhoYqQVQH1HDK309xTZvplS4xt/aesHJI0BiGfVyYzY PhFrp4eNUzCJh8JM2WbGZN4Rl49RBYmI3gthXYjshHzuxlONjSgarO+gvVCCvPv/qTx8 qrGKfjf4qzwDVtsY7aE0vKRX6XseTpeIHlvfXSn2eK0BoXUwbNlaxfZOV4vmAe6TSzGU e60A== 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=mT/Rzj/K1U6LEdiuCQ0lI11+dkVn7b9E0XXmRpME0Iw=; b=je3smfDlvbUDiQlJ3OdQ/SjpgNaw7IhKpY8fmZ61q8p4/ae1ORj9XO28Ma4Gz/fM89 McdWJk+w7NrVLOPs10dYGeFHC5ITR9laY+pG2TnsEyH4HU8dvdSzxklAVkYJ/4ZaQm/i 7w+yFti1QmOzlFLMBwkV9mpGA8Wp+z00bhGFJ+42XpSSMFsX3Qhb7C3tBm5oT7VPcSJZ JhXDxTb/mW0hTjUcurOPg/Y5OVp4279VtEZdS1iWasZ2ze/9ClFbHHlQHDe175gm3TtG HOLAjySN5C5uOMogx84P3UBIOVxEPOgMsXHKBEk3+t6mQos/PJOEPcLf5L3LVWNyofh1 Z7Bg== X-Gm-Message-State: APjAAAWwFmlRnKod9PF9Tfrh/8qljuRufVFerPSKo5URtk5HdcBg03FO YWDBd9ri1qGq1IPnhrsROA== X-Google-Smtp-Source: APXvYqwbuNRZHpigaByCk14TWw3JAvaYPfUWctBtVHiC64WR8YmKclVxECeUWMZYBgmL9ald3y/SjA== X-Received: by 2002:a5d:85da:: with SMTP id e26mr223223ios.101.1568666790358; Mon, 16 Sep 2019 13:46:30 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id c6sm3528iom.34.2019.09.16.13.46.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 13:46:29 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v2 4/9] NFSv4: Handle RPC level errors in LAYOUTRETURN Date: Mon, 16 Sep 2019 16:44:14 -0400 Message-Id: <20190916204419.21717-5-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916204419.21717-4-trond.myklebust@hammerspace.com> References: <20190916204419.21717-1-trond.myklebust@hammerspace.com> <20190916204419.21717-2-trond.myklebust@hammerspace.com> <20190916204419.21717-3-trond.myklebust@hammerspace.com> <20190916204419.21717-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 Handle RPC level errors by assuming that the RPC call was successful. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 9 +++++++++ fs/nfs/pnfs.c | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index fcdfddfd3ab4..a5deb00b5ad1 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -9057,6 +9057,15 @@ static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) if (!nfs41_sequence_process(task, &lrp->res.seq_res)) return; + /* + * Was there an RPC level error? Assume the call succeeded, + * and that we need to release the layout + */ + if (task->tk_rpc_status != 0 && RPC_WAS_SENT(task)) { + lrp->res.lrs_present = 0; + return; + } + server = NFS_SERVER(lrp->args.inode); switch (task->tk_status) { case -NFS4ERR_OLD_STATEID: diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 6436047dc999..abc7188f1853 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1455,6 +1455,21 @@ int pnfs_roc_done(struct rpc_task *task, struct inode *inode, case 0: retval = 0; break; + case -NFS4ERR_NOMATCHING_LAYOUT: + /* Was there an RPC level error? If not, retry */ + if (task->tk_rpc_status == 0) + break; + /* If the call was not sent, let caller handle it */ + if (!RPC_WAS_SENT(task)) + return 0; + /* + * Otherwise, assume the call succeeded and + * that we need to release the layout + */ + *ret = 0; + (*respp)->lrs_present = 0; + retval = 0; + break; case -NFS4ERR_DELAY: /* Let the caller handle the retry */ *ret = -NFS4ERR_NOMATCHING_LAYOUT; From patchwork Mon Sep 16 20:44:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11147791 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 70DB514ED for ; Mon, 16 Sep 2019 20:46:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4FE39206A4 for ; Mon, 16 Sep 2019 20:46:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MyHmdb/n" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387596AbfIPUqc (ORCPT ); Mon, 16 Sep 2019 16:46:32 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:39180 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733156AbfIPUqc (ORCPT ); Mon, 16 Sep 2019 16:46:32 -0400 Received: by mail-io1-f65.google.com with SMTP id a1so2296946ioc.6 for ; Mon, 16 Sep 2019 13:46:32 -0700 (PDT) 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=owbPNNcxjT5XKu6v3G4mEstWx8051g6tPkh8ytztNTM=; b=MyHmdb/n26VD6LgAUwgE/tpuztM2eJ8jOk9xRQ5awqpVNLVb1tAos7V+hO3s1DXLol UhzRyhdLyOq7iT1buBndKffWNb2y1HmV07nNfrFqS9TF+xkDoRN77+9KTTY36q98RsFu Jy42EKPJbUE5LxjCtycj5e3SrmmRSK1KSlUdI18B7UFC4OYi55kBANV08dcHe8MOq41n UGQ+eKEqR+EgVJ784NvDlqooQOJIVvdw4GBUm9bChpuiZwHJeIo6PyNQvFzCJiGIGORC FP0D37lSXxc8znysvwmCXcOOOj+J/82UaXqaf+6cbNAQNsQaObjZeMJh4nDpZ4ba9rWI d4NQ== 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=owbPNNcxjT5XKu6v3G4mEstWx8051g6tPkh8ytztNTM=; b=gyYb64X/yVkp7Ev3dusn8xsxuMROy9sEIYnaNbKVMEvhfQ0FR7Cgb2o61uqFy4THTc geUNcxCCdfyRmYnpAAb6tgu1hfRhtldJ8bLcxEq/stPOyBPRtxShmdXZnRPcYKHFjz09 I6p83eUEJlqMLRlrCnPrp2isfnkG8L/f9wJlRiT8jyU8zQyN/OAB6YB1cebWUxDFR6P9 51SHsaJFrQhlNeUHBmuVNpBC+kBeU5+qKY+Z8eYNZJ2YTazq/esX2CP3/u/0hEgmi5QE EooZEleJRlczMeY4cIaicVkl/tiDP618GeYSLiU0MwEU5Ik2TlHVqjk6Ia/CwGjrT3Rr 7WIQ== X-Gm-Message-State: APjAAAX3SfcQLhFu1YZBQ9+rL1ooFw7f5oYO4pfoSbixUjTtNGX4R6vW g0+P36Etq8o0TMISJScioA== X-Google-Smtp-Source: APXvYqwCFaLI1q4hXtXBp94pCVD7+ywIvJooeTd/Sa/mFdhTRwhwjP6D0LZPGeBjuGT+pMsoqjnwBQ== X-Received: by 2002:a6b:4a01:: with SMTP id w1mr232275iob.222.1568666791419; Mon, 16 Sep 2019 13:46:31 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id c6sm3528iom.34.2019.09.16.13.46.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 13:46:30 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v2 5/9] NFSv4: Add a helper to increment stateid seqids Date: Mon, 16 Sep 2019 16:44:15 -0400 Message-Id: <20190916204419.21717-6-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916204419.21717-5-trond.myklebust@hammerspace.com> References: <20190916204419.21717-1-trond.myklebust@hammerspace.com> <20190916204419.21717-2-trond.myklebust@hammerspace.com> <20190916204419.21717-3-trond.myklebust@hammerspace.com> <20190916204419.21717-4-trond.myklebust@hammerspace.com> <20190916204419.21717-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 Add a helper function to increment stateid seqids according to the rules specified in RFC5661 Section 8.2.2. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4_fs.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index 3564da1ba8a1..e8f74ed98e42 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h @@ -574,6 +574,15 @@ static inline bool nfs4_stateid_is_newer(const nfs4_stateid *s1, const nfs4_stat return (s32)(be32_to_cpu(s1->seqid) - be32_to_cpu(s2->seqid)) > 0; } +static inline void nfs4_stateid_seqid_inc(nfs4_stateid *s1) +{ + u32 seqid = be32_to_cpu(s1->seqid); + + if (++seqid == 0) + ++seqid; + s1->seqid = cpu_to_be32(seqid); +} + static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state) { return test_bit(NFS_STATE_RECOVERY_FAILED, &state->flags) == 0; From patchwork Mon Sep 16 20:44:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11147793 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 C088314ED for ; Mon, 16 Sep 2019 20:46:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9CE8D206A4 for ; Mon, 16 Sep 2019 20:46:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gMxS5jiU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387800AbfIPUqe (ORCPT ); Mon, 16 Sep 2019 16:46:34 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:34477 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733156AbfIPUqd (ORCPT ); Mon, 16 Sep 2019 16:46:33 -0400 Received: by mail-io1-f68.google.com with SMTP id q1so2391746ion.1 for ; Mon, 16 Sep 2019 13:46:33 -0700 (PDT) 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=yyGDQpMVH1rTLSPHW8HYSc7W3EA/zyjV2dF3PYsHi3Q=; b=gMxS5jiUJ3WEa/Ytk9JtjYVsgPfWh0HSGOCijKwH0IaAPuPTmZbp2FDD4QdmMXTR4j gBxmEthqmKNDpF6RXpqa7G1oyWwPT89UGV0Xy+duoHF3Vndu04XMYFY7HGTwhtrJ5eKA /2Lyh7y/wTAk6kmVqL5gVPkMpaSk9IpbD4CCVtuqg5tkZgcHMJtO2gnhxyRYZ5NeaSaI +ldrC1552yXf/Atcz0sQxTCbYZI96rqxCwIxTXvS+oryD+YVnGvQvNRS2mUb7O9OO2pl Ijl8q3nUjsy5feaagYli9TFVRVDbx9HsHxqf8fqGWayMpIT7DKg4shJLlIASMz7CKqz7 F/Hw== 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=yyGDQpMVH1rTLSPHW8HYSc7W3EA/zyjV2dF3PYsHi3Q=; b=mPDUFFgAJfRH8UmI5oSt8NNbfueUAtZv8MoQmjWvvxjDgA3P4f93RQ0jTm26Sl/jW8 9d4G5g6y8OwoH9Zpf/zKTZYOa6iRAy+aZW/xrpzvjrE6shNRXq/pA6jFV4HZ0aGySPp0 aeRifUKpJ9Ykubm1KPtRWEFsep9c8rVFVLmYVk5FXKfmfGJjBqM7bb7PMUVNGvQn1BKC ifTEchEDPzfP80Y1dNnRPLu345szCVHZGvwshN0YTdFjP6BIo+2qAl2CGSLyonOyMi35 3NP0aNA1GWEz0p9OY6BaH3s4VmgemerLsf10f2+F5+fFK822A5UBLiKmqQV25RUlHfqY Dfog== X-Gm-Message-State: APjAAAVdWpQGau9j3KEeRc9gMgnI/dCSrU/rFlphINhHYOm6Yfve9ob4 tdcdEDbDUGnl+F6OzxHGLQ== X-Google-Smtp-Source: APXvYqzyacEanqFQQQ+vcwvNkDJwvu07G/fpB1SS9gohpiMss/vqRXqUxyO6k9j4a/b9Ri4nA/+mGg== X-Received: by 2002:a6b:1787:: with SMTP id 129mr263688iox.140.1568666792487; Mon, 16 Sep 2019 13:46:32 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id c6sm3528iom.34.2019.09.16.13.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 13:46:31 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v2 6/9] pNFS: Handle NFS4ERR_OLD_STATEID on layoutreturn by bumping the state seqid Date: Mon, 16 Sep 2019 16:44:16 -0400 Message-Id: <20190916204419.21717-7-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916204419.21717-6-trond.myklebust@hammerspace.com> References: <20190916204419.21717-1-trond.myklebust@hammerspace.com> <20190916204419.21717-2-trond.myklebust@hammerspace.com> <20190916204419.21717-3-trond.myklebust@hammerspace.com> <20190916204419.21717-4-trond.myklebust@hammerspace.com> <20190916204419.21717-5-trond.myklebust@hammerspace.com> <20190916204419.21717-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 If a LAYOUTRETURN receives a reply of NFS4ERR_OLD_STATEID then assume we've missed an update, and just bump the stateid. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 2 +- fs/nfs/pnfs.c | 18 ++++++++++++++---- fs/nfs/pnfs.h | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index a5deb00b5ad1..cbaf6b7ac128 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -9069,7 +9069,7 @@ static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) server = NFS_SERVER(lrp->args.inode); switch (task->tk_status) { case -NFS4ERR_OLD_STATEID: - if (nfs4_layoutreturn_refresh_stateid(&lrp->args.stateid, + if (nfs4_layout_refresh_old_stateid(&lrp->args.stateid, &lrp->args.range, lrp->args.inode)) goto out_restart; diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index abc7188f1853..bb80034a7661 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -359,9 +359,10 @@ pnfs_clear_lseg_state(struct pnfs_layout_segment *lseg, } /* - * Update the seqid of a layout stateid + * Update the seqid of a layout stateid after receiving + * NFS4ERR_OLD_STATEID */ -bool nfs4_layoutreturn_refresh_stateid(nfs4_stateid *dst, +bool nfs4_layout_refresh_old_stateid(nfs4_stateid *dst, struct pnfs_layout_range *dst_range, struct inode *inode) { @@ -377,7 +378,15 @@ bool nfs4_layoutreturn_refresh_stateid(nfs4_stateid *dst, spin_lock(&inode->i_lock); lo = NFS_I(inode)->layout; - if (lo && nfs4_stateid_match_other(dst, &lo->plh_stateid)) { + if (lo && pnfs_layout_is_valid(lo) && + nfs4_stateid_match_other(dst, &lo->plh_stateid)) { + /* Is our call using the most recent seqid? If so, bump it */ + if (!nfs4_stateid_is_newer(&lo->plh_stateid, dst)) { + nfs4_stateid_seqid_inc(dst); + ret = true; + goto out; + } + /* Try to update the seqid to the most recent */ err = pnfs_mark_matching_lsegs_return(lo, &head, &range, 0); if (err != -EBUSY) { dst->seqid = lo->plh_stateid.seqid; @@ -385,6 +394,7 @@ bool nfs4_layoutreturn_refresh_stateid(nfs4_stateid *dst, ret = true; } } +out: spin_unlock(&inode->i_lock); pnfs_free_lseg_list(&head); return ret; @@ -1475,7 +1485,7 @@ int pnfs_roc_done(struct rpc_task *task, struct inode *inode, *ret = -NFS4ERR_NOMATCHING_LAYOUT; return 0; case -NFS4ERR_OLD_STATEID: - if (!nfs4_layoutreturn_refresh_stateid(&arg->stateid, + if (!nfs4_layout_refresh_old_stateid(&arg->stateid, &arg->range, inode)) break; *ret = -NFS4ERR_NOMATCHING_LAYOUT; diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h index 3ef3756d437c..f8a38065c7e4 100644 --- a/fs/nfs/pnfs.h +++ b/fs/nfs/pnfs.h @@ -261,7 +261,7 @@ int pnfs_destroy_layouts_byfsid(struct nfs_client *clp, bool is_recall); int pnfs_destroy_layouts_byclid(struct nfs_client *clp, bool is_recall); -bool nfs4_layoutreturn_refresh_stateid(nfs4_stateid *dst, +bool nfs4_layout_refresh_old_stateid(nfs4_stateid *dst, struct pnfs_layout_range *dst_range, struct inode *inode); void pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo); @@ -798,7 +798,7 @@ static inline void nfs4_pnfs_v3_ds_connect_unload(void) { } -static inline bool nfs4_layoutreturn_refresh_stateid(nfs4_stateid *dst, +static inline bool nfs4_layout_refresh_old_stateid(nfs4_stateid *dst, struct pnfs_layout_range *dst_range, struct inode *inode) { From patchwork Mon Sep 16 20:44:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11147795 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 7431214E5 for ; Mon, 16 Sep 2019 20:46:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 51883206A4 for ; Mon, 16 Sep 2019 20:46:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="O8sSYwON" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387856AbfIPUqe (ORCPT ); Mon, 16 Sep 2019 16:46:34 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:37404 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387796AbfIPUqe (ORCPT ); Mon, 16 Sep 2019 16:46:34 -0400 Received: by mail-io1-f67.google.com with SMTP id b19so2342333iob.4 for ; Mon, 16 Sep 2019 13:46:33 -0700 (PDT) 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=tm3Z204lhcQueHhZs5vFp/leKoUofNIJTGBebGTHcyI=; b=O8sSYwONTZCAlzWfm3VUd7zcnha2h957yO0p5/dMqBxsQ5/FCm00iONVd44wrQOqEL xRfVs828YC/V7qgF3hzFkJxUrqGyV2AejN2FrEs4gdHCELBNiLnbvpelJaB55F8n5jog oXwdZcBNv3+Kp7IrV63W8br32wOatuitLTJuQGeVJc0NTTYxqjKgUfZrS6wa+a33w3Eq 5Ic6yHor36y53ZdCViTJhP87uhCntCmRrexH5XLYDceKD8LGIpZg8wPa0yMf1wthdG55 FTIDjA0NLKpmkWnDjsc+foDt5+uKsXkAJ4hrR494N05xUzgSH4O+7J/Bu0JCY/F5YRJ5 cvGQ== 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=tm3Z204lhcQueHhZs5vFp/leKoUofNIJTGBebGTHcyI=; b=GUT1ieDDRH7vOR35vg5KVolMmiZVNKj59wKX1V4rFRD1fAaQe0krq5D2NFGGadjt3I AN++0VJIosjE+V/mTdbVcBB+iWnFwfb+WydO0JpCgX2okmhFhIpeYTYodMM7zpLmdv/4 hXHGqszKLRNxjf2nxC0GiKOlf6tfYRG4SzvWqE6b1nKbMjE/3r7ZxqMsSDvu5O+VLK0x 3tk0/hBLg+ks3dkJnn69vAYbAW5PcJsE22+Ap+VxRA+RLyVaDFofHB5H4gKeYdEWavEb 1RLCl6IQHUIETYDvkCshKbihlMhpD8bMTJedoo9ox0HVdTkbIVUFV52p3LOGvtq6gvVA WdRQ== X-Gm-Message-State: APjAAAWxRGl2W87cQuMfoZivST3J8z+GjbIyjAZfFsy44rJaOtsrx3TU y8+PWf0+fjf518IP92UOTA== X-Google-Smtp-Source: APXvYqyFEAEhfSWjuLcQvP9J3I+tizH5gudTZBCoFrvEOSIdlhvsO2FZ1irGWevC3e2x/G1tgeD6uw== X-Received: by 2002:a6b:3906:: with SMTP id g6mr282823ioa.48.1568666793262; Mon, 16 Sep 2019 13:46:33 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id c6sm3528iom.34.2019.09.16.13.46.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 13:46:32 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v2 7/9] NFSv4: Fix OPEN_DOWNGRADE error handling Date: Mon, 16 Sep 2019 16:44:17 -0400 Message-Id: <20190916204419.21717-8-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916204419.21717-7-trond.myklebust@hammerspace.com> References: <20190916204419.21717-1-trond.myklebust@hammerspace.com> <20190916204419.21717-2-trond.myklebust@hammerspace.com> <20190916204419.21717-3-trond.myklebust@hammerspace.com> <20190916204419.21717-4-trond.myklebust@hammerspace.com> <20190916204419.21717-5-trond.myklebust@hammerspace.com> <20190916204419.21717-6-trond.myklebust@hammerspace.com> <20190916204419.21717-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 If OPEN_DOWNGRADE returns a state error, then we want to initiate state recovery in addition to marking the stateid as closed. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index cbaf6b7ac128..025dd5efbf34 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -3394,7 +3394,9 @@ static void nfs4_close_done(struct rpc_task *task, void *data) task->tk_msg.rpc_cred); /* Fallthrough */ case -NFS4ERR_BAD_STATEID: - break; + if (calldata->arg.fmode == 0) + break; + /* Fallthrough */ default: task->tk_status = nfs4_async_handle_exception(task, server, task->tk_status, &exception); From patchwork Mon Sep 16 20:44:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11147797 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 AE3D514E5 for ; Mon, 16 Sep 2019 20:46:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 80C8A20644 for ; Mon, 16 Sep 2019 20:46:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iT0Qif5j" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733255AbfIPUqf (ORCPT ); Mon, 16 Sep 2019 16:46:35 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:39192 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733156AbfIPUqf (ORCPT ); Mon, 16 Sep 2019 16:46:35 -0400 Received: by mail-io1-f65.google.com with SMTP id a1so2297240ioc.6 for ; Mon, 16 Sep 2019 13:46:34 -0700 (PDT) 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=dKBtfXBDb2I4SIWkL8RbGSdtWIaBiUXWBZYasSgkTuM=; b=iT0Qif5jqj6WB6v4kVzkV10QlNu/4nPhtNaNv+5zjs9KTSDpIs3HLj0F8ZvnFP7FeE CYhzF3OIv3+nCd78Y0VtMGVKX5L4If3zf9oH8z/cGCGLErcNllwQ8qbVngdU0WiJvOaF v3Vm7uSX4iP3w8C9/FybbZDL2EPqVySl2QYfEf4xyElD+hIalefszfLVx8/P6HRmmH5C b2TKPR9N/zPh7uQN35PX4FBMWbhcLk8PnMXk9D+c+fNi1I6yQvuBSepGEJUjhQlth5jN VHr+KNW4N7byDPKzrGvw3wFX6mSzLETnSfU0Jlba5g69tm2fpZrGyKE0Sc0xCr5DBQGT Az6g== 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=dKBtfXBDb2I4SIWkL8RbGSdtWIaBiUXWBZYasSgkTuM=; b=I9ATI2nZGZ5QBFdDWkLwxyIS6Lt1ojBKEys1nVmsvzdcbCgOEefK3Ccd5+Nm7/yf+e NZ4gI0V3E0J6zlqMDM2hihdyhQoKo0rdji4nqBOwQesSKNZiXAK5bRjzdstSD8WSLAfx FGgiHTmTqPlUCwrnDyevbg3kjYCR88w6M4pdY6FOccj9wUGwUoiNN29uMkrcacxykosg Nm7K7u8WadM6wXetyOCeWMO0lowuOqXYip3NcYV8no0hTI2bed7+b2zh9NaxPbUpP+9+ bb7Yo/7r2sgZXsNhHODdZ5ELDAWan09ld1BFY+SNyuF60DuZw/aJpFB/bYi2+628C9Sf E37Q== X-Gm-Message-State: APjAAAVJFmCjnuXLei3KnqqV987s/PAb0o/8l8V3pcQRALMlmYow1UqL MQk2KzdkAJ40ImtA/fADBSe3Z1dIWw== X-Google-Smtp-Source: APXvYqyMsqKS7rzsM4AiyhEuYt4OSmZS4bohObkQSHIXVg87uzkzGOEEivrcc9TMvuQz+jTngONaQw== X-Received: by 2002:a5e:8b43:: with SMTP id z3mr276306iom.114.1568666793990; Mon, 16 Sep 2019 13:46:33 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id c6sm3528iom.34.2019.09.16.13.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 13:46:33 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v2 8/9] NFSv4: Handle NFS4ERR_OLD_STATEID in CLOSE/OPEN_DOWNGRADE Date: Mon, 16 Sep 2019 16:44:18 -0400 Message-Id: <20190916204419.21717-9-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916204419.21717-8-trond.myklebust@hammerspace.com> References: <20190916204419.21717-1-trond.myklebust@hammerspace.com> <20190916204419.21717-2-trond.myklebust@hammerspace.com> <20190916204419.21717-3-trond.myklebust@hammerspace.com> <20190916204419.21717-4-trond.myklebust@hammerspace.com> <20190916204419.21717-5-trond.myklebust@hammerspace.com> <20190916204419.21717-6-trond.myklebust@hammerspace.com> <20190916204419.21717-7-trond.myklebust@hammerspace.com> <20190916204419.21717-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 If a CLOSE or OPEN_DOWNGRADE operation receives a NFS4ERR_OLD_STATEID then bump the seqid before resending. Ensure we only bump the seqid by 1. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4_fs.h | 2 -- fs/nfs/nfs4proc.c | 75 ++++++++++++++++++++++++++++++++++++++++++++-- fs/nfs/nfs4state.c | 16 ---------- 3 files changed, 72 insertions(+), 21 deletions(-) diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index e8f74ed98e42..16b2e5cc3e94 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h @@ -491,8 +491,6 @@ extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t, const struct nfs_lock_context *, nfs4_stateid *, const struct cred **); -extern bool nfs4_refresh_open_stateid(nfs4_stateid *dst, - struct nfs4_state *state); extern bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state); diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 025dd5efbf34..c14af2c1c6b6 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -3308,6 +3308,75 @@ nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) return pnfs_wait_on_layoutreturn(inode, task); } +/* + * Update the seqid of an open stateid + */ +static void nfs4_sync_open_stateid(nfs4_stateid *dst, + struct nfs4_state *state) +{ + __be32 seqid_open; + u32 dst_seqid; + int seq; + + for (;;) { + if (!nfs4_valid_open_stateid(state)) + break; + seq = read_seqbegin(&state->seqlock); + if (!nfs4_state_match_open_stateid_other(state, dst)) { + nfs4_stateid_copy(dst, &state->open_stateid); + if (read_seqretry(&state->seqlock, seq)) + continue; + break; + } + seqid_open = state->open_stateid.seqid; + if (read_seqretry(&state->seqlock, seq)) + continue; + + dst_seqid = be32_to_cpu(dst->seqid); + if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0) + dst->seqid = seqid_open; + break; + } +} + +/* + * Update the seqid of an open stateid after receiving + * NFS4ERR_OLD_STATEID + */ +static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst, + struct nfs4_state *state) +{ + __be32 seqid_open; + u32 dst_seqid; + bool ret; + int seq; + + for (;;) { + ret = false; + if (!nfs4_valid_open_stateid(state)) + break; + seq = read_seqbegin(&state->seqlock); + if (!nfs4_state_match_open_stateid_other(state, dst)) { + if (read_seqretry(&state->seqlock, seq)) + continue; + break; + } + seqid_open = state->open_stateid.seqid; + if (read_seqretry(&state->seqlock, seq)) + continue; + + dst_seqid = be32_to_cpu(dst->seqid); + if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) >= 0) + dst->seqid = cpu_to_be32(dst_seqid + 1); + else + dst->seqid = seqid_open; + ret = true; + break; + } + + return ret; +} + struct nfs4_closedata { struct inode *inode; struct nfs4_state *state; @@ -3382,7 +3451,7 @@ static void nfs4_close_done(struct rpc_task *task, void *data) break; case -NFS4ERR_OLD_STATEID: /* Did we race with OPEN? */ - if (nfs4_refresh_open_stateid(&calldata->arg.stateid, + if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid, state)) goto out_restart; goto out_release; @@ -3451,8 +3520,8 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) } else if (is_rdwr) calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; - if (!nfs4_valid_open_stateid(state) || - !nfs4_refresh_open_stateid(&calldata->arg.stateid, state)) + nfs4_sync_open_stateid(&calldata->arg.stateid, state); + if (!nfs4_valid_open_stateid(state)) call_close = 0; spin_unlock(&state->owner->so_lock); diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index cad4e064b328..e23945174da4 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c @@ -1015,22 +1015,6 @@ static int nfs4_copy_lock_stateid(nfs4_stateid *dst, return ret; } -bool nfs4_refresh_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) -{ - bool ret; - int seq; - - do { - ret = false; - seq = read_seqbegin(&state->seqlock); - if (nfs4_state_match_open_stateid_other(state, dst)) { - dst->seqid = state->open_stateid.seqid; - ret = true; - } - } while (read_seqretry(&state->seqlock, seq)); - return ret; -} - bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) { bool ret; From patchwork Mon Sep 16 20:44:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11147799 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 760FA14ED for ; Mon, 16 Sep 2019 20:46:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 54E91206A4 for ; Mon, 16 Sep 2019 20:46:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bANDj+Bb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733156AbfIPUqg (ORCPT ); Mon, 16 Sep 2019 16:46:36 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:45469 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733128AbfIPUqg (ORCPT ); Mon, 16 Sep 2019 16:46:36 -0400 Received: by mail-io1-f66.google.com with SMTP id f12so2198281iog.12 for ; Mon, 16 Sep 2019 13:46:35 -0700 (PDT) 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=426706+FlYC3v0VZqCIDoAzzSSKZhgN5MXl6xlGWijs=; b=bANDj+BbdbZWv/66Ppod+FT6LjyN9dWPwLG1lruyg/yhrJps3kuXAo47fF832iAJgP lAcvbhH6Xtx+W/eP+i1/FfpXVdXpA7lce8Y71URjU5y6qsNnmTOyooIhOlzO0GwVzQsI uS8dqyq7EU0J/RL8AVVrDLj19Gz38/CacgdVhKUb+auj75FOTa27abVFNqWdS/pff+H8 FW8AXEtQmbH4BTBnIRZKxZSeopH6cqLCfvIA5nN+SdOEwRJmEWGEF7GEEal09SvYsxAZ OaaILzWrU2EavcUPx1SX5H1X+PHhghblcvHSAslJ7KD/1kifBeiQZtuqipJqcRCI4DxM ocJg== 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=426706+FlYC3v0VZqCIDoAzzSSKZhgN5MXl6xlGWijs=; b=nT/UevhbjnVopml9JyTd39DFIx+1O/qP9p+HcVvrVlNnbleHdGk4pyjb6JaIpZpvzh YoOLDXjGaPHqRY3Lq14tET0ALipk99I5B9wli9cBZdoVxUkR9Nv94RCmfAfvm7MR9TTB gcdWGLlNNqKPFnxayInSNBiY/ytxJpRU0rGSkphVlkPxBqDLQg/MQ6huvc06C7A+PyyC Hb2a8preh2Q+hhM63R54g/tvUOjUf75mRpCbeu4W/uvgSXYyPjHUvvhVazsVypi1TsvQ 1ivtlkjpnmYAcXsC4bsekQ7H650EGp86aywNfa6cxVS0/jz6EQGtyI/4dnWo9mRLduhz Z6rA== X-Gm-Message-State: APjAAAWaNGPqMDrHjwVjk1OQQJLBcT9sny0twl/RxXGj7UROgoIZgX5T qYQ/2B7jUjWe6hqqaMnbPg== X-Google-Smtp-Source: APXvYqy8Z/MY9HZgv5A+iibQxWapEKnJcYE3LosYUvp8RvqDpH7QFY+ud3lgQ1COtHFAyM9u93OeDQ== X-Received: by 2002:a6b:3c0a:: with SMTP id k10mr242248iob.282.1568666794710; Mon, 16 Sep 2019 13:46:34 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id c6sm3528iom.34.2019.09.16.13.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 13:46:34 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v2 9/9] NFSv4: Handle NFS4ERR_OLD_STATEID in LOCKU Date: Mon, 16 Sep 2019 16:44:19 -0400 Message-Id: <20190916204419.21717-10-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916204419.21717-9-trond.myklebust@hammerspace.com> References: <20190916204419.21717-1-trond.myklebust@hammerspace.com> <20190916204419.21717-2-trond.myklebust@hammerspace.com> <20190916204419.21717-3-trond.myklebust@hammerspace.com> <20190916204419.21717-4-trond.myklebust@hammerspace.com> <20190916204419.21717-5-trond.myklebust@hammerspace.com> <20190916204419.21717-6-trond.myklebust@hammerspace.com> <20190916204419.21717-7-trond.myklebust@hammerspace.com> <20190916204419.21717-8-trond.myklebust@hammerspace.com> <20190916204419.21717-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 If a LOCKU request receives a NFS4ERR_OLD_STATEID, then bump the seqid before resending. Ensure we only bump the seqid by 1. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 48 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index c14af2c1c6b6..2fe6f8737023 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -6411,6 +6411,42 @@ static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock * return err; } +/* + * Update the seqid of a lock stateid after receiving + * NFS4ERR_OLD_STATEID + */ +static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst, + struct nfs4_lock_state *lsp) +{ + struct nfs4_state *state = lsp->ls_state; + bool ret = false; + + spin_lock(&state->state_lock); + if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid)) + goto out; + if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst)) + nfs4_stateid_seqid_inc(dst); + else + dst->seqid = lsp->ls_stateid.seqid; + ret = true; +out: + spin_unlock(&state->state_lock); + return ret; +} + +static bool nfs4_sync_lock_stateid(nfs4_stateid *dst, + struct nfs4_lock_state *lsp) +{ + struct nfs4_state *state = lsp->ls_state; + bool ret; + + spin_lock(&state->state_lock); + ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid); + nfs4_stateid_copy(dst, &lsp->ls_stateid); + spin_unlock(&state->state_lock); + return ret; +} + struct nfs4_unlockdata { struct nfs_locku_args arg; struct nfs_locku_res res; @@ -6444,6 +6480,7 @@ static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, locks_init_lock(&p->fl); locks_copy_lock(&p->fl, fl); p->server = NFS_SERVER(inode); + nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid); return p; } @@ -6482,10 +6519,14 @@ static void nfs4_locku_done(struct rpc_task *task, void *data) task->tk_msg.rpc_cred); /* Fall through */ case -NFS4ERR_BAD_STATEID: - case -NFS4ERR_OLD_STATEID: case -NFS4ERR_STALE_STATEID: - if (!nfs4_stateid_match(&calldata->arg.stateid, - &calldata->lsp->ls_stateid)) + if (nfs4_sync_lock_stateid(&calldata->arg.stateid, + calldata->lsp)) + rpc_restart_call_prepare(task); + break; + case -NFS4ERR_OLD_STATEID: + if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid, + calldata->lsp)) rpc_restart_call_prepare(task); break; default: @@ -6508,7 +6549,6 @@ static void nfs4_locku_prepare(struct rpc_task *task, void *data) if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) goto out_wait; - nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { /* Note: exit _without_ running nfs4_locku_done */ goto out_no_action;