login
Login
/
Register
Search
Search this site:
Forums
News
Blogs
Features
Site
Home
»
Mailing list archives
»
linux-kernel
»
2008
»
September
»
16
Re: [RFC v5][PATCH 9/9] Restore open file descriprtors
view
thread
Previous message: [
thread
] [
date
] [
author
]
Next message: [
thread
] [
date
] [
author
]
[view in full thread]
From: Serge E. Hallyn
Subject:
Re: [RFC v5][PATCH 9/9] Restore open file descriprtors
Date: Tuesday, September 16, 2008 - 4:08 pm
Quoting Oren Laadan (
orenl@cs.columbia.edu
):
quoted text
> Restore open file descriptors: for each FD read 'struct cr_hdr_fd_ent' > and lookup objref in the hash table; if not found (first occurence), read > in 'struct cr_hdr_fd_data', create a new FD and register in the hash. > Otherwise attach the file pointer from the hash as an FD. > > This patch only handles basic FDs - regular files, directories and also > symbolic links. > > Signed-off-by: Oren Laadan <orenl@cs.columbia.edu> > --- > checkpoint/Makefile | 2 +- > checkpoint/restart.c | 4 + > checkpoint/rstr_file.c | 202 ++++++++++++++++++++++++++++++++++++++++++++ > include/linux/checkpoint.h | 1 + > 4 files changed, 208 insertions(+), 1 deletions(-) > create mode 100644 checkpoint/rstr_file.c > > diff --git a/checkpoint/Makefile b/checkpoint/Makefile > index 7496695..88bbc10 100644 > --- a/checkpoint/Makefile > +++ b/checkpoint/Makefile > @@ -3,4 +3,4 @@ > # > > obj-$(CONFIG_CHECKPOINT_RESTART) += sys.o checkpoint.o restart.o objhash.o \ > - ckpt_mem.o rstr_mem.o ckpt_file.o > + ckpt_mem.o rstr_mem.o ckpt_file.o rstr_file.o > diff --git a/checkpoint/restart.c b/checkpoint/restart.c > index a0d5e60..956e274 100644 > --- a/checkpoint/restart.c > +++ b/checkpoint/restart.c > @@ -212,6 +212,10 @@ static int cr_read_task(struct cr_ctx *ctx) > cr_debug("memory: ret %d\n", ret); > if (ret < 0) > goto out; > + ret = cr_read_files(ctx); > + cr_debug("files: ret %d\n", ret); > + if (ret < 0) > + goto out; > ret = cr_read_thread(ctx); > cr_debug("thread: ret %d\n", ret); > if (ret < 0) > diff --git a/checkpoint/rstr_file.c b/checkpoint/rstr_file.c > new file mode 100644 > index 0000000..780c0fc > --- /dev/null > +++ b/checkpoint/rstr_file.c > @@ -0,0 +1,202 @@ > +/* > + * Checkpoint file descriptors > + * > + * Copyright (C) 2008 Oren Laadan > + * > + * This file is subject to the terms and conditions of the GNU General Public > + * License. See the file COPYING in the main directory of the Linux > + * distribution for more details. > + */ > + > +#include <linux/kernel.h> > +#include <linux/sched.h> > +#include <linux/fs.h> > +#include <linux/file.h> > +#include <linux/fdtable.h> > +#include <linux/fsnotify.h> > +#include <linux/syscalls.h> > +#include <linux/checkpoint.h> > +#include <linux/checkpoint_hdr.h> > + > +#include "checkpoint_file.h" > + > +static int cr_close_all_fds(struct files_struct *files) > +{ > + int *fdtable; > + int nfds; > + > + nfds = cr_scan_fds(files, &fdtable); > + if (nfds < 0) > + return nfds; > + while (nfds--) > + sys_close(fdtable[nfds]); > + kfree(fdtable); > + return 0; > +} > + > +/** > + * cr_attach_file - attach a lonely file ptr to a file descriptor > + * @file: lonely file pointer > + */ > +static int cr_attach_file(struct file *file) > +{ > + int fd = get_unused_fd_flags(0); > + > + if (fd >= 0) { > + fsnotify_open(file->f_path.dentry); > + fd_install(fd, file); > + } > + return fd; > +} > + > +#define CR_SETFL_MASK (O_APPEND|O_NONBLOCK|O_NDELAY|FASYNC|O_DIRECT|O_NOATIME) > + > +/* cr_read_fd_data - restore the state of a given file pointer */ > +static int > +cr_read_fd_data(struct cr_ctx *ctx, struct files_struct *files, int parent) > +{ > + struct cr_hdr_fd_data *hh = cr_hbuf_get(ctx, sizeof(*hh));
You're leaking hh in a whole slew of error paths.
quoted text
> + struct file *file; > + int fd, rparent, ret; > + > + rparent = cr_read_obj_type(ctx, hh, sizeof(*hh), CR_HDR_FD_DATA); > + cr_debug("rparent %d parent %d flags %#x mode %#x how %d\n", > + rparent, parent, hh->f_flags, hh->f_mode, hh->fd_type); > + if (rparent < 0) > + return rparent; > + if (rparent != parent) > + return -EINVAL; > + /* FIX: more sanity checks on f_flags, f_mode etc */ > + > + switch (hh->fd_type) { > + case CR_FD_FILE: > + case CR_FD_DIR: > + case CR_FD_LINK: > + file = cr_read_open_fname(ctx, hh->f_flags, hh->f_mode); > + break; > + default: > + file = ERR_PTR(-EINVAL); > + break; > + } > + > + if (IS_ERR(file)) > + return PTR_ERR(file); > + > + /* FIX: need to restore uid, gid, owner etc */ > + > + fd = cr_attach_file(file); /* no need to cleanup 'file' below */ > + if (fd < 0) { > + filp_close(file, NULL); > + return fd; > + } > + > + /* register new <objref, file> tuple in hash table */ > + ret = cr_obj_add_ref(ctx, (void *) file, parent, CR_OBJ_FILE, 0); > + if (ret < 0) > + goto out; > + ret = sys_fcntl(fd, F_SETFL, hh->f_flags & CR_SETFL_MASK); > + if (ret < 0) > + goto out; > + ret = vfs_llseek(file, hh->f_pos, SEEK_SET); > + if (ret == -ESPIPE) /* ignore error on non-seekable files */ > + ret = 0; > + > + out: > + cr_hbuf_put(ctx, sizeof(*hh)); > + return ret < 0 ? ret : fd; > +} > + > +/** > + * cr_read_fd_ent - restore the state of a given file descriptor > + * @ctx: checkpoint context > + * @files: files_struct pointer > + * @parent: parent objref > + * > + * Restores the state of a file descriptor; looks up the objref (in the > + * header) in the hash table, and if found picks the matching file and > + * use it; otherwise calls cr_read_fd_data to restore the file too. > + */ > +static int > +cr_read_fd_ent(struct cr_ctx *ctx, struct files_struct *files, int parent) > +{ > + struct cr_hdr_fd_ent *hh = cr_hbuf_get(ctx, sizeof(*hh));
Again.
quoted text
> + struct file *file; > + int newfd, rparent; > + > + rparent = cr_read_obj_type(ctx, hh, sizeof(*hh), CR_HDR_FD_ENT); > + cr_debug("rparent %d parent %d ref %d\n", rparent, parent, hh->objref); > + if (rparent < 0) > + return rparent; > + if (rparent != parent) > + return -EINVAL; > + cr_debug("fd %d coe %d\n", hh->fd, hh->close_on_exec); > + if (hh->objref <= 0) > + return -EINVAL; > + > + file = cr_obj_get_by_ref(ctx, hh->objref, CR_OBJ_FILE); > + if (IS_ERR(file)) > + return PTR_ERR(file); > + > + if (file) { > + newfd = cr_attach_file(file); > + if (newfd < 0) > + return newfd; > + get_file(file); > + } else { > + /* create new file pointer (and register in hash table) */ > + newfd = cr_read_fd_data(ctx, files, hh->objref); > + if (newfd < 0) > + return newfd; > + } > + > + cr_debug("newfd got %d wanted %d\n", newfd, hh->fd); > + > + /* if newfd isn't desired fd then reposition it */ > + if (newfd != hh->fd) { > + int ret = sys_dup2(newfd, hh->fd); > + if (ret < 0) > + return ret; > + sys_close(newfd); > + } > + > + if (hh->close_on_exec) > + set_close_on_exec(hh->fd, 1); > + > + cr_hbuf_put(ctx, sizeof(*hh)); > + return 0; > +} > + > +int cr_read_files(struct cr_ctx *ctx) > +{ > + struct cr_hdr_files *hh = cr_hbuf_get(ctx, sizeof(*hh));
Again...
quoted text
> + struct files_struct *files = current->files; > + int i, parent, ret; > + > + parent = cr_read_obj_type(ctx, hh, sizeof(*hh), CR_HDR_FILES); > + if (parent < 0) > + return parent; > +#if 0 /* activate when containers are used */ > + if (parent != task_pid_vnr(current)) > + return -EINVAL; > +#endif > + cr_debug("objref %d nfds %d\n", hh->objref, hh->nfds); > + if (hh->objref < 0 || hh->nfds < 0) > + return -EINVAL; > + > + if (hh->nfds > sysctl_nr_open) > + return -EMFILE; > + > + /* point of no return -- close all file descriptors */ > + ret = cr_close_all_fds(files); > + if (ret < 0) > + return ret; > + > + for (i = 0; i < hh->nfds; i++) { > + ret = cr_read_fd_ent(ctx, files, hh->objref); > + if (ret < 0) > + break; > + } > + > + cr_hbuf_put(ctx, sizeof(*hh)); > + return ret; > +} > diff --git a/include/linux/checkpoint.h b/include/linux/checkpoint.h > index a202c54..fd3baac 100644 > --- a/include/linux/checkpoint.h > +++ b/include/linux/checkpoint.h > @@ -89,6 +89,7 @@ extern int cr_write_files(struct cr_ctx *ctx, struct task_struct *t); > > extern int do_restart(struct cr_ctx *ctx); > extern int cr_read_mm(struct cr_ctx *ctx); > +extern int cr_read_files(struct cr_ctx *ctx); > > #define cr_debug(fmt, args...) \ > pr_debug("[CR:%s] " fmt, __func__, ## args) > -- > 1.5.4.3 > > _______________________________________________ > Containers mailing list >
Containers@lists.linux-foundation.org
>
https://lists.linux-foundation.org/mailman/listinfo/containers
--
unsubscribe notice
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to
majordomo@vger.kernel.org
More majordomo info at
http://vger.kernel.org/majordomo-info.html
Please read the FAQ at
http://www.tux.org/lkml/
Previous message: [
thread
] [
date
] [
author
]
Next message: [
thread
] [
date
] [
author
]
Messages in current thread:
[RFC v5][PATCH 0/9] Kernel based checkpoint/restart
, Oren Laadan
, (Sat Sep 13, 4:05 pm)
[RFC v5][PATCH 1/8] Create syscalls: sys_checkpoint, sys_r ...
, Oren Laadan
, (Sat Sep 13, 4:05 pm)
[RFC v5][PATCH 2/8] General infrastructure for checkpoint ...
, Oren Laadan
, (Sat Sep 13, 4:06 pm)
[RFC v5][PATCH 3/8] x86 support for checkpoint/restart
, Oren Laadan
, (Sat Sep 13, 4:06 pm)
[RFC v5][PATCH 4/8] Dump memory address space
, Oren Laadan
, (Sat Sep 13, 4:06 pm)
[RFC v5][PATCH 5/8] Restore memory address space
, Oren Laadan
, (Sat Sep 13, 4:06 pm)
[RFC v5][PATCH 6/8] Checkpoint/restart: initial documentation
, Oren Laadan
, (Sat Sep 13, 4:06 pm)
[RFC v5][PATCH 7/8] Infrastructure for shared objects
, Oren Laadan
, (Sat Sep 13, 4:06 pm)
[RFC v5][PATCH 8/8] Dump open file descriptors
, Oren Laadan
, (Sat Sep 13, 4:06 pm)
[RFC v5][PATCH 9/9] Restore open file descriprtors
, Oren Laadan
, (Sat Sep 13, 4:06 pm)
[RFC v5][PATCH 9/9] Restore open file descriprtors
, Oren Laadan
, (Sat Sep 13, 4:22 pm)
Re: [RFC v5][PATCH 8/8] Dump open file descriptors
, Bastian Blank
, (Sun Sep 14, 2:51 am)
Re: [RFC v5][PATCH 8/8] Dump open file descriptors
, Oren Laadan
, (Sun Sep 14, 8:40 am)
Re: [RFC v5][PATCH 2/8] General infrastructure for checkpo ...
, Dave Hansen
, (Mon Sep 15, 10:54 am)
Re: [RFC v5][PATCH 2/8] General infrastructure for checkpo ...
, Dave Hansen
, (Mon Sep 15, 10:59 am)
Re: [RFC v5][PATCH 2/8] General infrastructure for checkpo ...
, Dave Hansen
, (Mon Sep 15, 11:00 am)
Re: [RFC v5][PATCH 2/8] General infrastructure for checkpo ...
, Dave Hansen
, (Mon Sep 15, 11:02 am)
Re: [RFC v5][PATCH 2/8] General infrastructure for checkpo ...
, Oren Laadan
, (Mon Sep 15, 11:52 am)
Re: [RFC v5][PATCH 2/8] General infrastructure for checkpo ...
, Dave Hansen
, (Mon Sep 15, 12:13 pm)
Re: [RFC v5][PATCH 5/8] Restore memory address space
, Dave Hansen
, (Mon Sep 15, 12:14 pm)
Re: [RFC v5][PATCH 6/8] Checkpoint/restart: initial docume ...
, Serge E. Hallyn
, (Mon Sep 15, 1:26 pm)
Re: [RFC v5][PATCH 1/8] Create syscalls: sys_checkpoint, s ...
, Serge E. Hallyn
, (Mon Sep 15, 1:28 pm)
Re: [RFC v5][PATCH 2/8] General infrastructure for checkpo ...
, Serge E. Hallyn
, (Mon Sep 15, 2:15 pm)
Re: [RFC v5][PATCH 3/8] x86 support for checkpoint/restart
, Serge E. Hallyn
, (Mon Sep 15, 2:31 pm)
Re: [RFC v5][PATCH 2/8] General infrastructure for checkpo ...
, Bastian Blank
, (Tue Sep 16, 5:27 am)
Re: [RFC v5][PATCH 8/8] Dump open file descriptors
, Dave Hansen
, (Tue Sep 16, 8:54 am)
Re: [RFC v5][PATCH 7/8] Infrastructure for shared objects
, Dave Hansen
, (Tue Sep 16, 9:48 am)
Re: [RFC v5][PATCH 8/8] Dump open file descriptors
, Dave Hansen
, (Tue Sep 16, 9:55 am)
Re: [RFC v5][PATCH 7/8] Infrastructure for shared objects
, Serge E. Hallyn
, (Tue Sep 16, 1:54 pm)
Re: [RFC v5][PATCH 7/8] Infrastructure for shared objects
, Oren Laadan
, (Tue Sep 16, 2:36 pm)
Re: [RFC v5][PATCH 7/8] Infrastructure for shared objects
, Serge E. Hallyn
, (Tue Sep 16, 3:09 pm)
Re: [RFC v5][PATCH 8/8] Dump open file descriptors
, Serge E. Hallyn
, (Tue Sep 16, 4:03 pm)
Re: [RFC v5][PATCH 9/9] Restore open file descriprtors
, Serge E. Hallyn
, (Tue Sep 16, 4:08 pm)
Re: [RFC v5][PATCH 9/9] Restore open file descriprtors
, Oren Laadan
, (Tue Sep 16, 5:11 pm)
Re: [RFC v5][PATCH 9/9] Restore open file descriprtors
, Serge E. Hallyn
, (Tue Sep 16, 9:56 pm)
Re: [RFC v5][PATCH 6/8] Checkpoint/restart: initial docume ...
, MinChan Kim
, (Tue Sep 16, 11:23 pm)
Re: [RFC v5][PATCH 4/8] Dump memory address space
, MinChan Kim
, (Tue Sep 16, 11:48 pm)
Re: [RFC v5][PATCH 7/8] Infrastructure for shared objects
, MinChan Kim
, (Wed Sep 17, 12:31 am)
Re: [RFC v5][PATCH 0/9] Kernel based checkpoint/restart
, Serge E. Hallyn
, (Wed Sep 17, 7:16 am)
Re: [RFC v5][PATCH 8/8] Dump open file descriptors
, Dave Hansen
, (Mon Sep 22, 8:31 am)
Re: [RFC v5][PATCH 9/9] Restore open file descriprtors
, Dave Hansen
, (Mon Sep 22, 9:02 am)
Re: [RFC v5][PATCH 0/9] Kernel based checkpoint/restart
, Serge E. Hallyn
, (Wed Sep 24, 2:42 pm)
Re: [RFC v5][PATCH 0/9] Kernel based checkpoint/restart
, Cedric Le Goater
, (Thu Sep 25, 5:58 am)
Re: [RFC v5][PATCH 0/9] Kernel based checkpoint/restart
, Oren Laadan
, (Wed Oct 8, 2:59 am)
Navigation
Mailing list archives
Recent posts
Popular discussions
linux-kernel
:
Mel Gorman
Re: [PATCH 1/4] vmstat: remove zone->lock from walk_zones_in_node
Guenter Roeck
Re: [lm-sensors] Location for thermal drivers
David Woodhouse
Re: RFC: Moving firmware blobs out of the kernel.
Siddha, Suresh B
Re: [PATCH 2.6.21 review I] [11/25] x86: default to physical mode on hotplug CPU k...
Peter Zijlstra
Re: [patch 4/6] mm: merge populate and nopage into fault (fixes nonlinear)
git-commits-head
:
Linux Kernel Mailing List
[MIPS] Fix potential latency problem due to non-atomic cpu_wait.
Linux Kernel Mailing List
USB: rename USB_SPEED_VARIABLE to USB_SPEED_WIRELESS
Linux Kernel Mailing List
lib/vsprintf.c: fix bug omitting minus sign of numbers (module_param)
Linux Kernel Mailing List
[Bluetooth] Initiate authentication during connection establishment
Linux Kernel Mailing List
[POWERPC] 4xx: Add ppc40x_defconfig
linux-netdev
:
MERCEDES
Your mail id has won 950,000.00 in the MERCEDES Benz Online Promo.for claims send:
David Miller
Re: [PATCH] xen/netfront: do not mark packets of length < MSS as GSO
David Miller
Re: skb_segment() questions
Shan Wei
[RFC PATCH net-next 2/5]IPv6:netfilter: Send an ICMPv6 "Fragment Reassembly Timeou...
Stanislaw Gruszka
[PATCH 1/4] bnx2x: use smp_mb() to keep ordering of read write operations
git
:
Nicolas Sebrecht
git-svn died of signal 11 (was "3 failures on test t9100 (svn)")
Junio C Hamano
Re: [PATCH 2/2] Add url.<base>.pushInsteadOf: URL rewriting for push only
Martin Langhoff
Re: [PATCH] GIT commit statistics.
Alexandre Julliard
[PATCH] gitweb: Put back shortlog instead of graphiclog in the project list.
Josh Triplett
[PATCH 2/2] Add url.<base>.pushInsteadOf: URL rewriting for push only
openbsd-misc
:
Taisto Qvist XX
Re: AMD GEODE LX-800 just works with kernel from install42.iso and kernelpanics wi...
Nico Meijer
Re: gOS Develop Kit with VIA pc-1 Processor Platform VIA C7-D
Andreas Bihlmaier
Re: jetway board sensors (Fintek F71805F)
admin
Drive a 2009 car from R799p/m
Antti Harri
Re: how to create a sha256 hash
Colocation donated by:
Syndicate