2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. 2N/A/* Private function prototypes */ 2N/A/* ******************************************************************** */ 2N/A/* Public Functions */ 2N/A/* ******************************************************************** */ 2N/A * Function: be_create_snapshot 2N/A * Description: Creates a recursive snapshot of all the datasets within a BE. 2N/A * If the name of the BE to snapshot is not provided, it assumes 2N/A * we're snapshotting the currently running BE. If the snapshot 2N/A * name is not provided it creates an auto named snapshot, which 2N/A * will be returned to the caller upon success. 2N/A * be_attrs - pointer to nvlist_t of attributes being passed in. 2N/A * The following attributes are used by this function: 2N/A * BE_ATTR_ORIG_BE_NAME *optional 2N/A * BE_ATTR_ALT_POOL *optional 2N/A * BE_ATTR_SNAP_NAME *optional 2N/A * BE_ATTR_POLICY *optional 2N/A * If the BE_ATTR_SNAP_NAME was not passed in, upon 2N/A * successful BE snapshot creation, the following 2N/A * attribute value will be returned to the caller by 2N/A * setting it in the be_attrs parameter passed in: 2N/A * BE_SUCCESS - Success 2N/A * be_errno_t - Failure 2N/A * Check to see if we have write access to the root filesystem 2N/A /* Initialize libzfs handle */ 2N/A /* Get original BE name if one was provided */ 2N/A "lookup BE_ATTR_ORIG_BE_NAME attribute\n"));
2N/A /* Validate original BE name if one was provided */ 2N/A /* Get alternate "pool" */ 2N/A "BE_ATTR_ALT_POOL attribute\n"));
2N/A /* Get snapshot name to create if one was provided */ 2N/A "failed to lookup BE_ATTR_SNAP_NAME attribute\n"));
2N/A /* Get BE policy to create this snapshot under */ 2N/A "failed to lookup BE_ATTR_POLICY attribute\n"));
2N/A * If no snap_name ws provided, we're going to create an 2N/A * auto named snapshot. Set flag so that we know to pass 2N/A * the auto named snapshot to the caller later. 2N/A * Set auto named snapshot name in the 2N/A * nvlist passed in by the caller. 2N/A "failed to add auto snap name (%s) to " 2N/A * Function: be_destroy_snapshot 2N/A * Description: Iterates through all the datasets of the BE and deletes 2N/A * the snapshots of each one with the specified name. If the 2N/A * BE name is not provided, it assumes we're operating on the 2N/A * currently running BE. The name of the snapshot name to 2N/A * destroy must be provided. 2N/A * be_attrs - pointer to nvlist_t of attributes being passed in. 2N/A * The following attribute values are used by this 2N/A * BE_ATTR_ORIG_BE_NAME *optional 2N/A * BE_ATTR_SNAP_NAME *required 2N/A * BE_SUCCESS - Success 2N/A * be_errno_t - Failure 2N/A * Check to see if we have write access to the root filesystem 2N/A /* Initialize libzfs handle */ 2N/A /* Get original BE name if one was provided */ 2N/A "failed to lookup BE_ATTR_ORIG_BE_NAME attribute\n"));
2N/A /* Validate original BE name if one was provided */ 2N/A /* Get snapshot name to destroy */ 2N/A "failed to lookup BE_ATTR_SNAP_NAME attribute.\n"));
2N/A * Function: be_rollback 2N/A * Description: Rolls back a BE and all of its children datasets to the 2N/A * named snapshot. All of the BE's datasets must have the 2N/A * named snapshot for this function to succeed. If the name 2N/A * of the BE is not passed in, this function assumes we're 2N/A * operating on the currently booted live BE. 2N/A * Note - This function does not check if the BE has any 2N/A * younger snapshots than the one we're trying to rollback to. 2N/A * If it does, then those younger snapshots and their dependent 2N/A * clone file systems will get destroyed in the process of 2N/A * be_attrs - pointer to nvlist_t of attributes being passed in. 2N/A * The following attributes are used by this function: 2N/A * BE_ATTR_ORIG_BE_NAME *optional 2N/A * BE_ATTR_SNAP_NAME *required 2N/A * BE_SUCCESS - Success 2N/A * be_errno_t - Failure 2N/A * Check to see if we have write access to the root filesystem 2N/A /* Initialize libzfs handle */ 2N/A /* Get original BE name if one was provided */ 2N/A "failed to lookup BE_ATTR_ORIG_BE_NAME attribute\n"));
2N/A /* If original BE name not provided, use current BE */ 2N/A /* Validate original BE name */ 2N/A /* Get snapshot name to rollback to */ 2N/A "failed to lookup BE_ATTR_SNAP_NAME attribute.\n"));
2N/A /* Find which zpool obe_name lives in */ 2N/A "zpool_iter failed: %s\n"),
2N/A /* Generate string for BE's root dataset */ 2N/A /* Get handle to BE's root dataset */ 2N/A "failed to open BE root dataset (%s): %s\n"),
2N/A * Check that snapshot name exists for this BE and all of its 2N/A * children file systems. This call will end up closing the 2N/A * zfs handle passed in whether it succeeds or fails. 2N/A /* Get handle to BE's root dataset */ 2N/A "failed to open BE root dataset (%s): %s\n"),
2N/A * Iterate through a BE's datasets and roll them all back to 2N/A * the specified snapshot. This call will end up closing the 2N/A * zfs handle passed in whether it succeeds or fails. 2N/A/* ******************************************************************** */ 2N/A/* Semi-Private Functions */ 2N/A/* ******************************************************************** */ 2N/A * Function: _be_create_snapshot 2N/A * Description: see be_create_snapshot 2N/A * be_name - The name of the BE that we're taking a snapshot of. 2N/A * altpool - Pointer to alternate "pool" area to find the BE. 2N/A * snap_name - The name of the snapshot we're creating. If 2N/A * snap_name is NULL an auto generated name will be used, 2N/A * and upon success, will return that name via this 2N/A * reference pointer. The caller is responsible for 2N/A * freeing the returned name. 2N/A * policy - The clean-up policy type. (library wide use only) 2N/A * BE_SUCCESS - Success 2N/A * be_errno_t - Failure 2N/A * Semi-private (library wide use only) 2N/A * Check to see if we're operating inside a Solaris Container 2N/A * or the Global Zone. 2N/A /* Set parameters in bt structure */ 2N/A /* If original BE name not supplied, use current BE */ 2N/A /* Find which zpool obe_name lives in */ 2N/A "zpool_iter failed: %s\n"),
2N/A * Check to see if this is an attempt to create a BE 2N/A * snapshot of a zone BE that is not associated with the 2N/A * currently active global zone. 2N/A "not supported on unbootable BE\n"));
2N/A /* If BE policy not specified, use the default policy */ 2N/A /* Validate policy type */ 2N/A * If snapshot name not specified, set auto name flag and 2N/A * generate auto snapshot name. 2N/A "failed to create auto snapshot name\n"));
2N/A /* Generate the name of the snapshot to take. */ 2N/A /* Get handle to BE's root dataset */ 2N/A "failed to open BE root dataset (%s): %s\n"),
2N/A /* Get the ZFS pool version of the pool where this dataset resides */ 2N/A * If ZFS pool version supports snapshot user properties, store 2N/A * cleanup policy there. Otherwise don't set one - this 2N/A * snapshot will always inherit the cleanup policy from 2N/A "internal error: out of memory\n"));
2N/A "internal error: out of memory\n"));
2N/A * If an explicit cleanup policy was requested 2N/A * by the caller and we don't support it, error out. 2N/A "cleanup policy: ZFS pool version is %d\n"),
2N/A /* Create the snapshots recursively */ 2N/A "recursive snapshot of %s failed: %s\n"),
2N/A /* Sleep 1 before retrying */ 2N/A /* Generate new auto snapshot name. */ 2N/A "be_create_snapshot: failed to " 2N/A "create auto snapshot name\n"));
2N/A /* Generate string of the snapshot to take. */ 2N/A /* Create the snapshots recursively */ 2N/A "be_create_snapshot: " 2N/A "recursive snapshot of %s " 2N/A * If we exhausted the maximum number of tries, 2N/A * free the auto snap name and set error. 2N/A "failed to create unique auto snapshot " 2N/A * If we succeeded in creating an auto named snapshot, store 2N/A * the name in the nvlist passed in by the caller. 2N/A * Function: _be_destroy_snapshot 2N/A * Description: see be_destroy_snapshot 2N/A * be_name - The name of the BE that the snapshot belongs to. 2N/A * snap_name - The name of the snapshot we're destroying. 2N/A * BE_SUCCESS - Success 2N/A * be_errno_t - Failure 2N/A * Semi-private (library wide use only) 2N/A /* Make sure we actaully have a snapshot name */ 2N/A "invalid snapshot name\n"));
2N/A /* Set parameters in bt structure */ 2N/A /* If original BE name not supplied, use current BE */ 2N/A /* Find which zpool be_name lives in */ 2N/A "zpool_iter failed: %s\n"),
2N/A * Detect if the BE snapshot to destroy has the 'active on boot' 2N/A "not supported on unbootable BE\n"));
2N/A * The zfs_open failed, return an error. 2N/A "failed to open BE root dataset (%s): %s\n"),
2N/A * Generate the name of the snapshot to take. 2N/A * destroy the snapshot. 2N/A * The boolean set to B_FALSE and passed to zfs_destroy_snaps() 2N/A * tells zfs to process and destroy the snapshots now. 2N/A * Otherwise the call will potentially return where the 2N/A * snapshot isn't actually destroyed yet, and ZFS is waiting 2N/A * until all the references to the snapshot have been 2N/A * released before actually destroying the snapshot. 2N/A "failed to destroy snapshot %s: %s\n"),
ss,
2N/A/* ******************************************************************** */ 2N/A/* Private Functions */ 2N/A/* ******************************************************************** */ 2N/A * Function: be_rollback_check_callback 2N/A * Description: Callback function used to iterate through a BE's filesystems 2N/A * to check if a given snapshot name exists. 2N/A * zhp - zfs_handle_t pointer to filesystem being processed. 2N/A * data - name of the snapshot to check for. 2N/A * 0 - Success, snapshot name exists for all filesystems. 2N/A * be_errno_t - Failure, snapshot name does not exist for all 2N/A /* Generate string for this filesystem's snapshot name */ 2N/A /* Check if snapshot exists */ 2N/A "snapshot does not exist %s\n"),
ss);
2N/A /* Iterate this dataset's children and check them */ 2N/A * Function: be_rollback_callback 2N/A * Description: Callback function used to iterate through a BE's filesystems 2N/A * and roll them all back to the specified snapshot name. 2N/A * zhp - zfs_handle_t pointer to filesystem being processed. 2N/A * data - name of snapshot to rollback to. 2N/A * be_errno_t - Failure 2N/A /* Generate string for this filesystem's snapshot name */ 2N/A /* Get handle to this filesystem's snapshot */ 2N/A /* Rollback dataset */ 2N/A "failed to rollback BE dataset %s to snapshot %s: %s\n"),
2N/A /* Iterate this dataset's children and roll them back */