Skip to content

Commit d4e7820

Browse files
authored
Merge pull request #4518 from knight42/feat/btrfs-config-root-path
feat(snapshot::btrfs): config root_path
2 parents 445e26f + a52daa2 commit d4e7820

3 files changed

Lines changed: 62 additions & 16 deletions

File tree

cmd/containerd/builtins_btrfs_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818

1919
package main
2020

21-
import _ "github.com/containerd/containerd/snapshots/btrfs"
21+
import _ "github.com/containerd/containerd/snapshots/btrfs/plugin"

snapshots/btrfs/btrfs.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,18 @@ import (
2626
"strings"
2727

2828
"github.com/containerd/btrfs"
29+
"github.com/containerd/continuity/fs"
30+
2931
"github.com/containerd/containerd/log"
3032
"github.com/containerd/containerd/mount"
31-
"github.com/containerd/containerd/platforms"
3233
"github.com/containerd/containerd/plugin"
3334
"github.com/containerd/containerd/snapshots"
3435
"github.com/containerd/containerd/snapshots/storage"
35-
"github.com/containerd/continuity/fs"
3636

37-
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3837
"github.com/pkg/errors"
3938
"github.com/sirupsen/logrus"
4039
)
4140

42-
func init() {
43-
plugin.Register(&plugin.Registration{
44-
ID: "btrfs",
45-
Type: plugin.SnapshotPlugin,
46-
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
47-
ic.Meta.Platforms = []ocispec.Platform{platforms.DefaultSpec()}
48-
ic.Meta.Exports = map[string]string{"root": ic.Root}
49-
return NewSnapshotter(ic.Root)
50-
},
51-
})
52-
}
53-
5441
type snapshotter struct {
5542
device string // device of the root
5643
root string // root provides paths for internal storage.

snapshots/btrfs/plugin/plugin.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// +build linux,!no_btrfs
2+
3+
/*
4+
Copyright The containerd Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package plugin
20+
21+
import (
22+
"errors"
23+
24+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
25+
26+
"github.com/containerd/containerd/platforms"
27+
"github.com/containerd/containerd/plugin"
28+
"github.com/containerd/containerd/snapshots/btrfs"
29+
)
30+
31+
// Config represents configuration for the btrfs plugin.
32+
type Config struct {
33+
// Root directory for the plugin
34+
RootPath string `toml:"root_path"`
35+
}
36+
37+
func init() {
38+
plugin.Register(&plugin.Registration{
39+
ID: "btrfs",
40+
Type: plugin.SnapshotPlugin,
41+
Config: &Config{},
42+
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
43+
ic.Meta.Platforms = []ocispec.Platform{platforms.DefaultSpec()}
44+
45+
config, ok := ic.Config.(*Config)
46+
if !ok {
47+
return nil, errors.New("invalid btrfs configuration")
48+
}
49+
50+
root := ic.Root
51+
if len(config.RootPath) != 0 {
52+
root = config.RootPath
53+
}
54+
55+
ic.Meta.Exports = map[string]string{"root": root}
56+
return btrfs.NewSnapshotter(root)
57+
},
58+
})
59+
}

0 commit comments

Comments
 (0)