Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
| ... | ... |
@@ -502,15 +502,9 @@ func (ls *layerStore) ReinitRWLayer(l RWLayer) error {
|
| 502 | 502 |
ls.mountL.Lock() |
| 503 | 503 |
defer ls.mountL.Unlock() |
| 504 | 504 |
|
| 505 |
- m, ok := ls.mounts[l.Name()] |
|
| 506 |
- if !ok {
|
|
| 505 |
+ if _, ok := ls.mounts[l.Name()]; !ok {
|
|
| 507 | 506 |
return ErrMountDoesNotExist |
| 508 | 507 |
} |
| 509 |
- |
|
| 510 |
- if err := m.incActivityCount(l); err != nil {
|
|
| 511 |
- return err |
|
| 512 |
- } |
|
| 513 |
- |
|
| 514 | 508 |
return nil |
| 515 | 509 |
} |
| 516 | 510 |
|
| ... | ... |
@@ -400,14 +400,11 @@ func TestStoreRestore(t *testing.T) {
|
| 400 | 400 |
if err := ioutil.WriteFile(filepath.Join(path, "testfile.txt"), []byte("nothing here"), 0644); err != nil {
|
| 401 | 401 |
t.Fatal(err) |
| 402 | 402 |
} |
| 403 |
- assertActivityCount(t, m, 1) |
|
| 404 | 403 |
|
| 405 | 404 |
if err := m.Unmount(); err != nil {
|
| 406 | 405 |
t.Fatal(err) |
| 407 | 406 |
} |
| 408 | 407 |
|
| 409 |
- assertActivityCount(t, m, 0) |
|
| 410 |
- |
|
| 411 | 408 |
ls2, err := NewStoreFromGraphDriver(ls.(*layerStore).store, ls.(*layerStore).driver) |
| 412 | 409 |
if err != nil {
|
| 413 | 410 |
t.Fatal(err) |
| ... | ... |
@@ -438,20 +435,15 @@ func TestStoreRestore(t *testing.T) {
|
| 438 | 438 |
t.Fatalf("Unexpected path %s, expected %s", mountPath, path)
|
| 439 | 439 |
} |
| 440 | 440 |
|
| 441 |
- assertActivityCount(t, m2, 1) |
|
| 442 |
- |
|
| 443 | 441 |
if mountPath, err := m2.Mount(""); err != nil {
|
| 444 | 442 |
t.Fatal(err) |
| 445 | 443 |
} else if path != mountPath {
|
| 446 | 444 |
t.Fatalf("Unexpected path %s, expected %s", mountPath, path)
|
| 447 | 445 |
} |
| 448 |
- assertActivityCount(t, m2, 2) |
|
| 449 | 446 |
if err := m2.Unmount(); err != nil {
|
| 450 | 447 |
t.Fatal(err) |
| 451 | 448 |
} |
| 452 | 449 |
|
| 453 |
- assertActivityCount(t, m2, 1) |
|
| 454 |
- |
|
| 455 | 450 |
b, err := ioutil.ReadFile(filepath.Join(path, "testfile.txt")) |
| 456 | 451 |
if err != nil {
|
| 457 | 452 |
t.Fatal(err) |
| ... | ... |
@@ -464,8 +456,6 @@ func TestStoreRestore(t *testing.T) {
|
| 464 | 464 |
t.Fatal(err) |
| 465 | 465 |
} |
| 466 | 466 |
|
| 467 |
- assertActivityCount(t, m2, 0) |
|
| 468 |
- |
|
| 469 | 467 |
if metadata, err := ls2.ReleaseRWLayer(m2); err != nil {
|
| 470 | 468 |
t.Fatal(err) |
| 471 | 469 |
} else if len(metadata) != 0 {
|
| ... | ... |
@@ -674,13 +664,6 @@ func assertReferences(t *testing.T, references ...Layer) {
|
| 674 | 674 |
} |
| 675 | 675 |
} |
| 676 | 676 |
|
| 677 |
-func assertActivityCount(t *testing.T, l RWLayer, expected int) {
|
|
| 678 |
- rl := l.(*referencedRWLayer) |
|
| 679 |
- if rl.activityCount != expected {
|
|
| 680 |
- t.Fatalf("Unexpected activity count %d, expected %d", rl.activityCount, expected)
|
|
| 681 |
- } |
|
| 682 |
-} |
|
| 683 |
- |
|
| 684 | 677 |
func TestRegisterExistingLayer(t *testing.T) {
|
| 685 | 678 |
ls, _, cleanup := newTestStore(t) |
| 686 | 679 |
defer cleanup() |
| ... | ... |
@@ -380,8 +380,6 @@ func TestMountMigration(t *testing.T) {
|
| 380 | 380 |
Kind: archive.ChangeAdd, |
| 381 | 381 |
}) |
| 382 | 382 |
|
| 383 |
- assertActivityCount(t, rwLayer1, 1) |
|
| 384 |
- |
|
| 385 | 383 |
if _, err := ls.CreateRWLayer("migration-mount", layer1.ChainID(), "", nil, nil); err == nil {
|
| 386 | 384 |
t.Fatal("Expected error creating mount with same name")
|
| 387 | 385 |
} else if err != ErrMountNameConflict {
|
| ... | ... |
@@ -401,16 +399,10 @@ func TestMountMigration(t *testing.T) {
|
| 401 | 401 |
t.Fatal(err) |
| 402 | 402 |
} |
| 403 | 403 |
|
| 404 |
- assertActivityCount(t, rwLayer2, 1) |
|
| 405 |
- assertActivityCount(t, rwLayer1, 1) |
|
| 406 |
- |
|
| 407 | 404 |
if _, err := rwLayer2.Mount(""); err != nil {
|
| 408 | 405 |
t.Fatal(err) |
| 409 | 406 |
} |
| 410 | 407 |
|
| 411 |
- assertActivityCount(t, rwLayer2, 2) |
|
| 412 |
- assertActivityCount(t, rwLayer1, 1) |
|
| 413 |
- |
|
| 414 | 408 |
if metadata, err := ls.Release(layer1); err != nil {
|
| 415 | 409 |
t.Fatal(err) |
| 416 | 410 |
} else if len(metadata) > 0 {
|
| ... | ... |
@@ -420,8 +412,6 @@ func TestMountMigration(t *testing.T) {
|
| 420 | 420 |
if err := rwLayer1.Unmount(); err != nil {
|
| 421 | 421 |
t.Fatal(err) |
| 422 | 422 |
} |
| 423 |
- assertActivityCount(t, rwLayer2, 2) |
|
| 424 |
- assertActivityCount(t, rwLayer1, 0) |
|
| 425 | 423 |
|
| 426 | 424 |
if _, err := ls.ReleaseRWLayer(rwLayer1); err != nil {
|
| 427 | 425 |
t.Fatal(err) |
| ... | ... |
@@ -430,9 +420,6 @@ func TestMountMigration(t *testing.T) {
|
| 430 | 430 |
if err := rwLayer2.Unmount(); err != nil {
|
| 431 | 431 |
t.Fatal(err) |
| 432 | 432 |
} |
| 433 |
- if _, err := ls.ReleaseRWLayer(rwLayer2); err == nil {
|
|
| 434 |
- t.Fatal("Expected error deleting active mount")
|
|
| 435 |
- } |
|
| 436 | 433 |
if err := rwLayer2.Unmount(); err != nil {
|
| 437 | 434 |
t.Fatal(err) |
| 438 | 435 |
} |
| ... | ... |
@@ -2,7 +2,6 @@ package layer |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"io" |
| 5 |
- "sync" |
|
| 6 | 5 |
|
| 7 | 6 |
"github.com/docker/docker/pkg/archive" |
| 8 | 7 |
) |
| ... | ... |
@@ -83,106 +82,30 @@ func (ml *mountedLayer) hasReferences() bool {
|
| 83 | 83 |
return len(ml.references) > 0 |
| 84 | 84 |
} |
| 85 | 85 |
|
| 86 |
-func (ml *mountedLayer) incActivityCount(ref RWLayer) error {
|
|
| 87 |
- rl, ok := ml.references[ref] |
|
| 88 |
- if !ok {
|
|
| 89 |
- return ErrLayerNotRetained |
|
| 90 |
- } |
|
| 91 |
- |
|
| 92 |
- if err := rl.acquire(); err != nil {
|
|
| 93 |
- return err |
|
| 94 |
- } |
|
| 95 |
- return nil |
|
| 96 |
-} |
|
| 97 |
- |
|
| 98 | 86 |
func (ml *mountedLayer) deleteReference(ref RWLayer) error {
|
| 99 |
- rl, ok := ml.references[ref] |
|
| 100 |
- if !ok {
|
|
| 87 |
+ if _, ok := ml.references[ref]; !ok {
|
|
| 101 | 88 |
return ErrLayerNotRetained |
| 102 | 89 |
} |
| 103 |
- |
|
| 104 |
- if err := rl.release(); err != nil {
|
|
| 105 |
- return err |
|
| 106 |
- } |
|
| 107 | 90 |
delete(ml.references, ref) |
| 108 |
- |
|
| 109 | 91 |
return nil |
| 110 | 92 |
} |
| 111 | 93 |
|
| 112 | 94 |
func (ml *mountedLayer) retakeReference(r RWLayer) {
|
| 113 | 95 |
if ref, ok := r.(*referencedRWLayer); ok {
|
| 114 |
- ref.activityCount = 0 |
|
| 115 | 96 |
ml.references[ref] = ref |
| 116 | 97 |
} |
| 117 | 98 |
} |
| 118 | 99 |
|
| 119 | 100 |
type referencedRWLayer struct {
|
| 120 | 101 |
*mountedLayer |
| 121 |
- |
|
| 122 |
- activityL sync.Mutex |
|
| 123 |
- activityCount int |
|
| 124 |
-} |
|
| 125 |
- |
|
| 126 |
-func (rl *referencedRWLayer) acquire() error {
|
|
| 127 |
- rl.activityL.Lock() |
|
| 128 |
- defer rl.activityL.Unlock() |
|
| 129 |
- |
|
| 130 |
- rl.activityCount++ |
|
| 131 |
- |
|
| 132 |
- return nil |
|
| 133 |
-} |
|
| 134 |
- |
|
| 135 |
-func (rl *referencedRWLayer) release() error {
|
|
| 136 |
- rl.activityL.Lock() |
|
| 137 |
- defer rl.activityL.Unlock() |
|
| 138 |
- |
|
| 139 |
- if rl.activityCount > 0 {
|
|
| 140 |
- return ErrActiveMount |
|
| 141 |
- } |
|
| 142 |
- |
|
| 143 |
- rl.activityCount = -1 |
|
| 144 |
- |
|
| 145 |
- return nil |
|
| 146 | 102 |
} |
| 147 | 103 |
|
| 148 | 104 |
func (rl *referencedRWLayer) Mount(mountLabel string) (string, error) {
|
| 149 |
- rl.activityL.Lock() |
|
| 150 |
- defer rl.activityL.Unlock() |
|
| 151 |
- |
|
| 152 |
- if rl.activityCount == -1 {
|
|
| 153 |
- return "", ErrLayerNotRetained |
|
| 154 |
- } |
|
| 155 |
- |
|
| 156 |
- if rl.activityCount > 0 {
|
|
| 157 |
- rl.activityCount++ |
|
| 158 |
- return rl.path, nil |
|
| 159 |
- } |
|
| 160 |
- |
|
| 161 |
- m, err := rl.mountedLayer.Mount(mountLabel) |
|
| 162 |
- if err == nil {
|
|
| 163 |
- rl.activityCount++ |
|
| 164 |
- rl.path = m |
|
| 165 |
- } |
|
| 166 |
- return m, err |
|
| 105 |
+ return rl.mountedLayer.Mount(mountLabel) |
|
| 167 | 106 |
} |
| 168 | 107 |
|
| 169 | 108 |
// Unmount decrements the activity count and unmounts the underlying layer |
| 170 | 109 |
// Callers should only call `Unmount` once per call to `Mount`, even on error. |
| 171 | 110 |
func (rl *referencedRWLayer) Unmount() error {
|
| 172 |
- rl.activityL.Lock() |
|
| 173 |
- defer rl.activityL.Unlock() |
|
| 174 |
- |
|
| 175 |
- if rl.activityCount == 0 {
|
|
| 176 |
- return ErrNotMounted |
|
| 177 |
- } |
|
| 178 |
- if rl.activityCount == -1 {
|
|
| 179 |
- return ErrLayerNotRetained |
|
| 180 |
- } |
|
| 181 |
- |
|
| 182 |
- rl.activityCount-- |
|
| 183 |
- if rl.activityCount > 0 {
|
|
| 184 |
- return nil |
|
| 185 |
- } |
|
| 186 |
- |
|
| 187 | 111 |
return rl.mountedLayer.Unmount() |
| 188 | 112 |
} |