Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
| ... | ... |
@@ -208,7 +208,6 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r * |
| 208 | 208 |
output.Write(notVerboseBuffer.Bytes()) |
| 209 | 209 |
} |
| 210 | 210 |
|
| 211 |
- logrus.Debugf("isflushed %v", output.Flushed())
|
|
| 212 | 211 |
// Do not write the error in the http output if it's still empty. |
| 213 | 212 |
// This prevents from writing a 200(OK) when there is an internal error. |
| 214 | 213 |
if !output.Flushed() {
|
| ... | ... |
@@ -245,21 +245,23 @@ func (s *snapshotter) Mounts(ctx context.Context, key string) (snapshot.Mountabl |
| 245 | 245 |
} |
| 246 | 246 |
if l != nil {
|
| 247 | 247 |
id := identity.NewID() |
| 248 |
- rwlayer, err := s.opt.LayerStore.CreateRWLayer(id, l.ChainID(), nil) |
|
| 249 |
- if err != nil {
|
|
| 250 |
- return nil, err |
|
| 251 |
- } |
|
| 252 |
- rootfs, err := rwlayer.Mount("")
|
|
| 253 |
- if err != nil {
|
|
| 254 |
- return nil, err |
|
| 255 |
- } |
|
| 256 |
- mnt := []mount.Mount{{
|
|
| 257 |
- Source: rootfs.Path(), |
|
| 258 |
- Type: "bind", |
|
| 259 |
- Options: []string{"rbind"},
|
|
| 260 |
- }} |
|
| 261 |
- return &constMountable{
|
|
| 262 |
- mounts: mnt, |
|
| 248 |
+ var rwlayer layer.RWLayer |
|
| 249 |
+ return &mountable{
|
|
| 250 |
+ acquire: func() ([]mount.Mount, error) {
|
|
| 251 |
+ rwlayer, err = s.opt.LayerStore.CreateRWLayer(id, l.ChainID(), nil) |
|
| 252 |
+ if err != nil {
|
|
| 253 |
+ return nil, err |
|
| 254 |
+ } |
|
| 255 |
+ rootfs, err := rwlayer.Mount("")
|
|
| 256 |
+ if err != nil {
|
|
| 257 |
+ return nil, err |
|
| 258 |
+ } |
|
| 259 |
+ return []mount.Mount{{
|
|
| 260 |
+ Source: rootfs.Path(), |
|
| 261 |
+ Type: "bind", |
|
| 262 |
+ Options: []string{"rbind"},
|
|
| 263 |
+ }}, nil |
|
| 264 |
+ }, |
|
| 263 | 265 |
release: func() error {
|
| 264 | 266 |
_, err := s.opt.LayerStore.ReleaseRWLayer(rwlayer) |
| 265 | 267 |
return err |
| ... | ... |
@@ -269,17 +271,18 @@ func (s *snapshotter) Mounts(ctx context.Context, key string) (snapshot.Mountabl |
| 269 | 269 |
|
| 270 | 270 |
id, _ := s.getGraphDriverID(key) |
| 271 | 271 |
|
| 272 |
- rootfs, err := s.opt.GraphDriver.Get(id, "") |
|
| 273 |
- if err != nil {
|
|
| 274 |
- return nil, err |
|
| 275 |
- } |
|
| 276 |
- mnt := []mount.Mount{{
|
|
| 277 |
- Source: rootfs.Path(), |
|
| 278 |
- Type: "bind", |
|
| 279 |
- Options: []string{"rbind"},
|
|
| 280 |
- }} |
|
| 281 |
- return &constMountable{
|
|
| 282 |
- mounts: mnt, |
|
| 272 |
+ return &mountable{
|
|
| 273 |
+ acquire: func() ([]mount.Mount, error) {
|
|
| 274 |
+ rootfs, err := s.opt.GraphDriver.Get(id, "") |
|
| 275 |
+ if err != nil {
|
|
| 276 |
+ return nil, err |
|
| 277 |
+ } |
|
| 278 |
+ return []mount.Mount{{
|
|
| 279 |
+ Source: rootfs.Path(), |
|
| 280 |
+ Type: "bind", |
|
| 281 |
+ Options: []string{"rbind"},
|
|
| 282 |
+ }}, nil |
|
| 283 |
+ }, |
|
| 283 | 284 |
release: func() error {
|
| 284 | 285 |
return s.opt.GraphDriver.Put(id) |
| 285 | 286 |
}, |
| ... | ... |
@@ -428,18 +431,37 @@ func (s *snapshotter) Close() error {
|
| 428 | 428 |
return s.db.Close() |
| 429 | 429 |
} |
| 430 | 430 |
|
| 431 |
-type constMountable struct {
|
|
| 431 |
+type mountable struct {
|
|
| 432 |
+ mu sync.Mutex |
|
| 432 | 433 |
mounts []mount.Mount |
| 434 |
+ acquire func() ([]mount.Mount, error) |
|
| 433 | 435 |
release func() error |
| 434 | 436 |
} |
| 435 | 437 |
|
| 436 |
-func (m *constMountable) Mount() ([]mount.Mount, error) {
|
|
| 438 |
+func (m *mountable) Mount() ([]mount.Mount, error) {
|
|
| 439 |
+ m.mu.Lock() |
|
| 440 |
+ defer m.mu.Unlock() |
|
| 441 |
+ |
|
| 442 |
+ if m.mounts != nil {
|
|
| 443 |
+ return m.mounts, nil |
|
| 444 |
+ } |
|
| 445 |
+ |
|
| 446 |
+ mounts, err := m.acquire() |
|
| 447 |
+ if err != nil {
|
|
| 448 |
+ return nil, err |
|
| 449 |
+ } |
|
| 450 |
+ m.mounts = mounts |
|
| 451 |
+ |
|
| 437 | 452 |
return m.mounts, nil |
| 438 | 453 |
} |
| 439 | 454 |
|
| 440 |
-func (m *constMountable) Release() error {
|
|
| 455 |
+func (m *mountable) Release() error {
|
|
| 456 |
+ m.mu.Lock() |
|
| 457 |
+ defer m.mu.Unlock() |
|
| 441 | 458 |
if m.release == nil {
|
| 442 | 459 |
return nil |
| 443 | 460 |
} |
| 461 |
+ |
|
| 462 |
+ m.mounts = nil |
|
| 444 | 463 |
return m.release() |
| 445 | 464 |
} |