Skip to content

Commit

Permalink
ceph: release the LV immediately after the osd process exits
Browse files Browse the repository at this point in the history
When the OSD is running on a PVC, the LV needs to be released immediately
after the OSD process exits. The cleanup was being skipped when the OSD
process exited and returning an error rather than allowing the
LV cleanup to proceed.

Signed-off-by: Travis Nielsen <[email protected]>
  • Loading branch information
travisn authored and binoue committed Apr 10, 2020
1 parent 0ee420d commit ea29e34
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions pkg/daemon/ceph/osd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import (
"os"
"os/signal"
"regexp"
"strconv"
"syscall"
"time"

"strings"

Expand Down Expand Up @@ -82,14 +80,14 @@ func StartOSD(context *clusterd.Context, osdType, osdID, osdUUID, lvPath string,

// run the ceph-osd daemon
if err := context.Executor.ExecuteCommand(false, "", "ceph-osd", cephArgs...); err != nil {
return fmt.Errorf("failed to start osd. %+v", err)
// Instead of returning, we want to allow the lvm release to happen below, so we just log the err
logger.Errorf("failed to start osd or shutting down. %+v", err)
}

if pvcBackedOSD {
if err := releaseLVMDevice(context, volumeGroupName); err != nil {
return fmt.Errorf("failed to release device from lvm. %+v", err)
}

}

return nil
Expand All @@ -106,47 +104,25 @@ func handleTerminate(context *clusterd.Context, lvPath, volumeGroupName string)
if err != nil {
return fmt.Errorf("failed to kill ceph-osd process. %+v", err)
}
if err := releaseLVMDevice(context, volumeGroupName); err != nil {
return fmt.Errorf("failed to release device from lvm. %+v", err)
}
return nil
}
}
}

func killCephOSDProcess(context *clusterd.Context, lvPath string) error {

processKilled := false
pid, err := context.Executor.ExecuteCommandWithOutput(false, "", "fuser", "-a", lvPath)
if err != nil {
return fmt.Errorf("failed to retrieve process ID for - %s. Error %+v", lvPath, err)
}

logger.Debugf("process ID for ceph-osd: %s", pid)
logger.Infof("process ID for ceph-osd: %s", pid)

// shut down the osd-ceph process so that lvm release does not show device in use error.
if pid != "" {
if err := context.Executor.ExecuteCommand(false, "", "kill", pid); err != nil {
return fmt.Errorf("failed to delete ceph-osd process. %+v", err)
}
} else {
return nil
}

pidInt, err := strconv.Atoi(pid)
if err != nil {
return fmt.Errorf("failed to convert process ID - %s to string. Error %+v ", pid, err)
}
for !processKilled {
_, err := os.FindProcess(int(pidInt))
if err != nil {
logger.Infof("ceph-osd process deleted successfully")
processKilled = true
} else {
logger.Infof("ceph-osd process still running")
time.Sleep(2 * time.Second)
continue
}
}

return nil
Expand Down

0 comments on commit ea29e34

Please sign in to comment.