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.sun.com/software/products/lustre/docs/GPLv2.pdf
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef _MGS_INTERNAL_H
38 #define _MGS_INTERNAL_H
40 #include <libcfs/libcfs.h>
41 #include <lustre_log.h>
42 #include <lustre_export.h>
43 #include <lustre_nodemap.h>
44 #include <dt_object.h>
46 #define MGSSELF_NAME "_mgs"
48 #define MGS_SERVICE_WATCHDOG_FACTOR 2
50 /* -- imperative recovery control data structures -- */
55 struct mgs_nidtbl_target {
56 struct list_head mnt_list;
57 struct mgs_nidtbl *mnt_fs;
59 int mnt_type; /* OST or MDT */
60 cfs_time_t mnt_last_active;
61 struct mgs_target_info mnt_mti;
71 #define IR_STRINGS { "full", "startup", "disabled", "partial" }
78 * maintain fs client nodes of mgs.
81 struct fs_db *mfc_fsdb;
83 * Where the fs client comes from.
85 struct obd_export *mfc_export;
87 * list of fs clients from the same export,
88 * protected by mgs_export_data->med_lock
90 struct list_head mfc_export_list;
92 * list of fs clients in the same fsdb, protected by fsdb->fsdb_mutex
94 struct list_head mfc_fsdb_list;
95 unsigned mfc_ir_capable:1;
99 struct fs_db *mn_fsdb;
100 struct file *mn_version_file;
101 struct mutex mn_lock;
104 struct list_head mn_targets;
107 struct mgs_tgt_srpc_conf {
108 struct mgs_tgt_srpc_conf *mtsc_next;
110 struct sptlrpc_rule_set mtsc_rset;
113 #define INDEX_MAP_SIZE 8192 /* covers indicies to FFFF */
115 #define FSDB_LOG_EMPTY (0) /* missing client log */
116 #define FSDB_OLDLOG14 (1) /* log starts in old (1.4) style */
117 #define FSDB_REVOKING_LOCK (2) /* DLM lock is being revoked */
118 #define FSDB_MGS_SELF (3) /* for '_mgs', used by sptlrpc */
119 #define FSDB_OSCNAME18 (4) /* old 1.8 style OSC naming */
120 #define FSDB_UDESC (5) /* sptlrpc user desc, will be obsolete */
121 #define FSDB_REVOKING_PARAMS (6) /* DLM lock is being revoked */
125 struct list_head fsdb_list; /* list of databases */
126 struct mutex fsdb_mutex;
127 void *fsdb_ost_index_map; /* bitmap of used indicies */
128 void *fsdb_mdt_index_map; /* bitmap of used indicies */
130 char *fsdb_clilov; /* COMPAT_146 client lov name */
132 unsigned long fsdb_flags;
135 /* in-memory copy of the srpc rules, guarded by fsdb_lock */
136 struct sptlrpc_rule_set fsdb_srpc_gen;
137 struct mgs_tgt_srpc_conf *fsdb_srpc_tgt;
139 /* list of fs clients, mgs_fsc. protected by mgs_mutex */
140 struct list_head fsdb_clients;
141 int fsdb_nonir_clients;
144 /* Target NIDs Table */
145 struct mgs_nidtbl fsdb_nidtbl;
147 /* async thread to notify clients */
148 struct mgs_device *fsdb_mgs;
149 wait_queue_head_t fsdb_notify_waitq;
150 struct completion fsdb_notify_comp;
151 cfs_time_t fsdb_notify_start;
152 atomic_t fsdb_notify_phase;
153 volatile unsigned int fsdb_notify_async:1,
156 unsigned int fsdb_notify_total;
157 unsigned int fsdb_notify_max;
158 unsigned int fsdb_notify_count;
162 struct dt_device mgs_dt_dev;
163 struct ptlrpc_service *mgs_service;
164 struct dt_device *mgs_bottom;
165 struct obd_export *mgs_bottom_exp;
166 struct dt_object *mgs_configs_dir;
167 struct dt_object *mgs_nidtbl_dir;
168 struct list_head mgs_fs_db_list;
169 spinlock_t mgs_lock; /* covers mgs_fs_db_list */
170 cfs_proc_dir_entry_t *mgs_proc_live;
171 cfs_proc_dir_entry_t *mgs_proc_osd;
172 cfs_proc_dir_entry_t *mgs_proc_fstype;
173 cfs_proc_dir_entry_t *mgs_proc_mntdev;
174 cfs_time_t mgs_start_time;
175 struct obd_device *mgs_obd;
176 struct local_oid_storage *mgs_los;
177 struct mutex mgs_mutex;
178 struct lu_target mgs_lut;
181 /* this is a top object */
183 struct lu_object_header mgo_header;
184 struct dt_object mgo_obj;
189 int mgs_init_fsdb_list(struct mgs_device *mgs);
190 int mgs_cleanup_fsdb_list(struct mgs_device *mgs);
191 int mgs_params_fsdb_setup(const struct lu_env *env, struct mgs_device *mgs,
193 int mgs_params_fsdb_cleanup(const struct lu_env *env, struct mgs_device *mgs);
194 int mgs_find_or_make_fsdb(const struct lu_env *env, struct mgs_device *mgs,
195 char *name, struct fs_db **dbh);
196 struct fs_db *mgs_find_fsdb(struct mgs_device *mgs, char *fsname);
197 int mgs_get_fsdb_srpc_from_llog(const struct lu_env *env,
198 struct mgs_device *mgs, struct fs_db *fsdb);
199 int mgs_check_index(const struct lu_env *env, struct mgs_device *mgs,
200 struct mgs_target_info *mti);
201 int mgs_check_failnid(const struct lu_env *env, struct mgs_device *mgs,
202 struct mgs_target_info *mti);
203 int mgs_write_log_target(const struct lu_env *env, struct mgs_device *mgs,
204 struct mgs_target_info *mti, struct fs_db *fsdb);
205 int mgs_replace_nids(const struct lu_env *env, struct mgs_device *mgs,
206 char *devname, char *nids);
207 int mgs_erase_log(const struct lu_env *env, struct mgs_device *mgs,
209 int mgs_erase_logs(const struct lu_env *env, struct mgs_device *mgs,
211 int mgs_setparam(const struct lu_env *env, struct mgs_device *mgs,
212 struct lustre_cfg *lcfg, char *fsname);
213 int mgs_list_logs(const struct lu_env *env, struct mgs_device *mgs,
214 struct obd_ioctl_data *data);
215 int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
216 enum lcfg_command_type cmd, char *poolname, char *fsname,
218 int mgs_nodemap_cmd(const struct lu_env *env, struct mgs_device *mgs,
219 enum lcfg_command_type cmd, const char *nodemap_name,
223 int mgs_get_lock(struct obd_device *obd, struct ldlm_res_id *res,
224 struct lustre_handle *lockh);
225 int mgs_put_lock(struct lustre_handle *lockh);
226 void mgs_revoke_lock(struct mgs_device *mgs, struct fs_db *fsdb, int type);
229 int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
230 struct mgs_target_info *mti);
231 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
233 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb);
234 void mgs_ir_notify_complete(struct fs_db *fsdb);
235 int mgs_get_ir_logs(struct ptlrpc_request *req);
236 int lprocfs_wr_ir_state(struct file *file, const char *buffer,
237 size_t count, void *data);
238 int lprocfs_rd_ir_state(struct seq_file *seq, void *data);
240 lprocfs_ir_timeout_seq_write(struct file *file, const char *buffer,
241 size_t count, loff_t *off);
242 int lprocfs_ir_timeout_seq_show(struct seq_file *seq, void *data);
243 void mgs_fsc_cleanup(struct obd_export *exp);
244 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb);
245 int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
249 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
251 int mgs_client_free(struct obd_export *exp);
252 int mgs_fs_setup(const struct lu_env *env, struct mgs_device *m);
253 int mgs_fs_cleanup(const struct lu_env *env, struct mgs_device *m);
256 int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name);
257 void lproc_mgs_cleanup(struct mgs_device *mgs);
258 int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb);
259 int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb);
261 static inline int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name)
263 static inline void lproc_mgs_cleanup(struct mgs_device *mgs)
265 static inline int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
267 static inline int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
271 /* mgs/lproc_mgs.c */
273 LPROC_MGS_CONNECT = 0,
274 LPROC_MGS_DISCONNECT,
276 LPROC_MGS_TARGET_REG,
277 LPROC_MGS_TARGET_DEL,
280 void mgs_counter_incr(struct obd_export *exp, int opcode);
281 void mgs_stats_counter_init(struct lprocfs_stats *stats);
284 struct mgs_target_info *comp_tmti;
285 struct mgs_target_info *comp_mti;
286 struct fs_db *comp_fsdb;
287 struct obd_device *comp_obd;
290 struct mgs_thread_info {
291 struct lustre_cfg_bufs mgi_bufs;
292 char mgi_fsname[MTI_NAME_MAXLEN];
293 struct cfg_marker mgi_marker;
294 struct temp_comp mgi_comp;
297 extern struct lu_context_key mgs_thread_key;
299 static inline struct mgs_thread_info *mgs_env_info(const struct lu_env *env)
301 struct mgs_thread_info *info;
304 info = lu_context_key_get(&env->le_ctx, &mgs_thread_key);
306 rc = lu_env_refill((struct lu_env *)env);
309 info = lu_context_key_get(&env->le_ctx, &mgs_thread_key);
311 LASSERT(info != NULL);
315 extern const struct lu_device_operations mgs_lu_ops;
317 static inline int lu_device_is_mgs(struct lu_device *d)
319 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mgs_lu_ops);
322 static inline struct mgs_device* lu2mgs_dev(struct lu_device *d)
324 LASSERT(lu_device_is_mgs(d));
325 return container_of0(d, struct mgs_device, mgs_dt_dev.dd_lu_dev);
328 static inline struct mgs_device *exp2mgs_dev(struct obd_export *exp)
330 return lu2mgs_dev(exp->exp_obd->obd_lu_dev);
333 static inline struct lu_device *mgs2lu_dev(struct mgs_device *d)
335 return (&d->mgs_dt_dev.dd_lu_dev);
338 static inline struct mgs_device *dt2mgs_dev(struct dt_device *d)
340 LASSERT(lu_device_is_mgs(&d->dd_lu_dev));
341 return container_of0(d, struct mgs_device, mgs_dt_dev);
344 static inline struct mgs_object *lu2mgs_obj(struct lu_object *o)
346 LASSERT(ergo(o != NULL, lu_device_is_mgs(o->lo_dev)));
347 return container_of0(o, struct mgs_object, mgo_obj.do_lu);
350 static inline struct lu_object *mgs2lu_obj(struct mgs_object *obj)
352 return &obj->mgo_obj.do_lu;
355 static inline struct mgs_object *mgs_obj(const struct lu_object *o)
357 LASSERT(lu_device_is_mgs(o->lo_dev));
358 return container_of0(o, struct mgs_object, mgo_obj.do_lu);
361 static inline struct mgs_object *dt2mgs_obj(const struct dt_object *d)
363 return mgs_obj(&d->do_lu);
366 static inline struct dt_object* mgs_object_child(struct mgs_object *o)
368 return container_of0(lu_object_next(mgs2lu_obj(o)),
369 struct dt_object, do_lu);
372 static inline struct dt_object *dt_object_child(struct dt_object *o)
374 return container_of0(lu_object_next(&(o)->do_lu),
375 struct dt_object, do_lu);
377 struct mgs_direntry {
378 struct list_head mde_list;
383 static inline void mgs_direntry_free(struct mgs_direntry *de)
385 LASSERT(list_empty(&de->mde_list));
387 LASSERT(de->mde_len);
388 OBD_FREE(de->mde_name, de->mde_len);
393 static inline struct mgs_direntry *mgs_direntry_alloc(int len)
395 struct mgs_direntry *de;
401 OBD_ALLOC(de->mde_name, len);
402 if (de->mde_name == NULL) {
408 INIT_LIST_HEAD(&de->mde_list);
414 int class_dentry_readdir(const struct lu_env *env, struct mgs_device *mgs,
415 struct list_head *list);
417 #endif /* _MGS_INTERNAL_H */