Support disk usage in windows-lcow snapshot

Windows snapshot usage was completed in ref: #3785 but lcow didnt get updated.

Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
This commit is contained in:
Justin Terry (VM) 2020-01-08 13:43:48 -08:00
parent d3c1691ae1
commit cd1cad9d55

View File

@ -98,7 +98,6 @@ func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
// Should be used for parent resolution, existence checks and to discern // Should be used for parent resolution, existence checks and to discern
// the kind of snapshot. // the kind of snapshot.
func (s *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error) { func (s *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error) {
log.G(ctx).Debug("Starting Stat")
ctx, t, err := s.ms.TransactionContext(ctx, false) ctx, t, err := s.ms.TransactionContext(ctx, false)
if err != nil { if err != nil {
return snapshots.Info{}, err return snapshots.Info{}, err
@ -110,7 +109,6 @@ func (s *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, err
} }
func (s *snapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error) { func (s *snapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error) {
log.G(ctx).Debug("Starting Update")
ctx, t, err := s.ms.TransactionContext(ctx, true) ctx, t, err := s.ms.TransactionContext(ctx, true)
if err != nil { if err != nil {
return snapshots.Info{}, err return snapshots.Info{}, err
@ -130,21 +128,21 @@ func (s *snapshotter) Update(ctx context.Context, info snapshots.Info, fieldpath
} }
func (s *snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) { func (s *snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) {
log.G(ctx).Debug("Starting Usage")
ctx, t, err := s.ms.TransactionContext(ctx, false) ctx, t, err := s.ms.TransactionContext(ctx, false)
if err != nil { if err != nil {
return snapshots.Usage{}, err return snapshots.Usage{}, err
} }
defer t.Rollback() id, info, usage, err := storage.GetInfo(ctx, key)
t.Rollback() // transaction no longer needed at this point.
_, info, usage, err := storage.GetInfo(ctx, key)
if err != nil { if err != nil {
return snapshots.Usage{}, err return snapshots.Usage{}, err
} }
if info.Kind == snapshots.KindActive { if info.Kind == snapshots.KindActive {
du := fs.Usage{ du, err := fs.DiskUsage(ctx, s.getSnapshotDir(id))
Size: 0, if err != nil {
return snapshots.Usage{}, err
} }
usage = snapshots.Usage(du) usage = snapshots.Usage(du)
} }
@ -153,12 +151,10 @@ func (s *snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, e
} }
func (s *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) { func (s *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
log.G(ctx).Debug("Starting Prepare")
return s.createSnapshot(ctx, snapshots.KindActive, key, parent, opts) return s.createSnapshot(ctx, snapshots.KindActive, key, parent, opts)
} }
func (s *snapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) { func (s *snapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
log.G(ctx).Debug("Starting View")
return s.createSnapshot(ctx, snapshots.KindView, key, parent, opts) return s.createSnapshot(ctx, snapshots.KindView, key, parent, opts)
} }
@ -167,7 +163,6 @@ func (s *snapshotter) View(ctx context.Context, key, parent string, opts ...snap
// //
// This can be used to recover mounts after calling View or Prepare. // This can be used to recover mounts after calling View or Prepare.
func (s *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) { func (s *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) {
log.G(ctx).Debug("Starting Mounts")
ctx, t, err := s.ms.TransactionContext(ctx, false) ctx, t, err := s.ms.TransactionContext(ctx, false)
if err != nil { if err != nil {
return nil, err return nil, err
@ -182,31 +177,39 @@ func (s *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
} }
func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error { func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error {
log.G(ctx).Debug("Starting Commit")
ctx, t, err := s.ms.TransactionContext(ctx, true) ctx, t, err := s.ms.TransactionContext(ctx, true)
if err != nil { if err != nil {
return err return err
} }
defer t.Rollback() defer func() {
if err != nil {
if rerr := t.Rollback(); rerr != nil {
log.G(ctx).WithError(rerr).Warn("failed to rollback transaction")
}
}
}()
usage := fs.Usage{ // grab the existing id
Size: 0, id, _, _, err := storage.GetInfo(ctx, key)
if err != nil {
return err
}
usage, err := fs.DiskUsage(ctx, s.getSnapshotDir(id))
if err != nil {
return err
} }
if _, err = storage.CommitActive(ctx, key, name, snapshots.Usage(usage), opts...); err != nil { if _, err = storage.CommitActive(ctx, key, name, snapshots.Usage(usage), opts...); err != nil {
return errors.Wrap(err, "failed to commit snapshot") return errors.Wrap(err, "failed to commit snapshot")
} }
if err := t.Commit(); err != nil { return t.Commit()
return err
}
return nil
} }
// Remove abandons the transaction identified by key. All resources // Remove abandons the transaction identified by key. All resources
// associated with the key will be removed. // associated with the key will be removed.
func (s *snapshotter) Remove(ctx context.Context, key string) error { func (s *snapshotter) Remove(ctx context.Context, key string) error {
log.G(ctx).Debug("Starting Remove")
ctx, t, err := s.ms.TransactionContext(ctx, true) ctx, t, err := s.ms.TransactionContext(ctx, true)
if err != nil { if err != nil {
return err return err
@ -242,7 +245,6 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
// Walk the committed snapshots. // Walk the committed snapshots.
func (s *snapshotter) Walk(ctx context.Context, fn snapshots.WalkFunc, fs ...string) error { func (s *snapshotter) Walk(ctx context.Context, fn snapshots.WalkFunc, fs ...string) error {
log.G(ctx).Debug("Starting Walk")
ctx, t, err := s.ms.TransactionContext(ctx, false) ctx, t, err := s.ms.TransactionContext(ctx, false)
if err != nil { if err != nil {
return err return err