...
1
2
3 package main
4
5 import (
6 gcontext "context"
7
8 "github.com/Microsoft/hcsshim/internal/appargs"
9 "github.com/Microsoft/hcsshim/internal/lcow"
10 "github.com/Microsoft/hcsshim/internal/oc"
11 "github.com/Microsoft/hcsshim/internal/uvm"
12 "github.com/Microsoft/hcsshim/osversion"
13 "github.com/pkg/errors"
14 "github.com/urfave/cli"
15 )
16
17 const (
18
19 prepareDiskStr = "prepare-disk"
20 )
21
22 var prepareDiskCommand = cli.Command{
23 Name: prepareDiskStr,
24 Usage: "format a disk with ext4",
25 Description: "Format a disk with ext4. To be used prior to exposing a pass-through disk. Prerequisite is that disk should be offline ('Get-Disk -Number <disk num> | Set-Disk -IsOffline $true').",
26 Flags: []cli.Flag{
27 cli.StringFlag{
28 Name: "destpath",
29 Usage: "Required: describes the destination disk path",
30 },
31 },
32 Before: appargs.Validate(),
33 Action: func(context *cli.Context) (err error) {
34 ctx, span := oc.StartSpan(gcontext.Background(), prepareDiskStr)
35 defer span.End()
36 defer func() { oc.SetSpanStatus(span, err) }()
37
38 dest := context.String("destpath")
39 if dest == "" {
40 return errors.New("'destpath' is required")
41 }
42
43 if osversion.Build() < osversion.RS5 {
44 return errors.New("LCOW is not supported pre-RS5")
45 }
46
47 opts := uvm.NewDefaultOptionsLCOW("preparedisk-uvm", context.GlobalString("owner"))
48
49
50 opts.SCSIControllerCount = 1
51
52 preparediskUVM, err := uvm.CreateLCOW(ctx, opts)
53 if err != nil {
54 return errors.Wrapf(err, "failed to create '%s'", opts.ID)
55 }
56 defer preparediskUVM.Close()
57 if err := preparediskUVM.Start(ctx); err != nil {
58 return errors.Wrapf(err, "failed to start '%s'", opts.ID)
59 }
60 if err := lcow.FormatDisk(ctx, preparediskUVM, dest); err != nil {
61 return errors.Wrapf(err, "failed to format disk '%s' with ext4", opts.ID)
62 }
63
64 return nil
65 },
66 }
67
View as plain text