From a4678200e5d4e1e567171ea75526e782486d3ca0 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Thu, 23 Feb 2023 18:07:43 +0100 Subject: [PATCH] rbd: allow setting `mkfsOptions` in the StorageClass Add `mkfsOptions` to the StorageClass and pass them to the `mkfs` command while creating the filesystem on the RBD device. Fixes: #374 Signed-off-by: Niels de Vos --- docs/deploy-rbd.md | 1 + examples/rbd/storageclass.yaml | 11 +++++++++++ internal/rbd/nodeserver.go | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/docs/deploy-rbd.md b/docs/deploy-rbd.md index 0f3838f72..270d734d1 100644 --- a/docs/deploy-rbd.md +++ b/docs/deploy-rbd.md @@ -61,6 +61,7 @@ make image-cephcsi | `volumeNamePrefix` | no | Prefix to use for naming RBD images (defaults to `csi-vol-`). | | `snapshotNamePrefix` | no | Prefix to use for naming RBD snapshot images (defaults to `csi-snap-`). | | `imageFeatures` | no | RBD image features. CSI RBD currently supports `layering`, `journaling`, `exclusive-lock`, `object-map`, `fast-diff`, `deep-flatten` features. deep-flatten is added for cloned images. Refer for image feature dependencies. | +| `mkfsOptions` | no | Options to pass to the `mkfs` command while creating the filesystem on the RBD device. Check the man-page for the `mkfs` command for the filesystem for more details. When `mkfsOptions` is set here, the defaults will not be used, consider including them in this parameter. | | `tryOtherMounters` | no | Specifies whether to try other mounters in case if the current mounter fails to mount the rbd image for any reason | | `mapOptions` | no | Map options to use when mapping rbd image. See [krbd](https://docs.ceph.com/docs/master/man/8/rbd/#kernel-rbd-krbd-options) and [nbd](https://docs.ceph.com/docs/master/man/8/rbd-nbd/#options) options. | | `unmapOptions` | no | Unmap options to use when unmapping rbd image. See [krbd](https://docs.ceph.com/docs/master/man/8/rbd/#kernel-rbd-krbd-options) and [nbd](https://docs.ceph.com/docs/master/man/8/rbd-nbd/#options) options. | diff --git a/examples/rbd/storageclass.yaml b/examples/rbd/storageclass.yaml index 7270b642b..0e476fa2b 100644 --- a/examples/rbd/storageclass.yaml +++ b/examples/rbd/storageclass.yaml @@ -37,6 +37,17 @@ parameters: # imageFeatures: layering,journaling,exclusive-lock,object-map,fast-diff imageFeatures: "layering" + # (optional) Options to pass to the `mkfs` command while creating the + # filesystem on the RBD device. Check the man-page for the `mkfs` command + # for the filesystem for more details. When `mkfsOptions` is set here, the + # defaults will not be used, consider including them in this parameter. + # + # The default options depend on the csi.storage.k8s.io/fstype setting: + # - ext4: "-m0 -Enodiscard,lazy_itable_init=1,lazy_journal_init=1" + # - xfs: "-onouuid -K" + # + # mkfsOptions: "-m0 -Ediscard -i1024" + # (optional) Specifies whether to try other mounters in case if the current # mounter fails to mount the rbd image for any reason. True means fallback # to next mounter, default is set to false. diff --git a/internal/rbd/nodeserver.go b/internal/rbd/nodeserver.go index 68b0f0a37..338b5791d 100644 --- a/internal/rbd/nodeserver.go +++ b/internal/rbd/nodeserver.go @@ -784,6 +784,15 @@ func (ns *NodeServer) mountVolumeToStagePath( if existingFormat == "" && !staticVol && !readOnly { args := mkfsDefaultArgs[fsType] + // if the VolumeContext contains "mkfsOptions", use those as args instead + volumeCtx := req.GetVolumeContext() + if volumeCtx != nil { + mkfsOptions := volumeCtx["mkfsOptions"] + if mkfsOptions != "" { + args = strings.Split(mkfsOptions, " ") + } + } + // add extra arguments depending on the filesystem mkfs := "mkfs." + fsType switch fsType {