|
|
a3470f |
From e1e80bc293f5a84087d5a35054cd8bc0abfa4836 Mon Sep 17 00:00:00 2001
|
|
|
a3470f |
From: Pranith Kumar K <pkarampu@redhat.com>
|
|
|
a3470f |
Date: Wed, 13 Jun 2018 12:17:28 +0530
|
|
|
a3470f |
Subject: [PATCH 302/305] storage/posix: Handle ENOSPC correctly in zero_fill
|
|
|
a3470f |
|
|
|
a3470f |
Upstream patch: https://review.gluster.org/20254
|
|
|
a3470f |
|
|
|
a3470f |
BUG: 1594658
|
|
|
a3470f |
Change-Id: Icc521d86cc510f88b67d334b346095713899087a
|
|
|
a3470f |
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
|
|
|
a3470f |
Reviewed-on: https://code.engineering.redhat.com/gerrit/142311
|
|
|
a3470f |
Tested-by: RHGS Build Bot <nigelb@redhat.com>
|
|
|
a3470f |
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
|
|
|
a3470f |
---
|
|
|
a3470f |
tests/basic/posix/zero-fill-enospace.c | 64 ++++++++++++++++++++++++++++++++++
|
|
|
a3470f |
tests/basic/posix/zero-fill-enospace.t | 35 +++++++++++++++++++
|
|
|
a3470f |
xlators/storage/posix/src/posix.c | 23 +++++++++++-
|
|
|
a3470f |
3 files changed, 121 insertions(+), 1 deletion(-)
|
|
|
a3470f |
create mode 100644 tests/basic/posix/zero-fill-enospace.c
|
|
|
a3470f |
create mode 100644 tests/basic/posix/zero-fill-enospace.t
|
|
|
a3470f |
|
|
|
a3470f |
diff --git a/tests/basic/posix/zero-fill-enospace.c b/tests/basic/posix/zero-fill-enospace.c
|
|
|
a3470f |
new file mode 100644
|
|
|
a3470f |
index 0000000..b1aaa57
|
|
|
a3470f |
--- /dev/null
|
|
|
a3470f |
+++ b/tests/basic/posix/zero-fill-enospace.c
|
|
|
a3470f |
@@ -0,0 +1,64 @@
|
|
|
a3470f |
+#include <stdio.h>
|
|
|
a3470f |
+#include <glusterfs/api/glfs.h>
|
|
|
a3470f |
+#include <glusterfs/api/glfs-handles.h>
|
|
|
a3470f |
+
|
|
|
a3470f |
+int
|
|
|
a3470f |
+main (int argc, char *argv[])
|
|
|
a3470f |
+{
|
|
|
a3470f |
+ glfs_t *fs = NULL;
|
|
|
a3470f |
+ glfs_fd_t *fd = NULL;
|
|
|
a3470f |
+ int ret = 1;
|
|
|
a3470f |
+ int size = 0;
|
|
|
a3470f |
+
|
|
|
a3470f |
+ if (argc != 6) {
|
|
|
a3470f |
+ fprintf (stderr, "Syntax: %s <host> <volname> <file-path> <log-file> <size>\n", argv[0]);
|
|
|
a3470f |
+ return 1;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+
|
|
|
a3470f |
+ fs = glfs_new (argv[2]);
|
|
|
a3470f |
+ if (!fs) {
|
|
|
a3470f |
+ fprintf (stderr, "glfs_new: returned NULL\n");
|
|
|
a3470f |
+ return 1;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+
|
|
|
a3470f |
+ ret = glfs_set_volfile_server (fs, "tcp", argv[1], 24007);
|
|
|
a3470f |
+ if (ret != 0) {
|
|
|
a3470f |
+ fprintf (stderr, "glfs_set_volfile_server: retuned %d\n", ret);
|
|
|
a3470f |
+ goto out;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+ ret = glfs_set_logging (fs, argv[4], 7);
|
|
|
a3470f |
+ if (ret != 0) {
|
|
|
a3470f |
+ fprintf (stderr, "glfs_set_logging: returned %d\n", ret);
|
|
|
a3470f |
+ goto out;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+ ret = glfs_init (fs);
|
|
|
a3470f |
+ if (ret != 0) {
|
|
|
a3470f |
+ fprintf (stderr, "glfs_init: returned %d\n", ret);
|
|
|
a3470f |
+ goto out;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+
|
|
|
a3470f |
+ fd = glfs_open (fs, argv[3], O_RDWR);
|
|
|
a3470f |
+ if (fd == NULL) {
|
|
|
a3470f |
+ fprintf (stderr, "glfs_open: returned NULL\n");
|
|
|
a3470f |
+ goto out;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+
|
|
|
a3470f |
+ size = atoi(argv[5]);
|
|
|
a3470f |
+ if (size < 0) {
|
|
|
a3470f |
+ fprintf (stderr, "Wrong size %s", argv[5]);
|
|
|
a3470f |
+ goto out;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+ ret = glfs_zerofill (fd, 0, atoi(argv[5]));
|
|
|
a3470f |
+ if (ret <= 0) {
|
|
|
a3470f |
+ fprintf (stderr, "glfs_zerofill: returned %d\n", ret);
|
|
|
a3470f |
+ goto out;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+
|
|
|
a3470f |
+ ret = 0;
|
|
|
a3470f |
+
|
|
|
a3470f |
+out:
|
|
|
a3470f |
+ if (fd)
|
|
|
a3470f |
+ glfs_close(fd);
|
|
|
a3470f |
+ glfs_fini (fs);
|
|
|
a3470f |
+ return ret;
|
|
|
a3470f |
+}
|
|
|
a3470f |
diff --git a/tests/basic/posix/zero-fill-enospace.t b/tests/basic/posix/zero-fill-enospace.t
|
|
|
a3470f |
new file mode 100644
|
|
|
a3470f |
index 0000000..ac2e61b
|
|
|
a3470f |
--- /dev/null
|
|
|
a3470f |
+++ b/tests/basic/posix/zero-fill-enospace.t
|
|
|
a3470f |
@@ -0,0 +1,35 @@
|
|
|
a3470f |
+#!/bin/bash
|
|
|
a3470f |
+
|
|
|
a3470f |
+. $(dirname $0)/../../include.rc
|
|
|
a3470f |
+. $(dirname $0)/../../volume.rc
|
|
|
a3470f |
+. $(dirname $0)/../../dht.rc
|
|
|
a3470f |
+
|
|
|
a3470f |
+cleanup;
|
|
|
a3470f |
+
|
|
|
a3470f |
+TEST glusterd;
|
|
|
a3470f |
+TEST pidof glusterd;
|
|
|
a3470f |
+
|
|
|
a3470f |
+TEST truncate -s 100M $B0/brick1
|
|
|
a3470f |
+
|
|
|
a3470f |
+TEST L1=`SETUP_LOOP $B0/brick1`
|
|
|
a3470f |
+TEST MKFS_LOOP $L1
|
|
|
a3470f |
+
|
|
|
a3470f |
+TEST mkdir -p $B0/${V0}1
|
|
|
a3470f |
+
|
|
|
a3470f |
+TEST MOUNT_LOOP $L1 $B0/${V0}1
|
|
|
a3470f |
+
|
|
|
a3470f |
+TEST $CLI volume create $V0 $H0:$B0/${V0}1
|
|
|
a3470f |
+
|
|
|
a3470f |
+TEST $CLI volume start $V0;
|
|
|
a3470f |
+
|
|
|
a3470f |
+TEST glusterfs -s $H0 --volfile-id=$V0 $M0
|
|
|
a3470f |
+TEST touch $M0/foo
|
|
|
a3470f |
+TEST build_tester $(dirname $0)/zero-fill-enospace.c -lgfapi -Wall -O2
|
|
|
a3470f |
+TEST ! $(dirname $0)/zero-fill-enospace $H0 $V0 /foo `gluster --print-logdir`/glfs-$V0.log 104857600
|
|
|
a3470f |
+
|
|
|
a3470f |
+TEST force_umount $M0
|
|
|
a3470f |
+TEST $CLI volume stop $V0
|
|
|
a3470f |
+UMOUNT_LOOP ${B0}/${V0}1
|
|
|
a3470f |
+rm -f ${B0}/brick1
|
|
|
a3470f |
+
|
|
|
a3470f |
+cleanup
|
|
|
a3470f |
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
|
|
|
a3470f |
index af54882..01f472b 100644
|
|
|
a3470f |
--- a/xlators/storage/posix/src/posix.c
|
|
|
a3470f |
+++ b/xlators/storage/posix/src/posix.c
|
|
|
a3470f |
@@ -943,17 +943,32 @@ _posix_do_zerofill(int fd, off_t offset, off_t len, int o_direct)
|
|
|
a3470f |
op_ret = sys_writev (fd, vector, num_vect);
|
|
|
a3470f |
if (op_ret < 0)
|
|
|
a3470f |
goto err;
|
|
|
a3470f |
+ if (op_ret != (vect_size * num_vect)) {
|
|
|
a3470f |
+ op_ret = -1;
|
|
|
a3470f |
+ errno = ENOSPC;
|
|
|
a3470f |
+ goto err;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
}
|
|
|
a3470f |
if (extra) {
|
|
|
a3470f |
op_ret = sys_writev (fd, vector, extra);
|
|
|
a3470f |
if (op_ret < 0)
|
|
|
a3470f |
goto err;
|
|
|
a3470f |
+ if (op_ret != (vect_size * extra)) {
|
|
|
a3470f |
+ op_ret = -1;
|
|
|
a3470f |
+ errno = ENOSPC;
|
|
|
a3470f |
+ goto err;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
}
|
|
|
a3470f |
if (remain) {
|
|
|
a3470f |
vector[0].iov_len = remain;
|
|
|
a3470f |
op_ret = sys_writev (fd, vector , 1);
|
|
|
a3470f |
if (op_ret < 0)
|
|
|
a3470f |
goto err;
|
|
|
a3470f |
+ if (op_ret != remain) {
|
|
|
a3470f |
+ op_ret = -1;
|
|
|
a3470f |
+ errno = ENOSPC;
|
|
|
a3470f |
+ goto err;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
}
|
|
|
a3470f |
err:
|
|
|
a3470f |
if (o_direct)
|
|
|
a3470f |
@@ -1014,8 +1029,14 @@ posix_do_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
|
|
|
a3470f |
*/
|
|
|
a3470f |
flags = FALLOC_FL_ZERO_RANGE;
|
|
|
a3470f |
ret = sys_fallocate (pfd->fd, flags, offset, len);
|
|
|
a3470f |
- if (ret == 0)
|
|
|
a3470f |
+ if (ret == 0) {
|
|
|
a3470f |
goto fsync;
|
|
|
a3470f |
+ } else {
|
|
|
a3470f |
+ ret = -errno;
|
|
|
a3470f |
+ if ((ret != -ENOSYS) && (ret != -EOPNOTSUPP)) {
|
|
|
a3470f |
+ goto out;
|
|
|
a3470f |
+ }
|
|
|
a3470f |
+ }
|
|
|
a3470f |
|
|
|
a3470f |
ret = _posix_do_zerofill (pfd->fd, offset, len, pfd->flags & O_DIRECT);
|
|
|
a3470f |
if (ret < 0) {
|
|
|
a3470f |
--
|
|
|
a3470f |
1.8.3.1
|
|
|
a3470f |
|