diff --git a/examples/rbd/storageclass.yaml b/examples/rbd/storageclass.yaml index ced2eaafe..80b421412 100644 --- a/examples/rbd/storageclass.yaml +++ b/examples/rbd/storageclass.yaml @@ -69,6 +69,12 @@ parameters: # on supported nodes # mounter: rbd-nbd + # (optional) ceph client log location, eg: rbd-nbd + # By default host-path /var/log/ceph of node is bind-mounted into + # csi-rbdplugin pod at /var/log/ceph mount path. See docs/rbd-nbd.md + # for available configuration options. + # cephLogDir: /var/log/ceph + # (optional) Prefix to use for naming RBD images. # If omitted, defaults to "csi-vol-". # volumeNamePrefix: "foo-bar-" diff --git a/internal/rbd/nodeserver.go b/internal/rbd/nodeserver.go index 6f6642028..6ba99034b 100644 --- a/internal/rbd/nodeserver.go +++ b/internal/rbd/nodeserver.go @@ -274,6 +274,7 @@ func (ns *NodeServer) NodeStageVolume( volOptions.MapOptions = req.GetVolumeContext()["mapOptions"] volOptions.UnmapOptions = req.GetVolumeContext()["unmapOptions"] volOptions.Mounter = req.GetVolumeContext()["mounter"] + volOptions.LogDir = req.GetVolumeContext()["cephLogDir"] err = volOptions.Connect(cr) if err != nil { diff --git a/internal/rbd/rbd_attach.go b/internal/rbd/rbd_attach.go index 81c7487a1..822782e2f 100644 --- a/internal/rbd/rbd_attach.go +++ b/internal/rbd/rbd_attach.go @@ -296,6 +296,14 @@ func createPath(ctx context.Context, volOpt *rbdVolume, device string, cr *util. util.WarningLog(ctx, "failed to detect if image %q is thick-provisioned: %v", volOpt, err) } + if isNbd { + if volOpt.LogDir == "" { + volOpt.LogDir = defaultLogDir + } + mapArgs = append(mapArgs, "--log-file", + getCephClientLogFileName(volOpt.VolID, volOpt.LogDir, "rbd-nbd")) + } + cli := rbd if device != "" { // TODO: use rbd cli for attach/detach in the future diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 8a6a24352..f6bbea5f6 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -50,6 +50,7 @@ const ( rbdImageWatcherSteps = 10 rbdDefaultMounter = "rbd" rbdNbdMounter = "rbd-nbd" + defaultLogDir = "/var/log/ceph" // Output strings returned during invocation of "ceph rbd task add remove " when // command is not supported by ceph manager. Used to check errors and recover when the command @@ -136,6 +137,7 @@ type rbdVolume struct { ReservedID string MapOptions string UnmapOptions string + LogDir string VolName string `json:"volName"` MonValueFromSecret string `json:"monValueFromSecret"` VolSize int64 `json:"volSize"` @@ -2002,3 +2004,16 @@ func (ri *rbdImage) addSnapshotScheduling( return nil } + +// getCephClientLogFileName compiles the complete log file path based on inputs. +func getCephClientLogFileName(id, logDir, prefix string) string { + if prefix == "" { + prefix = "ceph" + } + + if logDir == "" { + logDir = defaultLogDir + } + + return fmt.Sprintf("%s/%s-%s.log", logDir, prefix, id) +}