plugin.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package graphdriver
  2. import (
  3. "fmt"
  4. "io"
  5. "path/filepath"
  6. "github.com/docker/docker/pkg/plugingetter"
  7. "github.com/docker/docker/plugin/v2"
  8. )
  9. type pluginClient interface {
  10. // Call calls the specified method with the specified arguments for the plugin.
  11. Call(string, interface{}, interface{}) error
  12. // Stream calls the specified method with the specified arguments for the plugin and returns the response IO stream
  13. Stream(string, interface{}) (io.ReadCloser, error)
  14. // SendFile calls the specified method, and passes through the IO stream
  15. SendFile(string, io.Reader, interface{}) error
  16. }
  17. func lookupPlugin(name string, pg plugingetter.PluginGetter, config Options) (Driver, error) {
  18. if !config.ExperimentalEnabled {
  19. return nil, fmt.Errorf("graphdriver plugins are only supported with experimental mode")
  20. }
  21. pl, err := pg.Get(name, "GraphDriver", plugingetter.Acquire)
  22. if err != nil {
  23. return nil, fmt.Errorf("Error looking up graphdriver plugin %s: %v", name, err)
  24. }
  25. return newPluginDriver(name, pl, config)
  26. }
  27. func newPluginDriver(name string, pl plugingetter.CompatPlugin, config Options) (Driver, error) {
  28. home := config.Root
  29. if !pl.IsV1() {
  30. if p, ok := pl.(*v2.Plugin); ok {
  31. if p.PropagatedMount != "" {
  32. home = p.PluginObj.Config.PropagatedMount
  33. }
  34. }
  35. }
  36. proxy := &graphDriverProxy{name, pl, Capabilities{}}
  37. return proxy, proxy.Init(filepath.Join(home, name), config.DriverOptions, config.UIDMaps, config.GIDMaps)
  38. }