4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #ifndef _MOUNT_UTILS_H_
34 #define _MOUNT_UTILS_H_
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.
54 #include <sys/types.h>
57 #include <libcfs/util/list.h>
58 #include <lustre_disk.h>
59 #include <lustre_param.h>
61 extern char *progname;
65 #define vprint(fmt, arg...) if (verbose > 0) printf(fmt, ##arg)
66 #define verrprint(fmt, arg...) if (verbose >= 0) fprintf(stderr, fmt, ##arg)
69 #define MO_IS_LOOP 0x01
70 #define MO_FORCEFORMAT 0x02
71 #define MO_FAILOVER 0x04
72 #define MO_DRYRUN 0x08
74 #define MO_NOHOSTID_CHECK 0x20
75 #define MO_RENAME 0x40
76 #define MO_ERASE_ALL 0x80
78 #define MAX_LOOP_DEVICES 16
79 #define INDEX_UNASSIGNED 0xFFFF
81 /* Maximum length of on-disk parameters in the form key=<value> */
82 #define PARAM_MAX 4096
84 /* used to describe the options to format the lustre disk, not persistent */
86 struct lustre_disk_data mo_ldd; /* to be written in MOUNT_DATA_FILE */
87 char mo_device[128]; /* disk device name */
88 char **mo_pool_vdevs; /* list of pool vdevs */
89 char mo_loopdev[128]; /* in case a loop dev is needed */
90 char mo_mkfsopts[512]; /* options to the backing-store mkfs */
91 char *mo_mountopts; /* mount options for backing fs */
92 __u64 mo_device_kb; /* in KB */
98 /* used to describe the options to mount the lustre disk */
100 struct lustre_disk_data mo_ldd;
101 char *mo_orig_options;
102 char *mo_usource; /* user-specified mount device */
103 char *mo_source; /* our mount device name */
104 char mo_target[PATH_MAX]; /* mount directory */
106 char mo_skpath[PATH_MAX]; /* shared key file/directory */
113 int mo_md_stripe_cache_size;
115 int mo_max_sectors_kb;
118 int get_mountdata(char *, struct lustre_disk_data *);
120 #define MT_STR(data) mt_str((data)->ldd_mount_type)
123 #define IS_MDT(data) ((data)->ldd_flags & LDD_F_SV_TYPE_MDT)
125 #define IS_OST(data) ((data)->ldd_flags & LDD_F_SV_TYPE_OST)
127 #define IS_MGS(data) ((data)->ldd_flags & LDD_F_SV_TYPE_MGS)
129 #define IS_SERVER(data) ((data)->ldd_flags & (LDD_F_SV_TYPE_MGS | \
130 LDD_F_SV_TYPE_MDT | LDD_F_SV_TYPE_OST))
133 /* mkfs/mount helper functions */
135 int run_command_err(char *cmd, int cmdsz, char *error_msg);
136 int run_command(char *cmd, int cmdsz);
137 int add_param(char *buf, char *key, char *val);
138 int append_param(char *buf, char *key, char *val, char sep);
139 int get_param(char *buf, char *key, char **val);
140 char *strscat(char *dst, char *src, int buflen);
141 char *strscpy(char *dst, char *src, int buflen);
142 int check_mtab_entry(char *spec1, char *spec2, char *mntpt, char *type);
143 int update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
144 int flags, int freq, int pass);
145 int update_utab_entry(struct mount_opts *mop);
146 int check_mountfsoptions(char *mountopts, char *wanted_mountopts);
147 void trim_mountfsoptions(char *s);
148 __u64 get_device_size(char* device);
149 int lustre_rename_fsname(struct mkfs_opts *mop, const char *mntpt,
150 const char *oldname);
152 /* loopback helper functions */
153 int file_create(char *path, __u64 size);
154 int loop_format(struct mkfs_opts *mop);
155 int loop_setup(struct mkfs_opts *mop);
156 int loop_cleanup(struct mkfs_opts *mop);
158 /* generic target support */
159 int osd_write_ldd(struct mkfs_opts *mop);
160 int osd_read_ldd(char *dev, struct lustre_disk_data *ldd);
161 int osd_erase_ldd(struct mkfs_opts *mop, char *param);
162 void osd_print_ldd_params(struct mkfs_opts *mop);
163 int osd_is_lustre(char *dev, unsigned *mount_type);
164 int osd_make_lustre(struct mkfs_opts *mop);
165 int osd_prepare_lustre(struct mkfs_opts *mop,
166 char *wanted_mountopts, size_t len);
167 int osd_fix_mountopts(struct mkfs_opts *mop, char *mountopts, size_t len);
168 int osd_tune_lustre(char *dev, struct mount_opts *mop);
169 int osd_label_lustre(struct mount_opts *mop);
170 int osd_rename_fsname(struct mkfs_opts *mop, const char *oldname);
171 int osd_enable_quota(struct mkfs_opts *mop);
175 struct module_backfs_ops {
178 int (*read_ldd)(char *ds, struct lustre_disk_data *ldd);
179 int (*write_ldd)(struct mkfs_opts *mop);
180 int (*erase_ldd)(struct mkfs_opts *mop, char *param);
181 void (*print_ldd_params)(struct mkfs_opts *mop);
182 int (*is_lustre)(char *dev, enum ldd_mount_type *mount_type);
183 int (*make_lustre)(struct mkfs_opts *mop);
184 int (*prepare_lustre)(struct mkfs_opts *mop,
185 char *wanted_mountopts, size_t len);
186 int (*fix_mountopts)(struct mkfs_opts *mop,
187 char *mountopts, size_t len);
188 int (*tune_lustre)(char *dev, struct mount_opts *mop);
189 int (*label_lustre)(struct mount_opts *mop);
190 int (*enable_quota)(struct mkfs_opts *mop);
191 int (*rename_fsname)(struct mkfs_opts *mop, const char *oldname);
195 struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type);
196 void unload_backfs_ops(struct module_backfs_ops *ops);
197 #ifdef HAVE_OPENSSL_SSK
198 int load_shared_keys(struct mount_opts *mop);
200 static inline int load_shared_keys(struct mount_opts *mop)