Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp175064rwd; Wed, 17 May 2023 16:44:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4KGubeeIjylIDdSEqLbcRuiXjgUJENUuugY04mMSwdfwUTzJuECCCEGHsdZ/xFusgHxbvA X-Received: by 2002:a17:90b:38c:b0:24d:ec16:6f8c with SMTP id ga12-20020a17090b038c00b0024dec166f8cmr578290pjb.20.1684367077070; Wed, 17 May 2023 16:44:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684367077; cv=none; d=google.com; s=arc-20160816; b=1KP1V5h3CpenRbTWOEP2MSWwFXTPrnpxg5DnvGGx0m2GV+xpo+9/1X2OFxtICCkbQD 5ZXWkx5lpWipTOsOty+55LggP1Ml6r0olWY5J6bekEwYC3NOD+Dz2JWBstaa1LGGK2aT WyuyhxFuoTqNZyuaBK+swmhsmTZ/HEiOVskcF/fT8vmD8Z8H29dNFEEYbW/zeSWdy2AL k8dUWd3abOAyOjiBiF9oIT5hzuLh0nhbK2jbJTtw8pIo7RlT//DqzCU23ho4Ke2qN6uz HNd3+fT6HqeVjlZEP9H+69WzJ4YgJ03HUxMgppCXNgQKz+pjDYYd1boiukAmYcAGfzmD Pa1w== 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=13yFsu/hc2QefBrXwXw9AQoe32PXPPNvjMgyb8bREfE=; b=k3OhhIA5oDf+jbSYChVtPRFL1o5VyGaj8blyjyqAXIYctoFh7uho9Ea1KqNo+Jbwau qeN9j4NV9t0LmVMVls1L77/zjNpIRYLrfp12tFHyfgNBTls6N11vclxi/cNpxSvcPp8v TGHNd+T4N60072BsgvNBAB96OcjsZJHfeodQYRKH9meCIYJbVl2EwiKyiJu3mcp1w6gv yUOrJ9IJdG894KbZyAfusKncCmfdFPB2pIdeskleSXRxgefsga4zYg6Ochvbqd2Uh7fK g7ckUqHAyVRizNIhyXM3gUMZDNTvXf/jHIcVhwZs4CCBybDkdtvroZgfbS7FAeM+bO3W EwCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=0OZNozKm; 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 h14-20020a17090a470e00b0024df9561b5asi251370pjg.143.2023.05.17.16.44.15; Wed, 17 May 2023 16:44:37 -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=0OZNozKm; 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 S229457AbjEQXjX (ORCPT + 99 others); Wed, 17 May 2023 19:39:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjEQXjV (ORCPT ); Wed, 17 May 2023 19:39:21 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08F2046B7; Wed, 17 May 2023 16:39:16 -0700 (PDT) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34HIGocf018161; Wed, 17 May 2023 23:39:13 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=13yFsu/hc2QefBrXwXw9AQoe32PXPPNvjMgyb8bREfE=; b=0OZNozKmFSE+hL5S9Ki2xYKxnsWDxbQ65Bw7+VCu377pIGZC+5oeKsONAw5VzTVBRy9M +bQfWrDfngAfW+Qe2KrGsUPQp5Swi1CdJLd8IpWQ/W5H1zp5Brqanxu7MytXLWZS+F7K kXnecqdESdEzeWu8JktBYbSZ95VNmMjxB1+Nn9ZkgonFcRjXKJsq49i/iaQDUGjz+U4E RJLv7fxm47sKr8O71DsuQuBt/WolG7/K9jRa9n8/db7c2xClAGRbITFTo2fVZXA05+pm 3zIm0WUVu63P6WVd6zwy+kPqmuuYcK1qzCF0FhIrR3T1yN82vgEqM2WPmF0G1oHAppYr 7A== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qj0ye6q8a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 May 2023 23:39:13 +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 34HN94Qs032131; Wed, 17 May 2023 23:39:13 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3qj10c3umj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 May 2023 23:39:13 +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 34HNdABl015880; Wed, 17 May 2023 23:39:12 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 3qj10c3u5n-3; Wed, 17 May 2023 23:39:12 +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 v3 2/2] NFSD: enable support for write delegation Date: Wed, 17 May 2023 16:38:10 -0700 Message-Id: <1684366690-28029-3-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1684366690-28029-1-git-send-email-dai.ngo@oracle.com> References: <1684366690-28029-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-17_04,2023-05-17_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 spamscore=0 bulkscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305170194 X-Proofpoint-ORIG-GUID: d7PWcoDHnUI4-tmHszg440bs8Yt6zc7G X-Proofpoint-GUID: d7PWcoDHnUI4-tmHszg440bs8Yt6zc7G 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, RCVD_IN_MSPIKE_H2,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..09a9e16407f9 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 deleg; /* * 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); + deleg = NFS4_OPEN_DELEGATE_WRITE; + } else { + nf = find_readable_file(fp); + deleg = 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, deleg); if (!dp) goto out_delegees; - fl = nfs4_alloc_init_lease(dp, NFS4_OPEN_DELEGATE_READ); + fl = nfs4_alloc_init_lease(dp, deleg); if (!fl) goto out_clnt_odstate; @@ -5583,6 +5590,7 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, struct svc_fh *parent = NULL; int cb_up; int status = 0; + u32 wdeleg = false; cb_up = nfsd4_cb_channel_good(oo->oo_owner.so_client); open->op_recall = 0; @@ -5590,8 +5598,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 +5623,9 @@ 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; + wdeleg = open->op_share_access & NFS4_SHARE_ACCESS_WRITE; + open->op_delegate_type = wdeleg ? + NFS4_OPEN_DELEGATE_WRITE : NFS4_OPEN_DELEGATE_READ; nfs4_put_stid(&dp->dl_stid); return; out_no_deleg: -- 2.9.5