[patch-2.3.99-pre10-3] BUGFIX /proc/sys/fs/file-nr is wrong.

From: Tigran Aivazian (tigran@veritas.com)
Date: Thu May 25 2000 - 03:58:29 EST


Hi Linus,

The assumption that C code:

int x;
int y;
int z;

allocates x,y,z at consecutive virtual addresses is wrong. Yet it is
assumed when passing &nr_files in kernel/sysctl.c and saying "give me, I
pray thee, 3 sizeof(int)". This results in garbage displayed in
/proc/sys/fs/file-nr.

To fix this, I followed (almost) the same technique as inodes_stat in
fs/inode.c, i.e. gathered variables in a structure called files_stat.

Tested under 2.3.99-pre10-3 (aka 2.4.0-test1)

Regards,
Tigran

PS. Also, I updated my email address in MAINTAINERS/CREDITS and added a
D-line "Various kernel patches" to CREDITS.
                                                                             

diff -urN -X dontdiff linux/CREDITS filenr/CREDITS
--- linux/CREDITS Thu May 25 09:08:30 2000
+++ filenr/CREDITS Thu May 25 09:49:38 2000
@@ -38,10 +38,11 @@
 S: Ireland
 
 N: Tigran A. Aivazian
-E: tigran@ocston.org
+E: tigran@veritas.com
 W: http://www.ocston.org/~tigran
 D: BFS filesystem
 D: Intel P6 CPU microcode update support
+D: Various kernel patches
 S: United Kingdom
 
 N: Werner Almesberger
diff -urN -X dontdiff linux/Documentation/filesystems/bfs.txt filenr/Documentation/filesystems/bfs.txt
--- linux/Documentation/filesystems/bfs.txt Mon Feb 7 02:43:21 2000
+++ filenr/Documentation/filesystems/bfs.txt Thu May 25 09:50:07 2000
@@ -54,4 +54,4 @@
 If you have any patches, questions or suggestions regarding this BFS
 implementation please contact the author:
 
-Tigran A. Aivazian <tigran@ocston.org>.
+Tigran A. Aivazian <tigran@veritas.com>
diff -urN -X dontdiff linux/MAINTAINERS filenr/MAINTAINERS
--- linux/MAINTAINERS Thu May 25 09:08:30 2000
+++ filenr/MAINTAINERS Thu May 25 09:49:52 2000
@@ -178,7 +178,7 @@
 
 BFS FILE SYSTEM
 P: Tigran A. Aivazian
-M: tigran@ocston.org
+M: tigran@veritas.com
 L: linux-kernel@vger.rutgers.edu
 W: http://www.ocston.org/~tigran/patches/bfs
 S: Maintained
@@ -540,7 +540,7 @@
 
 INTEL P6 MICROCODE UPDATE SUPPORT
 P: Tigran Aivazian
-M: tigran@sco.com
+M: tigran@veritas.com
 S: Maintained
 
 IP MASQUERADING:
diff -urN -X dontdiff linux/fs/file_table.c filenr/fs/file_table.c
--- linux/fs/file_table.c Sat May 13 09:32:52 2000
+++ filenr/fs/file_table.c Thu May 25 09:35:15 2000
@@ -15,9 +15,7 @@
 static kmem_cache_t *filp_cache;
 
 /* sysctl tunables... */
-int nr_files; /* read only */
-int nr_free_files; /* read only */
-int max_files = NR_FILE;/* tunable */
+struct files_stat_struct files_stat = {0, 0, NR_FILE};
 
 /* Here the new files go */
 static LIST_HEAD(anon_list);
@@ -52,11 +50,11 @@
         struct file * f;
 
         file_list_lock();
- if (nr_free_files > NR_RESERVED_FILES) {
+ if (files_stat.nr_free_files > NR_RESERVED_FILES) {
         used_one:
                 f = list_entry(free_list.next, struct file, f_list);
                 list_del(&f->f_list);
- nr_free_files--;
+ files_stat.nr_free_files--;
         new_one:
                 file_list_unlock();
                 memset(f, 0, sizeof(*f));
@@ -72,25 +70,25 @@
         /*
          * Use a reserved one if we're the superuser
          */
- if (nr_free_files && !current->euid)
+ if (files_stat.nr_free_files && !current->euid)
                 goto used_one;
         /*
          * Allocate a new one if we're below the limit.
          */
- if (nr_files < max_files) {
+ if (files_stat.nr_files < files_stat.max_files) {
                 file_list_unlock();
                 f = kmem_cache_alloc(filp_cache, SLAB_KERNEL);
                 file_list_lock();
                 if (f) {
- nr_files++;
+ files_stat.nr_files++;
                         goto new_one;
                 }
                 /* Big problems... */
                 printk("VFS: filp allocation failed\n");
 
- } else if (max_files > old_max) {
- printk("VFS: file-max limit %d reached\n", max_files);
- old_max = max_files;
+ } else if (files_stat.max_files > old_max) {
+ printk("VFS: file-max limit %d reached\n", files_stat.max_files);
+ old_max = files_stat.max_files;
         }
         file_list_unlock();
         return NULL;
@@ -146,7 +144,7 @@
         file_list_lock();
         list_del(&file->f_list);
         list_add(&file->f_list, &free_list);
- nr_free_files++;
+ files_stat.nr_free_files++;
         file_list_unlock();
 }
 
@@ -158,7 +156,7 @@
                 file_list_lock();
                 list_del(&file->f_list);
                 list_add(&file->f_list, &free_list);
- nr_free_files++;
+ files_stat.nr_free_files++;
                 file_list_unlock();
         }
 }
diff -urN -X dontdiff linux/include/linux/fs.h filenr/include/linux/fs.h
--- linux/include/linux/fs.h Thu May 25 09:08:31 2000
+++ filenr/include/linux/fs.h Thu May 25 09:30:25 2000
@@ -47,7 +47,12 @@
 #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
 
 /* And dynamically-tunable limits and defaults: */
-extern int max_files, nr_files, nr_free_files;
+struct files_stat_struct {
+ int nr_files; /* read only */
+ int nr_free_files; /* read only */
+ int max_files; /* tunable */
+};
+extern struct files_stat_struct files_stat;
 extern int max_super_blocks, nr_super_blocks;
 
 #define NR_FILE 8192 /* this can well be larger on a larger system */
diff -urN -X dontdiff linux/kernel/sysctl.c filenr/kernel/sysctl.c
--- linux/kernel/sysctl.c Sat May 13 09:32:54 2000
+++ filenr/kernel/sysctl.c Thu May 25 09:31:05 2000
@@ -255,9 +255,9 @@
          0444, NULL, &proc_dointvec},
         {FS_STATINODE, "inode-state", &inodes_stat, 7*sizeof(int),
          0444, NULL, &proc_dointvec},
- {FS_NRFILE, "file-nr", &nr_files, 3*sizeof(int),
+ {FS_NRFILE, "file-nr", &files_stat, 3*sizeof(int),
          0444, NULL, &proc_dointvec},
- {FS_MAXFILE, "file-max", &max_files, sizeof(int),
+ {FS_MAXFILE, "file-max", &files_stat.max_files, sizeof(int),
          0644, NULL, &proc_dointvec},
         {FS_NRSUPER, "super-nr", &nr_super_blocks, sizeof(int),
          0444, NULL, &proc_dointvec},
diff -urN -X dontdiff linux/net/netsyms.c filenr/net/netsyms.c
--- linux/net/netsyms.c Sat May 13 09:32:45 2000
+++ filenr/net/netsyms.c Thu May 25 09:37:26 2000
@@ -196,7 +196,7 @@
 
 /* Needed by unix.o */
 EXPORT_SYMBOL(scm_fp_dup);
-EXPORT_SYMBOL(max_files);
+EXPORT_SYMBOL(files_stat);
 EXPORT_SYMBOL(memcpy_toiovec);
 EXPORT_SYMBOL(csum_partial);
 
diff -urN -X dontdiff linux/net/unix/af_unix.c filenr/net/unix/af_unix.c
--- linux/net/unix/af_unix.c Wed May 24 04:35:05 2000
+++ filenr/net/unix/af_unix.c Thu May 25 09:36:31 2000
@@ -445,7 +445,7 @@
 {
         struct sock *sk;
 
- if (atomic_read(&unix_nr_socks) >= 2*max_files)
+ if (atomic_read(&unix_nr_socks) >= 2*files_stat.max_files)
                 return NULL;
 
         MOD_INC_USE_COUNT;

-
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/



This archive was generated by hypermail 2b29 : Wed May 31 2000 - 21:00:13 EST