@@ -27,8 +27,6 @@ import (
27
27
mountutil "github.com/firecracker-microvm/firecracker-containerd/snapshotter/internal/mount"
28
28
)
29
29
30
- const proxiedFunctionCallErrorString = "Proxied function call failed"
31
-
32
30
// Snapshotter routes snapshotter requests to their destined
33
31
// remote snapshotter via their snapshotter namespace.
34
32
//
@@ -46,234 +44,179 @@ func NewSnapshotter(cache cache.Cache, fetchSnapshotter cache.SnapshotterProvide
46
44
47
45
// Stat proxies remote snapshotter stat request.
48
46
//
49
- // See https://github.com/containerd/containerd/blob/main /snapshots/snapshotter.go
47
+ // See https://github.com/containerd/containerd/blob/v1.6.4 /snapshots/snapshotter.go
50
48
func (s * Snapshotter ) Stat (ctx context.Context , key string ) (snapshots.Info , error ) {
51
49
contextLogger := log .G (ctx ).WithField ("function" , "Stat" )
52
- namespace , err := getNamespaceFromContext (ctx , contextLogger )
53
- if err != nil {
54
- return snapshots.Info {}, err
55
- }
56
- logger := contextLogger .WithField ("namespace" , namespace )
57
50
58
- snapshotter , err := s .getSnapshotterFromCache (ctx , namespace , logger )
51
+ snapshotter , err := s .getSnapshotterFromCache (ctx , contextLogger )
59
52
if err != nil {
60
53
return snapshots.Info {}, err
61
54
}
62
55
63
- info , err := snapshotter .Stat (ctx , key )
64
- if err != nil {
65
- contextLogger .WithError (err ).Error (proxiedFunctionCallErrorString )
66
- return snapshots.Info {}, err
67
- }
68
- return info , nil
56
+ return snapshotter .Stat (ctx , key )
69
57
}
70
58
71
59
// Update proxies remote snapshotter update request.
72
60
//
73
- // See https://github.com/containerd/containerd/blob/main /snapshots/snapshotter.go
61
+ // See https://github.com/containerd/containerd/blob/v1.6.4 /snapshots/snapshotter.go
74
62
func (s * Snapshotter ) Update (ctx context.Context , info snapshots.Info , fieldpaths ... string ) (snapshots.Info , error ) {
75
63
contextLogger := log .G (ctx ).WithField ("function" , "Update" )
76
- namespace , err := getNamespaceFromContext (ctx , contextLogger )
77
- if err != nil {
78
- return snapshots.Info {}, err
79
- }
80
- logger := contextLogger .WithField ("namespace" , namespace )
81
64
82
- snapshotter , err := s .getSnapshotterFromCache (ctx , namespace , logger )
65
+ snapshotter , err := s .getSnapshotterFromCache (ctx , contextLogger )
83
66
if err != nil {
84
67
return snapshots.Info {}, err
85
68
}
86
69
87
- updatedInfo , err := snapshotter .Update (ctx , info , fieldpaths ... )
88
- if err != nil {
89
- contextLogger .WithError (err ).Error (proxiedFunctionCallErrorString )
90
- return snapshots.Info {}, err
91
- }
92
- return updatedInfo , nil
70
+ return snapshotter .Update (ctx , info , fieldpaths ... )
93
71
}
94
72
95
73
// Usage proxies remote snapshotter usage request.
96
74
//
97
- // See https://github.com/containerd/containerd/blob/main /snapshots/snapshotter.go
75
+ // See https://github.com/containerd/containerd/blob/v1.6.4 /snapshots/snapshotter.go
98
76
func (s * Snapshotter ) Usage (ctx context.Context , key string ) (snapshots.Usage , error ) {
99
77
contextLogger := log .G (ctx ).WithField ("function" , "Usage" )
100
- namespace , err := getNamespaceFromContext (ctx , contextLogger )
101
- if err != nil {
102
- return snapshots.Usage {}, err
103
- }
104
- logger := contextLogger .WithField ("namespace" , namespace )
105
78
106
- snapshotter , err := s .getSnapshotterFromCache (ctx , namespace , logger )
79
+ snapshotter , err := s .getSnapshotterFromCache (ctx , contextLogger )
107
80
if err != nil {
108
81
return snapshots.Usage {}, err
109
82
}
110
83
111
- usage , err := snapshotter .Usage (ctx , key )
112
- if err != nil {
113
- contextLogger .WithError (err ).Error (proxiedFunctionCallErrorString )
114
- return snapshots.Usage {}, err
115
- }
116
- return usage , nil
84
+ return snapshotter .Usage (ctx , key )
117
85
}
118
86
119
87
// Mounts proxies remote snapshotter mounts request.
120
88
//
121
- // See https://github.com/containerd/containerd/blob/main /snapshots/snapshotter.go
89
+ // See https://github.com/containerd/containerd/blob/v1.6.4 /snapshots/snapshotter.go
122
90
func (s * Snapshotter ) Mounts (ctx context.Context , key string ) ([]mount.Mount , error ) {
123
91
contextLogger := log .G (ctx ).WithField ("function" , "Mounts" )
124
- namespace , err := getNamespaceFromContext (ctx , contextLogger )
125
- if err != nil {
126
- return []mount.Mount {}, err
127
- }
128
- logger := contextLogger .WithField ("namespace" , namespace )
129
92
130
- snapshotter , err := s .getSnapshotterFromCache (ctx , namespace , logger )
93
+ snapshotter , err := s .getSnapshotterFromCache (ctx , contextLogger )
131
94
if err != nil {
132
95
return []mount.Mount {}, err
133
96
}
134
97
135
98
mounts , err := snapshotter .Mounts (ctx , key )
136
99
if err != nil {
137
- contextLogger .WithError (err ).Error (proxiedFunctionCallErrorString )
138
100
return []mount.Mount {}, err
139
101
}
140
102
return mountutil .Map (mounts , vm .AddLocalMountIdentifier ), nil
141
103
}
142
104
143
105
// Prepare proxies remote snapshotter prepare request.
144
106
//
145
- // See https://github.com/containerd/containerd/blob/main /snapshots/snapshotter.go
107
+ // See https://github.com/containerd/containerd/blob/v1.6.4 /snapshots/snapshotter.go
146
108
func (s * Snapshotter ) Prepare (ctx context.Context , key string , parent string , opts ... snapshots.Opt ) ([]mount.Mount , error ) {
147
109
contextLogger := log .G (ctx ).WithField ("function" , "Prepare" )
148
- namespace , err := getNamespaceFromContext (ctx , contextLogger )
149
- if err != nil {
150
- return []mount.Mount {}, err
151
- }
152
- logger := contextLogger .WithField ("namespace" , namespace )
153
110
154
- snapshotter , err := s .getSnapshotterFromCache (ctx , namespace , logger )
111
+ snapshotter , err := s .getSnapshotterFromCache (ctx , contextLogger )
155
112
if err != nil {
156
113
return []mount.Mount {}, err
157
114
}
158
115
159
116
mounts , err := snapshotter .Prepare (ctx , key , parent , opts ... )
160
117
if err != nil {
161
- contextLogger .WithError (err ).Error (proxiedFunctionCallErrorString )
162
118
return []mount.Mount {}, err
163
119
}
164
120
return mountutil .Map (mounts , vm .AddLocalMountIdentifier ), nil
165
121
}
166
122
167
123
// View proxies remote snapshotter view request.
168
124
//
169
- // See https://github.com/containerd/containerd/blob/main /snapshots/snapshotter.go
125
+ // See https://github.com/containerd/containerd/blob/v1.6.4 /snapshots/snapshotter.go
170
126
func (s * Snapshotter ) View (ctx context.Context , key string , parent string , opts ... snapshots.Opt ) ([]mount.Mount , error ) {
171
127
contextLogger := log .G (ctx ).WithField ("function" , "View" )
172
- namespace , err := getNamespaceFromContext (ctx , contextLogger )
173
- if err != nil {
174
- return []mount.Mount {}, err
175
- }
176
- logger := contextLogger .WithField ("namespace" , namespace )
177
128
178
- snapshotter , err := s .getSnapshotterFromCache (ctx , namespace , logger )
129
+ snapshotter , err := s .getSnapshotterFromCache (ctx , contextLogger )
179
130
if err != nil {
180
131
return []mount.Mount {}, err
181
132
}
182
133
183
134
mounts , err := snapshotter .View (ctx , key , parent , opts ... )
184
135
if err != nil {
185
- contextLogger .WithError (err ).Error (proxiedFunctionCallErrorString )
186
136
return []mount.Mount {}, err
187
137
}
188
138
return mountutil .Map (mounts , vm .AddLocalMountIdentifier ), nil
189
139
}
190
140
191
141
// Commit proxies remote snapshotter commit request.
192
142
//
193
- // See https://github.com/containerd/containerd/blob/main /snapshots/snapshotter.go
143
+ // See https://github.com/containerd/containerd/blob/v1.6.4 /snapshots/snapshotter.go
194
144
func (s * Snapshotter ) Commit (ctx context.Context , name string , key string , opts ... snapshots.Opt ) error {
195
145
contextLogger := log .G (ctx ).WithField ("function" , "Commit" )
196
- namespace , err := getNamespaceFromContext (ctx , contextLogger )
197
- if err != nil {
198
- return err
199
- }
200
- logger := contextLogger .WithField ("namespace" , namespace )
201
146
202
- snapshotter , err := s .getSnapshotterFromCache (ctx , namespace , logger )
147
+ snapshotter , err := s .getSnapshotterFromCache (ctx , contextLogger )
203
148
if err != nil {
204
149
return err
205
150
}
206
151
207
- err = snapshotter .Commit (ctx , name , key , opts ... )
208
- if err != nil {
209
- contextLogger .WithError (err ).Error (proxiedFunctionCallErrorString )
210
- return err
211
- }
212
- return nil
152
+ return snapshotter .Commit (ctx , name , key , opts ... )
213
153
}
214
154
215
155
// Remove proxies remote snapshotter remove request.
216
156
//
217
- // See https://github.com/containerd/containerd/blob/main /snapshots/snapshotter.go
157
+ // See https://github.com/containerd/containerd/blob/v1.6.4 /snapshots/snapshotter.go
218
158
func (s * Snapshotter ) Remove (ctx context.Context , key string ) error {
219
159
contextLogger := log .G (ctx ).WithField ("function" , "Remove" )
220
- namespace , err := getNamespaceFromContext (ctx , contextLogger )
221
- if err != nil {
222
- return err
223
- }
224
- logger := contextLogger .WithField ("namespace" , namespace )
225
160
226
- snapshotter , err := s .getSnapshotterFromCache (ctx , namespace , logger )
161
+ snapshotter , err := s .getSnapshotterFromCache (ctx , contextLogger )
227
162
if err != nil {
228
163
return err
229
164
}
230
165
231
- err = snapshotter .Remove (ctx , key )
232
- if err != nil {
233
- contextLogger .WithError (err ).Error (proxiedFunctionCallErrorString )
234
- return err
235
- }
236
- return nil
166
+ return snapshotter .Remove (ctx , key )
237
167
}
238
168
239
169
// Walk proxies remote snapshotter walk request.
240
170
//
241
- // See https://github.com/containerd/containerd/blob/main /snapshots/snapshotter.go
171
+ // See https://github.com/containerd/containerd/blob/v1.6.4 /snapshots/snapshotter.go
242
172
func (s * Snapshotter ) Walk (ctx context.Context , fn snapshots.WalkFunc , filters ... string ) error {
243
173
contextLogger := log .G (ctx ).WithField ("function" , "Walk" )
244
- namespace , err := getNamespaceFromContext (ctx , contextLogger )
174
+
175
+ _ , err := getNamespaceFromContext (ctx , contextLogger )
245
176
if err != nil {
246
177
contextLogger .Debug ("no namespace found, proxying walk function to all cached snapshotters" )
247
178
return s .cache .WalkAll (ctx , fn , filters ... )
248
179
}
249
- logger := contextLogger .WithField ("namespace" , namespace )
250
180
251
- snapshotter , err := s .getSnapshotterFromCache (ctx , namespace , logger )
181
+ snapshotter , err := s .getSnapshotterFromCache (ctx , contextLogger )
252
182
if err != nil {
253
183
return err
254
184
}
255
185
256
- err = snapshotter .Walk (ctx , fn , filters ... )
257
- if err != nil {
258
- contextLogger .WithError (err ).Error (proxiedFunctionCallErrorString )
259
- return err
260
- }
261
- return nil
186
+ return snapshotter .Walk (ctx , fn , filters ... )
262
187
}
263
188
264
189
// Close calls close on all cached remote snapshotters.
265
190
//
266
- // See https://github.com/containerd/containerd/blob/main /snapshots/snapshotter.go
191
+ // See https://github.com/containerd/containerd/blob/v1.6.4 /snapshots/snapshotter.go
267
192
func (s * Snapshotter ) Close () error {
268
193
return s .cache .Close ()
269
194
}
270
195
196
+ // Cleanup proxies remote snapshotter cleanup request.
197
+ //
198
+ // See https://github.com/containerd/containerd/blob/v1.6.4/snapshots/snapshotter.go
199
+ func (s * Snapshotter ) Cleanup (ctx context.Context ) error {
200
+ contextLogger := log .G (ctx ).WithField ("function" , "Cleanup" )
201
+
202
+ snapshotter , err := s .getSnapshotterFromCache (ctx , contextLogger )
203
+ if err != nil {
204
+ return err
205
+ }
206
+
207
+ return snapshotter .(snapshots.Cleaner ).Cleanup (ctx )
208
+ }
209
+
271
210
const snapshotterNotFoundErrorString = "Snapshotter not found in cache"
272
211
273
- func (s * Snapshotter ) getSnapshotterFromCache (ctx context.Context , namespace string , log * logrus.Entry ) (snapshots.Snapshotter , error ) {
212
+ func (s * Snapshotter ) getSnapshotterFromCache (ctx context.Context , log * logrus.Entry ) (snapshots.Snapshotter , error ) {
213
+ namespace , err := getNamespaceFromContext (ctx , log )
214
+ if err != nil {
215
+ return nil , err
216
+ }
274
217
snapshotter , err := s .cache .Get (ctx , namespace , s .fetchSnapshotter )
275
218
if err != nil {
276
- log .WithError (err ).Error (snapshotterNotFoundErrorString )
219
+ log .WithField ( "namespace" , namespace ). WithError (err ).Error (snapshotterNotFoundErrorString )
277
220
return nil , err
278
221
}
279
222
return snapshotter , nil
0 commit comments