mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-17 20:00:23 +00:00
rbd: add "--options notrim" when mapping a thick-provisioned image
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
cc96bdaac3
commit
b5020657e6
@ -208,7 +208,7 @@ func attachRBDImage(ctx context.Context, volOptions *rbdVolume, cr *util.Credent
|
||||
return devicePath, err
|
||||
}
|
||||
|
||||
func appendDeviceTypeAndOptions(cmdArgs []string, isNbd bool, userOptions string) []string {
|
||||
func appendDeviceTypeAndOptions(cmdArgs []string, isNbd, isThick bool, userOptions string) []string {
|
||||
accessType := accessTypeKRbd
|
||||
if isNbd {
|
||||
accessType = accessTypeNbd
|
||||
@ -221,6 +221,11 @@ func appendDeviceTypeAndOptions(cmdArgs []string, isNbd bool, userOptions string
|
||||
// owned by the initial user namespace.
|
||||
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 != "" {
|
||||
// userOptions is appended after, possibly overriding the above
|
||||
// default options.
|
||||
@ -248,7 +253,13 @@ func createPath(ctx context.Context, volOpt *rbdVolume, cr *util.Credentials) (s
|
||||
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 {
|
||||
mapArgs = append(mapArgs, "--read-only")
|
||||
}
|
||||
@ -326,7 +337,7 @@ func detachRBDImageOrDeviceSpec(ctx context.Context, imageOrDeviceSpec string, i
|
||||
}
|
||||
|
||||
unmapArgs := []string{"unmap", imageOrDeviceSpec}
|
||||
unmapArgs = appendDeviceTypeAndOptions(unmapArgs, isNbd, unmapOptions)
|
||||
unmapArgs = appendDeviceTypeAndOptions(unmapArgs, isNbd, false, unmapOptions)
|
||||
|
||||
_, stderr, err := util.ExecCommand(ctx, rbd, unmapArgs...)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user