linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@citi.umich.edu>
To: linux-fsdevel@vger.kernel.org
Cc: nfs@lists.sourceforge.net, Marc Eshel <eshel@almaden.ibm.com>
Subject: [PATCH 14/14] gfs2: nfs lock support for gfs2
Date: Sat,  3 Feb 2007 00:34:10 -0500	[thread overview]
Message-ID: <31147.4227150486$1170480904@news.gmane.org> (raw)
Message-ID: <6d1e339108dad3e204a1eb53e736a2a0f73dda22.1170479265.git.bfields@citi.umich.edu> (raw)
In-Reply-To: <11704808522949-git-send-email->
In-Reply-To: <ad8373acbb12f165b625f6065bc0ca86f3982b7f.1170479265.git.bfields@citi.umich.edu>

From: Marc Eshel <eshel@almaden.ibm.com> - unquoted

Add NFS lock support to GFS2.  (Untested.)

Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
 fs/gfs2/locking/dlm/plock.c    |   76 +++++++++++++++++++++++++++++++++++++--
 fs/gfs2/ops_file.c             |    5 +++
 include/linux/lock_dlm_plock.h |    3 ++
 3 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/fs/gfs2/locking/dlm/plock.c b/fs/gfs2/locking/dlm/plock.c
index 3799f19..da6c01c 100644
--- a/fs/gfs2/locking/dlm/plock.c
+++ b/fs/gfs2/locking/dlm/plock.c
@@ -59,6 +59,8 @@ static void send_op(struct plock_op *op)
 	wake_up(&send_wq);
 }
 
+/* XXX: unlock? cancel? ... */
+
 int gdlm_plock(void *lockspace, struct lm_lockname *name,
 	       struct file *file, int cmd, struct file_lock *fl)
 {
@@ -79,9 +81,20 @@ int gdlm_plock(void *lockspace, struct lm_lockname *name,
 	op->info.start		= fl->fl_start;
 	op->info.end		= fl->fl_end;
 	op->info.owner		= (__u64)(long) fl->fl_owner;
+	if (fl->fl_lmops && fl->fl_lmops->fl_notify) {
+		op->info.callback	= fl->fl_lmops->fl_notify;
+		/* might need to make a copy */
+		op->info.fl		= fl;
+		op->info.file		= file;
+	} else
+		op->info.callback	= NULL;
 
 	send_op(op);
-	wait_event(recv_wq, (op->done != 0));
+
+	if (op->info.callback == NULL)
+		wait_event(recv_wq, (op->done != 0));
+	else
+		return -EINPROGRESS;
 
 	spin_lock(&ops_lock);
 	if (!list_empty(&op->list)) {
@@ -103,6 +116,58 @@ int gdlm_plock(void *lockspace, struct lm_lockname *name,
 	return rv;
 }
 
+/* Returns failure iff a succesful lock operation should be canceled */
+static int gdlm_plock_callback(struct plock_op *op)
+{
+	struct file *file;
+	struct file_lock *fl;
+	int (*notify)(void *, void *, int) = NULL;
+	int rv = 0;
+
+	spin_lock(&ops_lock);
+	if (!list_empty(&op->list)) {
+		printk(KERN_INFO "plock op on list\n");
+		list_del(&op->list);
+	}
+	spin_unlock(&ops_lock);
+
+	/* check if the following 2 are still valid or make a copy */
+	file = op->info.file;
+	fl = op->info.fl;
+	notify = op->info.callback;
+
+	if (op->info.rv) {
+		notify(fl, NULL, op->info.rv);
+		goto out;
+	}
+
+	/* got fs lock; bookkeep locally as well: */
+	if (posix_lock_file(file, fl)) {
+		/*
+		 * This can only happen in the case of kmalloc() failure.
+		 * The filesystem's own lock is the authoritative lock,
+		 * so a failure to get the lock locally is not a disaster.
+		 * As long as GFS cannot reliably cancel locks (especially
+		 * in a low-memory situation), we're better off ignoring
+		 * this failure than trying to recover.
+		 */
+		log_error("gdlm_plock: vfs lock error file %p fl %p",
+				file, fl);
+	}
+
+	rv = notify(fl, NULL, 0);
+	if (rv) {
+		/* XXX: We need to cancel the fs lock here: */
+		printk("gfs2 lock granted after lock request failed;"
+						" dangling lock!\n");
+		goto out;
+	}
+
+out:
+	kfree(op);
+	return rv;
+}
+
 int gdlm_punlock(void *lockspace, struct lm_lockname *name,
 		 struct file *file, struct file_lock *fl)
 {
@@ -243,9 +308,12 @@ static ssize_t dev_write(struct file *file, const char __user *u, size_t count,
 	}
 	spin_unlock(&ops_lock);
 
-	if (found)
-		wake_up(&recv_wq);
-	else
+	if (found) {
+		if (op->info.callback)
+			count = gdlm_plock_callback(op);
+		else
+			wake_up(&recv_wq);
+	} else
 		printk(KERN_INFO "gdlm dev_write no op %x %llx\n", info.fsid,
 			(unsigned long long)info.number);
 	return count;
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c
index faa07e4..acf23b2 100644
--- a/fs/gfs2/ops_file.c
+++ b/fs/gfs2/ops_file.c
@@ -576,6 +576,11 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
 		}
 	}
 
+	if (cmd == F_CANCELLK) {
+		/* Hack: */
+		cmd = F_SETLK;
+		fl->fl_type = F_UNLCK;
+	}
 	if (IS_GETLK(cmd))
 		return gfs2_lm_plock_get(sdp, &name, file, fl);
 	else if (fl->fl_type == F_UNLCK)
diff --git a/include/linux/lock_dlm_plock.h b/include/linux/lock_dlm_plock.h
index fc34151..809c5b7 100644
--- a/include/linux/lock_dlm_plock.h
+++ b/include/linux/lock_dlm_plock.h
@@ -35,6 +35,9 @@ struct gdlm_plock_info {
 	__u64 start;
 	__u64 end;
 	__u64 owner;
+	void *callback;
+	void *fl;
+	void *file;
 };
 
 #endif
-- 
1.5.0.rc1.g72fe


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

WARNING: multiple messages have this Message-ID (diff)
From: "J. Bruce Fields" <bfields@citi.umich.edu>
To: linux-fsdevel@vger.kernel.org
Cc: nfs@lists.sourceforge.net, Marc Eshel <eshel@almaden.ibm.com>
Subject: [PATCH 14/14] gfs2: nfs lock support for gfs2
Date: Sat,  3 Feb 2007 00:34:10 -0500	[thread overview]
Message-ID: <35925.1134250828$1170484088@news.gmane.org> (raw)
Message-ID: <6d1e339108dad3e204a1eb53e736a2a0f73dda22.1170479265.git.bfields@citi.umich.edu> (raw)
In-Reply-To: <11704808522949-git-send-email->
In-Reply-To: <ad8373acbb12f165b625f6065bc0ca86f3982b7f.1170479265.git.bfields@citi.umich.edu>

From: Marc Eshel <eshel@almaden.ibm.com> - unquoted

Add NFS lock support to GFS2.  (Untested.)

Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
 fs/gfs2/locking/dlm/plock.c    |   76 +++++++++++++++++++++++++++++++++++++--
 fs/gfs2/ops_file.c             |    5 +++
 include/linux/lock_dlm_plock.h |    3 ++
 3 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/fs/gfs2/locking/dlm/plock.c b/fs/gfs2/locking/dlm/plock.c
index 3799f19..da6c01c 100644
--- a/fs/gfs2/locking/dlm/plock.c
+++ b/fs/gfs2/locking/dlm/plock.c
@@ -59,6 +59,8 @@ static void send_op(struct plock_op *op)
 	wake_up(&send_wq);
 }
 
+/* XXX: unlock? cancel? ... */
+
 int gdlm_plock(void *lockspace, struct lm_lockname *name,
 	       struct file *file, int cmd, struct file_lock *fl)
 {
@@ -79,9 +81,20 @@ int gdlm_plock(void *lockspace, struct lm_lockname *name,
 	op->info.start		= fl->fl_start;
 	op->info.end		= fl->fl_end;
 	op->info.owner		= (__u64)(long) fl->fl_owner;
+	if (fl->fl_lmops && fl->fl_lmops->fl_notify) {
+		op->info.callback	= fl->fl_lmops->fl_notify;
+		/* might need to make a copy */
+		op->info.fl		= fl;
+		op->info.file		= file;
+	} else
+		op->info.callback	= NULL;
 
 	send_op(op);
-	wait_event(recv_wq, (op->done != 0));
+
+	if (op->info.callback == NULL)
+		wait_event(recv_wq, (op->done != 0));
+	else
+		return -EINPROGRESS;
 
 	spin_lock(&ops_lock);
 	if (!list_empty(&op->list)) {
@@ -103,6 +116,58 @@ int gdlm_plock(void *lockspace, struct lm_lockname *name,
 	return rv;
 }
 
+/* Returns failure iff a succesful lock operation should be canceled */
+static int gdlm_plock_callback(struct plock_op *op)
+{
+	struct file *file;
+	struct file_lock *fl;
+	int (*notify)(void *, void *, int) = NULL;
+	int rv = 0;
+
+	spin_lock(&ops_lock);
+	if (!list_empty(&op->list)) {
+		printk(KERN_INFO "plock op on list\n");
+		list_del(&op->list);
+	}
+	spin_unlock(&ops_lock);
+
+	/* check if the following 2 are still valid or make a copy */
+	file = op->info.file;
+	fl = op->info.fl;
+	notify = op->info.callback;
+
+	if (op->info.rv) {
+		notify(fl, NULL, op->info.rv);
+		goto out;
+	}
+
+	/* got fs lock; bookkeep locally as well: */
+	if (posix_lock_file(file, fl)) {
+		/*
+		 * This can only happen in the case of kmalloc() failure.
+		 * The filesystem's own lock is the authoritative lock,
+		 * so a failure to get the lock locally is not a disaster.
+		 * As long as GFS cannot reliably cancel locks (especially
+		 * in a low-memory situation), we're better off ignoring
+		 * this failure than trying to recover.
+		 */
+		log_error("gdlm_plock: vfs lock error file %p fl %p",
+				file, fl);
+	}
+
+	rv = notify(fl, NULL, 0);
+	if (rv) {
+		/* XXX: We need to cancel the fs lock here: */
+		printk("gfs2 lock granted after lock request failed;"
+						" dangling lock!\n");
+		goto out;
+	}
+
+out:
+	kfree(op);
+	return rv;
+}
+
 int gdlm_punlock(void *lockspace, struct lm_lockname *name,
 		 struct file *file, struct file_lock *fl)
 {
@@ -243,9 +308,12 @@ static ssize_t dev_write(struct file *file, const char __user *u, size_t count,
 	}
 	spin_unlock(&ops_lock);
 
-	if (found)
-		wake_up(&recv_wq);
-	else
+	if (found) {
+		if (op->info.callback)
+			count = gdlm_plock_callback(op);
+		else
+			wake_up(&recv_wq);
+	} else
 		printk(KERN_INFO "gdlm dev_write no op %x %llx\n", info.fsid,
 			(unsigned long long)info.number);
 	return count;
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c
index faa07e4..acf23b2 100644
--- a/fs/gfs2/ops_file.c
+++ b/fs/gfs2/ops_file.c
@@ -576,6 +576,11 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
 		}
 	}
 
+	if (cmd == F_CANCELLK) {
+		/* Hack: */
+		cmd = F_SETLK;
+		fl->fl_type = F_UNLCK;
+	}
 	if (IS_GETLK(cmd))
 		return gfs2_lm_plock_get(sdp, &name, file, fl);
 	else if (fl->fl_type == F_UNLCK)
diff --git a/include/linux/lock_dlm_plock.h b/include/linux/lock_dlm_plock.h
index fc34151..809c5b7 100644
--- a/include/linux/lock_dlm_plock.h
+++ b/include/linux/lock_dlm_plock.h
@@ -35,6 +35,9 @@ struct gdlm_plock_info {
 	__u64 start;
 	__u64 end;
 	__u64 owner;
+	void *callback;
+	void *fl;
+	void *file;
 };
 
 #endif
-- 
1.5.0.rc1.g72fe


      parent reply	other threads:[~2007-02-03  5:34 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <11704808501171-git-send-email->
     [not found] ` <11704808502512-git-send-email->
     [not found]   ` <11704808513862-git-send-email->
     [not found]     ` <1170480851972-git-send-email->
     [not found]       ` <11704808513070-git-send-email->
     [not found]         ` <117048085185-git-send-email->
     [not found]           ` <11704808513263-git-send-email->
     [not found]             ` <11704808513185-git-send-email->
     [not found]               ` <11704808511238-git-send-email->
     [not found]                 ` <11704808513085-git-send-email->
     [not found]                   ` <11704808521765-git-send-email->
     [not found]                     ` <11704808523686-git-send-email->
     [not found] ` <ad8373acbb12f165b625f6065bc0ca86f3982b7f.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:33   ` [PATCH 1/14] locks: always unlock on close J. Bruce Fields
2007-02-03  5:33   ` J. Bruce Fields
     [not found]   ` <5cdd83858bf5c75e14742bbd03b462f5ec4997fe.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:33     ` [PATCH 2/14] locks: factor out generic/filesystem switch from test_lock J. Bruce Fields
2007-02-03  5:33     ` J. Bruce Fields
2007-02-03  8:50     ` Christoph Hellwig
2007-02-04  1:48       ` J. Bruce Fields
2007-02-04  8:41         ` Christoph Hellwig
2007-02-04  0:32     ` [NFS] " Trond Myklebust
2007-02-04  1:52       ` J. Bruce Fields
     [not found]   ` <1dd47bf9aeb6f19c82a59efb2f4236f23f73019d.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:33     ` [PATCH 3/14] locks: factor out generic/filesystem switch from setlock code J. Bruce Fields
2007-02-03  5:33     ` J. Bruce Fields
2007-02-03  8:51     ` Christoph Hellwig
2007-02-03  5:16       ` Brad Boyer
2007-02-04  2:27         ` J. Bruce Fields
2007-02-04  8:37         ` Christoph Hellwig
2007-02-03 21:27           ` Brad Boyer
2007-02-04  1:58       ` J. Bruce Fields
     [not found]   ` <96a0abaf64b433a7e7450e7e35d0baf2c44103db.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:34     ` [PATCH 4/14] locks: add locking function that returns conflicting lock J. Bruce Fields
2007-02-03  5:34     ` J. Bruce Fields
2007-02-03  8:54     ` Christoph Hellwig
2007-02-04  2:02       ` J. Bruce Fields
     [not found]   ` <a4ecb8974d61a5077d24cf42ed2c564b4fa7aadf.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:34     ` [PATCH 5/14] locks: add fl_notify arguments for asynchronous lock return J. Bruce Fields
2007-02-03  5:34     ` J. Bruce Fields
     [not found]   ` <fdf19cb6a33a08dd9220cdf2379d712d3c15e66f.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:34     ` [PATCH 6/14] locks: add lock cancel command J. Bruce Fields
2007-02-03  5:34     ` J. Bruce Fields
     [not found]   ` <d1c313156428c533721d67f938ca72759b192156.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:34     ` [PATCH 7/14] nfsd4: Convert NFSv4 to new lock interface J. Bruce Fields
2007-02-03  5:34     ` J. Bruce Fields
     [not found]   ` <8096fc4eb11f5c5678197fdee8afe0e2780357fc.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:34     ` [PATCH 8/14] lockd: save lock state on deferral J. Bruce Fields
2007-02-03  5:34     ` J. Bruce Fields
     [not found]   ` <6f2a40ca33ea2b58e3f515bea9be1e0fa8cda6aa.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:34     ` [PATCH 9/14] lockd: handle fl_notify callbacks J. Bruce Fields
2007-02-03  5:34     ` J. Bruce Fields
2007-02-04  0:40     ` [NFS] " Trond Myklebust
2007-02-04  2:10       ` J. Bruce Fields
     [not found]   ` <19e4ad761534f2afd8045321c950a9336c6b1fc2.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:34     ` [PATCH 10/14] lockd: pass cookie in nlmsvc_testlock J. Bruce Fields
2007-02-03  5:34     ` J. Bruce Fields
     [not found]   ` <ecc19d4bdf659f8cd1bbe4783625af5040f0b83a.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:34     ` [PATCH 11/14] lockd: handle test_lock deferrals J. Bruce Fields
2007-02-03  5:34     ` J. Bruce Fields
     [not found]   ` <ed8e1981069ef91a62c19a16b37d51c819a5196f.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:34     ` [PATCH 12/14] lockd: always preallocate block in nlmsvc_lock() J. Bruce Fields
2007-02-03  5:34     ` J. Bruce Fields
     [not found]   ` <b18934dedc3dd49bd1578256944c8fb756db2a6c.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:34     ` [PATCH 13/14] lockd: add code to handle deferred lock requests J. Bruce Fields
2007-02-03  5:34     ` J. Bruce Fields
     [not found]   ` <6d1e339108dad3e204a1eb53e736a2a0f73dda22.1170479265.git.bfields@citi.umich.edu>
2007-02-03  5:34     ` [PATCH 14/14] gfs2: nfs lock support for gfs2 J. Bruce Fields
2007-02-03  5:34     ` J. Bruce Fields [this message]

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='31147.4227150486$1170480904@news.gmane.org' \
    --to=bfields@citi.umich.edu \
    --cc=eshel@almaden.ibm.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=nfs@lists.sourceforge.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).