Whamcloud - gitweb
LU-6068 misc: update Intel copyright messages 2014
[fs/lustre-release.git] / lustre / ptlrpc / gss / lproc_gss.c
index fd0b7b1..06d7cf7 100644 (file)
@@ -26,6 +26,8 @@
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  */
 
 #define DEBUG_SUBSYSTEM S_SEC
-#ifdef __KERNEL__
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/dcache.h>
 #include <linux/fs.h>
 #include <linux/mutex.h>
-#else
-#include <liblustre.h>
-#endif
 
 #include <obd.h>
 #include <obd_class.h>
@@ -64,21 +62,21 @@ static struct proc_dir_entry *gss_proc_lk = NULL;
  * statistic of "out-of-sequence-window"
  */
 static struct {
-       spinlock_t  oos_lock;
-        cfs_atomic_t    oos_cli_count;       /* client occurrence */
-        int             oos_cli_behind;      /* client max seqs behind */
-        cfs_atomic_t    oos_svc_replay[3];   /* server replay detected */
-        cfs_atomic_t    oos_svc_pass[3];     /* server verified ok */
+       spinlock_t      oos_lock;
+       atomic_t        oos_cli_count;          /* client occurrence */
+       int             oos_cli_behind;         /* client max seqs behind */
+       atomic_t        oos_svc_replay[3];      /* server replay detected */
+       atomic_t        oos_svc_pass[3];        /* server verified ok */
 } gss_stat_oos = {
-        .oos_cli_count  = CFS_ATOMIC_INIT(0),
-        .oos_cli_behind = 0,
-        .oos_svc_replay = { CFS_ATOMIC_INIT(0), },
-        .oos_svc_pass   = { CFS_ATOMIC_INIT(0), },
+       .oos_cli_count  = ATOMIC_INIT(0),
+       .oos_cli_behind = 0,
+       .oos_svc_replay = { ATOMIC_INIT(0), },
+       .oos_svc_pass   = { ATOMIC_INIT(0), },
 };
 
 void gss_stat_oos_record_cli(int behind)
 {
-       cfs_atomic_inc(&gss_stat_oos.oos_cli_count);
+       atomic_inc(&gss_stat_oos.oos_cli_count);
 
        spin_lock(&gss_stat_oos.oos_lock);
        if (behind > gss_stat_oos.oos_cli_behind)
@@ -88,45 +86,41 @@ void gss_stat_oos_record_cli(int behind)
 
 void gss_stat_oos_record_svc(int phase, int replay)
 {
-        LASSERT(phase >= 0 && phase <= 2);
+       LASSERT(phase >= 0 && phase <= 2);
 
-        if (replay)
-                cfs_atomic_inc(&gss_stat_oos.oos_svc_replay[phase]);
-        else
-                cfs_atomic_inc(&gss_stat_oos.oos_svc_pass[phase]);
+       if (replay)
+               atomic_inc(&gss_stat_oos.oos_svc_replay[phase]);
+       else
+               atomic_inc(&gss_stat_oos.oos_svc_pass[phase]);
 }
 
-static int gss_proc_read_oos(char *page, char **start, off_t off, int count,
-                             int *eof, void *data)
+static int gss_proc_oos_seq_show(struct seq_file *m, void *v)
 {
-        int written;
-
-        written = snprintf(page, count,
-                        "seqwin:                %u\n"
-                        "backwin:               %u\n"
-                        "client fall behind seqwin\n"
-                        "  occurrence:          %d\n"
-                        "  max seq behind:      %d\n"
-                        "server replay detected:\n"
-                        "  phase 0:             %d\n"
-                        "  phase 1:             %d\n"
-                        "  phase 2:             %d\n"
-                        "server verify ok:\n"
-                        "  phase 2:             %d\n",
-                        GSS_SEQ_WIN_MAIN,
-                        GSS_SEQ_WIN_BACK,
-                        cfs_atomic_read(&gss_stat_oos.oos_cli_count),
-                        gss_stat_oos.oos_cli_behind,
-                        cfs_atomic_read(&gss_stat_oos.oos_svc_replay[0]),
-                        cfs_atomic_read(&gss_stat_oos.oos_svc_replay[1]),
-                        cfs_atomic_read(&gss_stat_oos.oos_svc_replay[2]),
-                        cfs_atomic_read(&gss_stat_oos.oos_svc_pass[2]));
-
-        return written;
+       return seq_printf(m, "seqwin:              %u\n"
+                         "backwin:             %u\n"
+                         "client fall behind seqwin\n"
+                         "  occurrence:        %d\n"
+                         "  max seq behind:    %d\n"
+                         "server replay detected:\n"
+                         "  phase 0:           %d\n"
+                         "  phase 1:           %d\n"
+                         "  phase 2:           %d\n"
+                         "server verify ok:\n"
+                         "  phase 2:           %d\n",
+                         GSS_SEQ_WIN_MAIN,
+                         GSS_SEQ_WIN_BACK,
+                         atomic_read(&gss_stat_oos.oos_cli_count),
+                         gss_stat_oos.oos_cli_behind,
+                         atomic_read(&gss_stat_oos.oos_svc_replay[0]),
+                         atomic_read(&gss_stat_oos.oos_svc_replay[1]),
+                         atomic_read(&gss_stat_oos.oos_svc_replay[2]),
+                         atomic_read(&gss_stat_oos.oos_svc_pass[2]));
 }
+LPROC_SEQ_FOPS_RO(gss_proc_oos);
 
-static int gss_proc_write_secinit(struct file *file, const char *buffer,
-                                  unsigned long count, void *data)
+static ssize_t
+gss_proc_write_secinit(struct file *file, const char *buffer,
+                                 size_t count, loff_t *off)
 {
         int rc;
 
@@ -135,14 +129,20 @@ static int gss_proc_write_secinit(struct file *file, const char *buffer,
                 LASSERT(rc < 0);
                 return rc;
         }
-
-        return ((int) count);
+       return count;
 }
 
-static struct lprocfs_vars gss_lprocfs_vars[] = {
-        { "replays", gss_proc_read_oos, NULL },
-        { "init_channel", NULL, gss_proc_write_secinit, NULL, NULL, 0222 },
-        { NULL }
+static const struct file_operations gss_proc_secinit = {
+       .write = gss_proc_write_secinit,
+};
+
+static struct lprocfs_seq_vars gss_lprocfs_vars[] = {
+       { .name =       "replays",
+         .fops =       &gss_proc_oos_fops      },
+       { .name =       "init_channel",
+         .fops =       &gss_proc_secinit,
+         .proc_mode =  0222                    },
+       { NULL }
 };
 
 /*
@@ -152,14 +152,14 @@ static struct lprocfs_vars gss_lprocfs_vars[] = {
  */
 static int gss_lk_debug_level = 1;
 
-static int gss_lk_proc_read_dl(char *page, char **start, off_t off,
-                               int count, int *eof, void *data)
+static int gss_lk_proc_dl_seq_show(struct seq_file *m, void *v)
 {
-        return snprintf(page, count, "%u\n", gss_lk_debug_level);
+       return seq_printf(m, "%u\n", gss_lk_debug_level);
 }
 
-static int gss_lk_proc_write_dl(struct file *file, const char *buffer,
-                                unsigned long count, void *data)
+static ssize_t
+gss_lk_proc_dl_seq_write(struct file *file, const char *buffer,
+                               size_t count, loff_t *off)
 {
         int     val, rc;
 
@@ -173,10 +173,12 @@ static int gss_lk_proc_write_dl(struct file *file, const char *buffer,
         gss_lk_debug_level = val;
         return count;
 }
+LPROC_SEQ_FOPS(gss_lk_proc_dl);
 
-static struct lprocfs_vars gss_lk_lprocfs_vars[] = {
-        { "debug_level", gss_lk_proc_read_dl, gss_lk_proc_write_dl, NULL },
-        { NULL }
+static struct lprocfs_seq_vars gss_lk_lprocfs_vars[] = {
+       { .name =       "debug_level",
+         .fops =       &gss_lk_proc_dl_fops    },
+       { NULL }
 };
 
 void gss_exit_lproc(void)
@@ -194,28 +196,31 @@ void gss_exit_lproc(void)
 
 int gss_init_lproc(void)
 {
-       int     rc;
+       int     rc;
 
        spin_lock_init(&gss_stat_oos.oos_lock);
 
-        gss_proc_root = lprocfs_register("gss", sptlrpc_proc_root,
-                                         gss_lprocfs_vars, NULL);
-        if (IS_ERR(gss_proc_root)) {
-                gss_proc_root = NULL;
-                GOTO(err_out, rc = PTR_ERR(gss_proc_root));
-        }
-
-        gss_proc_lk = lprocfs_register("lgss_keyring", gss_proc_root,
-                                       gss_lk_lprocfs_vars, NULL);
-        if (IS_ERR(gss_proc_lk)) {
-                gss_proc_lk = NULL;
-                GOTO(err_out, rc = PTR_ERR(gss_proc_root));
-        }
-
-        return 0;
-
-err_out:
-        CERROR("failed to initialize gss lproc entries: %d\n", rc);
-        gss_exit_lproc();
-        return rc;
+       gss_proc_root = lprocfs_seq_register("gss", sptlrpc_proc_root,
+                                               gss_lprocfs_vars, NULL);
+       if (IS_ERR(gss_proc_root)) {
+               rc = PTR_ERR(gss_proc_root);
+               gss_proc_root = NULL;
+               GOTO(out, rc);
+       }
+
+       gss_proc_lk = lprocfs_seq_register("lgss_keyring", gss_proc_root,
+                                               gss_lk_lprocfs_vars, NULL);
+       if (IS_ERR(gss_proc_lk)) {
+               rc = PTR_ERR(gss_proc_lk);
+               gss_proc_lk = NULL;
+               GOTO(out, rc);
+       }
+
+       return 0;
+
+out:
+       CERROR("failed to initialize gss lproc entries: %d\n", rc);
+       gss_exit_lproc();
+
+       return rc;
 }