MCPcopy
hub / github.com/containerd/containerd / init

Function init

plugins/mount/manager.go:39–125  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37)
38
39func init() {
40 registry.Register(&plugin.Registration{
41 Type: plugins.MountManagerPlugin,
42 ID: "bolt",
43 Requires: []plugin.Type{
44 plugins.MetadataPlugin,
45 plugins.MountHandlerPlugin,
46 },
47 InitFn: func(ic *plugin.InitContext) (any, error) {
48 md, err := ic.GetSingle(plugins.MetadataPlugin)
49 if err != nil {
50 return nil, err
51 }
52 hp, err := ic.GetByType(plugins.MountHandlerPlugin)
53 if err != nil && !errors.Is(err, plugin.ErrPluginNotFound) {
54 return nil, err
55 }
56 var opts []manager.Opt
57 for k, v := range hp {
58 opts = append(opts, manager.WithMountHandler(k, v.(mount.Handler)))
59 }
60
61 root := ic.Properties[plugins.PropertyStateDir]
62
63 // TODO: Allow overriding root and target directory from config
64
65 targets := filepath.Join(root, "t")
66 if merr := os.MkdirAll(targets, 0700); merr != nil {
67 return nil, merr
68 }
69
70 // roots are the directories that mount handlers can operate in
71 // TODO: support additional roots from config
72 opts = append(opts, manager.WithAllowedRoot(filepath.Dir(ic.Properties[plugins.PropertyRootDir])))
73
74 //if _, ok := mhandlers["mkdir"]; !ok {
75 // mkdir, err := handlers.MkdirHandler(roots...)
76 // if err != nil {
77 // return nil, fmt.Errorf("failed to create mkdir handler: %w", err)
78 // }
79 // mhandlers["mkdir"] = mkdir
80 //}
81
82 metadb := filepath.Join(root, "mounts.db")
83
84 db, err := bolt.Open(metadb, 0600, nil)
85 if err != nil {
86 return nil, fmt.Errorf("failed to open database file: %w", err)
87 }
88
89 mm, err := manager.NewManager(db, targets, opts...)
90 if err != nil {
91 db.Close()
92 return nil, fmt.Errorf("failed to create mount manager: %w", err)
93 }
94
95 //TODO: IF has sync
96 if sync, ok := mm.(interface{ Sync(context.Context) error }); ok {

Callers

nothing calls this directly

Calls 14

WithMountHandlerFunction · 0.92
WithAllowedRootFunction · 0.92
NewManagerFunction · 0.92
WithTransactionFunction · 0.92
DirMethod · 0.80
RegisterReadinessMethod · 0.80
RollbackMethod · 0.80
RegisterMethod · 0.65
MkdirAllMethod · 0.65
CloseMethod · 0.65
SyncMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…