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) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, 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 _LMV_INTERNAL_H_
38 #define _LMV_INTERNAL_H_
39 
40 #include "../include/lustre/lustre_idl.h"
41 #include "../include/obd.h"
42 
43 #define LMV_MAX_TGT_COUNT 128
44 
45 #define lmv_init_lock(lmv)   mutex_lock(&lmv->init_mutex)
46 #define lmv_init_unlock(lmv) mutex_unlock(&lmv->init_mutex)
47 
48 #define LL_IT2STR(it)					\
49 	((it) ? ldlm_it2str((it)->it_op) : "0")
50 
51 int lmv_check_connect(struct obd_device *obd);
52 
53 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
54 		    void *lmm, int lmmsize, struct lookup_intent *it,
55 		    int flags, struct ptlrpc_request **reqp,
56 		    ldlm_blocking_callback cb_blocking,
57 		    __u64 extra_lock_flags);
58 
59 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
60 		      void *lmm, int lmmsize, struct lookup_intent *it,
61 		      int flags, struct ptlrpc_request **reqp,
62 		      ldlm_blocking_callback cb_blocking,
63 		      __u64 extra_lock_flags);
64 
65 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
66 		    void *lmm, int lmmsize, struct lookup_intent *it,
67 		    int flags, struct ptlrpc_request **reqp,
68 		    ldlm_blocking_callback cb_blocking,
69 		    __u64 extra_lock_flags);
70 
71 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
72 		     void *, int);
73 int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid, u32 *mds);
74 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds);
75 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
76 		  struct md_op_data *op_data);
77 
lmv_get_mea(struct ptlrpc_request * req)78 static inline struct lmv_stripe_md *lmv_get_mea(struct ptlrpc_request *req)
79 {
80 	struct mdt_body	 *body;
81 	struct lmv_stripe_md    *mea;
82 
83 	LASSERT(req != NULL);
84 
85 	body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
86 
87 	if (!body || !S_ISDIR(body->mode) || !body->eadatasize)
88 		return NULL;
89 
90 	mea = req_capsule_server_sized_get(&req->rq_pill, &RMF_MDT_MD,
91 					   body->eadatasize);
92 	LASSERT(mea != NULL);
93 
94 	if (mea->mea_count == 0)
95 		return NULL;
96 	if (mea->mea_magic != MEA_MAGIC_LAST_CHAR &&
97 		mea->mea_magic != MEA_MAGIC_ALL_CHARS &&
98 		mea->mea_magic != MEA_MAGIC_HASH_SEGMENT)
99 		return NULL;
100 
101 	return mea;
102 }
103 
lmv_get_easize(struct lmv_obd * lmv)104 static inline int lmv_get_easize(struct lmv_obd *lmv)
105 {
106 	return sizeof(struct lmv_stripe_md) +
107 		lmv->desc.ld_tgt_count *
108 		sizeof(struct lu_fid);
109 }
110 
111 static inline struct lmv_tgt_desc *
lmv_get_target(struct lmv_obd * lmv,u32 mds)112 lmv_get_target(struct lmv_obd *lmv, u32 mds)
113 {
114 	int count = lmv->desc.ld_tgt_count;
115 	int i;
116 
117 	for (i = 0; i < count; i++) {
118 		if (lmv->tgts[i] == NULL)
119 			continue;
120 
121 		if (lmv->tgts[i]->ltd_idx == mds)
122 			return lmv->tgts[i];
123 	}
124 
125 	return ERR_PTR(-ENODEV);
126 }
127 
128 static inline struct lmv_tgt_desc *
lmv_find_target(struct lmv_obd * lmv,const struct lu_fid * fid)129 lmv_find_target(struct lmv_obd *lmv, const struct lu_fid *fid)
130 {
131 	u32 mds = 0;
132 	int rc;
133 
134 	if (lmv->desc.ld_tgt_count > 1) {
135 		rc = lmv_fld_lookup(lmv, fid, &mds);
136 		if (rc)
137 			return ERR_PTR(rc);
138 	}
139 
140 	return lmv_get_target(lmv, mds);
141 }
142 
143 struct lmv_tgt_desc
144 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
145 		struct lu_fid *fid);
146 /* lproc_lmv.c */
147 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars);
148 
149 extern struct file_operations lmv_proc_target_fops;
150 
151 #endif
152