2021-11-26 22:32:29 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
/* Network filesystem caching backend to use cache files on a premounted
|
|
|
|
* filesystem
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
|
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/namei.h>
|
|
|
|
#include <linux/mount.h>
|
|
|
|
#include <linux/statfs.h>
|
|
|
|
#include <linux/sysctl.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/netfs.h>
|
|
|
|
#include <trace/events/netfs.h>
|
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
unsigned cachefiles_debug;
|
|
|
|
module_param_named(debug, cachefiles_debug, uint, S_IWUSR | S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(cachefiles_debug, "CacheFiles debugging mask");
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Mounted-filesystem based cache");
|
|
|
|
MODULE_AUTHOR("Red Hat, Inc.");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2021-11-26 23:12:07 +08:00
|
|
|
static struct miscdevice cachefiles_dev = {
|
|
|
|
.minor = MISC_DYNAMIC_MINOR,
|
|
|
|
.name = "cachefiles",
|
|
|
|
.fops = &cachefiles_daemon_fops,
|
|
|
|
};
|
|
|
|
|
2021-11-26 22:32:29 +08:00
|
|
|
/*
|
|
|
|
* initialise the fs caching module
|
|
|
|
*/
|
|
|
|
static int __init cachefiles_init(void)
|
|
|
|
{
|
2021-10-21 15:15:26 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = cachefiles_register_error_injection();
|
|
|
|
if (ret < 0)
|
|
|
|
goto error_einj;
|
2021-11-26 23:12:07 +08:00
|
|
|
ret = misc_register(&cachefiles_dev);
|
|
|
|
if (ret < 0)
|
|
|
|
goto error_dev;
|
2021-10-21 15:15:26 +08:00
|
|
|
|
2021-11-26 22:32:29 +08:00
|
|
|
pr_info("Loaded\n");
|
|
|
|
return 0;
|
2021-10-21 15:15:26 +08:00
|
|
|
|
2021-11-26 23:12:07 +08:00
|
|
|
error_dev:
|
|
|
|
cachefiles_unregister_error_injection();
|
2021-10-21 15:15:26 +08:00
|
|
|
error_einj:
|
|
|
|
pr_err("failed to register: %d\n", ret);
|
|
|
|
return ret;
|
2021-11-26 22:32:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fs_initcall(cachefiles_init);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* clean up on module removal
|
|
|
|
*/
|
|
|
|
static void __exit cachefiles_exit(void)
|
|
|
|
{
|
|
|
|
pr_info("Unloading\n");
|
2021-10-21 15:15:26 +08:00
|
|
|
|
2021-11-26 23:12:07 +08:00
|
|
|
misc_deregister(&cachefiles_dev);
|
2021-10-21 15:15:26 +08:00
|
|
|
cachefiles_unregister_error_injection();
|
2021-11-26 22:32:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_exit(cachefiles_exit);
|