xref: /illumos-gate/usr/src/lib/libbe/common/libbe.h (revision b713c91e)
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.
24f169c0eaSGlenn Lagasse  */
25f169c0eaSGlenn Lagasse 
267e0e2549SAlexander Eremin /*
277e0e2549SAlexander Eremin  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
28f5e5a2c4SToomas Soome  * Copyright 2016 Toomas Soome <tsoome@me.com>
290afb687bSGary Mills  * Copyright 2015 Gary Mills
30a897f28bSAndy Fiddaman  * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
317e0e2549SAlexander Eremin  */
327e0e2549SAlexander Eremin 
33f169c0eaSGlenn Lagasse #ifndef _LIBBE_H
34f169c0eaSGlenn Lagasse #define	_LIBBE_H
35f169c0eaSGlenn Lagasse 
36f169c0eaSGlenn Lagasse #include <libnvpair.h>
37f169c0eaSGlenn Lagasse #include <uuid/uuid.h>
38f169c0eaSGlenn Lagasse #include <libzfs.h>
39f169c0eaSGlenn Lagasse 
40f169c0eaSGlenn Lagasse #ifdef __cplusplus
41f169c0eaSGlenn Lagasse extern "C" {
42f169c0eaSGlenn Lagasse #endif
43f169c0eaSGlenn Lagasse 
44f169c0eaSGlenn Lagasse #define	BE_ATTR_ORIG_BE_NAME	"orig_be_name"
45f169c0eaSGlenn Lagasse #define	BE_ATTR_ORIG_BE_POOL	"orig_be_pool"
46c7c0ceafSToomas Soome #define	BE_ATTR_ORIG_BE_ROOT	"orig_be_root"
47f169c0eaSGlenn Lagasse #define	BE_ATTR_SNAP_NAME	"snap_name"
48f169c0eaSGlenn Lagasse 
49f169c0eaSGlenn Lagasse #define	BE_ATTR_NEW_BE_NAME	"new_be_name"
50f169c0eaSGlenn Lagasse #define	BE_ATTR_NEW_BE_POOL	"new_be_pool"
51f169c0eaSGlenn Lagasse #define	BE_ATTR_NEW_BE_DESC	"new_be_desc"
52f169c0eaSGlenn Lagasse #define	BE_ATTR_POLICY		"policy"
53f169c0eaSGlenn Lagasse #define	BE_ATTR_ZFS_PROPERTIES	"zfs_properties"
54f169c0eaSGlenn Lagasse 
55f169c0eaSGlenn Lagasse #define	BE_ATTR_FS_NAMES	"fs_names"
56f169c0eaSGlenn Lagasse #define	BE_ATTR_FS_NUM		"fs_num"
57f169c0eaSGlenn Lagasse #define	BE_ATTR_SHARED_FS_NAMES	"shared_fs_names"
58f169c0eaSGlenn Lagasse #define	BE_ATTR_SHARED_FS_NUM	"shared_fs_num"
59f169c0eaSGlenn Lagasse 
60f169c0eaSGlenn Lagasse #define	BE_ATTR_MOUNTPOINT	"mountpoint"
61f169c0eaSGlenn Lagasse #define	BE_ATTR_MOUNT_FLAGS	"mount_flags"
62f169c0eaSGlenn Lagasse #define	BE_ATTR_UNMOUNT_FLAGS	"unmount_flags"
63f169c0eaSGlenn Lagasse #define	BE_ATTR_DESTROY_FLAGS	"destroy_flags"
64c7c0ceafSToomas Soome #define	BE_ATTR_INSTALL_FLAGS	"install_flags"
65f169c0eaSGlenn Lagasse #define	BE_ATTR_ROOT_DS		"root_ds"
66f169c0eaSGlenn Lagasse #define	BE_ATTR_UUID_STR	"uuid_str"
67f169c0eaSGlenn Lagasse 
68f169c0eaSGlenn Lagasse #define	BE_ATTR_ACTIVE		"active"
69f169c0eaSGlenn Lagasse #define	BE_ATTR_ACTIVE_ON_BOOT	"active_boot"
70*b713c91eSToomas Soome #define	BE_ATTR_ACTIVE_NEXTBOOT	"active_nextboot"
717e0e2549SAlexander Eremin #define	BE_ATTR_GLOBAL_ACTIVE	"global_active"
72f169c0eaSGlenn Lagasse #define	BE_ATTR_SPACE		"space_used"
73f169c0eaSGlenn Lagasse #define	BE_ATTR_DATASET		"dataset"
74f169c0eaSGlenn Lagasse #define	BE_ATTR_STATUS		"status"
75f169c0eaSGlenn Lagasse #define	BE_ATTR_DATE		"date"
76f169c0eaSGlenn Lagasse #define	BE_ATTR_MOUNTED		"mounted"
77f169c0eaSGlenn Lagasse 
78f169c0eaSGlenn Lagasse /*
79f169c0eaSGlenn Lagasse  * libbe error codes
80f169c0eaSGlenn Lagasse  *
81f169c0eaSGlenn Lagasse  * NOTE: there is a copy of this enum in beadm/messages.py. To keep these
82f169c0eaSGlenn Lagasse  *       in sync please make sure to add any new error messages at the end
83f169c0eaSGlenn Lagasse  *       of this enumeration.
84f169c0eaSGlenn Lagasse  */
853579e3c3SAurelien Larcher typedef enum {
86f169c0eaSGlenn Lagasse 	BE_SUCCESS = 0,
87f169c0eaSGlenn Lagasse 	BE_ERR_ACCESS = 4000,	/* permission denied */
88f169c0eaSGlenn Lagasse 	BE_ERR_ACTIVATE_CURR,	/* Activation of current BE failed */
89f169c0eaSGlenn Lagasse 	BE_ERR_AUTONAME,	/* auto naming failed */
90f169c0eaSGlenn Lagasse 	BE_ERR_BE_NOENT,	/* No such BE */
91f169c0eaSGlenn Lagasse 	BE_ERR_BUSY,		/* mount busy */
92f169c0eaSGlenn Lagasse 	BE_ERR_CANCELED,	/* operation canceled */
93f169c0eaSGlenn Lagasse 	BE_ERR_CLONE,		/* BE clone failed */
94f169c0eaSGlenn Lagasse 	BE_ERR_COPY,		/* BE copy failed */
95f169c0eaSGlenn Lagasse 	BE_ERR_CREATDS,		/* dataset creation failed */
96f169c0eaSGlenn Lagasse 	BE_ERR_CURR_BE_NOT_FOUND,	/* Can't find current BE */
97f169c0eaSGlenn Lagasse 	BE_ERR_DESTROY,		/* failed to destroy BE or snapshot */
98f169c0eaSGlenn Lagasse 	BE_ERR_DEMOTE,		/* BE demotion failed */
99f169c0eaSGlenn Lagasse 	BE_ERR_DSTYPE,		/* invalid dataset type */
100f169c0eaSGlenn Lagasse 	BE_ERR_BE_EXISTS,	/* BE exists */
101f169c0eaSGlenn Lagasse 	BE_ERR_INIT,		/* be_zfs_init failed */
102f169c0eaSGlenn Lagasse 	BE_ERR_INTR,		/* interupted system call */
103f169c0eaSGlenn Lagasse 	BE_ERR_INVAL,		/* invalid argument */
104f169c0eaSGlenn Lagasse 	BE_ERR_INVALPROP,	/* invalid property for dataset */
105f169c0eaSGlenn Lagasse 	BE_ERR_INVALMOUNTPOINT,	/* Unexpected mountpoint */
106f169c0eaSGlenn Lagasse 	BE_ERR_MOUNT,		/* mount failed */
107f169c0eaSGlenn Lagasse 	BE_ERR_MOUNTED,		/* already mounted */
108a897f28bSAndy Fiddaman 	BE_ERR_NAMETOOLONG,	/* name > BUFSIZ */
109f169c0eaSGlenn Lagasse 	BE_ERR_NOENT,		/* Doesn't exist */
110f169c0eaSGlenn Lagasse 	BE_ERR_POOL_NOENT,	/* No such pool */
111f169c0eaSGlenn Lagasse 	BE_ERR_NODEV,		/* No such device */
112f169c0eaSGlenn Lagasse 	BE_ERR_NOTMOUNTED,	/* File system not mounted */
113f169c0eaSGlenn Lagasse 	BE_ERR_NOMEM,		/* not enough memory */
114f169c0eaSGlenn Lagasse 	BE_ERR_NONINHERIT,	/* property is not inheritable for BE dataset */
115f169c0eaSGlenn Lagasse 	BE_ERR_NXIO,		/* No such device or address */
116f169c0eaSGlenn Lagasse 	BE_ERR_NOSPC,		/* No space on device */
117f169c0eaSGlenn Lagasse 	BE_ERR_NOTSUP,		/* Operation not supported */
118f169c0eaSGlenn Lagasse 	BE_ERR_OPEN,		/* open failed */
119f169c0eaSGlenn Lagasse 	BE_ERR_PERM,		/* Not owner */
120f169c0eaSGlenn Lagasse 	BE_ERR_UNAVAIL,		/* The BE is currently unavailable */
121f169c0eaSGlenn Lagasse 	BE_ERR_PROMOTE,		/* BE promotion failed */
122f169c0eaSGlenn Lagasse 	BE_ERR_ROFS,		/* read only file system */
123f169c0eaSGlenn Lagasse 	BE_ERR_READONLYDS,	/* read only dataset */
124f169c0eaSGlenn Lagasse 	BE_ERR_READONLYPROP,	/* read only property */
125f169c0eaSGlenn Lagasse 	BE_ERR_SS_EXISTS,	/* snapshot exists */
126f169c0eaSGlenn Lagasse 	BE_ERR_SS_NOENT,	/* No such snapshot */
127f169c0eaSGlenn Lagasse 	BE_ERR_UMOUNT,		/* unmount failed */
128f169c0eaSGlenn Lagasse 	BE_ERR_UMOUNT_CURR_BE,	/* Can't unmount current BE */
129f169c0eaSGlenn Lagasse 	BE_ERR_UMOUNT_SHARED,	/* unmount of shared File System failed */
130f169c0eaSGlenn Lagasse 	BE_ERR_UNKNOWN,		/* Unknown error */
131f169c0eaSGlenn Lagasse 	BE_ERR_ZFS,		/* ZFS returned an error */
132f169c0eaSGlenn Lagasse 	BE_ERR_DESTROY_CURR_BE,	/* Cannot destroy current BE */
133f169c0eaSGlenn Lagasse 	BE_ERR_GEN_UUID,	/* Failed to generate uuid */
134f169c0eaSGlenn Lagasse 	BE_ERR_PARSE_UUID,	/* Failed to parse uuid */
135f169c0eaSGlenn Lagasse 	BE_ERR_NO_UUID,		/* BE has no uuid */
136f169c0eaSGlenn Lagasse 	BE_ERR_ZONE_NO_PARENTBE,    /* Zone root dataset has no parent uuid */
137f169c0eaSGlenn Lagasse 	BE_ERR_ZONE_MULTIPLE_ACTIVE, /* Zone has multiple active roots */
138f169c0eaSGlenn Lagasse 	BE_ERR_ZONE_NO_ACTIVE_ROOT, /* Zone has no active root for this BE */
139f169c0eaSGlenn Lagasse 	BE_ERR_ZONE_ROOT_NOT_LEGACY, /* Zone root dataset mntpt is not legacy */
140f169c0eaSGlenn Lagasse 	BE_ERR_NO_MOUNTED_ZONE,	/* Zone not mounted in alternate BE */
141f169c0eaSGlenn Lagasse 	BE_ERR_MOUNT_ZONEROOT,	/* Failed to mount a zone root */
142f169c0eaSGlenn Lagasse 	BE_ERR_UMOUNT_ZONEROOT,	/* Failed to unmount a zone root */
143f169c0eaSGlenn Lagasse 	BE_ERR_ZONES_UNMOUNT,	/* Unable to unmount a zone. */
144f169c0eaSGlenn Lagasse 	BE_ERR_FAULT,		/* Bad Address */
145f169c0eaSGlenn Lagasse 	BE_ERR_RENAME_ACTIVE,	/* Renaming the active BE is not supported */
146f169c0eaSGlenn Lagasse 	BE_ERR_NO_MENU,		/* Missing boot menu file */
147f169c0eaSGlenn Lagasse 	BE_ERR_DEV_BUSY,	/* Device is Busy */
148f169c0eaSGlenn Lagasse 	BE_ERR_BAD_MENU_PATH,	/* Invalid path for menu.lst file */
149f169c0eaSGlenn Lagasse 	BE_ERR_ZONE_SS_EXISTS,	/* zone snapshot already exists */
150f169c0eaSGlenn Lagasse 	BE_ERR_ADD_SPLASH_ICT,	/* Add_splash_image ICT failed */
151f169c0eaSGlenn Lagasse 	BE_ERR_BOOTFILE_INST,	/* Error installing boot files */
152f169c0eaSGlenn Lagasse 	BE_ERR_EXTCMD		/* External command error */
153f169c0eaSGlenn Lagasse } be_errno_t;
154f169c0eaSGlenn Lagasse 
155f169c0eaSGlenn Lagasse /*
156f169c0eaSGlenn Lagasse  * Data structures used to return the listing and information of BEs.
157f169c0eaSGlenn Lagasse  */
158f169c0eaSGlenn Lagasse typedef struct be_dataset_list {
159f169c0eaSGlenn Lagasse 	uint64_t	be_ds_space_used;
160f169c0eaSGlenn Lagasse 	boolean_t	be_ds_mounted;
161f169c0eaSGlenn Lagasse 	char		*be_dataset_name;
162f169c0eaSGlenn Lagasse 	time_t		be_ds_creation;	/* Date/time stamp when created */
163f169c0eaSGlenn Lagasse 	char		*be_ds_mntpt;
164f169c0eaSGlenn Lagasse 	char		*be_ds_plcy_type;	/* cleanup policy type */
165f169c0eaSGlenn Lagasse 	struct be_dataset_list	*be_next_dataset;
166f169c0eaSGlenn Lagasse } be_dataset_list_t;
167f169c0eaSGlenn Lagasse 
168f169c0eaSGlenn Lagasse typedef struct be_snapshot_list {
169f169c0eaSGlenn Lagasse 	uint64_t be_snapshot_space_used;	/* bytes of disk space used */
170f169c0eaSGlenn Lagasse 	char	*be_snapshot_name;
171f169c0eaSGlenn Lagasse 	time_t	be_snapshot_creation;	/* Date/time stamp when created */
172f169c0eaSGlenn Lagasse 	char	*be_snapshot_type;	/* cleanup policy type */
173f169c0eaSGlenn Lagasse 	struct	be_snapshot_list *be_next_snapshot;
174f169c0eaSGlenn Lagasse } be_snapshot_list_t;
175f169c0eaSGlenn Lagasse 
176f169c0eaSGlenn Lagasse typedef struct be_node_list {
177f169c0eaSGlenn Lagasse 	boolean_t be_mounted;		/* is BE currently mounted */
178*b713c91eSToomas Soome 	boolean_t be_active_next;	/* is this BE active on next boot */
179f169c0eaSGlenn Lagasse 	boolean_t be_active_on_boot;	/* is this BE active on boot */
180f169c0eaSGlenn Lagasse 	boolean_t be_active;		/* is this BE active currently */
1817e0e2549SAlexander Eremin 	boolean_t be_global_active;	/* is zone's BE associated with */
1827e0e2549SAlexander Eremin 					/* an active global BE */
183f169c0eaSGlenn Lagasse 	uint64_t be_space_used;
184f169c0eaSGlenn Lagasse 	char *be_node_name;
185f169c0eaSGlenn Lagasse 	char *be_rpool;
186f169c0eaSGlenn Lagasse 	char *be_root_ds;
187f169c0eaSGlenn Lagasse 	char *be_mntpt;
188f169c0eaSGlenn Lagasse 	char *be_policy_type;		/* cleanup policy type */
189f169c0eaSGlenn Lagasse 	char *be_uuid_str;		/* string representation of uuid */
190f169c0eaSGlenn Lagasse 	time_t be_node_creation;	/* Date/time stamp when created */
191f169c0eaSGlenn Lagasse 	struct be_dataset_list *be_node_datasets;
192f169c0eaSGlenn Lagasse 	uint_t be_node_num_datasets;
193f169c0eaSGlenn Lagasse 	struct be_snapshot_list *be_node_snapshots;
194f169c0eaSGlenn Lagasse 	uint_t be_node_num_snapshots;
195f169c0eaSGlenn Lagasse 	struct be_node_list *be_next_node;
196f169c0eaSGlenn Lagasse } be_node_list_t;
197f169c0eaSGlenn Lagasse 
198f169c0eaSGlenn Lagasse /* Flags used with mounting a BE */
199f169c0eaSGlenn Lagasse #define	BE_MOUNT_FLAG_NULL		0x00000000
200f169c0eaSGlenn Lagasse #define	BE_MOUNT_FLAG_SHARED_FS		0x00000001
201f169c0eaSGlenn Lagasse #define	BE_MOUNT_FLAG_SHARED_RW		0x00000002
202f169c0eaSGlenn Lagasse #define	BE_MOUNT_FLAG_NO_ZONES		0x00000004
203f169c0eaSGlenn Lagasse 
204f169c0eaSGlenn Lagasse /* Flags used with unmounting a BE */
205f169c0eaSGlenn Lagasse #define	BE_UNMOUNT_FLAG_NULL		0x00000000
206f169c0eaSGlenn Lagasse #define	BE_UNMOUNT_FLAG_FORCE		0x00000001
207f169c0eaSGlenn Lagasse 
208f169c0eaSGlenn Lagasse /* Flags used with destroying a BE */
209f169c0eaSGlenn Lagasse #define	BE_DESTROY_FLAG_NULL		0x00000000
210f169c0eaSGlenn Lagasse #define	BE_DESTROY_FLAG_SNAPSHOTS	0x00000001
211f169c0eaSGlenn Lagasse #define	BE_DESTROY_FLAG_FORCE_UNMOUNT	0x00000002
212f169c0eaSGlenn Lagasse 
213c7c0ceafSToomas Soome /* Flags for installboot */
214c7c0ceafSToomas Soome #define	BE_INSTALLBOOT_FLAG_NULL	0x00000000
215c7c0ceafSToomas Soome #define	BE_INSTALLBOOT_FLAG_MBR		0x00000001
216c7c0ceafSToomas Soome #define	BE_INSTALLBOOT_FLAG_FORCE	0x00000002
217c7c0ceafSToomas Soome #define	BE_INSTALLBOOT_FLAG_VERBOSE	0x00000004
218c7c0ceafSToomas Soome 
219a897f28bSAndy Fiddaman /* Flags for be_list() */
220a897f28bSAndy Fiddaman #define	BE_LIST_DEFAULT			0x00000000
221a897f28bSAndy Fiddaman #define	BE_LIST_SNAPSHOTS		0x00000001
222a897f28bSAndy Fiddaman #define	BE_LIST_ALL			BE_LIST_SNAPSHOTS
223a897f28bSAndy Fiddaman 
2244adca7e7SToomas Soome /* sort rules for be_sort() */
2254adca7e7SToomas Soome typedef enum {
2264adca7e7SToomas Soome 	BE_SORT_UNSPECIFIED = -1,
2274adca7e7SToomas Soome 	BE_SORT_DATE = 0,
2284adca7e7SToomas Soome 	BE_SORT_DATE_REV,
2294adca7e7SToomas Soome 	BE_SORT_NAME,
2304adca7e7SToomas Soome 	BE_SORT_NAME_REV,
2314adca7e7SToomas Soome 	BE_SORT_SPACE,
2324adca7e7SToomas Soome 	BE_SORT_SPACE_REV
2334adca7e7SToomas Soome } be_sort_t;
2344adca7e7SToomas Soome 
235f5e5a2c4SToomas Soome /* for fastboot arguments */
236f5e5a2c4SToomas Soome #define	BE_ENTRY_DEFAULT	(-1)
237f169c0eaSGlenn Lagasse /*
238f169c0eaSGlenn Lagasse  * BE functions
239f169c0eaSGlenn Lagasse  */
240f169c0eaSGlenn Lagasse int be_init(nvlist_t *);
241f169c0eaSGlenn Lagasse int be_destroy(nvlist_t *);
242f169c0eaSGlenn Lagasse int be_copy(nvlist_t *);
243f169c0eaSGlenn Lagasse 
244f169c0eaSGlenn Lagasse int be_mount(nvlist_t *);
245f169c0eaSGlenn Lagasse int be_unmount(nvlist_t *);
246f169c0eaSGlenn Lagasse 
247f169c0eaSGlenn Lagasse int be_rename(nvlist_t *);
248f169c0eaSGlenn Lagasse 
249f169c0eaSGlenn Lagasse int be_activate(nvlist_t *);
250f169c0eaSGlenn Lagasse 
251f169c0eaSGlenn Lagasse int be_create_snapshot(nvlist_t *);
252f169c0eaSGlenn Lagasse int be_destroy_snapshot(nvlist_t *);
253f169c0eaSGlenn Lagasse int be_rollback(nvlist_t *);
254f169c0eaSGlenn Lagasse 
255f169c0eaSGlenn Lagasse /*
256f169c0eaSGlenn Lagasse  * Functions for listing and getting information about existing BEs.
257f169c0eaSGlenn Lagasse  */
258a897f28bSAndy Fiddaman int be_list(char *, be_node_list_t **, uint64_t);
259f169c0eaSGlenn Lagasse void be_free_list(be_node_list_t *);
260f169c0eaSGlenn Lagasse int be_max_avail(char *, uint64_t *);
261f169c0eaSGlenn Lagasse char *be_err_to_str(int);
2620afb687bSGary Mills int be_sort(be_node_list_t **, int);
263f5e5a2c4SToomas Soome int be_get_boot_args(char **, int);
264c7c0ceafSToomas Soome /*
265c7c0ceafSToomas Soome  * Installboot support
266c7c0ceafSToomas Soome  */
267c7c0ceafSToomas Soome int be_installboot(nvlist_t *);
268c7c0ceafSToomas Soome 
269f169c0eaSGlenn Lagasse /*
270f169c0eaSGlenn Lagasse  * Library functions
271f169c0eaSGlenn Lagasse  */
272f169c0eaSGlenn Lagasse void libbe_print_errors(boolean_t);
273f169c0eaSGlenn Lagasse 
274f169c0eaSGlenn Lagasse #ifdef __cplusplus
275f169c0eaSGlenn Lagasse }
276f169c0eaSGlenn Lagasse #endif
277f169c0eaSGlenn Lagasse 
278f169c0eaSGlenn Lagasse #endif	/* _LIBBE_H */
279