summaryrefslogtreecommitdiffstats
path: root/tests/basic/quota.c
diff options
context:
space:
mode:
authorvmallika <vmallika@redhat.com>2015-05-28 12:30:02 +0530
committerPranith Kumar Karampuri <pkarampu@redhat.com>2015-05-28 23:29:07 -0700
commitf6e72c45ad754073bc8269e954d236bab9e4a0e7 (patch)
treebd2ab7c55e85aab08cfbf6ccaa151ea1158e97ac /tests/basic/quota.c
parente3408108e36dac08d217f558b5cc69dff71bbcbf (diff)
Quota: fix testcases not to send parallel writes for accurate
quota enforcement This is a backport of http://review.gluster.org/#/c/10878 > Currently quota enforcer doesn't consider parallel writes > and allows quota to exceed limit where there are high rate > of parallel writes. Bug# 1223658 tracks the issue. > > This patch fixes the spurious failures by not sending > parallel writes. > Using O_SYNC and O_APPEND flags and block size > not more that 256k (For higher block size NFS client > splits the block into 256k chinks and does parallel writes) > > Change-Id: I297c164b030cecb87ce5b494c02b09e8b073b276 > BUG: 1223798 > Signed-off-by: vmallika <vmallika@redhat.com> > Reviewed-on: http://review.gluster.org/10878 > Tested-by: NetBSD Build System > Tested-by: Gluster Build System <jenkins@build.gluster.com> > Reviewed-by: Raghavendra G <rgowdapp@redhat.com> > Tested-by: Raghavendra G <rgowdapp@redhat.com> Change-Id: I78b6250eb0b3fbbbab1d4348d4e81d6292c6c6bb BUG: 1224894 Signed-off-by: vmallika <vmallika@redhat.com> Reviewed-on: http://review.gluster.org/10910 Tested-by: Gluster Build System <jenkins@build.gluster.com> Tested-by: NetBSD Build System Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Diffstat (limited to 'tests/basic/quota.c')
-rw-r--r--tests/basic/quota.c82
1 files changed, 62 insertions, 20 deletions
diff --git a/tests/basic/quota.c b/tests/basic/quota.c
index 4cc0322e132..50f56d6d718 100644
--- a/tests/basic/quota.c
+++ b/tests/basic/quota.c
@@ -3,45 +3,87 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+
+ssize_t
+nwrite (int fd, const void *buf, size_t count)
+{
+ ssize_t ret = 0;
+ ssize_t written = 0;
+
+ for (written = 0; written != count; written += ret) {
+ ret = write (fd, buf + written, count - written);
+ if (ret < 0) {
+ if (errno == EINTR)
+ ret = 0;
+ else
+ goto out;
+ }
+ }
+
+ ret = written;
+out:
+ return ret;
+}
int
-file_write (char *filename, int filesize)
+file_write (char *filename, int bs, int count)
{
- int fd, ret = 0;
- int i = 0;
- char buf[1024] = {'a',};
- fd = open (filename, O_RDWR|O_CREAT|O_APPEND, 0600);
- while (i < filesize) {
- ret = write(fd, buf, sizeof(buf));
+ int fd = 0;
+ int ret = -1;
+ int i = 0;
+ char *buf = NULL;
+
+ bs = bs * 1024;
+
+ buf = (char *) malloc (bs);
+ if (buf == NULL)
+ goto out;
+
+ memset (buf, 0, bs);
+
+ fd = open (filename, O_RDWR|O_CREAT|O_SYNC, 0600);
+ while (i < count) {
+ ret = nwrite(fd, buf, bs);
if (ret == -1) {
close (fd);
- return ret;
- }
- i += sizeof(buf);
- ret = fdatasync(fd);
- if (ret) {
- close (fd);
- return ret;
+ goto out;
}
+ i++;
}
+
+ ret = fdatasync(fd);
+ if (ret) {
+ close (fd);
+ goto out;
+ }
+
ret = close(fd);
if (ret)
- return ret;
+ goto out;
- return 0;
+ ret = 0;
+
+out:
+ if (buf)
+ free (buf);
+ return ret;
}
int
main (int argc, char **argv)
{
- if (argc != 3) {
- printf("Usage: %s <filename> <size(in bytes)>\n", argv[0]);
+ if (argc != 4) {
+ printf("Usage: %s <filename> <block size in k> <count>\n",
+ argv[0]);
return EXIT_FAILURE;
}
- printf ("argv[2] is %s\n", argv[2]);
- if (file_write (argv[1], atoi(argv[2])) == -1)
+ if (file_write (argv[1], atoi(argv[2]), atoi(argv[3])) < 0) {
+ perror ("write failed");
return EXIT_FAILURE;
+ }
return EXIT_SUCCESS;
}