summaryrefslogtreecommitdiffstats
path: root/kernel/drivers/xen/xenfs/xenstored.c
blob: fef20dbc6a5c2dfada86792f4eea7e7a631085e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/mm.h>
#include <linux/fs.h>

#include <xen/page.h>

#include "xenfs.h"
#include "../xenbus/xenbus_comms.h"

static ssize_t xsd_read(struct file *file, char __user *buf,
			    size_t size, loff_t *off)
{
	const char *str = (const char *)file->private_data;
	return simple_read_from_buffer(buf, size, off, str, strlen(str));
}

static int xsd_release(struct inode *inode, struct file *file)
{
	kfree(file->private_data);
	return 0;
}

static int xsd_kva_open(struct inode *inode, struct file *file)
{
	file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
					       xen_store_interface);
	if (!file->private_data)
		return -ENOMEM;
	return 0;
}

static int xsd_kva_mmap(struct file *file, struct vm_area_struct *vma)
{
	size_t size = vma->vm_end - vma->vm_start;

	if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
		return -EINVAL;

	if (remap_pfn_range(vma, vma->vm_start,
			    virt_to_pfn(xen_store_interface),
			    size, vma->vm_page_prot))
		return -EAGAIN;

	return 0;
}

const struct file_operations xsd_kva_file_ops = {
	.open = xsd_kva_open,
	.mmap = xsd_kva_mmap,
	.read = xsd_read,
	.release = xsd_release,
};

static int xsd_port_open(struct inode *inode, struct file *file)
{
	file->private_data = (void *)kasprintf(GFP_KERNEL, "%d",
					       xen_store_evtchn);
	if (!file->private_data)
		return -ENOMEM;
	return 0;
}

const struct file_operations xsd_port_file_ops = {
	.open = xsd_port_open,
	.read = xsd_read,
	.release = xsd_release,
};