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