blob: 440382b403c3d6a0d1c99cb4995d0a2784cda945 [file] [log] [blame]
Michael Holzheu24bbb1f2006-06-23 02:05:06 -07001/*
Michael Holzheuf19bfb22006-09-20 15:58:44 +02002 * arch/s390/hypfs/inode.c
Michael Holzheu24bbb1f2006-06-23 02:05:06 -07003 * Hypervisor filesystem for Linux on s390.
4 *
Michael Holzheuf55495b2008-12-25 13:39:39 +01005 * Copyright IBM Corp. 2006, 2008
Michael Holzheu24bbb1f2006-06-23 02:05:06 -07006 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
7 */
8
Michael Holzheuf55495b2008-12-25 13:39:39 +01009#define KMSG_COMPONENT "hypfs"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Michael Holzheu24bbb1f2006-06-23 02:05:06 -070012#include <linux/types.h>
13#include <linux/errno.h>
14#include <linux/fs.h>
15#include <linux/namei.h>
16#include <linux/vfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Michael Holzheu24bbb1f2006-06-23 02:05:06 -070018#include <linux/pagemap.h>
Michael Holzheu24bbb1f2006-06-23 02:05:06 -070019#include <linux/time.h>
20#include <linux/parser.h>
21#include <linux/sysfs.h>
22#include <linux/module.h>
Michael Holzheub01af5b2007-08-10 14:32:27 +020023#include <linux/seq_file.h>
24#include <linux/mount.h>
Michael Holzheu24bbb1f2006-06-23 02:05:06 -070025#include <asm/ebcdic.h>
26#include "hypfs.h"
Michael Holzheu24bbb1f2006-06-23 02:05:06 -070027
28#define HYPFS_MAGIC 0x687970 /* ASCII 'hyp' */
29#define TMP_SIZE 64 /* size of temporary buffers */
30
31static struct dentry *hypfs_create_update_file(struct super_block *sb,
32 struct dentry *dir);
33
34struct hypfs_sb_info {
35 uid_t uid; /* uid used for files and dirs */
36 gid_t gid; /* gid used for files and dirs */
37 struct dentry *update_file; /* file to trigger update */
38 time_t last_update; /* last update time in secs since 1970 */
39 struct mutex lock; /* lock to protect update process */
40};
41
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -080042static const struct file_operations hypfs_file_ops;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -070043static struct file_system_type hypfs_type;
Alexey Dobriyanb87221d2009-09-21 17:01:09 -070044static const struct super_operations hypfs_s_ops;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -070045
46/* start of list of all dentries, which have to be deleted on update */
47static struct dentry *hypfs_last_dentry;
48
49static void hypfs_update_update(struct super_block *sb)
50{
51 struct hypfs_sb_info *sb_info = sb->s_fs_info;
52 struct inode *inode = sb_info->update_file->d_inode;
53
54 sb_info->last_update = get_seconds();
55 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
56}
57
58/* directory tree removal functions */
59
60static void hypfs_add_dentry(struct dentry *dentry)
61{
62 dentry->d_fsdata = hypfs_last_dentry;
63 hypfs_last_dentry = dentry;
64}
65
Michael Holzheu9b5a03e2007-08-22 13:51:43 +020066static inline int hypfs_positive(struct dentry *dentry)
67{
68 return dentry->d_inode && !d_unhashed(dentry);
69}
70
Michael Holzheu24bbb1f2006-06-23 02:05:06 -070071static void hypfs_remove(struct dentry *dentry)
72{
73 struct dentry *parent;
74
75 parent = dentry->d_parent;
Michael Holzheu9b5a03e2007-08-22 13:51:43 +020076 if (!parent || !parent->d_inode)
77 return;
78 mutex_lock(&parent->d_inode->i_mutex);
79 if (hypfs_positive(dentry)) {
80 if (S_ISDIR(dentry->d_inode->i_mode))
81 simple_rmdir(parent->d_inode, dentry);
82 else
83 simple_unlink(parent->d_inode, dentry);
84 }
Michael Holzheu24bbb1f2006-06-23 02:05:06 -070085 d_delete(dentry);
86 dput(dentry);
Michael Holzheu9b5a03e2007-08-22 13:51:43 +020087 mutex_unlock(&parent->d_inode->i_mutex);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -070088}
89
90static void hypfs_delete_tree(struct dentry *root)
91{
92 while (hypfs_last_dentry) {
93 struct dentry *next_dentry;
94 next_dentry = hypfs_last_dentry->d_fsdata;
95 hypfs_remove(hypfs_last_dentry);
96 hypfs_last_dentry = next_dentry;
97 }
98}
99
Al Virofec0eba2011-07-24 23:30:19 -0400100static struct inode *hypfs_make_inode(struct super_block *sb, umode_t mode)
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700101{
102 struct inode *ret = new_inode(sb);
103
104 if (ret) {
105 struct hypfs_sb_info *hypfs_info = sb->s_fs_info;
Michael Holzheuc960bec2012-06-29 14:48:09 +0200106 ret->i_ino = get_next_ino();
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700107 ret->i_mode = mode;
108 ret->i_uid = hypfs_info->uid;
109 ret->i_gid = hypfs_info->gid;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700110 ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
Al Virofec0eba2011-07-24 23:30:19 -0400111 if (S_ISDIR(mode))
Miklos Szeredibfe86842011-10-28 14:13:29 +0200112 set_nlink(ret, 2);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700113 }
114 return ret;
115}
116
Al Virob69257f2010-06-04 21:02:59 -0400117static void hypfs_evict_inode(struct inode *inode)
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700118{
Jan Karadbd57682012-05-03 14:48:02 +0200119 clear_inode(inode);
Theodore Ts'o8e18e292006-09-27 01:50:46 -0700120 kfree(inode->i_private);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700121}
122
123static int hypfs_open(struct inode *inode, struct file *filp)
124{
Josef Sipekd20343e2006-12-08 02:37:35 -0800125 char *data = filp->f_path.dentry->d_inode->i_private;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700126 struct hypfs_sb_info *fs_info;
127
128 if (filp->f_mode & FMODE_WRITE) {
129 if (!(inode->i_mode & S_IWUGO))
130 return -EACCES;
131 }
132 if (filp->f_mode & FMODE_READ) {
133 if (!(inode->i_mode & S_IRUGO))
134 return -EACCES;
135 }
136
137 fs_info = inode->i_sb->s_fs_info;
138 if(data) {
139 mutex_lock(&fs_info->lock);
140 filp->private_data = kstrdup(data, GFP_KERNEL);
141 if (!filp->private_data) {
142 mutex_unlock(&fs_info->lock);
143 return -ENOMEM;
144 }
145 mutex_unlock(&fs_info->lock);
146 }
Martin Schwidefsky58ea91c2010-05-17 10:00:07 +0200147 return nonseekable_open(inode, filp);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700148}
149
Badari Pulavarty027445c2006-09-30 23:28:46 -0700150static ssize_t hypfs_aio_read(struct kiocb *iocb, const struct iovec *iov,
151 unsigned long nr_segs, loff_t offset)
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700152{
153 char *data;
Akinobu Mitaa29591c2008-07-14 09:59:16 +0200154 ssize_t ret;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700155 struct file *filp = iocb->ki_filp;
Badari Pulavarty027445c2006-09-30 23:28:46 -0700156 /* XXX: temporary */
157 char __user *buf = iov[0].iov_base;
158 size_t count = iov[0].iov_len;
159
Akinobu Mitaa29591c2008-07-14 09:59:16 +0200160 if (nr_segs != 1)
161 return -EINVAL;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700162
163 data = filp->private_data;
Akinobu Mitaa29591c2008-07-14 09:59:16 +0200164 ret = simple_read_from_buffer(buf, count, &offset, data, strlen(data));
165 if (ret <= 0)
166 return ret;
167
168 iocb->ki_pos += ret;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700169 file_accessed(filp);
Akinobu Mitaa29591c2008-07-14 09:59:16 +0200170
171 return ret;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700172}
Badari Pulavarty027445c2006-09-30 23:28:46 -0700173static ssize_t hypfs_aio_write(struct kiocb *iocb, const struct iovec *iov,
174 unsigned long nr_segs, loff_t offset)
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700175{
176 int rc;
177 struct super_block *sb;
178 struct hypfs_sb_info *fs_info;
Badari Pulavarty027445c2006-09-30 23:28:46 -0700179 size_t count = iov_length(iov, nr_segs);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700180
Josef Sipekd20343e2006-12-08 02:37:35 -0800181 sb = iocb->ki_filp->f_path.dentry->d_inode->i_sb;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700182 fs_info = sb->s_fs_info;
183 /*
184 * Currently we only allow one update per second for two reasons:
185 * 1. diag 204 is VERY expensive
186 * 2. If several processes do updates in parallel and then read the
187 * hypfs data, the likelihood of collisions is reduced, if we restrict
188 * the minimum update interval. A collision occurs, if during the
189 * data gathering of one process another process triggers an update
190 * If the first process wants to ensure consistent data, it has
191 * to restart data collection in this case.
192 */
193 mutex_lock(&fs_info->lock);
194 if (fs_info->last_update == get_seconds()) {
195 rc = -EBUSY;
196 goto out;
197 }
198 hypfs_delete_tree(sb->s_root);
Michael Holzheu31cb4bd2007-02-05 21:18:29 +0100199 if (MACHINE_IS_VM)
200 rc = hypfs_vm_create_files(sb, sb->s_root);
201 else
202 rc = hypfs_diag_create_files(sb, sb->s_root);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700203 if (rc) {
Michael Holzheuf55495b2008-12-25 13:39:39 +0100204 pr_err("Updating the hypfs tree failed\n");
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700205 hypfs_delete_tree(sb->s_root);
206 goto out;
207 }
208 hypfs_update_update(sb);
209 rc = count;
210out:
211 mutex_unlock(&fs_info->lock);
212 return rc;
213}
214
215static int hypfs_release(struct inode *inode, struct file *filp)
216{
217 kfree(filp->private_data);
218 return 0;
219}
220
221enum { opt_uid, opt_gid, opt_err };
222
Steven Whitehousea447c092008-10-13 10:46:57 +0100223static const match_table_t hypfs_tokens = {
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700224 {opt_uid, "uid=%u"},
225 {opt_gid, "gid=%u"},
226 {opt_err, NULL}
227};
228
229static int hypfs_parse_options(char *options, struct super_block *sb)
230{
231 char *str;
232 substring_t args[MAX_OPT_ARGS];
233
234 if (!options)
235 return 0;
236 while ((str = strsep(&options, ",")) != NULL) {
237 int token, option;
238 struct hypfs_sb_info *hypfs_info = sb->s_fs_info;
239
240 if (!*str)
241 continue;
242 token = match_token(str, hypfs_tokens, args);
243 switch (token) {
244 case opt_uid:
245 if (match_int(&args[0], &option))
246 return -EINVAL;
247 hypfs_info->uid = option;
248 break;
249 case opt_gid:
250 if (match_int(&args[0], &option))
251 return -EINVAL;
252 hypfs_info->gid = option;
253 break;
254 case opt_err:
255 default:
Michael Holzheuf55495b2008-12-25 13:39:39 +0100256 pr_err("%s is not a valid mount option\n", str);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700257 return -EINVAL;
258 }
259 }
260 return 0;
261}
262
Al Viro34c80b12011-12-08 21:32:45 -0500263static int hypfs_show_options(struct seq_file *s, struct dentry *root)
Michael Holzheub01af5b2007-08-10 14:32:27 +0200264{
Al Viro34c80b12011-12-08 21:32:45 -0500265 struct hypfs_sb_info *hypfs_info = root->d_sb->s_fs_info;
Michael Holzheub01af5b2007-08-10 14:32:27 +0200266
267 seq_printf(s, ",uid=%u", hypfs_info->uid);
268 seq_printf(s, ",gid=%u", hypfs_info->gid);
269 return 0;
270}
271
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700272static int hypfs_fill_super(struct super_block *sb, void *data, int silent)
273{
274 struct inode *root_inode;
275 struct dentry *root_dentry;
276 int rc = 0;
277 struct hypfs_sb_info *sbi;
278
279 sbi = kzalloc(sizeof(struct hypfs_sb_info), GFP_KERNEL);
280 if (!sbi)
281 return -ENOMEM;
282 mutex_init(&sbi->lock);
David Howellse5423702008-11-14 10:38:39 +1100283 sbi->uid = current_uid();
284 sbi->gid = current_gid();
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700285 sb->s_fs_info = sbi;
286 sb->s_blocksize = PAGE_CACHE_SIZE;
287 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
288 sb->s_magic = HYPFS_MAGIC;
289 sb->s_op = &hypfs_s_ops;
Al Virof1771ff2010-01-25 18:36:07 -0500290 if (hypfs_parse_options(data, sb))
291 return -EINVAL;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700292 root_inode = hypfs_make_inode(sb, S_IFDIR | 0755);
Al Virof1771ff2010-01-25 18:36:07 -0500293 if (!root_inode)
294 return -ENOMEM;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700295 root_inode->i_op = &simple_dir_inode_operations;
296 root_inode->i_fop = &simple_dir_operations;
Al Viro48fde702012-01-08 22:15:13 -0500297 sb->s_root = root_dentry = d_make_root(root_inode);
298 if (!root_dentry)
Al Virof1771ff2010-01-25 18:36:07 -0500299 return -ENOMEM;
Michael Holzheu31cb4bd2007-02-05 21:18:29 +0100300 if (MACHINE_IS_VM)
301 rc = hypfs_vm_create_files(sb, root_dentry);
302 else
303 rc = hypfs_diag_create_files(sb, root_dentry);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700304 if (rc)
Al Virof1771ff2010-01-25 18:36:07 -0500305 return rc;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700306 sbi->update_file = hypfs_create_update_file(sb, root_dentry);
Al Virof1771ff2010-01-25 18:36:07 -0500307 if (IS_ERR(sbi->update_file))
308 return PTR_ERR(sbi->update_file);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700309 hypfs_update_update(sb);
Michael Holzheuf55495b2008-12-25 13:39:39 +0100310 pr_info("Hypervisor filesystem mounted\n");
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700311 return 0;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700312}
313
Al Virofc14f2f2010-07-25 01:48:30 +0400314static struct dentry *hypfs_mount(struct file_system_type *fst, int flags,
315 const char *devname, void *data)
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700316{
Al Virofc14f2f2010-07-25 01:48:30 +0400317 return mount_single(fst, flags, data, hypfs_fill_super);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700318}
319
320static void hypfs_kill_super(struct super_block *sb)
321{
322 struct hypfs_sb_info *sb_info = sb->s_fs_info;
323
Al Virof1771ff2010-01-25 18:36:07 -0500324 if (sb->s_root)
Michael Holzheu388c5712006-09-20 16:00:04 +0200325 hypfs_delete_tree(sb->s_root);
Al Virof1771ff2010-01-25 18:36:07 -0500326 if (sb_info->update_file)
Michael Holzheu388c5712006-09-20 16:00:04 +0200327 hypfs_remove(sb_info->update_file);
Al Virof1771ff2010-01-25 18:36:07 -0500328 kfree(sb->s_fs_info);
329 sb->s_fs_info = NULL;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700330 kill_litter_super(sb);
331}
332
333static struct dentry *hypfs_create_file(struct super_block *sb,
334 struct dentry *parent, const char *name,
Al Virofec0eba2011-07-24 23:30:19 -0400335 char *data, umode_t mode)
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700336{
337 struct dentry *dentry;
338 struct inode *inode;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700339
Michael Holzheu9b5a03e2007-08-22 13:51:43 +0200340 mutex_lock(&parent->d_inode->i_mutex);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700341 dentry = lookup_one_len(name, parent, strlen(name));
Michael Holzheu9b5a03e2007-08-22 13:51:43 +0200342 if (IS_ERR(dentry)) {
343 dentry = ERR_PTR(-ENOMEM);
344 goto fail;
345 }
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700346 inode = hypfs_make_inode(sb, mode);
347 if (!inode) {
348 dput(dentry);
Michael Holzheu9b5a03e2007-08-22 13:51:43 +0200349 dentry = ERR_PTR(-ENOMEM);
350 goto fail;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700351 }
Al Virofec0eba2011-07-24 23:30:19 -0400352 if (S_ISREG(mode)) {
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700353 inode->i_fop = &hypfs_file_ops;
354 if (data)
355 inode->i_size = strlen(data);
356 else
357 inode->i_size = 0;
Al Virofec0eba2011-07-24 23:30:19 -0400358 } else if (S_ISDIR(mode)) {
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700359 inode->i_op = &simple_dir_inode_operations;
360 inode->i_fop = &simple_dir_operations;
Miklos Szeredi6d6b77f2011-10-28 14:13:28 +0200361 inc_nlink(parent->d_inode);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700362 } else
363 BUG();
Theodore Ts'o8e18e292006-09-27 01:50:46 -0700364 inode->i_private = data;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700365 d_instantiate(dentry, inode);
366 dget(dentry);
Michael Holzheu9b5a03e2007-08-22 13:51:43 +0200367fail:
368 mutex_unlock(&parent->d_inode->i_mutex);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700369 return dentry;
370}
371
372struct dentry *hypfs_mkdir(struct super_block *sb, struct dentry *parent,
373 const char *name)
374{
375 struct dentry *dentry;
376
377 dentry = hypfs_create_file(sb, parent, name, NULL, S_IFDIR | DIR_MODE);
378 if (IS_ERR(dentry))
379 return dentry;
380 hypfs_add_dentry(dentry);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700381 return dentry;
382}
383
384static struct dentry *hypfs_create_update_file(struct super_block *sb,
385 struct dentry *dir)
386{
387 struct dentry *dentry;
388
389 dentry = hypfs_create_file(sb, dir, "update", NULL,
390 S_IFREG | UPDATE_FILE_MODE);
391 /*
392 * We do not put the update file on the 'delete' list with
393 * hypfs_add_dentry(), since it should not be removed when the tree
394 * is updated.
395 */
396 return dentry;
397}
398
399struct dentry *hypfs_create_u64(struct super_block *sb, struct dentry *dir,
400 const char *name, __u64 value)
401{
402 char *buffer;
403 char tmp[TMP_SIZE];
404 struct dentry *dentry;
405
Michael Holzheuad2a5d82009-09-11 10:28:54 +0200406 snprintf(tmp, TMP_SIZE, "%llu\n", (unsigned long long int)value);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700407 buffer = kstrdup(tmp, GFP_KERNEL);
408 if (!buffer)
409 return ERR_PTR(-ENOMEM);
410 dentry =
411 hypfs_create_file(sb, dir, name, buffer, S_IFREG | REG_FILE_MODE);
412 if (IS_ERR(dentry)) {
413 kfree(buffer);
414 return ERR_PTR(-ENOMEM);
415 }
416 hypfs_add_dentry(dentry);
417 return dentry;
418}
419
420struct dentry *hypfs_create_str(struct super_block *sb, struct dentry *dir,
421 const char *name, char *string)
422{
423 char *buffer;
424 struct dentry *dentry;
425
426 buffer = kmalloc(strlen(string) + 2, GFP_KERNEL);
427 if (!buffer)
428 return ERR_PTR(-ENOMEM);
429 sprintf(buffer, "%s\n", string);
430 dentry =
431 hypfs_create_file(sb, dir, name, buffer, S_IFREG | REG_FILE_MODE);
432 if (IS_ERR(dentry)) {
433 kfree(buffer);
434 return ERR_PTR(-ENOMEM);
435 }
436 hypfs_add_dentry(dentry);
437 return dentry;
438}
439
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800440static const struct file_operations hypfs_file_ops = {
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700441 .open = hypfs_open,
442 .release = hypfs_release,
443 .read = do_sync_read,
444 .write = do_sync_write,
445 .aio_read = hypfs_aio_read,
446 .aio_write = hypfs_aio_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200447 .llseek = no_llseek,
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700448};
449
450static struct file_system_type hypfs_type = {
451 .owner = THIS_MODULE,
452 .name = "s390_hypfs",
Al Virofc14f2f2010-07-25 01:48:30 +0400453 .mount = hypfs_mount,
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700454 .kill_sb = hypfs_kill_super
455};
456
Alexey Dobriyanb87221d2009-09-21 17:01:09 -0700457static const struct super_operations hypfs_s_ops = {
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700458 .statfs = simple_statfs,
Al Virob69257f2010-06-04 21:02:59 -0400459 .evict_inode = hypfs_evict_inode,
Michael Holzheub01af5b2007-08-10 14:32:27 +0200460 .show_options = hypfs_show_options,
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700461};
462
Greg Kroah-Hartman9b477702007-11-01 09:29:06 -0600463static struct kobject *s390_kobj;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700464
465static int __init hypfs_init(void)
466{
467 int rc;
468
Michael Holzheu2fcb3682011-01-05 12:47:43 +0100469 rc = hypfs_dbfs_init();
470 if (rc)
471 return rc;
Michael Holzheu57b28f62010-05-17 10:00:20 +0200472 if (hypfs_diag_init()) {
473 rc = -ENODATA;
Michael Holzheu2fcb3682011-01-05 12:47:43 +0100474 goto fail_dbfs_exit;
Michael Holzheu57b28f62010-05-17 10:00:20 +0200475 }
476 if (hypfs_vm_init()) {
477 rc = -ENODATA;
478 goto fail_hypfs_diag_exit;
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700479 }
Greg Kroah-Hartman9b477702007-11-01 09:29:06 -0600480 s390_kobj = kobject_create_and_add("s390", hypervisor_kobj);
481 if (!s390_kobj) {
Joe Perchesa419aef2009-08-18 11:18:35 -0700482 rc = -ENOMEM;
Michael Holzheu57b28f62010-05-17 10:00:20 +0200483 goto fail_hypfs_vm_exit;
Greg Kroah-Hartman9b477702007-11-01 09:29:06 -0600484 }
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700485 rc = register_filesystem(&hypfs_type);
486 if (rc)
487 goto fail_filesystem;
488 return 0;
489
490fail_filesystem:
Greg Kroah-Hartman38a382a2007-12-20 08:13:05 -0800491 kobject_put(s390_kobj);
Michael Holzheu57b28f62010-05-17 10:00:20 +0200492fail_hypfs_vm_exit:
493 hypfs_vm_exit();
494fail_hypfs_diag_exit:
495 hypfs_diag_exit();
Michael Holzheu2fcb3682011-01-05 12:47:43 +0100496fail_dbfs_exit:
497 hypfs_dbfs_exit();
Michael Holzheuf55495b2008-12-25 13:39:39 +0100498 pr_err("Initialization of hypfs failed with rc=%i\n", rc);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700499 return rc;
500}
501
502static void __exit hypfs_exit(void)
503{
Michael Holzheu57b28f62010-05-17 10:00:20 +0200504 hypfs_diag_exit();
505 hypfs_vm_exit();
Michael Holzheu2fcb3682011-01-05 12:47:43 +0100506 hypfs_dbfs_exit();
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700507 unregister_filesystem(&hypfs_type);
Greg Kroah-Hartman38a382a2007-12-20 08:13:05 -0800508 kobject_put(s390_kobj);
Michael Holzheu24bbb1f2006-06-23 02:05:06 -0700509}
510
511module_init(hypfs_init)
512module_exit(hypfs_exit)
513
514MODULE_LICENSE("GPL");
515MODULE_AUTHOR("Michael Holzheu <holzheu@de.ibm.com>");
516MODULE_DESCRIPTION("s390 Hypervisor Filesystem");