MCPcopy Index your code
hub / github.com/containerd/containerd / NewPoolDevice

Function NewPoolDevice

plugins/snapshots/devmapper/pool_device.go:46–88  ·  view source on GitHub ↗

NewPoolDevice creates new thin-pool from existing data and metadata volumes. If pool 'poolName' already exists, it'll be reloaded with new parameters.

(ctx context.Context, config *Config)

Source from the content-addressed store, hash-verified

44// NewPoolDevice creates new thin-pool from existing data and metadata volumes.
45// If pool 'poolName' already exists, it'll be reloaded with new parameters.
46func NewPoolDevice(ctx context.Context, config *Config) (*PoolDevice, error) {
47 log.G(ctx).Infof("initializing pool device %q", config.PoolName)
48
49 version, err := dmsetup.Version()
50 if err != nil {
51 log.G(ctx).Error("dmsetup not available")
52 return nil, err
53 }
54
55 log.G(ctx).Infof("using dmsetup:\n%s", version)
56
57 if config.DiscardBlocks {
58 err := blkdiscard.CheckBinary()
59 if err != nil {
60 log.G(ctx).Errorf("blkdiscard is not available:%v", err)
61 return nil, err
62 }
63 }
64
65 dbpath := filepath.Join(config.RootPath, config.PoolName+".db")
66 poolMetaStore, err := NewPoolMetadata(dbpath)
67 if err != nil {
68 return nil, err
69 }
70
71 // Make sure pool exists and available
72 poolPath := dmsetup.GetFullDevicePath(config.PoolName)
73 if _, err := dmsetup.Info(poolPath); err != nil {
74 return nil, fmt.Errorf("failed to query pool %q: %w", poolPath, err)
75 }
76
77 poolDevice := &PoolDevice{
78 poolName: config.PoolName,
79 metadata: poolMetaStore,
80 discardBlocks: config.DiscardBlocks,
81 }
82
83 if err := poolDevice.ensureDeviceStates(ctx); err != nil {
84 return nil, fmt.Errorf("failed to check devices state: %w", err)
85 }
86
87 return poolDevice, nil
88}
89
90func skipRetry(err error) bool {
91 if err == nil {

Callers 2

NewSnapshotterFunction · 0.85
TestPoolDeviceFunction · 0.85

Calls 7

ensureDeviceStatesMethod · 0.95
VersionFunction · 0.92
CheckBinaryFunction · 0.92
GetFullDevicePathFunction · 0.92
InfoFunction · 0.92
NewPoolMetadataFunction · 0.85
ErrorMethod · 0.45

Tested by 1

TestPoolDeviceFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…