Fix sparse gcc-base-dir

The sparse has default value for the gcc's base directory when sparse
was compiled.  So, if gcc was updated, but sparse was not rebuilded,
sparse's default value may not work correctly.

So, this overwrites the base directory with current gcc.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Fix sparse for debian's multiarch include path

Debian patched gcc to add multiarch include path
(e.g. /usr/include/x86_64-linux-gnu).

We have to teach to sparse about this.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Don't use variable length array in clear_other_magic()

sparse warns about variable length array. And it is not good for
kernel debugging (outputs confusing asm).

For now, user is clear_other_magic() only. So, fix clear_other_magic().
If we want to this later, let's adjust sparse flags then.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Fix cleanup target for *.gcda, *.gcno, and *.orig

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Separate "coverage" target from "tests" target in Makefile

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Fix conflict of XATTR_CREATE/REPLACE and struct xattr

XATTR_CREATE/REPLACE and struct xattr are conflicting with kernel.
Don't use some sort of common name.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Fix usage of -m32 in Makefile

If arch is e.g. armv5tejl, we add -m32 to CFLAGS. But, actually, We
just want to use -m32 only if i686.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Add command line option parser to replace getopt

Signed-off-by: Daniel Phillips <daniel@tux3.org>
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Suppress sparse warning for ptr-subtraction-blows

sparse warns if structure is not power-of-two, and using pointer
subtraction. This seems to be useless.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Convert tux3.c to new options parser

This adds help and usage autogenerate and other conveniences
Separate command line parsing from tux3 filesystem operations

Signed-off-by: Daniel Phillips <daniel@tux3.org>
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cleanup INIT_DISKSB() usage

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Fix sparse warning for TUX3_MAGIC

sparse warns about initialization of disksuper->magic.

tests/balloc.c:268:21: warning: too long initializer-string for array of char

This doesn't have problem though, warning is true.

To fix this, use exact "char [8]" type for TUX3_MAGIC. And
additionally define TUX3_MAGIC_STR as string.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Fix option parsing so per-command options can follow

Also fix the verbose option to be available globally, and per command.

Signed-off-by: Daniel Phillips <daniel@tux3.org>
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Clarify destroy buffers on exit logic

Signed-off-by: Daniel Phillips <daniel@tux3.org>
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Tidy up attributions and whitespace

Signed-off-by: Daniel Phillips <daniel@tux3.org>
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Remove extra semi-colon after logline()

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Support die() on other arch than x86

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Fix bufindex() on 32bits arch

On 32bits arch, we can't divide 64bits by 32bits. there are several
way to fix this though.

Best way would be pass "sb" to bufindex(), and use "sb->blockbits".
For now, this fixes by hack as minimal patch.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Fix error handling in replay of btree

vol_getblk() and vol_bread() returns NULL on error.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Fix race of free_forked_buffers()

If inode was evicted, it calls free_forked_buffers() to make sure all
forked buffers related to inode was freed.  So, free_forked_buffers()
is called arbitrary timing of inode reclaimer (this is also true if we
had multiple background deltas).

So, we have to make sure there is no race with free_forked_buffers(),
forked buffer, and I/O path.

Now, we have race between free_forked_buffers() and
bufvec_prepare_and_lock_page()

    free_forked_buffers()         bufvec_prepare_and_lock_page()

                                      TestClearPageDirty()
        PageDirty()
        PageWriteback()
        /* thinks I/O was done */
                                      TestSetPageWriteback()

With above race, free_forked_buffers() thinks page is not under I/O
path. But, is_freeable_forked() and buffer_busy() are assuming it is
called only if I/O for page was already done.

This fixes race by setting writeback flag before dirty.
FIXME: we would want to use refcount to free forked page somehow.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>