1 // SPDX-License-Identifier: GPL-2.0
3 * Hypervisor filesystem for Linux on s390 - debugfs interface
5 * Copyright IBM Corp. 2010
9 #include <linux/slab.h>
12 static struct dentry *dbfs_dir;
14 static struct hypfs_dbfs_data *hypfs_dbfs_data_alloc(struct hypfs_dbfs_file *f)
16 struct hypfs_dbfs_data *data;
18 data = kmalloc(sizeof(*data), GFP_KERNEL);
25 static void hypfs_dbfs_data_free(struct hypfs_dbfs_data *data)
27 data->dbfs_file->data_free(data->buf_free_ptr);
31 static ssize_t dbfs_read(struct file *file, char __user *buf,
32 size_t size, loff_t *ppos)
34 struct hypfs_dbfs_data *data;
35 struct hypfs_dbfs_file *df;
41 df = file_inode(file)->i_private;
42 if (mutex_lock_interruptible(&df->lock))
45 data = hypfs_dbfs_data_alloc(df);
47 mutex_unlock(&df->lock);
50 rc = df->data_create(&data->buf, &data->buf_free_ptr, &data->size);
52 mutex_unlock(&df->lock);
56 mutex_unlock(&df->lock);
58 rc = simple_read_from_buffer(buf, size, ppos, data->buf, data->size);
59 hypfs_dbfs_data_free(data);
63 static long dbfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
65 struct hypfs_dbfs_file *df = file_inode(file)->i_private;
68 mutex_lock(&df->lock);
69 if (df->unlocked_ioctl)
70 rc = df->unlocked_ioctl(file, cmd, arg);
73 mutex_unlock(&df->lock);
77 static const struct file_operations dbfs_ops = {
79 .unlocked_ioctl = dbfs_ioctl,
82 void hypfs_dbfs_create_file(struct hypfs_dbfs_file *df)
84 df->dentry = debugfs_create_file(df->name, 0400, dbfs_dir, df,
86 mutex_init(&df->lock);
89 void hypfs_dbfs_remove_file(struct hypfs_dbfs_file *df)
91 debugfs_remove(df->dentry);
94 static int __init hypfs_dbfs_init(void)
98 dbfs_dir = debugfs_create_dir("s390_hypfs", NULL);
99 if (hypfs_diag_init())
102 goto fail_hypfs_diag_exit;
104 if (hypfs_diag0c_init())
105 goto fail_hypfs_sprp_exit;
106 rc = hypfs_fs_init();
108 goto fail_hypfs_diag0c_exit;
111 fail_hypfs_diag0c_exit:
113 fail_hypfs_sprp_exit:
116 fail_hypfs_diag_exit:
118 pr_err("Initialization of hypfs failed with rc=%i\n", rc);
120 debugfs_remove(dbfs_dir);
123 device_initcall(hypfs_dbfs_init)