blob: 12bd511e8988fa9ec0c94f876b902ff0d3fc0345 [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 LOV_INTERNAL_H
34#define LOV_INTERNAL_H
35
Greg Kroah-Hartman0cf0f7a2014-07-11 22:01:58 -070036#include "../include/obd_class.h"
37#include "../include/lustre/lustre_user.h"
Peng Taod7e09d02013-05-02 16:46:55 +080038
John L. Hammond081b7262014-04-27 13:06:40 -040039/* lov_do_div64(a, b) returns a % b, and a = a / b.
40 * The 32-bit code is LOV-specific due to knowing about stripe limits in
41 * order to reduce the divisor to a 32-bit number. If the divisor is
Oleg Drokinacb9abc2016-02-24 22:00:32 -050042 * already a 32-bit value the compiler handles this directly.
43 */
John L. Hammond081b7262014-04-27 13:06:40 -040044#if BITS_PER_LONG == 64
45# define lov_do_div64(n, base) ({ \
46 uint64_t __base = (base); \
47 uint64_t __rem; \
48 __rem = ((uint64_t)(n)) % __base; \
49 (n) = ((uint64_t)(n)) / __base; \
50 __rem; \
51})
52#elif BITS_PER_LONG == 32
53# define lov_do_div64(n, base) ({ \
54 uint64_t __rem; \
55 if ((sizeof(base) > 4) && (((base) & 0xffffffff00000000ULL) != 0)) { \
56 int __remainder; \
57 LASSERTF(!((base) & (LOV_MIN_STRIPE_SIZE - 1)), "64 bit lov " \
58 "division %llu / %llu\n", (n), (uint64_t)(base)); \
59 __remainder = (n) & (LOV_MIN_STRIPE_SIZE - 1); \
60 (n) >>= LOV_MIN_STRIPE_BITS; \
61 __rem = do_div(n, (base) >> LOV_MIN_STRIPE_BITS); \
62 __rem <<= LOV_MIN_STRIPE_BITS; \
63 __rem += __remainder; \
64 } else { \
65 __rem = do_div(n, base); \
66 } \
67 __rem; \
68})
69#endif
70
John L. Hammondae322e02016-05-04 10:28:54 -040071#define pool_tgt_size(p) ((p)->pool_obds.op_size)
72#define pool_tgt_count(p) ((p)->pool_obds.op_count)
73#define pool_tgt_array(p) ((p)->pool_obds.op_array)
74#define pool_tgt_rw_sem(p) ((p)->pool_obds.op_rw_sem)
75
76struct pool_desc {
77 char pool_name[LOV_MAXPOOLNAME + 1];
78 struct ost_pool pool_obds;
79 atomic_t pool_refcount;
80 struct hlist_node pool_hash; /* access by poolname */
81 struct list_head pool_list; /* serial access */
82 struct dentry *pool_debugfs_entry; /* file in debugfs */
83 struct obd_device *pool_lobd; /* owner */
84};
85
Peng Taod7e09d02013-05-02 16:46:55 +080086struct lov_request {
87 struct obd_info rq_oi;
88 struct lov_request_set *rq_rqset;
89
90 struct list_head rq_link;
91
92 int rq_idx; /* index in lov->tgts array */
93 int rq_stripe; /* stripe number */
94 int rq_complete;
95 int rq_rc;
Peng Taod7e09d02013-05-02 16:46:55 +080096
Oleg Drokin21aef7d2014-08-15 12:55:56 -040097 u32 rq_oabufs;
98 u32 rq_pgaidx;
Peng Taod7e09d02013-05-02 16:46:55 +080099};
100
101struct lov_request_set {
Peng Taod7e09d02013-05-02 16:46:55 +0800102 struct obd_info *set_oi;
103 atomic_t set_refcount;
104 struct obd_export *set_exp;
105 /* XXX: There is @set_exp already, however obd_statfs gets obd_device
Oleg Drokinacb9abc2016-02-24 22:00:32 -0500106 * only.
107 */
Peng Taod7e09d02013-05-02 16:46:55 +0800108 struct obd_device *set_obd;
109 int set_count;
110 atomic_t set_completes;
111 atomic_t set_success;
112 atomic_t set_finish_checked;
113 struct llog_cookie *set_cookies;
114 int set_cookie_sent;
Peng Taod7e09d02013-05-02 16:46:55 +0800115 struct list_head set_list;
116 wait_queue_head_t set_waitq;
Peng Taod7e09d02013-05-02 16:46:55 +0800117};
118
119extern struct kmem_cache *lov_oinfo_slab;
120
Dulshani Gunawardhana126e7da2013-10-20 23:05:37 +0530121extern struct lu_kmem_descr lov_caches[];
122
Peng Taod7e09d02013-05-02 16:46:55 +0800123void lov_finish_set(struct lov_request_set *set);
124
Peng Taod7e09d02013-05-02 16:46:55 +0800125static inline void lov_put_reqset(struct lov_request_set *set)
126{
127 if (atomic_dec_and_test(&set->set_refcount))
128 lov_finish_set(set);
129}
130
Peng Taod7e09d02013-05-02 16:46:55 +0800131#define lov_uuid2str(lv, index) \
132 (char *)((lv)->lov_tgts[index]->ltd_uuid.uuid)
133
134/* lov_merge.c */
Oleg Drokin21aef7d2014-08-15 12:55:56 -0400135void lov_merge_attrs(struct obdo *tgt, struct obdo *src, u64 valid,
Peng Taod7e09d02013-05-02 16:46:55 +0800136 struct lov_stripe_md *lsm, int stripeno, int *set);
Peng Taod7e09d02013-05-02 16:46:55 +0800137int lov_adjust_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
Oleg Drokin21aef7d2014-08-15 12:55:56 -0400138 u64 size, int shrink);
Peng Taod7e09d02013-05-02 16:46:55 +0800139int lov_merge_lvb_kms(struct lov_stripe_md *lsm,
140 struct ost_lvb *lvb, __u64 *kms_place);
141
142/* lov_offset.c */
Oleg Drokinf1564f12016-02-26 01:50:05 -0500143u64 lov_stripe_size(struct lov_stripe_md *lsm, u64 ost_size, int stripeno);
Oleg Drokin21aef7d2014-08-15 12:55:56 -0400144int lov_stripe_offset(struct lov_stripe_md *lsm, u64 lov_off,
145 int stripeno, u64 *u64);
Oleg Drokinf1564f12016-02-26 01:50:05 -0500146u64 lov_size_to_stripe(struct lov_stripe_md *lsm, u64 file_size, int stripeno);
Peng Taod7e09d02013-05-02 16:46:55 +0800147int lov_stripe_intersects(struct lov_stripe_md *lsm, int stripeno,
Oleg Drokin21aef7d2014-08-15 12:55:56 -0400148 u64 start, u64 end,
149 u64 *obd_start, u64 *obd_end);
150int lov_stripe_number(struct lov_stripe_md *lsm, u64 lov_off);
Jinshan Xiongfd7444f2016-03-30 19:48:33 -0400151pgoff_t lov_stripe_pgoff(struct lov_stripe_md *lsm, pgoff_t stripe_index,
152 int stripe);
Peng Taod7e09d02013-05-02 16:46:55 +0800153
Peng Taod7e09d02013-05-02 16:46:55 +0800154/* lov_request.c */
Peng Taod7e09d02013-05-02 16:46:55 +0800155int lov_update_common_set(struct lov_request_set *set,
156 struct lov_request *req, int rc);
Peng Taod7e09d02013-05-02 16:46:55 +0800157int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo,
158 struct lov_request_set **reqset);
159int lov_fini_getattr_set(struct lov_request_set *set);
160int lov_prep_destroy_set(struct obd_export *exp, struct obd_info *oinfo,
161 struct obdo *src_oa, struct lov_stripe_md *lsm,
162 struct obd_trans_info *oti,
163 struct lov_request_set **reqset);
Peng Taod7e09d02013-05-02 16:46:55 +0800164int lov_fini_destroy_set(struct lov_request_set *set);
165int lov_prep_setattr_set(struct obd_export *exp, struct obd_info *oinfo,
166 struct obd_trans_info *oti,
167 struct lov_request_set **reqset);
168int lov_update_setattr_set(struct lov_request_set *set,
169 struct lov_request *req, int rc);
170int lov_fini_setattr_set(struct lov_request_set *set);
Peng Taod7e09d02013-05-02 16:46:55 +0800171int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
172 struct lov_request_set **reqset);
Peng Taod7e09d02013-05-02 16:46:55 +0800173int lov_fini_statfs(struct obd_device *obd, struct obd_statfs *osfs,
174 int success);
175int lov_fini_statfs_set(struct lov_request_set *set);
176int lov_statfs_interpret(struct ptlrpc_request_set *rqset, void *data, int rc);
177
178/* lov_obd.c */
John L. Hammondae322e02016-05-04 10:28:54 -0400179void lov_stripe_lock(struct lov_stripe_md *md);
180void lov_stripe_unlock(struct lov_stripe_md *md);
Peng Taod7e09d02013-05-02 16:46:55 +0800181void lov_fix_desc(struct lov_desc *desc);
182void lov_fix_desc_stripe_size(__u64 *val);
183void lov_fix_desc_stripe_count(__u32 *val);
184void lov_fix_desc_pattern(__u32 *val);
185void lov_fix_desc_qos_maxage(__u32 *val);
186__u16 lov_get_stripecnt(struct lov_obd *lov, __u32 magic, __u16 stripe_count);
187int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
188 struct obd_connect_data *data);
189int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
190int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,
191 __u32 *indexp, int *genp);
192int lov_del_target(struct obd_device *obd, __u32 index,
193 struct obd_uuid *uuidp, int gen);
Peng Taod7e09d02013-05-02 16:46:55 +0800194
195/* lov_pack.c */
196int lov_packmd(struct obd_export *exp, struct lov_mds_md **lmm,
197 struct lov_stripe_md *lsm);
198int lov_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
199 struct lov_mds_md *lmm, int lmm_bytes);
Peng Taod7e09d02013-05-02 16:46:55 +0800200int lov_getstripe(struct obd_export *exp,
Oleg Drokin55f37f02016-01-03 12:05:49 -0500201 struct lov_stripe_md *lsm, struct lov_user_md __user *lump);
Peng Taod7e09d02013-05-02 16:46:55 +0800202int lov_alloc_memmd(struct lov_stripe_md **lsmp, __u16 stripe_count,
203 int pattern, int magic);
204int lov_free_memmd(struct lov_stripe_md **lsmp);
205
206void lov_dump_lmm_v1(int level, struct lov_mds_md_v1 *lmm);
207void lov_dump_lmm_v3(int level, struct lov_mds_md_v3 *lmm);
Andreas Dilger53b78532013-06-03 21:40:47 +0800208void lov_dump_lmm_common(int level, void *lmmp);
Peng Taod7e09d02013-05-02 16:46:55 +0800209
210/* lov_ea.c */
211struct lov_stripe_md *lsm_alloc_plain(__u16 stripe_count, int *size);
212void lsm_free_plain(struct lov_stripe_md *lsm);
John L. Hammond081b7262014-04-27 13:06:40 -0400213void dump_lsm(unsigned int level, const struct lov_stripe_md *lsm);
Peng Taod7e09d02013-05-02 16:46:55 +0800214
Peng Taod7e09d02013-05-02 16:46:55 +0800215/* lproc_lov.c */
Peng Tao2c185ff2013-12-04 01:54:59 +0800216extern const struct file_operations lov_proc_target_fops;
Peng Taod7e09d02013-05-02 16:46:55 +0800217void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars);
Peng Taod7e09d02013-05-02 16:46:55 +0800218
219/* lov_cl.c */
220extern struct lu_device_type lov_device_type;
221
222/* pools */
James Simmonsdb9fc062015-10-28 12:54:24 -0400223extern struct cfs_hash_ops pool_hash_operations;
Peng Taod7e09d02013-05-02 16:46:55 +0800224/* ost_pool methods */
225int lov_ost_pool_init(struct ost_pool *op, unsigned int count);
226int lov_ost_pool_extend(struct ost_pool *op, unsigned int min_count);
227int lov_ost_pool_add(struct ost_pool *op, __u32 idx, unsigned int min_count);
228int lov_ost_pool_remove(struct ost_pool *op, __u32 idx);
229int lov_ost_pool_free(struct ost_pool *op);
230
231/* high level pool methods */
232int lov_pool_new(struct obd_device *obd, char *poolname);
233int lov_pool_del(struct obd_device *obd, char *poolname);
234int lov_pool_add(struct obd_device *obd, char *poolname, char *ostname);
235int lov_pool_remove(struct obd_device *obd, char *poolname, char *ostname);
Peng Taod7e09d02013-05-02 16:46:55 +0800236void lov_pool_putref(struct pool_desc *pool);
237
238static inline struct lov_stripe_md *lsm_addref(struct lov_stripe_md *lsm)
239{
240 LASSERT(atomic_read(&lsm->lsm_refc) > 0);
241 atomic_inc(&lsm->lsm_refc);
242 return lsm;
243}
244
Yang Sheng397632e2015-03-25 21:53:22 -0400245static inline bool lov_oinfo_is_dummy(const struct lov_oinfo *loi)
246{
247 if (unlikely(loi->loi_oi.oi.oi_id == 0 &&
248 loi->loi_oi.oi.oi_seq == 0 &&
249 loi->loi_ost_idx == 0 &&
250 loi->loi_ost_gen == 0))
251 return true;
252
253 return false;
254}
255
Peng Taod7e09d02013-05-02 16:46:55 +0800256#endif