License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-2.6/btrfs-unstable.git] / drivers / xen / xenfs / xenstored.c
blobf59235f9f8a29d91ebad331c46eb8ad25fa5141f
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/slab.h>
3 #include <linux/types.h>
4 #include <linux/mm.h>
5 #include <linux/fs.h>
7 #include <xen/page.h>
8 #include <xen/xenbus.h>
10 #include "xenfs.h"
12 static ssize_t xsd_read(struct file *file, char __user *buf,
13 size_t size, loff_t *off)
15 const char *str = (const char *)file->private_data;
16 return simple_read_from_buffer(buf, size, off, str, strlen(str));
19 static int xsd_release(struct inode *inode, struct file *file)
21 kfree(file->private_data);
22 return 0;
25 static int xsd_kva_open(struct inode *inode, struct file *file)
27 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
28 xen_store_interface);
29 if (!file->private_data)
30 return -ENOMEM;
31 return 0;
34 static int xsd_kva_mmap(struct file *file, struct vm_area_struct *vma)
36 size_t size = vma->vm_end - vma->vm_start;
38 if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
39 return -EINVAL;
41 if (remap_pfn_range(vma, vma->vm_start,
42 virt_to_pfn(xen_store_interface),
43 size, vma->vm_page_prot))
44 return -EAGAIN;
46 return 0;
49 const struct file_operations xsd_kva_file_ops = {
50 .open = xsd_kva_open,
51 .mmap = xsd_kva_mmap,
52 .read = xsd_read,
53 .release = xsd_release,
56 static int xsd_port_open(struct inode *inode, struct file *file)
58 file->private_data = (void *)kasprintf(GFP_KERNEL, "%d",
59 xen_store_evtchn);
60 if (!file->private_data)
61 return -ENOMEM;
62 return 0;
65 const struct file_operations xsd_port_file_ops = {
66 .open = xsd_port_open,
67 .read = xsd_read,
68 .release = xsd_release,