/*
* 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
*/
/*
*/
/*
* System includes
*/
#include <stdio.h>
#include <strings.h>
#include <libzfs.h>
#include "libbe.h"
static void usage(void);
typedef struct be_command {
const char *name;
} be_command_t;
{ "create", be_do_create },
{ "destroy", be_do_destroy },
{ "list", be_do_list },
{ "mount", be_do_mount },
{ "unmount", be_do_unmount },
{ "rename", be_do_rename },
{ "activate", be_do_activate },
{ "create_snap", be_do_create_snapshot },
{ "destroy_snap", be_do_destroy_snapshot },
};
{{"libbe:prop1", "libbe:prop2"},
{"libbe:prop3", "mountpoint"},
{"libbe:prop5", "libbe:prop6"}};
{{"val1", "val2"},
{"val3", "/foodir"},
{"val5", "val6"}};
{{"libbe:prop1", "libbe:prop2"},
{"libbe:prop3", "libbe:prop4"},
{"libbe:prop5", "libbe:prop6"},
{"libbe:prop7", "mountpoint"}};
{{"val1", "val2"},
{"val3", "val4"},
{"val5", "val6"},
{"val7", "/mydir"}};
static void
usage(void)
{
(void) printf("usage:\n"
"\ttbeadm\n"
"\ttbeadm create [-d BE_desc] [-e nonActiveBe | -i [-n]] \n"
"\t\t[-o property=value] ... [-p zpool] [beName]\n"
"\ttbeadm destroy [-fs] beName\n"
"\ttbeadm create_snap [-p policy] beName [snapshot]\n"
"\ttbeadm destroy_snap beName snapshot\n"
"\ttbeadm list [-s] [beName]\n"
"\ttbeadm mount [-s ro|rw] beName mountpoint\n"
"\ttbeadm unmount [-f] beName\n"
"\ttbeadm rename origBeName newBeName\n"
"\ttbeadm activate beName\n"
"\ttbeadm rollback beName snapshot\n");
}
int
if (argc < 2) {
usage();
return (1);
}
/* Turn error printing on */
} else {
usage();
return (1);
}
/* NOTREACHED */
}
static int
{
int c;
printf("nvlist_alloc failed.\n");
return (1);
}
switch (c) {
case 'd':
break;
case 'e':
break;
case 'i':
/* Special option to test be_init() function */
break;
case 'n':
/* Initialize a nested BE. */
break;
case 'a':
/* Allow auto-naming when initializing a BE */
break;
case 'o':
0) != 0) {
printf("nvlist_alloc failed.\n");
return (1);
}
}
"'=' for -o option\n");
return (1);
}
*propval = '\0';
propval++;
&strval) == 0) {
"specified multiple times\n", propname);
return (1);
}
!= 0) {
"error: out of memory\n");
return (1);
}
break;
case 'p':
break;
default:
usage();
return (1);
}
}
printf("ERROR: -e and -i are exclusive options\n");
usage();
return (1);
}
if (argc == 1) {
} else if (argc > 1) {
usage();
return (1);
}
if (obe_name) {
/*
* Check if obe_name is really a snapshot name.
* If so, split it out.
*/
cp[0] = '\0';
}
}
}
printf("nvlist_alloc failed.\n");
return (1);
}
if (zfs_props) {
zfs_props) != 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_ZFS_PROPERTES (%s).\n", zfs_props);
return (1);
}
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_ORIG_BE_NAME (%s).\n", obe_name);
return (1);
}
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_SNAP_NANE (%s).\n", snap_name);
return (1);
}
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_NEW_BE_POOL (%s).\n", nbe_zpool);
return (1);
}
}
if (nbe_name) {
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_NEW_BE_NAME (%s).\n", nbe_name);
return (1);
}
}
if (nbe_desc) {
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_NEW_BE_DESC (%s)\n", nbe_desc);
return (1);
}
}
if (init) {
int i, j;
/*
* Add boolean value to determine if we're initializing
* a nested BE.
*/
nested_be) != 0) {
return (1);
}
/*
* Add boolean value to determine if we're allowing
* auto-naming in case there is a BE name conflict.
*/
return (1);
}
/*
* Add the default file system test values to test
* creating an initial BE.
*/
printf("nvlist_add_uint16 failed for BE_ATTR_FS_NUM "
"(%d).\n", fs_num);
return (1);
}
printf("nvlist_add_string_array failed for "
"BE_ATTR_FS_NAMES\n");
return (1);
}
/* Add properties for the non-shared filesystems. */
if ((fs_zfs_props_nvlist_array =
printf("memory allocation failed\n");
return (1);
}
for (i = 0; i < fs_num; i++) {
if (nvlist_alloc(&fs_zfs_props_nvlist_array[i],
NV_UNIQUE_NAME, 0) != 0) {
printf("nvlist_alloc_failed\n");
return (1);
}
for (j = 0; j < fs_num_props; j++) {
if (nvlist_add_string(
fs_zfs_prop_names[i][j],
fs_zfs_prop_values[i][j]) != 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_FS_ZFS_PROPERTIES\n");
return (1);
}
}
}
fs_zfs_props_nvlist_array, fs_num) != 0) {
printf("nvlist_add_nvlist_array failed for "
"BE_ATTR_FS_ZFS_PROPERTIES\n");
return (1);
}
shared_fs_num) != 0) {
printf("nvlist_add_uint16 failed for "
"BE_ATTR_SHARED_FS_NUM (%d).\n", shared_fs_num);
return (1);
}
shared_fs_names, shared_fs_num) != 0) {
printf("nvlist_add_string_array failed for "
"BE_ATTR_SHARED_FS_NAMES\n");
return (1);
}
/* Add properties for the shared filesystems. */
printf("memory allocation failed\n");
return (1);
}
for (i = 0; i < shared_fs_num; i++) {
NV_UNIQUE_NAME, 0) != 0) {
printf("nvlist_alloc_failed\n");
return (1);
}
for (j = 0; j < shared_fs_num_props; j++) {
if (nvlist_add_string(
shared_fs_zfs_prop_names[i][j],
shared_fs_zfs_prop_values[i][j]) != 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_SHARED_FS_ZFS_PROPERTIES\n");
return (1);
}
}
}
printf("nvlist_add_nvlist_array failed for "
"BE_ATTR_SHARED_FS_ZFS_PROPERTIES\n");
return (1);
}
/*
* We requested to allow auto named BE; find out the
* name of the BE that was initialized for us.
*/
&nbe_name) != 0) {
printf("failed to get BE_ATTR_NEW_BE_NAME "
"attribute\n");
ret = 1;
} else {
}
}
return (ret);
}
/*
* We requested an auto named BE; find out the
* name of the BE that was created for us and
* the auto snapshot created from the original BE.
*/
&nbe_name) != 0) {
printf("failed to get BE_ATTR_NEW_BE_NAME attribute\n");
ret = 1;
} else {
}
&snap_name) != 0) {
printf("failed to get BE_ATTR_SNAP_NAME attribute\n");
ret = 1;
} else {
}
}
return (ret);
}
static int
{
int c;
int destroy_flags = 0;
char *be_name;
switch (c) {
case 'f':
break;
case 's':
break;
default:
usage();
return (1);
}
}
if (argc != 1) {
usage();
return (1);
}
printf("nvlist_alloc failed.\n");
return (1);
}
printf("nvlist_add_string failed for BE_ATTR_NEW_BE_NAME "
"(%s).\n", argv[0]);
return (1);
}
!= 0) {
printf("nvlist_add_uint16 failed for "
"BE_ATTR_DESTROY_FLAGS.\n");
return (1);
}
return (be_destroy(be_attrs));
}
static int
{
int c = 0;
switch (c) {
case 's':
break;
default:
usage();
return (1);
}
}
if (argc == 1) {
} else {
}
if (err == BE_SUCCESS) {
"BE name\t\tActive\tActive \tBootable Dataset\t\t\t"
"Policy\tUUID\n");
" \t\t \ton boot\t\t \t\t \t \n");
"-------\t\t------\t-------\t-------- -------\t\t\t"
"------\t----\n");
printf("%s%s%s\t%s\t%s\t %s\t%s%s\t%s\n",
if (snaps) {
printf("Snapshot Name\n");
printf("--------------\n");
printf("%s\n",
}
}
}
}
return (err);
}
static int
{
char *obe_name;
char *nbe_name;
usage();
return (1);
}
printf("nvlist_alloc failed.\n");
return (1);
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_ORIG_BE_NAME (%s).\n", obe_name);
return (1);
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_NEW_BE_NAME (%s).\n", nbe_name);
return (1);
}
}
static int
{
int c;
switch (c) {
case 'p':
break;
default:
usage();
return (1);
}
}
usage();
return (1);
}
if (argc > 1) {
/* Snapshot name provided */
}
printf("nvlist_alloc failed.\n");
return (1);
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_ORIG_BE_NAME (%s).\n", obe_name);
return (1);
}
if (policy) {
printf("nvlist_add_string failed for "
"BE_ATTR_POLICY (%s).\n", policy);
return (1);
}
}
if (snap_name) {
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_SNAP_NAME (%s).\n", snap_name);
return (1);
}
}
/*
* We requested an auto named snapshot; find out
* the snapshot name that was created for us.
*/
&snap_name) != 0) {
printf("failed to get BE_ATTR_SNAP_NAME attribute\n");
ret = 1;
} else {
}
}
return (ret);
}
static int
{
char *obe_name;
char *snap_name;
if (argc != 2) {
usage();
return (1);
}
printf("nvlist_alloc failed.\n");
return (1);
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_ORIG_BE_NAME (%s).\n", obe_name);
return (1);
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_SNAP_NAME (%s).\n", snap_name);
return (1);
}
return (be_destroy_snapshot(be_attrs));
}
static int
{
char *obe_name;
char *snap_name;
usage();
return (1);
}
printf("nvlist_alloc failed.\n");
return (1);
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_ORIG_BE_NAME (%s).\n", obe_name);
return (1);
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_SNAP_NAME (%s).\n", snap_name);
return (1);
}
return (be_rollback(be_attrs));
}
static int
{
char *obe_name;
usage();
return (1);
}
printf("nvlist_alloc failed.\n");
return (1);
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_ORIG_BE_NAME (%s).\n", obe_name);
return (1);
}
return (be_activate(be_attrs));
}
static int
{
int c;
int mount_flags = 0;
char *obe_name;
char *mountpoint;
switch (c) {
case 's':
printf("The -s flag requires an argument "
"[ rw | ro ]\n");
usage();
return (1);
}
break;
default:
usage();
return (1);
}
}
usage();
return (1);
}
if (argc == 2) {
} else {
/*
* XXX - Need to generate a random mountpoint here;
* right now we're just exitting if one isn't supplied.
*/
usage();
return (1);
}
printf("nvlist_alloc failed.\n");
return (1);
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_ORIG_BE_NAME (%s).\n", obe_name);
return (1);
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_MOUNTPOINT (%s).\n", mountpoint);
return (1);
}
if (shared_fs) {
mount_flags) != 0) {
printf("nvlist_add_uint16 failed for "
"BE_ATTR_MOUNT_FLAGS (%d).\n", mount_flags);
return (1);
}
}
}
static int
{
int c;
int unmount_flags = 0;
char *obe_name;
switch (c) {
case 'f':
break;
default:
usage();
return (1);
}
}
if (argc != 1) {
usage();
return (1);
}
printf("nvlist_alloc failed.\n");
return (1);
}
!= 0) {
printf("nvlist_add_string failed for "
"BE_ATTR_ORIG_BE_NAME (%s).\n", obe_name);
return (1);
}
!= 0) {
printf("nvlist_add_uint16 failed for "
"BE_ATTR_UNMOUNT_FLAGS\n");
return (1);
}
return (be_unmount(be_attrs));
}