feat: replace github.com/pkg/errors to errors
Signed-off-by: haoyun <yun.hao@daocloud.io> Co-authored-by: zounengren <zouyee1989@gmail.com>
This commit is contained in:
@@ -31,7 +31,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containerd/continuity/fs/fstest"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
@@ -287,7 +286,7 @@ func updateFile(name string) applierFn {
|
||||
path := filepath.Join(root, name)
|
||||
file, err := os.OpenFile(path, os.O_WRONLY, 0600)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to open %q", path)
|
||||
return fmt.Errorf("failed to open %q: %w", path, err)
|
||||
}
|
||||
|
||||
info, err := file.Stat()
|
||||
@@ -305,7 +304,7 @@ func updateFile(name string) applierFn {
|
||||
}
|
||||
|
||||
if _, err := file.WriteAt(buf, offset); err != nil {
|
||||
return errors.Wrapf(err, "failed to write %q at offset %d", path, offset)
|
||||
return fmt.Errorf("failed to write %q at offset %d: %w", path, offset, err)
|
||||
}
|
||||
|
||||
return file.Close()
|
||||
|
||||
@@ -35,7 +35,6 @@ import (
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/containerd/snapshots/storage"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -69,7 +68,7 @@ func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
|
||||
return nil, err
|
||||
}
|
||||
if mnt.FSType != "btrfs" {
|
||||
return nil, errors.Wrapf(plugin.ErrSkipPlugin, "path %s (%s) must be a btrfs filesystem to be used with the btrfs snapshotter", root, mnt.FSType)
|
||||
return nil, fmt.Errorf("path %s (%s) must be a btrfs filesystem to be used with the btrfs snapshotter: %w", root, mnt.FSType, plugin.ErrSkipPlugin)
|
||||
}
|
||||
var (
|
||||
active = filepath.Join(root, "active")
|
||||
@@ -275,7 +274,7 @@ func (b *snapshotter) mounts(dir string, s storage.Snapshot) ([]mount.Mount, err
|
||||
func (b *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) (err error) {
|
||||
usage, err := b.usage(ctx, key)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to compute usage")
|
||||
return fmt.Errorf("failed to compute usage: %w", err)
|
||||
}
|
||||
|
||||
ctx, t, err := b.ms.TransactionContext(ctx, true)
|
||||
@@ -292,7 +291,7 @@ func (b *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
|
||||
|
||||
id, err := storage.CommitActive(ctx, key, name, usage, opts...) // TODO(stevvooe): Resolve a usage value for btrfs
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to commit")
|
||||
return fmt.Errorf("failed to commit: %w", err)
|
||||
}
|
||||
|
||||
source := filepath.Join(b.root, "active", id)
|
||||
@@ -331,7 +330,7 @@ func (b *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
|
||||
s, err := storage.GetSnapshot(ctx, key)
|
||||
t.Rollback()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get active snapshot")
|
||||
return nil, fmt.Errorf("failed to get active snapshot: %w", err)
|
||||
}
|
||||
|
||||
dir := filepath.Join(b.root, strings.ToLower(s.Kind.String()), s.ID)
|
||||
@@ -366,7 +365,7 @@ func (b *snapshotter) Remove(ctx context.Context, key string) (err error) {
|
||||
|
||||
id, k, err := storage.Remove(ctx, key)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to remove snapshot")
|
||||
return fmt.Errorf("failed to remove snapshot: %w", err)
|
||||
}
|
||||
|
||||
switch k {
|
||||
@@ -389,7 +388,7 @@ func (b *snapshotter) Remove(ctx context.Context, key string) (err error) {
|
||||
}
|
||||
|
||||
if err := btrfs.SubvolDelete(source); err != nil {
|
||||
return errors.Wrapf(err, "failed to remove snapshot %v", source)
|
||||
return fmt.Errorf("failed to remove snapshot %v: %w", source, err)
|
||||
}
|
||||
|
||||
err = t.Commit()
|
||||
|
||||
@@ -22,6 +22,8 @@ package btrfs
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -34,7 +36,6 @@ import (
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/containerd/snapshots/testsuite"
|
||||
"github.com/containerd/continuity/testutil/loopback"
|
||||
"github.com/pkg/errors"
|
||||
exec "golang.org/x/sys/execabs"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@@ -66,7 +67,7 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
|
||||
|
||||
if out, err := exec.Command(mkbtrfs, loop.Device).CombinedOutput(); err != nil {
|
||||
loop.Close()
|
||||
return nil, nil, errors.Wrapf(err, "failed to make btrfs filesystem (out: %q)", out)
|
||||
return nil, nil, fmt.Errorf("failed to make btrfs filesystem (out: %q): %w", out, err)
|
||||
}
|
||||
// sync after a mkfs on the loopback before trying to mount the device
|
||||
unix.Sync()
|
||||
@@ -75,7 +76,7 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
|
||||
for i := 0; i < 5; i++ {
|
||||
if out, err := exec.Command("mount", loop.Device, root).CombinedOutput(); err != nil {
|
||||
loop.Close()
|
||||
return nil, nil, errors.Wrapf(err, "failed to mount device %s (out: %q)", loop.Device, out)
|
||||
return nil, nil, fmt.Errorf("failed to mount device %s (out: %q): %w", loop.Device, out, err)
|
||||
}
|
||||
|
||||
if i > 0 {
|
||||
@@ -95,7 +96,7 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
|
||||
unix.Unmount(root, 0)
|
||||
}
|
||||
if snapshotter == nil {
|
||||
return nil, nil, errors.Wrap(err, "failed to successfully create snapshotter after 5 attempts")
|
||||
return nil, nil, fmt.Errorf("failed to successfully create snapshotter after 5 attempts: %w", err)
|
||||
}
|
||||
|
||||
return snapshotter, func() error {
|
||||
@@ -104,7 +105,7 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
|
||||
}
|
||||
err := mount.UnmountAll(root, unix.MNT_DETACH)
|
||||
if cerr := loop.Close(); cerr != nil {
|
||||
err = errors.Wrap(cerr, "device cleanup failed")
|
||||
err = fmt.Errorf("device cleanup failed: %w", cerr)
|
||||
}
|
||||
return err
|
||||
}, nil
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"github.com/docker/go-units"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/pelletier/go-toml"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Config represents device mapper configuration loaded from file.
|
||||
@@ -68,11 +67,11 @@ func LoadConfig(path string) (*Config, error) {
|
||||
config := Config{}
|
||||
file, err := toml.LoadFile(path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to open devmapepr TOML: %s", path)
|
||||
return nil, fmt.Errorf("failed to open devmapepr TOML: %s: %w", path, err)
|
||||
}
|
||||
|
||||
if err := file.Unmarshal(&config); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to unmarshal devmapper TOML")
|
||||
return nil, fmt.Errorf("failed to unmarshal devmapper TOML: %w", err)
|
||||
}
|
||||
|
||||
if err := config.parse(); err != nil {
|
||||
@@ -89,7 +88,7 @@ func LoadConfig(path string) (*Config, error) {
|
||||
func (c *Config) parse() error {
|
||||
baseImageSize, err := units.RAMInBytes(c.BaseImageSize)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to parse base image size: '%s'", c.BaseImageSize)
|
||||
return fmt.Errorf("failed to parse base image size: '%s': %w", c.BaseImageSize, err)
|
||||
}
|
||||
|
||||
if c.FileSystemType == "" {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
package dmsetup
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -29,7 +30,6 @@ import (
|
||||
"strings"
|
||||
|
||||
blkdiscard "github.com/containerd/containerd/snapshots/devmapper/blkdiscard"
|
||||
"github.com/pkg/errors"
|
||||
exec "golang.org/x/sys/execabs"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@@ -101,7 +101,7 @@ const (
|
||||
func makeThinPoolMapping(dataFile, metaFile string, blockSizeSectors uint32) (string, error) {
|
||||
dataDeviceSizeBytes, err := BlockDeviceSize(dataFile)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "failed to get block device size: %s", dataFile)
|
||||
return "", fmt.Errorf("failed to get block device size: %s: %w", dataFile, err)
|
||||
}
|
||||
|
||||
// Thin-pool mapping target has the following format:
|
||||
@@ -259,7 +259,7 @@ func Info(deviceName string) ([]*DeviceInfo, error) {
|
||||
&info.EventNumber)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to parse line %q", line)
|
||||
return nil, fmt.Errorf("failed to parse line %q: %w", line, err)
|
||||
}
|
||||
|
||||
// Parse attributes (see "man 8 dmsetup" for details)
|
||||
@@ -309,17 +309,17 @@ func Status(deviceName string) (*DeviceStatus, error) {
|
||||
const MinParseCount = 4
|
||||
parts := strings.Split(output, " ")
|
||||
if len(parts) < MinParseCount {
|
||||
return nil, errors.Errorf("failed to parse output: %q", output)
|
||||
return nil, fmt.Errorf("failed to parse output: %q", output)
|
||||
}
|
||||
|
||||
status.Offset, err = strconv.ParseInt(parts[0], 10, 64)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to parse offset: %q", parts[0])
|
||||
return nil, fmt.Errorf("failed to parse offset: %q: %w", parts[0], err)
|
||||
}
|
||||
|
||||
status.Length, err = strconv.ParseInt(parts[1], 10, 64)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to parse length: %q", parts[1])
|
||||
return nil, fmt.Errorf("failed to parse length: %q: %w", parts[1], err)
|
||||
}
|
||||
|
||||
status.Target = parts[2]
|
||||
@@ -347,7 +347,7 @@ func BlockDeviceSize(path string) (int64, error) {
|
||||
|
||||
size, err := f.Seek(0, io.SeekEnd)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to seek on %q", path)
|
||||
return 0, fmt.Errorf("failed to seek on %q: %w", path, err)
|
||||
}
|
||||
return size, nil
|
||||
}
|
||||
@@ -379,7 +379,7 @@ func dmsetup(args ...string) (string, error) {
|
||||
return "", errno
|
||||
}
|
||||
|
||||
return "", errors.Wrapf(err, "dmsetup %s\nerror: %s\n", strings.Join(args, " "), output)
|
||||
return "", fmt.Errorf("dmsetup %s\nerror: %s\n: %w", strings.Join(args, " "), output, err)
|
||||
}
|
||||
|
||||
output = strings.TrimSuffix(output, "\n")
|
||||
|
||||
@@ -22,10 +22,10 @@ package devmapper
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
@@ -70,7 +70,7 @@ func NewPoolMetadata(dbfile string) (*PoolMetadata, error) {
|
||||
|
||||
metadata := &PoolMetadata{db: db}
|
||||
if err := metadata.ensureDatabaseInitialized(); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to initialize database")
|
||||
return nil, fmt.Errorf("failed to initialize database: %w", err)
|
||||
}
|
||||
|
||||
return metadata, nil
|
||||
@@ -102,7 +102,7 @@ func (m *PoolMetadata) AddDevice(ctx context.Context, info *DeviceInfo) error {
|
||||
// See https://github.com/containerd/containerd/pull/3436 for more context.
|
||||
var existing DeviceInfo
|
||||
if err := getObject(devicesBucket, info.Name, &existing); err == nil && existing.State != Faulty {
|
||||
return errors.Wrapf(ErrAlreadyExists, "device %q is already there %+v", info.Name, existing)
|
||||
return fmt.Errorf("device %q is already there %+v: %w", info.Name, existing, ErrAlreadyExists)
|
||||
}
|
||||
|
||||
// Find next available device ID
|
||||
@@ -117,7 +117,7 @@ func (m *PoolMetadata) AddDevice(ctx context.Context, info *DeviceInfo) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to save metadata for device %q (parent: %q)", info.Name, info.ParentName)
|
||||
return fmt.Errorf("failed to save metadata for device %q (parent: %q): %w", info.Name, info.ParentName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -213,7 +213,7 @@ func markDeviceID(tx *bolt.Tx, deviceID uint32, state deviceIDState) error {
|
||||
)
|
||||
|
||||
if err := bucket.Put([]byte(key), value); err != nil {
|
||||
return errors.Wrapf(err, "failed to free device id %q", key)
|
||||
return fmt.Errorf("failed to free device id %q: %w", key, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -282,7 +282,7 @@ func (m *PoolMetadata) RemoveDevice(ctx context.Context, name string) error {
|
||||
}
|
||||
|
||||
if err := bucket.Delete([]byte(name)); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete device info for %q", name)
|
||||
return fmt.Errorf("failed to delete device info for %q: %w", name, err)
|
||||
}
|
||||
|
||||
return markDeviceID(tx, device.DeviceID, deviceFree)
|
||||
@@ -297,7 +297,7 @@ func (m *PoolMetadata) WalkDevices(ctx context.Context, cb func(info *DeviceInfo
|
||||
return bucket.ForEach(func(key, value []byte) error {
|
||||
device := &DeviceInfo{}
|
||||
if err := json.Unmarshal(value, device); err != nil {
|
||||
return errors.Wrapf(err, "failed to unmarshal %s", key)
|
||||
return fmt.Errorf("failed to unmarshal %s: %w", key, err)
|
||||
}
|
||||
|
||||
return cb(device)
|
||||
@@ -340,16 +340,16 @@ func putObject(bucket *bolt.Bucket, key string, obj interface{}, overwrite bool)
|
||||
keyBytes := []byte(key)
|
||||
|
||||
if !overwrite && bucket.Get(keyBytes) != nil {
|
||||
return errors.Errorf("object with key %q already exists", key)
|
||||
return fmt.Errorf("object with key %q already exists", key)
|
||||
}
|
||||
|
||||
data, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to marshal object with key %q", key)
|
||||
return fmt.Errorf("failed to marshal object with key %q: %w", key, err)
|
||||
}
|
||||
|
||||
if err := bucket.Put(keyBytes, data); err != nil {
|
||||
return errors.Wrapf(err, "failed to insert object with key %q", key)
|
||||
return fmt.Errorf("failed to insert object with key %q: %w", key, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -363,7 +363,7 @@ func getObject(bucket *bolt.Bucket, key string, obj interface{}) error {
|
||||
|
||||
if obj != nil {
|
||||
if err := json.Unmarshal(data, obj); err != nil {
|
||||
return errors.Wrapf(err, "failed to unmarshal object with key %q", key)
|
||||
return fmt.Errorf("failed to unmarshal object with key %q: %w", key, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,12 +21,12 @@ package devmapper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"go.etcd.io/bbolt"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/snapshots/devmapper"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -21,12 +21,13 @@ package devmapper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/containerd/containerd/log"
|
||||
@@ -72,7 +73,7 @@ func NewPoolDevice(ctx context.Context, config *Config) (*PoolDevice, error) {
|
||||
// Make sure pool exists and available
|
||||
poolPath := dmsetup.GetFullDevicePath(config.PoolName)
|
||||
if _, err := dmsetup.Info(poolPath); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to query pool %q", poolPath)
|
||||
return nil, fmt.Errorf("failed to query pool %q: %w", poolPath, err)
|
||||
}
|
||||
|
||||
poolDevice := &PoolDevice{
|
||||
@@ -82,7 +83,7 @@ func NewPoolDevice(ctx context.Context, config *Config) (*PoolDevice, error) {
|
||||
}
|
||||
|
||||
if err := poolDevice.ensureDeviceStates(ctx); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to check devices state")
|
||||
return nil, fmt.Errorf("failed to check devices state: %w", err)
|
||||
}
|
||||
|
||||
return poolDevice, nil
|
||||
@@ -134,7 +135,7 @@ func (p *PoolDevice) ensureDeviceStates(ctx context.Context) error {
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "failed to query devices from metastore")
|
||||
return fmt.Errorf("failed to query devices from metastore: %w", err)
|
||||
}
|
||||
|
||||
var result *multierror.Error
|
||||
@@ -175,7 +176,7 @@ func (p *PoolDevice) transition(ctx context.Context, deviceName string, tryingSt
|
||||
})
|
||||
|
||||
if uerr != nil {
|
||||
return errors.Wrapf(uerr, "failed to set device %q state to %q", deviceName, tryingState)
|
||||
return fmt.Errorf("failed to set device %q state to %q: %w", deviceName, tryingState, uerr)
|
||||
}
|
||||
|
||||
var result *multierror.Error
|
||||
@@ -293,7 +294,7 @@ func (p *PoolDevice) createDevice(ctx context.Context, info *DeviceInfo) error {
|
||||
if err := p.transition(ctx, info.Name, Creating, Created, func() error {
|
||||
return dmsetup.CreateDevice(p.poolName, info.DeviceID)
|
||||
}); err != nil {
|
||||
return errors.Wrapf(err, "failed to create new thin device %q (dev: %d)", info.Name, info.DeviceID)
|
||||
return fmt.Errorf("failed to create new thin device %q (dev: %d): %w", info.Name, info.DeviceID, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -304,7 +305,7 @@ func (p *PoolDevice) activateDevice(ctx context.Context, info *DeviceInfo) error
|
||||
if err := p.transition(ctx, info.Name, Activating, Activated, func() error {
|
||||
return dmsetup.ActivateDevice(p.poolName, info.Name, info.DeviceID, info.Size, "")
|
||||
}); err != nil {
|
||||
return errors.Wrapf(err, "failed to activate new thin device %q (dev: %d)", info.Name, info.DeviceID)
|
||||
return fmt.Errorf("failed to activate new thin device %q (dev: %d): %w", info.Name, info.DeviceID, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -314,7 +315,7 @@ func (p *PoolDevice) activateDevice(ctx context.Context, info *DeviceInfo) error
|
||||
func (p *PoolDevice) CreateSnapshotDevice(ctx context.Context, deviceName string, snapshotName string, virtualSizeBytes uint64) (retErr error) {
|
||||
baseInfo, err := p.metadata.GetDevice(ctx, deviceName)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to query device metadata for %q", deviceName)
|
||||
return fmt.Errorf("failed to query device metadata for %q: %w", deviceName, err)
|
||||
}
|
||||
|
||||
snapInfo := &DeviceInfo{
|
||||
@@ -386,12 +387,13 @@ func (p *PoolDevice) createSnapshot(ctx context.Context, baseInfo, snapInfo *Dev
|
||||
if err := p.transition(ctx, snapInfo.Name, Creating, Created, func() error {
|
||||
return dmsetup.CreateSnapshot(p.poolName, snapInfo.DeviceID, baseInfo.DeviceID)
|
||||
}); err != nil {
|
||||
return errors.Wrapf(err,
|
||||
"failed to create snapshot %q (dev: %d) from %q (dev: %d)",
|
||||
return fmt.Errorf(
|
||||
"failed to create snapshot %q (dev: %d) from %q (dev: %d): %w",
|
||||
snapInfo.Name,
|
||||
snapInfo.DeviceID,
|
||||
baseInfo.Name,
|
||||
baseInfo.DeviceID)
|
||||
baseInfo.DeviceID, err,
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -402,7 +404,7 @@ func (p *PoolDevice) SuspendDevice(ctx context.Context, deviceName string) error
|
||||
if err := p.transition(ctx, deviceName, Suspending, Suspended, func() error {
|
||||
return dmsetup.SuspendDevice(deviceName)
|
||||
}); err != nil {
|
||||
return errors.Wrapf(err, "failed to suspend device %q", deviceName)
|
||||
return fmt.Errorf("failed to suspend device %q: %w", deviceName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -413,7 +415,7 @@ func (p *PoolDevice) ResumeDevice(ctx context.Context, deviceName string) error
|
||||
if err := p.transition(ctx, deviceName, Resuming, Resumed, func() error {
|
||||
return dmsetup.ResumeDevice(deviceName)
|
||||
}); err != nil {
|
||||
return errors.Wrapf(err, "failed to resume device %q", deviceName)
|
||||
return fmt.Errorf("failed to resume device %q: %w", deviceName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -446,13 +448,13 @@ func (p *PoolDevice) DeactivateDevice(ctx context.Context, deviceName string, de
|
||||
}
|
||||
}
|
||||
if err := dmsetup.RemoveDevice(deviceName, opts...); err != nil {
|
||||
return errors.Wrap(err, "failed to deactivate device")
|
||||
return fmt.Errorf("failed to deactivate device: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}); err != nil {
|
||||
return errors.Wrapf(err, "failed to deactivate device %q", deviceName)
|
||||
return fmt.Errorf("failed to deactivate device %q: %w", deviceName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -487,7 +489,7 @@ func (p *PoolDevice) IsLoaded(deviceName string) bool {
|
||||
func (p *PoolDevice) GetUsage(deviceName string) (int64, error) {
|
||||
status, err := dmsetup.Status(deviceName)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "can't get status for device %q", deviceName)
|
||||
return 0, fmt.Errorf("can't get status for device %q: %w", deviceName, err)
|
||||
}
|
||||
|
||||
if len(status.Params) == 0 {
|
||||
@@ -496,7 +498,7 @@ func (p *PoolDevice) GetUsage(deviceName string) (int64, error) {
|
||||
|
||||
count, err := strconv.ParseInt(status.Params[0], 10, 64)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to parse status params: %q", status.Params[0])
|
||||
return 0, fmt.Errorf("failed to parse status params: %q: %w", status.Params[0], err)
|
||||
}
|
||||
|
||||
return count * dmsetup.SectorSize, nil
|
||||
@@ -506,7 +508,7 @@ func (p *PoolDevice) GetUsage(deviceName string) (int64, error) {
|
||||
func (p *PoolDevice) RemoveDevice(ctx context.Context, deviceName string) error {
|
||||
info, err := p.metadata.GetDevice(ctx, deviceName)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "can't query metadata for device %q", deviceName)
|
||||
return fmt.Errorf("can't query metadata for device %q: %w", deviceName, err)
|
||||
}
|
||||
|
||||
if err := p.DeactivateDevice(ctx, deviceName, false, true); err != nil {
|
||||
@@ -519,7 +521,7 @@ func (p *PoolDevice) RemoveDevice(ctx context.Context, deviceName string) error
|
||||
|
||||
// Remove record from meta store and free device ID
|
||||
if err := p.metadata.RemoveDevice(ctx, deviceName); err != nil {
|
||||
return errors.Wrapf(err, "can't remove device %q metadata from store after removal", deviceName)
|
||||
return fmt.Errorf("can't remove device %q metadata from store after removal: %w", deviceName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -537,7 +539,7 @@ func (p *PoolDevice) deleteDevice(ctx context.Context, info *DeviceInfo) error {
|
||||
return nil
|
||||
})
|
||||
}); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete device %q (dev id: %d)", info.Name, info.DeviceID)
|
||||
return fmt.Errorf("failed to delete device %q (dev id: %d): %w", info.Name, info.DeviceID, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -547,7 +549,7 @@ func (p *PoolDevice) deleteDevice(ctx context.Context, info *DeviceInfo) error {
|
||||
func (p *PoolDevice) RemovePool(ctx context.Context) error {
|
||||
deviceNames, err := p.metadata.GetDeviceNames(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "can't query device names")
|
||||
return fmt.Errorf("can't query device names: %w", err)
|
||||
}
|
||||
|
||||
var result *multierror.Error
|
||||
@@ -555,12 +557,12 @@ func (p *PoolDevice) RemovePool(ctx context.Context) error {
|
||||
// Deactivate devices if any
|
||||
for _, name := range deviceNames {
|
||||
if err := p.DeactivateDevice(ctx, name, true, true); err != nil {
|
||||
result = multierror.Append(result, errors.Wrapf(err, "failed to remove %q", name))
|
||||
result = multierror.Append(result, fmt.Errorf("failed to remove %q: %w", name, err))
|
||||
}
|
||||
}
|
||||
|
||||
if err := dmsetup.RemoveDevice(p.poolName, dmsetup.RemoveWithForce, dmsetup.RemoveWithRetries, dmsetup.RemoveDeferred); err != nil {
|
||||
result = multierror.Append(result, errors.Wrapf(err, "failed to remove pool %q", p.poolName))
|
||||
result = multierror.Append(result, fmt.Errorf("failed to remove pool %q: %w", p.poolName, err))
|
||||
}
|
||||
|
||||
return result.ErrorOrNil()
|
||||
|
||||
@@ -21,6 +21,7 @@ package devmapper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -34,7 +35,6 @@ import (
|
||||
"github.com/containerd/containerd/snapshots/devmapper/dmsetup"
|
||||
"github.com/containerd/containerd/snapshots/storage"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
exec "golang.org/x/sys/execabs"
|
||||
)
|
||||
@@ -76,12 +76,12 @@ func NewSnapshotter(ctx context.Context, config *Config) (*Snapshotter, error) {
|
||||
var cleanupFn []closeFunc
|
||||
|
||||
if err := os.MkdirAll(config.RootPath, 0750); err != nil && !os.IsExist(err) {
|
||||
return nil, errors.Wrapf(err, "failed to create root directory: %s", config.RootPath)
|
||||
return nil, fmt.Errorf("failed to create root directory: %s: %w", config.RootPath, err)
|
||||
}
|
||||
|
||||
store, err := storage.NewMetaStore(filepath.Join(config.RootPath, metadataFileName))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create metastore")
|
||||
return nil, fmt.Errorf("failed to create metastore: %w", err)
|
||||
}
|
||||
|
||||
cleanupFn = append(cleanupFn, store.Close)
|
||||
@@ -481,7 +481,7 @@ func mkfs(ctx context.Context, fs fsType, fsOptions string, path string) error {
|
||||
b, err := exec.Command(mkfsCommand, args...).CombinedOutput()
|
||||
out := string(b)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "%s couldn't initialize %q: %s", mkfsCommand, path, out)
|
||||
return fmt.Errorf("%s couldn't initialize %q: %s: %w", mkfsCommand, path, out, err)
|
||||
}
|
||||
|
||||
log.G(ctx).Debugf("mkfs:\n%s", out)
|
||||
@@ -539,12 +539,12 @@ func (s *Snapshotter) withTransaction(ctx context.Context, writable bool, fn fun
|
||||
if err != nil || !writable {
|
||||
if terr := trans.Rollback(); terr != nil {
|
||||
log.G(ctx).WithError(terr).Error("failed to rollback transaction")
|
||||
result = multierror.Append(result, errors.Wrap(terr, "rollback failed"))
|
||||
result = multierror.Append(result, fmt.Errorf("rollback failed: %w", terr))
|
||||
}
|
||||
} else {
|
||||
if terr := trans.Commit(); terr != nil {
|
||||
log.G(ctx).WithError(terr).Error("failed to commit transaction")
|
||||
result = multierror.Append(result, errors.Wrap(terr, "commit failed"))
|
||||
result = multierror.Append(result, fmt.Errorf("commit failed: %w", terr))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ import (
|
||||
"github.com/containerd/containerd/snapshots/storage"
|
||||
"github.com/containerd/continuity/fs"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -80,7 +79,7 @@ func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
|
||||
return nil, err
|
||||
}
|
||||
if strings.ToLower(fsType) != "ntfs" {
|
||||
return nil, errors.Wrapf(errdefs.ErrInvalidArgument, "%s is not on an NTFS volume - only NTFS volumes are supported", root)
|
||||
return nil, fmt.Errorf("%s is not on an NTFS volume - only NTFS volumes are supported: %w", root, errdefs.ErrInvalidArgument)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(root, 0700); err != nil {
|
||||
@@ -180,7 +179,7 @@ func (s *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
|
||||
|
||||
snapshot, err := storage.GetSnapshot(ctx, key)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get snapshot mount")
|
||||
return nil, fmt.Errorf("failed to get snapshot mount: %w", err)
|
||||
}
|
||||
return s.mounts(snapshot), nil
|
||||
}
|
||||
@@ -210,7 +209,7 @@ func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
|
||||
}
|
||||
|
||||
if _, err = storage.CommitActive(ctx, key, name, snapshots.Usage(usage), opts...); err != nil {
|
||||
return errors.Wrap(err, "failed to commit snapshot")
|
||||
return fmt.Errorf("failed to commit snapshot: %w", err)
|
||||
}
|
||||
|
||||
return t.Commit()
|
||||
@@ -227,7 +226,7 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
|
||||
|
||||
id, _, err := storage.Remove(ctx, key)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to remove")
|
||||
return fmt.Errorf("failed to remove: %w", err)
|
||||
}
|
||||
|
||||
path := s.getSnapshotDir(id)
|
||||
@@ -241,7 +240,7 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
|
||||
// May cause inconsistent data on disk
|
||||
log.G(ctx).WithError(err1).WithField("path", renamed).Error("Failed to rename after failed commit")
|
||||
}
|
||||
return errors.Wrap(err, "failed to commit")
|
||||
return fmt.Errorf("failed to commit: %w", err)
|
||||
}
|
||||
|
||||
if err := os.RemoveAll(renamed); err != nil {
|
||||
@@ -319,7 +318,7 @@ func (s *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
|
||||
newSnapshot, err := storage.CreateSnapshot(ctx, kind, key, parent, opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create snapshot")
|
||||
return nil, fmt.Errorf("failed to create snapshot: %w", err)
|
||||
}
|
||||
|
||||
if kind == snapshots.KindActive {
|
||||
@@ -385,20 +384,20 @@ func (s *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
destPath := filepath.Join(snDir, "sandbox.vhdx")
|
||||
dest, err := os.OpenFile(destPath, os.O_RDWR|os.O_CREATE, 0700)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create sandbox.vhdx in snapshot")
|
||||
return nil, fmt.Errorf("failed to create sandbox.vhdx in snapshot: %w", err)
|
||||
}
|
||||
defer dest.Close()
|
||||
if _, err := io.Copy(dest, scratchSource); err != nil {
|
||||
dest.Close()
|
||||
os.Remove(destPath)
|
||||
return nil, errors.Wrap(err, "failed to copy cached scratch.vhdx to sandbox.vhdx in snapshot")
|
||||
return nil, fmt.Errorf("failed to copy cached scratch.vhdx to sandbox.vhdx in snapshot: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := t.Commit(); err != nil {
|
||||
return nil, errors.Wrap(err, "commit failed")
|
||||
return nil, fmt.Errorf("commit failed: %w", err)
|
||||
}
|
||||
|
||||
return s.mounts(newSnapshot), nil
|
||||
@@ -417,19 +416,19 @@ func (s *snapshotter) handleSharing(ctx context.Context, id, snDir string) error
|
||||
|
||||
mounts, err := s.Mounts(ctx, key)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get mounts for owner snapshot")
|
||||
return fmt.Errorf("failed to get mounts for owner snapshot: %w", err)
|
||||
}
|
||||
|
||||
sandboxPath := filepath.Join(mounts[0].Source, "sandbox.vhdx")
|
||||
linkPath := filepath.Join(snDir, "sandbox.vhdx")
|
||||
if _, err := os.Stat(sandboxPath); err != nil {
|
||||
return errors.Wrap(err, "failed to find sandbox.vhdx in snapshot directory")
|
||||
return fmt.Errorf("failed to find sandbox.vhdx in snapshot directory: %w", err)
|
||||
}
|
||||
|
||||
// We've found everything we need, now just make a symlink in our new snapshot to the
|
||||
// sandbox.vhdx in the scratch we're asking to share.
|
||||
if err := os.Symlink(sandboxPath, linkPath); err != nil {
|
||||
return errors.Wrap(err, "failed to create symlink for sandbox scratch space")
|
||||
return fmt.Errorf("failed to create symlink for sandbox scratch space: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -452,7 +451,7 @@ func (s *snapshotter) openOrCreateScratch(ctx context.Context, sizeGB int, scrat
|
||||
scratchSource, err := os.OpenFile(scratchFinalPath, os.O_RDONLY, 0700)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return nil, errors.Wrapf(err, "failed to open vhd %s for read", vhdFileName)
|
||||
return nil, fmt.Errorf("failed to open vhd %s for read: %w", vhdFileName, err)
|
||||
}
|
||||
|
||||
log.G(ctx).Debugf("vhdx %s not found, creating a new one", vhdFileName)
|
||||
@@ -478,16 +477,16 @@ func (s *snapshotter) openOrCreateScratch(ctx context.Context, sizeGB int, scrat
|
||||
|
||||
if err := rhcs.CreateScratchWithOpts(ctx, scratchTempPath, &opt); err != nil {
|
||||
os.Remove(scratchTempPath)
|
||||
return nil, errors.Wrapf(err, "failed to create '%s' temp file", scratchTempName)
|
||||
return nil, fmt.Errorf("failed to create '%s' temp file: %w", scratchTempName, err)
|
||||
}
|
||||
if err := os.Rename(scratchTempPath, scratchFinalPath); err != nil {
|
||||
os.Remove(scratchTempPath)
|
||||
return nil, errors.Wrapf(err, "failed to rename '%s' temp file to 'scratch.vhdx'", scratchTempName)
|
||||
return nil, fmt.Errorf("failed to rename '%s' temp file to 'scratch.vhdx': %w", scratchTempName, err)
|
||||
}
|
||||
scratchSource, err = os.OpenFile(scratchFinalPath, os.O_RDONLY, 0700)
|
||||
if err != nil {
|
||||
os.Remove(scratchFinalPath)
|
||||
return nil, errors.Wrap(err, "failed to open scratch.vhdx for read after creation")
|
||||
return nil, fmt.Errorf("failed to open scratch.vhdx for read after creation: %w", err)
|
||||
}
|
||||
} else {
|
||||
log.G(ctx).Debugf("scratch vhd %s was already present. Retrieved from cache", vhdFileName)
|
||||
|
||||
@@ -18,6 +18,7 @@ package native
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -27,7 +28,6 @@ import (
|
||||
"github.com/containerd/containerd/snapshots/storage"
|
||||
|
||||
"github.com/containerd/continuity/fs"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type snapshotter struct {
|
||||
@@ -137,7 +137,7 @@ func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
|
||||
s, err := storage.GetSnapshot(ctx, key)
|
||||
t.Rollback()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get snapshot mount")
|
||||
return nil, fmt.Errorf("failed to get snapshot mount: %w", err)
|
||||
}
|
||||
return o.mounts(s), nil
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
|
||||
if rerr := t.Rollback(); rerr != nil {
|
||||
log.G(ctx).WithError(rerr).Warn("failed to rollback transaction")
|
||||
}
|
||||
return errors.Wrap(err, "failed to commit snapshot")
|
||||
return fmt.Errorf("failed to commit snapshot: %w", err)
|
||||
}
|
||||
return t.Commit()
|
||||
}
|
||||
@@ -184,14 +184,14 @@ func (o *snapshotter) Remove(ctx context.Context, key string) (err error) {
|
||||
|
||||
id, _, err := storage.Remove(ctx, key)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to remove")
|
||||
return fmt.Errorf("failed to remove: %w", err)
|
||||
}
|
||||
|
||||
path := o.getSnapshotDir(id)
|
||||
renamed := filepath.Join(o.root, "snapshots", "rm-"+id)
|
||||
if err := os.Rename(path, renamed); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return errors.Wrap(err, "failed to rename")
|
||||
return fmt.Errorf("failed to rename: %w", err)
|
||||
}
|
||||
renamed = ""
|
||||
}
|
||||
@@ -205,7 +205,7 @@ func (o *snapshotter) Remove(ctx context.Context, key string) (err error) {
|
||||
log.G(ctx).WithError(err1).WithField("path", renamed).Error("failed to rename after failed commit")
|
||||
}
|
||||
}
|
||||
return errors.Wrap(err, "failed to commit")
|
||||
return fmt.Errorf("failed to commit: %w", err)
|
||||
}
|
||||
if renamed != "" {
|
||||
if err := os.RemoveAll(renamed); err != nil {
|
||||
@@ -235,21 +235,21 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
if kind == snapshots.KindActive || parent == "" {
|
||||
td, err = os.MkdirTemp(filepath.Join(o.root, "snapshots"), "new-")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create temp dir")
|
||||
return nil, fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
if err := os.Chmod(td, 0755); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to chmod %s to 0755", td)
|
||||
return nil, fmt.Errorf("failed to chmod %s to 0755: %w", td, err)
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if td != "" {
|
||||
if err1 := os.RemoveAll(td); err1 != nil {
|
||||
err = errors.Wrapf(err, "remove failed: %v", err1)
|
||||
err = fmt.Errorf("remove failed: %v: %w", err1, err)
|
||||
}
|
||||
}
|
||||
if path != "" {
|
||||
if err1 := os.RemoveAll(path); err1 != nil {
|
||||
err = errors.Wrapf(err, "failed to remove path: %v", err1)
|
||||
err = fmt.Errorf("failed to remove path: %v: %w", err1, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,7 +266,7 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
if rerr := t.Rollback(); rerr != nil {
|
||||
log.G(ctx).WithError(rerr).Warn("failed to rollback transaction")
|
||||
}
|
||||
return nil, errors.Wrap(err, "failed to create snapshot")
|
||||
return nil, fmt.Errorf("failed to create snapshot: %w", err)
|
||||
}
|
||||
|
||||
if td != "" {
|
||||
@@ -281,7 +281,7 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
fs.WithXAttrErrorHandler(xattrErrorHandler),
|
||||
}
|
||||
if err := fs.CopyDir(td, parent, copyDirOpts...); err != nil {
|
||||
return nil, errors.Wrap(err, "copying of parent failed")
|
||||
return nil, fmt.Errorf("copying of parent failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,13 +290,13 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
if rerr := t.Rollback(); rerr != nil {
|
||||
log.G(ctx).WithError(rerr).Warn("failed to rollback transaction")
|
||||
}
|
||||
return nil, errors.Wrap(err, "failed to rename")
|
||||
return nil, fmt.Errorf("failed to rename: %w", err)
|
||||
}
|
||||
td = ""
|
||||
}
|
||||
|
||||
if err := t.Commit(); err != nil {
|
||||
return nil, errors.Wrap(err, "commit failed")
|
||||
return nil, fmt.Errorf("commit failed: %w", err)
|
||||
}
|
||||
|
||||
return o.mounts(s), nil
|
||||
|
||||
@@ -33,7 +33,6 @@ import (
|
||||
"github.com/containerd/containerd/snapshots/overlay/overlayutils"
|
||||
"github.com/containerd/containerd/snapshots/storage"
|
||||
"github.com/containerd/continuity/fs"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -231,7 +230,7 @@ func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
|
||||
s, err := storage.GetSnapshot(ctx, key)
|
||||
t.Rollback()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get active mount")
|
||||
return nil, fmt.Errorf("failed to get active mount: %w", err)
|
||||
}
|
||||
return o.mounts(s), nil
|
||||
}
|
||||
@@ -262,7 +261,7 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
|
||||
}
|
||||
|
||||
if _, err = storage.CommitActive(ctx, key, name, snapshots.Usage(usage), opts...); err != nil {
|
||||
return errors.Wrap(err, "failed to commit snapshot")
|
||||
return fmt.Errorf("failed to commit snapshot: %w", err)
|
||||
}
|
||||
return t.Commit()
|
||||
}
|
||||
@@ -285,14 +284,14 @@ func (o *snapshotter) Remove(ctx context.Context, key string) (err error) {
|
||||
|
||||
_, _, err = storage.Remove(ctx, key)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to remove")
|
||||
return fmt.Errorf("failed to remove: %w", err)
|
||||
}
|
||||
|
||||
if !o.asyncRemove {
|
||||
var removals []string
|
||||
removals, err = o.getCleanupDirectories(ctx, t)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to get directories for removal")
|
||||
return fmt.Errorf("unable to get directories for removal: %w", err)
|
||||
}
|
||||
|
||||
// Remove directories after the transaction is closed, failures must not
|
||||
@@ -411,7 +410,7 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
if path != "" {
|
||||
if err1 := os.RemoveAll(path); err1 != nil {
|
||||
log.G(ctx).WithError(err1).WithField("path", path).Error("failed to reclaim snapshot directory, directory may need removal")
|
||||
err = errors.Wrapf(err, "failed to remove path: %v", err1)
|
||||
err = fmt.Errorf("failed to remove path: %v: %w", err1, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -423,7 +422,7 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
if rerr := t.Rollback(); rerr != nil {
|
||||
log.G(ctx).WithError(rerr).Warn("failed to rollback transaction")
|
||||
}
|
||||
return nil, errors.Wrap(err, "failed to create prepare snapshot dir")
|
||||
return nil, fmt.Errorf("failed to create prepare snapshot dir: %w", err)
|
||||
}
|
||||
rollback := true
|
||||
defer func() {
|
||||
@@ -436,13 +435,13 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
|
||||
s, err := storage.CreateSnapshot(ctx, kind, key, parent, opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create snapshot")
|
||||
return nil, fmt.Errorf("failed to create snapshot: %w", err)
|
||||
}
|
||||
|
||||
if len(s.ParentIDs) > 0 {
|
||||
st, err := os.Stat(o.upperPath(s.ParentIDs[0]))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to stat parent")
|
||||
return nil, fmt.Errorf("failed to stat parent: %w", err)
|
||||
}
|
||||
|
||||
stat := st.Sys().(*syscall.Stat_t)
|
||||
@@ -451,19 +450,19 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
if rerr := t.Rollback(); rerr != nil {
|
||||
log.G(ctx).WithError(rerr).Warn("failed to rollback transaction")
|
||||
}
|
||||
return nil, errors.Wrap(err, "failed to chown")
|
||||
return nil, fmt.Errorf("failed to chown: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
path = filepath.Join(snapshotDir, s.ID)
|
||||
if err = os.Rename(td, path); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to rename")
|
||||
return nil, fmt.Errorf("failed to rename: %w", err)
|
||||
}
|
||||
td = ""
|
||||
|
||||
rollback = false
|
||||
if err = t.Commit(); err != nil {
|
||||
return nil, errors.Wrap(err, "commit failed")
|
||||
return nil, fmt.Errorf("commit failed: %w", err)
|
||||
}
|
||||
|
||||
return o.mounts(s), nil
|
||||
@@ -472,7 +471,7 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
func (o *snapshotter) prepareDirectory(ctx context.Context, snapshotDir string, kind snapshots.Kind) (string, error) {
|
||||
td, err := os.MkdirTemp(snapshotDir, "new-")
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to create temp dir")
|
||||
return "", fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
|
||||
if err := os.Mkdir(filepath.Join(td, "fs"), 0755); err != nil {
|
||||
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/pkg/userns"
|
||||
"github.com/containerd/continuity/fs"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// SupportsMultipleLowerDir checks if the system supports multiple lowerdirs,
|
||||
@@ -63,7 +62,7 @@ func SupportsMultipleLowerDir(d string) error {
|
||||
}
|
||||
dest := filepath.Join(td, "merged")
|
||||
if err := m.Mount(dest); err != nil {
|
||||
return errors.Wrap(err, "failed to mount overlay")
|
||||
return fmt.Errorf("failed to mount overlay: %w", err)
|
||||
}
|
||||
if err := mount.UnmountAll(dest, 0); err != nil {
|
||||
log.L.WithError(err).Warnf("Failed to unmount check directory %v", dest)
|
||||
|
||||
@@ -19,6 +19,7 @@ package storage
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -27,7 +28,6 @@ import (
|
||||
"github.com/containerd/containerd/filters"
|
||||
"github.com/containerd/containerd/metadata/boltutil"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/pkg/errors"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
@@ -100,7 +100,7 @@ func UpdateInfo(ctx context.Context, info snapshots.Info, fieldpaths ...string)
|
||||
err := withBucket(ctx, func(ctx context.Context, bkt, pbkt *bolt.Bucket) error {
|
||||
sbkt := bkt.Bucket([]byte(info.Name))
|
||||
if sbkt == nil {
|
||||
return errors.Wrap(errdefs.ErrNotFound, "snapshot does not exist")
|
||||
return fmt.Errorf("snapshot does not exist: %w", errdefs.ErrNotFound)
|
||||
}
|
||||
if err := readSnapshot(sbkt, nil, &updated); err != nil {
|
||||
return err
|
||||
@@ -122,7 +122,7 @@ func UpdateInfo(ctx context.Context, info snapshots.Info, fieldpaths ...string)
|
||||
case "labels":
|
||||
updated.Labels = info.Labels
|
||||
default:
|
||||
return errors.Wrapf(errdefs.ErrInvalidArgument, "cannot update %q field on snapshot %q", path, info.Name)
|
||||
return fmt.Errorf("cannot update %q field on snapshot %q: %w", path, info.Name, errdefs.ErrInvalidArgument)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -181,25 +181,25 @@ func GetSnapshot(ctx context.Context, key string) (s Snapshot, err error) {
|
||||
err = withBucket(ctx, func(ctx context.Context, bkt, pbkt *bolt.Bucket) error {
|
||||
sbkt := bkt.Bucket([]byte(key))
|
||||
if sbkt == nil {
|
||||
return errors.Wrap(errdefs.ErrNotFound, "snapshot does not exist")
|
||||
return fmt.Errorf("snapshot does not exist: %w", errdefs.ErrNotFound)
|
||||
}
|
||||
|
||||
s.ID = fmt.Sprintf("%d", readID(sbkt))
|
||||
s.Kind = readKind(sbkt)
|
||||
|
||||
if s.Kind != snapshots.KindActive && s.Kind != snapshots.KindView {
|
||||
return errors.Wrapf(errdefs.ErrFailedPrecondition, "requested snapshot %v not active or view", key)
|
||||
return fmt.Errorf("requested snapshot %v not active or view: %w", key, errdefs.ErrFailedPrecondition)
|
||||
}
|
||||
|
||||
if parentKey := sbkt.Get(bucketKeyParent); len(parentKey) > 0 {
|
||||
spbkt := bkt.Bucket(parentKey)
|
||||
if spbkt == nil {
|
||||
return errors.Wrap(errdefs.ErrNotFound, "parent does not exist")
|
||||
return fmt.Errorf("parent does not exist: %w", errdefs.ErrNotFound)
|
||||
}
|
||||
|
||||
s.ParentIDs, err = parents(bkt, spbkt, readID(spbkt))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get parent chain")
|
||||
return fmt.Errorf("failed to get parent chain: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -216,7 +216,7 @@ func CreateSnapshot(ctx context.Context, kind snapshots.Kind, key, parent string
|
||||
switch kind {
|
||||
case snapshots.KindActive, snapshots.KindView:
|
||||
default:
|
||||
return Snapshot{}, errors.Wrapf(errdefs.ErrInvalidArgument, "snapshot type %v invalid; only snapshots of type Active or View can be created", kind)
|
||||
return Snapshot{}, fmt.Errorf("snapshot type %v invalid; only snapshots of type Active or View can be created: %w", kind, errdefs.ErrInvalidArgument)
|
||||
}
|
||||
var base snapshots.Info
|
||||
for _, opt := range opts {
|
||||
@@ -232,24 +232,24 @@ func CreateSnapshot(ctx context.Context, kind snapshots.Kind, key, parent string
|
||||
if parent != "" {
|
||||
spbkt = bkt.Bucket([]byte(parent))
|
||||
if spbkt == nil {
|
||||
return errors.Wrapf(errdefs.ErrNotFound, "missing parent %q bucket", parent)
|
||||
return fmt.Errorf("missing parent %q bucket: %w", parent, errdefs.ErrNotFound)
|
||||
}
|
||||
|
||||
if readKind(spbkt) != snapshots.KindCommitted {
|
||||
return errors.Wrapf(errdefs.ErrInvalidArgument, "parent %q is not committed snapshot", parent)
|
||||
return fmt.Errorf("parent %q is not committed snapshot: %w", parent, errdefs.ErrInvalidArgument)
|
||||
}
|
||||
}
|
||||
sbkt, err := bkt.CreateBucket([]byte(key))
|
||||
if err != nil {
|
||||
if err == bolt.ErrBucketExists {
|
||||
err = errors.Wrapf(errdefs.ErrAlreadyExists, "snapshot %v", key)
|
||||
err = fmt.Errorf("snapshot %v: %w", key, errdefs.ErrAlreadyExists)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
id, err := bkt.NextSequence()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unable to get identifier for snapshot %q", key)
|
||||
return fmt.Errorf("unable to get identifier for snapshot %q: %w", key, err)
|
||||
}
|
||||
|
||||
t := time.Now().UTC()
|
||||
@@ -270,12 +270,12 @@ func CreateSnapshot(ctx context.Context, kind snapshots.Kind, key, parent string
|
||||
// Store a backlink from the key to the parent. Store the snapshot name
|
||||
// as the value to allow following the backlink to the snapshot value.
|
||||
if err := pbkt.Put(parentKey(pid, id), []byte(key)); err != nil {
|
||||
return errors.Wrapf(err, "failed to write parent link for snapshot %q", key)
|
||||
return fmt.Errorf("failed to write parent link for snapshot %q: %w", key, err)
|
||||
}
|
||||
|
||||
s.ParentIDs, err = parents(bkt, spbkt, pid)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to get parent chain for snapshot %q", key)
|
||||
return fmt.Errorf("failed to get parent chain for snapshot %q: %w", key, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,33 +302,33 @@ func Remove(ctx context.Context, key string) (string, snapshots.Kind, error) {
|
||||
if err := withBucket(ctx, func(ctx context.Context, bkt, pbkt *bolt.Bucket) error {
|
||||
sbkt := bkt.Bucket([]byte(key))
|
||||
if sbkt == nil {
|
||||
return errors.Wrapf(errdefs.ErrNotFound, "snapshot %v", key)
|
||||
return fmt.Errorf("snapshot %v: %w", key, errdefs.ErrNotFound)
|
||||
}
|
||||
|
||||
if err := readSnapshot(sbkt, &id, &si); err != nil {
|
||||
return errors.Wrapf(err, "failed to read snapshot %s", key)
|
||||
return fmt.Errorf("failed to read snapshot %s: %w", key, err)
|
||||
}
|
||||
|
||||
if pbkt != nil {
|
||||
k, _ := pbkt.Cursor().Seek(parentPrefixKey(id))
|
||||
if getParentPrefix(k) == id {
|
||||
return errors.Wrap(errdefs.ErrFailedPrecondition, "cannot remove snapshot with child")
|
||||
return fmt.Errorf("cannot remove snapshot with child: %w", errdefs.ErrFailedPrecondition)
|
||||
}
|
||||
|
||||
if si.Parent != "" {
|
||||
spbkt := bkt.Bucket([]byte(si.Parent))
|
||||
if spbkt == nil {
|
||||
return errors.Wrapf(errdefs.ErrNotFound, "snapshot %v", key)
|
||||
return fmt.Errorf("snapshot %v: %w", key, errdefs.ErrNotFound)
|
||||
}
|
||||
|
||||
if err := pbkt.Delete(parentKey(readID(spbkt), id)); err != nil {
|
||||
return errors.Wrap(err, "failed to delete parent link")
|
||||
return fmt.Errorf("failed to delete parent link: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := bkt.DeleteBucket([]byte(key)); err != nil {
|
||||
return errors.Wrap(err, "failed to delete snapshot")
|
||||
return fmt.Errorf("failed to delete snapshot: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -362,20 +362,20 @@ func CommitActive(ctx context.Context, key, name string, usage snapshots.Usage,
|
||||
if err == bolt.ErrBucketExists {
|
||||
err = errdefs.ErrAlreadyExists
|
||||
}
|
||||
return errors.Wrapf(err, "committed snapshot %v", name)
|
||||
return fmt.Errorf("committed snapshot %v: %w", name, err)
|
||||
}
|
||||
sbkt := bkt.Bucket([]byte(key))
|
||||
if sbkt == nil {
|
||||
return errors.Wrapf(errdefs.ErrNotFound, "failed to get active snapshot %q", key)
|
||||
return fmt.Errorf("failed to get active snapshot %q: %w", key, errdefs.ErrNotFound)
|
||||
}
|
||||
|
||||
var si snapshots.Info
|
||||
if err := readSnapshot(sbkt, &id, &si); err != nil {
|
||||
return errors.Wrapf(err, "failed to read active snapshot %q", key)
|
||||
return fmt.Errorf("failed to read active snapshot %q: %w", key, err)
|
||||
}
|
||||
|
||||
if si.Kind != snapshots.KindActive {
|
||||
return errors.Wrapf(errdefs.ErrFailedPrecondition, "snapshot %q is not active", key)
|
||||
return fmt.Errorf("snapshot %q is not active: %w", key, errdefs.ErrFailedPrecondition)
|
||||
}
|
||||
si.Kind = snapshots.KindCommitted
|
||||
si.Created = time.Now().UTC()
|
||||
@@ -391,18 +391,18 @@ func CommitActive(ctx context.Context, key, name string, usage snapshots.Usage,
|
||||
return err
|
||||
}
|
||||
if err := bkt.DeleteBucket([]byte(key)); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete active snapshot %q", key)
|
||||
return fmt.Errorf("failed to delete active snapshot %q: %w", key, err)
|
||||
}
|
||||
if si.Parent != "" {
|
||||
spbkt := bkt.Bucket([]byte(si.Parent))
|
||||
if spbkt == nil {
|
||||
return errors.Wrapf(errdefs.ErrNotFound, "missing parent %q of snapshot %q", si.Parent, key)
|
||||
return fmt.Errorf("missing parent %q of snapshot %q: %w", si.Parent, key, errdefs.ErrNotFound)
|
||||
}
|
||||
pid := readID(spbkt)
|
||||
|
||||
// Updates parent back link to use new key
|
||||
if err := pbkt.Put(parentKey(pid, id), []byte(name)); err != nil {
|
||||
return errors.Wrapf(err, "failed to update parent link %q from %q to %q", pid, key, name)
|
||||
return fmt.Errorf("failed to update parent link %q from %q to %q: %w", pid, key, name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,15 +441,15 @@ func withSnapshotBucket(ctx context.Context, key string, fn func(context.Context
|
||||
}
|
||||
vbkt := tx.Bucket(bucketKeyStorageVersion)
|
||||
if vbkt == nil {
|
||||
return errors.Wrap(errdefs.ErrNotFound, "bucket does not exist")
|
||||
return fmt.Errorf("bucket does not exist: %w", errdefs.ErrNotFound)
|
||||
}
|
||||
bkt := vbkt.Bucket(bucketKeySnapshot)
|
||||
if bkt == nil {
|
||||
return errors.Wrap(errdefs.ErrNotFound, "snapshots bucket does not exist")
|
||||
return fmt.Errorf("snapshots bucket does not exist: %w", errdefs.ErrNotFound)
|
||||
}
|
||||
bkt = bkt.Bucket([]byte(key))
|
||||
if bkt == nil {
|
||||
return errors.Wrap(errdefs.ErrNotFound, "snapshot does not exist")
|
||||
return fmt.Errorf("snapshot does not exist: %w", errdefs.ErrNotFound)
|
||||
}
|
||||
|
||||
return fn(ctx, bkt, vbkt.Bucket(bucketKeyParents))
|
||||
@@ -462,7 +462,7 @@ func withBucket(ctx context.Context, fn func(context.Context, *bolt.Bucket, *bol
|
||||
}
|
||||
bkt := tx.Bucket(bucketKeyStorageVersion)
|
||||
if bkt == nil {
|
||||
return errors.Wrap(errdefs.ErrNotFound, "bucket does not exist")
|
||||
return fmt.Errorf("bucket does not exist: %w", errdefs.ErrNotFound)
|
||||
}
|
||||
return fn(ctx, bkt.Bucket(bucketKeySnapshot), bkt.Bucket(bucketKeyParents))
|
||||
}
|
||||
@@ -475,15 +475,15 @@ func createBucketIfNotExists(ctx context.Context, fn func(context.Context, *bolt
|
||||
|
||||
bkt, err := tx.CreateBucketIfNotExists(bucketKeyStorageVersion)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create version bucket")
|
||||
return fmt.Errorf("failed to create version bucket: %w", err)
|
||||
}
|
||||
sbkt, err := bkt.CreateBucketIfNotExists(bucketKeySnapshot)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create snapshots bucket")
|
||||
return fmt.Errorf("failed to create snapshots bucket: %w", err)
|
||||
}
|
||||
pbkt, err := bkt.CreateBucketIfNotExists(bucketKeyParents)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create parents bucket")
|
||||
return fmt.Errorf("failed to create parents bucket: %w", err)
|
||||
}
|
||||
return fn(ctx, sbkt, pbkt)
|
||||
}
|
||||
@@ -498,7 +498,7 @@ func parents(bkt, pbkt *bolt.Bucket, parent uint64) (parents []string, err error
|
||||
}
|
||||
pbkt = bkt.Bucket(parentKey)
|
||||
if pbkt == nil {
|
||||
return nil, errors.Wrap(errdefs.ErrNotFound, "missing parent")
|
||||
return nil, fmt.Errorf("missing parent: %w", errdefs.ErrNotFound)
|
||||
}
|
||||
|
||||
parent = readID(pbkt)
|
||||
|
||||
@@ -23,10 +23,10 @@ package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/pkg/errors"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
@@ -88,7 +88,7 @@ func (ms *MetaStore) TransactionContext(ctx context.Context, writable bool) (con
|
||||
db, err := bolt.Open(ms.dbfile, 0600, nil)
|
||||
if err != nil {
|
||||
ms.dbL.Unlock()
|
||||
return ctx, nil, errors.Wrap(err, "failed to open database file")
|
||||
return ctx, nil, fmt.Errorf("failed to open database file: %w", err)
|
||||
}
|
||||
ms.db = db
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func (ms *MetaStore) TransactionContext(ctx context.Context, writable bool) (con
|
||||
|
||||
tx, err := ms.db.Begin(writable)
|
||||
if err != nil {
|
||||
return ctx, nil, errors.Wrap(err, "failed to start transaction")
|
||||
return ctx, nil, fmt.Errorf("failed to start transaction: %w", err)
|
||||
}
|
||||
|
||||
ctx = context.WithValue(ctx, transactionKey{}, tx)
|
||||
|
||||
@@ -18,6 +18,7 @@ package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -26,7 +27,6 @@ import (
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/pkg/errors"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
@@ -147,31 +147,31 @@ func inWriteTransaction(fn testFunc) testFunc {
|
||||
// - "active-5": readonly active with parent "committed-2"
|
||||
func basePopulate(ctx context.Context, ms *MetaStore) error {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "committed-tmp-1", ""); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
return fmt.Errorf("failed to create active: %w", err)
|
||||
}
|
||||
if _, err := CommitActive(ctx, "committed-tmp-1", "committed-1", snapshots.Usage{Size: 1}); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
return fmt.Errorf("failed to create active: %w", err)
|
||||
}
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "committed-tmp-2", "committed-1"); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
return fmt.Errorf("failed to create active: %w", err)
|
||||
}
|
||||
if _, err := CommitActive(ctx, "committed-tmp-2", "committed-2", snapshots.Usage{Size: 2}); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
return fmt.Errorf("failed to create active: %w", err)
|
||||
}
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "active-1", ""); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
return fmt.Errorf("failed to create active: %w", err)
|
||||
}
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "active-2", "committed-1"); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
return fmt.Errorf("failed to create active: %w", err)
|
||||
}
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "active-3", "committed-2"); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
return fmt.Errorf("failed to create active: %w", err)
|
||||
}
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindView, "view-1", ""); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
return fmt.Errorf("failed to create active: %w", err)
|
||||
}
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindView, "view-2", "committed-2"); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
return fmt.Errorf("failed to create active: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -286,10 +286,10 @@ func testGetSnapshot(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
snapshotMap := map[string]Snapshot{}
|
||||
populate := func(ctx context.Context, ms *MetaStore) error {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "committed-tmp-1", ""); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
return fmt.Errorf("failed to create active: %w", err)
|
||||
}
|
||||
if _, err := CommitActive(ctx, "committed-tmp-1", "committed-1", snapshots.Usage{}); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
return fmt.Errorf("failed to create active: %w", err)
|
||||
}
|
||||
|
||||
for _, opts := range []struct {
|
||||
@@ -318,7 +318,7 @@ func testGetSnapshot(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
} {
|
||||
active, err := CreateSnapshot(ctx, opts.Kind, opts.Name, opts.Parent)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
return fmt.Errorf("failed to create active: %w", err)
|
||||
}
|
||||
snapshotMap[opts.Name] = active
|
||||
}
|
||||
|
||||
@@ -25,22 +25,21 @@ import (
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/continuity/fs/fstest"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func applyToMounts(m []mount.Mount, work string, a fstest.Applier) (err error) {
|
||||
td, err := os.MkdirTemp(work, "prepare")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp dir")
|
||||
return fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(td)
|
||||
|
||||
if err := mount.All(m, td); err != nil {
|
||||
return errors.Wrap(err, "failed to mount")
|
||||
return fmt.Errorf("failed to mount: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
if err1 := mount.UnmountAll(td, umountflags); err == nil {
|
||||
err = errors.Wrap(err1, "failed to unmount")
|
||||
if err1 := mount.UnmountAll(td, umountflags); err1 != nil && err == nil {
|
||||
err = fmt.Errorf("failed to unmount: %w", err1)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -55,15 +54,15 @@ func createSnapshot(ctx context.Context, sn snapshots.Snapshotter, parent, work
|
||||
|
||||
m, err := sn.Prepare(ctx, prepare, parent, opt)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to prepare snapshot")
|
||||
return "", fmt.Errorf("failed to prepare snapshot: %w", err)
|
||||
}
|
||||
|
||||
if err := applyToMounts(m, work, a); err != nil {
|
||||
return "", errors.Wrap(err, "failed to apply")
|
||||
return "", fmt.Errorf("failed to apply: %w", err)
|
||||
}
|
||||
|
||||
if err := sn.Commit(ctx, n, prepare, opt); err != nil {
|
||||
return "", errors.Wrap(err, "failed to commit")
|
||||
return "", fmt.Errorf("failed to commit: %w", err)
|
||||
}
|
||||
|
||||
return n, nil
|
||||
@@ -72,36 +71,36 @@ func createSnapshot(ctx context.Context, sn snapshots.Snapshotter, parent, work
|
||||
func checkSnapshot(ctx context.Context, sn snapshots.Snapshotter, work, name, check string) (err error) {
|
||||
td, err := os.MkdirTemp(work, "check")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp dir")
|
||||
return fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
if err1 := os.RemoveAll(td); err == nil {
|
||||
err = errors.Wrapf(err1, "failed to remove temporary directory %s", td)
|
||||
if err1 := os.RemoveAll(td); err1 != nil && err == nil {
|
||||
err = fmt.Errorf("failed to remove temporary directory %s: %w", td, err1)
|
||||
}
|
||||
}()
|
||||
|
||||
view := fmt.Sprintf("%s-view", name)
|
||||
m, err := sn.View(ctx, view, name, opt)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create view")
|
||||
return fmt.Errorf("failed to create view: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
if err1 := sn.Remove(ctx, view); err == nil {
|
||||
err = errors.Wrap(err1, "failed to remove view")
|
||||
if err1 := sn.Remove(ctx, view); err1 != nil && err == nil {
|
||||
err = fmt.Errorf("failed to remove view: %w", err1)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := mount.All(m, td); err != nil {
|
||||
return errors.Wrap(err, "failed to mount")
|
||||
return fmt.Errorf("failed to mount: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
if err1 := mount.UnmountAll(td, umountflags); err == nil {
|
||||
err = errors.Wrap(err1, "failed to unmount view")
|
||||
if err1 := mount.UnmountAll(td, umountflags); err1 != nil && err == nil {
|
||||
err = fmt.Errorf("failed to unmount view: %w", err1)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := fstest.CheckDirectoryEqual(check, td); err != nil {
|
||||
return errors.Wrap(err, "check directory failed")
|
||||
return fmt.Errorf("check directory failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -113,7 +112,7 @@ func checkSnapshot(ctx context.Context, sn snapshots.Snapshotter, work, name, ch
|
||||
func checkSnapshots(ctx context.Context, sn snapshots.Snapshotter, work string, as ...fstest.Applier) error {
|
||||
td, err := os.MkdirTemp(work, "flat")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp dir")
|
||||
return fmt.Errorf("failed to create temp dir: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(td)
|
||||
|
||||
@@ -121,15 +120,15 @@ func checkSnapshots(ctx context.Context, sn snapshots.Snapshotter, work string,
|
||||
for i, a := range as {
|
||||
s, err := createSnapshot(ctx, sn, parentID, work, a)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to create snapshot %d", i+1)
|
||||
return fmt.Errorf("failed to create snapshot %d: %w", i+1, err)
|
||||
}
|
||||
|
||||
if err := a.Apply(td); err != nil {
|
||||
return errors.Wrapf(err, "failed to apply to check directory on %d", i+1)
|
||||
return fmt.Errorf("failed to apply to check directory on %d: %w", i+1, err)
|
||||
}
|
||||
|
||||
if err := checkSnapshot(ctx, sn, work, s, td); err != nil {
|
||||
return errors.Wrapf(err, "snapshot check failed on snapshot %d", i+1)
|
||||
return fmt.Errorf("snapshot check failed on snapshot %d: %w", i+1, err)
|
||||
}
|
||||
|
||||
parentID = s
|
||||
@@ -141,28 +140,28 @@ func checkSnapshots(ctx context.Context, sn snapshots.Snapshotter, work string,
|
||||
// checkInfo checks that the infos are the same
|
||||
func checkInfo(si1, si2 snapshots.Info) error {
|
||||
if si1.Kind != si2.Kind {
|
||||
return errors.Errorf("Expected kind %v, got %v", si1.Kind, si2.Kind)
|
||||
return fmt.Errorf("Expected kind %v, got %v", si1.Kind, si2.Kind)
|
||||
}
|
||||
if si1.Name != si2.Name {
|
||||
return errors.Errorf("Expected name %v, got %v", si1.Name, si2.Name)
|
||||
return fmt.Errorf("Expected name %v, got %v", si1.Name, si2.Name)
|
||||
}
|
||||
if si1.Parent != si2.Parent {
|
||||
return errors.Errorf("Expected Parent %v, got %v", si1.Parent, si2.Parent)
|
||||
return fmt.Errorf("Expected Parent %v, got %v", si1.Parent, si2.Parent)
|
||||
}
|
||||
if len(si1.Labels) != len(si2.Labels) {
|
||||
return errors.Errorf("Expected %d labels, got %d", len(si1.Labels), len(si2.Labels))
|
||||
return fmt.Errorf("Expected %d labels, got %d", len(si1.Labels), len(si2.Labels))
|
||||
}
|
||||
for k, l1 := range si1.Labels {
|
||||
l2 := si2.Labels[k]
|
||||
if l1 != l2 {
|
||||
return errors.Errorf("Expected label %v, got %v", l1, l2)
|
||||
return fmt.Errorf("Expected label %v, got %v", l1, l2)
|
||||
}
|
||||
}
|
||||
if si1.Created != si2.Created {
|
||||
return errors.Errorf("Expected Created %v, got %v", si1.Created, si2.Created)
|
||||
return fmt.Errorf("Expected Created %v, got %v", si1.Created, si2.Created)
|
||||
}
|
||||
if si1.Updated != si2.Updated {
|
||||
return errors.Errorf("Expected Updated %v, got %v", si1.Updated, si2.Updated)
|
||||
return fmt.Errorf("Expected Updated %v, got %v", si1.Updated, si2.Updated)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -22,6 +22,7 @@ package windows
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -43,7 +44,6 @@ import (
|
||||
"github.com/containerd/containerd/snapshots/storage"
|
||||
"github.com/containerd/continuity/fs"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -77,7 +77,7 @@ func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
|
||||
return nil, err
|
||||
}
|
||||
if strings.ToLower(fsType) != "ntfs" {
|
||||
return nil, errors.Wrapf(errdefs.ErrInvalidArgument, "%s is not on an NTFS volume - only NTFS volumes are supported", root)
|
||||
return nil, fmt.Errorf("%s is not on an NTFS volume - only NTFS volumes are supported: %w", root, errdefs.ErrInvalidArgument)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(root, 0700); err != nil {
|
||||
@@ -182,7 +182,7 @@ func (s *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
|
||||
|
||||
snapshot, err := storage.GetSnapshot(ctx, key)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get snapshot mount")
|
||||
return nil, fmt.Errorf("failed to get snapshot mount: %w", err)
|
||||
}
|
||||
return s.mounts(snapshot), nil
|
||||
}
|
||||
@@ -204,7 +204,7 @@ func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
|
||||
// grab the existing id
|
||||
id, _, _, err := storage.GetInfo(ctx, key)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to get storage info for %s", key)
|
||||
return fmt.Errorf("failed to get storage info for %s: %w", key, err)
|
||||
}
|
||||
|
||||
snapshot, err := storage.GetSnapshot(ctx, key)
|
||||
@@ -224,11 +224,11 @@ func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
|
||||
|
||||
usage, err := fs.DiskUsage(ctx, path)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to collect disk usage of snapshot storage: %s", path)
|
||||
return fmt.Errorf("failed to collect disk usage of snapshot storage: %s: %w", path, err)
|
||||
}
|
||||
|
||||
if _, err := storage.CommitActive(ctx, key, name, snapshots.Usage(usage), opts...); err != nil {
|
||||
return errors.Wrap(err, "failed to commit snapshot")
|
||||
return fmt.Errorf("failed to commit snapshot: %w", err)
|
||||
}
|
||||
return t.Commit()
|
||||
}
|
||||
@@ -244,7 +244,7 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
|
||||
|
||||
id, _, err := storage.Remove(ctx, key)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to remove")
|
||||
return fmt.Errorf("failed to remove: %w", err)
|
||||
}
|
||||
|
||||
path := s.getSnapshotDir(id)
|
||||
@@ -265,11 +265,11 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
|
||||
)
|
||||
|
||||
if deactivateErr := hcsshim.DeactivateLayer(di, layerID); deactivateErr != nil {
|
||||
return errors.Wrapf(err, "failed to deactivate layer following failed rename: %s", deactivateErr)
|
||||
return fmt.Errorf("failed to deactivate layer following failed rename: %s: %w", deactivateErr, err)
|
||||
}
|
||||
|
||||
if renameErr := os.Rename(path, renamed); renameErr != nil && !os.IsNotExist(renameErr) {
|
||||
return errors.Wrapf(err, "second rename attempt following detach failed: %s", renameErr)
|
||||
return fmt.Errorf("second rename attempt following detach failed: %s: %w", renameErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
|
||||
// May cause inconsistent data on disk
|
||||
log.G(ctx).WithError(err1).WithField("path", renamed).Error("Failed to rename after failed commit")
|
||||
}
|
||||
return errors.Wrap(err, "failed to commit")
|
||||
return fmt.Errorf("failed to commit: %w", err)
|
||||
}
|
||||
|
||||
if err := hcsshim.DestroyLayer(s.info, renamedID); err != nil {
|
||||
@@ -356,7 +356,7 @@ func (s *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
|
||||
newSnapshot, err := storage.CreateSnapshot(ctx, kind, key, parent, opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create snapshot")
|
||||
return nil, fmt.Errorf("failed to create snapshot: %w", err)
|
||||
}
|
||||
|
||||
if kind == snapshots.KindActive {
|
||||
@@ -385,7 +385,7 @@ func (s *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
if sizeGBstr, ok := snapshotInfo.Labels[rootfsSizeLabel]; ok {
|
||||
i32, err := strconv.ParseInt(sizeGBstr, 10, 32)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to parse label %q=%q", rootfsSizeLabel, sizeGBstr)
|
||||
return nil, fmt.Errorf("failed to parse label %q=%q: %w", rootfsSizeLabel, sizeGBstr, err)
|
||||
}
|
||||
sizeGB = int(i32)
|
||||
}
|
||||
@@ -398,17 +398,17 @@ func (s *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
|
||||
// This has to be run first to avoid clashing with the containers sandbox.vhdx.
|
||||
if makeUVMScratch {
|
||||
if err := s.createUVMScratchLayer(ctx, snDir, parentLayerPaths); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to make UVM's scratch layer")
|
||||
return nil, fmt.Errorf("failed to make UVM's scratch layer: %w", err)
|
||||
}
|
||||
}
|
||||
if err := s.createScratchLayer(ctx, snDir, parentLayerPaths, sizeGB); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create scratch layer")
|
||||
return nil, fmt.Errorf("failed to create scratch layer: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := t.Commit(); err != nil {
|
||||
return nil, errors.Wrap(err, "commit failed")
|
||||
return nil, fmt.Errorf("commit failed: %w", err)
|
||||
}
|
||||
|
||||
return s.mounts(newSnapshot), nil
|
||||
@@ -450,7 +450,7 @@ func (s *snapshotter) createScratchLayer(ctx context.Context, snDir string, pare
|
||||
if _, err := os.Stat(templateDiffDisk); os.IsNotExist(err) {
|
||||
// Scratch disk not present so lets make it.
|
||||
if err := computestorage.SetupContainerBaseLayer(ctx, baseLayer, templateBase, templateDiffDisk, 1); err != nil {
|
||||
return errors.Wrapf(err, "failed to create scratch vhdx at %q", baseLayer)
|
||||
return fmt.Errorf("failed to create scratch vhdx at %q: %w", baseLayer, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,7 +462,7 @@ func (s *snapshotter) createScratchLayer(ctx context.Context, snDir string, pare
|
||||
if expand {
|
||||
gbToByte := 1024 * 1024 * 1024
|
||||
if err := hcsshim.ExpandSandboxSize(s.info, filepath.Base(snDir), uint64(gbToByte*sizeGB)); err != nil {
|
||||
return errors.Wrapf(err, "failed to expand sandbox vhdx size to %d GB", sizeGB)
|
||||
return fmt.Errorf("failed to expand sandbox vhdx size to %d GB: %w", sizeGB, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -476,7 +476,7 @@ func (s *snapshotter) convertScratchToReadOnlyLayer(ctx context.Context, snapsho
|
||||
// temporary, leaving it enabled is OK for now.
|
||||
// https://github.com/containerd/containerd/issues/1681
|
||||
if err := winio.EnableProcessPrivileges([]string{winio.SeBackupPrivilege, winio.SeRestorePrivilege}); err != nil {
|
||||
return errors.Wrap(err, "failed to enable necessary privileges")
|
||||
return fmt.Errorf("failed to enable necessary privileges: %w", err)
|
||||
}
|
||||
|
||||
parentLayerPaths := s.parentIDsToParentPaths(snapshot.ParentIDs)
|
||||
@@ -488,11 +488,11 @@ func (s *snapshotter) convertScratchToReadOnlyLayer(ctx context.Context, snapsho
|
||||
}()
|
||||
|
||||
if _, err := ociwclayer.ImportLayerFromTar(ctx, reader, path, parentLayerPaths); err != nil {
|
||||
return errors.Wrap(err, "failed to reimport snapshot")
|
||||
return fmt.Errorf("failed to reimport snapshot: %w", err)
|
||||
}
|
||||
|
||||
if _, err := io.Copy(io.Discard, reader); err != nil {
|
||||
return errors.Wrap(err, "failed discarding extra data in import stream")
|
||||
return fmt.Errorf("failed discarding extra data in import stream: %w", err)
|
||||
}
|
||||
|
||||
// NOTE: We do not delete the sandbox.vhdx here, as that will break later calls to
|
||||
@@ -516,7 +516,7 @@ func (s *snapshotter) createUVMScratchLayer(ctx context.Context, snDir string, p
|
||||
// Make sure base layer has a UtilityVM folder.
|
||||
uvmPath := filepath.Join(baseLayer, "UtilityVM")
|
||||
if _, err := os.Stat(uvmPath); os.IsNotExist(err) {
|
||||
return errors.Wrapf(err, "failed to find UtilityVM directory in base layer %q", baseLayer)
|
||||
return fmt.Errorf("failed to find UtilityVM directory in base layer %q: %w", baseLayer, err)
|
||||
}
|
||||
|
||||
templateDiffDisk := filepath.Join(uvmPath, "SystemTemplate.vhdx")
|
||||
@@ -530,7 +530,7 @@ func (s *snapshotter) createUVMScratchLayer(ctx context.Context, snDir string, p
|
||||
// Move the sandbox.vhdx into a nested vm folder to avoid clashing with a containers sandbox.vhdx.
|
||||
vmScratchDir := filepath.Join(snDir, "vm")
|
||||
if err := os.MkdirAll(vmScratchDir, 0777); err != nil {
|
||||
return errors.Wrap(err, "failed to make `vm` directory for vm's scratch space")
|
||||
return fmt.Errorf("failed to make `vm` directory for vm's scratch space: %w", err)
|
||||
}
|
||||
|
||||
return copyScratchDisk(templateDiffDisk, filepath.Join(vmScratchDir, "sandbox.vhdx"))
|
||||
@@ -539,19 +539,19 @@ func (s *snapshotter) createUVMScratchLayer(ctx context.Context, snDir string, p
|
||||
func copyScratchDisk(source, dest string) error {
|
||||
scratchSource, err := os.OpenFile(source, os.O_RDWR, 0700)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to open %s", source)
|
||||
return fmt.Errorf("failed to open %s: %w", source, err)
|
||||
}
|
||||
defer scratchSource.Close()
|
||||
|
||||
f, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE, 0700)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create sandbox.vhdx in snapshot")
|
||||
return fmt.Errorf("failed to create sandbox.vhdx in snapshot: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if _, err := io.Copy(f, scratchSource); err != nil {
|
||||
os.Remove(dest)
|
||||
return errors.Wrapf(err, "failed to copy cached %q to %q in snapshot", source, dest)
|
||||
return fmt.Errorf("failed to copy cached %q to %q in snapshot: %w", source, dest, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user