From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: guaneryu@gmail.com
Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org
Subject: Re: [PATCH 02/10] fsx: always check buffer after each operation
Date: Tue, 20 Nov 2018 17:18:31 -0800 [thread overview]
Message-ID: <20181121011831.GP6792@magnolia> (raw)
In-Reply-To: <154275101368.8611.120389888153356093.stgit@magnolia>
On Tue, Nov 20, 2018 at 01:56:53PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
>
> Add a new option to make fsx read the file after each operation and
> compare it with the good buffer to try to catch corruptions as soon as
> they occur.
>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> ltp/fsx.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------
> 1 file changed, 56 insertions(+), 9 deletions(-)
>
>
> diff --git a/ltp/fsx.c b/ltp/fsx.c
> index 5601c70c..4b3a5d5a 100644
> --- a/ltp/fsx.c
> +++ b/ltp/fsx.c
> @@ -160,7 +160,8 @@ int punch_hole_calls = 1; /* -H flag disables */
> int zero_range_calls = 1; /* -z flag disables */
> int collapse_range_calls = 1; /* -C flag disables */
> int insert_range_calls = 1; /* -I flag disables */
> -int mapped_reads = 1; /* -R flag disables it */
> +int mapped_reads = 1; /* -R flag disables it */
> +int check_file = 1; /* -X flag disables */
[from irc discussion with dave]
This probably ought to be inverted (i.e. 0 by default, -X sets it to 1)
so that we don't go messing with internal state.
--D
> int integrity = 0; /* -i flag */
> int fsxgoodfd = 0;
> int o_direct; /* -Z */
> @@ -561,7 +562,7 @@ dump_fsync_buffer(void)
> }
>
> void
> -check_buffers(unsigned offset, unsigned size)
> +check_buffers(char *buf, unsigned offset, unsigned size)
> {
> unsigned char c, t;
> unsigned i = 0;
> @@ -569,19 +570,19 @@ check_buffers(unsigned offset, unsigned size)
> unsigned op = 0;
> unsigned bad = 0;
>
> - if (memcmp(good_buf + offset, temp_buf, size) != 0) {
> + if (memcmp(good_buf + offset, buf, size) != 0) {
> prt("READ BAD DATA: offset = 0x%x, size = 0x%x, fname = %s\n",
> offset, size, fname);
> prt("OFFSET\tGOOD\tBAD\tRANGE\n");
> while (size > 0) {
> c = good_buf[offset];
> - t = temp_buf[i];
> + t = buf[i];
> if (c != t) {
> if (n < 16) {
> - bad = short_at(&temp_buf[i]);
> + bad = short_at(&buf[i]);
> prt("0x%05x\t0x%04x\t0x%04x", offset,
> short_at(&good_buf[offset]), bad);
> - op = temp_buf[offset & 1 ? i+1 : i];
> + op = buf[offset & 1 ? i+1 : i];
> prt("\t0x%05x\n", n);
> if (op)
> prt("operation# (mod 256) for "
> @@ -725,7 +726,46 @@ doread(unsigned offset, unsigned size)
> iret, size);
> report_failure(141);
> }
> - check_buffers(offset, size);
> + check_buffers(temp_buf, offset, size);
> +}
> +
> +void
> +check_contents(void)
> +{
> + static char *check_buf;
> + unsigned offset = 0;
> + unsigned size = file_size;
> + off_t ret;
> + unsigned iret;
> +
> + if (!check_buf) {
> + check_buf = (char *) malloc(maxfilelen + writebdy);
> + assert(check_buf != NULL);
> + check_buf = round_ptr_up(check_buf, writebdy, 0);
> + memset(check_buf, '\0', maxfilelen);
> + }
> +
> + if (o_direct)
> + size -= size % readbdy;
> + if (size == 0)
> + return;
> +
> + ret = lseek(fd, (off_t)offset, SEEK_SET);
> + if (ret == (off_t)-1) {
> + prterr("doread: lseek");
> + report_failure(140);
> + }
> +
> + iret = fsxread(fd, check_buf, size, offset);
> + if (iret != size) {
> + if (iret == -1)
> + prterr("check_contents: read");
> + else
> + prt("short check read: 0x%x bytes instead of 0x%x\n",
> + iret, size);
> + report_failure(141);
> + }
> + check_buffers(check_buf, offset, size);
> }
>
>
> @@ -808,7 +848,7 @@ domapread(unsigned offset, unsigned size)
> report_failure(191);
> }
>
> - check_buffers(offset, size);
> + check_buffers(temp_buf, offset, size);
> }
>
>
> @@ -1624,6 +1664,9 @@ test(void)
> break;
> }
>
> + if (check_file)
> + check_contents();
> +
> out:
> if (sizechecks && testcalls > simulatedopcount)
> check_size();
> @@ -1684,6 +1727,7 @@ usage(void)
> -P: save .fsxlog .fsxops and .fsxgood files in dirpath (default ./)\n\
> -S seed: for random # generator (default 1) 0 gets timestamp\n\
> -W: mapped write operations DISabled\n\
> + -X: Do not read file and compare to good buffer after every operation.\n\
> -R: read() system calls only (mapped reads disabled)\n\
> -Z: O_DIRECT (use -R, -W, -r and -w too)\n\
> --replay-ops opsfile: replay ops from recorded .fsxops file\n\
> @@ -1880,7 +1924,7 @@ main(int argc, char **argv)
> setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
>
> while ((ch = getopt_long(argc, argv,
> - "b:c:dfg:i:j:kl:m:no:p:qr:s:t:w:xyAD:FKHzCILN:OP:RS:WZ",
> + "b:c:dfg:i:j:kl:m:no:p:qr:s:t:w:xyAD:FKHzCILN:OP:RS:WXZ",
> longopts, NULL)) != EOF)
> switch (ch) {
> case 'b':
> @@ -2044,6 +2088,9 @@ main(int argc, char **argv)
> if (!quiet)
> prt("mapped writes DISABLED\n");
> break;
> + case 'X':
> + check_file = 0;
> + break;
> case 'Z':
> o_direct = O_DIRECT;
> o_flags |= O_DIRECT;
>
next prev parent reply other threads:[~2018-11-21 11:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-20 21:56 [PATCH v2 00/10] xfstests: add copy/dedupe/clone to fsx/fsstress Darrick J. Wong
2018-11-20 21:56 ` [PATCH 01/10] fsx: shut up compiler warnings Darrick J. Wong
2018-11-20 21:56 ` [PATCH 02/10] fsx: always check buffer after each operation Darrick J. Wong
2018-11-21 1:18 ` Darrick J. Wong [this message]
2018-11-22 2:15 ` Darrick J. Wong
2018-11-20 21:56 ` [PATCH 03/10] fsx: use an enum to define the operation commands Darrick J. Wong
2018-11-20 21:57 ` [PATCH 04/10] fsx: add five-argument logging function Darrick J. Wong
2018-11-20 21:57 ` [PATCH 05/10] fsx: add clone range Darrick J. Wong
2018-11-22 2:14 ` Darrick J. Wong
2018-11-20 21:57 ` [PATCH 06/10] fsx: add FIDEDUPERANGE support Darrick J. Wong
2018-11-20 21:57 ` [PATCH 07/10] fsstress: add copy_file_range support Darrick J. Wong
2018-11-20 21:57 ` [PATCH 08/10] fsx: " Darrick J. Wong
2018-11-20 21:57 ` [PATCH 09/10] fsx: clean up copy/dedupe file range support Darrick J. Wong
2018-11-20 21:57 ` [PATCH 10/10] common/dump: disable copyrange Darrick J. Wong
2018-11-21 18:38 ` [PATCH 11/10] generic: long fsx soak tests Darrick J. Wong
2018-12-10 17:30 ` [PATCH v2 00/10] xfstests: add copy/dedupe/clone to fsx/fsstress Luis Henriques
2018-12-12 4:58 ` Darrick J. Wong
2018-12-12 11:19 ` Luis Henriques
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=20181121011831.GP6792@magnolia \
--to=darrick.wong@oracle.com \
--cc=fstests@vger.kernel.org \
--cc=guaneryu@gmail.com \
--cc=linux-xfs@vger.kernel.org \
/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).