1# SPDX-License-Identifier: Apache-2.0 2# 3# Copyright 2015 ClusterHQ 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18""" 19Important `libzfs_core` constants. 20""" 21 22from __future__ import absolute_import, division, print_function 23import errno 24import sys 25 26 27# Compat for platform-specific errnos 28if sys.platform.startswith('freebsd'): 29 ECHRNG = errno.ENXIO 30 ECKSUM = 97 # EINTEGRITY 31 ETIME = errno.ETIMEDOUT 32else: 33 ECHRNG = errno.ECHRNG 34 ECKSUM = errno.EBADE 35 ETIME = errno.ETIME 36 37 38# https://stackoverflow.com/a/1695250 39def enum_with_offset(offset, sequential, named): 40 enums = dict(((b, a + offset) for a, b in enumerate(sequential)), **named) 41 return type('Enum', (), enums) 42 43 44def enum(*sequential, **named): 45 return enum_with_offset(0, sequential, named) 46 47 48#: Maximum length of any ZFS name. 49MAXNAMELEN = 255 50#: Default channel program limits 51ZCP_DEFAULT_INSTRLIMIT = 10 * 1000 * 1000 52ZCP_DEFAULT_MEMLIMIT = 10 * 1024 * 1024 53#: Encryption wrapping key length 54WRAPPING_KEY_LEN = 32 55#: Encryption key location enum 56zfs_key_location = enum( 57 'ZFS_KEYLOCATION_NONE', 58 'ZFS_KEYLOCATION_PROMPT', 59 'ZFS_KEYLOCATION_URI' 60) 61#: Encryption key format enum 62zfs_keyformat = enum( 63 'ZFS_KEYFORMAT_NONE', 64 'ZFS_KEYFORMAT_RAW', 65 'ZFS_KEYFORMAT_HEX', 66 'ZFS_KEYFORMAT_PASSPHRASE' 67) 68# Encryption algorithms enum 69zio_encrypt = enum( 70 'ZIO_CRYPT_INHERIT', 71 'ZIO_CRYPT_ON', 72 'ZIO_CRYPT_OFF', 73 'ZIO_CRYPT_AES_128_CCM', 74 'ZIO_CRYPT_AES_192_CCM', 75 'ZIO_CRYPT_AES_256_CCM', 76 'ZIO_CRYPT_AES_128_GCM', 77 'ZIO_CRYPT_AES_192_GCM', 78 'ZIO_CRYPT_AES_256_GCM' 79) 80# ZFS-specific error codes 81zfs_errno = enum_with_offset(1024, [ 82 'ZFS_ERR_CHECKPOINT_EXISTS', 83 'ZFS_ERR_DISCARDING_CHECKPOINT', 84 'ZFS_ERR_NO_CHECKPOINT', 85 'ZFS_ERR_DEVRM_IN_PROGRESS', 86 'ZFS_ERR_VDEV_TOO_BIG', 87 'ZFS_ERR_IOC_CMD_UNAVAIL', 88 'ZFS_ERR_IOC_ARG_UNAVAIL', 89 'ZFS_ERR_IOC_ARG_REQUIRED', 90 'ZFS_ERR_IOC_ARG_BADTYPE', 91 'ZFS_ERR_WRONG_PARENT', 92 'ZFS_ERR_FROM_IVSET_GUID_MISSING', 93 'ZFS_ERR_FROM_IVSET_GUID_MISMATCH', 94 'ZFS_ERR_SPILL_BLOCK_FLAG_MISSING', 95 'ZFS_ERR_UNKNOWN_SEND_STREAM_FEATURE', 96 'ZFS_ERR_EXPORT_IN_PROGRESS', 97 'ZFS_ERR_BOOKMARK_SOURCE_NOT_ANCESTOR', 98 'ZFS_ERR_STREAM_TRUNCATED', 99 'ZFS_ERR_STREAM_LARGE_BLOCK_MISMATCH', 100 'ZFS_ERR_RESILVER_IN_PROGRESS', 101 'ZFS_ERR_REBUILD_IN_PROGRESS', 102 'ZFS_ERR_BADPROP', 103 'ZFS_ERR_VDEV_NOTSUP', 104 'ZFS_ERR_NOT_USER_NAMESPACE', 105 'ZFS_ERR_RESUME_EXISTS', 106 'ZFS_ERR_CRYPTO_NOTSUP', 107 'ZFS_ERR_RAIDZ_EXPAND_IN_PROGRESS', 108 ], 109 {} 110) 111# compat before we used the enum helper for these values 112ZFS_ERR_CHECKPOINT_EXISTS = zfs_errno.ZFS_ERR_CHECKPOINT_EXISTS 113assert (ZFS_ERR_CHECKPOINT_EXISTS == 1024) 114ZFS_ERR_DISCARDING_CHECKPOINT = zfs_errno.ZFS_ERR_DISCARDING_CHECKPOINT 115ZFS_ERR_NO_CHECKPOINT = zfs_errno.ZFS_ERR_NO_CHECKPOINT 116ZFS_ERR_DEVRM_IN_PROGRESS = zfs_errno.ZFS_ERR_DEVRM_IN_PROGRESS 117ZFS_ERR_VDEV_TOO_BIG = zfs_errno.ZFS_ERR_VDEV_TOO_BIG 118ZFS_ERR_WRONG_PARENT = zfs_errno.ZFS_ERR_WRONG_PARENT 119ZFS_ERR_VDEV_NOTSUP = zfs_errno.ZFS_ERR_VDEV_NOTSUP 120ZFS_ERR_RAIDZ_EXPAND_IN_PROGRESS = zfs_errno.ZFS_ERR_RAIDZ_EXPAND_IN_PROGRESS 121 122# vim: softtabstop=4 tabstop=4 expandtab shiftwidth=4 123