@@ -59,12 +59,19 @@ const (
59
59
// storageTypeRemoteBlock means that there is no unpacked layer data.
60
60
// But there are labels to mark data that will be pulling on demand.
61
61
storageTypeRemoteBlock
62
+
63
+ // storageTypeLocalLayer means that the unpacked layer data is in
64
+ // a tar file, which needs to generate overlaybd-turboOCI meta before
65
+ // create an overlaybd device
66
+ storageTypeLocalLayer
62
67
)
63
68
64
69
const (
65
70
RoDir = "overlayfs" // overlayfs as rootfs. upper + lower (overlaybd)
66
71
RwDir = "dir" // mount overlaybd as rootfs
67
72
RwDev = "dev" // use overlaybd directly
73
+
74
+ LayerBlob = "layer" // decompressed tgz layer (maybe compressed by ZFile)
68
75
)
69
76
70
77
type Registry struct {
@@ -574,8 +581,20 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
574
581
var m []mount.Mount
575
582
switch stype {
576
583
case storageTypeNormal :
577
- m = o .normalOverlayMount (s )
578
- log .G (ctx ).Debugf ("return mount point(R/W mode: %s): %v" , writeType , m )
584
+ if _ , ok := info .Labels [label .LayerToTurboOCI ]; ok {
585
+ m = []mount.Mount {
586
+ {
587
+ Source : o .upperPath (s .ID ),
588
+ Type : "bind" ,
589
+ Options : []string {
590
+ "rw" ,
591
+ "rbind" ,
592
+ },
593
+ },
594
+ }
595
+ } else {
596
+ m = o .normalOverlayMount (s )
597
+ }
579
598
case storageTypeLocalBlock , storageTypeRemoteBlock :
580
599
m , err = o .basedOnBlockDeviceMount (ctx , s , writeType )
581
600
if err != nil {
@@ -584,6 +603,7 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
584
603
default :
585
604
panic ("unreachable" )
586
605
}
606
+ log .G (ctx ).Debugf ("return mount point(R/W mode: %s): %v" , writeType , m )
587
607
return m , nil
588
608
589
609
}
@@ -595,8 +615,15 @@ func (o *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...s
595
615
defer func () {
596
616
if retErr != nil {
597
617
metrics .GRPCErrCount .WithLabelValues ("Prepare" ).Inc ()
618
+ } else {
619
+ log .G (ctx ).WithFields (logrus.Fields {
620
+ "d" : time .Since (start ),
621
+ "key" : key ,
622
+ "parent" : parent ,
623
+ }).Infof ("Prepare" )
598
624
}
599
625
metrics .GRPCLatency .WithLabelValues ("Prepare" ).Observe (time .Since (start ).Seconds ())
626
+
600
627
}()
601
628
return o .createMountPoint (ctx , snapshots .KindActive , key , parent , opts ... )
602
629
}
@@ -626,6 +653,11 @@ func (o *snapshotter) Mounts(ctx context.Context, key string) (_ []mount.Mount,
626
653
defer func () {
627
654
if retErr != nil {
628
655
metrics .GRPCErrCount .WithLabelValues ("Mounts" ).Inc ()
656
+ } else {
657
+ log .G (ctx ).WithFields (logrus.Fields {
658
+ "d" : time .Since (start ),
659
+ "key" : key ,
660
+ }).Infof ("Mounts" )
629
661
}
630
662
metrics .GRPCLatency .WithLabelValues ("Mounts" ).Observe (time .Since (start ).Seconds ())
631
663
}()
@@ -691,6 +723,12 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
691
723
defer func () {
692
724
if retErr != nil {
693
725
metrics .GRPCErrCount .WithLabelValues ("Commit" ).Inc ()
726
+ } else {
727
+ log .G (ctx ).WithFields (logrus.Fields {
728
+ "d" : time .Since (start ),
729
+ "name" : name ,
730
+ "key" : key ,
731
+ }).Infof ("Commit" )
694
732
}
695
733
metrics .GRPCLatency .WithLabelValues ("Commit" ).Observe (time .Since (start ).Seconds ())
696
734
}()
@@ -746,6 +784,15 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
746
784
}
747
785
748
786
log .G (ctx ).Debugf ("Commit info (id: %s, info: %v, stype: %d)" , id , info .Labels , stype )
787
+ // Firstly, try to convert an OCIv1 tarball to a turboOCI layer.
788
+ // then change stype to 'storageTypeLocalBlock' which can make it attach a overlaybd block
789
+ if stype == storageTypeLocalLayer {
790
+ log .G (ctx ).Infof ("convet a local blob to turboOCI layer (sn: %s)" , id )
791
+ if err := o .constructOverlayBDSpec (ctx , name , false ); err != nil {
792
+ return errors .Wrapf (err , "failed to construct overlaybd config" )
793
+ }
794
+ stype = storageTypeLocalBlock
795
+ }
749
796
750
797
if stype == storageTypeLocalBlock {
751
798
if err := o .constructOverlayBDSpec (ctx , name , false ); err != nil {
@@ -1158,6 +1205,13 @@ func (o *snapshotter) identifySnapshotStorageType(ctx context.Context, id string
1158
1205
if err == nil {
1159
1206
return st , nil
1160
1207
}
1208
+
1209
+ // check layer.tar if it should be converted to turboOCI
1210
+ filePath = o .overlaybdOCILayerPath (id )
1211
+ if _ , err := os .Stat (filePath ); err == nil {
1212
+ log .G (ctx ).Infof ("uncompressed layer found in sn: %s" , id )
1213
+ return storageTypeLocalLayer , nil
1214
+ }
1161
1215
if os .IsNotExist (err ) {
1162
1216
// check config.v1.json
1163
1217
log .G (ctx ).Debugf ("failed to identify by writable_data(sn: %s), try to identify by config.v1.json" , id )
@@ -1168,6 +1222,7 @@ func (o *snapshotter) identifySnapshotStorageType(ctx context.Context, id string
1168
1222
}
1169
1223
return storageTypeNormal , nil
1170
1224
}
1225
+
1171
1226
log .G (ctx ).Debugf ("storageType(sn: %s): %d" , id , st )
1172
1227
1173
1228
return st , err
@@ -1185,10 +1240,18 @@ func (o *snapshotter) workPath(id string) string {
1185
1240
return filepath .Join (o .root , "snapshots" , id , "work" )
1186
1241
}
1187
1242
1243
+ func (o * snapshotter ) convertTempdir (id string ) string {
1244
+ return filepath .Join (o .root , "snapshots" , id , "temp" )
1245
+ }
1246
+
1188
1247
func (o * snapshotter ) blockPath (id string ) string {
1189
1248
return filepath .Join (o .root , "snapshots" , id , "block" )
1190
1249
}
1191
1250
1251
+ func (o * snapshotter ) turboOCIFsMeta (id string ) string {
1252
+ return filepath .Join (o .root , "snapshots" , id , "fs" , "ext4.fs.meta" )
1253
+ }
1254
+
1192
1255
func (o * snapshotter ) magicFilePath (id string ) string {
1193
1256
return filepath .Join (o .root , "snapshots" , id , "fs" , "overlaybd.commit" )
1194
1257
}
@@ -1217,12 +1280,16 @@ func (o *snapshotter) overlaybdWritableDataPath(id string) string {
1217
1280
return filepath .Join (o .root , "snapshots" , id , "block" , "writable_data" )
1218
1281
}
1219
1282
1220
- func (o * snapshotter ) overlaybdBackstoreMarkFile (id string ) string {
1221
- return filepath .Join (o .root , "snapshots" , id , "block" , "backstore_mark " )
1283
+ func (o * snapshotter ) overlaybdOCILayerPath (id string ) string {
1284
+ return filepath .Join (o .root , "snapshots" , id , "layer.tar " )
1222
1285
}
1223
1286
1224
- func (o * snapshotter ) turboOCIFsMeta (id string ) string {
1225
- return filepath .Join (o .root , "snapshots" , id , "fs" , "ext4.fs.meta" )
1287
+ func (o * snapshotter ) overlaybdOCILayerMeta (id string ) string {
1288
+ return filepath .Join (o .root , "snapshots" , id , "layer.metadata" )
1289
+ }
1290
+
1291
+ func (o * snapshotter ) overlaybdBackstoreMarkFile (id string ) string {
1292
+ return filepath .Join (o .root , "snapshots" , id , "block" , "backstore_mark" )
1226
1293
}
1227
1294
1228
1295
func (o * snapshotter ) turboOCIGzipIdx (id string ) string {
0 commit comments