public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ken Preslan <kpreslan@redhat.com>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] Allow cluster-wide flock
Date: Mon, 30 Aug 2004 10:19:45 -0500	[thread overview]
Message-ID: <20040830151945.GA16894@potassium.msp.redhat.com> (raw)

Hi,

Below is a patch that lets a cluster filesystem (such as GFS) implement
flock across a the cluster.  Please apply.

Thanks!


diff -urN -p linux-2.6.9-rc1-mm1/fs/locks.c linux/fs/locks.c
--- linux-2.6.9-rc1-mm1/fs/locks.c	2004-08-27 10:54:32.939282703 -0500
+++ linux/fs/locks.c	2004-08-27 10:54:34.540910950 -0500
@@ -1318,6 +1318,33 @@ out_unlock:
 }
 
 /**
+ * flock_lock_file_wait - Apply a FLOCK-style lock to a file
+ * @filp: The file to apply the lock to
+ * @fl: The lock to be applied
+ *
+ * Add a FLOCK style lock to a file.
+ */
+int flock_lock_file_wait(struct file *filp, struct file_lock *fl)
+{
+	int error;
+	might_sleep();
+	for (;;) {
+		error = flock_lock_file(filp, fl);
+		if ((error != -EAGAIN) || !(fl->fl_flags & FL_SLEEP))
+			break;
+		error = wait_event_interruptible(fl->fl_wait, !fl->fl_next);
+		if (!error)
+			continue;
+
+		locks_delete_block(fl);
+		break;
+	}
+	return error;
+}
+
+EXPORT_SYMBOL(flock_lock_file_wait);
+
+/**
  *	sys_flock: - flock() system call.
  *	@fd: the file descriptor to lock.
  *	@cmd: the type of lock to apply.
@@ -1365,6 +1392,13 @@ asmlinkage long sys_flock(unsigned int f
 	if (error)
 		goto out_free;
 
+	if (filp->f_op && filp->f_op->lock) {
+		error = filp->f_op->lock(filp,
+					(can_sleep) ? F_SETLKW : F_SETLK,
+					lock);
+		goto out_free;
+	}
+
 	for (;;) {
 		error = flock_lock_file(filp, lock);
 		if ((error != -EAGAIN) || !can_sleep)
@@ -1732,6 +1766,12 @@ void locks_remove_flock(struct file *fil
 	if (!inode->i_flock)
 		return;
 
+	if (filp->f_op && filp->f_op->lock) {
+		struct file_lock fl = { .fl_flags = FL_FLOCK,
+					.fl_type = F_UNLCK };
+		filp->f_op->lock(filp, F_SETLKW, &fl);
+	}	
+
 	lock_kernel();
 	before = &inode->i_flock;
 
diff -urN -p linux-2.6.9-rc1-mm1/include/linux/fs.h linux/include/linux/fs.h
--- linux-2.6.9-rc1-mm1/include/linux/fs.h	2004-08-27 10:54:32.941282239 -0500
+++ linux/include/linux/fs.h	2004-08-27 10:54:34.541910717 -0500
@@ -697,6 +697,7 @@ extern int posix_lock_file_wait(struct f
 extern void posix_block_lock(struct file_lock *, struct file_lock *);
 extern void posix_unblock_lock(struct file *, struct file_lock *);
 extern int posix_locks_deadlock(struct file_lock *, struct file_lock *);
+extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl);
 extern int __break_lease(struct inode *inode, unsigned int flags);
 extern void lease_get_mtime(struct inode *, struct timespec *time);
 extern int lock_may_read(struct inode *, loff_t start, unsigned long count);



             reply	other threads:[~2004-08-30 15:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-30 15:19 Ken Preslan [this message]
2004-08-30 14:35 ` [PATCH] Allow cluster-wide flock Alan Cox
  -- strict thread matches above, loose matches on Subject: below --
2004-08-30 23:05 Trond Myklebust
2004-08-31 22:42 ` Ken Preslan
2004-08-31  3:11 Steve French

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=20040830151945.GA16894@potassium.msp.redhat.com \
    --to=kpreslan@redhat.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /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