Whamcloud - gitweb
Branch b1_8
[fs/lustre-release.git] / lustre / include / lustre_mds.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *   This file is part of Lustre, http://www.lustre.org
5  *
6  * MDS data structures.
7  * See also lustre_idl.h for wire formats of requests.
8  */
9
10 #ifndef _LUSTRE_MDS_H
11 #define _LUSTRE_MDS_H
12
13 #include <lustre_handles.h>
14 #include <libcfs/kp30.h>
15 #include <lustre/lustre_idl.h>
16 #include <lustre_lib.h>
17 #include <lustre_dlm.h>
18 #include <lustre_log.h>
19 #include <lustre_export.h>
20
21 #if defined(__linux__)
22 #include <linux/lustre_mds.h>
23 #elif defined(__APPLE__)
24 #include <darwin/lustre_mds.h>
25 #elif defined(__WINNT__)
26 #include <winnt/lustre_mds.h>
27 #else
28 #error Unsupported operating system.
29 #endif
30
31 struct ldlm_lock_desc;
32 struct mds_obd;
33 struct ptlrpc_connection;
34 struct ptlrpc_client;
35 struct obd_export;
36 struct ptlrpc_request;
37 struct obd_device;
38 struct ll_file_data;
39
40 struct lustre_md {
41         struct mds_body         *body;
42         struct lov_stripe_md    *lsm;
43 #ifdef CONFIG_FS_POSIX_ACL
44         struct posix_acl        *posix_acl;
45 #endif
46 };
47
48 struct mdc_op_data {
49         struct ll_fid    fid1;
50         struct ll_fid    fid2;
51         struct ll_fid    fid3;
52         struct ll_fid    fid4;
53         __u64            mod_time;
54         const char      *name;
55         int              namelen;
56         __u32            create_mode;
57         __u32            suppgids[2];
58         void            *data;
59 };
60
61 struct mds_update_record {
62         __u32 ur_opcode;
63         struct ll_fid *ur_fid1;
64         struct ll_fid *ur_fid2;
65         int ur_namelen;
66         char *ur_name;
67         int ur_tgtlen;
68         char *ur_tgt;
69         int ur_eadatalen;
70         void *ur_eadata;
71         int ur_cookielen;
72         struct llog_cookie *ur_logcookies;
73         struct iattr ur_iattr;
74         struct lvfs_ucred ur_uc;
75         __u64 ur_rdev;
76         __u64 ur_time;
77         __u32 ur_mode;
78         __u32 ur_flags;
79         struct lvfs_grp_hash_entry *ur_grp_entry;
80         struct ldlm_request *ur_dlm;
81 };
82
83 /* file data for open files on MDS */
84 struct mds_file_data {
85         struct portals_handle mfd_handle; /* must be first */
86         atomic_t              mfd_refcount;
87         struct list_head      mfd_list; /* protected by med_open_lock */
88         __u64                 mfd_xid;
89         int                   mfd_mode;
90         struct dentry        *mfd_dentry;
91 };
92
93 /* ACL */
94 #ifdef CONFIG_FS_POSIX_ACL
95 # ifdef HAVE_XATTR_ACL
96 #  define MDS_XATTR_NAME_ACL_ACCESS XATTR_NAME_ACL_ACCESS
97 #  define mds_xattr_acl_size(entry) xattr_acl_size(entry)
98 # else /* HAVE_XATTR_ACL */
99 #  define MDS_XATTR_NAME_ACL_ACCESS POSIX_ACL_XATTR_ACCESS
100 #  define mds_xattr_acl_size(entry) posix_acl_xattr_size(entry)
101 # endif /* HAVE_XATTR_ACL */
102
103 # define LUSTRE_POSIX_ACL_MAX_ENTRIES   (32)
104 #  define LUSTRE_POSIX_ACL_MAX_SIZE      \
105                 (mds_xattr_acl_size(LUSTRE_POSIX_ACL_MAX_ENTRIES))
106 #else /* CONFIG_FS_POSIX_ACL */
107 # define LUSTRE_POSIX_ACL_MAX_SIZE      0
108 #endif /* CONFIG_FS_POSIX_ACL */
109
110 /* mds/mds_reint.c */
111 int mds_reint_rec(struct mds_update_record *r, int offset,
112                   struct ptlrpc_request *req, struct lustre_handle *);
113
114 /* mds/mds_lov.c */
115
116 /* mdc/mdc_locks.c */
117 struct md_enqueue_info;
118
119 int it_disposition(struct lookup_intent *it, int flag);
120 void it_set_disposition(struct lookup_intent *it, int flag);
121 void it_clear_disposition(struct lookup_intent *it, int flag);
122 int it_open_error(int phase, struct lookup_intent *it);
123 void mdc_set_lock_data(__u64 *lockh, void *data);
124 int mdc_change_cbdata(struct obd_export *exp, struct ll_fid *fid,
125                       ldlm_iterator_t it, void *data);
126 int mdc_revalidate_lock(struct obd_export *exp,
127                         struct lookup_intent *it,
128                         struct ll_fid *fid);
129 int mdc_intent_lock(struct obd_export *exp,
130                     struct mdc_op_data *,
131                     void *lmm, int lmmsize,
132                     struct lookup_intent *, int,
133                     struct ptlrpc_request **reqp,
134                     ldlm_blocking_callback cb_blocking, int extra_lock_flags);
135 int mdc_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
136                 struct lookup_intent *it, struct mdc_op_data *data,
137                 struct lustre_handle *lockh, void *lmm, int lmmlen,
138                 int extra_lock_flags);
139 int mdc_intent_getattr_async(struct obd_export *exp,
140                              struct md_enqueue_info *minfo,
141                              struct ldlm_enqueue_info *einfo);
142
143 /* mdc/mdc_request.c */
144 int mdc_init_ea_size(struct obd_export *mdc_exp, struct obd_export *lov_exp);
145 int mdc_req2lustre_md(struct ptlrpc_request *req, int offset,
146                       struct obd_export *exp, struct lustre_md *md);
147 void mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md);
148 int mdc_getstatus(struct obd_export *exp, struct ll_fid *rootfid);
149 int mdc_getattr(struct obd_export *exp, struct ll_fid *fid,
150                 obd_valid valid, unsigned int ea_size,
151                 struct ptlrpc_request **request);
152 int mdc_getattr_name(struct obd_export *exp, struct ll_fid *fid,
153                      const char *filename, int namelen, unsigned long valid,
154                      unsigned int ea_size, struct ptlrpc_request **request);
155 int mdc_setattr(struct obd_export *exp, struct mdc_op_data *data,
156                 struct iattr *iattr, void *ea, int ealen, void *ea2, int ea2len,
157                 struct ptlrpc_request **request);
158 int mdc_setxattr(struct obd_export *exp, struct ll_fid *fid,
159                  obd_valid valid, const char *xattr_name,
160                  const char *input, int input_size,
161                  int output_size, int flags,
162                  struct ptlrpc_request **request);
163 int mdc_getxattr(struct obd_export *exp, struct ll_fid *fid,
164                  obd_valid valid, const char *xattr_name,
165                  const char *input, int input_size,
166                  int output_size, struct ptlrpc_request **request);
167 int mdc_open(struct obd_export *exp, obd_id ino, int type, int flags,
168              struct lov_mds_md *lmm, int lmm_size, struct lustre_handle *fh,
169              struct ptlrpc_request **);
170 struct obd_client_handle;
171 void mdc_set_open_replay_data(struct obd_client_handle *och,
172                               struct ptlrpc_request *open_req);
173 void mdc_clear_open_replay_data(struct obd_client_handle *och);
174 int mdc_close(struct obd_export *, struct obdo *, struct obd_client_handle *,
175               struct ptlrpc_request **);
176 int mdc_readpage(struct obd_export *exp, struct ll_fid *mdc_fid, __u64 offset,
177                  struct page *, struct ptlrpc_request **);
178 int mdc_create(struct obd_export *exp, struct mdc_op_data *op_data,
179                const void *data, int datalen, int mode, __u32 uid, __u32 gid,
180                __u32 cap_effective, __u64 rdev,struct ptlrpc_request **request);
181 int mdc_unlink(struct obd_export *exp, struct mdc_op_data *data,
182                struct ptlrpc_request **request);
183 int mdc_link(struct obd_export *exp, struct mdc_op_data *data,
184              struct ptlrpc_request **);
185 int mdc_rename(struct obd_export *exp, struct mdc_op_data *data,
186                const char *old, int oldlen, const char *new, int newlen,
187                struct ptlrpc_request **request);
188 int mdc_sync(struct obd_export *exp, struct ll_fid *fid,
189              struct ptlrpc_request **);
190 int mdc_create_client(struct obd_uuid uuid, struct ptlrpc_client *cl);
191 int mdc_resource_get_unused(struct obd_export *exp, struct ll_fid *fid,
192                             struct list_head *cancels, ldlm_mode_t mode,
193                             __u64 bits);
194
195 /* Store the generation of a newly-created inode in |req| for replay. */
196 void mdc_store_inode_generation(struct ptlrpc_request *req, int reqoff,
197                                 int repoff);
198 int mdc_llog_process(struct obd_export *, char *logname, llog_cb_t, void *data);
199 int mdc_done_writing(struct obd_export *exp, struct obdo *);
200
201 static inline void mdc_pack_fid(struct ll_fid *fid, obd_id ino, __u32 gen,
202                                 int type)
203 {
204         fid->id = ino;
205         fid->generation = gen;
206         fid->f_type = type;
207 }
208
209 static inline int it_to_lock_mode(struct lookup_intent *it)
210 {
211         /* CREAT needs to be tested before open (both could be set) */
212         if (it->it_op & IT_CREAT)
213                 return LCK_CW;
214         else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP))
215                 return LCK_CR;
216
217         LBUG();
218         return -EINVAL;
219 }
220
221 /* ioctls for trying requests */
222 #define IOC_REQUEST_TYPE                   'f'
223 #define IOC_REQUEST_MIN_NR                 30
224
225 #define IOC_REQUEST_GETATTR             _IOWR('f', 30, long)
226 #define IOC_REQUEST_READPAGE            _IOWR('f', 31, long)
227 #define IOC_REQUEST_SETATTR             _IOWR('f', 32, long)
228 #define IOC_REQUEST_CREATE              _IOWR('f', 33, long)
229 #define IOC_REQUEST_OPEN                _IOWR('f', 34, long)
230 #define IOC_REQUEST_CLOSE               _IOWR('f', 35, long)
231 #define IOC_REQUEST_MAX_NR               35
232
233 /* metadata stat-ahead */
234 typedef int (* md_enqueue_cb_t)(struct obd_export *exp,
235                                 struct ptlrpc_request *req,
236                                 struct md_enqueue_info *minfo,
237                                 int rc);
238
239 struct md_enqueue_info {
240         struct obd_export      *mi_exp;
241         struct mdc_op_data      mi_data;
242         struct lookup_intent    mi_it;
243         struct lustre_handle    mi_lockh;
244         struct dentry          *mi_dentry;
245         md_enqueue_cb_t         mi_cb;
246         unsigned int            mi_generation;
247         void                   *mi_cbdata;
248 };
249
250 struct mdc_enqueue_args {
251         struct md_enqueue_info   *ma_mi;
252         struct ldlm_enqueue_info *ma_ei;
253 };
254
255 #endif