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)
| 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. |
| 46 | func 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 | |
| 90 | func skipRetry(err error) bool { |
| 91 | if err == nil { |
searching dependent graphs…