Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1183455rwd; Sat, 20 May 2023 14:39:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4C9HA/Vy7h0BjEB8ebSuwD279pMdL8lmkXF39vklYBL7GucvEbd8YvsVXl4CXLjws6GZwB X-Received: by 2002:a05:6a20:12d3:b0:103:3885:3738 with SMTP id v19-20020a056a2012d300b0010338853738mr7352277pzg.19.1684618747154; Sat, 20 May 2023 14:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684618747; cv=none; d=google.com; s=arc-20160816; b=C52eF9dpPi9DasIs2rxile2XE4SMxi0gwubJJwW3dZFlfmpXmxkgsUyubyr8eULhmC 13/pK4MXFKN2KNXjMXC2R1zRxmdyo+TJJJC9XtltE5f4tOTVJ8fDbUUbOmV76197gr8x F6h2KRmoU/mdiU6rqZ7ViI5/pm9jEvyEzKX5auqFtFDos87JotgXlgTc9J+QfD3gBXGF IUyS3kvQsCTbnGZxB75OAOcwo1OzLh9zb7ZfjkaaYDcpyzZTr+r0ZXOas2EYTaUTqciH JiA9HPFM7NYdmI0OSpF/DcxVxzV3ep3p3qOl6EK6lRKfa7uzJhNAYG61/YcVC1Hcpe+Y rLGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=FEI1eQUp0kWImsC9LR9KOwOIMD0Cj1cL43HKtV5CyBc=; b=L65UTXACN/wR8WlgYe5JYzYp1eUZexQl2JqeCEUwTdZAurUxtUzCt2lzU0jB+o7y1f HZzFwFDE8QBGEWPpozUVzUh4tQCtAJwa0+tWOmGnU3wohL49keEr+P+B2LBk0PiyJ7c5 9OTYjHHrAHwIVbZOCULXjuALicfC4jpP/os6/Lzlzf64cBWfQT3lGN/7nTnFFiQ0meGZ dm6Wl5WiZ7YNmaZx9XHMeSAPBRDvYpKLeu3k9zS/O3k0AC1I7J8S2tuwxuQrdK5//Hk+ x3s7JJPDLvfi2Jz0DYzFOvP8pasiw8FzlkTPJSmm3OEtSolb8qDJQWQ9rn/oovyzrRLd U2hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=dL0czhPS; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z22-20020a63b916000000b0053045acfebdsi2120854pge.34.2023.05.20.14.38.52; Sat, 20 May 2023 14:39:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=dL0czhPS; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229662AbjETVhA (ORCPT + 99 others); Sat, 20 May 2023 17:37:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbjETVg5 (ORCPT ); Sat, 20 May 2023 17:36:57 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF416E9; Sat, 20 May 2023 14:36:56 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34KLUbdC002300; Sat, 20 May 2023 21:36:49 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-03-30; bh=FEI1eQUp0kWImsC9LR9KOwOIMD0Cj1cL43HKtV5CyBc=; b=dL0czhPSXpPhL4X0aZz1IrQdYN2BTnfMsDnl4hzyUg/Oj8DJRD9SKAsVOAMkqQhaiNSh kticHHuK3cX+fY9aUK+9a9ChVvL9iQr/XFQDPqp/G22vWT+yLbMclpTrTIdMVyd/U4P9 heOf7+X5IOALzF3JxSWp8gzyG9VxUv4j+1EBX+pnaOncvyaVbVFYu7Me15FxCEi4pZF1 iZ6j1Kgdmt+XkNrAxt0R4m97pp5z+UU3+8gQFEZSHZfF+3Ibv+ydFIZ7L950F7vhQhGh OWp3cZyvlkswSf3Bs7/RCYJwkqx2Jd7XIALfqbsVVdRGZgso4LX1jw0WJc24axgssZgJ 5A== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp420nc5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 20 May 2023 21:36:49 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34KGE0IJ011165; Sat, 20 May 2023 21:36:47 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3qpmn82h4n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 20 May 2023 21:36:47 +0000 Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34KLajTp030297; Sat, 20 May 2023 21:36:47 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3qpmn82h46-3; Sat, 20 May 2023 21:36:47 +0000 From: Dai Ngo To: chuck.lever@oracle.com, jlayton@kernel.org Cc: linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 2/4] NFSD: enable support for write delegation Date: Sat, 20 May 2023 14:36:33 -0700 Message-Id: <1684618595-4178-3-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1684618595-4178-1-git-send-email-dai.ngo@oracle.com> References: <1684618595-4178-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-20_14,2023-05-17_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 malwarescore=0 suspectscore=0 adultscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305200192 X-Proofpoint-ORIG-GUID: jowcoDm3o6FBHmnoRow6KItGtKBp6Lcr X-Proofpoint-GUID: jowcoDm3o6FBHmnoRow6KItGtKBp6Lcr X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This patch grants write delegation for OPEN with NFS4_SHARE_ACCESS_WRITE if there is no conflict with other OPENs. Write delegation conflict with another OPEN, REMOVE, RENAME and SETATTR are handled the same as read delegation using notify_change, try_break_deleg. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 6e61fa3acaf1..3f98b7485c72 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1144,7 +1144,7 @@ static void block_delegations(struct knfsd_fh *fh) static struct nfs4_delegation * alloc_init_deleg(struct nfs4_client *clp, struct nfs4_file *fp, - struct nfs4_clnt_odstate *odstate) + struct nfs4_clnt_odstate *odstate, u32 dl_type) { struct nfs4_delegation *dp; long n; @@ -1170,7 +1170,7 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_file *fp, INIT_LIST_HEAD(&dp->dl_recall_lru); dp->dl_clnt_odstate = odstate; get_clnt_odstate(odstate); - dp->dl_type = NFS4_OPEN_DELEGATE_READ; + dp->dl_type = dl_type; dp->dl_retries = 1; dp->dl_recalled = false; nfsd4_init_cb(&dp->dl_recall, dp->dl_stid.sc_client, @@ -5451,6 +5451,7 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, struct nfs4_delegation *dp; struct nfsd_file *nf; struct file_lock *fl; + u32 dl_type; /* * The fi_had_conflict and nfs_get_existing_delegation checks @@ -5460,7 +5461,13 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, if (fp->fi_had_conflict) return ERR_PTR(-EAGAIN); - nf = find_readable_file(fp); + if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) { + nf = find_writeable_file(fp); + dl_type = NFS4_OPEN_DELEGATE_WRITE; + } else { + nf = find_readable_file(fp); + dl_type = NFS4_OPEN_DELEGATE_READ; + } if (!nf) { /* * We probably could attempt another open and get a read @@ -5491,11 +5498,11 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, return ERR_PTR(status); status = -ENOMEM; - dp = alloc_init_deleg(clp, fp, odstate); + dp = alloc_init_deleg(clp, fp, odstate, dl_type); if (!dp) goto out_delegees; - fl = nfs4_alloc_init_lease(dp, NFS4_OPEN_DELEGATE_READ); + fl = nfs4_alloc_init_lease(dp, dl_type); if (!fl) goto out_clnt_odstate; @@ -5590,8 +5597,6 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, case NFS4_OPEN_CLAIM_PREVIOUS: if (!cb_up) open->op_recall = 1; - if (open->op_delegate_type != NFS4_OPEN_DELEGATE_READ) - goto out_no_deleg; break; case NFS4_OPEN_CLAIM_NULL: parent = currentfh; @@ -5617,7 +5622,10 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, memcpy(&open->op_delegate_stateid, &dp->dl_stid.sc_stateid, sizeof(dp->dl_stid.sc_stateid)); trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid); - open->op_delegate_type = NFS4_OPEN_DELEGATE_READ; + if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) + open->op_delegate_type = NFS4_OPEN_DELEGATE_WRITE; + else + open->op_delegate_type = NFS4_OPEN_DELEGATE_READ; nfs4_put_stid(&dp->dl_stid); return; out_no_deleg: -- 2.9.5