summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2018-10-18 13:19:25 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2018-10-18 13:19:25 +0000
commitc6d34d2b1dfd2a8be003867d868e26d325f8584f (patch)
tree5c36cac7ab2fa45b173ddb059b691107e8464e9d
parent6b508e02be117789a6cab7fa09de1f41250a04a6 (diff)
parenta897f28bdf15b072de311fba1dadf86da4f4b420 (diff)
downloadillumos-joyent-c6d34d2b1dfd2a8be003867d868e26d325f8584f.tar.gz
[illumos-gate merge]
commit a897f28bdf15b072de311fba1dadf86da4f4b420 9892 Most consumers of be_list() do not need snapshots commit 4ac23efef166d029b8dda8f16179b1ab9a70c27a 9891 libbe slow building snapshot list commit abc102c3e125a6b08c1d5b54449c08b53b45978a 9889 libbe reads defaults too often
-rw-r--r--usr/src/cmd/beadm/beadm.c4
-rw-r--r--usr/src/cmd/boot/bootadm/bootadm.c6
-rw-r--r--usr/src/cmd/boot/bootadm/bootadm_loader.c9
-rw-r--r--usr/src/lib/libbe/common/be_activate.c6
-rw-r--r--usr/src/lib/libbe/common/be_list.c196
-rw-r--r--usr/src/lib/libbe/common/be_utils.c9
-rw-r--r--usr/src/lib/libbe/common/libbe.h10
-rw-r--r--usr/src/lib/libbe/common/libbe_priv.h5
-rw-r--r--usr/src/lib/pylibbe/common/libbe_py.c25
9 files changed, 143 insertions, 127 deletions
diff --git a/usr/src/cmd/beadm/beadm.c b/usr/src/cmd/beadm/beadm.c
index 3667c762a4..ee18dcdcb5 100644
--- a/usr/src/cmd/beadm/beadm.c
+++ b/usr/src/cmd/beadm/beadm.c
@@ -26,6 +26,7 @@
* Copyright 2015 Gary Mills
* Copyright (c) 2015 by Delphix. All rights reserved.
* Copyright 2017 Jason King
+ * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
*/
/*
@@ -1147,7 +1148,8 @@ be_do_list(int argc, char **argv)
if (argc == 1)
be_name = argv[0];
- err = be_list(be_name, &be_nodes);
+ err = be_list(be_name, &be_nodes,
+ snaps ? BE_LIST_SNAPSHOTS : BE_LIST_DEFAULT);
switch (err) {
case BE_SUCCESS:
diff --git a/usr/src/cmd/boot/bootadm/bootadm.c b/usr/src/cmd/boot/bootadm/bootadm.c
index bedca2a6b5..36d167fafb 100644
--- a/usr/src/cmd/boot/bootadm/bootadm.c
+++ b/usr/src/cmd/boot/bootadm/bootadm.c
@@ -1137,7 +1137,7 @@ install_bootloader(void)
goto done;
}
- if (be_list(NULL, &be_nodes) != BE_SUCCESS) {
+ if (be_list(NULL, &be_nodes, BE_LIST_DEFAULT) != BE_SUCCESS) {
bam_error(_("No BE's found\n"));
goto done;
}
@@ -1197,7 +1197,7 @@ install_bootloader(void)
}
}
- if (be_list(NULL, &be_nodes) != BE_SUCCESS) {
+ if (be_list(NULL, &be_nodes, BE_LIST_DEFAULT) != BE_SUCCESS) {
bam_error(_("No BE's found\n"));
ret = BAM_ERROR;
goto done;
@@ -3312,7 +3312,7 @@ is_be(char *root)
/*
* Check if the current dataset is BE
*/
- if (be_list(NULL, &be_nodes) == BE_SUCCESS) {
+ if (be_list(NULL, &be_nodes, BE_LIST_DEFAULT) == BE_SUCCESS) {
for (cur_be = be_nodes; cur_be != NULL;
cur_be = cur_be->be_next_node) {
diff --git a/usr/src/cmd/boot/bootadm/bootadm_loader.c b/usr/src/cmd/boot/bootadm/bootadm_loader.c
index 56b509b9ed..6f96f4b053 100644
--- a/usr/src/cmd/boot/bootadm/bootadm_loader.c
+++ b/usr/src/cmd/boot/bootadm/bootadm_loader.c
@@ -26,6 +26,7 @@
/*
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
* Copyright 2016 Toomas Soome <tsoome@me.com>
+ * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
*/
/*
@@ -282,7 +283,7 @@ menu_read(struct menu_lst *menu, char *menu_path)
if (fp == NULL)
return (BAM_ERROR);
- if (be_list(NULL, &be_nodes) != BE_SUCCESS)
+ if (be_list(NULL, &be_nodes, BE_LIST_DEFAULT) != BE_SUCCESS)
be_nodes = NULL;
/*
@@ -718,7 +719,7 @@ bam_mount_be(menu_entry_t *entry, char **dir)
goto out;
}
- ret = be_list(NULL, &be_nodes);
+ ret = be_list(NULL, &be_nodes, BE_LIST_DEFAULT);
if (ret != BE_SUCCESS) {
goto out;
}
@@ -1028,7 +1029,7 @@ update_entry(struct menu_lst *menu, char *menu_root, char *osdev)
FILE *fp;
(void) snprintf(path, PATH_MAX, "%s%s", menu_root, MENU);
- rv = be_list(NULL, &be_nodes);
+ rv = be_list(NULL, &be_nodes, BE_LIST_DEFAULT);
if (rv != BE_SUCCESS)
return (BAM_ERROR);
@@ -1205,7 +1206,7 @@ list_setting(struct menu_lst *menu, char *which, char *setting)
/* find default entry */
if (entry == -1) {
- ret = be_list(NULL, &be_nodes);
+ ret = be_list(NULL, &be_nodes, BE_LIST_DEFAULT);
if (ret != BE_SUCCESS) {
bam_error(_("No BE's found\n"));
return (BAM_ERROR);
diff --git a/usr/src/lib/libbe/common/be_activate.c b/usr/src/lib/libbe/common/be_activate.c
index 7b0f3cda52..9fd95e1e8a 100644
--- a/usr/src/lib/libbe/common/be_activate.c
+++ b/usr/src/lib/libbe/common/be_activate.c
@@ -26,6 +26,7 @@
/*
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
* Copyright 2016 Toomas Soome <tsoome@me.com>
+ * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
*/
#include <assert.h>
@@ -275,7 +276,8 @@ _be_activate(char *be_name)
}
}
- if ((ret = _be_list(cb.obe_name, &be_nodes)) != BE_SUCCESS) {
+ if ((ret = _be_list(cb.obe_name, &be_nodes, BE_LIST_DEFAULT))
+ != BE_SUCCESS) {
return (ret);
}
@@ -445,7 +447,7 @@ be_is_active_on_boot(char *be_name)
return (B_FALSE);
}
- if (_be_list(be_name, &be_node) != BE_SUCCESS) {
+ if (_be_list(be_name, &be_node, BE_LIST_DEFAULT) != BE_SUCCESS) {
return (B_FALSE);
}
diff --git a/usr/src/lib/libbe/common/be_list.c b/usr/src/lib/libbe/common/be_list.c
index d56a9b6974..926b7260da 100644
--- a/usr/src/lib/libbe/common/be_list.c
+++ b/usr/src/lib/libbe/common/be_list.c
@@ -29,6 +29,7 @@
* Copyright 2015 Toomas Soome <tsoome@me.com>
* Copyright 2015 Gary Mills
* Copyright (c) 2016 Martin Matuska. All rights reserved.
+ * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
*/
#include <assert.h>
@@ -55,7 +56,11 @@ typedef struct list_callback_data {
char *be_name;
be_node_list_t *be_nodes_head;
be_node_list_t *be_nodes;
+ be_dataset_list_t **be_datasets_tail;
+ be_snapshot_list_t **be_snapshots_tail;
char current_be[MAXPATHLEN];
+ struct be_defaults be_defaults;
+ uint64_t flags;
} list_callback_data_t;
/*
@@ -81,6 +86,7 @@ static int be_qsort_compare_BEs_space_rev(const void *, const void *);
static int be_qsort_compare_snapshots(const void *x, const void *y);
static int be_qsort_compare_datasets(const void *x, const void *y);
static void *be_list_alloc(int *, size_t);
+static int be_allocate_callback_nodes(list_callback_data_t *);
/*
* Private data.
@@ -116,7 +122,7 @@ static boolean_t zone_be = B_FALSE;
* Public
*/
int
-be_list(char *be_name, be_node_list_t **be_nodes)
+be_list(char *be_name, be_node_list_t **be_nodes, uint64_t flags)
{
int ret = BE_SUCCESS;
@@ -133,7 +139,7 @@ be_list(char *be_name, be_node_list_t **be_nodes)
}
}
- ret = _be_list(be_name, be_nodes);
+ ret = _be_list(be_name, be_nodes, flags);
be_zfs_fini();
@@ -213,7 +219,7 @@ be_sort(be_node_list_t **be_nodes, int order)
* Semi-private (library wide use only)
*/
int
-_be_list(char *be_name, be_node_list_t **be_nodes)
+_be_list(char *be_name, be_node_list_t **be_nodes, uint64_t flags)
{
list_callback_data_t cb = { 0 };
be_transaction_data_t bt = { 0 };
@@ -221,12 +227,12 @@ _be_list(char *be_name, be_node_list_t **be_nodes)
int sret;
zpool_handle_t *zphp;
char *rpool = NULL;
- struct be_defaults be_defaults;
if (be_nodes == NULL)
return (BE_ERR_INVAL);
- be_get_defaults(&be_defaults);
+ be_get_defaults(&cb.be_defaults);
+ cb.flags = flags;
if (be_find_current_be(&bt) != BE_SUCCESS) {
/*
@@ -248,7 +254,7 @@ _be_list(char *be_name, be_node_list_t **be_nodes)
if (be_name != NULL)
cb.be_name = strdup(be_name);
- if (be_defaults.be_deflt_rpool_container && rpool != NULL) {
+ if (cb.be_defaults.be_deflt_rpool_container && rpool != NULL) {
if ((zphp = zpool_open(g_zfs, rpool)) == NULL) {
be_print_err(gettext("be_list: failed to "
"open rpool (%s): %s\n"), rpool,
@@ -384,16 +390,14 @@ be_get_zone_be_list(char *zone_be_name, char *zone_be_container_ds,
(void) strcpy(be_container_ds, zone_be_container_ds);
- if (cb.be_nodes_head == NULL) {
- if ((cb.be_nodes_head = be_list_alloc(&ret,
- sizeof (be_node_list_t))) == NULL) {
- ZFS_CLOSE(zhp);
- goto cleanup;
- }
- cb.be_nodes = cb.be_nodes_head;
+ if ((ret = be_allocate_callback_nodes(&cb)) != BE_SUCCESS) {
+ ZFS_CLOSE(zhp);
+ goto cleanup;
}
- if (ret == 0)
+ if (ret == 0) {
+ be_get_defaults(&cb.be_defaults);
ret = zfs_iter_filesystems(zhp, be_add_children_callback, &cb);
+ }
ZFS_CLOSE(zhp);
*zbe_nodes = cb.be_nodes_head;
@@ -489,14 +493,10 @@ be_get_list_callback(zpool_handle_t *zlp, void *data)
* within the pool
*/
if (cb->be_name != NULL) {
- if (cb->be_nodes_head == NULL) {
- if ((cb->be_nodes_head = be_list_alloc(&ret,
- sizeof (be_node_list_t))) == NULL) {
- ZFS_CLOSE(zhp);
- zpool_close(zlp);
- return (ret);
- }
- cb->be_nodes = cb->be_nodes_head;
+ if ((ret = be_allocate_callback_nodes(cb)) != BE_SUCCESS) {
+ ZFS_CLOSE(zhp);
+ zpool_close(zlp);
+ return (ret);
}
if ((ret = be_get_node_data(zhp, cb->be_nodes, cb->be_name,
@@ -505,8 +505,9 @@ be_get_list_callback(zpool_handle_t *zlp, void *data)
zpool_close(zlp);
return (ret);
}
- ret = zfs_iter_snapshots(zhp, B_FALSE, be_add_children_callback,
- cb);
+ if (cb->flags & BE_LIST_SNAPSHOTS)
+ ret = zfs_iter_snapshots(zhp, B_FALSE,
+ be_add_children_callback, cb);
}
if (ret == 0)
@@ -518,6 +519,38 @@ be_get_list_callback(zpool_handle_t *zlp, void *data)
}
/*
+ * Function: be_allocate_callback_nodes
+ * Description: Function to create the be_nodes list in the callback data
+ * structure, and set up tail pointers to the dataset and
+ * snapshot lists.
+ * Parameters:
+ * data - pointer to the callback data.
+ * Returns:
+ * 0 - Success
+ * be_errno_t - Failure
+ * Scope:
+ * Private
+ */
+static int
+be_allocate_callback_nodes(list_callback_data_t *cb)
+{
+ int ret = BE_SUCCESS;
+
+ if (cb->be_nodes_head != NULL)
+ return (BE_SUCCESS);
+
+ if ((cb->be_nodes_head = be_list_alloc(&ret, sizeof (be_node_list_t)))
+ == NULL)
+ return (ret);
+
+ cb->be_nodes = cb->be_nodes_head;
+ cb->be_snapshots_tail = &cb->be_nodes->be_node_snapshots;
+ cb->be_datasets_tail = &cb->be_nodes->be_node_datasets;
+
+ return (BE_SUCCESS);
+}
+
+/*
* Function: be_add_children_callback
* Description: Callback function used by zfs_iter to look through all
* the datasets and snapshots for each BE and add them to
@@ -539,9 +572,6 @@ be_add_children_callback(zfs_handle_t *zhp, void *data)
list_callback_data_t *cb = (list_callback_data_t *)data;
char *str = NULL, *ds_path = NULL;
int ret = 0;
- struct be_defaults be_defaults;
-
- be_get_defaults(&be_defaults);
ds_path = str = strdup(zfs_get_name(zhp));
@@ -549,60 +579,38 @@ be_add_children_callback(zfs_handle_t *zhp, void *data)
* get past the end of the container dataset plus the trailing "/"
*/
str = str + (strlen(be_container_ds) + 1);
- if (be_defaults.be_deflt_rpool_container) {
+ if (cb->be_defaults.be_deflt_rpool_container) {
/* just skip if invalid */
if (!be_valid_be_name(str))
return (BE_SUCCESS);
}
- if (cb->be_nodes_head == NULL) {
- if ((cb->be_nodes_head = be_list_alloc(&ret,
- sizeof (be_node_list_t))) == NULL) {
- ZFS_CLOSE(zhp);
- return (ret);
- }
- cb->be_nodes = cb->be_nodes_head;
+ if (cb->be_nodes_head == NULL &&
+ (ret = be_allocate_callback_nodes(cb)) != BE_SUCCESS) {
+ ZFS_CLOSE(zhp);
+ return (ret);
}
if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT && !zone_be) {
- be_snapshot_list_t *snapshots = NULL;
- if (cb->be_nodes->be_node_snapshots == NULL) {
- if ((cb->be_nodes->be_node_snapshots =
- be_list_alloc(&ret, sizeof (be_snapshot_list_t)))
- == NULL || ret != BE_SUCCESS) {
- ZFS_CLOSE(zhp);
- return (ret);
- }
- cb->be_nodes->be_node_snapshots->be_next_snapshot =
- NULL;
- snapshots = cb->be_nodes->be_node_snapshots;
- } else {
- for (snapshots = cb->be_nodes->be_node_snapshots;
- snapshots != NULL;
- snapshots = snapshots->be_next_snapshot) {
- if (snapshots->be_next_snapshot != NULL)
- continue;
- /*
- * We're at the end of the list add the
- * new snapshot.
- */
- if ((snapshots->be_next_snapshot =
- be_list_alloc(&ret,
- sizeof (be_snapshot_list_t))) == NULL ||
- ret != BE_SUCCESS) {
- ZFS_CLOSE(zhp);
- return (ret);
- }
- snapshots = snapshots->be_next_snapshot;
- snapshots->be_next_snapshot = NULL;
- break;
- }
+ be_snapshot_list_t *snapshot;
+
+ if ((snapshot = be_list_alloc(&ret,
+ sizeof (be_snapshot_list_t))) == NULL ||
+ ret != BE_SUCCESS) {
+ ZFS_CLOSE(zhp);
+ return (ret);
}
- if ((ret = be_get_ss_data(zhp, str, snapshots,
+
+ if ((ret = be_get_ss_data(zhp, str, snapshot,
cb->be_nodes)) != BE_SUCCESS) {
+ free(snapshot);
ZFS_CLOSE(zhp);
return (ret);
}
+
+ snapshot->be_next_snapshot = NULL;
+ *cb->be_snapshots_tail = snapshot;
+ cb->be_snapshots_tail = &snapshot->be_next_snapshot;
} else if (strchr(str, '/') == NULL) {
if (cb->be_nodes->be_node_name != NULL) {
if ((cb->be_nodes->be_next_node =
@@ -632,46 +640,30 @@ be_add_children_callback(zfs_handle_t *zhp, void *data)
return (ret);
}
} else if (strchr(str, '/') != NULL && !zone_be) {
- be_dataset_list_t *datasets = NULL;
- if (cb->be_nodes->be_node_datasets == NULL) {
- if ((cb->be_nodes->be_node_datasets =
- be_list_alloc(&ret, sizeof (be_dataset_list_t)))
- == NULL || ret != BE_SUCCESS) {
- ZFS_CLOSE(zhp);
- return (ret);
- }
- cb->be_nodes->be_node_datasets->be_next_dataset = NULL;
- datasets = cb->be_nodes->be_node_datasets;
- } else {
- for (datasets = cb->be_nodes->be_node_datasets;
- datasets != NULL;
- datasets = datasets->be_next_dataset) {
- if (datasets->be_next_dataset != NULL)
- continue;
- /*
- * We're at the end of the list add
- * the new dataset.
- */
- if ((datasets->be_next_dataset =
- be_list_alloc(&ret,
- sizeof (be_dataset_list_t)))
- == NULL || ret != BE_SUCCESS) {
- ZFS_CLOSE(zhp);
- return (ret);
- }
- datasets = datasets->be_next_dataset;
- datasets->be_next_dataset = NULL;
- break;
- }
+ be_dataset_list_t *dataset;
+
+ if ((dataset = be_list_alloc(&ret,
+ sizeof (be_dataset_list_t))) == NULL ||
+ ret != BE_SUCCESS) {
+ ZFS_CLOSE(zhp);
+ return (ret);
}
if ((ret = be_get_ds_data(zhp, str,
- datasets, cb->be_nodes)) != BE_SUCCESS) {
+ dataset, cb->be_nodes)) != BE_SUCCESS) {
+ free(dataset);
ZFS_CLOSE(zhp);
return (ret);
}
+
+ dataset->be_next_dataset = NULL;
+ *cb->be_datasets_tail = dataset;
+ cb->be_datasets_tail = &dataset->be_next_dataset;
}
- ret = zfs_iter_children(zhp, be_add_children_callback, cb);
+ if (cb->flags & BE_LIST_SNAPSHOTS)
+ ret = zfs_iter_children(zhp, be_add_children_callback, cb);
+ else
+ ret = zfs_iter_filesystems(zhp, be_add_children_callback, cb);
if (ret != 0) {
be_print_err(gettext("be_add_children_callback: "
"encountered error: %s\n"),
@@ -1336,7 +1328,7 @@ be_get_ss_data(
* size - The size of memory to allocate.
* Returns:
* Success - A pointer to the allocated memory
- * Failure - NULL
+ * Failure - NULL
* Scope:
* Private
*/
diff --git a/usr/src/lib/libbe/common/be_utils.c b/usr/src/lib/libbe/common/be_utils.c
index fb2f662fc7..b29120c824 100644
--- a/usr/src/lib/libbe/common/be_utils.c
+++ b/usr/src/lib/libbe/common/be_utils.c
@@ -24,6 +24,7 @@
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
* Copyright 2016 Toomas Soome <tsoome@me.com>
* Copyright (c) 2015 by Delphix. All rights reserved.
+ * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
*/
@@ -140,7 +141,7 @@ be_get_boot_args(char **fbarg, int entry)
goto done;
}
- ret = _be_list(NULL, &be_nodes);
+ ret = _be_list(NULL, &be_nodes, BE_LIST_DEFAULT);
if (ret != BE_SUCCESS)
goto done;
@@ -2627,7 +2628,7 @@ be_print_err(char *prnt_str, ...)
/*
* Function: be_find_current_be
* Description: Find the currently "active" BE. Fill in the
- * passed in be_transaction_data_t reference with the
+ * passed in be_transaction_data_t reference with the
* active BE's data.
* Paramters:
* none
@@ -3679,7 +3680,7 @@ be_get_auto_name(char *obe_name, char *be_container_ds, boolean_t zone_be)
"be_get_zone_be_list failed\n"));
return (NULL);
}
- } else if (_be_list(NULL, &be_nodes) != BE_SUCCESS) {
+ } else if (_be_list(NULL, &be_nodes, BE_LIST_DEFAULT) != BE_SUCCESS) {
be_print_err(gettext("be_get_auto_name: be_list failed\n"));
return (NULL);
}
@@ -3971,7 +3972,7 @@ be_create_menu(
/*
* Now we need to add all the BE's back into the the file.
*/
- if (_be_list(NULL, &be_nodes) == BE_SUCCESS) {
+ if (_be_list(NULL, &be_nodes, BE_LIST_DEFAULT) == BE_SUCCESS) {
while (be_nodes != NULL) {
if (strcmp(pool, be_nodes->be_rpool) == 0) {
(void) be_append_menu(be_nodes->be_node_name,
diff --git a/usr/src/lib/libbe/common/libbe.h b/usr/src/lib/libbe/common/libbe.h
index a78f7a62f8..83dffd2dcd 100644
--- a/usr/src/lib/libbe/common/libbe.h
+++ b/usr/src/lib/libbe/common/libbe.h
@@ -27,6 +27,7 @@
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
* Copyright 2016 Toomas Soome <tsoome@me.com>
* Copyright 2015 Gary Mills
+ * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
*/
#ifndef _LIBBE_H
@@ -103,7 +104,7 @@ enum {
BE_ERR_INVALMOUNTPOINT, /* Unexpected mountpoint */
BE_ERR_MOUNT, /* mount failed */
BE_ERR_MOUNTED, /* already mounted */
- BE_ERR_NAMETOOLONG, /* name > BUFSIZ */
+ BE_ERR_NAMETOOLONG, /* name > BUFSIZ */
BE_ERR_NOENT, /* Doesn't exist */
BE_ERR_POOL_NOENT, /* No such pool */
BE_ERR_NODEV, /* No such device */
@@ -213,6 +214,11 @@ typedef struct be_node_list {
#define BE_INSTALLBOOT_FLAG_FORCE 0x00000002
#define BE_INSTALLBOOT_FLAG_VERBOSE 0x00000004
+/* Flags for be_list() */
+#define BE_LIST_DEFAULT 0x00000000
+#define BE_LIST_SNAPSHOTS 0x00000001
+#define BE_LIST_ALL BE_LIST_SNAPSHOTS
+
/* sort rules for be_sort() */
typedef enum {
BE_SORT_UNSPECIFIED = -1,
@@ -247,7 +253,7 @@ int be_rollback(nvlist_t *);
/*
* Functions for listing and getting information about existing BEs.
*/
-int be_list(char *, be_node_list_t **);
+int be_list(char *, be_node_list_t **, uint64_t);
void be_free_list(be_node_list_t *);
int be_max_avail(char *, uint64_t *);
char *be_err_to_str(int);
diff --git a/usr/src/lib/libbe/common/libbe_priv.h b/usr/src/lib/libbe/common/libbe_priv.h
index d9cb964c25..cdae3a7413 100644
--- a/usr/src/lib/libbe/common/libbe_priv.h
+++ b/usr/src/lib/libbe/common/libbe_priv.h
@@ -24,6 +24,7 @@
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
* Copyright 2016 Toomas Soome <tsoome@me.com>
* Copyright (c) 2015 by Delphix. All rights reserved.
+ * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
*/
#ifndef _LIBBE_PRIV_H
@@ -89,7 +90,7 @@ typedef struct be_transaction_data {
char *obe_zpool; /* Original BE pool */
char *obe_snap_name; /* Original BE snapshot name */
char *obe_altroot; /* Original BE altroot */
- char *nbe_name; /* New BE name */
+ char *nbe_name; /* New BE name */
char *nbe_root_ds; /* New BE root dataset */
char *nbe_zpool; /* New BE pool */
char *nbe_desc; /* New BE description */
@@ -151,7 +152,7 @@ int be_set_uuid(char *);
int be_get_uuid(const char *, uuid_t *);
/* be_list.c */
-int _be_list(char *, be_node_list_t **);
+int _be_list(char *, be_node_list_t **, uint64_t);
int be_get_zone_be_list(char *, char *, be_node_list_t **);
/* be_mount.c */
diff --git a/usr/src/lib/pylibbe/common/libbe_py.c b/usr/src/lib/pylibbe/common/libbe_py.c
index 9cc1a7ac81..fb5102bdb6 100644
--- a/usr/src/lib/pylibbe/common/libbe_py.c
+++ b/usr/src/lib/pylibbe/common/libbe_py.c
@@ -22,6 +22,7 @@
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2012 OmniTI Computer Consulting, Inc. All rights reserved.
+ * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
*/
#include <Python.h>
@@ -49,7 +50,7 @@ enum {
PyObject *beCreateSnapshot(PyObject *, PyObject *);
PyObject *beCopy(PyObject *, PyObject *);
-PyObject *beList(PyObject *, PyObject *);
+PyObject *beList(PyObject *, PyObject *, PyObject *);
PyObject *beActivate(PyObject *, PyObject *);
PyObject *beDestroy(PyObject *, PyObject *);
PyObject *beDestroySnapshot(PyObject *, PyObject *);
@@ -269,7 +270,8 @@ beCopy(PyObject *self, PyObject *args)
* to gather information about Boot Environments
* Parameters:
* args - pointer to a python object containing:
- * beName - The name of the BE to list (optional)
+ * bename - The name of the BE to list (optional)
+ * nosnaps - boolean indicating whether to exclude snapshots (optional)
*
* Returns a pointer to a python object. That Python object will consist of
* the return code and a list of Dicts or NULL.
@@ -280,14 +282,18 @@ beCopy(PyObject *self, PyObject *args)
*/
/* ARGSUSED */
PyObject *
-beList(PyObject *self, PyObject *args)
+beList(PyObject *self, PyObject *args, PyObject *keywds)
{
char *beName = NULL;
+ int noSnaps = 0;
int ret = BE_PY_SUCCESS;
be_node_list_t *list = NULL;
be_node_list_t *be = NULL;
PyObject *dict = NULL;
PyObject *listOfDicts = NULL;
+ uint64_t listopts = BE_LIST_SNAPSHOTS;
+
+ static char *kwlist[] = {"bename", "nosnaps", NULL};
if ((listOfDicts = PyList_New(0)) == NULL) {
ret = BE_PY_ERR_DICT;
@@ -295,12 +301,16 @@ beList(PyObject *self, PyObject *args)
goto done;
}
- if (!PyArg_ParseTuple(args, "|z", &beName)) {
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "|zi",
+ kwlist, &beName, &noSnaps)) {
ret = BE_PY_ERR_PARSETUPLE;
goto done;
}
- if ((ret = be_list(beName, &list)) != BE_SUCCESS) {
+ if (noSnaps)
+ listopts &= ~BE_LIST_SNAPSHOTS;
+
+ if ((ret = be_list(beName, &list, listopts)) != BE_SUCCESS) {
goto done;
}
@@ -641,7 +651,7 @@ beMount(PyObject *self, PyObject *args)
PyObject *
beUnmount(PyObject *self, PyObject *args)
{
- char *beName = NULL;
+ char *beName = NULL;
int force_unmount = 0;
int unmount_flags = 0;
int ret = BE_PY_SUCCESS;
@@ -1079,7 +1089,8 @@ static struct PyMethodDef libbeMethods[] = {
"Destroy a snapshot."},
{"beMount", (PyCFunction)beMount, METH_VARARGS, "Mount a BE."},
{"beUnmount", (PyCFunction)beUnmount, METH_VARARGS, "Unmount a BE."},
- {"beList", (PyCFunction)beList, METH_VARARGS, "List BE info."},
+ {"beList", (PyCFunction)beList, METH_VARARGS | METH_KEYWORDS,
+ "List BE info."},
{"beRename", (PyCFunction)beRename, METH_VARARGS, "Rename a BE."},
{"beActivate", (PyCFunction)beActivate, METH_VARARGS, "Activate a BE."},
{"beRollback", (PyCFunction)beRollback, METH_VARARGS, "Rollback a BE."},