pyzfs: add missing libzfs_core functions

This change adds the following libzfs_core functions to pyzfs:
lzc_remap, lzc_pool_checkpoint, lzc_pool_checkpoint_discard

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
Closes #7793 
Closes #7800
This commit is contained in:
LOLi 2018-08-20 19:11:52 +02:00 committed by Brian Behlendorf
parent 34fe773e30
commit c962fd6c4e
7 changed files with 148 additions and 1 deletions

View File

@ -63,6 +63,8 @@ from ._libzfs_core import (
lzc_get_holds,
lzc_hold,
lzc_load_key,
lzc_pool_checkpoint,
lzc_pool_checkpoint_discard,
lzc_promote,
lzc_receive,
lzc_receive_one,
@ -70,6 +72,7 @@ from ._libzfs_core import (
lzc_receive_with_cmdprops,
lzc_receive_with_header,
lzc_release,
lzc_remap,
lzc_reopen,
lzc_rollback,
lzc_rollback_to,
@ -116,6 +119,8 @@ __all__ = [
'lzc_get_holds',
'lzc_hold',
'lzc_load_key',
'lzc_pool_checkpoint',
'lzc_pool_checkpoint_discard',
'lzc_promote',
'lzc_receive',
'lzc_receive_one',
@ -123,6 +128,7 @@ __all__ = [
'lzc_receive_with_cmdprops',
'lzc_receive_with_header',
'lzc_release',
'lzc_remap',
'lzc_reopen',
'lzc_rollback',
'lzc_rollback_to',

View File

@ -57,5 +57,12 @@ zio_encrypt = enum(
'ZIO_CRYPT_AES_192_GCM',
'ZIO_CRYPT_AES_256_GCM'
)
# ZFS-specific error codes
ZFS_ERR_CHECKPOINT_EXISTS = 1024
ZFS_ERR_DISCARDING_CHECKPOINT = 1025
ZFS_ERR_NO_CHECKPOINT = 1026
ZFS_ERR_DEVRM_IN_PROGRESS = 1027
ZFS_ERR_VDEV_TOO_BIG = 1028
# vim: softtabstop=4 tabstop=4 expandtab shiftwidth=4

View File

@ -31,7 +31,14 @@ import errno
import re
import string
from . import exceptions as lzc_exc
from ._constants import MAXNAMELEN
from ._constants import (
MAXNAMELEN,
ZFS_ERR_CHECKPOINT_EXISTS,
ZFS_ERR_DISCARDING_CHECKPOINT,
ZFS_ERR_NO_CHECKPOINT,
ZFS_ERR_DEVRM_IN_PROGRESS,
ZFS_ERR_VDEV_TOO_BIG
)
def lzc_create_translate_error(ret, name, ds_type, props):
@ -548,6 +555,32 @@ def lzc_remap_translate_error(ret, name):
raise _generic_exception(ret, name, "Failed to remap dataset")
def lzc_pool_checkpoint_translate_error(ret, name, discard=False):
if ret == 0:
return
if ret == errno.ENOENT:
raise lzc_exc.PoolNotFound(name)
if ret == ZFS_ERR_CHECKPOINT_EXISTS:
raise lzc_exc.CheckpointExists()
if ret == ZFS_ERR_NO_CHECKPOINT:
raise lzc_exc.CheckpointNotFound()
if ret == ZFS_ERR_DISCARDING_CHECKPOINT:
raise lzc_exc.CheckpointDiscarding()
if ret == ZFS_ERR_DEVRM_IN_PROGRESS:
raise lzc_exc.DeviceRemovalRunning()
if ret == ZFS_ERR_VDEV_TOO_BIG:
raise lzc_exc.DeviceTooBig()
if discard:
raise _generic_exception(
ret, name, "Failed to discard pool checkpoint")
else:
raise _generic_exception(ret, name, "Failed to create pool checkpoint")
def lzc_pool_checkpoint_discard_translate_error(ret, name):
lzc_pool_checkpoint_translate_error(ret, name, discard=True)
def lzc_rename_translate_error(ret, source, target):
if ret == 0:
return

View File

@ -1574,6 +1574,37 @@ def lzc_remap(name):
errors.lzc_remap_translate_error(ret, name)
@_uncommitted()
def lzc_pool_checkpoint(name):
'''
Creates a checkpoint for the specified pool.
:param bytes name: the name of the pool to create a checkpoint for.
:raises CheckpointExists: if the pool already has a checkpoint.
:raises CheckpointDiscarding: if ZFS is in the middle of discarding a
checkpoint for this pool.
:raises DeviceRemovalRunning: if a vdev is currently being removed.
:raises DeviceTooBig: if one or more top-level vdevs exceed the maximum
vdev size.
'''
ret = _lib.lzc_pool_checkpoint(name)
errors.lzc_pool_checkpoint_translate_error(ret, name)
@_uncommitted()
def lzc_pool_checkpoint_discard(name):
'''
Discard the checkpoint from the specified pool.
:param bytes name: the name of the pool to discard the checkpoint from.
:raises CheckpointNotFound: if pool does not have a checkpoint.
:raises CheckpointDiscarding: if ZFS is in the middle of discarding a
checkpoint for this pool.
'''
ret = _lib.lzc_pool_checkpoint_discard(name)
errors.lzc_pool_checkpoint_discard_translate_error(ret, name)
@_uncommitted()
def lzc_rename(source, target):
'''

View File

@ -127,6 +127,8 @@ CDEF = """
int lzc_sync(const char *, nvlist_t *, nvlist_t **);
int lzc_unload_key(const char *);
int lzc_remap(const char *);
int lzc_pool_checkpoint(const char *);
int lzc_pool_checkpoint_discard(const char *);
int lzc_rename(const char *, const char *, nvlist_t *, char **);
int lzc_destroy_one(const char *fsname, nvlist_t *);

View File

@ -19,6 +19,13 @@ Exceptions that can be raised by libzfs_core operations.
"""
import errno
from ._constants import (
ZFS_ERR_CHECKPOINT_EXISTS,
ZFS_ERR_DISCARDING_CHECKPOINT,
ZFS_ERR_NO_CHECKPOINT,
ZFS_ERR_DEVRM_IN_PROGRESS,
ZFS_ERR_VDEV_TOO_BIG
)
class ZFSError(Exception):
@ -547,4 +554,29 @@ class ZCPPermissionError(ZCPError):
message = "Channel programs must be run as root"
class CheckpointExists(ZFSError):
errno = ZFS_ERR_CHECKPOINT_EXISTS
message = "Pool already has a checkpoint"
class CheckpointNotFound(ZFSError):
errno = ZFS_ERR_NO_CHECKPOINT
message = "Pool does not have a checkpoint"
class CheckpointDiscarding(ZFSError):
errno = ZFS_ERR_DISCARDING_CHECKPOINT
message = "Pool checkpoint is being discarded"
class DeviceRemovalRunning(ZFSError):
errno = ZFS_ERR_DEVRM_IN_PROGRESS
message = "A vdev is currently being removed"
class DeviceTooBig(ZFSError):
errno = ZFS_ERR_VDEV_TOO_BIG
message = "One or more top-level vdevs exceed the maximum vdev size"
# vim: softtabstop=4 tabstop=4 expandtab shiftwidth=4

View File

@ -3576,6 +3576,42 @@ zfs.sync.snapshot('""" + pool + """@zcp')
lzc.lzc_remap(name)
def test_checkpoint(self):
pool = ZFSTest.pool.getRoot().getName()
lzc.lzc_pool_checkpoint(pool)
def test_checkpoint_missing_pool(self):
pool = "nonexistent"
with self.assertRaises(lzc_exc.PoolNotFound):
lzc.lzc_pool_checkpoint(pool)
def test_checkpoint_already_exists(self):
pool = ZFSTest.pool.getRoot().getName()
lzc.lzc_pool_checkpoint(pool)
with self.assertRaises(lzc_exc.CheckpointExists):
lzc.lzc_pool_checkpoint(pool)
def test_checkpoint_discard(self):
pool = ZFSTest.pool.getRoot().getName()
lzc.lzc_pool_checkpoint(pool)
lzc.lzc_pool_checkpoint_discard(pool)
def test_checkpoint_discard_missing_pool(self):
pool = "nonexistent"
with self.assertRaises(lzc_exc.PoolNotFound):
lzc.lzc_pool_checkpoint_discard(pool)
def test_checkpoint_discard_missing_checkpoint(self):
pool = ZFSTest.pool.getRoot().getName()
with self.assertRaises(lzc_exc.CheckpointNotFound):
lzc.lzc_pool_checkpoint_discard(pool)
@needs_support(lzc.lzc_list_children)
def test_list_children(self):
name = ZFSTest.pool.makeName("fs1/fs")