1package hcsshim 2 3import ( 4 "sync" 5 6 "github.com/sirupsen/logrus" 7) 8 9var prepareLayerLock sync.Mutex 10 11// PrepareLayer finds a mounted read-write layer matching layerId and enables the 12// the filesystem filter for use on that layer. This requires the paths to all 13// parent layers, and is necessary in order to view or interact with the layer 14// as an actual filesystem (reading and writing files, creating directories, etc). 15// Disabling the filter must be done via UnprepareLayer. 16func PrepareLayer(info DriverInfo, layerId string, parentLayerPaths []string) error { 17 title := "hcsshim::PrepareLayer " 18 logrus.Debugf(title+"flavour %d layerId %s", info.Flavour, layerId) 19 20 // Generate layer descriptors 21 layers, err := layerPathsToDescriptors(parentLayerPaths) 22 if err != nil { 23 return err 24 } 25 26 // Convert info to API calling convention 27 infop, err := convertDriverInfo(info) 28 if err != nil { 29 logrus.Error(err) 30 return err 31 } 32 33 // This lock is a temporary workaround for a Windows bug. Only allowing one 34 // call to prepareLayer at a time vastly reduces the chance of a timeout. 35 prepareLayerLock.Lock() 36 defer prepareLayerLock.Unlock() 37 err = prepareLayer(&infop, layerId, layers) 38 if err != nil { 39 err = makeErrorf(err, title, "layerId=%s flavour=%d", layerId, info.Flavour) 40 logrus.Error(err) 41 return err 42 } 43 44 logrus.Debugf(title+"succeeded flavour=%d layerId=%s", info.Flavour, layerId) 45 return nil 46} 47