20 Jul, 2011

2 commits


31 Mar, 2011

1 commit


24 Jan, 2011

1 commit


15 Oct, 2010

1 commit

  • All file_operations should get a .llseek operation so we can make
    nonseekable_open the default for future file operations without a
    .llseek pointer.

    The three cases that we can automatically detect are no_llseek, seq_lseek
    and default_llseek. For cases where we can we can automatically prove that
    the file offset is always ignored, we use noop_llseek, which maintains
    the current behavior of not returning an error from a seek.

    New drivers should normally not use noop_llseek but instead use no_llseek
    and call nonseekable_open at open time. Existing drivers can be converted
    to do the same when the maintainer knows for certain that no user code
    relies on calling seek on the device file.

    The generated code is often incorrectly indented and right now contains
    comments that clarify for each added line why a specific variant was
    chosen. In the version that gets submitted upstream, the comments will
    be gone and I will manually fix the indentation, because there does not
    seem to be a way to do that using coccinelle.

    Some amount of new code is currently sitting in linux-next that should get
    the same modifications, which I will do at the end of the merge window.

    Many thanks to Julia Lawall for helping me learn to write a semantic
    patch that does all this.

    ===== begin semantic patch =====
    // This adds an llseek= method to all file operations,
    // as a preparation for making no_llseek the default.
    //
    // The rules are
    // - use no_llseek explicitly if we do nonseekable_open
    // - use seq_lseek for sequential files
    // - use default_llseek if we know we access f_pos
    // - use noop_llseek if we know we don't access f_pos,
    // but we still want to allow users to call lseek
    //
    @ open1 exists @
    identifier nested_open;
    @@
    nested_open(...)
    {

    }

    @ open exists@
    identifier open_f;
    identifier i, f;
    identifier open1.nested_open;
    @@
    int open_f(struct inode *i, struct file *f)
    {

    }

    @ read disable optional_qualifier exists @
    identifier read_f;
    identifier f, p, s, off;
    type ssize_t, size_t, loff_t;
    expression E;
    identifier func;
    @@
    ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
    {

    }

    @ read_no_fpos disable optional_qualifier exists @
    identifier read_f;
    identifier f, p, s, off;
    type ssize_t, size_t, loff_t;
    @@
    ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
    {
    ... when != off
    }

    @ write @
    identifier write_f;
    identifier f, p, s, off;
    type ssize_t, size_t, loff_t;
    expression E;
    identifier func;
    @@
    ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
    {

    }

    @ write_no_fpos @
    identifier write_f;
    identifier f, p, s, off;
    type ssize_t, size_t, loff_t;
    @@
    ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
    {
    ... when != off
    }

    @ fops0 @
    identifier fops;
    @@
    struct file_operations fops = {
    ...
    };

    @ has_llseek depends on fops0 @
    identifier fops0.fops;
    identifier llseek_f;
    @@
    struct file_operations fops = {
    ...
    .llseek = llseek_f,
    ...
    };

    @ has_read depends on fops0 @
    identifier fops0.fops;
    identifier read_f;
    @@
    struct file_operations fops = {
    ...
    .read = read_f,
    ...
    };

    @ has_write depends on fops0 @
    identifier fops0.fops;
    identifier write_f;
    @@
    struct file_operations fops = {
    ...
    .write = write_f,
    ...
    };

    @ has_open depends on fops0 @
    identifier fops0.fops;
    identifier open_f;
    @@
    struct file_operations fops = {
    ...
    .open = open_f,
    ...
    };

    // use no_llseek if we call nonseekable_open
    ////////////////////////////////////////////
    @ nonseekable1 depends on !has_llseek && has_open @
    identifier fops0.fops;
    identifier nso ~= "nonseekable_open";
    @@
    struct file_operations fops = {
    ... .open = nso, ...
    +.llseek = no_llseek, /* nonseekable */
    };

    @ nonseekable2 depends on !has_llseek @
    identifier fops0.fops;
    identifier open.open_f;
    @@
    struct file_operations fops = {
    ... .open = open_f, ...
    +.llseek = no_llseek, /* open uses nonseekable */
    };

    // use seq_lseek for sequential files
    /////////////////////////////////////
    @ seq depends on !has_llseek @
    identifier fops0.fops;
    identifier sr ~= "seq_read";
    @@
    struct file_operations fops = {
    ... .read = sr, ...
    +.llseek = seq_lseek, /* we have seq_read */
    };

    // use default_llseek if there is a readdir
    ///////////////////////////////////////////
    @ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier readdir_e;
    @@
    // any other fop is used that changes pos
    struct file_operations fops = {
    ... .readdir = readdir_e, ...
    +.llseek = default_llseek, /* readdir is present */
    };

    // use default_llseek if at least one of read/write touches f_pos
    /////////////////////////////////////////////////////////////////
    @ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier read.read_f;
    @@
    // read fops use offset
    struct file_operations fops = {
    ... .read = read_f, ...
    +.llseek = default_llseek, /* read accesses f_pos */
    };

    @ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier write.write_f;
    @@
    // write fops use offset
    struct file_operations fops = {
    ... .write = write_f, ...
    + .llseek = default_llseek, /* write accesses f_pos */
    };

    // Use noop_llseek if neither read nor write accesses f_pos
    ///////////////////////////////////////////////////////////

    @ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier read_no_fpos.read_f;
    identifier write_no_fpos.write_f;
    @@
    // write fops use offset
    struct file_operations fops = {
    ...
    .write = write_f,
    .read = read_f,
    ...
    +.llseek = noop_llseek, /* read and write both use no f_pos */
    };

    @ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier write_no_fpos.write_f;
    @@
    struct file_operations fops = {
    ... .write = write_f, ...
    +.llseek = noop_llseek, /* write uses no f_pos */
    };

    @ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    identifier read_no_fpos.read_f;
    @@
    struct file_operations fops = {
    ... .read = read_f, ...
    +.llseek = noop_llseek, /* read uses no f_pos */
    };

    @ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
    identifier fops0.fops;
    @@
    struct file_operations fops = {
    ...
    +.llseek = noop_llseek, /* no read or write fn */
    };
    ===== End semantic patch =====

    Signed-off-by: Arnd Bergmann
    Cc: Julia Lawall
    Cc: Christoph Hellwig

    Arnd Bergmann
     

13 Aug, 2010

1 commit


11 Aug, 2010

3 commits

  • Add three helpers that retrieve a refcounted copy of the root and cwd
    from the supplied fs_struct.

    get_fs_root()
    get_fs_pwd()
    get_fs_root_and_pwd()

    Signed-off-by: Miklos Szeredi
    Signed-off-by: Al Viro

    Miklos Szeredi
     
  • Dentry references should not be acquired without a corresponding
    vfsmount ref.

    Signed-off-by: Miklos Szeredi
    Acked-by: David Howells
    Signed-off-by: Al Viro

    Miklos Szeredi
     
  • * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6: (96 commits)
    no need for list_for_each_entry_safe()/resetting with superblock list
    Fix sget() race with failing mount
    vfs: don't hold s_umount over close_bdev_exclusive() call
    sysv: do not mark superblock dirty on remount
    sysv: do not mark superblock dirty on mount
    btrfs: remove junk sb_dirt change
    BFS: clean up the superblock usage
    AFFS: wait for sb synchronization when needed
    AFFS: clean up dirty flag usage
    cifs: truncate fallout
    mbcache: fix shrinker function return value
    mbcache: Remove unused features
    add f_flags to struct statfs(64)
    pass a struct path to vfs_statfs
    update VFS documentation for method changes.
    All filesystems that need invalidate_inode_buffers() are doing that explicitly
    convert remaining ->clear_inode() to ->evict_inode()
    Make ->drop_inode() just return whether inode needs to be dropped
    fs/inode.c:clear_inode() is gone
    fs/inode.c:evict() doesn't care about delete vs. non-delete paths now
    ...

    Fix up trivial conflicts in fs/nilfs2/super.c

    Linus Torvalds
     

10 Aug, 2010

1 commit

  • We'll need the path to implement the flags field for statvfs support.
    We do have it available in all callers except:

    - ecryptfs_statfs. This one doesn't actually need vfs_statfs but just
    needs to do a caller to the lower filesystem statfs method.
    - sys_ustat. Add a non-exported statfs_by_dentry helper for it which
    doesn't won't be able to fill out the flags field later on.

    In addition rename the helpers for statfs vs fstatfs to do_*statfs instead
    of the misleading vfs prefix.

    Signed-off-by: Christoph Hellwig
    Signed-off-by: Al Viro

    Christoph Hellwig
     

23 Jul, 2010

2 commits

  • Make fscache operation to use only workqueue instead of combination of
    workqueue and slow-work. FSCACHE_OP_SLOW is dropped and
    FSCACHE_OP_FAST is renamed to FSCACHE_OP_ASYNC and uses newly added
    fscache_op_wq workqueue to execute op->processor().
    fscache_operation_init_slow() is dropped and fscache_operation_init()
    now takes @processor argument directly.

    * Unbound workqueue is used.

    * fscache_retrieval_work() is no longer necessary as OP_ASYNC now does
    the equivalent thing.

    * sysctl fscache.operation_max_active added to control concurrency.
    The default value is nr_cpus clamped between 2 and
    WQ_UNBOUND_MAX_ACTIVE.

    * debugfs support is dropped for now. Tracing API based debug
    facility is planned to be added.

    Signed-off-by: Tejun Heo
    Acked-by: David Howells

    Tejun Heo
     
  • Make fscache object state transition callbacks use workqueue instead
    of slow-work. New dedicated unbound CPU workqueue fscache_object_wq
    is created. get/put callbacks are renamed and modified to take
    @object and called directly from the enqueue wrapper and the work
    function. While at it, make all open coded instances of get/put to
    use fscache_get/put_object().

    * Unbound workqueue is used.

    * work_busy() output is printed instead of slow-work flags in object
    debugging outputs. They mean basically the same thing bit-for-bit.

    * sysctl fscache.object_max_active added to control concurrency. The
    default value is nr_cpus clamped between 4 and
    WQ_UNBOUND_MAX_ACTIVE.

    * slow_work_sleep_till_thread_needed() is replaced with fscache
    private implementation fscache_object_sleep_till_congested() which
    waits on fscache_object_wq congestion.

    * debugfs support is dropped for now. Tracing API based debug
    facility is planned to be added.

    Signed-off-by: Tejun Heo
    Acked-by: David Howells

    Tejun Heo
     

13 May, 2010

1 commit

  • cachefiles_determine_cache_security() is expected to return with a
    security override in place. However, if set_create_files_as() fails, we
    fail to do this. In this case, we should just reinstate the security
    override that was set by the caller.

    Furthermore, if set_create_files_as() fails, we should dispose of the
    new credentials we were in the process of creating.

    Signed-off-by: David Howells
    Signed-off-by: Linus Torvalds

    David Howells
     

12 May, 2010

1 commit

  • Fix an occasional EIO returned by a call to vfs_unlink():

    [ 4868.465413] CacheFiles: I/O Error: Unlink failed
    [ 4868.465444] FS-Cache: Cache cachefiles stopped due to I/O error
    [ 4947.320011] CacheFiles: File cache on md3 unregistering
    [ 4947.320041] FS-Cache: Withdrawing cache "mycache"
    [ 5127.348683] FS-Cache: Cache "mycache" added (type cachefiles)
    [ 5127.348716] CacheFiles: File cache on md3 registered
    [ 7076.871081] CacheFiles: I/O Error: Unlink failed
    [ 7076.871130] FS-Cache: Cache cachefiles stopped due to I/O error
    [ 7116.780891] CacheFiles: File cache on md3 unregistering
    [ 7116.780937] FS-Cache: Withdrawing cache "mycache"
    [ 7296.813394] FS-Cache: Cache "mycache" added (type cachefiles)
    [ 7296.813432] CacheFiles: File cache on md3 registered

    What happens is this:

    (1) A cached NFS file is seen to have become out of date, so NFS retires the
    object and immediately acquires a new object with the same key.

    (2) Retirement of the old object is done asynchronously - so the lookup/create
    to generate the new object may be done first.

    This can be a problem as the old object and the new object must exist at
    the same point in the backing filesystem (i.e. they must have the same
    pathname).

    (3) The lookup for the new object sees that a backing file already exists,
    checks to see whether it is valid and sees that it isn't. It then deletes
    that file and creates a new one on disk.

    (4) The retirement phase for the old file is then performed. It tries to
    delete the dentry it has, but ext4_unlink() returns -EIO because the inode
    attached to that dentry no longer matches the inode number associated with
    the filename in the parent directory.

    The trace below shows this quite well.

    [md5sum] ==> __fscache_relinquish_cookie(ffff88002d12fb58{NFS.fh,ffff88002ce62100},1)
    [md5sum] ==> __fscache_acquire_cookie({NFS.server},{NFS.fh},ffff88002ce62100)

    NFS has retired the old cookie and asked for a new one.

    [kslowd] ==> fscache_object_state_machine({OBJ52,OBJECT_ACTIVE,24})
    [kslowd] OBJECT_DYING]
    [kslowd] ==> fscache_object_state_machine({OBJ53,OBJECT_INIT,0})
    [kslowd] OBJECT_LOOKING_UP]
    [kslowd] ==> fscache_object_state_machine({OBJ52,OBJECT_DYING,24})
    [kslowd] OBJECT_RECYCLING]

    The old object (OBJ52) is going through the terminal states to get rid of it,
    whilst the new object - (OBJ53) - is coming into being.

    [kslowd] ==> fscache_object_state_machine({OBJ53,OBJECT_LOOKING_UP,0})
    [kslowd] ==> cachefiles_walk_to_object({ffff88003029d8b8},OBJ53,@68,)
    [kslowd] lookup '@68'
    [kslowd] next -> ffff88002ce41bd0 positive
    [kslowd] advance
    [kslowd] lookup 'Es0g00og0_Nd_XCYe3BOzvXrsBLMlN6aw16M1htaA'
    [kslowd] next -> ffff8800369faac8 positive

    The new object has looked up the subdir in which the file would be in (getting
    dentry ffff88002ce41bd0) and then looked up the file itself (getting dentry
    ffff8800369faac8).

    [kslowd] validate 'Es0g00og0_Nd_XCYe3BOzvXrsBLMlN6aw16M1htaA'
    [kslowd] ==> cachefiles_bury_object(,'@68','Es0g00og0_Nd_XCYe3BOzvXrsBLMlN6aw16M1htaA')
    [kslowd] remove ffff8800369faac8 from ffff88002ce41bd0
    [kslowd] unlink stale object
    [kslowd] inode does not match i_ino.

    [kslowd] OBJECT_DEAD]
    [kslowd] ==> fscache_object_state_machine({OBJ53,OBJECT_AVAILABLE,0})
    [kslowd] OBJECT_ACTIVE]

    (Note that the above trace includes extra information beyond that produced by
    the upstream code).

    The fix is to note when an object that is being retired has had its object
    deleted preemptively by a replacement object that is being created, and to
    skip the second removal attempt in such a case.

    Reported-by: Greg M
    Reported-by: Mark Moseley
    Reported-by: Romain DEGEZ
    Signed-off-by: David Howells
    Signed-off-by: Linus Torvalds

    David Howells
     

30 Mar, 2010

1 commit

  • …it slab.h inclusion from percpu.h

    percpu.h is included by sched.h and module.h and thus ends up being
    included when building most .c files. percpu.h includes slab.h which
    in turn includes gfp.h making everything defined by the two files
    universally available and complicating inclusion dependencies.

    percpu.h -> slab.h dependency is about to be removed. Prepare for
    this change by updating users of gfp and slab facilities include those
    headers directly instead of assuming availability. As this conversion
    needs to touch large number of source files, the following script is
    used as the basis of conversion.

    http://userweb.kernel.org/~tj/misc/slabh-sweep.py

    The script does the followings.

    * Scan files for gfp and slab usages and update includes such that
    only the necessary includes are there. ie. if only gfp is used,
    gfp.h, if slab is used, slab.h.

    * When the script inserts a new include, it looks at the include
    blocks and try to put the new include such that its order conforms
    to its surrounding. It's put in the include block which contains
    core kernel includes, in the same order that the rest are ordered -
    alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
    doesn't seem to be any matching order.

    * If the script can't find a place to put a new include (mostly
    because the file doesn't have fitting include block), it prints out
    an error message indicating which .h file needs to be added to the
    file.

    The conversion was done in the following steps.

    1. The initial automatic conversion of all .c files updated slightly
    over 4000 files, deleting around 700 includes and adding ~480 gfp.h
    and ~3000 slab.h inclusions. The script emitted errors for ~400
    files.

    2. Each error was manually checked. Some didn't need the inclusion,
    some needed manual addition while adding it to implementation .h or
    embedding .c file was more appropriate for others. This step added
    inclusions to around 150 files.

    3. The script was run again and the output was compared to the edits
    from #2 to make sure no file was left behind.

    4. Several build tests were done and a couple of problems were fixed.
    e.g. lib/decompress_*.c used malloc/free() wrappers around slab
    APIs requiring slab.h to be added manually.

    5. The script was run on all .h files but without automatically
    editing them as sprinkling gfp.h and slab.h inclusions around .h
    files could easily lead to inclusion dependency hell. Most gfp.h
    inclusion directives were ignored as stuff from gfp.h was usually
    wildly available and often used in preprocessor macros. Each
    slab.h inclusion directive was examined and added manually as
    necessary.

    6. percpu.h was updated not to include slab.h.

    7. Build test were done on the following configurations and failures
    were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
    distributed build env didn't work with gcov compiles) and a few
    more options had to be turned off depending on archs to make things
    build (like ipr on powerpc/64 which failed due to missing writeq).

    * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
    * powerpc and powerpc64 SMP allmodconfig
    * sparc and sparc64 SMP allmodconfig
    * ia64 SMP allmodconfig
    * s390 SMP allmodconfig
    * alpha SMP allmodconfig
    * um on x86_64 SMP allmodconfig

    8. percpu.h modifications were reverted so that it could be applied as
    a separate patch and serve as bisection point.

    Given the fact that I had only a couple of failures from tests on step
    6, I'm fairly confident about the coverage of this conversion patch.
    If there is a breakage, it's likely to be something in one of the arch
    headers which should be easily discoverable easily on most builds of
    the specific arch.

    Signed-off-by: Tejun Heo <tj@kernel.org>
    Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>

    Tejun Heo
     

20 Feb, 2010

1 commit

  • cachefiles_delete_object() can race with rename. It gets the parent directory
    of the object it's asked to delete, then locks it - but rename may have changed
    the object's parent between the get and the completion of the lock.

    However, if such a circumstance is detected, we abandon our attempt to delete
    the object - since it's no longer in the index key path, it won't be seen
    again by lookups of that key. The assumption is that cachefilesd may have
    culled it by renaming it to the graveyard for later destruction.

    Signed-off-by: David Howells
    Signed-off-by: Al Viro

    David Howells
     

17 Dec, 2009

2 commits


16 Dec, 2009

1 commit

  • Makes use of skip_spaces() defined in lib/string.c for removing leading
    spaces from strings all over the tree.

    It decreases lib.a code size by 47 bytes and reuses the function tree-wide:
    text data bss dec hex filename
    64688 584 592 65864 10148 (TOTALS-BEFORE)
    64641 584 592 65817 10119 (TOTALS-AFTER)

    Also, while at it, if we see (*str && isspace(*str)), we can be sure to
    remove the first condition (*str) as the second one (isspace(*str)) also
    evaluates to 0 whenever *str == 0, making it redundant. In other words,
    "a char equals zero is never a space".

    Julia Lawall tried the semantic patch (http://coccinelle.lip6.fr) below,
    and found occurrences of this pattern on 3 more files:
    drivers/leds/led-class.c
    drivers/leds/ledtrig-timer.c
    drivers/video/output.c

    @@
    expression str;
    @@

    ( // ignore skip_spaces cases
    while (*str && isspace(*str)) { \(str++;\|++str;\) }
    |
    - *str &&
    isspace(*str)
    )

    Signed-off-by: André Goddard Rosa
    Cc: Julia Lawall
    Cc: Martin Schwidefsky
    Cc: Jeff Dike
    Cc: Ingo Molnar
    Cc: Thomas Gleixner
    Cc: "H. Peter Anvin"
    Cc: Richard Purdie
    Cc: Neil Brown
    Cc: Kyle McMartin
    Cc: Henrique de Moraes Holschuh
    Cc: David Howells
    Cc:
    Cc: Samuel Ortiz
    Cc: Patrick McHardy
    Cc: Takashi Iwai
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    André Goddard Rosa
     

01 Dec, 2009

1 commit


20 Nov, 2009

7 commits

  • Don't log the CacheFiles lookup/create object routined failing with ENOBUFS as
    under high memory load or high cache load they can do this quite a lot. This
    error simply means that the requested object cannot be created on disk due to
    lack of space, or due to failure of the backing filesystem to find sufficient
    resources.

    Signed-off-by: David Howells

    David Howells
     
  • Catch an overly long wait for an old, dying active object when we want to
    replace it with a new one. The probability is that all the slow-work threads
    are hogged, and the delete can't get a look in.

    What we do instead is:

    (1) if there's nothing in the slow work queue, we sleep until either the dying
    object has finished dying or there is something in the slow work queue
    behind which we can queue our object.

    (2) if there is something in the slow work queue, we return ETIMEDOUT to
    fscache_lookup_object(), which then puts us back on the slow work queue,
    presumably behind the deletion that we're blocked by. We are then
    deferred for a while until we work our way back through the queue -
    without blocking a slow-work thread unnecessarily.

    A backtrace similar to the following may appear in the log without this patch:

    INFO: task kslowd004:5711 blocked for more than 120 seconds.
    "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
    kslowd004 D 0000000000000000 0 5711 2 0x00000080
    ffff88000340bb80 0000000000000046 ffff88002550d000 0000000000000000
    ffff88002550d000 0000000000000007 ffff88000340bfd8 ffff88002550d2a8
    000000000000ddf0 00000000000118c0 00000000000118c0 ffff88002550d2a8
    Call Trace:
    [] ? trace_hardirqs_on+0xd/0xf
    [] ? cachefiles_wait_bit+0x0/0xd [cachefiles]
    [] cachefiles_wait_bit+0x9/0xd [cachefiles]
    [] __wait_on_bit+0x43/0x76
    [] ? ext3_xattr_get+0x1ec/0x270
    [] out_of_line_wait_on_bit+0x69/0x74
    [] ? cachefiles_wait_bit+0x0/0xd [cachefiles]
    [] ? wake_bit_function+0x0/0x2e
    [] cachefiles_mark_object_active+0x203/0x23b [cachefiles]
    [] cachefiles_walk_to_object+0x558/0x827 [cachefiles]
    [] cachefiles_lookup_object+0xac/0x12a [cachefiles]
    [] fscache_lookup_object+0x1c7/0x214 [fscache]
    [] fscache_object_state_machine+0xa5/0x52d [fscache]
    [] fscache_object_slow_work_execute+0x5f/0xa0 [fscache]
    [] slow_work_execute+0x18f/0x2d1
    [] slow_work_thread+0x1c5/0x308
    [] ? autoremove_wake_function+0x0/0x34
    [] ? slow_work_thread+0x0/0x308
    [] kthread+0x7a/0x82
    [] child_rip+0xa/0x20
    [] ? restore_args+0x0/0x30
    [] ? kthread+0x0/0x82
    [] ? child_rip+0x0/0x20
    1 lock held by kslowd004/5711:
    #0: (&sb->s_type->i_mutex_key#7/1){+.+.+.}, at: [] cachefiles_walk_to_object+0x1b3/0x827 [cachefiles]

    Signed-off-by: David Howells

    David Howells
     
  • Show more debugging information if cachefiles_mark_object_active() is asked to
    activate an active object.

    This may happen, for instance, if the netfs tries to register an object with
    the same key multiple times.

    The code is changed to (a) get the appropriate object lock to protect the
    cookie pointer whilst we dereference it, and (b) get and display the cookie key
    if available.

    Signed-off-by: David Howells

    David Howells
     
  • Mark parent directory locks as I_MUTEX_PARENT in the callers of
    cachefiles_bury_object() so that lockdep doesn't complain when that invokes
    vfs_unlink():

    =============================================
    [ INFO: possible recursive locking detected ]
    2.6.32-rc6-cachefs #47
    ---------------------------------------------
    kslowd002/3089 is trying to acquire lock:
    (&sb->s_type->i_mutex_key#7){+.+.+.}, at: [] vfs_unlink+0x8b/0x128

    but task is already holding lock:
    (&sb->s_type->i_mutex_key#7){+.+.+.}, at: [] cachefiles_walk_to_object+0x1b0/0x831 [cachefiles]

    other info that might help us debug this:
    1 lock held by kslowd002/3089:
    #0: (&sb->s_type->i_mutex_key#7){+.+.+.}, at: [] cachefiles_walk_to_object+0x1b0/0x831 [cachefiles]

    stack backtrace:
    Pid: 3089, comm: kslowd002 Not tainted 2.6.32-rc6-cachefs #47
    Call Trace:
    [] __lock_acquire+0x1649/0x16e3
    [] ? inode_has_perm+0x5f/0x61
    [] lock_acquire+0x57/0x6d
    [] ? vfs_unlink+0x8b/0x128
    [] mutex_lock_nested+0x54/0x292
    [] ? vfs_unlink+0x8b/0x128
    [] ? selinux_inode_permission+0x8e/0x90
    [] ? security_inode_permission+0x1c/0x1e
    [] ? inode_permission+0x99/0xa5
    [] vfs_unlink+0x8b/0x128
    [] ? kfree+0xed/0xf9
    [] cachefiles_bury_object+0xb6/0x420 [cachefiles]
    [] ? trace_hardirqs_on+0xd/0xf
    [] ? cachefiles_check_object_xattr+0x233/0x293 [cachefiles]
    [] cachefiles_walk_to_object+0x4ff/0x831 [cachefiles]
    [] ? finish_task_switch+0x0/0xb2
    [] cachefiles_lookup_object+0xac/0x12a [cachefiles]
    [] fscache_lookup_object+0x1c7/0x214 [fscache]
    [] fscache_object_state_machine+0xa5/0x52d [fscache]
    [] fscache_object_slow_work_execute+0x5f/0xa0 [fscache]
    [] slow_work_execute+0x18f/0x2d1
    [] slow_work_thread+0x1c5/0x308
    [] ? autoremove_wake_function+0x0/0x34
    [] ? slow_work_thread+0x0/0x308
    [] kthread+0x7a/0x82
    [] child_rip+0xa/0x20
    [] ? restore_args+0x0/0x30
    [] ? kthread+0x0/0x82
    [] ? child_rip+0x0/0x20

    Signed-off-by: Daivd Howells

    David Howells
     
  • Handle truncate unlocking the page we're attempting to read from the backing
    device before the read has completed.

    This was causing reports like the following to occur:

    Pid: 4765, comm: kslowd Not tainted 2.6.30.1 #1
    Call Trace:
    [] ? cachefiles_read_waiter+0xd9/0x147 [cachefiles]
    [] ? __wait_on_bit+0x60/0x6f
    [] ? __wake_up_common+0x3f/0x71
    [] ? __wake_up+0x30/0x44
    [] ? __wake_up_bit+0x28/0x2d
    [] ? ext3_truncate+0x4d7/0x8ed [ext3]
    [] ? pagevec_lookup+0x17/0x1f
    [] ? unmap_mapping_range+0x59/0x1ff
    [] ? __wake_up+0x30/0x44
    [] ? vmtruncate+0xc2/0xe2
    [] ? inode_setattr+0x22/0x10a
    [] ? ext3_setattr+0x17b/0x1e6 [ext3]
    [] ? notify_change+0x186/0x2c9
    [] ? cachefiles_attr_changed+0x133/0x1cd [cachefiles]
    [] ? cachefiles_lookup_object+0xcf/0x12a [cachefiles]
    [] ? fscache_lookup_object+0x110/0x122 [fscache]
    [] ? fscache_object_slow_work_execute+0x590/0x6bc
    [fscache]
    [] ? slow_work_thread+0x285/0x43a
    [] ? autoremove_wake_function+0x0/0x2e
    [] ? slow_work_thread+0x0/0x43a
    [] ? kthread+0x54/0x81
    [] ? child_rip+0xa/0x20
    [] ? kthread+0x0/0x81
    [] ? child_rip+0x0/0x20
    CacheFiles: I/O Error: Readpage failed on backing file 200000000000810
    FS-Cache: Cache cachefiles stopped due to I/O error

    Reported-by: Christian Kujau
    Reported-by: Takashi Iwai
    Reported-by: Duc Le Minh
    Signed-off-by: David Howells

    David Howells
     
  • cachefiles_write_page() writes a full page to the backing file for the last
    page of the netfs file, even if the netfs file's last page is only a partial
    page.

    This causes the EOF on the backing file to be extended beyond the EOF of the
    netfs, and thus the backing file will be truncated by cachefiles_attr_changed()
    called from cachefiles_lookup_object().

    So we need to limit the write we make to the backing file on that last page
    such that it doesn't push the EOF too far.

    Also, if a backing file that has a partial page at the end is expanded, we
    discard the partial page and refetch it on the basis that we then have a hole
    in the file with invalid data, and should the power go out... A better way to
    deal with this could be to record a note that the partial page contains invalid
    data until the correct data is written into it.

    This isn't a problem for netfs's that discard the whole backing file if the
    file size changes (such as NFS).

    Signed-off-by: David Howells

    David Howells
     
  • Allow the current state of all fscache objects to be dumped by doing:

    cat /proc/fs/fscache/objects

    By default, all objects and all fields will be shown. This can be restricted
    by adding a suitable key to one of the caller's keyrings (such as the session
    keyring):

    keyctl add user fscache:objlist "" @s

    The are:

    K Show hexdump of object key (don't show if not given)
    A Show hexdump of object aux data (don't show if not given)

    And paired restrictions:

    C Show objects that have a cookie
    c Show objects that don't have a cookie
    B Show objects that are busy
    b Show objects that aren't busy
    W Show objects that have pending writes
    w Show objects that don't have pending writes
    R Show objects that have outstanding reads
    r Show objects that don't have outstanding reads
    S Show objects that have slow work queued
    s Show objects that don't have slow work queued

    If neither side of a restriction pair is given, then both are implied. For
    example:

    keyctl add user fscache:objlist KB @s

    shows objects that are busy, and lists their object keys, but does not dump
    their auxiliary data. It also implies "CcWwRrSs", but as 'B' is given, 'b' is
    not implied.

    Signed-off-by: David Howells

    David Howells
     

12 Jun, 2009

2 commits


28 May, 2009

1 commit


03 Apr, 2009

1 commit

  • Add an FS-Cache cache-backend that permits a mounted filesystem to be used as a
    backing store for the cache.

    CacheFiles uses a userspace daemon to do some of the cache management - such as
    reaping stale nodes and culling. This is called cachefilesd and lives in
    /sbin. The source for the daemon can be downloaded from:

    http://people.redhat.com/~dhowells/cachefs/cachefilesd.c

    And an example configuration from:

    http://people.redhat.com/~dhowells/cachefs/cachefilesd.conf

    The filesystem and data integrity of the cache are only as good as those of the
    filesystem providing the backing services. Note that CacheFiles does not
    attempt to journal anything since the journalling interfaces of the various
    filesystems are very specific in nature.

    CacheFiles creates a misc character device - "/dev/cachefiles" - that is used
    to communication with the daemon. Only one thing may have this open at once,
    and whilst it is open, a cache is at least partially in existence. The daemon
    opens this and sends commands down it to control the cache.

    CacheFiles is currently limited to a single cache.

    CacheFiles attempts to maintain at least a certain percentage of free space on
    the filesystem, shrinking the cache by culling the objects it contains to make
    space if necessary - see the "Cache Culling" section. This means it can be
    placed on the same medium as a live set of data, and will expand to make use of
    spare space and automatically contract when the set of data requires more
    space.

    ============
    REQUIREMENTS
    ============

    The use of CacheFiles and its daemon requires the following features to be
    available in the system and in the cache filesystem:

    - dnotify.

    - extended attributes (xattrs).

    - openat() and friends.

    - bmap() support on files in the filesystem (FIBMAP ioctl).

    - The use of bmap() to detect a partial page at the end of the file.

    It is strongly recommended that the "dir_index" option is enabled on Ext3
    filesystems being used as a cache.

    =============
    CONFIGURATION
    =============

    The cache is configured by a script in /etc/cachefilesd.conf. These commands
    set up cache ready for use. The following script commands are available:

    (*) brun %
    (*) bcull %
    (*) bstop %
    (*) frun %
    (*) fcull %
    (*) fstop %

    Configure the culling limits. Optional. See the section on culling
    The defaults are 7% (run), 5% (cull) and 1% (stop) respectively.

    The commands beginning with a 'b' are file space (block) limits, those
    beginning with an 'f' are file count limits.

    (*) dir

    Specify the directory containing the root of the cache. Mandatory.

    (*) tag

    Specify a tag to FS-Cache to use in distinguishing multiple caches.
    Optional. The default is "CacheFiles".

    (*) debug

    Specify a numeric bitmask to control debugging in the kernel module.
    Optional. The default is zero (all off). The following values can be
    OR'd into the mask to collect various information:

    1 Turn on trace of function entry (_enter() macros)
    2 Turn on trace of function exit (_leave() macros)
    4 Turn on trace of internal debug points (_debug())

    This mask can also be set through sysfs, eg:

    echo 5 >/sys/modules/cachefiles/parameters/debug

    ==================
    STARTING THE CACHE
    ==================

    The cache is started by running the daemon. The daemon opens the cache device,
    configures the cache and tells it to begin caching. At that point the cache
    binds to fscache and the cache becomes live.

    The daemon is run as follows:

    /sbin/cachefilesd [-d]* [-s] [-n] [-f ]

    The flags are:

    (*) -d

    Increase the debugging level. This can be specified multiple times and
    is cumulative with itself.

    (*) -s

    Send messages to stderr instead of syslog.

    (*) -n

    Don't daemonise and go into background.

    (*) -f

    Use an alternative configuration file rather than the default one.

    ===============
    THINGS TO AVOID
    ===============

    Do not mount other things within the cache as this will cause problems. The
    kernel module contains its own very cut-down path walking facility that ignores
    mountpoints, but the daemon can't avoid them.

    Do not create, rename or unlink files and directories in the cache whilst the
    cache is active, as this may cause the state to become uncertain.

    Renaming files in the cache might make objects appear to be other objects (the
    filename is part of the lookup key).

    Do not change or remove the extended attributes attached to cache files by the
    cache as this will cause the cache state management to get confused.

    Do not create files or directories in the cache, lest the cache get confused or
    serve incorrect data.

    Do not chmod files in the cache. The module creates things with minimal
    permissions to prevent random users being able to access them directly.

    =============
    CACHE CULLING
    =============

    The cache may need culling occasionally to make space. This involves
    discarding objects from the cache that have been used less recently than
    anything else. Culling is based on the access time of data objects. Empty
    directories are culled if not in use.

    Cache culling is done on the basis of the percentage of blocks and the
    percentage of files available in the underlying filesystem. There are six
    "limits":

    (*) brun
    (*) frun

    If the amount of free space and the number of available files in the cache
    rises above both these limits, then culling is turned off.

    (*) bcull
    (*) fcull

    If the amount of available space or the number of available files in the
    cache falls below either of these limits, then culling is started.

    (*) bstop
    (*) fstop

    If the amount of available space or the number of available files in the
    cache falls below either of these limits, then no further allocation of
    disk space or files is permitted until culling has raised things above
    these limits again.

    These must be configured thusly:

    0 < bcull < brun < 100
    0 < fcull < frun < 100

    Note that these are percentages of available space and available files, and do
    _not_ appear as 100 minus the percentage displayed by the "df" program.

    The userspace daemon scans the cache to build up a table of cullable objects.
    These are then culled in least recently used order. A new scan of the cache is
    started as soon as space is made in the table. Objects will be skipped if
    their atimes have changed or if the kernel module says it is still using them.

    ===============
    CACHE STRUCTURE
    ===============

    The CacheFiles module will create two directories in the directory it was
    given:

    (*) cache/

    (*) graveyard/

    The active cache objects all reside in the first directory. The CacheFiles
    kernel module moves any retired or culled objects that it can't simply unlink
    to the graveyard from which the daemon will actually delete them.

    The daemon uses dnotify to monitor the graveyard directory, and will delete
    anything that appears therein.

    The module represents index objects as directories with the filename "I..." or
    "J...". Note that the "cache/" directory is itself a special index.

    Data objects are represented as files if they have no children, or directories
    if they do. Their filenames all begin "D..." or "E...". If represented as a
    directory, data objects will have a file in the directory called "data" that
    actually holds the data.

    Special objects are similar to data objects, except their filenames begin
    "S..." or "T...".

    If an object has children, then it will be represented as a directory.
    Immediately in the representative directory are a collection of directories
    named for hash values of the child object keys with an '@' prepended. Into
    this directory, if possible, will be placed the representations of the child
    objects:

    INDEX INDEX INDEX DATA FILES
    ========= ========== ================================= ================
    cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400
    cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...DB1ry
    cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...N22ry
    cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...FP1ry

    If the key is so long that it exceeds NAME_MAX with the decorations added on to
    it, then it will be cut into pieces, the first few of which will be used to
    make a nest of directories, and the last one of which will be the objects
    inside the last directory. The names of the intermediate directories will have
    '+' prepended:

    J1223/@23/+xy...z/+kl...m/Epqr

    Note that keys are raw data, and not only may they exceed NAME_MAX in size,
    they may also contain things like '/' and NUL characters, and so they may not
    be suitable for turning directly into a filename.

    To handle this, CacheFiles will use a suitably printable filename directly and
    "base-64" encode ones that aren't directly suitable. The two versions of
    object filenames indicate the encoding:

    OBJECT TYPE PRINTABLE ENCODED
    =============== =============== ===============
    Index "I..." "J..."
    Data "D..." "E..."
    Special "S..." "T..."

    Intermediate directories are always "@" or "+" as appropriate.

    Each object in the cache has an extended attribute label that holds the object
    type ID (required to distinguish special objects) and the auxiliary data from
    the netfs. The latter is used to detect stale objects in the cache and update
    or retire them.

    Note that CacheFiles will erase from the cache any file it doesn't recognise or
    any file of an incorrect type (such as a FIFO file or a device file).

    ==========================
    SECURITY MODEL AND SELINUX
    ==========================

    CacheFiles is implemented to deal properly with the LSM security features of
    the Linux kernel and the SELinux facility.

    One of the problems that CacheFiles faces is that it is generally acting on
    behalf of a process, and running in that process's context, and that includes a
    security context that is not appropriate for accessing the cache - either
    because the files in the cache are inaccessible to that process, or because if
    the process creates a file in the cache, that file may be inaccessible to other
    processes.

    The way CacheFiles works is to temporarily change the security context (fsuid,
    fsgid and actor security label) that the process acts as - without changing the
    security context of the process when it the target of an operation performed by
    some other process (so signalling and suchlike still work correctly).

    When the CacheFiles module is asked to bind to its cache, it:

    (1) Finds the security label attached to the root cache directory and uses
    that as the security label with which it will create files. By default,
    this is:

    cachefiles_var_t

    (2) Finds the security label of the process which issued the bind request
    (presumed to be the cachefilesd daemon), which by default will be:

    cachefilesd_t

    and asks LSM to supply a security ID as which it should act given the
    daemon's label. By default, this will be:

    cachefiles_kernel_t

    SELinux transitions the daemon's security ID to the module's security ID
    based on a rule of this form in the policy.

    type_transition ;

    For instance:

    type_transition cachefilesd_t kernel_t : process cachefiles_kernel_t;

    The module's security ID gives it permission to create, move and remove files
    and directories in the cache, to find and access directories and files in the
    cache, to set and access extended attributes on cache objects, and to read and
    write files in the cache.

    The daemon's security ID gives it only a very restricted set of permissions: it
    may scan directories, stat files and erase files and directories. It may
    not read or write files in the cache, and so it is precluded from accessing the
    data cached therein; nor is it permitted to create new files in the cache.

    There are policy source files available in:

    http://people.redhat.com/~dhowells/fscache/cachefilesd-0.8.tar.bz2

    and later versions. In that tarball, see the files:

    cachefilesd.te
    cachefilesd.fc
    cachefilesd.if

    They are built and installed directly by the RPM.

    If a non-RPM based system is being used, then copy the above files to their own
    directory and run:

    make -f /usr/share/selinux/devel/Makefile
    semodule -i cachefilesd.pp

    You will need checkpolicy and selinux-policy-devel installed prior to the
    build.

    By default, the cache is located in /var/fscache, but if it is desirable that
    it should be elsewhere, than either the above policy files must be altered, or
    an auxiliary policy must be installed to label the alternate location of the
    cache.

    For instructions on how to add an auxiliary policy to enable the cache to be
    located elsewhere when SELinux is in enforcing mode, please see:

    /usr/share/doc/cachefilesd-*/move-cache.txt

    When the cachefilesd rpm is installed; alternatively, the document can be found
    in the sources.

    ==================
    A NOTE ON SECURITY
    ==================

    CacheFiles makes use of the split security in the task_struct. It allocates
    its own task_security structure, and redirects current->act_as to point to it
    when it acts on behalf of another process, in that process's context.

    The reason it does this is that it calls vfs_mkdir() and suchlike rather than
    bypassing security and calling inode ops directly. Therefore the VFS and LSM
    may deny the CacheFiles access to the cache data because under some
    circumstances the caching code is running in the security context of whatever
    process issued the original syscall on the netfs.

    Furthermore, should CacheFiles create a file or directory, the security
    parameters with that object is created (UID, GID, security label) would be
    derived from that process that issued the system call, thus potentially
    preventing other processes from accessing the cache - including CacheFiles's
    cache management daemon (cachefilesd).

    What is required is to temporarily override the security of the process that
    issued the system call. We can't, however, just do an in-place change of the
    security data as that affects the process as an object, not just as a subject.
    This means it may lose signals or ptrace events for example, and affects what
    the process looks like in /proc.

    So CacheFiles makes use of a logical split in the security between the
    objective security (task->sec) and the subjective security (task->act_as). The
    objective security holds the intrinsic security properties of a process and is
    never overridden. This is what appears in /proc, and is what is used when a
    process is the target of an operation by some other process (SIGKILL for
    example).

    The subjective security holds the active security properties of a process, and
    may be overridden. This is not seen externally, and is used whan a process
    acts upon another object, for example SIGKILLing another process or opening a
    file.

    LSM hooks exist that allow SELinux (or Smack or whatever) to reject a request
    for CacheFiles to run in a context of a specific security label, or to create
    files and directories with another security label.

    This documentation is added by the patch to:

    Documentation/filesystems/caching/cachefiles.txt

    Signed-Off-By: David Howells
    Acked-by: Steve Dickson
    Acked-by: Trond Myklebust
    Acked-by: Al Viro
    Tested-by: Daire Byrne

    David Howells