vserver 1.9.5.x5
[linux-2.6.git] / fs / file.c
index d40c402..92b5f25 100644 (file)
--- a/fs/file.c
+++ b/fs/file.c
@@ -12,8 +12,7 @@
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/file.h>
-
-#include <asm/bitops.h>
+#include <linux/bitops.h>
 
 
 /*
@@ -54,7 +53,9 @@ void free_fd_array(struct file **array, int num)
  * spinlock held for write.
  */
 
-int expand_fd_array(struct files_struct *files, int nr)
+static int expand_fd_array(struct files_struct *files, int nr)
+       __releases(files->file_lock)
+       __acquires(files->file_lock)
 {
        struct file **new_fds;
        int error, nfds;
@@ -157,7 +158,9 @@ void free_fdset(fd_set *array, int num)
  * Expand the fdset in the files_struct.  Called with the files spinlock
  * held for write.
  */
-int expand_fdset(struct files_struct *files, int nr)
+static int expand_fdset(struct files_struct *files, int nr)
+       __releases(file->file_lock)
+       __acquires(file->file_lock)
 {
        fd_set *new_openset = NULL, *new_execset = NULL;
        int error, nfds = 0;
@@ -226,3 +229,26 @@ out:
        return error;
 }
 
+/*
+ * Expand files.
+ * Return <0 on error; 0 nothing done; 1 files expanded, we may have blocked.
+ * Should be called with the files->file_lock spinlock held for write.
+ */
+int expand_files(struct files_struct *files, int nr)
+{
+       int err, expand = 0;
+
+       if (nr >= files->max_fdset) {
+               expand = 1;
+               if ((err = expand_fdset(files, nr)))
+                       goto out;
+       }
+       if (nr >= files->max_fds) {
+               expand = 1;
+               if ((err = expand_fd_array(files, nr)))
+                       goto out;
+       }
+       err = expand;
+out:
+       return err;
+}