summaryrefslogtreecommitdiff
path: root/fs/file.c
diff options
context:
space:
mode:
authorDipankar Sarma <dipankar@in.ibm.com>2005-09-09 13:04:10 -0700
committerLinus Torvalds <torvalds@g5.osdl.org>2005-09-09 13:57:55 -0700
commitbadf16621c1f9d1ac753be056fce11b43d6e0be5 (patch)
tree3fdf833fdf2e3d3a439090743539680449ec3428 /fs/file.c
parentc0dfb2905126e9e94edebbce8d3e05001301f52d (diff)
[PATCH] files: break up files struct
In order for the RCU to work, the file table array, sets and their sizes must be updated atomically. Instead of ensuring this through too many memory barriers, we put the arrays and their sizes in a separate structure. This patch takes the first step of putting the file table elements in a separate structure fdtable that is embedded withing files_struct. It also changes all the users to refer to the file table using files_fdtable() macro. Subsequent applciation of RCU becomes easier after this. Signed-off-by: Dipankar Sarma <dipankar@in.ibm.com> Signed-Off-By: David Howells <dhowells@redhat.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/file.c')
-rw-r--r--fs/file.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/fs/file.c b/fs/file.c
index 92b5f25985d..f5926ce73f3 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -59,13 +59,15 @@ static int expand_fd_array(struct files_struct *files, int nr)
{
struct file **new_fds;
int error, nfds;
+ struct fdtable *fdt;
error = -EMFILE;
- if (files->max_fds >= NR_OPEN || nr >= NR_OPEN)
+ fdt = files_fdtable(files);
+ if (fdt->max_fds >= NR_OPEN || nr >= NR_OPEN)
goto out;
- nfds = files->max_fds;
+ nfds = fdt->max_fds;
spin_unlock(&files->file_lock);
/*
@@ -95,13 +97,14 @@ static int expand_fd_array(struct files_struct *files, int nr)
goto out;
/* Copy the existing array and install the new pointer */
+ fdt = files_fdtable(files);
- if (nfds > files->max_fds) {
+ if (nfds > fdt->max_fds) {
struct file **old_fds;
int i;
- old_fds = xchg(&files->fd, new_fds);
- i = xchg(&files->max_fds, nfds);
+ old_fds = xchg(&fdt->fd, new_fds);
+ i = xchg(&fdt->max_fds, nfds);
/* Don't copy/clear the array if we are creating a new
fd array for fork() */
@@ -164,12 +167,14 @@ static int expand_fdset(struct files_struct *files, int nr)
{
fd_set *new_openset = NULL, *new_execset = NULL;
int error, nfds = 0;
+ struct fdtable *fdt;
error = -EMFILE;
- if (files->max_fdset >= NR_OPEN || nr >= NR_OPEN)
+ fdt = files_fdtable(files);
+ if (fdt->max_fdset >= NR_OPEN || nr >= NR_OPEN)
goto out;
- nfds = files->max_fdset;
+ nfds = fdt->max_fdset;
spin_unlock(&files->file_lock);
/* Expand to the max in easy steps */
@@ -193,24 +198,25 @@ static int expand_fdset(struct files_struct *files, int nr)
error = 0;
/* Copy the existing tables and install the new pointers */
- if (nfds > files->max_fdset) {
- int i = files->max_fdset / (sizeof(unsigned long) * 8);
- int count = (nfds - files->max_fdset) / 8;
+ fdt = files_fdtable(files);
+ if (nfds > fdt->max_fdset) {
+ int i = fdt->max_fdset / (sizeof(unsigned long) * 8);
+ int count = (nfds - fdt->max_fdset) / 8;
/*
* Don't copy the entire array if the current fdset is
* not yet initialised.
*/
if (i) {
- memcpy (new_openset, files->open_fds, files->max_fdset/8);
- memcpy (new_execset, files->close_on_exec, files->max_fdset/8);
+ memcpy (new_openset, fdt->open_fds, fdt->max_fdset/8);
+ memcpy (new_execset, fdt->close_on_exec, fdt->max_fdset/8);
memset (&new_openset->fds_bits[i], 0, count);
memset (&new_execset->fds_bits[i], 0, count);
}
- nfds = xchg(&files->max_fdset, nfds);
- new_openset = xchg(&files->open_fds, new_openset);
- new_execset = xchg(&files->close_on_exec, new_execset);
+ nfds = xchg(&fdt->max_fdset, nfds);
+ new_openset = xchg(&fdt->open_fds, new_openset);
+ new_execset = xchg(&fdt->close_on_exec, new_execset);
spin_unlock(&files->file_lock);
free_fdset (new_openset, nfds);
free_fdset (new_execset, nfds);
@@ -237,13 +243,15 @@ out:
int expand_files(struct files_struct *files, int nr)
{
int err, expand = 0;
+ struct fdtable *fdt;
- if (nr >= files->max_fdset) {
+ fdt = files_fdtable(files);
+ if (nr >= fdt->max_fdset) {
expand = 1;
if ((err = expand_fdset(files, nr)))
goto out;
}
- if (nr >= files->max_fds) {
+ if (nr >= fdt->max_fds) {
expand = 1;
if ((err = expand_fd_array(files, nr)))
goto out;