...

Source file src/github.com/Microsoft/hcsshim/internal/uvmfolder/locate.go

Documentation: github.com/Microsoft/hcsshim/internal/uvmfolder

     1  package uvmfolder
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  	"path/filepath"
     8  
     9  	"github.com/Microsoft/hcsshim/internal/log"
    10  	"github.com/sirupsen/logrus"
    11  )
    12  
    13  // LocateUVMFolder searches a set of layer folders to determine the "uppermost"
    14  // layer which has a utility VM image. The order of the layers is (for historical) reasons
    15  // Read-only-layers followed by an optional read-write layer. The RO layers are in reverse
    16  // order so that the upper-most RO layer is at the start, and the base OS layer is the
    17  // end.
    18  func LocateUVMFolder(ctx context.Context, layerFolders []string) (string, error) {
    19  	var uvmFolder string
    20  	index := 0
    21  	for _, layerFolder := range layerFolders {
    22  		_, err := os.Stat(filepath.Join(layerFolder, `UtilityVM`))
    23  		if err == nil {
    24  			uvmFolder = layerFolder
    25  			break
    26  		}
    27  		if !os.IsNotExist(err) {
    28  			return "", err
    29  		}
    30  		index++
    31  	}
    32  	if uvmFolder == "" {
    33  		return "", fmt.Errorf("utility VM folder could not be found in layers")
    34  	}
    35  	log.G(ctx).WithFields(logrus.Fields{
    36  		"index":  index + 1,
    37  		"count":  len(layerFolders),
    38  		"folder": uvmFolder,
    39  	}).Debug("hcsshim::LocateUVMFolder: found")
    40  	return uvmFolder, nil
    41  }
    42  

View as plain text