Whamcloud - gitweb
LU-1214 ldlm: splits server specific lock handling from client
[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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  *
32  * Copyright (c) 2011, 2012, 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
39 #ifndef _LL_H
40 #define _LL_H
41
42 /** \defgroup lite lite
43  *
44  * @{
45  */
46
47 #if defined(__linux__)
48 #include <linux/lustre_lite.h>
49 #elif defined(__APPLE__)
50 #include <darwin/lustre_lite.h>
51 #elif defined(__WINNT__)
52 #include <winnt/lustre_lite.h>
53 #else
54 #error Unsupported operating system.
55 #endif
56
57 #include <obd_class.h>
58 #include <obd_ost.h>
59 #include <lustre_net.h>
60 #include <lustre_mds.h>
61 #include <lustre_ha.h>
62
63 /* 4UL * 1024 * 1024 */
64 #define LL_MAX_BLKSIZE_BITS     (22)
65 #define LL_MAX_BLKSIZE          (1UL<<LL_MAX_BLKSIZE_BITS)
66
67 #include <lustre/lustre_user.h>
68
69
70 struct lustre_rw_params {
71         int                lrp_lock_mode;
72         ldlm_policy_data_t lrp_policy;
73         obd_flag           lrp_brw_flags;
74         int                lrp_ast_flags;
75 };
76
77 /*
78  * XXX nikita: this function lives in the header because it is used by both
79  * llite kernel module and liblustre library, and there is no (?) better place
80  * to put it in.
81  */
82 static inline void lustre_build_lock_params(int cmd, unsigned long open_flags,
83                                             __u64 connect_flags,
84                                             loff_t pos, ssize_t len,
85                                             struct lustre_rw_params *params)
86 {
87         params->lrp_lock_mode = (cmd == OBD_BRW_READ) ? LCK_PR : LCK_PW;
88         params->lrp_brw_flags = 0;
89
90         params->lrp_policy.l_extent.start = pos;
91         params->lrp_policy.l_extent.end = pos + len - 1;
92         /*
93          * for now O_APPEND always takes local locks.
94          */
95         if (cmd == OBD_BRW_WRITE && (open_flags & O_APPEND)) {
96                 params->lrp_policy.l_extent.start = 0;
97                 params->lrp_policy.l_extent.end   = OBD_OBJECT_EOF;
98         } else if (LIBLUSTRE_CLIENT && (connect_flags & OBD_CONNECT_SRVLOCK)) {
99                 /*
100                  * liblustre: OST-side locking for all non-O_APPEND
101                  * reads/writes.
102                  */
103                 params->lrp_lock_mode = LCK_NL;
104                 params->lrp_brw_flags = OBD_BRW_SRVLOCK;
105         } else {
106                 /*
107                  * nothing special for the kernel. In the future llite may use
108                  * OST-side locks for small writes into highly contended
109                  * files.
110                  */
111         }
112         params->lrp_ast_flags = (open_flags & O_NONBLOCK) ?
113                 LDLM_FL_BLOCK_NOWAIT : 0;
114 }
115
116 /*
117  * This is embedded into liblustre and llite super-blocks to keep track of
118  * connect flags (capabilities) supported by all imports given mount is
119  * connected to.
120  */
121 struct lustre_client_ocd {
122         /*
123          * This is conjunction of connect_flags across all imports (LOVs) this
124          * mount is connected to. This field is updated by cl_ocd_update()
125          * under ->lco_lock.
126          */
127         __u64              lco_flags;
128         cfs_mutex_t        lco_lock;
129         struct obd_export *lco_md_exp;
130         struct obd_export *lco_dt_exp;
131 };
132
133 /*
134  * Chain of hash overflow pages.
135  */
136 struct ll_dir_chain {
137         /* XXX something. Later */
138 };
139
140 static inline void ll_dir_chain_init(struct ll_dir_chain *chain)
141 {
142 }
143
144 static inline void ll_dir_chain_fini(struct ll_dir_chain *chain)
145 {
146 }
147
148 static inline unsigned long hash_x_index(__u64 hash, int hash64)
149 {
150 #ifdef __KERNEL__
151         if (BITS_PER_LONG == 32 && hash64)
152                 hash >>= 32;
153 #endif
154         return ~0UL - hash;
155 }
156
157 /** @} lite */
158
159 #endif