On Wed, Jun 23, 1999 at 08:04:53AM +0200, Peter van der Landen wrote:
> The Cyrus documentation suggests using chattr -R +S on the queue directories
> as well as the mailboxes. Would that be less effective than using a
> sync-mounted filesystem?

Dan fsyncs explicitely all the _files_ when needed, so there's no problem
with them. But in Linux the metadata, e.g. the directory entries are not
written synchronously by default. Suppose qmail receives a mail message,
writes it to the queue, fsyncs it and reports mail received. In case of
power failure at this point the file was written ok but its directory entry
was not on disk yet. After bootup fsck puts the message to /lost+found
where you can find it but it is not in the qmail queue.

The solution that Linus proposed was to fsync the _directory_ too in
addition to the _file_ and that is what my shared library does. Actually it
fsyncs the directories every time when link, unlink, open and rename system
calls are used (they update directory entries), needed or not.

Dan's suggestion is to mount all the file systems with option "sync". It
makes all writing to that file system synchronous which might be a bit
overkill when the problem is only with metadata.

chattr +S is a good idea but it doesn't work. I guess it works for _files_:
a file with that attribute is written synchronously. But there is no problem
in that field in case of qmail because Dan uses fsyncs. (With sendmail,
procmail, poppers and imappers it may be different.) But chattr +S does not
make writing the directory entries synchronous which is the problem. I
tested it a year ago and it didn't work for Linux kernels in use at that
time.

You can try it yourself to see if it works or not with kernels today:

1. mkdir testdir1 testdir2
2. chattr +S testdir2
3. killall -KILL update
4. sync
5. echo "without -S" > testdir1/file1
6. echo "with -S" > testdir2/file2
7. switch off the power
8. switch on the power
9. after fsck look for the files in the directories /lost+found, testdir1
   and testdir2.
   
If the chattr trick worked you would have the file "file2" in the
directory testdir2.

Reply via email to