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, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #ifndef _MGS_INTERNAL_H
34 #define _MGS_INTERNAL_H
36 #include <libcfs/libcfs.h>
37 #include <lustre_log.h>
38 #include <lustre_export.h>
39 #include <lustre_nodemap.h>
40 #include <dt_object.h>
42 #define MGSSELF_NAME "_mgs"
44 #define MGS_SERVICE_WATCHDOG_FACTOR 2
46 /* -- imperative recovery control data structures -- */
51 struct mgs_nidtbl_target {
52 struct list_head mnt_list;
53 struct mgs_nidtbl *mnt_fs;
55 int mnt_type; /* OST or MDT */
56 struct mgs_target_info mnt_mti;
66 #define IR_STRINGS { "full", "startup", "disabled", "partial" }
73 * maintain fs client nodes of mgs.
76 struct fs_db *mfc_fsdb;
78 * Where the fs client comes from.
80 struct obd_export *mfc_export;
82 * list of fs clients from the same export,
83 * protected by mgs_export_data->med_lock
85 struct list_head mfc_export_list;
87 * list of fs clients in the same fsdb, protected by fsdb->fsdb_mutex
89 struct list_head mfc_fsdb_list;
90 unsigned mfc_ir_capable:1;
94 struct fs_db *mn_fsdb;
95 struct file *mn_version_file;
99 struct list_head mn_targets;
102 struct mgs_tgt_srpc_conf {
103 struct mgs_tgt_srpc_conf *mtsc_next;
105 struct sptlrpc_rule_set mtsc_rset;
108 #define INDEX_MAP_SIZE 8192 /* covers indicies to FFFF */
110 #define FSDB_LOG_EMPTY (0) /* missing client log */
111 #define FSDB_OLDLOG14 (1) /* log starts in old (1.4) style */
112 #define FSDB_REVOKING_LOCK (2) /* DLM lock is being revoked */
113 #define FSDB_MGS_SELF (3) /* for '_mgs', used by sptlrpc */
114 #define FSDB_OSCNAME18 (4) /* old 1.8 style OSC naming */
115 #define FSDB_UDESC (5) /* sptlrpc user desc, will be obsolete */
116 #define FSDB_REVOKING_PARAMS (6) /* DLM lock is being revoked */
120 struct list_head fsdb_list; /* list of databases */
121 struct mutex fsdb_mutex;
123 void *fsdb_ost_index_map; /* bitmap of used indicies */
124 void *fsdb_barrier_map; /* bitmap of barrier */
126 void *fsdb_mdt_index_map; /* bitmap of used indicies */
128 char *fsdb_clilov; /* COMPAT_146 client lov name */
130 unsigned long fsdb_flags;
131 __u32 fsdb_barrier_status;
133 time64_t fsdb_barrier_timeout;
134 __u32 fsdb_barrier_expected;
135 int fsdb_barrier_result;
136 time64_t fsdb_barrier_latest_create_time;
138 /* in-memory copy of the srpc rules, guarded by fsdb_lock */
139 struct sptlrpc_rule_set fsdb_srpc_gen;
140 struct mgs_tgt_srpc_conf *fsdb_srpc_tgt;
142 /* list of fs clients, mgs_fsc. protected by mgs_mutex */
143 struct list_head fsdb_clients;
144 int fsdb_nonir_clients;
147 /* Target NIDs Table */
148 struct mgs_nidtbl fsdb_nidtbl;
150 /* async thread to notify clients */
151 struct mgs_device *fsdb_mgs;
152 wait_queue_head_t fsdb_notify_waitq;
153 struct completion fsdb_notify_comp;
154 ktime_t fsdb_notify_start;
155 atomic_t fsdb_notify_phase;
156 volatile unsigned int fsdb_notify_async:1,
158 fsdb_has_lproc_entry:1,
159 fsdb_barrier_disabled:1;
161 ktime_t fsdb_notify_total;
162 ktime_t fsdb_notify_max;
163 unsigned int fsdb_notify_count;
168 struct dt_device mgs_dt_dev;
169 struct ptlrpc_service *mgs_service;
170 struct dt_device *mgs_bottom;
171 struct obd_export *mgs_bottom_exp;
172 struct dt_object *mgs_configs_dir;
173 struct dt_object *mgs_nidtbl_dir;
174 struct list_head mgs_fs_db_list;
175 spinlock_t mgs_lock; /* covers mgs_fs_db_list */
176 struct proc_dir_entry *mgs_proc_live;
177 struct proc_dir_entry *mgs_proc_osd;
178 struct proc_dir_entry *mgs_proc_fstype;
179 struct proc_dir_entry *mgs_proc_mntdev;
180 time64_t mgs_start_time;
181 struct obd_device *mgs_obd;
182 struct kset *mgs_kset;
183 struct local_oid_storage *mgs_los;
184 struct mutex mgs_mutex;
185 struct mutex mgs_health_mutex;
186 struct rw_semaphore mgs_barrier_rwsem;
187 struct lu_target mgs_lut;
190 /* this is a top object */
192 struct lu_object_header mgo_header;
193 struct dt_object mgo_obj;
198 int mgs_init_fsdb_list(struct mgs_device *mgs);
199 int mgs_cleanup_fsdb_list(struct mgs_device *mgs);
200 int mgs__mgs_fsdb_setup(const struct lu_env *env, struct mgs_device *mgs);
201 int mgs_params_fsdb_setup(const struct lu_env *env, struct mgs_device *mgs);
202 int mgs_params_fsdb_cleanup(const struct lu_env *env, struct mgs_device *mgs);
203 int mgs_find_or_make_fsdb(const struct lu_env *env, struct mgs_device *mgs,
204 char *name, struct fs_db **dbh);
205 struct fs_db *mgs_find_fsdb(struct mgs_device *mgs, const char *fsname);
206 void mgs_put_fsdb(struct mgs_device *mgs, struct fs_db *fsdb);
207 int mgs_get_fsdb_srpc_from_llog(const struct lu_env *env,
208 struct mgs_device *mgs, struct fs_db *fsdb);
209 int mgs_check_index(const struct lu_env *env, struct mgs_device *mgs,
210 struct mgs_target_info *mti);
211 int mgs_write_log_target(const struct lu_env *env, struct mgs_device *mgs,
212 struct mgs_target_info *mti, struct fs_db *fsdb);
213 int mgs_replace_nids(const struct lu_env *env, struct mgs_device *mgs,
214 char *devname, char *nids);
215 int mgs_erase_log(const struct lu_env *env, struct mgs_device *mgs,
217 int mgs_erase_logs(const struct lu_env *env, struct mgs_device *mgs,
219 int mgs_setparam(const struct lu_env *env, struct mgs_device *mgs,
220 struct lustre_cfg *lcfg, char *fsname);
221 int mgs_list_logs(const struct lu_env *env, struct mgs_device *mgs,
222 struct obd_ioctl_data *data);
223 int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
224 enum lcfg_command_type cmd, char *poolname, char *fsname,
226 int mgs_nodemap_cmd(const struct lu_env *env, struct mgs_device *mgs,
227 enum lcfg_command_type cmd, const char *nodemap_name,
231 int mgs_get_lock(struct obd_device *obd, struct ldlm_res_id *res,
232 struct lustre_handle *lockh);
233 int mgs_put_lock(struct lustre_handle *lockh);
234 void mgs_revoke_lock(struct mgs_device *mgs, struct fs_db *fsdb, int type);
237 int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
238 struct mgs_target_info *mti);
239 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
241 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb);
242 void mgs_ir_notify_complete(struct fs_db *fsdb);
243 int mgs_get_ir_logs(struct ptlrpc_request *req);
244 int lprocfs_wr_ir_state(struct file *file, const char __user *buffer,
245 size_t count, void *data);
246 int lprocfs_rd_ir_state(struct seq_file *seq, void *data);
248 lprocfs_ir_timeout_seq_write(struct file *file, const char __user *buffer,
249 size_t count, loff_t *off);
250 int lprocfs_ir_timeout_seq_show(struct seq_file *seq, void *data);
251 void mgs_fsc_cleanup(struct obd_export *exp);
252 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb);
253 int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
257 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
259 int mgs_client_free(struct obd_export *exp);
260 int mgs_fs_setup(const struct lu_env *env, struct mgs_device *m);
261 int mgs_fs_cleanup(const struct lu_env *env, struct mgs_device *m);
264 int mgs_iocontrol_barrier(const struct lu_env *env,
265 struct mgs_device *mgs,
266 struct obd_ioctl_data *data);
268 #ifdef CONFIG_PROC_FS
269 int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name);
270 void lproc_mgs_cleanup(struct mgs_device *mgs);
271 int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb);
272 int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb);
274 static inline int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name)
276 static inline void lproc_mgs_cleanup(struct mgs_device *mgs)
278 static inline int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
280 static inline int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
284 /* mgs/lproc_mgs.c */
286 LPROC_MGS_CONNECT = 0,
287 LPROC_MGS_DISCONNECT,
289 LPROC_MGS_TARGET_REG,
290 LPROC_MGS_TARGET_DEL,
293 void mgs_counter_incr(struct obd_export *exp, int opcode);
294 void mgs_stats_counter_init(struct lprocfs_stats *stats);
297 struct mgs_target_info *comp_tmti;
298 struct mgs_target_info *comp_mti;
299 struct fs_db *comp_fsdb;
300 struct obd_device *comp_obd;
303 struct mgs_thread_info {
304 struct lustre_cfg_bufs mgi_bufs;
305 char mgi_fsname[MTI_NAME_MAXLEN];
306 struct cfg_marker mgi_marker;
307 struct temp_comp mgi_comp;
308 union ldlm_gl_desc mgi_gl_desc;
311 extern struct lu_context_key mgs_thread_key;
313 static inline struct mgs_thread_info *mgs_env_info(const struct lu_env *env)
315 struct mgs_thread_info *info;
318 info = lu_context_key_get(&env->le_ctx, &mgs_thread_key);
320 rc = lu_env_refill((struct lu_env *)env);
323 info = lu_context_key_get(&env->le_ctx, &mgs_thread_key);
325 LASSERT(info != NULL);
329 extern const struct lu_device_operations mgs_lu_ops;
331 static inline int lu_device_is_mgs(struct lu_device *d)
333 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mgs_lu_ops);
336 static inline struct mgs_device* lu2mgs_dev(struct lu_device *d)
338 LASSERT(lu_device_is_mgs(d));
339 return container_of0(d, struct mgs_device, mgs_dt_dev.dd_lu_dev);
342 static inline struct mgs_device *exp2mgs_dev(struct obd_export *exp)
344 return lu2mgs_dev(exp->exp_obd->obd_lu_dev);
347 static inline struct lu_device *mgs2lu_dev(struct mgs_device *d)
349 return (&d->mgs_dt_dev.dd_lu_dev);
352 static inline struct mgs_device *dt2mgs_dev(struct dt_device *d)
354 LASSERT(lu_device_is_mgs(&d->dd_lu_dev));
355 return container_of0(d, struct mgs_device, mgs_dt_dev);
358 static inline struct mgs_object *lu2mgs_obj(struct lu_object *o)
360 LASSERT(ergo(o != NULL, lu_device_is_mgs(o->lo_dev)));
361 return container_of0(o, struct mgs_object, mgo_obj.do_lu);
364 static inline struct lu_object *mgs2lu_obj(struct mgs_object *obj)
366 return &obj->mgo_obj.do_lu;
369 static inline struct mgs_object *mgs_obj(const struct lu_object *o)
371 LASSERT(lu_device_is_mgs(o->lo_dev));
372 return container_of0(o, struct mgs_object, mgo_obj.do_lu);
375 static inline struct mgs_object *dt2mgs_obj(const struct dt_object *d)
377 return mgs_obj(&d->do_lu);
380 static inline struct dt_object* mgs_object_child(struct mgs_object *o)
382 return container_of0(lu_object_next(mgs2lu_obj(o)),
383 struct dt_object, do_lu);
386 struct mgs_direntry {
387 struct list_head mde_list;
392 static inline void mgs_direntry_free(struct mgs_direntry *de)
394 LASSERT(list_empty(&de->mde_list));
396 LASSERT(de->mde_len);
397 OBD_FREE(de->mde_name, de->mde_len);
402 static inline struct mgs_direntry *mgs_direntry_alloc(int len)
404 struct mgs_direntry *de;
410 OBD_ALLOC(de->mde_name, len);
411 if (de->mde_name == NULL) {
417 INIT_LIST_HEAD(&de->mde_list);
423 int class_dentry_readdir(const struct lu_env *env, struct mgs_device *mgs,
424 struct list_head *list);
425 int mgs_lcfg_fork(const struct lu_env *env, struct mgs_device *mgs,
426 const char *oldname, const char *newname);
427 int mgs_lcfg_erase(const struct lu_env *env, struct mgs_device *mgs,
429 int mgs_lcfg_rename(const struct lu_env *env, struct mgs_device *mgs);
431 #endif /* _MGS_INTERNAL_H */