Skip to content

Commit e66cd5c

Browse files
authored
Merge pull request #277 from BigVan/main
Add isPrepareRootfs() method.
2 parents 08d5d61 + 0e3623c commit e66cd5c

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

docs/QUICKSTART.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ After download, install the rpm/deb package.
5454
#### Config
5555

5656
The config file is `/etc/overlaybd-snapshotter/config.json`. Please create the file if not exists.
57+
**We suggest the root path of snapshotter is a subpath of containerd's root**
5758

5859
```json
5960
{
@@ -82,7 +83,7 @@ The config file is `/etc/overlaybd-snapshotter/config.json`. Please create the f
8283
```
8384
| Field | Description |
8485
| ----- | ----------- |
85-
| `root` | the root directory to store snapshots |
86+
| `root` | the root directory to store snapshots. **Suggestion: This path should be a subpath of containerd's root** |
8687
| `address` | the socket address used to connect withcontainerd. |
8788
| `verbose` | log level, `info` or `debug` |
8889
| `rwMode` | rootfs mode about wether to use native writable layer. See [Native Support for Writable](./WRITABLE.md) for detail. |

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/containerd/continuity v0.4.3
88
github.com/containerd/go-cni v1.1.9
99
github.com/containerd/log v0.1.0
10-
github.com/data-accelerator/zdfs v0.1.3
10+
github.com/data-accelerator/zdfs v0.1.4
1111
github.com/go-sql-driver/mysql v1.6.0
1212
github.com/jessevdk/go-flags v1.5.0
1313
github.com/moby/locker v1.0.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
107107
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
108108
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
109109
github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
110-
github.com/data-accelerator/zdfs v0.1.3 h1:fhe2PiV+JvauZ2rBFguEM8/DcFkxtJI+6973E24zTWM=
111-
github.com/data-accelerator/zdfs v0.1.3/go.mod h1:MnDNsg9RiB+Ey0DzOOQ5sdMSyS8fGKGbcOYI1VULSPI=
110+
github.com/data-accelerator/zdfs v0.1.4 h1:S7M1lpnVPDANXXXD1ZI6p3ZUempNYVLxUkXbgEUVUkM=
111+
github.com/data-accelerator/zdfs v0.1.4/go.mod h1:MnDNsg9RiB+Ey0DzOOQ5sdMSyS8fGKGbcOYI1VULSPI=
112112
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
113113
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
114114
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

pkg/label/label.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ const (
9595

9696
// LayerToTurboOCI is used to convert local layer to turboOCI with tar index
9797
LayerToTurboOCI = "containerd.io/snapshot/overlaybd/convert2turbo-oci"
98+
99+
SnapshotType = "containerd.io/snapshot/type"
98100
)
99101

100102
// used in filterAnnotationsForSave (https://github.com/moby/buildkit/blob/v0.11/cache/refs.go#L882)

pkg/snapshot/overlay.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ func (o *snapshotter) checkTurboOCI(labels map[string]string) (bool, string, str
364364
return false, "", ""
365365
}
366366

367+
func (o *snapshotter) isPrepareRootfs(info snapshots.Info) bool {
368+
if _, ok := info.Labels[label.TargetSnapshotRef]; ok {
369+
return false
370+
}
371+
if info.Labels[label.SnapshotType] == "image" {
372+
return false
373+
}
374+
return true
375+
}
376+
367377
func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind, key string, parent string, opts ...snapshots.Opt) (_ []mount.Mount, retErr error) {
368378

369379
ctx, t, err := o.ms.TransactionContext(ctx, true)
@@ -384,6 +394,7 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
384394
if err != nil {
385395
return nil, err
386396
}
397+
log.G(ctx).Infof("sn: %s, labels:[%+v]", id, info.Labels)
387398
defer func() {
388399
// the transaction rollback makes created snapshot invalid, just clean it.
389400
if retErr != nil && rollback {
@@ -495,8 +506,8 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
495506
writeType := o.getWritableType(ctx, parentID, info)
496507

497508
// If Preparing for rootfs, find metadata from its parent (top layer), launch and mount backstore device.
498-
if _, ok := info.Labels[label.TargetSnapshotRef]; !ok {
499-
log.G(ctx).Infof("Preparing rootfs. writeType: %s", writeType)
509+
if o.isPrepareRootfs(info) {
510+
log.G(ctx).Infof("Preparing rootfs(%s). writeType: %s", s.ID, writeType)
500511
if writeType != RoDir {
501512
stype = storageTypeLocalBlock
502513
if err := o.constructOverlayBDSpec(ctx, key, true); err != nil {
@@ -515,8 +526,8 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
515526
parentIsAccelLayer := parentInfo.Labels[label.AccelerationLayer] == "yes"
516527
needRecordTrace := info.Labels[label.RecordTrace] == "yes"
517528
recordTracePath := info.Labels[label.RecordTracePath]
518-
log.G(ctx).Infof("Prepare rootfs (parentIsAccelLayer: %t, needRecordTrace: %t, recordTracePath: %s)",
519-
parentIsAccelLayer, needRecordTrace, recordTracePath)
529+
log.G(ctx).Infof("Prepare rootfs (sn: %s, parentIsAccelLayer: %t, needRecordTrace: %t, recordTracePath: %s)",
530+
id, parentIsAccelLayer, needRecordTrace, recordTracePath)
520531

521532
if parentIsAccelLayer {
522533
log.G(ctx).Infof("get accel-layer in parent (id: %s)", id)

0 commit comments

Comments
 (0)