/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2012 by Delphix. All rights reserved.
*/
#include <assert.h>
#include <libintl.h>
#include <libnvpair.h>
#include <libzfs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libbe.h>
#include <libbe_priv.h>
/* ******************************************************************** */
/* Public Functions */
/* ******************************************************************** */
/*
* Function: be_rename
* Description: Renames the BE from the original name to the new name
* passed in through be_attrs. Also the entries in vfstab and
* menu.lst are updated with the new name.
* Parameters:
* be_attrs - pointer to nvlist_t of attributes being passed in.
* The following attribute values are used by
* this function:
*
* BE_ATTR_ORIG_BE_NAME *required
* BE_ATTR_NEW_BE_NAME *required
* Return:
* BE_SUCCESS - Success
* be_errno_t - Failure
* Scope:
* Public
*/
int
{
/* Initialize libzfs handle */
if (!be_zfs_init())
return (BE_ERR_INIT);
/* Get original BE name to rename from */
!= 0) {
"lookup BE_ATTR_ORIG_BE_NAME attribute\n"));
be_zfs_fini();
return (BE_ERR_INVAL);
}
/* Get new BE name to rename to */
!= 0) {
"lookup BE_ATTR_NEW_BE_NAME attribute\n"));
be_zfs_fini();
return (BE_ERR_INVAL);
}
/*
* Get the currently active BE and check to see if this
* is an attempt to rename the currently active BE.
*/
"active BE\n"));
be_zfs_fini();
return (BE_ERR_CURR_BE_NOT_FOUND);
}
"the currently active BE, which is not supported\n"));
be_zfs_fini();
return (BE_ERR_RENAME_ACTIVE);
}
/* Validate original BE name */
be_zfs_fini();
return (BE_ERR_INVAL);
}
/* Validate new BE name */
be_zfs_fini();
return (BE_ERR_INVAL);
}
/* Find which zpool the BE is in */
be_zfs_fini();
return (BE_ERR_BE_NOENT);
} else if (zret < 0) {
be_zfs_fini();
return (ret);
}
/* New BE will reside in the same zpool as orig BE */
/*
* Generate a list of file systems from the BE that are legacy
* mounted before renaming. We use this list to determine which
* entries in the vfstab we need to update after we've renamed the BE.
*/
&fld)) != BE_SUCCESS) {
"get legacy mounted file system list for %s\n"),
goto done;
}
/* Get handle to BE's root dataset */
== NULL) {
"open BE root dataset (%s): %s\n"),
goto done;
}
/* Rename of BE's root dataset. */
goto done;
}
/* Refresh handle to BE's root dataset after the rename */
== NULL) {
"open BE root dataset (%s): %s\n"),
goto done;
}
/* If BE is already mounted, get its mountpoint */
"get altroot of mounted BE %s: %s\n"),
goto done;
}
/* Update BE's vfstab */
goto done;
}
/* Update this BE's GRUB menu entry */
"failed to update grub menu entry from %s to %s\n"),
}
done:
be_zfs_fini();
return (ret);
}