aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/pyzfs/libzfs_core/exceptions.py
blob: e484b07b64504f3df7d1ff04805275c841aaa5b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
#
# Copyright 2015 ClusterHQ
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

"""
Exceptions that can be raised by libzfs_core operations.
"""
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,
    ZFS_ERR_DEVRM_IN_PROGRESS,
    ZFS_ERR_VDEV_TOO_BIG,
    ZFS_ERR_WRONG_PARENT,
    zfs_errno
)


class ZFSError(Exception):
    errno = None
    message = None
    name = None

    def __str__(self):
        if self.name is not None:
            return "[Errno %d] %s: '%s'" % (
                self.errno, self.message, self.name)
        else:
            return "[Errno %d] %s" % (self.errno, self.message)

    def __repr__(self):
        return "%s(%r, %r)" % (
            self.__class__.__name__, self.errno, self.message)


class ZFSGenericError(ZFSError):

    def __init__(self, errno, name, message):
        self.errno = errno
        self.message = message
        self.name = name


class ZFSInitializationFailed(ZFSError):
    message = "Failed to initialize libzfs_core"

    def __init__(self, errno):
        self.errno = errno


class MultipleOperationsFailure(ZFSError):

    def __init__(self, errors, suppressed_count):
        # Use first of the individual error codes
        # as an overall error code.  This is more consistent.
        self.errno = errors[0].errno
        self.errors = errors
        # this many errors were encountered but not placed on the `errors` list
        self.suppressed_count = suppressed_count

    def __str__(self):
        return "%s, %d errors included, %d suppressed" % (
            ZFSError.__str__(self), len(self.errors), self.suppressed_count)

    def __repr__(self):
        return "%s(%r, %r, errors=%r, suppressed=%r)" % (
            self.__class__.__name__, self.errno, self.message, self.errors,
            self.suppressed_count)


class DatasetNotFound(ZFSError):

    """
    This exception is raised when an operation failure can be caused by a
    missing snapshot or a missing filesystem and it is impossible to
    distinguish between the causes.
    """
    errno = errno.ENOENT
    message = "Dataset not found"

    def __init__(self, name):
        self.name = name


class DatasetExists(ZFSError):

    """
    This exception is raised when an operation failure can be caused by an
    existing snapshot or filesystem and it is impossible to distinguish between
    the causes.
    """
    errno = errno.EEXIST
    message = "Dataset already exists"

    def __init__(self, name):
        self.name = name


class NotClone(ZFSError):
    errno = errno.EINVAL
    message = "Filesystem is not a clone, can not promote"

    def __init__(self, name):
        self.name = name


class FilesystemExists(DatasetExists):
    message = "Filesystem already exists"

    def __init__(self, name):
        self.name = name


class FilesystemNotFound(DatasetNotFound):
    message = "Filesystem not found"

    def __init__(self, name):
        self.name = name


class ParentNotFound(ZFSError):
    errno = errno.ENOENT
    message = "Parent not found"

    def __init__(self, name):
        self.name = name


class WrongParent(ZFSError):
    errno = ZFS_ERR_WRONG_PARENT
    message = "Parent dataset is not a filesystem"

    def __init__(self, name):
        self.name = name


class SnapshotExists(DatasetExists):
    message = "Snapshot already exists"

    def __init__(self, name):
        self.name = name


class SnapshotNotFound(DatasetNotFound):
    message = "Snapshot not found"

    def __init__(self, name):
        self.name = name


class SnapshotNotLatest(ZFSError):
    errno = errno.EEXIST
    message = "Snapshot is not the latest"

    def __init__(self, name):
        self.name = name


class SnapshotIsCloned(ZFSError):
    errno = errno.EEXIST
    message = "Snapshot is cloned"

    def __init__(self, name):
        self.name = name


class SnapshotIsHeld(ZFSError):
    errno = errno.EBUSY
    message = "Snapshot is held"

    def __init__(self, name):
        self.name = name


class DuplicateSnapshots(ZFSError):
    errno = errno.EXDEV
    message = "Requested multiple snapshots of the same filesystem"

    def __init__(self, name):
        self.name = name


class SnapshotFailure(MultipleOperationsFailure):
    message = "Creation of snapshot(s) failed for one or more reasons"

    def __init__(self, errors, suppressed_count):
        super(SnapshotFailure, self).__init__(errors, suppressed_count)


class SnapshotDestructionFailure(MultipleOperationsFailure):
    message = "Destruction of snapshot(s) failed for one or more reasons"

    def __init__(self, errors, suppressed_count):
        super(SnapshotDestructionFailure, self).__init__(
            errors, suppressed_count)


class BookmarkExists(ZFSError):
    errno = errno.EEXIST
    message = "Bookmark already exists"

    def __init__(self, name):
        self.name = name


class BookmarkNotFound(ZFSError):
    errno = errno.ENOENT
    message = "Bookmark not found"

    def __init__(self, name):
        self.name = name


class BookmarkMismatch(ZFSError):
    errno = errno.EINVAL
    message = "source is not an ancestor of the new bookmark's dataset"

    def __init__(self, name):
        self.name = name


class BookmarkSourceInvalid(ZFSError):
    errno = errno.EINVAL
    message = "Bookmark source is not a valid snapshot or existing bookmark"

    def __init__(self, name):
        self.name = name


class BookmarkNotSupported(ZFSError):
    errno = errno.ENOTSUP
    message = "Bookmark feature is not supported"

    def __init__(self, name):
        self.name = name


class BookmarkFailure(MultipleOperationsFailure):
    message = "Creation of bookmark(s) failed for one or more reasons"

    def __init__(self, errors, suppressed_count):
        super(BookmarkFailure, self).__init__(errors, suppressed_count)


class BookmarkDestructionFailure(MultipleOperationsFailure):
    message = "Destruction of bookmark(s) failed for one or more reasons"

    def __init__(self, errors, suppressed_count):
        super(BookmarkDestructionFailure, self).__init__(
            errors, suppressed_count)


class BadHoldCleanupFD(ZFSError):
    errno = errno.EBADF
    message = "Bad file descriptor as cleanup file descriptor"


class HoldExists(ZFSError):
    errno = errno.EEXIST
    message = "Hold with a given tag already exists on snapshot"

    def __init__(self, name):
        self.name = name


class HoldNotFound(ZFSError):
    errno = errno.ENOENT
    message = "Hold with a given tag does not exist on snapshot"

    def __init__(self, name):
        self.name = name


class HoldFailure(MultipleOperationsFailure):
    message = "Placement of hold(s) failed for one or more reasons"

    def __init__(self, errors, suppressed_count):
        super(HoldFailure, self).__init__(errors, suppressed_count)


class HoldReleaseFailure(MultipleOperationsFailure):
    message = "Release of hold(s) failed for one or more reasons"

    def __init__(self, errors, suppressed_count):
        super(HoldReleaseFailure, self).__init__(errors, suppressed_count)


class SnapshotMismatch(ZFSError):
    errno = errno.ENODEV
    message = "Snapshot is not descendant of source snapshot"

    def __init__(self, name):
        self.name = name


class StreamMismatch(ZFSError):
    errno = errno.ENODEV
    message = "Stream is not applicable to destination dataset"

    def __init__(self, name):
        self.name = name


class DestinationModified(ZFSError):
    errno = errno.ETXTBSY
    message = "Destination dataset has modifications that can not be undone"

    def __init__(self, name):
        self.name = name


class BadStream(ZFSError):
    errno = ECKSUM
    message = "Bad backup stream"


class StreamFeatureNotSupported(ZFSError):
    errno = errno.ENOTSUP
    message = "Stream contains unsupported feature"


class UnknownStreamFeature(ZFSError):
    errno = errno.ENOTSUP
    message = "Unknown feature requested for stream"


class StreamFeatureInvalid(ZFSError):
    errno = errno.EINVAL
    message = "Kernel modules must be upgraded to receive this stream"


class StreamFeatureIncompatible(ZFSError):
    errno = errno.EINVAL
    message = "Incompatible embedded feature with encrypted receive"


class StreamTruncated(ZFSError):
    errno = zfs_errno.ZFS_ERR_STREAM_TRUNCATED
    message = "incomplete stream"


class ReceivePropertyFailure(MultipleOperationsFailure):
    message = "Receiving of properties failed for one or more reasons"

    def __init__(self, errors, suppressed_count):
        super(ReceivePropertyFailure, self).__init__(errors, suppressed_count)


class StreamIOError(ZFSError):
    message = "I/O error while writing or reading stream"

    def __init__(self, errno):
        self.errno = errno


class ZIOError(ZFSError):
    errno = errno.EIO
    message = "I/O error"

    def __init__(self, name):
        self.name = name


class NoSpace(ZFSError):
    errno = errno.ENOSPC
    message = "No space left"

    def __init__(self, name):
        self.name = name


class QuotaExceeded(ZFSError):
    errno = errno.EDQUOT
    message = "Quota exceeded"

    def __init__(self, name):
        self.name = name


class DatasetBusy(ZFSError):
    errno = errno.EBUSY
    message = "Dataset is busy"

    def __init__(self, name):
        self.name = name


class NameTooLong(ZFSError):
    errno = errno.ENAMETOOLONG
    message = "Dataset name is too long"

    def __init__(self, name):
        self.name = name


class NameInvalid(ZFSError):
    errno = errno.EINVAL
    message = "Invalid name"

    def __init__(self, name):
        self.name = name


class SnapshotNameInvalid(NameInvalid):
    message = "Invalid name for snapshot"

    def __init__(self, name):
        self.name = name


class FilesystemNameInvalid(NameInvalid):
    message = "Invalid name for filesystem or volume"

    def __init__(self, name):
        self.name = name


class BookmarkNameInvalid(NameInvalid):
    message = "Invalid name for bookmark"

    def __init__(self, name):
        self.name = name


class ReadOnlyPool(ZFSError):
    errno = errno.EROFS
    message = "Pool is read-only"

    def __init__(self, name):
        self.name = name


class SuspendedPool(ZFSError):
    errno = errno.EAGAIN
    message = "Pool is suspended"

    def __init__(self, name):
        self.name = name


class PoolNotFound(ZFSError):
    errno = errno.EXDEV
    message = "No such pool"

    def __init__(self, name):
        self.name = name


class PoolsDiffer(ZFSError):
    errno = errno.EXDEV
    message = "Source and target belong to different pools"

    def __init__(self, name):
        self.name = name


class FeatureNotSupported(ZFSError):
    errno = errno.ENOTSUP
    message = "Feature is not supported in this version"

    def __init__(self, name):
        self.name = name


class PropertyNotSupported(ZFSError):
    errno = errno.ENOTSUP
    message = "Property is not supported in this version"

    def __init__(self, name):
        self.name = name


class PropertyInvalid(ZFSError):
    errno = errno.EINVAL
    message = "Invalid property or property value"

    def __init__(self, name):
        self.name = name


class DatasetTypeInvalid(ZFSError):
    errno = errno.EINVAL
    message = "Specified dataset type is unknown"

    def __init__(self, name):
        self.name = name


class UnknownCryptCommand(ZFSError):
    errno = errno.EINVAL
    message = "Specified crypt command is invalid"

    def __init__(self, name):
        self.name = name


class EncryptionKeyNotLoaded(ZFSError):
    errno = errno.EACCES
    message = "Encryption key is not currently loaded"


class EncryptionKeyAlreadyLoaded(ZFSError):
    errno = errno.EEXIST
    message = "Encryption key is already loaded"


class EncryptionKeyInvalid(ZFSError):
    errno = errno.EACCES
    message = "Incorrect encryption key provided"


class ZCPError(ZFSError):
    errno = None
    message = None


class ZCPSyntaxError(ZCPError):
    errno = errno.EINVAL
    message = "Channel program contains syntax errors"

    def __init__(self, details):
        self.details = details


class ZCPRuntimeError(ZCPError):
    errno = ECHRNG
    message = "Channel programs encountered a runtime error"

    def __init__(self, details):
        self.details = details


class ZCPLimitInvalid(ZCPError):
    errno = errno.EINVAL
    message = "Channel program called with invalid limits"


class ZCPTimeout(ZCPError):
    errno = ETIME
    message = "Channel program timed out"


class ZCPSpaceError(ZCPError):
    errno = errno.ENOSPC
    message = "Channel program exhausted the memory limit"


class ZCPMemoryError(ZCPError):
    errno = errno.ENOMEM
    message = "Channel program return value too large"


class ZCPPermissionError(ZCPError):
    errno = errno.EPERM
    message = "Channel programs must be run as root"


class CheckpointExists(ZFSError):
    errno = ZFS_ERR_CHECKPOINT_EXISTS
    message = "Pool already has a checkpoint"


class CheckpointNotFound(ZFSError):
    errno = ZFS_ERR_NO_CHECKPOINT
    message = "Pool does not have a checkpoint"


class CheckpointDiscarding(ZFSError):
    errno = ZFS_ERR_DISCARDING_CHECKPOINT
    message = "Pool checkpoint is being discarded"


class DeviceRemovalRunning(ZFSError):
    errno = ZFS_ERR_DEVRM_IN_PROGRESS
    message = "A vdev is currently being removed"


class DeviceTooBig(ZFSError):
    errno = ZFS_ERR_VDEV_TOO_BIG
    message = "One or more top-level vdevs exceed the maximum vdev size"


# vim: softtabstop=4 tabstop=4 expandtab shiftwidth=4