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