Remove unnecessary CSTYLED escapes on top-level macro invocations
[zfs.git] / contrib / pyzfs / libzfs_core / exceptions.py
blobba8f7e49093c83939aa833151679432a9a3a2f00
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_ERR_RAIDZ_EXPAND_IN_PROGRESS,
34 zfs_errno
38 class ZFSError(Exception):
39 errno = None
40 message = None
41 name = None
43 def __str__(self):
44 if self.name is not None:
45 return "[Errno %d] %s: '%s'" % (
46 self.errno, self.message, self.name)
47 else:
48 return "[Errno %d] %s" % (self.errno, self.message)
50 def __repr__(self):
51 return "%s(%r, %r)" % (
52 self.__class__.__name__, self.errno, self.message)
55 class ZFSGenericError(ZFSError):
57 def __init__(self, errno, name, message):
58 self.errno = errno
59 self.message = message
60 self.name = name
63 class ZFSInitializationFailed(ZFSError):
64 message = "Failed to initialize libzfs_core"
66 def __init__(self, errno):
67 self.errno = errno
70 class MultipleOperationsFailure(ZFSError):
72 def __init__(self, errors, suppressed_count):
73 # Use first of the individual error codes
74 # as an overall error code. This is more consistent.
75 self.errno = errors[0].errno
76 self.errors = errors
77 # this many errors were encountered but not placed on the `errors` list
78 self.suppressed_count = suppressed_count
80 def __str__(self):
81 return "%s, %d errors included, %d suppressed" % (
82 ZFSError.__str__(self), len(self.errors), self.suppressed_count)
84 def __repr__(self):
85 return "%s(%r, %r, errors=%r, suppressed=%r)" % (
86 self.__class__.__name__, self.errno, self.message, self.errors,
87 self.suppressed_count)
90 class DatasetNotFound(ZFSError):
92 """
93 This exception is raised when an operation failure can be caused by a
94 missing snapshot or a missing filesystem and it is impossible to
95 distinguish between the causes.
96 """
97 errno = errno.ENOENT
98 message = "Dataset not found"
100 def __init__(self, name):
101 self.name = name
104 class DatasetExists(ZFSError):
107 This exception is raised when an operation failure can be caused by an
108 existing snapshot or filesystem and it is impossible to distinguish between
109 the causes.
111 errno = errno.EEXIST
112 message = "Dataset already exists"
114 def __init__(self, name):
115 self.name = name
118 class NotClone(ZFSError):
119 errno = errno.EINVAL
120 message = "Filesystem is not a clone, can not promote"
122 def __init__(self, name):
123 self.name = name
126 class FilesystemExists(DatasetExists):
127 message = "Filesystem already exists"
129 def __init__(self, name):
130 self.name = name
133 class FilesystemNotFound(DatasetNotFound):
134 message = "Filesystem not found"
136 def __init__(self, name):
137 self.name = name
140 class ParentNotFound(ZFSError):
141 errno = errno.ENOENT
142 message = "Parent not found"
144 def __init__(self, name):
145 self.name = name
148 class WrongParent(ZFSError):
149 errno = ZFS_ERR_WRONG_PARENT
150 message = "Parent dataset is not a filesystem"
152 def __init__(self, name):
153 self.name = name
156 class SnapshotExists(DatasetExists):
157 message = "Snapshot already exists"
159 def __init__(self, name):
160 self.name = name
163 class SnapshotNotFound(DatasetNotFound):
164 message = "Snapshot not found"
166 def __init__(self, name):
167 self.name = name
170 class SnapshotNotLatest(ZFSError):
171 errno = errno.EEXIST
172 message = "Snapshot is not the latest"
174 def __init__(self, name):
175 self.name = name
178 class SnapshotIsCloned(ZFSError):
179 errno = errno.EEXIST
180 message = "Snapshot is cloned"
182 def __init__(self, name):
183 self.name = name
186 class SnapshotIsHeld(ZFSError):
187 errno = errno.EBUSY
188 message = "Snapshot is held"
190 def __init__(self, name):
191 self.name = name
194 class DuplicateSnapshots(ZFSError):
195 errno = errno.EXDEV
196 message = "Requested multiple snapshots of the same filesystem"
198 def __init__(self, name):
199 self.name = name
202 class SnapshotFailure(MultipleOperationsFailure):
203 message = "Creation of snapshot(s) failed for one or more reasons"
205 def __init__(self, errors, suppressed_count):
206 super(SnapshotFailure, self).__init__(errors, suppressed_count)
209 class SnapshotDestructionFailure(MultipleOperationsFailure):
210 message = "Destruction of snapshot(s) failed for one or more reasons"
212 def __init__(self, errors, suppressed_count):
213 super(SnapshotDestructionFailure, self).__init__(
214 errors, suppressed_count)
217 class BookmarkExists(ZFSError):
218 errno = errno.EEXIST
219 message = "Bookmark already exists"
221 def __init__(self, name):
222 self.name = name
225 class BookmarkNotFound(ZFSError):
226 errno = errno.ENOENT
227 message = "Bookmark not found"
229 def __init__(self, name):
230 self.name = name
233 class BookmarkMismatch(ZFSError):
234 errno = errno.EINVAL
235 message = "source is not an ancestor of the new bookmark's dataset"
237 def __init__(self, name):
238 self.name = name
241 class BookmarkSourceInvalid(ZFSError):
242 errno = errno.EINVAL
243 message = "Bookmark source is not a valid snapshot or existing bookmark"
245 def __init__(self, name):
246 self.name = name
249 class BookmarkNotSupported(ZFSError):
250 errno = errno.ENOTSUP
251 message = "Bookmark feature is not supported"
253 def __init__(self, name):
254 self.name = name
257 class BookmarkFailure(MultipleOperationsFailure):
258 message = "Creation of bookmark(s) failed for one or more reasons"
260 def __init__(self, errors, suppressed_count):
261 super(BookmarkFailure, self).__init__(errors, suppressed_count)
264 class BookmarkDestructionFailure(MultipleOperationsFailure):
265 message = "Destruction of bookmark(s) failed for one or more reasons"
267 def __init__(self, errors, suppressed_count):
268 super(BookmarkDestructionFailure, self).__init__(
269 errors, suppressed_count)
272 class BadHoldCleanupFD(ZFSError):
273 errno = errno.EBADF
274 message = "Bad file descriptor as cleanup file descriptor"
277 class HoldExists(ZFSError):
278 errno = errno.EEXIST
279 message = "Hold with a given tag already exists on snapshot"
281 def __init__(self, name):
282 self.name = name
285 class HoldNotFound(ZFSError):
286 errno = errno.ENOENT
287 message = "Hold with a given tag does not exist on snapshot"
289 def __init__(self, name):
290 self.name = name
293 class HoldFailure(MultipleOperationsFailure):
294 message = "Placement of hold(s) failed for one or more reasons"
296 def __init__(self, errors, suppressed_count):
297 super(HoldFailure, self).__init__(errors, suppressed_count)
300 class HoldReleaseFailure(MultipleOperationsFailure):
301 message = "Release of hold(s) failed for one or more reasons"
303 def __init__(self, errors, suppressed_count):
304 super(HoldReleaseFailure, self).__init__(errors, suppressed_count)
307 class SnapshotMismatch(ZFSError):
308 errno = errno.ENODEV
309 message = "Snapshot is not descendant of source snapshot"
311 def __init__(self, name):
312 self.name = name
315 class StreamMismatch(ZFSError):
316 errno = errno.ENODEV
317 message = "Stream is not applicable to destination dataset"
319 def __init__(self, name):
320 self.name = name
323 class DestinationModified(ZFSError):
324 errno = errno.ETXTBSY
325 message = "Destination dataset has modifications that can not be undone"
327 def __init__(self, name):
328 self.name = name
331 class BadStream(ZFSError):
332 errno = ECKSUM
333 message = "Bad backup stream"
336 class StreamFeatureNotSupported(ZFSError):
337 errno = errno.ENOTSUP
338 message = "Stream contains unsupported feature"
341 class UnknownStreamFeature(ZFSError):
342 errno = errno.ENOTSUP
343 message = "Unknown feature requested for stream"
346 class StreamFeatureInvalid(ZFSError):
347 errno = errno.EINVAL
348 message = "Kernel modules must be upgraded to receive this stream"
351 class StreamFeatureIncompatible(ZFSError):
352 errno = errno.EINVAL
353 message = "Incompatible embedded feature with encrypted receive"
356 class StreamTruncated(ZFSError):
357 errno = zfs_errno.ZFS_ERR_STREAM_TRUNCATED
358 message = "incomplete stream"
361 class ReceivePropertyFailure(MultipleOperationsFailure):
362 message = "Receiving of properties failed for one or more reasons"
364 def __init__(self, errors, suppressed_count):
365 super(ReceivePropertyFailure, self).__init__(errors, suppressed_count)
368 class StreamIOError(ZFSError):
369 message = "I/O error while writing or reading stream"
371 def __init__(self, errno):
372 self.errno = errno
375 class ZIOError(ZFSError):
376 errno = errno.EIO
377 message = "I/O error"
379 def __init__(self, name):
380 self.name = name
383 class NoSpace(ZFSError):
384 errno = errno.ENOSPC
385 message = "No space left"
387 def __init__(self, name):
388 self.name = name
391 class QuotaExceeded(ZFSError):
392 errno = errno.EDQUOT
393 message = "Quota exceeded"
395 def __init__(self, name):
396 self.name = name
399 class DatasetBusy(ZFSError):
400 errno = errno.EBUSY
401 message = "Dataset is busy"
403 def __init__(self, name):
404 self.name = name
407 class NameTooLong(ZFSError):
408 errno = errno.ENAMETOOLONG
409 message = "Dataset name is too long"
411 def __init__(self, name):
412 self.name = name
415 class NameInvalid(ZFSError):
416 errno = errno.EINVAL
417 message = "Invalid name"
419 def __init__(self, name):
420 self.name = name
423 class SnapshotNameInvalid(NameInvalid):
424 message = "Invalid name for snapshot"
426 def __init__(self, name):
427 self.name = name
430 class FilesystemNameInvalid(NameInvalid):
431 message = "Invalid name for filesystem or volume"
433 def __init__(self, name):
434 self.name = name
437 class BookmarkNameInvalid(NameInvalid):
438 message = "Invalid name for bookmark"
440 def __init__(self, name):
441 self.name = name
444 class ReadOnlyPool(ZFSError):
445 errno = errno.EROFS
446 message = "Pool is read-only"
448 def __init__(self, name):
449 self.name = name
452 class SuspendedPool(ZFSError):
453 errno = errno.EAGAIN
454 message = "Pool is suspended"
456 def __init__(self, name):
457 self.name = name
460 class PoolNotFound(ZFSError):
461 errno = errno.EXDEV
462 message = "No such pool"
464 def __init__(self, name):
465 self.name = name
468 class PoolsDiffer(ZFSError):
469 errno = errno.EXDEV
470 message = "Source and target belong to different pools"
472 def __init__(self, name):
473 self.name = name
476 class FeatureNotSupported(ZFSError):
477 errno = errno.ENOTSUP
478 message = "Feature is not supported in this version"
480 def __init__(self, name):
481 self.name = name
484 class PropertyNotSupported(ZFSError):
485 errno = errno.ENOTSUP
486 message = "Property is not supported in this version"
488 def __init__(self, name):
489 self.name = name
492 class PropertyInvalid(ZFSError):
493 errno = errno.EINVAL
494 message = "Invalid property or property value"
496 def __init__(self, name):
497 self.name = name
500 class DatasetTypeInvalid(ZFSError):
501 errno = errno.EINVAL
502 message = "Specified dataset type is unknown"
504 def __init__(self, name):
505 self.name = name
508 class UnknownCryptCommand(ZFSError):
509 errno = errno.EINVAL
510 message = "Specified crypt command is invalid"
512 def __init__(self, name):
513 self.name = name
516 class EncryptionKeyNotLoaded(ZFSError):
517 errno = errno.EACCES
518 message = "Encryption key is not currently loaded"
521 class EncryptionKeyAlreadyLoaded(ZFSError):
522 errno = errno.EEXIST
523 message = "Encryption key is already loaded"
526 class EncryptionKeyInvalid(ZFSError):
527 errno = errno.EACCES
528 message = "Incorrect encryption key provided"
531 class ZCPError(ZFSError):
532 errno = None
533 message = None
536 class ZCPSyntaxError(ZCPError):
537 errno = errno.EINVAL
538 message = "Channel program contains syntax errors"
540 def __init__(self, details):
541 self.details = details
544 class ZCPRuntimeError(ZCPError):
545 errno = ECHRNG
546 message = "Channel programs encountered a runtime error"
548 def __init__(self, details):
549 self.details = details
552 class ZCPLimitInvalid(ZCPError):
553 errno = errno.EINVAL
554 message = "Channel program called with invalid limits"
557 class ZCPTimeout(ZCPError):
558 errno = ETIME
559 message = "Channel program timed out"
562 class ZCPSpaceError(ZCPError):
563 errno = errno.ENOSPC
564 message = "Channel program exhausted the memory limit"
567 class ZCPMemoryError(ZCPError):
568 errno = errno.ENOMEM
569 message = "Channel program return value too large"
572 class ZCPPermissionError(ZCPError):
573 errno = errno.EPERM
574 message = "Channel programs must be run as root"
577 class CheckpointExists(ZFSError):
578 errno = ZFS_ERR_CHECKPOINT_EXISTS
579 message = "Pool already has a checkpoint"
582 class CheckpointNotFound(ZFSError):
583 errno = ZFS_ERR_NO_CHECKPOINT
584 message = "Pool does not have a checkpoint"
587 class CheckpointDiscarding(ZFSError):
588 errno = ZFS_ERR_DISCARDING_CHECKPOINT
589 message = "Pool checkpoint is being discarded"
592 class DeviceRemovalRunning(ZFSError):
593 errno = ZFS_ERR_DEVRM_IN_PROGRESS
594 message = "A vdev is currently being removed"
597 class DeviceTooBig(ZFSError):
598 errno = ZFS_ERR_VDEV_TOO_BIG
599 message = "One or more top-level vdevs exceed the maximum vdev size"
602 class RaidzExpansionRunning(ZFSError):
603 errno = ZFS_ERR_RAIDZ_EXPAND_IN_PROGRESS
604 message = "A raidz device is currently expanding"
607 # vim: softtabstop=4 tabstop=4 expandtab shiftwidth=4