1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * Definitions shared between vvp and liblustre, and other clients in the
39 * Author: Oleg Drokin <oleg.drokin@sun.com>
40 * Author: Nikita Danilov <nikita.danilov@sun.com>
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);
51 * Common IO arguments for various VFS I/O interfaces.
55 #ifndef HAVE_FILE_WRITEV
56 struct kiocb *cia_iocb;
58 struct iovec *cia_iov;
59 unsigned long cia_nrsegs;
60 read_actor_t cia_actor;
65 * Locking policy for truncate.
67 enum ccc_trunc_lock_type {
68 /** Locking is done by server */
70 /** Extent lock is enqueued */
72 /** Existing local extent lock is used */
77 * IO state private to vvp or slp layers.
81 struct cl_io_slice cui_cl;
82 struct cl_io_lock_link cui_link;
84 * I/O vector information to or from which read/write is going.
86 struct iovec *cui_iov;
87 unsigned long cui_nrsegs;
89 * Total iov count for left IO.
91 unsigned long cui_tot_nrsegs;
93 * Old length for iov that was truncated partially.
97 * Total size for the left IO.
103 int cui_locks_released;
104 enum ccc_trunc_lock_type cui_local_lock;
108 * True iff io is processing glimpse right now.
112 * File descriptor against which IO is done.
114 struct ll_file_data *cui_fd;
115 #ifndef HAVE_FILE_WRITEV
116 struct kiocb *cui_iocb;
120 extern struct lu_context_key ccc_key;
121 extern struct lu_context_key ccc_session_key;
123 struct ccc_thread_info {
124 struct cl_lock_descr cti_descr;
126 struct cl_sync_io cti_sync_io;
127 struct cl_attr cti_attr;
130 static inline struct ccc_thread_info *ccc_env_info(const struct lu_env *env)
132 struct ccc_thread_info *info;
134 info = lu_context_key_get(&env->le_ctx, &ccc_key);
135 LASSERT(info != NULL);
140 struct ccc_io cs_ios;
143 static inline struct ccc_session *ccc_env_session(const struct lu_env *env)
145 struct ccc_session *ses;
147 ses = lu_context_key_get(env->le_ses, &ccc_session_key);
148 LASSERT(ses != NULL);
152 static inline struct ccc_io *ccc_env_io(const struct lu_env *env)
154 return &ccc_env_session(env)->cs_ios;
158 * ccc-private object state.
161 struct cl_object_header cob_header;
162 struct cl_object cob_cl;
163 struct inode *cob_inode;
166 * A list of dirty pages pending IO in the cache. Used by
167 * SOM. Protected by ll_inode_info::lli_lock.
169 * \see ccc_page::cpg_pending_linkage
171 struct list_head cob_pending_list;
174 * Access this counter is protected by inode->i_sem. Now that
175 * the lifetime of transient pages must be covered by inode sem,
176 * we don't need to hold any lock..
178 int cob_transient_pages;
180 * Number of outstanding mmaps on this file.
182 * \see ll_vm_open(), ll_vm_close().
184 atomic_t cob_mmap_cnt;
188 * ccc-private page state.
191 struct cl_page_slice cpg_cl;
192 int cpg_defer_uptodate;
194 int cpg_write_queued;
196 * Non-empty iff this page is already counted in
197 * ccc_object::cob_pending_list. Protected by
198 * ccc_object::cob_pending_guard. This list is only used as a flag,
199 * that is, never iterated through, only checked for list_empty(), but
200 * having a list is useful for debugging.
202 struct list_head cpg_pending_linkage;
204 cfs_page_t *cpg_page;
205 struct cl_sync_io *cpg_sync_io;
207 * checksum for paranoid I/O debugging enabled by
208 * ENABLE_LLITE_CHECKSUM configuration option.
210 * XXX This cannot be implemented reliably because checksum cannot be
211 * updated from ->set_page_dirty() that is called without page VM
217 static inline struct ccc_page *cl2ccc_page(const struct cl_page_slice *slice)
219 return container_of(slice, struct ccc_page, cpg_cl);
222 struct cl_page *ccc_vmpage_page_transient(cfs_page_t *vmpage);
225 struct cl_device cdv_cl;
226 struct super_block *cdv_sb;
227 struct cl_device *cdv_next;
231 struct cl_lock_slice clk_cl;
235 struct cl_req_slice crq_cl;
238 void *ccc_key_init (const struct lu_context *ctx,
239 struct lu_context_key *key);
240 void ccc_key_fini (const struct lu_context *ctx,
241 struct lu_context_key *key, void *data);
242 void *ccc_session_key_init(const struct lu_context *ctx,
243 struct lu_context_key *key);
244 void ccc_session_key_fini(const struct lu_context *ctx,
245 struct lu_context_key *key, void *data);
247 int ccc_device_init (const struct lu_env *env,
249 const char *name, struct lu_device *next);
250 struct lu_device *ccc_device_fini (const struct lu_env *env,
251 struct lu_device *d);
252 struct lu_device *ccc_device_alloc(const struct lu_env *env,
253 struct lu_device_type *t,
254 struct lustre_cfg *cfg,
255 const struct lu_device_operations *luops,
256 const struct cl_device_operations *clops);
257 struct lu_device *ccc_device_free (const struct lu_env *env,
258 struct lu_device *d);
259 struct lu_object *ccc_object_alloc(const struct lu_env *env,
260 const struct lu_object_header *hdr,
261 struct lu_device *dev,
262 const struct cl_object_operations *clops,
263 const struct lu_object_operations *luops);
265 int ccc_req_init(const struct lu_env *env, struct cl_device *dev,
267 void ccc_umount(const struct lu_env *env, struct cl_device *dev);
268 int ccc_global_init(struct lu_device_type *device_type);
269 void ccc_global_fini(struct lu_device_type *device_type);
270 int ccc_object_init0(const struct lu_env *env,struct ccc_object *vob,
271 const struct cl_object_conf *conf);
272 int ccc_object_init(const struct lu_env *env, struct lu_object *obj,
273 const struct lu_object_conf *conf);
274 void ccc_object_free(const struct lu_env *env, struct lu_object *obj);
275 int ccc_lock_init(const struct lu_env *env, struct cl_object *obj,
276 struct cl_lock *lock, const struct cl_io *io,
277 const struct cl_lock_operations *lkops);
278 int ccc_attr_set(const struct lu_env *env, struct cl_object *obj,
279 const struct cl_attr *attr, unsigned valid);
280 int ccc_object_glimpse(const struct lu_env *env,
281 const struct cl_object *obj, struct ost_lvb *lvb);
282 int ccc_conf_set(const struct lu_env *env, struct cl_object *obj,
283 const struct cl_object_conf *conf);
284 cfs_page_t *ccc_page_vmpage(const struct lu_env *env,
285 const struct cl_page_slice *slice);
286 int ccc_page_is_under_lock(const struct lu_env *env,
287 const struct cl_page_slice *slice, struct cl_io *io);
288 int ccc_fail(const struct lu_env *env, const struct cl_page_slice *slice);
289 void ccc_transient_page_verify(const struct cl_page *page);
290 void ccc_transient_page_own(const struct lu_env *env,
291 const struct cl_page_slice *slice,
293 void ccc_transient_page_assume(const struct lu_env *env,
294 const struct cl_page_slice *slice,
296 void ccc_transient_page_unassume(const struct lu_env *env,
297 const struct cl_page_slice *slice,
299 void ccc_transient_page_disown(const struct lu_env *env,
300 const struct cl_page_slice *slice,
302 void ccc_transient_page_discard(const struct lu_env *env,
303 const struct cl_page_slice *slice,
305 int ccc_transient_page_prep(const struct lu_env *env,
306 const struct cl_page_slice *slice,
308 void ccc_lock_fini(const struct lu_env *env,struct cl_lock_slice *slice);
309 int ccc_lock_enqueue(const struct lu_env *env,const struct cl_lock_slice *slice,
310 struct cl_io *io, __u32 enqflags);
311 int ccc_lock_unuse(const struct lu_env *env,const struct cl_lock_slice *slice);
312 int ccc_lock_wait(const struct lu_env *env,const struct cl_lock_slice *slice);
313 int ccc_lock_fits_into(const struct lu_env *env,
314 const struct cl_lock_slice *slice,
315 const struct cl_lock_descr *need,
316 const struct cl_io *io);
317 void ccc_lock_state(const struct lu_env *env,
318 const struct cl_lock_slice *slice,
319 enum cl_lock_state state);
321 void ccc_io_fini(const struct lu_env *env, const struct cl_io_slice *ios);
322 int ccc_io_one_lock_index(const struct lu_env *env, struct cl_io *io,
323 __u32 enqflags, enum cl_lock_mode mode,
324 pgoff_t start, pgoff_t end);
325 int ccc_io_one_lock(const struct lu_env *env, struct cl_io *io,
326 __u32 enqflags, enum cl_lock_mode mode,
327 loff_t start, loff_t end);
328 void ccc_io_end(const struct lu_env *env, const struct cl_io_slice *ios);
329 int ccc_prep_size(const struct lu_env *env, struct cl_object *obj,
330 struct cl_io *io, loff_t pos, int vfslock);
331 void ccc_req_completion(const struct lu_env *env,
332 const struct cl_req_slice *slice, int ioret);
333 void ccc_req_attr_set(const struct lu_env *env,const struct cl_req_slice *slice,
334 const struct cl_object *obj,
335 struct cl_req_attr *oa, obd_valid flags);
337 struct lu_device *ccc2lu_dev (struct ccc_device *vdv);
338 struct lu_object *ccc2lu (struct ccc_object *vob);
339 struct ccc_device *lu2ccc_dev (const struct lu_device *d);
340 struct ccc_device *cl2ccc_dev (const struct cl_device *d);
341 struct ccc_object *lu2ccc (const struct lu_object *obj);
342 struct ccc_object *cl2ccc (const struct cl_object *obj);
343 struct ccc_lock *cl2ccc_lock (const struct cl_lock_slice *slice);
344 struct ccc_io *cl2ccc_io (const struct lu_env *env,
345 const struct cl_io_slice *slice);
346 struct ccc_req *cl2ccc_req (const struct cl_req_slice *slice);
347 cfs_page_t *cl2vm_page (const struct cl_page_slice *slice);
348 struct inode *ccc_object_inode(const struct cl_object *obj);
349 struct ccc_object *cl_inode2ccc (struct inode *inode);
351 int cl_setattr_do_truncate(struct inode *inode, loff_t size,
352 struct obd_capa *capa);
353 int cl_setattr_ost(struct inode *inode, struct obd_capa *capa);
355 struct cl_page *ccc_vmpage_page_transient(cfs_page_t *vmpage);
356 int ccc_object_invariant(const struct cl_object *obj);
357 int cl_inode_init(struct inode *inode, struct lustre_md *md);
358 void cl_inode_fini(struct inode *inode);
359 int cl_local_size(struct inode *inode);
361 #ifdef INVARIANT_CHECK
362 # define CLOBINVRNT(env, clob, expr) \
364 if (unlikely(!(expr))) { \
365 LU_OBJECT_DEBUG(D_ERROR, (env), &(clob)->co_lu, #expr "\n"); \
369 #else /* !INVARIANT_CHECK */
370 # define CLOBINVRNT(env, clob, expr) \
371 ((void)sizeof(env), (void)sizeof(clob), (void)sizeof !!(expr))
372 #endif /* !INVARIANT_CHECK */
375 #endif /*LCLIENT_H */