Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / lustre / include / lustre_lite.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 _LL_H
38 #define _LL_H
39
40 #if defined(__linux__)
41 #include <linux/lustre_lite.h>
42 #elif defined(__APPLE__)
43 #include <darwin/lustre_lite.h>
44 #elif defined(__WINNT__)
45 #include <winnt/lustre_lite.h>
46 #else
47 #error Unsupported operating system.
48 #endif
49
50 #include <obd_class.h>
51 #include <obd_ost.h>
52 #include <lustre_net.h>
53 #include <lustre_mds.h>
54 #include <lustre_ha.h>
55
56 #ifdef __KERNEL__
57
58 /* careful, this is easy to screw up */
59 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << CFS_PAGE_SHIFT)
60
61 #endif
62
63 #define LLAP_FROM_COOKIE(c)                                                    \
64         (LASSERT(((struct ll_async_page *)(c))->llap_magic == LLAP_MAGIC),     \
65          (struct ll_async_page *)(c))
66
67 /* 4UL * 1024 * 1024 */
68 #define LL_MAX_BLKSIZE_BITS     (22)
69 #define LL_MAX_BLKSIZE          (1UL<<LL_MAX_BLKSIZE_BITS)
70
71 #include <lustre/lustre_user.h>
72
73
74 struct lustre_rw_params {
75         int                lrp_lock_mode;
76         ldlm_policy_data_t lrp_policy;
77         obd_flag           lrp_brw_flags;
78         int                lrp_ast_flags;
79 };
80
81 /*
82  * XXX nikita: this function lives in the header because it is used by both
83  * llite kernel module and liblustre library, and there is no (?) better place
84  * to put it in.
85  */
86 static inline void lustre_build_lock_params(int cmd, unsigned long open_flags,
87                                             __u64 connect_flags,
88                                             loff_t pos, ssize_t len,
89                                             struct lustre_rw_params *params)
90 {
91         params->lrp_lock_mode = (cmd == OBD_BRW_READ) ? LCK_PR : LCK_PW;
92         params->lrp_brw_flags = 0;
93
94         params->lrp_policy.l_extent.start = pos;
95         params->lrp_policy.l_extent.end = pos + len - 1;
96         /*
97          * for now O_APPEND always takes local locks.
98          */
99         if (cmd == OBD_BRW_WRITE && (open_flags & O_APPEND)) {
100                 params->lrp_policy.l_extent.start = 0;
101                 params->lrp_policy.l_extent.end   = OBD_OBJECT_EOF;
102         } else if (LIBLUSTRE_CLIENT && (connect_flags & OBD_CONNECT_SRVLOCK)) {
103                 /*
104                  * liblustre: OST-side locking for all non-O_APPEND
105                  * reads/writes.
106                  */
107                 params->lrp_lock_mode = LCK_NL;
108                 params->lrp_brw_flags = OBD_BRW_SRVLOCK;
109         } else {
110                 /*
111                  * nothing special for the kernel. In the future llite may use
112                  * OST-side locks for small writes into highly contended
113                  * files.
114                  */
115         }
116         params->lrp_ast_flags = (open_flags & O_NONBLOCK) ?
117                 LDLM_FL_BLOCK_NOWAIT : 0;
118 }
119
120 /*
121  * This is embedded into liblustre and llite super-blocks to keep track of
122  * connect flags (capabilities) supported by all imports given mount is
123  * connected to.
124  */
125 struct lustre_client_ocd {
126         /*
127          * This is conjunction of connect_flags across all imports (LOVs) this
128          * mount is connected to. This field is updated by ll_ocd_update()
129          * under ->lco_lock.
130          */
131         __u64      lco_flags;
132         spinlock_t lco_lock;
133 };
134
135 /*
136  * This function is used as an upcall-callback hooked by liblustre and llite
137  * clients into obd_notify() listeners chain to handle notifications about
138  * change of import connect_flags. See llu_fsswop_mount() and
139  * lustre_common_fill_super().
140  *
141  * Again, it is dumped into this header for the lack of a better place.
142  */
143 static inline int ll_ocd_update(struct obd_device *host,
144                                 struct obd_device *watched,
145                                 enum obd_notify_event ev, void *owner)
146 {
147         struct lustre_client_ocd *lco;
148         struct client_obd        *cli;
149         __u64 flags;
150         int   result;
151
152         ENTRY;
153         if (!strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
154                 cli = &watched->u.cli;
155                 lco = owner;
156                 flags = cli->cl_import->imp_connect_data.ocd_connect_flags;
157                 CDEBUG(D_SUPER, "Changing connect_flags: "LPX64" -> "LPX64"\n",
158                        lco->lco_flags, flags);
159                 spin_lock(&lco->lco_lock);
160                 lco->lco_flags &= flags;
161                 spin_unlock(&lco->lco_lock);
162                 result = 0;
163         } else {
164                 CERROR("unexpected notification from %s %s!\n",
165                        watched->obd_type->typ_name,
166                        watched->obd_name);
167                 result = -EINVAL;
168         }
169         RETURN(result);
170 }
171
172 /*      
173  * Chain of hash overflow pages.
174  */            
175 struct ll_dir_chain {
176         /* XXX something. Later */
177 };
178         
179 static inline void ll_dir_chain_init(struct ll_dir_chain *chain)
180 {       
181 }
182
183 static inline void ll_dir_chain_fini(struct ll_dir_chain *chain)
184 {
185 }
186
187 static inline __u32 hash_x_index(__u32 value)
188 {
189         return ((__u32)~0) - value;
190 }
191 #endif