Whamcloud - gitweb
land b_md onto HEAD. the highlights:
[fs/lustre-release.git] / lustre / include / linux / lustre_fsfilt.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001 Cluster File Systems, Inc. <info@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Filesystem interface helper.
22  *
23  */
24
25 #ifndef _LUSTRE_FSFILT_H
26 #define _LUSTRE_FSFILT_H
27
28 #ifdef __KERNEL__
29
30 #include <linux/obd.h>
31 #include <linux/fs.h>
32
33 typedef void (*fsfilt_cb_t)(struct obd_device *obd, __u64 last_rcvd, int error);
34
35 struct fsfilt_objinfo {
36         struct dentry *fso_dentry;
37         int fso_bufcnt;
38 };
39
40 struct fsfilt_operations {
41         struct list_head fs_list;
42         struct module *fs_owner;
43         char   *fs_type;
44         void   *(* fs_start)(struct inode *inode, int op);
45         void   *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
46                                  int niocount, struct niobuf_remote *nb);
47         int     (* fs_commit)(struct inode *inode, void *handle);
48         int     (* fs_setattr)(struct dentry *dentry, void *handle,
49                                struct iattr *iattr);
50         int     (* fs_set_md)(struct inode *inode, void *handle, void *md,
51                               int size);
52         int     (* fs_get_md)(struct inode *inode, void *md, int size);
53         ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
54                                 loff_t *offset);
55         int     (* fs_journal_data)(struct file *file);
56         int     (* fs_set_last_rcvd)(struct obd_device *obd, __u64 last_rcvd,
57                                      void *handle, fsfilt_cb_t cb_func);
58         int     (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
59 };
60
61 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
62 extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
63 extern struct fsfilt_operations *fsfilt_get_ops(char *type);
64 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
65
66 #define FSFILT_OP_UNLINK         1
67 #define FSFILT_OP_RMDIR          2
68 #define FSFILT_OP_RENAME         3
69 #define FSFILT_OP_CREATE         4
70 #define FSFILT_OP_MKDIR          5
71 #define FSFILT_OP_SYMLINK        6
72 #define FSFILT_OP_MKNOD          7
73 #define FSFILT_OP_SETATTR        8
74 #define FSFILT_OP_LINK           9
75
76 static inline void *fsfilt_start(struct obd_device *obd,
77                                  struct inode *inode, int op)
78 {
79         return obd->obd_fsops->fs_start(inode, op);
80 }
81
82 static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
83                                      struct fsfilt_objinfo *fso, int niocount,
84                                      struct niobuf_remote *nb)
85 {
86         return obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb);
87 }
88
89 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
90                                 void *handle)
91 {
92         return obd->obd_fsops->fs_commit(inode, handle);
93 }
94
95 static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
96                                  void *handle, struct iattr *iattr)
97 {
98         int rc;
99         /*
100          * NOTE: we probably don't need to take i_sem here when changing
101          *       ATTR_SIZE because the MDS never needs to truncate a file.
102          *       The ext2/ext3 code never truncates a directory, and files
103          *       stored on the MDS are entirely sparse (no data blocks).
104          *       If we do need to get it, we can do it here.
105          */
106         lock_kernel();
107         rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr);
108         unlock_kernel();
109
110         return rc;
111 }
112
113 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
114                                 void *handle, void *md, int size)
115 {
116         return obd->obd_fsops->fs_set_md(inode, handle, md, size);
117 }
118
119 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
120                                 void *md, int size)
121 {
122         return obd->obd_fsops->fs_get_md(inode, md, size);
123 }
124
125 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
126                                       struct file *file, char *buf,
127                                       size_t count, loff_t *offset)
128 {
129         return obd->obd_fsops->fs_readpage(file, buf, count, offset);
130 }
131
132 static inline int fsfilt_journal_data(struct obd_device *obd, struct file *file)
133 {
134         return obd->obd_fsops->fs_journal_data(file);
135 }
136
137 static inline int fsfilt_set_last_rcvd(struct obd_device *obd, __u64 last_rcvd,
138                                        void *handle, fsfilt_cb_t cb_func)
139 {
140         return obd->obd_fsops->fs_set_last_rcvd(obd, last_rcvd,handle,cb_func);
141 }
142
143 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *fs,
144                                 struct obd_statfs *osfs)
145 {
146         return obd->obd_fsops->fs_statfs(fs, osfs);
147 }
148
149 #endif /* __KERNEL__ */
150
151 #endif