blob: 7a27f0961955c3bea63cad737622cbab589d6afa [file] [log] [blame]
Peng Taod7e09d02013-05-02 16:46:55 +08001/*
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
Oleg Drokin6a5b99a2016-06-14 23:33:40 -040018 * http://www.gnu.org/licenses/gpl-2.0.html
Peng Taod7e09d02013-05-02 16:46:55 +080019 *
Peng Taod7e09d02013-05-02 16:46:55 +080020 * GPL HEADER END
21 */
22/*
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
25 *
Andreas Dilger1dc563a2015-11-08 18:09:37 -050026 * Copyright (c) 2011, 2015, Intel Corporation.
Peng Taod7e09d02013-05-02 16:46:55 +080027 */
28/*
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
31 */
32
33#ifndef OSC_INTERNAL_H
34#define OSC_INTERNAL_H
35
36#define OAP_MAGIC 8675309
37
Li Xiaefd9d72015-09-14 18:41:32 -040038extern atomic_t osc_pool_req_count;
39extern unsigned int osc_reqpool_maxreqcount;
40extern struct ptlrpc_request_pool *osc_rq_pool;
41
Peng Taod7e09d02013-05-02 16:46:55 +080042struct lu_env;
43
44enum async_flags {
45 ASYNC_READY = 0x1, /* ap_make_ready will not be called before this
Oleg Drokin30aa9c52016-02-24 22:00:37 -050046 * page is added to an rpc
47 */
Peng Taod7e09d02013-05-02 16:46:55 +080048 ASYNC_URGENT = 0x2, /* page must be put into an RPC before return */
49 ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called
Oleg Drokin30aa9c52016-02-24 22:00:37 -050050 * to give the caller a chance to update
51 * or cancel the size of the io
52 */
Peng Taod7e09d02013-05-02 16:46:55 +080053 ASYNC_HP = 0x10,
54};
55
56struct osc_async_page {
57 int oap_magic;
58 unsigned short oap_cmd;
59 unsigned short oap_interrupted:1;
60
61 struct list_head oap_pending_item;
62 struct list_head oap_rpc_item;
63
Oleg Drokin21aef7d2014-08-15 12:55:56 -040064 u64 oap_obj_off;
Peng Taod7e09d02013-05-02 16:46:55 +080065 unsigned oap_page_off;
66 enum async_flags oap_async_flags;
67
68 struct brw_page oap_brw_page;
69
70 struct ptlrpc_request *oap_request;
71 struct client_obd *oap_cli;
72 struct osc_object *oap_obj;
73
74 struct ldlm_lock *oap_ldlm_lock;
75 spinlock_t oap_lock;
76};
77
78#define oap_page oap_brw_page.pg
79#define oap_count oap_brw_page.count
80#define oap_brw_flags oap_brw_page.flag
81
Jinshan Xiong77605e42016-03-30 19:48:30 -040082static inline struct osc_async_page *brw_page2oap(struct brw_page *pga)
83{
84 return (struct osc_async_page *)container_of(pga, struct osc_async_page,
85 oap_brw_page);
86}
87
Peng Taod7e09d02013-05-02 16:46:55 +080088struct osc_cache_waiter {
89 struct list_head ocw_entry;
90 wait_queue_head_t ocw_waitq;
91 struct osc_async_page *ocw_oap;
92 int ocw_grant;
93 int ocw_rc;
94};
95
Peng Taod7e09d02013-05-02 16:46:55 +080096void osc_wake_cache_waiters(struct client_obd *cli);
97int osc_shrink_grant_to_target(struct client_obd *cli, __u64 target_bytes);
98void osc_update_next_shrink(struct client_obd *cli);
99
100/*
101 * cl integration.
102 */
Greg Kroah-Hartman3ee30012014-07-11 22:16:18 -0700103#include "../include/cl_object.h"
Peng Taod7e09d02013-05-02 16:46:55 +0800104
105extern struct ptlrpc_request_set *PTLRPCD_SET;
106
Jinshan Xiong06563b52016-03-30 19:48:40 -0400107typedef int (*osc_enqueue_upcall_f)(void *cookie, struct lustre_handle *lockh,
108 int rc);
109
Peng Taod7e09d02013-05-02 16:46:55 +0800110int osc_enqueue_base(struct obd_export *exp, struct ldlm_res_id *res_id,
111 __u64 *flags, ldlm_policy_data_t *policy,
112 struct ost_lvb *lvb, int kms_valid,
Jinshan Xiong06563b52016-03-30 19:48:40 -0400113 osc_enqueue_upcall_f upcall,
Peng Taod7e09d02013-05-02 16:46:55 +0800114 void *cookie, struct ldlm_enqueue_info *einfo,
Peng Taod7e09d02013-05-02 16:46:55 +0800115 struct ptlrpc_request_set *rqset, int async, int agl);
116int osc_cancel_base(struct lustre_handle *lockh, __u32 mode);
117
118int osc_match_base(struct obd_export *exp, struct ldlm_res_id *res_id,
119 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
Dmitry Eremin875332d2014-06-22 21:32:08 -0400120 __u64 *flags, void *data, struct lustre_handle *lockh,
Peng Taod7e09d02013-05-02 16:46:55 +0800121 int unref);
122
123int 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);
127int 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);
130int 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
134int osc_process_config_base(struct obd_device *obd, struct lustre_cfg *cfg);
135int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
Olaf Weberc5c4c6f2015-09-14 18:41:35 -0400136 struct list_head *ext_list, int cmd);
Jinshan Xiong2579d8d2016-03-30 19:48:27 -0400137int osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,
138 int target, bool force);
Jinshan Xiong5196e422016-03-30 19:48:26 -0400139int osc_lru_reclaim(struct client_obd *cli);
Peng Taod7e09d02013-05-02 16:46:55 +0800140
Jinshan Xiongf56b3552016-03-30 19:48:31 -0400141unsigned long osc_ldlm_weigh_ast(struct ldlm_lock *dlmlock);
Peng Taod7e09d02013-05-02 16:46:55 +0800142
Peng Taod7e09d02013-05-02 16:46:55 +0800143int osc_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
144
Peng Taod7e09d02013-05-02 16:46:55 +0800145int lproc_osc_attach_seqstat(struct obd_device *dev);
146void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars);
Peng Taod7e09d02013-05-02 16:46:55 +0800147
148extern struct lu_device_type osc_device_type;
149
150static inline int osc_recoverable_error(int rc)
151{
152 return (rc == -EIO || rc == -EROFS || rc == -ENOMEM ||
153 rc == -EAGAIN || rc == -EINPROGRESS);
154}
155
156static inline unsigned long rpcs_in_flight(struct client_obd *cli)
157{
158 return cli->cl_r_in_flight + cli->cl_w_in_flight;
159}
160
Peng Taod7e09d02013-05-02 16:46:55 +0800161struct osc_device {
162 struct cl_device od_cl;
163 struct obd_export *od_exp;
164
165 /* Write stats is actually protected by client_obd's lock. */
166 struct osc_stats {
167 uint64_t os_lockless_writes; /* by bytes */
168 uint64_t os_lockless_reads; /* by bytes */
169 uint64_t os_lockless_truncates; /* by times */
170 } od_stats;
171
172 /* configuration item(s) */
173 int od_contention_time;
174 int od_lockless_truncate;
175};
176
177static inline struct osc_device *obd2osc_dev(const struct obd_device *d)
178{
179 return container_of0(d->obd_lu_dev, struct osc_device, od_cl.cd_lu_dev);
180}
181
Peng Taod7e09d02013-05-02 16:46:55 +0800182extern struct kmem_cache *osc_quota_kmem;
183struct osc_quota_info {
184 /** linkage for quota hash table */
185 struct hlist_node oqi_hash;
Oleg Drokin21aef7d2014-08-15 12:55:56 -0400186 u32 oqi_id;
Peng Taod7e09d02013-05-02 16:46:55 +0800187};
Mike Rapoportc9f6bb92015-10-13 16:03:42 +0300188
Peng Taod7e09d02013-05-02 16:46:55 +0800189int osc_quota_setup(struct obd_device *obd);
190int osc_quota_cleanup(struct obd_device *obd);
191int osc_quota_setdq(struct client_obd *cli, const unsigned int qid[],
Oleg Drokin21aef7d2014-08-15 12:55:56 -0400192 u32 valid, u32 flags);
Peng Taod7e09d02013-05-02 16:46:55 +0800193int osc_quota_chkdq(struct client_obd *cli, const unsigned int qid[]);
194int osc_quotactl(struct obd_device *unused, struct obd_export *exp,
195 struct obd_quotactl *oqctl);
196int osc_quotacheck(struct obd_device *unused, struct obd_export *exp,
197 struct obd_quotactl *oqctl);
198int osc_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk);
Prakash Suryaac5b1482016-04-27 18:21:04 -0400199void osc_inc_unstable_pages(struct ptlrpc_request *req);
200void osc_dec_unstable_pages(struct ptlrpc_request *req);
Prakash Suryaad479282016-04-27 18:21:06 -0400201int osc_over_unstable_soft_limit(struct client_obd *cli);
Prakash Suryaac5b1482016-04-27 18:21:04 -0400202
Jinshan Xiong06563b52016-03-30 19:48:40 -0400203struct ldlm_lock *osc_dlmlock_at_pgoff(const struct lu_env *env,
204 struct osc_object *obj, pgoff_t index,
205 int pending, int canceling);
Peng Taod7e09d02013-05-02 16:46:55 +0800206
Peng Taod7e09d02013-05-02 16:46:55 +0800207#endif /* OSC_INTERNAL_H */