Skip to content

Commit

Permalink
Merge pull request rook#10212 from cybozu-go/osd-fix-disk-uuid-manage…
Browse files Browse the repository at this point in the history
…ment

osd: fix disk uuid management
  • Loading branch information
satoru-takeuchi committed May 9, 2022
2 parents 85a4c86 + 4c46dd1 commit 286e824
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 5 additions & 3 deletions pkg/clusterd/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/discover/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down
12 changes: 9 additions & 3 deletions pkg/util/sys/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"strconv"
"strings"

"github.com/pkg/errors"

"github.com/google/uuid"
"github.com/rook/rook/pkg/util/exec"
)
Expand Down Expand Up @@ -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, "/")
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 286e824

Please sign in to comment.