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