static int qemu_rbd_snap_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) { BDRVRBDState *s = bs->opaque; int r; if (sn_info->name[0] == '\0') { return -EINVAL; /* we need a name for rbd snapshots */ } /* * rbd snapshots are using the name as the user controlled unique identifier * we can't use the rbd snapid for that purpose, as it can't be set */ if (sn_info->id_str[0] != '\0' && strcmp(sn_info->id_str, sn_info->name) != 0) { return -EINVAL; } if (strlen(sn_info->name) >= sizeof(sn_info->id_str)) { return -ERANGE; } r = rbd_snap_create(s->image, sn_info->name); if (r < 0) { error_report("failed to create snap: %s", strerror(-r)); return r; } return 0; }
int __librbd_clone(struct rbd_ctx *ctx, const char *src_snapname, const char *dst_imagename, int *order, int stripe_unit, int stripe_count) { int ret; ret = rbd_snap_create(ctx->image, src_snapname); if (ret < 0) { prt("rbd_snap_create(%s@%s) failed\n", ctx->name, src_snapname); return ret; } ret = rbd_snap_protect(ctx->image, src_snapname); if (ret < 0) { prt("rbd_snap_protect(%s@%s) failed\n", ctx->name, src_snapname); return ret; } ret = rbd_clone2(ioctx, ctx->name, src_snapname, ioctx, dst_imagename, RBD_FEATURES_ALL, order, stripe_unit, stripe_count); if (ret < 0) { prt("rbd_clone2(%s@%s -> %s) failed\n", ctx->name, src_snapname, dst_imagename); return ret; } return 0; }
void do_clone() { char filename[1024]; char imagename[1024]; char lastimagename[1024]; int ret, fd; int order = 0, stripe_unit = 0, stripe_count = 0; if (randomize_striping) { order = 18 + rand() % 8; stripe_unit = 1ull << (order - 1 - (rand() % 8)); stripe_count = 2 + rand() % 14; } log4(OP_CLONE, 0, 0, 0); ++num_clones; prt("%lu clone\t%d order %d su %d sc %d\n", testcalls, num_clones, order, stripe_unit, stripe_count); clone_filename(filename, sizeof(filename), num_clones); if ((fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) { simple_err("do_clone: open", -errno); exit(162); } save_buffer(good_buf, file_size, fd); if ((ret = close(fd)) < 0) { simple_err("do_clone: close", -errno); exit(163); } if ((ret = rbd_snap_create(image, "snap")) < 0) { simple_err("do_clone: rbd create snap", ret); exit(164); } if ((ret = rbd_snap_protect(image, "snap")) < 0) { simple_err("do_clone: rbd protect snap", ret); exit(164); } clone_imagename(imagename, sizeof(imagename), num_clones); clone_imagename(lastimagename, sizeof(lastimagename), num_clones - 1); ret = rbd_clone2(ioctx, lastimagename, "snap", ioctx, imagename, RBD_FEATURES_ALL, &order, stripe_unit, stripe_count); if (ret < 0) { simple_err("do_clone: rbd clone", ret); exit(165); } rbd_close(image); if ((ret = rbd_open(ioctx, imagename, &image, NULL)) < 0) { simple_err("do_clone: rbd open", ret); exit(166); } }
int __librbd_clone(struct rbd_ctx *ctx, const char *src_snapname, const char *dst_imagename, int *order, int stripe_unit, int stripe_count, bool krbd) { int ret; ret = rbd_snap_create(ctx->image, src_snapname); if (ret < 0) { prt("rbd_snap_create(%s@%s) failed\n", ctx->name, src_snapname); return ret; } ret = rbd_snap_protect(ctx->image, src_snapname); if (ret < 0) { prt("rbd_snap_protect(%s@%s) failed\n", ctx->name, src_snapname); return ret; } uint64_t features = RBD_FEATURES_ALL; if (krbd) { features &= ~(RBD_FEATURE_EXCLUSIVE_LOCK | RBD_FEATURE_OBJECT_MAP); } ret = rbd_clone2(ioctx, ctx->name, src_snapname, ioctx, dst_imagename, features, order, stripe_unit, stripe_count); if (ret < 0) { prt("rbd_clone2(%s@%s -> %s) failed\n", ctx->name, src_snapname, dst_imagename); return ret; } return 0; }
void test_create_snap(rbd_image_t image, const char *name) { assert(rbd_snap_create(image, name) == 0); }