LINUX: Make sysctl definitions more concise
[openafs.git] / src / afs / LINUX / osi_sysctl.c
1 /*
2  * osi_sysctl.c: Linux sysctl interface to OpenAFS
3  *
4  * $Id$
5  *
6  * Written Jan 30, 2002 by Kris Van Hees (Sine Nomine Associates)
7  */
8
9 #include <afsconfig.h>
10 #include "afs/param.h"
11
12 #include "afs/sysincludes.h"    /* Standard vendor system headers */
13 #include "afsincludes.h"        /* Afs-based standard headers */
14 #include "afs/afs_stats.h"      /* afs statistics */
15
16 #include <linux/sysctl.h>
17 #ifdef HAVE_LINUX_CONFIG_H
18 #include <linux/config.h>
19 #endif
20
21 #ifdef CONFIG_SYSCTL
22
23 /* From afs_util.c */
24 extern afs_int32 afs_md5inum;
25
26 /* From afs_analyze.c */
27 extern afs_int32 hm_retry_RO;
28 extern afs_int32 hm_retry_RW;
29 extern afs_int32 hm_retry_int;
30 extern afs_int32 afs_blocksUsed_0;
31 extern afs_int32 afs_blocksUsed_1;
32 extern afs_int32 afs_blocksUsed_2;
33 extern afs_int32 afs_pct1;
34 extern afs_int32 afs_pct2;
35
36 # ifdef STRUCT_CTL_TABLE_HAS_CTL_NAME
37 #  ifdef CTL_UNNUMBERED
38 #   define AFS_SYSCTL_NAME(num) .ctl_name = CTL_UNNUMBERED,
39 #  else
40 #   define AFS_SYSCTL_NAME(num) .ctl_name = num,
41 #  endif
42 # else
43 #  define AFS_SYSCTL_NAME(num)
44 # endif
45
46 # define AFS_SYSCTL_INT2(num, perms, name, var) { \
47     AFS_SYSCTL_NAME(num) \
48     .procname           = name, \
49     .data               = &var, \
50     .maxlen             = sizeof(var), \
51     .mode               = perms, \
52     .proc_handler       = &proc_dointvec \
53 }
54 # define AFS_SYSCTL_INT(num, perms, var) \
55         AFS_SYSCTL_INT2(num, perms, #var, var)
56
57 static struct ctl_table_header *afs_sysctl = NULL;
58
59 static struct ctl_table afs_sysctl_table[] = {
60     AFS_SYSCTL_INT(1, 0644, hm_retry_RO),
61     AFS_SYSCTL_INT(2, 0644, hm_retry_RW),
62     AFS_SYSCTL_INT(3, 0644, hm_retry_int),
63
64     AFS_SYSCTL_INT2(4, 0644, "GCPAGs",      afs_gcpags),
65     AFS_SYSCTL_INT2(5, 0644, "rx_deadtime", afs_rx_deadtime),
66     AFS_SYSCTL_INT2(6, 0644, "bkVolPref",   afs_bkvolpref),
67
68     AFS_SYSCTL_INT( 7, 0444, afs_blocksUsed),
69     AFS_SYSCTL_INT( 8, 0644, afs_blocksUsed_0),
70     AFS_SYSCTL_INT( 9, 0644, afs_blocksUsed_1),
71     AFS_SYSCTL_INT(10, 0644, afs_blocksUsed_2),
72
73     AFS_SYSCTL_INT( 11, 0644, afs_pct1),
74     AFS_SYSCTL_INT( 12, 0644, afs_pct2),
75     AFS_SYSCTL_INT( 13, 0644, afs_cacheBlocks),
76     AFS_SYSCTL_INT2(14, 0644, "md5inum", afs_md5inum),
77
78     {
79         .procname       = 0
80     }
81 };
82
83 static struct ctl_table fs_sysctl_table[] = {
84     {
85         AFS_SYSCTL_NAME(1)
86         .procname       = "afs",
87         .mode           = 0555,
88         .child          = afs_sysctl_table
89     },
90     {
91         .procname       = 0
92     }
93 };
94
95 int
96 osi_sysctl_init()
97 {
98 # if defined(REGISTER_SYSCTL_TABLE_NOFLAG)
99     afs_sysctl = register_sysctl_table(fs_sysctl_table);
100 # else
101     afs_sysctl = register_sysctl_table(fs_sysctl_table, 0);
102 # endif
103     if (!afs_sysctl)
104         return -1;
105
106     return 0;
107 }
108
109 void
110 osi_sysctl_clean()
111 {
112     if (afs_sysctl) {
113         unregister_sysctl_table(afs_sysctl);
114         afs_sysctl = NULL;
115     }
116 }
117
118 #endif /* CONFIG_SYSCTL */