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, Whamcloud, Inc.
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_export.h>
43 #define MGSSELF_NAME "_mgs"
45 #define MGS_SERVICE_WATCHDOG_FACTOR 2
47 /* -- imperative recovery control data structures -- */
52 struct mgs_nidtbl_target {
54 struct mgs_nidtbl *mnt_fs;
56 int mnt_type; /* OST or MDT */
57 cfs_time_t mnt_last_active;
58 struct mgs_target_info mnt_mti;
68 #define IR_STRINGS { "full", "startup", "disabled", "partial" }
75 * maintain fs client nodes of mgs.
78 struct fs_db *mfc_fsdb;
80 * Where the fs client comes from.
82 struct obd_export *mfc_export;
84 * list of fs clients from the same export,
85 * protected by mgs_export_data->med_lock
87 cfs_list_t mfc_export_list;
89 * list of fs clients in the same fsdb, protected by fsdb->fsdb_mutex
91 cfs_list_t mfc_fsdb_list;
92 unsigned mfc_ir_capable:1;
96 struct fs_db *mn_fsdb;
97 struct file *mn_version_file;
101 cfs_list_t mn_targets;
104 struct mgs_tgt_srpc_conf {
105 struct mgs_tgt_srpc_conf *mtsc_next;
107 struct sptlrpc_rule_set mtsc_rset;
110 #define INDEX_MAP_SIZE 8192 /* covers indicies to FFFF */
112 #define FSDB_LOG_EMPTY (0) /* missing client log */
113 #define FSDB_OLDLOG14 (1) /* log starts in old (1.4) style */
114 #define FSDB_REVOKING_LOCK (2) /* DLM lock is being revoked */
115 #define FSDB_MGS_SELF (3) /* for '_mgs', used by sptlrpc */
116 #define FSDB_OSCNAME18 (4) /* old 1.8 style OSC naming */
117 #define FSDB_UDESC (5) /* sptlrpc user desc, will be obsolete */
121 cfs_list_t fsdb_list; /* list of databases */
122 cfs_mutex_t fsdb_mutex;
123 void *fsdb_ost_index_map; /* bitmap of used indicies */
124 void *fsdb_mdt_index_map; /* bitmap of used indicies */
126 char *fsdb_clilov; /* COMPAT_146 client lov name */
128 unsigned long fsdb_flags;
131 /* in-memory copy of the srpc rules, guarded by fsdb_lock */
132 struct sptlrpc_rule_set fsdb_srpc_gen;
133 struct mgs_tgt_srpc_conf *fsdb_srpc_tgt;
135 /* list of fs clients, mgs_fsc. protected by mgs_mutex */
136 cfs_list_t fsdb_clients;
137 int fsdb_nonir_clients;
140 /* Target NIDs Table */
141 struct mgs_nidtbl fsdb_nidtbl;
143 /* async thread to notify clients */
144 struct obd_device *fsdb_obd;
145 struct mgs_device *fsdb_mgs;
146 cfs_waitq_t fsdb_notify_waitq;
147 cfs_completion_t fsdb_notify_comp;
148 cfs_time_t fsdb_notify_start;
149 cfs_atomic_t fsdb_notify_phase;
150 volatile int fsdb_notify_async:1,
153 unsigned int fsdb_notify_total;
154 unsigned int fsdb_notify_max;
155 unsigned int fsdb_notify_count;
159 int class_dentry_readdir(const struct lu_env *env,
160 struct mgs_device *mgs, cfs_list_t *list);
162 int mgs_init_fsdb_list(struct mgs_device *mgs);
163 int mgs_cleanup_fsdb_list(struct mgs_device *mgs);
164 int mgs_find_or_make_fsdb(const struct lu_env *env, struct mgs_device *mgs, char *name,
166 struct fs_db *mgs_find_fsdb(struct mgs_device *mgs, char *fsname);
167 int mgs_get_fsdb_srpc_from_llog(const struct lu_env *env, struct mgs_device *mgs, struct fs_db *fsdb);
168 int mgs_check_index(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti);
169 int mgs_check_failnid(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti);
170 int mgs_write_log_target(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti,
172 int mgs_upgrade_sv_14(const struct lu_env *env, struct mgs_device *mgs,
173 struct mgs_target_info *mti, struct fs_db *fsdb);
174 int mgs_erase_log(const struct lu_env *env, struct mgs_device *mgs,
176 int mgs_erase_logs(const struct lu_env *env, struct mgs_device *mgs,
178 int mgs_setparam(const struct lu_env *env, struct mgs_device *mgs,
179 struct lustre_cfg *lcfg, char *fsname);
180 int mgs_list_logs(const struct lu_env *env, struct mgs_device *mgs,
181 struct obd_ioctl_data *data);
182 int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
183 enum lcfg_command_type cmd, char *poolname, char *fsname,
187 int mgs_get_lock(struct obd_device *obd, struct ldlm_res_id *res,
188 struct lustre_handle *lockh);
189 int mgs_put_lock(struct lustre_handle *lockh);
190 void mgs_revoke_lock(struct mgs_device *mgs, struct fs_db *fsdb, int type);
193 int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
194 struct mgs_target_info *mti);
195 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
197 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb);
198 void mgs_ir_notify_complete(struct fs_db *fsdb);
199 int mgs_get_ir_logs(struct ptlrpc_request *req);
200 int lprocfs_wr_ir_state(struct file *file, const char *buffer,
201 unsigned long count, void *data);
202 int lprocfs_rd_ir_state(struct seq_file *seq, void *data);
203 int lprocfs_wr_ir_timeout(struct file *file, const char *buffer,
204 unsigned long count, void *data);
205 int lprocfs_rd_ir_timeout(char *page, char **start, off_t off, int count,
206 int *eof, void *data);
207 void mgs_fsc_cleanup(struct obd_export *exp);
208 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb);
209 int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
213 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
215 int mgs_client_free(struct obd_export *exp);
216 int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt);
217 int mgs_fs_cleanup(struct obd_device *obddev);
219 #define strsuf(buf, suffix) (strcmp((buf)+strlen(buf)-strlen(suffix), (suffix)))
221 int lproc_mgs_setup(struct mgs_device *mgs);
222 int lproc_mgs_cleanup(struct mgs_device *mgs);
223 int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb);
224 int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb);
225 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars);
227 static inline int lproc_mgs_setup(struct obd_device *dev)
229 static inline int lproc_mgs_cleanup(struct obd_device *obd)
231 static inline int lproc_mgs_add_live(struct mgs_device *obd, struct fs_db *fsdb)
233 static inline int lproc_mgs_del_live(struct mgs_device *obd, struct fs_db *fsdb)
235 static void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
237 memset(lvars, 0, sizeof(*lvars));
241 /* mgs/lproc_mgs.c */
243 LPROC_MGS_CONNECT = 0,
244 LPROC_MGS_DISCONNECT,
246 LPROC_MGS_TARGET_REG,
247 LPROC_MGS_TARGET_DEL,
250 void mgs_counter_incr(struct obd_export *exp, int opcode);
251 void mgs_stats_counter_init(struct lprocfs_stats *stats);
255 struct mgs_target_info *comp_tmti;
256 struct mgs_target_info *comp_mti;
257 struct fs_db *comp_fsdb;
258 struct mgs_device *comp_mgs;
259 const struct lu_env *comp_env;
262 struct mgs_thread_info {
263 struct lustre_cfg_bufs mgi_bufs;
264 char mgi_fsname[MTI_NAME_MAXLEN];
265 struct cfg_marker mgi_marker;
266 struct temp_comp mgi_comp;
269 extern struct lu_context_key mgs_thread_key;
271 static inline struct mgs_thread_info *mgs_env_info(const struct lu_env *env)
273 struct mgs_thread_info *info;
275 info = lu_context_key_get(&env->le_ctx, &mgs_thread_key);
276 LASSERT(info != NULL);
280 static inline struct mgs_device *exp2mgs_dev(struct obd_export *exp)
282 return &exp->exp_obd->u.mgs;
285 #endif /* _MGS_INTERNAL_H */