Skip to content

Commit

Permalink
snapshot: fix error on proxy driver when switching different snapshotter
Browse files Browse the repository at this point in the history
Fixes: #592

Signed-off-by: ChengyuZhu6 <chengyu.zhu@intel.com>
  • Loading branch information
ChengyuZhu6 committed Apr 28, 2024
1 parent ce4848e commit c1fbf56
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ func (o *snapshotter) Cleanup(ctx context.Context) error {
}

func (o *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error) {
log.L.Debugf("[Stat] snapshots")
_, info, _, err := snapshot.GetSnapshotInfo(ctx, o.ms, key)
if checkErr := o.checkLabelsWithDriver(info.Labels); checkErr != nil {
return snapshots.Info{}, errors.New("not found")
}
return info, err
}

Expand Down Expand Up @@ -1011,3 +1015,12 @@ func (o *snapshotter) snapshotRoot() string {
func (o *snapshotter) snapshotDir(id string) string {
return filepath.Join(o.snapshotRoot(), id)
}

func (o *snapshotter) checkLabelsWithDriver(labels map[string]string) error {
isProxyDriver := config.GetFsDriver() == config.FsDriverProxy
isProxyLabel := label.IsNydusProxyMode(labels)
if (isProxyDriver && !isProxyLabel) || (!isProxyDriver && isProxyLabel) {
return errors.Errorf("check Labels With Driver failed, driver = %q, labels = %q", config.GetFsDriver(), labels)
}
return nil
}

0 comments on commit c1fbf56

Please sign in to comment.