Skip to content

Commit

Permalink
DOSE-566 better error handling for pool import
Browse files Browse the repository at this point in the history
  • Loading branch information
grwilson committed Oct 6, 2021
1 parent 79aea74 commit 401276f
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 231 deletions.
8 changes: 4 additions & 4 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3756,7 +3756,7 @@ zpool_do_import(int argc, char **argv)
usage(B_FALSE);
}

if (zoa_resume_destroy(&idata) != 0) {
if (zoa_resume_destroy(g_zfs, &idata) != 0) {
(void) fprintf(stderr,
gettext("Error resuming destroy\n"));
return (1);
Expand Down Expand Up @@ -8747,9 +8747,9 @@ zpool_do_status(int argc, char **argv)
print_timestamp(timestamp_fmt);

if (cb.cb_print_destroyed)
zoa_list_destroyed_pools();
zoa_list_destroyed_pools(g_zfs);
if (cb.cb_clear_destroyed)
zoa_clear_destroyed_pools();
zoa_clear_destroyed_pools(g_zfs);
if (cb.cb_clear_destroyed || cb.cb_print_destroyed)
return (0);

Expand All @@ -8761,7 +8761,7 @@ zpool_do_status(int argc, char **argv)
status_callback, &cb);

if (cb.cb_allpools)
zoa_list_destroying_pools();
zoa_list_destroying_pools(g_zfs);

if (cb.vcdl != NULL)
free_vdev_cmd_data_list(cb.vcdl);
Expand Down
8 changes: 4 additions & 4 deletions include/libzutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ typedef struct importargs {

_LIBZUTIL_H nvlist_t *zpool_search_import(void *, importargs_t *,
const pool_config_ops_t *);
_LIBZUTIL_H void zoa_list_destroying_pools(void);
_LIBZUTIL_H void zoa_list_destroyed_pools(void);
_LIBZUTIL_H void zoa_clear_destroyed_pools(void);
_LIBZUTIL_H int zoa_resume_destroy(importargs_t *import);
_LIBZUTIL_H void zoa_list_destroying_pools(void *);
_LIBZUTIL_H void zoa_list_destroyed_pools(void *);
_LIBZUTIL_H void zoa_clear_destroyed_pools(void *);
_LIBZUTIL_H int zoa_resume_destroy(void *, importargs_t *import);

_LIBZUTIL_H int zpool_find_config(void *, const char *, nvlist_t **,
importargs_t *, const pool_config_ops_t *);
Expand Down
9 changes: 4 additions & 5 deletions lib/libzutil/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ USER_C = \
zutil_import.c \
zutil_import.h \
zutil_nicenum.c \
zutil_pool.c
zutil_pool.c \
zutil_zoa.c \
zutil_zoa.h

if BUILD_LINUX
USER_C += \
os/linux/zutil_device_path_os.c \
os/linux/zutil_import_os.c \
os/linux/zutil_zoa_os.c \
os/linux/zutil_compat.c \
os/linux/zutil_zoa.h
os/linux/zutil_compat.c
endif

if BUILD_FREEBSD
Expand All @@ -31,7 +31,6 @@ DEFAULT_INCLUDES += -I$(top_srcdir)/include/os/freebsd/zfs
USER_C += \
os/freebsd/zutil_device_path_os.c \
os/freebsd/zutil_import_os.c \
os/freebsd/zutil_zoa_os.c \
os/freebsd/zutil_compat.c

VPATH += $(top_srcdir)/module/os/freebsd/zfs
Expand Down
8 changes: 0 additions & 8 deletions lib/libzutil/os/freebsd/zutil_import_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,3 @@ zfs_dev_flush(int fd __unused)
{
return (0);
}

void
zpool_find_import_agent(libpc_handle_t *hdl __unused,
importargs_t *iarg __unused, pthread_mutex_t *lock __unused,
avl_tree_t *cache __unused)
{

}
46 changes: 0 additions & 46 deletions lib/libzutil/os/freebsd/zutil_zoa_os.c

This file was deleted.

142 changes: 0 additions & 142 deletions lib/libzutil/os/linux/zutil_import_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,15 @@
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/dktp/fdisk.h>
#include <sys/vdev_impl.h>
#include <sys/fs/zfs.h>
#include <sys/vdev_object_store.h>

#include <thread_pool.h>
#include <libzutil.h>
#include <libnvpair.h>

#include "zutil_import.h"
#include "zutil_zoa.h"

#ifdef HAVE_LIBUDEV
#include <libudev.h>
Expand Down Expand Up @@ -382,143 +377,6 @@ zpool_find_import_blkid(libpc_handle_t *hdl, pthread_mutex_t *lock,
return (0);
}

int
zoa_resume_destroy(importargs_t *iarg)
{
char *endpoint = NULL;
char *region = NULL;
char *bucket = NULL;
char *profile = NULL;

nvlist_lookup_string(iarg->props, "path", &bucket);
if (bucket == NULL && iarg->path != NULL) {
bucket = iarg->path[0];
}
if (bucket == NULL) {
return (-1);
}
if (nvlist_lookup_string(iarg->props, "object-endpoint", &endpoint)
!= 0) {
return (-1);
}
if (nvlist_lookup_string(iarg->props, "object-region", &region) != 0) {
return (-1);
}
nvlist_lookup_string(iarg->props, "object-credentials-profile",
&profile);

// Resume destroy
nvlist_t *msg = fnvlist_alloc();
fnvlist_add_string(msg, AGENT_TYPE, AGENT_TYPE_RESUME_DESTROY_POOL);
fnvlist_add_string(msg, AGENT_BUCKET, bucket);
fnvlist_add_string(msg, AGENT_REGION, region);
fnvlist_add_string(msg, AGENT_ENDPOINT, endpoint);
if (profile != NULL) {
fnvlist_add_string(msg, AGENT_CRED_PROFILE, profile);
}
fnvlist_add_uint64(msg, AGENT_GUID, iarg->guid);
if (iarg->poolname != NULL) {
fnvlist_add_string(msg, AGENT_NAME, iarg->poolname);
}

nvlist_t *resp = zoa_send_recv_msg(msg, ZFS_ROOT_SOCKET);
if (resp == NULL)
return (-1);

const char *type = fnvlist_lookup_string(resp, AGENT_TYPE);
if (strcmp(type, AGENT_TYPE_RESUME_DESTROY_POOL_DONE) == 0) {
return (0);
}

return (-1);
}

void
zpool_find_import_agent(libpc_handle_t *hdl, importargs_t *iarg,
pthread_mutex_t *lock, avl_tree_t *cache)
{
char *profile = NULL, *bucket = NULL, *endpoint, *region;

// TODO: We don't handle multiple search paths yet
nvlist_lookup_string(iarg->props, "path", &bucket);
if (bucket == NULL && iarg->path != NULL) {
bucket = iarg->path[0];
}
if ((nvlist_lookup_string(iarg->props, "object-endpoint",
&endpoint)) != 0) {
return;
}
if ((nvlist_lookup_string(iarg->props, "object-region",
&region)) != 0) {
return;
}
nvlist_lookup_string(iarg->props, "object-credentials-profile",
&profile);

nvlist_t *msg = fnvlist_alloc();
fnvlist_add_string(msg, AGENT_TYPE, AGENT_TYPE_GET_POOLS);
if (bucket != NULL)
fnvlist_add_string(msg, AGENT_BUCKET, bucket);
fnvlist_add_string(msg, AGENT_REGION, region);
fnvlist_add_string(msg, AGENT_ENDPOINT, endpoint);
if (profile != NULL) {
fnvlist_add_string(msg, AGENT_CRED_PROFILE, profile);
}
if (iarg->guid != 0)
fnvlist_add_uint64(msg, AGENT_GUID, iarg->guid);

nvlist_t *resp = zoa_send_recv_msg(msg, ZFS_PUBLIC_SOCKET);

nvpair_t *elem = NULL;
while ((elem = nvlist_next_nvpair(resp, elem)) != NULL) {
avl_index_t where;
rdsk_node_t *slice;
nvlist_t *config;
VERIFY0(nvpair_value_nvlist(elem, &config));

nvlist_t *tree = fnvlist_lookup_nvlist(config,
ZPOOL_CONFIG_VDEV_TREE);

char *type;
if (profile != NULL &&
nvlist_lookup_string(tree, ZPOOL_CONFIG_TYPE, &type) == 0 &&
strcmp(type, VDEV_TYPE_OBJSTORE) == 0) {
fnvlist_add_string(tree,
ZPOOL_CONFIG_CRED_PROFILE, profile);
}
uint64_t guid;
if (nvlist_lookup_uint64(tree, ZPOOL_CONFIG_GUID, &guid) != 0) {
continue;
}

slice = zutil_alloc(hdl, sizeof (rdsk_node_t));
if (asprintf(&slice->rn_name, "%s", fnvlist_lookup_string(tree,
ZPOOL_CONFIG_PATH)) == -1) {
free(slice);
return;
}
slice->rn_vdev_guid = guid;
slice->rn_lock = lock;
slice->rn_avl = cache;
slice->rn_hdl = hdl;
slice->rn_order = IMPORT_ORDER_PREFERRED_1;
slice->rn_labelpaths = B_FALSE;
slice->rn_config = fnvlist_dup(config);
slice->rn_external = B_TRUE;

pthread_mutex_lock(lock);
if (avl_find(cache, slice, &where)) {
free(slice->rn_name);
free(slice);
} else {
avl_insert(cache, slice, where);
}
pthread_mutex_unlock(lock);
}
fnvlist_free(resp);
}


/*
* Linux persistent device strings for vdev labels
*
Expand Down
Loading

0 comments on commit 401276f

Please sign in to comment.