Whamcloud - gitweb
4eb656f3d880addb6a165cb6c1e5e4c9e5f605b1
[fs/lustre-release.git] / lustre / mgs / mgs_internal.h
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, Whamcloud, Inc.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef _MGS_INTERNAL_H
38 #define _MGS_INTERNAL_H
39
40 #include <libcfs/libcfs.h>
41 #include <lustre_export.h>
42
43 #define MGSSELF_NAME    "_mgs"
44
45 #define MGS_SERVICE_WATCHDOG_FACTOR 2
46
47 /* -- imperative recovery control data structures -- */
48 /**
49  * restarting targets.
50  */
51 struct mgs_nidtbl;
52 struct mgs_nidtbl_target {
53         cfs_list_t              mnt_list;
54         struct mgs_nidtbl      *mnt_fs;
55         u64                     mnt_version;
56         int                     mnt_type; /* OST or MDT */
57         cfs_time_t              mnt_last_active;
58         struct mgs_target_info  mnt_mti;
59 };
60
61 enum {
62         IR_FULL = 0,
63         IR_STARTUP,
64         IR_DISABLED,
65         IR_PARTIAL
66 };
67
68 #define IR_STRINGS { "full", "startup", "disabled", "partial" }
69
70 /**
71  */
72 struct fs_db;
73
74 /**
75  * maintain fs client nodes of mgs.
76  */
77 struct mgs_fsc {
78         struct fs_db      *mfc_fsdb;
79         /**
80          * Where the fs client comes from.
81          */
82         struct obd_export *mfc_export;
83         /**
84          * list of fs clients from the same export,
85          * protected by mgs_export_data->med_lock
86          */
87         cfs_list_t         mfc_export_list;
88         /**
89          * list of fs clients in the same fsdb, protected by fsdb->fsdb_mutex
90          */
91         cfs_list_t        mfc_fsdb_list;
92         unsigned          mfc_ir_capable:1;
93 };
94
95 struct mgs_nidtbl {
96         struct fs_db *mn_fsdb;
97         struct file  *mn_version_file;
98         cfs_mutex_t   mn_lock;
99         u64           mn_version;
100         int           mn_nr_targets;
101         cfs_list_t    mn_targets;
102 };
103
104 struct mgs_tgt_srpc_conf {
105         struct mgs_tgt_srpc_conf  *mtsc_next;
106         char                      *mtsc_tgt;
107         struct sptlrpc_rule_set    mtsc_rset;
108 };
109
110 #define INDEX_MAP_SIZE  8192     /* covers indicies to FFFF */
111
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 */
118
119 struct fs_db {
120         char              fsdb_name[9];
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 */
125         int               fsdb_mdt_count;
126         char             *fsdb_clilov;       /* COMPAT_146 client lov name */
127         char             *fsdb_clilmv;
128         unsigned long     fsdb_flags;
129         __u32             fsdb_gen;
130
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;
134
135         /* list of fs clients, mgs_fsc. protected by mgs_mutex */
136         cfs_list_t           fsdb_clients;
137         int                  fsdb_nonir_clients;
138         int                  fsdb_ir_state;
139
140         /* Target NIDs Table */
141         struct mgs_nidtbl    fsdb_nidtbl;
142
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,
151                              fsdb_notify_stop:1;
152         /* statistic data */
153         unsigned int         fsdb_notify_total;
154         unsigned int         fsdb_notify_max;
155         unsigned int         fsdb_notify_count;
156 };
157
158 /* mgs_llog.c */
159 int class_dentry_readdir(const struct lu_env *env,
160                          struct mgs_device *mgs, cfs_list_t *list);
161
162 struct mgs_device {
163         struct dt_device                 mgs_dt_dev;
164         struct ptlrpc_service           *mgs_service;
165         struct dt_device                *mgs_bottom;
166         struct obd_export               *mgs_bottom_exp;
167         struct dentry                   *mgs_configs_dir;
168         struct dt_object                *mgs_nidtbl_dir;
169         cfs_list_t                       mgs_fs_db_list;
170         cfs_spinlock_t                   mgs_lock; /* covers mgs_fs_db_list */
171         cfs_proc_dir_entry_t            *mgs_proc_live;
172         cfs_time_t                       mgs_start_time;
173         struct obd_device               *mgs_obd;
174         struct local_oid_storage        *mgs_los;
175         struct vfsmount                 *mgs_vfsmnt;
176         struct super_block              *mgs_sb;
177         cfs_mutex_t                      mgs_mutex;
178 };
179
180 /* this is a top object */
181 struct mgs_object {
182         struct lu_object_header mgo_header;
183         struct dt_object        mgo_obj;
184         int                     mgo_no_attrs;
185         int                     mgo_reserved;
186 };
187
188 int mgs_init_fsdb_list(struct mgs_device *mgs);
189 int mgs_cleanup_fsdb_list(struct mgs_device *mgs);
190 int mgs_find_or_make_fsdb(const struct lu_env *env, struct mgs_device *mgs, char *name,
191                           struct fs_db **dbh);
192 struct fs_db *mgs_find_fsdb(struct mgs_device *mgs, char *fsname);
193 int mgs_get_fsdb_srpc_from_llog(const struct lu_env *env, struct mgs_device *mgs, struct fs_db *fsdb);
194 int mgs_check_index(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti);
195 int mgs_check_failnid(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti);
196 int mgs_write_log_target(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti,
197                          struct fs_db *fsdb);
198 int mgs_upgrade_sv_14(const struct lu_env *env, struct mgs_device *mgs,
199                       struct mgs_target_info *mti, struct fs_db *fsdb);
200 int mgs_erase_log(const struct lu_env *env, struct mgs_device *mgs,
201                   char *name);
202 int mgs_erase_logs(const struct lu_env *env, struct mgs_device *mgs,
203                    char *fsname);
204 int mgs_setparam(const struct lu_env *env, struct mgs_device *mgs,
205                  struct lustre_cfg *lcfg, char *fsname);
206 int mgs_list_logs(const struct lu_env *env, struct mgs_device *mgs,
207                   struct obd_ioctl_data *data);
208 int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
209                  enum lcfg_command_type cmd, char *poolname, char *fsname,
210                  char *ostname);
211
212 /* mgs_handler.c */
213 int  mgs_get_lock(struct obd_device *obd, struct ldlm_res_id *res,
214                   struct lustre_handle *lockh);
215 int  mgs_put_lock(struct lustre_handle *lockh);
216 void mgs_revoke_lock(struct mgs_device *mgs, struct fs_db *fsdb, int type);
217
218 /* mgs_nids.c */
219 int  mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
220                    struct mgs_target_info *mti);
221 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
222                    struct fs_db *fsdb);
223 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb);
224 void mgs_ir_notify_complete(struct fs_db *fsdb);
225 int  mgs_get_ir_logs(struct ptlrpc_request *req);
226 int  lprocfs_wr_ir_state(struct file *file, const char *buffer,
227                            unsigned long count, void *data);
228 int  lprocfs_rd_ir_state(struct seq_file *seq, void *data);
229 int  lprocfs_wr_ir_timeout(struct file *file, const char *buffer,
230                            unsigned long count, void *data);
231 int  lprocfs_rd_ir_timeout(char *page, char **start, off_t off, int count,
232                            int *eof, void *data);
233 void mgs_fsc_cleanup(struct obd_export *exp);
234 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb);
235 int  mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
236                     char *fsname);
237
238 /* mgs_fs.c */
239 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
240                           void *localdata);
241 int mgs_client_free(struct obd_export *exp);
242 int mgs_fs_setup(const struct lu_env *env, struct mgs_device *m);
243 int mgs_fs_cleanup(const struct lu_env *env, struct mgs_device *m);
244
245 #define strsuf(buf, suffix) (strcmp((buf)+strlen(buf)-strlen(suffix), (suffix)))
246 #ifdef LPROCFS
247 int lproc_mgs_setup(struct mgs_device *mgs);
248 int lproc_mgs_cleanup(struct mgs_device *mgs);
249 int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb);
250 int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb);
251 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars);
252 #else
253 static inline int lproc_mgs_setup(struct obd_device *dev)
254 {return 0;}
255 static inline int lproc_mgs_cleanup(struct obd_device *obd)
256 {return 0;}
257 static inline int lproc_mgs_add_live(struct mgs_device *obd, struct fs_db *fsdb)
258 {return 0;}
259 static inline int lproc_mgs_del_live(struct mgs_device *obd, struct fs_db *fsdb)
260 {return 0;}
261 static void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
262 {
263         memset(lvars, 0, sizeof(*lvars));
264 }
265 #endif
266
267 /* mgs/lproc_mgs.c */
268 enum {
269         LPROC_MGS_CONNECT = 0,
270         LPROC_MGS_DISCONNECT,
271         LPROC_MGS_EXCEPTION,
272         LPROC_MGS_TARGET_REG,
273         LPROC_MGS_TARGET_DEL,
274         LPROC_MGS_LAST
275 };
276 void mgs_counter_incr(struct obd_export *exp, int opcode);
277 void mgs_stats_counter_init(struct lprocfs_stats *stats);
278
279 struct temp_comp
280 {
281         struct mgs_target_info  *comp_tmti;
282         struct mgs_target_info  *comp_mti;
283         struct fs_db            *comp_fsdb;
284         struct mgs_device       *comp_mgs;
285         const struct lu_env     *comp_env;
286 };
287
288 struct mgs_thread_info {
289         struct lustre_cfg_bufs  mgi_bufs;
290         char                    mgi_fsname[MTI_NAME_MAXLEN];
291         struct cfg_marker       mgi_marker;
292         struct temp_comp        mgi_comp;
293 };
294
295 extern struct lu_context_key mgs_thread_key;
296
297 static inline struct mgs_thread_info *mgs_env_info(const struct lu_env *env)
298 {
299         struct mgs_thread_info *info;
300
301         info = lu_context_key_get(&env->le_ctx, &mgs_thread_key);
302         LASSERT(info != NULL);
303         return info;
304 }
305
306 extern const struct lu_device_operations mgs_lu_ops;
307
308 static inline int lu_device_is_mgs(struct lu_device *d)
309 {
310         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mgs_lu_ops);
311 }
312
313 static inline struct mgs_device* lu2mgs_dev(struct lu_device *d)
314 {
315         LASSERT(lu_device_is_mgs(d));
316         return container_of0(d, struct mgs_device, mgs_dt_dev.dd_lu_dev);
317 }
318
319 static inline struct mgs_device *exp2mgs_dev(struct obd_export *exp)
320 {
321         return lu2mgs_dev(exp->exp_obd->obd_lu_dev);
322 }
323
324 static inline struct lu_device *mgs2lu_dev(struct mgs_device *d)
325 {
326         return (&d->mgs_dt_dev.dd_lu_dev);
327 }
328
329 static inline struct mgs_device *dt2mgs_dev(struct dt_device *d)
330 {
331         LASSERT(lu_device_is_mgs(&d->dd_lu_dev));
332         return container_of0(d, struct mgs_device, mgs_dt_dev);
333 }
334
335 static inline struct mgs_object *lu2mgs_obj(struct lu_object *o)
336 {
337         LASSERT(ergo(o != NULL, lu_device_is_mgs(o->lo_dev)));
338         return container_of0(o, struct mgs_object, mgo_obj.do_lu);
339 }
340
341 static inline struct lu_object *mgs2lu_obj(struct mgs_object *obj)
342 {
343         return &obj->mgo_obj.do_lu;
344 }
345
346 static inline struct mgs_object *mgs_obj(const struct lu_object *o)
347 {
348         LASSERT(lu_device_is_mgs(o->lo_dev));
349         return container_of0(o, struct mgs_object, mgo_obj.do_lu);
350 }
351
352 static inline struct mgs_object *dt2mgs_obj(const struct dt_object *d)
353 {
354         return mgs_obj(&d->do_lu);
355 }
356
357 static inline struct dt_object* mgs_object_child(struct mgs_object *o)
358 {
359         return container_of0(lu_object_next(mgs2lu_obj(o)),
360                              struct dt_object, do_lu);
361 }
362
363 static inline struct dt_object *dt_object_child(struct dt_object *o)
364 {
365         return container_of0(lu_object_next(&(o)->do_lu),
366                              struct dt_object, do_lu);
367 }
368
369 #endif /* _MGS_INTERNAL_H */