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