summaryrefslogtreecommitdiffstats
path: root/tests/bitrot/br-stub.c
diff options
context:
space:
mode:
authorRaghavendra Bhat <raghavendra@redhat.com>2015-05-15 14:10:48 +0530
committerVenky Shankar <vshankar@redhat.com>2015-05-31 08:00:16 -0700
commit37cc99fc3a991241df49133902928bd789d95066 (patch)
tree5e53e9bc48000517637b399fb99b791f72841d48 /tests/bitrot/br-stub.c
parentd76e9b83454786e6845d0cad3c2c0695815fae1b (diff)
features/bit-rot-stub: implement mknod fop
With the absence of mknod() fop implementation in bitrot stub, further operations that trigger versioning resulted in crashes as they expect the inode context to be valid. Therefore, this patch implements mknod() following similar simantics to fops such as create(). Furthermore, bitrot stub test C program is fixed to stop lying and validate obj versions according to the versioning protocol. Change-Id: If76f252577445d1851d6c13c7e969e864e2183ef BUG: 1221914 Original-Author: Raghavendra Bhat <raghavendra@redhat.com> Signed-off-by: Venky Shankar <vshankar@redhat.com> Reviewed-on: http://review.gluster.org/10790 Tested-by: NetBSD Build System <jenkins@build.gluster.org> Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'tests/bitrot/br-stub.c')
-rw-r--r--tests/bitrot/br-stub.c47
1 files changed, 32 insertions, 15 deletions
diff --git a/tests/bitrot/br-stub.c b/tests/bitrot/br-stub.c
index e164170bb83..5b862832e77 100644
--- a/tests/bitrot/br-stub.c
+++ b/tests/bitrot/br-stub.c
@@ -9,6 +9,7 @@
#include <stdint.h>
#include <sys/types.h>
#include <sys/xattr.h>
+#include <errno.h>
#include "bit-rot-object-version.h"
@@ -24,23 +25,26 @@ brstub_validate_version (char *bpath, unsigned long version)
xsize = sizeof (br_version_t);
xv = calloc (1, xsize);
- if (!xv)
+ if (!xv) {
+ match = -1;
goto err;
+ }
ret = getxattr (bpath, "trusted.bit-rot.version", xv, xsize);
- if (ret < 0)
+ if (ret < 0) {
+ if (errno == ENODATA)
+ match = -2;
goto err;
+ }
if (xv->ongoingversion != version) {
- match = -1;
+ match = -3;
fprintf (stderr, "ongoingversion: %lu\n", xv->ongoingversion);
}
free (xv);
- return match;
-
err:
- return -1;
+ return match;
}
int
@@ -58,8 +62,9 @@ brstub_write_validation (char *filp, char *bpath, unsigned long startversion)
close (fd1);
ret = brstub_validate_version (bpath, startversion);
- if (ret == 0)
+ if (ret != -2)
goto err;
+
/* single open (write/) check */
fd1 = open (filp, O_RDWR);
if (fd1 < 0)
@@ -76,19 +81,26 @@ brstub_write_validation (char *filp, char *bpath, unsigned long startversion)
* versioning as it would have not reached the bit-rot-stub.
*/
fsync (fd1);
- startversion++;
ret = brstub_validate_version (bpath, startversion);
- if (ret < 0)
+ if (ret != 0)
goto err;
ret = write (fd1, string, strlen (string));
if (ret <= 0)
goto err;
+ fsync (fd1); /* let it reach the disk */
ret = brstub_validate_version (bpath, startversion);
- if (ret < 0)
+ if (ret != 0)
goto err;
close (fd1);
+
+ /**
+ * Well, this is not a _real_ test per se . For this test to pass
+ * the inode should not get a forget() in the interim. Therefore,
+ * perform this test asap.
+ */
+
/* multi open (write/) check */
fd1 = open (filp, O_RDWR);
if (fd1 < 0)
@@ -101,9 +113,14 @@ brstub_write_validation (char *filp, char *bpath, unsigned long startversion)
if (ret <= 0)
goto err;
- ret = write (fd1, string, strlen (string));
+ ret = write (fd2, string, strlen (string));
if (ret <= 0)
goto err;
+
+ /* probably do a syncfs() */
+ fsync (fd1);
+ fsync (fd2);
+
close (fd1);
close (fd2);
@@ -111,7 +128,7 @@ brstub_write_validation (char *filp, char *bpath, unsigned long startversion)
* incremented once per write()/write().../close()/close() sequence
*/
ret = brstub_validate_version (bpath, startversion);
- if (ret < 0)
+ if (ret != 0)
goto err;
return 0;
@@ -134,12 +151,12 @@ brstub_new_object_validate (char *filp, char *brick)
(void) snprintf (bpath, PATH_MAX, "%s/%s", brick, fname);
printf ("Validating initial version..\n");
- ret = brstub_validate_version (bpath, 1);
- if (ret == 0)
+ ret = brstub_validate_version (bpath, 2);
+ if (ret != -2) /* version _should_ be missing */
goto err;
printf ("Validating version on modifications..\n");
- ret = brstub_write_validation (filp, bpath, 1);
+ ret = brstub_write_validation (filp, bpath, 2);
if (ret < 0)
goto err;