|
@@ -25,15 +25,29 @@ type volumeMetadata struct {
|
|
|
Labels map[string]string
|
|
|
}
|
|
|
|
|
|
-type volumeWithLabels struct {
|
|
|
+type volumeWrapper struct {
|
|
|
volume.Volume
|
|
|
labels map[string]string
|
|
|
+ scope string
|
|
|
}
|
|
|
|
|
|
-func (v volumeWithLabels) Labels() map[string]string {
|
|
|
+func (v volumeWrapper) Labels() map[string]string {
|
|
|
return v.labels
|
|
|
}
|
|
|
|
|
|
+func (v volumeWrapper) Scope() string {
|
|
|
+ return v.scope
|
|
|
+}
|
|
|
+
|
|
|
+func (v volumeWrapper) CachedPath() string {
|
|
|
+ if vv, ok := v.Volume.(interface {
|
|
|
+ CachedPath() string
|
|
|
+ }); ok {
|
|
|
+ return vv.CachedPath()
|
|
|
+ }
|
|
|
+ return v.Volume.Path()
|
|
|
+}
|
|
|
+
|
|
|
// New initializes a VolumeStore to keep
|
|
|
// reference counting of volumes in the system.
|
|
|
func New(rootPath string) (*VolumeStore, error) {
|
|
@@ -166,6 +180,10 @@ func (s *VolumeStore) list() ([]volume.Volume, []string, error) {
|
|
|
chVols <- vols{driverName: d.Name(), err: &OpErr{Err: err, Name: d.Name(), Op: "list"}}
|
|
|
return
|
|
|
}
|
|
|
+ for i, v := range vs {
|
|
|
+ vs[i] = volumeWrapper{v, s.labels[v.Name()], d.Scope()}
|
|
|
+ }
|
|
|
+
|
|
|
chVols <- vols{vols: vs}
|
|
|
}(vd)
|
|
|
}
|
|
@@ -291,7 +309,7 @@ func (s *VolumeStore) create(name, driverName string, opts, labels map[string]st
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return volumeWithLabels{v, labels}, nil
|
|
|
+ return volumeWrapper{v, labels, vd.Scope()}, nil
|
|
|
}
|
|
|
|
|
|
// GetWithRef gets a volume with the given name from the passed in driver and stores the ref
|
|
@@ -313,10 +331,8 @@ func (s *VolumeStore) GetWithRef(name, driverName, ref string) (volume.Volume, e
|
|
|
}
|
|
|
|
|
|
s.setNamed(v, ref)
|
|
|
- if labels, ok := s.labels[name]; ok {
|
|
|
- return volumeWithLabels{v, labels}, nil
|
|
|
- }
|
|
|
- return v, nil
|
|
|
+
|
|
|
+ return volumeWrapper{v, s.labels[name], vd.Scope()}, nil
|
|
|
}
|
|
|
|
|
|
// Get looks if a volume with the given name exists and returns it if so
|
|
@@ -376,7 +392,7 @@ func (s *VolumeStore) getVolume(name string) (volume.Volume, error) {
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
- return volumeWithLabels{vol, labels}, nil
|
|
|
+ return volumeWrapper{vol, labels, vd.Scope()}, nil
|
|
|
}
|
|
|
|
|
|
logrus.Debugf("Probing all drivers for volume with name: %s", name)
|
|
@@ -391,7 +407,7 @@ func (s *VolumeStore) getVolume(name string) (volume.Volume, error) {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
- return volumeWithLabels{v, labels}, nil
|
|
|
+ return volumeWrapper{v, labels, d.Scope()}, nil
|
|
|
}
|
|
|
return nil, errNoSuchVolume
|
|
|
}
|
|
@@ -412,7 +428,7 @@ func (s *VolumeStore) Remove(v volume.Volume) error {
|
|
|
}
|
|
|
|
|
|
logrus.Debugf("Removing volume reference: driver %s, name %s", v.DriverName(), name)
|
|
|
- vol := withoutLabels(v)
|
|
|
+ vol := unwrapVolume(v)
|
|
|
if err := vd.Remove(vol); err != nil {
|
|
|
return &OpErr{Err: err, Name: name, Op: "remove"}
|
|
|
}
|
|
@@ -465,6 +481,9 @@ func (s *VolumeStore) FilterByDriver(name string) ([]volume.Volume, error) {
|
|
|
if err != nil {
|
|
|
return nil, &OpErr{Err: err, Name: name, Op: "list"}
|
|
|
}
|
|
|
+ for i, v := range ls {
|
|
|
+ ls[i] = volumeWrapper{v, s.labels[v.Name()], vd.Scope()}
|
|
|
+ }
|
|
|
return ls, nil
|
|
|
}
|
|
|
|
|
@@ -497,8 +516,8 @@ func (s *VolumeStore) filter(vols []volume.Volume, f filterFunc) []volume.Volume
|
|
|
return ls
|
|
|
}
|
|
|
|
|
|
-func withoutLabels(v volume.Volume) volume.Volume {
|
|
|
- if vol, ok := v.(volumeWithLabels); ok {
|
|
|
+func unwrapVolume(v volume.Volume) volume.Volume {
|
|
|
+ if vol, ok := v.(volumeWrapper); ok {
|
|
|
return vol.Volume
|
|
|
}
|
|
|
|