2015-06-05 16:09:53 -04:00
|
|
|
package graphdriver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2016-10-20 19:40:59 -04:00
|
|
|
"io"
|
2016-12-10 11:40:01 -05:00
|
|
|
"path/filepath"
|
2015-06-05 16:09:53 -04:00
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/archive"
|
2016-11-19 11:41:07 -05:00
|
|
|
"github.com/docker/docker/pkg/idtools"
|
2016-11-30 16:02:45 -05:00
|
|
|
"github.com/docker/docker/pkg/plugingetter"
|
2017-03-20 14:38:17 -04:00
|
|
|
"github.com/docker/docker/pkg/plugins"
|
2015-06-05 16:09:53 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type graphDriverProxy struct {
|
2016-12-10 11:40:01 -05:00
|
|
|
name string
|
|
|
|
p plugingetter.CompatPlugin
|
2017-03-20 14:38:17 -04:00
|
|
|
caps Capabilities
|
2015-06-05 16:09:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type graphDriverRequest struct {
|
2016-11-19 11:41:07 -05:00
|
|
|
ID string `json:",omitempty"`
|
|
|
|
Parent string `json:",omitempty"`
|
|
|
|
MountLabel string `json:",omitempty"`
|
|
|
|
StorageOpt map[string]string `json:",omitempty"`
|
2015-06-05 16:09:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type graphDriverResponse struct {
|
2017-03-20 14:38:17 -04:00
|
|
|
Err string `json:",omitempty"`
|
|
|
|
Dir string `json:",omitempty"`
|
|
|
|
Exists bool `json:",omitempty"`
|
|
|
|
Status [][2]string `json:",omitempty"`
|
|
|
|
Changes []archive.Change `json:",omitempty"`
|
|
|
|
Size int64 `json:",omitempty"`
|
|
|
|
Metadata map[string]string `json:",omitempty"`
|
|
|
|
Capabilities Capabilities `json:",omitempty"`
|
2015-06-05 16:09:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type graphDriverInitRequest struct {
|
2016-11-19 11:41:07 -05:00
|
|
|
Home string
|
|
|
|
Opts []string `json:"Opts"`
|
|
|
|
UIDMaps []idtools.IDMap `json:"UIDMaps"`
|
|
|
|
GIDMaps []idtools.IDMap `json:"GIDMaps"`
|
2015-06-05 16:09:53 -04:00
|
|
|
}
|
|
|
|
|
2016-11-19 11:41:07 -05:00
|
|
|
func (d *graphDriverProxy) Init(home string, opts []string, uidMaps, gidMaps []idtools.IDMap) error {
|
2016-11-30 16:02:45 -05:00
|
|
|
if !d.p.IsV1() {
|
|
|
|
if cp, ok := d.p.(plugingetter.CountedPlugin); ok {
|
|
|
|
// always acquire here, it will be cleaned up on daemon shutdown
|
|
|
|
cp.Acquire()
|
|
|
|
}
|
|
|
|
}
|
2015-06-05 16:09:53 -04:00
|
|
|
args := &graphDriverInitRequest{
|
2016-11-19 11:41:07 -05:00
|
|
|
Home: home,
|
|
|
|
Opts: opts,
|
|
|
|
UIDMaps: uidMaps,
|
|
|
|
GIDMaps: gidMaps,
|
2015-06-05 16:09:53 -04:00
|
|
|
}
|
|
|
|
var ret graphDriverResponse
|
2016-12-10 11:40:01 -05:00
|
|
|
if err := d.p.Client().Call("GraphDriver.Init", args, &ret); err != nil {
|
2015-06-05 16:09:53 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if ret.Err != "" {
|
|
|
|
return errors.New(ret.Err)
|
|
|
|
}
|
2017-03-20 14:38:17 -04:00
|
|
|
caps, err := d.fetchCaps()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
d.caps = caps
|
2015-06-05 16:09:53 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-03-20 14:38:17 -04:00
|
|
|
func (d *graphDriverProxy) fetchCaps() (Capabilities, error) {
|
|
|
|
args := &graphDriverRequest{}
|
|
|
|
var ret graphDriverResponse
|
|
|
|
if err := d.p.Client().Call("GraphDriver.Capabilities", args, &ret); err != nil {
|
|
|
|
if !plugins.IsNotFound(err) {
|
|
|
|
return Capabilities{}, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret.Capabilities, nil
|
|
|
|
}
|
|
|
|
|
2015-06-05 16:09:53 -04:00
|
|
|
func (d *graphDriverProxy) String() string {
|
|
|
|
return d.name
|
|
|
|
}
|
|
|
|
|
2017-03-20 14:38:17 -04:00
|
|
|
func (d *graphDriverProxy) Capabilities() Capabilities {
|
|
|
|
return d.caps
|
|
|
|
}
|
|
|
|
|
2016-11-09 15:59:58 -05:00
|
|
|
func (d *graphDriverProxy) CreateReadWrite(id, parent string, opts *CreateOpts) error {
|
2017-02-28 05:12:02 -05:00
|
|
|
return d.create("GraphDriver.CreateReadWrite", id, parent, opts)
|
2016-02-18 20:24:59 -05:00
|
|
|
}
|
|
|
|
|
2016-11-09 15:59:58 -05:00
|
|
|
func (d *graphDriverProxy) Create(id, parent string, opts *CreateOpts) error {
|
2017-02-28 05:12:02 -05:00
|
|
|
return d.create("GraphDriver.Create", id, parent, opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *graphDriverProxy) create(method, id, parent string, opts *CreateOpts) error {
|
2015-06-05 16:09:53 -04:00
|
|
|
args := &graphDriverRequest{
|
2016-11-19 11:41:07 -05:00
|
|
|
ID: id,
|
|
|
|
Parent: parent,
|
|
|
|
}
|
|
|
|
if opts != nil {
|
|
|
|
args.MountLabel = opts.MountLabel
|
|
|
|
args.StorageOpt = opts.StorageOpt
|
2015-06-05 16:09:53 -04:00
|
|
|
}
|
|
|
|
var ret graphDriverResponse
|
2017-02-28 05:12:02 -05:00
|
|
|
if err := d.p.Client().Call(method, args, &ret); err != nil {
|
2015-06-05 16:09:53 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if ret.Err != "" {
|
|
|
|
return errors.New(ret.Err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *graphDriverProxy) Remove(id string) error {
|
|
|
|
args := &graphDriverRequest{ID: id}
|
|
|
|
var ret graphDriverResponse
|
2016-12-10 11:40:01 -05:00
|
|
|
if err := d.p.Client().Call("GraphDriver.Remove", args, &ret); err != nil {
|
2015-06-05 16:09:53 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if ret.Err != "" {
|
|
|
|
return errors.New(ret.Err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *graphDriverProxy) Get(id, mountLabel string) (string, error) {
|
|
|
|
args := &graphDriverRequest{
|
|
|
|
ID: id,
|
|
|
|
MountLabel: mountLabel,
|
|
|
|
}
|
|
|
|
var ret graphDriverResponse
|
2016-12-10 11:40:01 -05:00
|
|
|
if err := d.p.Client().Call("GraphDriver.Get", args, &ret); err != nil {
|
2015-06-05 16:09:53 -04:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
var err error
|
|
|
|
if ret.Err != "" {
|
|
|
|
err = errors.New(ret.Err)
|
|
|
|
}
|
2016-12-10 11:40:01 -05:00
|
|
|
return filepath.Join(d.p.BasePath(), ret.Dir), err
|
2015-06-05 16:09:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *graphDriverProxy) Put(id string) error {
|
|
|
|
args := &graphDriverRequest{ID: id}
|
|
|
|
var ret graphDriverResponse
|
2016-12-10 11:40:01 -05:00
|
|
|
if err := d.p.Client().Call("GraphDriver.Put", args, &ret); err != nil {
|
2015-06-05 16:09:53 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if ret.Err != "" {
|
|
|
|
return errors.New(ret.Err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *graphDriverProxy) Exists(id string) bool {
|
|
|
|
args := &graphDriverRequest{ID: id}
|
|
|
|
var ret graphDriverResponse
|
2016-12-10 11:40:01 -05:00
|
|
|
if err := d.p.Client().Call("GraphDriver.Exists", args, &ret); err != nil {
|
2015-06-05 16:09:53 -04:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return ret.Exists
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *graphDriverProxy) Status() [][2]string {
|
|
|
|
args := &graphDriverRequest{}
|
|
|
|
var ret graphDriverResponse
|
2016-12-10 11:40:01 -05:00
|
|
|
if err := d.p.Client().Call("GraphDriver.Status", args, &ret); err != nil {
|
2015-06-05 16:09:53 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return ret.Status
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *graphDriverProxy) GetMetadata(id string) (map[string]string, error) {
|
|
|
|
args := &graphDriverRequest{
|
|
|
|
ID: id,
|
|
|
|
}
|
|
|
|
var ret graphDriverResponse
|
2016-12-10 11:40:01 -05:00
|
|
|
if err := d.p.Client().Call("GraphDriver.GetMetadata", args, &ret); err != nil {
|
2015-06-05 16:09:53 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if ret.Err != "" {
|
|
|
|
return nil, errors.New(ret.Err)
|
|
|
|
}
|
|
|
|
return ret.Metadata, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *graphDriverProxy) Cleanup() error {
|
2016-11-30 16:02:45 -05:00
|
|
|
if !d.p.IsV1() {
|
|
|
|
if cp, ok := d.p.(plugingetter.CountedPlugin); ok {
|
|
|
|
// always release
|
|
|
|
defer cp.Release()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-05 16:09:53 -04:00
|
|
|
args := &graphDriverRequest{}
|
|
|
|
var ret graphDriverResponse
|
2016-12-10 11:40:01 -05:00
|
|
|
if err := d.p.Client().Call("GraphDriver.Cleanup", args, &ret); err != nil {
|
2015-06-05 16:09:53 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if ret.Err != "" {
|
|
|
|
return errors.New(ret.Err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-10-20 19:40:59 -04:00
|
|
|
func (d *graphDriverProxy) Diff(id, parent string) (io.ReadCloser, error) {
|
2015-06-05 16:09:53 -04:00
|
|
|
args := &graphDriverRequest{
|
|
|
|
ID: id,
|
|
|
|
Parent: parent,
|
|
|
|
}
|
2016-12-10 11:40:01 -05:00
|
|
|
body, err := d.p.Client().Stream("GraphDriver.Diff", args)
|
2015-06-05 16:09:53 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-10-20 19:40:59 -04:00
|
|
|
return body, nil
|
2015-06-05 16:09:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *graphDriverProxy) Changes(id, parent string) ([]archive.Change, error) {
|
|
|
|
args := &graphDriverRequest{
|
|
|
|
ID: id,
|
|
|
|
Parent: parent,
|
|
|
|
}
|
|
|
|
var ret graphDriverResponse
|
2016-12-10 11:40:01 -05:00
|
|
|
if err := d.p.Client().Call("GraphDriver.Changes", args, &ret); err != nil {
|
2015-06-05 16:09:53 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if ret.Err != "" {
|
|
|
|
return nil, errors.New(ret.Err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret.Changes, nil
|
|
|
|
}
|
|
|
|
|
2016-10-20 19:40:59 -04:00
|
|
|
func (d *graphDriverProxy) ApplyDiff(id, parent string, diff io.Reader) (int64, error) {
|
2015-06-05 16:09:53 -04:00
|
|
|
var ret graphDriverResponse
|
2016-12-10 11:40:01 -05:00
|
|
|
if err := d.p.Client().SendFile(fmt.Sprintf("GraphDriver.ApplyDiff?id=%s&parent=%s", id, parent), diff, &ret); err != nil {
|
2015-06-05 16:09:53 -04:00
|
|
|
return -1, err
|
|
|
|
}
|
|
|
|
if ret.Err != "" {
|
|
|
|
return -1, errors.New(ret.Err)
|
|
|
|
}
|
|
|
|
return ret.Size, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *graphDriverProxy) DiffSize(id, parent string) (int64, error) {
|
|
|
|
args := &graphDriverRequest{
|
|
|
|
ID: id,
|
|
|
|
Parent: parent,
|
|
|
|
}
|
|
|
|
var ret graphDriverResponse
|
2016-12-10 11:40:01 -05:00
|
|
|
if err := d.p.Client().Call("GraphDriver.DiffSize", args, &ret); err != nil {
|
2015-06-05 16:09:53 -04:00
|
|
|
return -1, err
|
|
|
|
}
|
|
|
|
if ret.Err != "" {
|
|
|
|
return -1, errors.New(ret.Err)
|
|
|
|
}
|
|
|
|
return ret.Size, nil
|
|
|
|
}
|