From: Jeff Moyer <jmoyer@redhat.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Zach Brown <zach.brown@oracle.com>, linux-kernel@vger.kernel.org
Subject: Re: [patch] call truncate_inode_pages in the DIO fallback to buffered I/O path
Date: Wed, 04 Oct 2006 17:22:46 -0400 [thread overview]
Message-ID: <x494puj7p3t.fsf@segfault.boston.devel.redhat.com> (raw)
In-Reply-To: <x49ejtn7qfy.fsf@segfault.boston.devel.redhat.com> (Jeff Moyer's message of "Wed, 04 Oct 2006 16:53:53 -0400")
==> Regarding Re: [patch] call truncate_inode_pages in the DIO fallback to buffered I/O path; Jeff Moyer <jmoyer@redhat.com> adds:
jmoyer> Again, sorry that I didn't include a better description. I've
jmoyer> attached my reproducer to this message.
Oops, forgot to attach it.
-Jeff
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
int
make_sparse(const char *filename, off_t len)
{
int fd;
fd = open(filename, O_WRONLY | O_CREAT, 0644);
if (fd < 0) {
perror("open");
return -1;
}
if (ftruncate(fd, 0) != 0) {
perror("ftruncate");
return -1;
}
if (ftruncate(fd, len) != 0) {
perror("ftruncate");
return -1;
}
close(fd);
return 0;
}
int
main(int argc, char **argv)
{
int fd, i, nr_pages, ret;
off_t len;
int page_size = getpagesize();
char *buf;
char *pattern;
if (argc < 3) {
printf("Usage: %s <filename> <size-in-megabytes>\n", argv[0]);
exit(1);
}
/* convert length to megabytes */
len = strtoul(argv[2], NULL, 10);
len <<= 20;
if (make_sparse(argv[1], len) < 0)
exit(4);
nr_pages = len / page_size;
if ((ret = posix_memalign((void **)&buf, 1024, page_size)) != 0) {
errno = ret;
perror("posix_memalign");
exit(2);
}
fd = open(argv[1], O_WRONLY | O_CREAT | O_DIRECT);
if (fd < 0) {
perror("open");
exit(3);
}
memset(buf, 'b', page_size);
for (i = 0; i < nr_pages; i++) {
ret = write(fd, buf, page_size);
if (ret < 0) {
perror("write");
exit(5);
}
}
close(fd);
/* now read the data back in and make sure it hit the disk! */
pattern = malloc(page_size);
if (!pattern) {
perror("malloc");
exit(1);
}
memset(pattern, 'b', page_size);
fd = open(argv[1], O_RDONLY);
if (fd < 0) {
perror("open");
exit(1);
}
while (i < len) {
memset(buf, 0, sizeof(buf));
ret = read(fd, buf, page_size);
if (ret != page_size) {
if (ret < 0)
perror("read");
else
fprintf(stderr, "short read of %d\n", ret);
exit(1);
}
if (memcmp(buf, pattern, page_size)) {
fprintf(stderr, "Invalid Data!\n");
exit(1);
}
i += page_size;
}
exit(0);
}
next prev parent reply other threads:[~2006-10-04 21:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-04 17:04 Jeff Moyer
2006-10-04 17:25 ` Andrew Morton
2006-10-04 17:51 ` Zach Brown
2006-10-04 17:53 ` Jeff Moyer
2006-10-04 18:16 ` Andrew Morton
2006-10-04 18:40 ` Zach Brown
2006-10-04 19:16 ` Andrew Morton
2006-10-04 20:53 ` Jeff Moyer
2006-10-04 21:22 ` Jeff Moyer [this message]
2006-10-04 23:55 ` Andrew Morton
2006-10-05 19:31 ` Jeff Moyer
2006-10-06 20:11 ` Andrew Morton
2006-10-11 16:48 ` jmoyer
2006-10-11 18:37 ` Andrew Morton
2006-10-12 22:01 ` Jeff Moyer
2006-10-12 22:37 ` Andrew Morton
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=x494puj7p3t.fsf@segfault.boston.devel.redhat.com \
--to=jmoyer@redhat.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=zach.brown@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
all inboxes | Powered by JetHome®