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