Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 *  xenfs.c - a filesystem for passing info between the a domain and
  4 *  the hypervisor.
  5 *
  6 * 2008-10-07  Alex Zeffertt    Replaced /proc/xen/xenbus with xenfs filesystem
  7 *                              and /proc/xen compatibility mount point.
  8 *                              Turned xenfs into a loadable module.
  9 */
 10
 11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 12
 13#include <linux/kernel.h>
 14#include <linux/errno.h>
 15#include <linux/module.h>
 16#include <linux/fs.h>
 17#include <linux/fs_context.h>
 18#include <linux/magic.h>
 19
 20#include <xen/xen.h>
 21#include <xen/xenbus.h>
 22
 23#include "xenfs.h"
 24#include "../privcmd.h"
 
 25
 26#include <asm/xen/hypervisor.h>
 27
 28MODULE_DESCRIPTION("Xen filesystem");
 29MODULE_LICENSE("GPL");
 30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 31static ssize_t capabilities_read(struct file *file, char __user *buf,
 32				 size_t size, loff_t *off)
 33{
 34	char *tmp = "";
 35
 36	if (xen_initial_domain())
 37		tmp = "control_d\n";
 38
 39	return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
 40}
 41
 42static const struct file_operations capabilities_file_ops = {
 43	.read = capabilities_read,
 44	.llseek = default_llseek,
 45};
 46
 47static int xenfs_fill_super(struct super_block *sb, struct fs_context *fc)
 48{
 49	static const struct tree_descr xenfs_files[] = {
 50		[2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
 51		{ "capabilities", &capabilities_file_ops, S_IRUGO },
 52		{ "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
 53		{""},
 54	};
 55
 56	static const struct tree_descr xenfs_init_files[] = {
 57		[2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
 58		{ "capabilities", &capabilities_file_ops, S_IRUGO },
 59		{ "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
 60		{ "xsd_kva", &xsd_kva_file_ops, S_IRUSR|S_IWUSR},
 61		{ "xsd_port", &xsd_port_file_ops, S_IRUSR|S_IWUSR},
 62#ifdef CONFIG_XEN_SYMS
 63		{ "xensyms", &xensyms_ops, S_IRUSR},
 64#endif
 65		{""},
 66	};
 
 67
 68	return simple_fill_super(sb, XENFS_SUPER_MAGIC,
 69			xen_initial_domain() ? xenfs_init_files : xenfs_files);
 70}
 
 
 
 
 
 
 
 71
 72static int xenfs_get_tree(struct fs_context *fc)
 73{
 74	return get_tree_single(fc, xenfs_fill_super);
 75}
 76
 77static const struct fs_context_operations xenfs_context_ops = {
 78	.get_tree	= xenfs_get_tree,
 79};
 80
 81static int xenfs_init_fs_context(struct fs_context *fc)
 82{
 83	fc->ops = &xenfs_context_ops;
 84	return 0;
 85}
 86
 87static struct file_system_type xenfs_type = {
 88	.owner =	THIS_MODULE,
 89	.name =		"xenfs",
 90	.init_fs_context = xenfs_init_fs_context,
 91	.kill_sb =	kill_litter_super,
 92};
 93MODULE_ALIAS_FS("xenfs");
 94
 95static int __init xenfs_init(void)
 96{
 97	if (xen_domain())
 98		return register_filesystem(&xenfs_type);
 99
 
100	return 0;
101}
102
103static void __exit xenfs_exit(void)
104{
105	if (xen_domain())
106		unregister_filesystem(&xenfs_type);
107}
108
109module_init(xenfs_init);
110module_exit(xenfs_exit);
111
v3.5.6
 
  1/*
  2 *  xenfs.c - a filesystem for passing info between the a domain and
  3 *  the hypervisor.
  4 *
  5 * 2008-10-07  Alex Zeffertt    Replaced /proc/xen/xenbus with xenfs filesystem
  6 *                              and /proc/xen compatibility mount point.
  7 *                              Turned xenfs into a loadable module.
  8 */
  9
 
 
 10#include <linux/kernel.h>
 11#include <linux/errno.h>
 12#include <linux/module.h>
 13#include <linux/fs.h>
 
 14#include <linux/magic.h>
 15
 16#include <xen/xen.h>
 
 17
 18#include "xenfs.h"
 19#include "../privcmd.h"
 20#include "../xenbus/xenbus_comms.h"
 21
 22#include <asm/xen/hypervisor.h>
 23
 24MODULE_DESCRIPTION("Xen filesystem");
 25MODULE_LICENSE("GPL");
 26
 27static struct inode *xenfs_make_inode(struct super_block *sb, int mode)
 28{
 29	struct inode *ret = new_inode(sb);
 30
 31	if (ret) {
 32		ret->i_mode = mode;
 33		ret->i_uid = ret->i_gid = 0;
 34		ret->i_blocks = 0;
 35		ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
 36	}
 37	return ret;
 38}
 39
 40static struct dentry *xenfs_create_file(struct super_block *sb,
 41					struct dentry *parent,
 42					const char *name,
 43					const struct file_operations *fops,
 44					void *data,
 45					int mode)
 46{
 47	struct dentry *dentry;
 48	struct inode *inode;
 49
 50	dentry = d_alloc_name(parent, name);
 51	if (!dentry)
 52		return NULL;
 53
 54	inode = xenfs_make_inode(sb, S_IFREG | mode);
 55	if (!inode) {
 56		dput(dentry);
 57		return NULL;
 58	}
 59
 60	inode->i_fop = fops;
 61	inode->i_private = data;
 62
 63	d_add(dentry, inode);
 64	return dentry;
 65}
 66
 67static ssize_t capabilities_read(struct file *file, char __user *buf,
 68				 size_t size, loff_t *off)
 69{
 70	char *tmp = "";
 71
 72	if (xen_initial_domain())
 73		tmp = "control_d\n";
 74
 75	return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
 76}
 77
 78static const struct file_operations capabilities_file_ops = {
 79	.read = capabilities_read,
 80	.llseek = default_llseek,
 81};
 82
 83static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
 84{
 85	static struct tree_descr xenfs_files[] = {
 86		[1] = {},
 87		{ "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
 
 
 
 
 
 
 88		{ "capabilities", &capabilities_file_ops, S_IRUGO },
 89		{ "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
 
 
 
 
 
 90		{""},
 91	};
 92	int rc;
 93
 94	rc = simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files);
 95	if (rc < 0)
 96		return rc;
 97
 98	if (xen_initial_domain()) {
 99		xenfs_create_file(sb, sb->s_root, "xsd_kva",
100				  &xsd_kva_file_ops, NULL, S_IRUSR|S_IWUSR);
101		xenfs_create_file(sb, sb->s_root, "xsd_port",
102				  &xsd_port_file_ops, NULL, S_IRUSR|S_IWUSR);
103	}
104
105	return rc;
 
 
106}
107
108static struct dentry *xenfs_mount(struct file_system_type *fs_type,
109				  int flags, const char *dev_name,
110				  void *data)
 
 
111{
112	return mount_single(fs_type, flags, data, xenfs_fill_super);
 
113}
114
115static struct file_system_type xenfs_type = {
116	.owner =	THIS_MODULE,
117	.name =		"xenfs",
118	.mount =	xenfs_mount,
119	.kill_sb =	kill_litter_super,
120};
 
121
122static int __init xenfs_init(void)
123{
124	if (xen_domain())
125		return register_filesystem(&xenfs_type);
126
127	printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
128	return 0;
129}
130
131static void __exit xenfs_exit(void)
132{
133	if (xen_domain())
134		unregister_filesystem(&xenfs_type);
135}
136
137module_init(xenfs_init);
138module_exit(xenfs_exit);
139