xref: /titanic_41/usr/src/lib/libbe/common/libbe_priv.h (revision 2386db6850f3faeca05a34f5928b3eff8a4a87c6)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
25  * Copyright (c) 2015 by Delphix. All rights reserved.
26  */
27 
28 #ifndef	_LIBBE_PRIV_H
29 #define	_LIBBE_PRIV_H
30 
31 #include <libnvpair.h>
32 #include <libzfs.h>
33 #include <instzones_api.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #define	ARCH_LENGTH		MAXNAMELEN
40 #define	BE_AUTO_NAME_MAX_TRY	3
41 #define	BE_AUTO_NAME_DELIM	'-'
42 #define	BE_DEFAULTS		"/etc/default/be"
43 #define	BE_DFLT_BENAME_STARTS	"BENAME_STARTS_WITH="
44 #define	BE_CONTAINER_DS_NAME	"ROOT"
45 #define	BE_DEFAULT_CONSOLE	"text"
46 #define	BE_POLICY_PROPERTY	"org.opensolaris.libbe:policy"
47 #define	BE_UUID_PROPERTY	"org.opensolaris.libbe:uuid"
48 #define	BE_PLCY_STATIC		"static"
49 #define	BE_PLCY_VOLATILE	"volatile"
50 #define	BE_GRUB_MENU		"/boot/grub/menu.lst"
51 #define	BE_SPARC_MENU		"/boot/menu.lst"
52 #define	BE_GRUB_COMMENT		"#============ End of LIBBE entry ============="
53 #define	BE_GRUB_SPLASH		"splashimage /boot/solaris.xpm"
54 #define	BE_GRUB_FOREGROUND	"foreground 343434"
55 #define	BE_GRUB_BACKGROUND	"background F7FBFF"
56 #define	BE_GRUB_DEFAULT		"default 0"
57 #define	BE_WHITE_SPACE		" \t\r\n"
58 #define	BE_CAP_FILE		"/boot/grub/capability"
59 #define	BE_INSTALL_GRUB		"/sbin/installgrub"
60 #define	BE_STAGE_1		"/boot/grub/stage1"
61 #define	BE_STAGE_2		"/boot/grub/stage2"
62 #define	ZFS_CLOSE(_zhp) \
63 	if (_zhp) { \
64 		zfs_close(_zhp); \
65 		_zhp = NULL; \
66 	}
67 
68 #define	BE_ZONE_PARENTBE_PROPERTY	"org.opensolaris.libbe:parentbe"
69 #define	BE_ZONE_ACTIVE_PROPERTY		"org.opensolaris.libbe:active"
70 #define	BE_ZONE_SUPPORTED_BRANDS	"ipkg labeled"
71 #define	BE_ZONE_SUPPORTED_BRANDS_DELIM	" "
72 
73 /* Maximum length for the BE name. */
74 #define	BE_NAME_MAX_LEN		64
75 
76 #define	MAX(a, b) ((a) > (b) ? (a) : (b))
77 #define	MIN(a, b) ((a) < (b) ? (a) : (b))
78 
79 typedef struct be_transaction_data {
80 	char		*obe_name;	/* Original BE name */
81 	char		*obe_root_ds;	/* Original BE root dataset */
82 	char		*obe_zpool;	/* Original BE pool */
83 	char		*obe_snap_name;	/* Original BE snapshot name */
84 	char		*obe_altroot;	/* Original BE altroot */
85 	char 		*nbe_name;	/* New BE name */
86 	char		*nbe_root_ds;	/* New BE root dataset */
87 	char		*nbe_zpool;	/* New BE pool */
88 	char		*nbe_desc;	/* New BE description */
89 	nvlist_t	*nbe_zfs_props;	/* New BE dataset properties */
90 	char		*policy;	/* BE policy type */
91 } be_transaction_data_t;
92 
93 typedef struct be_mount_data {
94 	char		*altroot;	/* Location of where to mount BE */
95 	boolean_t	shared_fs;	/* Mount shared file sytsems */
96 	boolean_t	shared_rw;	/* Mount shared file systems rw */
97 } be_mount_data_t;
98 
99 typedef struct be_unmount_data {
100 	char		*altroot;	/* Location of where BE is mounted */
101 	boolean_t	force;		/* Forcibly unmount */
102 } be_unmount_data_t;
103 
104 typedef struct be_destroy_data {
105 	boolean_t	destroy_snaps;	/* Destroy snapshots of BE */
106 	boolean_t	force_unmount;	/* Forcibly unmount BE if mounted */
107 	uuid_t		gz_be_uuid;	/* UUID of the global zone BE */
108 } be_destroy_data_t;
109 
110 typedef struct be_demote_data {
111 	zfs_handle_t	*clone_zhp;	/* clone dataset to promote */
112 	time_t		origin_creation; /* snapshot creation time of clone */
113 	const char	*snapshot;	/* snapshot of dataset being demoted */
114 	boolean_t	find_in_BE;	/* flag noting to find clone in BE */
115 } be_demote_data_t;
116 
117 typedef struct be_fs_list_data {
118 	char		*altroot;
119 	char		**fs_list;
120 	int		fs_num;
121 } be_fs_list_data_t;
122 
123 typedef struct be_plcy_list {
124 	char			*be_plcy_name;
125 	int			be_num_max;
126 	int			be_num_min;
127 	time_t			be_age_max;
128 	int			be_usage_pcnt;
129 	struct be_plcy_list	*be_next_plcy;
130 }be_plcy_list_t;
131 
132 struct be_defaults {
133 	boolean_t	be_deflt_rpool_container;
134 	char		be_deflt_bename_starts_with[ZFS_MAX_DATASET_NAME_LEN];
135 };
136 
137 /* Library globals */
138 extern libzfs_handle_t *g_zfs;
139 extern boolean_t do_print;
140 
141 /* be_create.c */
142 int be_set_uuid(char *);
143 int be_get_uuid(const char *, uuid_t *);
144 
145 /* be_list.c */
146 int _be_list(char *, be_node_list_t **);
147 int be_get_zone_be_list(char *, char *, be_node_list_t **);
148 
149 /* be_mount.c */
150 int _be_mount(char *, char **, int);
151 int _be_unmount(char *, int);
152 int be_mount_pool(zfs_handle_t *, char **, char **, boolean_t *);
153 int be_unmount_pool(zfs_handle_t *, char *, char *);
154 int be_mount_zone_root(zfs_handle_t *, be_mount_data_t *);
155 int be_unmount_zone_root(zfs_handle_t *, be_unmount_data_t *);
156 int be_get_legacy_fs(char *, char *, char *, char *, be_fs_list_data_t *);
157 void be_free_fs_list(be_fs_list_data_t *);
158 char *be_get_ds_from_dir(char *);
159 int be_make_tmp_mountpoint(char **);
160 
161 /* be_snapshot.c */
162 int _be_create_snapshot(char *, char **, char *);
163 int _be_destroy_snapshot(char *, char *);
164 
165 /* be_utils.c */
166 boolean_t be_zfs_init(void);
167 void be_zfs_fini(void);
168 void be_make_root_ds(const char *, const char *, char *, int);
169 void be_make_container_ds(const char *, char *, int);
170 char *be_make_name_from_ds(const char *, char *);
171 int be_append_menu(char *, char *, char *, char *, char *);
172 int be_remove_menu(char *, char *, char *);
173 int be_update_menu(char *, char *, char *, char *);
174 int be_default_grub_bootfs(const char *, char **);
175 boolean_t be_has_menu_entry(char *, char *, int *);
176 int be_run_cmd(char *, char *, int, char *, int);
177 int be_change_grub_default(char *, char *);
178 int be_update_vfstab(char *, char *, char *, be_fs_list_data_t *, char *);
179 int be_update_zone_vfstab(zfs_handle_t *, char *, char *, char *,
180     be_fs_list_data_t *);
181 int be_maxsize_avail(zfs_handle_t *, uint64_t *);
182 char *be_auto_snap_name(void);
183 char *be_auto_be_name(char *);
184 char *be_auto_zone_be_name(char *, char *);
185 char *be_default_policy(void);
186 boolean_t valid_be_policy(char *);
187 boolean_t be_valid_auto_snap_name(char *);
188 boolean_t be_valid_be_name(const char *);
189 void be_print_err(char *, ...);
190 int be_find_current_be(be_transaction_data_t *);
191 int zfs_err_to_be_err(libzfs_handle_t *);
192 int errno_to_be_err(int);
193 
194 /* be_activate.c */
195 int _be_activate(char *);
196 int be_activate_current_be(void);
197 boolean_t be_is_active_on_boot(char *);
198 
199 /* be_zones.c */
200 void be_make_zoneroot(char *, char *, int);
201 int be_find_active_zone_root(zfs_handle_t *, char *, char *, int);
202 int be_find_mounted_zone_root(char *, char *, char *, int);
203 boolean_t be_zone_supported(char *);
204 zoneBrandList_t *be_get_supported_brandlist(void);
205 int be_zone_get_parent_uuid(const char *, uuid_t *);
206 int be_zone_set_parent_uuid(char *, uuid_t);
207 boolean_t be_zone_compare_uuids(char *);
208 
209 /* check architecture functions */
210 char *be_get_default_isa(void);
211 boolean_t be_is_isa(char *);
212 boolean_t be_has_grub(void);
213 
214 /* callback functions */
215 int be_exists_callback(zpool_handle_t *, void *);
216 int be_find_zpool_callback(zpool_handle_t *, void *);
217 int be_zpool_find_current_be_callback(zpool_handle_t *, void *);
218 int be_zfs_find_current_be_callback(zfs_handle_t *, void *);
219 int be_check_be_roots_callback(zpool_handle_t *, void *);
220 
221 /* defaults */
222 void be_get_defaults(struct be_defaults *defaults);
223 
224 #ifdef __cplusplus
225 }
226 #endif
227 
228 #endif	/* _LIBBE_PRIV_H */
229