...

Source file src/github.com/Microsoft/hcsshim/cmd/shimdiag/share.go

Documentation: github.com/Microsoft/hcsshim/cmd/shimdiag

     1  //go:build windows
     2  
     3  package main
     4  
     5  import (
     6  	"context"
     7  	"fmt"
     8  
     9  	"github.com/Microsoft/hcsshim/internal/appargs"
    10  	"github.com/Microsoft/hcsshim/internal/shimdiag"
    11  	"github.com/urfave/cli"
    12  )
    13  
    14  // LCOW root FS VHD is mounted read only so the only place you can mount a directory
    15  // is over an existing mount point like /home etc. Single file mapping will not work and
    16  // will return 'mkdir /path: read-only file system'. You can set the preferred root fs type
    17  // to initrd to circumvent this.
    18  
    19  var shareCommand = cli.Command{
    20  	Name:      "share",
    21  	Usage:     "Share a file/directory in a shim's hosting utility VM",
    22  	ArgsUsage: "[flags] <shim name> <host_path> <uvm_path>",
    23  	Flags: []cli.Flag{
    24  		cli.BoolFlag{
    25  			Name:  "readonly,ro",
    26  			Usage: "Make the directory/file being shared read only",
    27  		},
    28  	},
    29  	Before: appargs.Validate(appargs.String, appargs.String, appargs.String),
    30  	Action: func(c *cli.Context) error {
    31  		args := c.Args()
    32  		var (
    33  			readOnly = c.Bool("readonly")
    34  			shimName = args[0]
    35  			hostPath = args[1]
    36  			uvmPath  = args[2]
    37  		)
    38  		shim, err := shimdiag.GetShim(shimName)
    39  		if err != nil {
    40  			return err
    41  		}
    42  
    43  		req := &shimdiag.ShareRequest{
    44  			HostPath: hostPath,
    45  			UvmPath:  uvmPath,
    46  			ReadOnly: readOnly,
    47  		}
    48  
    49  		svc := shimdiag.NewShimDiagClient(shim)
    50  		_, err = svc.DiagShare(context.Background(), req)
    51  		if err != nil {
    52  			return fmt.Errorf("failed to share directory %s into UVM: %s", hostPath, err)
    53  		}
    54  
    55  		fmt.Printf("Shared %s into %s at %s\n", hostPath, shimName, uvmPath)
    56  		return nil
    57  	},
    58  }
    59  

View as plain text