Skip to content

Commit

Permalink
Merge pull request #277 from BigVan/main
Browse files Browse the repository at this point in the history
Add isPrepareRootfs() method.
  • Loading branch information
liulanzheng authored Apr 11, 2024
2 parents 08d5d61 + 0e3623c commit e66cd5c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
3 changes: 2 additions & 1 deletion docs/QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ After download, install the rpm/deb package.
#### Config

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

```json
{
Expand Down Expand Up @@ -82,7 +83,7 @@ The config file is `/etc/overlaybd-snapshotter/config.json`. Please create the f
```
| Field | Description |
| ----- | ----------- |
| `root` | the root directory to store snapshots |
| `root` | the root directory to store snapshots. **Suggestion: This path should be a subpath of containerd's root** |
| `address` | the socket address used to connect withcontainerd. |
| `verbose` | log level, `info` or `debug` |
| `rwMode` | rootfs mode about wether to use native writable layer. See [Native Support for Writable](./WRITABLE.md) for detail. |
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/containerd/continuity v0.4.3
github.com/containerd/go-cni v1.1.9
github.com/containerd/log v0.1.0
github.com/data-accelerator/zdfs v0.1.3
github.com/data-accelerator/zdfs v0.1.4
github.com/go-sql-driver/mysql v1.6.0
github.com/jessevdk/go-flags v1.5.0
github.com/moby/locker v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/data-accelerator/zdfs v0.1.3 h1:fhe2PiV+JvauZ2rBFguEM8/DcFkxtJI+6973E24zTWM=
github.com/data-accelerator/zdfs v0.1.3/go.mod h1:MnDNsg9RiB+Ey0DzOOQ5sdMSyS8fGKGbcOYI1VULSPI=
github.com/data-accelerator/zdfs v0.1.4 h1:S7M1lpnVPDANXXXD1ZI6p3ZUempNYVLxUkXbgEUVUkM=
github.com/data-accelerator/zdfs v0.1.4/go.mod h1:MnDNsg9RiB+Ey0DzOOQ5sdMSyS8fGKGbcOYI1VULSPI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 2 additions & 0 deletions pkg/label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ const (

// LayerToTurboOCI is used to convert local layer to turboOCI with tar index
LayerToTurboOCI = "containerd.io/snapshot/overlaybd/convert2turbo-oci"

SnapshotType = "containerd.io/snapshot/type"
)

// used in filterAnnotationsForSave (https://github.com/moby/buildkit/blob/v0.11/cache/refs.go#L882)
Expand Down
19 changes: 15 additions & 4 deletions pkg/snapshot/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,16 @@ func (o *snapshotter) checkTurboOCI(labels map[string]string) (bool, string, str
return false, "", ""
}

func (o *snapshotter) isPrepareRootfs(info snapshots.Info) bool {
if _, ok := info.Labels[label.TargetSnapshotRef]; ok {
return false
}
if info.Labels[label.SnapshotType] == "image" {
return false
}
return true
}

func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind, key string, parent string, opts ...snapshots.Opt) (_ []mount.Mount, retErr error) {

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

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

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

0 comments on commit e66cd5c

Please sign in to comment.