Whamcloud - gitweb
LU-8726 osd-ldiskfs: bypass read for benchmarking
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32
33 #ifndef _MGS_INTERNAL_H
34 #define _MGS_INTERNAL_H
35
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>
41
42 #define MGSSELF_NAME    "_mgs"
43
44 #define MGS_SERVICE_WATCHDOG_FACTOR 2
45
46 /* -- imperative recovery control data structures -- */
47 /**
48  * restarting targets.
49  */
50 struct mgs_nidtbl;
51 struct mgs_nidtbl_target {
52         struct list_head        mnt_list;
53         struct mgs_nidtbl      *mnt_fs;
54         u64                     mnt_version;
55         int                     mnt_type;       /* OST or MDT */
56         cfs_time_t              mnt_last_active;
57         struct mgs_target_info  mnt_mti;
58 };
59
60 enum {
61         IR_FULL = 0,
62         IR_STARTUP,
63         IR_DISABLED,
64         IR_PARTIAL
65 };
66
67 #define IR_STRINGS { "full", "startup", "disabled", "partial" }
68
69 /**
70  */
71 struct fs_db;
72
73 /**
74  * maintain fs client nodes of mgs.
75  */
76 struct mgs_fsc {
77         struct fs_db            *mfc_fsdb;
78         /**
79          * Where the fs client comes from.
80          */
81         struct obd_export       *mfc_export;
82         /**
83          * list of fs clients from the same export,
84          * protected by mgs_export_data->med_lock
85          */
86         struct list_head        mfc_export_list;
87         /**
88          * list of fs clients in the same fsdb, protected by fsdb->fsdb_mutex
89          */
90         struct list_head        mfc_fsdb_list;
91         unsigned                mfc_ir_capable:1;
92 };
93
94 struct mgs_nidtbl {
95         struct fs_db            *mn_fsdb;
96         struct file             *mn_version_file;
97         struct mutex             mn_lock;
98         u64                      mn_version;
99         int                      mn_nr_targets;
100         struct list_head         mn_targets;
101 };
102
103 struct mgs_tgt_srpc_conf {
104         struct mgs_tgt_srpc_conf  *mtsc_next;
105         char                      *mtsc_tgt;
106         struct sptlrpc_rule_set    mtsc_rset;
107 };
108
109 #define INDEX_MAP_SIZE  8192     /* covers indicies to FFFF */
110
111 #define FSDB_LOG_EMPTY          (0)  /* missing client log */
112 #define FSDB_OLDLOG14           (1)  /* log starts in old (1.4) style */
113 #define FSDB_REVOKING_LOCK      (2)  /* DLM lock is being revoked */
114 #define FSDB_MGS_SELF           (3)  /* for '_mgs', used by sptlrpc */
115 #define FSDB_OSCNAME18          (4)  /* old 1.8 style OSC naming */
116 #define FSDB_UDESC              (5)  /* sptlrpc user desc, will be obsolete */
117 #define FSDB_REVOKING_PARAMS    (6)  /* DLM lock is being revoked */
118
119 struct fs_db {
120         char              fsdb_name[20];
121         struct list_head  fsdb_list;            /* list of databases */
122         struct mutex      fsdb_mutex;
123         union {
124                 void     *fsdb_ost_index_map;   /* bitmap of used indicies */
125                 void     *fsdb_barrier_map;     /* bitmap of barrier */
126         };
127         void             *fsdb_mdt_index_map;   /* bitmap of used indicies */
128         atomic_t          fsdb_ref;
129         int               fsdb_mdt_count;
130         char             *fsdb_clilov;  /* COMPAT_146 client lov name */
131         char             *fsdb_clilmv;
132         unsigned long     fsdb_flags;
133         __u32             fsdb_barrier_status;
134         __u32             fsdb_barrier_timeout;
135         time_t            fsdb_barrier_latest_create_time;
136
137         /* in-memory copy of the srpc rules, guarded by fsdb_lock */
138         struct sptlrpc_rule_set   fsdb_srpc_gen;
139         struct mgs_tgt_srpc_conf *fsdb_srpc_tgt;
140
141         /* list of fs clients, mgs_fsc. protected by mgs_mutex */
142         struct list_head     fsdb_clients;
143         int                  fsdb_nonir_clients;
144         int                  fsdb_ir_state;
145
146         /* Target NIDs Table */
147         struct mgs_nidtbl    fsdb_nidtbl;
148
149         /* async thread to notify clients */
150         struct mgs_device    *fsdb_mgs;
151         wait_queue_head_t     fsdb_notify_waitq;
152         struct completion     fsdb_notify_comp;
153         cfs_time_t            fsdb_notify_start;
154         atomic_t              fsdb_notify_phase;
155         volatile unsigned int fsdb_notify_async:1,
156                               fsdb_notify_stop:1,
157                               fsdb_has_lproc_entry:1,
158                               fsdb_barrier_disabled:1;
159         /* statistic data */
160         unsigned int    fsdb_notify_total;
161         unsigned int    fsdb_notify_max;
162         unsigned int    fsdb_notify_count;
163         __u32           fsdb_gen;
164 };
165
166 struct mgs_device {
167         struct dt_device                 mgs_dt_dev;
168         struct ptlrpc_service           *mgs_service;
169         struct dt_device                *mgs_bottom;
170         struct obd_export               *mgs_bottom_exp;
171         struct dt_object                *mgs_configs_dir;
172         struct dt_object                *mgs_nidtbl_dir;
173         struct list_head                 mgs_fs_db_list;
174         spinlock_t                       mgs_lock; /* covers mgs_fs_db_list */
175         struct proc_dir_entry           *mgs_proc_live;
176         struct proc_dir_entry           *mgs_proc_osd;
177         struct proc_dir_entry           *mgs_proc_fstype;
178         struct proc_dir_entry           *mgs_proc_mntdev;
179         cfs_time_t                       mgs_start_time;
180         struct obd_device               *mgs_obd;
181         struct local_oid_storage        *mgs_los;
182         struct mutex                     mgs_mutex;
183         struct mutex                     mgs_health_mutex;
184         struct rw_semaphore              mgs_barrier_rwsem;
185         struct lu_target                 mgs_lut;
186 };
187
188 /* this is a top object */
189 struct mgs_object {
190         struct lu_object_header mgo_header;
191         struct dt_object        mgo_obj;
192         int                     mgo_no_attrs;
193         int                     mgo_reserved;
194 };
195
196 int mgs_init_fsdb_list(struct mgs_device *mgs);
197 int mgs_cleanup_fsdb_list(struct mgs_device *mgs);
198 int mgs__mgs_fsdb_setup(const struct lu_env *env, struct mgs_device *mgs);
199 int mgs_params_fsdb_setup(const struct lu_env *env, struct mgs_device *mgs);
200 int mgs_params_fsdb_cleanup(const struct lu_env *env, struct mgs_device *mgs);
201 int mgs_find_or_make_fsdb(const struct lu_env *env, struct mgs_device *mgs,
202                           char *name, struct fs_db **dbh);
203 struct fs_db *mgs_find_fsdb(struct mgs_device *mgs, const char *fsname);
204 void mgs_put_fsdb(struct mgs_device *mgs, struct fs_db *fsdb);
205 int mgs_get_fsdb_srpc_from_llog(const struct lu_env *env,
206                                 struct mgs_device *mgs, struct fs_db *fsdb);
207 int mgs_check_index(const struct lu_env *env, struct mgs_device *mgs,
208                     struct mgs_target_info *mti);
209 int mgs_write_log_target(const struct lu_env *env, struct mgs_device *mgs,
210                          struct mgs_target_info *mti, struct fs_db *fsdb);
211 int mgs_replace_nids(const struct lu_env *env, struct mgs_device *mgs,
212                      char *devname, char *nids);
213 int mgs_erase_log(const struct lu_env *env, struct mgs_device *mgs,
214                   char *name);
215 int mgs_erase_logs(const struct lu_env *env, struct mgs_device *mgs,
216                    const char *fsname);
217 int mgs_setparam(const struct lu_env *env, struct mgs_device *mgs,
218                  struct lustre_cfg *lcfg, char *fsname);
219 int mgs_list_logs(const struct lu_env *env, struct mgs_device *mgs,
220                   struct obd_ioctl_data *data);
221 int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
222                  enum lcfg_command_type cmd, char *poolname, char *fsname,
223                  char *ostname);
224 int mgs_nodemap_cmd(const struct lu_env *env, struct mgs_device *mgs,
225                     enum lcfg_command_type cmd, const char *nodemap_name,
226                     char *param);
227
228 /* mgs_handler.c */
229 int  mgs_get_lock(struct obd_device *obd, struct ldlm_res_id *res,
230                   struct lustre_handle *lockh);
231 int  mgs_put_lock(struct lustre_handle *lockh);
232 void mgs_revoke_lock(struct mgs_device *mgs, struct fs_db *fsdb, int type);
233
234 /* mgs_nids.c */
235 int  mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
236                    struct mgs_target_info *mti);
237 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
238                    struct fs_db *fsdb);
239 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb);
240 void mgs_ir_notify_complete(struct fs_db *fsdb);
241 int  mgs_get_ir_logs(struct ptlrpc_request *req);
242 int  lprocfs_wr_ir_state(struct file *file, const char __user *buffer,
243                          size_t count, void *data);
244 int  lprocfs_rd_ir_state(struct seq_file *seq, void *data);
245 ssize_t
246 lprocfs_ir_timeout_seq_write(struct file *file, const char __user *buffer,
247                              size_t count, loff_t *off);
248 int  lprocfs_ir_timeout_seq_show(struct seq_file *seq, void *data);
249 void mgs_fsc_cleanup(struct obd_export *exp);
250 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb);
251 int  mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
252                     char *fsname);
253
254 /* mgs_fs.c */
255 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
256                           void *localdata);
257 int mgs_client_free(struct obd_export *exp);
258 int mgs_fs_setup(const struct lu_env *env, struct mgs_device *m);
259 int mgs_fs_cleanup(const struct lu_env *env, struct mgs_device *m);
260
261 #ifdef CONFIG_PROC_FS
262 int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name);
263 void lproc_mgs_cleanup(struct mgs_device *mgs);
264 int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb);
265 int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb);
266 #else
267 static inline int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name)
268 {return 0;}
269 static inline void lproc_mgs_cleanup(struct mgs_device *mgs)
270 {}
271 static inline int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
272 {return 0;}
273 static inline int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
274 {return 0;}
275 #endif
276
277 /* mgs/lproc_mgs.c */
278 enum {
279         LPROC_MGS_CONNECT = 0,
280         LPROC_MGS_DISCONNECT,
281         LPROC_MGS_EXCEPTION,
282         LPROC_MGS_TARGET_REG,
283         LPROC_MGS_TARGET_DEL,
284         LPROC_MGS_LAST
285 };
286 void mgs_counter_incr(struct obd_export *exp, int opcode);
287 void mgs_stats_counter_init(struct lprocfs_stats *stats);
288
289 struct temp_comp {
290         struct mgs_target_info  *comp_tmti;
291         struct mgs_target_info  *comp_mti;
292         struct fs_db            *comp_fsdb;
293         struct obd_device       *comp_obd;
294 };
295
296 struct mgs_thread_info {
297         struct lustre_cfg_bufs  mgi_bufs;
298         char                    mgi_fsname[MTI_NAME_MAXLEN];
299         struct cfg_marker       mgi_marker;
300         struct temp_comp        mgi_comp;
301 };
302
303 extern struct lu_context_key mgs_thread_key;
304
305 static inline struct mgs_thread_info *mgs_env_info(const struct lu_env *env)
306 {
307         struct mgs_thread_info  *info;
308         int                     rc;
309
310         info = lu_context_key_get(&env->le_ctx, &mgs_thread_key);
311         if (info == NULL) {
312                 rc = lu_env_refill((struct lu_env *)env);
313                 if (rc != 0)
314                         return ERR_PTR(rc);
315                 info = lu_context_key_get(&env->le_ctx, &mgs_thread_key);
316         }
317         LASSERT(info != NULL);
318         return info;
319 }
320
321 extern const struct lu_device_operations mgs_lu_ops;
322
323 static inline int lu_device_is_mgs(struct lu_device *d)
324 {
325         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mgs_lu_ops);
326 }
327
328 static inline struct mgs_device* lu2mgs_dev(struct lu_device *d)
329 {
330         LASSERT(lu_device_is_mgs(d));
331         return container_of0(d, struct mgs_device, mgs_dt_dev.dd_lu_dev);
332 }
333
334 static inline struct mgs_device *exp2mgs_dev(struct obd_export *exp)
335 {
336         return lu2mgs_dev(exp->exp_obd->obd_lu_dev);
337 }
338
339 static inline struct lu_device *mgs2lu_dev(struct mgs_device *d)
340 {
341         return (&d->mgs_dt_dev.dd_lu_dev);
342 }
343
344 static inline struct mgs_device *dt2mgs_dev(struct dt_device *d)
345 {
346         LASSERT(lu_device_is_mgs(&d->dd_lu_dev));
347         return container_of0(d, struct mgs_device, mgs_dt_dev);
348 }
349
350 static inline struct mgs_object *lu2mgs_obj(struct lu_object *o)
351 {
352         LASSERT(ergo(o != NULL, lu_device_is_mgs(o->lo_dev)));
353         return container_of0(o, struct mgs_object, mgo_obj.do_lu);
354 }
355
356 static inline struct lu_object *mgs2lu_obj(struct mgs_object *obj)
357 {
358         return &obj->mgo_obj.do_lu;
359 }
360
361 static inline struct mgs_object *mgs_obj(const struct lu_object *o)
362 {
363         LASSERT(lu_device_is_mgs(o->lo_dev));
364         return container_of0(o, struct mgs_object, mgo_obj.do_lu);
365 }
366
367 static inline struct mgs_object *dt2mgs_obj(const struct dt_object *d)
368 {
369         return mgs_obj(&d->do_lu);
370 }
371
372 static inline struct dt_object* mgs_object_child(struct mgs_object *o)
373 {
374         return container_of0(lu_object_next(mgs2lu_obj(o)),
375                              struct dt_object, do_lu);
376 }
377
378 struct mgs_direntry {
379         struct list_head         mde_list;
380         char                    *mde_name;
381         int                      mde_len;
382 };
383
384 static inline void mgs_direntry_free(struct mgs_direntry *de)
385 {
386         LASSERT(list_empty(&de->mde_list));
387         if (de) {
388                 LASSERT(de->mde_len);
389                 OBD_FREE(de->mde_name, de->mde_len);
390                 OBD_FREE_PTR(de);
391         }
392 }
393
394 static inline struct mgs_direntry *mgs_direntry_alloc(int len)
395 {
396         struct mgs_direntry *de;
397
398         OBD_ALLOC_PTR(de);
399         if (de == NULL)
400                 return NULL;
401
402         OBD_ALLOC(de->mde_name, len);
403         if (de->mde_name == NULL) {
404                 OBD_FREE_PTR(de);
405                 return NULL;
406         }
407
408         de->mde_len = len;
409         INIT_LIST_HEAD(&de->mde_list);
410
411         return de;
412 }
413
414 /* mgs_llog.c */
415 int class_dentry_readdir(const struct lu_env *env, struct mgs_device *mgs,
416                          struct list_head *list);
417
418 #endif /* _MGS_INTERNAL_H */