Whamcloud - gitweb
LU-5458: libcfs: protect kkuc_groups from write access
[fs/lustre-release.git] / lustre / osc / osc_internal.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2013, Intel Corporation.
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 OSC_INTERNAL_H
38 #define OSC_INTERNAL_H
39
40 #define OAP_MAGIC 8675309
41
42 struct lu_env;
43
44 enum async_flags {
45         ASYNC_READY = 0x1, /* ap_make_ready will not be called before this
46                               page is added to an rpc */
47         ASYNC_URGENT = 0x2, /* page must be put into an RPC before return */
48         ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called
49                                      to give the caller a chance to update
50                                      or cancel the size of the io */
51         ASYNC_HP = 0x10,
52 };
53
54 struct osc_async_page {
55         int                     oap_magic;
56         unsigned short          oap_cmd;
57         unsigned short          oap_interrupted:1;
58
59         struct list_head        oap_pending_item;
60         struct list_head        oap_rpc_item;
61
62         obd_off                 oap_obj_off;
63         unsigned                oap_page_off;
64         enum async_flags        oap_async_flags;
65
66         struct brw_page         oap_brw_page;
67
68         struct ptlrpc_request   *oap_request;
69         struct client_obd       *oap_cli;
70         struct osc_object       *oap_obj;
71
72         spinlock_t               oap_lock;
73 };
74
75 #define oap_page        oap_brw_page.pg
76 #define oap_count       oap_brw_page.count
77 #define oap_brw_flags   oap_brw_page.flag
78
79 static inline struct osc_async_page *brw_page2oap(struct brw_page *pga)
80 {
81         return (struct osc_async_page *)container_of(pga, struct osc_async_page,
82                                                      oap_brw_page);
83 }
84
85 struct osc_cache_waiter {
86         struct list_head        ocw_entry;
87         wait_queue_head_t       ocw_waitq;
88         struct osc_async_page  *ocw_oap;
89         int                     ocw_grant;
90         int                     ocw_rc;
91 };
92
93 int osc_create(const struct lu_env *env, struct obd_export *exp,
94                struct obdo *oa, struct lov_stripe_md **ea,
95                struct obd_trans_info *oti);
96 int osc_real_create(struct obd_export *exp, struct obdo *oa,
97                     struct lov_stripe_md **ea, struct obd_trans_info *oti);
98 void osc_wake_cache_waiters(struct client_obd *cli);
99 int osc_shrink_grant_to_target(struct client_obd *cli, __u64 target_bytes);
100 void osc_update_next_shrink(struct client_obd *cli);
101
102 /*
103  * cl integration.
104  */
105 #include <cl_object.h>
106
107 extern struct ptlrpc_request_set *PTLRPCD_SET;
108
109 int osc_enqueue_base(struct obd_export *exp, struct ldlm_res_id *res_id,
110                      __u64 *flags, ldlm_policy_data_t *policy,
111                      struct ost_lvb *lvb, int kms_valid,
112                      obd_enqueue_update_f upcall,
113                      void *cookie, struct ldlm_enqueue_info *einfo,
114                      struct lustre_handle *lockh,
115                      struct ptlrpc_request_set *rqset, int async, int agl);
116 int osc_cancel_base(struct lustre_handle *lockh, __u32 mode);
117
118 int osc_match_base(struct obd_export *exp, struct ldlm_res_id *res_id,
119                    __u32 type, ldlm_policy_data_t *policy, __u32 mode,
120                    __u64 *flags, void *data, struct lustre_handle *lockh,
121                    int unref);
122
123 int osc_setattr_async_base(struct obd_export *exp, struct obd_info *oinfo,
124                            struct obd_trans_info *oti,
125                            obd_enqueue_update_f upcall, void *cookie,
126                            struct ptlrpc_request_set *rqset);
127 int osc_punch_base(struct obd_export *exp, struct obd_info *oinfo,
128                    obd_enqueue_update_f upcall, void *cookie,
129                    struct ptlrpc_request_set *rqset);
130 int osc_sync_base(struct obd_export *exp, struct obd_info *oinfo,
131                   obd_enqueue_update_f upcall, void *cookie,
132                   struct ptlrpc_request_set *rqset);
133
134 int osc_process_config_base(struct obd_device *obd, struct lustre_cfg *cfg);
135 int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
136                   struct list_head *ext_list, int cmd, pdl_policy_t p);
137 long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,
138                    long target, bool force);
139 long osc_lru_reclaim(struct client_obd *cli);
140
141 extern spinlock_t osc_ast_guard;
142 unsigned long osc_ldlm_weigh_ast(struct ldlm_lock *dlmlock);
143
144 int osc_cleanup(struct obd_device *obd);
145 int osc_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
146
147 #ifdef LPROCFS
148 extern struct lprocfs_seq_vars lprocfs_osc_obd_vars[];
149 int lproc_osc_attach_seqstat(struct obd_device *dev);
150 #else
151 static inline int lproc_osc_attach_seqstat(struct obd_device *dev) {return 0;}
152 #endif
153
154 extern struct lu_device_type osc_device_type;
155
156 static inline int osc_recoverable_error(int rc)
157 {
158         return (rc == -EIO || rc == -EROFS || rc == -ENOMEM ||
159                 rc == -EAGAIN || rc == -EINPROGRESS);
160 }
161
162 static inline unsigned long rpcs_in_flight(struct client_obd *cli)
163 {
164         return cli->cl_r_in_flight + cli->cl_w_in_flight;
165 }
166
167 #ifndef min_t
168 #define min_t(type,x,y) \
169         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
170 #endif
171
172 struct osc_device {
173         struct cl_device    od_cl;
174         struct obd_export  *od_exp;
175
176         /* Write stats is actually protected by client_obd's lock. */
177         struct osc_stats {
178                 uint64_t     os_lockless_writes;          /* by bytes */
179                 uint64_t     os_lockless_reads;           /* by bytes */
180                 uint64_t     os_lockless_truncates;       /* by times */
181         } od_stats;
182
183         /* configuration item(s) */
184         int                 od_contention_time;
185         int                 od_lockless_truncate;
186 };
187
188 static inline struct osc_device *obd2osc_dev(const struct obd_device *d)
189 {
190         return container_of0(d->obd_lu_dev, struct osc_device, od_cl.cd_lu_dev);
191 }
192
193 extern struct kmem_cache *osc_quota_kmem;
194 struct osc_quota_info {
195         /** linkage for quota hash table */
196         struct hlist_node oqi_hash;
197         obd_uid           oqi_id;
198 };
199 int osc_quota_setup(struct obd_device *obd);
200 int osc_quota_cleanup(struct obd_device *obd);
201 int osc_quota_setdq(struct client_obd *cli, const unsigned int qid[],
202                     obd_flag valid, obd_flag flags);
203 int osc_quota_chkdq(struct client_obd *cli, const unsigned int qid[]);
204 int osc_quotactl(struct obd_device *unused, struct obd_export *exp,
205                  struct obd_quotactl *oqctl);
206 int osc_quotacheck(struct obd_device *unused, struct obd_export *exp,
207                    struct obd_quotactl *oqctl);
208 int osc_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk);
209
210 void osc_inc_unstable_pages(struct ptlrpc_request *req);
211 void osc_dec_unstable_pages(struct ptlrpc_request *req);
212 bool osc_over_unstable_soft_limit(struct client_obd *cli);
213 #endif /* OSC_INTERNAL_H */