Skip to contentSkip to conversation

nfsd4: fix break_lease flags on nfsd open

PATCH In review J. Bruce Fields 2 participants 3 messages Jun 9, 2011 – Jun 12, 2011

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

PATCH 1/2 nfsd4: fix break_lease flags on nfsd open

From: J. Bruce Fields <[email protected]>

Thanks to Casey Bodley for pointing out that on a read open we pass 0, instead of O_RDONLY, to break_lease, with the result that a read open is treated like a write open for the purposes of lease breaking!

---
 fs/nfsd/vfs.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
fs/nfsd/vfs.c +9 -6
index f3fb61b..848a4af 100644
@@ -696,7 +696,15 @@ nfsd_access(struct svc_rqst *rqstp, struct svc_fh *fhp, u32 *access, u32 *suppor
 }
 #endif /* CONFIG_NFSD_V3 */
 
+static int nfsd_open_break_lease(struct inode *inode, int access)
+{
+	unsigned int mode;
 
+	if (access & NFSD_MAY_NOT_BREAK_LEASE)
+		return 0;
+	mode = (access & NFSD_MAY_WRITE) ? O_WRONLY : O_RDONLY;
+	return break_lease(inode, mode | O_NONBLOCK);
+}
 
 /*
  * Open an existing file or directory.
@@ -744,12 +752,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
 	if (!inode->i_fop)
 		goto out;
 
-	/*
-	 * Check to see if there are any leases on this file.
-	 * This may block while leases are broken.
-	 */
-	if (!(access & NFSD_MAY_NOT_BREAK_LEASE))
-		host_err = break_lease(inode, O_NONBLOCK | ((access & NFSD_MAY_WRITE) ? O_WRONLY : 0));
+	 host_err = nfsd_open_break_lease(inode, access);
 	if (host_err) /* NOMEM or WOULDBLOCK */
 		goto out_nfserr;
 
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 33 lines · J. Bruce Fields

From: J. Bruce Fields <[email protected]>

Thanks to Casey Bodley for pointing out that on a read open we pass 0, instead of O_RDONLY, to break_lease, with the result that a read open is treated like a write open for the purposes of lease breaking!

---
 fs/nfsd/vfs.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
fs/nfsd/vfs.c +8 -0
index f3fb61b..848a4af 100644
@@ -696,7 +696,15 @@ nfsd_access(struct svc_rqst *rqstp, struct svc_fh *fhp, u32 *access, u32 *suppor
 }
 #endif /* CONFIG_NFSD_V3 */
 
+static int nfsd_open_break_lease(struct inode *inode, int access)
+{
+	unsigned int mode;
 
+	if (access & NFSD_MAY_NOT_BREAK_LEASE)
+		return 0;
+	mode = (access & NFSD_MAY_WRITE) ? O_WRONLY : O_RDONLY;
+	return break_lease(inode, mode | O_NONBLOCK);
+}
 
 /*
  * Open an existing file or directory.

fs/nfsd/vfs.c nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, · line 755

Quoted 10 lines
fs/nfsd/vfs.c +1 -6
@@ -744,12 +752,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
 	if (!inode->i_fop)
 		goto out;
 
-	/*
-	 * Check to see if there are any leases on this file.
-	 * This may block while leases are broken.
-	 */
-	if (!(access & NFSD_MAY_NOT_BREAK_LEASE))
-		host_err = break_lease(inode, O_NONBLOCK | ((access & NFSD_MAY_WRITE) ? O_WRONLY : 0));
+	 host_err = nfsd_open_break_lease(inode, access);

nit: looks like there's an extra space before "host_err ="...

Benny

Quoted 3 lines
fs/nfsd/vfs.c +0 -0
 	if (host_err) /* NOMEM or WOULDBLOCK */
 		goto out_nfserr;
 
#2 lore raw
Quoted 37 lines · Benny Halevy
Quoted 36 lines · J. Bruce Fields

From: J. Bruce Fields <[email protected]>

Thanks to Casey Bodley for pointing out that on a read open we pass 0, instead of O_RDONLY, to break_lease, with the result that a read open is treated like a write open for the purposes of lease breaking!

---
 fs/nfsd/vfs.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
fs/nfsd/vfs.c +8 -0
index f3fb61b..848a4af 100644
@@ -696,7 +696,15 @@ nfsd_access(struct svc_rqst *rqstp, struct svc_fh *fhp, u32 *access, u32 *suppor
 }
 #endif /* CONFIG_NFSD_V3 */
 
+static int nfsd_open_break_lease(struct inode *inode, int access)
+{
+	unsigned int mode;
 
+	if (access & NFSD_MAY_NOT_BREAK_LEASE)
+		return 0;
+	mode = (access & NFSD_MAY_WRITE) ? O_WRONLY : O_RDONLY;
+	return break_lease(inode, mode | O_NONBLOCK);
+}
 
 /*
  * Open an existing file or directory.
@@ -744,12 +752,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
 	if (!inode->i_fop)
 		goto out;
 
Quoted 9 lines

fs/nfsd/vfs.c nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, · line 755

Quoted 7 lines
fs/nfsd/vfs.c +1 -6
-	/*
-	 * Check to see if there are any leases on this file.
-	 * This may block while leases are broken.
-	 */
-	if (!(access & NFSD_MAY_NOT_BREAK_LEASE))
-		host_err = break_lease(inode, O_NONBLOCK | ((access & NFSD_MAY_WRITE) ? O_WRONLY : 0));
+	 host_err = nfsd_open_break_lease(inode, access);

nit: looks like there's an extra space before "host_err ="...

Whoops, yup; fixed.--b.

Quoted 6 lines

Benny

Quoted 3 lines
fs/nfsd/vfs.c +0 -0
 	if (host_err) /* NOMEM or WOULDBLOCK */
 		goto out_nfserr;