Lines Matching full:object

19  * Allocate a cache object record.
26 struct cachefiles_object *object; in cachefiles_alloc_object() local
30 object = kmem_cache_zalloc(cachefiles_object_jar, GFP_KERNEL); in cachefiles_alloc_object()
31 if (!object) in cachefiles_alloc_object()
34 if (cachefiles_ondemand_init_obj_info(object, volume)) { in cachefiles_alloc_object()
35 kmem_cache_free(cachefiles_object_jar, object); in cachefiles_alloc_object()
39 refcount_set(&object->ref, 1); in cachefiles_alloc_object()
41 spin_lock_init(&object->lock); in cachefiles_alloc_object()
42 INIT_LIST_HEAD(&object->cache_link); in cachefiles_alloc_object()
43 object->volume = volume; in cachefiles_alloc_object()
44 object->debug_id = atomic_inc_return(&cachefiles_object_debug_id); in cachefiles_alloc_object()
45 object->cookie = fscache_get_cookie(cookie, fscache_cookie_get_attach_object); in cachefiles_alloc_object()
48 trace_cachefiles_ref(object->debug_id, cookie->debug_id, 1, in cachefiles_alloc_object()
50 return object; in cachefiles_alloc_object()
54 * Note that an object has been seen.
56 void cachefiles_see_object(struct cachefiles_object *object, in cachefiles_see_object() argument
59 trace_cachefiles_ref(object->debug_id, object->cookie->debug_id, in cachefiles_see_object()
60 refcount_read(&object->ref), why); in cachefiles_see_object()
64 * Increment the usage count on an object;
66 struct cachefiles_object *cachefiles_grab_object(struct cachefiles_object *object, in cachefiles_grab_object() argument
71 __refcount_inc(&object->ref, &r); in cachefiles_grab_object()
72 trace_cachefiles_ref(object->debug_id, object->cookie->debug_id, r, why); in cachefiles_grab_object()
73 return object; in cachefiles_grab_object()
77 * dispose of a reference to an object
79 void cachefiles_put_object(struct cachefiles_object *object, in cachefiles_put_object() argument
82 unsigned int object_debug_id = object->debug_id; in cachefiles_put_object()
83 unsigned int cookie_debug_id = object->cookie->debug_id; in cachefiles_put_object()
88 done = __refcount_dec_and_test(&object->ref, &r); in cachefiles_put_object()
91 _debug("- kill object OBJ%x", object_debug_id); in cachefiles_put_object()
93 ASSERTCMP(object->file, ==, NULL); in cachefiles_put_object()
95 kfree(object->d_name); in cachefiles_put_object()
96 cachefiles_ondemand_deinit_obj_info(object); in cachefiles_put_object()
97 cache = object->volume->cache->cache; in cachefiles_put_object()
98 fscache_put_cookie(object->cookie, fscache_cookie_put_object); in cachefiles_put_object()
99 object->cookie = NULL; in cachefiles_put_object()
100 kmem_cache_free(cachefiles_object_jar, object); in cachefiles_put_object()
114 static int cachefiles_adjust_size(struct cachefiles_object *object) in cachefiles_adjust_size() argument
117 struct file *file = object->file; in cachefiles_adjust_size()
122 ni_size = object->cookie->object_size; in cachefiles_adjust_size()
126 object->debug_id, (unsigned long long) ni_size); in cachefiles_adjust_size()
166 cachefiles_io_error_obj(object, "Size set failed"); in cachefiles_adjust_size()
179 struct cachefiles_object *object; in cachefiles_lookup_cookie() local
184 object = cachefiles_alloc_object(cookie); in cachefiles_lookup_cookie()
185 if (!object) in cachefiles_lookup_cookie()
188 _enter("{OBJ%x}", object->debug_id); in cachefiles_lookup_cookie()
190 if (!cachefiles_cook_key(object)) in cachefiles_lookup_cookie()
193 cookie->cache_priv = object; in cachefiles_lookup_cookie()
197 success = cachefiles_look_up_object(object); in cachefiles_lookup_cookie()
201 cachefiles_see_object(object, cachefiles_obj_see_lookup_cookie); in cachefiles_lookup_cookie()
204 list_add(&object->cache_link, &cache->object_list); in cachefiles_lookup_cookie()
206 cachefiles_adjust_size(object); in cachefiles_lookup_cookie()
214 cachefiles_see_object(object, cachefiles_obj_see_lookup_failed); in cachefiles_lookup_cookie()
216 _debug("failed c=%08x o=%08x", cookie->debug_id, object->debug_id); in cachefiles_lookup_cookie()
218 * drop it before we can withdraw the object. in cachefiles_lookup_cookie()
223 cachefiles_put_object(object, cachefiles_obj_put_alloc_fail); in cachefiles_lookup_cookie()
229 * Shorten the backing object to discard any dirty data and free up
232 static bool cachefiles_shorten_object(struct cachefiles_object *object, in cachefiles_shorten_object() argument
235 struct cachefiles_cache *cache = object->volume->cache; in cachefiles_shorten_object()
243 trace_cachefiles_trunc(object, inode, i_size, dio_size, in cachefiles_shorten_object()
249 trace_cachefiles_io_error(object, file_inode(file), ret, in cachefiles_shorten_object()
251 cachefiles_io_error_obj(object, "Trunc-to-size failed %d", ret); in cachefiles_shorten_object()
252 cachefiles_remove_object_xattr(cache, object, file->f_path.dentry); in cachefiles_shorten_object()
257 trace_cachefiles_trunc(object, inode, dio_size, new_size, in cachefiles_shorten_object()
264 trace_cachefiles_io_error(object, file_inode(file), ret, in cachefiles_shorten_object()
266 cachefiles_io_error_obj(object, "Trunc-to-dio-size failed %d", ret); in cachefiles_shorten_object()
267 cachefiles_remove_object_xattr(cache, object, file->f_path.dentry); in cachefiles_shorten_object()
276 * Resize the backing object.
281 struct cachefiles_object *object = cachefiles_cres_object(cres); in cachefiles_resize_cookie() local
282 struct cachefiles_cache *cache = object->volume->cache; in cachefiles_resize_cookie()
283 struct fscache_cookie *cookie = object->cookie; in cachefiles_resize_cookie()
292 cachefiles_shorten_object(object, file, new_size); in cachefiles_resize_cookie()
294 object->cookie->object_size = new_size; in cachefiles_resize_cookie()
306 * Commit changes to the object as we drop it.
308 static void cachefiles_commit_object(struct cachefiles_object *object, in cachefiles_commit_object() argument
313 if (test_and_clear_bit(FSCACHE_COOKIE_LOCAL_WRITE, &object->cookie->flags)) in cachefiles_commit_object()
315 if (test_and_clear_bit(FSCACHE_COOKIE_NEEDS_UPDATE, &object->cookie->flags)) in cachefiles_commit_object()
318 cachefiles_set_object_xattr(object); in cachefiles_commit_object()
320 if (test_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags)) in cachefiles_commit_object()
321 cachefiles_commit_tmpfile(cache, object); in cachefiles_commit_object()
325 * Finalise and object and close the VFS structs that we have.
327 static void cachefiles_clean_up_object(struct cachefiles_object *object, in cachefiles_clean_up_object() argument
330 if (test_bit(FSCACHE_COOKIE_RETIRED, &object->cookie->flags)) { in cachefiles_clean_up_object()
331 if (!test_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags)) { in cachefiles_clean_up_object()
332 cachefiles_see_object(object, cachefiles_obj_see_clean_delete); in cachefiles_clean_up_object()
333 _debug("- inval object OBJ%x", object->debug_id); in cachefiles_clean_up_object()
334 cachefiles_delete_object(object, FSCACHE_OBJECT_WAS_RETIRED); in cachefiles_clean_up_object()
336 cachefiles_see_object(object, cachefiles_obj_see_clean_drop_tmp); in cachefiles_clean_up_object()
337 _debug("- inval object OBJ%x tmpfile", object->debug_id); in cachefiles_clean_up_object()
340 cachefiles_see_object(object, cachefiles_obj_see_clean_commit); in cachefiles_clean_up_object()
341 cachefiles_commit_object(object, cache); in cachefiles_clean_up_object()
344 cachefiles_unmark_inode_in_use(object, object->file); in cachefiles_clean_up_object()
345 if (object->file) { in cachefiles_clean_up_object()
346 fput(object->file); in cachefiles_clean_up_object()
347 object->file = NULL; in cachefiles_clean_up_object()
356 struct cachefiles_object *object = cookie->cache_priv; in cachefiles_withdraw_cookie() local
357 struct cachefiles_cache *cache = object->volume->cache; in cachefiles_withdraw_cookie()
360 _enter("o=%x", object->debug_id); in cachefiles_withdraw_cookie()
361 cachefiles_see_object(object, cachefiles_obj_see_withdraw_cookie); in cachefiles_withdraw_cookie()
363 if (!list_empty(&object->cache_link)) { in cachefiles_withdraw_cookie()
365 cachefiles_see_object(object, cachefiles_obj_see_withdrawal); in cachefiles_withdraw_cookie()
366 list_del_init(&object->cache_link); in cachefiles_withdraw_cookie()
370 cachefiles_ondemand_clean_object(object); in cachefiles_withdraw_cookie()
372 if (object->file) { in cachefiles_withdraw_cookie()
374 cachefiles_clean_up_object(object, cache); in cachefiles_withdraw_cookie()
379 cachefiles_put_object(object, cachefiles_obj_put_detach); in cachefiles_withdraw_cookie()
387 struct cachefiles_object *object = cookie->cache_priv; in cachefiles_invalidate_cookie() local
391 _enter("o=%x,[%llu]", object->debug_id, object->cookie->object_size); in cachefiles_invalidate_cookie()
393 old_tmpfile = test_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags); in cachefiles_invalidate_cookie()
395 if (!object->file) { in cachefiles_invalidate_cookie()
401 new_file = cachefiles_create_tmpfile(object); in cachefiles_invalidate_cookie()
407 spin_lock(&object->lock); in cachefiles_invalidate_cookie()
409 old_file = object->file; in cachefiles_invalidate_cookie()
410 object->file = new_file; in cachefiles_invalidate_cookie()
411 object->content_info = CACHEFILES_CONTENT_NO_DATA; in cachefiles_invalidate_cookie()
412 set_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags); in cachefiles_invalidate_cookie()
413 set_bit(FSCACHE_COOKIE_NEEDS_UPDATE, &object->cookie->flags); in cachefiles_invalidate_cookie()
415 spin_unlock(&object->lock); in cachefiles_invalidate_cookie()
423 struct cachefiles_volume *volume = object->volume; in cachefiles_invalidate_cookie()
427 cachefiles_bury_object(volume->cache, object, fan, in cachefiles_invalidate_cookie()