]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test_librbd_fsx: also flatten as part of randomize_parent_overlap 2230/head
authorIlya Dryomov <ilya.dryomov@inktank.com>
Tue, 29 Jul 2014 14:29:19 +0000 (18:29 +0400)
committerIlya Dryomov <ilya.dryomov@inktank.com>
Fri, 8 Aug 2014 14:53:14 +0000 (18:53 +0400)
With randomize_parent_overlap fsx will randomly truncate base images
after they have been cloned from.  This throws flatten into the mix:
base image will be flattened with 2/16 chance (equal to the chance of
leaving the image intact).

Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
src/test/librbd/fsx.c

index b7f31463962f74712a5b4c6240f352323acd76f1..38ae4ccb75f2a6a992116d1cf3230cf7a7960ff0 100644 (file)
@@ -1369,23 +1369,25 @@ do_clone()
        }
 
        if (randomize_parent_overlap && rbd_image_has_parent(&ctx)) {
-               int rand = get_random() % 15;
-               uint64_t overlap;
+               int rand = get_random() % 16 + 1; // [1..16]
 
-               ret = rbd_get_overlap(ctx.image, &overlap);
-               if (ret < 0) {
-                       prterrcode("do_clone: rbd_get_overlap", ret);
-                       exit(1);
-               }
+               if (rand < 13) {
+                       uint64_t overlap;
 
-               if (rand < 3) {
-                       newsize = 0;
-               } else if (rand < 12) {
-                       newsize = overlap * (((double)rand - 2) / 10);
-                       newsize -= newsize % truncbdy;
-               }
+                       ret = rbd_get_overlap(ctx.image, &overlap);
+                       if (ret < 0) {
+                               prterrcode("do_clone: rbd_get_overlap", ret);
+                               exit(1);
+                       }
 
-               if (newsize != (uint64_t)file_size) {
+                       if (rand < 10) {        // 9/16
+                               newsize = overlap * ((double)rand / 10);
+                               newsize -= newsize % truncbdy;
+                       } else {                // 3/16
+                               newsize = 0;
+                       }
+
+                       assert(newsize != (uint64_t)file_size);
                        prt("truncating image %s from 0x%llx (overlap 0x%llx) to 0x%llx\n",
                            ctx.name, file_size, overlap, newsize);
 
@@ -1394,7 +1396,15 @@ do_clone()
                                prterrcode("do_clone: ops->resize", ret);
                                exit(1);
                        }
-               } else {
+               } else if (rand < 15) {         // 2/16
+                       prt("flattening image %s\n", ctx.name);
+
+                       ret = ops->flatten(&ctx);
+                       if (ret < 0) {
+                               prterrcode("do_clone: ops->flatten", ret);
+                               exit(1);
+                       }
+               } else {                        // 2/16
                        prt("leaving image %s intact\n", ctx.name);
                }
        }