Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't count reserved partitions (gpt) when checking if any exist #145

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

@andyzhangx andyzhangx Sep 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wongma7 if it's a MBR disk, Type would be IFS, so this change would break existing MBR disk, and before 1.22, default windows disk type would be MBR disk, that's a breaking and incompatible change.

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