Whamcloud - gitweb
LU-5092 nodemap: remove nodemap_idx_action, only act on MGS
[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, 2015, 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 /**
50  * Initialize MGS per-export statistics.
51  *
52  * This function sets up procfs entries for various MGS export counters. These
53  * counters are for per-client statistics tracked on the server.
54  *
55  * \param[in] obd       OBD device
56  * \param[in] exp       OBD export
57  * \param[in] localdata NID of client
58  *
59  * \retval              0 if successful
60  * \retval              negative value on error
61  */
62 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
63                           void *localdata)
64 {
65         lnet_nid_t *client_nid = localdata;
66         struct nid_stat *stats;
67         int rc;
68         ENTRY;
69
70         rc = lprocfs_exp_setup(exp, client_nid);
71         if (rc != 0)
72                 /* Mask error for already created /proc entries */
73                 RETURN(rc == -EALREADY ? 0 : rc);
74
75         stats = exp->exp_nid_stats;
76         stats->nid_stats = lprocfs_alloc_stats(NUM_OBD_STATS + LPROC_MGS_LAST,
77                                                 LPROCFS_STATS_FLAG_NOPERCPU);
78         if (stats->nid_stats == NULL)
79                 RETURN(-ENOMEM);
80
81         lprocfs_init_ops_stats(LPROC_MGS_LAST, stats->nid_stats);
82
83         mgs_stats_counter_init(stats->nid_stats);
84
85         rc = lprocfs_register_stats(stats->nid_proc, "stats", stats->nid_stats);
86         if (rc != 0) {
87                 lprocfs_free_stats(&stats->nid_stats);
88                 GOTO(out, rc);
89         }
90
91         rc = lprocfs_nid_ldlm_stats_init(stats);
92         if (rc != 0)
93                 GOTO(out, rc);
94
95 out:
96         RETURN(rc);
97 }
98
99 /**
100  * Add client export data to the MGS.  This data is currently NOT stored on
101  * disk in the last_rcvd file or anywhere else.  In the event of a MGS
102  * crash all connections are treated as new connections.
103  */
104 int mgs_client_add(struct obd_device *obd, struct obd_export *exp,
105                           void *localdata)
106 {
107         return 0;
108 }
109
110 /* Remove client export data from the MGS */
111 int mgs_client_free(struct obd_export *exp)
112 {
113         return 0;
114 }
115
116 int mgs_fs_setup(const struct lu_env *env, struct mgs_device *mgs)
117 {
118         struct lu_fid            fid;
119         struct dt_object        *o;
120         struct lu_fid            rfid;
121         struct dt_object        *root;
122         struct dt_object        *nm_config_file_obj;
123         struct nm_config_file   *nm_config_file;
124         int                      rc;
125
126         ENTRY;
127
128         OBD_SET_CTXT_MAGIC(&mgs->mgs_obd->obd_lvfs_ctxt);
129         mgs->mgs_obd->obd_lvfs_ctxt.dt = mgs->mgs_bottom;
130
131         /* XXX: fix when support for N:1 layering is implemented */
132         LASSERT(mgs->mgs_dt_dev.dd_lu_dev.ld_site);
133         mgs->mgs_dt_dev.dd_lu_dev.ld_site->ls_top_dev =
134                 &mgs->mgs_dt_dev.dd_lu_dev;
135
136         /* Setup the configs dir */
137         fid.f_seq = FID_SEQ_LOCAL_NAME;
138         fid.f_oid = 1;
139         fid.f_ver = 0;
140         rc = local_oid_storage_init(env, mgs->mgs_bottom, &fid, &mgs->mgs_los);
141         if (rc)
142                 GOTO(out, rc);
143
144         rc = dt_root_get(env, mgs->mgs_bottom, &rfid);
145         if (rc)
146                 GOTO(out_los, rc);
147
148         root = dt_locate_at(env, mgs->mgs_bottom, &rfid,
149                             &mgs->mgs_dt_dev.dd_lu_dev, NULL);
150         if (unlikely(IS_ERR(root)))
151                 GOTO(out_los, rc = PTR_ERR(root));
152
153         o = local_file_find_or_create(env, mgs->mgs_los, root,
154                                       MOUNT_CONFIGS_DIR,
155                                       S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO);
156         if (IS_ERR(o))
157                 GOTO(out_root, rc = PTR_ERR(o));
158
159         if (!dt_try_as_dir(env, o)) {
160                 lu_object_put(env, &o->do_lu);
161                 GOTO(out_root, rc = -ENOTDIR);
162         }
163
164         mgs->mgs_configs_dir = o;
165
166         /* colocated MDT will cache config in target / dir */
167         nm_config_file_obj = local_index_find_or_create(env, mgs->mgs_los,
168                                                         mgs->mgs_configs_dir,
169                                                         LUSTRE_NODEMAP_NAME,
170                                                         S_IFREG | S_IRUGO |
171                                                                   S_IWUSR,
172                                                         &dt_nodemap_features);
173         if (IS_ERR(nm_config_file_obj))
174                 GOTO(out_configs, rc = PTR_ERR(nm_config_file_obj));
175
176         if (nm_config_file_obj->do_index_ops == NULL) {
177                 rc = nm_config_file_obj->do_ops->do_index_try(env,
178                                                         nm_config_file_obj,
179                                                         &dt_nodemap_features);
180                 if (rc < 0) {
181                         lu_object_put(env, &nm_config_file_obj->do_lu);
182                         GOTO(out_configs, rc);
183                 }
184         }
185         nm_config_file = nm_config_file_register(env, nm_config_file_obj,
186                                                  mgs->mgs_los, NCFT_MGS);
187         if (IS_ERR(nm_config_file)) {
188                 lu_object_put(env, &nm_config_file_obj->do_lu);
189                 CERROR("%s: error loading nodemap config file, file must be "
190                        "removed via ldiskfs: rc = %ld\n",
191                        mgs->mgs_obd->obd_name, PTR_ERR(nm_config_file));
192                 GOTO(out_configs, rc = PTR_ERR(nm_config_file));
193         }
194         mgs->mgs_obd->u.obt.obt_nodemap_config_file = nm_config_file;
195
196         /* create directory to store nid table versions */
197         o = local_file_find_or_create(env, mgs->mgs_los, root, MGS_NIDTBL_DIR,
198                                       S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO);
199         if (IS_ERR(o))
200                 GOTO(out_nm, rc = PTR_ERR(o));
201
202         mgs->mgs_nidtbl_dir = o;
203
204 out_nm:
205         if (rc < 0) {
206                 nm_config_file_deregister(env, nm_config_file, NCFT_MGS);
207                 mgs->mgs_obd->u.obt.obt_nodemap_config_file = NULL;
208         }
209 out_configs:
210         if (rc < 0) {
211                 lu_object_put(env, &mgs->mgs_configs_dir->do_lu);
212                 mgs->mgs_configs_dir = NULL;
213         }
214 out_root:
215         lu_object_put(env, &root->do_lu);
216 out_los:
217         if (rc) {
218                 local_oid_storage_fini(env, mgs->mgs_los);
219                 mgs->mgs_los = NULL;
220         }
221 out:
222         mgs->mgs_dt_dev.dd_lu_dev.ld_site->ls_top_dev = NULL;
223
224         return rc;
225 }
226
227 int mgs_fs_cleanup(const struct lu_env *env, struct mgs_device *mgs)
228 {
229         if (mgs->mgs_configs_dir) {
230                 lu_object_put(env, &mgs->mgs_configs_dir->do_lu);
231                 mgs->mgs_configs_dir = NULL;
232         }
233         if (mgs->mgs_nidtbl_dir) {
234                 lu_object_put(env, &mgs->mgs_nidtbl_dir->do_lu);
235                 mgs->mgs_nidtbl_dir = NULL;
236         }
237         if (mgs->mgs_obd->u.obt.obt_nodemap_config_file != NULL) {
238                 nm_config_file_deregister(env,
239                                 mgs->mgs_obd->u.obt.obt_nodemap_config_file,
240                                 NCFT_MGS);
241                 mgs->mgs_obd->u.obt.obt_nodemap_config_file = NULL;
242         }
243
244         if (mgs->mgs_los) {
245                 local_oid_storage_fini(env, mgs->mgs_los);
246                 mgs->mgs_los = NULL;
247         }
248
249         return 0;
250 }