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