Whamcloud - gitweb
LU-1346 libcfs: cleanup libcfs primitive (linux-prim.h)
[fs/lustre-release.git] / libcfs / libcfs / darwin / darwin-proc.c
index 1a6d177..1780f5b 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -26,7 +24,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
@@ -56,7 +54,7 @@ static struct libcfs_sysctl_sprite {
         struct sysctl_oid_list  *ss_link;
 } libcfs_sysctl_sprite = { 0, NULL };
 
-static cfs_sysctl_table_header_t *libcfs_table_header = NULL;
+static struct ctl_table_header *libcfs_table_header = NULL;
 extern unsigned int libcfs_debug;
 extern unsigned int libcfs_subsystem_debug;
 extern unsigned int libcfs_printk;
@@ -144,6 +142,25 @@ static int sysctl_debug_mb SYSCTL_HANDLER_ARGS
        return error;
 }
 
+static int proc_fail_loc SYSCTL_HANDLER_ARGS
+{
+        int error = 0;
+        long old_fail_loc = cfs_fail_loc;
+
+        error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req);
+        if (!error && req->newptr != USER_ADDR_NULL) {
+                if (old_fail_loc != cfs_fail_loc)
+                        cfs_waitq_signal(&cfs_race_waitq);
+        } else  if (req->newptr != USER_ADDR_NULL) {
+                /* Something was wrong with the write request */
+                printf ("sysctl fail loc fault: %d.\n", error);
+        } else {
+                /* Read request */
+                error = SYSCTL_OUT(req, &cfs_fail_loc, sizeof cfs_fail_loc);
+        }
+        return error;
+}
+
 /*
  * sysctl table for lnet
  */
@@ -183,9 +200,11 @@ SYSCTL_PROC(_lnet,                 OID_AUTO,       daemon_file,
 SYSCTL_PROC(_lnet,                     OID_AUTO,       debug_mb,
             CTLTYPE_INT | CTLFLAG_RW,                  0,
             0,         &sysctl_debug_mb,               "L",    "debug_mb");
+SYSCTL_PROC(_lnet,                      OID_AUTO,       fail_loc, 
+             CTLTYPE_INT | CTLFLAG_RW ,                 &cfs_fail_loc,
+             0,         &proc_fail_loc,                 "I",    "cfs_fail_loc");
 
-
-static cfs_sysctl_table_t      top_table[] = {
+static struct ctl_table        top_table[] = {
        &sysctl__lnet,
        &sysctl__lnet_debug,
        &sysctl__lnet_subsystem_debug,
@@ -197,34 +216,35 @@ static cfs_sysctl_table_t top_table[] = {
        &sysctl__lnet_debug_kernel,
        &sysctl__lnet_daemon_file,
        &sysctl__lnet_debug_mb,
+        &sysctl__lnet_cfs_fail_loc
        NULL
 };
 
 /*
  * Register sysctl table
  */
-cfs_sysctl_table_header_t *
-cfs_register_sysctl_table (cfs_sysctl_table_t *table, int arg)
+struct ctl_table_header *
+register_sysctl_table(struct ctl_table *table, int arg)
 {
-        cfs_sysctl_table_t      item;
-        int i = 0;
+       struct ctl_table      item;
+       int i = 0;
 
-        while ((item = table[i++]) != NULL) 
-                sysctl_register_oid(item);
-        return table;
+       while ((item = table[i++]) != NULL)
+               sysctl_register_oid(item);
+       return table;
 }
 
 /*
  * Unregister sysctl table
  */
-void
-cfs_unregister_sysctl_table (cfs_sysctl_table_header_t *table) {
-        int i = 0;
-        cfs_sysctl_table_t      item;
+void unregister_sysctl_table(struct ctl_table_header *table)
+{
+       int i = 0;
+       struct ctl_table      item;
 
-        while ((item = table[i++]) != NULL) 
-                sysctl_unregister_oid(item);
-        return;
+       while ((item = table[i++]) != NULL)
+               sysctl_unregister_oid(item);
+       return;
 }
 
 /*
@@ -393,8 +413,8 @@ int
 insert_proc(void)
 {
 #if 1
-        if (!libcfs_table_header) 
-                libcfs_table_header = cfs_register_sysctl_table(top_table, 0);
+       if (!libcfs_table_header)
+               libcfs_table_header = register_sysctl_table(top_table);
 #endif
        return 0;
 }
@@ -403,9 +423,9 @@ void
 remove_proc(void)
 {
 #if 1
-        if (libcfs_table_header != NULL) 
-                cfs_unregister_sysctl_table(libcfs_table_header); 
-        libcfs_table_header = NULL;
+       if (libcfs_table_header != NULL)
+               unregister_sysctl_table(libcfs_table_header);
+       libcfs_table_header = NULL;
 #endif
        return;
 }