zfs 0.8 support (#15)

* Rename Rewind-Policy to Load-Policy

See 8a393be353 (diff-f29552ad5ed97006cc80fc2b453cbe39R726) for details.

Signed-off-by: steigr <me@stei.gr>

* Use threadpool for zpool_search_import.

See e89f1295d4 (diff-24bf46767aadc66215cb194bdba266e7) for details.

Signed-off-by: steigr <me@stei.gr>

* Use sendflags struct.

See 835db58592 for details.

Signed-off-by: steigr <me@stei.gr>

* Added new pool properties `Checkpoint` and `LoadGuid`

OpenZFS 9166 - zfs storage pool checkpoint: d2734cce68
read/write kstats per dataset: a448a2557e

Signed-off-by: steigr <me@stei.gr>
This commit is contained in:
steigr 2019-06-20 21:17:31 +02:00 committed by Faruk Kasumovic
parent 99406fb402
commit b16d96b1a8
4 changed files with 42 additions and 34 deletions

View File

@ -178,6 +178,8 @@ const (
PoolPropTName PoolPropTName
PoolPropMaxNodeSize PoolPropMaxNodeSize
PoolPropMultiHost PoolPropMultiHost
PoolPropCheckpoint
PoolPropLoadGuid
PoolNumProps PoolNumProps
) )

View File

@ -131,7 +131,7 @@ func (d *Dataset) send(FromName string, outf *os.File, flags *SendFlags) (err er
func (d *Dataset) SendOne(FromName string, outf *os.File, flags *SendFlags) (err error) { func (d *Dataset) SendOne(FromName string, outf *os.File, flags *SendFlags) (err error) {
var cfromname, ctoname *C.char var cfromname, ctoname *C.char
var dpath string var dpath string
var lzc_send_flags uint32 var lzc_send_flags C.struct_sendflags
if d.Type == DatasetTypeSnapshot || (len(FromName) > 0 && !strings.Contains(FromName, "#")) { if d.Type == DatasetTypeSnapshot || (len(FromName) > 0 && !strings.Contains(FromName, "#")) {
err = fmt.Errorf( err = fmt.Errorf(
@ -144,10 +144,10 @@ func (d *Dataset) SendOne(FromName string, outf *os.File, flags *SendFlags) (err
} }
if flags.LargeBlock { if flags.LargeBlock {
lzc_send_flags |= C.LZC_SEND_FLAG_LARGE_BLOCK lzc_send_flags.largeblock = booleanT(true)
} }
if flags.EmbedData { if flags.EmbedData {
lzc_send_flags |= C.LZC_SEND_FLAG_EMBED_DATA lzc_send_flags.embed_data = booleanT(true)
} }
// if (flags.Compress) // if (flags.Compress)
// lzc_send_flags |= LZC_SEND_FLAG_COMPRESS; // lzc_send_flags |= LZC_SEND_FLAG_COMPRESS;

58
zpool.c
View File

@ -6,6 +6,8 @@ typedef unsigned long int rlim64_t;
#include <libzfs.h> #include <libzfs.h>
#include <libzfs/sys/zfs_context.h> #include <libzfs/sys/zfs_context.h>
#include <libzutil.h>
#include <thread_pool.h>
#include <memory.h> #include <memory.h>
#include <string.h> #include <string.h>
@ -79,11 +81,11 @@ char *sZPOOL_CONFIG_DEGRADED = ZPOOL_CONFIG_DEGRADED;
char *sZPOOL_CONFIG_REMOVED = ZPOOL_CONFIG_REMOVED; char *sZPOOL_CONFIG_REMOVED = ZPOOL_CONFIG_REMOVED;
char *sZPOOL_CONFIG_FRU = ZPOOL_CONFIG_FRU; char *sZPOOL_CONFIG_FRU = ZPOOL_CONFIG_FRU;
char *sZPOOL_CONFIG_AUX_STATE = ZPOOL_CONFIG_AUX_STATE; char *sZPOOL_CONFIG_AUX_STATE = ZPOOL_CONFIG_AUX_STATE;
char *sZPOOL_REWIND_POLICY = ZPOOL_REWIND_POLICY; char *sZPOOL_LOAD_POLICY = ZPOOL_LOAD_POLICY;
char *sZPOOL_REWIND_REQUEST = ZPOOL_REWIND_REQUEST; char *sZPOOL_LOAD_REWIND_POLICY = ZPOOL_LOAD_REWIND_POLICY;
char *sZPOOL_REWIND_REQUEST_TXG = ZPOOL_REWIND_REQUEST_TXG; char *sZPOOL_LOAD_REQUEST_TXG = ZPOOL_LOAD_REQUEST_TXG;
char *sZPOOL_REWIND_META_THRESH = ZPOOL_REWIND_META_THRESH; char *sZPOOL_LOAD_META_THRESH = ZPOOL_LOAD_META_THRESH;
char *sZPOOL_REWIND_DATA_THRESH = ZPOOL_REWIND_DATA_THRESH; char *sZPOOL_LOAD_DATA_THRESH = ZPOOL_LOAD_DATA_THRESH;
char *sZPOOL_CONFIG_LOAD_TIME = ZPOOL_CONFIG_LOAD_TIME; char *sZPOOL_CONFIG_LOAD_TIME = ZPOOL_CONFIG_LOAD_TIME;
char *sZPOOL_CONFIG_LOAD_DATA_ERRORS = ZPOOL_CONFIG_LOAD_DATA_ERRORS; char *sZPOOL_CONFIG_LOAD_DATA_ERRORS = ZPOOL_CONFIG_LOAD_DATA_ERRORS;
char *sZPOOL_CONFIG_REWIND_TIME = ZPOOL_CONFIG_REWIND_TIME; char *sZPOOL_CONFIG_REWIND_TIME = ZPOOL_CONFIG_REWIND_TIME;
@ -216,7 +218,7 @@ property_list_ptr read_append_zpool_property(zpool_list_ptr pool, property_list_
// printf("p: %s %s %s\n", newitem->name, newitem->value, newitem->source); // printf("p: %s %s %s\n", newitem->name, newitem->value, newitem->source);
newitem->pnext = proot; newitem->pnext = proot;
proot = newitem; proot = newitem;
return proot; return proot;
} }
@ -231,24 +233,22 @@ property_list_t *read_zpool_properties(zpool_list_ptr pool) {
root = read_append_zpool_property(pool, root, ZPOOL_PROP_HEALTH); root = read_append_zpool_property(pool, root, ZPOOL_PROP_HEALTH);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_GUID); root = read_append_zpool_property(pool, root, ZPOOL_PROP_GUID);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_VERSION); root = read_append_zpool_property(pool, root, ZPOOL_PROP_VERSION);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_BOOTFS); root = read_append_zpool_property(pool, root, ZPOOL_PROP_BOOTFS);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_DELEGATION); root = read_append_zpool_property(pool, root, ZPOOL_PROP_DELEGATION);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_AUTOREPLACE); root = read_append_zpool_property(pool, root, ZPOOL_PROP_AUTOREPLACE);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_CACHEFILE); root = read_append_zpool_property(pool, root, ZPOOL_PROP_CACHEFILE);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_FAILUREMODE); root = read_append_zpool_property(pool, root, ZPOOL_PROP_FAILUREMODE);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_LISTSNAPS); root = read_append_zpool_property(pool, root, ZPOOL_PROP_LISTSNAPS);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_AUTOEXPAND); root = read_append_zpool_property(pool, root, ZPOOL_PROP_AUTOEXPAND);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_DEDUPDITTO); root = read_append_zpool_property(pool, root, ZPOOL_PROP_DEDUPDITTO);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_DEDUPRATIO); root = read_append_zpool_property(pool, root, ZPOOL_PROP_DEDUPRATIO);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_FREE); root = read_append_zpool_property(pool, root, ZPOOL_PROP_FREE);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_ALLOCATED); root = read_append_zpool_property(pool, root, ZPOOL_PROP_ALLOCATED);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_READONLY); root = read_append_zpool_property(pool, root, ZPOOL_PROP_READONLY);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_ASHIFT); root = read_append_zpool_property(pool, root, ZPOOL_PROP_ASHIFT);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_COMMENT); root = read_append_zpool_property(pool, root, ZPOOL_PROP_COMMENT);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_EXPANDSZ); root = read_append_zpool_property(pool, root, ZPOOL_PROP_EXPANDSZ);
root = read_append_zpool_property(pool, root, ZPOOL_PROP_FREEING); root = read_append_zpool_property(pool, root, ZPOOL_PROP_FREEING);
list = new_property_list(); list = new_property_list();
list->property = ZPOOL_NUM_PROPS; list->property = ZPOOL_NUM_PROPS;
@ -455,7 +455,7 @@ uint64_t get_vdev_is_log(nvlist_ptr nv) {
} }
// return // return
uint64_t get_zpool_state(nvlist_ptr nv) { uint64_t get_zpool_state(nvlist_ptr nv) {
uint64_t state = 0; uint64_t state = 0;
nvlist_lookup_uint64(nv, ZPOOL_CONFIG_POOL_STATE, &state); nvlist_lookup_uint64(nv, ZPOOL_CONFIG_POOL_STATE, &state);
@ -501,18 +501,24 @@ nvlist_ptr go_zpool_search_import(libzfs_handle_ptr zfsh, int paths, char **path
idata.paths = paths; idata.paths = paths;
// idata.scan = 0; // idata.scan = 0;
thread_init(); tpool_t *t;
pools = zpool_search_import(zfsh, &idata); t = tpool_create(1, 5 * sysconf(_SC_NPROCESSORS_ONLN), 0, NULL);
thread_fini(); if (t == NULL)
return NULL;
pools = zpool_search_import(zfsh, &idata, &libzfs_config_ops);
tpool_wait(t);
tpool_destroy(t);
return pools; return pools;
} }
int do_zpool_clear(zpool_list_t *pool, const char *device, u_int32_t rewind_policy) { int do_zpool_clear(zpool_list_t *pool, const char *device, u_int32_t load_policy) {
nvlist_t *policy = NULL; nvlist_t *policy = NULL;
int ret = 0; int ret = 0;
if (nvlist_alloc(&policy, NV_UNIQUE_NAME, 0) != 0 || if (nvlist_alloc(&policy, NV_UNIQUE_NAME, 0) != 0 ||
nvlist_add_uint32(policy, ZPOOL_REWIND_REQUEST, rewind_policy) != 0) nvlist_add_uint32(policy, ZPOOL_LOAD_POLICY, load_policy) != 0)
return (1); return (1);
if (zpool_clear(pool->zph, device, policy) != 0) if (zpool_clear(pool->zph, device, policy) != 0)
@ -521,4 +527,4 @@ int do_zpool_clear(zpool_list_t *pool, const char *device, u_int32_t rewind_poli
nvlist_free(policy); nvlist_free(policy);
return (ret); return (ret);
} }

10
zpool.h
View File

@ -149,11 +149,11 @@ extern char *sZPOOL_CONFIG_DEGRADED;
extern char *sZPOOL_CONFIG_REMOVED; extern char *sZPOOL_CONFIG_REMOVED;
extern char *sZPOOL_CONFIG_FRU; extern char *sZPOOL_CONFIG_FRU;
extern char *sZPOOL_CONFIG_AUX_STATE; extern char *sZPOOL_CONFIG_AUX_STATE;
extern char *sZPOOL_REWIND_POLICY; extern char *sZPOOL_LOAD_POLICY;
extern char *sZPOOL_REWIND_REQUEST; extern char *sZPOOL_LOAD_REWIND_POLICY;
extern char *sZPOOL_REWIND_REQUEST_TXG; extern char *sZPOOL_LOAD_REQUEST_TXG;
extern char *sZPOOL_REWIND_META_THRESH; extern char *sZPOOL_LOAD_META_THRESH;
extern char *sZPOOL_REWIND_DATA_THRESH; extern char *sZPOOL_LOAD_DATA_THRESH;
extern char *sZPOOL_CONFIG_LOAD_TIME; extern char *sZPOOL_CONFIG_LOAD_TIME;
extern char *sZPOOL_CONFIG_LOAD_DATA_ERRORS; extern char *sZPOOL_CONFIG_LOAD_DATA_ERRORS;
extern char *sZPOOL_CONFIG_REWIND_TIME; extern char *sZPOOL_CONFIG_REWIND_TIME;