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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
39 * lustre/include/lustre_disk.h
41 * Lustre disk format definitions.
43 * Author: Nathan Rutman <nathan@clusterfs.com>
46 #ifndef _LUSTRE_DISK_H
47 #define _LUSTRE_DISK_H
49 /** \defgroup disk disk
54 #include <libcfs/libcfs.h>
55 #include <lnet/types.h>
57 /****************** on-disk files *********************/
59 #define MDT_LOGS_DIR "LOGS" /* COMPAT_146 */
60 #define MOUNT_CONFIGS_DIR "CONFIGS"
61 #define CONFIGS_FILE "mountdata"
62 /** Persistent mount data are stored on the disk in this file. */
63 #define MOUNT_DATA_FILE MOUNT_CONFIGS_DIR"/"CONFIGS_FILE
64 #define LAST_RCVD "last_rcvd"
65 #define LOV_OBJID "lov_objid"
66 #define HEALTH_CHECK "health_check"
67 #define CAPA_KEYS "capa_keys"
68 #define CHANGELOG_USERS "changelog_users"
71 /****************** persistent mount data *********************/
73 #define LDD_F_SV_TYPE_MDT 0x0001
74 #define LDD_F_SV_TYPE_OST 0x0002
75 #define LDD_F_SV_TYPE_MGS 0x0004
76 #define LDD_F_SV_ALL 0x0008
77 /** need an index assignment */
78 #define LDD_F_NEED_INDEX 0x0010
79 /** never registered */
80 #define LDD_F_VIRGIN 0x0020
81 /** update the config logs for this server */
82 #define LDD_F_UPDATE 0x0040
83 /** rewrite the LDD */
84 #define LDD_F_REWRITE_LDD 0x0080
85 /** regenerate config logs for this fs or server */
86 #define LDD_F_WRITECONF 0x0100
88 #define LDD_F_UPGRADE14 0x0200
89 /** process as lctl conf_param */
90 #define LDD_F_PARAM 0x0400
91 /** backend fs make use of IAM directory format. */
92 #define LDD_F_IAM_DIR 0x0800
93 /** all nodes are specified as service nodes */
94 #define LDD_F_NO_PRIMNODE 0x1000
105 static inline char *mt_str(enum ldd_mount_type mt)
107 static char *mount_type_string[] = {
114 return mount_type_string[mt];
117 #define LDD_INCOMPAT_SUPP 0
118 #define LDD_ROCOMPAT_SUPP 0
120 #define LDD_MAGIC 0x1dd00001
122 /* On-disk configuration file. In host-endian order. */
123 struct lustre_disk_data {
125 __u32 ldd_feature_compat; /* compatible feature flags */
126 __u32 ldd_feature_rocompat;/* read-only compatible feature flags */
127 __u32 ldd_feature_incompat;/* incompatible feature flags */
129 __u32 ldd_config_ver; /* config rewrite count - not used */
130 __u32 ldd_flags; /* LDD_SV_TYPE */
131 __u32 ldd_svindex; /* server index (0001), must match
133 __u32 ldd_mount_type; /* target fs type LDD_MT_* */
134 char ldd_fsname[64]; /* filesystem this server is part of,
136 char ldd_svname[64]; /* this server's name (lustre-mdt0001)*/
137 __u8 ldd_uuid[40]; /* server UUID (COMPAT_146) */
139 /*200*/ char ldd_userdata[1024 - 200]; /* arbitrary user string */
140 /*1024*/__u8 ldd_padding[4096 - 1024];
141 /*4096*/char ldd_mount_opts[4096]; /* target fs mount opts */
142 /*8192*/char ldd_params[4096]; /* key=value pairs */
145 #define IS_MDT(data) ((data)->ldd_flags & LDD_F_SV_TYPE_MDT)
146 #define IS_OST(data) ((data)->ldd_flags & LDD_F_SV_TYPE_OST)
147 #define IS_MGS(data) ((data)->ldd_flags & LDD_F_SV_TYPE_MGS)
148 #define MT_STR(data) mt_str((data)->ldd_mount_type)
150 /* Make the mdt/ost server obd name based on the filesystem name */
151 static inline int server_make_name(__u32 flags, __u16 index, char *fs,
154 if (flags & (LDD_F_SV_TYPE_MDT | LDD_F_SV_TYPE_OST)) {
155 if (!(flags & LDD_F_SV_ALL))
156 sprintf(name, "%.8s-%s%04x", fs,
157 (flags & LDD_F_SV_TYPE_MDT) ? "MDT" : "OST",
159 } else if (flags & LDD_F_SV_TYPE_MGS) {
160 sprintf(name, "MGS");
162 CERROR("unknown server type %#x\n", flags);
168 /* Get the index from the obd name */
169 int server_name2index(char *svname, __u32 *idx, char **endptr);
172 /****************** mount command *********************/
174 /* The lmd is only used internally by Lustre; mount simply passes
175 everything as string options */
177 #define LMD_MAGIC 0xbdacbd03
179 /* gleaned from the mount command - no persistent info here */
180 struct lustre_mount_data {
182 __u32 lmd_flags; /* lustre mount flags */
183 int lmd_mgs_failnodes; /* mgs failover node count */
184 int lmd_exclude_count;
185 int lmd_recovery_time_soft;
186 int lmd_recovery_time_hard;
187 char *lmd_dev; /* device name */
188 char *lmd_profile; /* client only */
189 char *lmd_mgssec; /* sptlrpc flavor to mgs */
190 char *lmd_opts; /* lustre mount options (as opposed to
191 _device_ mount options) */
192 __u32 *lmd_exclude; /* array of OSTs to ignore */
195 #define LMD_FLG_SERVER 0x0001 /* Mounting a server */
196 #define LMD_FLG_CLIENT 0x0002 /* Mounting a client */
197 #define LMD_FLG_ABORT_RECOV 0x0008 /* Abort recovery */
198 #define LMD_FLG_NOSVC 0x0010 /* Only start MGS/MGC for servers,
200 #define LMD_FLG_NOMGS 0x0020 /* Only start target for servers, reusing
201 existing MGS services */
202 #define LMD_FLG_WRITECONF 0x0040 /* Rewrite config log */
204 #define lmd_is_client(x) ((x)->lmd_flags & LMD_FLG_CLIENT)
207 /****************** last_rcvd file *********************/
209 /** version recovery epoch */
210 #define LR_EPOCH_BITS 32
211 #define lr_epoch(a) ((a) >> LR_EPOCH_BITS)
212 #define LR_EXPIRE_INTERVALS 16 /**< number of intervals to track transno */
213 #define ENOENT_VERSION 1 /** 'virtual' version of non-existent object */
215 #define LR_SERVER_SIZE 512
216 #define LR_CLIENT_START 8192
217 #define LR_CLIENT_SIZE 128
218 #if LR_CLIENT_START < LR_SERVER_SIZE
219 #error "Can't have LR_CLIENT_START < LR_SERVER_SIZE"
223 * This limit is arbitrary (131072 clients on x86), but it is convenient to use
224 * 2^n * CFS_PAGE_SIZE * 8 for the number of bits that fit an order-n allocation.
225 * If we need more than 131072 clients (order-2 allocation on x86) then this
226 * should become an array of single-page pointers that are allocated on demand.
228 #if (128 * 1024UL) > (CFS_PAGE_SIZE * 8)
229 #define LR_MAX_CLIENTS (128 * 1024UL)
231 #define LR_MAX_CLIENTS (CFS_PAGE_SIZE * 8)
234 /** COMPAT_146: this is an OST (temporary) */
235 #define OBD_COMPAT_OST 0x00000002
236 /** COMPAT_146: this is an MDT (temporary) */
237 #define OBD_COMPAT_MDT 0x00000004
238 /** 2.0 server, interop flag to show server version is changed */
239 #define OBD_COMPAT_20 0x00000008
241 /** MDS handles LOV_OBJID file */
242 #define OBD_ROCOMPAT_LOVOBJID 0x00000001
244 /** OST handles group subdirs */
245 #define OBD_INCOMPAT_GROUPS 0x00000001
246 /** this is an OST */
247 #define OBD_INCOMPAT_OST 0x00000002
248 /** this is an MDT */
249 #define OBD_INCOMPAT_MDT 0x00000004
250 /** common last_rvcd format */
251 #define OBD_INCOMPAT_COMMON_LR 0x00000008
252 /** FID is enabled */
253 #define OBD_INCOMPAT_FID 0x00000010
254 /** Size-on-MDS is enabled */
255 #define OBD_INCOMPAT_SOM 0x00000020
256 /** filesystem using iam format to store directory entries */
257 #define OBD_INCOMPAT_IAM_DIR 0x00000040
258 /** LMA attribute contains per-inode incompatible flags */
259 #define OBD_INCOMPAT_LMA 0x00000080
262 /* Data stored per server at the head of the last_rcvd file. In le32 order.
263 This should be common to filter_internal.h, lustre_mds.h */
264 struct lr_server_data {
265 __u8 lsd_uuid[40]; /* server UUID */
266 __u64 lsd_last_transno; /* last completed transaction ID */
267 __u64 lsd_compat14; /* reserved - compat with old last_rcvd */
268 __u64 lsd_mount_count; /* incarnation number */
269 __u32 lsd_feature_compat; /* compatible feature flags */
270 __u32 lsd_feature_rocompat;/* read-only compatible feature flags */
271 __u32 lsd_feature_incompat;/* incompatible feature flags */
272 __u32 lsd_server_size; /* size of server data area */
273 __u32 lsd_client_start; /* start of per-client data area */
274 __u16 lsd_client_size; /* size of per-client data area */
275 __u16 lsd_subdir_count; /* number of subdirectories for objects */
276 __u64 lsd_catalog_oid; /* recovery catalog object id */
277 __u32 lsd_catalog_ogen; /* recovery catalog inode generation */
278 __u8 lsd_peeruuid[40]; /* UUID of MDS associated with this OST */
279 __u32 lsd_ost_index; /* index number of OST in LOV */
280 __u32 lsd_mdt_index; /* index number of MDT in LMV */
281 __u32 lsd_start_epoch; /* VBR: start epoch from last boot */
282 /** transaction values since lsd_trans_table_time */
283 __u64 lsd_trans_table[LR_EXPIRE_INTERVALS];
284 /** start point of transno table below */
285 __u32 lsd_trans_table_time; /* time of first slot in table above */
286 __u32 lsd_expire_intervals; /* LR_EXPIRE_INTERVALS */
287 __u8 lsd_padding[LR_SERVER_SIZE - 288];
290 /* Data stored per client in the last_rcvd file. In le32 order. */
291 struct lsd_client_data {
292 __u8 lcd_uuid[40]; /* client UUID */
293 __u64 lcd_last_transno; /* last completed transaction ID */
294 __u64 lcd_last_xid; /* xid for the last transaction */
295 __u32 lcd_last_result; /* result from last RPC */
296 __u32 lcd_last_data; /* per-op data (disposition for open &c.) */
297 /* for MDS_CLOSE requests */
298 __u64 lcd_last_close_transno; /* last completed transaction ID */
299 __u64 lcd_last_close_xid; /* xid for the last transaction */
300 __u32 lcd_last_close_result; /* result from last RPC */
301 __u32 lcd_last_close_data; /* per-op data */
302 /* VBR: last versions */
303 __u64 lcd_pre_versions[4];
304 __u32 lcd_last_epoch;
305 /** orphans handling for delayed export rely on that */
306 __u32 lcd_first_epoch;
307 __u8 lcd_padding[LR_CLIENT_SIZE - 128];
310 /* bug20354: the lcd_uuid for export of clients may be wrong */
311 static inline void check_lcd(char *obd_name, int index,
312 struct lsd_client_data *lcd)
314 int length = sizeof(lcd->lcd_uuid);
315 if (strnlen((char*)lcd->lcd_uuid, length) == length) {
316 lcd->lcd_uuid[length - 1] = '\0';
318 LCONSOLE_ERROR("the client UUID (%s) on %s for exports"
319 "stored in last_rcvd(index = %d) is bad!\n",
320 lcd->lcd_uuid, obd_name, index);
324 /* last_rcvd handling */
325 static inline void lsd_le_to_cpu(struct lr_server_data *buf,
326 struct lr_server_data *lsd)
329 memcpy(lsd->lsd_uuid, buf->lsd_uuid, sizeof (lsd->lsd_uuid));
330 lsd->lsd_last_transno = le64_to_cpu(buf->lsd_last_transno);
331 lsd->lsd_compat14 = le64_to_cpu(buf->lsd_compat14);
332 lsd->lsd_mount_count = le64_to_cpu(buf->lsd_mount_count);
333 lsd->lsd_feature_compat = le32_to_cpu(buf->lsd_feature_compat);
334 lsd->lsd_feature_rocompat = le32_to_cpu(buf->lsd_feature_rocompat);
335 lsd->lsd_feature_incompat = le32_to_cpu(buf->lsd_feature_incompat);
336 lsd->lsd_server_size = le32_to_cpu(buf->lsd_server_size);
337 lsd->lsd_client_start = le32_to_cpu(buf->lsd_client_start);
338 lsd->lsd_client_size = le16_to_cpu(buf->lsd_client_size);
339 lsd->lsd_subdir_count = le16_to_cpu(buf->lsd_subdir_count);
340 lsd->lsd_catalog_oid = le64_to_cpu(buf->lsd_catalog_oid);
341 lsd->lsd_catalog_ogen = le32_to_cpu(buf->lsd_catalog_ogen);
342 memcpy(lsd->lsd_peeruuid, buf->lsd_peeruuid, sizeof(lsd->lsd_peeruuid));
343 lsd->lsd_ost_index = le32_to_cpu(buf->lsd_ost_index);
344 lsd->lsd_mdt_index = le32_to_cpu(buf->lsd_mdt_index);
345 lsd->lsd_start_epoch = le32_to_cpu(buf->lsd_start_epoch);
346 for (i = 0; i < LR_EXPIRE_INTERVALS; i++)
347 lsd->lsd_trans_table[i] = le64_to_cpu(buf->lsd_trans_table[i]);
348 lsd->lsd_trans_table_time = le32_to_cpu(buf->lsd_trans_table_time);
349 lsd->lsd_expire_intervals = le32_to_cpu(buf->lsd_expire_intervals);
352 static inline void lsd_cpu_to_le(struct lr_server_data *lsd,
353 struct lr_server_data *buf)
356 memcpy(buf->lsd_uuid, lsd->lsd_uuid, sizeof (buf->lsd_uuid));
357 buf->lsd_last_transno = cpu_to_le64(lsd->lsd_last_transno);
358 buf->lsd_compat14 = cpu_to_le64(lsd->lsd_compat14);
359 buf->lsd_mount_count = cpu_to_le64(lsd->lsd_mount_count);
360 buf->lsd_feature_compat = cpu_to_le32(lsd->lsd_feature_compat);
361 buf->lsd_feature_rocompat = cpu_to_le32(lsd->lsd_feature_rocompat);
362 buf->lsd_feature_incompat = cpu_to_le32(lsd->lsd_feature_incompat);
363 buf->lsd_server_size = cpu_to_le32(lsd->lsd_server_size);
364 buf->lsd_client_start = cpu_to_le32(lsd->lsd_client_start);
365 buf->lsd_client_size = cpu_to_le16(lsd->lsd_client_size);
366 buf->lsd_subdir_count = cpu_to_le16(lsd->lsd_subdir_count);
367 buf->lsd_catalog_oid = cpu_to_le64(lsd->lsd_catalog_oid);
368 buf->lsd_catalog_ogen = cpu_to_le32(lsd->lsd_catalog_ogen);
369 memcpy(buf->lsd_peeruuid, lsd->lsd_peeruuid, sizeof(buf->lsd_peeruuid));
370 buf->lsd_ost_index = cpu_to_le32(lsd->lsd_ost_index);
371 buf->lsd_mdt_index = cpu_to_le32(lsd->lsd_mdt_index);
372 buf->lsd_start_epoch = cpu_to_le32(lsd->lsd_start_epoch);
373 for (i = 0; i < LR_EXPIRE_INTERVALS; i++)
374 buf->lsd_trans_table[i] = cpu_to_le64(lsd->lsd_trans_table[i]);
375 buf->lsd_trans_table_time = cpu_to_le32(lsd->lsd_trans_table_time);
376 buf->lsd_expire_intervals = cpu_to_le32(lsd->lsd_expire_intervals);
379 static inline void lcd_le_to_cpu(struct lsd_client_data *buf,
380 struct lsd_client_data *lcd)
382 memcpy(lcd->lcd_uuid, buf->lcd_uuid, sizeof (lcd->lcd_uuid));
383 lcd->lcd_last_transno = le64_to_cpu(buf->lcd_last_transno);
384 lcd->lcd_last_xid = le64_to_cpu(buf->lcd_last_xid);
385 lcd->lcd_last_result = le32_to_cpu(buf->lcd_last_result);
386 lcd->lcd_last_data = le32_to_cpu(buf->lcd_last_data);
387 lcd->lcd_last_close_transno = le64_to_cpu(buf->lcd_last_close_transno);
388 lcd->lcd_last_close_xid = le64_to_cpu(buf->lcd_last_close_xid);
389 lcd->lcd_last_close_result = le32_to_cpu(buf->lcd_last_close_result);
390 lcd->lcd_last_close_data = le32_to_cpu(buf->lcd_last_close_data);
391 lcd->lcd_pre_versions[0] = le64_to_cpu(buf->lcd_pre_versions[0]);
392 lcd->lcd_pre_versions[1] = le64_to_cpu(buf->lcd_pre_versions[1]);
393 lcd->lcd_pre_versions[2] = le64_to_cpu(buf->lcd_pre_versions[2]);
394 lcd->lcd_pre_versions[3] = le64_to_cpu(buf->lcd_pre_versions[3]);
395 lcd->lcd_last_epoch = le32_to_cpu(buf->lcd_last_epoch);
396 lcd->lcd_first_epoch = le32_to_cpu(buf->lcd_first_epoch);
399 static inline void lcd_cpu_to_le(struct lsd_client_data *lcd,
400 struct lsd_client_data *buf)
402 memcpy(buf->lcd_uuid, lcd->lcd_uuid, sizeof (lcd->lcd_uuid));
403 buf->lcd_last_transno = cpu_to_le64(lcd->lcd_last_transno);
404 buf->lcd_last_xid = cpu_to_le64(lcd->lcd_last_xid);
405 buf->lcd_last_result = cpu_to_le32(lcd->lcd_last_result);
406 buf->lcd_last_data = cpu_to_le32(lcd->lcd_last_data);
407 buf->lcd_last_close_transno = cpu_to_le64(lcd->lcd_last_close_transno);
408 buf->lcd_last_close_xid = cpu_to_le64(lcd->lcd_last_close_xid);
409 buf->lcd_last_close_result = cpu_to_le32(lcd->lcd_last_close_result);
410 buf->lcd_last_close_data = cpu_to_le32(lcd->lcd_last_close_data);
411 buf->lcd_pre_versions[0] = cpu_to_le64(lcd->lcd_pre_versions[0]);
412 buf->lcd_pre_versions[1] = cpu_to_le64(lcd->lcd_pre_versions[1]);
413 buf->lcd_pre_versions[2] = cpu_to_le64(lcd->lcd_pre_versions[2]);
414 buf->lcd_pre_versions[3] = cpu_to_le64(lcd->lcd_pre_versions[3]);
415 buf->lcd_last_epoch = cpu_to_le32(lcd->lcd_last_epoch);
416 buf->lcd_first_epoch = cpu_to_le32(lcd->lcd_first_epoch);
419 static inline __u64 lcd_last_transno(struct lsd_client_data *lcd)
421 return (lcd->lcd_last_transno > lcd->lcd_last_close_transno ?
422 lcd->lcd_last_transno : lcd->lcd_last_close_transno);
425 static inline __u64 lcd_last_xid(struct lsd_client_data *lcd)
427 return (lcd->lcd_last_xid > lcd->lcd_last_close_xid ?
428 lcd->lcd_last_xid : lcd->lcd_last_close_xid);
431 /****************** superblock additional info *********************/
436 struct lustre_sb_info {
438 struct obd_device *lsi_mgc; /* mgc obd */
439 struct lustre_mount_data *lsi_lmd; /* mount command info */
440 struct lustre_disk_data *lsi_ldd; /* mount info on-disk */
441 struct ll_sb_info *lsi_llsbi; /* add'l client sbi info */
442 struct vfsmount *lsi_srv_mnt; /* the one server mount */
443 cfs_atomic_t lsi_mounts; /* references to the srv_mnt */
444 struct backing_dev_info lsi_bdi; /* each client mountpoint needs own backing_dev_info */
447 #define LSI_SERVER 0x00000001
448 #define LSI_UMOUNT_FORCE 0x00000010
449 #define LSI_UMOUNT_FAILOVER 0x00000020
450 #define LSI_BDI_INITIALIZED 0x00000040
452 #define s2lsi(sb) ((struct lustre_sb_info *)((sb)->s_fs_info))
453 #define s2lsi_nocast(sb) ((sb)->s_fs_info)
455 #define get_profile_name(sb) (s2lsi(sb)->lsi_lmd->lmd_profile)
457 #endif /* __KERNEL__ */
459 /****************** mount lookup info *********************/
461 struct lustre_mount_info {
463 struct super_block *lmi_sb;
464 struct vfsmount *lmi_mnt;
465 cfs_list_t lmi_list_chain;
468 /****************** prototypes *********************/
473 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
474 struct vfsmount *mnt));
475 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb));
478 int lustre_common_put_super(struct super_block *sb);
479 struct lustre_mount_info *server_find_mount_locked(const char *name);
480 struct lustre_mount_info *server_get_mount(const char *name);
481 struct lustre_mount_info *server_get_mount_2(const char *name);
482 int server_put_mount(const char *name, struct vfsmount *mnt);
483 int server_put_mount_2(const char *name, struct vfsmount *mnt);
484 int server_register_target(struct super_block *sb);
485 struct mgs_target_info;
486 int server_mti_print(char *title, struct mgs_target_info *mti);
489 int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id);
495 #endif // _LUSTRE_DISK_H