From c1fbf56b7e53a39d8148533fa61cc8a2f9562b96 Mon Sep 17 00:00:00 2001 From: ChengyuZhu6 Date: Sun, 28 Apr 2024 15:41:23 +0800 Subject: [PATCH] snapshot: fix error on proxy driver when switching different snapshotter Fixes: #592 Signed-off-by: ChengyuZhu6 --- snapshot/snapshot.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/snapshot/snapshot.go b/snapshot/snapshot.go index f829d3132c..0648d00318 100644 --- a/snapshot/snapshot.go +++ b/snapshot/snapshot.go @@ -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 } @@ -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 +}