Whamcloud - gitweb
LU-8900 snapshot: rename filesysetem fsname
[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, 2016, 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 <lustre_disk.h>
59 #include <lustre_param.h>
60
61 extern char *progname;
62 extern int verbose;
63 extern int failover;
64
65 #define vprint(fmt, arg...) if (verbose > 0) printf(fmt, ##arg)
66 #define verrprint(fmt, arg...) if (verbose >= 0) fprintf(stderr, fmt, ##arg)
67
68 /* mo_flags */
69 #define MO_IS_LOOP              0x01
70 #define MO_FORCEFORMAT          0x02
71 #define MO_FAILOVER             0x04
72 #define MO_DRYRUN               0x08
73 #define MO_QUOTA                0x10
74 #define MO_NOHOSTID_CHECK       0x20
75 #define MO_RENAME               0x40
76
77 #define MAX_LOOP_DEVICES        16
78 #define INDEX_UNASSIGNED        0xFFFF
79
80 /* used to describe the options to format the lustre disk, not persistent */
81 struct mkfs_opts {
82         struct lustre_disk_data mo_ldd; /* to be written in MOUNT_DATA_FILE */
83         char    mo_device[128];   /* disk device name */
84         char    **mo_pool_vdevs;  /* list of pool vdevs */
85         char    mo_loopdev[128];  /* in case a loop dev is needed */
86         char    mo_mkfsopts[512]; /* options to the backing-store mkfs */
87         char    *mo_mountopts;    /* mount options for backing fs */
88         __u64   mo_device_kb;     /* in KB */
89         int     mo_stripe_count;
90         int     mo_flags;
91         int     mo_mgs_failnodes;
92 };
93
94 /* used to describe the options to mount the lustre disk */
95 struct mount_opts {
96         struct lustre_disk_data  mo_ldd;
97         char    *mo_orig_options;
98         char    *mo_usource;            /* user-specified mount device */
99         char    *mo_source;             /* our mount device name */
100         char     mo_target[PATH_MAX];   /* mount directory */
101 #ifdef HAVE_GSS
102         char     mo_skpath[PATH_MAX];   /* shared key file/directory */
103 #endif
104         int      mo_nomtab;
105         int      mo_fake;
106         int      mo_force;
107         int      mo_retry;
108         int      mo_have_mgsnid;
109         int      mo_md_stripe_cache_size;
110         int      mo_nosvc;
111         int      mo_max_sectors_kb;
112 };
113
114 int get_mountdata(char *, struct lustre_disk_data *);
115
116 #define MT_STR(data)   mt_str((data)->ldd_mount_type)
117
118 #undef IS_MDT
119 #define IS_MDT(data)   ((data)->ldd_flags & LDD_F_SV_TYPE_MDT)
120 #undef IS_OST
121 #define IS_OST(data)   ((data)->ldd_flags & LDD_F_SV_TYPE_OST)
122 #undef IS_MGS
123 #define IS_MGS(data)  ((data)->ldd_flags & LDD_F_SV_TYPE_MGS)
124 #undef IS_SERVER
125 #define IS_SERVER(data) ((data)->ldd_flags & (LDD_F_SV_TYPE_MGS | \
126                           LDD_F_SV_TYPE_MDT | LDD_F_SV_TYPE_OST))
127
128
129 /* mkfs/mount helper functions */
130 void fatal(void);
131 int run_command_err(char *cmd, int cmdsz, char *error_msg);
132 int run_command(char *cmd, int cmdsz);
133 int add_param(char *buf, char *key, char *val);
134 int append_param(char *buf, char *key, char *val, char sep);
135 int get_param(char *buf, char *key, char **val);
136 char *strscat(char *dst, char *src, int buflen);
137 char *strscpy(char *dst, char *src, int buflen);
138 int check_mtab_entry(char *spec1, char *spec2, char *mntpt, char *type);
139 int update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
140                       int flags, int freq, int pass);
141 int update_utab_entry(struct mount_opts *mop);
142 int check_mountfsoptions(char *mountopts, char *wanted_mountopts);
143 void trim_mountfsoptions(char *s);
144 __u64 get_device_size(char* device);
145 int lustre_rename_fsname(struct mkfs_opts *mop, const char *mntpt,
146                          const char *oldname);
147
148 /* loopback helper functions */
149 int file_create(char *path, __u64 size);
150 int loop_format(struct mkfs_opts *mop);
151 int loop_setup(struct mkfs_opts *mop);
152 int loop_cleanup(struct mkfs_opts *mop);
153
154 /* generic target support */
155 int osd_write_ldd(struct mkfs_opts *mop);
156 int osd_read_ldd(char *dev, struct lustre_disk_data *ldd);
157 int osd_is_lustre(char *dev, unsigned *mount_type);
158 int osd_make_lustre(struct mkfs_opts *mop);
159 int osd_prepare_lustre(struct mkfs_opts *mop,
160                        char *wanted_mountopts, size_t len);
161 int osd_fix_mountopts(struct mkfs_opts *mop, char *mountopts, size_t len);
162 int osd_tune_lustre(char *dev, struct mount_opts *mop);
163 int osd_label_lustre(struct mount_opts *mop);
164 int osd_rename_fsname(struct mkfs_opts *mop, const char *oldname);
165 int osd_enable_quota(struct mkfs_opts *mop);
166 int osd_init(void);
167 void osd_fini(void);
168
169 struct module_backfs_ops {
170         int     (*init)(void);
171         void    (*fini)(void);
172         int     (*read_ldd)(char *ds,  struct lustre_disk_data *ldd);
173         int     (*write_ldd)(struct mkfs_opts *mop);
174         int     (*is_lustre)(char *dev, enum ldd_mount_type *mount_type);
175         int     (*make_lustre)(struct mkfs_opts *mop);
176         int     (*prepare_lustre)(struct mkfs_opts *mop,
177                                   char *wanted_mountopts, size_t len);
178         int     (*fix_mountopts)(struct mkfs_opts *mop,
179                                  char *mountopts, size_t len);
180         int     (*tune_lustre)(char *dev, struct mount_opts *mop);
181         int     (*label_lustre)(struct mount_opts *mop);
182         int     (*enable_quota)(struct mkfs_opts *mop);
183         int     (*rename_fsname)(struct mkfs_opts *mop, const char *oldname);
184         void   *dl_handle;
185 };
186
187 struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type);
188 void unload_backfs_ops(struct module_backfs_ops *ops);
189 #ifdef HAVE_OPENSSL_SSK
190 int load_shared_keys(struct mount_opts *mop);
191 #else
192 static inline int load_shared_keys(struct mount_opts *mop)
193 {
194         return EOPNOTSUPP;
195 }
196 #endif
197 #endif