Move some of the optional parameters of CreateRWLayer() in a struct
called CreateRWLayerOpts. This will make it easy to add more options
arguments without having to change signature of CreateRWLayer().
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
| ... | ... |
@@ -210,8 +210,13 @@ func (daemon *Daemon) setRWLayer(container *container.Container) error {
|
| 210 | 210 |
layerID = img.RootFS.ChainID() |
| 211 | 211 |
} |
| 212 | 212 |
|
| 213 |
- rwLayer, err := daemon.layerStore.CreateRWLayer(container.ID, layerID, container.MountLabel, daemon.getLayerInit(), container.HostConfig.StorageOpt) |
|
| 213 |
+ rwLayerOpts := &layer.CreateRWLayerOpts{
|
|
| 214 |
+ MountLabel: container.MountLabel, |
|
| 215 |
+ InitFunc: daemon.getLayerInit(), |
|
| 216 |
+ StorageOpt: container.HostConfig.StorageOpt, |
|
| 217 |
+ } |
|
| 214 | 218 |
|
| 219 |
+ rwLayer, err := daemon.layerStore.CreateRWLayer(container.ID, layerID, rwLayerOpts) |
|
| 215 | 220 |
if err != nil {
|
| 216 | 221 |
return err |
| 217 | 222 |
} |
| ... | ... |
@@ -126,7 +126,7 @@ func (ls *mockLayerStore) Get(chainID layer.ChainID) (layer.Layer, error) {
|
| 126 | 126 |
func (ls *mockLayerStore) Release(l layer.Layer) ([]layer.Metadata, error) {
|
| 127 | 127 |
return []layer.Metadata{}, nil
|
| 128 | 128 |
} |
| 129 |
-func (ls *mockLayerStore) CreateRWLayer(string, layer.ChainID, string, layer.MountInit, map[string]string) (layer.RWLayer, error) {
|
|
| 129 |
+func (ls *mockLayerStore) CreateRWLayer(string, layer.ChainID, *layer.CreateRWLayerOpts) (layer.RWLayer, error) {
|
|
| 130 | 130 |
return nil, errors.New("not implemented")
|
| 131 | 131 |
} |
| 132 | 132 |
|
| ... | ... |
@@ -169,6 +169,13 @@ type Metadata struct {
|
| 169 | 169 |
// RWLayer. |
| 170 | 170 |
type MountInit func(root string) error |
| 171 | 171 |
|
| 172 |
+// CreateRWLayerOpts contains optional arguments to be passed to CreateRWLayer |
|
| 173 |
+type CreateRWLayerOpts struct {
|
|
| 174 |
+ MountLabel string |
|
| 175 |
+ InitFunc MountInit |
|
| 176 |
+ StorageOpt map[string]string |
|
| 177 |
+} |
|
| 178 |
+ |
|
| 172 | 179 |
// Store represents a backend for managing both |
| 173 | 180 |
// read-only and read-write layers. |
| 174 | 181 |
type Store interface {
|
| ... | ... |
@@ -177,7 +184,7 @@ type Store interface {
|
| 177 | 177 |
Map() map[ChainID]Layer |
| 178 | 178 |
Release(Layer) ([]Metadata, error) |
| 179 | 179 |
|
| 180 |
- CreateRWLayer(id string, parent ChainID, mountLabel string, initFunc MountInit, storageOpt map[string]string) (RWLayer, error) |
|
| 180 |
+ CreateRWLayer(id string, parent ChainID, opts *CreateRWLayerOpts) (RWLayer, error) |
|
| 181 | 181 |
GetRWLayer(id string) (RWLayer, error) |
| 182 | 182 |
GetMountID(id string) (string, error) |
| 183 | 183 |
ReleaseRWLayer(RWLayer) ([]Metadata, error) |
| ... | ... |
@@ -444,7 +444,19 @@ func (ls *layerStore) Release(l Layer) ([]Metadata, error) {
|
| 444 | 444 |
return ls.releaseLayer(layer) |
| 445 | 445 |
} |
| 446 | 446 |
|
| 447 |
-func (ls *layerStore) CreateRWLayer(name string, parent ChainID, mountLabel string, initFunc MountInit, storageOpt map[string]string) (RWLayer, error) {
|
|
| 447 |
+func (ls *layerStore) CreateRWLayer(name string, parent ChainID, opts *CreateRWLayerOpts) (RWLayer, error) {
|
|
| 448 |
+ var ( |
|
| 449 |
+ storageOpt map[string]string |
|
| 450 |
+ initFunc MountInit |
|
| 451 |
+ mountLabel string |
|
| 452 |
+ ) |
|
| 453 |
+ |
|
| 454 |
+ if opts != nil {
|
|
| 455 |
+ mountLabel = opts.MountLabel |
|
| 456 |
+ storageOpt = opts.StorageOpt |
|
| 457 |
+ initFunc = opts.InitFunc |
|
| 458 |
+ } |
|
| 459 |
+ |
|
| 448 | 460 |
ls.mountL.Lock() |
| 449 | 461 |
defer ls.mountL.Unlock() |
| 450 | 462 |
m, ok := ls.mounts[name] |
| ... | ... |
@@ -84,7 +84,7 @@ type layerInit func(root string) error |
| 84 | 84 |
|
| 85 | 85 |
func createLayer(ls Store, parent ChainID, layerFunc layerInit) (Layer, error) {
|
| 86 | 86 |
containerID := stringid.GenerateRandomID() |
| 87 |
- mount, err := ls.CreateRWLayer(containerID, parent, "", nil, nil) |
|
| 87 |
+ mount, err := ls.CreateRWLayer(containerID, parent, nil) |
|
| 88 | 88 |
if err != nil {
|
| 89 | 89 |
return nil, err |
| 90 | 90 |
} |
| ... | ... |
@@ -276,7 +276,7 @@ func TestMountAndRegister(t *testing.T) {
|
| 276 | 276 |
size, _ := layer.Size() |
| 277 | 277 |
t.Logf("Layer size: %d", size)
|
| 278 | 278 |
|
| 279 |
- mount2, err := ls.CreateRWLayer("new-test-mount", layer.ChainID(), "", nil, nil)
|
|
| 279 |
+ mount2, err := ls.CreateRWLayer("new-test-mount", layer.ChainID(), nil)
|
|
| 280 | 280 |
if err != nil {
|
| 281 | 281 |
t.Fatal(err) |
| 282 | 282 |
} |
| ... | ... |
@@ -384,7 +384,7 @@ func TestStoreRestore(t *testing.T) {
|
| 384 | 384 |
t.Fatal(err) |
| 385 | 385 |
} |
| 386 | 386 |
|
| 387 |
- m, err := ls.CreateRWLayer("some-mount_name", layer3.ChainID(), "", nil, nil)
|
|
| 387 |
+ m, err := ls.CreateRWLayer("some-mount_name", layer3.ChainID(), nil)
|
|
| 388 | 388 |
if err != nil {
|
| 389 | 389 |
t.Fatal(err) |
| 390 | 390 |
} |
| ... | ... |
@@ -415,7 +415,7 @@ func TestStoreRestore(t *testing.T) {
|
| 415 | 415 |
assertLayerEqual(t, layer3b, layer3) |
| 416 | 416 |
|
| 417 | 417 |
// Create again with same name, should return error |
| 418 |
- if _, err := ls2.CreateRWLayer("some-mount_name", layer3b.ChainID(), "", nil, nil); err == nil {
|
|
| 418 |
+ if _, err := ls2.CreateRWLayer("some-mount_name", layer3b.ChainID(), nil); err == nil {
|
|
| 419 | 419 |
t.Fatal("Expected error creating mount with same name")
|
| 420 | 420 |
} else if err != ErrMountNameConflict {
|
| 421 | 421 |
t.Fatal(err) |
| ... | ... |
@@ -380,7 +380,7 @@ func TestMountMigration(t *testing.T) {
|
| 380 | 380 |
Kind: archive.ChangeAdd, |
| 381 | 381 |
}) |
| 382 | 382 |
|
| 383 |
- if _, err := ls.CreateRWLayer("migration-mount", layer1.ChainID(), "", nil, nil); err == nil {
|
|
| 383 |
+ if _, err := ls.CreateRWLayer("migration-mount", layer1.ChainID(), nil); err == nil {
|
|
| 384 | 384 |
t.Fatal("Expected error creating mount with same name")
|
| 385 | 385 |
} else if err != ErrMountNameConflict {
|
| 386 | 386 |
t.Fatal(err) |
| ... | ... |
@@ -32,7 +32,10 @@ func TestMountInit(t *testing.T) {
|
| 32 | 32 |
return initfile.ApplyFile(root) |
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 |
- m, err := ls.CreateRWLayer("fun-mount", layer.ChainID(), "", mountInit, nil)
|
|
| 35 |
+ rwLayerOpts := &CreateRWLayerOpts{
|
|
| 36 |
+ InitFunc: mountInit, |
|
| 37 |
+ } |
|
| 38 |
+ m, err := ls.CreateRWLayer("fun-mount", layer.ChainID(), rwLayerOpts)
|
|
| 36 | 39 |
if err != nil {
|
| 37 | 40 |
t.Fatal(err) |
| 38 | 41 |
} |
| ... | ... |
@@ -88,8 +91,11 @@ func TestMountSize(t *testing.T) {
|
| 88 | 88 |
mountInit := func(root string) error {
|
| 89 | 89 |
return newTestFile("file-init", contentInit, 0777).ApplyFile(root)
|
| 90 | 90 |
} |
| 91 |
+ rwLayerOpts := &CreateRWLayerOpts{
|
|
| 92 |
+ InitFunc: mountInit, |
|
| 93 |
+ } |
|
| 91 | 94 |
|
| 92 |
- m, err := ls.CreateRWLayer("mount-size", layer.ChainID(), "", mountInit, nil)
|
|
| 95 |
+ m, err := ls.CreateRWLayer("mount-size", layer.ChainID(), rwLayerOpts)
|
|
| 93 | 96 |
if err != nil {
|
| 94 | 97 |
t.Fatal(err) |
| 95 | 98 |
} |
| ... | ... |
@@ -137,8 +143,11 @@ func TestMountChanges(t *testing.T) {
|
| 137 | 137 |
mountInit := func(root string) error {
|
| 138 | 138 |
return initfile.ApplyFile(root) |
| 139 | 139 |
} |
| 140 |
+ rwLayerOpts := &CreateRWLayerOpts{
|
|
| 141 |
+ InitFunc: mountInit, |
|
| 142 |
+ } |
|
| 140 | 143 |
|
| 141 |
- m, err := ls.CreateRWLayer("mount-changes", layer.ChainID(), "", mountInit, nil)
|
|
| 144 |
+ m, err := ls.CreateRWLayer("mount-changes", layer.ChainID(), rwLayerOpts)
|
|
| 142 | 145 |
if err != nil {
|
| 143 | 146 |
t.Fatal(err) |
| 144 | 147 |
} |