...

Source file src/github.com/Microsoft/hcsshim/internal/lcow/disk.go

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

     1  //go:build windows
     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  // FormatDisk creates a utility vm, mounts the disk as a scsi disk onto to the VM
    16  // and then formats it with ext4. Disk is expected to be made offline before this
    17  // command is run. The following powershell commands:
    18  // 'Get-Disk -Number <disk num> | Set-Disk -IsOffline $true'
    19  // can be used to offline the disk.
    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) // No destination as not formatted
    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