fs/cachefiles/cache.c

Source file repositories/reference/linux-study-clean/fs/cachefiles/cache.c

File Facts

System
Linux kernel
Corpus path
fs/cachefiles/cache.c
Extension
.c
Size
11033 bytes
Lines
429
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

if ((count & 63) == 0) {
			spin_unlock(&cache->object_list_lock);
			cond_resched();
			spin_lock(&cache->object_list_lock);
		}
	}

	spin_unlock(&cache->object_list_lock);
	_leave(" [%u objs]", count);
}

/*
 * Withdraw fscache volumes.
 */
static void cachefiles_withdraw_fscache_volumes(struct cachefiles_cache *cache)
{
	struct list_head *cur;
	struct cachefiles_volume *volume;
	struct fscache_volume *vcookie;

	_enter("");
retry:
	spin_lock(&cache->object_list_lock);
	list_for_each(cur, &cache->volumes) {
		volume = list_entry(cur, struct cachefiles_volume, cache_link);

		if (atomic_read(&volume->vcookie->n_accesses) == 0)
			continue;

		vcookie = fscache_try_get_volume(volume->vcookie,
						 fscache_volume_get_withdraw);
		if (vcookie) {
			spin_unlock(&cache->object_list_lock);
			fscache_withdraw_volume(vcookie);
			fscache_put_volume(vcookie, fscache_volume_put_withdraw);
			goto retry;
		}
	}
	spin_unlock(&cache->object_list_lock);

	_leave("");
}

/*
 * Withdraw cachefiles volumes.
 */
static void cachefiles_withdraw_volumes(struct cachefiles_cache *cache)
{
	_enter("");

	for (;;) {
		struct fscache_volume *vcookie = NULL;
		struct cachefiles_volume *volume = NULL;

		spin_lock(&cache->object_list_lock);
		if (!list_empty(&cache->volumes)) {
			volume = list_first_entry(&cache->volumes,
						  struct cachefiles_volume, cache_link);
			vcookie = fscache_try_get_volume(volume->vcookie,
							 fscache_volume_get_withdraw);
			if (!vcookie) {
				spin_unlock(&cache->object_list_lock);
				cpu_relax();
				continue;
			}
			list_del_init(&volume->cache_link);
		}
		spin_unlock(&cache->object_list_lock);
		if (!volume)
			break;

		cachefiles_withdraw_volume(volume);
		fscache_put_volume(vcookie, fscache_volume_put_withdraw);
	}

	_leave("");
}

/*
 * Sync a cache to backing disk.
 */
static void cachefiles_sync_cache(struct cachefiles_cache *cache)
{
	const struct cred *saved_cred;
	int ret;

	_enter("%s", cache->cache->name);

	/* make sure all pages pinned by operations on behalf of the netfs are
	 * written to disc */

Annotation

Implementation Notes