Lines Matching full:volume

2 /* Volume-level cache cookie handling.
20 struct fscache_volume *fscache_get_volume(struct fscache_volume *volume, in fscache_get_volume() argument
25 __refcount_inc(&volume->ref, &ref); in fscache_get_volume()
26 trace_fscache_volume(volume->debug_id, ref + 1, where); in fscache_get_volume()
27 return volume; in fscache_get_volume()
30 static void fscache_see_volume(struct fscache_volume *volume, in fscache_see_volume() argument
33 int ref = refcount_read(&volume->ref); in fscache_see_volume()
35 trace_fscache_volume(volume->debug_id, ref, where); in fscache_see_volume()
39 * Pin the cache behind a volume so that we can access it.
41 static void __fscache_begin_volume_access(struct fscache_volume *volume, in __fscache_begin_volume_access() argument
47 n_accesses = atomic_inc_return(&volume->n_accesses); in __fscache_begin_volume_access()
49 trace_fscache_access_volume(volume->debug_id, cookie ? cookie->debug_id : 0, in __fscache_begin_volume_access()
50 refcount_read(&volume->ref), in __fscache_begin_volume_access()
55 * fscache_begin_volume_access - Pin a cache so a volume can be accessed
56 * @volume: The volume cookie
61 * accessing a volume and returns true if successful. This works as follows:
66 * (2) If the cache tests as live, then we increment the volume's n_accesses
70 * (3) When we end the access, we decrement the volume's n_accesses and wake
73 * (4) Whilst the cache is caching, the volume's n_accesses is kept
77 * accesses, the volume's n_accesses is decremented and we wait for it to
83 bool fscache_begin_volume_access(struct fscache_volume *volume, in fscache_begin_volume_access() argument
87 if (!fscache_cache_is_live(volume->cache)) in fscache_begin_volume_access()
89 __fscache_begin_volume_access(volume, cookie, why); in fscache_begin_volume_access()
90 if (!fscache_cache_is_live(volume->cache)) { in fscache_begin_volume_access()
91 fscache_end_volume_access(volume, cookie, fscache_access_unlive); in fscache_begin_volume_access()
99 * @volume: The volume cookie
103 * Unpin a cache volume after we've accessed it. The datafile @cookie and the
106 void fscache_end_volume_access(struct fscache_volume *volume, in fscache_end_volume_access() argument
113 n_accesses = atomic_dec_return(&volume->n_accesses); in fscache_end_volume_access()
114 trace_fscache_access_volume(volume->debug_id, cookie ? cookie->debug_id : 0, in fscache_end_volume_access()
115 refcount_read(&volume->ref), in fscache_end_volume_access()
118 wake_up_var(&volume->n_accesses); in fscache_end_volume_access()
136 static bool fscache_is_acquire_pending(struct fscache_volume *volume) in fscache_is_acquire_pending() argument
138 return test_bit(FSCACHE_VOLUME_ACQUIRE_PENDING, &volume->flags); in fscache_is_acquire_pending()
147 pr_notice("Potential volume collision new=%08x old=%08x", in fscache_wait_on_volume_collision()
156 * Attempt to insert the new volume into the hash. If there's a collision, we
157 * wait for the old volume to complete if it's being relinquished and an error
197 * Allocate and initialise a volume representation cookie.
204 struct fscache_volume *volume; in fscache_alloc_volume() local
220 volume = kzalloc(struct_size(volume, coherency, coherency_len), in fscache_alloc_volume()
222 if (!volume) in fscache_alloc_volume()
225 volume->cache = cache; in fscache_alloc_volume()
226 volume->coherency_len = coherency_len; in fscache_alloc_volume()
228 memcpy(volume->coherency, coherency_data, coherency_len); in fscache_alloc_volume()
229 INIT_LIST_HEAD(&volume->proc_link); in fscache_alloc_volume()
230 INIT_WORK(&volume->work, fscache_create_volume_work); in fscache_alloc_volume()
231 refcount_set(&volume->ref, 1); in fscache_alloc_volume()
232 spin_lock_init(&volume->lock); in fscache_alloc_volume()
244 volume->key = key; in fscache_alloc_volume()
245 volume->key_hash = fscache_hash(0, key, hlen); in fscache_alloc_volume()
247 volume->debug_id = atomic_inc_return(&fscache_volume_debug_id); in fscache_alloc_volume()
250 list_add_tail(&volume->proc_link, &fscache_volumes); in fscache_alloc_volume()
251 fscache_see_volume(volume, fscache_volume_new_acquire); in fscache_alloc_volume()
254 _leave(" = v=%x", volume->debug_id); in fscache_alloc_volume()
255 return volume; in fscache_alloc_volume()
258 kfree(volume); in fscache_alloc_volume()
266 * Create a volume's representation on disk. Have a volume ref and a cache
272 struct fscache_volume *volume = in fscache_create_volume_work() local
275 fscache_see_volume(volume, fscache_volume_see_create_work); in fscache_create_volume_work()
277 ops = volume->cache->ops; in fscache_create_volume_work()
279 ops->acquire_volume(volume); in fscache_create_volume_work()
280 fscache_end_cache_access(volume->cache, in fscache_create_volume_work()
283 clear_and_wake_up_bit(FSCACHE_VOLUME_CREATING, &volume->flags); in fscache_create_volume_work()
284 fscache_put_volume(volume, fscache_volume_put_create_work); in fscache_create_volume_work()
288 * Dispatch a worker thread to create a volume's representation on disk.
290 void fscache_create_volume(struct fscache_volume *volume, bool wait) in fscache_create_volume() argument
292 if (test_and_set_bit(FSCACHE_VOLUME_CREATING, &volume->flags)) in fscache_create_volume()
294 if (volume->cache_priv) in fscache_create_volume()
296 if (!fscache_begin_cache_access(volume->cache, in fscache_create_volume()
300 fscache_get_volume(volume, fscache_volume_get_create_work); in fscache_create_volume()
301 if (!schedule_work(&volume->work)) in fscache_create_volume()
302 fscache_put_volume(volume, fscache_volume_put_create_work); in fscache_create_volume()
306 fscache_see_volume(volume, fscache_volume_wait_create_work); in fscache_create_volume()
307 wait_on_bit(&volume->flags, FSCACHE_VOLUME_CREATING, in fscache_create_volume()
312 clear_bit_unlock(FSCACHE_VOLUME_CREATING, &volume->flags); in fscache_create_volume()
313 wake_up_bit(&volume->flags, FSCACHE_VOLUME_CREATING); in fscache_create_volume()
317 * Acquire a volume representation cookie and link it to a (proposed) cache.
324 struct fscache_volume *volume; in __fscache_acquire_volume() local
326 volume = fscache_alloc_volume(volume_key, cache_name, in __fscache_acquire_volume()
328 if (!volume) in __fscache_acquire_volume()
331 if (!fscache_hash_volume(volume)) { in __fscache_acquire_volume()
332 fscache_put_volume(volume, fscache_volume_put_hash_collision); in __fscache_acquire_volume()
336 fscache_create_volume(volume, false); in __fscache_acquire_volume()
337 return volume; in __fscache_acquire_volume()
341 static void fscache_wake_pending_volume(struct fscache_volume *volume, in fscache_wake_pending_volume() argument
348 if (fscache_volume_same(cursor, volume)) { in fscache_wake_pending_volume()
358 * Remove a volume cookie from the hash table.
360 static void fscache_unhash_volume(struct fscache_volume *volume) in fscache_unhash_volume() argument
365 bucket = volume->key_hash & (ARRAY_SIZE(fscache_volume_hash) - 1); in fscache_unhash_volume()
369 hlist_bl_del(&volume->hash_link); in fscache_unhash_volume()
370 if (test_bit(FSCACHE_VOLUME_COLLIDED_WITH, &volume->flags)) in fscache_unhash_volume()
371 fscache_wake_pending_volume(volume, h); in fscache_unhash_volume()
376 * Drop a cache's volume attachments.
378 static void fscache_free_volume(struct fscache_volume *volume) in fscache_free_volume() argument
380 struct fscache_cache *cache = volume->cache; in fscache_free_volume()
382 if (volume->cache_priv) { in fscache_free_volume()
383 __fscache_begin_volume_access(volume, NULL, in fscache_free_volume()
385 if (volume->cache_priv) in fscache_free_volume()
386 cache->ops->free_volume(volume); in fscache_free_volume()
387 fscache_end_volume_access(volume, NULL, in fscache_free_volume()
392 list_del_init(&volume->proc_link); in fscache_free_volume()
393 atomic_dec(&volume->cache->n_volumes); in fscache_free_volume()
396 if (!hlist_bl_unhashed(&volume->hash_link)) in fscache_free_volume()
397 fscache_unhash_volume(volume); in fscache_free_volume()
399 trace_fscache_volume(volume->debug_id, 0, fscache_volume_free); in fscache_free_volume()
400 kfree(volume->key); in fscache_free_volume()
401 kfree(volume); in fscache_free_volume()
407 * Drop a reference to a volume cookie.
409 void fscache_put_volume(struct fscache_volume *volume, in fscache_put_volume() argument
412 if (volume) { in fscache_put_volume()
413 unsigned int debug_id = volume->debug_id; in fscache_put_volume()
417 zero = __refcount_dec_and_test(&volume->ref, &ref); in fscache_put_volume()
420 fscache_free_volume(volume); in fscache_put_volume()
425 * Relinquish a volume representation cookie.
427 void __fscache_relinquish_volume(struct fscache_volume *volume, in __fscache_relinquish_volume() argument
431 if (WARN_ON(test_and_set_bit(FSCACHE_VOLUME_RELINQUISHED, &volume->flags))) in __fscache_relinquish_volume()
435 set_bit(FSCACHE_VOLUME_INVALIDATE, &volume->flags); in __fscache_relinquish_volume()
437 memcpy(volume->coherency, coherency_data, volume->coherency_len); in __fscache_relinquish_volume()
440 fscache_put_volume(volume, fscache_volume_put_relinquish); in __fscache_relinquish_volume()
445 * fscache_withdraw_volume - Withdraw a volume from being cached
446 * @volume: Volume cookie
448 * Withdraw a cache volume from service, waiting for all accesses to complete
451 void fscache_withdraw_volume(struct fscache_volume *volume) in fscache_withdraw_volume() argument
455 _debug("withdraw V=%x", volume->debug_id); in fscache_withdraw_volume()
458 n_accesses = atomic_dec_return(&volume->n_accesses); in fscache_withdraw_volume()
459 trace_fscache_access_volume(volume->debug_id, 0, in fscache_withdraw_volume()
460 refcount_read(&volume->ref), in fscache_withdraw_volume()
463 wait_var_event(&volume->n_accesses, in fscache_withdraw_volume()
464 atomic_read(&volume->n_accesses) == 0); in fscache_withdraw_volume()
474 struct fscache_volume *volume; in fscache_volumes_seq_show() local
478 "VOLUME REF nCOOK ACC FL CACHE KEY\n" in fscache_volumes_seq_show()
483 volume = list_entry(v, struct fscache_volume, proc_link); in fscache_volumes_seq_show()
486 volume->debug_id, in fscache_volumes_seq_show()
487 refcount_read(&volume->ref), in fscache_volumes_seq_show()
488 atomic_read(&volume->n_cookies), in fscache_volumes_seq_show()
489 atomic_read(&volume->n_accesses), in fscache_volumes_seq_show()
490 volume->flags, in fscache_volumes_seq_show()
491 volume->cache->name ?: "-", in fscache_volumes_seq_show()
492 volume->key + 1); in fscache_volumes_seq_show()