Linux Audio

Check our new training course

Embedded Linux training

Mar 10-20, 2025, special US time zones
Register
Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Hypervisor filesystem for Linux on s390 - debugfs interface
  4 *
  5 * Copyright IBM Corp. 2010
  6 * Author(s): Michael Holzheu <holzheu@linux.vnet.ibm.com>
  7 */
  8
  9#include <linux/slab.h>
 10#include "hypfs.h"
 11
 12static struct dentry *dbfs_dir;
 13
 14static struct hypfs_dbfs_data *hypfs_dbfs_data_alloc(struct hypfs_dbfs_file *f)
 15{
 16	struct hypfs_dbfs_data *data;
 17
 18	data = kmalloc(sizeof(*data), GFP_KERNEL);
 19	if (!data)
 20		return NULL;
 21	data->dbfs_file = f;
 22	return data;
 23}
 24
 25static void hypfs_dbfs_data_free(struct hypfs_dbfs_data *data)
 26{
 27	data->dbfs_file->data_free(data->buf_free_ptr);
 28	kfree(data);
 29}
 30
 31static ssize_t dbfs_read(struct file *file, char __user *buf,
 32			 size_t size, loff_t *ppos)
 33{
 34	struct hypfs_dbfs_data *data;
 35	struct hypfs_dbfs_file *df;
 36	ssize_t rc;
 37
 38	if (*ppos != 0)
 39		return 0;
 40
 41	df = file_inode(file)->i_private;
 42	mutex_lock(&df->lock);
 43	data = hypfs_dbfs_data_alloc(df);
 44	if (!data) {
 45		mutex_unlock(&df->lock);
 46		return -ENOMEM;
 47	}
 48	rc = df->data_create(&data->buf, &data->buf_free_ptr, &data->size);
 49	if (rc) {
 50		mutex_unlock(&df->lock);
 51		kfree(data);
 52		return rc;
 53	}
 54	mutex_unlock(&df->lock);
 55
 56	rc = simple_read_from_buffer(buf, size, ppos, data->buf, data->size);
 57	hypfs_dbfs_data_free(data);
 58	return rc;
 59}
 60
 61static long dbfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 62{
 63	struct hypfs_dbfs_file *df = file_inode(file)->i_private;
 64	long rc;
 65
 66	mutex_lock(&df->lock);
 67	if (df->unlocked_ioctl)
 68		rc = df->unlocked_ioctl(file, cmd, arg);
 69	else
 70		rc = -ENOTTY;
 71	mutex_unlock(&df->lock);
 72	return rc;
 73}
 74
 75static const struct file_operations dbfs_ops = {
 76	.read		= dbfs_read,
 77	.llseek		= no_llseek,
 78	.unlocked_ioctl = dbfs_ioctl,
 79};
 80
 81void hypfs_dbfs_create_file(struct hypfs_dbfs_file *df)
 82{
 83	df->dentry = debugfs_create_file(df->name, 0400, dbfs_dir, df,
 84					 &dbfs_ops);
 
 
 85	mutex_init(&df->lock);
 
 86}
 87
 88void hypfs_dbfs_remove_file(struct hypfs_dbfs_file *df)
 89{
 90	debugfs_remove(df->dentry);
 91}
 92
 93static int __init hypfs_dbfs_init(void)
 94{
 95	int rc = -ENODATA;
 96
 97	dbfs_dir = debugfs_create_dir("s390_hypfs", NULL);
 98	if (hypfs_diag_init())
 99		goto fail_dbfs_exit;
100	if (hypfs_vm_init())
101		goto fail_hypfs_diag_exit;
102	hypfs_sprp_init();
103	if (hypfs_diag0c_init())
104		goto fail_hypfs_sprp_exit;
105	rc = hypfs_fs_init();
106	if (rc)
107		goto fail_hypfs_diag0c_exit;
108	return 0;
109
110fail_hypfs_diag0c_exit:
111	hypfs_diag0c_exit();
112fail_hypfs_sprp_exit:
113	hypfs_sprp_exit();
114	hypfs_vm_exit();
115fail_hypfs_diag_exit:
116	hypfs_diag_exit();
117	pr_err("Initialization of hypfs failed with rc=%i\n", rc);
118fail_dbfs_exit:
119	debugfs_remove(dbfs_dir);
120	return rc;
121}
122device_initcall(hypfs_dbfs_init)
v4.10.11
 
  1/*
  2 * Hypervisor filesystem for Linux on s390 - debugfs interface
  3 *
  4 * Copyright IBM Corp. 2010
  5 * Author(s): Michael Holzheu <holzheu@linux.vnet.ibm.com>
  6 */
  7
  8#include <linux/slab.h>
  9#include "hypfs.h"
 10
 11static struct dentry *dbfs_dir;
 12
 13static struct hypfs_dbfs_data *hypfs_dbfs_data_alloc(struct hypfs_dbfs_file *f)
 14{
 15	struct hypfs_dbfs_data *data;
 16
 17	data = kmalloc(sizeof(*data), GFP_KERNEL);
 18	if (!data)
 19		return NULL;
 20	data->dbfs_file = f;
 21	return data;
 22}
 23
 24static void hypfs_dbfs_data_free(struct hypfs_dbfs_data *data)
 25{
 26	data->dbfs_file->data_free(data->buf_free_ptr);
 27	kfree(data);
 28}
 29
 30static ssize_t dbfs_read(struct file *file, char __user *buf,
 31			 size_t size, loff_t *ppos)
 32{
 33	struct hypfs_dbfs_data *data;
 34	struct hypfs_dbfs_file *df;
 35	ssize_t rc;
 36
 37	if (*ppos != 0)
 38		return 0;
 39
 40	df = file_inode(file)->i_private;
 41	mutex_lock(&df->lock);
 42	data = hypfs_dbfs_data_alloc(df);
 43	if (!data) {
 44		mutex_unlock(&df->lock);
 45		return -ENOMEM;
 46	}
 47	rc = df->data_create(&data->buf, &data->buf_free_ptr, &data->size);
 48	if (rc) {
 49		mutex_unlock(&df->lock);
 50		kfree(data);
 51		return rc;
 52	}
 53	mutex_unlock(&df->lock);
 54
 55	rc = simple_read_from_buffer(buf, size, ppos, data->buf, data->size);
 56	hypfs_dbfs_data_free(data);
 57	return rc;
 58}
 59
 60static long dbfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 61{
 62	struct hypfs_dbfs_file *df = file_inode(file)->i_private;
 63	long rc;
 64
 65	mutex_lock(&df->lock);
 66	if (df->unlocked_ioctl)
 67		rc = df->unlocked_ioctl(file, cmd, arg);
 68	else
 69		rc = -ENOTTY;
 70	mutex_unlock(&df->lock);
 71	return rc;
 72}
 73
 74static const struct file_operations dbfs_ops = {
 75	.read		= dbfs_read,
 76	.llseek		= no_llseek,
 77	.unlocked_ioctl = dbfs_ioctl,
 78};
 79
 80int hypfs_dbfs_create_file(struct hypfs_dbfs_file *df)
 81{
 82	df->dentry = debugfs_create_file(df->name, 0400, dbfs_dir, df,
 83					 &dbfs_ops);
 84	if (IS_ERR(df->dentry))
 85		return PTR_ERR(df->dentry);
 86	mutex_init(&df->lock);
 87	return 0;
 88}
 89
 90void hypfs_dbfs_remove_file(struct hypfs_dbfs_file *df)
 91{
 92	debugfs_remove(df->dentry);
 93}
 94
 95int hypfs_dbfs_init(void)
 96{
 
 
 97	dbfs_dir = debugfs_create_dir("s390_hypfs", NULL);
 98	return PTR_ERR_OR_ZERO(dbfs_dir);
 99}
 
 
 
 
 
 
 
 
 
100
101void hypfs_dbfs_exit(void)
102{
 
 
 
 
 
 
 
103	debugfs_remove(dbfs_dir);
 
104}