rbd: add "--options notrim" when mapping a thick-provisioned image

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2021-02-02 10:25:37 +01:00 committed by mergify[bot]
parent cc96bdaac3
commit b5020657e6

View File

@ -208,7 +208,7 @@ func attachRBDImage(ctx context.Context, volOptions *rbdVolume, cr *util.Credent
return devicePath, err return devicePath, err
} }
func appendDeviceTypeAndOptions(cmdArgs []string, isNbd bool, userOptions string) []string { func appendDeviceTypeAndOptions(cmdArgs []string, isNbd, isThick bool, userOptions string) []string {
accessType := accessTypeKRbd accessType := accessTypeKRbd
if isNbd { if isNbd {
accessType = accessTypeNbd accessType = accessTypeNbd
@ -221,6 +221,11 @@ func appendDeviceTypeAndOptions(cmdArgs []string, isNbd bool, userOptions string
// owned by the initial user namespace. // owned by the initial user namespace.
cmdArgs = append(cmdArgs, "--options", "noudev") cmdArgs = append(cmdArgs, "--options", "noudev")
} }
if isThick {
// When an image is thick-provisioned, any discard/unmap/trim
// requests should not free extents.
cmdArgs = append(cmdArgs, "--options", "notrim")
}
if userOptions != "" { if userOptions != "" {
// userOptions is appended after, possibly overriding the above // userOptions is appended after, possibly overriding the above
// default options. // default options.
@ -248,7 +253,13 @@ func createPath(ctx context.Context, volOpt *rbdVolume, cr *util.Credentials) (s
isNbd = true isNbd = true
} }
mapArgs = appendDeviceTypeAndOptions(mapArgs, isNbd, volOpt.MapOptions) // check if the image should stay thick-provisioned
isThick, err := volOpt.isThickProvisioned()
if err != nil {
util.WarningLog(ctx, "failed to detect if image %q is thick-provisioned: %v", volOpt.String(), err)
}
mapArgs = appendDeviceTypeAndOptions(mapArgs, isNbd, isThick, volOpt.MapOptions)
if volOpt.readOnly { if volOpt.readOnly {
mapArgs = append(mapArgs, "--read-only") mapArgs = append(mapArgs, "--read-only")
} }
@ -326,7 +337,7 @@ func detachRBDImageOrDeviceSpec(ctx context.Context, imageOrDeviceSpec string, i
} }
unmapArgs := []string{"unmap", imageOrDeviceSpec} unmapArgs := []string{"unmap", imageOrDeviceSpec}
unmapArgs = appendDeviceTypeAndOptions(unmapArgs, isNbd, unmapOptions) unmapArgs = appendDeviceTypeAndOptions(unmapArgs, isNbd, false, unmapOptions)
_, stderr, err := util.ExecCommand(ctx, rbd, unmapArgs...) _, stderr, err := util.ExecCommand(ctx, rbd, unmapArgs...)
if err != nil { if err != nil {