Whamcloud - gitweb
Change the cleanup scripts to use the debug_kernel instead of get_debug.
[fs/lustre-release.git] / lustre / lib / simple.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lib/simple.c
5  *
6  * Copyright (C) 2002  Cluster File Systems, Inc.
7  *
8  * This code is issued under the GNU General Public License.
9  * See the file COPYING in this distribution
10  *
11  * by Peter Braam <braam@clusterfs.com>
12  * and Andreas Dilger <adilger@clusterfs.com>
13  */
14
15 #define EXPORT_SYMTAB
16
17 #include <linux/version.h>
18 #include <linux/fs.h>
19 #include <asm/unistd.h>
20
21 #define DEBUG_SUBSYSTEM S_FILTER
22
23 #include <linux/lustre_mds.h>
24 #include <linux/lustre_lib.h>
25 #include <linux/lustre_net.h>
26
27
28 /* push / pop to root of obd store */
29 void push_ctxt(struct obd_run_ctxt *save, struct obd_run_ctxt *new)
30 {
31         save->fs = get_fs();
32         save->pwd = dget(current->fs->pwd);
33         save->pwdmnt = mntget(current->fs->pwdmnt);
34
35         set_fs(new->fs);
36         set_fs_pwd(current->fs, new->pwdmnt, new->pwd);
37 }
38
39 void pop_ctxt(struct obd_run_ctxt *saved)
40 {
41         set_fs(saved->fs);
42         set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd);
43
44         dput(saved->pwd);
45         mntput(saved->pwdmnt);
46 }
47
48 /* utility to make a directory */
49 struct dentry *simple_mkdir(struct dentry *dir, char *name, int mode)
50 {
51         struct dentry *dchild;
52         int err;
53         ENTRY;
54
55         CDEBUG(D_INODE, "creating directory %*s\n", strlen(name), name);
56         dchild = lookup_one_len(name, dir, strlen(name));
57         if (IS_ERR(dchild))
58                 RETURN(dchild);
59
60         if (dchild->d_inode) {
61                 if (!S_ISDIR(dchild->d_inode->i_mode))
62                         GOTO(out, err = -ENOTDIR);
63
64                 RETURN(dchild);
65         }
66
67         err = vfs_mkdir(dir->d_inode, dchild, mode);
68         EXIT;
69 out:
70         if (err) {
71                 dput(dchild);
72                 RETURN(ERR_PTR(err));
73         }
74
75         RETURN(dchild);
76 }
77
78 int lustre_fread(struct file *file, char *str, int len, loff_t *off)
79 {
80         if (!file || !file->f_op || !file->f_op->read || !off)
81                 RETURN(-ENOSYS);
82
83         return file->f_op->read(file, str, len, off);
84 }
85
86 int lustre_fwrite(struct file *file, const char *str, int len, loff_t *off)
87 {
88         if (!file || !file->f_op || !off)
89                 RETURN(-ENOSYS);
90
91         if (!file->f_op->write)
92                 RETURN(-EROFS);
93
94         return file->f_op->write(file, str, len, off);
95 }
96
97 int lustre_fsync(struct file *file)
98 {
99         if (!file || !file->f_op || !file->f_op->fsync)
100                 RETURN(-ENOSYS);
101
102         return file->f_op->fsync(file, file->f_dentry, 0);
103 }