From: Oren Laadan <orenl@cs.columbia.edu>
To: Dave Hansen <dave@linux.vnet.ibm.com>
Cc: arnd@arndb.de, jeremy@goop.org, linux-kernel@vger.kernel.org,
containers@lists.linux-foundation.org
Subject: Re: [RFC v3][PATCH 8/9] File descriprtors (dump)
Date: Sun, 07 Sep 2008 00:52:12 -0400 [thread overview]
Message-ID: <48C35DFC.9080903@cs.columbia.edu> (raw)
In-Reply-To: <1220553660.23386.60.camel@nimitz>
Dave Hansen wrote:
> On Thu, 2008-09-04 at 04:05 -0400, Oren Laadan wrote:
>> +/**
>> + * cr_scan_fds - scan file table and construct array of open fds
>> + * @files: files_struct pointer
>> + * @fdtable: (output) array of open fds
>> + * @return: the number of open fds found
>> + *
>> + * Allocates the file descriptors array (*fdtable), caller should free
>> + */
>> +int cr_scan_fds(struct files_struct *files, int **fdtable)
>> +{
>> + struct fdtable *fdt;
>> + int *fdlist;
>> + int i, n, max;
>> +
>> + max = CR_DEFAULT_FDTABLE;
>> +
>> + repeat:
>> + n = 0;
>> + fdlist = kmalloc(max * sizeof(*fdlist), GFP_KERNEL);
>> + if (!fdlist)
>> + return -ENOMEM;
>> +
>> + spin_lock(&files->file_lock);
>> + fdt = files_fdtable(files);
>> + for (i = 0; i < fdt->max_fds; i++) {
>> + if (fcheck_files(files, i)) {
>> + if (n == max) {
>> + spin_unlock(&files->file_lock);
>> + kfree(fdlist);
>> + max *= 2;
>> + if (max < 0) { /* overflow ? */
>> + n = -EMFILE;
>> + break;
>> + }
>> + goto repeat;
>> + }
>> + fdlist[n++] = i;
>> + }
>> + }
>> + spin_unlock(&files->file_lock);
>> +
>> + *fdtable = fdlist;
>> + return n;
>> +}
>
> That loop needs some love. At least save us from one level of
> indenting:
>
>> + for (i = 0; i < fdt->max_fds; i++) {
>> + if (!fcheck_files(files, i)
>> continue;
>> if (n == max) {
>> + spin_unlock(&files->file_lock);
>> + kfree(fdlist);
>> + max *= 2;
>> + if (max < 0) { /* overflow ? */
>> + n = -EMFILE;
>> + break;
>> + }
>> + goto repeat;
>> + }
>> + fdlist[n++] = i;
>> + }
>
> My gut also says that there has to be a better way to find a good size
> for fdlist() than growing it this way.
Can you suggest a better way to find the open files of a task ?
Either I loop twice (loop to count, then allocate, then loop to fill),
or optimistically try an initial guess and expand on demand.
>
> Why do we even have a fixed size for this?
>
> +#define CR_DEFAULT_FDTABLE 256
>
>> +/* cr_write_fd_data - dump the state of a given file pointer */
>> +static int cr_write_fd_data(struct cr_ctx *ctx, struct file *file, int parent)
>> +{
>> + struct cr_hdr h;
>> + struct cr_hdr_fd_data *hh = cr_hbuf_get(ctx, sizeof(*hh));
>> + struct dentry *dent = file->f_dentry;
>> + struct inode *inode = dent->d_inode;
>> + enum fd_type fd_type;
>> + int ret;
>> +
>> + h.type = CR_HDR_FD_DATA;
>> + h.len = sizeof(*hh);
>> + h.parent = parent;
>> +
>> + BUG_ON(!inode);
>
> Why a BUG_ON()? We'll deref it in just a sec anyway. We prefer to just
> get the NULL dereference rather than an explicit BUG_ON().
>
>> + hh->f_flags = file->f_flags;
>> + hh->f_mode = file->f_mode;
>> + hh->f_pos = file->f_pos;
>> + hh->f_uid = file->f_uid;
>> + hh->f_gid = file->f_gid;
>
> Is there a plan to save off the 'struct user' here instead? Nested user
> namespaces in one checkpoint image might get confused otherwise.
Of course. Eventually, 'struct user' will be another shared object that
is encountered and saved with the checkpoint image.
>
>> + hh->f_version = file->f_version;
>> + /* FIX: need also file->f_owner */
>> +
>> + switch (inode->i_mode & S_IFMT) {
>> + case S_IFREG:
>> + fd_type = CR_FD_FILE;
>> + break;
>> + case S_IFDIR:
>> + fd_type = CR_FD_DIR;
>> + break;
>> + case S_IFLNK:
>> + fd_type = CR_FD_LINK;
>> + break;
>> + default:
>> + return -EBADF;
>> + }
>
> Why don't we just store (and use) (inode->i_mode & S_IFMT) in fd_type
> instead of making our own types?
There will be others that cannot be inferred from inode->i_mode,
e.g. CR_FD_FILE_UNLINKED, CR_FD_DIR_UNLINKED, CR_FD_SOCK_UNIX,
CR_FD_SOCK_INET_V4, CR_FD_EVENTPOLL etc.
>
>> + /* FIX: check if the file/dir/link is unlinked */
>> + hh->fd_type = fd_type;
[...]
Oren.
next prev parent reply other threads:[~2008-09-07 4:55 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-04 7:57 [RFC v3][PATCH 0/9] Kernel based checkpoint/restart Oren Laadan
2008-09-04 8:02 ` [RFC v3][PATCH 1/9] Create syscalls: sys_checkpoint, sys_restart Oren Laadan
2008-09-04 8:37 ` Cedric Le Goater
[not found] ` <Pine.LNX.4.64.0809040401320.5982-CXF6herHY6ykSYb+qCZC/1i27PF6R63G9nwVQlTi/Pw@public.gmane.org>
2008-09-04 8:37 ` Cedric Le Goater
2008-09-04 14:42 ` Serge E. Hallyn
2008-09-04 14:42 ` Serge E. Hallyn
2008-09-04 17:32 ` Oren Laadan
[not found] ` <48C01B92.60900-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2008-09-04 20:37 ` Serge E. Hallyn
2008-09-04 20:37 ` Serge E. Hallyn
[not found] ` <20080904203730.GA28313-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-09-04 21:05 ` Oren Laadan
2008-09-04 21:05 ` Oren Laadan
2008-09-04 22:03 ` Serge E. Hallyn
[not found] ` <48C04D7C.6020500-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2008-09-04 22:03 ` Serge E. Hallyn
2008-09-08 15:02 ` [Devel] " Andrey Mirkin
[not found] ` <200809081902.33709.amirkin-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2008-09-08 16:07 ` Cedric Le Goater
2008-09-08 16:07 ` Cedric Le Goater
[not found] ` <20080904144223.GA19364-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-09-04 17:32 ` Oren Laadan
2008-09-08 15:02 ` [Devel] " Andrey Mirkin
[not found] ` <Pine.LNX.4.64.0809040354440.460-CXF6herHY6ykSYb+qCZC/1i27PF6R63G9nwVQlTi/Pw@public.gmane.org>
2008-09-04 8:02 ` Oren Laadan
2008-09-04 8:02 ` [RFC v3][PATCH 2/9] General infrastructure for checkpoint restart Oren Laadan
2008-09-04 8:03 ` [RFC v3][PATCH 3/9] x86 support for checkpoint/restart Oren Laadan
2008-09-04 8:03 ` [RFC v3][PATCH 4/9] Memory management (dump) Oren Laadan
2008-09-04 8:04 ` [RFC v3][PATCH 5/9] Memory managemnet (restore) Oren Laadan
2008-09-04 8:04 ` [RFC v3][PATCH 6/9] Checkpoint/restart: initial documentation Oren Laadan
2008-09-04 8:05 ` [RFC v3][PATCH 7/9] Infrastructure for shared objects Oren Laadan
2008-09-04 8:05 ` [RFC v3][PATCH 8/9] File descriprtors (dump) Oren Laadan
2008-09-04 8:06 ` [RFC v3][PATCH 9/9] File descriprtors (restore) Oren Laadan
2008-09-04 8:02 ` [RFC v3][PATCH 2/9] General infrastructure for checkpoint restart Oren Laadan
[not found] ` <Pine.LNX.4.64.0809040402170.5982-CXF6herHY6ykSYb+qCZC/1i27PF6R63G9nwVQlTi/Pw@public.gmane.org>
2008-09-04 9:12 ` Louis Rilling
2008-09-04 9:12 ` Louis Rilling
[not found] ` <20080904091230.GW14473-Hu8+6S1rdjywhHL9vcZdMVaTQe2KTcn/@public.gmane.org>
2008-09-04 16:00 ` Serge E. Hallyn
2008-09-04 16:00 ` Serge E. Hallyn
2008-09-04 16:03 ` Serge E. Hallyn
2008-09-04 16:03 ` Serge E. Hallyn
[not found] ` <20080904160311.GC19364-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-09-04 16:09 ` Dave Hansen
2008-09-04 16:09 ` Dave Hansen
2008-09-04 8:03 ` [RFC v3][PATCH 3/9] x86 support for checkpoint/restart Oren Laadan
2008-09-04 8:03 ` [RFC v3][PATCH 4/9] Memory management (dump) Oren Laadan
[not found] ` <Pine.LNX.4.64.0809040403120.5982-CXF6herHY6ykSYb+qCZC/1i27PF6R63G9nwVQlTi/Pw@public.gmane.org>
2008-09-04 18:25 ` Dave Hansen
2008-09-04 18:25 ` Dave Hansen
2008-09-07 1:54 ` Oren Laadan
2008-09-07 1:54 ` Oren Laadan
[not found] ` <48C3343D.9000407-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2008-09-08 15:55 ` Dave Hansen
2008-09-08 15:55 ` Dave Hansen
2008-09-04 8:04 ` [RFC v3][PATCH 5/9] Memory managemnet (restore) Oren Laadan
2008-09-04 18:08 ` Dave Hansen
2008-09-07 3:09 ` Oren Laadan
[not found] ` <48C345D2.1020603-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2008-09-08 16:49 ` Dave Hansen
2008-09-08 16:49 ` Dave Hansen
2008-09-09 6:01 ` Oren Laadan
2008-09-09 6:01 ` Oren Laadan
2008-09-10 21:42 ` Dave Hansen
2008-09-10 22:00 ` Cleanups for: [PATCH " Dave Hansen
2008-09-10 22:00 ` Dave Hansen
2008-09-11 7:37 ` [RFC v3][PATCH " Oren Laadan
2008-09-11 15:38 ` Serge E. Hallyn
[not found] ` <48C8CAC6.3090209-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2008-09-11 15:38 ` Serge E. Hallyn
2008-09-12 16:34 ` Dave Hansen
2008-09-12 16:34 ` Dave Hansen
2008-09-11 7:37 ` Oren Laadan
[not found] ` <48C6113A.3080804-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2008-09-10 21:42 ` Dave Hansen
2008-09-07 3:09 ` Oren Laadan
[not found] ` <Pine.LNX.4.64.0809040404060.5982-CXF6herHY6ykSYb+qCZC/1i27PF6R63G9nwVQlTi/Pw@public.gmane.org>
2008-09-04 18:08 ` Dave Hansen
2008-09-04 8:04 ` [RFC v3][PATCH 6/9] Checkpoint/restart: initial documentation Oren Laadan
2008-09-04 8:05 ` [RFC v3][PATCH 7/9] Infrastructure for shared objects Oren Laadan
[not found] ` <Pine.LNX.4.64.0809040404550.5982-CXF6herHY6ykSYb+qCZC/1i27PF6R63G9nwVQlTi/Pw@public.gmane.org>
2008-09-04 9:38 ` Louis Rilling
2008-09-04 18:14 ` Dave Hansen
2008-09-04 9:38 ` Louis Rilling
[not found] ` <20080904093803.GX14473-Hu8+6S1rdjywhHL9vcZdMVaTQe2KTcn/@public.gmane.org>
2008-09-04 14:23 ` Oren Laadan
2008-09-04 14:23 ` Oren Laadan
2008-09-04 18:14 ` Dave Hansen
2008-09-04 8:05 ` [RFC v3][PATCH 8/9] File descriprtors (dump) Oren Laadan
2008-09-04 9:47 ` Louis Rilling
2008-09-04 14:43 ` Oren Laadan
[not found] ` <20080904094740.GY14473-Hu8+6S1rdjywhHL9vcZdMVaTQe2KTcn/@public.gmane.org>
2008-09-04 14:43 ` Oren Laadan
2008-09-04 15:01 ` Dave Hansen
[not found] ` <Pine.LNX.4.64.0809040405250.5982-CXF6herHY6ykSYb+qCZC/1i27PF6R63G9nwVQlTi/Pw@public.gmane.org>
2008-09-04 9:47 ` Louis Rilling
2008-09-04 15:01 ` Dave Hansen
2008-09-04 18:41 ` Dave Hansen
2008-09-04 18:41 ` Dave Hansen
2008-09-07 4:52 ` Oren Laadan
2008-09-07 4:52 ` Oren Laadan [this message]
2008-09-08 16:57 ` Dave Hansen
[not found] ` <48C35DFC.9080903-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2008-09-08 16:57 ` Dave Hansen
2008-09-04 8:06 ` [RFC v3][PATCH 9/9] File descriprtors (restore) 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=48C35DFC.9080903@cs.columbia.edu \
--to=orenl@cs.columbia.edu \
--cc=arnd@arndb.de \
--cc=containers@lists.linux-foundation.org \
--cc=dave@linux.vnet.ibm.com \
--cc=jeremy@goop.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.