Skip to content

Commit fcd9dc2

Browse files
committed
devmapper: add pool metadata
Signed-off-by: Maksym Pavlenko <[email protected]>
1 parent 809e5fd commit fcd9dc2

3 files changed

Lines changed: 604 additions & 0 deletions

File tree

snapshots/devmapper/device_info.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
Copyright The containerd Authors.
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+
package devmapper
18+
19+
import (
20+
"fmt"
21+
)
22+
23+
const (
24+
maxDeviceID = 0xffffff // Device IDs are 24-bit numbers
25+
)
26+
27+
// DeviceState represents current devmapper device state reflected in meta store
28+
type DeviceState int
29+
30+
const (
31+
// Unknown means that device just allocated and no operations were performed
32+
Unknown DeviceState = iota
33+
// Creating means that device is going to be created
34+
Creating
35+
// Created means that devices successfully created
36+
Created
37+
// Activating means that device is going to be activated
38+
Activating
39+
// Activated means that device successfully activated
40+
Activated
41+
// Suspending means that device is going to be suspended
42+
Suspending
43+
// Suspended means that device successfully suspended
44+
Suspended
45+
// Resuming means that device is going to be resumed from suspended state
46+
Resuming
47+
// Resumed means that device successfully resumed
48+
Resumed
49+
// Deactivating means that device is going to be deactivated
50+
Deactivating
51+
// Deactivated means that device successfully deactivated
52+
Deactivated
53+
// Removing means that device is going to be removed
54+
Removing
55+
// Removed means that device successfully removed but not yet deleted from meta store
56+
Removed
57+
)
58+
59+
func (s DeviceState) String() string {
60+
switch s {
61+
case Creating:
62+
return "Creating"
63+
case Created:
64+
return "Created"
65+
case Activating:
66+
return "Activating"
67+
case Activated:
68+
return "Activated"
69+
case Suspending:
70+
return "Suspending"
71+
case Suspended:
72+
return "Suspended"
73+
case Resuming:
74+
return "Resuming"
75+
case Resumed:
76+
return "Resumed"
77+
case Deactivating:
78+
return "Deactivating"
79+
case Deactivated:
80+
return "Deactivated"
81+
case Removing:
82+
return "Removing"
83+
case Removed:
84+
return "Removed"
85+
default:
86+
return fmt.Sprintf("unknown %d", s)
87+
}
88+
}
89+
90+
// DeviceInfo represents metadata for thin device within thin-pool
91+
type DeviceInfo struct {
92+
// DeviceID is a 24-bit number assigned to a device within thin-pool device
93+
DeviceID uint32 `json:"device_id"`
94+
// Size is a thin device size
95+
Size uint64 `json:"size"`
96+
// Name is a device name to be used in /dev/mapper/
97+
Name string `json:"name"`
98+
// ParentName is a name of parent device (if snapshot)
99+
ParentName string `json:"parent_name"`
100+
// State represents current device state
101+
State DeviceState `json:"state"`
102+
// Error details if device state change failed
103+
Error string `json:"error"`
104+
}

0 commit comments

Comments
 (0)