From 9a4533e5493668bd95cfd44d6aa0aad795885567 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 1 Dec 2021 15:41:32 +0530 Subject: [PATCH] rbd: create 1MiB size dummy image we added a workaround for rbd scheduling by creating a dummy image in #2656. with the fix we are creating a dummy image of the size of the first actual rbd image which is sent in EnableVolumeReplication request if the actual rbd image size is 1TiB we are creating a dummy image of 1TiB which is not good. even though its a thin provisioned rbd images this is causing issue for the transfer of the snapshot during the mirroring operation. This commit recreates the rbd image with 1MiB size which is the smaller supported size in rbd. Signed-off-by: Madhu Rajanna --- internal/rbd/replicationcontrollerserver.go | 33 +++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/internal/rbd/replicationcontrollerserver.go b/internal/rbd/replicationcontrollerserver.go index 11a8bd90663..8387f776c3f 100644 --- a/internal/rbd/replicationcontrollerserver.go +++ b/internal/rbd/replicationcontrollerserver.go @@ -300,23 +300,46 @@ func getOperationName(poolName string, optName operation) string { // createDummyImage creates a dummy image as a workaround for the rbd // scheduling problem. func createDummyImage(ctx context.Context, rbdVol *rbdVolume) error { + var err error + var imgName string + + dummyImageOpsLock.Lock() + defer dummyImageOpsLock.Unlock() optName := getOperationName(rbdVol.Pool, dummyImageCreated) if _, ok := operationLock.Load(optName); !ok { // create a dummy image - imgName, err := getDummyImageName(rbdVol.conn) + imgName, err = getDummyImageName(rbdVol.conn) if err != nil { return err } dummyVol := *rbdVol dummyVol.RbdImageName = imgName + // create 1MiB dummy image. 1MiB=1048576 bytes + dummyVol.VolSize = 1048576 err = createImage(ctx, &dummyVol, dummyVol.conn.Creds) - if err != nil && !strings.Contains(err.Error(), "File exists") { - return err + if err != nil { + if strings.Contains(err.Error(), "File exists") { + err = repairDummyImage(ctx, &dummyVol) + } + } + if err == nil { + operationLock.Store(optName, true) } - operationLock.Store(optName, true) } - return nil + return err +} + +// repairDummyImage deletes and recreates the dummy image. +func repairDummyImage(ctx context.Context, dummyVol *rbdVolume) error { + // deleting and recreating the dummy image will not impact anything as its + // a workaround to fix the scheduling problem. + err := deleteImage(ctx, dummyVol, dummyVol.conn.Creds) + if err != nil { + return err + } + + return createImage(ctx, dummyVol, dummyVol.conn.Creds) } // tickleMirroringOnDummyImage disables and reenables mirroring on the dummy image, and sets a