goto nomem;
}
- atomic_set(&cookie->usage, 1);
+ refcount_set(&cookie->ref, 1);
atomic_set(&cookie->n_children, 0);
cookie->debug_id = atomic_inc_return(&fscache_cookie_debug_id);
collision:
if (test_and_set_bit(FSCACHE_COOKIE_ACQUIRED, &cursor->flags)) {
- trace_fscache_cookie(cursor->debug_id, atomic_read(&cursor->usage),
+ trace_fscache_cookie(cursor->debug_id, refcount_read(&cursor->ref),
fscache_cookie_collision);
pr_err("Duplicate cookie detected\n");
fscache_print_cookie(cursor, 'O');
BUG_ON(!radix_tree_empty(&cookie->stores));
if (cookie->parent) {
- ASSERTCMP(atomic_read(&cookie->parent->usage), >, 0);
+ ASSERTCMP(refcount_read(&cookie->parent->ref), >, 0);
ASSERTCMP(atomic_read(&cookie->parent->n_children), >, 0);
atomic_dec(&cookie->parent->n_children);
}
/* Dispose of the netfs's link to the cookie */
- ASSERTCMP(atomic_read(&cookie->usage), >, 0);
fscache_cookie_put(cookie, fscache_cookie_put_relinquish);
_leave("");
enum fscache_cookie_trace where)
{
struct fscache_cookie *parent;
- int usage;
+ int ref;
_enter("%x", cookie->debug_id);
do {
unsigned int cookie_debug_id = cookie->debug_id;
- usage = atomic_dec_return(&cookie->usage);
- trace_fscache_cookie(cookie_debug_id, usage, where);
+ bool zero = __refcount_dec_and_test(&cookie->ref, &ref);
- if (usage > 0)
+ trace_fscache_cookie(cookie_debug_id, ref - 1, where);
+ if (!zero)
return;
- BUG_ON(usage < 0);
parent = cookie->parent;
fscache_unhash_cookie(cookie);
_leave("");
}
+/*
+ * Get a reference to a cookie.
+ */
+struct fscache_cookie *fscache_cookie_get(struct fscache_cookie *cookie,
+ enum fscache_cookie_trace where)
+{
+ int ref;
+
+ __refcount_inc(&cookie->ref, &ref);
+ trace_fscache_cookie(cookie->debug_id, ref + 1, where);
+ return cookie;
+}
+
/*
* check the consistency between the netfs inode and the backing cache
*
"%08x %08x %5u %5u %3u %s %03lx %-16s %px",
cookie->debug_id,
cookie->parent ? cookie->parent->debug_id : 0,
- atomic_read(&cookie->usage),
+ refcount_read(&cookie->ref),
atomic_read(&cookie->n_children),
atomic_read(&cookie->n_active),
type,
TRACE_EVENT(fscache_cookie,
TP_PROTO(unsigned int cookie_debug_id,
- int usage,
+ int ref,
enum fscache_cookie_trace where),
- TP_ARGS(cookie_debug_id, usage, where),
+ TP_ARGS(cookie_debug_id, ref, where),
TP_STRUCT__entry(
__field(unsigned int, cookie )
__field(enum fscache_cookie_trace, where )
- __field(int, usage )
+ __field(int, ref )
),
TP_fast_assign(
__entry->cookie = cookie_debug_id;
__entry->where = where;
- __entry->usage = usage;
+ __entry->ref = ref;
),
- TP_printk("%s c=%08x u=%d",
+ TP_printk("%s c=%08x r=%d",
__print_symbolic(__entry->where, fscache_cookie_traces),
- __entry->cookie, __entry->usage)
+ __entry->cookie, __entry->ref)
);
TRACE_EVENT(fscache_netfs,
__field(unsigned int, cookie )
__field(unsigned int, parent )
__array(char, name, 8 )
- __field(int, p_usage )
+ __field(int, p_ref )
__field(int, p_n_children )
__field(u8, p_flags )
),
TP_fast_assign(
__entry->cookie = cookie->debug_id;
__entry->parent = cookie->parent->debug_id;
- __entry->p_usage = atomic_read(&cookie->parent->usage);
+ __entry->p_ref = refcount_read(&cookie->parent->ref);
__entry->p_n_children = atomic_read(&cookie->parent->n_children);
__entry->p_flags = cookie->parent->flags;
memcpy(__entry->name, cookie->def->name, 8);
__entry->name[7] = 0;
),
- TP_printk("c=%08x p=%08x pu=%d pc=%d pf=%02x n=%s",
- __entry->cookie, __entry->parent, __entry->p_usage,
+ TP_printk("c=%08x p=%08x pr=%d pc=%d pf=%02x n=%s",
+ __entry->cookie, __entry->parent, __entry->p_ref,
__entry->p_n_children, __entry->p_flags, __entry->name)
);
TP_STRUCT__entry(
__field(unsigned int, cookie )
__field(unsigned int, parent )
- __field(int, usage )
+ __field(int, ref )
__field(int, n_children )
__field(int, n_active )
__field(u8, flags )
TP_fast_assign(
__entry->cookie = cookie->debug_id;
__entry->parent = cookie->parent->debug_id;
- __entry->usage = atomic_read(&cookie->usage);
+ __entry->ref = refcount_read(&cookie->ref);
__entry->n_children = atomic_read(&cookie->n_children);
__entry->n_active = atomic_read(&cookie->n_active);
__entry->flags = cookie->flags;
__entry->retire = retire;
),
- TP_printk("c=%08x u=%d p=%08x Nc=%d Na=%d f=%02x r=%u",
- __entry->cookie, __entry->usage,
+ TP_printk("c=%08x r=%d p=%08x Nc=%d Na=%d f=%02x r=%u",
+ __entry->cookie, __entry->ref,
__entry->parent, __entry->n_children, __entry->n_active,
__entry->flags, __entry->retire)
);
TP_STRUCT__entry(
__field(unsigned int, cookie )
- __field(int, usage )
+ __field(int, ref )
__field(int, n_children )
__field(int, n_active )
__field(u8, flags )
TP_fast_assign(
__entry->cookie = cookie->debug_id;
- __entry->usage = atomic_read(&cookie->usage);
+ __entry->ref = refcount_read(&cookie->ref);
__entry->n_children = atomic_read(&cookie->n_children);
__entry->n_active = atomic_read(&cookie->n_active);
__entry->flags = cookie->flags;
),
- TP_printk("c=%08x u=%d Nc=%d Na=%d f=%02x",
- __entry->cookie, __entry->usage,
+ TP_printk("c=%08x r=%d Nc=%d Na=%d f=%02x",
+ __entry->cookie, __entry->ref,
__entry->n_children, __entry->n_active, __entry->flags)
);
TP_STRUCT__entry(
__field(unsigned int, cookie )
- __field(int, usage )
+ __field(int, ref )
__field(int, n_children )
__field(int, n_active )
__field(u8, flags )
TP_fast_assign(
__entry->cookie = cookie->debug_id;
- __entry->usage = atomic_read(&cookie->usage);
+ __entry->ref = refcount_read(&cookie->ref);
__entry->n_children = atomic_read(&cookie->n_children);
__entry->n_active = atomic_read(&cookie->n_active);
__entry->flags = cookie->flags;
),
- TP_printk("c=%08x u=%d Nc=%d Na=%d f=%02x",
- __entry->cookie, __entry->usage,
+ TP_printk("c=%08x r=%d Nc=%d Na=%d f=%02x",
+ __entry->cookie, __entry->ref,
__entry->n_children, __entry->n_active, __entry->flags)
);