2 * Hypervisor filesystem for Linux on s390 - debugfs interface
4 * Copyright IBM Corp. 2010
8 #include <linux/slab.h>
11 static struct dentry *dbfs_dir;
13 static struct hypfs_dbfs_data *hypfs_dbfs_data_alloc(struct hypfs_dbfs_file *f)
15 struct hypfs_dbfs_data *data;
17 data = kmalloc(sizeof(*data), GFP_KERNEL);
24 static void hypfs_dbfs_data_free(struct hypfs_dbfs_data *data)
26 data->dbfs_file->data_free(data->buf_free_ptr);
30 static ssize_t dbfs_read(struct file *file, char __user *buf,
31 size_t size, loff_t *ppos)
33 struct hypfs_dbfs_data *data;
34 struct hypfs_dbfs_file *df;
40 df = file_inode(file)->i_private;
41 mutex_lock(&df->lock);
42 data = hypfs_dbfs_data_alloc(df);
44 mutex_unlock(&df->lock);
47 rc = df->data_create(&data->buf, &data->buf_free_ptr, &data->size);
49 mutex_unlock(&df->lock);
53 mutex_unlock(&df->lock);
55 rc = simple_read_from_buffer(buf, size, ppos, data->buf, data->size);
56 hypfs_dbfs_data_free(data);
60 static long dbfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
62 struct hypfs_dbfs_file *df = file_inode(file)->i_private;
65 mutex_lock(&df->lock);
66 if (df->unlocked_ioctl)
67 rc = df->unlocked_ioctl(file, cmd, arg);
70 mutex_unlock(&df->lock);
74 static const struct file_operations dbfs_ops = {
77 .unlocked_ioctl = dbfs_ioctl,
80 int hypfs_dbfs_create_file(struct hypfs_dbfs_file *df)
82 df->dentry = debugfs_create_file(df->name, 0400, dbfs_dir, df,
84 if (IS_ERR(df->dentry))
85 return PTR_ERR(df->dentry);
86 mutex_init(&df->lock);
90 void hypfs_dbfs_remove_file(struct hypfs_dbfs_file *df)
92 debugfs_remove(df->dentry);
95 int hypfs_dbfs_init(void)
97 dbfs_dir = debugfs_create_dir("s390_hypfs", NULL);
98 return PTR_ERR_OR_ZERO(dbfs_dir);
101 void hypfs_dbfs_exit(void)
103 debugfs_remove(dbfs_dir);