Skip to content

Commit

Permalink
fix(disk): non-existing block device results in longhorn-manager to b…
Browse files Browse the repository at this point in the history
…e in Crashloopbackoff state

Non-existing block device results in longhorn-manager pods to be in Crashloopbackoff state.
When longhorn-manager pods are in Crashloopbackoff, users are unable to update the default-data-path setting.

In the fix, IsPotentialBlockDisk() blindly creates a diskSpec for the default data path. Disk monitor will update the diskStatus.

Longhorn 9073

Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit committed Jul 24, 2024
1 parent 45bef51 commit 7507d53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
11 changes: 1 addition & 10 deletions datastore/longhorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2584,16 +2584,7 @@ func (s *DataStore) needDefaultDiskCreation(dataPath string) bool {
}

// Do not create default block-type disk if v2 data engine is disabled
ok, err := types.IsBlockDisk(dataPath)
if err != nil {
logrus.WithError(err).Errorf("Failed to check if the data path %v is block-type", dataPath)
return false
}
if ok {
return false
}

return true
return !types.IsPotentialBlockDisk(dataPath)
}

func (s *DataStore) GetNodeRO(name string) (*longhorn.Node, error) {
Expand Down
22 changes: 7 additions & 15 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,34 +1055,26 @@ func IsBDF(addr string) bool {
return bdfPattern.MatchString(addr)
}

func IsBlockDisk(path string) (bool, error) {
func IsPotentialBlockDisk(path string) bool {
if IsBDF(path) {
return true, nil
return true
}

fileInfo, err := os.Stat(path)
if err != nil {
if !os.IsNotExist(err) {
return false, errors.Wrapf(err, "failed to stat %v for creating default disk", path)
}
if strings.HasPrefix(path, "/dev/") {
return false, errors.Wrapf(err, "creating default block-type disk %v is not supported", path)
}
logrus.WithError(err).Warnf("Failed to get file info for %v", path)
return strings.HasPrefix(path, "/dev/")
}

if fileInfo != nil && (fileInfo.Mode()&os.ModeDevice) == os.ModeDevice {
return true, nil
return true
}

return false, nil
return false
}

func CreateDefaultDisk(dataPath string, storageReservedPercentage int64) (map[string]longhorn.DiskSpec, error) {
ok, err := IsBlockDisk(dataPath)
if err != nil {
return nil, errors.Wrapf(err, "failed to check if %v is a block device", dataPath)
}
if ok {
if IsPotentialBlockDisk(dataPath) {
return map[string]longhorn.DiskSpec{
DefaultDiskPrefix + util.RandomID(): {
Type: longhorn.DiskTypeBlock,
Expand Down

0 comments on commit 7507d53

Please sign in to comment.