Whamcloud - gitweb
LU-1301 mgs: introduce mgs_thread_info
[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 #ifdef __KERNEL__
41 # include <linux/fs.h>
42 #endif
43 #include <libcfs/libcfs.h>
44 #include <lustre/lustre_idl.h>
45 #include <lustre_lib.h>
46 #include <lustre_dlm.h>
47 #include <lustre_log.h>
48 #include <lustre_export.h>
49
50 #define MGSSELF_NAME    "_mgs"
51
52 #define MGS_SERVICE_WATCHDOG_FACTOR 2
53
54 /* -- imperative recovery control data structures -- */
55 /**
56  * restarting targets.
57  */
58 struct mgs_nidtbl;
59 struct mgs_nidtbl_target {
60         cfs_list_t              mnt_list;
61         struct mgs_nidtbl      *mnt_fs;
62         u64                     mnt_version;
63         int                     mnt_type; /* OST or MDT */
64         cfs_time_t              mnt_last_active;
65         struct mgs_target_info  mnt_mti;
66 };
67
68 enum {
69         IR_FULL = 0,
70         IR_STARTUP,
71         IR_DISABLED,
72         IR_PARTIAL
73 };
74
75 #define IR_STRINGS { "full", "startup", "disabled", "partial" }
76
77 /**
78  */
79 struct fs_db;
80
81 /**
82  * maintain fs client nodes of mgs.
83  */
84 struct mgs_fsc {
85         struct fs_db      *mfc_fsdb;
86         /**
87          * Where the fs client comes from.
88          */
89         struct obd_export *mfc_export;
90         /**
91          * list of fs clients from the same export,
92          * protected by mgs_export_data->med_lock
93          */
94         cfs_list_t         mfc_export_list;
95         /**
96          * list of fs clients in the same fsdb, protected by fsdb->fsdb_mutex
97          */
98         cfs_list_t        mfc_fsdb_list;
99         unsigned          mfc_ir_capable:1;
100 };
101
102 struct mgs_nidtbl {
103         struct fs_db *mn_fsdb;
104         struct file  *mn_version_file;
105         cfs_mutex_t   mn_lock;
106         u64           mn_version;
107         int           mn_nr_targets;
108         cfs_list_t    mn_targets;
109 };
110
111 struct mgs_tgt_srpc_conf {
112         struct mgs_tgt_srpc_conf  *mtsc_next;
113         char                      *mtsc_tgt;
114         struct sptlrpc_rule_set    mtsc_rset;
115 };
116
117 #define INDEX_MAP_SIZE  8192     /* covers indicies to FFFF */
118
119 #define FSDB_LOG_EMPTY          (0)  /* missing client log */
120 #define FSDB_OLDLOG14           (1)  /* log starts in old (1.4) style */
121 #define FSDB_REVOKING_LOCK      (2)  /* DLM lock is being revoked */
122 #define FSDB_MGS_SELF           (3)  /* for '_mgs', used by sptlrpc */
123 #define FSDB_OSCNAME18          (4)  /* old 1.8 style OSC naming */
124 #define FSDB_UDESC              (5)  /* sptlrpc user desc, will be obsolete */
125
126 struct fs_db {
127         char              fsdb_name[9];
128         cfs_list_t        fsdb_list;           /* list of databases */
129         cfs_mutex_t       fsdb_mutex;
130         void             *fsdb_ost_index_map;  /* bitmap of used indicies */
131         void             *fsdb_mdt_index_map;  /* bitmap of used indicies */
132         int               fsdb_mdt_count;
133         /* COMPAT_146 these items must be recorded out of the old client log */
134         char             *fsdb_clilov;       /* COMPAT_146 client lov name */
135         char             *fsdb_clilmv;
136         char             *fsdb_mdtlov;       /* COMPAT_146 mds lov name */
137         char             *fsdb_mdtlmv;
138         char             *fsdb_mdc;          /* COMPAT_146 mdc name */
139         /* end COMPAT_146 */
140         unsigned long     fsdb_flags;
141         __u32             fsdb_gen;
142
143         /* in-memory copy of the srpc rules, guarded by fsdb_lock */
144         struct sptlrpc_rule_set   fsdb_srpc_gen;
145         struct mgs_tgt_srpc_conf *fsdb_srpc_tgt;
146
147         /* list of fs clients, mgs_fsc. protected by mgs_mutex */
148         cfs_list_t           fsdb_clients;
149         int                  fsdb_nonir_clients;
150         int                  fsdb_ir_state;
151
152         /* Target NIDs Table */
153         struct mgs_nidtbl    fsdb_nidtbl;
154
155         /* async thread to notify clients */
156         struct obd_device   *fsdb_obd;
157         struct mgs_device   *fsdb_mgs;
158         cfs_waitq_t          fsdb_notify_waitq;
159         cfs_completion_t     fsdb_notify_comp;
160         cfs_time_t           fsdb_notify_start;
161         cfs_atomic_t         fsdb_notify_phase;
162         volatile int         fsdb_notify_async:1,
163                              fsdb_notify_stop:1;
164         /* statistic data */
165         unsigned int         fsdb_notify_total;
166         unsigned int         fsdb_notify_max;
167         unsigned int         fsdb_notify_count;
168 };
169
170 /* mgs_llog.c */
171 int class_dentry_readdir(const struct lu_env *env,
172                          struct mgs_device *mgs, cfs_list_t *list);
173
174 int mgs_init_fsdb_list(struct mgs_device *mgs);
175 int mgs_cleanup_fsdb_list(struct mgs_device *mgs);
176 int mgs_find_or_make_fsdb(const struct lu_env *env, struct mgs_device *mgs, char *name,
177                           struct fs_db **dbh);
178 struct fs_db *mgs_find_fsdb(struct mgs_device *mgs, char *fsname);
179 int mgs_get_fsdb_srpc_from_llog(const struct lu_env *env, struct mgs_device *mgs, struct fs_db *fsdb);
180 int mgs_check_index(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti);
181 int mgs_check_failnid(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti);
182 int mgs_write_log_target(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti,
183                          struct fs_db *fsdb);
184 int mgs_upgrade_sv_14(const struct lu_env *env, struct mgs_device *mgs,
185                       struct mgs_target_info *mti, struct fs_db *fsdb);
186 int mgs_erase_log(const struct lu_env *env, struct mgs_device *mgs,
187                   char *name);
188 int mgs_erase_logs(const struct lu_env *env, struct mgs_device *mgs,
189                    char *fsname);
190 int mgs_setparam(const struct lu_env *env, struct mgs_device *mgs,
191                  struct lustre_cfg *lcfg, char *fsname);
192 int mgs_list_logs(const struct lu_env *env, struct mgs_device *mgs,
193                   struct obd_ioctl_data *data);
194 int mgs_pool_cmd(const struct lu_env *env, struct mgs_device *mgs,
195                  enum lcfg_command_type cmd, char *poolname, char *fsname,
196                  char *ostname);
197
198 /* mgs_handler.c */
199 int  mgs_get_lock(struct obd_device *obd, struct ldlm_res_id *res,
200                   struct lustre_handle *lockh);
201 int  mgs_put_lock(struct lustre_handle *lockh);
202 void mgs_revoke_lock(struct mgs_device *mgs, struct fs_db *fsdb, int type);
203
204 /* mgs_nids.c */
205 int  mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
206                    struct mgs_target_info *mti);
207 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
208                    struct fs_db *fsdb);
209 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb);
210 void mgs_ir_notify_complete(struct fs_db *fsdb);
211 int  mgs_get_ir_logs(struct ptlrpc_request *req);
212 int  lprocfs_wr_ir_state(struct file *file, const char *buffer,
213                            unsigned long count, void *data);
214 int  lprocfs_rd_ir_state(struct seq_file *seq, void *data);
215 int  lprocfs_wr_ir_timeout(struct file *file, const char *buffer,
216                            unsigned long count, void *data);
217 int  lprocfs_rd_ir_timeout(char *page, char **start, off_t off, int count,
218                            int *eof, void *data);
219 void mgs_fsc_cleanup(struct obd_export *exp);
220 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb);
221 int  mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
222                     char *fsname);
223
224 /* mgs_fs.c */
225 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
226                           void *localdata);
227 int mgs_client_free(struct obd_export *exp);
228 int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt);
229 int mgs_fs_cleanup(struct obd_device *obddev);
230
231 #define strsuf(buf, suffix) (strcmp((buf)+strlen(buf)-strlen(suffix), (suffix)))
232 #ifdef LPROCFS
233 int lproc_mgs_setup(struct mgs_device *mgs);
234 int lproc_mgs_cleanup(struct mgs_device *mgs);
235 int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb);
236 int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb);
237 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars);
238 #else
239 static inline int lproc_mgs_setup(struct obd_device *dev)
240 {return 0;}
241 static inline int lproc_mgs_cleanup(struct obd_device *obd)
242 {return 0;}
243 static inline int lproc_mgs_add_live(struct mgs_device *obd, struct fs_db *fsdb)
244 {return 0;}
245 static inline int lproc_mgs_del_live(struct mgs_device *obd, struct fs_db *fsdb)
246 {return 0;}
247 static void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
248 {
249         memset(lvars, 0, sizeof(*lvars));
250 }
251 #endif
252
253 /* mgs/lproc_mgs.c */
254 enum {
255         LPROC_MGS_CONNECT = 0,
256         LPROC_MGS_DISCONNECT,
257         LPROC_MGS_EXCEPTION,
258         LPROC_MGS_TARGET_REG,
259         LPROC_MGS_TARGET_DEL,
260         LPROC_MGS_LAST
261 };
262 void mgs_counter_incr(struct obd_export *exp, int opcode);
263 void mgs_stats_counter_init(struct lprocfs_stats *stats);
264
265 struct temp_comp
266 {
267         struct mgs_target_info  *comp_tmti;
268         struct mgs_target_info  *comp_mti;
269         struct fs_db            *comp_fsdb;
270         struct mgs_device       *comp_mgs;
271         const struct lu_env     *comp_env;
272 };
273
274 struct mgs_thread_info {
275         struct lustre_cfg_bufs  mgi_bufs;
276         char                    mgi_fsname[MTI_NAME_MAXLEN];
277         struct cfg_marker       mgi_marker;
278         struct temp_comp        mgi_comp;
279 };
280
281 extern struct lu_context_key mgs_thread_key;
282
283 static inline struct mgs_thread_info *mgs_env_info(const struct lu_env *env)
284 {
285         struct mgs_thread_info *info;
286
287         info = lu_context_key_get(&env->le_ctx, &mgs_thread_key);
288         LASSERT(info != NULL);
289         return info;
290 }
291
292 static inline struct mgs_device *exp2mgs_dev(struct obd_export *exp)
293 {
294         return &exp->exp_obd->u.mgs;
295 }
296
297 #endif /* _MGS_INTERNAL_H */