...
1
2
3 package lcow
4
5 import (
6 "context"
7 "errors"
8 "fmt"
9
10 "github.com/Microsoft/hcsshim/internal/log"
11 "github.com/Microsoft/hcsshim/internal/uvm"
12 "github.com/sirupsen/logrus"
13 )
14
15
16
17
18
19
20 func FormatDisk(ctx context.Context, lcowUVM *uvm.UtilityVM, destPath string) error {
21 if lcowUVM == nil {
22 return fmt.Errorf("no uvm")
23 }
24
25 if lcowUVM.OS() != "linux" {
26 return errors.New("lcow::FormatDisk requires a linux utility VM to operate")
27 }
28
29 log.G(ctx).WithFields(logrus.Fields{
30 "dest": destPath,
31 }).Debug("lcow::FormatDisk opts")
32
33 var options []string
34 scsi, err := lcowUVM.AddSCSIPhysicalDisk(ctx, destPath, "", false, options)
35 if err != nil {
36 return err
37 }
38
39 defer func() {
40 _ = scsi.Release(ctx)
41 }()
42
43 log.G(ctx).WithFields(logrus.Fields{
44 "dest": destPath,
45 "controller": scsi.Controller,
46 "lun": scsi.LUN,
47 }).Debug("lcow::FormatDisk device attached")
48
49 if err := formatDiskUvm(ctx, lcowUVM, scsi.Controller, scsi.LUN, destPath); err != nil {
50 return err
51 }
52 log.G(ctx).WithField("dest", destPath).Debug("lcow::FormatDisk complete")
53
54 return nil
55 }
56
View as plain text