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