rbd: remove per volume rbd-nbd logfiles on detach

- Update the meta stash with logDir details
- Use the same to remove logfile on unstage/unmap to be space efficient

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
Prasanna Kumar Kalever 2021-08-20 06:36:35 +05:30 committed by mergify[bot]
parent d67e88ccd0
commit ea3def0db2
3 changed files with 15 additions and 3 deletions

View File

@ -275,6 +275,9 @@ func (ns *NodeServer) NodeStageVolume(
volOptions.UnmapOptions = req.GetVolumeContext()["unmapOptions"] volOptions.UnmapOptions = req.GetVolumeContext()["unmapOptions"]
volOptions.Mounter = req.GetVolumeContext()["mounter"] volOptions.Mounter = req.GetVolumeContext()["mounter"]
volOptions.LogDir = req.GetVolumeContext()["cephLogDir"] volOptions.LogDir = req.GetVolumeContext()["cephLogDir"]
if volOptions.LogDir == "" {
volOptions.LogDir = defaultLogDir
}
err = volOptions.Connect(cr) err = volOptions.Connect(cr)
if err != nil { if err != nil {
@ -827,6 +830,7 @@ func (ns *NodeServer) NodeUnstageVolume(
encrypted: imgInfo.Encrypted, encrypted: imgInfo.Encrypted,
volumeID: req.GetVolumeId(), volumeID: req.GetVolumeId(),
unmapOptions: imgInfo.UnmapOptions, unmapOptions: imgInfo.UnmapOptions,
logDir: imgInfo.LogDir,
} }
if err = detachRBDImageOrDeviceSpec(ctx, dArgs); err != nil { if err = detachRBDImageOrDeviceSpec(ctx, dArgs); err != nil {
util.ErrorLog( util.ErrorLog(

View File

@ -88,6 +88,7 @@ type detachRBDImageArgs struct {
encrypted bool encrypted bool
volumeID string volumeID string
unmapOptions string unmapOptions string
logDir string
} }
// rbdGetDeviceList queries rbd about mapped devices and returns a list of rbdDeviceInfo // rbdGetDeviceList queries rbd about mapped devices and returns a list of rbdDeviceInfo
@ -306,9 +307,6 @@ func createPath(ctx context.Context, volOpt *rbdVolume, device string, cr *util.
} }
if isNbd { if isNbd {
if volOpt.LogDir == "" {
volOpt.LogDir = defaultLogDir
}
mapArgs = append(mapArgs, "--log-file", mapArgs = append(mapArgs, "--log-file",
getCephClientLogFileName(volOpt.VolID, volOpt.LogDir, "rbd-nbd")) getCephClientLogFileName(volOpt.VolID, volOpt.LogDir, "rbd-nbd"))
} }
@ -341,6 +339,7 @@ func createPath(ctx context.Context, volOpt *rbdVolume, device string, cr *util.
encrypted: volOpt.isEncrypted(), encrypted: volOpt.isEncrypted(),
volumeID: volOpt.VolID, volumeID: volOpt.VolID,
unmapOptions: volOpt.UnmapOptions, unmapOptions: volOpt.UnmapOptions,
logDir: volOpt.LogDir,
} }
detErr := detachRBDImageOrDeviceSpec(ctx, dArgs) detErr := detachRBDImageOrDeviceSpec(ctx, dArgs)
if detErr != nil { if detErr != nil {
@ -442,6 +441,13 @@ func detachRBDImageOrDeviceSpec(
return fmt.Errorf("rbd: unmap for spec (%s) failed (%w): (%s)", dArgs.imageOrDeviceSpec, err, stderr) return fmt.Errorf("rbd: unmap for spec (%s) failed (%w): (%s)", dArgs.imageOrDeviceSpec, err, stderr)
} }
if dArgs.isNbd && dArgs.logDir != "" {
logFile := getCephClientLogFileName(dArgs.volumeID, dArgs.logDir, "rbd-nbd")
if err = os.Remove(logFile); err != nil {
util.WarningLog(ctx, "failed to remove logfile: %s, error: %v",
logFile, err)
}
}
return nil return nil
} }

View File

@ -1525,6 +1525,7 @@ type rbdImageMetadataStash struct {
NbdAccess bool `json:"accessType"` NbdAccess bool `json:"accessType"`
Encrypted bool `json:"encrypted"` Encrypted bool `json:"encrypted"`
DevicePath string `json:"device"` // holds NBD device path for now DevicePath string `json:"device"` // holds NBD device path for now
LogDir string `json:"logDir"` // holds the client log path
} }
// file name in which image metadata is stashed. // file name in which image metadata is stashed.
@ -1555,6 +1556,7 @@ func stashRBDImageMetadata(volOptions *rbdVolume, metaDataPath string) error {
imgMeta.NbdAccess = false imgMeta.NbdAccess = false
if volOptions.Mounter == rbdTonbd && hasNBD { if volOptions.Mounter == rbdTonbd && hasNBD {
imgMeta.NbdAccess = true imgMeta.NbdAccess = true
imgMeta.LogDir = volOptions.LogDir
} }
encodedBytes, err := json.Marshal(imgMeta) encodedBytes, err := json.Marshal(imgMeta)