mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
Implemented zpool sync command
This addition will enable us to sync an open TXG to the main pool on demand. The functionality is similar to 'sync(2)' but 'zpool sync' will return when data has hit the main storage instead of potentially just the ZIL as is the case with the 'sync(2)' cmd. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed by: Matthew Ahrens <mahrens@delphix.com> Signed-off-by: Alek Pinchuk <apinchuk@datto.com> Closes #6122
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2014 by Delphix. All rights reserved.
|
||||
* Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
|
||||
* Copyright (c) 2017 Datto Inc.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
@@ -3288,6 +3289,27 @@ zpool_reopen(zpool_handle_t *zhp)
|
||||
return (zpool_standard_error(hdl, errno, msg));
|
||||
}
|
||||
|
||||
/* call into libzfs_core to execute the sync IOCTL per pool */
|
||||
int
|
||||
zpool_sync_one(zpool_handle_t *zhp, void *data)
|
||||
{
|
||||
int ret;
|
||||
libzfs_handle_t *hdl = zpool_get_handle(zhp);
|
||||
const char *pool_name = zpool_get_name(zhp);
|
||||
boolean_t *force = data;
|
||||
nvlist_t *innvl = fnvlist_alloc();
|
||||
|
||||
fnvlist_add_boolean_value(innvl, "force", *force);
|
||||
if ((ret = lzc_sync(pool_name, innvl, NULL)) != 0) {
|
||||
nvlist_free(innvl);
|
||||
return (zpool_standard_error_fmt(hdl, ret,
|
||||
dgettext(TEXT_DOMAIN, "sync '%s' failed"), pool_name));
|
||||
}
|
||||
nvlist_free(innvl);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if defined(__sun__) || defined(__sun)
|
||||
/*
|
||||
* Convert from a devid string to a path.
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
|
||||
* Copyright (c) 2013 Steven Hartland. All rights reserved.
|
||||
* Copyright (c) 2017 Datto Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -126,17 +127,20 @@ lzc_ioctl(zfs_ioc_t ioc, const char *name,
|
||||
{
|
||||
zfs_cmd_t zc = {"\0"};
|
||||
int error = 0;
|
||||
char *packed;
|
||||
size_t size;
|
||||
char *packed = NULL;
|
||||
size_t size = 0;
|
||||
|
||||
ASSERT3S(g_refcount, >, 0);
|
||||
VERIFY3S(g_fd, !=, -1);
|
||||
|
||||
(void) strlcpy(zc.zc_name, name, sizeof (zc.zc_name));
|
||||
if (name != NULL)
|
||||
(void) strlcpy(zc.zc_name, name, sizeof (zc.zc_name));
|
||||
|
||||
packed = fnvlist_pack(source, &size);
|
||||
zc.zc_nvlist_src = (uint64_t)(uintptr_t)packed;
|
||||
zc.zc_nvlist_src_size = size;
|
||||
if (source != NULL) {
|
||||
packed = fnvlist_pack(source, &size);
|
||||
zc.zc_nvlist_src = (uint64_t)(uintptr_t)packed;
|
||||
zc.zc_nvlist_src_size = size;
|
||||
}
|
||||
|
||||
if (resultp != NULL) {
|
||||
*resultp = NULL;
|
||||
@@ -340,6 +344,18 @@ lzc_exists(const char *dataset)
|
||||
return (ioctl(g_fd, ZFS_IOC_OBJSET_STATS, &zc) == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* outnvl is unused.
|
||||
* It was added to preserve the function signature in case it is
|
||||
* needed in the future.
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
lzc_sync(const char *pool_name, nvlist_t *innvl, nvlist_t **outnvl)
|
||||
{
|
||||
return (lzc_ioctl(ZFS_IOC_POOL_SYNC, pool_name, innvl, NULL));
|
||||
}
|
||||
|
||||
/*
|
||||
* Create "user holds" on snapshots. If there is a hold on a snapshot,
|
||||
* the snapshot can not be destroyed. (However, it can be marked for deletion
|
||||
@@ -440,11 +456,7 @@ lzc_release(nvlist_t *holds, nvlist_t **errlist)
|
||||
int
|
||||
lzc_get_holds(const char *snapname, nvlist_t **holdsp)
|
||||
{
|
||||
int error;
|
||||
nvlist_t *innvl = fnvlist_alloc();
|
||||
error = lzc_ioctl(ZFS_IOC_GET_HOLDS, snapname, innvl, holdsp);
|
||||
fnvlist_free(innvl);
|
||||
return (error);
|
||||
return (lzc_ioctl(ZFS_IOC_GET_HOLDS, snapname, NULL, holdsp));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user