Skip to content

Commit 1bc6add

Browse files
authored
Merge pull request #145 from wongma7/partitiondiskgpt
Don't count reserved partitions (gpt) when checking if any exist
2 parents 2b7dc43 + f49b740 commit 1bc6add

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

internal/os/disk/api.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ type API interface {
3333
IsDiskInitialized(diskNumber uint32) (bool, error)
3434
// InitializeDisk initializes the disk `diskNumber`
3535
InitializeDisk(diskNumber uint32) error
36-
// PartitionsExist checks if the disk `diskNumber` has any partitions.
37-
PartitionsExist(diskNumber uint32) (bool, error)
38-
// CreatePartitoin creates a partition in disk `diskNumber`
39-
CreatePartition(diskNumber uint32) error
36+
// BasicPartitionsExist checks if the disk `diskNumber` has any basic partitions.
37+
BasicPartitionsExist(diskNumber uint32) (bool, error)
38+
// CreateBasicPartition creates a partition in disk `diskNumber`
39+
CreateBasicPartition(diskNumber uint32) error
4040
// Rescan updates the host storage cache (re-enumerates disk, partition and volume objects)
4141
Rescan() error
4242
// GetDiskNumberByName gets a disk number by page83 ID (disk name)
@@ -157,8 +157,8 @@ func (DiskAPI) InitializeDisk(diskNumber uint32) error {
157157
return nil
158158
}
159159

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

173-
func (DiskAPI) CreatePartition(diskNumber uint32) error {
173+
func (DiskAPI) CreateBasicPartition(diskNumber uint32) error {
174174
cmd := fmt.Sprintf("New-Partition -DiskNumber %d -UseMaximumSize", diskNumber)
175175
out, err := runExec(cmd)
176176
if err != nil {

internal/server/disk/server.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ func (s *Server) PartitionDisk(context context.Context, request *internal.Partit
6666
klog.V(4).Infof("Disk %d already initialized", diskNumber)
6767
}
6868

69-
klog.V(4).Infof("Checking if disk %d is partitioned", diskNumber)
70-
partitioned, err := s.hostAPI.PartitionsExist(diskNumber)
69+
klog.V(4).Infof("Checking if disk %d has basic partitions", diskNumber)
70+
partitioned, err := s.hostAPI.BasicPartitionsExist(diskNumber)
7171
if err != nil {
72-
klog.Errorf("failed check PartitionsExist %v", err)
72+
klog.Errorf("failed check BasicPartitionsExist %v", err)
7373
return response, err
7474
}
7575
if !partitioned {
76-
klog.V(4).Infof("Creating partition on disk %d", diskNumber)
77-
err = s.hostAPI.CreatePartition(diskNumber)
76+
klog.V(4).Infof("Creating basic partition on disk %d", diskNumber)
77+
err = s.hostAPI.CreateBasicPartition(diskNumber)
7878
if err != nil {
79-
klog.Errorf("failed CreatePartition %v", err)
79+
klog.Errorf("failed CreateBasicPartition %v", err)
8080
return response, err
8181
}
8282
} else {

0 commit comments

Comments
 (0)