Whamcloud - gitweb
Revert "b=20563 Increase LUSTRE_SEQ_MAX_WIDTH"
[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 (c) 2008, 2010, Oracle and/or its affiliates. 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  * Locking policy for setattr.
52  */
53 enum ccc_setattr_lock_type {
54         /** Locking is done by server */
55         SETATTR_NOLOCK,
56         /** Extent lock is enqueued */
57         SETATTR_EXTENT_LOCK,
58         /** Existing local extent lock is used */
59         SETATTR_MATCH_LOCK
60 };
61
62
63 /**
64  * IO state private to vvp or slp layers.
65  */
66 struct ccc_io {
67         /** super class */
68         struct cl_io_slice     cui_cl;
69         struct cl_io_lock_link cui_link;
70         /**
71          * I/O vector information to or from which read/write is going.
72          */
73         struct iovec *cui_iov;
74         unsigned long cui_nrsegs;
75         /**
76          * Total iov count for left IO.
77          */
78         unsigned long cui_tot_nrsegs;
79         /**
80          * Old length for iov that was truncated partially.
81          */
82         size_t cui_iov_olen;
83         /**
84          * Total size for the left IO.
85          */
86         size_t cui_tot_count;
87
88         union {
89                 struct {
90                         int                        cui_locks_released;
91                         enum ccc_setattr_lock_type cui_local_lock;
92                 } setattr;
93         } u;
94         /**
95          * True iff io is processing glimpse right now.
96          */
97         int                  cui_glimpse;
98         /**
99          * File descriptor against which IO is done.
100          */
101         struct ll_file_data *cui_fd;
102 #ifndef HAVE_FILE_WRITEV
103         struct kiocb *cui_iocb;
104 #endif
105 };
106
107 /**
108  * True, if \a io is a normal io, False for other (sendfile, splice*).
109  * must be impementated in arch specific code.
110  */
111 int cl_is_normalio(const struct lu_env *env, const struct cl_io *io);
112
113 extern struct lu_context_key ccc_key;
114 extern struct lu_context_key ccc_session_key;
115
116 struct ccc_thread_info {
117         struct cl_lock_descr cti_descr;
118         struct cl_io         cti_io;
119         struct cl_attr       cti_attr;
120 };
121
122 static inline struct ccc_thread_info *ccc_env_info(const struct lu_env *env)
123 {
124         struct ccc_thread_info      *info;
125
126         info = lu_context_key_get(&env->le_ctx, &ccc_key);
127         LASSERT(info != NULL);
128         return info;
129 }
130
131 static inline struct cl_attr *ccc_env_thread_attr(const struct lu_env *env)
132 {
133         struct cl_attr *attr = &ccc_env_info(env)->cti_attr;
134         memset(attr, 0, sizeof(*attr));
135         return attr;
136 }
137
138 struct ccc_session {
139         struct ccc_io cs_ios;
140 };
141
142 static inline struct ccc_session *ccc_env_session(const struct lu_env *env)
143 {
144         struct ccc_session *ses;
145
146         ses = lu_context_key_get(env->le_ses, &ccc_session_key);
147         LASSERT(ses != NULL);
148         return ses;
149 }
150
151 static inline struct ccc_io *ccc_env_io(const struct lu_env *env)
152 {
153         return &ccc_env_session(env)->cs_ios;
154 }
155
156 /**
157  * ccc-private object state.
158  */
159 struct ccc_object {
160         struct cl_object_header cob_header;
161         struct cl_object        cob_cl;
162         struct inode           *cob_inode;
163
164         /**
165          * A list of dirty pages pending IO in the cache. Used by
166          * SOM. Protected by ll_inode_info::lli_lock.
167          *
168          * \see ccc_page::cpg_pending_linkage
169          */
170         cfs_list_t             cob_pending_list;
171
172         /**
173          * Access this counter is protected by inode->i_sem. Now that
174          * the lifetime of transient pages must be covered by inode sem,
175          * we don't need to hold any lock..
176          */
177         int                     cob_transient_pages;
178         /**
179          * Number of outstanding mmaps on this file.
180          *
181          * \see ll_vm_open(), ll_vm_close().
182          */
183         cfs_atomic_t            cob_mmap_cnt;
184 };
185
186 /**
187  * ccc-private page state.
188  */
189 struct ccc_page {
190         struct cl_page_slice cpg_cl;
191         int                  cpg_defer_uptodate;
192         int                  cpg_ra_used;
193         int                  cpg_write_queued;
194         /**
195          * Non-empty iff this page is already counted in
196          * ccc_object::cob_pending_list. Protected by
197          * ccc_object::cob_pending_guard. This list is only used as a flag,
198          * that is, never iterated through, only checked for list_empty(), but
199          * having a list is useful for debugging.
200          */
201         cfs_list_t           cpg_pending_linkage;
202         /** VM page */
203         cfs_page_t          *cpg_page;
204 };
205
206 static inline struct ccc_page *cl2ccc_page(const struct cl_page_slice *slice)
207 {
208         return container_of(slice, struct ccc_page, cpg_cl);
209 }
210
211 struct cl_page    *ccc_vmpage_page_transient(cfs_page_t *vmpage);
212
213 struct ccc_device {
214         struct cl_device    cdv_cl;
215         struct super_block *cdv_sb;
216         struct cl_device   *cdv_next;
217 };
218
219 struct ccc_lock {
220         struct cl_lock_slice clk_cl;
221 };
222
223 struct ccc_req {
224         struct cl_req_slice  crq_cl;
225 };
226
227 void *ccc_key_init        (const struct lu_context *ctx,
228                            struct lu_context_key *key);
229 void  ccc_key_fini        (const struct lu_context *ctx,
230                            struct lu_context_key *key, void *data);
231 void *ccc_session_key_init(const struct lu_context *ctx,
232                            struct lu_context_key *key);
233 void  ccc_session_key_fini(const struct lu_context *ctx,
234                            struct lu_context_key *key, void *data);
235
236 int              ccc_device_init  (const struct lu_env *env,
237                                    struct lu_device *d,
238                                    const char *name, struct lu_device *next);
239 struct lu_device *ccc_device_fini (const struct lu_env *env,
240                                    struct lu_device *d);
241 struct lu_device *ccc_device_alloc(const struct lu_env *env,
242                                    struct lu_device_type *t,
243                                    struct lustre_cfg *cfg,
244                                    const struct lu_device_operations *luops,
245                                    const struct cl_device_operations *clops);
246 struct lu_device *ccc_device_free (const struct lu_env *env,
247                                    struct lu_device *d);
248 struct lu_object *ccc_object_alloc(const struct lu_env *env,
249                                    const struct lu_object_header *hdr,
250                                    struct lu_device *dev,
251                                    const struct cl_object_operations *clops,
252                                    const struct lu_object_operations *luops);
253
254 int ccc_req_init(const struct lu_env *env, struct cl_device *dev,
255                  struct cl_req *req);
256 void ccc_umount(const struct lu_env *env, struct cl_device *dev);
257 int ccc_global_init(struct lu_device_type *device_type);
258 void ccc_global_fini(struct lu_device_type *device_type);
259 int ccc_object_init0(const struct lu_env *env,struct ccc_object *vob,
260                      const struct cl_object_conf *conf);
261 int ccc_object_init(const struct lu_env *env, struct lu_object *obj,
262                     const struct lu_object_conf *conf);
263 void ccc_object_free(const struct lu_env *env, struct lu_object *obj);
264 int ccc_lock_init(const struct lu_env *env, struct cl_object *obj,
265                   struct cl_lock *lock, const struct cl_io *io,
266                   const struct cl_lock_operations *lkops);
267 int ccc_attr_set(const struct lu_env *env, struct cl_object *obj,
268                  const struct cl_attr *attr, unsigned valid);
269 int ccc_object_glimpse(const struct lu_env *env,
270                        const struct cl_object *obj, struct ost_lvb *lvb);
271 int ccc_conf_set(const struct lu_env *env, struct cl_object *obj,
272                  const struct cl_object_conf *conf);
273 cfs_page_t *ccc_page_vmpage(const struct lu_env *env,
274                             const struct cl_page_slice *slice);
275 int ccc_page_is_under_lock(const struct lu_env *env,
276                            const struct cl_page_slice *slice, struct cl_io *io);
277 int ccc_fail(const struct lu_env *env, const struct cl_page_slice *slice);
278 void ccc_transient_page_verify(const struct cl_page *page);
279 int  ccc_transient_page_own(const struct lu_env *env,
280                             const struct cl_page_slice *slice,
281                             struct cl_io *io, int nonblock);
282 void ccc_transient_page_assume(const struct lu_env *env,
283                                const struct cl_page_slice *slice,
284                                struct cl_io *io);
285 void ccc_transient_page_unassume(const struct lu_env *env,
286                                  const struct cl_page_slice *slice,
287                                  struct cl_io *io);
288 void ccc_transient_page_disown(const struct lu_env *env,
289                                const struct cl_page_slice *slice,
290                                struct cl_io *io);
291 void ccc_transient_page_discard(const struct lu_env *env,
292                                 const struct cl_page_slice *slice,
293                                 struct cl_io *io);
294 int ccc_transient_page_prep(const struct lu_env *env,
295                             const struct cl_page_slice *slice,
296                             struct cl_io *io);
297 void ccc_lock_delete(const struct lu_env *env,
298                      const struct cl_lock_slice *slice);
299 void ccc_lock_fini(const struct lu_env *env,struct cl_lock_slice *slice);
300 int ccc_lock_enqueue(const struct lu_env *env,const struct cl_lock_slice *slice,
301                      struct cl_io *io, __u32 enqflags);
302 int ccc_lock_unuse(const struct lu_env *env,const struct cl_lock_slice *slice);
303 int ccc_lock_wait(const struct lu_env *env,const struct cl_lock_slice *slice);
304 int ccc_lock_fits_into(const struct lu_env *env,
305                        const struct cl_lock_slice *slice,
306                        const struct cl_lock_descr *need,
307                        const struct cl_io *io);
308 void ccc_lock_state(const struct lu_env *env,
309                     const struct cl_lock_slice *slice,
310                     enum cl_lock_state state);
311
312 void ccc_io_fini(const struct lu_env *env, const struct cl_io_slice *ios);
313 int ccc_io_one_lock_index(const struct lu_env *env, struct cl_io *io,
314                           __u32 enqflags, enum cl_lock_mode mode,
315                           pgoff_t start, pgoff_t end);
316 int ccc_io_one_lock(const struct lu_env *env, struct cl_io *io,
317                     __u32 enqflags, enum cl_lock_mode mode,
318                     loff_t start, loff_t end);
319 void ccc_io_end(const struct lu_env *env, const struct cl_io_slice *ios);
320 void ccc_io_advance(const struct lu_env *env, const struct cl_io_slice *ios,
321                     size_t nob);
322 void ccc_io_update_iov(const struct lu_env *env, struct ccc_io *cio,
323                        struct cl_io *io);
324 int ccc_prep_size(const struct lu_env *env, struct cl_object *obj,
325                   struct cl_io *io, loff_t start, size_t count, int vfslock,
326                   int *exceed);
327 void ccc_req_completion(const struct lu_env *env,
328                         const struct cl_req_slice *slice, int ioret);
329 void ccc_req_attr_set(const struct lu_env *env,const struct cl_req_slice *slice,
330                       const struct cl_object *obj,
331                       struct cl_req_attr *oa, obd_valid flags);
332
333 struct lu_device   *ccc2lu_dev      (struct ccc_device *vdv);
334 struct lu_object   *ccc2lu          (struct ccc_object *vob);
335 struct ccc_device  *lu2ccc_dev      (const struct lu_device *d);
336 struct ccc_device  *cl2ccc_dev      (const struct cl_device *d);
337 struct ccc_object  *lu2ccc          (const struct lu_object *obj);
338 struct ccc_object  *cl2ccc          (const struct cl_object *obj);
339 struct ccc_lock    *cl2ccc_lock     (const struct cl_lock_slice *slice);
340 struct ccc_io      *cl2ccc_io       (const struct lu_env *env,
341                                      const struct cl_io_slice *slice);
342 struct ccc_req     *cl2ccc_req      (const struct cl_req_slice *slice);
343 cfs_page_t         *cl2vm_page      (const struct cl_page_slice *slice);
344 struct inode       *ccc_object_inode(const struct cl_object *obj);
345 struct ccc_object  *cl_inode2ccc    (struct inode *inode);
346
347 int cl_setattr_ost(struct inode *inode, const struct iattr *attr,
348                    struct obd_capa *capa);
349
350 struct cl_page *ccc_vmpage_page_transient(cfs_page_t *vmpage);
351 int ccc_object_invariant(const struct cl_object *obj);
352 int cl_inode_init(struct inode *inode, struct lustre_md *md);
353 void cl_inode_fini(struct inode *inode);
354 int cl_local_size(struct inode *inode);
355
356 __u16 ll_dirent_type_get(struct lu_dirent *ent);
357 ino_t cl_fid_build_ino(const struct lu_fid *fid);
358 __u32 cl_fid_build_gen(const struct lu_fid *fid);
359
360 #ifdef INVARIANT_CHECK
361 # define CLOBINVRNT(env, clob, expr)                                    \
362   do {                                                                  \
363           if (unlikely(!(expr))) {                                      \
364                   LU_OBJECT_DEBUG(D_ERROR, (env), &(clob)->co_lu, #expr "\n"); \
365                   LINVRNT(0);                                           \
366           }                                                             \
367   } while (0)
368 #else /* !INVARIANT_CHECK */
369 # define CLOBINVRNT(env, clob, expr)                                    \
370         ((void)sizeof(env), (void)sizeof(clob), (void)sizeof !!(expr))
371 #endif /* !INVARIANT_CHECK */
372
373 int cl_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp);
374 int cl_ocd_update(struct obd_device *host,
375                   struct obd_device *watched,
376                   enum obd_notify_event ev, void *owner, void *data);
377
378 struct ccc_grouplock {
379         struct lu_env   *cg_env;
380         struct cl_lock  *cg_lock;
381         unsigned long    cg_gid;
382 };
383
384 int  cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock,
385                       struct ccc_grouplock *cg);
386 void cl_put_grouplock(struct ccc_grouplock *cg);
387
388 #endif /*LCLIENT_H */