Whamcloud - gitweb
LU-7759 utils: build mount.lustre with libmount
[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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2014, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef _MOUNT_UTILS_H_
38 #define _MOUNT_UTILS_H_
39
40 /* Some of the userland headers for libzfs also require
41  * zfs/spl linux kernel headers, but including these pull
42  * in linux kernel headers which conflicts with the
43  * userland version of libcfs. So the solution is tell the
44  * libzfs user land headrs that the zfs/spl kernel headers
45  * are already included even if this is not the case.
46  */
47 #ifdef HAVE_ZFS_OSD
48 #define _SPL_ZFS_H
49 #define _SPL_SIGNAL_H
50 #endif
51 #include <ctype.h>
52 #include <errno.h>
53 #include <fcntl.h>
54 #include <limits.h>
55 #include <stdbool.h>
56 #include <stdlib.h>
57 #include <string.h>
58 #include <sys/types.h>
59 #include <sys/stat.h>
60
61 #include <lustre_disk.h>
62 #include <lustre_param.h>
63
64 extern char *progname;
65 extern int verbose;
66 extern int failover;
67
68 #define vprint(fmt, arg...) if (verbose > 0) printf(fmt, ##arg)
69 #define verrprint(fmt, arg...) if (verbose >= 0) fprintf(stderr, fmt, ##arg)
70
71 /* mo_flags */
72 #define MO_IS_LOOP              0x01
73 #define MO_FORCEFORMAT          0x02
74 #define MO_FAILOVER             0x04
75 #define MO_DRYRUN               0x08
76 #define MO_QUOTA                0x10
77
78 #define MAX_LOOP_DEVICES        16
79 #define INDEX_UNASSIGNED        0xFFFF
80
81 /* used to describe the options to format the lustre disk, not persistent */
82 struct mkfs_opts {
83         struct lustre_disk_data mo_ldd; /* to be written in MOUNT_DATA_FILE */
84         char    mo_device[128];   /* disk device name */
85         char    **mo_pool_vdevs;  /* list of pool vdevs */
86         char    mo_loopdev[128];  /* in case a loop dev is needed */
87         char    mo_mkfsopts[512]; /* options to the backing-store mkfs */
88         char    *mo_mountopts;    /* mount options for backing fs */
89         __u64   mo_device_kb;     /* in KB */
90         int     mo_stripe_count;
91         int     mo_flags;
92         int     mo_mgs_failnodes;
93 };
94
95 /* used to describe the options to mount the lustre disk */
96 struct mount_opts {
97         struct lustre_disk_data  mo_ldd;
98         char    *mo_orig_options;
99         char    *mo_usource;            /* user-specified mount device */
100         char    *mo_source;             /* our mount device name */
101         char     mo_target[PATH_MAX];   /* mount directory */
102         int      mo_nomtab;
103         int      mo_fake;
104         int      mo_force;
105         int      mo_retry;
106         int      mo_have_mgsnid;
107         int      mo_md_stripe_cache_size;
108         int      mo_nosvc;
109 };
110
111 int get_mountdata(char *, struct lustre_disk_data *);
112
113 #define MT_STR(data)   mt_str((data)->ldd_mount_type)
114
115 #undef IS_MDT
116 #define IS_MDT(data)   ((data)->ldd_flags & LDD_F_SV_TYPE_MDT)
117 #undef IS_OST
118 #define IS_OST(data)   ((data)->ldd_flags & LDD_F_SV_TYPE_OST)
119 #undef IS_MGS
120 #define IS_MGS(data)  ((data)->ldd_flags & LDD_F_SV_TYPE_MGS)
121
122 /* mkfs/mount helper functions */
123 void fatal(void);
124 int run_command_err(char *cmd, int cmdsz, char *error_msg);
125 int run_command(char *cmd, int cmdsz);
126 int add_param(char *buf, char *key, char *val);
127 int append_param(char *buf, char *key, char *val, char sep);
128 int get_param(char *buf, char *key, char **val);
129 char *strscat(char *dst, char *src, int buflen);
130 char *strscpy(char *dst, char *src, int buflen);
131 int check_mtab_entry(char *spec1, char *spec2, char *mntpt, char *type);
132 int update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
133                       int flags, int freq, int pass);
134 int update_utab_entry(struct mount_opts *mop);
135 int check_mountfsoptions(char *mountopts, char *wanted_mountopts);
136 void trim_mountfsoptions(char *s);
137 __u64 get_device_size(char* device);
138
139 /* loopback helper functions */
140 int file_create(char *path, __u64 size);
141 int loop_format(struct mkfs_opts *mop);
142 int loop_setup(struct mkfs_opts *mop);
143 int loop_cleanup(struct mkfs_opts *mop);
144
145 /* generic target support */
146 int osd_write_ldd(struct mkfs_opts *mop);
147 int osd_read_ldd(char *dev, struct lustre_disk_data *ldd);
148 int osd_is_lustre(char *dev, unsigned *mount_type);
149 int osd_make_lustre(struct mkfs_opts *mop);
150 int osd_prepare_lustre(struct mkfs_opts *mop,
151                        char *wanted_mountopts, size_t len);
152 int osd_fix_mountopts(struct mkfs_opts *mop, char *mountopts, size_t len);
153 int osd_tune_lustre(char *dev, struct mount_opts *mop);
154 int osd_label_lustre(struct mount_opts *mop);
155 int osd_enable_quota(struct mkfs_opts *mop);
156 int osd_init(void);
157 void osd_fini(void);
158
159 struct module_backfs_ops {
160         int     (*init)(void);
161         void    (*fini)(void);
162         int     (*read_ldd)(char *ds,  struct lustre_disk_data *ldd);
163         int     (*write_ldd)(struct mkfs_opts *mop);
164         int     (*is_lustre)(char *dev, enum ldd_mount_type *mount_type);
165         int     (*make_lustre)(struct mkfs_opts *mop);
166         int     (*prepare_lustre)(struct mkfs_opts *mop,
167                                   char *wanted_mountopts, size_t len);
168         int     (*fix_mountopts)(struct mkfs_opts *mop,
169                                  char *mountopts, size_t len);
170         int     (*tune_lustre)(char *dev, struct mount_opts *mop);
171         int     (*label_lustre)(struct mount_opts *mop);
172         int     (*enable_quota)(struct mkfs_opts *mop);
173         void   *dl_handle;
174 };
175
176 struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type);
177 void unload_backfs_ops(struct module_backfs_ops *ops);
178
179 #endif