@@ -17,11 +17,13 @@ import (
17
17
18
18
"github.com/containerd/containerd/log"
19
19
"github.com/containerd/containerd/mount"
20
+ "github.com/containerd/containerd/snapshots"
20
21
"github.com/containerd/containerd/snapshots/storage"
21
22
"github.com/containerd/nydus-snapshotter/config/daemonconfig"
22
23
"github.com/containerd/nydus-snapshotter/pkg/label"
23
24
"github.com/containerd/nydus-snapshotter/pkg/layout"
24
25
"github.com/containerd/nydus-snapshotter/pkg/rafs"
26
+ "github.com/containerd/nydus-snapshotter/pkg/snapshot"
25
27
"github.com/pkg/errors"
26
28
)
27
29
@@ -101,7 +103,7 @@ func (o *snapshotter) remoteMountWithExtraOptions(ctx context.Context, s storage
101
103
}, nil
102
104
}
103
105
104
- func (o * snapshotter ) mountWithKataVolume (ctx context.Context , id string , overlayOptions []string ) ([]mount.Mount , error ) {
106
+ func (o * snapshotter ) mountWithKataVolume (ctx context.Context , id string , overlayOptions []string , key string ) ([]mount.Mount , error ) {
105
107
hasVolume := false
106
108
rafs := rafs .RafsGlobalCache .Get (id )
107
109
if rafs == nil {
@@ -122,7 +124,7 @@ func (o *snapshotter) mountWithKataVolume(ctx context.Context, id string, overla
122
124
123
125
// Insert Kata volume for tarfs
124
126
if blobID , ok := rafs .Annotations [label .NydusTarfsLayer ]; ok {
125
- options , err := o .mountWithTarfsVolume (* rafs , blobID )
127
+ options , err := o .mountWithTarfsVolume (ctx , * rafs , blobID , key )
126
128
if err != nil {
127
129
return []mount.Mount {}, errors .Wrapf (err , "create kata volume for tarfs" )
128
130
}
@@ -149,66 +151,103 @@ func (o *snapshotter) mountWithKataVolume(ctx context.Context, id string, overla
149
151
150
152
func (o * snapshotter ) mountWithProxyVolume (rafs rafs.Rafs ) ([]string , error ) {
151
153
options := []string {}
154
+ source := rafs .Annotations [label .CRIImageRef ]
152
155
for k , v := range rafs .Annotations {
153
156
options = append (options , fmt .Sprintf ("%s=%s" , k , v ))
154
157
}
155
-
156
- volume := & KataVirtualVolume {
157
- VolumeType : KataVirtualVolumeImageGuestPullType ,
158
- Source : "" ,
159
- FSType : "" ,
160
- Options : options ,
161
- ImagePull : & ImagePullVolume {Metadata : rafs .Annotations },
162
- }
163
- if ! volume .Validate () {
164
- return []string {}, errors .Errorf ("got invalid kata volume, %v" , volume )
165
- }
166
-
167
- info , err := EncodeKataVirtualVolumeToBase64 (* volume )
158
+ opt , err := o .prepareKataVirtualVolume (label .NydusProxyMode , source , KataVirtualVolumeImageGuestPullType , "" , options , rafs .Annotations )
168
159
if err != nil {
169
- return [] string {} , errors .Errorf ( "failed to encoding Kata Volume info %v" , volume )
160
+ return options , errors .Wrapf ( err , "failed to prepare KataVirtualVolume" )
170
161
}
171
- opt := fmt .Sprintf ("%s=%s" , KataVirtualVolumeOptionName , info )
172
-
173
162
return []string {opt }, nil
174
163
}
175
164
176
- func (o * snapshotter ) mountWithTarfsVolume (rafs rafs.Rafs , blobID string ) ([]string , error ) {
177
- var volume * KataVirtualVolume
178
-
165
+ func (o * snapshotter ) mountWithTarfsVolume (ctx context.Context , rafs rafs.Rafs , blobID , key string ) ([]string , error ) {
166
+ options := []string {}
179
167
if info , ok := rafs .Annotations [label .NydusImageBlockInfo ]; ok {
180
168
path , err := o .fs .GetTarfsImageDiskFilePath (blobID )
181
169
if err != nil {
182
170
return []string {}, errors .Wrapf (err , "get tarfs image disk file path" )
183
171
}
184
- volume = & KataVirtualVolume {
185
- VolumeType : KataVirtualVolumeImageRawBlockType ,
186
- Source : path ,
187
- FSType : "erofs" ,
188
- Options : []string {"ro" },
172
+ log .L .Debugf ("mountWithTarfsVolume info %v" , info )
173
+ opt , err := o .prepareKataVirtualVolume (label .NydusImageBlockInfo , path , KataVirtualVolumeImageRawBlockType , "erofs" , []string {"ro" }, rafs .Annotations )
174
+ if err != nil {
175
+ return options , errors .Wrapf (err , "failed to prepare KataVirtualVolume for image_raw_block" )
189
176
}
190
- if len (info ) > 0 {
191
- dmverity , err := parseTarfsDmVerityInfo (info )
177
+
178
+ options = append (options , opt )
179
+ log .L .Debugf ("mountWithTarfsVolume type=%v, options %v" , KataVirtualVolumeImageRawBlockType , options )
180
+ return options , nil
181
+ }
182
+
183
+ if _ , ok := rafs .Annotations [label .NydusLayerBlockInfo ]; ok {
184
+ for {
185
+ pID , pInfo , _ , pErr := snapshot .GetSnapshotInfo (ctx , o .ms , key )
186
+ log .G (ctx ).Debugf ("mountWithKataVolume pID= %v, pInfo = %v" , pID , pInfo )
187
+
188
+ if pErr != nil {
189
+ return options , errors .Wrapf (pErr , "failed to get snapshot info" )
190
+ }
191
+ if pInfo .Kind == snapshots .KindActive {
192
+ key = pInfo .Parent
193
+ continue
194
+ }
195
+
196
+ blobID = pInfo .Labels [label .NydusTarfsLayer ]
197
+ path , err := o .fs .GetTarfsLayerDiskFilePath (blobID )
192
198
if err != nil {
193
- return [] string {}, err
199
+ return options , errors . Wrapf ( err , "get tarfs image disk file path" )
194
200
}
195
- volume .DmVerity = & dmverity
201
+
202
+ opt , err := o .prepareKataVirtualVolume (label .NydusLayerBlockInfo , path , KataVirtualVolumeLayerRawBlockType , "erofs" , []string {"ro" }, pInfo .Labels )
203
+ if err != nil {
204
+ return options , errors .Wrapf (err , "failed to prepare KataVirtualVolume for layer_raw_block" )
205
+ }
206
+
207
+ options = append (options , opt )
208
+
209
+ if pInfo .Parent == "" {
210
+ break
211
+ }
212
+ key = pInfo .Parent
196
213
}
214
+ log .L .Debugf ("mountWithTarfsVolume type=%v, options %v" , KataVirtualVolumeLayerRawBlockType , options )
215
+ return options , nil
197
216
}
198
217
199
- if volume != nil {
200
- if ! volume .Validate () {
201
- return []string {}, errors .Errorf ("got invalid kata volume, %v" , volume )
202
- }
203
- info , err := EncodeKataVirtualVolumeToBase64 (* volume )
204
- if err != nil {
205
- return []string {}, errors .Errorf ("failed to encoding Kata Volume info %v" , volume )
218
+ // If Neither image_raw_block or layer_raw_block, return empty strings
219
+ return options , nil
220
+ }
221
+
222
+ func (o * snapshotter ) prepareKataVirtualVolume (blockType , source , volumeType , fsType string , options []string , labels map [string ]string ) (string , error ) {
223
+ volume := & KataVirtualVolume {
224
+ VolumeType : volumeType ,
225
+ Source : source ,
226
+ FSType : fsType ,
227
+ Options : options ,
228
+ }
229
+ if blockType == label .NydusImageBlockInfo || blockType == label .NydusLayerBlockInfo {
230
+ dmverityInfo := labels [blockType ]
231
+ if len (dmverityInfo ) > 0 {
232
+ dmverity , err := parseTarfsDmVerityInfo (dmverityInfo )
233
+ if err != nil {
234
+ return "" , err
235
+ }
236
+ volume .DmVerity = & dmverity
206
237
}
207
- opt := fmt . Sprintf ( "%s=%s" , KataVirtualVolumeOptionName , info )
208
- return [] string { opt }, nil
238
+ } else if blockType == label . NydusProxyMode {
239
+ volume . ImagePull = & ImagePullVolume { Metadata : labels }
209
240
}
210
241
211
- return []string {}, nil
242
+ if ! volume .Validate () {
243
+ return "" , errors .Errorf ("got invalid kata volume, %v" , volume )
244
+ }
245
+ info , err := EncodeKataVirtualVolumeToBase64 (* volume )
246
+ if err != nil {
247
+ return "" , errors .Errorf ("failed to encoding Kata Volume info %v" , volume )
248
+ }
249
+ opt := fmt .Sprintf ("%s=%s" , KataVirtualVolumeOptionName , info )
250
+ return opt , nil
212
251
}
213
252
214
253
func parseTarfsDmVerityInfo (info string ) (DmVerityInfo , error ) {
0 commit comments