Skip to content

Commit

Permalink
Merge pull request #145 from wongma7/partitiondiskgpt
Browse files Browse the repository at this point in the history
Don't count reserved partitions (gpt) when checking if any exist
  • Loading branch information
k8s-ci-robot authored Jun 3, 2021
2 parents 2b7dc43 + f49b740 commit 1bc6add
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions internal/os/disk/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ type API interface {
IsDiskInitialized(diskNumber uint32) (bool, error)
// InitializeDisk initializes the disk `diskNumber`
InitializeDisk(diskNumber uint32) error
// PartitionsExist checks if the disk `diskNumber` has any partitions.
PartitionsExist(diskNumber uint32) (bool, error)
// CreatePartitoin creates a partition in disk `diskNumber`
CreatePartition(diskNumber uint32) error
// BasicPartitionsExist checks if the disk `diskNumber` has any basic partitions.
BasicPartitionsExist(diskNumber uint32) (bool, error)
// CreateBasicPartition creates a partition in disk `diskNumber`
CreateBasicPartition(diskNumber uint32) error
// Rescan updates the host storage cache (re-enumerates disk, partition and volume objects)
Rescan() error
// GetDiskNumberByName gets a disk number by page83 ID (disk name)
Expand Down Expand Up @@ -157,8 +157,8 @@ func (DiskAPI) InitializeDisk(diskNumber uint32) error {
return nil
}

func (DiskAPI) PartitionsExist(diskNumber uint32) (bool, error) {
cmd := fmt.Sprintf("Get-Partition | Where DiskNumber -eq %d", diskNumber)
func (DiskAPI) BasicPartitionsExist(diskNumber uint32) (bool, error) {
cmd := fmt.Sprintf("Get-Partition | Where DiskNumber -eq %d | Where Type -eq Basic", diskNumber)
out, err := runExec(cmd)
if err != nil {
return false, fmt.Errorf("error checking presence of partitions on disk %d: %v, %v", diskNumber, out, err)
Expand All @@ -170,7 +170,7 @@ func (DiskAPI) PartitionsExist(diskNumber uint32) (bool, error) {
return false, nil
}

func (DiskAPI) CreatePartition(diskNumber uint32) error {
func (DiskAPI) CreateBasicPartition(diskNumber uint32) error {
cmd := fmt.Sprintf("New-Partition -DiskNumber %d -UseMaximumSize", diskNumber)
out, err := runExec(cmd)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions internal/server/disk/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ func (s *Server) PartitionDisk(context context.Context, request *internal.Partit
klog.V(4).Infof("Disk %d already initialized", diskNumber)
}

klog.V(4).Infof("Checking if disk %d is partitioned", diskNumber)
partitioned, err := s.hostAPI.PartitionsExist(diskNumber)
klog.V(4).Infof("Checking if disk %d has basic partitions", diskNumber)
partitioned, err := s.hostAPI.BasicPartitionsExist(diskNumber)
if err != nil {
klog.Errorf("failed check PartitionsExist %v", err)
klog.Errorf("failed check BasicPartitionsExist %v", err)
return response, err
}
if !partitioned {
klog.V(4).Infof("Creating partition on disk %d", diskNumber)
err = s.hostAPI.CreatePartition(diskNumber)
klog.V(4).Infof("Creating basic partition on disk %d", diskNumber)
err = s.hostAPI.CreateBasicPartition(diskNumber)
if err != nil {
klog.Errorf("failed CreatePartition %v", err)
klog.Errorf("failed CreateBasicPartition %v", err)
return response, err
}
} else {
Expand Down

0 comments on commit 1bc6add

Please sign in to comment.