github.com/demonoid81/containerd@v1.3.4/snapshots/devmapper/device_info.go (about) 1 // +build linux 2 3 /* 4 Copyright The containerd Authors. 5 6 Licensed under the Apache License, Version 2.0 (the "License"); 7 you may not use this file except in compliance with the License. 8 You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 17 */ 18 19 package devmapper 20 21 import ( 22 "fmt" 23 ) 24 25 const ( 26 maxDeviceID = 0xffffff // Device IDs are 24-bit numbers 27 ) 28 29 // DeviceState represents current devmapper device state reflected in meta store 30 type DeviceState int 31 32 const ( 33 // Unknown means that device just allocated and no operations were performed 34 Unknown DeviceState = iota 35 // Creating means that device is going to be created 36 Creating 37 // Created means that devices successfully created 38 Created 39 // Activating means that device is going to be activated 40 Activating 41 // Activated means that device successfully activated 42 Activated 43 // Suspending means that device is going to be suspended 44 Suspending 45 // Suspended means that device successfully suspended 46 Suspended 47 // Resuming means that device is going to be resumed from suspended state 48 Resuming 49 // Resumed means that device successfully resumed 50 Resumed 51 // Deactivating means that device is going to be deactivated 52 Deactivating 53 // Deactivated means that device successfully deactivated 54 Deactivated 55 // Removing means that device is going to be removed 56 Removing 57 // Removed means that device successfully removed but not yet deleted from meta store 58 Removed 59 // Faulty means that the device is errored and the snapshotter failed to rollback it 60 Faulty 61 ) 62 63 func (s DeviceState) String() string { 64 switch s { 65 case Creating: 66 return "Creating" 67 case Created: 68 return "Created" 69 case Activating: 70 return "Activating" 71 case Activated: 72 return "Activated" 73 case Suspending: 74 return "Suspending" 75 case Suspended: 76 return "Suspended" 77 case Resuming: 78 return "Resuming" 79 case Resumed: 80 return "Resumed" 81 case Deactivating: 82 return "Deactivating" 83 case Deactivated: 84 return "Deactivated" 85 case Removing: 86 return "Removing" 87 case Removed: 88 return "Removed" 89 case Faulty: 90 return "Faulty" 91 default: 92 return fmt.Sprintf("unknown %d", s) 93 } 94 } 95 96 // DeviceInfo represents metadata for thin device within thin-pool 97 type DeviceInfo struct { 98 // DeviceID is a 24-bit number assigned to a device within thin-pool device 99 DeviceID uint32 `json:"device_id"` 100 // Size is a thin device size 101 Size uint64 `json:"size"` 102 // Name is a device name to be used in /dev/mapper/ 103 Name string `json:"name"` 104 // ParentName is a name of parent device (if snapshot) 105 ParentName string `json:"parent_name"` 106 // State represents current device state 107 State DeviceState `json:"state"` 108 // Error details if device state change failed 109 Error string `json:"error"` 110 }