Whamcloud - gitweb
5bff0a2295c02615c5c2e9458f967bca8955f278
[fs/lustre-release.git] / lustre / include / lustre_cache.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
37 #ifndef LUSTRE_CACHE_H
38 #define LUSTRE_CACHE_H
39 #include <obd.h>
40 #include <lustre/lustre_idl.h>
41 #include <lustre_dlm.h>
42
43 struct lustre_cache;
44 struct osc_async_page;
45 struct page_removal_cb_element {
46         struct list_head        prce_list;
47         obd_page_removal_cb_t   prce_callback;
48         atomic_t                prce_refcnt;
49 };
50
51 typedef int (*cache_iterate_extents_cb_t)(struct lustre_cache *,
52                                           struct lustre_handle *,
53                                           struct osc_async_page *,
54                                           void *);
55 typedef int (*cache_iterate_locks_cb_t)(struct lustre_cache *,
56                                         struct ldlm_res_id *,
57                                         struct lustre_handle *, void *);
58
59 struct lustre_cache {
60         struct list_head         lc_locks_list;
61         spinlock_t               lc_locks_list_lock;
62         struct list_head         lc_page_removal_callback_list;
63         rwlock_t                 lc_page_removal_cb_lock; /* iterate vs modify list */
64         struct obd_device       *lc_obd;
65         obd_pin_extent_cb        lc_pin_extent_cb;
66 };
67
68 int cache_add_lock(struct lustre_cache *cache, struct lustre_handle *lockh);
69 int cache_add_extent(struct lustre_cache *cache, struct ldlm_res_id *res,
70                      struct osc_async_page *extent,
71                      struct lustre_handle *lockh);
72 void cache_remove_extent(struct lustre_cache *, struct osc_async_page *);
73 int cache_add_extent_removal_cb(struct lustre_cache *cache,
74                                 obd_page_removal_cb_t func_cb,
75                                 obd_pin_extent_cb pin_cb);
76 int cache_del_extent_removal_cb(struct lustre_cache *cache,
77                                 obd_page_removal_cb_t func_cb);
78 int cache_iterate_extents(struct lustre_cache *cache, struct lustre_handle *lockh,
79                           cache_iterate_extents_cb_t cb_func, void *data);
80 int cache_remove_lock(struct lustre_cache *cache, struct lustre_handle *lockh);
81 int cache_iterate_locks(struct lustre_cache *cache, struct ldlm_res_id *res,
82                         cache_iterate_locks_cb_t cb_fun, void *data);
83 struct lustre_cache *cache_create(struct obd_device *obd);
84 int cache_destroy(struct lustre_cache *cache);
85
86
87 #endif /* LUSTRE_CACHE_H */