Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Procfs support for lockd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright (c) 2014 Jeff Layton <jlayton@primarydata.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/nsproxy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "netns.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "procfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)  * We only allow strings that start with 'Y', 'y', or '1'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) nlm_end_grace_write(struct file *file, const char __user *buf, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 		    loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	struct lockd_net *ln = net_generic(current->nsproxy->net_ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 					   lockd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	if (size < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	data = simple_transaction_get(file, buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 		return PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	switch(data[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	case 'Y':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	case 'y':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	case '1':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 		locks_end_grace(&ln->lockd_manager);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) nlm_end_grace_read(struct file *file, char __user *buf, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 		   loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	struct lockd_net *ln = net_generic(current->nsproxy->net_ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 					   lockd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	char resp[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	resp[0] = list_empty(&ln->lockd_manager.list) ? 'Y' : 'N';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	resp[1] = '\n';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	resp[2] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	return simple_read_from_buffer(buf, size, pos, resp, sizeof(resp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static const struct proc_ops lockd_end_grace_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	.proc_write	= nlm_end_grace_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	.proc_read	= nlm_end_grace_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	.proc_lseek	= default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	.proc_release	= simple_transaction_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) lockd_create_procfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	struct proc_dir_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	entry = proc_mkdir("fs/lockd", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	entry = proc_create("nlm_end_grace", S_IRUGO|S_IWUSR, entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 			    &lockd_end_grace_proc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	if (!entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 		remove_proc_entry("fs/lockd", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) void __exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) lockd_remove_procfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 	remove_proc_entry("fs/lockd/nlm_end_grace", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 	remove_proc_entry("fs/lockd", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }