pyzfs: Add constants for platform-specific errnos
FreeBSD doesn't have EBADE, ECHRNG, or ETIME. Add constants for these and set them appropriately for the platform. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ryan Moeller <ryan@iXsystems.com> Closes #10061
This commit is contained in:
parent
13fac09868
commit
276410387e
|
@ -19,6 +19,19 @@ Important `libzfs_core` constants.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
import errno
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
# Compat for platform-specific errnos
|
||||||
|
if sys.platform.startswith('freebsd'):
|
||||||
|
ECHRNG = errno.ENXIO
|
||||||
|
ECKSUM = 97 # EINTEGRITY
|
||||||
|
ETIME = errno.ETIMEDOUT
|
||||||
|
else:
|
||||||
|
ECHRNG = errno.ECHRNG
|
||||||
|
ECKSUM = errno.EBADE
|
||||||
|
ETIME = errno.ETIME
|
||||||
|
|
||||||
|
|
||||||
# https://stackoverflow.com/a/1695250
|
# https://stackoverflow.com/a/1695250
|
||||||
|
|
|
@ -33,6 +33,9 @@ import re
|
||||||
import string
|
import string
|
||||||
from . import exceptions as lzc_exc
|
from . import exceptions as lzc_exc
|
||||||
from ._constants import (
|
from ._constants import (
|
||||||
|
ECHRNG,
|
||||||
|
ECKSUM,
|
||||||
|
ETIME,
|
||||||
MAXNAMELEN,
|
MAXNAMELEN,
|
||||||
ZFS_ERR_CHECKPOINT_EXISTS,
|
ZFS_ERR_CHECKPOINT_EXISTS,
|
||||||
ZFS_ERR_DISCARDING_CHECKPOINT,
|
ZFS_ERR_DISCARDING_CHECKPOINT,
|
||||||
|
@ -462,7 +465,7 @@ def lzc_receive_translate_errors(
|
||||||
raise lzc_exc.ReadOnlyPool(_pool_name(snapname))
|
raise lzc_exc.ReadOnlyPool(_pool_name(snapname))
|
||||||
if ret == errno.EAGAIN:
|
if ret == errno.EAGAIN:
|
||||||
raise lzc_exc.SuspendedPool(_pool_name(snapname))
|
raise lzc_exc.SuspendedPool(_pool_name(snapname))
|
||||||
if ret == errno.EBADE: # ECKSUM
|
if ret == ECKSUM:
|
||||||
raise lzc_exc.BadStream()
|
raise lzc_exc.BadStream()
|
||||||
if ret == ZFS_ERR_WRONG_PARENT:
|
if ret == ZFS_ERR_WRONG_PARENT:
|
||||||
raise lzc_exc.WrongParent(_fs_name(snapname))
|
raise lzc_exc.WrongParent(_fs_name(snapname))
|
||||||
|
@ -550,7 +553,7 @@ def lzc_channel_program_translate_error(ret, name, error):
|
||||||
return
|
return
|
||||||
if ret == errno.ENOENT:
|
if ret == errno.ENOENT:
|
||||||
raise lzc_exc.PoolNotFound(name)
|
raise lzc_exc.PoolNotFound(name)
|
||||||
if ret == errno.ETIME:
|
if ret == ETIME:
|
||||||
raise lzc_exc.ZCPTimeout()
|
raise lzc_exc.ZCPTimeout()
|
||||||
if ret == errno.ENOMEM:
|
if ret == errno.ENOMEM:
|
||||||
raise lzc_exc.ZCPMemoryError()
|
raise lzc_exc.ZCPMemoryError()
|
||||||
|
@ -558,7 +561,7 @@ def lzc_channel_program_translate_error(ret, name, error):
|
||||||
raise lzc_exc.ZCPSpaceError()
|
raise lzc_exc.ZCPSpaceError()
|
||||||
if ret == errno.EPERM:
|
if ret == errno.EPERM:
|
||||||
raise lzc_exc.ZCPPermissionError()
|
raise lzc_exc.ZCPPermissionError()
|
||||||
if ret == errno.ECHRNG:
|
if ret == ECHRNG:
|
||||||
raise lzc_exc.ZCPRuntimeError(error)
|
raise lzc_exc.ZCPRuntimeError(error)
|
||||||
if ret == errno.EINVAL:
|
if ret == errno.EINVAL:
|
||||||
if error is None:
|
if error is None:
|
||||||
|
|
|
@ -21,6 +21,9 @@ from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
from ._constants import (
|
from ._constants import (
|
||||||
|
ECHRNG,
|
||||||
|
ECKSUM,
|
||||||
|
ETIME,
|
||||||
ZFS_ERR_CHECKPOINT_EXISTS,
|
ZFS_ERR_CHECKPOINT_EXISTS,
|
||||||
ZFS_ERR_DISCARDING_CHECKPOINT,
|
ZFS_ERR_DISCARDING_CHECKPOINT,
|
||||||
ZFS_ERR_NO_CHECKPOINT,
|
ZFS_ERR_NO_CHECKPOINT,
|
||||||
|
@ -324,7 +327,7 @@ class DestinationModified(ZFSError):
|
||||||
|
|
||||||
|
|
||||||
class BadStream(ZFSError):
|
class BadStream(ZFSError):
|
||||||
errno = errno.EBADE
|
errno = ECKSUM
|
||||||
message = "Bad backup stream"
|
message = "Bad backup stream"
|
||||||
|
|
||||||
|
|
||||||
|
@ -532,7 +535,7 @@ class ZCPSyntaxError(ZCPError):
|
||||||
|
|
||||||
|
|
||||||
class ZCPRuntimeError(ZCPError):
|
class ZCPRuntimeError(ZCPError):
|
||||||
errno = errno.ECHRNG
|
errno = ECHRNG
|
||||||
message = "Channel programs encountered a runtime error"
|
message = "Channel programs encountered a runtime error"
|
||||||
|
|
||||||
def __init__(self, details):
|
def __init__(self, details):
|
||||||
|
@ -545,7 +548,7 @@ class ZCPLimitInvalid(ZCPError):
|
||||||
|
|
||||||
|
|
||||||
class ZCPTimeout(ZCPError):
|
class ZCPTimeout(ZCPError):
|
||||||
errno = errno.ETIME
|
errno = ETIME
|
||||||
message = "Channel program timed out"
|
message = "Channel program timed out"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue