Lines Matching refs:volume

20 struct fscache_volume *fscache_get_volume(struct fscache_volume *volume,
25 __refcount_inc(&volume->ref, &ref);
26 trace_fscache_volume(volume->debug_id, ref + 1, where);
27 return volume;
30 static void fscache_see_volume(struct fscache_volume *volume,
33 int ref = refcount_read(&volume->ref);
35 trace_fscache_volume(volume->debug_id, ref, where);
39 * Pin the cache behind a volume so that we can access it.
41 static void __fscache_begin_volume_access(struct fscache_volume *volume,
47 n_accesses = atomic_inc_return(&volume->n_accesses);
49 trace_fscache_access_volume(volume->debug_id, cookie ? cookie->debug_id : 0,
50 refcount_read(&volume->ref),
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,
87 if (!fscache_cache_is_live(volume->cache))
89 __fscache_begin_volume_access(volume, cookie, why);
90 if (!fscache_cache_is_live(volume->cache)) {
91 fscache_end_volume_access(volume, cookie, fscache_access_unlive);
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,
113 n_accesses = atomic_dec_return(&volume->n_accesses);
114 trace_fscache_access_volume(volume->debug_id, cookie ? cookie->debug_id : 0,
115 refcount_read(&volume->ref),
118 wake_up_var(&volume->n_accesses);
136 static bool fscache_is_acquire_pending(struct fscache_volume *volume)
138 return test_bit(FSCACHE_VOLUME_ACQUIRE_PENDING, &volume->flags);
147 pr_notice("Potential volume collision new=%08x old=%08x",
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;
220 volume = kzalloc(struct_size(volume, coherency, coherency_len),
222 if (!volume)
225 volume->cache = cache;
226 volume->coherency_len = coherency_len;
228 memcpy(volume->coherency, coherency_data, coherency_len);
229 INIT_LIST_HEAD(&volume->proc_link);
230 INIT_WORK(&volume->work, fscache_create_volume_work);
231 refcount_set(&volume->ref, 1);
232 spin_lock_init(&volume->lock);
244 volume->key = key;
245 volume->key_hash = fscache_hash(0, key, hlen);
247 volume->debug_id = atomic_inc_return(&fscache_volume_debug_id);
250 list_add_tail(&volume->proc_link, &fscache_volumes);
251 fscache_see_volume(volume, fscache_volume_new_acquire);
254 _leave(" = v=%x", volume->debug_id);
255 return volume;
258 kfree(volume);
266 * Create a volume's representation on disk. Have a volume ref and a cache
272 struct fscache_volume *volume =
275 fscache_see_volume(volume, fscache_volume_see_create_work);
277 ops = volume->cache->ops;
279 ops->acquire_volume(volume);
280 fscache_end_cache_access(volume->cache,
283 clear_and_wake_up_bit(FSCACHE_VOLUME_CREATING, &volume->flags);
284 fscache_put_volume(volume, fscache_volume_put_create_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)
292 if (test_and_set_bit(FSCACHE_VOLUME_CREATING, &volume->flags))
294 if (volume->cache_priv)
296 if (!fscache_begin_cache_access(volume->cache,
300 fscache_get_volume(volume, fscache_volume_get_create_work);
301 if (!schedule_work(&volume->work))
302 fscache_put_volume(volume, fscache_volume_put_create_work);
306 fscache_see_volume(volume, fscache_volume_wait_create_work);
307 wait_on_bit(&volume->flags, FSCACHE_VOLUME_CREATING,
312 clear_bit_unlock(FSCACHE_VOLUME_CREATING, &volume->flags);
313 wake_up_bit(&volume->flags, FSCACHE_VOLUME_CREATING);
317 * Acquire a volume representation cookie and link it to a (proposed) cache.
324 struct fscache_volume *volume;
326 volume = fscache_alloc_volume(volume_key, cache_name,
328 if (!volume)
331 if (!fscache_hash_volume(volume)) {
332 fscache_put_volume(volume, fscache_volume_put_hash_collision);
336 fscache_create_volume(volume, false);
337 return volume;
341 static void fscache_wake_pending_volume(struct fscache_volume *volume,
348 if (fscache_volume_same(cursor, volume)) {
358 * Remove a volume cookie from the hash table.
360 static void fscache_unhash_volume(struct fscache_volume *volume)
365 bucket = volume->key_hash & (ARRAY_SIZE(fscache_volume_hash) - 1);
369 hlist_bl_del(&volume->hash_link);
370 if (test_bit(FSCACHE_VOLUME_COLLIDED_WITH, &volume->flags))
371 fscache_wake_pending_volume(volume, h);
376 * Drop a cache's volume attachments.
378 static void fscache_free_volume(struct fscache_volume *volume)
380 struct fscache_cache *cache = volume->cache;
382 if (volume->cache_priv) {
383 __fscache_begin_volume_access(volume, NULL,
385 if (volume->cache_priv)
386 cache->ops->free_volume(volume);
387 fscache_end_volume_access(volume, NULL,
392 list_del_init(&volume->proc_link);
393 atomic_dec(&volume->cache->n_volumes);
396 if (!hlist_bl_unhashed(&volume->hash_link))
397 fscache_unhash_volume(volume);
399 trace_fscache_volume(volume->debug_id, 0, fscache_volume_free);
400 kfree(volume->key);
401 kfree(volume);
407 * Drop a reference to a volume cookie.
409 void fscache_put_volume(struct fscache_volume *volume,
412 if (volume) {
413 unsigned int debug_id = volume->debug_id;
417 zero = __refcount_dec_and_test(&volume->ref, &ref);
420 fscache_free_volume(volume);
425 * Relinquish a volume representation cookie.
427 void __fscache_relinquish_volume(struct fscache_volume *volume,
431 if (WARN_ON(test_and_set_bit(FSCACHE_VOLUME_RELINQUISHED, &volume->flags)))
435 set_bit(FSCACHE_VOLUME_INVALIDATE, &volume->flags);
437 memcpy(volume->coherency, coherency_data, volume->coherency_len);
440 fscache_put_volume(volume, fscache_volume_put_relinquish);
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)
455 _debug("withdraw V=%x", volume->debug_id);
458 n_accesses = atomic_dec_return(&volume->n_accesses);
459 trace_fscache_access_volume(volume->debug_id, 0,
460 refcount_read(&volume->ref),
463 wait_var_event(&volume->n_accesses,
464 atomic_read(&volume->n_accesses) == 0);
474 struct fscache_volume *volume;
483 volume = list_entry(v, struct fscache_volume, proc_link);
486 volume->debug_id,
487 refcount_read(&volume->ref),
488 atomic_read(&volume->n_cookies),
489 atomic_read(&volume->n_accesses),
490 volume->flags,
491 volume->cache->name ?: "-",
492 volume->key + 1);