^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-1.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Hypervisor filesystem for Linux on s390.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright IBM Corp. 2006, 2008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author(s): Michael Holzheu <holzheu@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define KMSG_COMPONENT "hypfs"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/fs_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/fs_parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/kobject.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/uio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/ebcdic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "hypfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define HYPFS_MAGIC 0x687970 /* ASCII 'hyp' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define TMP_SIZE 64 /* size of temporary buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static struct dentry *hypfs_create_update_file(struct dentry *dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct hypfs_sb_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) kuid_t uid; /* uid used for files and dirs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) kgid_t gid; /* gid used for files and dirs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct dentry *update_file; /* file to trigger update */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) time64_t last_update; /* last update, CLOCK_MONOTONIC time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct mutex lock; /* lock to protect update process */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static const struct file_operations hypfs_file_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static struct file_system_type hypfs_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static const struct super_operations hypfs_s_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /* start of list of all dentries, which have to be deleted on update */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static struct dentry *hypfs_last_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static void hypfs_update_update(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct hypfs_sb_info *sb_info = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct inode *inode = d_inode(sb_info->update_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) sb_info->last_update = ktime_get_seconds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* directory tree removal functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static void hypfs_add_dentry(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) dentry->d_fsdata = hypfs_last_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) hypfs_last_dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static void hypfs_remove(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct dentry *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) parent = dentry->d_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) inode_lock(d_inode(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (simple_positive(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (d_is_dir(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) simple_rmdir(d_inode(parent), dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) simple_unlink(d_inode(parent), dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) d_drop(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) inode_unlock(d_inode(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static void hypfs_delete_tree(struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) while (hypfs_last_dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct dentry *next_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) next_dentry = hypfs_last_dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) hypfs_remove(hypfs_last_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) hypfs_last_dentry = next_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static struct inode *hypfs_make_inode(struct super_block *sb, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct inode *ret = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct hypfs_sb_info *hypfs_info = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) ret->i_ino = get_next_ino();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) ret->i_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ret->i_uid = hypfs_info->uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ret->i_gid = hypfs_info->gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ret->i_atime = ret->i_mtime = ret->i_ctime = current_time(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (S_ISDIR(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) set_nlink(ret, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static void hypfs_evict_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) kfree(inode->i_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static int hypfs_open(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) char *data = file_inode(filp)->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct hypfs_sb_info *fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (filp->f_mode & FMODE_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (!(inode->i_mode & S_IWUGO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (filp->f_mode & FMODE_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (!(inode->i_mode & S_IRUGO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) fs_info = inode->i_sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if(data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) mutex_lock(&fs_info->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) filp->private_data = kstrdup(data, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (!filp->private_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) mutex_unlock(&fs_info->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) mutex_unlock(&fs_info->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return nonseekable_open(inode, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static ssize_t hypfs_read_iter(struct kiocb *iocb, struct iov_iter *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct file *file = iocb->ki_filp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) char *data = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) size_t available = strlen(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) loff_t pos = iocb->ki_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) size_t count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (pos < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (pos >= available || !iov_iter_count(to))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) count = copy_to_iter(data + pos, available - pos, to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) iocb->ki_pos = pos + count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) file_accessed(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static ssize_t hypfs_write_iter(struct kiocb *iocb, struct iov_iter *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct super_block *sb = file_inode(iocb->ki_filp)->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct hypfs_sb_info *fs_info = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) size_t count = iov_iter_count(from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * Currently we only allow one update per second for two reasons:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * 1. diag 204 is VERY expensive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * 2. If several processes do updates in parallel and then read the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * hypfs data, the likelihood of collisions is reduced, if we restrict
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * the minimum update interval. A collision occurs, if during the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * data gathering of one process another process triggers an update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * If the first process wants to ensure consistent data, it has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * to restart data collection in this case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) mutex_lock(&fs_info->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (fs_info->last_update == ktime_get_seconds()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) rc = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) hypfs_delete_tree(sb->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (MACHINE_IS_VM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) rc = hypfs_vm_create_files(sb->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) rc = hypfs_diag_create_files(sb->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) pr_err("Updating the hypfs tree failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) hypfs_delete_tree(sb->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) hypfs_update_update(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) rc = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) iov_iter_advance(from, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) mutex_unlock(&fs_info->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static int hypfs_release(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) kfree(filp->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) enum { Opt_uid, Opt_gid, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static const struct fs_parameter_spec hypfs_fs_parameters[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) fsparam_u32("gid", Opt_gid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) fsparam_u32("uid", Opt_uid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static int hypfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct hypfs_sb_info *hypfs_info = fc->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct fs_parse_result result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) kuid_t uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) kgid_t gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) opt = fs_parse(fc, hypfs_fs_parameters, param, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (opt < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) switch (opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) case Opt_uid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) uid = make_kuid(current_user_ns(), result.uint_32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (!uid_valid(uid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return invalf(fc, "Unknown uid");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) hypfs_info->uid = uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) case Opt_gid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) gid = make_kgid(current_user_ns(), result.uint_32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (!gid_valid(gid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return invalf(fc, "Unknown gid");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) hypfs_info->gid = gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static int hypfs_show_options(struct seq_file *s, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct hypfs_sb_info *hypfs_info = root->d_sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) seq_printf(s, ",uid=%u", from_kuid_munged(&init_user_ns, hypfs_info->uid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) seq_printf(s, ",gid=%u", from_kgid_munged(&init_user_ns, hypfs_info->gid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static int hypfs_fill_super(struct super_block *sb, struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct hypfs_sb_info *sbi = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) struct inode *root_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct dentry *root_dentry, *update_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) sb->s_blocksize = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) sb->s_blocksize_bits = PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) sb->s_magic = HYPFS_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) sb->s_op = &hypfs_s_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) root_inode = hypfs_make_inode(sb, S_IFDIR | 0755);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (!root_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) root_inode->i_op = &simple_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) root_inode->i_fop = &simple_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) sb->s_root = root_dentry = d_make_root(root_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (!root_dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (MACHINE_IS_VM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) rc = hypfs_vm_create_files(root_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) rc = hypfs_diag_create_files(root_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) update_file = hypfs_create_update_file(root_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (IS_ERR(update_file))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return PTR_ERR(update_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) sbi->update_file = update_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) hypfs_update_update(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) pr_info("Hypervisor filesystem mounted\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static int hypfs_get_tree(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return get_tree_single(fc, hypfs_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static void hypfs_free_fc(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) kfree(fc->s_fs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static const struct fs_context_operations hypfs_context_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) .free = hypfs_free_fc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) .parse_param = hypfs_parse_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) .get_tree = hypfs_get_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static int hypfs_init_fs_context(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct hypfs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) sbi = kzalloc(sizeof(struct hypfs_sb_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (!sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) mutex_init(&sbi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) sbi->uid = current_uid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) sbi->gid = current_gid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) fc->s_fs_info = sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) fc->ops = &hypfs_context_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static void hypfs_kill_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct hypfs_sb_info *sb_info = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (sb->s_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) hypfs_delete_tree(sb->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (sb_info && sb_info->update_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) hypfs_remove(sb_info->update_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) kfree(sb->s_fs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) kill_litter_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static struct dentry *hypfs_create_file(struct dentry *parent, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) char *data, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) inode_lock(d_inode(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) dentry = lookup_one_len(name, parent, strlen(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) dentry = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) inode = hypfs_make_inode(parent->d_sb, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) dentry = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (S_ISREG(mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) inode->i_fop = &hypfs_file_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) inode->i_size = strlen(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) inode->i_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) } else if (S_ISDIR(mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) inode->i_op = &simple_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) inode->i_fop = &simple_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) inc_nlink(d_inode(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) inode->i_private = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) dget(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) inode_unlock(d_inode(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct dentry *hypfs_mkdir(struct dentry *parent, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) dentry = hypfs_create_file(parent, name, NULL, S_IFDIR | DIR_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (IS_ERR(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) hypfs_add_dentry(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static struct dentry *hypfs_create_update_file(struct dentry *dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) dentry = hypfs_create_file(dir, "update", NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) S_IFREG | UPDATE_FILE_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * We do not put the update file on the 'delete' list with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * hypfs_add_dentry(), since it should not be removed when the tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * is updated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct dentry *hypfs_create_u64(struct dentry *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) const char *name, __u64 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) char tmp[TMP_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) snprintf(tmp, TMP_SIZE, "%llu\n", (unsigned long long int)value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) buffer = kstrdup(tmp, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) dentry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) hypfs_create_file(dir, name, buffer, S_IFREG | REG_FILE_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) hypfs_add_dentry(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct dentry *hypfs_create_str(struct dentry *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) const char *name, char *string)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) buffer = kmalloc(strlen(string) + 2, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) sprintf(buffer, "%s\n", string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) dentry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) hypfs_create_file(dir, name, buffer, S_IFREG | REG_FILE_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) hypfs_add_dentry(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static const struct file_operations hypfs_file_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) .open = hypfs_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) .release = hypfs_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) .read_iter = hypfs_read_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) .write_iter = hypfs_write_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) .llseek = no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static struct file_system_type hypfs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) .name = "s390_hypfs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) .init_fs_context = hypfs_init_fs_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) .parameters = hypfs_fs_parameters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) .kill_sb = hypfs_kill_super
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static const struct super_operations hypfs_s_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) .statfs = simple_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) .evict_inode = hypfs_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) .show_options = hypfs_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static int __init hypfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) hypfs_dbfs_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if (hypfs_diag_init()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) rc = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) goto fail_dbfs_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (hypfs_vm_init()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) rc = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) goto fail_hypfs_diag_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) hypfs_sprp_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (hypfs_diag0c_init()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) rc = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) goto fail_hypfs_sprp_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) rc = sysfs_create_mount_point(hypervisor_kobj, "s390");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) goto fail_hypfs_diag0c_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) rc = register_filesystem(&hypfs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) goto fail_filesystem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) fail_filesystem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) sysfs_remove_mount_point(hypervisor_kobj, "s390");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) fail_hypfs_diag0c_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) hypfs_diag0c_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) fail_hypfs_sprp_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) hypfs_sprp_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) hypfs_vm_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) fail_hypfs_diag_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) hypfs_diag_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) fail_dbfs_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) hypfs_dbfs_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) pr_err("Initialization of hypfs failed with rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) device_initcall(hypfs_init)