Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[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, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31
32 #ifndef _MGS_INTERNAL_H
33 #define _MGS_INTERNAL_H
34
35 #include <libcfs/libcfs.h>
36 #include <lustre_log.h>
37 #include <lustre_export.h>
38 #include <lustre_nodemap.h>
39 #include <dt_object.h>
40
41 #define MGSSELF_NAME    "_mgs"
42
43 #define MGS_SERVICE_WATCHDOG_FACTOR 2
44
45 /* -- imperative recovery control data structures -- */
46 /**
47  * restarting targets.
48  */
49 struct mgs_nidtbl;
50 struct mgs_nidtbl_target {
51         struct list_head        mnt_list;
52         struct mgs_nidtbl      *mnt_fs;
53         u64                     mnt_version;
54         int                     mnt_type;       /* OST or MDT */
55         struct mgs_target_info  mnt_mti;
56 };
57
58 enum {
59         IR_FULL = 0,
60         IR_STARTUP,
61         IR_DISABLED,
62         IR_PARTIAL
63 };
64
65 #define IR_STRINGS { "full", "startup", "disabled", "partial" }
66
67 /**
68  */
69 struct fs_db;
70
71 /**
72  * maintain fs client nodes of mgs.
73  */
74 struct mgs_fsc {
75         struct fs_db            *mfc_fsdb;
76         /**
77          * Where the fs client comes from.
78          */
79         struct obd_export       *mfc_export;
80         /**
81          * list of fs clients from the same export,
82          * protected by mgs_export_data->med_lock
83          */
84         struct list_head        mfc_export_list;
85         /**
86          * list of fs clients in the same fsdb, protected by fsdb->fsdb_mutex
87          */
88         struct list_head        mfc_fsdb_list;
89         unsigned                mfc_ir_capable:1;
90 };
91
92 struct mgs_nidtbl {
93         struct fs_db            *mn_fsdb;
94         struct file             *mn_version_file;
95         struct mutex             mn_lock;
96         u64                      mn_version;
97         int                      mn_nr_targets;
98         struct list_head         mn_targets;
99 };
100
101 struct mgs_tgt_srpc_conf {
102         struct mgs_tgt_srpc_conf  *mtsc_next;
103         char                      *mtsc_tgt;
104         struct sptlrpc_rule_set    mtsc_rset;
105 };
106
107 #define INDEX_MAP_SIZE  8192     /* covers indicies to FFFF */
108 #define INDEX_MAP_MAX_VALUE     ((INDEX_MAP_SIZE * 8) - 1)
109
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 */
117
118 struct fs_db {
119         char              fsdb_name[20];
120         struct list_head  fsdb_list;            /* list of databases */
121         struct mutex      fsdb_mutex;
122         union {
123                 void     *fsdb_ost_index_map;   /* bitmap of used indicies */
124                 void     *fsdb_barrier_map;     /* bitmap of barrier */
125         };
126         void             *fsdb_mdt_index_map;   /* bitmap of used indicies */
127         atomic_t          fsdb_ref;
128         char             *fsdb_clilov;  /* COMPAT_146 client lov name */
129         char             *fsdb_clilmv;
130         unsigned long     fsdb_flags;
131         __u32             fsdb_barrier_status;
132         int               fsdb_mdt_count;
133         time64_t          fsdb_barrier_timeout;
134         __u32             fsdb_barrier_expected;
135         int               fsdb_barrier_result;
136         time64_t          fsdb_barrier_latest_create_time;
137
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;
141
142         /* list of fs clients, mgs_fsc. protected by mgs_mutex */
143         struct list_head     fsdb_clients;
144         int                  fsdb_nonir_clients;
145         int                  fsdb_ir_state;
146
147         /* Target NIDs Table */
148         struct mgs_nidtbl    fsdb_nidtbl;
149
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,
157                               fsdb_notify_stop:1,
158                               fsdb_has_lproc_entry:1,
159                               fsdb_barrier_disabled:1;
160         /* statistic data */
161         ktime_t         fsdb_notify_total;
162         ktime_t         fsdb_notify_max;
163         unsigned int    fsdb_notify_count;
164         __u32           fsdb_gen;
165 };
166
167 struct mgs_device {
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 attribute                *mgs_fstype;
179         struct attribute                *mgs_mntdev;
180         time64_t                         mgs_start_time;
181         struct obd_device               *mgs_obd;
182         struct local_oid_storage        *mgs_los;
183         struct mutex                     mgs_mutex;
184         struct mutex                     mgs_health_mutex;
185         struct rw_semaphore              mgs_barrier_rwsem;
186         struct lu_target                 mgs_lut;
187 };
188
189 /* this is a top object */
190 struct mgs_object {
191         struct lu_object_header mgo_header;
192         struct dt_object        mgo_obj;
193         int                     mgo_no_attrs;
194         int                     mgo_reserved;
195 };
196
197 int mgs_init_fsdb_list(struct mgs_device *mgs);
198 int mgs_cleanup_fsdb_list(struct mgs_device *mgs);
199 int mgs__mgs_fsdb_setup(const struct lu_env *env, struct mgs_device *mgs);
200 int mgs_params_fsdb_setup(const struct lu_env *env, struct mgs_device *mgs);
201 int mgs_params_fsdb_cleanup(const struct lu_env *env, struct mgs_device *mgs);
202 int mgs_find_or_make_fsdb(const struct lu_env *env, struct mgs_device *mgs,
203                           char *name, struct fs_db **dbh);
204 int mgs_find_or_make_fsdb_nolock(const struct lu_env *env,
205                                   struct mgs_device *mgs, char *name,
206                                   struct fs_db **dbh);
207 struct fs_db *mgs_find_fsdb(struct mgs_device *mgs, const char *fsname);
208 void mgs_put_fsdb(struct mgs_device *mgs, struct fs_db *fsdb);
209 int mgs_get_fsdb_srpc_from_llog(const struct lu_env *env,
210                                 struct mgs_device *mgs, struct fs_db *fsdb);
211 int mgs_check_index(const struct lu_env *env, struct mgs_device *mgs,
212                     struct mgs_target_info *mti);
213 int mgs_write_log_target(const struct lu_env *env, struct mgs_device *mgs,
214                          struct mgs_target_info *mti, struct fs_db *fsdb);
215 int mgs_replace_nids(const struct lu_env *env, struct mgs_device *mgs,
216                      char *devname, char *nids);
217 int mgs_clear_configs(const struct lu_env *env, struct mgs_device *mgs,
218                       const char *devname);
219 int mgs_erase_log(const struct lu_env *env, struct mgs_device *mgs,
220                   char *name);
221 int mgs_erase_logs(const struct lu_env *env, struct mgs_device *mgs,
222                    const char *fsname);
223 int mgs_set_param(const struct lu_env *env, struct mgs_device *mgs,
224                   struct lustre_cfg *lcfg);
225 int mgs_list_logs(const struct lu_env *env, struct mgs_device *mgs,
226                   struct obd_ioctl_data *data);
227 int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
228                  enum lcfg_command_type cmd, char *poolname, char *fsname,
229                  char *ostname);
230
231 /* mgs_handler.c */
232 int  mgs_get_lock(struct obd_device *obd, struct ldlm_res_id *res,
233                   struct lustre_handle *lockh);
234 int  mgs_put_lock(struct lustre_handle *lockh);
235 void mgs_revoke_lock(struct mgs_device *mgs, struct fs_db *fsdb,
236                      enum mgs_cfg_type type);
237
238 /* mgs_nids.c */
239 int  mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
240                    struct mgs_target_info *mti);
241 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
242                    struct fs_db *fsdb);
243 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb);
244 void mgs_ir_notify_complete(struct fs_db *fsdb);
245 int  mgs_get_ir_logs(struct ptlrpc_request *req);
246 int  lprocfs_wr_ir_state(struct file *file, const char __user *buffer,
247                          size_t count, void *data);
248 int  lprocfs_rd_ir_state(struct seq_file *seq, void *data);
249 ssize_t
250 lprocfs_ir_timeout_seq_write(struct file *file, const char __user *buffer,
251                              size_t count, loff_t *off);
252 int  lprocfs_ir_timeout_seq_show(struct seq_file *seq, void *data);
253 void mgs_fsc_cleanup(struct obd_export *exp);
254 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb);
255 int  mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
256                     char *fsname);
257
258 /* mgs_fs.c */
259 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
260                           void *localdata);
261 int mgs_client_free(struct obd_export *exp);
262 int mgs_fs_setup(const struct lu_env *env, struct mgs_device *m);
263 int mgs_fs_cleanup(const struct lu_env *env, struct mgs_device *m);
264
265 /* mgs_barrier.c */
266 int mgs_iocontrol_barrier(const struct lu_env *env,
267                           struct mgs_device *mgs,
268                           struct obd_ioctl_data *data);
269
270 #ifdef CONFIG_PROC_FS
271 int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name);
272 void lproc_mgs_cleanup(struct mgs_device *mgs);
273 int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb);
274 int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb);
275 #else
276 static inline int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name)
277 {return 0;}
278 static inline void lproc_mgs_cleanup(struct mgs_device *mgs)
279 {}
280 static inline int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
281 {return 0;}
282 static inline int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
283 {return 0;}
284 #endif
285
286 /* mgs/lproc_mgs.c */
287 enum {
288         LPROC_MGS_CONNECT = 0,
289         LPROC_MGS_DISCONNECT,
290         LPROC_MGS_EXCEPTION,
291         LPROC_MGS_TARGET_REG,
292         LPROC_MGS_TARGET_DEL,
293         LPROC_MGS_LAST
294 };
295 void mgs_counter_incr(struct obd_export *exp, int opcode);
296 void mgs_stats_counter_init(struct lprocfs_stats *stats);
297
298 struct temp_comp {
299         struct mgs_target_info  *comp_tmti;
300         struct mgs_target_info  *comp_mti;
301         struct fs_db            *comp_fsdb;
302         struct obd_device       *comp_obd;
303 };
304
305 struct mgs_thread_info {
306         struct lustre_cfg_bufs  mgi_bufs;
307         char                    mgi_fsname[MTI_NAME_MAXLEN];
308         struct cfg_marker       mgi_marker;
309         struct temp_comp        mgi_comp;
310         union ldlm_gl_desc      mgi_gl_desc;
311 };
312
313 extern struct lu_context_key mgs_thread_key;
314
315 static inline struct mgs_thread_info *mgs_env_info(const struct lu_env *env)
316 {
317         return lu_env_info(env, &mgs_thread_key);
318 }
319
320 extern const struct lu_device_operations mgs_lu_ops;
321
322 static inline int lu_device_is_mgs(struct lu_device *d)
323 {
324         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mgs_lu_ops);
325 }
326
327 static inline struct mgs_device* lu2mgs_dev(struct lu_device *d)
328 {
329         LASSERT(lu_device_is_mgs(d));
330         return container_of_safe(d, struct mgs_device, mgs_dt_dev.dd_lu_dev);
331 }
332
333 static inline struct mgs_device *exp2mgs_dev(struct obd_export *exp)
334 {
335         return lu2mgs_dev(exp->exp_obd->obd_lu_dev);
336 }
337
338 static inline struct lu_device *mgs2lu_dev(struct mgs_device *d)
339 {
340         return (&d->mgs_dt_dev.dd_lu_dev);
341 }
342
343 static inline struct mgs_device *dt2mgs_dev(struct dt_device *d)
344 {
345         LASSERT(lu_device_is_mgs(&d->dd_lu_dev));
346         return container_of(d, struct mgs_device, mgs_dt_dev);
347 }
348
349 static inline struct mgs_object *lu2mgs_obj(struct lu_object *o)
350 {
351         LASSERT(ergo(o != NULL, lu_device_is_mgs(o->lo_dev)));
352         return container_of_safe(o, struct mgs_object, mgo_obj.do_lu);
353 }
354
355 static inline struct lu_object *mgs2lu_obj(struct mgs_object *obj)
356 {
357         return &obj->mgo_obj.do_lu;
358 }
359
360 static inline struct mgs_object *mgs_obj(const struct lu_object *o)
361 {
362         LASSERT(lu_device_is_mgs(o->lo_dev));
363         return container_of(o, struct mgs_object, mgo_obj.do_lu);
364 }
365
366 static inline struct mgs_object *dt2mgs_obj(const struct dt_object *d)
367 {
368         return mgs_obj(&d->do_lu);
369 }
370
371 static inline struct dt_object* mgs_object_child(struct mgs_object *o)
372 {
373         return container_of(lu_object_next(mgs2lu_obj(o)),
374                             struct dt_object, do_lu);
375 }
376
377 struct mgs_direntry {
378         struct list_head         mde_list;
379         char                    *mde_name;
380         int                      mde_len;
381 };
382
383 static inline void mgs_direntry_free(struct mgs_direntry *de)
384 {
385         LASSERT(list_empty(&de->mde_list));
386         if (de) {
387                 LASSERT(de->mde_len);
388                 OBD_FREE(de->mde_name, de->mde_len);
389                 OBD_FREE_PTR(de);
390         }
391 }
392
393 static inline struct mgs_direntry *mgs_direntry_alloc(int len)
394 {
395         struct mgs_direntry *de;
396
397         OBD_ALLOC_PTR(de);
398         if (de == NULL)
399                 return NULL;
400
401         OBD_ALLOC(de->mde_name, len);
402         if (de->mde_name == NULL) {
403                 OBD_FREE_PTR(de);
404                 return NULL;
405         }
406
407         de->mde_len = len;
408         INIT_LIST_HEAD(&de->mde_list);
409
410         return de;
411 }
412
413 /* mgs_llog.c */
414 int class_dentry_readdir(const struct lu_env *env, struct mgs_device *mgs,
415                          struct list_head *list);
416 int mgs_lcfg_fork(const struct lu_env *env, struct mgs_device *mgs,
417                   const char *oldname, const char *newname);
418 int mgs_lcfg_erase(const struct lu_env *env, struct mgs_device *mgs,
419                    const char *fsname);
420 int mgs_lcfg_rename(const struct lu_env *env, struct mgs_device *mgs);
421
422 #endif /* _MGS_INTERNAL_H */