From: "J. Bruce Fields" <bfields@redhat.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Christoph Hellwig <hch@infradead.org>,
"J. Bruce Fields" <bfields@redhat.com>
Subject: [PATCH 2/6] locks: give break_lease its own flags
Date: Fri, 3 Feb 2012 16:09:53 -0500 [thread overview]
Message-ID: <1328303397-3872-3-git-send-email-bfields@redhat.com> (raw)
In-Reply-To: <20120203205818.GE2999@fieldses.org>
From: "J. Bruce Fields" <bfields@redhat.com>
Instead of passing O_* flags to break_lease, give it its own set of
constants to use. We'll want more bits here soon.
Be careful to continue treating these bits the same way for now, so
there isn't a "flag day" for break_lease callers. We'll probably change
the constants eventually, though.
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
---
fs/locks.c | 10 +++++-----
fs/nfsd/vfs.c | 6 +++---
fs/open.c | 4 ++--
include/linux/fs.h | 27 +++++++++++++++++++++++++++
4 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/fs/locks.c b/fs/locks.c
index ea07a98..5f9ae63 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1188,12 +1188,12 @@ static void time_out_leases(struct inode *inode)
/**
* __break_lease - revoke all outstanding leases on file
* @inode: the inode of the file to return
- * @mode: the open mode (read or write)
+ * @mode: the type of leases to break
*
* break_lease (inlined for speed) has checked there already is at least
- * some kind of lock (maybe a lease) on this file. Leases are broken on
- * a call to open() or truncate(). This function can sleep unless you
- * specified %O_NONBLOCK to your open().
+ * some kind of lock (maybe a lease) on this file.
+ * This function will wait for the lease to be broken unless you include
+ * BREAK_NONBLOCK in the mode.
*/
int __break_lease(struct inode *inode, unsigned int mode)
{
@@ -1202,7 +1202,7 @@ int __break_lease(struct inode *inode, unsigned int mode)
struct file_lock *fl;
unsigned long break_time;
int i_have_this_lease = 0;
- int want_write = (mode & O_ACCMODE) != O_RDONLY;
+ int want_write = (mode & BREAK_RW_MASK) != BREAK_W_LEASES;
new_fl = lease_alloc(NULL, want_write ? F_WRLCK : F_RDLCK);
if (IS_ERR(new_fl))
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index edf6d3e..4ef03536 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -276,7 +276,7 @@ static int nfsd_break_lease(struct inode *inode)
{
if (!S_ISREG(inode->i_mode))
return 0;
- return break_lease(inode, O_WRONLY | O_NONBLOCK);
+ return break_lease(inode, BREAK_R_AND_W_LEASES | BREAK_NONBLOCK);
}
/*
@@ -731,8 +731,8 @@ static int nfsd_open_break_lease(struct inode *inode, int access)
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);
+ mode = (access & NFSD_MAY_WRITE) ? BREAK_R_AND_W_LEASES : BREAK_W_LEASES;
+ return break_lease(inode, mode | BREAK_NONBLOCK);
}
/*
diff --git a/fs/open.c b/fs/open.c
index 77becc0..9e45cd5 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -105,7 +105,7 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
* Make sure that there are no leases. get_write_access() protects
* against the truncate racing with a lease-granting setlease().
*/
- error = break_lease(inode, O_WRONLY);
+ error = break_lease(inode, BREAK_R_AND_W_LEASES);
if (error)
goto put_write_and_out;
@@ -685,7 +685,7 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
if (error)
goto cleanup_all;
- error = break_lease(inode, f->f_flags);
+ error = open_break_lease(inode, f->f_flags);
if (error)
goto cleanup_all;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 234b086..89c8481 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1091,6 +1091,22 @@ static inline int file_check_writeable(struct file *filp)
#define FL_DOWNGRADE_PENDING 256 /* Lease is being downgraded */
#define FL_UNLOCK_PENDING 512 /* Lease is being broken */
+/* break-lease flags */
+/*
+ * These agree with O_RDONLY, O_WRONLY, O_ACCMODE, and O_NONBLOCK as a
+ * (possibly temporary) courtesy to developers of any out-of-tree
+ * code that calls break_lease:
+ */
+#define BREAK_W_LEASES 00000000
+#define BREAK_R_AND_W_LEASES 00000001
+#define BREAK_RW_MASK 00000003
+#define BREAK_NONBLOCK 00004000
+/*
+ * Read delegations are also broken on operations that modify file
+ * metadata or the set of links that point to a file:
+ */
+#define BREAK_ONLY_DELEGS 00000010
+
/*
* Special return value from posix_lock_file() and vfs_lock_file() for
* asynchronous locking.
@@ -1972,6 +1988,13 @@ static inline int break_lease(struct inode *inode, unsigned int mode)
return __break_lease(inode, mode);
return 0;
}
+
+static inline int open_break_lease(struct inode *inode, unsigned int mode)
+{
+ unsigned int type = (mode & O_ACCMODE) == O_RDONLY ?
+ BREAK_W_LEASES : BREAK_R_AND_W_LEASES;
+ return __break_lease(inode, type);
+}
#else /* !CONFIG_FILE_LOCKING */
static inline int locks_mandatory_locked(struct inode *inode)
{
@@ -2011,6 +2034,10 @@ static inline int break_lease(struct inode *inode, unsigned int mode)
return 0;
}
+static inline int open_break_lease(struct inode *inode, unsigned int mode)
+{
+ return 0;
+}
#endif /* CONFIG_FILE_LOCKING */
/* fs/open.c */
--
1.7.5.4
WARNING: multiple messages have this Message-ID (diff)
From: "J. Bruce Fields" <bfields-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Al Viro <viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
Cc: linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Christoph Hellwig <hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
"J. Bruce Fields"
<bfields-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH 2/6] locks: give break_lease its own flags
Date: Fri, 3 Feb 2012 16:09:53 -0500 [thread overview]
Message-ID: <1328303397-3872-3-git-send-email-bfields@redhat.com> (raw)
In-Reply-To: <20120203205818.GE2999-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
From: "J. Bruce Fields" <bfields-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Instead of passing O_* flags to break_lease, give it its own set of
constants to use. We'll want more bits here soon.
Be careful to continue treating these bits the same way for now, so
there isn't a "flag day" for break_lease callers. We'll probably change
the constants eventually, though.
Signed-off-by: J. Bruce Fields <bfields-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
fs/locks.c | 10 +++++-----
fs/nfsd/vfs.c | 6 +++---
fs/open.c | 4 ++--
include/linux/fs.h | 27 +++++++++++++++++++++++++++
4 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/fs/locks.c b/fs/locks.c
index ea07a98..5f9ae63 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1188,12 +1188,12 @@ static void time_out_leases(struct inode *inode)
/**
* __break_lease - revoke all outstanding leases on file
* @inode: the inode of the file to return
- * @mode: the open mode (read or write)
+ * @mode: the type of leases to break
*
* break_lease (inlined for speed) has checked there already is at least
- * some kind of lock (maybe a lease) on this file. Leases are broken on
- * a call to open() or truncate(). This function can sleep unless you
- * specified %O_NONBLOCK to your open().
+ * some kind of lock (maybe a lease) on this file.
+ * This function will wait for the lease to be broken unless you include
+ * BREAK_NONBLOCK in the mode.
*/
int __break_lease(struct inode *inode, unsigned int mode)
{
@@ -1202,7 +1202,7 @@ int __break_lease(struct inode *inode, unsigned int mode)
struct file_lock *fl;
unsigned long break_time;
int i_have_this_lease = 0;
- int want_write = (mode & O_ACCMODE) != O_RDONLY;
+ int want_write = (mode & BREAK_RW_MASK) != BREAK_W_LEASES;
new_fl = lease_alloc(NULL, want_write ? F_WRLCK : F_RDLCK);
if (IS_ERR(new_fl))
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index edf6d3e..4ef03536 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -276,7 +276,7 @@ static int nfsd_break_lease(struct inode *inode)
{
if (!S_ISREG(inode->i_mode))
return 0;
- return break_lease(inode, O_WRONLY | O_NONBLOCK);
+ return break_lease(inode, BREAK_R_AND_W_LEASES | BREAK_NONBLOCK);
}
/*
@@ -731,8 +731,8 @@ static int nfsd_open_break_lease(struct inode *inode, int access)
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);
+ mode = (access & NFSD_MAY_WRITE) ? BREAK_R_AND_W_LEASES : BREAK_W_LEASES;
+ return break_lease(inode, mode | BREAK_NONBLOCK);
}
/*
diff --git a/fs/open.c b/fs/open.c
index 77becc0..9e45cd5 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -105,7 +105,7 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
* Make sure that there are no leases. get_write_access() protects
* against the truncate racing with a lease-granting setlease().
*/
- error = break_lease(inode, O_WRONLY);
+ error = break_lease(inode, BREAK_R_AND_W_LEASES);
if (error)
goto put_write_and_out;
@@ -685,7 +685,7 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
if (error)
goto cleanup_all;
- error = break_lease(inode, f->f_flags);
+ error = open_break_lease(inode, f->f_flags);
if (error)
goto cleanup_all;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 234b086..89c8481 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1091,6 +1091,22 @@ static inline int file_check_writeable(struct file *filp)
#define FL_DOWNGRADE_PENDING 256 /* Lease is being downgraded */
#define FL_UNLOCK_PENDING 512 /* Lease is being broken */
+/* break-lease flags */
+/*
+ * These agree with O_RDONLY, O_WRONLY, O_ACCMODE, and O_NONBLOCK as a
+ * (possibly temporary) courtesy to developers of any out-of-tree
+ * code that calls break_lease:
+ */
+#define BREAK_W_LEASES 00000000
+#define BREAK_R_AND_W_LEASES 00000001
+#define BREAK_RW_MASK 00000003
+#define BREAK_NONBLOCK 00004000
+/*
+ * Read delegations are also broken on operations that modify file
+ * metadata or the set of links that point to a file:
+ */
+#define BREAK_ONLY_DELEGS 00000010
+
/*
* Special return value from posix_lock_file() and vfs_lock_file() for
* asynchronous locking.
@@ -1972,6 +1988,13 @@ static inline int break_lease(struct inode *inode, unsigned int mode)
return __break_lease(inode, mode);
return 0;
}
+
+static inline int open_break_lease(struct inode *inode, unsigned int mode)
+{
+ unsigned int type = (mode & O_ACCMODE) == O_RDONLY ?
+ BREAK_W_LEASES : BREAK_R_AND_W_LEASES;
+ return __break_lease(inode, type);
+}
#else /* !CONFIG_FILE_LOCKING */
static inline int locks_mandatory_locked(struct inode *inode)
{
@@ -2011,6 +2034,10 @@ static inline int break_lease(struct inode *inode, unsigned int mode)
return 0;
}
+static inline int open_break_lease(struct inode *inode, unsigned int mode)
+{
+ return 0;
+}
#endif /* CONFIG_FILE_LOCKING */
/* fs/open.c */
--
1.7.5.4
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2012-02-03 21:10 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-17 16:00 [RFC PATCH 0/6] Fix NFSv4 delegations J. Bruce Fields
2012-01-17 16:00 ` [RFC PATCH 1/6] locks: introduce new FL_DELEG lock flag J. Bruce Fields
2012-01-17 16:00 ` J. Bruce Fields
2012-01-17 16:00 ` [RFC PATCH 2/6] locks: give break_lease its own flags J. Bruce Fields
2012-01-17 16:17 ` Bypass encrypt and decrypt data in dm-crypt Fan Zhang
2012-01-17 16:17 ` Fan Zhang
2012-01-17 16:00 ` [RFC PATCH 3/6] locks: break delegations on unlink J. Bruce Fields
2012-01-17 16:00 ` J. Bruce Fields
2012-01-17 16:00 ` [RFC PATCH 4/6] locks: break delegations on rename J. Bruce Fields
2012-01-17 16:00 ` [RFC PATCH 5/6] locks: break delegations on any attribute modification J. Bruce Fields
2012-01-17 16:00 ` [RFC PATCH 6/6] locks: break delegations on link J. Bruce Fields
2012-01-17 16:00 ` J. Bruce Fields
2012-02-03 20:58 ` [RFC PATCH 0/6] Fix NFSv4 delegations J. Bruce Fields
2012-02-03 21:09 ` Provide vfs support for " J. Bruce Fields
2012-02-03 21:09 ` J. Bruce Fields
2012-02-03 21:09 ` [PATCH 1/6] locks: introduce new FL_DELEG lock flag J. Bruce Fields
2012-02-03 21:09 ` J. Bruce Fields [this message]
2012-02-03 21:09 ` [PATCH 2/6] locks: give break_lease its own flags J. Bruce Fields
2012-02-03 21:09 ` [PATCH 3/6] locks: break delegations on unlink J. Bruce Fields
2012-02-03 21:09 ` J. Bruce Fields
2012-02-03 21:09 ` [PATCH 4/6] locks: break delegations on rename J. Bruce Fields
2012-02-03 21:09 ` [PATCH 5/6] locks: break delegations on any attribute modification J. Bruce Fields
2012-02-03 21:09 ` [PATCH 6/6] locks: break delegations on link J. Bruce Fields
2012-02-03 21:09 ` J. Bruce Fields
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1328303397-3872-3-git-send-email-bfields@redhat.com \
--to=bfields@redhat.com \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.