go.mod: github.com/containerd/zfs v0.0.0-20210322090317-0e92c2247fb7

Contains "Implements zfs usage by returning the USED field from the zfs snapshot"
(https://github.com/containerd/zfs/pull/38)

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda
2021-03-22 15:44:55 +09:00
parent 56f17a0856
commit 8cdc1f13b6
5 changed files with 45 additions and 7 deletions

View File

@@ -23,7 +23,6 @@ import (
"github.com/pkg/errors"
)
// Config represents configuration for the zfs plugin
type Config struct {
// Root directory for the plugin

View File

@@ -20,6 +20,7 @@ package zfs
import (
"context"
"math"
"path/filepath"
"github.com/containerd/containerd/log"
@@ -116,7 +117,40 @@ func (z *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, err
// Usage retrieves the disk usage of the top-level snapshot.
func (z *snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) {
return snapshots.Usage{}, errors.New("zfs does not implement Usage() yet")
return z.usage(ctx, key)
}
func (z *snapshotter) usage(ctx context.Context, key string) (snapshots.Usage, error) {
ctx, t, err := z.ms.TransactionContext(ctx, false)
if err != nil {
return snapshots.Usage{}, err
}
id, info, usage, err := storage.GetInfo(ctx, key)
t.Rollback() //nolint:errcheck
if err != nil {
return snapshots.Usage{}, err
}
if info.Kind == snapshots.KindActive {
activeName := filepath.Join(z.dataset.Name, id)
sDataset, err := zfs.GetDataset(activeName)
if err != nil {
return snapshots.Usage{}, err
}
if sDataset.Used > math.MaxInt64 {
return snapshots.Usage{}, errors.Errorf("Dataset size exceeds maximum snapshot size of %v bytes", math.MaxInt64)
}
usage = snapshots.Usage{
Size: int64(sDataset.Used),
Inodes: -1,
}
}
return usage, nil
}
// Walk the committed snapshots.
@@ -201,6 +235,11 @@ func (z *snapshotter) mounts(dataset *zfs.Dataset, readonly bool) ([]mount.Mount
}
func (z *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) (err error) {
usage, err := z.usage(ctx, key)
if err != nil {
return errors.Wrap(err, "failed to compute usage")
}
ctx, t, err := z.ms.TransactionContext(ctx, true)
if err != nil {
return err
@@ -213,7 +252,7 @@ func (z *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
}
}()
id, err := storage.CommitActive(ctx, key, name, snapshots.Usage{}, opts...)
id, err := storage.CommitActive(ctx, key, name, usage, opts...)
if err != nil {
return errors.Wrap(err, "failed to commit")
}

2
vendor/modules.txt vendored
View File

@@ -105,7 +105,7 @@ github.com/containerd/ttrpc/plugin
# github.com/containerd/typeurl v1.0.1
## explicit
github.com/containerd/typeurl
# github.com/containerd/zfs v0.0.0-20210315114300-dde8f0fda960
# github.com/containerd/zfs v0.0.0-20210322090317-0e92c2247fb7
## explicit
github.com/containerd/zfs
github.com/containerd/zfs/plugin