Tag zfs-2.2.2
[zfs.git] / contrib / pyzfs / libzfs_core / exceptions.py
blobe484b07b64504f3df7d1ff04805275c841aaa5b1
2 # Copyright 2015 ClusterHQ
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 """
18 Exceptions that can be raised by libzfs_core operations.
19 """
20 from __future__ import absolute_import, division, print_function
22 import errno
23 from ._constants import (
24 ECHRNG,
25 ECKSUM,
26 ETIME,
27 ZFS_ERR_CHECKPOINT_EXISTS,
28 ZFS_ERR_DISCARDING_CHECKPOINT,
29 ZFS_ERR_NO_CHECKPOINT,
30 ZFS_ERR_DEVRM_IN_PROGRESS,
31 ZFS_ERR_VDEV_TOO_BIG,
32 ZFS_ERR_WRONG_PARENT,
33 zfs_errno
37 class ZFSError(Exception):
38 errno = None
39 message = None
40 name = None
42 def __str__(self):
43 if self.name is not None:
44 return "[Errno %d] %s: '%s'" % (
45 self.errno, self.message, self.name)
46 else:
47 return "[Errno %d] %s" % (self.errno, self.message)
49 def __repr__(self):
50 return "%s(%r, %r)" % (
51 self.__class__.__name__, self.errno, self.message)
54 class ZFSGenericError(ZFSError):
56 def __init__(self, errno, name, message):
57 self.errno = errno
58 self.message = message
59 self.name = name
62 class ZFSInitializationFailed(ZFSError):
63 message = "Failed to initialize libzfs_core"
65 def __init__(self, errno):
66 self.errno = errno
69 class MultipleOperationsFailure(ZFSError):
71 def __init__(self, errors, suppressed_count):
72 # Use first of the individual error codes
73 # as an overall error code. This is more consistent.
74 self.errno = errors[0].errno
75 self.errors = errors
76 # this many errors were encountered but not placed on the `errors` list
77 self.suppressed_count = suppressed_count
79 def __str__(self):
80 return "%s, %d errors included, %d suppressed" % (
81 ZFSError.__str__(self), len(self.errors), self.suppressed_count)
83 def __repr__(self):
84 return "%s(%r, %r, errors=%r, suppressed=%r)" % (
85 self.__class__.__name__, self.errno, self.message, self.errors,
86 self.suppressed_count)
89 class DatasetNotFound(ZFSError):
91 """
92 This exception is raised when an operation failure can be caused by a
93 missing snapshot or a missing filesystem and it is impossible to
94 distinguish between the causes.
95 """
96 errno = errno.ENOENT
97 message = "Dataset not found"
99 def __init__(self, name):
100 self.name = name
103 class DatasetExists(ZFSError):
106 This exception is raised when an operation failure can be caused by an
107 existing snapshot or filesystem and it is impossible to distinguish between
108 the causes.
110 errno = errno.EEXIST
111 message = "Dataset already exists"
113 def __init__(self, name):
114 self.name = name
117 class NotClone(ZFSError):
118 errno = errno.EINVAL
119 message = "Filesystem is not a clone, can not promote"
121 def __init__(self, name):
122 self.name = name
125 class FilesystemExists(DatasetExists):
126 message = "Filesystem already exists"
128 def __init__(self, name):
129 self.name = name
132 class FilesystemNotFound(DatasetNotFound):
133 message = "Filesystem not found"
135 def __init__(self, name):
136 self.name = name
139 class ParentNotFound(ZFSError):
140 errno = errno.ENOENT
141 message = "Parent not found"
143 def __init__(self, name):
144 self.name = name
147 class WrongParent(ZFSError):
148 errno = ZFS_ERR_WRONG_PARENT
149 message = "Parent dataset is not a filesystem"
151 def __init__(self, name):
152 self.name = name
155 class SnapshotExists(DatasetExists):
156 message = "Snapshot already exists"
158 def __init__(self, name):
159 self.name = name
162 class SnapshotNotFound(DatasetNotFound):
163 message = "Snapshot not found"
165 def __init__(self, name):
166 self.name = name
169 class SnapshotNotLatest(ZFSError):
170 errno = errno.EEXIST
171 message = "Snapshot is not the latest"
173 def __init__(self, name):
174 self.name = name
177 class SnapshotIsCloned(ZFSError):
178 errno = errno.EEXIST
179 message = "Snapshot is cloned"
181 def __init__(self, name):
182 self.name = name
185 class SnapshotIsHeld(ZFSError):
186 errno = errno.EBUSY
187 message = "Snapshot is held"
189 def __init__(self, name):
190 self.name = name
193 class DuplicateSnapshots(ZFSError):
194 errno = errno.EXDEV
195 message = "Requested multiple snapshots of the same filesystem"
197 def __init__(self, name):
198 self.name = name
201 class SnapshotFailure(MultipleOperationsFailure):
202 message = "Creation of snapshot(s) failed for one or more reasons"
204 def __init__(self, errors, suppressed_count):
205 super(SnapshotFailure, self).__init__(errors, suppressed_count)
208 class SnapshotDestructionFailure(MultipleOperationsFailure):
209 message = "Destruction of snapshot(s) failed for one or more reasons"
211 def __init__(self, errors, suppressed_count):
212 super(SnapshotDestructionFailure, self).__init__(
213 errors, suppressed_count)
216 class BookmarkExists(ZFSError):
217 errno = errno.EEXIST
218 message = "Bookmark already exists"
220 def __init__(self, name):
221 self.name = name
224 class BookmarkNotFound(ZFSError):
225 errno = errno.ENOENT
226 message = "Bookmark not found"
228 def __init__(self, name):
229 self.name = name
232 class BookmarkMismatch(ZFSError):
233 errno = errno.EINVAL
234 message = "source is not an ancestor of the new bookmark's dataset"
236 def __init__(self, name):
237 self.name = name
240 class BookmarkSourceInvalid(ZFSError):
241 errno = errno.EINVAL
242 message = "Bookmark source is not a valid snapshot or existing bookmark"
244 def __init__(self, name):
245 self.name = name
248 class BookmarkNotSupported(ZFSError):
249 errno = errno.ENOTSUP
250 message = "Bookmark feature is not supported"
252 def __init__(self, name):
253 self.name = name
256 class BookmarkFailure(MultipleOperationsFailure):
257 message = "Creation of bookmark(s) failed for one or more reasons"
259 def __init__(self, errors, suppressed_count):
260 super(BookmarkFailure, self).__init__(errors, suppressed_count)
263 class BookmarkDestructionFailure(MultipleOperationsFailure):
264 message = "Destruction of bookmark(s) failed for one or more reasons"
266 def __init__(self, errors, suppressed_count):
267 super(BookmarkDestructionFailure, self).__init__(
268 errors, suppressed_count)
271 class BadHoldCleanupFD(ZFSError):
272 errno = errno.EBADF
273 message = "Bad file descriptor as cleanup file descriptor"
276 class HoldExists(ZFSError):
277 errno = errno.EEXIST
278 message = "Hold with a given tag already exists on snapshot"
280 def __init__(self, name):
281 self.name = name
284 class HoldNotFound(ZFSError):
285 errno = errno.ENOENT
286 message = "Hold with a given tag does not exist on snapshot"
288 def __init__(self, name):
289 self.name = name
292 class HoldFailure(MultipleOperationsFailure):
293 message = "Placement of hold(s) failed for one or more reasons"
295 def __init__(self, errors, suppressed_count):
296 super(HoldFailure, self).__init__(errors, suppressed_count)
299 class HoldReleaseFailure(MultipleOperationsFailure):
300 message = "Release of hold(s) failed for one or more reasons"
302 def __init__(self, errors, suppressed_count):
303 super(HoldReleaseFailure, self).__init__(errors, suppressed_count)
306 class SnapshotMismatch(ZFSError):
307 errno = errno.ENODEV
308 message = "Snapshot is not descendant of source snapshot"
310 def __init__(self, name):
311 self.name = name
314 class StreamMismatch(ZFSError):
315 errno = errno.ENODEV
316 message = "Stream is not applicable to destination dataset"
318 def __init__(self, name):
319 self.name = name
322 class DestinationModified(ZFSError):
323 errno = errno.ETXTBSY
324 message = "Destination dataset has modifications that can not be undone"
326 def __init__(self, name):
327 self.name = name
330 class BadStream(ZFSError):
331 errno = ECKSUM
332 message = "Bad backup stream"
335 class StreamFeatureNotSupported(ZFSError):
336 errno = errno.ENOTSUP
337 message = "Stream contains unsupported feature"
340 class UnknownStreamFeature(ZFSError):
341 errno = errno.ENOTSUP
342 message = "Unknown feature requested for stream"
345 class StreamFeatureInvalid(ZFSError):
346 errno = errno.EINVAL
347 message = "Kernel modules must be upgraded to receive this stream"
350 class StreamFeatureIncompatible(ZFSError):
351 errno = errno.EINVAL
352 message = "Incompatible embedded feature with encrypted receive"
355 class StreamTruncated(ZFSError):
356 errno = zfs_errno.ZFS_ERR_STREAM_TRUNCATED
357 message = "incomplete stream"
360 class ReceivePropertyFailure(MultipleOperationsFailure):
361 message = "Receiving of properties failed for one or more reasons"
363 def __init__(self, errors, suppressed_count):
364 super(ReceivePropertyFailure, self).__init__(errors, suppressed_count)
367 class StreamIOError(ZFSError):
368 message = "I/O error while writing or reading stream"
370 def __init__(self, errno):
371 self.errno = errno
374 class ZIOError(ZFSError):
375 errno = errno.EIO
376 message = "I/O error"
378 def __init__(self, name):
379 self.name = name
382 class NoSpace(ZFSError):
383 errno = errno.ENOSPC
384 message = "No space left"
386 def __init__(self, name):
387 self.name = name
390 class QuotaExceeded(ZFSError):
391 errno = errno.EDQUOT
392 message = "Quota exceeded"
394 def __init__(self, name):
395 self.name = name
398 class DatasetBusy(ZFSError):
399 errno = errno.EBUSY
400 message = "Dataset is busy"
402 def __init__(self, name):
403 self.name = name
406 class NameTooLong(ZFSError):
407 errno = errno.ENAMETOOLONG
408 message = "Dataset name is too long"
410 def __init__(self, name):
411 self.name = name
414 class NameInvalid(ZFSError):
415 errno = errno.EINVAL
416 message = "Invalid name"
418 def __init__(self, name):
419 self.name = name
422 class SnapshotNameInvalid(NameInvalid):
423 message = "Invalid name for snapshot"
425 def __init__(self, name):
426 self.name = name
429 class FilesystemNameInvalid(NameInvalid):
430 message = "Invalid name for filesystem or volume"
432 def __init__(self, name):
433 self.name = name
436 class BookmarkNameInvalid(NameInvalid):
437 message = "Invalid name for bookmark"
439 def __init__(self, name):
440 self.name = name
443 class ReadOnlyPool(ZFSError):
444 errno = errno.EROFS
445 message = "Pool is read-only"
447 def __init__(self, name):
448 self.name = name
451 class SuspendedPool(ZFSError):
452 errno = errno.EAGAIN
453 message = "Pool is suspended"
455 def __init__(self, name):
456 self.name = name
459 class PoolNotFound(ZFSError):
460 errno = errno.EXDEV
461 message = "No such pool"
463 def __init__(self, name):
464 self.name = name
467 class PoolsDiffer(ZFSError):
468 errno = errno.EXDEV
469 message = "Source and target belong to different pools"
471 def __init__(self, name):
472 self.name = name
475 class FeatureNotSupported(ZFSError):
476 errno = errno.ENOTSUP
477 message = "Feature is not supported in this version"
479 def __init__(self, name):
480 self.name = name
483 class PropertyNotSupported(ZFSError):
484 errno = errno.ENOTSUP
485 message = "Property is not supported in this version"
487 def __init__(self, name):
488 self.name = name
491 class PropertyInvalid(ZFSError):
492 errno = errno.EINVAL
493 message = "Invalid property or property value"
495 def __init__(self, name):
496 self.name = name
499 class DatasetTypeInvalid(ZFSError):
500 errno = errno.EINVAL
501 message = "Specified dataset type is unknown"
503 def __init__(self, name):
504 self.name = name
507 class UnknownCryptCommand(ZFSError):
508 errno = errno.EINVAL
509 message = "Specified crypt command is invalid"
511 def __init__(self, name):
512 self.name = name
515 class EncryptionKeyNotLoaded(ZFSError):
516 errno = errno.EACCES
517 message = "Encryption key is not currently loaded"
520 class EncryptionKeyAlreadyLoaded(ZFSError):
521 errno = errno.EEXIST
522 message = "Encryption key is already loaded"
525 class EncryptionKeyInvalid(ZFSError):
526 errno = errno.EACCES
527 message = "Incorrect encryption key provided"
530 class ZCPError(ZFSError):
531 errno = None
532 message = None
535 class ZCPSyntaxError(ZCPError):
536 errno = errno.EINVAL
537 message = "Channel program contains syntax errors"
539 def __init__(self, details):
540 self.details = details
543 class ZCPRuntimeError(ZCPError):
544 errno = ECHRNG
545 message = "Channel programs encountered a runtime error"
547 def __init__(self, details):
548 self.details = details
551 class ZCPLimitInvalid(ZCPError):
552 errno = errno.EINVAL
553 message = "Channel program called with invalid limits"
556 class ZCPTimeout(ZCPError):
557 errno = ETIME
558 message = "Channel program timed out"
561 class ZCPSpaceError(ZCPError):
562 errno = errno.ENOSPC
563 message = "Channel program exhausted the memory limit"
566 class ZCPMemoryError(ZCPError):
567 errno = errno.ENOMEM
568 message = "Channel program return value too large"
571 class ZCPPermissionError(ZCPError):
572 errno = errno.EPERM
573 message = "Channel programs must be run as root"
576 class CheckpointExists(ZFSError):
577 errno = ZFS_ERR_CHECKPOINT_EXISTS
578 message = "Pool already has a checkpoint"
581 class CheckpointNotFound(ZFSError):
582 errno = ZFS_ERR_NO_CHECKPOINT
583 message = "Pool does not have a checkpoint"
586 class CheckpointDiscarding(ZFSError):
587 errno = ZFS_ERR_DISCARDING_CHECKPOINT
588 message = "Pool checkpoint is being discarded"
591 class DeviceRemovalRunning(ZFSError):
592 errno = ZFS_ERR_DEVRM_IN_PROGRESS
593 message = "A vdev is currently being removed"
596 class DeviceTooBig(ZFSError):
597 errno = ZFS_ERR_VDEV_TOO_BIG
598 message = "One or more top-level vdevs exceed the maximum vdev size"
601 # vim: softtabstop=4 tabstop=4 expandtab shiftwidth=4