2015-05-27 16:15:14 -04:00
|
|
|
package hcsshim
|
|
|
|
|
2016-10-26 18:03:40 -04:00
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
2017-07-26 18:03:47 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-10-26 18:03:40 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var prepareLayerLock sync.Mutex
|
2015-05-27 16:15:14 -04:00
|
|
|
|
2015-08-27 18:46:00 -04:00
|
|
|
// PrepareLayer finds a mounted read-write layer matching layerId and enables the
|
|
|
|
// the filesystem filter for use on that layer. This requires the paths to all
|
|
|
|
// parent layers, and is necessary in order to view or interact with the layer
|
|
|
|
// as an actual filesystem (reading and writing files, creating directories, etc).
|
|
|
|
// Disabling the filter must be done via UnprepareLayer.
|
2015-05-27 16:15:14 -04:00
|
|
|
func PrepareLayer(info DriverInfo, layerId string, parentLayerPaths []string) error {
|
|
|
|
title := "hcsshim::PrepareLayer "
|
|
|
|
logrus.Debugf(title+"flavour %d layerId %s", info.Flavour, layerId)
|
|
|
|
|
|
|
|
// Generate layer descriptors
|
|
|
|
layers, err := layerPathsToDescriptors(parentLayerPaths)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert info to API calling convention
|
|
|
|
infop, err := convertDriverInfo(info)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Error(err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-10-26 18:03:40 -04:00
|
|
|
// This lock is a temporary workaround for a Windows bug. Only allowing one
|
|
|
|
// call to prepareLayer at a time vastly reduces the chance of a timeout.
|
|
|
|
prepareLayerLock.Lock()
|
|
|
|
defer prepareLayerLock.Unlock()
|
2016-02-01 18:09:35 -05:00
|
|
|
err = prepareLayer(&infop, layerId, layers)
|
|
|
|
if err != nil {
|
|
|
|
err = makeErrorf(err, title, "layerId=%s flavour=%d", layerId, info.Flavour)
|
2015-05-27 16:15:14 -04:00
|
|
|
logrus.Error(err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-10-12 19:34:03 -04:00
|
|
|
logrus.Debugf(title+"succeeded flavour=%d layerId=%s", info.Flavour, layerId)
|
2015-05-27 16:15:14 -04:00
|
|
|
return nil
|
|
|
|
}
|