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 12 static struct dentry *dbfs_dir; 13 14 static 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 25 static 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 31 static 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 if (mutex_lock_interruptible(&df->lock)) 43 return -ERESTARTSYS; 44 45 data = hypfs_dbfs_data_alloc(df); 46 if (!data) { 47 mutex_unlock(&df->lock); 48 return -ENOMEM; 49 } 50 rc = df->data_create(&data->buf, &data->buf_free_ptr, &data->size); 51 if (rc) { 52 mutex_unlock(&df->lock); 53 kfree(data); 54 return rc; 55 } 56 mutex_unlock(&df->lock); 57 58 rc = simple_read_from_buffer(buf, size, ppos, data->buf, data->size); 59 hypfs_dbfs_data_free(data); 60 return rc; 61 } 62 63 static long dbfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 64 { 65 struct hypfs_dbfs_file *df = file_inode(file)->i_private; 66 long rc; 67 68 mutex_lock(&df->lock); 69 if (df->unlocked_ioctl) 70 rc = df->unlocked_ioctl(file, cmd, arg); 71 else 72 rc = -ENOTTY; 73 mutex_unlock(&df->lock); 74 return rc; 75 } 76 77 static const struct file_operations dbfs_ops = { 78 .read = dbfs_read, 79 .llseek = no_llseek, 80 .unlocked_ioctl = dbfs_ioctl, 81 }; 82 83 void hypfs_dbfs_create_file(struct hypfs_dbfs_file *df) 84 { 85 df->dentry = debugfs_create_file(df->name, 0400, dbfs_dir, df, 86 &dbfs_ops); 87 mutex_init(&df->lock); 88 } 89 90 void hypfs_dbfs_remove_file(struct hypfs_dbfs_file *df) 91 { 92 debugfs_remove(df->dentry); 93 } 94 95 static int __init hypfs_dbfs_init(void) 96 { 97 int rc = -ENODATA; 98 99 dbfs_dir = debugfs_create_dir("s390_hypfs", NULL); 100 if (hypfs_diag_init()) 101 goto fail_dbfs_exit; 102 if (hypfs_vm_init()) 103 goto fail_hypfs_diag_exit; 104 hypfs_sprp_init(); 105 if (hypfs_diag0c_init()) 106 goto fail_hypfs_sprp_exit; 107 rc = hypfs_fs_init(); 108 if (rc) 109 goto fail_hypfs_diag0c_exit; 110 return 0; 111 112 fail_hypfs_diag0c_exit: 113 hypfs_diag0c_exit(); 114 fail_hypfs_sprp_exit: 115 hypfs_sprp_exit(); 116 hypfs_vm_exit(); 117 fail_hypfs_diag_exit: 118 hypfs_diag_exit(); 119 pr_err("Initialization of hypfs failed with rc=%i\n", rc); 120 fail_dbfs_exit: 121 debugfs_remove(dbfs_dir); 122 return rc; 123 } 124 device_initcall(hypfs_dbfs_init) 125
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.