Whamcloud - gitweb
land b1_5 onto HEAD
[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
5 #ifndef _LL_H
6 #define _LL_H
7
8 #if defined(__linux__)
9 #include <linux/lustre_lite.h>
10 #elif defined(__APPLE__)
11 #include <darwin/lustre_lite.h>
12 #elif defined(__WINNT__)
13 #include <winnt/lustre_lite.h>
14 #else
15 #error Unsupported operating system.
16 #endif
17
18 #include <obd_class.h>
19 #include <obd_ost.h>
20 #include <lustre_net.h>
21 #include <lustre_mds.h>
22 #include <lustre_ha.h>
23
24 #ifdef __KERNEL__
25
26 /* careful, this is easy to screw up */
27 #define PAGE_CACHE_MAXBYTES ((__u64)(~0UL) << CFS_PAGE_SHIFT)
28
29 #endif
30
31 #define LLAP_FROM_COOKIE(c)                                                    \
32         (LASSERT(((struct ll_async_page *)(c))->llap_magic == LLAP_MAGIC),     \
33          (struct ll_async_page *)(c))
34
35 // 4*1024*1024
36 #define LL_MAX_BLKSIZE_BITS     (22)
37 #define LL_MAX_BLKSIZE          (1UL<<LL_MAX_BLKSIZE_BITS)
38
39 #include <lustre/lustre_user.h>
40
41
42 struct lustre_rw_params {
43         int                lrp_lock_mode;
44         ldlm_policy_data_t lrp_policy;
45         obd_flag           lrp_brw_flags;
46         int                lrp_ast_flags;
47 };
48
49 /*
50  * XXX nikita: this function lives in the header because it is used by both
51  * llite kernel module and liblustre library, and there is no (?) better place
52  * to put it in.
53  */
54 static inline void lustre_build_lock_params(int cmd, unsigned long open_flags,
55                                             __u64 connect_flags,
56                                             loff_t pos, ssize_t len,
57                                             struct lustre_rw_params *params)
58 {
59         params->lrp_lock_mode = (cmd == OBD_BRW_READ) ? LCK_PR : LCK_PW;
60         params->lrp_brw_flags = 0;
61
62         params->lrp_policy.l_extent.start = pos;
63         params->lrp_policy.l_extent.end = pos + len - 1;
64         /*
65          * for now O_APPEND always takes local locks.
66          */
67         if (cmd == OBD_BRW_WRITE && (open_flags & O_APPEND)) {
68                 params->lrp_policy.l_extent.start = 0;
69                 params->lrp_policy.l_extent.end   = OBD_OBJECT_EOF;
70         } else if (LIBLUSTRE_CLIENT && (connect_flags & OBD_CONNECT_SRVLOCK)) {
71                 /*
72                  * liblustre: OST-side locking for all non-O_APPEND
73                  * reads/writes.
74                  */
75                 params->lrp_lock_mode = LCK_NL;
76                 params->lrp_brw_flags = OBD_BRW_SRVLOCK;
77         } else {
78                 /*
79                  * nothing special for the kernel. In the future llite may use
80                  * OST-side locks for small writes into highly contended
81                  * files.
82                  */
83         }
84         params->lrp_ast_flags = (open_flags & O_NONBLOCK) ?
85                 LDLM_FL_BLOCK_NOWAIT : 0;
86 }
87
88 /*
89  * This is embedded into liblustre and llite super-blocks to keep track of
90  * connect flags (capabilities) supported by all imports given mount is
91  * connected to.
92  */
93 struct lustre_client_ocd {
94         /*
95          * This is conjunction of connect_flags across all imports (LOVs) this
96          * mount is connected to. This field is updated by ll_ocd_update()
97          * under ->lco_lock.
98          */
99         __u64      lco_flags;
100         spinlock_t lco_lock;
101 };
102
103 /*
104  * This function is used as an upcall-callback hooked by liblustre and llite
105  * clients into obd_notify() listeners chain to handle notifications about
106  * change of import connect_flags. See llu_fsswop_mount() and
107  * lustre_common_fill_super().
108  *
109  * Again, it is dumped into this header for the lack of a better place.
110  */
111 static inline int ll_ocd_update(struct obd_device *host,
112                                 struct obd_device *watched,
113                                 enum obd_notify_event ev, void *owner)
114 {
115         struct lustre_client_ocd *lco;
116         struct client_obd        *cli;
117         __u64 flags;
118         int   result;
119
120         ENTRY;
121         if (!strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
122                 cli = &watched->u.cli;
123                 lco = owner;
124                 flags = cli->cl_import->imp_connect_data.ocd_connect_flags;
125                 CDEBUG(D_SUPER, "Changing connect_flags: "LPX64" -> "LPX64"\n",
126                        lco->lco_flags, flags);
127                 spin_lock(&lco->lco_lock);
128                 lco->lco_flags &= flags;
129                 spin_unlock(&lco->lco_lock);
130                 result = 0;
131         } else {
132                 CERROR("unexpected notification from %s %s!\n",
133                        watched->obd_type->typ_name,
134                        watched->obd_name);
135                 result = -EINVAL;
136         }
137         RETURN(result);
138 }
139
140 #endif