PageRenderTime 30ms CodeModel.GetById 12ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/core/10.5/fusefs/fuse_sysctl.c

http://macfuse.googlecode.com/
C | 308 lines | 253 code | 41 blank | 14 comment | 30 complexity | ac2e17a9af13284f272aca12ee9586e1 MD5 | raw file
  1/*
  2 * Copyright (C) 2006-2008 Google. All Rights Reserved.
  3 * Amit Singh <singh@>
  4 */
  5
  6#include <sys/systm.h>
  7#include <sys/types.h>
  8#include <sys/sysctl.h>
  9
 10#include "fuse.h"
 11#include "fuse_device.h"
 12#include "fuse_sysctl.h"
 13#include <fuse_param.h>
 14#include <fuse_version.h>
 15
 16/* NB: none of these are bigger than unsigned 32-bit. */
 17
 18int32_t  fuse_admin_group            = 0;                                  // rw
 19int32_t  fuse_allow_other            = 0;                                  // rw
 20uint32_t fuse_api_major              = FUSE_KERNEL_VERSION;                // r
 21uint32_t fuse_api_minor              = FUSE_KERNEL_MINOR_VERSION;          // r
 22int32_t  fuse_fh_current             = 0;                                  // r
 23uint32_t fuse_fh_reuse_count         = 0;                                  // r
 24uint32_t fuse_fh_upcall_count        = 0;                                  // r
 25uint32_t fuse_fh_zombies             = 0;                                  // r
 26int32_t  fuse_iov_credit             = FUSE_DEFAULT_IOV_CREDIT;            // rw
 27int32_t  fuse_iov_current            = 0;                                  // r
 28uint32_t fuse_iov_permanent_bufsize  = FUSE_DEFAULT_IOV_PERMANENT_BUFSIZE; // rw
 29int32_t  fuse_kill                   = -1;                                 // w
 30int32_t  fuse_print_vnodes           = -1;                                 // w
 31uint32_t fuse_lookup_cache_hits      = 0;                                  // r
 32uint32_t fuse_lookup_cache_misses    = 0;                                  // r
 33uint32_t fuse_lookup_cache_overrides = 0;                                  // r
 34uint32_t fuse_max_freetickets        = FUSE_DEFAULT_MAX_FREE_TICKETS;      // rw
 35uint32_t fuse_max_tickets            = 0;                                  // rw
 36int32_t  fuse_mount_count            = 0;                                  // r
 37int32_t  fuse_memory_allocated       = 0;                                  // r
 38int32_t  fuse_realloc_count          = 0;                                  // r
 39int32_t  fuse_tickets_current        = 0;                                  // r
 40uint32_t fuse_userkernel_bufsize     = FUSE_DEFAULT_USERKERNEL_BUFSIZE;    // rw
 41int32_t  fuse_vnodes_current         = 0;                                  // r
 42
 43SYSCTL_DECL(_macfuse);
 44SYSCTL_NODE(, OID_AUTO, macfuse, CTLFLAG_RW, 0,
 45            "MacFUSE Sysctl Interface");
 46SYSCTL_NODE(_macfuse, OID_AUTO, control, CTLFLAG_RW, 0,
 47            "MacFUSE Controls");
 48SYSCTL_NODE(_macfuse, OID_AUTO, counters, CTLFLAG_RW, 0,
 49            "MacFUSE Monotonic Counters");
 50SYSCTL_NODE(_macfuse, OID_AUTO, resourceusage, CTLFLAG_RW, 0,
 51            "MacFUSE Resource Usage");
 52SYSCTL_NODE(_macfuse, OID_AUTO, tunables, CTLFLAG_RW, 0,
 53            "MacFUSE Tunables");
 54SYSCTL_NODE(_macfuse, OID_AUTO, version, CTLFLAG_RW, 0,
 55            "MacFUSE Version Information");
 56
 57/* fuse.control */
 58
 59int sysctl_macfuse_control_kill_handler SYSCTL_HANDLER_ARGS;
 60int sysctl_macfuse_control_print_vnodes_handler SYSCTL_HANDLER_ARGS;
 61int sysctl_macfuse_tunables_userkernel_bufsize_handler SYSCTL_HANDLER_ARGS;
 62
 63int
 64sysctl_macfuse_control_kill_handler SYSCTL_HANDLER_ARGS
 65{
 66    int error = 0;
 67    (void)oidp;
 68
 69    if (arg1) {
 70        error = SYSCTL_OUT(req, arg1, sizeof(int));
 71    } else {
 72        error = SYSCTL_OUT(req, &arg2, sizeof(int));
 73    }
 74
 75    if (error || !req->newptr) {
 76        return error;
 77    }
 78
 79    if (!arg1) {
 80        error = EPERM;
 81    } else {
 82        error = SYSCTL_IN(req, arg1, sizeof(int));
 83        if (error == 0) {
 84            error = fuse_device_kill(*(int *)arg1, req->p);
 85        }
 86        fuse_kill = -1; /* set it back */
 87    }
 88
 89    return error;
 90}
 91
 92int
 93sysctl_macfuse_control_print_vnodes_handler SYSCTL_HANDLER_ARGS
 94{
 95    int error = 0;
 96    (void)oidp;
 97
 98    if (arg1) {
 99        error = SYSCTL_OUT(req, arg1, sizeof(uint32_t));
100    } else {
101        error = SYSCTL_OUT(req, &arg2, sizeof(uint32_t));
102    }
103
104    if (error || !req->newptr) {
105        return error;
106    }
107
108    if (!arg1) {
109        error = EPERM;
110    } else {
111        error = SYSCTL_IN(req, arg1, sizeof(int));
112        if (error == 0) {
113            error = fuse_device_print_vnodes(*(int *)arg1, req->p);
114        }
115        fuse_print_vnodes = -1; /* set it back */
116    }
117
118    return error;
119}
120
121int
122sysctl_macfuse_tunables_userkernel_bufsize_handler SYSCTL_HANDLER_ARGS
123{
124    int error = 0;
125    (void)oidp;
126
127    if (arg1) {
128        error = SYSCTL_OUT(req, arg1, sizeof(int));
129    } else {
130        error = SYSCTL_OUT(req, &arg2, sizeof(int));
131    }
132
133    if (error || !req->newptr) {
134        return error;
135    }
136
137    if (!arg1) {
138        error = EPERM;
139    } else {
140        error = SYSCTL_IN(req, arg1, sizeof(uint32_t));
141        if (error == 0) {
142            uint32_t incoming = *(uint32_t *)arg1;
143            incoming = fuse_round_page_32(incoming);
144            if (incoming > FUSE_MAX_USERKERNEL_BUFSIZE) {
145                error = E2BIG;
146            } else if (incoming < FUSE_MIN_USERKERNEL_BUFSIZE) {
147                error = EINVAL;
148            } else {
149                fuse_userkernel_bufsize = incoming;
150            }
151        }
152    }
153
154    return error;
155}
156
157SYSCTL_PROC(_macfuse_control, // our parent
158            OID_AUTO,         // automatically assign object ID
159            kill,             // our name
160
161            // type flag/access flag
162            (CTLTYPE_INT | CTLFLAG_WR | CTLFLAG_ANYBODY),
163
164            &fuse_kill,       // location of our data
165            0,                // argument passed to our handler
166
167            // our handler function
168            sysctl_macfuse_control_kill_handler,
169
170            "I",              // our data type (integer)
171            "MacFUSE Controls: Kill the Given File System");
172
173SYSCTL_PROC(_macfuse_control,   // our parent
174            OID_AUTO,           // automatically assign object ID
175            print_vnodes,       // our name
176
177            // type flag/access flag
178            (CTLTYPE_INT | CTLFLAG_WR),
179
180            &fuse_print_vnodes, // location of our data
181            0,                  // argument passed to our handler
182
183            // our handler function
184            sysctl_macfuse_control_print_vnodes_handler,
185
186            "I",                // our data type (integer)
187            "MacFUSE Controls: Print Vnodes for the Given File System");
188
189/* fuse.counters */
190SYSCTL_INT(_macfuse_counters, OID_AUTO, filehandle_reuse, CTLFLAG_RD,
191           &fuse_fh_reuse_count, 0, "");
192SYSCTL_INT(_macfuse_counters, OID_AUTO, filehandle_upcalls, CTLFLAG_RD,
193           &fuse_fh_upcall_count, 0, "");
194SYSCTL_INT(_macfuse_counters, OID_AUTO, lookup_cache_hits, CTLFLAG_RD,
195           &fuse_lookup_cache_hits, 0, "");
196SYSCTL_INT(_macfuse_counters, OID_AUTO, lookup_cache_misses, CTLFLAG_RD,
197           &fuse_lookup_cache_misses, 0, "");
198SYSCTL_INT(_macfuse_counters, OID_AUTO, lookup_cache_overrides,
199           CTLFLAG_RD, &fuse_lookup_cache_overrides, 0, "");
200SYSCTL_INT(_macfuse_counters, OID_AUTO, memory_reallocs, CTLFLAG_RD,
201           &fuse_realloc_count, 0, "");
202
203/* fuse.resourceusage */
204SYSCTL_INT(_macfuse_resourceusage, OID_AUTO, filehandles, CTLFLAG_RD,
205           &fuse_fh_current, 0, "");
206SYSCTL_INT(_macfuse_resourceusage, OID_AUTO, filehandles_zombies, CTLFLAG_RD,
207           &fuse_fh_zombies, 0, "");
208SYSCTL_INT(_macfuse_resourceusage, OID_AUTO, ipc_iovs, CTLFLAG_RD,
209           &fuse_iov_current, 0, "");
210SYSCTL_INT(_macfuse_resourceusage, OID_AUTO, ipc_tickets, CTLFLAG_RD,
211           &fuse_tickets_current, 0, "");
212SYSCTL_INT(_macfuse_resourceusage, OID_AUTO, memory_bytes, CTLFLAG_RD,
213           &fuse_memory_allocated, 0, "");
214SYSCTL_INT(_macfuse_resourceusage, OID_AUTO, mounts, CTLFLAG_RD,
215           &fuse_mount_count, 0, "");
216SYSCTL_INT(_macfuse_resourceusage, OID_AUTO, vnodes, CTLFLAG_RD,
217           &fuse_vnodes_current, 0, "");
218
219/* fuse.tunables */
220SYSCTL_INT(_macfuse_tunables, OID_AUTO, admin_group, CTLFLAG_RW,
221           &fuse_admin_group, 0, "");
222SYSCTL_INT(_macfuse_tunables, OID_AUTO, allow_other, CTLFLAG_RW,
223           &fuse_allow_other, 0, "");
224SYSCTL_INT(_macfuse_tunables, OID_AUTO, iov_credit, CTLFLAG_RW,
225           &fuse_iov_credit, 0, "");
226SYSCTL_INT(_macfuse_tunables, OID_AUTO, iov_permanent_bufsize, CTLFLAG_RW,
227           &fuse_iov_permanent_bufsize, 0, "");
228SYSCTL_INT(_macfuse_tunables, OID_AUTO, max_freetickets, CTLFLAG_RW,
229           &fuse_max_freetickets, 0, "");
230SYSCTL_INT(_macfuse_tunables, OID_AUTO, max_tickets, CTLFLAG_RW,
231           &fuse_max_tickets, 0, "");
232SYSCTL_PROC(_macfuse_tunables,          // our parent
233            OID_AUTO,                   // automatically assign object ID
234            userkernel_bufsize,         // our name
235            (CTLTYPE_INT | CTLFLAG_WR), // type flag/access flag
236            &fuse_userkernel_bufsize,   // location of our data
237            0,                          // argument passed to our handler
238            sysctl_macfuse_tunables_userkernel_bufsize_handler,    
239            "I",                        // our data type (integer)
240            "MacFUSE Tunables");        // our description
241
242/* fuse.version */
243SYSCTL_INT(_macfuse_version, OID_AUTO, api_major, CTLFLAG_RD,
244           &fuse_api_major, 0, "");
245SYSCTL_INT(_macfuse_version, OID_AUTO, api_minor, CTLFLAG_RD,
246           &fuse_api_minor, 0, "");
247SYSCTL_STRING(_macfuse_version, OID_AUTO, number, CTLFLAG_RD,
248              MACFUSE_VERSION, 0, "");
249SYSCTL_STRING(_macfuse_version, OID_AUTO, string, CTLFLAG_RD,
250              MACFUSE_VERSION ", " MACFUSE_TIMESTAMP, 0, "");
251
252static struct sysctl_oid *fuse_sysctl_list[] =
253{
254    &sysctl__macfuse_control,
255    &sysctl__macfuse_counters,
256    &sysctl__macfuse_resourceusage,
257    &sysctl__macfuse_tunables,
258    &sysctl__macfuse_version,
259    &sysctl__macfuse_control_kill,
260    &sysctl__macfuse_control_print_vnodes,
261    &sysctl__macfuse_counters_filehandle_reuse,
262    &sysctl__macfuse_counters_filehandle_upcalls,
263    &sysctl__macfuse_counters_lookup_cache_hits,
264    &sysctl__macfuse_counters_lookup_cache_misses,
265    &sysctl__macfuse_counters_lookup_cache_overrides,
266    &sysctl__macfuse_counters_memory_reallocs,
267    &sysctl__macfuse_resourceusage_filehandles,
268    &sysctl__macfuse_resourceusage_filehandles_zombies,
269    &sysctl__macfuse_resourceusage_ipc_iovs,
270    &sysctl__macfuse_resourceusage_ipc_tickets,
271    &sysctl__macfuse_resourceusage_memory_bytes,
272    &sysctl__macfuse_resourceusage_mounts,
273    &sysctl__macfuse_resourceusage_vnodes,
274    &sysctl__macfuse_tunables_admin_group,
275    &sysctl__macfuse_tunables_allow_other,
276    &sysctl__macfuse_tunables_iov_credit,
277    &sysctl__macfuse_tunables_iov_permanent_bufsize,
278    &sysctl__macfuse_tunables_max_freetickets,
279    &sysctl__macfuse_tunables_max_tickets,
280    &sysctl__macfuse_tunables_userkernel_bufsize,
281    &sysctl__macfuse_version_api_major,
282    &sysctl__macfuse_version_api_minor,
283    &sysctl__macfuse_version_number,
284    &sysctl__macfuse_version_string,
285    (struct sysctl_oid *)0
286};
287
288void
289fuse_sysctl_start(void)
290{
291    int i;
292
293    sysctl_register_oid(&sysctl__macfuse);
294    for (i = 0; fuse_sysctl_list[i]; i++) {
295       sysctl_register_oid(fuse_sysctl_list[i]);
296    }
297}
298
299void
300fuse_sysctl_stop(void)
301{
302    int i;
303
304    for (i = 0; fuse_sysctl_list[i]; i++) {
305       sysctl_unregister_oid(fuse_sysctl_list[i]);
306    }
307    sysctl_unregister_oid(&sysctl__macfuse);
308}