linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
To: Oren Laadan <orenl@cs.columbia.edu>
Cc: Serge Hallyn <serge@hallyn.com>,
	Matt Helsley <matthltc@us.ibm.com>, Dan Smith <danms@us.ibm.com>,
	John Stultz <johnstul@us.ibm.com>,
	Matthew Wilcox <matthew@wil.cx>,
	Jamie Lokier <jamie@shareable.org>,
	<linux-fsdevel@vger.kernel.org>,
	Containers <containers@lists.linux-foundation.org>
Subject: [PATCH 06/16][cr][v3]: Checkpoint file-locks
Date: Tue,  3 Aug 2010 16:11:27 -0700	[thread overview]
Message-ID: <1280877097-12377-7-git-send-email-sukadev@linux.vnet.ibm.com> (raw)
In-Reply-To: <1280877097-12377-1-git-send-email-sukadev@linux.vnet.ibm.com>

While checkpointing each file-descriptor, find all the locks on the
file and save information about the lock in the checkpoint-image.
A follow-on patch will use this informaiton to restore the file-locks.

Changelog[v3]:
	[Oren Laadan] Add a missing (loff_t) type cast and use a macro
		to set the marker/dummy file lock

Changelog[v2]:
	[Matt Helsley]: Use fixed sizes (__s64) instead of 'loff_t' in
		'struct ckpt_hdr_file_lock'.
	[Matt Helsley, Serge Hallyn]: Highlight new use of BKL (using
		lock_flocks() macros as suggested by Serge).
	[Matt Helsley]: Reorg code a bit to simplify error handling.
	[Matt Helsley]: Reorg code to initialize marker-lock (Pass a
		NULL lock to checkpoint_one_lock() to indicate marker).

Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
---
 fs/checkpoint.c                |  100 ++++++++++++++++++++++++++++++++++-----
 include/linux/checkpoint_hdr.h |   18 +++++++
 2 files changed, 105 insertions(+), 13 deletions(-)

diff --git a/fs/checkpoint.c b/fs/checkpoint.c
index b5486c1..57b6944 100644
--- a/fs/checkpoint.c
+++ b/fs/checkpoint.c
@@ -26,8 +26,19 @@
 #include <linux/checkpoint.h>
 #include <linux/eventpoll.h>
 #include <linux/eventfd.h>
+#include <linux/smp_lock.h>
 #include <net/sock.h>
 
+/*
+ * TODO: This code uses the BKL for consistency with other uses of
+ * 	 'for_each_lock()'. But since the BKL may be replaced with another
+ * 	 lock in the future, use lock_flocks() macros instead. lock_flocks()
+ * 	 are currently used in BKL-fix sand boxes and when those changes
+ * 	 are merged, the following macros can be removed
+ */
+#define lock_flocks()		lock_kernel()
+#define unlock_flocks()	unlock_kernel()
+
 /**************************************************************************
  * Checkpoint
  */
@@ -256,8 +267,78 @@ static int checkpoint_file(struct ckpt_ctx *ctx, void *ptr)
 	return ret;
 }
 
+static int checkpoint_one_file_lock(struct ckpt_ctx *ctx, struct file *file,
+		struct file_lock *lock)
+{
+	int rc;
+	struct ckpt_hdr_file_lock *h;
+
+	h = ckpt_hdr_get_type(ctx, sizeof(*h), CKPT_HDR_FILE_LOCK);
+	if (!h)
+		return -ENOMEM;
+
+	if (lock) {
+		h->fl_start = lock->fl_start;
+		h->fl_end = lock->fl_end;
+		h->fl_type = lock->fl_type;
+		h->fl_flags = lock->fl_flags;
+	} else {
+		/* Checkpoint a dummy lock as a marker */
+		CKPT_HDR_SET_MARKER_FILE_LOCK(h);
+	}
+
+	rc = ckpt_write_obj(ctx, &h->h);
+
+	ckpt_hdr_put(ctx, h);
+
+	return rc;
+}
+
+int
+checkpoint_file_locks(struct ckpt_ctx *ctx, struct files_struct *files,
+		struct file *file)
+{
+	int rc;
+	struct inode *inode;
+	struct file_lock **lockpp;
+	struct file_lock *lockp;
+
+	lock_flocks();
+	inode = file->f_path.dentry->d_inode;
+	for_each_lock(inode, lockpp) {
+		lockp = *lockpp;
+		ckpt_debug("Lock [%lld, %lld, %d, 0x%x]\n", lockp->fl_start,
+				lockp->fl_end, lockp->fl_type, lockp->fl_flags);
+
+		if (lockp->fl_owner != files)
+			continue;
+
+		rc = -EBADF;
+		if (IS_POSIX(lockp))
+			rc = checkpoint_one_file_lock(ctx, file, lockp);
+
+		if (rc < 0) {
+			ckpt_err(ctx,  rc, "%(T), checkpoint of lock "
+					"[%lld, %lld, %d, 0x%x] failed\n",
+					lockp->fl_start, lockp->fl_end,
+					lockp->fl_type, lockp->fl_flags);
+			goto out;
+		}
+	}
+
+	/*
+	 * At the end of file-locks for this file, checkpoint a marker.
+	 */
+	rc = checkpoint_one_file_lock(ctx, file, NULL);
+	if (rc < 0)
+		ckpt_err(ctx,  rc, "%(T), checkpoint marker-lock failed\n");
+out:
+	unlock_flocks();
+	return rc;
+}
+
 /**
- * ckpt_write_file_desc - dump the state of a given file descriptor
+ * checkpoint_file_desc - dump the state of a given file descriptor
  * @ctx: checkpoint context
  * @files: files_struct pointer
  * @fd: file descriptor
@@ -288,18 +369,6 @@ static int checkpoint_file_desc(struct ckpt_ctx *ctx,
 	}
 	rcu_read_unlock();
 
-	ret = find_locks_with_owner(file, files);
-	/*
-	 * find_locks_with_owner() returns an error when there
-	 * are no locks found, so we *want* it to return an error
-	 * code.  Its success means we have to fail the checkpoint.
-	 */
-	if (!ret) {
-		ret = -EBADF;
-		ckpt_err(ctx, ret, "%(T)fd %d has file lock or lease\n", fd);
-		goto out;
-	}
-
 	/* sanity check (although this shouldn't happen) */
 	ret = -EBADF;
 	if (!file) {
@@ -323,6 +392,11 @@ static int checkpoint_file_desc(struct ckpt_ctx *ctx,
 	h->fd_close_on_exec = coe;
 
 	ret = ckpt_write_obj(ctx, &h->h);
+	if (ret < 0)
+		goto out;
+
+	ret = checkpoint_file_locks(ctx, files, file);
+
 out:
 	ckpt_hdr_put(ctx, h);
 	if (file)
diff --git a/include/linux/checkpoint_hdr.h b/include/linux/checkpoint_hdr.h
index 0381019..ad08c8e 100644
--- a/include/linux/checkpoint_hdr.h
+++ b/include/linux/checkpoint_hdr.h
@@ -144,6 +144,8 @@ enum {
 #define CKPT_HDR_TTY_LDISC CKPT_HDR_TTY_LDISC
 	CKPT_HDR_EPOLL_ITEMS,  /* must be after file-table */
 #define CKPT_HDR_EPOLL_ITEMS CKPT_HDR_EPOLL_ITEMS
+	CKPT_HDR_FILE_LOCK,
+#define CKPT_HDR_FILE_LOCK CKPT_HDR_FILE_LOCK
 
 	CKPT_HDR_MM = 401,
 #define CKPT_HDR_MM CKPT_HDR_MM
@@ -586,6 +588,22 @@ struct ckpt_hdr_file_generic {
 	struct ckpt_hdr_file common;
 } __attribute__((aligned(8)));
 
+struct ckpt_hdr_file_lock {
+       struct ckpt_hdr h;
+       __s64 fl_start;
+       __s64 fl_end;
+       __u8 fl_type;
+       __u8 fl_flags;
+};
+
+#define CKPT_HDR_SET_MARKER_FILE_LOCK(h) {		\
+		h->fl_flags = FL_POSIX;		\
+		h->fl_start = (loff_t) -1;	\
+}
+
+#define CKPT_HDR_IS_MARKER_FILE_LOCK(h)		\
+		((h->fl_flags == FL_POSIX) && (h->fl_start == (loff_t) -1))
+
 struct ckpt_hdr_file_pipe {
 	struct ckpt_hdr_file common;
 	__s32 pipe_objref;
-- 
1.6.0.4


  parent reply	other threads:[~2010-08-03 23:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-03 23:11 [PATCH 00/16][cr][v3]: C/R file owner, locks, leases Sukadev Bhattiprolu
2010-08-03 23:11 ` [PATCH 01/16][cr][v3]: Add uid, euid params to f_modown() Sukadev Bhattiprolu
2010-08-03 23:11 ` [PATCH 02/16][cr][v3]: Add uid, euid params to __f_setown() Sukadev Bhattiprolu
2010-08-03 23:11 ` [PATCH 03/16][cr][v3]: Checkpoint file-owner information Sukadev Bhattiprolu
2010-08-03 23:11 ` [PATCH 04/16][cr][v3]: Restore file_owner info Sukadev Bhattiprolu
2010-08-04 23:01   ` Oren Laadan
2010-08-03 23:11 ` [PATCH 05/16][cr][v3]: Move file_lock macros into linux/fs.h Sukadev Bhattiprolu
2010-08-03 23:11 ` Sukadev Bhattiprolu [this message]
2010-08-04 23:26   ` [PATCH 06/16][cr][v3]: Checkpoint file-locks Oren Laadan
2010-08-03 23:11 ` [PATCH 07/16][cr][v3]: Define flock_set() Sukadev Bhattiprolu
2010-08-03 23:11 ` [PATCH 08/16][cr][v3]: Define flock64_set() Sukadev Bhattiprolu
2010-08-03 23:11 ` [PATCH 09/16][cr][v3]: Restore file-locks Sukadev Bhattiprolu
2010-08-03 23:11 ` [PATCH 10/16][cr][v3]: Initialize ->fl_break_time to 0 Sukadev Bhattiprolu
2010-08-03 23:11 ` [PATCH 11/16][cr][v3]: Add ->fl_type_prev field Sukadev Bhattiprolu
2010-08-03 23:11 ` [PATCH 12/16][cr][v3]: Add ->fl_break_notified field Sukadev Bhattiprolu
2010-08-03 23:11 ` [PATCH 13/16][cr][v3]: Add jiffies_begin field to ckpt_ctx Sukadev Bhattiprolu
2010-08-03 23:11 ` [PATCH 14/16][cr][v3]: Checkpoint file-leases Sukadev Bhattiprolu
2010-08-03 23:11 ` [PATCH 15/16][cr][v3]: Define do_setlease() Sukadev Bhattiprolu
2010-08-03 23:11 ` [PATCH 16/16][cr][v3]: Restore file-leases Sukadev Bhattiprolu
2010-08-04 23:35   ` Oren Laadan
2010-08-04 10:45 ` [PATCH 00/16][cr][v3]: C/R file owner, locks, leases Steven Whitehouse
2010-08-04 17:26   ` Matt Helsley
2010-08-04 18:03     ` Oren Laadan
2010-08-04 19:01   ` Sukadev Bhattiprolu
2010-08-04 19:16     ` Oren Laadan

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=1280877097-12377-7-git-send-email-sukadev@linux.vnet.ibm.com \
    --to=sukadev@linux.vnet.ibm.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=danms@us.ibm.com \
    --cc=jamie@shareable.org \
    --cc=johnstul@us.ibm.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=matthltc@us.ibm.com \
    --cc=orenl@cs.columbia.edu \
    --cc=serge@hallyn.com \
    /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).