4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
33 * Lustre Management Server (MGS) filesystem interface code
35 * Author: Nathan Rutman <nathan@clusterfs.com>
36 * Author: Alex Zhuravlev <bzzz@whamcloud.com>
39 #define DEBUG_SUBSYSTEM S_MGS
41 #include <lustre_fid.h>
42 #include "mgs_internal.h"
45 * Initialize MGS per-export statistics.
47 * This function sets up procfs entries for various MGS export counters. These
48 * counters are for per-client statistics tracked on the server.
50 * \param[in] obd OBD device
51 * \param[in] exp OBD export
52 * \param[in] localdata NID of client
54 * \retval 0 if successful
55 * \retval negative value on error
57 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
60 struct lnet_nid *client_nid = localdata;
61 struct nid_stat *stats;
66 rc = lprocfs_exp_setup(exp, client_nid);
68 /* Mask error for already created /proc entries */
69 RETURN(rc == -EALREADY ? 0 : rc);
71 stats = exp->exp_nid_stats;
72 stats->nid_stats = lprocfs_stats_alloc(LPROC_MGS_LAST,
73 LPROCFS_STATS_FLAG_NOPERCPU);
74 if (stats->nid_stats == NULL)
77 mgs_stats_counter_init(stats->nid_stats);
79 rc = lprocfs_stats_register(stats->nid_proc, "stats", stats->nid_stats);
81 lprocfs_stats_free(&stats->nid_stats);
85 rc = lprocfs_nid_ldlm_stats_init(stats);
93 /* Remove client export data from the MGS */
94 int mgs_client_free(struct obd_export *exp)
99 int mgs_fs_setup(const struct lu_env *env, struct mgs_device *mgs)
104 struct dt_object *root;
105 struct dt_object *nm_config_file_obj;
106 struct nm_config_file *nm_config_file;
111 OBD_SET_CTXT_MAGIC(&mgs->mgs_obd->obd_lvfs_ctxt);
112 mgs->mgs_obd->obd_lvfs_ctxt.dt = mgs->mgs_bottom;
114 /* XXX: fix when support for N:1 layering is implemented */
115 LASSERT(mgs->mgs_dt_dev.dd_lu_dev.ld_site);
116 mgs->mgs_dt_dev.dd_lu_dev.ld_site->ls_top_dev =
117 &mgs->mgs_dt_dev.dd_lu_dev;
119 /* Setup the configs dir */
120 fid.f_seq = FID_SEQ_LOCAL_NAME;
123 rc = local_oid_storage_init(env, mgs->mgs_bottom, &fid, &mgs->mgs_los);
127 rc = dt_root_get(env, mgs->mgs_bottom, &rfid);
131 root = dt_locate_at(env, mgs->mgs_bottom, &rfid,
132 &mgs->mgs_dt_dev.dd_lu_dev, NULL);
133 if (unlikely(IS_ERR(root)))
134 GOTO(out_los, rc = PTR_ERR(root));
136 o = local_file_find_or_create(env, mgs->mgs_los, root,
140 GOTO(out_root, rc = PTR_ERR(o));
142 if (!dt_try_as_dir(env, o, true)) {
143 dt_object_put(env, o);
144 GOTO(out_root, rc = -ENOTDIR);
147 mgs->mgs_configs_dir = o;
149 /* colocated MDT will cache config in target root dir */
150 nm_config_file_obj = local_index_find_or_create(env, mgs->mgs_los,
151 mgs->mgs_configs_dir,
154 &dt_nodemap_features);
155 if (IS_ERR(nm_config_file_obj))
156 GOTO(out_configs, rc = PTR_ERR(nm_config_file_obj));
158 if (nm_config_file_obj->do_index_ops == NULL) {
159 rc = nm_config_file_obj->do_ops->do_index_try(env,
161 &dt_nodemap_features);
163 dt_object_put(env, nm_config_file_obj);
164 GOTO(out_configs, rc);
167 nm_config_file = nm_config_file_register_mgs(env, nm_config_file_obj,
169 dt_object_put(env, nm_config_file_obj);
170 if (IS_ERR(nm_config_file)) {
171 CERROR("%s: error loading nodemap config file, file must be "
172 "removed via ldiskfs: rc = %ld\n",
173 mgs->mgs_obd->obd_name, PTR_ERR(nm_config_file));
174 GOTO(out_configs, rc = PTR_ERR(nm_config_file));
176 obd2obt(mgs->mgs_obd)->obt_nodemap_config_file = nm_config_file;
178 /* create directory to store nid table versions */
179 o = local_file_find_or_create(env, mgs->mgs_los, root, MGS_NIDTBL_DIR,
182 GOTO(out_nm, rc = PTR_ERR(o));
184 mgs->mgs_nidtbl_dir = o;
188 nm_config_file_deregister_mgs(env, nm_config_file);
189 obd2obt(mgs->mgs_obd)->obt_nodemap_config_file = NULL;
193 dt_object_put(env, mgs->mgs_configs_dir);
194 mgs->mgs_configs_dir = NULL;
197 dt_object_put(env, root);
200 local_oid_storage_fini(env, mgs->mgs_los);
204 mgs->mgs_dt_dev.dd_lu_dev.ld_site->ls_top_dev = NULL;
209 int mgs_fs_cleanup(const struct lu_env *env, struct mgs_device *mgs)
211 struct lustre_cfg_bufs bufs;
212 struct lustre_cfg *lcfg;
215 * For the MGS on independent device from MDT, it notifies the lower
216 * layer OSD to backup index before the umount via LCFG_PRE_CLEANUP.
218 lustre_cfg_bufs_reset(&bufs, mgs->mgs_obd->obd_name);
219 lustre_cfg_bufs_set_string(&bufs, 1, NULL);
220 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
222 CERROR("%s: failed to trigger LCFG_PRE_CLEANUP\n",
223 mgs->mgs_obd->obd_name);
225 struct lu_device *l = &mgs->mgs_bottom->dd_lu_dev;
227 lustre_cfg_init(lcfg, LCFG_PRE_CLEANUP, &bufs);
228 l->ld_ops->ldo_process_config(env, l, lcfg);
229 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount,
230 lcfg->lcfg_buflens));
233 if (mgs->mgs_configs_dir) {
234 dt_object_put(env, mgs->mgs_configs_dir);
235 mgs->mgs_configs_dir = NULL;
237 if (mgs->mgs_nidtbl_dir) {
238 dt_object_put(env, mgs->mgs_nidtbl_dir);
239 mgs->mgs_nidtbl_dir = NULL;
241 if (obd2obt(mgs->mgs_obd)->obt_nodemap_config_file != NULL) {
242 struct nm_config_file *ncf;
244 ncf = obd2obt(mgs->mgs_obd)->obt_nodemap_config_file;
245 nm_config_file_deregister_mgs(env, ncf);
246 obd2obt(mgs->mgs_obd)->obt_nodemap_config_file = NULL;
250 local_oid_storage_fini(env, mgs->mgs_los);