From 75abc4ad3630af97374e33589ac180d2802ba2d2 Mon Sep 17 00:00:00 2001 From: praveengt Date: Tue, 6 Apr 2021 20:27:03 +0530 Subject: [PATCH 1/5] Multi Disk changes --- pkg/device/device-util.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/pkg/device/device-util.go b/pkg/device/device-util.go index 7493c8a5..0fb2b21f 100644 --- a/pkg/device/device-util.go +++ b/pkg/device/device-util.go @@ -39,7 +39,7 @@ const ( PartitionPrint = "parted /dev/%s unit b print --script" PartitionCreate = "parted /dev/%s mkpart %s %dMiB %dMiB --script" PartitionDelete = "parted /dev/%s rm %d --script" - PartitionWipeFS = "wipefs -a /dev/%s%d" + PartitionWipeFS = "wipefs --force -a /dev/%s%d" ) type partUsed struct { @@ -85,12 +85,32 @@ func CreateVolume(vol *apis.DeviceVolume) error { klog.Errorf("findBestPart Failed") return err } - return createPart(disk, start, partitionName, capacityMiB) + return wipefsAndCreatePart(disk, start, partitionName, capacityMiB, diskMetaName) } -func createPart(disk string, start uint64, partitionName string, size uint64) error { +// DeletePart Todo +func wipefsAndCreatePart(disk string, start uint64, partitionName string, size uint64, diskMetaName string) error { + klog.Infof("Creating Partition %s %s", partitionName, diskMetaName) _, err := RunCommand(strings.Split(fmt.Sprintf(PartitionCreate, disk, partitionName, start, start+size), " ")) + if err != nil { + klog.Errorf("Create Partition failed %s", err) + return err + } + + pList, err := getAllPartsUsed(diskMetaName, partitionName) + if err != nil { + klog.Errorf("GetAllPartsUsed failed %s", err) + return err + } + + klog.Infof("Running WipeFS for Partition %s %d", pList[0].DiskName, pList[0].PartNum) + _, err = RunCommand(strings.Split(fmt.Sprintf(PartitionWipeFS, pList[0].DiskName, pList[0].PartNum), " ")) + if err != nil { + klog.Errorf("WipeFS failed %s", err) + return err + } return err + } // getAllPartsFree Todo From af2ceb65528e12195e529c6f13298b272a1ae2d9 Mon Sep 17 00:00:00 2001 From: Akhil Mohan Date: Thu, 8 Apr 2021 12:37:06 +0530 Subject: [PATCH 2/5] get partition path and run wipefs Signed-off-by: Akhil Mohan --- pkg/device/device-util.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/device/device-util.go b/pkg/device/device-util.go index 0fb2b21f..5b87f68c 100644 --- a/pkg/device/device-util.go +++ b/pkg/device/device-util.go @@ -39,7 +39,7 @@ const ( PartitionPrint = "parted /dev/%s unit b print --script" PartitionCreate = "parted /dev/%s mkpart %s %dMiB %dMiB --script" PartitionDelete = "parted /dev/%s rm %d --script" - PartitionWipeFS = "wipefs --force -a /dev/%s%d" + PartitionWipeFS = "wipefs --force -a %s" ) type partUsed struct { @@ -104,7 +104,7 @@ func wipefsAndCreatePart(disk string, start uint64, partitionName string, size u } klog.Infof("Running WipeFS for Partition %s %d", pList[0].DiskName, pList[0].PartNum) - _, err = RunCommand(strings.Split(fmt.Sprintf(PartitionWipeFS, pList[0].DiskName, pList[0].PartNum), " ")) + _, err = RunCommand(strings.Split(fmt.Sprintf(PartitionWipeFS, getPartitionPath(pList[0].DiskName, pList[0].PartNum)), " ")) if err != nil { klog.Errorf("WipeFS failed %s", err) return err @@ -203,7 +203,7 @@ func DestroyVolume(vol *apis.DeviceVolume) error { // DeletePart Todo func wipefsAndDeletePart(disk string, partNum uint32) error { - _, err := RunCommand(strings.Split(fmt.Sprintf(getPartitionPath(disk, partNum), disk, partNum), " ")) + _, err := RunCommand(strings.Split(fmt.Sprintf(PartitionWipeFS, getPartitionPath(disk, partNum)), " ")) if err != nil { klog.Errorf("WipeFS failed %s", err) return err From 5d97c1761931c4f599bdabc4b27bf6da08a4f152 Mon Sep 17 00:00:00 2001 From: Akhil Mohan Date: Thu, 8 Apr 2021 14:18:41 +0530 Subject: [PATCH 3/5] refactor the code to separate wipefs function Signed-off-by: Akhil Mohan --- pkg/device/device-util.go | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/pkg/device/device-util.go b/pkg/device/device-util.go index 5b87f68c..7c4120d0 100644 --- a/pkg/device/device-util.go +++ b/pkg/device/device-util.go @@ -103,14 +103,12 @@ func wipefsAndCreatePart(disk string, start uint64, partitionName string, size u return err } - klog.Infof("Running WipeFS for Partition %s %d", pList[0].DiskName, pList[0].PartNum) - _, err = RunCommand(strings.Split(fmt.Sprintf(PartitionWipeFS, getPartitionPath(pList[0].DiskName, pList[0].PartNum)), " ")) + err = wipeFsPartition(pList[0].DiskName, pList[0].PartNum) if err != nil { - klog.Errorf("WipeFS failed %s", err) - return err + klog.Infof("Deleting partition %d on disk %s because wipefs failed", pList[0].PartNum, pList[0].DiskName) + return deletePartition(pList[0].DiskName, pList[0].PartNum) } - return err - + return nil } // getAllPartsFree Todo @@ -201,16 +199,29 @@ func DestroyVolume(vol *apis.DeviceVolume) error { } -// DeletePart Todo func wipefsAndDeletePart(disk string, partNum uint32) error { - _, err := RunCommand(strings.Split(fmt.Sprintf(PartitionWipeFS, getPartitionPath(disk, partNum)), " ")) + err := wipeFsPartition(disk, partNum) if err != nil { - klog.Errorf("WipeFS failed %s", err) return err } - _, err = RunCommand(strings.Split(fmt.Sprintf(PartitionDelete, disk, partNum), " ")) + return deletePartition(disk, partNum) +} + +// deletes the given partition from the disk +func deletePartition(disk string, partNum uint32) error { + _, err := RunCommand(strings.Split(fmt.Sprintf(PartitionDelete, disk, partNum), " ")) + if err != nil { + klog.Errorf("Delete Partition failed for disk: %s, partition: %d . Error: %s", disk, partNum, err) + } + return err +} + +// performs a force wipefs on the given partition +func wipeFsPartition(disk string, partNum uint32) error { + klog.Infof("Running WipeFS for disk: %s, partition %d", disk, partNum) + _, err := RunCommand(strings.Split(fmt.Sprintf(PartitionWipeFS, getPartitionPath(disk, partNum)), " ")) if err != nil { - klog.Errorf("Delete Partition failed %s", err) + klog.Errorf("WipeFS failed for disk: %s, partition: %d . Error: %s", disk, partNum, err) } return err } From eed63f194f7bdc44bb1572e1e9ae685cf2f27679 Mon Sep 17 00:00:00 2001 From: Akhil Mohan Date: Thu, 8 Apr 2021 15:55:12 +0530 Subject: [PATCH 4/5] add error messages Signed-off-by: Akhil Mohan --- pkg/device/device-util.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/device/device-util.go b/pkg/device/device-util.go index 7c4120d0..5f9f743e 100644 --- a/pkg/device/device-util.go +++ b/pkg/device/device-util.go @@ -106,7 +106,10 @@ func wipefsAndCreatePart(disk string, start uint64, partitionName string, size u err = wipeFsPartition(pList[0].DiskName, pList[0].PartNum) if err != nil { klog.Infof("Deleting partition %d on disk %s because wipefs failed", pList[0].PartNum, pList[0].DiskName) - return deletePartition(pList[0].DiskName, pList[0].PartNum) + _ = deletePartition(pList[0].DiskName, pList[0].PartNum) + // the error will be returned irrespective of the return value of delete partition, + // as create partition has failed. + return err } return nil } From 3948c9541cbca0d3bfce62e4dd6d2a8700b3b5f7 Mon Sep 17 00:00:00 2001 From: Akhil Mohan Date: Thu, 8 Apr 2021 18:20:49 +0530 Subject: [PATCH 5/5] add error message for deletepartition Signed-off-by: Akhil Mohan --- pkg/device/device-util.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/device/device-util.go b/pkg/device/device-util.go index 5f9f743e..e55288fe 100644 --- a/pkg/device/device-util.go +++ b/pkg/device/device-util.go @@ -106,7 +106,10 @@ func wipefsAndCreatePart(disk string, start uint64, partitionName string, size u err = wipeFsPartition(pList[0].DiskName, pList[0].PartNum) if err != nil { klog.Infof("Deleting partition %d on disk %s because wipefs failed", pList[0].PartNum, pList[0].DiskName) - _ = deletePartition(pList[0].DiskName, pList[0].PartNum) + err1 := deletePartition(pList[0].DiskName, pList[0].PartNum) + if err1 != nil { + klog.Errorf("could not delete partition %d on disk %s, created during CreateVolume(). Error: %s", pList[0].PartNum, pList[0].DiskName, err1) + } // the error will be returned irrespective of the return value of delete partition, // as create partition has failed. return err