Whamcloud - gitweb
LU-12546 mdt: abort recovery between MDTs
[fs/lustre-release.git] / lustre / include / lustre_disk.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/include/lustre_disk.h
33  *
34  * Lustre disk format definitions.
35  *
36  * Author: Nathan Rutman <nathan@clusterfs.com>
37  */
38
39 #ifndef _LUSTRE_DISK_H
40 #define _LUSTRE_DISK_H
41
42 /** \defgroup disk disk
43  *
44  * @{
45  */
46 #include <asm/byteorder.h>
47 #include <linux/types.h>
48 #include <linux/backing-dev.h>
49 #include <linux/list.h>
50 #include <libcfs/libcfs.h>
51 #include <uapi/linux/lustre/lustre_disk.h>
52 #include <uapi/linux/lustre/lustre_idl.h>
53
54 #define IS_MDT(data)            ((data)->lsi_flags & LDD_F_SV_TYPE_MDT)
55 #define IS_OST(data)            ((data)->lsi_flags & LDD_F_SV_TYPE_OST)
56 #define IS_MGS(data)            ((data)->lsi_flags & LDD_F_SV_TYPE_MGS)
57 #define IS_SERVER(data)         ((data)->lsi_flags & (LDD_F_SV_TYPE_MGS | \
58                                                       LDD_F_SV_TYPE_MDT | \
59                                                       LDD_F_SV_TYPE_OST))
60 #define MT_STR(data)            mt_str((data)->ldd_mount_type)
61
62 /****************** mount command *********************/
63
64 /* The lmd is only used internally by Lustre; mount simply passes
65  * everything as string options
66  */
67 #define LMD_MAGIC               0xbdacbd03
68 #define LMD_PARAMS_MAXLEN       4096
69
70 /* gleaned from the mount command - no persistent info here */
71 struct lustre_mount_data {
72         u32     lmd_magic;
73         u32     lmd_flags;      /* lustre mount flags */
74         int     lmd_mgs_failnodes; /* mgs failover node count */
75         int     lmd_exclude_count;
76         int     lmd_recovery_time_soft;
77         int     lmd_recovery_time_hard;
78         char   *lmd_dev;        /* device name */
79         char   *lmd_profile;    /* client only */
80         char   *lmd_fileset;    /* mount fileset */
81         char   *lmd_mgssec;     /* sptlrpc flavor to mgs */
82         char   *lmd_opts;       /* lustre mount options (as opposed to
83                                  * device_ mount options) */
84         char   *lmd_params;     /* lustre params */
85         u32    *lmd_exclude;    /* array of OSTs to ignore */
86         char   *lmd_mgs;        /* MGS nid */
87         char   *lmd_osd_type;   /* OSD type */
88         char   *lmd_nidnet;     /* network to restrict this client to */
89 };
90
91 #define LMD_FLG_SERVER          0x0001  /* Mounting a server */
92 #define LMD_FLG_CLIENT          0x0002  /* Mounting a client */
93 #define LMD_FLG_SKIP_LFSCK      0x0004  /* NOT auto resume LFSCK when mount */
94 #define LMD_FLG_ABORT_RECOV     0x0008  /* Abort recovery */
95 #define LMD_FLG_NOSVC           0x0010  /* Only start MGS/MGC for servers,
96                                            no other services */
97 #define LMD_FLG_NOMGS           0x0020  /* Only start target for servers, reusing
98                                            existing MGS services */
99 #define LMD_FLG_WRITECONF       0x0040  /* Rewrite config log */
100 #define LMD_FLG_NOIR            0x0080  /* NO imperative recovery */
101 #define LMD_FLG_NOSCRUB         0x0100  /* Do not trigger scrub automatically */
102 #define LMD_FLG_MGS             0x0200  /* Also start MGS along with server */
103 #define LMD_FLG_IAM             0x0400  /* IAM dir */
104 #define LMD_FLG_NO_PRIMNODE     0x0800  /* all nodes are service nodes */
105 #define LMD_FLG_VIRGIN          0x1000  /* the service registers first time */
106 #define LMD_FLG_UPDATE          0x2000  /* update parameters */
107 #define LMD_FLG_HSM             0x4000  /* Start coordinator */
108 #define LMD_FLG_DEV_RDONLY      0x8000  /* discard modification quitely */
109 #define LMD_FLG_NO_PRECREATE    0x10000 /* do not allow OST object creation */
110 #define LMD_FLG_LOCAL_RECOV     0x20000 /* force recovery for local clients */
111 #define LMD_FLG_ABORT_RECOV_MDT 0x40000 /* Abort recovery between MDTs */
112
113 #define lmd_is_client(x) ((x)->lmd_flags & LMD_FLG_CLIENT)
114
115 /****************** superblock additional info *********************/
116 struct ll_sb_info;
117 struct kobject;
118
119 struct lustre_sb_info {
120         int                       lsi_flags;
121         struct obd_device        *lsi_mgc;     /* mgc obd */
122         struct lustre_mount_data *lsi_lmd;     /* mount command info */
123         struct ll_sb_info        *lsi_llsbi;   /* add'l client sbi info */
124         struct dt_device         *lsi_dt_dev;  /* dt device to access disk fs*/
125         atomic_t                  lsi_mounts;  /* references to the srv_mnt */
126         struct kobject           *lsi_kobj;
127         char                      lsi_svname[MTI_NAME_MAXLEN];
128         /* lsi_osd_obdname format = 'lsi->ls_svname'-osd */
129         char                      lsi_osd_obdname[MTI_NAME_MAXLEN + 4];
130         /* lsi_osd_uuid format = 'lsi->ls_osd_obdname'_UUID */
131         char                      lsi_osd_uuid[MTI_NAME_MAXLEN + 9];
132         struct obd_export        *lsi_osd_exp;
133         char                      lsi_osd_type[16];
134         char                      lsi_fstype[16];
135         struct backing_dev_info   lsi_bdi;     /* each client mountpoint needs
136                                                   own backing_dev_info */
137         /* protect lsi_lwp_list */
138         struct mutex              lsi_lwp_mutex;
139         struct list_head          lsi_lwp_list;
140         unsigned long             lsi_lwp_started:1,
141                                   lsi_server_started:1;
142 #ifdef CONFIG_LL_ENCRYPTION
143         const struct llcrypt_operations *lsi_cop;
144         struct key               *lsi_master_keys; /* master crypto keys used */
145 #endif
146 };
147
148 #define LSI_UMOUNT_FAILOVER              0x00200000
149
150 #define     s2lsi(sb)        ((struct lustre_sb_info *)((sb)->s_fs_info))
151 #define     s2lsi_nocast(sb) ((sb)->s_fs_info)
152
153 #define     get_profile_name(sb)   (s2lsi(sb)->lsi_lmd->lmd_profile)
154 #define     get_mount_fileset(sb)  (s2lsi(sb)->lsi_lmd->lmd_fileset)
155
156 # ifdef HAVE_SERVER_SUPPORT
157 /* opc for target register */
158 #define LDD_F_OPC_REG   0x10000000
159 #define LDD_F_OPC_UNREG 0x20000000
160 #define LDD_F_OPC_READY 0x40000000
161 #define LDD_F_OPC_MASK  0xf0000000
162
163 #define LDD_F_MASK      0xFFFF
164
165 /*
166  * This limit is arbitrary (131072 clients on x86), but it is convenient to use
167  * 2^n * PAGE_SIZE * 8 for the number of bits that fit an order-n allocation.
168  * If we need more than 131072 clients (order-2 allocation on x86) then this
169  * should become an array of single-page pointers that are allocated on demand.
170  */
171 #if (128 * 1024UL) > (PAGE_SIZE * 8)
172 #define LR_MAX_CLIENTS (128 * 1024UL)
173 #else
174 #define LR_MAX_CLIENTS (PAGE_SIZE * 8)
175 #endif
176
177 /** COMPAT_146: this is an OST (temporary) */
178 #define OBD_COMPAT_OST          0x00000002
179 /** COMPAT_146: this is an MDT (temporary) */
180 #define OBD_COMPAT_MDT          0x00000004
181 /** 2.0 server, interop flag to show server version is changed */
182 #define OBD_COMPAT_20           0x00000008
183
184 /** MDS handles LOV_OBJID file */
185 #define OBD_ROCOMPAT_LOVOBJID           0x00000001
186 /** store OST index in the IDIF */
187 #define OBD_ROCOMPAT_IDX_IN_IDIF        0x00000002
188
189 /** OST handles group subdirs */
190 #define OBD_INCOMPAT_GROUPS     0x00000001
191 /** this is an OST */
192 #define OBD_INCOMPAT_OST        0x00000002
193 /** this is an MDT */
194 #define OBD_INCOMPAT_MDT        0x00000004
195 /** common last_rvcd format */
196 #define OBD_INCOMPAT_COMMON_LR  0x00000008
197 /** FID is enabled */
198 #define OBD_INCOMPAT_FID        0x00000010
199 /** Size-on-MDS is enabled */
200 #define OBD_INCOMPAT_SOM        0x00000020
201 /** filesystem using iam format to store directory entries */
202 #define OBD_INCOMPAT_IAM_DIR    0x00000040
203 /** LMA attribute contains per-inode incompatible flags */
204 #define OBD_INCOMPAT_LMA        0x00000080
205 /** lmm_stripe_count has been shrunk from u32 to u16 and the remaining 16
206  * bits are now used to store a generation. Once we start changing the layout
207  * and bumping the generation, old versions expecting a 32-bit lmm_stripe_count
208  * will be confused by interpreting stripe_count | gen << 16 as the actual
209  * stripe count */
210 #define OBD_INCOMPAT_LMM_VER    0x00000100
211 /** multiple OI files for MDT */
212 #define OBD_INCOMPAT_MULTI_OI   0x00000200
213 /** multiple RPCs in flight */
214 #define OBD_INCOMPAT_MULTI_RPCS 0x00000400
215
216 /* last_rcvd handling */
217 static inline void lsd_le_to_cpu(struct lr_server_data *buf,
218                                  struct lr_server_data *lsd)
219 {
220         int i;
221
222         memcpy(lsd->lsd_uuid, buf->lsd_uuid, sizeof(lsd->lsd_uuid));
223         lsd->lsd_last_transno = le64_to_cpu(buf->lsd_last_transno);
224         lsd->lsd_compat14 = le64_to_cpu(buf->lsd_compat14);
225         lsd->lsd_mount_count = le64_to_cpu(buf->lsd_mount_count);
226         lsd->lsd_feature_compat = le32_to_cpu(buf->lsd_feature_compat);
227         lsd->lsd_feature_rocompat = le32_to_cpu(buf->lsd_feature_rocompat);
228         lsd->lsd_feature_incompat = le32_to_cpu(buf->lsd_feature_incompat);
229         lsd->lsd_server_size = le32_to_cpu(buf->lsd_server_size);
230         lsd->lsd_client_start = le32_to_cpu(buf->lsd_client_start);
231         lsd->lsd_client_size = le16_to_cpu(buf->lsd_client_size);
232         lsd->lsd_subdir_count = le16_to_cpu(buf->lsd_subdir_count);
233         lsd->lsd_catalog_oid = le64_to_cpu(buf->lsd_catalog_oid);
234         lsd->lsd_catalog_ogen = le32_to_cpu(buf->lsd_catalog_ogen);
235         memcpy(lsd->lsd_peeruuid, buf->lsd_peeruuid, sizeof(lsd->lsd_peeruuid));
236         lsd->lsd_osd_index = le32_to_cpu(buf->lsd_osd_index);
237         lsd->lsd_padding1 = le32_to_cpu(buf->lsd_padding1);
238         lsd->lsd_start_epoch = le32_to_cpu(buf->lsd_start_epoch);
239         for (i = 0; i < LR_EXPIRE_INTERVALS; i++)
240                 lsd->lsd_trans_table[i] = le64_to_cpu(buf->lsd_trans_table[i]);
241         lsd->lsd_trans_table_time = le32_to_cpu(buf->lsd_trans_table_time);
242         lsd->lsd_expire_intervals = le32_to_cpu(buf->lsd_expire_intervals);
243 }
244
245 static inline void lsd_cpu_to_le(struct lr_server_data *lsd,
246                                  struct lr_server_data *buf)
247 {
248         int i;
249
250         memcpy(buf->lsd_uuid, lsd->lsd_uuid, sizeof(buf->lsd_uuid));
251         buf->lsd_last_transno = cpu_to_le64(lsd->lsd_last_transno);
252         buf->lsd_compat14 = cpu_to_le64(lsd->lsd_compat14);
253         buf->lsd_mount_count = cpu_to_le64(lsd->lsd_mount_count);
254         buf->lsd_feature_compat = cpu_to_le32(lsd->lsd_feature_compat);
255         buf->lsd_feature_rocompat = cpu_to_le32(lsd->lsd_feature_rocompat);
256         buf->lsd_feature_incompat = cpu_to_le32(lsd->lsd_feature_incompat);
257         buf->lsd_server_size = cpu_to_le32(lsd->lsd_server_size);
258         buf->lsd_client_start = cpu_to_le32(lsd->lsd_client_start);
259         buf->lsd_client_size = cpu_to_le16(lsd->lsd_client_size);
260         buf->lsd_subdir_count = cpu_to_le16(lsd->lsd_subdir_count);
261         buf->lsd_catalog_oid = cpu_to_le64(lsd->lsd_catalog_oid);
262         buf->lsd_catalog_ogen = cpu_to_le32(lsd->lsd_catalog_ogen);
263         memcpy(buf->lsd_peeruuid, lsd->lsd_peeruuid, sizeof(buf->lsd_peeruuid));
264         buf->lsd_osd_index = cpu_to_le32(lsd->lsd_osd_index);
265         buf->lsd_padding1 = cpu_to_le32(lsd->lsd_padding1);
266         buf->lsd_start_epoch = cpu_to_le32(lsd->lsd_start_epoch);
267         for (i = 0; i < LR_EXPIRE_INTERVALS; i++)
268                 buf->lsd_trans_table[i] = cpu_to_le64(lsd->lsd_trans_table[i]);
269         buf->lsd_trans_table_time = cpu_to_le32(lsd->lsd_trans_table_time);
270         buf->lsd_expire_intervals = cpu_to_le32(lsd->lsd_expire_intervals);
271 }
272
273 static inline void lcd_le_to_cpu(struct lsd_client_data *buf,
274                                  struct lsd_client_data *lcd)
275 {
276         memcpy(lcd->lcd_uuid, buf->lcd_uuid, sizeof (lcd->lcd_uuid));
277         lcd->lcd_last_transno = le64_to_cpu(buf->lcd_last_transno);
278         lcd->lcd_last_xid = le64_to_cpu(buf->lcd_last_xid);
279         lcd->lcd_last_result = le32_to_cpu(buf->lcd_last_result);
280         lcd->lcd_last_data = le32_to_cpu(buf->lcd_last_data);
281         lcd->lcd_last_close_transno = le64_to_cpu(buf->lcd_last_close_transno);
282         lcd->lcd_last_close_xid = le64_to_cpu(buf->lcd_last_close_xid);
283         lcd->lcd_last_close_result = le32_to_cpu(buf->lcd_last_close_result);
284         lcd->lcd_last_close_data = le32_to_cpu(buf->lcd_last_close_data);
285         lcd->lcd_pre_versions[0] = le64_to_cpu(buf->lcd_pre_versions[0]);
286         lcd->lcd_pre_versions[1] = le64_to_cpu(buf->lcd_pre_versions[1]);
287         lcd->lcd_pre_versions[2] = le64_to_cpu(buf->lcd_pre_versions[2]);
288         lcd->lcd_pre_versions[3] = le64_to_cpu(buf->lcd_pre_versions[3]);
289         lcd->lcd_last_epoch = le32_to_cpu(buf->lcd_last_epoch);
290         lcd->lcd_generation = le32_to_cpu(buf->lcd_generation);
291 }
292
293 static inline void lcd_cpu_to_le(struct lsd_client_data *lcd,
294                                  struct lsd_client_data *buf)
295 {
296         memcpy(buf->lcd_uuid, lcd->lcd_uuid, sizeof (lcd->lcd_uuid));
297         buf->lcd_last_transno = cpu_to_le64(lcd->lcd_last_transno);
298         buf->lcd_last_xid = cpu_to_le64(lcd->lcd_last_xid);
299         buf->lcd_last_result = cpu_to_le32(lcd->lcd_last_result);
300         buf->lcd_last_data = cpu_to_le32(lcd->lcd_last_data);
301         buf->lcd_last_close_transno = cpu_to_le64(lcd->lcd_last_close_transno);
302         buf->lcd_last_close_xid = cpu_to_le64(lcd->lcd_last_close_xid);
303         buf->lcd_last_close_result = cpu_to_le32(lcd->lcd_last_close_result);
304         buf->lcd_last_close_data = cpu_to_le32(lcd->lcd_last_close_data);
305         buf->lcd_pre_versions[0] = cpu_to_le64(lcd->lcd_pre_versions[0]);
306         buf->lcd_pre_versions[1] = cpu_to_le64(lcd->lcd_pre_versions[1]);
307         buf->lcd_pre_versions[2] = cpu_to_le64(lcd->lcd_pre_versions[2]);
308         buf->lcd_pre_versions[3] = cpu_to_le64(lcd->lcd_pre_versions[3]);
309         buf->lcd_last_epoch = cpu_to_le32(lcd->lcd_last_epoch);
310         buf->lcd_generation = cpu_to_le32(lcd->lcd_generation);
311 }
312
313 static inline u64 lcd_last_transno(struct lsd_client_data *lcd)
314 {
315         return (lcd->lcd_last_transno > lcd->lcd_last_close_transno ?
316                 lcd->lcd_last_transno : lcd->lcd_last_close_transno);
317 }
318
319 static inline u64 lcd_last_xid(struct lsd_client_data *lcd)
320 {
321         return (lcd->lcd_last_xid > lcd->lcd_last_close_xid ?
322                 lcd->lcd_last_xid : lcd->lcd_last_close_xid);
323 }
324
325 /****************** mount lookup info *********************/
326
327 struct lustre_mount_info {
328         char                    *lmi_name;
329         struct super_block      *lmi_sb;
330         struct list_head         lmi_list_chain;
331 };
332
333 /****************** prototypes *********************/
334
335 /* obd_mount_server.c */
336 int server_fill_super(struct super_block *sb);
337 struct lustre_mount_info *server_get_mount(const char *name);
338 int server_put_mount(const char *name, bool dereg_mnt);
339 struct mgs_target_info;
340 int server_mti_print(const char *title, struct mgs_target_info *mti);
341 void server_calc_timeout(struct lustre_sb_info *lsi, struct obd_device *obd);
342
343 /* obd_mount.c */
344 int server_name2svname(const char *label, char *svname, const char **endptr,
345                        size_t svsize);
346
347 int server_name_is_ost(const char *svname);
348 int target_name2index(const char *svname, u32 *idx, const char **endptr);
349
350 int lustre_put_lsi(struct super_block *sb);
351 int lustre_start_simple(char *obdname, char *type, char *uuid,
352                         char *s1, char *s2, char *s3, char *s4);
353 int lustre_start_mgc(struct super_block *sb);
354 #endif /* HAVE_SERVER_SUPPORT */
355 int server_name2fsname(const char *svname, char *fsname, const char **endptr);
356 void obdname2fsname(const char *tgt, char *fsname, size_t fslen);
357
358 void lustre_register_super_ops(struct module *mod,
359                                int (*cfs)(struct super_block *sb),
360                                void (*ksc)(struct super_block *sb));
361 int lustre_common_put_super(struct super_block *sb);
362
363 int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id, int type);
364 int mgc_logname2resid(char *fsname, struct ldlm_res_id *res_id, int type);
365
366 /** @} disk */
367
368 #endif /* _LUSTRE_DISK_H */