Whamcloud - gitweb
LU-1030 osc: move io data from lov_oinfo into osc_object
[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, 2012, Whamcloud, Inc.
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         cfs_list_t              oap_pending_item;
60         cfs_list_t              oap_urgent_item;
61         cfs_list_t              oap_rpc_item;
62
63         obd_off                 oap_obj_off;
64         unsigned                oap_page_off;
65         enum async_flags        oap_async_flags;
66
67         struct brw_page         oap_brw_page;
68
69         struct ptlrpc_request   *oap_request;
70         struct client_obd       *oap_cli;
71         struct osc_object       *oap_obj;
72
73         struct ldlm_lock        *oap_ldlm_lock;
74         cfs_spinlock_t           oap_lock;
75 };
76
77 #define oap_page        oap_brw_page.pg
78 #define oap_count       oap_brw_page.count
79 #define oap_brw_flags   oap_brw_page.flag
80
81 struct osc_cache_waiter {
82         cfs_list_t              ocw_entry;
83         cfs_waitq_t             ocw_waitq;
84         struct osc_async_page  *ocw_oap;
85         int                     ocw_rc;
86 };
87
88 #define OSCC_FLAG_RECOVERING         0x01
89 #define OSCC_FLAG_CREATING           0x02
90 #define OSCC_FLAG_NOSPC              0x04 /* can't create more objects on OST */
91 #define OSCC_FLAG_SYNC_IN_PROGRESS   0x08 /* only allow one thread to sync */
92 #define OSCC_FLAG_LOW                0x10
93 #define OSCC_FLAG_EXITING            0x20
94 #define OSCC_FLAG_DEGRADED           0x40
95 #define OSCC_FLAG_RDONLY             0x80
96 #define OSCC_FLAG_NOSPC_BLK          0x100 /* no more block space on OST */
97
98 int osc_precreate(struct obd_export *exp);
99 int osc_create(const struct lu_env *env, struct obd_export *exp,
100                struct obdo *oa, struct lov_stripe_md **ea,
101                struct obd_trans_info *oti);
102 int osc_create_async(struct obd_export *exp, struct obd_info *oinfo,
103                      struct lov_stripe_md **ea, struct obd_trans_info *oti);
104 int osc_real_create(struct obd_export *exp, struct obdo *oa,
105                     struct lov_stripe_md **ea, struct obd_trans_info *oti);
106 void oscc_init(struct obd_device *obd);
107 void osc_wake_cache_waiters(struct client_obd *cli);
108 int osc_shrink_grant_to_target(struct client_obd *cli, long target);
109 void osc_update_next_shrink(struct client_obd *cli);
110
111 /*
112  * cl integration.
113  */
114 #include <cl_object.h>
115
116 extern struct ptlrpc_request_set *PTLRPCD_SET;
117
118 int osc_enqueue_base(struct obd_export *exp, struct ldlm_res_id *res_id,
119                      int *flags, ldlm_policy_data_t *policy,
120                      struct ost_lvb *lvb, int kms_valid,
121                      obd_enqueue_update_f upcall,
122                      void *cookie, struct ldlm_enqueue_info *einfo,
123                      struct lustre_handle *lockh,
124                      struct ptlrpc_request_set *rqset, int async, int agl);
125 int osc_cancel_base(struct lustre_handle *lockh, __u32 mode);
126
127 int osc_match_base(struct obd_export *exp, struct ldlm_res_id *res_id,
128                    __u32 type, ldlm_policy_data_t *policy, __u32 mode,
129                    int *flags, void *data, struct lustre_handle *lockh,
130                    int unref);
131
132 int osc_setattr_async_base(struct obd_export *exp, struct obd_info *oinfo,
133                            struct obd_trans_info *oti,
134                            obd_enqueue_update_f upcall, void *cookie,
135                            struct ptlrpc_request_set *rqset);
136 int osc_punch_base(struct obd_export *exp, struct obd_info *oinfo,
137                    obd_enqueue_update_f upcall, void *cookie,
138                    struct ptlrpc_request_set *rqset);
139
140 int osc_process_config_base(struct obd_device *obd, struct lustre_cfg *cfg);
141 int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
142                   cfs_list_t *rpc_list, int page_count, int cmd,
143                   pdl_policy_t p);
144
145 struct cl_page *osc_oap2cl_page(struct osc_async_page *oap);
146 extern cfs_spinlock_t osc_ast_guard;
147
148 int osc_cleanup(struct obd_device *obd);
149 int osc_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
150
151 #ifdef LPROCFS
152 int lproc_osc_attach_seqstat(struct obd_device *dev);
153 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars);
154 #else
155 static inline int lproc_osc_attach_seqstat(struct obd_device *dev) {return 0;}
156 static inline void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
157 {
158         memset(lvars, 0, sizeof(*lvars));
159 }
160 #endif
161
162 extern struct lu_device_type osc_device_type;
163
164 static inline int osc_recoverable_error(int rc)
165 {
166         return (rc == -EIO || rc == -EROFS || rc == -ENOMEM ||
167                 rc == -EAGAIN || rc == -EINPROGRESS);
168 }
169
170 static inline unsigned long rpcs_in_flight(struct client_obd *cli)
171 {
172         return cli->cl_r_in_flight + cli->cl_w_in_flight;
173 }
174
175 #ifndef min_t
176 #define min_t(type,x,y) \
177         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
178 #endif
179
180 struct osc_device {
181         struct cl_device    od_cl;
182         struct obd_export  *od_exp;
183
184         /* Write stats is actually protected by client_obd's lock. */
185         struct osc_stats {
186                 uint64_t     os_lockless_writes;          /* by bytes */
187                 uint64_t     os_lockless_reads;           /* by bytes */
188                 uint64_t     os_lockless_truncates;       /* by times */
189         } od_stats;
190
191         /* configuration item(s) */
192         int                 od_contention_time;
193         int                 od_lockless_truncate;
194 };
195
196 static inline struct osc_device *obd2osc_dev(const struct obd_device *d)
197 {
198         return container_of0(d->obd_lu_dev, struct osc_device, od_cl.cd_lu_dev);
199 }
200
201 int osc_dlm_lock_pageref(struct ldlm_lock *dlm);
202
203 int osc_quota_init(void);
204 int osc_quota_exit(void);
205 int osc_quota_cleanup(struct obd_device *obd);
206 int osc_quota_setdq(struct client_obd *cli, const unsigned int qid[],
207                     obd_flag valid, obd_flag flags);
208 int osc_quota_chkdq(struct client_obd *cli, const unsigned int qid[]);
209 int osc_quotactl(struct obd_device *unused, struct obd_export *exp,
210                  struct obd_quotactl *oqctl);
211 int osc_quotacheck(struct obd_device *unused, struct obd_export *exp,
212                    struct obd_quotactl *oqctl);
213 int osc_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk);
214 int osc_quota_adjust_qunit(struct obd_export *exp,
215                            struct quota_adjust_qunit *oqaq,
216                            struct lustre_quota_ctxt *qctxt,
217                            struct ptlrpc_request_set *rqset);
218 #endif /* OSC_INTERNAL_H */