summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/bitrot/br-stub.c147
-rw-r--r--tests/bitrot/br-stub.t44
-rw-r--r--xlators/features/bit-rot/src/stub/bit-rot-common.h17
-rw-r--r--xlators/features/bit-rot/src/stub/bit-rot-object-version.h30
4 files changed, 222 insertions, 16 deletions
diff --git a/tests/bitrot/br-stub.c b/tests/bitrot/br-stub.c
new file mode 100644
index 00000000000..81481f86905
--- /dev/null
+++ b/tests/bitrot/br-stub.c
@@ -0,0 +1,147 @@
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/xattr.h>
+
+#include "bit-rot-object-version.h"
+
+/* NOTE: no size discovery */
+int
+brstub_validate_version (char *bpath, unsigned long version)
+{
+ int ret = 0;
+ int match = 0;
+ size_t xsize = 0;
+ br_version_t *xv = NULL;
+
+ xsize = sizeof (br_version_t);
+
+ xv = calloc (1, xsize);
+ if (!xv)
+ goto err;
+
+ ret = getxattr (bpath, "trusted.glusterfs.bit-rot.version", xv, xsize);
+ if (ret < 0)
+ goto err;
+
+ if (xv->ongoingversion != version)
+ match = -1;
+ free (xv);
+
+ return match;
+
+ err:
+ return -1;
+}
+
+int
+brstub_open_validation (char *filp, char *bpath, unsigned long startversion)
+{
+ int fd1 = 0;
+ int fd2 = 0;
+ int ret = 0;
+
+ /* read only check */
+ fd1 = open (filp, O_RDONLY);
+ if (fd1 < 0)
+ goto err;
+ close (fd1);
+
+ ret = brstub_validate_version (bpath, startversion);
+ if (ret < 0)
+ goto err;
+
+ /* single open (write/) check */
+ fd1 = open (filp, O_RDWR);
+ if (fd1 < 0)
+ goto err;
+ close (fd1);
+
+ startversion++;
+ ret = brstub_validate_version (bpath, startversion);
+
+ /* multi open (write/) check */
+ fd1 = open (filp, O_RDWR);
+ if (fd1 < 0)
+ goto err;
+ fd2 = open (filp, O_WRONLY);
+ if (fd1 < 0)
+ goto err;
+ close (fd1);
+ close (fd2);
+
+ /**
+ * incremented once per open()/open().../close()/close() sequence
+ */
+ startversion++;
+ ret = brstub_validate_version (bpath, startversion);
+ if (ret < 0)
+ goto err;
+
+ return 0;
+
+ err:
+ return -1;
+}
+
+int
+brstub_new_object_validate (char *filp, char *brick)
+{
+ int ret = 0;
+ char *fname = NULL;
+ char bpath[PATH_MAX] = {0,};
+
+ fname = basename (filp);
+ if (!fname)
+ goto err;
+
+ (void) snprintf (bpath, PATH_MAX, "%s/%s", brick, fname);
+
+ printf ("Validating initial version..\n");
+ ret = brstub_validate_version (bpath, 1);
+ if (ret < 0)
+ goto err;
+
+ printf ("Validating version on modifications..\n");
+ ret = brstub_open_validation (filp, bpath, 1);
+ if (ret < 0)
+ goto err;
+
+ return 0;
+
+ err:
+ return -1;
+}
+
+int
+main (int argc, char **argv)
+{
+ int ret = 0;
+ char *filp = NULL;
+ char *brick = NULL;
+
+ if (argc != 3) {
+ printf ("Usage: %s <path> <brick>\n", argv[0]);
+ goto err;
+ }
+
+ filp = argv[1];
+ brick = argv[2];
+
+ printf ("Validating object version [%s]\n", filp);
+ ret = brstub_new_object_validate (filp, brick);
+ if (ret < 0)
+ goto err;
+
+ return 0;
+
+ err:
+ return -1;
+}
diff --git a/tests/bitrot/br-stub.t b/tests/bitrot/br-stub.t
new file mode 100644
index 00000000000..11d02418785
--- /dev/null
+++ b/tests/bitrot/br-stub.t
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+. $(dirname $0)/../include.rc
+. $(dirname $0)/../volume.rc
+
+STUB_SOURCE=$(dirname $0)/br-stub.c
+STUB_EXEC=$(dirname $0)/br-stub
+
+cleanup;
+
+TEST glusterd
+TEST pidof glusterd
+
+## Create a distribute volume (B=2)
+TEST $CLI volume create $V0 $H0:$B0/${V0}1 $H0:$B0/${V0}2;
+EXPECT "$V0" volinfo_field $V0 'Volume Name';
+EXPECT 'Created' volinfo_field $V0 'Status';
+EXPECT '2' brick_count $V0
+
+## Turn off open-behind (stub does not work with anonfd yet..)
+TEST $CLI volume set $V0 performance.open-behind off
+EXPECT 'off' volinfo_field $V0 'performance.open-behind'
+
+## Start the volume
+TEST $CLI volume start $V0;
+EXPECT 'Started' volinfo_field $V0 'Status';
+
+## Mount the volume
+TEST $GFS --volfile-server=$H0 --volfile-id=$V0 $M0;
+
+## Build stub C source
+build_tester $STUB_SOURCE -o $STUB_EXEC -I$(dirname $0)/../../xlators/features/bit-rot/src/stub
+TEST [ -e $STUB_EXEC ]
+
+## create & check version
+fname="$M0/filezero"
+touch $fname
+backpath=$(get_backend_paths $fname)
+TEST $STUB_EXEC $fname $(dirname $backpath)
+
+## cleanups..
+rm -f $STUB_EXEC
+
+cleanup;
diff --git a/xlators/features/bit-rot/src/stub/bit-rot-common.h b/xlators/features/bit-rot/src/stub/bit-rot-common.h
index ae1f45f6d1d..fdf23142768 100644
--- a/xlators/features/bit-rot/src/stub/bit-rot-common.h
+++ b/xlators/features/bit-rot/src/stub/bit-rot-common.h
@@ -17,22 +17,7 @@
#endif
#include "glusterfs.h"
-
-/**
- * on-disk formats for ongoing version and object signature.
- */
-typedef struct br_version {
- unsigned long ongoingversion;
- uint32_t timebuf[2];
-} br_version_t;
-
-typedef struct br_signature {
- int8_t signaturetype;
-
- unsigned long signedversion;
-
- char signature[0];
-} br_signature_t;
+#include "bit-rot-object-version.h"
#define BR_VXATTR_VERSION (1 << 0)
#define BR_VXATTR_SIGNATURE (1 << 1)
diff --git a/xlators/features/bit-rot/src/stub/bit-rot-object-version.h b/xlators/features/bit-rot/src/stub/bit-rot-object-version.h
new file mode 100644
index 00000000000..a158adf8153
--- /dev/null
+++ b/xlators/features/bit-rot/src/stub/bit-rot-object-version.h
@@ -0,0 +1,30 @@
+/*
+ Copyright (c) 2015 Red Hat, Inc. <http://www.redhat.com>
+ This file is part of GlusterFS.
+
+ This file is licensed to you under your choice of the GNU Lesser
+ General Public License, version 3 or any later version (LGPLv3 or
+ later), or the GNU General Public License, version 2 (GPLv2), in all
+ cases as published by the Free Software Foundation.
+*/
+
+#ifndef __BIT_ROT_OBJECT_VERSION_H
+#define __BIT_ROT_OBJECT_VERSION_H
+
+/**
+ * on-disk formats for ongoing version and object signature.
+ */
+typedef struct br_version {
+ unsigned long ongoingversion;
+ uint32_t timebuf[2];
+} br_version_t;
+
+typedef struct br_signature {
+ int8_t signaturetype;
+
+ unsigned long signedversion;
+
+ char signature[0];
+} br_signature_t;
+
+#endif