xref: /illumos-gate/usr/src/lib/libbe/common/libbe_priv.h (revision 7931524763ef94dc16989451dddd206563d03bb4)
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 2016 Toomas Soome <tsoome@me.com>
26  * Copyright (c) 2015 by Delphix. All rights reserved.
27  * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
28  */
29 
30 #ifndef	_LIBBE_PRIV_H
31 #define	_LIBBE_PRIV_H
32 
33 #include <libnvpair.h>
34 #include <libzfs.h>
35 #include <instzones_api.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #define	ARCH_LENGTH		MAXNAMELEN
42 #define	BE_AUTO_NAME_MAX_TRY	3
43 #define	BE_AUTO_NAME_DELIM	'-'
44 #define	BE_DEFAULTS		"/etc/default/be"
45 #define	BE_DFLT_BENAME_STARTS	"BENAME_STARTS_WITH="
46 #define	BE_DFLT_BE_HAS_GRUB	"BE_HAS_GRUB="
47 #define	BE_CONTAINER_DS_NAME	"ROOT"
48 #define	BE_DEFAULT_CONSOLE	"text"
49 #define	BE_POLICY_PROPERTY	"org.opensolaris.libbe:policy"
50 #define	BE_UUID_PROPERTY	"org.opensolaris.libbe:uuid"
51 #define	BE_PLCY_STATIC		"static"
52 #define	BE_PLCY_VOLATILE	"volatile"
53 #define	BE_GRUB_MENU		"/boot/grub/menu.lst"
54 #define	BE_SPARC_MENU		"/boot/menu.lst"
55 #define	BE_GRUB_COMMENT		"#============ End of LIBBE entry ============="
56 #define	BE_GRUB_SPLASH		"splashimage /boot/solaris.xpm"
57 #define	BE_GRUB_FOREGROUND	"foreground 343434"
58 #define	BE_GRUB_BACKGROUND	"background F7FBFF"
59 #define	BE_GRUB_DEFAULT		"default 0"
60 #define	BE_WHITE_SPACE		" \t\r\n"
61 #define	BE_CAP_FILE		"/boot/grub/capability"
62 #define	BE_INSTALL_GRUB		"/sbin/installgrub"
63 #define	BE_GRUB_STAGE_1		"/boot/grub/stage1"
64 #define	BE_GRUB_STAGE_2		"/boot/grub/stage2"
65 #define	BE_INSTALL_BOOT		"/usr/sbin/installboot"
66 #define	BE_LOADER_STAGE_1	"/boot/pmbr"
67 #define	BE_LOADER_STAGE_2	"/boot/gptzfsboot"
68 #define	BE_SPARC_BOOTBLK	"/lib/fs/zfs/bootblk"
69 
70 #define	ZFS_CLOSE(_zhp) \
71 	if (_zhp) { \
72 		zfs_close(_zhp); \
73 		_zhp = NULL; \
74 	}
75 
76 #define	BE_ZONE_PARENTBE_PROPERTY	"org.opensolaris.libbe:parentbe"
77 #define	BE_ZONE_ACTIVE_PROPERTY		"org.opensolaris.libbe:active"
78 #define	BE_ZONE_SUPPORTED_BRANDS	"ipkg labeled"
79 #define	BE_ZONE_SUPPORTED_BRANDS_DELIM	" "
80 
81 /* Maximum length for the BE name. */
82 #define	BE_NAME_MAX_LEN		64
83 
84 #define	MAX(a, b) ((a) > (b) ? (a) : (b))
85 #define	MIN(a, b) ((a) < (b) ? (a) : (b))
86 
87 typedef struct be_transaction_data {
88 	char		*obe_name;	/* Original BE name */
89 	char		*obe_root_ds;	/* Original BE root dataset */
90 	char		*obe_zpool;	/* Original BE pool */
91 	char		*obe_snap_name;	/* Original BE snapshot name */
92 	char		*obe_altroot;	/* Original BE altroot */
93 	char		*nbe_name;	/* New BE name */
94 	char		*nbe_root_ds;	/* New BE root dataset */
95 	char		*nbe_zpool;	/* New BE pool */
96 	char		*nbe_desc;	/* New BE description */
97 	nvlist_t	*nbe_zfs_props;	/* New BE dataset properties */
98 	char		*policy;	/* BE policy type */
99 } be_transaction_data_t;
100 
101 typedef struct be_mount_data {
102 	char		*altroot;	/* Location of where to mount BE */
103 	boolean_t	shared_fs;	/* Mount shared file sytsems */
104 	boolean_t	shared_rw;	/* Mount shared file systems rw */
105 } be_mount_data_t;
106 
107 typedef struct be_unmount_data {
108 	char		*altroot;	/* Location of where BE is mounted */
109 	boolean_t	force;		/* Forcibly unmount */
110 } be_unmount_data_t;
111 
112 typedef struct be_destroy_data {
113 	boolean_t	destroy_snaps;	/* Destroy snapshots of BE */
114 	boolean_t	force_unmount;	/* Forcibly unmount BE if mounted */
115 	uuid_t		gz_be_uuid;	/* UUID of the global zone BE */
116 } be_destroy_data_t;
117 
118 typedef struct be_demote_data {
119 	zfs_handle_t	*clone_zhp;	/* clone dataset to promote */
120 	time_t		origin_creation; /* snapshot creation time of clone */
121 	const char	*snapshot;	/* snapshot of dataset being demoted */
122 	boolean_t	find_in_BE;	/* flag noting to find clone in BE */
123 } be_demote_data_t;
124 
125 typedef struct be_fs_list_data {
126 	char		*altroot;
127 	char		**fs_list;
128 	int		fs_num;
129 } be_fs_list_data_t;
130 
131 typedef struct be_plcy_list {
132 	char			*be_plcy_name;
133 	int			be_num_max;
134 	int			be_num_min;
135 	time_t			be_age_max;
136 	int			be_usage_pcnt;
137 	struct be_plcy_list	*be_next_plcy;
138 }be_plcy_list_t;
139 
140 struct be_defaults {
141 	boolean_t	be_deflt_rpool_container;
142 	boolean_t	be_deflt_grub;
143 	char		be_deflt_bename_starts_with[ZFS_MAX_DATASET_NAME_LEN];
144 };
145 
146 /* Library globals */
147 extern libzfs_handle_t *g_zfs;
148 extern boolean_t do_print;
149 
150 /* be_create.c */
151 int be_set_uuid(char *);
152 int be_get_uuid(const char *, uuid_t *);
153 
154 /* be_list.c */
155 int _be_list(char *, be_node_list_t **, uint64_t);
156 int be_get_zone_be_list(char *, char *, be_node_list_t **);
157 
158 /* be_mount.c */
159 int _be_mount(char *, char **, int);
160 int _be_unmount(char *, int);
161 int be_mount_pool(zfs_handle_t *, char **, char **, boolean_t *);
162 int be_unmount_pool(zfs_handle_t *, char *, char *);
163 int be_mount_zone_root(zfs_handle_t *, be_mount_data_t *);
164 int be_unmount_zone_root(zfs_handle_t *, be_unmount_data_t *);
165 int be_get_legacy_fs(char *, char *, char *, char *, be_fs_list_data_t *);
166 void be_free_fs_list(be_fs_list_data_t *);
167 char *be_get_ds_from_dir(char *);
168 int be_make_tmp_mountpoint(char **);
169 
170 /* be_snapshot.c */
171 int _be_create_snapshot(char *, char **, char *);
172 int _be_destroy_snapshot(char *, char *);
173 
174 /* be_utils.c */
175 boolean_t be_zfs_init(void);
176 void be_zfs_fini(void);
177 void be_make_root_ds(const char *, const char *, char *, int);
178 void be_make_container_ds(const char *, char *, int);
179 char *be_make_name_from_ds(const char *, char *);
180 int be_append_menu(char *, char *, char *, char *, char *);
181 int be_remove_menu(char *, char *, char *);
182 int be_update_menu(char *, char *, char *, char *);
183 int be_default_grub_bootfs(const char *, char **);
184 boolean_t be_has_menu_entry(char *, char *, int *);
185 int be_run_cmd(char *, char *, int, char *, int);
186 int be_change_grub_default(char *, char *);
187 int be_update_vfstab(char *, char *, char *, be_fs_list_data_t *, char *);
188 int be_update_zone_vfstab(zfs_handle_t *, char *, char *, char *,
189     be_fs_list_data_t *);
190 int be_maxsize_avail(zfs_handle_t *, uint64_t *);
191 char *be_auto_snap_name(void);
192 char *be_auto_be_name(char *);
193 char *be_auto_zone_be_name(char *, char *);
194 char *be_default_policy(void);
195 boolean_t valid_be_policy(char *);
196 boolean_t be_valid_auto_snap_name(char *);
197 boolean_t be_valid_be_name(const char *);
198 void be_print_err(char *, ...);
199 int be_find_current_be(be_transaction_data_t *);
200 int zfs_err_to_be_err(libzfs_handle_t *);
201 int errno_to_be_err(int);
202 
203 /* be_activate.c */
204 int _be_activate(char *);
205 int be_activate_current_be(void);
206 boolean_t be_is_active_on_boot(char *);
207 
208 /* be_zones.c */
209 void be_make_zoneroot(char *, char *, int);
210 int be_find_active_zone_root(zfs_handle_t *, char *, char *, int);
211 int be_find_mounted_zone_root(char *, char *, char *, int);
212 boolean_t be_zone_supported(char *);
213 zoneBrandList_t *be_get_supported_brandlist(void);
214 int be_zone_get_parent_uuid(const char *, uuid_t *);
215 int be_zone_set_parent_uuid(char *, uuid_t);
216 boolean_t be_zone_compare_uuids(char *);
217 
218 /* check architecture functions */
219 char *be_get_default_isa(void);
220 char *be_get_platform(void);
221 boolean_t be_is_isa(char *);
222 boolean_t be_has_grub(void);
223 
224 /* callback functions */
225 int be_exists_callback(zpool_handle_t *, void *);
226 int be_find_zpool_callback(zpool_handle_t *, void *);
227 int be_zpool_find_current_be_callback(zpool_handle_t *, void *);
228 int be_zfs_find_current_be_callback(zfs_handle_t *, void *);
229 int be_check_be_roots_callback(zpool_handle_t *, void *);
230 
231 /* defaults */
232 void be_get_defaults(struct be_defaults *defaults);
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 
238 #endif	/* _LIBBE_PRIV_H */
239