Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Hypervisor filesystem for Linux on s390 - debugfs interface
0004  *
0005  * Copyright IBM Corp. 2010
0006  * Author(s): Michael Holzheu <holzheu@linux.vnet.ibm.com>
0007  */
0008 
0009 #include <linux/slab.h>
0010 #include "hypfs.h"
0011 
0012 static struct dentry *dbfs_dir;
0013 
0014 static struct hypfs_dbfs_data *hypfs_dbfs_data_alloc(struct hypfs_dbfs_file *f)
0015 {
0016     struct hypfs_dbfs_data *data;
0017 
0018     data = kmalloc(sizeof(*data), GFP_KERNEL);
0019     if (!data)
0020         return NULL;
0021     data->dbfs_file = f;
0022     return data;
0023 }
0024 
0025 static void hypfs_dbfs_data_free(struct hypfs_dbfs_data *data)
0026 {
0027     data->dbfs_file->data_free(data->buf_free_ptr);
0028     kfree(data);
0029 }
0030 
0031 static ssize_t dbfs_read(struct file *file, char __user *buf,
0032              size_t size, loff_t *ppos)
0033 {
0034     struct hypfs_dbfs_data *data;
0035     struct hypfs_dbfs_file *df;
0036     ssize_t rc;
0037 
0038     if (*ppos != 0)
0039         return 0;
0040 
0041     df = file_inode(file)->i_private;
0042     mutex_lock(&df->lock);
0043     data = hypfs_dbfs_data_alloc(df);
0044     if (!data) {
0045         mutex_unlock(&df->lock);
0046         return -ENOMEM;
0047     }
0048     rc = df->data_create(&data->buf, &data->buf_free_ptr, &data->size);
0049     if (rc) {
0050         mutex_unlock(&df->lock);
0051         kfree(data);
0052         return rc;
0053     }
0054     mutex_unlock(&df->lock);
0055 
0056     rc = simple_read_from_buffer(buf, size, ppos, data->buf, data->size);
0057     hypfs_dbfs_data_free(data);
0058     return rc;
0059 }
0060 
0061 static long dbfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
0062 {
0063     struct hypfs_dbfs_file *df = file_inode(file)->i_private;
0064     long rc;
0065 
0066     mutex_lock(&df->lock);
0067     if (df->unlocked_ioctl)
0068         rc = df->unlocked_ioctl(file, cmd, arg);
0069     else
0070         rc = -ENOTTY;
0071     mutex_unlock(&df->lock);
0072     return rc;
0073 }
0074 
0075 static const struct file_operations dbfs_ops = {
0076     .read       = dbfs_read,
0077     .llseek     = no_llseek,
0078     .unlocked_ioctl = dbfs_ioctl,
0079 };
0080 
0081 void hypfs_dbfs_create_file(struct hypfs_dbfs_file *df)
0082 {
0083     df->dentry = debugfs_create_file(df->name, 0400, dbfs_dir, df,
0084                      &dbfs_ops);
0085     mutex_init(&df->lock);
0086 }
0087 
0088 void hypfs_dbfs_remove_file(struct hypfs_dbfs_file *df)
0089 {
0090     debugfs_remove(df->dentry);
0091 }
0092 
0093 void hypfs_dbfs_init(void)
0094 {
0095     dbfs_dir = debugfs_create_dir("s390_hypfs", NULL);
0096 }
0097 
0098 void hypfs_dbfs_exit(void)
0099 {
0100     debugfs_remove(dbfs_dir);
0101 }