Whamcloud - gitweb
- make HEAD from b_post_cmd3
[fs/lustre-release.git] / lustre / cmm / cmm_lproc.c
1 /* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  cmm/cmm_lproc.c
5  *  CMM lprocfs stuff
6  *
7  *  Copyright (C) 2006 Cluster File Systems, Inc.
8  *   Author: Wang Di      <wangdi@clusterfs.com>
9  *   Author: Yury Umanets <umka@clusterfs.com>
10  *
11  *   This file is part of the Lustre file system, http://www.lustre.org
12  *   Lustre is a trademark of Cluster File Systems, Inc.
13  *
14  *   You may have signed or agreed to another license before downloading
15  *   this software.  If so, you are bound by the terms and conditions
16  *   of that agreement, and the following does not apply to you.  See the
17  *   LICENSE file included with this distribution for more information.
18  *
19  *   If you did not agree to a different license, then this copy of Lustre
20  *   is open source software; you can redistribute it and/or modify it
21  *   under the terms of version 2 of the GNU General Public License as
22  *   published by the Free Software Foundation.
23  *
24  *   In either case, Lustre is distributed in the hope that it will be
25  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
26  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  *   license text for more details.
28  */
29 #ifndef EXPORT_SYMTAB
30 # define EXPORT_SYMTAB
31 #endif
32 #define DEBUG_SUBSYSTEM S_MDS
33
34 #include <linux/module.h>
35 #include <obd.h>
36 #include <obd_class.h>
37 #include <lustre_ver.h>
38 #include <obd_support.h>
39 #include <lprocfs_status.h>
40 #include <lu_time.h>
41
42 #include <lustre/lustre_idl.h>
43
44 #include "cmm_internal.h"
45
46 static const char *cmm_counter_names[LPROC_CMM_NR] = {
47         [LPROC_CMM_SPLIT_CHECK] = "split_check",
48         [LPROC_CMM_SPLIT]       = "split",
49         [LPROC_CMM_LOOKUP]      = "lookup",
50         [LPROC_CMM_CREATE]      = "create"
51 };
52
53 int cmm_procfs_init(struct cmm_device *cmm, const char *name)
54 {
55         struct lu_device    *ld = &cmm->cmm_md_dev.md_lu_dev;
56         struct obd_type     *type;
57         int                  rc;
58         ENTRY;
59
60         type = ld->ld_type->ldt_obd_type;
61
62         LASSERT(name != NULL);
63         LASSERT(type != NULL);
64
65         /* Find the type procroot and add the proc entry for this device. */
66         cmm->cmm_proc_entry = lprocfs_register(name, type->typ_procroot,
67                                                NULL, NULL);
68         if (IS_ERR(cmm->cmm_proc_entry)) {
69                 rc = PTR_ERR(cmm->cmm_proc_entry);
70                 CERROR("Error %d setting up lprocfs for %s\n",
71                        rc, name);
72                 cmm->cmm_proc_entry = NULL;
73                 GOTO(out, rc);
74         }
75
76         rc = lu_time_init(&cmm->cmm_stats,
77                           cmm->cmm_proc_entry,
78                           cmm_counter_names, ARRAY_SIZE(cmm_counter_names));
79
80         EXIT;
81 out:
82         if (rc)
83                cmm_procfs_fini(cmm);
84         return rc;
85 }
86
87 int cmm_procfs_fini(struct cmm_device *cmm)
88 {
89         if (cmm->cmm_stats)
90                 lu_time_fini(&cmm->cmm_stats);
91
92         if (cmm->cmm_proc_entry) {
93                  lprocfs_remove(&cmm->cmm_proc_entry);
94                  cmm->cmm_proc_entry = NULL;
95         }
96         RETURN(0);
97 }
98
99 void cmm_lprocfs_time_start(const struct lu_env *env)
100 {
101         lu_lprocfs_time_start(env);
102 }
103
104 void cmm_lprocfs_time_end(const struct lu_env *env, struct cmm_device *cmm,
105                           int idx)
106 {
107         lu_lprocfs_time_end(env, cmm->cmm_stats, idx);
108 }