1. 20 11月, 2009 5 次提交
    • D
      FS-Cache: Fix lock misorder in fscache_write_op() · 1bccf513
      David Howells 提交于
      FS-Cache has two structs internally for keeping track of the internal state of
      a cached file: the fscache_cookie struct, which represents the netfs's state,
      and fscache_object struct, which represents the cache's state.  Each has a
      pointer that points to the other (when both are in existence), and each has a
      spinlock for pointer maintenance.
      
      Since netfs operations approach these structures from the cookie side, they get
      the cookie lock first, then the object lock.  Cache operations, on the other
      hand, approach from the object side, and get the object lock first.  It is not
      then permitted for a cache operation to get the cookie lock whilst it is
      holding the object lock lest deadlock occur; instead, it must do one of two
      things:
      
       (1) increment the cookie usage counter, drop the object lock and then get both
           locks in order, or
      
       (2) simply hold the object lock as certain parts of the cookie may not be
           altered whilst the object lock is held.
      
      It is also not permitted to follow either pointer without holding the lock at
      the end you start with.  To break the pointers between the cookie and the
      object, both locks must be held.
      
      fscache_write_op(), however, violates the locking rules: It attempts to get the
      cookie lock without (a) checking that the cookie pointer is a valid pointer,
      and (b) holding the object lock to protect the cookie pointer whilst it follows
      it.  This is so that it can access the pending page store tree without
      interference from __fscache_write_page().
      
      This is fixed by splitting the cookie lock, such that the page store tracking
      tree is protected by its own lock, and checking that the cookie pointer is
      non-NULL before we attempt to follow it whilst holding the object lock.
      
      The new lock is subordinate to both the cookie lock and the object lock, and so
      should be taken after those.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      1bccf513
    • D
      FS-Cache: Permit cache retrieval ops to be interrupted in the initial wait phase · 5753c441
      David Howells 提交于
      Permit the operations to retrieve data from the cache or to allocate space in
      the cache for future writes to be interrupted whilst they're waiting for
      permission for the operation to proceed.  Typically this wait occurs whilst the
      cache object is being looked up on disk in the background.
      
      If an interruption occurs, and the operation has not yet been given the
      go-ahead to run, the operation is dequeued and cancelled, and control returns
      to the read operation of the netfs routine with none of the requested pages
      having been read or in any way marked as known by the cache.
      
      This means that the initial wait is done interruptibly rather than
      uninterruptibly.
      
      In addition, extra stats values are made available to show the number of ops
      cancelled and the number of cache space allocations interrupted.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      5753c441
    • D
      FS-Cache: Add counters for entry/exit to/from cache operation functions · 52bd75fd
      David Howells 提交于
      Count entries to and exits from cache operation table functions.  Maintain
      these as a single counter that's added to or removed from as appropriate.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      52bd75fd
    • D
      FS-Cache: Allow the current state of all objects to be dumped · 4fbf4291
      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 "<restrictions>" @s
      
      The <restrictions> 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: NDavid Howells <dhowells@redhat.com>
      4fbf4291
    • D
      FS-Cache: Annotate slow-work runqueue proc lines for FS-Cache work items · 440f0aff
      David Howells 提交于
      Annotate slow-work runqueue proc lines for FS-Cache work items.  Objects
      include the object ID and the state.  Operations include the object ID, the
      operation ID and the operation type and state.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      440f0aff
  2. 03 4月, 2009 1 次提交
    • D
      FS-Cache: Implement data I/O part of netfs API · b5108822
      David Howells 提交于
      Implement the data I/O part of the FS-Cache netfs API.  The documentation and
      API header file were added in a previous patch.
      
      This patch implements the following functions for the netfs to call:
      
       (*) fscache_attr_changed().
      
           Indicate that the object has changed its attributes.  The only attribute
           currently recorded is the file size.  Only pages within the set file size
           will be stored in the cache.
      
           This operation is submitted for asynchronous processing, and will return
           immediately.  It will return -ENOMEM if an out of memory error is
           encountered, -ENOBUFS if the object is not actually cached, or 0 if the
           operation is successfully queued.
      
       (*) fscache_read_or_alloc_page().
       (*) fscache_read_or_alloc_pages().
      
           Request data be fetched from the disk, and allocate internal metadata to
           track the netfs pages and reserve disk space for unknown pages.
      
           These operations perform semi-asynchronous data reads.  Upon returning
           they will indicate which pages they think can be retrieved from disk, and
           will have set in progress attempts to retrieve those pages.
      
           These will return, in order of preference, -ENOMEM on memory allocation
           error, -ERESTARTSYS if a signal interrupted proceedings, -ENODATA if one
           or more requested pages are not yet cached, -ENOBUFS if the object is not
           actually cached or if there isn't space for future pages to be cached on
           this object, or 0 if successful.
      
           In the case of the multipage function, the pages for which reads are set
           in progress will be removed from the list and the page count decreased
           appropriately.
      
           If any read operations should fail, the completion function will be given
           an error, and will also be passed contextual information to allow the
           netfs to fall back to querying the server for the absent pages.
      
           For each successful read, the page completion function will also be
           called.
      
           Any pages subsequently tracked by the cache will have PG_fscache set upon
           them on return.  fscache_uncache_page() must be called for such pages.
      
           If supplied by the netfs, the mark_pages_cached() cookie op will be
           invoked for any pages now tracked.
      
       (*) fscache_alloc_page().
      
           Allocate internal metadata to track a netfs page and reserve disk space.
      
           This will return -ENOMEM on memory allocation error, -ERESTARTSYS on
           signal, -ENOBUFS if the object isn't cached, or there isn't enough space
           in the cache, or 0 if successful.
      
           Any pages subsequently tracked by the cache will have PG_fscache set upon
           them on return.  fscache_uncache_page() must be called for such pages.
      
           If supplied by the netfs, the mark_pages_cached() cookie op will be
           invoked for any pages now tracked.
      
       (*) fscache_write_page().
      
           Request data be stored to disk.  This may only be called on pages that
           have been read or alloc'd by the above three functions and have not yet
           been uncached.
      
           This will return -ENOMEM on memory allocation error, -ERESTARTSYS on
           signal, -ENOBUFS if the object isn't cached, or there isn't immediately
           enough space in the cache, or 0 if successful.
      
           On a successful return, this operation will have queued the page for
           asynchronous writing to the cache.  The page will be returned with
           PG_fscache_write set until the write completes one way or another.  The
           caller will not be notified if the write fails due to an I/O error.  If
           that happens, the object will become available and all pending writes will
           be aborted.
      
           Note that the cache may batch up page writes, and so it may take a while
           to get around to writing them out.
      
           The caller must assume that until PG_fscache_write is cleared the page is
           use by the cache.  Any changes made to the page may be reflected on disk.
           The page may even be under DMA.
      
       (*) fscache_uncache_page().
      
           Indicate that the cache should stop tracking a page previously read or
           alloc'd from the cache.  If the page was alloc'd only, but unwritten, it
           will not appear on disk.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NSteve Dickson <steved@redhat.com>
      Acked-by: NTrond Myklebust <Trond.Myklebust@netapp.com>
      Acked-by: NAl Viro <viro@zeniv.linux.org.uk>
      Tested-by: NDaire Byrne <Daire.Byrne@framestore.com>
      b5108822