1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/include/lustre_disk.h
38 * Lustre disk format definitions.
40 * Author: Nathan Rutman <nathan@clusterfs.com>
43 #ifndef _LUSTRE_DISK_H
44 #define _LUSTRE_DISK_H
46 #include <libcfs/libcfs.h>
47 #include <lnet/types.h>
49 /****************** on-disk files *********************/
51 #define MDT_LOGS_DIR "LOGS" /* COMPAT_146 */
52 #define MOUNT_CONFIGS_DIR "CONFIGS"
53 #define CONFIGS_FILE "mountdata"
54 /** Persistent mount data are stored on the disk in this file. */
55 #define MOUNT_DATA_FILE MOUNT_CONFIGS_DIR"/"CONFIGS_FILE
56 #define LAST_RCVD "last_rcvd"
57 #define LOV_OBJID "lov_objid"
58 #define HEALTH_CHECK "health_check"
59 #define CAPA_KEYS "capa_keys"
60 #define CHANGELOG_USERS "changelog_users"
63 /****************** persistent mount data *********************/
65 #define LDD_F_SV_TYPE_MDT 0x0001
66 #define LDD_F_SV_TYPE_OST 0x0002
67 #define LDD_F_SV_TYPE_MGS 0x0004
68 #define LDD_F_SV_ALL 0x0008
69 /** need an index assignment */
70 #define LDD_F_NEED_INDEX 0x0010
71 /** never registered */
72 #define LDD_F_VIRGIN 0x0020
73 /** update the config logs for this server*/
74 #define LDD_F_UPDATE 0x0040
75 /** rewrite the LDD */
76 #define LDD_F_REWRITE_LDD 0x0080
77 /** regenerate all logs for this fs */
78 #define LDD_F_WRITECONF 0x0100
80 #define LDD_F_UPGRADE14 0x0200
81 /** process as lctl conf_param */
82 #define LDD_F_PARAM 0x0400
83 /** backend fs make use of IAM directory format. */
84 #define LDD_F_IAM_DIR 0x0800
95 static inline char *mt_str(enum ldd_mount_type mt)
97 static char *mount_type_string[] = {
104 return mount_type_string[mt];
107 #define LDD_INCOMPAT_SUPP 0
108 #define LDD_ROCOMPAT_SUPP 0
110 #define LDD_MAGIC 0x1dd00001
112 /* On-disk configuration file. In host-endian order. */
113 struct lustre_disk_data {
115 __u32 ldd_feature_compat; /* compatible feature flags */
116 __u32 ldd_feature_rocompat;/* read-only compatible feature flags */
117 __u32 ldd_feature_incompat;/* incompatible feature flags */
119 __u32 ldd_config_ver; /* config rewrite count - not used */
120 __u32 ldd_flags; /* LDD_SV_TYPE */
121 __u32 ldd_svindex; /* server index (0001), must match
123 __u32 ldd_mount_type; /* target fs type LDD_MT_* */
124 char ldd_fsname[64]; /* filesystem this server is part of */
125 char ldd_svname[64]; /* this server's name (lustre-mdt0001)*/
126 __u8 ldd_uuid[40]; /* server UUID (COMPAT_146) */
128 /*200*/ char ldd_userdata[1024 - 200]; /* arbitrary user string */
129 /*1024*/__u8 ldd_padding[4096 - 1024];
130 /*4096*/char ldd_mount_opts[4096]; /* target fs mount opts */
131 /*8192*/char ldd_params[4096]; /* key=value pairs */
134 #define IS_MDT(data) ((data)->ldd_flags & LDD_F_SV_TYPE_MDT)
135 #define IS_OST(data) ((data)->ldd_flags & LDD_F_SV_TYPE_OST)
136 #define IS_MGS(data) ((data)->ldd_flags & LDD_F_SV_TYPE_MGS)
137 #define MT_STR(data) mt_str((data)->ldd_mount_type)
139 /* Make the mdt/ost server obd name based on the filesystem name */
140 static inline int server_make_name(__u32 flags, __u16 index, char *fs,
143 if (flags & (LDD_F_SV_TYPE_MDT | LDD_F_SV_TYPE_OST)) {
144 if (!(flags & LDD_F_SV_ALL))
145 sprintf(name, "%.8s-%s%04x", fs,
146 (flags & LDD_F_SV_TYPE_MDT) ? "MDT" : "OST",
148 } else if (flags & LDD_F_SV_TYPE_MGS) {
149 sprintf(name, "MGS");
151 CERROR("unknown server type %#x\n", flags);
157 /* Get the index from the obd name */
158 int server_name2index(char *svname, __u32 *idx, char **endptr);
161 /****************** mount command *********************/
163 /* The lmd is only used internally by Lustre; mount simply passes
164 everything as string options */
166 #define LMD_MAGIC 0xbdacbd03
168 /* gleaned from the mount command - no persistent info here */
169 struct lustre_mount_data {
171 __u32 lmd_flags; /* lustre mount flags */
172 int lmd_mgs_failnodes; /* mgs failover node count */
173 int lmd_exclude_count;
174 char *lmd_dev; /* device name */
175 char *lmd_profile; /* client only */
176 char *lmd_mgssec; /* sptlrpc flavor to mgs */
177 char *lmd_opts; /* lustre mount options (as opposed to
178 _device_ mount options) */
179 __u32 *lmd_exclude; /* array of OSTs to ignore */
182 #define LMD_FLG_SERVER 0x0001 /* Mounting a server */
183 #define LMD_FLG_CLIENT 0x0002 /* Mounting a client */
184 #define LMD_FLG_ABORT_RECOV 0x0008 /* Abort recovery */
185 #define LMD_FLG_NOSVC 0x0010 /* Only start MGS/MGC for servers,
187 #define LMD_FLG_NOMGS 0x0020 /* Only start target for servers, reusing
188 existing MGS services */
190 #define lmd_is_client(x) ((x)->lmd_flags & LMD_FLG_CLIENT)
193 /****************** last_rcvd file *********************/
195 /** version recovery epoch */
196 #define LR_EPOCH_BITS 32
197 #define lr_epoch(a) ((a) >> LR_EPOCH_BITS)
198 #define LR_EXPIRE_INTERVALS 16 /**< number of intervals to track transno */
200 #define LR_SERVER_SIZE 512
201 #define LR_CLIENT_START 8192
202 #define LR_CLIENT_SIZE 128
203 #if LR_CLIENT_START < LR_SERVER_SIZE
204 #error "Can't have LR_CLIENT_START < LR_SERVER_SIZE"
208 * This limit is arbitrary (131072 clients on x86), but it is convenient to use
209 * 2^n * CFS_PAGE_SIZE * 8 for the number of bits that fit an order-n allocation.
210 * If we need more than 131072 clients (order-2 allocation on x86) then this
211 * should become an array of single-page pointers that are allocated on demand.
213 #if (128 * 1024UL) > (CFS_PAGE_SIZE * 8)
214 #define LR_MAX_CLIENTS (128 * 1024UL)
216 #define LR_MAX_CLIENTS (CFS_PAGE_SIZE * 8)
219 #define LR_CLIENT_BITMAP_SIZE ((LR_MAX_CLIENTS >> 3) / sizeof(long))
221 /** COMPAT_146: this is an OST (temporary) */
222 #define OBD_COMPAT_OST 0x00000002
223 /** COMPAT_146: this is an MDT (temporary) */
224 #define OBD_COMPAT_MDT 0x00000004
226 /** MDS handles LOV_OBJID file */
227 #define OBD_ROCOMPAT_LOVOBJID 0x00000001
229 /** OST handles group subdirs */
230 #define OBD_INCOMPAT_GROUPS 0x00000001
231 /** this is an OST */
232 #define OBD_INCOMPAT_OST 0x00000002
233 /** this is an MDT */
234 #define OBD_INCOMPAT_MDT 0x00000004
235 /** common last_rvcd format */
236 #define OBD_INCOMPAT_COMMON_LR 0x00000008
237 /** FID is enabled */
238 #define OBD_INCOMPAT_FID 0x00000010
240 * lustre disk using iam format to store directory entries
242 #define OBD_INCOMPAT_IAM_DIR 0x00000020
245 /* Data stored per server at the head of the last_rcvd file. In le32 order.
246 This should be common to filter_internal.h, lustre_mds.h */
247 struct lr_server_data {
248 __u8 lsd_uuid[40]; /* server UUID */
249 __u64 lsd_last_transno; /* last completed transaction ID */
250 __u64 lsd_compat14; /* reserved - compat with old last_rcvd */
251 __u64 lsd_mount_count; /* incarnation number */
252 __u32 lsd_feature_compat; /* compatible feature flags */
253 __u32 lsd_feature_rocompat;/* read-only compatible feature flags */
254 __u32 lsd_feature_incompat;/* incompatible feature flags */
255 __u32 lsd_server_size; /* size of server data area */
256 __u32 lsd_client_start; /* start of per-client data area */
257 __u16 lsd_client_size; /* size of per-client data area */
258 __u16 lsd_subdir_count; /* number of subdirectories for objects */
259 __u64 lsd_catalog_oid; /* recovery catalog object id */
260 __u32 lsd_catalog_ogen; /* recovery catalog inode generation */
261 __u8 lsd_peeruuid[40]; /* UUID of MDS associated with this OST */
262 __u32 lsd_ost_index; /* index number of OST in LOV */
263 __u32 lsd_mdt_index; /* index number of MDT in LMV */
264 __u32 lsd_start_epoch; /* VBR: start epoch from last boot */
265 /** transaction values since lsd_trans_table_time */
266 __u64 lsd_trans_table[LR_EXPIRE_INTERVALS];
267 /** start point of transno table below */
268 __u32 lsd_trans_table_time; /* time of first slot in table above */
269 __u32 lsd_expire_intervals; /* LR_EXPIRE_INTERVALS */
270 __u8 lsd_padding[LR_SERVER_SIZE - 288];
273 /* Data stored per client in the last_rcvd file. In le32 order. */
274 struct lsd_client_data {
275 __u8 lcd_uuid[40]; /* client UUID */
276 __u64 lcd_last_transno; /* last completed transaction ID */
277 __u64 lcd_last_xid; /* xid for the last transaction */
278 __u32 lcd_last_result; /* result from last RPC */
279 __u32 lcd_last_data; /* per-op data (disposition for open &c.) */
280 /* for MDS_CLOSE requests */
281 __u64 lcd_last_close_transno; /* last completed transaction ID */
282 __u64 lcd_last_close_xid; /* xid for the last transaction */
283 __u32 lcd_last_close_result; /* result from last RPC */
284 __u32 lcd_last_close_data; /* per-op data */
285 /* VBR: last versions */
286 __u64 lcd_pre_versions[4];
287 __u32 lcd_last_epoch;
288 /** orphans handling for delayed export rely on that */
289 __u32 lcd_first_epoch;
290 __u8 lcd_padding[LR_CLIENT_SIZE - 128];
293 /* last_rcvd handling */
294 static inline void lsd_le_to_cpu(struct lr_server_data *buf,
295 struct lr_server_data *lsd)
298 memcpy(lsd->lsd_uuid, buf->lsd_uuid, sizeof (lsd->lsd_uuid));
299 lsd->lsd_last_transno = le64_to_cpu(buf->lsd_last_transno);
300 lsd->lsd_compat14 = le64_to_cpu(buf->lsd_compat14);
301 lsd->lsd_mount_count = le64_to_cpu(buf->lsd_mount_count);
302 lsd->lsd_feature_compat = le32_to_cpu(buf->lsd_feature_compat);
303 lsd->lsd_feature_rocompat = le32_to_cpu(buf->lsd_feature_rocompat);
304 lsd->lsd_feature_incompat = le32_to_cpu(buf->lsd_feature_incompat);
305 lsd->lsd_server_size = le32_to_cpu(buf->lsd_server_size);
306 lsd->lsd_client_start = le32_to_cpu(buf->lsd_client_start);
307 lsd->lsd_client_size = le16_to_cpu(buf->lsd_client_size);
308 lsd->lsd_subdir_count = le16_to_cpu(buf->lsd_subdir_count);
309 lsd->lsd_catalog_oid = le64_to_cpu(buf->lsd_catalog_oid);
310 lsd->lsd_catalog_ogen = le32_to_cpu(buf->lsd_catalog_ogen);
311 memcpy(lsd->lsd_peeruuid, buf->lsd_peeruuid, sizeof(lsd->lsd_peeruuid));
312 lsd->lsd_ost_index = le32_to_cpu(buf->lsd_ost_index);
313 lsd->lsd_mdt_index = le32_to_cpu(buf->lsd_mdt_index);
314 lsd->lsd_start_epoch = le32_to_cpu(buf->lsd_start_epoch);
315 for (i = 0; i < LR_EXPIRE_INTERVALS; i++)
316 lsd->lsd_trans_table[i] = le64_to_cpu(buf->lsd_trans_table[i]);
317 lsd->lsd_trans_table_time = le32_to_cpu(buf->lsd_trans_table_time);
318 lsd->lsd_expire_intervals = le32_to_cpu(buf->lsd_expire_intervals);
321 static inline void lsd_cpu_to_le(struct lr_server_data *lsd,
322 struct lr_server_data *buf)
325 memcpy(buf->lsd_uuid, lsd->lsd_uuid, sizeof (buf->lsd_uuid));
326 buf->lsd_last_transno = cpu_to_le64(lsd->lsd_last_transno);
327 buf->lsd_compat14 = cpu_to_le64(lsd->lsd_compat14);
328 buf->lsd_mount_count = cpu_to_le64(lsd->lsd_mount_count);
329 buf->lsd_feature_compat = cpu_to_le32(lsd->lsd_feature_compat);
330 buf->lsd_feature_rocompat = cpu_to_le32(lsd->lsd_feature_rocompat);
331 buf->lsd_feature_incompat = cpu_to_le32(lsd->lsd_feature_incompat);
332 buf->lsd_server_size = cpu_to_le32(lsd->lsd_server_size);
333 buf->lsd_client_start = cpu_to_le32(lsd->lsd_client_start);
334 buf->lsd_client_size = cpu_to_le16(lsd->lsd_client_size);
335 buf->lsd_subdir_count = cpu_to_le16(lsd->lsd_subdir_count);
336 buf->lsd_catalog_oid = cpu_to_le64(lsd->lsd_catalog_oid);
337 buf->lsd_catalog_ogen = cpu_to_le32(lsd->lsd_catalog_ogen);
338 memcpy(buf->lsd_peeruuid, lsd->lsd_peeruuid, sizeof(buf->lsd_peeruuid));
339 buf->lsd_ost_index = cpu_to_le32(lsd->lsd_ost_index);
340 buf->lsd_mdt_index = cpu_to_le32(lsd->lsd_mdt_index);
341 buf->lsd_start_epoch = cpu_to_le32(lsd->lsd_start_epoch);
342 for (i = 0; i < LR_EXPIRE_INTERVALS; i++)
343 buf->lsd_trans_table[i] = cpu_to_le64(lsd->lsd_trans_table[i]);
344 buf->lsd_trans_table_time = cpu_to_le32(lsd->lsd_trans_table_time);
345 buf->lsd_expire_intervals = cpu_to_le32(lsd->lsd_expire_intervals);
348 static inline void lcd_le_to_cpu(struct lsd_client_data *buf,
349 struct lsd_client_data *lcd)
351 memcpy(lcd->lcd_uuid, buf->lcd_uuid, sizeof (lcd->lcd_uuid));
352 lcd->lcd_last_transno = le64_to_cpu(buf->lcd_last_transno);
353 lcd->lcd_last_xid = le64_to_cpu(buf->lcd_last_xid);
354 lcd->lcd_last_result = le32_to_cpu(buf->lcd_last_result);
355 lcd->lcd_last_data = le32_to_cpu(buf->lcd_last_data);
356 lcd->lcd_last_close_transno = le64_to_cpu(buf->lcd_last_close_transno);
357 lcd->lcd_last_close_xid = le64_to_cpu(buf->lcd_last_close_xid);
358 lcd->lcd_last_close_result = le32_to_cpu(buf->lcd_last_close_result);
359 lcd->lcd_last_close_data = le32_to_cpu(buf->lcd_last_close_data);
360 lcd->lcd_pre_versions[0] = le64_to_cpu(buf->lcd_pre_versions[0]);
361 lcd->lcd_pre_versions[1] = le64_to_cpu(buf->lcd_pre_versions[1]);
362 lcd->lcd_pre_versions[2] = le64_to_cpu(buf->lcd_pre_versions[2]);
363 lcd->lcd_pre_versions[3] = le64_to_cpu(buf->lcd_pre_versions[3]);
364 lcd->lcd_last_epoch = le32_to_cpu(buf->lcd_last_epoch);
365 lcd->lcd_first_epoch = le32_to_cpu(buf->lcd_first_epoch);
368 static inline void lcd_cpu_to_le(struct lsd_client_data *lcd,
369 struct lsd_client_data *buf)
371 memcpy(buf->lcd_uuid, lcd->lcd_uuid, sizeof (lcd->lcd_uuid));
372 buf->lcd_last_transno = cpu_to_le64(lcd->lcd_last_transno);
373 buf->lcd_last_xid = cpu_to_le64(lcd->lcd_last_xid);
374 buf->lcd_last_result = cpu_to_le32(lcd->lcd_last_result);
375 buf->lcd_last_data = cpu_to_le32(lcd->lcd_last_data);
376 buf->lcd_last_close_transno = cpu_to_le64(lcd->lcd_last_close_transno);
377 buf->lcd_last_close_xid = cpu_to_le64(lcd->lcd_last_close_xid);
378 buf->lcd_last_close_result = cpu_to_le32(lcd->lcd_last_close_result);
379 buf->lcd_last_close_data = cpu_to_le32(lcd->lcd_last_close_data);
380 buf->lcd_pre_versions[0] = cpu_to_le64(lcd->lcd_pre_versions[0]);
381 buf->lcd_pre_versions[1] = cpu_to_le64(lcd->lcd_pre_versions[1]);
382 buf->lcd_pre_versions[2] = cpu_to_le64(lcd->lcd_pre_versions[2]);
383 buf->lcd_pre_versions[3] = cpu_to_le64(lcd->lcd_pre_versions[3]);
384 buf->lcd_last_epoch = cpu_to_le32(lcd->lcd_last_epoch);
385 buf->lcd_first_epoch = cpu_to_le32(lcd->lcd_first_epoch);
388 static inline __u64 lcd_last_transno(struct lsd_client_data *lcd)
390 return (lcd->lcd_last_transno > lcd->lcd_last_close_transno ?
391 lcd->lcd_last_transno : lcd->lcd_last_close_transno);
394 static inline __u64 lcd_last_xid(struct lsd_client_data *lcd)
396 return (lcd->lcd_last_xid > lcd->lcd_last_close_xid ?
397 lcd->lcd_last_xid : lcd->lcd_last_close_xid);
400 /****************** superblock additional info *********************/
405 struct lustre_sb_info {
407 struct obd_device *lsi_mgc; /* mgc obd */
408 struct lustre_mount_data *lsi_lmd; /* mount command info */
409 struct lustre_disk_data *lsi_ldd; /* mount info on-disk */
410 struct ll_sb_info *lsi_llsbi; /* add'l client sbi info */
411 struct vfsmount *lsi_srv_mnt; /* the one server mount */
412 atomic_t lsi_mounts; /* references to the srv_mnt */
415 #define LSI_SERVER 0x00000001
416 #define LSI_UMOUNT_FORCE 0x00000010
417 #define LSI_UMOUNT_FAILOVER 0x00000020
419 #define s2lsi(sb) ((struct lustre_sb_info *)((sb)->s_fs_info))
420 #define s2lsi_nocast(sb) ((sb)->s_fs_info)
422 #define get_profile_name(sb) (s2lsi(sb)->lsi_lmd->lmd_profile)
424 #endif /* __KERNEL__ */
426 /****************** mount lookup info *********************/
428 struct lustre_mount_info {
430 struct super_block *lmi_sb;
431 struct vfsmount *lmi_mnt;
432 struct list_head lmi_list_chain;
435 /****************** prototypes *********************/
440 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb));
441 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb));
444 int lustre_common_put_super(struct super_block *sb);
445 struct lustre_mount_info *server_get_mount(const char *name);
446 struct lustre_mount_info *server_get_mount_2(const char *name);
447 int server_put_mount(const char *name, struct vfsmount *mnt);
448 int server_put_mount_2(const char *name, struct vfsmount *mnt);
449 int server_register_target(struct super_block *sb);
450 struct mgs_target_info;
451 int server_mti_print(char *title, struct mgs_target_info *mti);
454 int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id);
458 #endif // _LUSTRE_DISK_H