91c7fbbf63
Provide fscache_cancel_op() with a pointer to a function it should invoke under lock if it cancels an operation. Use this to clear the remaining page count upon cancellation of a pending retrieval operation so that fscache_release_retrieval_op() doesn't get an assertion failure (see below). This can happen when a signal occurs, say from CTRL-C being pressed during data retrieval. FS-Cache: Assertion failed 3 == 0 is false ------------[ cut here ]------------ kernel BUG at fs/fscache/page.c:237! invalid opcode: 0000 [#641] SMP Modules linked in: cachefiles(F) nfsv4(F) nfsv3(F) nfsv2(F) nfs(F) fscache(F) auth_rpcgss(F) nfs_acl(F) lockd(F) sunrpc(F) CPU 0 Pid: 6075, comm: slurp-q Tainted: GF D 3.7.0-rc8-fsdevel+ #411 /DG965RY RIP: 0010:[<ffffffffa007f328>] [<ffffffffa007f328>] fscache_release_retrieval_op+0x75/0xff [fscache] RSP: 0000:ffff88001c6d7988 EFLAGS: 00010296 RAX: 000000000000000f RBX: ffff880014cdfe00 RCX: ffffffff6c102000 RDX: ffffffff8102d1ad RSI: ffffffff6c102000 RDI: ffffffff8102d1d6 RBP: ffff88001c6d7998 R08: 0000000000000002 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000000 R12: 00000000fffffe00 R13: ffff88001c6d7ab4 R14: ffff88001a8638a0 R15: ffff88001552b190 FS: 00007f877aaf0700(0000) GS:ffff88003bc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b CR2: 00007fff11378fd2 CR3: 000000001c6c6000 CR4: 00000000000007f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Process slurp-q (pid: 6075, threadinfo ffff88001c6d6000, task ffff88001c6c4080) Stack: ffffffffa007ec07 ffff880014cdfe00 ffff88001c6d79c8 ffffffffa007db4d ffffffffa007ec07 ffff880014cdfe00 00000000fffffe00 ffff88001c6d7ab4 ffff88001c6d7a38 ffffffffa008116d 0000000000000000 ffff88001c6c4080 Call Trace: [<ffffffffa007ec07>] ? fscache_cancel_op+0x194/0x1cf [fscache] [<ffffffffa007db4d>] fscache_put_operation+0x135/0x2ed [fscache] [<ffffffffa007ec07>] ? fscache_cancel_op+0x194/0x1cf [fscache] [<ffffffffa008116d>] __fscache_read_or_alloc_pages+0x413/0x4bc [fscache] [<ffffffff810ac8ae>] ? __alloc_pages_nodemask+0x195/0x75c [<ffffffffa00aab0f>] __nfs_readpages_from_fscache+0x86/0x13d [nfs] [<ffffffffa00a5fe0>] nfs_readpages+0x186/0x1bd [nfs] [<ffffffff810d23c8>] ? alloc_pages_current+0xc7/0xe4 [<ffffffff810a68b5>] ? __page_cache_alloc+0x84/0x91 [<ffffffff810af912>] ? __do_page_cache_readahead+0xa6/0x2e0 [<ffffffff810afaa3>] __do_page_cache_readahead+0x237/0x2e0 [<ffffffff810af912>] ? __do_page_cache_readahead+0xa6/0x2e0 [<ffffffff810afe3e>] ra_submit+0x1c/0x20 [<ffffffff810b019b>] ondemand_readahead+0x359/0x382 [<ffffffff810b0279>] page_cache_sync_readahead+0x38/0x3a [<ffffffff810a77b5>] generic_file_aio_read+0x26b/0x637 [<ffffffffa00f1852>] ? nfs_mark_delegation_referenced+0xb/0xb [nfsv4] [<ffffffffa009cc85>] nfs_file_read+0xaa/0xcf [nfs] [<ffffffff810db5b3>] do_sync_read+0x91/0xd1 [<ffffffff810dbb8b>] vfs_read+0x9b/0x144 [<ffffffff810dbc78>] sys_read+0x44/0x75 [<ffffffff81422892>] system_call_fastpath+0x16/0x1b Signed-off-by: David Howells <dhowells@redhat.com>
452 lines
13 KiB
C
452 lines
13 KiB
C
/* Internal definitions for FS-Cache
|
|
*
|
|
* Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the License, or (at your option) any later version.
|
|
*/
|
|
|
|
/*
|
|
* Lock order, in the order in which multiple locks should be obtained:
|
|
* - fscache_addremove_sem
|
|
* - cookie->lock
|
|
* - cookie->parent->lock
|
|
* - cache->object_list_lock
|
|
* - object->lock
|
|
* - object->parent->lock
|
|
* - cookie->stores_lock
|
|
* - fscache_thread_lock
|
|
*
|
|
*/
|
|
|
|
#include <linux/fscache-cache.h>
|
|
#include <linux/sched.h>
|
|
|
|
#define FSCACHE_MIN_THREADS 4
|
|
#define FSCACHE_MAX_THREADS 32
|
|
|
|
/*
|
|
* cache.c
|
|
*/
|
|
extern struct list_head fscache_cache_list;
|
|
extern struct rw_semaphore fscache_addremove_sem;
|
|
|
|
extern struct fscache_cache *fscache_select_cache_for_object(
|
|
struct fscache_cookie *);
|
|
|
|
/*
|
|
* cookie.c
|
|
*/
|
|
extern struct kmem_cache *fscache_cookie_jar;
|
|
|
|
extern void fscache_cookie_init_once(void *);
|
|
extern void __fscache_cookie_put(struct fscache_cookie *);
|
|
|
|
/*
|
|
* fsdef.c
|
|
*/
|
|
extern struct fscache_cookie fscache_fsdef_index;
|
|
extern struct fscache_cookie_def fscache_fsdef_netfs_def;
|
|
|
|
/*
|
|
* histogram.c
|
|
*/
|
|
#ifdef CONFIG_FSCACHE_HISTOGRAM
|
|
extern atomic_t fscache_obj_instantiate_histogram[HZ];
|
|
extern atomic_t fscache_objs_histogram[HZ];
|
|
extern atomic_t fscache_ops_histogram[HZ];
|
|
extern atomic_t fscache_retrieval_delay_histogram[HZ];
|
|
extern atomic_t fscache_retrieval_histogram[HZ];
|
|
|
|
static inline void fscache_hist(atomic_t histogram[], unsigned long start_jif)
|
|
{
|
|
unsigned long jif = jiffies - start_jif;
|
|
if (jif >= HZ)
|
|
jif = HZ - 1;
|
|
atomic_inc(&histogram[jif]);
|
|
}
|
|
|
|
extern const struct file_operations fscache_histogram_fops;
|
|
|
|
#else
|
|
#define fscache_hist(hist, start_jif) do {} while (0)
|
|
#endif
|
|
|
|
/*
|
|
* main.c
|
|
*/
|
|
extern unsigned fscache_defer_lookup;
|
|
extern unsigned fscache_defer_create;
|
|
extern unsigned fscache_debug;
|
|
extern struct kobject *fscache_root;
|
|
extern struct workqueue_struct *fscache_object_wq;
|
|
extern struct workqueue_struct *fscache_op_wq;
|
|
DECLARE_PER_CPU(wait_queue_head_t, fscache_object_cong_wait);
|
|
|
|
static inline bool fscache_object_congested(void)
|
|
{
|
|
return workqueue_congested(WORK_CPU_UNBOUND, fscache_object_wq);
|
|
}
|
|
|
|
extern int fscache_wait_bit(void *);
|
|
extern int fscache_wait_bit_interruptible(void *);
|
|
|
|
/*
|
|
* object.c
|
|
*/
|
|
extern const char fscache_object_states_short[FSCACHE_OBJECT__NSTATES][5];
|
|
|
|
extern void fscache_withdrawing_object(struct fscache_cache *,
|
|
struct fscache_object *);
|
|
extern void fscache_enqueue_object(struct fscache_object *);
|
|
|
|
/*
|
|
* object-list.c
|
|
*/
|
|
#ifdef CONFIG_FSCACHE_OBJECT_LIST
|
|
extern const struct file_operations fscache_objlist_fops;
|
|
|
|
extern void fscache_objlist_add(struct fscache_object *);
|
|
#else
|
|
#define fscache_objlist_add(object) do {} while(0)
|
|
#endif
|
|
|
|
/*
|
|
* operation.c
|
|
*/
|
|
extern int fscache_submit_exclusive_op(struct fscache_object *,
|
|
struct fscache_operation *);
|
|
extern int fscache_submit_op(struct fscache_object *,
|
|
struct fscache_operation *);
|
|
extern int fscache_cancel_op(struct fscache_operation *,
|
|
void (*)(struct fscache_operation *));
|
|
extern void fscache_cancel_all_ops(struct fscache_object *);
|
|
extern void fscache_abort_object(struct fscache_object *);
|
|
extern void fscache_start_operations(struct fscache_object *);
|
|
extern void fscache_operation_gc(struct work_struct *);
|
|
|
|
/*
|
|
* page.c
|
|
*/
|
|
extern void fscache_invalidate_writes(struct fscache_cookie *);
|
|
|
|
/*
|
|
* proc.c
|
|
*/
|
|
#ifdef CONFIG_PROC_FS
|
|
extern int __init fscache_proc_init(void);
|
|
extern void fscache_proc_cleanup(void);
|
|
#else
|
|
#define fscache_proc_init() (0)
|
|
#define fscache_proc_cleanup() do {} while (0)
|
|
#endif
|
|
|
|
/*
|
|
* stats.c
|
|
*/
|
|
#ifdef CONFIG_FSCACHE_STATS
|
|
extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
|
|
extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
|
|
|
|
extern atomic_t fscache_n_op_pend;
|
|
extern atomic_t fscache_n_op_run;
|
|
extern atomic_t fscache_n_op_enqueue;
|
|
extern atomic_t fscache_n_op_deferred_release;
|
|
extern atomic_t fscache_n_op_release;
|
|
extern atomic_t fscache_n_op_gc;
|
|
extern atomic_t fscache_n_op_cancelled;
|
|
extern atomic_t fscache_n_op_rejected;
|
|
|
|
extern atomic_t fscache_n_attr_changed;
|
|
extern atomic_t fscache_n_attr_changed_ok;
|
|
extern atomic_t fscache_n_attr_changed_nobufs;
|
|
extern atomic_t fscache_n_attr_changed_nomem;
|
|
extern atomic_t fscache_n_attr_changed_calls;
|
|
|
|
extern atomic_t fscache_n_allocs;
|
|
extern atomic_t fscache_n_allocs_ok;
|
|
extern atomic_t fscache_n_allocs_wait;
|
|
extern atomic_t fscache_n_allocs_nobufs;
|
|
extern atomic_t fscache_n_allocs_intr;
|
|
extern atomic_t fscache_n_allocs_object_dead;
|
|
extern atomic_t fscache_n_alloc_ops;
|
|
extern atomic_t fscache_n_alloc_op_waits;
|
|
|
|
extern atomic_t fscache_n_retrievals;
|
|
extern atomic_t fscache_n_retrievals_ok;
|
|
extern atomic_t fscache_n_retrievals_wait;
|
|
extern atomic_t fscache_n_retrievals_nodata;
|
|
extern atomic_t fscache_n_retrievals_nobufs;
|
|
extern atomic_t fscache_n_retrievals_intr;
|
|
extern atomic_t fscache_n_retrievals_nomem;
|
|
extern atomic_t fscache_n_retrievals_object_dead;
|
|
extern atomic_t fscache_n_retrieval_ops;
|
|
extern atomic_t fscache_n_retrieval_op_waits;
|
|
|
|
extern atomic_t fscache_n_stores;
|
|
extern atomic_t fscache_n_stores_ok;
|
|
extern atomic_t fscache_n_stores_again;
|
|
extern atomic_t fscache_n_stores_nobufs;
|
|
extern atomic_t fscache_n_stores_oom;
|
|
extern atomic_t fscache_n_store_ops;
|
|
extern atomic_t fscache_n_store_calls;
|
|
extern atomic_t fscache_n_store_pages;
|
|
extern atomic_t fscache_n_store_radix_deletes;
|
|
extern atomic_t fscache_n_store_pages_over_limit;
|
|
|
|
extern atomic_t fscache_n_store_vmscan_not_storing;
|
|
extern atomic_t fscache_n_store_vmscan_gone;
|
|
extern atomic_t fscache_n_store_vmscan_busy;
|
|
extern atomic_t fscache_n_store_vmscan_cancelled;
|
|
extern atomic_t fscache_n_store_vmscan_wait;
|
|
|
|
extern atomic_t fscache_n_marks;
|
|
extern atomic_t fscache_n_uncaches;
|
|
|
|
extern atomic_t fscache_n_acquires;
|
|
extern atomic_t fscache_n_acquires_null;
|
|
extern atomic_t fscache_n_acquires_no_cache;
|
|
extern atomic_t fscache_n_acquires_ok;
|
|
extern atomic_t fscache_n_acquires_nobufs;
|
|
extern atomic_t fscache_n_acquires_oom;
|
|
|
|
extern atomic_t fscache_n_invalidates;
|
|
extern atomic_t fscache_n_invalidates_run;
|
|
|
|
extern atomic_t fscache_n_updates;
|
|
extern atomic_t fscache_n_updates_null;
|
|
extern atomic_t fscache_n_updates_run;
|
|
|
|
extern atomic_t fscache_n_relinquishes;
|
|
extern atomic_t fscache_n_relinquishes_null;
|
|
extern atomic_t fscache_n_relinquishes_waitcrt;
|
|
extern atomic_t fscache_n_relinquishes_retire;
|
|
|
|
extern atomic_t fscache_n_cookie_index;
|
|
extern atomic_t fscache_n_cookie_data;
|
|
extern atomic_t fscache_n_cookie_special;
|
|
|
|
extern atomic_t fscache_n_object_alloc;
|
|
extern atomic_t fscache_n_object_no_alloc;
|
|
extern atomic_t fscache_n_object_lookups;
|
|
extern atomic_t fscache_n_object_lookups_negative;
|
|
extern atomic_t fscache_n_object_lookups_positive;
|
|
extern atomic_t fscache_n_object_lookups_timed_out;
|
|
extern atomic_t fscache_n_object_created;
|
|
extern atomic_t fscache_n_object_avail;
|
|
extern atomic_t fscache_n_object_dead;
|
|
|
|
extern atomic_t fscache_n_checkaux_none;
|
|
extern atomic_t fscache_n_checkaux_okay;
|
|
extern atomic_t fscache_n_checkaux_update;
|
|
extern atomic_t fscache_n_checkaux_obsolete;
|
|
|
|
extern atomic_t fscache_n_cop_alloc_object;
|
|
extern atomic_t fscache_n_cop_lookup_object;
|
|
extern atomic_t fscache_n_cop_lookup_complete;
|
|
extern atomic_t fscache_n_cop_grab_object;
|
|
extern atomic_t fscache_n_cop_invalidate_object;
|
|
extern atomic_t fscache_n_cop_update_object;
|
|
extern atomic_t fscache_n_cop_drop_object;
|
|
extern atomic_t fscache_n_cop_put_object;
|
|
extern atomic_t fscache_n_cop_sync_cache;
|
|
extern atomic_t fscache_n_cop_attr_changed;
|
|
extern atomic_t fscache_n_cop_read_or_alloc_page;
|
|
extern atomic_t fscache_n_cop_read_or_alloc_pages;
|
|
extern atomic_t fscache_n_cop_allocate_page;
|
|
extern atomic_t fscache_n_cop_allocate_pages;
|
|
extern atomic_t fscache_n_cop_write_page;
|
|
extern atomic_t fscache_n_cop_uncache_page;
|
|
extern atomic_t fscache_n_cop_dissociate_pages;
|
|
|
|
static inline void fscache_stat(atomic_t *stat)
|
|
{
|
|
atomic_inc(stat);
|
|
}
|
|
|
|
static inline void fscache_stat_d(atomic_t *stat)
|
|
{
|
|
atomic_dec(stat);
|
|
}
|
|
|
|
#define __fscache_stat(stat) (stat)
|
|
|
|
extern const struct file_operations fscache_stats_fops;
|
|
#else
|
|
|
|
#define __fscache_stat(stat) (NULL)
|
|
#define fscache_stat(stat) do {} while (0)
|
|
#define fscache_stat_d(stat) do {} while (0)
|
|
#endif
|
|
|
|
/*
|
|
* raise an event on an object
|
|
* - if the event is not masked for that object, then the object is
|
|
* queued for attention by the thread pool.
|
|
*/
|
|
static inline void fscache_raise_event(struct fscache_object *object,
|
|
unsigned event)
|
|
{
|
|
BUG_ON(event >= NR_FSCACHE_OBJECT_EVENTS);
|
|
if (!test_and_set_bit(event, &object->events) &&
|
|
test_bit(event, &object->event_mask))
|
|
fscache_enqueue_object(object);
|
|
}
|
|
|
|
/*
|
|
* drop a reference to a cookie
|
|
*/
|
|
static inline void fscache_cookie_put(struct fscache_cookie *cookie)
|
|
{
|
|
BUG_ON(atomic_read(&cookie->usage) <= 0);
|
|
if (atomic_dec_and_test(&cookie->usage))
|
|
__fscache_cookie_put(cookie);
|
|
}
|
|
|
|
/*
|
|
* get an extra reference to a netfs retrieval context
|
|
*/
|
|
static inline
|
|
void *fscache_get_context(struct fscache_cookie *cookie, void *context)
|
|
{
|
|
if (cookie->def->get_context)
|
|
cookie->def->get_context(cookie->netfs_data, context);
|
|
return context;
|
|
}
|
|
|
|
/*
|
|
* release a reference to a netfs retrieval context
|
|
*/
|
|
static inline
|
|
void fscache_put_context(struct fscache_cookie *cookie, void *context)
|
|
{
|
|
if (cookie->def->put_context)
|
|
cookie->def->put_context(cookie->netfs_data, context);
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
/*
|
|
* debug tracing
|
|
*/
|
|
#define dbgprintk(FMT, ...) \
|
|
printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
|
|
|
|
#define kenter(FMT, ...) dbgprintk("==> %s("FMT")", __func__, ##__VA_ARGS__)
|
|
#define kleave(FMT, ...) dbgprintk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
|
|
#define kdebug(FMT, ...) dbgprintk(FMT, ##__VA_ARGS__)
|
|
|
|
#define kjournal(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
|
|
|
|
#ifdef __KDEBUG
|
|
#define _enter(FMT, ...) kenter(FMT, ##__VA_ARGS__)
|
|
#define _leave(FMT, ...) kleave(FMT, ##__VA_ARGS__)
|
|
#define _debug(FMT, ...) kdebug(FMT, ##__VA_ARGS__)
|
|
|
|
#elif defined(CONFIG_FSCACHE_DEBUG)
|
|
#define _enter(FMT, ...) \
|
|
do { \
|
|
if (__do_kdebug(ENTER)) \
|
|
kenter(FMT, ##__VA_ARGS__); \
|
|
} while (0)
|
|
|
|
#define _leave(FMT, ...) \
|
|
do { \
|
|
if (__do_kdebug(LEAVE)) \
|
|
kleave(FMT, ##__VA_ARGS__); \
|
|
} while (0)
|
|
|
|
#define _debug(FMT, ...) \
|
|
do { \
|
|
if (__do_kdebug(DEBUG)) \
|
|
kdebug(FMT, ##__VA_ARGS__); \
|
|
} while (0)
|
|
|
|
#else
|
|
#define _enter(FMT, ...) no_printk("==> %s("FMT")", __func__, ##__VA_ARGS__)
|
|
#define _leave(FMT, ...) no_printk("<== %s()"FMT"", __func__, ##__VA_ARGS__)
|
|
#define _debug(FMT, ...) no_printk(FMT, ##__VA_ARGS__)
|
|
#endif
|
|
|
|
/*
|
|
* determine whether a particular optional debugging point should be logged
|
|
* - we need to go through three steps to persuade cpp to correctly join the
|
|
* shorthand in FSCACHE_DEBUG_LEVEL with its prefix
|
|
*/
|
|
#define ____do_kdebug(LEVEL, POINT) \
|
|
unlikely((fscache_debug & \
|
|
(FSCACHE_POINT_##POINT << (FSCACHE_DEBUG_ ## LEVEL * 3))))
|
|
#define ___do_kdebug(LEVEL, POINT) \
|
|
____do_kdebug(LEVEL, POINT)
|
|
#define __do_kdebug(POINT) \
|
|
___do_kdebug(FSCACHE_DEBUG_LEVEL, POINT)
|
|
|
|
#define FSCACHE_DEBUG_CACHE 0
|
|
#define FSCACHE_DEBUG_COOKIE 1
|
|
#define FSCACHE_DEBUG_PAGE 2
|
|
#define FSCACHE_DEBUG_OPERATION 3
|
|
|
|
#define FSCACHE_POINT_ENTER 1
|
|
#define FSCACHE_POINT_LEAVE 2
|
|
#define FSCACHE_POINT_DEBUG 4
|
|
|
|
#ifndef FSCACHE_DEBUG_LEVEL
|
|
#define FSCACHE_DEBUG_LEVEL CACHE
|
|
#endif
|
|
|
|
/*
|
|
* assertions
|
|
*/
|
|
#if 1 /* defined(__KDEBUGALL) */
|
|
|
|
#define ASSERT(X) \
|
|
do { \
|
|
if (unlikely(!(X))) { \
|
|
printk(KERN_ERR "\n"); \
|
|
printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
|
|
BUG(); \
|
|
} \
|
|
} while (0)
|
|
|
|
#define ASSERTCMP(X, OP, Y) \
|
|
do { \
|
|
if (unlikely(!((X) OP (Y)))) { \
|
|
printk(KERN_ERR "\n"); \
|
|
printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
|
|
printk(KERN_ERR "%lx " #OP " %lx is false\n", \
|
|
(unsigned long)(X), (unsigned long)(Y)); \
|
|
BUG(); \
|
|
} \
|
|
} while (0)
|
|
|
|
#define ASSERTIF(C, X) \
|
|
do { \
|
|
if (unlikely((C) && !(X))) { \
|
|
printk(KERN_ERR "\n"); \
|
|
printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
|
|
BUG(); \
|
|
} \
|
|
} while (0)
|
|
|
|
#define ASSERTIFCMP(C, X, OP, Y) \
|
|
do { \
|
|
if (unlikely((C) && !((X) OP (Y)))) { \
|
|
printk(KERN_ERR "\n"); \
|
|
printk(KERN_ERR "FS-Cache: Assertion failed\n"); \
|
|
printk(KERN_ERR "%lx " #OP " %lx is false\n", \
|
|
(unsigned long)(X), (unsigned long)(Y)); \
|
|
BUG(); \
|
|
} \
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define ASSERT(X) do {} while (0)
|
|
#define ASSERTCMP(X, OP, Y) do {} while (0)
|
|
#define ASSERTIF(C, X) do {} while (0)
|
|
#define ASSERTIFCMP(C, X, OP, Y) do {} while (0)
|
|
|
|
#endif /* assert or not */
|