From 7145123b0ae4d625a419ee357a0df9467b1e8311 Mon Sep 17 00:00:00 2001 From: Paul Dagnelie Date: Tue, 17 Mar 2020 10:30:33 -0700 Subject: Separate warning for incomplete and corrupt streams This change adds a separate return code to zfs_ioc_recv that is used for incomplete streams, in addition to the existing return code for streams that contain corruption. Reviewed-by: Brian Behlendorf Reviewed-by: Matthew Ahrens Signed-off-by: Paul Dagnelie Closes #10122 --- contrib/pyzfs/libzfs_core/_constants.py | 1 + contrib/pyzfs/libzfs_core/_error_translation.py | 2 ++ contrib/pyzfs/libzfs_core/exceptions.py | 8 +++++++- contrib/pyzfs/libzfs_core/test/test_libzfs_core.py | 4 ++-- 4 files changed, 12 insertions(+), 3 deletions(-) (limited to 'contrib') diff --git a/contrib/pyzfs/libzfs_core/_constants.py b/contrib/pyzfs/libzfs_core/_constants.py index e1364aa33..5c285164b 100644 --- a/contrib/pyzfs/libzfs_core/_constants.py +++ b/contrib/pyzfs/libzfs_core/_constants.py @@ -94,6 +94,7 @@ zfs_errno = enum_with_offset(1024, [ 'ZFS_ERR_UNKNOWN_SEND_STREAM_FEATURE', 'ZFS_ERR_EXPORT_IN_PROGRESS', 'ZFS_ERR_BOOKMARK_SOURCE_NOT_ANCESTOR', + 'ZFS_ERR_STREAM_TRUNCATED', ], {} ) diff --git a/contrib/pyzfs/libzfs_core/_error_translation.py b/contrib/pyzfs/libzfs_core/_error_translation.py index 7881715c9..5a063c714 100644 --- a/contrib/pyzfs/libzfs_core/_error_translation.py +++ b/contrib/pyzfs/libzfs_core/_error_translation.py @@ -469,6 +469,8 @@ def lzc_receive_translate_errors( raise lzc_exc.BadStream() if ret == ZFS_ERR_WRONG_PARENT: raise lzc_exc.WrongParent(_fs_name(snapname)) + if ret == zfs_errno.ZFS_ERR_STREAM_TRUNCATED: + raise lzc_exc.StreamTruncated() raise lzc_exc.StreamIOError(ret) diff --git a/contrib/pyzfs/libzfs_core/exceptions.py b/contrib/pyzfs/libzfs_core/exceptions.py index 9eeab1d7c..6c571b7e2 100644 --- a/contrib/pyzfs/libzfs_core/exceptions.py +++ b/contrib/pyzfs/libzfs_core/exceptions.py @@ -29,7 +29,8 @@ from ._constants import ( ZFS_ERR_NO_CHECKPOINT, ZFS_ERR_DEVRM_IN_PROGRESS, ZFS_ERR_VDEV_TOO_BIG, - ZFS_ERR_WRONG_PARENT + ZFS_ERR_WRONG_PARENT, + zfs_errno ) @@ -351,6 +352,11 @@ class StreamFeatureIncompatible(ZFSError): message = "Incompatible embedded feature with encrypted receive" +class StreamTruncated(ZFSError): + errno = zfs_errno.ZFS_ERR_STREAM_TRUNCATED + message = "incomplete stream" + + class ReceivePropertyFailure(MultipleOperationsFailure): message = "Receiving of properties failed for one or more reasons" diff --git a/contrib/pyzfs/libzfs_core/test/test_libzfs_core.py b/contrib/pyzfs/libzfs_core/test/test_libzfs_core.py index f47583b83..a841f96af 100644 --- a/contrib/pyzfs/libzfs_core/test/test_libzfs_core.py +++ b/contrib/pyzfs/libzfs_core/test/test_libzfs_core.py @@ -2714,7 +2714,7 @@ class ZFSTest(unittest.TestCase): lzc.lzc_send(src, None, stream.fileno()) stream.seek(0) stream.truncate(1024 * 3) - with self.assertRaises(lzc_exc.BadStream): + with self.assertRaises(lzc_exc.StreamTruncated): lzc.lzc_receive_resumable(dst, stream.fileno()) # Resume token code from zfs_send_resume_token_to_nvlist() # XXX: if used more than twice move this code into an external func @@ -2771,7 +2771,7 @@ class ZFSTest(unittest.TestCase): lzc.lzc_send(snap2, snap1, stream.fileno()) stream.seek(0) stream.truncate(1024 * 3) - with self.assertRaises(lzc_exc.BadStream): + with self.assertRaises(lzc_exc.StreamTruncated): lzc.lzc_receive_resumable(dst2, stream.fileno()) # Resume token code from zfs_send_resume_token_to_nvlist() # format: --- -- cgit v1.2.3