Skip to content

Commit 4154235

Browse files
committed
feat: make btrfs root_path configurable
Part of #4514 Signed-off-by: Jian Zeng <[email protected]>
1 parent efa0e80 commit 4154235

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

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)