Whamcloud - gitweb
LU-17705 ptlrpc: replace synchronize_rcu() with rcu_barrier()
[fs/lustre-release.git] / lustre / utils / mount_utils.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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 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
33 #ifndef _MOUNT_UTILS_H_
34 #define _MOUNT_UTILS_H_
35
36 /* Some of the userland headers for libzfs also require
37  * zfs/spl linux kernel headers, but including these pull
38  * in linux kernel headers which conflicts with the
39  * userland version of libcfs. So the solution is tell the
40  * libzfs user land headrs that the zfs/spl kernel headers
41  * are already included even if this is not the case.
42  */
43 #ifdef HAVE_ZFS_OSD
44 #define _SPL_ZFS_H
45 #define _SPL_SIGNAL_H
46 #endif
47 #include <ctype.h>
48 #include <errno.h>
49 #include <fcntl.h>
50 #include <limits.h>
51 #include <stdbool.h>
52 #include <stdlib.h>
53 #include <string.h>
54 #include <sys/types.h>
55 #include <sys/stat.h>
56
57 #include <libcfs/util/list.h>
58 #include <linux/lustre/lustre_param.h>
59 #ifdef HAVE_SERVER_SUPPORT
60 #include <linux/lustre/lustre_disk.h>
61 #endif
62
63 extern char *progname;
64 extern int verbose;
65 extern int failover;
66
67 #define vprint(fmt, arg...) if (verbose > 0) printf(fmt, ##arg)
68 #define verrprint(fmt, arg...) if (verbose >= 0) fprintf(stderr, fmt, ##arg)
69
70 /* mo_flags */
71 #define MO_IS_LOOP              0x01
72 #define MO_FORCEFORMAT          0x02
73 #define MO_FAILOVER             0x04
74 #define MO_DRYRUN               0x08
75 #define MO_QUOTA                0x10
76 #define MO_NOHOSTID_CHECK       0x20
77 #define MO_RENAME               0x40
78 #define MO_ERASE_ALL            0x80
79
80 #define MAX_LOOP_DEVICES        16
81 #define INDEX_UNASSIGNED        0xFFFF
82
83 /* Maximum length of on-disk parameters in the form key=<value> */
84 #define PARAM_MAX               4096
85
86 #ifdef HAVE_SERVER_SUPPORT
87 /* On-disk configuration file. In host-endian order. */
88 struct lustre_disk_data {
89         __u32 ldd_magic;
90         __u32 ldd_feature_compat;       /* compatible feature flags */
91         __u32 ldd_feature_rocompat;     /* read-only compatible feature flags */
92         __u32 ldd_feature_incompat;     /* incompatible feature flags */
93
94         __u32 ldd_config_ver;           /* config rewrite count - not used */
95         __u32 ldd_flags;                /* LDD_SV_TYPE */
96         __u32 ldd_svindex;              /* server index (0001), must match
97                                          * svname
98                                          */
99         __u32 ldd_mount_type;           /* target fs type LDD_MT_* */
100         char  ldd_fsname[64];           /* filesystem this server is part of,
101                                          * MTI_NAME_MAXLEN
102                                          */
103         char  ldd_svname[64];           /* this server's name (lustre-mdt0001)*/
104         __u8  ldd_uuid[40];             /* server UUID (COMPAT_146) */
105
106         char  ldd_userdata[1024 - 200]; /* arbitrary user string '200' */
107         __u8  ldd_padding[4096 - 1024]; /* 1024 */
108         char  ldd_mount_opts[4096];     /* target fs mount opts '4096' */
109         char  ldd_params[4096];         /* key=value pairs '8192' */
110 };
111
112 /* used to describe the options to format the lustre disk, not persistent */
113 struct mkfs_opts {
114         struct lustre_disk_data mo_ldd; /* to be written in MOUNT_DATA_FILE */
115         char            mo_device[128];   /* disk device name */
116         char            **mo_pool_vdevs;  /* list of pool vdevs */
117         char            mo_loopdev[128];  /* in case a loop dev is needed */
118         char            mo_mkfsopts[512]; /* options for backing-store mkfs */
119         char            *mo_mountopts;    /* mount options for backing fs */
120         long long       mo_device_kb;     /* in KB */
121         int             mo_blocksize_kb;  /* blocksize in KB */
122         int             mo_stripe_count;
123         int             mo_flags;
124         int             mo_mgs_failnodes;
125         int             mo_inode_size;
126 };
127 #endif
128
129 /* used to describe the options to mount the lustre disk */
130 struct mount_opts {
131 #ifdef HAVE_SERVER_SUPPORT
132         struct lustre_disk_data  mo_ldd;
133 #endif
134         char    *mo_orig_options;
135         char    *mo_usource;            /* user-specified mount device */
136         char    *mo_source;             /* our mount device name */
137         char     mo_target[PATH_MAX];   /* mount directory */
138 #ifdef HAVE_GSS
139         char     mo_skpath[PATH_MAX];   /* shared key file/directory */
140 #endif
141         int      mo_nomtab;
142         int      mo_fake;
143         int      mo_force;
144         int      mo_retry;
145         int      mo_have_mgsnid;
146         int      mo_md_stripe_cache_size;
147         int      mo_nosvc;
148         int      mo_max_sectors_kb;
149 };
150
151 #ifdef HAVE_SERVER_SUPPORT
152 int get_mountdata(char *, struct lustre_disk_data *);
153
154 static inline const char *mt_str(enum ldd_mount_type mt)
155 {
156         static const char * const mount_type_string[] = {
157                 "ext3",
158                 "ldiskfs",
159                 "smfs",
160                 "reiserfs",
161                 "ldiskfs2",
162                 "zfs",
163         };
164         return mount_type_string[mt];
165 }
166
167 static inline const char *mt_type(enum ldd_mount_type mt)
168 {
169         static const char * const mount_type_string[] = {
170                 "osd-ldiskfs",
171                 "osd-ldiskfs",
172                 "osd-smfs",
173                 "osd-reiserfs",
174                 "osd-ldiskfs",
175                 "osd-zfs",
176         };
177         return mount_type_string[mt];
178 }
179 #endif /* HAVE_SERVER_SUPPORT */
180
181 #define MT_STR(data)   mt_str((data)->ldd_mount_type)
182
183 #define IS_MDT(data)   ((data)->ldd_flags & LDD_F_SV_TYPE_MDT)
184 #define IS_OST(data)   ((data)->ldd_flags & LDD_F_SV_TYPE_OST)
185 #define IS_MGS(data)  ((data)->ldd_flags & LDD_F_SV_TYPE_MGS)
186 #define IS_SEPARATED_MGS(data)  ((data)->ldd_flags == LDD_F_SV_TYPE_MGS)
187 #define IS_SERVER(data) ((data)->ldd_flags & (LDD_F_SV_TYPE_MGS | \
188                           LDD_F_SV_TYPE_MDT | LDD_F_SV_TYPE_OST))
189
190
191 /* mkfs/mount helper functions */
192 void fatal(void);
193 int run_command_err(char *cmd, int cmdsz, char *error_msg);
194 int run_command(char *cmd, int cmdsz);
195 int add_param(char *buf, char *key, char *val);
196 int append_param(char *buf, char *key, char *val, char sep);
197 int get_param(char *buf, char *key, char **val);
198 char *strscat(char *dst, char *src, int buflen);
199 char *strscpy(char *dst, char *src, int buflen);
200 int check_mtab_entry(char *spec1, char *spec2, char *mntpt, char *type);
201 int update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
202                       int flags, int freq, int pass);
203 int update_utab_entry(struct mount_opts *mop);
204 int check_mountfsoptions(char *mountopts, char *wanted_mountopts);
205 void trim_mountfsoptions(char *s);
206 #ifdef HAVE_SERVER_SUPPORT
207 __u64 get_device_size(char* device);
208 int lustre_rename_fsname(struct mkfs_opts *mop, const char *mntpt,
209                          const char *oldname);
210
211 /* loopback helper functions */
212 int file_create(char *path, __u64 size);
213 int loop_format(struct mkfs_opts *mop);
214 int loop_setup(struct mkfs_opts *mop);
215 int loop_cleanup(struct mkfs_opts *mop);
216
217 /* generic target support */
218 int osd_write_ldd(struct mkfs_opts *mop);
219 int osd_read_ldd(char *dev, struct lustre_disk_data *ldd);
220 int osd_erase_ldd(struct mkfs_opts *mop, char *param);
221 void osd_print_ldd_params(struct mkfs_opts *mop);
222 int osd_is_lustre(char *dev, unsigned *mount_type);
223 int osd_make_lustre(struct mkfs_opts *mop);
224 int osd_prepare_lustre(struct mkfs_opts *mop,
225                        char *wanted_mountopts, size_t len);
226 int osd_fix_mountopts(struct mkfs_opts *mop, char *mountopts, size_t len);
227 int osd_tune_lustre(char *dev, struct mount_opts *mop);
228 int osd_label_lustre(struct mount_opts *mop);
229 int osd_rename_fsname(struct mkfs_opts *mop, const char *oldname);
230 int osd_enable_quota(struct mkfs_opts *mop);
231 int osd_init(void);
232 void osd_fini(void);
233
234 struct module_backfs_ops {
235         int     (*init)(void);
236         void    (*fini)(void);
237         int     (*read_ldd)(char *ds,  struct lustre_disk_data *ldd);
238         int     (*write_ldd)(struct mkfs_opts *mop);
239         int     (*erase_ldd)(struct mkfs_opts *mop, char *param);
240         void    (*print_ldd_params)(struct mkfs_opts *mop);
241         int     (*is_lustre)(char *dev, enum ldd_mount_type *mount_type);
242         int     (*make_lustre)(struct mkfs_opts *mop);
243         int     (*prepare_lustre)(struct mkfs_opts *mop,
244                                   char *wanted_mountopts, size_t len);
245         int     (*fix_mountopts)(struct mkfs_opts *mop,
246                                  char *mountopts, size_t len);
247         int     (*tune_lustre)(char *dev, struct mount_opts *mop);
248         int     (*label_lustre)(struct mount_opts *mop);
249         int     (*enable_quota)(struct mkfs_opts *mop);
250         int     (*rename_fsname)(struct mkfs_opts *mop, const char *oldname);
251         void   *dl_handle;
252 };
253
254 struct module_backfs_ops zfs_ops;
255 struct module_backfs_ops ldiskfs_ops;
256
257 struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type);
258 void unload_backfs_ops(struct module_backfs_ops *ops);
259 #endif
260
261 #ifdef HAVE_OPENSSL_SSK
262 int load_shared_keys(struct mount_opts *mop);
263 #else
264 static inline int load_shared_keys(struct mount_opts *mop)
265 {
266         return EOPNOTSUPP;
267 }
268 #endif
269 #endif