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