Linux Container Development
 help / color / mirror / Atom feed
From: Nadia.Derbey-6ktuUTfB/bM@public.gmane.org
To: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Cc: Nadia Derbey <Nadia.Derbey-6ktuUTfB/bM@public.gmane.org>,
	pavel-+ZI9xUNit7I@public.gmane.org
Subject: [RFC PATCH 5/5] use next syscall data to predefine the file descriptor value
Date: Thu, 03 Jul 2008 16:40:18 +0200	[thread overview]
Message-ID: <20080703144226.157406000@bull.net> (raw)
In-Reply-To: 20080703144013.737951000@bull.net

[-- Attachment #1: fileopen_use_next_syscall_data.patch --]
[-- Type: text/plain, Size: 2589 bytes --]

[PATCH 05/05]

This patch uses the value written into the next_syscall_data proc file
as a target file descriptor for the next file to be opened.

This makes it easy to restart a process with the same fds as the ones it was
using during the checkpoint phase, instead of 1. opening the file, 2. dup2'ing
the open file descriptor.

The following syscalls are impacted if next_syscall_data is set:
. open()
. openat()

Signed-off-by: Nadia Derbey <Nadia.Derbey-6ktuUTfB/bM@public.gmane.org>

---
 fs/open.c |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)

Index: linux-2.6.26-rc5-mm3/fs/open.c
===================================================================
--- linux-2.6.26-rc5-mm3.orig/fs/open.c	2008-06-25 17:11:06.000000000 +0200
+++ linux-2.6.26-rc5-mm3/fs/open.c	2008-07-01 17:51:53.000000000 +0200
@@ -967,6 +967,55 @@ struct file *dentry_open(struct dentry *
 EXPORT_SYMBOL(dentry_open);
 
 /*
+ * Marks a given file descriptor entry as busy (should not be busy when this
+ * routine is called.
+ *
+ * files->next_fd is not updated: this lets the potentially created hole be
+ * filled up on next calls to get_unused_fd_flags.
+ *
+ * Returns the specified fd if successful, -errno else.
+ */
+static int get_predefined_fd_flags(int fd, int flags)
+{
+	struct files_struct *files = current->files;
+	int error;
+	struct fdtable *fdt;
+
+	error = -EINVAL;
+	if (fd < 0)
+		goto out;
+
+	error = -EMFILE;
+	if (fd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
+		goto out;
+
+	spin_lock(&files->file_lock);
+	fdt = files_fdtable(files);
+
+	error = expand_files(files, fd);
+	if (error < 0)
+		goto out_unlock;
+
+	error = -EBUSY;
+	if (FD_ISSET(fd, fdt->open_fds))
+		goto out_unlock;
+
+	FD_SET(fd, fdt->open_fds);
+	if (flags & O_CLOEXEC)
+		FD_SET(fd, fdt->close_on_exec);
+	else
+		FD_CLR(fd, fdt->close_on_exec);
+
+	BUG_ON(fdt->fd[fd] != NULL);
+
+	error = fd;
+out_unlock:
+	spin_unlock(&files->file_lock);
+out:
+	return error;
+}
+
+/*
  * Find an empty file descriptor entry, and mark it busy.
  */
 int get_unused_fd_flags(int flags)
@@ -1081,7 +1130,14 @@ long do_sys_open(int dfd, const char __u
 	int fd = PTR_ERR(tmp);
 
 	if (!IS_ERR(tmp)) {
-		fd = get_unused_fd_flags(flags);
+		if (next_data_set(current)) {
+			int next_fd = get_next_data(current);
+
+			fd = get_predefined_fd_flags(next_fd, flags);
+			reset_next_syscall_data(current);
+		} else
+			fd = get_unused_fd_flags(flags);
+
 		if (fd >= 0) {
 			struct file *f = do_filp_open(dfd, tmp, flags, mode);
 			if (IS_ERR(f)) {

--

  parent reply	other threads:[~2008-07-03 14:40 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-03 14:40 [RFC PATCH 0/5] Resend - Use procfs to change a syscall behavior Nadia.Derbey-6ktuUTfB/bM
2008-07-03 14:40 ` [RFC PATCH 1/5] adds the procfs facilities Nadia.Derbey-6ktuUTfB/bM
     [not found]   ` <20080703144224.723883000-6ktuUTfB/bM@public.gmane.org>
2008-07-07 18:30     ` Serge E. Hallyn
     [not found]       ` <20080707183030.GA22937-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-07-08  5:25         ` Nadia Derbey
2008-07-03 14:40 ` [RFC PATCH 2/5] use next syscall data to predefine ipc objects ids Nadia.Derbey-6ktuUTfB/bM
     [not found]   ` <20080703144224.982195000-6ktuUTfB/bM@public.gmane.org>
2008-07-07 18:35     ` Serge E. Hallyn
     [not found]       ` <20080707183512.GB22937-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-07-08  5:30         ` Nadia Derbey
2008-07-03 14:40 ` [RFC PATCH 3/5] use next syscall data to predefine process ids Nadia.Derbey-6ktuUTfB/bM
     [not found]   ` <20080703144225.489624000-6ktuUTfB/bM@public.gmane.org>
2008-07-07 18:54     ` Serge E. Hallyn
     [not found]       ` <20080707185424.GA25934-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-07-08  5:44         ` Nadia Derbey
2008-07-03 14:40 ` [RFC PATCH 4/5] use next syscall data to change the behavior of IPC_SET Nadia.Derbey-6ktuUTfB/bM
2008-07-03 14:40 ` Nadia.Derbey-6ktuUTfB/bM [this message]
     [not found] ` <20080703144013.737951000-6ktuUTfB/bM@public.gmane.org>
2008-07-04 10:27   ` [RFC PATCH 0/5] Resend - Use procfs to change a syscall behavior Pavel Machek
     [not found]     ` <20080704102702.GB4531-I/5MKhXcvmPrBKCeMvbIDA@public.gmane.org>
2008-07-04 12:07       ` Nadia Derbey
     [not found]         ` <486E1276.2080605-6ktuUTfB/bM@public.gmane.org>
2008-07-08 10:51           ` Pavel Machek
     [not found]             ` <20080708105143.GA15311-I/5MKhXcvmPrBKCeMvbIDA@public.gmane.org>
2008-07-08 21:47               ` Serge E. Hallyn
     [not found]                 ` <20080708214721.GA1972-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-07-08 21:53                   ` Pavel Machek
     [not found]                     ` <20080708215315.GD17083-I/5MKhXcvmPrBKCeMvbIDA@public.gmane.org>
2008-07-10  6:54                       ` Nadia Derbey
     [not found]                         ` <4875B212.5030604-6ktuUTfB/bM@public.gmane.org>
2008-07-10  7:01                           ` [Devel] " Paul Menage
     [not found]                             ` <6599ad830807100001j3f3a6cf2y7a19dda9382edb2c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-10  9:14                               ` Nadia Derbey
     [not found]                                 ` <4875D2EA.4010407-6ktuUTfB/bM@public.gmane.org>
2008-07-10  9:30                                   ` Paul Menage
     [not found]                                     ` <6599ad830807100230k2f3f3551sa4b804f4c20b43fe-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-10 10:11                                       ` Nadia Derbey
2008-07-10  7:42               ` Nadia Derbey
     [not found]                 ` <4875BD4B.2070402-6ktuUTfB/bM@public.gmane.org>
2008-07-10  8:54                   ` Pavel Machek
     [not found]                     ` <20080710085406.GA13258-I/5MKhXcvmPrBKCeMvbIDA@public.gmane.org>
2008-07-10  9:29                       ` Nadia Derbey
2008-07-10 17:53                       ` Dave Hansen
2008-07-10 18:45                         ` Pavel Machek
     [not found]                           ` <20080710184512.GA19428-I/5MKhXcvmPrBKCeMvbIDA@public.gmane.org>
2008-07-10 19:04                             ` Dave Hansen
2008-07-10 19:27                               ` Serge E. Hallyn
2008-07-07 19:01       ` Serge E. Hallyn
     [not found]         ` <20080707190119.GB25934-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-07-08 10:52           ` Pavel Machek
     [not found]             ` <20080708105228.GB15311-I/5MKhXcvmPrBKCeMvbIDA@public.gmane.org>
2008-07-08 21:50               ` Serge E. Hallyn
     [not found]                 ` <20080708215034.GB2179-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-07-08 21:58                   ` Pavel Machek
     [not found]                     ` <20080708215821.GE17083-I/5MKhXcvmPrBKCeMvbIDA@public.gmane.org>
2008-07-09  2:20                       ` Serge E. Hallyn
     [not found]                         ` <20080709022035.GA21249-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-07-10  7:58                           ` Nadia Derbey
     [not found]                             ` <4875C138.5060506-6ktuUTfB/bM@public.gmane.org>
2008-07-10  8:34                               ` [Devel] " Paul Menage
     [not found]                                 ` <6599ad830807100134l362ab98bt868e078eeb17b838-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-10  9:38                                   ` Nadia Derbey
2008-07-17 22:26                           ` Oren Laadan
  -- strict thread matches above, loose matches on Subject: below --
2008-07-08 11:24 [RFC PATCH 0/5] Resend -v2 " Nadia.Derbey-6ktuUTfB/bM
2008-07-08 11:24 ` [RFC PATCH 5/5] use next syscall data to predefine the file descriptor value Nadia.Derbey-6ktuUTfB/bM
     [not found]   ` <20080708112459.632357000-6ktuUTfB/bM@public.gmane.org>
2008-07-08 20:14     ` Serge E. Hallyn
     [not found]       ` <20080708201452.GE22904-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-07-09  5:00         ` kathys
     [not found]           ` <487445E4.6060107-8fk3Idey6ehBDgjK7y7TUQ@public.gmane.org>
2008-07-10  6:12             ` Nadia Derbey
     [not found]               ` <4875A849.1030206-6ktuUTfB/bM@public.gmane.org>
2008-07-14  4:58                 ` kathys
2008-07-10  0:32     ` Eric W. Biederman
     [not found]       ` <m1tzeyefz9.fsf-B27657KtZYmhTnVgQlOflh2eb7JE58TQ@public.gmane.org>
2008-07-10  6:25         ` Nadia Derbey

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=20080703144226.157406000@bull.net \
    --to=nadia.derbey-6ktuutfb/bm@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=pavel-+ZI9xUNit7I@public.gmane.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