Whamcloud - gitweb
LU-1770 ptlrpc: introducing OBD_CONNECT_FLOCK_OWNER flag
[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, Whamcloud, Inc.
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 #include <lustre_disk.h>
41 #include <lustre_param.h>
42
43 extern char *progname;
44 extern int verbose;
45 extern int failover;
46
47 #define vprint(fmt, arg...) if (verbose > 0) printf(fmt, ##arg)
48 #define verrprint(fmt, arg...) if (verbose >= 0) fprintf(stderr, fmt, ##arg)
49
50 /* mo_flags */
51 #define MO_IS_LOOP              0x01
52 #define MO_FORCEFORMAT          0x02
53 #define MO_FAILOVER             0x04
54 #define MO_DRYRUN               0x08
55 #define MO_QUOTA                0x10
56
57 #define MAX_LOOP_DEVICES        16
58 #define INDEX_UNASSIGNED        0xFFFF
59
60 /* used to describe the options to format the lustre disk, not persistent */
61 struct mkfs_opts {
62         struct lustre_disk_data mo_ldd; /* to be written in MOUNT_DATA_FILE */
63         char    mo_device[128];   /* disk device name */
64         char    **mo_pool_vdevs;  /* list of pool vdevs */
65         char    mo_loopdev[128];  /* in case a loop dev is needed */
66         char    mo_mkfsopts[512]; /* options to the backing-store mkfs */
67         __u64   mo_device_sz;     /* in KB */
68         int     mo_stripe_count;
69         int     mo_flags;
70         int     mo_mgs_failnodes;
71 };
72
73 /* used to describe the options to mount the lustre disk */
74 struct mount_opts {
75         struct lustre_disk_data  mo_ldd;
76         char    *mo_orig_options;
77         char    *mo_usource;            /* user-specified mount device */
78         char    *mo_source;             /* our mount device name */
79         char     mo_target[PATH_MAX];   /* mount directory */
80         int      mo_nomtab;
81         int      mo_fake;
82         int      mo_force;
83         int      mo_retry;
84         int      mo_have_mgsnid;
85         int      mo_md_stripe_cache_size;
86         int      mo_nosvc;
87 };
88
89 int get_mountdata(char *, struct lustre_disk_data *);
90
91 #define MT_STR(data)   mt_str((data)->ldd_mount_type)
92
93 #undef IS_MDT
94 #define IS_MDT(data)   ((data)->ldd_flags & LDD_F_SV_TYPE_MDT)
95 #undef IS_OST
96 #define IS_OST(data)   ((data)->ldd_flags & LDD_F_SV_TYPE_OST)
97 #undef IS_MGS
98 #define IS_MGS(data)  ((data)->ldd_flags & LDD_F_SV_TYPE_MGS)
99
100 /* mkfs/mount helper functions */
101 void fatal(void);
102 int run_command_err(char *cmd, int cmdsz, char *error_msg);
103 int run_command(char *cmd, int cmdsz);
104 int add_param(char *buf, char *key, char *val);
105 int get_param(char *buf, char *key, char **val);
106 char *strscat(char *dst, char *src, int buflen);
107 char *strscpy(char *dst, char *src, int buflen);
108 int check_mtab_entry(char *spec1, char *spec2, char *mntpt, char *type);
109 int update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
110                       int flags, int freq, int pass);
111 int check_mountfsoptions(char *mountopts, char *wanted_mountopts, int justwarn);
112 void trim_mountfsoptions(char *s);
113 __u64 get_device_size(char* device);
114
115 int is_block(char *devname);
116 void disp_old_e2fsprogs_msg(const char *feature, int make_backfs);
117 int make_lustre_backfs(struct mkfs_opts *mop);
118 int write_local_files(struct mkfs_opts *mop);
119 int read_local_files(struct mkfs_opts *mop);
120 int is_lustre_target(struct mkfs_opts *mop);
121
122 /* loopback helper functions */
123 int file_create(char *path, int size);
124 int loop_format(struct mkfs_opts *mop);
125 int loop_setup(struct mkfs_opts *mop);
126 int loop_cleanup(struct mkfs_opts *mop);
127
128 /* generic target support */
129 int osd_write_ldd(struct mkfs_opts *mop);
130 int osd_read_ldd(char *dev, struct lustre_disk_data *ldd);
131 int osd_is_lustre(char *dev, unsigned *mount_type);
132 int osd_make_lustre(struct mkfs_opts *mop);
133 int osd_prepare_lustre(struct mkfs_opts *mop,
134                        char *default_mountopts, int default_len,
135                        char *always_mountopts, int always_len);
136 int osd_tune_lustre(char *dev, struct mount_opts *mop);
137 int osd_label_lustre(struct mount_opts *mop);
138 int osd_enable_quota(struct mkfs_opts *mop);
139 int osd_init(void);
140 void osd_fini(void);
141
142 int ldiskfs_write_ldd(struct mkfs_opts *mop);
143 int ldiskfs_read_ldd(char *dev, struct lustre_disk_data *ldd);
144 int ldiskfs_is_lustre(char *dev, unsigned *mount_type);
145 int ldiskfs_make_lustre(struct mkfs_opts *mop);
146 int ldiskfs_prepare_lustre(struct mkfs_opts *mop,
147                            char *default_mountopts, int default_len,
148                            char *always_mountopts, int always_len);
149 int ldiskfs_tune_lustre(char *dev, struct mount_opts *mop);
150 int ldiskfs_label_lustre(struct mount_opts *mop);
151 int ldiskfs_enable_quota(struct mkfs_opts *mop);
152 int ldiskfs_init(void);
153 void ldiskfs_fini(void);
154
155 #ifdef HAVE_ZFS_OSD
156 int zfs_write_ldd(struct mkfs_opts *mop);
157 int zfs_read_ldd(char *ds,  struct lustre_disk_data *ldd);
158 int zfs_is_lustre(char *dev, unsigned *mount_type);
159 int zfs_make_lustre(struct mkfs_opts *mop);
160 int zfs_prepare_lustre(struct mkfs_opts *mop,
161                        char *default_mountopts, int default_len,
162                        char *always_mountopts, int always_len);
163 int zfs_tune_lustre(char *dev, struct mount_opts *mop);
164 int zfs_label_lustre(struct mount_opts *mop);
165 int zfs_init(void);
166 void zfs_fini(void);
167 #endif
168
169 #endif