From: Su Yanjun <suyj.fnst@cn.fujitsu.com>
To: <guaneryu@gmail.com>
Cc: <fstests@vger.kernel.org>, <suyj.fnst@cn.fujitsu.com>
Subject: [PATCH v2] fsx: add more check for copy_file_range
Date: Fri, 27 Sep 2019 09:53:54 +0800 [thread overview]
Message-ID: <1569549234-13096-1-git-send-email-suyj.fnst@cn.fujitsu.com> (raw)
Message-ID: <20190927015354.AVx1fDTytjssYlmnD-nAAjv44R_nEuSc080WVj7DDNk@z> (raw)
On some linux distros(RHEL7, centos 7) copy_file_range uses
general implementation (splice interface). splice interace
uses pipe_to_file. pipe_to_file only work for different page.
The userspace cant's be aware of such error because copy_file_range
returns ok too.
So for such case when copy_file_range return we read back data
then check it.
Also add check for do_clone_range following Eryu's advice.
Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>
---
v2:
- Use check_buffers instead memcmp code
- Add check for do_clone_range
- Fix return unique error number for the check code
---
ltp/fsx.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/ltp/fsx.c b/ltp/fsx.c
index 06d08e4..714bebc 100644
--- a/ltp/fsx.c
+++ b/ltp/fsx.c
@@ -1378,6 +1378,7 @@ test_clone_range(void)
void
do_clone_range(unsigned offset, unsigned length, unsigned dest)
{
+ int ret = 0;
struct file_clone_range fcr = {
.src_fd = fd,
.src_offset = offset,
@@ -1429,6 +1430,23 @@ do_clone_range(unsigned offset, unsigned length, unsigned dest)
memset(good_buf + file_size, '\0', dest - file_size);
if (dest + length > file_size)
file_size = dest + length;
+
+ ret = lseek(fd, (off_t)dest, SEEK_SET);
+ if (ret == (off_t)-1) {
+ prterr("do_clone_range: lseek");
+ report_failure(162);
+ }
+ ret = fsxread(fd, temp_buf, length, dest);
+ if (ret != length) {
+ if (ret == -1)
+ prterr("do_clone_range: read");
+ else
+ prt("short read: 0x%x bytes instead of 0x%x\n",
+ ret, length);
+ report_failure(163);
+ }
+ check_buffers(temp_buf, dest, length);
+
}
#else
@@ -1602,6 +1620,7 @@ do_copy_range(unsigned offset, unsigned length, unsigned dest)
size_t olen;
ssize_t nr;
int tries = 0;
+ int ret = 0;
if (length == 0) {
if (!quiet && testcalls > simulatedopcount)
@@ -1665,6 +1684,22 @@ do_copy_range(unsigned offset, unsigned length, unsigned dest)
memset(good_buf + file_size, '\0', dest - file_size);
if (dest + length > file_size)
file_size = dest + length;
+
+ ret = lseek(fd, (off_t)dest, SEEK_SET);
+ if (ret == (off_t)-1) {
+ prterr("do_copy_range: lseek");
+ report_failure(162);
+ }
+ ret = fsxread(fd, temp_buf, length, dest);
+ if (ret != length) {
+ if (ret == -1)
+ prterr("do_copy_range: read");
+ else
+ prt("short read: 0x%x bytes instead of 0x%x\n",
+ ret, length);
+ report_failure(163);
+ }
+ check_buffers(temp_buf, dest, length);
}
#else
--
2.7.4
next reply other threads:[~2019-09-27 1:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-27 1:53 Su Yanjun [this message]
2019-09-27 1:53 ` [PATCH v2] fsx: add more check for copy_file_range Su Yanjun
2019-10-05 19:07 ` Eryu Guan
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=1569549234-13096-1-git-send-email-suyj.fnst@cn.fujitsu.com \
--to=suyj.fnst@cn.fujitsu.com \
--cc=fstests@vger.kernel.org \
--cc=guaneryu@gmail.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;
as well as URLs for NNTP newsgroup(s).