2018-02-05 16:05:59 -05:00
|
|
|
package graphdriver // import "github.com/docker/docker/daemon/graphdriver"
|
2015-06-05 16:09:53 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-11-18 16:54:11 -05:00
|
|
|
"path/filepath"
|
2015-06-05 16:09:53 -04:00
|
|
|
|
2018-05-30 15:00:42 -04:00
|
|
|
"github.com/docker/docker/errdefs"
|
2016-10-07 16:53:14 -04:00
|
|
|
"github.com/docker/docker/pkg/plugingetter"
|
2018-04-24 21:45:00 -04:00
|
|
|
"github.com/docker/docker/pkg/plugins"
|
2019-08-05 10:37:47 -04:00
|
|
|
v2 "github.com/docker/docker/plugin/v2"
|
2018-04-24 21:45:00 -04:00
|
|
|
"github.com/pkg/errors"
|
2015-06-05 16:09:53 -04:00
|
|
|
)
|
|
|
|
|
2016-11-19 11:41:07 -05:00
|
|
|
func lookupPlugin(name string, pg plugingetter.PluginGetter, config Options) (Driver, error) {
|
|
|
|
if !config.ExperimentalEnabled {
|
|
|
|
return nil, fmt.Errorf("graphdriver plugins are only supported with experimental mode")
|
|
|
|
}
|
2016-12-19 21:18:43 -05:00
|
|
|
pl, err := pg.Get(name, "GraphDriver", plugingetter.Acquire)
|
2015-06-05 16:09:53 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error looking up graphdriver plugin %s: %v", name, err)
|
|
|
|
}
|
2016-11-19 11:41:07 -05:00
|
|
|
return newPluginDriver(name, pl, config)
|
2015-06-05 16:09:53 -04:00
|
|
|
}
|
|
|
|
|
2016-11-19 11:41:07 -05:00
|
|
|
func newPluginDriver(name string, pl plugingetter.CompatPlugin, config Options) (Driver, error) {
|
|
|
|
home := config.Root
|
2016-12-10 11:40:01 -05:00
|
|
|
if !pl.IsV1() {
|
|
|
|
if p, ok := pl.(*v2.Plugin); ok {
|
2017-12-14 09:29:11 -05:00
|
|
|
if p.PluginObj.Config.PropagatedMount != "" {
|
2016-12-10 11:40:01 -05:00
|
|
|
home = p.PluginObj.Config.PropagatedMount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-24 21:45:00 -04:00
|
|
|
|
|
|
|
var proxy *graphDriverProxy
|
|
|
|
|
2018-05-30 15:00:42 -04:00
|
|
|
switch pt := pl.(type) {
|
|
|
|
case plugingetter.PluginWithV1Client:
|
|
|
|
proxy = &graphDriverProxy{name, pl, Capabilities{}, pt.Client()}
|
|
|
|
case plugingetter.PluginAddr:
|
|
|
|
if pt.Protocol() != plugins.ProtocolSchemeHTTPV1 {
|
|
|
|
return nil, errors.Errorf("plugin protocol not supported: %s", pt.Protocol())
|
2018-04-24 21:45:00 -04:00
|
|
|
}
|
2018-05-30 15:00:42 -04:00
|
|
|
addr := pt.Addr()
|
|
|
|
client, err := plugins.NewClientWithTimeout(addr.Network()+"://"+addr.String(), nil, pt.Timeout())
|
2018-04-24 21:45:00 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error creating plugin client")
|
|
|
|
}
|
|
|
|
proxy = &graphDriverProxy{name, pl, Capabilities{}, client}
|
2018-05-30 15:00:42 -04:00
|
|
|
default:
|
|
|
|
return nil, errdefs.System(errors.Errorf("got unknown plugin type %T", pt))
|
2018-04-24 21:45:00 -04:00
|
|
|
}
|
2018-05-30 15:00:42 -04:00
|
|
|
|
2022-03-14 15:24:29 -04:00
|
|
|
return proxy, proxy.Init(filepath.Join(home, name), config.DriverOptions, config.IDMap)
|
2015-06-05 16:09:53 -04:00
|
|
|
}
|