From ea3def0db2534a74a99b0dd67a2c35a06c5b8020 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Fri, 20 Aug 2021 06:36:35 +0530 Subject: [PATCH] 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 --- internal/rbd/nodeserver.go | 4 ++++ internal/rbd/rbd_attach.go | 12 +++++++++--- internal/rbd/rbd_util.go | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/internal/rbd/nodeserver.go b/internal/rbd/nodeserver.go index 3e61f6a6b..03ddfee6f 100644 --- a/internal/rbd/nodeserver.go +++ b/internal/rbd/nodeserver.go @@ -275,6 +275,9 @@ func (ns *NodeServer) NodeStageVolume( volOptions.UnmapOptions = req.GetVolumeContext()["unmapOptions"] volOptions.Mounter = req.GetVolumeContext()["mounter"] volOptions.LogDir = req.GetVolumeContext()["cephLogDir"] + if volOptions.LogDir == "" { + volOptions.LogDir = defaultLogDir + } err = volOptions.Connect(cr) if err != nil { @@ -827,6 +830,7 @@ func (ns *NodeServer) NodeUnstageVolume( encrypted: imgInfo.Encrypted, volumeID: req.GetVolumeId(), unmapOptions: imgInfo.UnmapOptions, + logDir: imgInfo.LogDir, } if err = detachRBDImageOrDeviceSpec(ctx, dArgs); err != nil { util.ErrorLog( diff --git a/internal/rbd/rbd_attach.go b/internal/rbd/rbd_attach.go index 28bb480a5..98d16979a 100644 --- a/internal/rbd/rbd_attach.go +++ b/internal/rbd/rbd_attach.go @@ -88,6 +88,7 @@ type detachRBDImageArgs struct { encrypted bool volumeID string unmapOptions string + logDir string } // 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 volOpt.LogDir == "" { - volOpt.LogDir = defaultLogDir - } mapArgs = append(mapArgs, "--log-file", 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(), volumeID: volOpt.VolID, unmapOptions: volOpt.UnmapOptions, + logDir: volOpt.LogDir, } detErr := detachRBDImageOrDeviceSpec(ctx, dArgs) if detErr != nil { @@ -442,6 +441,13 @@ func detachRBDImageOrDeviceSpec( 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 } diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index f6bbea5f6..ad5727629 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -1525,6 +1525,7 @@ type rbdImageMetadataStash struct { NbdAccess bool `json:"accessType"` Encrypted bool `json:"encrypted"` 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. @@ -1555,6 +1556,7 @@ func stashRBDImageMetadata(volOptions *rbdVolume, metaDataPath string) error { imgMeta.NbdAccess = false if volOptions.Mounter == rbdTonbd && hasNBD { imgMeta.NbdAccess = true + imgMeta.LogDir = volOptions.LogDir } encodedBytes, err := json.Marshal(imgMeta)