Vendor in latest containers/storage
Fixes store.lock issue comming up when using store.Names Signed-off-by: umohnani8 <umohnani@redhat.com>
This commit is contained in:
parent
400713a58b
commit
cfc2393d58
119 changed files with 2846 additions and 1730 deletions
120
vendor/github.com/containers/storage/pkg/plugins/plugins.go
generated
vendored
120
vendor/github.com/containers/storage/pkg/plugins/plugins.go
generated
vendored
|
@ -1,19 +1,17 @@
|
|||
// Package plugins provides structures and helper functions to manage Docker
|
||||
// plugins.
|
||||
//
|
||||
// Storage discovers plugins by looking for them in the plugin directory whenever
|
||||
// Docker discovers plugins by looking for them in the plugin directory whenever
|
||||
// a user or container tries to use one by name. UNIX domain socket files must
|
||||
// be located under /run/containers/storage/plugins, whereas spec files can be
|
||||
// located either under /etc/containers/storage/plugins or
|
||||
// /usr/lib/containers/storage/plugins. This is handled by the Registry
|
||||
// interface, which lets you list all plugins or get a plugin by its name if it
|
||||
// exists.
|
||||
// be located under /run/container/storage/plugins, whereas spec files can be located
|
||||
// either under /etc/container/storage/plugins or /usr/lib/container/storage/plugins. This is handled
|
||||
// by the Registry interface, which lets you list all plugins or get a plugin by
|
||||
// its name if it exists.
|
||||
//
|
||||
// The plugins need to implement an HTTP server and bind this to the UNIX socket
|
||||
// or the address specified in the spec files.
|
||||
// A handshake is send at /Plugin.Activate, and plugins are expected to return
|
||||
// a Manifest with a list of subsystems which this plugin implements. As of
|
||||
// this writing, the known subsystem is "GraphDriver".
|
||||
// a Manifest with a list of of Docker subsystems which this plugin implements.
|
||||
//
|
||||
// In order to use a plugins, you can use the ``Get`` with the name of the
|
||||
// plugin and the subsystem it implements.
|
||||
|
@ -43,9 +41,14 @@ type plugins struct {
|
|||
plugins map[string]*Plugin
|
||||
}
|
||||
|
||||
type extpointHandlers struct {
|
||||
sync.RWMutex
|
||||
extpointHandlers map[string][]func(string, *Client)
|
||||
}
|
||||
|
||||
var (
|
||||
storage = plugins{plugins: make(map[string]*Plugin)}
|
||||
extpointHandlers = make(map[string]func(string, *Client))
|
||||
storage = plugins{plugins: make(map[string]*Plugin)}
|
||||
handlers = extpointHandlers{extpointHandlers: make(map[string][]func(string, *Client))}
|
||||
)
|
||||
|
||||
// Manifest lists what a plugin implements.
|
||||
|
@ -54,7 +57,7 @@ type Manifest struct {
|
|||
Implements []string
|
||||
}
|
||||
|
||||
// Plugin is the definition of a storage plugin.
|
||||
// Plugin is the definition of a container/storage plugin.
|
||||
type Plugin struct {
|
||||
// Name of the plugin
|
||||
name string
|
||||
|
@ -67,12 +70,12 @@ type Plugin struct {
|
|||
// Manifest of the plugin (see above)
|
||||
Manifest *Manifest `json:"-"`
|
||||
|
||||
// error produced by activation
|
||||
activateErr error
|
||||
// specifies if the activation sequence is completed (not if it is successful or not)
|
||||
activated bool
|
||||
// wait for activation to finish
|
||||
activateWait *sync.Cond
|
||||
// error produced by activation
|
||||
activateErr error
|
||||
// keeps track of callback handlers run against this plugin
|
||||
handlersRun bool
|
||||
}
|
||||
|
||||
// Name returns the name of the plugin.
|
||||
|
@ -85,6 +88,11 @@ func (p *Plugin) Client() *Client {
|
|||
return p.client
|
||||
}
|
||||
|
||||
// IsV1 returns true for V1 plugins and false otherwise.
|
||||
func (p *Plugin) IsV1() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// NewLocalPlugin creates a new local plugin.
|
||||
func NewLocalPlugin(name, addr string) *Plugin {
|
||||
return &Plugin{
|
||||
|
@ -98,19 +106,51 @@ func NewLocalPlugin(name, addr string) *Plugin {
|
|||
|
||||
func (p *Plugin) activate() error {
|
||||
p.activateWait.L.Lock()
|
||||
if p.activated {
|
||||
|
||||
if p.activated() {
|
||||
p.runHandlers()
|
||||
p.activateWait.L.Unlock()
|
||||
return p.activateErr
|
||||
}
|
||||
|
||||
p.activateErr = p.activateWithLock()
|
||||
p.activated = true
|
||||
|
||||
p.runHandlers()
|
||||
p.activateWait.L.Unlock()
|
||||
p.activateWait.Broadcast()
|
||||
return p.activateErr
|
||||
}
|
||||
|
||||
// runHandlers runs the registered handlers for the implemented plugin types
|
||||
// This should only be run after activation, and while the activation lock is held.
|
||||
func (p *Plugin) runHandlers() {
|
||||
if !p.activated() {
|
||||
return
|
||||
}
|
||||
|
||||
handlers.RLock()
|
||||
if !p.handlersRun {
|
||||
for _, iface := range p.Manifest.Implements {
|
||||
hdlrs, handled := handlers.extpointHandlers[iface]
|
||||
if !handled {
|
||||
continue
|
||||
}
|
||||
for _, handler := range hdlrs {
|
||||
handler(p.name, p.client)
|
||||
}
|
||||
}
|
||||
p.handlersRun = true
|
||||
}
|
||||
handlers.RUnlock()
|
||||
|
||||
}
|
||||
|
||||
// activated returns if the plugin has already been activated.
|
||||
// This should only be called with the activation lock held
|
||||
func (p *Plugin) activated() bool {
|
||||
return p.Manifest != nil
|
||||
}
|
||||
|
||||
func (p *Plugin) activateWithLock() error {
|
||||
c, err := NewClient(p.Addr, p.TLSConfig)
|
||||
if err != nil {
|
||||
|
@ -124,20 +164,12 @@ func (p *Plugin) activateWithLock() error {
|
|||
}
|
||||
|
||||
p.Manifest = m
|
||||
|
||||
for _, iface := range m.Implements {
|
||||
handler, handled := extpointHandlers[iface]
|
||||
if !handled {
|
||||
continue
|
||||
}
|
||||
handler(p.name, p.client)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Plugin) waitActive() error {
|
||||
p.activateWait.L.Lock()
|
||||
for !p.activated {
|
||||
for !p.activated() && p.activateErr == nil {
|
||||
p.activateWait.Wait()
|
||||
}
|
||||
p.activateWait.L.Unlock()
|
||||
|
@ -145,7 +177,7 @@ func (p *Plugin) waitActive() error {
|
|||
}
|
||||
|
||||
func (p *Plugin) implements(kind string) bool {
|
||||
if err := p.waitActive(); err != nil {
|
||||
if p.Manifest == nil {
|
||||
return false
|
||||
}
|
||||
for _, driver := range p.Manifest.Implements {
|
||||
|
@ -183,6 +215,10 @@ func loadWithRetry(name string, retry bool) (*Plugin, error) {
|
|||
}
|
||||
|
||||
storage.Lock()
|
||||
if pl, exists := storage.plugins[name]; exists {
|
||||
storage.Unlock()
|
||||
return pl, pl.activate()
|
||||
}
|
||||
storage.plugins[name] = pl
|
||||
storage.Unlock()
|
||||
|
||||
|
@ -214,7 +250,7 @@ func Get(name, imp string) (*Plugin, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if pl.implements(imp) {
|
||||
if err := pl.waitActive(); err == nil && pl.implements(imp) {
|
||||
logrus.Debugf("%s implements: %s", name, imp)
|
||||
return pl, nil
|
||||
}
|
||||
|
@ -223,7 +259,26 @@ func Get(name, imp string) (*Plugin, error) {
|
|||
|
||||
// Handle adds the specified function to the extpointHandlers.
|
||||
func Handle(iface string, fn func(string, *Client)) {
|
||||
extpointHandlers[iface] = fn
|
||||
handlers.Lock()
|
||||
hdlrs, ok := handlers.extpointHandlers[iface]
|
||||
if !ok {
|
||||
hdlrs = []func(string, *Client){}
|
||||
}
|
||||
|
||||
hdlrs = append(hdlrs, fn)
|
||||
handlers.extpointHandlers[iface] = hdlrs
|
||||
|
||||
storage.Lock()
|
||||
for _, p := range storage.plugins {
|
||||
p.activateWait.L.Lock()
|
||||
if p.activated() && p.implements(iface) {
|
||||
p.handlersRun = false
|
||||
}
|
||||
p.activateWait.L.Unlock()
|
||||
}
|
||||
storage.Unlock()
|
||||
|
||||
handlers.Unlock()
|
||||
}
|
||||
|
||||
// GetAll returns all the plugins for the specified implementation
|
||||
|
@ -241,7 +296,10 @@ func GetAll(imp string) ([]*Plugin, error) {
|
|||
chPl := make(chan *plLoad, len(pluginNames))
|
||||
var wg sync.WaitGroup
|
||||
for _, name := range pluginNames {
|
||||
if pl, ok := storage.plugins[name]; ok {
|
||||
storage.Lock()
|
||||
pl, ok := storage.plugins[name]
|
||||
storage.Unlock()
|
||||
if ok {
|
||||
chPl <- &plLoad{pl, nil}
|
||||
continue
|
||||
}
|
||||
|
@ -263,7 +321,7 @@ func GetAll(imp string) ([]*Plugin, error) {
|
|||
logrus.Error(pl.err)
|
||||
continue
|
||||
}
|
||||
if pl.pl.implements(imp) {
|
||||
if err := pl.pl.waitActive(); err == nil && pl.pl.implements(imp) {
|
||||
out = append(out, pl.pl)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue