Whamcloud - gitweb
Need to replace the nfs-utils-lustre that was installed with CMD2.
[fs/lustre-release.git] / lustre / include / linux / lprocfs_status.h
index 0a8a2a9..2e61e82 100644 (file)
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  *   Top level header file for LProc SNMP
+ *   Author: Hariharan Thantry thantry@users.sourceforge.net
  */
 #ifndef _LPROCFS_SNMP_H
 #define _LPROCFS_SNMP_H
 
-/*
-#ifndef LPROC_SNMP
-#define LPROC_SNMP
-#endif
-*/
 
+#ifdef __KERNEL__
+#include <linux/config.h>
+#include <linux/autoconf.h>
 #include <linux/proc_fs.h>
+#include <linux/version.h>
+#include <linux/smp.h>
+#include <libcfs/kp30.h>
+
+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+#  include <linux/statfs.h>
+# else 
+#  define kstatfs statfs
+# endif
+
+#else 
+#  define kstatfs statfs
+#endif
+
 
-struct lprocfs_vars{
-        char *name;
+#undef LPROCFS
+#if (defined(__KERNEL__) && defined(CONFIG_PROC_FS))
+# define LPROCFS
+#endif
+
+struct lprocfs_vars {
+        const char   *name;
         read_proc_t *read_fptr;
         write_proc_t *write_fptr;
+        void *data;
 };
 
-#ifdef LPROC_SNMP
-
-struct proc_dir_entry* lprocfs_mkdir(const char *dname,
-                                     struct proc_dir_entry *parent);
-struct proc_dir_entry* lprocfs_srch(struct proc_dir_entry *head,
-                                    const char *name);
-void lprocfs_remove_all(struct proc_dir_entry *root);
-struct proc_dir_entry* lprocfs_new_dir(struct proc_dir_entry *root,
-                                       const char *string,
-                                       const char *tok);
-int lprocfs_new_vars(struct proc_dir_entry *root, struct lprocfs_vars *list,
-                     const char *tok, void *data);
-
-int lprocfs_add_vars(struct proc_dir_entry *root, struct lprocfs_vars *var,
-                     void *data);
-int lprocfs_reg_obd(struct obd_device *device, struct lprocfs_vars *list,
-                    void *data);
-int lprocfs_dereg_obd(struct obd_device *device);
-struct proc_dir_entry* lprocfs_reg_mnt(char *mnt_name);
-int lprocfs_dereg_mnt(struct proc_dir_entry *root);
-
-int lprocfs_reg_class(struct obd_type *type, struct lprocfs_vars *list,
-                      void *data);
-int lprocfs_dereg_class(struct obd_type *class);
-int lprocfs_reg_main(void);
-int lprocfs_dereg_main(void);
-int lprocfs_ll_rd(char *page, char **start, off_t off, int count, int *eof,
-                  void *data);
-#else
+struct lprocfs_static_vars {
+        struct lprocfs_vars *module_vars;
+        struct lprocfs_vars *obd_vars;
+};
 
+/* An lprocfs counter can be configured using the enum bit masks below.
+ *
+ * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
+ * protects this counter from concurrent updates. If not specified,
+ * lprocfs an internal per-counter lock variable. External locks are
+ * not used to protect counter increments, but are used to protect
+ * counter readout and resets.
+ *
+ * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
+ * (i.e. counter can be incremented by more than "1"). When specified,
+ * the counter maintains min, max and sum in addition to a simple
+ * invocation count. This allows averages to be be computed.
+ * If not specified, the counter is an increment-by-1 counter.
+ * min, max, sum, etc. are not maintained.
+ *
+ * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
+ * squares (for multi-valued counter samples only). This allows
+ * external computation of standard deviation, but involves a 64-bit
+ * multiply per counter increment.
+ */
 
-static inline int lprocfs_add_vars(struct proc_dir_entry *root,
-                                  struct lprocfs_vars *var, void *data)
-{
-        return 0;
-}
+enum {
+        LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
+        LPROCFS_CNTR_AVGMINMAX    = 0x0002,
+        LPROCFS_CNTR_STDDEV       = 0x0004,
 
-static inline int lprocfs_reg_obd(struct obd_device* device,
-                                 struct lprocfs_vars* list, void* data)
-{
-        return 0;
-}
+        /* counter data type */
+        LPROCFS_TYPE_REGS         = 0x0100,
+        LPROCFS_TYPE_BYTES        = 0x0200,
+        LPROCFS_TYPE_PAGES        = 0x0400,
+        LPROCFS_TYPE_CYCLE        = 0x0800,
+};
 
-static inline int lprocfs_dereg_obd(struct obd_device* device)
-{
-        return 0;
-}
+struct lprocfs_atomic {
+        atomic_t               la_entry;
+        atomic_t               la_exit;
+};
 
-static inline struct proc_dir_entry* lprocfs_reg_mnt(char *name)
-{
-        return 0;
-}
+struct lprocfs_counter {
+        struct lprocfs_atomic  lc_cntl;  /* may need to move to per set */
+        unsigned int           lc_config;
+        __u64                  lc_count;
+        __u64                  lc_sum;
+        __u64                  lc_min;
+        __u64                  lc_max;
+        __u64                  lc_sumsquare;
+        const char            *lc_name;   /* must be static */
+        const char            *lc_units;  /* must be static */
+};
 
-static inline int lprocfs_dereg_mnt(struct proc_dir_entry* root)
-{
-        return 0;
-}
+struct lprocfs_percpu {
+        struct lprocfs_counter lp_cntr[0];
+};
 
-static inline int lprocfs_reg_class(struct obd_type* type,
-                                    struct lprocfs_vars* list, void* data)
-{
-        return 0;
-}
 
-static inline int lprocfs_dereg_class(struct obd_type* class)
-{
-        return 0;
-}
+struct lprocfs_stats {
+        unsigned int           ls_num;     /* # of counters */
+        unsigned int           ls_percpu_size;
+        struct lprocfs_percpu *ls_percpu[0];
+};
 
-static inline int lprocfs_reg_main(void)
-{
-        return 0;
-}
 
-static inline int lprocfs_dereg_main(void)
+/* class_obd.c */
+extern struct proc_dir_entry *proc_lustre_root;
+
+struct obd_device;
+struct file;
+
+#ifdef LPROCFS
+
+/* Two optimized LPROCFS counter increment functions are provided:
+ *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
+ *     lprocfs_counter_add(cntr) - use for multi-valued counters
+ * Counter data layout allows config flag, counter lock and the
+ * count itself to reside within a single cache line.
+ */
+
+static inline void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
+                                       long amount)
 {
-        return 0;
+        struct lprocfs_counter *percpu_cntr;
+
+        LASSERT(stats != NULL);
+        percpu_cntr = &(stats->ls_percpu[smp_processor_id()]->lp_cntr[idx]);
+        atomic_inc(&percpu_cntr->lc_cntl.la_entry);
+        percpu_cntr->lc_count++;
+
+        if (percpu_cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) {
+                percpu_cntr->lc_sum += amount;
+                if (percpu_cntr->lc_config & LPROCFS_CNTR_STDDEV)
+                        percpu_cntr->lc_sumsquare += (__u64)amount * amount;
+                if (amount < percpu_cntr->lc_min)
+                        percpu_cntr->lc_min = amount;
+                if (amount > percpu_cntr->lc_max)
+                        percpu_cntr->lc_max = amount;
+        }
+        atomic_inc(&percpu_cntr->lc_cntl.la_exit);
 }
 
-static inline int lprocfs_ll_rd(char *page, char **start, off_t off,
-                                int count, int *eof, void *data)
+static inline void lprocfs_counter_incr(struct lprocfs_stats *stats, int idx)
 {
-        return 0;
+        struct lprocfs_counter *percpu_cntr;
+
+        LASSERT(stats != NULL);
+        percpu_cntr = &(stats->ls_percpu[smp_processor_id()]->lp_cntr[idx]);
+        atomic_inc(&percpu_cntr->lc_cntl.la_entry);
+        percpu_cntr->lc_count++;
+        atomic_inc(&percpu_cntr->lc_cntl.la_exit);
 }
-#endif /* LPROC_SNMP */
+
+extern struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num);
+extern void lprocfs_free_stats(struct lprocfs_stats *stats);
+extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
+                                 unsigned conf, const char *name,
+                                 const char *units);
+extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
+                                   unsigned int num_private_stats);
+extern void lprocfs_free_obd_stats(struct obd_device *obddev);
+extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
+                                  unsigned int num_private_stats);
+extern void lprocfs_free_md_stats(struct obd_device *obddev);
+extern int lprocfs_register_stats(struct proc_dir_entry *root, 
+                                 const char *name,
+                                  struct lprocfs_stats *stats);
+
+#define LPROCFS_INIT_MULTI_VARS(array, size)                                   \
+void lprocfs_init_multi_vars(unsigned int idx,                                 \
+                             struct lprocfs_static_vars *x)                    \
+{                                                                              \
+       struct lprocfs_static_vars *glob = (struct lprocfs_static_vars*)array; \
+       LASSERT(glob != 0);                                                    \
+       LASSERT(idx < (unsigned int)(size));                                   \
+       x->module_vars = glob[idx].module_vars;                                \
+       x->obd_vars = glob[idx].obd_vars;                                      \
+}                                                                              \
+
+#define LPROCFS_INIT_VARS(name, vclass, vinstance)                            \
+void lprocfs_##name##_init_vars(struct lprocfs_static_vars *x)                \
+{                                                                                     \
+        x->module_vars = vclass;                                                      \
+        x->obd_vars = vinstance;                                                      \
+}                                                                                     \
+
+#define lprocfs_init_vars(NAME, VAR)                                          \
+do {                                                                          \
+        extern void lprocfs_##NAME##_init_vars(struct lprocfs_static_vars *);  \
+        lprocfs_##NAME##_init_vars(VAR);                                       \
+} while (0)
+
+extern void lprocfs_init_multi_vars(unsigned int idx,
+                                    struct lprocfs_static_vars *var);
+/* lprocfs_status.c */
+extern int lprocfs_add_vars(struct proc_dir_entry *root,
+                            struct lprocfs_vars *var,
+                            void *data);
+
+extern struct proc_dir_entry *lprocfs_register(const char *name,
+                                               struct proc_dir_entry *parent,
+                                               struct lprocfs_vars *list,
+                                               void *data);
+
+extern void lprocfs_remove(struct proc_dir_entry *root);
+
+extern struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *root,
+                                           const char *name);
+
+extern int lprocfs_obd_attach(struct obd_device *obd, struct lprocfs_vars *list);
+extern int lprocfs_obd_detach(struct obd_device *obd);
+
+/* Generic callbacks */
+
+extern int lprocfs_rd_u64(char *page, char **start, off_t off,
+                          int count, int *eof, void *data);
+extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
+                           int count, int *eof, void *data);
+extern int lprocfs_rd_name(char *page, char **start, off_t off,
+                           int count, int *eof, void *data);
+extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
+                             int count, int *eof, void *data);
+extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
+                                  int count, int *eof, void *data);
+extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
+                                int count, int *eof, void *data);
+extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
+                                  int count, int *eof, void *data);
+extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
+                              int count, int *eof, void *data);
+
+/* Statfs helpers */
+extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
+                              int count, int *eof, void *data);
+extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
+                                  int count, int *eof, void *data);
+extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
+                                 int count, int *eof, void *data);
+extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
+                                 int count, int *eof, void *data);
+extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
+                                 int count, int *eof, void *data);
+extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
+                                int count, int *eof, void *data);
+extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
+                                 int count, int *eof, void *data);
+
+extern int lprocfs_write_helper(const char *buffer, unsigned long count,
+                                int *val);
+extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
+                                    __u64 *val);
+int lprocfs_obd_seq_create(struct obd_device *dev, char *name, mode_t mode,
+                           struct file_operations *seq_fops, void *data);
+struct obd_histogram;
+void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
+void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
+void lprocfs_oh_clear(struct obd_histogram *oh);
+unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
+
+struct obd_service_time;
+void lprocfs_stime_record(struct obd_service_time *stime,
+                          struct timeval *large, struct timeval *small);
+unsigned long lprocfs_stime_avg_ms(struct obd_service_time *stime);
+unsigned long lprocfs_stime_avg_us(struct obd_service_time *stime);
+
+/* lprocfs_status.c: counter read/write functions */
+extern int lprocfs_counter_read(char *page, char **start, off_t off,
+                                int count, int *eof, void *data);
+extern int lprocfs_counter_write(struct file *file, const char *buffer,
+                                 unsigned long count, void *data);
+
+/* lprocfs_status.c: recovery status */
+int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
+                                   int count, int *eof, void *data);
+
+#else
+/* LPROCFS is not defined */
+static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
+                                       int index, long amount) { return; }
+static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
+                                        int index) { return; }
+static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
+                                        int index, unsigned conf,
+                                        const char *name, const char *units)
+{ return; }
+struct obd_service_time;
+static inline void lprocfs_stime_record(struct obd_service_time *stime,
+                          struct timeval *large, struct timeval *small)
+{ return; }
+
+
+static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num)
+{ return NULL; }
+static inline void lprocfs_free_stats(struct lprocfs_stats *stats)
+{ return; }
+
+static inline int lprocfs_register_stats(struct proc_dir_entry *root,
+                                            const char *name,
+                                            struct lprocfs_stats *stats)
+{ return 0; }
+static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
+                                             unsigned int num_private_stats)
+{ return 0; }
+static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
+{ return; }
+
+static inline struct proc_dir_entry *
+lprocfs_register(const char *name, struct proc_dir_entry *parent,
+                 struct lprocfs_vars *list, void *data) { return NULL; }
+#define LPROCFS_INIT_MULTI_VARS(array, size) do {} while (0)
+static inline void lprocfs_init_multi_vars(unsigned int idx,
+                                           struct lprocfs_static_vars *x) { return; }
+#define LPROCFS_INIT_VARS(name, vclass, vinstance) do {} while (0)
+#define lprocfs_init_vars(...) do {} while (0)
+static inline int lprocfs_add_vars(struct proc_dir_entry *root,
+                                   struct lprocfs_vars *var,
+                                   void *data) { return 0; }
+static inline void lprocfs_remove(struct proc_dir_entry *root) {};
+static inline struct proc_dir_entry *lprocfs_srch(struct proc_dir_entry *head,
+                                    const char *name) {return 0;}
+static inline int lprocfs_obd_attach(struct obd_device *dev,
+                                     struct lprocfs_vars *list) { return 0; }
+static inline int lprocfs_obd_detach(struct obd_device *dev)  { return 0; }
+static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
+                                 int count, int *eof, void *data) { return 0; }
+static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
+                                  int count, int *eof, void *data) { return 0; }
+static inline int lprocfs_rd_name(char *page, char **start, off_t off,
+                                  int count, int *eof, void *data) { return 0; }
+static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
+                                         int count, int *eof, void *data)
+{ return 0; }
+static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
+                                       int count, int *eof, void *data)
+{ return 0; }
+static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
+                                         int count, int *eof, void *data)
+{ return 0; }
+static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
+                                     int count, int *eof, void *data) { return 0; }
+
+/* Statfs helpers */
+static inline
+int lprocfs_rd_blksize(char *page, char **start, off_t off,
+                       int count, int *eof, void *data) { return 0; }
+static inline
+int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
+                           int count, int *eof, void *data) { return 0; }
+static inline
+int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
+                          int count, int *eof, void *data) { return 0; }
+static inline
+int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
+                           int count, int *eof, void *data) { return 0; }
+static inline
+int lprocfs_rd_filestotal(char *page, char **start, off_t off,
+                          int count, int *eof, void *data) { return 0; }
+static inline
+int lprocfs_rd_filesfree(char *page, char **start, off_t off,
+                         int count, int *eof, void *data)  { return 0; }
+static inline
+int lprocfs_rd_filegroups(char *page, char **start, off_t off,
+                          int count, int *eof, void *data) { return 0; }
+static inline
+int lprocfs_counter_read(char *page, char **start, off_t off,
+                         int count, int *eof, void *data) { return 0; }
+static inline
+int lprocfs_counter_write(struct file *file, const char *buffer,
+                          unsigned long count, void *data) { return 0; }
+#endif /* LPROCFS */
 
 #endif /* LPROCFS_SNMP_H */