[PATCH] ceph: check if file lock exists before sending unlock request

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When a process exits, kernel closes its files. locks_remove_file()
is called to remove file locks on these files. locks_remove_file()
tries unlocking files locks even there is no file locks.

Signed-off-by: "Yan, Zheng" <zyan@xxxxxxxxxx>
---
 fs/ceph/locks.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c
index 544e9e85b120..78be861259eb 100644
--- a/fs/ceph/locks.c
+++ b/fs/ceph/locks.c
@@ -255,9 +255,21 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl)
 	else
 		lock_cmd = CEPH_LOCK_UNLOCK;
 
+	if (op == CEPH_MDS_OP_SETFILELOCK && F_UNLCK == fl->fl_type) {
+		unsigned int orig_flags = fl->fl_flags;
+		fl->fl_flags |= FL_EXISTS;
+		err = posix_lock_file(file, fl, NULL);
+		fl->fl_flags = orig_flags;
+		if (err == -ENOENT) {
+			if (!(orig_flags & FL_EXISTS))
+				err = 0;
+			return err;
+		}
+	}
+
 	err = ceph_lock_message(CEPH_LOCK_FCNTL, op, inode, lock_cmd, wait, fl);
 	if (!err) {
-		if (op == CEPH_MDS_OP_SETFILELOCK) {
+		if (op == CEPH_MDS_OP_SETFILELOCK && F_UNLCK != fl->fl_type) {
 			dout("mds locked, locking locally\n");
 			err = posix_lock_file(file, fl, NULL);
 			if (err) {
@@ -311,9 +323,21 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
 	else
 		lock_cmd = CEPH_LOCK_UNLOCK;
 
+	if (F_UNLCK == fl->fl_type) {
+		unsigned int orig_flags = fl->fl_flags;
+		fl->fl_flags |= FL_EXISTS;
+		err = locks_lock_file_wait(file, fl);
+		fl->fl_flags = orig_flags;
+		if (err == -ENOENT) {
+			if (!(orig_flags & FL_EXISTS))
+				err = 0;
+			return err;
+		}
+	}
+
 	err = ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK,
 				inode, lock_cmd, wait, fl);
-	if (!err) {
+	if (!err && F_UNLCK != fl->fl_type) {
 		err = locks_lock_file_wait(file, fl);
 		if (err) {
 			ceph_lock_message(CEPH_LOCK_FLOCK,
-- 
2.21.1




[Index of Archives]     [CEPH Users]     [Ceph Large]     [Ceph Dev]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux