linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ryan Cumming <ryan@completely.kicks-ass.org>
To: chrisl@gnuchina.org, "Theodore Ts'o" <tytso@mit.edu>,
	Andreas Dilger <adilger@clusterfs.com>,
	linux-kernel@vger.kernel.org, ext2-devel@lists.sourceforge.net
Subject: Re: [PATCH] fix htree dir corrupt after fsck -fD
Date: Sun, 29 Sep 2002 01:36:51 -0700	[thread overview]
Message-ID: <200209290136.53403.ryan@completely.kicks-ass.org> (raw)
In-Reply-To: <200209290117.02331.ryan@completely.kicks-ass.org>

[-- Attachment #1: clearsigned data --]
[-- Type: Text/Plain, Size: 1035 bytes --]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On September 29, 2002 01:16, Ryan Cumming wrote:
> This is a completely fresh loopback EXT3 filesystem, untouched by fsck -D,
> and normally unmounted.

Oh, and I've attached the current version of my test program if anyone is 
interested.

It spawns 8 child processes which repeatedly create up to 1,000,000 files 
each, stat up to 1,000,000 (probably) non-existant files, and then unlink the 
files they created.

It also spawns another 4 processes which iterate over all of the directory 
entries using readdir(). For each file it encounters, it has an equal 
probability of renaming it, unlinking it, or truncating it to a random 
length.

It can corrupt my loopback test filesystems in under 5 minutes. Note that it 
will completely destroy any data in its working directory, however.

- -Ryan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)

iD8DBQE9lrulLGMzRzbJfbQRAgxMAJ46Y/L4FA8nuwe76MyGCyhG+mSE3QCgjb5a
TBJbqp55p5yOU2BY0AnW/TA=
=cKn9
-----END PGP SIGNATURE-----

[-- Attachment #2: fs-ream.c --]
[-- Type: text/x-csrc, Size: 1982 bytes --]

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>

#define BLIND_THREADS			8
#define READDIR_THREADS			4
#define MAX_FILE_COUNT_PER_THREAD	200000
#define SYNC_INTERVAL			1
#define MAX_FILE_SIZE			(8 * 1024 * 1024)

void blind_thread();
void readdir_thread();

int main(int argc, char *argv[])
{
	int i = 0;

	for(i = 0;i < BLIND_THREADS;i++)
	{
		if (!fork())
		{
			blind_thread();
		}
	}
	for(i = 0;i < READDIR_THREADS;i++)
	{
		if (!fork())
		{
			readdir_thread();
		}
	}


	while(1)
	{
		sleep(SYNC_INTERVAL);
		sync();
	}

	return 0;
}

void blind_thread()
{
	while(1) 
	{
		unsigned int seed;
		struct timeval tv;
		int i;
		int count;

		gettimeofday(&tv, NULL);
		seed = tv.tv_usec;
		count = seed % MAX_FILE_COUNT_PER_THREAD;

		srand(seed);
		printf("Creating %i files\n" , count);
		for(i = 0; i < count;i++)
		{
			char filename[32];
			snprintf(filename, 32, "%x", rand());
			close(open(filename, O_CREAT | O_RDONLY));
		}

		printf("Performing %i random lookups\n" , count);
		for(i = 0; i < count;i++)
		{
			char filename[32];
			struct stat useless;

			snprintf(filename, 32, "%x", rand());
			stat(filename, &useless);
		}

		srand(seed);
		printf("Unlinking %i files\n" , count);
		for(i = 0; i < count;i++)
		{
			char filename[32];
			snprintf(filename, 32, "%x", rand());
			unlink(filename);
		}
	}
}

void readdir_thread()
{
	while(1)
	{
		DIR *dir;
		struct dirent *entry;
		dir = opendir(".");

		while((entry = readdir(dir)))
		{
			struct stat st;
			stat(entry->d_name, &st);

			if (S_ISREG(st.st_mode))
			{
				switch(rand() % 3)
				{
				case 0:
					unlink(entry->d_name);
				case 1:
					truncate(entry->d_name, rand() % MAX_FILE_SIZE);
				case 2:
					{
						char filename[32];
						snprintf(filename, 32, "%x", rand());
						rename(entry->d_name, filename);
					}
				}
			}
		}

		closedir(dir);
	}
}

  reply	other threads:[~2002-09-29  8:31 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-25 20:03 [BK PATCH] Add ext3 indexed directory (htree) support tytso
2002-09-25 20:34 ` Andreas Dilger
2002-09-25 20:41 ` Dave Jones
2002-09-25 21:08   ` Andreas Dilger
2002-09-25 21:34   ` Theodore Ts'o
2002-09-25 22:54 ` Jeff Garzik
2002-09-25 23:29   ` Theodore Ts'o
2002-09-25 23:45     ` Ryan Cumming
2002-09-26  3:27       ` Theodore Ts'o
2002-09-26  5:23         ` Ryan Cumming
2002-09-26  5:57           ` Theodore Ts'o
2002-09-26  6:22             ` Ryan Cumming
2002-09-26 14:05               ` Theodore Ts'o
2002-09-26  6:25             ` Ryan Cumming
2002-09-26 11:25               ` Daniel Egger
2002-09-26  7:41             ` Ryan Cumming
2002-09-26 13:23               ` Theodore Ts'o
2002-09-26 15:42               ` Theodore Ts'o
2002-09-26 19:08                 ` Ryan Cumming
2002-09-26 19:51                   ` Horst von Brand
2002-09-26 19:59                     ` Ryan Cumming
2002-09-26 22:04                   ` Theodore Ts'o
2002-09-26 22:53                     ` Ryan Cumming
2002-09-26 23:57                       ` Theodore Ts'o
2002-09-27  1:00                         ` Ryan Cumming
2002-09-27  3:24                           ` Theodore Ts'o
2002-09-27  4:12                         ` Andreas Dilger
2002-09-27  7:55                           ` Ryan Cumming
2002-09-28  1:20                           ` Ryan Cumming
2002-09-28  1:46                             ` Ryan Cumming
2002-09-28 14:13                             ` Theodore Ts'o
2002-09-28 14:18                               ` Theodore Ts'o
2002-09-28 22:35                                 ` Ryan Cumming
2002-09-28 17:27                               ` [Ext2-devel] " Andreas Dilger
2002-09-28 18:43                                 ` chrisl
2002-09-28 19:45                                 ` chrisl
2002-09-28 22:30                               ` Ryan Cumming
2002-09-29  7:03                               ` [PATCH] fix htree dir corrupt after fsck -fD chrisl
2002-09-29  8:16                                 ` Ryan Cumming
2002-09-29  8:36                                   ` Ryan Cumming [this message]
2002-09-30  2:46                                   ` Ryan Cumming
2002-09-29 14:13                                 ` Theodore Ts'o
2002-09-25 23:31 ` [BK PATCH] Add ext3 indexed directory (htree) support Daniel Egger
2002-09-26  0:32   ` Randy.Dunlap
2002-09-26  0:50 ` Aaron Lehmann
2002-09-26  3:28   ` Theodore Ts'o
2002-09-29 17:12 [PATCH] fix htree dir corrupt after fsck -fD Marc-Christian 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=200209290136.53403.ryan@completely.kicks-ass.org \
    --to=ryan@completely.kicks-ass.org \
    --cc=adilger@clusterfs.com \
    --cc=chrisl@gnuchina.org \
    --cc=ext2-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --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).