Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp2198878ybe; Sat, 7 Sep 2019 10:43:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5BgATAY3CFlI8MzbGachvwPopnrWWyag/2gcHzhBpo6LUavC/M+PIoay05YHELOfmifh2 X-Received: by 2002:a63:6d6:: with SMTP id 205mr13956072pgg.262.1567878188690; Sat, 07 Sep 2019 10:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567878188; cv=none; d=google.com; s=arc-20160816; b=xK8PtV8V/MEI7LKvm5/S3kEPQE/ew573wLOqYJCIw57GPCliwt1g/tNmj2RiQWRG9r h3AVHMY9AaIw05/V9ZGj55iWO+/vwxuC9VTcIGMf4SFMEkSjgJS6wvsDHAsJy5k34aUz lyNnQouywvntgnYtk7je/urMgqkKRkISfKZeUbfmqLoOdqIwZGHMYZWYRFByFBrKxdr1 cpjvACeEfXkTwWW6hqWH4zq79TF2x1/2SyBCsAdn57JlbcpOh/4CMBCQ4y+k3khx8BcG T+yPVZQ0bwWZeLeTKy34oH8Qg3+85gKPg3RknuTNBwDg6i+LPAAlmAFHyGZuC3ZKG4/W c+UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=nUiJA7pzR4QkYh2b5I6Ld0az+4QHqkg6mc9NxtzqC7w=; b=MtIc7608pnSihXJrRHcmS5ZI1hlv1Q6iq4dnYHxtr9UF3r/JZJnvLiYmdz1HqnaDAF FroeIO1lTc/g7DZh8vv5481X8Qh2NN0jZpxFLsHM9ct5Su6pGLtCLAoL9eisM+SeGZWl /1IM9jn3WskOlw8QoBgAuYizthYQC6DdaqOpZvASwHD5VuuQE7MC5jyDeRX/FLLbHuNX dwtA3UUOFqNy7ZH4+fytRF8KeJ47uXaSVeKzZFAf3WT0NwPIWThrjChlgBDV4ZKQ5Y/V 1T9oqs0ExzmoWAWrG2pKMMEdmvq0k2f2dd+FQ2Xipjo+GKS28RvwWM2z4A+CpnqJXthn qpbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=g+WjSQFv; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x16si7954931pln.98.2019.09.07.10.42.38; Sat, 07 Sep 2019 10:43:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=g+WjSQFv; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392349AbfIFTqk (ORCPT + 99 others); Fri, 6 Sep 2019 15:46:40 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:40353 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbfIFTqk (ORCPT ); Fri, 6 Sep 2019 15:46:40 -0400 Received: by mail-io1-f66.google.com with SMTP id h144so15381010iof.7 for ; Fri, 06 Sep 2019 12:46:39 -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; bh=nUiJA7pzR4QkYh2b5I6Ld0az+4QHqkg6mc9NxtzqC7w=; b=g+WjSQFvGuk3oDnMKLRzi+xax49MypDaEJoDSbGCZtK4scF/61p72yHe61T8aaR9l3 lqvIXa2hnZP4kboRozX6QQufhQFw/8OQlC+yU+OFBI3JPKXaefaQQYXq56Juk+vhEhmS 3K/rWMyThOJG7xgwMbvdKKO1pfxaAAFNuGHYEI0mBh0a7mWAv/1aEu+qWJev4+KIp0El wRYUkiq73DRhXj8+EPhjCG2o99sG9QhN85SclqAHhXeVyLBTGH/KGvnfpxEK9GNu/JZ8 uI31BP1h9MekMU7G/dK8YuEy4j9Z+N8fDg3QoHMU2BmyXcAt8NtV2qX6enPir7tUvr4D zwGQ== 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; bh=nUiJA7pzR4QkYh2b5I6Ld0az+4QHqkg6mc9NxtzqC7w=; b=bYBsaU1lQN3ESPvAp+7paV9VMjBLq5fOw7MTUdCDkNVHK7WHrfX2IZ9EsjNI3jKNfd dgUyzII3+xy5LeDvDoS2GPONhuRtDqG3sYRt19i/BorjUkEqU9Yw+GSIgdynwAENmcHR dD7ZK9MQYzN/nXWkWzi1Cag0cA35e1lZxDF8u1Hh2+FHoRugOb6jBh6NMwzJH4wUv/W8 1lU9dVzl5iRmn7nd0j9NNYVWQEpZnITbUj8xxX26Yis2sqt289QmocD1i678sbABXbAc BvYJVLScrMZCQ8WbpFrtKUjpj70hGIxw8KGvmFbXrsI0ISN0EbHDxEe1Yj+Eu6gz5IRd 8t0A== X-Gm-Message-State: APjAAAV3Pg2Ot/aIOyKcszVE1bHP4ipjNrj9zjTQm3Tap/NDzH4V5F/C aqpyvQhb4ygj7KL7rfHvfcY= X-Received: by 2002:a6b:bcc4:: with SMTP id m187mr12993766iof.16.1567799199108; Fri, 06 Sep 2019 12:46:39 -0700 (PDT) Received: from Olgas-MBP-201.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id i14sm5118085ioi.47.2019.09.06.12.46.38 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 06 Sep 2019 12:46:38 -0700 (PDT) From: Olga Kornievskaia To: trond.myklebust@hammerspace.com, anna.schumaker@netapp.com, bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v6 05/19] NFS: inter ssc open Date: Fri, 6 Sep 2019 15:46:17 -0400 Message-Id: <20190906194631.3216-6-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20190906194631.3216-1-olga.kornievskaia@gmail.com> References: <20190906194631.3216-1-olga.kornievskaia@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org NFSv4.2 inter server to server copy requires the destination server to READ the data from the source server using the provided stateid and file handle. Given an NFSv4 stateid and filehandle from the COPY operaion, provide the destination server with an NFS client function to create a struct file suitable for the destiniation server to READ the data to be copied. Signed-off-by: Olga Kornievskaia Signed-off-by: Andy Adamson --- fs/nfs/nfs4_fs.h | 7 +++++ fs/nfs/nfs4file.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/nfs4proc.c | 5 ++- 3 files changed, 103 insertions(+), 3 deletions(-) diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index 8e590b4..5f27942 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h @@ -311,6 +311,13 @@ extern int nfs4_set_rw_stateid(nfs4_stateid *stateid, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, fmode_t fmode); +extern int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, + struct nfs_fattr *fattr, struct nfs4_label *label, + struct inode *inode); +extern int update_open_stateid(struct nfs4_state *state, + const nfs4_stateid *open_stateid, + const nfs4_stateid *deleg_stateid, + fmode_t fmode); extern int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo); diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index b68b41b..1898262a 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "delegation.h" #include "internal.h" #include "iostat.h" @@ -286,6 +287,99 @@ static loff_t nfs42_remap_file_range(struct file *src_file, loff_t src_off, out: return ret < 0 ? ret : count; } + +static int read_name_gen = 1; +#define SSC_READ_NAME_BODY "ssc_read_%d" + +struct file * +nfs42_ssc_open(struct vfsmount *ss_mnt, struct nfs_fh *src_fh, + nfs4_stateid *stateid) +{ + struct nfs_fattr fattr; + struct file *filep, *res; + struct nfs_server *server; + struct inode *r_ino = NULL; + struct nfs_open_context *ctx; + struct nfs4_state_owner *sp; + char *read_name; + int len, status = 0; + + server = NFS_SERVER(ss_mnt->mnt_root->d_inode); + + nfs_fattr_init(&fattr); + + status = nfs4_proc_getattr(server, src_fh, &fattr, NULL, NULL); + if (status < 0) { + res = ERR_PTR(status); + goto out; + } + + res = ERR_PTR(-ENOMEM); + len = strlen(SSC_READ_NAME_BODY) + 16; + read_name = kzalloc(len, GFP_NOFS); + if (read_name == NULL) + goto out; + snprintf(read_name, len, SSC_READ_NAME_BODY, read_name_gen++); + + r_ino = nfs_fhget(ss_mnt->mnt_root->d_inode->i_sb, src_fh, &fattr, + NULL); + if (IS_ERR(r_ino)) { + res = ERR_CAST(r_ino); + goto out; + } + + filep = alloc_file_pseudo(r_ino, ss_mnt, read_name, FMODE_READ, + r_ino->i_fop); + if (IS_ERR(filep)) { + res = ERR_CAST(filep); + goto out; + } + filep->f_mode |= FMODE_READ; + + ctx = alloc_nfs_open_context(filep->f_path.dentry, filep->f_mode, + filep); + if (IS_ERR(ctx)) { + res = ERR_CAST(ctx); + goto out_filep; + } + + res = ERR_PTR(-EINVAL); + sp = nfs4_get_state_owner(server, ctx->cred, GFP_KERNEL); + if (sp == NULL) + goto out_ctx; + + ctx->state = nfs4_get_open_state(r_ino, sp); + if (ctx->state == NULL) + goto out_stateowner; + + set_bit(NFS_OPEN_STATE, &ctx->state->flags); + memcpy(&ctx->state->open_stateid.other, &stateid->other, + NFS4_STATEID_OTHER_SIZE); + update_open_stateid(ctx->state, stateid, NULL, filep->f_mode); + + nfs_file_set_open_context(filep, ctx); + put_nfs_open_context(ctx); + + file_ra_state_init(&filep->f_ra, filep->f_mapping->host->i_mapping); + res = filep; +out: + return res; +out_stateowner: + nfs4_put_state_owner(sp); +out_ctx: + put_nfs_open_context(ctx); +out_filep: + fput(filep); + goto out; +} +EXPORT_SYMBOL_GPL(nfs42_ssc_open); +void nfs42_ssc_close(struct file *filep) +{ + struct nfs_open_context *ctx = nfs_file_open_context(filep); + + ctx->state->flags = 0; +} +EXPORT_SYMBOL_GPL(nfs42_ssc_close); #endif /* CONFIG_NFS_V4_2 */ const struct file_operations nfs4_file_operations = { diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 5311def..7ea446b 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -91,7 +91,6 @@ static int _nfs4_recover_proc_open(struct nfs4_opendata *data); static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); -static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label, struct inode *inode); static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label, struct inode *inode); static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, struct nfs_fattr *fattr, struct iattr *sattr, @@ -1713,7 +1712,7 @@ static void nfs_state_clear_delegation(struct nfs4_state *state) write_sequnlock(&state->seqlock); } -static int update_open_stateid(struct nfs4_state *state, +int update_open_stateid(struct nfs4_state *state, const nfs4_stateid *open_stateid, const nfs4_stateid *delegation, fmode_t fmode) @@ -4026,7 +4025,7 @@ static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); } -static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, +int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label, struct inode *inode) { -- 1.8.3.1