public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ben Pfaff <blp@cs.stanford.edu>
To: ext2-dev@lists.sourceforge.net
Cc: mc@cs.stanford.edu, linux-kernel@vger.kernel.org
Subject: [CHECKER] ext3 bug in ftruncate() with O_SYNC?
Date: Sun, 20 Mar 2005 21:46:16 -0800	[thread overview]
Message-ID: <87y8chft5j.fsf@benpfaff.org> (raw)

Hi.  We're doing some checking on Linux file systems and found
what appears to be a bug in the Linux 2.6.11 implementation of
ext3: when ftruncate shrinks a file, using a file descriptor
opened with O_SYNC, the file size is not updated synchronously.
I've appended a test program that illustrates the problem.  After
this program runs, the file system shows a file with length 1031,
not 4 as would be expected if the ftruncate completed
synchronously.  (If I insert an fsync before closing the file,
the file length is correct.)

Does this look like a bug to you guys?

Thanks,

Ben.

----------------------------------------------------------------------

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>

#define CHECK(ret) if(ret < 0) {perror(0); assert(0);}

int systemf(const char *fmt, ...)
{
	static char cmd[1024];

	va_list ap;
	va_start(ap, fmt);
	vsprintf(cmd, fmt, ap);
	va_end(ap);
	
	fprintf(stderr, "running cmd \"%s\"\n", cmd);
	return system(cmd);
}

main(int argc, char *argv[])
{
	int ret, fd;
	systemf("umount /dev/sbd0");
	systemf("sbin/mkfs.ext3 -F -j -b 1024 /dev/sbd0 2048");
	systemf("sbin/e2fsck.shared -y /dev/sbd0");
	systemf("mount -t ext3 /dev/sbd0 /mnt/sbd0 -o commit=65535");
	systemf("umount /dev/sbd0");
	systemf("mount -t ext3 /dev/sbd0 /mnt/sbd0 -o commit=65535");
	
	fd = open("/mnt/sbd0/0001", O_CREAT | O_RDWR | O_SYNC, 0700);
	CHECK(fd);
	ret = write(fd, "foobar", 6);
	CHECK(ret);
	ret = ftruncate(fd, 1031);
	CHECK(ret);
	ret = pwrite(fd, "bazzle", 6, 1031 - 6);
	CHECK(ret);
	ret = ftruncate(fd, 4);
	CHECK(ret);
        ret = close(fd);
        CHECK(ret);

#if 0
	{
		#include "../sbd/sbd.h"
		int sbd_fd = open("/dev/sbd0", O_RDONLY);
		ret = ioctl(sbd_fd, SBD_COPY_DISK, 1);
		CHECK(ret);
		close(sbd_fd);
	}
#else
	systemf("reboot -f -n");
#endif
	return 0;
}



-- 
Ben Pfaff 
email: blp@cs.stanford.edu
web: http://benpfaff.org

             reply	other threads:[~2005-03-21  5:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-21  5:46 Ben Pfaff [this message]
2005-03-22  3:51 ` [CHECKER] ext3 bug in ftruncate() with O_SYNC? Andrew Morton
2005-03-23 20:42   ` Stephen C. Tweedie

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=87y8chft5j.fsf@benpfaff.org \
    --to=blp@cs.stanford.edu \
    --cc=ext2-dev@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mc@cs.stanford.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