Skip to contentSkip to conversation

NFS fix the setting of exchange id flag

PATCH In review [email protected] 2 participants 2 messages Dec 3, 2010 – Dec 7, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFS fix the setting of exchange id flag

From: Andy Adamson <[email protected]>

Indicate support for referrals. Do not set any PNFS roles. Check the flags returned by the server for validity. Do not use exchange flags from an old client ID instance when recovering a client ID.

---
 fs/nfs/nfs4proc.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)
fs/nfs/nfs4proc.c +19 -4
index c244000..e77a2b9 100644
@@ -4494,6 +4494,23 @@ int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
 
 #ifdef CONFIG_NFS_V4_1
 /*
+ * Check the exchange flags returned by the server for invalid flags, having
+ * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
+ * DS flags set.
+ */
+static int nfs4_check_cl_exchange_flags(u32 flags)
+{
+	if (flags & ~EXCHGID4_FLAG_MASK_R ||
+	    (flags & EXCHGID4_FLAG_USE_PNFS_MDS &&
+	     flags & EXCHGID4_FLAG_USE_NON_PNFS) ||
+	    (!(flags & (EXCHGID4_FLAG_USE_PNFS_MDS |
+			EXCHGID4_FLAG_USE_NON_PNFS |
+			EXCHGID4_FLAG_USE_PNFS_DS))))
+		return NFS4ERR_INVAL;
+	return NFS_OK;
+}
+
+/*
  * nfs4_proc_exchange_id()
  *
  * Since the clientid has expired, all compounds using sessions
@@ -4506,7 +4523,7 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
 	nfs4_verifier verifier;
 	struct nfs41_exchange_id_args args = {
 		.client = clp,
-		.flags = clp->cl_exchange_flags,
+		.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER,
 	};
 	struct nfs41_exchange_id_res res = {
 		.client = clp,
@@ -4523,9 +4540,6 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
 	dprintk("--> %s\n", __func__);
 	BUG_ON(clp == NULL);
 
-	/* Remove server-only flags */
-	args.flags &= ~EXCHGID4_FLAG_CONFIRMED_R;
-
 	p = (u32 *)verifier.data;
 	*p++ = htonl((u32)clp->cl_boot_time.tv_sec);
 	*p = htonl((u32)clp->cl_boot_time.tv_nsec);
@@ -4551,6 +4565,7 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
 			break;
 	}
 
+	status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags);
 	dprintk("<-- %s status= %d\n", __func__, status);
 	return status;
 }
Signature · 1 line
1.6.6
#1 lore raw
Quoted 17 lines · On Fri, 2010-12-03 at 11:34 -0500, [email protected] wrote:

From: Andy Adamson <[email protected]>

Indicate support for referrals. Do not set any PNFS roles. Check the flags returned by the server for validity. Do not use exchange flags from an old client ID instance when recovering a client ID.

---
 fs/nfs/nfs4proc.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)
fs/nfs/nfs4proc.c +0 -0
index c244000..e77a2b9 100644
@@ -4494,6 +4494,23 @@ int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
 

fs/nfs/nfs4proc.c int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, · line 4504

Quoted 10 lines
fs/nfs/nfs4proc.c +8 -0
 #ifdef CONFIG_NFS_V4_1
 /*
+ * Check the exchange flags returned by the server for invalid flags, having
+ * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
+ * DS flags set.
+ */
+static int nfs4_check_cl_exchange_flags(u32 flags)
+{
+	if (flags & ~EXCHGID4_FLAG_MASK_R ||
+	    (flags & EXCHGID4_FLAG_USE_PNFS_MDS &&
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

fs/nfs/nfs4proc.c int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, · line 4505

Quoted 1 line
fs/nfs/nfs4proc.c +1 -0
+	     flags & EXCHGID4_FLAG_USE_NON_PNFS) ||
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

need brackets.

fs/nfs/nfs4proc.c int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, · line 4509

Quoted 4 lines
fs/nfs/nfs4proc.c +4 -0
+	    (!(flags & (EXCHGID4_FLAG_USE_PNFS_MDS |
+			EXCHGID4_FLAG_USE_NON_PNFS |
+			EXCHGID4_FLAG_USE_PNFS_DS))))
+		return NFS4ERR_INVAL;
			^^^^^^^^^^^^^^^ -NFS4ERR_INVAL?

Can we clean this up a little bit:

	if (flags & EXCHGID4_FLAG_MASK_R)
		goto out_inval;
	if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) &&
	    (flags & EXCHGID4_FLAG_USE_NON_PNFS))
		goto out_inval;
	if (....)
		goto out_inval;
	return NFS_OK;
out_inval:
	return -NFS4ERR_INVAL;
Quoted 34 lines
fs/nfs/nfs4proc.c +6 -4
+	return NFS_OK;
+}
+
+/*
  * nfs4_proc_exchange_id()
  *
  * Since the clientid has expired, all compounds using sessions
@@ -4506,7 +4523,7 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
 	nfs4_verifier verifier;
 	struct nfs41_exchange_id_args args = {
 		.client = clp,
-		.flags = clp->cl_exchange_flags,
+		.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER,
 	};
 	struct nfs41_exchange_id_res res = {
 		.client = clp,
@@ -4523,9 +4540,6 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
 	dprintk("--> %s\n", __func__);
 	BUG_ON(clp == NULL);
 
-	/* Remove server-only flags */
-	args.flags &= ~EXCHGID4_FLAG_CONFIRMED_R;
-
 	p = (u32 *)verifier.data;
 	*p++ = htonl((u32)clp->cl_boot_time.tv_sec);
 	*p = htonl((u32)clp->cl_boot_time.tv_nsec);
@@ -4551,6 +4565,7 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
 			break;
 	}
 
+	status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags);
 	dprintk("<-- %s status= %d\n", __func__, status);
 	return status;
 }
Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com