sysctl compatibility

Martin v. Loewis (loewis@informatik.hu-berlin.de)
Wed, 14 Jan 1998 11:39:02 +0100


Hi Linus,

This is a patch to resolve the sysctl conflict between Linux 2.0 and
Linux 2.1. Compared to the last patch, this does:
- consolidate coda and ntfs sysctls into sysctl.h, resolving a
conflict
- remove /proc/sys/sunrpc, moving the entries to /proc/sys/debug
- move the initial sysctl for net/ipv4 to 10 (one after the last
sysctl of 2.0). As a result, 2.0 and 2.1 don't share any IPV4
sysctls.
No attempt has been made to add compatibility support for the
now-obsolete 2.0 calls. For most of these, adding that support
is far from trivial, and probably not worth the effort.

As discussed, this breaks the sysctl numbering compared to earlier 2.1
snapshots.

Regards,
Martin

diff -ur linux-2.1.79.0/fs/coda/sysctl.c linux/fs/coda/sysctl.c
--- linux-2.1.79.0/fs/coda/sysctl.c Sun Dec 21 23:45:14 1997
+++ linux/fs/coda/sysctl.c Wed Jan 14 10:27:18 1998
@@ -41,15 +41,6 @@
void *buffer, size_t *lenp);

struct ctl_table_header *fs_table_header, *coda_table_header;
-#define FS_CODA 1 /* Coda file system */
-
-#define CODA_DEBUG 1 /* control debugging */
-#define CODA_ENTRY 2 /* control enter/leave pattern */
-#define CODA_TIMEOUT 3 /* timeout on upcalls to become intrble */
-#define CODA_MC 4 /* use/do not use the access cache */
-#define CODA_HARD 5 /* mount type "hard" or "soft" */
-
-

static ctl_table coda_table[] = {
{CODA_DEBUG, "debug", &coda_debug, sizeof(int), 0644, NULL, &coda_dointvec},
diff -ur linux-2.1.79.0/fs/ntfs/sysctl.c linux/fs/ntfs/sysctl.c
--- linux-2.1.79.0/fs/ntfs/sysctl.c Sat Dec 20 00:24:21 1997
+++ linux/fs/ntfs/sysctl.c Wed Jan 14 10:27:18 1998
@@ -16,15 +16,13 @@
int ntdebug = 0;

/* Add or remove the debug sysctl
- * Is this really the only file system with sysctls ?
*/
void ntfs_sysctl(int add)
{
-#define FS_NTFS 1
/* Definition of the sysctl */
static ctl_table ntfs_sysctls[]={
- {FS_NTFS, /* ID */
- "ntfs-debug", /* name in /proc */
+ {DEBUG_NTFS, /* ID */
+ "ntfs", /* name in /proc */
&ntdebug,sizeof(ntdebug), /* data ptr, data size */
0644, /* mode */
0, /* child */
@@ -34,10 +32,10 @@
0,0}, /* extra */
{0}
};
- /* Define the parent file : /proc/sys/fs */
+ /* Define the parent file : /proc/sys/debug */
static ctl_table sysctls_root[]={
- {CTL_FS,
- "fs",
+ {CTL_DEBUG,
+ "debug",
NULL,0,
0555,
ntfs_sysctls},
diff -ur linux-2.1.79.0/include/linux/sunrpc/debug.h linux/include/linux/sunrpc/debug.h
--- linux-2.1.79.0/include/linux/sunrpc/debug.h Mon Dec 22 02:46:24 1997
+++ linux/include/linux/sunrpc/debug.h Wed Jan 14 10:27:18 1998
@@ -73,19 +73,4 @@

#endif /* __KERNEL__ */

-/*
- * Declarations for the sysctl debug interface, which allows to read or
- * change the debug flags for rpc, nfs, nfsd, and lockd. Since the sunrpc
- * module currently registers its sysctl table dynamically, the sysctl path
- * for module FOO is <CTL_SUNRPC, CTL_FOODEBUG>.
- */
-#define CTL_SUNRPC 7249 /* arbitrary and hopefully unused */
-
-enum {
- CTL_RPCDEBUG = 1,
- CTL_NFSDEBUG,
- CTL_NFSDDEBUG,
- CTL_NLMDEBUG,
-};
-
#endif /* _LINUX_SUNRPC_DEBUG_H_ */
diff -ur linux-2.1.79.0/include/linux/sysctl.h linux/include/linux/sysctl.h
--- linux-2.1.79.0/include/linux/sysctl.h Wed Jan 14 10:37:40 1998
+++ linux/include/linux/sysctl.h Wed Jan 14 10:42:59 1998
@@ -58,6 +58,7 @@
KERN_MAXINODE,
KERN_NRFILE,
KERN_MAXFILE,
+ KERN_MAXID_OBSOLETE, /* Linux 2.0 compatibility */
KERN_SECURELVL, /* int: system security level */
KERN_PANIC, /* int: panic timeout */
KERN_REALROOTDEV, /* real root device to mount after initrd */
@@ -78,10 +79,11 @@
enum
{
VM_SWAPCTL=1, /* struct: Set vm swapping control */
- VM_SWAPOUT, /* int: Background pageout interval */
+ VM_KSWAPD, /* Linux 2.0 compatibility, obsolete */
VM_FREEPG, /* struct: Set free page thresholds */
VM_BDFLUSH, /* struct: Control buffer cache flushing */
VM_OVERCOMMIT_MEMORY, /* Turn off the virtual memory safety limit */
+ VM_SWAPOUT, /* int: Background pageout interval */
};


@@ -109,7 +111,8 @@
/* /proc/sys/net/core */
enum
{
- NET_CORE_WMEM_MAX=1,
+ NET_CORE_NET_ALIAS_MAX=1, /* Linux 2.0 compatibility, obsolete */
+ NET_CORE_WMEM_MAX,
NET_CORE_RMEM_MAX,
NET_CORE_WMEM_DEFAULT,
NET_CORE_RMEM_DEFAULT,
@@ -133,7 +136,7 @@
/* /proc/sys/net/ipv4 */
enum
{
- NET_IPV4_TCP_HOE_RETRANSMITS=1,
+ NET_IPV4_TCP_HOE_RETRANSMITS=10,
NET_IPV4_TCP_SACK,
NET_IPV4_TCP_TSACK,
NET_IPV4_TCP_TIMESTAMPS,
@@ -310,8 +313,27 @@
/* CTL_PROC names: */

/* CTL_FS names: */
+enum {
+ FS_CODA=1, /* Coda file system */
+};
+
+/* /proc/sys/fs/coda */
+enum {
+ CODA_DEBUG=1, /* control debugging */
+ CODA_ENTRY, /* control enter/leave pattern */
+ CODA_TIMEOUT, /* timeout on upcalls to become intrble */
+ CODA_MC, /* use/do not use the access cache */
+ CODA_HARD, /* mount type "hard" or "soft" */
+};

/* CTL_DEBUG names: */
+enum {
+ DEBUG_NTFS=1,
+ DEBUG_RPC,
+ DEBUG_NFS,
+ DEBUG_NFSD,
+ DEBUG_NLM,
+};

/* CTL_DEV names: */
enum {
diff -ur linux-2.1.79.0/net/sunrpc/sysctl.c linux/net/sunrpc/sysctl.c
--- linux-2.1.79.0/net/sunrpc/sysctl.c Wed Jan 14 10:37:48 1998
+++ linux/net/sunrpc/sysctl.c Wed Jan 14 11:19:06 1998
@@ -96,7 +96,7 @@
left--, p++;
*(unsigned int *) table->data = value;
/* Display the RPC tasks on writing to rpc_debug */
- if (table->ctl_name == CTL_RPCDEBUG) {
+ if (table->ctl_name == DEBUG_RPC) {
rpc_show_tasks();
}
} else {
@@ -121,7 +121,7 @@
#define DIRENTRY(nam1, nam2, child) \
{CTL_##nam1, #nam2, NULL, 0, 0555, child }
#define DBGENTRY(nam1, nam2) \
- {CTL_##nam1##DEBUG, #nam2 "_debug", &nam2##_debug, sizeof(int),\
+ {DEBUG_##nam1, #nam2, &nam2##_debug, sizeof(int),\
0644, NULL, &proc_dodebug}

static ctl_table debug_table[] = {
@@ -133,7 +133,7 @@
};

static ctl_table sunrpc_table[] = {
- DIRENTRY(SUNRPC, sunrpc, debug_table),
+ DIRENTRY(DEBUG, debug, debug_table),
{0}
};

Common subdirectories: linux-2.1.79.0/scripts/lxdialog and linux/scripts/lxdialog
diff -uN linux-2.1.79.0/scripts/sysctl_verify.py linux/scripts/sysctl_verify.py
--- linux-2.1.79.0/scripts/sysctl_verify.py Thu Jan 1 01:00:00 1970
+++ linux/scripts/sysctl_verify.py Wed Jan 14 10:27:34 1998
@@ -0,0 +1,98 @@
+#! /usr/bin/env python
+#This script compares <linux/sysctl.h> of two given Linux installations
+#and analyzes whether they are compatible
+import sys,regex,os
+def usage():
+ sys.stderr.write("Usage: %s <linux-directory1> <linux-directory2>\n" %
+ sys.argv[0])
+
+#Known Limitations
+#The analysis considers only the sysctl values present in both versions.
+#Values defined outside sysctl.h are not considered
+#sysctl definitions must consist only of upper case letters, digits,
+#and contain at least one underscore
+
+rex=regex.compile("[^A-Za-z0-9_]\([A-Z]+_[A-Z0-9_]+\)[^A-Za-z0-9_]")
+
+exclude=['CTL_NONE','CTL_ANY']
+
+def process_file(name):
+ "Parse a sysctl.h file, returning all ctl values"
+ try:
+ lines=open(name).readlines()
+ except IOError:
+ sys.stderr.write("Could not open %s\n" % name)
+ sys.exit(1)
+ result={}
+ for l in lines:
+ if rex.search(l)>=0 and rex.group(1) not in exclude:
+ result[rex.group(1)]=None
+ return result
+
+header="""
+#include <linux/types.h>
+#include "%s"
+main()
+{
+"""
+
+def print_source(keys,file,linux):
+ "Print sysconf test program into file"
+ file=open(file,"w")
+ file.write(header % linux)
+ for k in keys:
+ file.write('printf("%s=%%d\\n",%s);\n' % (k,k))
+ file.write("}\n")
+ file.close()
+
+
+def main(dir1,dir2):
+ file1=dir1+"/include/linux/sysctl.h"
+ file2=dir2+"/include/linux/sysctl.h"
+ #Process the files
+ k1=process_file(file1)
+ k2=process_file(file2)
+
+ #compare the files
+ keys=[]
+ for k in k1.keys():
+ if k2.has_key(k):
+ keys.append(k)
+ keys.sort()
+
+ print "Generating source"
+ try:
+ print_source(keys,"version1.c",file1)
+ print_source(keys,"version2.c",file2)
+ except IOError:
+ sys.stderr.write("Error producing output files\n")
+ sys.exit(1)
+
+ print "Compiling the source"
+ if os.system("cc -o version1 -I%s/include version1.c" % dir1) or \
+ os.system("cc -o version2 -I%s/include version2.c" % dir2):
+ sys.stderr.write("Error during compilation\n")
+ sys.exit(1)
+
+ print "Running programs"
+ try:
+ result1=os.popen("./version1","r").readlines()
+ result2=os.popen("./version2","r").readlines()
+ except:
+ sys.stderr.write("Error executing programs\n")
+ sys.exit(1)
+
+ print "Results"
+ if result1==result2:
+ print "sysctl.h is compatible in both Linux versions"
+ sys.exit(0)
+
+ for i in range(0,min(len(result1),len(result2))):
+ if result1[i]!=result2[i]:
+ print "-",result1[i],
+ print "+",result2[i],
+
+if len(sys.argv)!=3:
+ usage()
+else:
+ main(sys.argv[1],sys.argv[2])