[minor patch] exit_files()/exit_mm() -> NULL vs &init_xx

Andrea Arcangeli (andrea@e-mind.com)
Sun, 2 May 1999 02:39:27 +0200 (CEST)


In exit_files() we are taking a different approch than in exit_mm().

I think it's desiderable to have an always valid current->files. There are
cases where we may want to browse all file descriptors opened by every
task in the system.

Currently the only piece of code that may cause a current->files to become
NULL are two kernel threads: lockd and rcpiod. They are using exit_files()
to close all file descriptors. So I think we could change exit_files() to
do this:

Index: kernel/exit.c
===================================================================
RCS file: /var/cvs/linux/kernel/exit.c,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 exit.c
--- exit.c 1999/05/02 00:06:00 1.1.2.8
+++ linux/kernel/exit.c 1999/05/02 00:07:31
@@ -184,8 +184,8 @@
{
struct files_struct * files = tsk->files;

- if (files) {
- tsk->files = NULL;
+ if (files != &init_files) {
+ tsk->files = &init_files;
if (atomic_dec_and_test(&files->count)) {
close_files(files);
/*
Index: include/linux/sched.h
===================================================================
RCS file: /var/cvs/linux/include/linux/sched.h,v
retrieving revision 1.1.2.23
diff -u -r1.1.2.23 sched.h
--- sched.h 1999/04/24 01:44:51 1.1.2.23
+++ linux/include/linux/sched.h 1999/05/02 00:07:18
@@ -402,6 +402,7 @@
extern union task_union init_task_union;

extern struct mm_struct init_mm;
+extern struct files_struct init_files;
extern struct task_struct *task[NR_TASKS];

extern struct task_struct **tarray_freelist;
Index: arch/i386/kernel/init_task.c
===================================================================
RCS file: /var/cvs/linux/arch/i386/kernel/init_task.c,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 init_task.c
--- init_task.c 1999/01/18 01:37:07 1.1.2.1
+++ linux/arch/i386/kernel/init_task.c 1999/05/02 00:11:19
@@ -8,7 +8,7 @@
static struct vm_area_struct init_mmap = INIT_MMAP;
static struct fs_struct init_fs = INIT_FS;
static struct file * init_fd_array[NR_OPEN] = { NULL, };
-static struct files_struct init_files = INIT_FILES;
+struct files_struct init_files = INIT_FILES;
static struct signal_struct init_signals = INIT_SIGNALS;
struct mm_struct init_mm = INIT_MM;

This way we'll be sure to have an always vaild current->files for all
tasks.

We could take a different path: we could avoid all special cases in
__exit_files() and do by hand in the kernel-daemon initialization code:

exit_files(current);
current->files = init_task.files;
atomic_inc(&current->files->count);

(as kmod does for current->fs), instead of the only:

exit_files(current);

I taken the approch in the patch because I see it a bit more clean and in
order to follow what exit_mm() is doing just now. I am supposing such
additional check won't be a performance issue.

Comments?

Andrea Arcangeli

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/