Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / include / lustre_disk.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2006 Cluster File Systems, Inc.
5  *   Author: Nathan Rutman <nathan@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
9  *   Lustre is free software; you can redistribute it and/or
10  *   modify it under the terms of version 2 of the GNU General Public
11  *   License as published by the Free Software Foundation.
12  *
13  *   Lustre is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with Lustre; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  *
23  * Lustre disk format definitions.
24  */
25
26 #ifndef _LUSTRE_DISK_H
27 #define _LUSTRE_DISK_H
28
29 #include <libcfs/libcfs.h>
30 #include <lnet/types.h>
31
32 /****************** on-disk files *********************/
33
34 #define MDT_LOGS_DIR      "LOGS"  /* COMPAT_146 */
35 #define MOUNT_CONFIGS_DIR "CONFIGS"
36 /* Persistent mount data are stored on the disk in this file. */
37 #define MOUNT_DATA_FILE    MOUNT_CONFIGS_DIR"/mountdata"
38 #define LAST_RCVD         "last_received"
39 #define LOV_OBJID         "lov_objid"
40 #define HEALTH_CHECK      "health_check"
41 #define CAPA_KEYS         "capa_keys"
42
43 /****************** persistent mount data *********************/
44
45 #define LDD_F_SV_TYPE_MDT   0x0001
46 #define LDD_F_SV_TYPE_OST   0x0002
47 #define LDD_F_SV_TYPE_MGS   0x0004
48 #define LDD_F_NEED_INDEX    0x0010 /* need an index assignment */
49 #define LDD_F_VIRGIN        0x0020 /* never registered */
50 #define LDD_F_UPDATE        0x0040 /* update the config logs for this server*/
51 #define LDD_F_REWRITE_LDD   0x0080 /* rewrite the LDD */
52 #define LDD_F_WRITECONF     0x0100 /* regenerate all logs for this fs */
53 #define LDD_F_UPGRADE14     0x0200 /* COMPAT_14 */
54 #define LDD_F_PARAM         0x0400 /* process as lctl conf_param */
55
56 enum ldd_mount_type {
57         LDD_MT_EXT3 = 0,
58         LDD_MT_LDISKFS,
59         LDD_MT_SMFS,
60         LDD_MT_REISERFS,
61         LDD_MT_LDISKFS2,
62         LDD_MT_LAST
63 };
64
65 static inline char *mt_str(enum ldd_mount_type mt)
66 {
67         static char *mount_type_string[] = {
68                 "ext3",
69                 "ldiskfs",
70                 "smfs",
71                 "reiserfs",
72                 "ldiskfs2"
73         };
74         return mount_type_string[mt];
75 }
76
77 #define LDD_INCOMPAT_SUPP 0
78 #define LDD_ROCOMPAT_SUPP 0
79
80 #define LDD_MAGIC 0x1dd00001
81
82 /* On-disk configuration file. In host-endian order. */
83 struct lustre_disk_data {
84         __u32      ldd_magic;
85         __u32      ldd_feature_compat;  /* compatible feature flags */
86         __u32      ldd_feature_rocompat;/* read-only compatible feature flags */
87         __u32      ldd_feature_incompat;/* incompatible feature flags */
88
89         __u32      ldd_config_ver;      /* config rewrite count - not used */
90         __u32      ldd_flags;           /* LDD_SV_TYPE */
91         __u32      ldd_svindex;         /* server index (0001), must match 
92                                            svname */
93         __u32      ldd_mount_type;      /* target fs type LDD_MT_* */
94         char       ldd_fsname[64];      /* filesystem this server is part of */
95         char       ldd_svname[64];      /* this server's name (lustre-mdt0001)*/
96         __u8       ldd_uuid[40];        /* server UUID (COMPAT_146) */
97
98 /*200*/ char       ldd_userdata[1024 - 200]; /* arbitrary user string */
99 /*1024*/__u8       ldd_padding[4096 - 1024];
100 /*4096*/char       ldd_mount_opts[4096]; /* target fs mount opts */
101 /*8192*/char       ldd_params[4096];     /* key=value pairs */
102 };
103
104 #define IS_MDT(data)   ((data)->ldd_flags & LDD_F_SV_TYPE_MDT)
105 #define IS_OST(data)   ((data)->ldd_flags & LDD_F_SV_TYPE_OST)
106 #define IS_MGS(data)  ((data)->ldd_flags & LDD_F_SV_TYPE_MGS)
107 #define MT_STR(data)   mt_str((data)->ldd_mount_type)
108
109 /* Make the mdt/ost server obd name based on the filesystem name */
110 static inline int server_make_name(__u32 flags, __u16 index, char *fs,
111                                    char *name)
112 {
113         if (flags & (LDD_F_SV_TYPE_MDT | LDD_F_SV_TYPE_OST)) {
114                 sprintf(name, "%.8s-%s%04x", fs,
115                         (flags & LDD_F_SV_TYPE_MDT) ? "MDT" : "OST",
116                         index);
117         } else if (flags & LDD_F_SV_TYPE_MGS) {
118                 sprintf(name, "MGS");
119         } else {
120                 CERROR("unknown server type %#x\n", flags);
121                 return 1;
122         }
123         return 0;
124 }
125
126 /* Get the index from the obd name */
127 int server_name2index(char *svname, __u32 *idx, char **endptr);
128
129
130 /****************** mount command *********************/
131
132 /* The lmd is only used internally by Lustre; mount simply passes 
133    everything as string options */
134
135 #define LMD_MAGIC    0xbdacbd03
136
137 /* gleaned from the mount command - no persistent info here */
138 struct lustre_mount_data {
139         __u32      lmd_magic;
140         __u32      lmd_flags;         /* lustre mount flags */
141         int        lmd_mgs_failnodes; /* mgs failover node count */
142         int        lmd_exclude_count;
143         char      *lmd_dev;           /* device name */
144         char      *lmd_profile;       /* client only */
145         char      *lmd_opts;          /* lustre mount options (as opposed to 
146                                          _device_ mount options) */
147         __u32     *lmd_exclude;       /* array of OSTs to ignore */
148 };
149
150 #define LMD_FLG_SERVER       0x0001  /* Mounting a server */
151 #define LMD_FLG_CLIENT       0x0002  /* Mounting a client */
152 #define LMD_FLG_ABORT_RECOV  0x0008  /* Abort recovery */
153 #define LMD_FLG_NOSVC        0x0010  /* Only start MGS/MGC for servers, 
154                                         no other services */
155 #define LMD_FLG_NOMGS        0x0020  /* Only start target for servers, reusing
156                                         existing MGS services */
157
158 #define lmd_is_client(x) ((x)->lmd_flags & LMD_FLG_CLIENT) 
159
160
161 /****************** last_rcvd file *********************/
162
163 #define LR_SERVER_SIZE   512
164 #define LR_CLIENT_START 8192
165 #define LR_CLIENT_SIZE   128
166 #if LR_CLIENT_START < LR_SERVER_SIZE
167 #error "Can't have LR_CLIENT_START < LR_SERVER_SIZE"
168 #endif
169
170 /*
171  * This limit is arbitrary (131072 clients on x86), but it is convenient to use
172  * 2^n * CFS_PAGE_SIZE * 8 for the number of bits that fit an order-n allocation.
173  * If we need more than 131072 clients (order-2 allocation on x86) then this
174  * should become an array of single-page pointers that are allocated on demand.
175  */
176 #if (128 * 1024UL) > (CFS_PAGE_SIZE * 8)
177 #define LR_MAX_CLIENTS (128 * 1024UL)
178 #else
179 #define LR_MAX_CLIENTS (CFS_PAGE_SIZE * 8)
180 #endif
181
182 /* COMPAT_146 */
183 #define OBD_COMPAT_OST          0x00000002 /* this is an OST (temporary) */
184 #define OBD_COMPAT_MDT          0x00000004 /* this is an MDT (temporary) */
185 /* end COMPAT_146 */
186
187 #define OBD_ROCOMPAT_LOVOBJID   0x00000001 /* MDS handles LOV_OBJID file */
188
189 #define OBD_INCOMPAT_GROUPS     0x00000001 /* OST handles group subdirs */
190 #define OBD_INCOMPAT_OST        0x00000002 /* this is an OST */
191 #define OBD_INCOMPAT_MDT        0x00000004 /* this is an MDT */
192 #define OBD_INCOMPAT_COMMON_LR  0x00000008 /* common last_rvcd format */
193
194
195 /* Data stored per server at the head of the last_rcvd file.  In le32 order.
196    This should be common to filter_internal.h, lustre_mds.h */
197 struct lr_server_data {
198         __u8  lsd_uuid[40];        /* server UUID */
199         __u64 lsd_last_transno;    /* last completed transaction ID */
200         __u64 lsd_compat14;        /* reserved - compat with old last_rcvd */
201         __u64 lsd_mount_count;     /* incarnation number */
202         __u32 lsd_feature_compat;  /* compatible feature flags */
203         __u32 lsd_feature_rocompat;/* read-only compatible feature flags */
204         __u32 lsd_feature_incompat;/* incompatible feature flags */
205         __u32 lsd_server_size;     /* size of server data area */
206         __u32 lsd_client_start;    /* start of per-client data area */
207         __u16 lsd_client_size;     /* size of per-client data area */
208         __u16 lsd_subdir_count;    /* number of subdirectories for objects */
209         __u64 lsd_catalog_oid;     /* recovery catalog object id */
210         __u32 lsd_catalog_ogen;    /* recovery catalog inode generation */
211         __u8  lsd_peeruuid[40];    /* UUID of MDS associated with this OST */
212         __u32 lsd_ost_index;       /* index number of OST in LOV */
213         __u32 lsd_mdt_index;       /* index number of MDT in LMV */
214         __u8  lsd_padding[LR_SERVER_SIZE - 148];
215 };
216
217 /* Data stored per client in the last_rcvd file.  In le32 order. */
218 struct lsd_client_data {
219         __u8  lcd_uuid[40];      /* client UUID */
220         __u64 lcd_last_transno; /* last completed transaction ID */
221         __u64 lcd_last_xid;     /* xid for the last transaction */
222         __u32 lcd_last_result;  /* result from last RPC */
223         __u32 lcd_last_data;    /* per-op data (disposition for open &c.) */
224         /* for MDS_CLOSE requests */
225         __u64 lcd_last_close_transno; /* last completed transaction ID */
226         __u64 lcd_last_close_xid;     /* xid for the last transaction */
227         __u32 lcd_last_close_result;  /* result from last RPC */
228         __u32 lcd_last_close_data;    /* per-op data */
229         __u8  lcd_padding[LR_CLIENT_SIZE - 88];
230 };
231
232
233 #ifdef __KERNEL__
234 /****************** superblock additional info *********************/
235 struct ll_sb_info;
236
237 struct lustre_sb_info {
238         int                       lsi_flags;
239         struct obd_device        *lsi_mgc;     /* mgc obd */
240         struct lustre_mount_data *lsi_lmd;     /* mount command info */
241         struct lustre_disk_data  *lsi_ldd;     /* mount info on-disk */
242         struct ll_sb_info        *lsi_llsbi;   /* add'l client sbi info */
243         struct vfsmount          *lsi_srv_mnt; /* the one server mount */
244         atomic_t                  lsi_mounts;  /* references to the srv_mnt */
245 };
246
247 #define LSI_SERVER                       0x00000001
248 #define LSI_UMOUNT_FORCE                 0x00000010
249 #define LSI_UMOUNT_FAILOVER              0x00000020
250
251 #define     s2lsi(sb)        ((struct lustre_sb_info *)((sb)->s_fs_info))
252 #define     s2lsi_nocast(sb) ((sb)->s_fs_info)
253
254 #define     get_profile_name(sb)   (s2lsi(sb)->lsi_lmd->lmd_profile)
255
256 #endif /* __KERNEL__ */
257
258 /****************** mount lookup info *********************/
259
260 struct lustre_mount_info {
261         char               *lmi_name;
262         struct super_block *lmi_sb;
263         struct vfsmount    *lmi_mnt;
264         struct list_head    lmi_list_chain;
265 };
266
267 /****************** prototypes *********************/
268
269 #ifdef __KERNEL__
270 #include <obd_class.h>
271
272 /* obd_mount.c */
273 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb));
274 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb));
275
276
277 int lustre_common_put_super(struct super_block *sb);
278 int lustre_process_log(struct super_block *sb, char *logname, 
279                      struct config_llog_instance *cfg);
280 int lustre_end_log(struct super_block *sb, char *logname, 
281                        struct config_llog_instance *cfg);
282 struct lustre_mount_info *server_get_mount(const char *name);
283 struct lustre_mount_info *server_get_mount_2(const char *name);
284 int server_put_mount(const char *name, struct vfsmount *mnt);
285 int server_put_mount_2(const char *name, struct vfsmount *mnt);
286 int server_register_target(struct super_block *sb);
287 struct mgs_target_info;
288 int server_mti_print(char *title, struct mgs_target_info *mti);
289
290 /* mgc_request.c */
291 int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id);
292
293 #endif
294
295 #endif // _LUSTRE_DISK_H