summaryrefslogtreecommitdiff
path: root/qa/btrfs
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2011-09-29 11:48:00 -0700
committerSage Weil <sage@newdream.net>2011-09-29 11:48:00 -0700
commit697e664cc5f2c009d31ca5841c9d784a719ff2ac (patch)
tree772de82294b316b83d3b85d707f94616ef899b18 /qa/btrfs
parentbd9144408d928cf92036166e20bcc2ef41819534 (diff)
downloadceph-697e664cc5f2c009d31ca5841c9d784a719ff2ac.tar.gz
qa: btrfs: test_async_snap
Hammer on the btrfs async sync/snap create/remove ioctls. Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'qa/btrfs')
-rw-r--r--qa/btrfs/Makefile2
-rw-r--r--qa/btrfs/test_async_snap.c82
2 files changed, 83 insertions, 1 deletions
diff --git a/qa/btrfs/Makefile b/qa/btrfs/Makefile
index 8e82d30916b..354948c16bc 100644
--- a/qa/btrfs/Makefile
+++ b/qa/btrfs/Makefile
@@ -1,6 +1,6 @@
CFLAGS = -Wall -Wextra -D_GNU_SOURCE
-TARGETS = clone_range
+TARGETS = clone_range test_async_snap
.c:
$(CC) $(CFLAGS) $@.c -o $@
diff --git a/qa/btrfs/test_async_snap.c b/qa/btrfs/test_async_snap.c
new file mode 100644
index 00000000000..ffa4fe71598
--- /dev/null
+++ b/qa/btrfs/test_async_snap.c
@@ -0,0 +1,82 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <string.h>
+
+#include <linux/ioctl.h>
+#include <linux/types.h>
+#include "../../src/os/btrfs_ioctl.h"
+
+struct btrfs_ioctl_vol_args_v2 va;
+struct btrfs_ioctl_vol_args vold;
+int max = 4;
+
+void check_return(int r)
+{
+ if (r < 0) {
+ printf("********* failed with %d %s ********\n", errno, strerror(errno));
+ exit(1);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ int num = 100;
+
+ if (argc > 1)
+ num = atoi(argv[1]);
+ printf("will do %d iterations\n", num);
+
+ int cwd = open(".", O_RDONLY);
+ printf("cwd = %d\n", cwd);
+ while (1) {
+ if (rand() % 10 == 0) {
+ __u64 transid;
+ int r;
+ printf("sync starting\n");
+ r = ioctl(cwd, BTRFS_IOC_START_SYNC, &transid);
+ check_return(r);
+ printf("sync started, transid %lld, waiting\n", transid);
+ r = ioctl(cwd, BTRFS_IOC_WAIT_SYNC, &transid);
+ check_return(r);
+ printf("sync finished\n");
+ }
+
+ int i = rand() % max;
+ struct stat st;
+ va.fd = cwd;
+ sprintf(va.name, "test.%d", i);
+ va.transid = 0;
+ int r = stat(va.name, &st);
+ if (r < 0) {
+ if (rand() % 3 == 0) {
+ printf("snap create (sync) %s\n", va.name);
+ va.flags = 0;
+ r = ioctl(cwd, BTRFS_IOC_SNAP_CREATE_V2, &va);
+ check_return(r);
+ } else {
+ printf("snap create (async) %s\n", va.name);
+ va.flags = BTRFS_SUBVOL_CREATE_ASYNC;
+ r = ioctl(cwd, BTRFS_IOC_SNAP_CREATE_V2, &va);
+ check_return(r);
+ printf("snap created, transid %lld\n", va.transid);
+ if (rand() % 2 == 0) {
+ printf("waiting for async snap create\n");
+ r = ioctl(cwd, BTRFS_IOC_WAIT_SYNC, &va.transid);
+ check_return(r);
+ }
+ }
+ } else {
+ printf("snap remove %s\n", va.name);
+ vold.fd = va.fd;
+ strcpy(vold.name, va.name);
+ r = ioctl(cwd, BTRFS_IOC_SNAP_DESTROY, &vold);
+ check_return(r);
+ }
+ }
+}