osd: fix disk uuid management
- disk UUID should only be got for "disk" type device.
- It's not necessary to fail prepare job when failing to get disk UUID
- We should consider that `sgdisk` reports UUID even if there is no GPT.
Closes: https://github.com/rook/rook/issues/9948
Signed-off-by: Satoru Takeuchi <satoru.takeuchi@gmail.com>
(cherry picked from commit 4c46dd1abd)
This commit is contained in:
1 parent
600e5363f7
commit
573b4dfe62
3 files changed
+15
-7
No files matched your search
@@ -128,10 +128,12 @@ func PopulateDeviceInfo(d string, executor exec.Executor) (*sys.LocalDisk, error
|
||||
|
||||
// get the UUID for disks
|
||||
var diskUUID string
|
||||
if diskType != sys.PartType {
|
||||
diskUUID, err = sys.GetDiskUUID(d, executor)
|
||||
if diskType == sys.DiskType {
|
||||
uuid, err := sys.GetDiskUUID(d, executor)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
logger.Warning(err)
|
||||
} else {
|
||||
diskUUID = uuid
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ func checkMatchingDevice(checkDev sys.LocalDisk, devices []sys.LocalDisk) *sys.L
|
||||
// check if devices should be considered the same. the uuid can be
|
||||
// unstable, so we also use the reported serial and device name, which
|
||||
// appear to be more stable.
|
||||
if checkDev.UUID == dev.UUID {
|
||||
if checkDev.UUID != "" && dev.UUID != "" && checkDev.UUID == dev.UUID {
|
||||
return &devices[i]
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/rook/rook/pkg/util/exec"
|
||||
)
|
||||
@@ -255,8 +257,7 @@ func GetDeviceFilesystems(device string, executor exec.Executor) (string, error)
|
||||
// GetDiskUUID look up the UUID for a disk.
|
||||
func GetDiskUUID(device string, executor exec.Executor) (string, error) {
|
||||
if _, err := osexec.LookPath(sgdiskCmd); err != nil {
|
||||
logger.Warningf("sgdisk not found. skipping disk UUID.")
|
||||
return "sgdiskNotFound", nil
|
||||
return "", errors.Wrap(err, "sgdisk not found")
|
||||
}
|
||||
|
||||
devicePath := strings.Split(device, "/")
|
||||
@@ -266,7 +267,7 @@ func GetDiskUUID(device string, executor exec.Executor) (string, error) {
|
||||
|
||||
output, err := executor.ExecuteCommandWithOutput(sgdiskCmd, "--print", device)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", errors.Wrapf(err, "sgdisk failed. output=%s", output)
|
||||
}
|
||||
|
||||
return parseUUID(device, output)
|
||||
@@ -329,6 +330,11 @@ func parseUUID(device, output string) (string, error) {
|
||||
// find the line with the uuid
|
||||
lines := strings.Split(output, "\n")
|
||||
for _, line := range lines {
|
||||
// If GPT is not found in a disk, sgdisk creates a new GPT in memory and reports its UUID.
|
||||
// This ID changes each call and is not appropriate to identify the device.
|
||||
if strings.Contains(line, "Creating new GPT entries in memory.") {
|
||||
break
|
||||
}
|
||||
if strings.Contains(line, "Disk identifier (GUID)") {
|
||||
words := strings.Split(line, " ")
|
||||
for _, word := range words {
|
||||
|
||||
Reference in new issue
Block a user