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