fs/cachefiles/volume.c

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

File Facts

System
Linux kernel
Corpus path
fs/cachefiles/volume.c
Extension
.c
Size
3407 bytes
Lines
142
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 (ret < 0) {
			if (ret != -ESTALE)
				goto error_dir;
			vdentry = start_removing_dentry(cache->store, vdentry);
			if (!IS_ERR(vdentry))
				cachefiles_bury_object(cache, NULL, cache->store,
						       vdentry,
						       FSCACHE_VOLUME_IS_WEIRD);
			cachefiles_put_directory(volume->dentry);
			cond_resched();
			goto retry;
		}
	}
	
	for (i = 0; i < 256; i++) {
		sprintf(name, "@%02x", i);
		fan = cachefiles_get_directory(cache, vdentry, name, NULL);
		if (IS_ERR(fan))
			goto error_fan;
		volume->fanout[i] = fan;
	}

	cachefiles_end_secure(cache, saved_cred);

	vcookie->cache_priv = volume;
	n_accesses = atomic_inc_return(&vcookie->n_accesses); /* Stop wakeups on dec-to-0 */
	trace_fscache_access_volume(vcookie->debug_id, 0,
				    refcount_read(&vcookie->ref),
				    n_accesses, fscache_access_cache_pin);

	spin_lock(&cache->object_list_lock);
	list_add(&volume->cache_link, &volume->cache->volumes);
	spin_unlock(&cache->object_list_lock);

	kfree(name);
	return;

error_fan:
	for (i = 0; i < 256; i++)
		cachefiles_put_directory(volume->fanout[i]);
error_dir:
	cachefiles_put_directory(volume->dentry);
error_name:
	kfree(name);
error_vol:
	kfree(volume);
	cachefiles_end_secure(cache, saved_cred);
}

/*
 * Release a volume representation.
 */
static void __cachefiles_free_volume(struct cachefiles_volume *volume)
{
	int i;

	_enter("");

	volume->vcookie->cache_priv = NULL;

	for (i = 0; i < 256; i++)
		cachefiles_put_directory(volume->fanout[i]);
	cachefiles_put_directory(volume->dentry);
	kfree(volume);
}

void cachefiles_free_volume(struct fscache_volume *vcookie)
{
	struct cachefiles_volume *volume = vcookie->cache_priv;

	if (volume) {
		spin_lock(&volume->cache->object_list_lock);
		list_del_init(&volume->cache_link);
		spin_unlock(&volume->cache->object_list_lock);
		__cachefiles_free_volume(volume);
	}
}

void cachefiles_withdraw_volume(struct cachefiles_volume *volume)
{
	cachefiles_set_volume_xattr(volume);
	__cachefiles_free_volume(volume);
}

Annotation

Implementation Notes