lzc_get_holds,
lzc_hold,
lzc_load_key,
+ lzc_pool_checkpoint,
+ lzc_pool_checkpoint_discard,
lzc_promote,
lzc_receive,
lzc_receive_one,
lzc_receive_with_cmdprops,
lzc_receive_with_header,
lzc_release,
+ lzc_remap,
lzc_reopen,
lzc_rollback,
lzc_rollback_to,
'lzc_get_holds',
'lzc_hold',
'lzc_load_key',
+ 'lzc_pool_checkpoint',
+ 'lzc_pool_checkpoint_discard',
'lzc_promote',
'lzc_receive',
'lzc_receive_one',
'lzc_receive_with_cmdprops',
'lzc_receive_with_header',
'lzc_release',
+ 'lzc_remap',
'lzc_reopen',
'lzc_rollback',
'lzc_rollback_to',
'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
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):
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
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):
'''
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 *);
"""
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):
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
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")