From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Jens Axboe <axboe@kernel.dk>,
"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-fsdevel@vger.kernel.org, "Theodore Ts'o" <tytso@mit.edu>,
linux-ext4 <linux-ext4@vger.kernel.org>
Subject: BLKZEROOUT + pread should return zeroes, right?
Date: Mon, 13 Oct 2014 20:01:32 -0700 [thread overview]
Message-ID: <20141014030132.GA12013@birch.djwong.org> (raw)
Hi everyone,
What's the intended behavior if I issue BLKZEROOUT against a range of disk
sectors and immediately re-read the sectors into a buffer?
I've been trying to modify e2fsprogs to use BLKZEROOUT, and I noticed today
that if I run mke2fs and e2fsck -fn enough times in a tight loop, that
eventually e2fsck complains about corruption in blocks that ought to contain
zeroes. If I dd the block in question after the failure, I get zeroes as I'd
expect.
This feels incorrect -- if I pwrite a block, then blkzeroout the block, then
re-read it, I ought to see zeroes, right? Or is BLKZEROOUT some sort of
hint that isn't perfectly reliable, a la BLKDISCARD? Or maybe I'm just doing
it incorrectly? I looked at block/blk-num.c, this seems like it ought to be
ok.
I boiled the whole thing down into the attached test program, which can
reproduce the symptoms in a few loop iterations. If I insert "sleep(1);"
before the pread64, I pread zeroes every time; otherwise, I only pread zeroes
part of the time. If I call "ioctl(fd, BLKFLSBUF);" before the BLKZEROOUT, the
chances of preading zeroes increases dramatically, but is still not 100%.
So, uh, is this a bug? Or is that just how BLKZEROOUT works? Or did I fubar
the ioctl call?
$ gcc -Wall -g -o test test.c
$ sudo ./test /dev/sda
6: ERR 0 (0xffffffff)
--D
/* silly test program */
#define _XOPEN_SOURCE 600
#define _DARWIN_C_SOURCE
#define _FILE_OFFSET_BITS 64
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <sys/types.h>
#include <string.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <unistd.h>
#include <assert.h>
#define BUFSZ 4096
static int run(int iteration, const char *fname)
{
char buf[BUFSZ];
ssize_t sz;
uint64_t range[2];
int fd, ret, i;
printf("%d\r", iteration);
fflush(stdout);
fd = open(fname, O_RDWR);
if (fd < 0)
return 1;
memset(buf, 0xFF, BUFSZ);
sz = pwrite64(fd, buf, BUFSZ, 0);
if (sz != BUFSZ)
return 2;
range[0] = 0;
range[1] = 4096;
ret = ioctl(fd, BLKZEROOUT, range);
if (ret)
return 5;
sz = pread64(fd, buf, BUFSZ, 0);
if (sz != BUFSZ)
return 7;
for (i = 0; i < BUFSZ; i++) {
if (buf[i]) {
printf("%d: ERR %d (0x%x)\n", iteration, i, buf[i]);
return 8;
}
}
close(fd);
return 0;
}
int main(int argc, char *argv[])
{
int iter = 0;
int ret;
if (argc != 2) {
printf("Usage: %s blkdev\n", argv[0]);
return 0;
}
do {
ret = run(iter++, argv[1]);
} while (!ret);
return ret;
}
next reply other threads:[~2014-10-14 3:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-14 3:01 Darrick J. Wong [this message]
2014-10-14 4:27 ` BLKZEROOUT + pread should return zeroes, right? Dave Chinner
2014-10-14 6:02 ` Darrick J. Wong
2014-10-14 6:32 ` Theodore Ts'o
2014-10-15 1:25 ` Darrick J. Wong
2014-10-15 1:32 ` Martin K. Petersen
2014-10-16 20:04 ` Darrick J. Wong
2014-10-15 10:02 ` Theodore Ts'o
2014-10-15 12:09 ` Martin K. Petersen
2014-10-18 0:03 ` [RFC PATCH] block: make BLKZEROOUT invalidate page cache contents Darrick J. Wong
2014-10-14 9:21 ` BLKZEROOUT + pread should return zeroes, right? Christoph Hellwig
2014-10-14 13:44 ` Martin K. Petersen
2014-10-14 18:57 ` Zach Brown
2014-10-14 20:21 ` Dave Chinner
2014-10-15 1:02 ` Martin K. Petersen
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=20141014030132.GA12013@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=axboe@kernel.dk \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=tytso@mit.edu \
/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).