Skip to content

Commit

Permalink
server: Check the work directory in the monitor
Browse files Browse the repository at this point in the history
Longhorn 4738

Signed-off-by: Shuo Wu <shuo.wu@suse.com>
  • Loading branch information
shuo-wu authored and innobead committed Oct 27, 2022
1 parent 3e25f70 commit d50357f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
type Manager struct {
diskUUID string
diskPath string
workDir string
backingImages map[string]*BackingImage

portRangeMin int32
Expand Down Expand Up @@ -65,6 +66,7 @@ func NewManager(diskUUID, diskPath, portRange string, shutdownCh chan error) (*M
m := &Manager{
diskUUID: diskUUID,
diskPath: diskPath,
workDir: workDir,
backingImages: map[string]*BackingImage{},

portRangeMin: start,
Expand Down Expand Up @@ -129,6 +131,17 @@ func (m *Manager) startMonitoring() {
}
}
m.lock.RUnlock()

if workDirStat, err := os.Stat(m.workDir); os.IsNotExist(err) || (workDirStat != nil && !workDirStat.IsDir()) {
if err := os.RemoveAll(m.workDir); err != nil {
m.log.WithError(err).Error("Backing Image Manager: detected the backing image work directory becoming invalid but failed to do cleanup")
continue
}
if err := os.Mkdir(m.workDir, 0666); err != nil && !os.IsExist(err) {
m.log.WithError(err).Error("Backing Image Manager: failed to recreate the backing image work directory after cleaning up the invalid one")
continue
}
}
}
if done {
break
Expand Down

1 comment on commit d50357f

@csnelsonchu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask what is this fix for?

Please sign in to comment.