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