Adds StorageDriverFactory, unifying creation of StorageDrivers
Custom storage drivers can register a factory to create the driver by name, similar to the database/sql package's Register and Open factory.Create returns an in-process driver if registered or an IPC driver if one can be found, erroring otherwise This standardizes parameter passing for creation of storage drivers Also adds documentation for storagedriver package and children
This commit is contained in:
parent
ff81f3a719
commit
ca0084fad1
15 changed files with 290 additions and 79 deletions
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/docker/libchan/spdy"
|
||||
)
|
||||
|
||||
// Storage Driver implementation using a managed child process communicating over IPC
|
||||
type StorageDriverClient struct {
|
||||
subprocess *exec.Cmd
|
||||
socket *os.File
|
||||
|
@ -22,6 +23,13 @@ type StorageDriverClient struct {
|
|||
sender libchan.Sender
|
||||
}
|
||||
|
||||
// Constructs a new out-of-process storage driver using the driver name and configuration parameters
|
||||
// Must call Start() on this driver client before remote method calls can be made
|
||||
//
|
||||
// Looks for drivers in the following locations in order:
|
||||
// - Storage drivers directory (to be determined, yet not implemented)
|
||||
// - $GOPATH/bin
|
||||
// - $PATH
|
||||
func NewDriverClient(name string, parameters map[string]string) (*StorageDriverClient, error) {
|
||||
paramsBytes, err := json.Marshal(parameters)
|
||||
if err != nil {
|
||||
|
@ -46,6 +54,7 @@ func NewDriverClient(name string, parameters map[string]string) (*StorageDriverC
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Starts the designated child process storage driver and binds a socket to this process for IPC
|
||||
func (driver *StorageDriverClient) Start() error {
|
||||
fileDescriptors, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM, 0)
|
||||
if err != nil {
|
||||
|
@ -93,6 +102,8 @@ func (driver *StorageDriverClient) Start() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Stops the child process storage driver
|
||||
// storagedriver.StorageDriver methods called after Stop() will fail
|
||||
func (driver *StorageDriverClient) Stop() error {
|
||||
closeSenderErr := driver.sender.Close()
|
||||
closeTransportErr := driver.transport.Close()
|
||||
|
@ -109,6 +120,8 @@ func (driver *StorageDriverClient) Stop() error {
|
|||
return killErr
|
||||
}
|
||||
|
||||
// Implement the storagedriver.StorageDriver interface over IPC
|
||||
|
||||
func (driver *StorageDriverClient) GetContent(path string) ([]byte, error) {
|
||||
receiver, remoteSender := libchan.Pipe()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue