Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / include / lclient.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * Definitions shared between vvp and liblustre, and other clients in the
37  * future.
38  *
39  *   Author: Oleg Drokin <oleg.drokin@sun.com>
40  *   Author: Nikita Danilov <nikita.danilov@sun.com>
41  */
42
43 #ifndef LCLIENT_H
44 #define LCLIENT_H
45
46 int cl_glimpse_size(struct inode *inode);
47 int cl_glimpse_lock(const struct lu_env *env, struct cl_io *io,
48                     struct inode *inode, struct cl_object *clob);
49
50 /**
51  * Common IO arguments for various VFS I/O interfaces.
52  */
53 struct ccc_io_args {
54         int           cia_is_sendfile;
55 #ifndef HAVE_FILE_WRITEV
56         struct kiocb *cia_iocb;
57 #endif
58         struct iovec *cia_iov;
59         unsigned long cia_nrsegs;
60         read_actor_t  cia_actor;
61         void         *cia_target;
62 };
63
64 /**
65  * Locking policy for truncate.
66  */
67 enum ccc_trunc_lock_type {
68         /** Locking is done by server */
69         TRUNC_NOLOCK,
70         /** Extent lock is enqueued */
71         TRUNC_EXTENT,
72         /** Existing local extent lock is used */
73         TRUNC_MATCH
74 };
75
76 /**
77  * IO state private to vvp or slp layers.
78  */
79 struct ccc_io {
80         /** super class */
81         struct cl_io_slice     cui_cl;
82         struct cl_io_lock_link cui_link;
83         /**
84          * I/O vector information to or from which read/write is going.
85          */
86         struct iovec *cui_iov;
87         unsigned long cui_nrsegs;
88         /**
89          * Total iov count for left IO.
90          */
91         unsigned long cui_tot_nrsegs;
92         /**
93          * Old length for iov that was truncated partially.
94          */
95         size_t cui_iov_olen;
96         /**
97          * Total size for the left IO.
98          */
99         size_t cui_tot_count;
100
101         union {
102                 struct {
103                         int                      cui_locks_released;
104                         enum ccc_trunc_lock_type cui_local_lock;
105                 } trunc;
106         } u;
107         /**
108          * True iff io is processing glimpse right now.
109          */
110         int                  cui_glimpse;
111         /**
112          * File descriptor against which IO is done.
113          */
114         struct ll_file_data *cui_fd;
115 #ifndef HAVE_FILE_WRITEV
116         struct kiocb *cui_iocb;
117 #endif
118 };
119
120 extern struct lu_context_key ccc_key;
121 extern struct lu_context_key ccc_session_key;
122
123 struct ccc_thread_info {
124         struct cl_lock_descr cti_descr;
125         struct cl_io         cti_io;
126         struct cl_sync_io    cti_sync_io;
127         struct cl_attr       cti_attr;
128 };
129
130 static inline struct ccc_thread_info *ccc_env_info(const struct lu_env *env)
131 {
132         struct ccc_thread_info      *info;
133
134         info = lu_context_key_get(&env->le_ctx, &ccc_key);
135         LASSERT(info != NULL);
136         return info;
137 }
138
139 static inline struct cl_attr *ccc_env_thread_attr(const struct lu_env *env)
140 {
141         struct cl_attr *attr = &ccc_env_info(env)->cti_attr;
142         memset(attr, 0, sizeof(*attr));
143         return attr;
144 }
145
146 struct ccc_session {
147         struct ccc_io cs_ios;
148 };
149
150 static inline struct ccc_session *ccc_env_session(const struct lu_env *env)
151 {
152         struct ccc_session *ses;
153
154         ses = lu_context_key_get(env->le_ses, &ccc_session_key);
155         LASSERT(ses != NULL);
156         return ses;
157 }
158
159 static inline struct ccc_io *ccc_env_io(const struct lu_env *env)
160 {
161         return &ccc_env_session(env)->cs_ios;
162 }
163
164 /**
165  * ccc-private object state.
166  */
167 struct ccc_object {
168         struct cl_object_header cob_header;
169         struct cl_object        cob_cl;
170         struct inode           *cob_inode;
171
172         /**
173          * A list of dirty pages pending IO in the cache. Used by
174          * SOM. Protected by ll_inode_info::lli_lock.
175          *
176          * \see ccc_page::cpg_pending_linkage
177          */
178         struct list_head        cob_pending_list;
179
180         /**
181          * Access this counter is protected by inode->i_sem. Now that
182          * the lifetime of transient pages must be covered by inode sem,
183          * we don't need to hold any lock..
184          */
185         int                     cob_transient_pages;
186         /**
187          * Number of outstanding mmaps on this file.
188          *
189          * \see ll_vm_open(), ll_vm_close().
190          */
191         atomic_t                cob_mmap_cnt;
192 };
193
194 /**
195  * ccc-private page state.
196  */
197 struct ccc_page {
198         struct cl_page_slice cpg_cl;
199         int                  cpg_defer_uptodate;
200         int                  cpg_ra_used;
201         int                  cpg_write_queued;
202         /**
203          * Non-empty iff this page is already counted in
204          * ccc_object::cob_pending_list. Protected by
205          * ccc_object::cob_pending_guard. This list is only used as a flag,
206          * that is, never iterated through, only checked for list_empty(), but
207          * having a list is useful for debugging.
208          */
209         struct list_head     cpg_pending_linkage;
210         /** VM page */
211         cfs_page_t          *cpg_page;
212         struct cl_sync_io   *cpg_sync_io;
213         /**
214          * checksum for paranoid I/O debugging enabled by
215          * ENABLE_LLITE_CHECKSUM configuration option.
216          *
217          * XXX This cannot be implemented reliably because checksum cannot be
218          * updated from ->set_page_dirty() that is called without page VM
219          * lock.
220          */
221         __u32                cpg_checksum;
222 };
223
224 static inline struct ccc_page *cl2ccc_page(const struct cl_page_slice *slice)
225 {
226         return container_of(slice, struct ccc_page, cpg_cl);
227 }
228
229 struct cl_page    *ccc_vmpage_page_transient(cfs_page_t *vmpage);
230
231 struct ccc_device {
232         struct cl_device    cdv_cl;
233         struct super_block *cdv_sb;
234         struct cl_device   *cdv_next;
235 };
236
237 struct ccc_lock {
238         struct cl_lock_slice clk_cl;
239 };
240
241 struct ccc_req {
242         struct cl_req_slice  crq_cl;
243 };
244
245 void *ccc_key_init        (const struct lu_context *ctx,
246                            struct lu_context_key *key);
247 void  ccc_key_fini        (const struct lu_context *ctx,
248                            struct lu_context_key *key, void *data);
249 void *ccc_session_key_init(const struct lu_context *ctx,
250                            struct lu_context_key *key);
251 void  ccc_session_key_fini(const struct lu_context *ctx,
252                            struct lu_context_key *key, void *data);
253
254 int              ccc_device_init  (const struct lu_env *env,
255                                    struct lu_device *d,
256                                    const char *name, struct lu_device *next);
257 struct lu_device *ccc_device_fini (const struct lu_env *env,
258                                    struct lu_device *d);
259 struct lu_device *ccc_device_alloc(const struct lu_env *env,
260                                    struct lu_device_type *t,
261                                    struct lustre_cfg *cfg,
262                                    const struct lu_device_operations *luops,
263                                    const struct cl_device_operations *clops);
264 struct lu_device *ccc_device_free (const struct lu_env *env,
265                                    struct lu_device *d);
266 struct lu_object *ccc_object_alloc(const struct lu_env *env,
267                                    const struct lu_object_header *hdr,
268                                    struct lu_device *dev,
269                                    const struct cl_object_operations *clops,
270                                    const struct lu_object_operations *luops);
271
272 int ccc_req_init(const struct lu_env *env, struct cl_device *dev,
273                  struct cl_req *req);
274 void ccc_umount(const struct lu_env *env, struct cl_device *dev);
275 int ccc_global_init(struct lu_device_type *device_type);
276 void ccc_global_fini(struct lu_device_type *device_type);
277 int ccc_object_init0(const struct lu_env *env,struct ccc_object *vob,
278                      const struct cl_object_conf *conf);
279 int ccc_object_init(const struct lu_env *env, struct lu_object *obj,
280                     const struct lu_object_conf *conf);
281 void ccc_object_free(const struct lu_env *env, struct lu_object *obj);
282 int ccc_lock_init(const struct lu_env *env, struct cl_object *obj,
283                   struct cl_lock *lock, const struct cl_io *io,
284                   const struct cl_lock_operations *lkops);
285 int ccc_attr_set(const struct lu_env *env, struct cl_object *obj,
286                  const struct cl_attr *attr, unsigned valid);
287 int ccc_object_glimpse(const struct lu_env *env,
288                        const struct cl_object *obj, struct ost_lvb *lvb);
289 int ccc_conf_set(const struct lu_env *env, struct cl_object *obj,
290                  const struct cl_object_conf *conf);
291 cfs_page_t *ccc_page_vmpage(const struct lu_env *env,
292                             const struct cl_page_slice *slice);
293 int ccc_page_is_under_lock(const struct lu_env *env,
294                            const struct cl_page_slice *slice, struct cl_io *io);
295 int ccc_fail(const struct lu_env *env, const struct cl_page_slice *slice);
296 void ccc_transient_page_verify(const struct cl_page *page);
297 void ccc_transient_page_own(const struct lu_env *env,
298                             const struct cl_page_slice *slice,
299                             struct cl_io *io);
300 void ccc_transient_page_assume(const struct lu_env *env,
301                                const struct cl_page_slice *slice,
302                                struct cl_io *io);
303 void ccc_transient_page_unassume(const struct lu_env *env,
304                                  const struct cl_page_slice *slice,
305                                  struct cl_io *io);
306 void ccc_transient_page_disown(const struct lu_env *env,
307                                const struct cl_page_slice *slice,
308                                struct cl_io *io);
309 void ccc_transient_page_discard(const struct lu_env *env,
310                                 const struct cl_page_slice *slice,
311                                 struct cl_io *io);
312 int ccc_transient_page_prep(const struct lu_env *env,
313                             const struct cl_page_slice *slice,
314                             struct cl_io *io);
315 void ccc_lock_delete(const struct lu_env *env,
316                      const struct cl_lock_slice *slice);
317 void ccc_lock_fini(const struct lu_env *env,struct cl_lock_slice *slice);
318 int ccc_lock_enqueue(const struct lu_env *env,const struct cl_lock_slice *slice,
319                      struct cl_io *io, __u32 enqflags);
320 int ccc_lock_unuse(const struct lu_env *env,const struct cl_lock_slice *slice);
321 int ccc_lock_wait(const struct lu_env *env,const struct cl_lock_slice *slice);
322 int ccc_lock_fits_into(const struct lu_env *env,
323                        const struct cl_lock_slice *slice,
324                        const struct cl_lock_descr *need,
325                        const struct cl_io *io);
326 void ccc_lock_state(const struct lu_env *env,
327                     const struct cl_lock_slice *slice,
328                     enum cl_lock_state state);
329
330 void ccc_io_fini(const struct lu_env *env, const struct cl_io_slice *ios);
331 int ccc_io_one_lock_index(const struct lu_env *env, struct cl_io *io,
332                           __u32 enqflags, enum cl_lock_mode mode,
333                           pgoff_t start, pgoff_t end);
334 int ccc_io_one_lock(const struct lu_env *env, struct cl_io *io,
335                     __u32 enqflags, enum cl_lock_mode mode,
336                     loff_t start, loff_t end);
337 void ccc_io_end(const struct lu_env *env, const struct cl_io_slice *ios);
338 void ccc_io_advance(const struct lu_env *env, const struct cl_io_slice *ios,
339                     size_t nob);
340 void ccc_io_update_iov(const struct lu_env *env, struct ccc_io *cio,
341                        struct cl_io *io);
342 int ccc_prep_size(const struct lu_env *env, struct cl_object *obj,
343                   struct cl_io *io, loff_t start, size_t count, int vfslock,
344                   int *exceed);
345 void ccc_req_completion(const struct lu_env *env,
346                         const struct cl_req_slice *slice, int ioret);
347 void ccc_req_attr_set(const struct lu_env *env,const struct cl_req_slice *slice,
348                       const struct cl_object *obj,
349                       struct cl_req_attr *oa, obd_valid flags);
350
351 struct lu_device   *ccc2lu_dev      (struct ccc_device *vdv);
352 struct lu_object   *ccc2lu          (struct ccc_object *vob);
353 struct ccc_device  *lu2ccc_dev      (const struct lu_device *d);
354 struct ccc_device  *cl2ccc_dev      (const struct cl_device *d);
355 struct ccc_object  *lu2ccc          (const struct lu_object *obj);
356 struct ccc_object  *cl2ccc          (const struct cl_object *obj);
357 struct ccc_lock    *cl2ccc_lock     (const struct cl_lock_slice *slice);
358 struct ccc_io      *cl2ccc_io       (const struct lu_env *env,
359                                      const struct cl_io_slice *slice);
360 struct ccc_req     *cl2ccc_req      (const struct cl_req_slice *slice);
361 cfs_page_t         *cl2vm_page      (const struct cl_page_slice *slice);
362 struct inode       *ccc_object_inode(const struct cl_object *obj);
363 struct ccc_object  *cl_inode2ccc    (struct inode *inode);
364
365 int cl_setattr_do_truncate(struct inode *inode, loff_t size,
366                            struct obd_capa *capa);
367 int cl_setattr_ost(struct inode *inode, struct obd_capa *capa);
368
369 struct cl_page *ccc_vmpage_page_transient(cfs_page_t *vmpage);
370 int ccc_object_invariant(const struct cl_object *obj);
371 int cl_inode_init(struct inode *inode, struct lustre_md *md);
372 void cl_inode_fini(struct inode *inode);
373 int cl_local_size(struct inode *inode);
374
375 __u16 ll_dirent_type_get(struct lu_dirent *ent);
376
377 #ifdef INVARIANT_CHECK
378 # define CLOBINVRNT(env, clob, expr)                                    \
379   do {                                                                  \
380           if (unlikely(!(expr))) {                                      \
381                   LU_OBJECT_DEBUG(D_ERROR, (env), &(clob)->co_lu, #expr "\n"); \
382                   LINVRNT(0);                                           \
383           }                                                             \
384   } while (0)
385 #else /* !INVARIANT_CHECK */
386 # define CLOBINVRNT(env, clob, expr)                                    \
387         ((void)sizeof(env), (void)sizeof(clob), (void)sizeof !!(expr))
388 #endif /* !INVARIANT_CHECK */
389
390 int cl_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp);
391 int cl_ocd_update(struct obd_device *host,
392                   struct obd_device *watched,
393                   enum obd_notify_event ev, void *owner);
394
395 struct ccc_grouplock {
396         struct lu_env   *cg_env;
397         struct cl_lock  *cg_lock;
398         unsigned long    cg_gid;
399 };
400
401 int  cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock,
402                       struct ccc_grouplock *cg);
403 void cl_put_grouplock(struct ccc_grouplock *cg);
404
405 #endif /*LCLIENT_H */