Whamcloud - gitweb
ORNL-10: Basic IR implementation
[fs/lustre-release.git] / lustre / mgs / mgs_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
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 struct mgs_nidtbl {
80         struct fs_db *mn_fsdb;
81         struct file  *mn_version_file;
82         cfs_mutex_t   mn_lock;
83         u64           mn_version;
84         int           mn_nr_targets;
85         cfs_list_t    mn_targets;
86 };
87
88 struct mgs_tgt_srpc_conf {
89         struct mgs_tgt_srpc_conf  *mtsc_next;
90         char                      *mtsc_tgt;
91         struct sptlrpc_rule_set    mtsc_rset;
92 };
93
94 #define INDEX_MAP_SIZE  8192     /* covers indicies to FFFF */
95
96 #define FSDB_LOG_EMPTY          (0)  /* missing client log */
97 #define FSDB_OLDLOG14           (1)  /* log starts in old (1.4) style */
98 #define FSDB_REVOKING_LOCK      (2)  /* DLM lock is being revoked */
99 #define FSDB_MGS_SELF           (3)  /* for '_mgs', used by sptlrpc */
100 #define FSDB_OSCNAME18          (4)  /* old 1.8 style OSC naming */
101 #define FSDB_UDESC              (5)  /* sptlrpc user desc, will be obsolete */
102
103 struct fs_db {
104         char              fsdb_name[9];
105         cfs_list_t        fsdb_list;           /* list of databases */
106         cfs_semaphore_t   fsdb_sem;
107         void             *fsdb_ost_index_map;  /* bitmap of used indicies */
108         void             *fsdb_mdt_index_map;  /* bitmap of used indicies */
109         int               fsdb_mdt_count;
110         /* COMPAT_146 these items must be recorded out of the old client log */
111         char             *fsdb_clilov;       /* COMPAT_146 client lov name */
112         char             *fsdb_clilmv;
113         char             *fsdb_mdtlov;       /* COMPAT_146 mds lov name */
114         char             *fsdb_mdtlmv;
115         char             *fsdb_mdc;          /* COMPAT_146 mdc name */
116         /* end COMPAT_146 */
117         unsigned long     fsdb_flags;
118         __u32             fsdb_gen;
119
120         /* in-memory copy of the srpc rules, guarded by fsdb_lock */
121         struct sptlrpc_rule_set   fsdb_srpc_gen;
122         struct mgs_tgt_srpc_conf *fsdb_srpc_tgt;
123
124         int                  fsdb_ir_state;
125
126         /* Target NIDs Table */
127         struct mgs_nidtbl    fsdb_nidtbl;
128
129         /* async thread to notify clients */
130         struct obd_device   *fsdb_obd;
131         cfs_waitq_t          fsdb_notify_waitq;
132         cfs_completion_t     fsdb_notify_comp;
133         cfs_atomic_t         fsdb_notify_phase;
134         volatile int         fsdb_notify_async:1,
135                              fsdb_notify_stop:1;
136         /* statistic data */
137         unsigned int         fsdb_notify_total;
138         unsigned int         fsdb_notify_max;
139         unsigned int         fsdb_notify_count;
140 };
141
142 /* mgs_llog.c */
143 int class_dentry_readdir(struct obd_device *obd, struct dentry *dir,
144                          struct vfsmount *inmnt,
145                          cfs_list_t *dentry_list);
146
147 int mgs_init_fsdb_list(struct obd_device *obd);
148 int mgs_cleanup_fsdb_list(struct obd_device *obd);
149 int mgs_find_or_make_fsdb(struct obd_device *obd, char *name,
150                           struct fs_db **dbh);
151 struct fs_db *mgs_find_fsdb(struct obd_device *obd, char *fsname);
152 int mgs_get_fsdb_srpc_from_llog(struct obd_device *obd, struct fs_db *fsdb);
153 int mgs_check_index(struct obd_device *obd, struct mgs_target_info *mti);
154 int mgs_check_failnid(struct obd_device *obd, struct mgs_target_info *mti);
155 int mgs_write_log_target(struct obd_device *obd, struct mgs_target_info *mti,
156                          struct fs_db *fsdb);
157 int mgs_upgrade_sv_14(struct obd_device *obd, struct mgs_target_info *mti,
158                       struct fs_db *fsdb);
159 int mgs_erase_log(struct obd_device *obd, char *name);
160 int mgs_erase_logs(struct obd_device *obd, char *fsname);
161 int mgs_setparam(struct obd_device *obd, struct lustre_cfg *lcfg, char *fsname);
162
163 int mgs_pool_cmd(struct obd_device *obd, enum lcfg_command_type cmd,
164                  char *poolname, char *fsname, char *ostname);
165
166 /* mgs_handler.c */
167 void mgs_revoke_lock(struct obd_device *obd, struct fs_db *fsdb);
168 int  mgs_get_lock(struct obd_device *obd, struct ldlm_res_id *res,
169                   struct lustre_handle *lockh);
170 int  mgs_put_lock(struct lustre_handle *lockh);
171
172 /* mgs_nids.c */
173 int  mgs_ir_update(struct obd_device *obd, struct mgs_target_info *mti);
174 int  mgs_ir_init_fs(struct obd_device *obd, struct fs_db *fsdb);
175 void mgs_ir_fini_fs(struct obd_device *obd, struct fs_db *fsdb);
176 int  mgs_get_ir_logs(struct ptlrpc_request *req);
177 int  lprocfs_wr_ir_state(struct file *file, const char *buffer,
178                            unsigned long count, void *data);
179 int  lprocfs_rd_ir_state(struct seq_file *seq, void *data);
180 int  lprocfs_wr_ir_timeout(struct file *file, const char *buffer,
181                            unsigned long count, void *data);
182 int  lprocfs_rd_ir_timeout(char *page, char **start, off_t off, int count,
183                            int *eof, void *data);
184
185 /* mgs_fs.c */
186 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
187                           void *localdata);
188 int mgs_client_free(struct obd_export *exp);
189 int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt);
190 int mgs_fs_cleanup(struct obd_device *obddev);
191
192 #define strsuf(buf, suffix) (strcmp((buf)+strlen(buf)-strlen(suffix), (suffix)))
193 #ifdef LPROCFS
194 int lproc_mgs_setup(struct obd_device *dev);
195 int lproc_mgs_cleanup(struct obd_device *obd);
196 int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb);
197 int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb);
198 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars);
199 #else
200 static inline int lproc_mgs_setup(struct obd_device *dev)
201 {return 0;}
202 static inline int lproc_mgs_cleanup(struct obd_device *obd)
203 {return 0;}
204 static inline int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
205 {return 0;}
206 static inline int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb)
207 {return 0;}
208 static void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
209 {
210         memset(lvars, 0, sizeof(*lvars));
211 }
212 #endif
213
214 /* mgs/lproc_mgs.c */
215 enum {
216         LPROC_MGS_CONNECT = 0,
217         LPROC_MGS_DISCONNECT,
218         LPROC_MGS_EXCEPTION,
219         LPROC_MGS_TARGET_REG,
220         LPROC_MGS_TARGET_DEL,
221         LPROC_MGS_LAST
222 };
223 void mgs_counter_incr(struct obd_export *exp, int opcode);
224 void mgs_stats_counter_init(struct lprocfs_stats *stats);
225
226 #endif /* _MGS_INTERNAL_H */