1 // SPDX-License-Identifier: GPL-2.0
3 * Hypervisor filesystem for Linux on s390 - debugfs interface
5 * Copyright IBM Corp. 2010
6 * Author(s): Michael Holzheu <holzheu@linux.vnet.ibm.com>
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 mutex_lock(&df
->lock
);
43 data
= hypfs_dbfs_data_alloc(df
);
45 mutex_unlock(&df
->lock
);
48 rc
= df
->data_create(&data
->buf
, &data
->buf_free_ptr
, &data
->size
);
50 mutex_unlock(&df
->lock
);
54 mutex_unlock(&df
->lock
);
56 rc
= simple_read_from_buffer(buf
, size
, ppos
, data
->buf
, data
->size
);
57 hypfs_dbfs_data_free(data
);
61 static long dbfs_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
63 struct hypfs_dbfs_file
*df
= file_inode(file
)->i_private
;
66 mutex_lock(&df
->lock
);
67 if (df
->unlocked_ioctl
)
68 rc
= df
->unlocked_ioctl(file
, cmd
, arg
);
71 mutex_unlock(&df
->lock
);
75 static const struct file_operations dbfs_ops
= {
78 .unlocked_ioctl
= dbfs_ioctl
,
81 void hypfs_dbfs_create_file(struct hypfs_dbfs_file
*df
)
83 df
->dentry
= debugfs_create_file(df
->name
, 0400, dbfs_dir
, df
,
85 mutex_init(&df
->lock
);
88 void hypfs_dbfs_remove_file(struct hypfs_dbfs_file
*df
)
90 debugfs_remove(df
->dentry
);
93 void hypfs_dbfs_init(void)
95 dbfs_dir
= debugfs_create_dir("s390_hypfs", NULL
);
98 void hypfs_dbfs_exit(void)
100 debugfs_remove(dbfs_dir
);