@@ -11,7 +11,25 @@ import (
1111	"github.com/opencontainers/image-spec/identity" 
1212)
1313
14- const  defaultSnapshotterName  =  "overlayfs" 
14+ const  (
15+ 	defaultSnapshotterName  =  "overlayfs" 
16+ 	// SnapshotterKey is set as a key in context 
17+ 	SnapshotterKey  =  "snapshotter" 
18+ )
19+ 
20+ var  (
21+ 	currentSnapshotterName  =  defaultSnapshotterName 
22+ )
23+ 
24+ // SetSnapshotterName sets current snapshotter driver, it should be called only when daemon starts 
25+ func  SetSnapshotterName (name  string ) {
26+ 	currentSnapshotterName  =  name 
27+ }
28+ 
29+ // CurrentSnapshotterName returns current snapshotter driver 
30+ func  CurrentSnapshotterName () string  {
31+ 	return  currentSnapshotterName 
32+ }
1533
1634// CreateSnapshot creates a active snapshot with image's name and id. 
1735func  (c  * Client ) CreateSnapshot (ctx  context.Context , id , ref  string ) error  {
@@ -32,7 +50,7 @@ func (c *Client) CreateSnapshot(ctx context.Context, id, ref string) error {
3250	}
3351
3452	parent  :=  identity .ChainID (diffIDs ).String ()
35- 	_ , err  =  wrapperCli .client .SnapshotService (defaultSnapshotterName ).Prepare (ctx , id , parent )
53+ 	_ , err  =  wrapperCli .client .SnapshotService (CurrentSnapshotterName () ).Prepare (ctx , id , parent )
3654	return  err 
3755}
3856
@@ -43,7 +61,7 @@ func (c *Client) GetSnapshot(ctx context.Context, id string) (snapshots.Info, er
4361		return  snapshots.Info {}, fmt .Errorf ("failed to get a containerd grpc client: %v" , err )
4462	}
4563
46- 	service  :=  wrapperCli .client .SnapshotService (defaultSnapshotterName )
64+ 	service  :=  wrapperCli .client .SnapshotService (CurrentSnapshotterName () )
4765	defer  service .Close ()
4866
4967	return  service .Stat (ctx , id )
@@ -56,7 +74,7 @@ func (c *Client) RemoveSnapshot(ctx context.Context, id string) error {
5674		return  fmt .Errorf ("failed to get a containerd grpc client: %v" , err )
5775	}
5876
59- 	service  :=  wrapperCli .client .SnapshotService (defaultSnapshotterName )
77+ 	service  :=  wrapperCli .client .SnapshotService (CurrentSnapshotterName () )
6078	defer  service .Close ()
6179
6280	return  service .Remove (ctx , id )
@@ -70,7 +88,7 @@ func (c *Client) GetMounts(ctx context.Context, id string) ([]mount.Mount, error
7088		return  nil , fmt .Errorf ("failed to get a containerd grpc client: %v" , err )
7189	}
7290
73- 	service  :=  wrapperCli .client .SnapshotService (defaultSnapshotterName )
91+ 	service  :=  wrapperCli .client .SnapshotService (CurrentSnapshotterName () )
7492	defer  service .Close ()
7593
7694	return  service .Mounts (ctx , id )
@@ -84,7 +102,7 @@ func (c *Client) GetSnapshotUsage(ctx context.Context, id string) (snapshots.Usa
84102		return  snapshots.Usage {}, fmt .Errorf ("failed to get a containerd grpc client: %v" , err )
85103	}
86104
87- 	service  :=  wrapperCli .client .SnapshotService (defaultSnapshotterName )
105+ 	service  :=  wrapperCli .client .SnapshotService (CurrentSnapshotterName () )
88106	defer  service .Close ()
89107
90108	return  service .Usage (ctx , id )
@@ -97,7 +115,13 @@ func (c *Client) WalkSnapshot(ctx context.Context, fn func(context.Context, snap
97115		return  fmt .Errorf ("failed to get a containerd grpc client: %v" , err )
98116	}
99117
100- 	service  :=  wrapperCli .client .SnapshotService (defaultSnapshotterName )
118+ 	// Allow user to walk snapshots of specific snapshotter 
119+ 	snapshotter  :=  CurrentSnapshotterName ()
120+ 	if  sn , ok  :=  ctx .Value (SnapshotterKey ).(string ); ok  {
121+ 		snapshotter  =  sn 
122+ 	}
123+ 
124+ 	service  :=  wrapperCli .client .SnapshotService (snapshotter )
101125	defer  service .Close ()
102126
103127	return  service .Walk (ctx , fn )
0 commit comments