Whamcloud - gitweb
Add mount_count file to hold the current MDS generation number. Note that
[fs/lustre-release.git] / lustre / lib / simple.c
1 /*
2  *  lib/simple.c
3  *
4  * Copyright (C) 2002  Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  *
9  * by Peter Braam <braam@clusterfs.com>
10  * and Andreas Dilger <adilger@clusterfs.com>
11  */
12
13 #define EXPORT_SYMTAB
14
15 #include <linux/version.h>
16 #include <linux/fs.h>
17 #include <asm/unistd.h>
18
19 #define DEBUG_SUBSYSTEM S_FILTER
20
21 #include <linux/lustre_mds.h>
22 #include <linux/lustre_lib.h>
23 #include <linux/lustre_net.h>
24
25
26 /* push / pop to root of obd store */
27 void push_ctxt(struct obd_run_ctxt *save, struct obd_run_ctxt *new)
28
29         save->fs = get_fs();
30         save->pwd = dget(current->fs->pwd);
31         save->pwdmnt = mntget(current->fs->pwdmnt);
32
33         set_fs(new->fs);
34         set_fs_pwd(current->fs, new->pwdmnt, new->pwd);
35 }
36
37 void pop_ctxt(struct obd_run_ctxt *saved)
38 {
39         set_fs(saved->fs);
40         set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd);
41
42         dput(saved->pwd);
43         mntput(saved->pwdmnt);
44 }
45
46 /* utility to make a directory */
47 int simple_mkdir(struct dentry *dir, char *name, int mode)
48 {
49         struct dentry *dchild;
50         int err;
51         ENTRY;
52
53         dchild = lookup_one_len(name, dir, strlen(name));
54         if (IS_ERR(dchild))
55                 RETURN(PTR_ERR(dchild));
56
57         if (dchild->d_inode)
58                 GOTO(out, err = -EEXIST);
59
60         err = vfs_mkdir(dir->d_inode, dchild, mode);
61 out:
62         l_dput(dchild);
63
64         RETURN(err);
65 }
66
67 int lustre_fread(struct file *file, char *str, int len, loff_t *off)
68 {
69         if (!file || !file->f_op || !file->f_op->read || !off)
70                 RETURN(-EINVAL);
71
72         return file->f_op->read(file, str, len, off);
73 }
74
75 int lustre_fwrite(struct file *file, const char *str, int len, loff_t *off)
76 {
77         if (!file || !file->f_op || !file->f_op->write || !off)
78                 RETURN(-EINVAL);
79
80         if (!file->f_op->write)
81                 RETURN(-EROFS);
82
83         return file->f_op->write(file, str, len, off);
84 }