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@phunq.net>
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@phunq.net>
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 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@phunq.net>
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Clarify destroy buffers on exit logic

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

Signed-off-by: Daniel Phillips <daniel@phunq.net>
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>
Free pages related to inode for evict_inode() path

We call free_forked_buffers() on evict_inode() path to free forked
buffers. Currently, free_forked_buffers() checks all pages even if
inode was specified, to try to free forked pages as possible as early.

But evict_inode() is called arbitrary timing, and pages on
sb->forked_buffers list would usually be under I/O path. Because
free_forked_buffers() is called for each end of commit (i.e. only if
there is race with frontend and commit, pages are remaining on
forked_buffers after commit).

So, this changes to not try to free unrelated pages if inode was
specified to free_forked_buffers().

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