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
|
||||
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
|
||||
|
|
|
@ -33,6 +33,9 @@ import re
|
|||
import string
|
||||
from . import exceptions as lzc_exc
|
||||
from ._constants import (
|
||||
ECHRNG,
|
||||
ECKSUM,
|
||||
ETIME,
|
||||
MAXNAMELEN,
|
||||
ZFS_ERR_CHECKPOINT_EXISTS,
|
||||
ZFS_ERR_DISCARDING_CHECKPOINT,
|
||||
|
@ -462,7 +465,7 @@ def lzc_receive_translate_errors(
|
|||
raise lzc_exc.ReadOnlyPool(_pool_name(snapname))
|
||||
if ret == errno.EAGAIN:
|
||||
raise lzc_exc.SuspendedPool(_pool_name(snapname))
|
||||
if ret == errno.EBADE: # ECKSUM
|
||||
if ret == ECKSUM:
|
||||
raise lzc_exc.BadStream()
|
||||
if ret == ZFS_ERR_WRONG_PARENT:
|
||||
raise lzc_exc.WrongParent(_fs_name(snapname))
|
||||
|
@ -550,7 +553,7 @@ def lzc_channel_program_translate_error(ret, name, error):
|
|||
return
|
||||
if ret == errno.ENOENT:
|
||||
raise lzc_exc.PoolNotFound(name)
|
||||
if ret == errno.ETIME:
|
||||
if ret == ETIME:
|
||||
raise lzc_exc.ZCPTimeout()
|
||||
if ret == errno.ENOMEM:
|
||||
raise lzc_exc.ZCPMemoryError()
|
||||
|
@ -558,7 +561,7 @@ def lzc_channel_program_translate_error(ret, name, error):
|
|||
raise lzc_exc.ZCPSpaceError()
|
||||
if ret == errno.EPERM:
|
||||
raise lzc_exc.ZCPPermissionError()
|
||||
if ret == errno.ECHRNG:
|
||||
if ret == ECHRNG:
|
||||
raise lzc_exc.ZCPRuntimeError(error)
|
||||
if ret == errno.EINVAL:
|
||||
if error is None:
|
||||
|
|
|
@ -21,6 +21,9 @@ from __future__ import absolute_import, division, print_function
|
|||
|
||||
import errno
|
||||
from ._constants import (
|
||||
ECHRNG,
|
||||
ECKSUM,
|
||||
ETIME,
|
||||
ZFS_ERR_CHECKPOINT_EXISTS,
|
||||
ZFS_ERR_DISCARDING_CHECKPOINT,
|
||||
ZFS_ERR_NO_CHECKPOINT,
|
||||
|
@ -324,7 +327,7 @@ class DestinationModified(ZFSError):
|
|||
|
||||
|
||||
class BadStream(ZFSError):
|
||||
errno = errno.EBADE
|
||||
errno = ECKSUM
|
||||
message = "Bad backup stream"
|
||||
|
||||
|
||||
|
@ -532,7 +535,7 @@ class ZCPSyntaxError(ZCPError):
|
|||
|
||||
|
||||
class ZCPRuntimeError(ZCPError):
|
||||
errno = errno.ECHRNG
|
||||
errno = ECHRNG
|
||||
message = "Channel programs encountered a runtime error"
|
||||
|
||||
def __init__(self, details):
|
||||
|
@ -545,7 +548,7 @@ class ZCPLimitInvalid(ZCPError):
|
|||
|
||||
|
||||
class ZCPTimeout(ZCPError):
|
||||
errno = errno.ETIME
|
||||
errno = ETIME
|
||||
message = "Channel program timed out"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue