Whamcloud - gitweb
LU-2484 obd: add md_stats to MDC and LMV devices
[fs/lustre-release.git] / lustre / mgs / mgs_fs.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/mgs/mgs_fs.c
37  *
38  * Lustre Management Server (MGS) filesystem interface code
39  *
40  * Author: Nathan Rutman <nathan@clusterfs.com>
41  * Author: Alex Zhuravlev <bzzz@whamcloud.com>
42  */
43
44 #define DEBUG_SUBSYSTEM S_MGS
45
46 #include <lustre_fid.h>
47 #include "mgs_internal.h"
48
49 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
50                           void *localdata)
51 {
52         lnet_nid_t *client_nid = localdata;
53         struct nid_stat *tmp;
54         int rc, is_new_nid;
55         ENTRY;
56
57         rc = lprocfs_exp_setup(exp, client_nid, &is_new_nid);
58         if (rc != 0) {
59                 /* Mask error for already created /proc entries */
60                 if (rc == -EALREADY)
61                         rc = 0;
62                 GOTO(out, rc = 0);
63         }
64
65         if (!is_new_nid)
66                 GOTO(out, rc = 0);
67
68         tmp = exp->exp_nid_stats;
69         tmp->nid_stats = lprocfs_alloc_stats(NUM_OBD_STATS + LPROC_MGS_LAST,
70                                              LPROCFS_STATS_FLAG_NOPERCPU);
71         if (tmp->nid_stats == NULL)
72                 GOTO(out, rc = -ENOMEM);
73
74         lprocfs_init_ops_stats(LPROC_MGS_LAST, tmp->nid_stats);
75         mgs_stats_counter_init(tmp->nid_stats);
76         rc = lprocfs_register_stats(tmp->nid_proc, "stats", tmp->nid_stats);
77         if (rc != 0)
78                 GOTO(out, rc);
79
80         rc = lprocfs_nid_ldlm_stats_init(tmp);
81         if (rc != 0)
82                 GOTO(out, rc);
83
84         RETURN(0);
85 out:
86         return rc;
87 }
88
89 /**
90  * Add client export data to the MGS.  This data is currently NOT stored on
91  * disk in the last_rcvd file or anywhere else.  In the event of a MGS
92  * crash all connections are treated as new connections.
93  */
94 int mgs_client_add(struct obd_device *obd, struct obd_export *exp,
95                    void *localdata)
96 {
97         return 0;
98 }
99
100 /* Remove client export data from the MGS */
101 int mgs_client_free(struct obd_export *exp)
102 {
103         return 0;
104 }
105
106 int mgs_fs_setup(const struct lu_env *env, struct mgs_device *mgs)
107 {
108         struct lu_fid            fid;
109         struct dt_object        *o;
110         struct lu_fid            rfid;
111         struct dt_object        *root;
112         int                      rc;
113
114         ENTRY;
115
116         /* FIXME what's this?  Do I need it? */
117         rc = cfs_cleanup_group_info();
118         if (rc)
119                 RETURN(rc);
120
121         OBD_SET_CTXT_MAGIC(&mgs->mgs_obd->obd_lvfs_ctxt);
122         mgs->mgs_obd->obd_lvfs_ctxt.dt = mgs->mgs_bottom;
123
124         /* XXX: fix when support for N:1 layering is implemented */
125         LASSERT(mgs->mgs_dt_dev.dd_lu_dev.ld_site);
126         mgs->mgs_dt_dev.dd_lu_dev.ld_site->ls_top_dev =
127                 &mgs->mgs_dt_dev.dd_lu_dev;
128
129         /* Setup the configs dir */
130         fid.f_seq = FID_SEQ_LOCAL_NAME;
131         fid.f_oid = 1;
132         fid.f_ver = 0;
133         rc = local_oid_storage_init(env, mgs->mgs_bottom, &fid, &mgs->mgs_los);
134         if (rc)
135                 GOTO(out, rc);
136
137         rc = dt_root_get(env, mgs->mgs_bottom, &rfid);
138         if (rc)
139                 GOTO(out_los, rc);
140
141         root = dt_locate_at(env, mgs->mgs_bottom, &rfid,
142                             &mgs->mgs_dt_dev.dd_lu_dev);
143         if (unlikely(IS_ERR(root)))
144                 GOTO(out_los, rc = PTR_ERR(root));
145
146         o = local_file_find_or_create(env, mgs->mgs_los, root,
147                                       MOUNT_CONFIGS_DIR,
148                                       S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO);
149         if (IS_ERR(o))
150                 GOTO(out_root, rc = PTR_ERR(o));
151
152         if (!dt_try_as_dir(env, o)) {
153                 lu_object_put(env, &o->do_lu);
154                 GOTO(out_root, rc = -ENOTDIR);
155         }
156
157         mgs->mgs_configs_dir = o;
158
159         /* create directory to store nid table versions */
160         o = local_file_find_or_create(env, mgs->mgs_los, root, MGS_NIDTBL_DIR,
161                                       S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO);
162         if (IS_ERR(o)) {
163                 lu_object_put(env, &mgs->mgs_configs_dir->do_lu);
164                 mgs->mgs_configs_dir = NULL;
165                 GOTO(out_root, rc = PTR_ERR(o));
166         }
167
168         mgs->mgs_nidtbl_dir = o;
169
170 out_root:
171         lu_object_put(env, &root->do_lu);
172 out_los:
173         if (rc) {
174                 local_oid_storage_fini(env, mgs->mgs_los);
175                 mgs->mgs_los = NULL;
176         }
177 out:
178         mgs->mgs_dt_dev.dd_lu_dev.ld_site->ls_top_dev = NULL;
179
180         return rc;
181 }
182
183 int mgs_fs_cleanup(const struct lu_env *env, struct mgs_device *mgs)
184 {
185         class_disconnect_exports(mgs->mgs_obd); /* cleans up client info too */
186
187         if (mgs->mgs_configs_dir) {
188                 lu_object_put(env, &mgs->mgs_configs_dir->do_lu);
189                 mgs->mgs_configs_dir = NULL;
190         }
191         if (mgs->mgs_nidtbl_dir) {
192                 lu_object_put(env, &mgs->mgs_nidtbl_dir->do_lu);
193                 mgs->mgs_nidtbl_dir = NULL;
194         }
195         if (mgs->mgs_los) {
196                 local_oid_storage_fini(env, mgs->mgs_los);
197                 mgs->mgs_los = NULL;
198         }
199
200         return 0;
201 }