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