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