public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
To: Alexey Kodanev <alexey.kodanev@oracle.com>
Cc: vasily.isaenko@oracle.com, ltp-list@lists.sourceforge.net
Subject: [LTP] [PATCH] fallocate04: another check if SEEK_HOLE is not supported
Date: Mon, 18 May 2015 18:14:08 +0800	[thread overview]
Message-ID: <1431944048.27486.14.camel@G08FNSTD140232> (raw)
In-Reply-To: <1429621507-23503-1-git-send-email-alexey.kodanev@oracle.com>

SEEK_HOLE is only supported since version 3.1. Check the specified
range blocks are zeroed while the kernel does not supported SEEK_HOLE.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/fallocate/fallocate04.c | 49 ++++++++++++++++++-----
 1 file changed, 39 insertions(+), 10 deletions(-)

diff --git a/testcases/kernel/syscalls/fallocate/fallocate04.c b/testcases/kernel/syscalls/fallocate/fallocate04.c
index 911bbe8..9d9587b 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate04.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate04.c
@@ -50,6 +50,8 @@ static const option_t options[] = {
 	{NULL, NULL, NULL}
 };
 
+static off_t check_file_hole(int, off_t, off_t);
+
 static void help(void)
 {
 	printf("  -v      Verbose\n");
@@ -150,17 +152,12 @@ static void test02(void)
 	}
 
 	tst_resm(TINFO, "check that file has a hole with lseek(,,SEEK_HOLE)");
-	off_t ret = lseek(fd, 0, SEEK_HOLE);
 
-	if (ret != (ssize_t)block_size) {
-		/* exclude error when kernel doesn't have SEEK_HOLE support */
-		if (errno != EINVAL) {
-			tst_brkm(TFAIL | TERRNO, cleanup,
-				 "fallocate() or lseek() failed");
-		}
-		tst_resm(TWARN | TERRNO, "lseek() doesn't support SEEK_HOLE");
-	}
-	tst_resm(TINFO, "found a hole at '%ld' offset", ret);
+	off_t ret = check_file_hole(fd, block_size, block_size);
+	if (ret != (ssize_t)block_size)
+		tst_resm(TWARN | TERRNO, "No file hole found");
+	else
+		tst_resm(TINFO, "found a hole at '%ld' offset", ret);
 
 	size_t alloc_size1 = get_allocsize();
 
@@ -275,3 +272,35 @@ int main(int argc, char *argv[])
 
 	tst_exit();
 }
+
+static off_t check_file_hole(int fd, off_t offset, off_t len)
+{
+	off_t ret;
+
+	ret = lseek(fd, 0, SEEK_HOLE);
+	if (ret < 0) {
+		/* exclude error when kernel doesn't have SEEK_HOLE support */
+		if (errno != EINVAL)
+			tst_brkm(TFAIL | TERRNO, cleanup, "lseek() failed");
+
+		int i;
+		char *buf;
+
+		SAFE_LSEEK(cleanup, fd, offset, SEEK_SET);
+
+		buf = SAFE_MALLOC(cleanup, len);
+
+		SAFE_READ(cleanup, 1, fd, buf, len);
+
+		for (i = 0; i < len; i++) {
+			if (buf[i] != '\0')
+				break;
+		}
+
+		free(buf);
+
+		return i;
+	}
+
+	return ret;
+}
-- 
1.9.3




------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  parent reply	other threads:[~2015-05-18 10:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-21 13:05 [LTP] [PATCH v4] syscalls/fallocate04: add new fallocate() test Alexey Kodanev
2015-04-23  7:44 ` Jan Stancek
2015-04-27 14:07 ` Cyril Hrubis
     [not found]   ` <553E55D3.7070001@oracle.com>
2015-04-27 15:27     ` Cyril Hrubis
2015-05-18 10:14 ` Zeng Linggang [this message]
2015-05-18 14:03   ` [LTP] [PATCH] fallocate04: another check if SEEK_HOLE is not supported Alexey Kodanev
2015-05-19  8:50     ` [LTP] [PATCH v2] " Zeng Linggang
2015-05-19 11:18       ` Jan Stancek
2015-05-20  1:47         ` Zeng Linggang
2015-05-20  6:52           ` Jan Stancek
2015-05-20  9:58             ` Zeng Linggang
2015-05-20 11:32               ` Jan Stancek
2015-05-21  1:26                 ` Zeng Linggang
2015-05-20  8:13           ` Alexey Kodanev
2015-05-20  9:35             ` Zeng Linggang
2015-05-21  5:39 ` [LTP] [PATCH] fallocate04: Use tst_kvercmp after lseek(SEEK_HOLE) return EINVAL Zeng Linggang
2015-05-22 14:21   ` Jan Stancek
2015-06-04 11:35     ` Alexey Kodanev
2015-06-04 11:52       ` Jan Stancek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431944048.27486.14.camel@G08FNSTD140232 \
    --to=zenglg.jy@cn.fujitsu.com \
    --cc=alexey.kodanev@oracle.com \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=vasily.isaenko@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox