]>
Commit | Line | Data |
---|---|---|
d7e09d03 PT |
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 | #define DEBUG_SUBSYSTEM S_LMV | |
38 | #include <linux/slab.h> | |
39 | #include <linux/module.h> | |
40 | #include <linux/init.h> | |
d7e09d03 PT |
41 | #include <linux/pagemap.h> |
42 | #include <linux/mm.h> | |
43 | #include <asm/div64.h> | |
44 | #include <linux/seq_file.h> | |
45 | #include <linux/namei.h> | |
e8fd99fd | 46 | #include <linux/uaccess.h> |
d7e09d03 | 47 | |
a8c495ac GKH |
48 | #include "../include/lustre/lustre_idl.h" |
49 | #include "../include/obd_support.h" | |
50 | #include "../include/lustre_lib.h" | |
51 | #include "../include/lustre_net.h" | |
52 | #include "../include/obd_class.h" | |
53 | #include "../include/lprocfs_status.h" | |
54 | #include "../include/lustre_lite.h" | |
55 | #include "../include/lustre_fid.h" | |
d7e09d03 PT |
56 | #include "lmv_internal.h" |
57 | ||
58 | static void lmv_activate_target(struct lmv_obd *lmv, | |
59 | struct lmv_tgt_desc *tgt, | |
60 | int activate) | |
61 | { | |
62 | if (tgt->ltd_active == activate) | |
63 | return; | |
64 | ||
65 | tgt->ltd_active = activate; | |
66 | lmv->desc.ld_active_tgt_count += (activate ? 1 : -1); | |
67 | } | |
68 | ||
69 | /** | |
70 | * Error codes: | |
71 | * | |
72 | * -EINVAL : UUID can't be found in the LMV's target list | |
73 | * -ENOTCONN: The UUID is found, but the target connection is bad (!) | |
74 | * -EBADF : The UUID is found, but the OBD of the wrong type (!) | |
75 | */ | |
76 | static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid, | |
77 | int activate) | |
78 | { | |
73bb1da6 | 79 | struct lmv_tgt_desc *uninitialized_var(tgt); |
d7e09d03 PT |
80 | struct obd_device *obd; |
81 | int i; | |
82 | int rc = 0; | |
d7e09d03 PT |
83 | |
84 | CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n", | |
85 | lmv, uuid->uuid, activate); | |
86 | ||
87 | spin_lock(&lmv->lmv_lock); | |
88 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
89 | tgt = lmv->tgts[i]; | |
90 | if (tgt == NULL || tgt->ltd_exp == NULL) | |
91 | continue; | |
92 | ||
55f5a824 | 93 | CDEBUG(D_INFO, "Target idx %d is %s conn %#llx\n", i, |
d7e09d03 PT |
94 | tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie); |
95 | ||
96 | if (obd_uuid_equals(uuid, &tgt->ltd_uuid)) | |
97 | break; | |
98 | } | |
99 | ||
4d54556f JL |
100 | if (i == lmv->desc.ld_tgt_count) { |
101 | rc = -EINVAL; | |
102 | goto out_lmv_lock; | |
103 | } | |
d7e09d03 PT |
104 | |
105 | obd = class_exp2obd(tgt->ltd_exp); | |
4d54556f JL |
106 | if (obd == NULL) { |
107 | rc = -ENOTCONN; | |
108 | goto out_lmv_lock; | |
109 | } | |
d7e09d03 PT |
110 | |
111 | CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n", | |
112 | obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd, | |
113 | obd->obd_type->typ_name, i); | |
114 | LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0); | |
115 | ||
116 | if (tgt->ltd_active == activate) { | |
117 | CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd, | |
118 | activate ? "" : "in"); | |
4d54556f | 119 | goto out_lmv_lock; |
d7e09d03 PT |
120 | } |
121 | ||
122 | CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd, | |
123 | activate ? "" : "in"); | |
124 | lmv_activate_target(lmv, tgt, activate); | |
d7e09d03 PT |
125 | |
126 | out_lmv_lock: | |
127 | spin_unlock(&lmv->lmv_lock); | |
128 | return rc; | |
129 | } | |
130 | ||
5dc8d7b4 | 131 | static struct obd_uuid *lmv_get_uuid(struct obd_export *exp) |
d7e09d03 PT |
132 | { |
133 | struct lmv_obd *lmv = &exp->exp_obd->u.lmv; | |
134 | ||
135 | return obd_get_uuid(lmv->tgts[0]->ltd_exp); | |
136 | } | |
137 | ||
138 | static int lmv_notify(struct obd_device *obd, struct obd_device *watched, | |
139 | enum obd_notify_event ev, void *data) | |
140 | { | |
141 | struct obd_connect_data *conn_data; | |
142 | struct lmv_obd *lmv = &obd->u.lmv; | |
143 | struct obd_uuid *uuid; | |
144 | int rc = 0; | |
d7e09d03 PT |
145 | |
146 | if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) { | |
147 | CERROR("unexpected notification of %s %s!\n", | |
148 | watched->obd_type->typ_name, | |
149 | watched->obd_name); | |
0a3bdb00 | 150 | return -EINVAL; |
d7e09d03 PT |
151 | } |
152 | ||
153 | uuid = &watched->u.cli.cl_target_uuid; | |
154 | if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) { | |
155 | /* | |
156 | * Set MDC as active before notifying the observer, so the | |
157 | * observer can use the MDC normally. | |
158 | */ | |
159 | rc = lmv_set_mdc_active(lmv, uuid, | |
160 | ev == OBD_NOTIFY_ACTIVE); | |
161 | if (rc) { | |
162 | CERROR("%sactivation of %s failed: %d\n", | |
163 | ev == OBD_NOTIFY_ACTIVE ? "" : "de", | |
164 | uuid->uuid, rc); | |
0a3bdb00 | 165 | return rc; |
d7e09d03 PT |
166 | } |
167 | } else if (ev == OBD_NOTIFY_OCD) { | |
168 | conn_data = &watched->u.cli.cl_import->imp_connect_data; | |
169 | /* | |
170 | * XXX: Make sure that ocd_connect_flags from all targets are | |
171 | * the same. Otherwise one of MDTs runs wrong version or | |
172 | * something like this. --umka | |
173 | */ | |
174 | obd->obd_self_export->exp_connect_data = *conn_data; | |
175 | } | |
176 | #if 0 | |
177 | else if (ev == OBD_NOTIFY_DISCON) { | |
178 | /* | |
179 | * For disconnect event, flush fld cache for failout MDS case. | |
180 | */ | |
181 | fld_client_flush(&lmv->lmv_fld); | |
182 | } | |
183 | #endif | |
184 | /* | |
185 | * Pass the notification up the chain. | |
186 | */ | |
187 | if (obd->obd_observer) | |
188 | rc = obd_notify(obd->obd_observer, watched, ev, data); | |
189 | ||
0a3bdb00 | 190 | return rc; |
d7e09d03 PT |
191 | } |
192 | ||
193 | /** | |
194 | * This is fake connect function. Its purpose is to initialize lmv and say | |
195 | * caller that everything is okay. Real connection will be performed later. | |
196 | */ | |
197 | static int lmv_connect(const struct lu_env *env, | |
198 | struct obd_export **exp, struct obd_device *obd, | |
199 | struct obd_uuid *cluuid, struct obd_connect_data *data, | |
200 | void *localdata) | |
201 | { | |
202 | struct proc_dir_entry *lmv_proc_dir; | |
203 | struct lmv_obd *lmv = &obd->u.lmv; | |
204 | struct lustre_handle conn = { 0 }; | |
205 | int rc = 0; | |
d7e09d03 PT |
206 | |
207 | /* | |
208 | * We don't want to actually do the underlying connections more than | |
209 | * once, so keep track. | |
210 | */ | |
211 | lmv->refcount++; | |
212 | if (lmv->refcount > 1) { | |
213 | *exp = NULL; | |
0a3bdb00 | 214 | return 0; |
d7e09d03 PT |
215 | } |
216 | ||
217 | rc = class_connect(&conn, obd, cluuid); | |
218 | if (rc) { | |
219 | CERROR("class_connection() returned %d\n", rc); | |
0a3bdb00 | 220 | return rc; |
d7e09d03 PT |
221 | } |
222 | ||
223 | *exp = class_conn2export(&conn); | |
224 | class_export_get(*exp); | |
225 | ||
226 | lmv->exp = *exp; | |
227 | lmv->connected = 0; | |
228 | lmv->cluuid = *cluuid; | |
229 | ||
230 | if (data) | |
231 | lmv->conn_data = *data; | |
232 | ||
73bb1da6 PT |
233 | if (obd->obd_proc_private != NULL) { |
234 | lmv_proc_dir = obd->obd_proc_private; | |
235 | } else { | |
236 | lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry, | |
237 | NULL, NULL); | |
238 | if (IS_ERR(lmv_proc_dir)) { | |
239 | CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.", | |
240 | obd->obd_type->typ_name, obd->obd_name); | |
241 | lmv_proc_dir = NULL; | |
242 | } | |
243 | obd->obd_proc_private = lmv_proc_dir; | |
d7e09d03 PT |
244 | } |
245 | ||
246 | /* | |
247 | * All real clients should perform actual connection right away, because | |
248 | * it is possible, that LMV will not have opportunity to connect targets | |
249 | * and MDC stuff will be called directly, for instance while reading | |
250 | * ../mdc/../kbytesfree procfs file, etc. | |
251 | */ | |
252 | if (data->ocd_connect_flags & OBD_CONNECT_REAL) | |
253 | rc = lmv_check_connect(obd); | |
254 | ||
73bb1da6 PT |
255 | if (rc && lmv_proc_dir) { |
256 | lprocfs_remove(&lmv_proc_dir); | |
257 | obd->obd_proc_private = NULL; | |
d7e09d03 PT |
258 | } |
259 | ||
0a3bdb00 | 260 | return rc; |
d7e09d03 PT |
261 | } |
262 | ||
263 | static void lmv_set_timeouts(struct obd_device *obd) | |
264 | { | |
265 | struct lmv_tgt_desc *tgt; | |
266 | struct lmv_obd *lmv; | |
267 | int i; | |
268 | ||
269 | lmv = &obd->u.lmv; | |
270 | if (lmv->server_timeout == 0) | |
271 | return; | |
272 | ||
273 | if (lmv->connected == 0) | |
274 | return; | |
275 | ||
276 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
277 | tgt = lmv->tgts[i]; | |
278 | if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0) | |
279 | continue; | |
280 | ||
281 | obd_set_info_async(NULL, tgt->ltd_exp, sizeof(KEY_INTERMDS), | |
282 | KEY_INTERMDS, 0, NULL, NULL); | |
283 | } | |
284 | } | |
285 | ||
286 | static int lmv_init_ea_size(struct obd_export *exp, int easize, | |
44779340 | 287 | int def_easize, int cookiesize, int def_cookiesize) |
d7e09d03 PT |
288 | { |
289 | struct obd_device *obd = exp->exp_obd; | |
290 | struct lmv_obd *lmv = &obd->u.lmv; | |
291 | int i; | |
292 | int rc = 0; | |
293 | int change = 0; | |
d7e09d03 PT |
294 | |
295 | if (lmv->max_easize < easize) { | |
296 | lmv->max_easize = easize; | |
297 | change = 1; | |
298 | } | |
299 | if (lmv->max_def_easize < def_easize) { | |
300 | lmv->max_def_easize = def_easize; | |
301 | change = 1; | |
302 | } | |
303 | if (lmv->max_cookiesize < cookiesize) { | |
304 | lmv->max_cookiesize = cookiesize; | |
305 | change = 1; | |
306 | } | |
44779340 BB |
307 | if (lmv->max_def_cookiesize < def_cookiesize) { |
308 | lmv->max_def_cookiesize = def_cookiesize; | |
309 | change = 1; | |
310 | } | |
d7e09d03 | 311 | if (change == 0) |
0a3bdb00 | 312 | return 0; |
d7e09d03 PT |
313 | |
314 | if (lmv->connected == 0) | |
0a3bdb00 | 315 | return 0; |
d7e09d03 PT |
316 | |
317 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
318 | if (lmv->tgts[i] == NULL || | |
319 | lmv->tgts[i]->ltd_exp == NULL || | |
320 | lmv->tgts[i]->ltd_active == 0) { | |
321 | CWARN("%s: NULL export for %d\n", obd->obd_name, i); | |
322 | continue; | |
323 | } | |
324 | ||
325 | rc = md_init_ea_size(lmv->tgts[i]->ltd_exp, easize, def_easize, | |
44779340 | 326 | cookiesize, def_cookiesize); |
d7e09d03 | 327 | if (rc) { |
2d00bd17 JP |
328 | CERROR("%s: obd_init_ea_size() failed on MDT target %d: rc = %d.\n", |
329 | obd->obd_name, i, rc); | |
d7e09d03 PT |
330 | break; |
331 | } | |
332 | } | |
0a3bdb00 | 333 | return rc; |
d7e09d03 PT |
334 | } |
335 | ||
336 | #define MAX_STRING_SIZE 128 | |
337 | ||
5dc8d7b4 | 338 | static int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt) |
d7e09d03 PT |
339 | { |
340 | struct proc_dir_entry *lmv_proc_dir; | |
341 | struct lmv_obd *lmv = &obd->u.lmv; | |
342 | struct obd_uuid *cluuid = &lmv->cluuid; | |
343 | struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" }; | |
344 | struct obd_device *mdc_obd; | |
345 | struct obd_export *mdc_exp; | |
346 | struct lu_fld_target target; | |
347 | int rc; | |
d7e09d03 PT |
348 | |
349 | mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME, | |
350 | &obd->obd_uuid); | |
351 | if (!mdc_obd) { | |
352 | CERROR("target %s not attached\n", tgt->ltd_uuid.uuid); | |
0a3bdb00 | 353 | return -EINVAL; |
d7e09d03 PT |
354 | } |
355 | ||
356 | CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n", | |
357 | mdc_obd->obd_name, mdc_obd->obd_uuid.uuid, | |
358 | tgt->ltd_uuid.uuid, obd->obd_uuid.uuid, | |
359 | cluuid->uuid); | |
360 | ||
361 | if (!mdc_obd->obd_set_up) { | |
362 | CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid); | |
0a3bdb00 | 363 | return -EINVAL; |
d7e09d03 PT |
364 | } |
365 | ||
366 | rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid, | |
367 | &lmv->conn_data, NULL); | |
368 | if (rc) { | |
369 | CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc); | |
0a3bdb00 | 370 | return rc; |
d7e09d03 PT |
371 | } |
372 | ||
373 | /* | |
374 | * Init fid sequence client for this mdc and add new fld target. | |
375 | */ | |
376 | rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA); | |
377 | if (rc) | |
0a3bdb00 | 378 | return rc; |
d7e09d03 PT |
379 | |
380 | target.ft_srv = NULL; | |
381 | target.ft_exp = mdc_exp; | |
382 | target.ft_idx = tgt->ltd_idx; | |
383 | ||
384 | fld_client_add_target(&lmv->lmv_fld, &target); | |
385 | ||
386 | rc = obd_register_observer(mdc_obd, obd); | |
387 | if (rc) { | |
388 | obd_disconnect(mdc_exp); | |
389 | CERROR("target %s register_observer error %d\n", | |
390 | tgt->ltd_uuid.uuid, rc); | |
0a3bdb00 | 391 | return rc; |
d7e09d03 PT |
392 | } |
393 | ||
394 | if (obd->obd_observer) { | |
395 | /* | |
396 | * Tell the observer about the new target. | |
397 | */ | |
398 | rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd, | |
399 | OBD_NOTIFY_ACTIVE, | |
400 | (void *)(tgt - lmv->tgts[0])); | |
401 | if (rc) { | |
402 | obd_disconnect(mdc_exp); | |
0a3bdb00 | 403 | return rc; |
d7e09d03 PT |
404 | } |
405 | } | |
406 | ||
407 | tgt->ltd_active = 1; | |
408 | tgt->ltd_exp = mdc_exp; | |
409 | lmv->desc.ld_active_tgt_count++; | |
410 | ||
44779340 BB |
411 | md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize, |
412 | lmv->max_cookiesize, lmv->max_def_cookiesize); | |
d7e09d03 PT |
413 | |
414 | CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n", | |
415 | mdc_obd->obd_name, mdc_obd->obd_uuid.uuid, | |
416 | atomic_read(&obd->obd_refcount)); | |
417 | ||
73bb1da6 | 418 | lmv_proc_dir = obd->obd_proc_private; |
d7e09d03 PT |
419 | if (lmv_proc_dir) { |
420 | struct proc_dir_entry *mdc_symlink; | |
421 | ||
422 | LASSERT(mdc_obd->obd_type != NULL); | |
423 | LASSERT(mdc_obd->obd_type->typ_name != NULL); | |
424 | mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name, | |
425 | lmv_proc_dir, | |
426 | "../../../%s/%s", | |
427 | mdc_obd->obd_type->typ_name, | |
428 | mdc_obd->obd_name); | |
429 | if (mdc_symlink == NULL) { | |
2d00bd17 | 430 | CERROR("Could not register LMV target /proc/fs/lustre/%s/%s/target_obds/%s.", |
d7e09d03 PT |
431 | obd->obd_type->typ_name, obd->obd_name, |
432 | mdc_obd->obd_name); | |
433 | lprocfs_remove(&lmv_proc_dir); | |
73bb1da6 | 434 | obd->obd_proc_private = NULL; |
d7e09d03 PT |
435 | } |
436 | } | |
0a3bdb00 | 437 | return 0; |
d7e09d03 PT |
438 | } |
439 | ||
440 | static void lmv_del_target(struct lmv_obd *lmv, int index) | |
441 | { | |
442 | if (lmv->tgts[index] == NULL) | |
443 | return; | |
444 | ||
8bcf30c3 | 445 | kfree(lmv->tgts[index]); |
d7e09d03 PT |
446 | lmv->tgts[index] = NULL; |
447 | return; | |
448 | } | |
449 | ||
450 | static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp, | |
451 | __u32 index, int gen) | |
452 | { | |
453 | struct lmv_obd *lmv = &obd->u.lmv; | |
454 | struct lmv_tgt_desc *tgt; | |
455 | int rc = 0; | |
d7e09d03 PT |
456 | |
457 | CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index); | |
458 | ||
459 | lmv_init_lock(lmv); | |
460 | ||
461 | if (lmv->desc.ld_tgt_count == 0) { | |
462 | struct obd_device *mdc_obd; | |
463 | ||
464 | mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, | |
465 | &obd->obd_uuid); | |
466 | if (!mdc_obd) { | |
467 | lmv_init_unlock(lmv); | |
468 | CERROR("%s: Target %s not attached: rc = %d\n", | |
469 | obd->obd_name, uuidp->uuid, -EINVAL); | |
0a3bdb00 | 470 | return -EINVAL; |
d7e09d03 PT |
471 | } |
472 | } | |
473 | ||
474 | if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) { | |
475 | tgt = lmv->tgts[index]; | |
2d00bd17 JP |
476 | CERROR("%s: UUID %s already assigned at LOV target index %d: rc = %d\n", |
477 | obd->obd_name, | |
d7e09d03 PT |
478 | obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST); |
479 | lmv_init_unlock(lmv); | |
0a3bdb00 | 480 | return -EEXIST; |
d7e09d03 PT |
481 | } |
482 | ||
483 | if (index >= lmv->tgts_size) { | |
484 | /* We need to reallocate the lmv target array. */ | |
485 | struct lmv_tgt_desc **newtgts, **old = NULL; | |
486 | __u32 newsize = 1; | |
487 | __u32 oldsize = 0; | |
488 | ||
489 | while (newsize < index + 1) | |
302727b6 | 490 | newsize <<= 1; |
8bcf30c3 | 491 | newtgts = kcalloc(newsize, sizeof(*newtgts), GFP_NOFS); |
d7e09d03 PT |
492 | if (newtgts == NULL) { |
493 | lmv_init_unlock(lmv); | |
0a3bdb00 | 494 | return -ENOMEM; |
d7e09d03 PT |
495 | } |
496 | ||
497 | if (lmv->tgts_size) { | |
498 | memcpy(newtgts, lmv->tgts, | |
499 | sizeof(*newtgts) * lmv->tgts_size); | |
500 | old = lmv->tgts; | |
501 | oldsize = lmv->tgts_size; | |
502 | } | |
503 | ||
504 | lmv->tgts = newtgts; | |
505 | lmv->tgts_size = newsize; | |
506 | smp_rmb(); | |
13879e5d | 507 | kfree(old); |
d7e09d03 PT |
508 | |
509 | CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts, | |
510 | lmv->tgts_size); | |
511 | } | |
512 | ||
8bcf30c3 | 513 | tgt = kzalloc(sizeof(*tgt), GFP_NOFS); |
d7e09d03 PT |
514 | if (!tgt) { |
515 | lmv_init_unlock(lmv); | |
0a3bdb00 | 516 | return -ENOMEM; |
d7e09d03 PT |
517 | } |
518 | ||
519 | mutex_init(&tgt->ltd_fid_mutex); | |
520 | tgt->ltd_idx = index; | |
521 | tgt->ltd_uuid = *uuidp; | |
522 | tgt->ltd_active = 0; | |
523 | lmv->tgts[index] = tgt; | |
524 | if (index >= lmv->desc.ld_tgt_count) | |
525 | lmv->desc.ld_tgt_count = index + 1; | |
526 | ||
527 | if (lmv->connected) { | |
528 | rc = lmv_connect_mdc(obd, tgt); | |
529 | if (rc) { | |
530 | spin_lock(&lmv->lmv_lock); | |
531 | lmv->desc.ld_tgt_count--; | |
532 | memset(tgt, 0, sizeof(*tgt)); | |
533 | spin_unlock(&lmv->lmv_lock); | |
534 | } else { | |
535 | int easize = sizeof(struct lmv_stripe_md) + | |
44779340 BB |
536 | lmv->desc.ld_tgt_count * sizeof(struct lu_fid); |
537 | lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0); | |
d7e09d03 PT |
538 | } |
539 | } | |
540 | ||
541 | lmv_init_unlock(lmv); | |
0a3bdb00 | 542 | return rc; |
d7e09d03 PT |
543 | } |
544 | ||
545 | int lmv_check_connect(struct obd_device *obd) | |
546 | { | |
547 | struct lmv_obd *lmv = &obd->u.lmv; | |
548 | struct lmv_tgt_desc *tgt; | |
549 | int i; | |
550 | int rc; | |
551 | int easize; | |
d7e09d03 PT |
552 | |
553 | if (lmv->connected) | |
0a3bdb00 | 554 | return 0; |
d7e09d03 PT |
555 | |
556 | lmv_init_lock(lmv); | |
557 | if (lmv->connected) { | |
558 | lmv_init_unlock(lmv); | |
0a3bdb00 | 559 | return 0; |
d7e09d03 PT |
560 | } |
561 | ||
562 | if (lmv->desc.ld_tgt_count == 0) { | |
563 | lmv_init_unlock(lmv); | |
564 | CERROR("%s: no targets configured.\n", obd->obd_name); | |
0a3bdb00 | 565 | return -EINVAL; |
d7e09d03 PT |
566 | } |
567 | ||
568 | CDEBUG(D_CONFIG, "Time to connect %s to %s\n", | |
569 | lmv->cluuid.uuid, obd->obd_name); | |
570 | ||
571 | LASSERT(lmv->tgts != NULL); | |
572 | ||
573 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
574 | tgt = lmv->tgts[i]; | |
575 | if (tgt == NULL) | |
576 | continue; | |
577 | rc = lmv_connect_mdc(obd, tgt); | |
578 | if (rc) | |
4d54556f | 579 | goto out_disc; |
d7e09d03 PT |
580 | } |
581 | ||
582 | lmv_set_timeouts(obd); | |
583 | class_export_put(lmv->exp); | |
584 | lmv->connected = 1; | |
585 | easize = lmv_get_easize(lmv); | |
44779340 | 586 | lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0); |
d7e09d03 | 587 | lmv_init_unlock(lmv); |
0a3bdb00 | 588 | return 0; |
d7e09d03 PT |
589 | |
590 | out_disc: | |
591 | while (i-- > 0) { | |
592 | int rc2; | |
593 | tgt = lmv->tgts[i]; | |
594 | if (tgt == NULL) | |
595 | continue; | |
596 | tgt->ltd_active = 0; | |
597 | if (tgt->ltd_exp) { | |
598 | --lmv->desc.ld_active_tgt_count; | |
599 | rc2 = obd_disconnect(tgt->ltd_exp); | |
600 | if (rc2) { | |
2d00bd17 | 601 | CERROR("LMV target %s disconnect on MDC idx %d: error %d\n", |
d7e09d03 PT |
602 | tgt->ltd_uuid.uuid, i, rc2); |
603 | } | |
604 | } | |
605 | } | |
606 | class_disconnect(lmv->exp); | |
607 | lmv_init_unlock(lmv); | |
0a3bdb00 | 608 | return rc; |
d7e09d03 PT |
609 | } |
610 | ||
611 | static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt) | |
612 | { | |
613 | struct proc_dir_entry *lmv_proc_dir; | |
614 | struct lmv_obd *lmv = &obd->u.lmv; | |
615 | struct obd_device *mdc_obd; | |
616 | int rc; | |
d7e09d03 PT |
617 | |
618 | LASSERT(tgt != NULL); | |
619 | LASSERT(obd != NULL); | |
620 | ||
621 | mdc_obd = class_exp2obd(tgt->ltd_exp); | |
622 | ||
623 | if (mdc_obd) { | |
624 | mdc_obd->obd_force = obd->obd_force; | |
625 | mdc_obd->obd_fail = obd->obd_fail; | |
626 | mdc_obd->obd_no_recov = obd->obd_no_recov; | |
627 | } | |
628 | ||
73bb1da6 PT |
629 | lmv_proc_dir = obd->obd_proc_private; |
630 | if (lmv_proc_dir) | |
631 | lprocfs_remove_proc_entry(mdc_obd->obd_name, lmv_proc_dir); | |
d7e09d03 | 632 | |
d7e09d03 PT |
633 | rc = obd_fid_fini(tgt->ltd_exp->exp_obd); |
634 | if (rc) | |
b64767de | 635 | CERROR("Can't finalize fids factory\n"); |
d7e09d03 PT |
636 | |
637 | CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n", | |
638 | tgt->ltd_exp->exp_obd->obd_name, | |
639 | tgt->ltd_exp->exp_obd->obd_uuid.uuid); | |
640 | ||
641 | obd_register_observer(tgt->ltd_exp->exp_obd, NULL); | |
642 | rc = obd_disconnect(tgt->ltd_exp); | |
643 | if (rc) { | |
644 | if (tgt->ltd_active) { | |
645 | CERROR("Target %s disconnect error %d\n", | |
646 | tgt->ltd_uuid.uuid, rc); | |
647 | } | |
648 | } | |
649 | ||
650 | lmv_activate_target(lmv, tgt, 0); | |
651 | tgt->ltd_exp = NULL; | |
0a3bdb00 | 652 | return 0; |
d7e09d03 PT |
653 | } |
654 | ||
655 | static int lmv_disconnect(struct obd_export *exp) | |
656 | { | |
657 | struct obd_device *obd = class_exp2obd(exp); | |
d7e09d03 PT |
658 | struct lmv_obd *lmv = &obd->u.lmv; |
659 | int rc; | |
660 | int i; | |
d7e09d03 PT |
661 | |
662 | if (!lmv->tgts) | |
663 | goto out_local; | |
664 | ||
665 | /* | |
666 | * Only disconnect the underlying layers on the final disconnect. | |
667 | */ | |
668 | lmv->refcount--; | |
669 | if (lmv->refcount != 0) | |
670 | goto out_local; | |
671 | ||
672 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
673 | if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL) | |
674 | continue; | |
675 | ||
676 | lmv_disconnect_mdc(obd, lmv->tgts[i]); | |
677 | } | |
678 | ||
73bb1da6 | 679 | if (obd->obd_proc_private) |
b59fe845 | 680 | lprocfs_remove((struct proc_dir_entry **)&obd->obd_proc_private); |
73bb1da6 | 681 | else |
d7e09d03 PT |
682 | CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n", |
683 | obd->obd_type->typ_name, obd->obd_name); | |
d7e09d03 PT |
684 | |
685 | out_local: | |
686 | /* | |
687 | * This is the case when no real connection is established by | |
688 | * lmv_check_connect(). | |
689 | */ | |
690 | if (!lmv->connected) | |
691 | class_export_put(exp); | |
692 | rc = class_disconnect(exp); | |
693 | if (lmv->refcount == 0) | |
694 | lmv->connected = 0; | |
0a3bdb00 | 695 | return rc; |
d7e09d03 PT |
696 | } |
697 | ||
698 | static int lmv_fid2path(struct obd_export *exp, int len, void *karg, void *uarg) | |
699 | { | |
700 | struct obd_device *obddev = class_exp2obd(exp); | |
701 | struct lmv_obd *lmv = &obddev->u.lmv; | |
702 | struct getinfo_fid2path *gf; | |
703 | struct lmv_tgt_desc *tgt; | |
704 | struct getinfo_fid2path *remote_gf = NULL; | |
705 | int remote_gf_size = 0; | |
706 | int rc; | |
707 | ||
708 | gf = (struct getinfo_fid2path *)karg; | |
709 | tgt = lmv_find_target(lmv, &gf->gf_fid); | |
710 | if (IS_ERR(tgt)) | |
0a3bdb00 | 711 | return PTR_ERR(tgt); |
d7e09d03 PT |
712 | |
713 | repeat_fid2path: | |
714 | rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg); | |
715 | if (rc != 0 && rc != -EREMOTE) | |
4d54556f | 716 | goto out_fid2path; |
d7e09d03 PT |
717 | |
718 | /* If remote_gf != NULL, it means just building the | |
b64767de | 719 | * path on the remote MDT, copy this path segment to gf */ |
d7e09d03 PT |
720 | if (remote_gf != NULL) { |
721 | struct getinfo_fid2path *ori_gf; | |
722 | char *ptr; | |
723 | ||
724 | ori_gf = (struct getinfo_fid2path *)karg; | |
725 | if (strlen(ori_gf->gf_path) + | |
4d54556f JL |
726 | strlen(gf->gf_path) > ori_gf->gf_pathlen) { |
727 | rc = -EOVERFLOW; | |
728 | goto out_fid2path; | |
729 | } | |
d7e09d03 PT |
730 | |
731 | ptr = ori_gf->gf_path; | |
732 | ||
733 | memmove(ptr + strlen(gf->gf_path) + 1, ptr, | |
734 | strlen(ori_gf->gf_path)); | |
735 | ||
736 | strncpy(ptr, gf->gf_path, strlen(gf->gf_path)); | |
737 | ptr += strlen(gf->gf_path); | |
738 | *ptr = '/'; | |
739 | } | |
740 | ||
b0f5aad5 | 741 | CDEBUG(D_INFO, "%s: get path %s "DFID" rec: %llu ln: %u\n", |
d7e09d03 PT |
742 | tgt->ltd_exp->exp_obd->obd_name, |
743 | gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno, | |
744 | gf->gf_linkno); | |
745 | ||
746 | if (rc == 0) | |
4d54556f | 747 | goto out_fid2path; |
d7e09d03 PT |
748 | |
749 | /* sigh, has to go to another MDT to do path building further */ | |
750 | if (remote_gf == NULL) { | |
751 | remote_gf_size = sizeof(*remote_gf) + PATH_MAX; | |
8bcf30c3 | 752 | remote_gf = kzalloc(remote_gf_size, GFP_NOFS); |
4d54556f JL |
753 | if (remote_gf == NULL) { |
754 | rc = -ENOMEM; | |
755 | goto out_fid2path; | |
756 | } | |
d7e09d03 PT |
757 | remote_gf->gf_pathlen = PATH_MAX; |
758 | } | |
759 | ||
760 | if (!fid_is_sane(&gf->gf_fid)) { | |
761 | CERROR("%s: invalid FID "DFID": rc = %d\n", | |
762 | tgt->ltd_exp->exp_obd->obd_name, | |
763 | PFID(&gf->gf_fid), -EINVAL); | |
4d54556f JL |
764 | rc = -EINVAL; |
765 | goto out_fid2path; | |
d7e09d03 PT |
766 | } |
767 | ||
768 | tgt = lmv_find_target(lmv, &gf->gf_fid); | |
4d54556f JL |
769 | if (IS_ERR(tgt)) { |
770 | rc = -EINVAL; | |
771 | goto out_fid2path; | |
772 | } | |
d7e09d03 PT |
773 | |
774 | remote_gf->gf_fid = gf->gf_fid; | |
775 | remote_gf->gf_recno = -1; | |
776 | remote_gf->gf_linkno = -1; | |
777 | memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen); | |
778 | gf = remote_gf; | |
779 | goto repeat_fid2path; | |
780 | ||
781 | out_fid2path: | |
13879e5d | 782 | kfree(remote_gf); |
0a3bdb00 | 783 | return rc; |
d7e09d03 PT |
784 | } |
785 | ||
78eb9092 TL |
786 | static int lmv_hsm_req_count(struct lmv_obd *lmv, |
787 | const struct hsm_user_request *hur, | |
788 | const struct lmv_tgt_desc *tgt_mds) | |
789 | { | |
790 | int i, nr = 0; | |
791 | struct lmv_tgt_desc *curr_tgt; | |
792 | ||
793 | /* count how many requests must be sent to the given target */ | |
794 | for (i = 0; i < hur->hur_request.hr_itemcount; i++) { | |
795 | curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid); | |
796 | if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) | |
797 | nr++; | |
798 | } | |
799 | return nr; | |
800 | } | |
801 | ||
802 | static void lmv_hsm_req_build(struct lmv_obd *lmv, | |
803 | struct hsm_user_request *hur_in, | |
804 | const struct lmv_tgt_desc *tgt_mds, | |
805 | struct hsm_user_request *hur_out) | |
806 | { | |
807 | int i, nr_out; | |
808 | struct lmv_tgt_desc *curr_tgt; | |
809 | ||
810 | /* build the hsm_user_request for the given target */ | |
811 | hur_out->hur_request = hur_in->hur_request; | |
812 | nr_out = 0; | |
813 | for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) { | |
814 | curr_tgt = lmv_find_target(lmv, | |
815 | &hur_in->hur_user_item[i].hui_fid); | |
816 | if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) { | |
817 | hur_out->hur_user_item[nr_out] = | |
818 | hur_in->hur_user_item[i]; | |
819 | nr_out++; | |
820 | } | |
821 | } | |
822 | hur_out->hur_request.hr_itemcount = nr_out; | |
823 | memcpy(hur_data(hur_out), hur_data(hur_in), | |
824 | hur_in->hur_request.hr_data_len); | |
825 | } | |
826 | ||
827 | static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len, | |
828 | struct lustre_kernelcomm *lk, void *uarg) | |
829 | { | |
830 | int i, rc = 0; | |
78eb9092 TL |
831 | |
832 | /* unregister request (call from llapi_hsm_copytool_fini) */ | |
833 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
834 | /* best effort: try to clean as much as possible | |
835 | * (continue on error) */ | |
836 | obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, len, lk, uarg); | |
837 | } | |
838 | ||
839 | /* Whatever the result, remove copytool from kuc groups. | |
840 | * Unreached coordinators will get EPIPE on next requests | |
841 | * and will unregister automatically. | |
842 | */ | |
843 | rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group); | |
0a3bdb00 | 844 | return rc; |
78eb9092 TL |
845 | } |
846 | ||
847 | static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len, | |
848 | struct lustre_kernelcomm *lk, void *uarg) | |
849 | { | |
850 | struct file *filp; | |
851 | int i, j, err; | |
852 | int rc = 0; | |
853 | bool any_set = false; | |
78eb9092 TL |
854 | |
855 | /* All or nothing: try to register to all MDS. | |
856 | * In case of failure, unregister from previous MDS, | |
857 | * except if it because of inactive target. */ | |
858 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
859 | err = obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, | |
860 | len, lk, uarg); | |
861 | if (err) { | |
862 | if (lmv->tgts[i]->ltd_active) { | |
863 | /* permanent error */ | |
2d00bd17 JP |
864 | CERROR("error: iocontrol MDC %s on MDTidx %d cmd %x: err = %d\n", |
865 | lmv->tgts[i]->ltd_uuid.uuid, | |
866 | i, cmd, err); | |
78eb9092 TL |
867 | rc = err; |
868 | lk->lk_flags |= LK_FLG_STOP; | |
869 | /* unregister from previous MDS */ | |
870 | for (j = 0; j < i; j++) | |
871 | obd_iocontrol(cmd, | |
872 | lmv->tgts[j]->ltd_exp, | |
873 | len, lk, uarg); | |
0a3bdb00 | 874 | return rc; |
78eb9092 TL |
875 | } |
876 | /* else: transient error. | |
877 | * kuc will register to the missing MDT | |
878 | * when it is back */ | |
879 | } else { | |
880 | any_set = true; | |
881 | } | |
882 | } | |
883 | ||
884 | if (!any_set) | |
885 | /* no registration done: return error */ | |
0a3bdb00 | 886 | return -ENOTCONN; |
78eb9092 TL |
887 | |
888 | /* at least one registration done, with no failure */ | |
889 | filp = fget(lk->lk_wfd); | |
890 | if (filp == NULL) { | |
0a3bdb00 | 891 | return -EBADF; |
78eb9092 TL |
892 | } |
893 | rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group, lk->lk_data); | |
894 | if (rc != 0 && filp != NULL) | |
895 | fput(filp); | |
0a3bdb00 | 896 | return rc; |
78eb9092 TL |
897 | } |
898 | ||
899 | ||
900 | ||
901 | ||
d7e09d03 PT |
902 | static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp, |
903 | int len, void *karg, void *uarg) | |
904 | { | |
905 | struct obd_device *obddev = class_exp2obd(exp); | |
906 | struct lmv_obd *lmv = &obddev->u.lmv; | |
907 | int i = 0; | |
908 | int rc = 0; | |
909 | int set = 0; | |
910 | int count = lmv->desc.ld_tgt_count; | |
d7e09d03 PT |
911 | |
912 | if (count == 0) | |
0a3bdb00 | 913 | return -ENOTTY; |
d7e09d03 PT |
914 | |
915 | switch (cmd) { | |
916 | case IOC_OBD_STATFS: { | |
917 | struct obd_ioctl_data *data = karg; | |
918 | struct obd_device *mdc_obd; | |
919 | struct obd_statfs stat_buf = {0}; | |
920 | __u32 index; | |
921 | ||
922 | memcpy(&index, data->ioc_inlbuf2, sizeof(__u32)); | |
dbd18138 | 923 | if (index >= count) |
0a3bdb00 | 924 | return -ENODEV; |
d7e09d03 PT |
925 | |
926 | if (lmv->tgts[index] == NULL || | |
927 | lmv->tgts[index]->ltd_active == 0) | |
0a3bdb00 | 928 | return -ENODATA; |
d7e09d03 PT |
929 | |
930 | mdc_obd = class_exp2obd(lmv->tgts[index]->ltd_exp); | |
931 | if (!mdc_obd) | |
0a3bdb00 | 932 | return -EINVAL; |
d7e09d03 PT |
933 | |
934 | /* copy UUID */ | |
935 | if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd), | |
936 | min((int) data->ioc_plen2, | |
937 | (int) sizeof(struct obd_uuid)))) | |
0a3bdb00 | 938 | return -EFAULT; |
d7e09d03 PT |
939 | |
940 | rc = obd_statfs(NULL, lmv->tgts[index]->ltd_exp, &stat_buf, | |
941 | cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), | |
942 | 0); | |
943 | if (rc) | |
0a3bdb00 | 944 | return rc; |
d7e09d03 PT |
945 | if (copy_to_user(data->ioc_pbuf1, &stat_buf, |
946 | min((int) data->ioc_plen1, | |
947 | (int) sizeof(stat_buf)))) | |
0a3bdb00 | 948 | return -EFAULT; |
d7e09d03 PT |
949 | break; |
950 | } | |
951 | case OBD_IOC_QUOTACTL: { | |
952 | struct if_quotactl *qctl = karg; | |
953 | struct lmv_tgt_desc *tgt = NULL; | |
954 | struct obd_quotactl *oqctl; | |
955 | ||
956 | if (qctl->qc_valid == QC_MDTIDX) { | |
957 | if (qctl->qc_idx < 0 || count <= qctl->qc_idx) | |
0a3bdb00 | 958 | return -EINVAL; |
d7e09d03 PT |
959 | |
960 | tgt = lmv->tgts[qctl->qc_idx]; | |
961 | if (tgt == NULL || tgt->ltd_exp == NULL) | |
0a3bdb00 | 962 | return -EINVAL; |
d7e09d03 PT |
963 | } else if (qctl->qc_valid == QC_UUID) { |
964 | for (i = 0; i < count; i++) { | |
965 | tgt = lmv->tgts[i]; | |
966 | if (tgt == NULL) | |
967 | continue; | |
968 | if (!obd_uuid_equals(&tgt->ltd_uuid, | |
969 | &qctl->obd_uuid)) | |
970 | continue; | |
971 | ||
972 | if (tgt->ltd_exp == NULL) | |
0a3bdb00 | 973 | return -EINVAL; |
d7e09d03 PT |
974 | |
975 | break; | |
976 | } | |
977 | } else { | |
0a3bdb00 | 978 | return -EINVAL; |
d7e09d03 PT |
979 | } |
980 | ||
981 | if (i >= count) | |
0a3bdb00 | 982 | return -EAGAIN; |
d7e09d03 PT |
983 | |
984 | LASSERT(tgt && tgt->ltd_exp); | |
8bcf30c3 | 985 | oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS); |
d7e09d03 | 986 | if (!oqctl) |
0a3bdb00 | 987 | return -ENOMEM; |
d7e09d03 PT |
988 | |
989 | QCTL_COPY(oqctl, qctl); | |
990 | rc = obd_quotactl(tgt->ltd_exp, oqctl); | |
991 | if (rc == 0) { | |
992 | QCTL_COPY(qctl, oqctl); | |
993 | qctl->qc_valid = QC_MDTIDX; | |
994 | qctl->obd_uuid = tgt->ltd_uuid; | |
995 | } | |
8bcf30c3 | 996 | kfree(oqctl); |
d7e09d03 PT |
997 | break; |
998 | } | |
999 | case OBD_IOC_CHANGELOG_SEND: | |
1000 | case OBD_IOC_CHANGELOG_CLEAR: { | |
1001 | struct ioc_changelog *icc = karg; | |
1002 | ||
1003 | if (icc->icc_mdtindex >= count) | |
0a3bdb00 | 1004 | return -ENODEV; |
d7e09d03 PT |
1005 | |
1006 | if (lmv->tgts[icc->icc_mdtindex] == NULL || | |
1007 | lmv->tgts[icc->icc_mdtindex]->ltd_exp == NULL || | |
1008 | lmv->tgts[icc->icc_mdtindex]->ltd_active == 0) | |
0a3bdb00 | 1009 | return -ENODEV; |
d7e09d03 PT |
1010 | rc = obd_iocontrol(cmd, lmv->tgts[icc->icc_mdtindex]->ltd_exp, |
1011 | sizeof(*icc), icc, NULL); | |
1012 | break; | |
1013 | } | |
1014 | case LL_IOC_GET_CONNECT_FLAGS: { | |
1015 | if (lmv->tgts[0] == NULL) | |
0a3bdb00 | 1016 | return -ENODATA; |
d7e09d03 PT |
1017 | rc = obd_iocontrol(cmd, lmv->tgts[0]->ltd_exp, len, karg, uarg); |
1018 | break; | |
1019 | } | |
1020 | case OBD_IOC_FID2PATH: { | |
1021 | rc = lmv_fid2path(exp, len, karg, uarg); | |
1022 | break; | |
1023 | } | |
1024 | case LL_IOC_HSM_STATE_GET: | |
1025 | case LL_IOC_HSM_STATE_SET: | |
78eb9092 TL |
1026 | case LL_IOC_HSM_ACTION: { |
1027 | struct md_op_data *op_data = karg; | |
1028 | struct lmv_tgt_desc *tgt; | |
1029 | ||
1030 | tgt = lmv_find_target(lmv, &op_data->op_fid1); | |
1031 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1032 | return PTR_ERR(tgt); |
78eb9092 TL |
1033 | |
1034 | if (tgt->ltd_exp == NULL) | |
0a3bdb00 | 1035 | return -EINVAL; |
78eb9092 TL |
1036 | |
1037 | rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg); | |
1038 | break; | |
1039 | } | |
1040 | case LL_IOC_HSM_PROGRESS: { | |
1041 | const struct hsm_progress_kernel *hpk = karg; | |
1042 | struct lmv_tgt_desc *tgt; | |
1043 | ||
1044 | tgt = lmv_find_target(lmv, &hpk->hpk_fid); | |
1045 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1046 | return PTR_ERR(tgt); |
78eb9092 TL |
1047 | rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg); |
1048 | break; | |
1049 | } | |
1050 | case LL_IOC_HSM_REQUEST: { | |
1051 | struct hsm_user_request *hur = karg; | |
1052 | struct lmv_tgt_desc *tgt; | |
1053 | unsigned int reqcount = hur->hur_request.hr_itemcount; | |
1054 | ||
1055 | if (reqcount == 0) | |
0a3bdb00 | 1056 | return 0; |
78eb9092 TL |
1057 | |
1058 | /* if the request is about a single fid | |
1059 | * or if there is a single MDS, no need to split | |
1060 | * the request. */ | |
1061 | if (reqcount == 1 || count == 1) { | |
1062 | tgt = lmv_find_target(lmv, | |
1063 | &hur->hur_user_item[0].hui_fid); | |
1064 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1065 | return PTR_ERR(tgt); |
78eb9092 TL |
1066 | rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg); |
1067 | } else { | |
1068 | /* split fid list to their respective MDS */ | |
1069 | for (i = 0; i < count; i++) { | |
1070 | unsigned int nr, reqlen; | |
1071 | int rc1; | |
1072 | struct hsm_user_request *req; | |
1073 | ||
1074 | nr = lmv_hsm_req_count(lmv, hur, lmv->tgts[i]); | |
1075 | if (nr == 0) /* nothing for this MDS */ | |
1076 | continue; | |
1077 | ||
1078 | /* build a request with fids for this MDS */ | |
1079 | reqlen = offsetof(typeof(*hur), | |
1080 | hur_user_item[nr]) | |
1081 | + hur->hur_request.hr_data_len; | |
1082 | OBD_ALLOC_LARGE(req, reqlen); | |
1083 | if (req == NULL) | |
0a3bdb00 | 1084 | return -ENOMEM; |
78eb9092 TL |
1085 | |
1086 | lmv_hsm_req_build(lmv, hur, lmv->tgts[i], req); | |
1087 | ||
1088 | rc1 = obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, | |
1089 | reqlen, req, uarg); | |
1090 | if (rc1 != 0 && rc == 0) | |
1091 | rc = rc1; | |
1092 | OBD_FREE_LARGE(req, reqlen); | |
1093 | } | |
1094 | } | |
1095 | break; | |
1096 | } | |
d7e09d03 PT |
1097 | case LL_IOC_LOV_SWAP_LAYOUTS: { |
1098 | struct md_op_data *op_data = karg; | |
1099 | struct lmv_tgt_desc *tgt1, *tgt2; | |
1100 | ||
1101 | tgt1 = lmv_find_target(lmv, &op_data->op_fid1); | |
1102 | if (IS_ERR(tgt1)) | |
0a3bdb00 | 1103 | return PTR_ERR(tgt1); |
d7e09d03 PT |
1104 | |
1105 | tgt2 = lmv_find_target(lmv, &op_data->op_fid2); | |
1106 | if (IS_ERR(tgt2)) | |
0a3bdb00 | 1107 | return PTR_ERR(tgt2); |
d7e09d03 PT |
1108 | |
1109 | if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL)) | |
0a3bdb00 | 1110 | return -EINVAL; |
d7e09d03 PT |
1111 | |
1112 | /* only files on same MDT can have their layouts swapped */ | |
1113 | if (tgt1->ltd_idx != tgt2->ltd_idx) | |
0a3bdb00 | 1114 | return -EPERM; |
d7e09d03 PT |
1115 | |
1116 | rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg); | |
1117 | break; | |
1118 | } | |
78eb9092 TL |
1119 | case LL_IOC_HSM_CT_START: { |
1120 | struct lustre_kernelcomm *lk = karg; | |
1121 | if (lk->lk_flags & LK_FLG_STOP) | |
1122 | rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg); | |
1123 | else | |
1124 | rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg); | |
1125 | break; | |
1126 | } | |
d7e09d03 PT |
1127 | default: |
1128 | for (i = 0; i < count; i++) { | |
1129 | struct obd_device *mdc_obd; | |
1130 | int err; | |
1131 | ||
1132 | if (lmv->tgts[i] == NULL || | |
1133 | lmv->tgts[i]->ltd_exp == NULL) | |
1134 | continue; | |
1135 | /* ll_umount_begin() sets force flag but for lmv, not | |
1136 | * mdc. Let's pass it through */ | |
1137 | mdc_obd = class_exp2obd(lmv->tgts[i]->ltd_exp); | |
1138 | mdc_obd->obd_force = obddev->obd_force; | |
1139 | err = obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, len, | |
1140 | karg, uarg); | |
1141 | if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) { | |
0a3bdb00 | 1142 | return err; |
d7e09d03 PT |
1143 | } else if (err) { |
1144 | if (lmv->tgts[i]->ltd_active) { | |
2d00bd17 JP |
1145 | CERROR("error: iocontrol MDC %s on MDTidx %d cmd %x: err = %d\n", |
1146 | lmv->tgts[i]->ltd_uuid.uuid, | |
1147 | i, cmd, err); | |
d7e09d03 PT |
1148 | if (!rc) |
1149 | rc = err; | |
1150 | } | |
1151 | } else | |
1152 | set = 1; | |
1153 | } | |
1154 | if (!set && !rc) | |
1155 | rc = -EIO; | |
1156 | } | |
0a3bdb00 | 1157 | return rc; |
d7e09d03 PT |
1158 | } |
1159 | ||
1160 | #if 0 | |
1161 | static int lmv_all_chars_policy(int count, const char *name, | |
1162 | int len) | |
1163 | { | |
1164 | unsigned int c = 0; | |
1165 | ||
1166 | while (len > 0) | |
1167 | c += name[--len]; | |
1168 | c = c % count; | |
1169 | return c; | |
1170 | } | |
1171 | ||
1172 | static int lmv_nid_policy(struct lmv_obd *lmv) | |
1173 | { | |
1174 | struct obd_import *imp; | |
1175 | __u32 id; | |
1176 | ||
1177 | /* | |
1178 | * XXX: To get nid we assume that underlying obd device is mdc. | |
1179 | */ | |
1180 | imp = class_exp2cliimp(lmv->tgts[0].ltd_exp); | |
1181 | id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32); | |
1182 | return id % lmv->desc.ld_tgt_count; | |
1183 | } | |
1184 | ||
1185 | static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data, | |
fe672997 | 1186 | enum placement_policy placement) |
d7e09d03 PT |
1187 | { |
1188 | switch (placement) { | |
1189 | case PLACEMENT_CHAR_POLICY: | |
1190 | return lmv_all_chars_policy(lmv->desc.ld_tgt_count, | |
1191 | op_data->op_name, | |
1192 | op_data->op_namelen); | |
1193 | case PLACEMENT_NID_POLICY: | |
1194 | return lmv_nid_policy(lmv); | |
1195 | ||
1196 | default: | |
1197 | break; | |
1198 | } | |
1199 | ||
1200 | CERROR("Unsupported placement policy %x\n", placement); | |
1201 | return -EINVAL; | |
1202 | } | |
1203 | #endif | |
1204 | ||
1205 | /** | |
1206 | * This is _inode_ placement policy function (not name). | |
1207 | */ | |
1208 | static int lmv_placement_policy(struct obd_device *obd, | |
114acca8 | 1209 | struct md_op_data *op_data, u32 *mds) |
d7e09d03 PT |
1210 | { |
1211 | struct lmv_obd *lmv = &obd->u.lmv; | |
d7e09d03 PT |
1212 | |
1213 | LASSERT(mds != NULL); | |
1214 | ||
1215 | if (lmv->desc.ld_tgt_count == 1) { | |
1216 | *mds = 0; | |
0a3bdb00 | 1217 | return 0; |
d7e09d03 PT |
1218 | } |
1219 | ||
1220 | /** | |
1221 | * If stripe_offset is provided during setdirstripe | |
b64767de | 1222 | * (setdirstripe -i xx), xx MDS will be chosen. |
d7e09d03 PT |
1223 | */ |
1224 | if (op_data->op_cli_flags & CLI_SET_MEA) { | |
1225 | struct lmv_user_md *lum; | |
1226 | ||
1227 | lum = (struct lmv_user_md *)op_data->op_data; | |
1228 | if (lum->lum_type == LMV_STRIPE_TYPE && | |
1229 | lum->lum_stripe_offset != -1) { | |
1230 | if (lum->lum_stripe_offset >= lmv->desc.ld_tgt_count) { | |
2d00bd17 JP |
1231 | CERROR("%s: Stripe_offset %d > MDT count %d: rc = %d\n", |
1232 | obd->obd_name, | |
d7e09d03 PT |
1233 | lum->lum_stripe_offset, |
1234 | lmv->desc.ld_tgt_count, -ERANGE); | |
0a3bdb00 | 1235 | return -ERANGE; |
d7e09d03 PT |
1236 | } |
1237 | *mds = lum->lum_stripe_offset; | |
0a3bdb00 | 1238 | return 0; |
d7e09d03 PT |
1239 | } |
1240 | } | |
1241 | ||
1242 | /* Allocate new fid on target according to operation type and parent | |
1243 | * home mds. */ | |
1244 | *mds = op_data->op_mds; | |
0a3bdb00 | 1245 | return 0; |
d7e09d03 PT |
1246 | } |
1247 | ||
114acca8 | 1248 | int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds) |
d7e09d03 PT |
1249 | { |
1250 | struct lmv_tgt_desc *tgt; | |
1251 | int rc; | |
d7e09d03 PT |
1252 | |
1253 | tgt = lmv_get_target(lmv, mds); | |
1254 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1255 | return PTR_ERR(tgt); |
d7e09d03 PT |
1256 | |
1257 | /* | |
1258 | * New seq alloc and FLD setup should be atomic. Otherwise we may find | |
1259 | * on server that seq in new allocated fid is not yet known. | |
1260 | */ | |
1261 | mutex_lock(&tgt->ltd_fid_mutex); | |
1262 | ||
4d54556f JL |
1263 | if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL) { |
1264 | rc = -ENODEV; | |
1265 | goto out; | |
1266 | } | |
d7e09d03 PT |
1267 | |
1268 | /* | |
1269 | * Asking underlaying tgt layer to allocate new fid. | |
1270 | */ | |
1271 | rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL); | |
1272 | if (rc > 0) { | |
1273 | LASSERT(fid_is_sane(fid)); | |
1274 | rc = 0; | |
1275 | } | |
1276 | ||
d7e09d03 PT |
1277 | out: |
1278 | mutex_unlock(&tgt->ltd_fid_mutex); | |
1279 | return rc; | |
1280 | } | |
1281 | ||
1282 | int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid, | |
1283 | struct md_op_data *op_data) | |
1284 | { | |
1285 | struct obd_device *obd = class_exp2obd(exp); | |
1286 | struct lmv_obd *lmv = &obd->u.lmv; | |
114acca8 | 1287 | u32 mds = 0; |
d7e09d03 | 1288 | int rc; |
d7e09d03 PT |
1289 | |
1290 | LASSERT(op_data != NULL); | |
1291 | LASSERT(fid != NULL); | |
1292 | ||
1293 | rc = lmv_placement_policy(obd, op_data, &mds); | |
1294 | if (rc) { | |
2d00bd17 JP |
1295 | CERROR("Can't get target for allocating fid, rc %d\n", |
1296 | rc); | |
0a3bdb00 | 1297 | return rc; |
d7e09d03 PT |
1298 | } |
1299 | ||
1300 | rc = __lmv_fid_alloc(lmv, fid, mds); | |
1301 | if (rc) { | |
1302 | CERROR("Can't alloc new fid, rc %d\n", rc); | |
0a3bdb00 | 1303 | return rc; |
d7e09d03 PT |
1304 | } |
1305 | ||
0a3bdb00 | 1306 | return rc; |
d7e09d03 PT |
1307 | } |
1308 | ||
1309 | static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg) | |
1310 | { | |
1311 | struct lmv_obd *lmv = &obd->u.lmv; | |
1312 | struct lprocfs_static_vars lvars; | |
1313 | struct lmv_desc *desc; | |
1314 | int rc; | |
d7e09d03 PT |
1315 | |
1316 | if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) { | |
1317 | CERROR("LMV setup requires a descriptor\n"); | |
0a3bdb00 | 1318 | return -EINVAL; |
d7e09d03 PT |
1319 | } |
1320 | ||
1321 | desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1); | |
1322 | if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) { | |
1323 | CERROR("Lmv descriptor size wrong: %d > %d\n", | |
1324 | (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1)); | |
0a3bdb00 | 1325 | return -EINVAL; |
d7e09d03 PT |
1326 | } |
1327 | ||
8bcf30c3 | 1328 | lmv->tgts = kcalloc(32, sizeof(*lmv->tgts), GFP_NOFS); |
d7e09d03 | 1329 | if (lmv->tgts == NULL) |
0a3bdb00 | 1330 | return -ENOMEM; |
d7e09d03 PT |
1331 | lmv->tgts_size = 32; |
1332 | ||
1333 | obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid); | |
1334 | lmv->desc.ld_tgt_count = 0; | |
1335 | lmv->desc.ld_active_tgt_count = 0; | |
1336 | lmv->max_cookiesize = 0; | |
1337 | lmv->max_def_easize = 0; | |
1338 | lmv->max_easize = 0; | |
1339 | lmv->lmv_placement = PLACEMENT_CHAR_POLICY; | |
1340 | ||
1341 | spin_lock_init(&lmv->lmv_lock); | |
1342 | mutex_init(&lmv->init_mutex); | |
1343 | ||
1344 | lprocfs_lmv_init_vars(&lvars); | |
1345 | ||
1346 | lprocfs_obd_setup(obd, lvars.obd_vars); | |
f267cdb4 | 1347 | #if defined (CONFIG_PROC_FS) |
d7e09d03 PT |
1348 | { |
1349 | rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd", | |
1350 | 0444, &lmv_proc_target_fops, obd); | |
1351 | if (rc) | |
1352 | CWARN("%s: error adding LMV target_obd file: rc = %d\n", | |
1353 | obd->obd_name, rc); | |
1354 | } | |
1355 | #endif | |
1356 | rc = fld_client_init(&lmv->lmv_fld, obd->obd_name, | |
1357 | LUSTRE_CLI_FLD_HASH_DHT); | |
1358 | if (rc) { | |
1359 | CERROR("Can't init FLD, err %d\n", rc); | |
4d54556f | 1360 | goto out; |
d7e09d03 PT |
1361 | } |
1362 | ||
0a3bdb00 | 1363 | return 0; |
d7e09d03 PT |
1364 | |
1365 | out: | |
1366 | return rc; | |
1367 | } | |
1368 | ||
1369 | static int lmv_cleanup(struct obd_device *obd) | |
1370 | { | |
1371 | struct lmv_obd *lmv = &obd->u.lmv; | |
d7e09d03 PT |
1372 | |
1373 | fld_client_fini(&lmv->lmv_fld); | |
1374 | if (lmv->tgts != NULL) { | |
1375 | int i; | |
1376 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
1377 | if (lmv->tgts[i] == NULL) | |
1378 | continue; | |
1379 | lmv_del_target(lmv, i); | |
1380 | } | |
8bcf30c3 | 1381 | kfree(lmv->tgts); |
d7e09d03 PT |
1382 | lmv->tgts_size = 0; |
1383 | } | |
0a3bdb00 | 1384 | return 0; |
d7e09d03 PT |
1385 | } |
1386 | ||
21aef7d9 | 1387 | static int lmv_process_config(struct obd_device *obd, u32 len, void *buf) |
d7e09d03 PT |
1388 | { |
1389 | struct lustre_cfg *lcfg = buf; | |
1390 | struct obd_uuid obd_uuid; | |
1391 | int gen; | |
1392 | __u32 index; | |
1393 | int rc; | |
d7e09d03 PT |
1394 | |
1395 | switch (lcfg->lcfg_command) { | |
1396 | case LCFG_ADD_MDC: | |
1397 | /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID | |
1398 | * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */ | |
4d54556f JL |
1399 | if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid)) { |
1400 | rc = -EINVAL; | |
1401 | goto out; | |
1402 | } | |
d7e09d03 PT |
1403 | |
1404 | obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1)); | |
1405 | ||
4d54556f JL |
1406 | if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1) { |
1407 | rc = -EINVAL; | |
1408 | goto out; | |
1409 | } | |
1410 | if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1) { | |
1411 | rc = -EINVAL; | |
1412 | goto out; | |
1413 | } | |
d7e09d03 | 1414 | rc = lmv_add_target(obd, &obd_uuid, index, gen); |
4d54556f | 1415 | goto out; |
d7e09d03 PT |
1416 | default: |
1417 | CERROR("Unknown command: %d\n", lcfg->lcfg_command); | |
4d54556f JL |
1418 | rc = -EINVAL; |
1419 | goto out; | |
d7e09d03 PT |
1420 | } |
1421 | out: | |
0a3bdb00 | 1422 | return rc; |
d7e09d03 PT |
1423 | } |
1424 | ||
1425 | static int lmv_statfs(const struct lu_env *env, struct obd_export *exp, | |
1426 | struct obd_statfs *osfs, __u64 max_age, __u32 flags) | |
1427 | { | |
1428 | struct obd_device *obd = class_exp2obd(exp); | |
1429 | struct lmv_obd *lmv = &obd->u.lmv; | |
1430 | struct obd_statfs *temp; | |
1431 | int rc = 0; | |
1432 | int i; | |
d7e09d03 PT |
1433 | |
1434 | rc = lmv_check_connect(obd); | |
1435 | if (rc) | |
0a3bdb00 | 1436 | return rc; |
d7e09d03 | 1437 | |
8bcf30c3 | 1438 | temp = kzalloc(sizeof(*temp), GFP_NOFS); |
d7e09d03 | 1439 | if (temp == NULL) |
0a3bdb00 | 1440 | return -ENOMEM; |
d7e09d03 PT |
1441 | |
1442 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
1443 | if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL) | |
1444 | continue; | |
1445 | ||
1446 | rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp, | |
1447 | max_age, flags); | |
1448 | if (rc) { | |
1449 | CERROR("can't stat MDS #%d (%s), error %d\n", i, | |
1450 | lmv->tgts[i]->ltd_exp->exp_obd->obd_name, | |
1451 | rc); | |
4d54556f | 1452 | goto out_free_temp; |
d7e09d03 PT |
1453 | } |
1454 | ||
1455 | if (i == 0) { | |
1456 | *osfs = *temp; | |
1457 | /* If the statfs is from mount, it will needs | |
1458 | * retrieve necessary information from MDT0. | |
1459 | * i.e. mount does not need the merged osfs | |
1460 | * from all of MDT. | |
1461 | * And also clients can be mounted as long as | |
1462 | * MDT0 is in service*/ | |
1463 | if (flags & OBD_STATFS_FOR_MDT0) | |
4d54556f | 1464 | goto out_free_temp; |
d7e09d03 PT |
1465 | } else { |
1466 | osfs->os_bavail += temp->os_bavail; | |
1467 | osfs->os_blocks += temp->os_blocks; | |
1468 | osfs->os_ffree += temp->os_ffree; | |
1469 | osfs->os_files += temp->os_files; | |
1470 | } | |
1471 | } | |
1472 | ||
d7e09d03 | 1473 | out_free_temp: |
8bcf30c3 | 1474 | kfree(temp); |
d7e09d03 PT |
1475 | return rc; |
1476 | } | |
1477 | ||
1478 | static int lmv_getstatus(struct obd_export *exp, | |
1479 | struct lu_fid *fid, | |
1480 | struct obd_capa **pc) | |
1481 | { | |
1482 | struct obd_device *obd = exp->exp_obd; | |
1483 | struct lmv_obd *lmv = &obd->u.lmv; | |
1484 | int rc; | |
d7e09d03 PT |
1485 | |
1486 | rc = lmv_check_connect(obd); | |
1487 | if (rc) | |
0a3bdb00 | 1488 | return rc; |
d7e09d03 PT |
1489 | |
1490 | rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc); | |
0a3bdb00 | 1491 | return rc; |
d7e09d03 PT |
1492 | } |
1493 | ||
1494 | static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid, | |
21aef7d9 | 1495 | struct obd_capa *oc, u64 valid, const char *name, |
d7e09d03 PT |
1496 | const char *input, int input_size, int output_size, |
1497 | int flags, struct ptlrpc_request **request) | |
1498 | { | |
1499 | struct obd_device *obd = exp->exp_obd; | |
1500 | struct lmv_obd *lmv = &obd->u.lmv; | |
1501 | struct lmv_tgt_desc *tgt; | |
1502 | int rc; | |
d7e09d03 PT |
1503 | |
1504 | rc = lmv_check_connect(obd); | |
1505 | if (rc) | |
0a3bdb00 | 1506 | return rc; |
d7e09d03 PT |
1507 | |
1508 | tgt = lmv_find_target(lmv, fid); | |
1509 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1510 | return PTR_ERR(tgt); |
d7e09d03 PT |
1511 | |
1512 | rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input, | |
1513 | input_size, output_size, flags, request); | |
1514 | ||
0a3bdb00 | 1515 | return rc; |
d7e09d03 PT |
1516 | } |
1517 | ||
1518 | static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid, | |
21aef7d9 | 1519 | struct obd_capa *oc, u64 valid, const char *name, |
d7e09d03 PT |
1520 | const char *input, int input_size, int output_size, |
1521 | int flags, __u32 suppgid, | |
1522 | struct ptlrpc_request **request) | |
1523 | { | |
1524 | struct obd_device *obd = exp->exp_obd; | |
1525 | struct lmv_obd *lmv = &obd->u.lmv; | |
1526 | struct lmv_tgt_desc *tgt; | |
1527 | int rc; | |
d7e09d03 PT |
1528 | |
1529 | rc = lmv_check_connect(obd); | |
1530 | if (rc) | |
0a3bdb00 | 1531 | return rc; |
d7e09d03 PT |
1532 | |
1533 | tgt = lmv_find_target(lmv, fid); | |
1534 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1535 | return PTR_ERR(tgt); |
d7e09d03 PT |
1536 | |
1537 | rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input, | |
1538 | input_size, output_size, flags, suppgid, | |
1539 | request); | |
1540 | ||
0a3bdb00 | 1541 | return rc; |
d7e09d03 PT |
1542 | } |
1543 | ||
1544 | static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data, | |
1545 | struct ptlrpc_request **request) | |
1546 | { | |
1547 | struct obd_device *obd = exp->exp_obd; | |
1548 | struct lmv_obd *lmv = &obd->u.lmv; | |
1549 | struct lmv_tgt_desc *tgt; | |
1550 | int rc; | |
d7e09d03 PT |
1551 | |
1552 | rc = lmv_check_connect(obd); | |
1553 | if (rc) | |
0a3bdb00 | 1554 | return rc; |
d7e09d03 PT |
1555 | |
1556 | tgt = lmv_find_target(lmv, &op_data->op_fid1); | |
1557 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1558 | return PTR_ERR(tgt); |
d7e09d03 PT |
1559 | |
1560 | if (op_data->op_flags & MF_GET_MDT_IDX) { | |
1561 | op_data->op_mds = tgt->ltd_idx; | |
0a3bdb00 | 1562 | return 0; |
d7e09d03 PT |
1563 | } |
1564 | ||
1565 | rc = md_getattr(tgt->ltd_exp, op_data, request); | |
1566 | ||
0a3bdb00 | 1567 | return rc; |
d7e09d03 PT |
1568 | } |
1569 | ||
1570 | static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid) | |
1571 | { | |
1572 | struct obd_device *obd = exp->exp_obd; | |
1573 | struct lmv_obd *lmv = &obd->u.lmv; | |
1574 | int i; | |
1575 | int rc; | |
d7e09d03 PT |
1576 | |
1577 | rc = lmv_check_connect(obd); | |
1578 | if (rc) | |
0a3bdb00 | 1579 | return rc; |
d7e09d03 PT |
1580 | |
1581 | CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid)); | |
1582 | ||
1583 | /* | |
1584 | * With DNE every object can have two locks in different namespaces: | |
1585 | * lookup lock in space of MDT storing direntry and update/open lock in | |
1586 | * space of MDT storing inode. | |
1587 | */ | |
1588 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
1589 | if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL) | |
1590 | continue; | |
1591 | md_null_inode(lmv->tgts[i]->ltd_exp, fid); | |
1592 | } | |
1593 | ||
0a3bdb00 | 1594 | return 0; |
d7e09d03 PT |
1595 | } |
1596 | ||
1597 | static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid, | |
1598 | ldlm_iterator_t it, void *data) | |
1599 | { | |
1600 | struct obd_device *obd = exp->exp_obd; | |
1601 | struct lmv_obd *lmv = &obd->u.lmv; | |
1602 | int i; | |
1603 | int rc; | |
d7e09d03 PT |
1604 | |
1605 | rc = lmv_check_connect(obd); | |
1606 | if (rc) | |
0a3bdb00 | 1607 | return rc; |
d7e09d03 PT |
1608 | |
1609 | CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid)); | |
1610 | ||
1611 | /* | |
1612 | * With DNE every object can have two locks in different namespaces: | |
1613 | * lookup lock in space of MDT storing direntry and update/open lock in | |
1614 | * space of MDT storing inode. | |
1615 | */ | |
1616 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
1617 | if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL) | |
1618 | continue; | |
1619 | rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data); | |
1620 | if (rc) | |
0a3bdb00 | 1621 | return rc; |
d7e09d03 PT |
1622 | } |
1623 | ||
0a3bdb00 | 1624 | return rc; |
d7e09d03 PT |
1625 | } |
1626 | ||
1627 | ||
1628 | static int lmv_close(struct obd_export *exp, struct md_op_data *op_data, | |
1629 | struct md_open_data *mod, struct ptlrpc_request **request) | |
1630 | { | |
1631 | struct obd_device *obd = exp->exp_obd; | |
1632 | struct lmv_obd *lmv = &obd->u.lmv; | |
1633 | struct lmv_tgt_desc *tgt; | |
1634 | int rc; | |
d7e09d03 PT |
1635 | |
1636 | rc = lmv_check_connect(obd); | |
1637 | if (rc) | |
0a3bdb00 | 1638 | return rc; |
d7e09d03 PT |
1639 | |
1640 | tgt = lmv_find_target(lmv, &op_data->op_fid1); | |
1641 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1642 | return PTR_ERR(tgt); |
d7e09d03 PT |
1643 | |
1644 | CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1)); | |
1645 | rc = md_close(tgt->ltd_exp, op_data, mod, request); | |
0a3bdb00 | 1646 | return rc; |
d7e09d03 PT |
1647 | } |
1648 | ||
1649 | struct lmv_tgt_desc | |
1650 | *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data, | |
1651 | struct lu_fid *fid) | |
1652 | { | |
1653 | struct lmv_tgt_desc *tgt; | |
1654 | ||
1655 | tgt = lmv_find_target(lmv, fid); | |
1656 | if (IS_ERR(tgt)) | |
1657 | return tgt; | |
1658 | ||
1659 | op_data->op_mds = tgt->ltd_idx; | |
1660 | ||
1661 | return tgt; | |
1662 | } | |
1663 | ||
5dc8d7b4 LC |
1664 | static int lmv_create(struct obd_export *exp, struct md_op_data *op_data, |
1665 | const void *data, int datalen, int mode, __u32 uid, | |
1666 | __u32 gid, cfs_cap_t cap_effective, __u64 rdev, | |
1667 | struct ptlrpc_request **request) | |
d7e09d03 PT |
1668 | { |
1669 | struct obd_device *obd = exp->exp_obd; | |
1670 | struct lmv_obd *lmv = &obd->u.lmv; | |
1671 | struct lmv_tgt_desc *tgt; | |
1672 | int rc; | |
d7e09d03 PT |
1673 | |
1674 | rc = lmv_check_connect(obd); | |
1675 | if (rc) | |
0a3bdb00 | 1676 | return rc; |
d7e09d03 PT |
1677 | |
1678 | if (!lmv->desc.ld_active_tgt_count) | |
0a3bdb00 | 1679 | return -EIO; |
d7e09d03 PT |
1680 | |
1681 | tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1); | |
1682 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1683 | return PTR_ERR(tgt); |
d7e09d03 PT |
1684 | |
1685 | rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data); | |
1686 | if (rc) | |
0a3bdb00 | 1687 | return rc; |
d7e09d03 PT |
1688 | |
1689 | CDEBUG(D_INODE, "CREATE '%*s' on "DFID" -> mds #%x\n", | |
1690 | op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1), | |
1691 | op_data->op_mds); | |
1692 | ||
1693 | op_data->op_flags |= MF_MDC_CANCEL_FID1; | |
1694 | rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid, | |
1695 | cap_effective, rdev, request); | |
1696 | ||
1697 | if (rc == 0) { | |
1698 | if (*request == NULL) | |
0a3bdb00 | 1699 | return rc; |
d7e09d03 PT |
1700 | CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2)); |
1701 | } | |
0a3bdb00 | 1702 | return rc; |
d7e09d03 PT |
1703 | } |
1704 | ||
1705 | static int lmv_done_writing(struct obd_export *exp, | |
1706 | struct md_op_data *op_data, | |
1707 | struct md_open_data *mod) | |
1708 | { | |
1709 | struct obd_device *obd = exp->exp_obd; | |
1710 | struct lmv_obd *lmv = &obd->u.lmv; | |
1711 | struct lmv_tgt_desc *tgt; | |
1712 | int rc; | |
d7e09d03 PT |
1713 | |
1714 | rc = lmv_check_connect(obd); | |
1715 | if (rc) | |
0a3bdb00 | 1716 | return rc; |
d7e09d03 PT |
1717 | |
1718 | tgt = lmv_find_target(lmv, &op_data->op_fid1); | |
1719 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1720 | return PTR_ERR(tgt); |
d7e09d03 PT |
1721 | |
1722 | rc = md_done_writing(tgt->ltd_exp, op_data, mod); | |
0a3bdb00 | 1723 | return rc; |
d7e09d03 PT |
1724 | } |
1725 | ||
1726 | static int | |
1727 | lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo, | |
1728 | struct lookup_intent *it, struct md_op_data *op_data, | |
1729 | struct lustre_handle *lockh, void *lmm, int lmmsize, | |
875332d4 | 1730 | __u64 extra_lock_flags) |
d7e09d03 PT |
1731 | { |
1732 | struct ptlrpc_request *req = it->d.lustre.it_data; | |
1733 | struct obd_device *obd = exp->exp_obd; | |
1734 | struct lmv_obd *lmv = &obd->u.lmv; | |
1735 | struct lustre_handle plock; | |
1736 | struct lmv_tgt_desc *tgt; | |
1737 | struct md_op_data *rdata; | |
1738 | struct lu_fid fid1; | |
1739 | struct mdt_body *body; | |
1740 | int rc = 0; | |
1741 | int pmode; | |
d7e09d03 PT |
1742 | |
1743 | body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); | |
1744 | LASSERT(body != NULL); | |
1745 | ||
1746 | if (!(body->valid & OBD_MD_MDS)) | |
0a3bdb00 | 1747 | return 0; |
d7e09d03 PT |
1748 | |
1749 | CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n", | |
1750 | LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1)); | |
1751 | ||
1752 | /* | |
1753 | * We got LOOKUP lock, but we really need attrs. | |
1754 | */ | |
1755 | pmode = it->d.lustre.it_lock_mode; | |
1756 | LASSERT(pmode != 0); | |
1757 | memcpy(&plock, lockh, sizeof(plock)); | |
1758 | it->d.lustre.it_lock_mode = 0; | |
1759 | it->d.lustre.it_data = NULL; | |
1760 | fid1 = body->fid1; | |
1761 | ||
d7e09d03 PT |
1762 | ptlrpc_req_finished(req); |
1763 | ||
1764 | tgt = lmv_find_target(lmv, &fid1); | |
4d54556f JL |
1765 | if (IS_ERR(tgt)) { |
1766 | rc = PTR_ERR(tgt); | |
1767 | goto out; | |
1768 | } | |
d7e09d03 | 1769 | |
8bcf30c3 | 1770 | rdata = kzalloc(sizeof(*rdata), GFP_NOFS); |
4d54556f JL |
1771 | if (rdata == NULL) { |
1772 | rc = -ENOMEM; | |
1773 | goto out; | |
1774 | } | |
d7e09d03 PT |
1775 | |
1776 | rdata->op_fid1 = fid1; | |
1777 | rdata->op_bias = MDS_CROSS_REF; | |
1778 | ||
1779 | rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh, | |
1780 | lmm, lmmsize, NULL, extra_lock_flags); | |
8bcf30c3 | 1781 | kfree(rdata); |
d7e09d03 PT |
1782 | out: |
1783 | ldlm_lock_decref(&plock, pmode); | |
1784 | return rc; | |
1785 | } | |
1786 | ||
1787 | static int | |
1788 | lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo, | |
1789 | struct lookup_intent *it, struct md_op_data *op_data, | |
1790 | struct lustre_handle *lockh, void *lmm, int lmmsize, | |
1791 | struct ptlrpc_request **req, __u64 extra_lock_flags) | |
1792 | { | |
1793 | struct obd_device *obd = exp->exp_obd; | |
1794 | struct lmv_obd *lmv = &obd->u.lmv; | |
1795 | struct lmv_tgt_desc *tgt; | |
1796 | int rc; | |
d7e09d03 PT |
1797 | |
1798 | rc = lmv_check_connect(obd); | |
1799 | if (rc) | |
0a3bdb00 | 1800 | return rc; |
d7e09d03 PT |
1801 | |
1802 | CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n", | |
1803 | LL_IT2STR(it), PFID(&op_data->op_fid1)); | |
1804 | ||
1805 | tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1); | |
1806 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1807 | return PTR_ERR(tgt); |
d7e09d03 PT |
1808 | |
1809 | CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n", | |
1810 | LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx); | |
1811 | ||
1812 | rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh, | |
1813 | lmm, lmmsize, req, extra_lock_flags); | |
1814 | ||
1815 | if (rc == 0 && it && it->it_op == IT_OPEN) { | |
1816 | rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh, | |
1817 | lmm, lmmsize, extra_lock_flags); | |
1818 | } | |
0a3bdb00 | 1819 | return rc; |
d7e09d03 PT |
1820 | } |
1821 | ||
1822 | static int | |
1d8cb70c | 1823 | lmv_getattr_name(struct obd_export *exp, struct md_op_data *op_data, |
d7e09d03 PT |
1824 | struct ptlrpc_request **request) |
1825 | { | |
1826 | struct ptlrpc_request *req = NULL; | |
1827 | struct obd_device *obd = exp->exp_obd; | |
1828 | struct lmv_obd *lmv = &obd->u.lmv; | |
1829 | struct lmv_tgt_desc *tgt; | |
1830 | struct mdt_body *body; | |
1831 | int rc; | |
d7e09d03 PT |
1832 | |
1833 | rc = lmv_check_connect(obd); | |
1834 | if (rc) | |
0a3bdb00 | 1835 | return rc; |
d7e09d03 PT |
1836 | |
1837 | tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1); | |
1838 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1839 | return PTR_ERR(tgt); |
d7e09d03 PT |
1840 | |
1841 | CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n", | |
1842 | op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1), | |
1843 | tgt->ltd_idx); | |
1844 | ||
1845 | rc = md_getattr_name(tgt->ltd_exp, op_data, request); | |
1846 | if (rc != 0) | |
0a3bdb00 | 1847 | return rc; |
d7e09d03 PT |
1848 | |
1849 | body = req_capsule_server_get(&(*request)->rq_pill, | |
1850 | &RMF_MDT_BODY); | |
1851 | LASSERT(body != NULL); | |
1852 | ||
1853 | if (body->valid & OBD_MD_MDS) { | |
1854 | struct lu_fid rid = body->fid1; | |
1855 | CDEBUG(D_INODE, "Request attrs for "DFID"\n", | |
1856 | PFID(&rid)); | |
1857 | ||
1858 | tgt = lmv_find_target(lmv, &rid); | |
1859 | if (IS_ERR(tgt)) { | |
1860 | ptlrpc_req_finished(*request); | |
0a3bdb00 | 1861 | return PTR_ERR(tgt); |
d7e09d03 PT |
1862 | } |
1863 | ||
1864 | op_data->op_fid1 = rid; | |
1865 | op_data->op_valid |= OBD_MD_FLCROSSREF; | |
1866 | op_data->op_namelen = 0; | |
1867 | op_data->op_name = NULL; | |
1868 | rc = md_getattr_name(tgt->ltd_exp, op_data, &req); | |
1869 | ptlrpc_req_finished(*request); | |
1870 | *request = req; | |
1871 | } | |
1872 | ||
0a3bdb00 | 1873 | return rc; |
d7e09d03 PT |
1874 | } |
1875 | ||
1876 | #define md_op_data_fid(op_data, fl) \ | |
1877 | (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \ | |
1878 | fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \ | |
1879 | fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \ | |
1880 | fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \ | |
1881 | NULL) | |
1882 | ||
1883 | static int lmv_early_cancel(struct obd_export *exp, struct md_op_data *op_data, | |
1884 | int op_tgt, ldlm_mode_t mode, int bits, int flag) | |
1885 | { | |
1886 | struct lu_fid *fid = md_op_data_fid(op_data, flag); | |
1887 | struct obd_device *obd = exp->exp_obd; | |
1888 | struct lmv_obd *lmv = &obd->u.lmv; | |
1889 | struct lmv_tgt_desc *tgt; | |
1890 | ldlm_policy_data_t policy = {{0}}; | |
1891 | int rc = 0; | |
d7e09d03 PT |
1892 | |
1893 | if (!fid_is_sane(fid)) | |
0a3bdb00 | 1894 | return 0; |
d7e09d03 PT |
1895 | |
1896 | tgt = lmv_find_target(lmv, fid); | |
1897 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1898 | return PTR_ERR(tgt); |
d7e09d03 PT |
1899 | |
1900 | if (tgt->ltd_idx != op_tgt) { | |
1901 | CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid)); | |
1902 | policy.l_inodebits.bits = bits; | |
1903 | rc = md_cancel_unused(tgt->ltd_exp, fid, &policy, | |
1904 | mode, LCF_ASYNC, NULL); | |
1905 | } else { | |
1906 | CDEBUG(D_INODE, | |
1907 | "EARLY_CANCEL skip operation target %d on "DFID"\n", | |
1908 | op_tgt, PFID(fid)); | |
1909 | op_data->op_flags |= flag; | |
1910 | rc = 0; | |
1911 | } | |
1912 | ||
0a3bdb00 | 1913 | return rc; |
d7e09d03 PT |
1914 | } |
1915 | ||
1916 | /* | |
1917 | * llite passes fid of an target inode in op_data->op_fid1 and id of directory in | |
1918 | * op_data->op_fid2 | |
1919 | */ | |
1920 | static int lmv_link(struct obd_export *exp, struct md_op_data *op_data, | |
1921 | struct ptlrpc_request **request) | |
1922 | { | |
1923 | struct obd_device *obd = exp->exp_obd; | |
1924 | struct lmv_obd *lmv = &obd->u.lmv; | |
1925 | struct lmv_tgt_desc *tgt; | |
1926 | int rc; | |
d7e09d03 PT |
1927 | |
1928 | rc = lmv_check_connect(obd); | |
1929 | if (rc) | |
0a3bdb00 | 1930 | return rc; |
d7e09d03 PT |
1931 | |
1932 | LASSERT(op_data->op_namelen != 0); | |
1933 | ||
1934 | CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n", | |
1935 | PFID(&op_data->op_fid2), op_data->op_namelen, | |
1936 | op_data->op_name, PFID(&op_data->op_fid1)); | |
1937 | ||
4b1a25f0 PT |
1938 | op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid()); |
1939 | op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid()); | |
d7e09d03 PT |
1940 | op_data->op_cap = cfs_curproc_cap_pack(); |
1941 | tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2); | |
1942 | if (IS_ERR(tgt)) | |
0a3bdb00 | 1943 | return PTR_ERR(tgt); |
d7e09d03 PT |
1944 | |
1945 | /* | |
1946 | * Cancel UPDATE lock on child (fid1). | |
1947 | */ | |
1948 | op_data->op_flags |= MF_MDC_CANCEL_FID2; | |
1949 | rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX, | |
1950 | MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1); | |
1951 | if (rc != 0) | |
0a3bdb00 | 1952 | return rc; |
d7e09d03 PT |
1953 | |
1954 | rc = md_link(tgt->ltd_exp, op_data, request); | |
1955 | ||
0a3bdb00 | 1956 | return rc; |
d7e09d03 PT |
1957 | } |
1958 | ||
1959 | static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data, | |
1960 | const char *old, int oldlen, const char *new, int newlen, | |
1961 | struct ptlrpc_request **request) | |
1962 | { | |
1963 | struct obd_device *obd = exp->exp_obd; | |
1964 | struct lmv_obd *lmv = &obd->u.lmv; | |
1965 | struct lmv_tgt_desc *src_tgt; | |
1966 | struct lmv_tgt_desc *tgt_tgt; | |
1967 | int rc; | |
d7e09d03 PT |
1968 | |
1969 | LASSERT(oldlen != 0); | |
1970 | ||
1971 | CDEBUG(D_INODE, "RENAME %*s in "DFID" to %*s in "DFID"\n", | |
1972 | oldlen, old, PFID(&op_data->op_fid1), | |
1973 | newlen, new, PFID(&op_data->op_fid2)); | |
1974 | ||
1975 | rc = lmv_check_connect(obd); | |
1976 | if (rc) | |
0a3bdb00 | 1977 | return rc; |
d7e09d03 | 1978 | |
4b1a25f0 PT |
1979 | op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid()); |
1980 | op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid()); | |
d7e09d03 PT |
1981 | op_data->op_cap = cfs_curproc_cap_pack(); |
1982 | src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1); | |
1983 | if (IS_ERR(src_tgt)) | |
0a3bdb00 | 1984 | return PTR_ERR(src_tgt); |
d7e09d03 PT |
1985 | |
1986 | tgt_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2); | |
1987 | if (IS_ERR(tgt_tgt)) | |
0a3bdb00 | 1988 | return PTR_ERR(tgt_tgt); |
d7e09d03 PT |
1989 | /* |
1990 | * LOOKUP lock on src child (fid3) should also be cancelled for | |
1991 | * src_tgt in mdc_rename. | |
1992 | */ | |
1993 | op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3; | |
1994 | ||
1995 | /* | |
1996 | * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its | |
1997 | * own target. | |
1998 | */ | |
1999 | rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx, | |
2000 | LCK_EX, MDS_INODELOCK_UPDATE, | |
2001 | MF_MDC_CANCEL_FID2); | |
2002 | ||
2003 | /* | |
2004 | * Cancel LOOKUP locks on tgt child (fid4) for parent tgt_tgt. | |
2005 | */ | |
2006 | if (rc == 0) { | |
2007 | rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx, | |
2008 | LCK_EX, MDS_INODELOCK_LOOKUP, | |
2009 | MF_MDC_CANCEL_FID4); | |
2010 | } | |
2011 | ||
2012 | /* | |
2013 | * Cancel all the locks on tgt child (fid4). | |
2014 | */ | |
2015 | if (rc == 0) | |
2016 | rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx, | |
2017 | LCK_EX, MDS_INODELOCK_FULL, | |
2018 | MF_MDC_CANCEL_FID4); | |
2019 | ||
2020 | if (rc == 0) | |
2021 | rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen, | |
2022 | new, newlen, request); | |
0a3bdb00 | 2023 | return rc; |
d7e09d03 PT |
2024 | } |
2025 | ||
2026 | static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data, | |
2027 | void *ea, int ealen, void *ea2, int ea2len, | |
2028 | struct ptlrpc_request **request, | |
2029 | struct md_open_data **mod) | |
2030 | { | |
2031 | struct obd_device *obd = exp->exp_obd; | |
2032 | struct lmv_obd *lmv = &obd->u.lmv; | |
2033 | struct lmv_tgt_desc *tgt; | |
2034 | int rc = 0; | |
d7e09d03 PT |
2035 | |
2036 | rc = lmv_check_connect(obd); | |
2037 | if (rc) | |
0a3bdb00 | 2038 | return rc; |
d7e09d03 PT |
2039 | |
2040 | CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n", | |
2041 | PFID(&op_data->op_fid1), op_data->op_attr.ia_valid); | |
2042 | ||
2043 | op_data->op_flags |= MF_MDC_CANCEL_FID1; | |
2044 | tgt = lmv_find_target(lmv, &op_data->op_fid1); | |
2045 | if (IS_ERR(tgt)) | |
0a3bdb00 | 2046 | return PTR_ERR(tgt); |
d7e09d03 PT |
2047 | |
2048 | rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2, | |
2049 | ea2len, request, mod); | |
2050 | ||
0a3bdb00 | 2051 | return rc; |
d7e09d03 PT |
2052 | } |
2053 | ||
2054 | static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid, | |
2055 | struct obd_capa *oc, struct ptlrpc_request **request) | |
2056 | { | |
2057 | struct obd_device *obd = exp->exp_obd; | |
2058 | struct lmv_obd *lmv = &obd->u.lmv; | |
2059 | struct lmv_tgt_desc *tgt; | |
2060 | int rc; | |
d7e09d03 PT |
2061 | |
2062 | rc = lmv_check_connect(obd); | |
2063 | if (rc) | |
0a3bdb00 | 2064 | return rc; |
d7e09d03 PT |
2065 | |
2066 | tgt = lmv_find_target(lmv, fid); | |
2067 | if (IS_ERR(tgt)) | |
0a3bdb00 | 2068 | return PTR_ERR(tgt); |
d7e09d03 PT |
2069 | |
2070 | rc = md_sync(tgt->ltd_exp, fid, oc, request); | |
0a3bdb00 | 2071 | return rc; |
d7e09d03 PT |
2072 | } |
2073 | ||
2074 | /* | |
2075 | * Adjust a set of pages, each page containing an array of lu_dirpages, | |
2076 | * so that each page can be used as a single logical lu_dirpage. | |
2077 | * | |
2078 | * A lu_dirpage is laid out as follows, where s = ldp_hash_start, | |
2079 | * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a | |
2080 | * struct lu_dirent. It has size up to LU_PAGE_SIZE. The ldp_hash_end | |
2081 | * value is used as a cookie to request the next lu_dirpage in a | |
2082 | * directory listing that spans multiple pages (two in this example): | |
2083 | * ________ | |
2084 | * | | | |
2085 | * .|--------v------- -----. | |
2086 | * |s|e|f|p|ent|ent| ... |ent| | |
2087 | * '--|-------------- -----' Each CFS_PAGE contains a single | |
2088 | * '------. lu_dirpage. | |
2089 | * .---------v------- -----. | |
2090 | * |s|e|f|p|ent| 0 | ... | 0 | | |
2091 | * '----------------- -----' | |
2092 | * | |
2093 | * However, on hosts where the native VM page size (PAGE_CACHE_SIZE) is | |
2094 | * larger than LU_PAGE_SIZE, a single host page may contain multiple | |
2095 | * lu_dirpages. After reading the lu_dirpages from the MDS, the | |
2096 | * ldp_hash_end of the first lu_dirpage refers to the one immediately | |
2097 | * after it in the same CFS_PAGE (arrows simplified for brevity, but | |
2098 | * in general e0==s1, e1==s2, etc.): | |
2099 | * | |
2100 | * .-------------------- -----. | |
2101 | * |s0|e0|f0|p|ent|ent| ... |ent| | |
2102 | * |---v---------------- -----| | |
2103 | * |s1|e1|f1|p|ent|ent| ... |ent| | |
2104 | * |---v---------------- -----| Here, each CFS_PAGE contains | |
2105 | * ... multiple lu_dirpages. | |
2106 | * |---v---------------- -----| | |
2107 | * |s'|e'|f'|p|ent|ent| ... |ent| | |
2108 | * '---|---------------- -----' | |
2109 | * v | |
2110 | * .----------------------------. | |
2111 | * | next CFS_PAGE | | |
2112 | * | |
2113 | * This structure is transformed into a single logical lu_dirpage as follows: | |
2114 | * | |
2115 | * - Replace e0 with e' so the request for the next lu_dirpage gets the page | |
2116 | * labeled 'next CFS_PAGE'. | |
2117 | * | |
2118 | * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether | |
2119 | * a hash collision with the next page exists. | |
2120 | * | |
2121 | * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span | |
2122 | * to the first entry of the next lu_dirpage. | |
2123 | */ | |
2124 | #if PAGE_CACHE_SIZE > LU_PAGE_SIZE | |
2125 | static void lmv_adjust_dirpages(struct page **pages, int ncfspgs, int nlupgs) | |
2126 | { | |
2127 | int i; | |
2128 | ||
2129 | for (i = 0; i < ncfspgs; i++) { | |
2130 | struct lu_dirpage *dp = kmap(pages[i]); | |
2131 | struct lu_dirpage *first = dp; | |
2132 | struct lu_dirent *end_dirent = NULL; | |
2133 | struct lu_dirent *ent; | |
2134 | __u64 hash_end = dp->ldp_hash_end; | |
2135 | __u32 flags = dp->ldp_flags; | |
2136 | ||
cdb5f710 | 2137 | while (--nlupgs > 0) { |
d7e09d03 PT |
2138 | ent = lu_dirent_start(dp); |
2139 | for (end_dirent = ent; ent != NULL; | |
2140 | end_dirent = ent, ent = lu_dirent_next(ent)); | |
2141 | ||
2142 | /* Advance dp to next lu_dirpage. */ | |
2143 | dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE); | |
2144 | ||
2145 | /* Check if we've reached the end of the CFS_PAGE. */ | |
2146 | if (!((unsigned long)dp & ~CFS_PAGE_MASK)) | |
2147 | break; | |
2148 | ||
2149 | /* Save the hash and flags of this lu_dirpage. */ | |
2150 | hash_end = dp->ldp_hash_end; | |
2151 | flags = dp->ldp_flags; | |
2152 | ||
2153 | /* Check if lu_dirpage contains no entries. */ | |
2154 | if (!end_dirent) | |
2155 | break; | |
2156 | ||
2157 | /* Enlarge the end entry lde_reclen from 0 to | |
2158 | * first entry of next lu_dirpage. */ | |
2159 | LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0); | |
2160 | end_dirent->lde_reclen = | |
2161 | cpu_to_le16((char *)(dp->ldp_entries) - | |
2162 | (char *)end_dirent); | |
2163 | } | |
2164 | ||
2165 | first->ldp_hash_end = hash_end; | |
2166 | first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE); | |
2167 | first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE); | |
2168 | ||
2169 | kunmap(pages[i]); | |
2170 | } | |
cdb5f710 | 2171 | LASSERTF(nlupgs == 0, "left = %d", nlupgs); |
d7e09d03 PT |
2172 | } |
2173 | #else | |
2174 | #define lmv_adjust_dirpages(pages, ncfspgs, nlupgs) do {} while (0) | |
2175 | #endif /* PAGE_CACHE_SIZE > LU_PAGE_SIZE */ | |
2176 | ||
2177 | static int lmv_readpage(struct obd_export *exp, struct md_op_data *op_data, | |
2178 | struct page **pages, struct ptlrpc_request **request) | |
2179 | { | |
2180 | struct obd_device *obd = exp->exp_obd; | |
2181 | struct lmv_obd *lmv = &obd->u.lmv; | |
2182 | __u64 offset = op_data->op_offset; | |
2183 | int rc; | |
2184 | int ncfspgs; /* pages read in PAGE_CACHE_SIZE */ | |
2185 | int nlupgs; /* pages read in LU_PAGE_SIZE */ | |
2186 | struct lmv_tgt_desc *tgt; | |
d7e09d03 PT |
2187 | |
2188 | rc = lmv_check_connect(obd); | |
2189 | if (rc) | |
0a3bdb00 | 2190 | return rc; |
d7e09d03 | 2191 | |
55f5a824 | 2192 | CDEBUG(D_INODE, "READPAGE at %#llx from "DFID"\n", |
d7e09d03 PT |
2193 | offset, PFID(&op_data->op_fid1)); |
2194 | ||
2195 | tgt = lmv_find_target(lmv, &op_data->op_fid1); | |
2196 | if (IS_ERR(tgt)) | |
0a3bdb00 | 2197 | return PTR_ERR(tgt); |
d7e09d03 PT |
2198 | |
2199 | rc = md_readpage(tgt->ltd_exp, op_data, pages, request); | |
2200 | if (rc != 0) | |
0a3bdb00 | 2201 | return rc; |
d7e09d03 PT |
2202 | |
2203 | ncfspgs = ((*request)->rq_bulk->bd_nob_transferred + PAGE_CACHE_SIZE - 1) | |
2204 | >> PAGE_CACHE_SHIFT; | |
2205 | nlupgs = (*request)->rq_bulk->bd_nob_transferred >> LU_PAGE_SHIFT; | |
2206 | LASSERT(!((*request)->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK)); | |
2207 | LASSERT(ncfspgs > 0 && ncfspgs <= op_data->op_npages); | |
2208 | ||
2209 | CDEBUG(D_INODE, "read %d(%d)/%d pages\n", ncfspgs, nlupgs, | |
2210 | op_data->op_npages); | |
2211 | ||
2212 | lmv_adjust_dirpages(pages, ncfspgs, nlupgs); | |
2213 | ||
0a3bdb00 | 2214 | return rc; |
d7e09d03 PT |
2215 | } |
2216 | ||
2217 | static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data, | |
2218 | struct ptlrpc_request **request) | |
2219 | { | |
2220 | struct obd_device *obd = exp->exp_obd; | |
2221 | struct lmv_obd *lmv = &obd->u.lmv; | |
2222 | struct lmv_tgt_desc *tgt = NULL; | |
2223 | struct mdt_body *body; | |
2224 | int rc; | |
d7e09d03 PT |
2225 | |
2226 | rc = lmv_check_connect(obd); | |
2227 | if (rc) | |
0a3bdb00 | 2228 | return rc; |
d7e09d03 PT |
2229 | retry: |
2230 | /* Send unlink requests to the MDT where the child is located */ | |
2231 | if (likely(!fid_is_zero(&op_data->op_fid2))) | |
2232 | tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2); | |
2233 | else | |
2234 | tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1); | |
2235 | if (IS_ERR(tgt)) | |
0a3bdb00 | 2236 | return PTR_ERR(tgt); |
d7e09d03 | 2237 | |
4b1a25f0 PT |
2238 | op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid()); |
2239 | op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid()); | |
d7e09d03 PT |
2240 | op_data->op_cap = cfs_curproc_cap_pack(); |
2241 | ||
2242 | /* | |
2243 | * If child's fid is given, cancel unused locks for it if it is from | |
2244 | * another export than parent. | |
2245 | * | |
2246 | * LOOKUP lock for child (fid3) should also be cancelled on parent | |
2247 | * tgt_tgt in mdc_unlink(). | |
2248 | */ | |
2249 | op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3; | |
2250 | ||
2251 | /* | |
2252 | * Cancel FULL locks on child (fid3). | |
2253 | */ | |
2254 | rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX, | |
2255 | MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3); | |
2256 | ||
2257 | if (rc != 0) | |
0a3bdb00 | 2258 | return rc; |
d7e09d03 PT |
2259 | |
2260 | CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n", | |
2261 | PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx); | |
2262 | ||
2263 | rc = md_unlink(tgt->ltd_exp, op_data, request); | |
2264 | if (rc != 0 && rc != -EREMOTE) | |
0a3bdb00 | 2265 | return rc; |
d7e09d03 PT |
2266 | |
2267 | body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY); | |
2268 | if (body == NULL) | |
0a3bdb00 | 2269 | return -EPROTO; |
d7e09d03 PT |
2270 | |
2271 | /* Not cross-ref case, just get out of here. */ | |
2272 | if (likely(!(body->valid & OBD_MD_MDS))) | |
0a3bdb00 | 2273 | return 0; |
d7e09d03 PT |
2274 | |
2275 | CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n", | |
2276 | exp->exp_obd->obd_name, PFID(&body->fid1)); | |
2277 | ||
2278 | /* This is a remote object, try remote MDT, Note: it may | |
2279 | * try more than 1 time here, Considering following case | |
2280 | * /mnt/lustre is root on MDT0, remote1 is on MDT1 | |
2281 | * 1. Initially A does not know where remote1 is, it send | |
2282 | * unlink RPC to MDT0, MDT0 return -EREMOTE, it will | |
2283 | * resend unlink RPC to MDT1 (retry 1st time). | |
2284 | * | |
2285 | * 2. During the unlink RPC in flight, | |
2286 | * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2 | |
2287 | * and create new remote1, but on MDT0 | |
2288 | * | |
2289 | * 3. MDT1 get unlink RPC(from A), then do remote lock on | |
2290 | * /mnt/lustre, then lookup get fid of remote1, and find | |
2291 | * it is remote dir again, and replay -EREMOTE again. | |
2292 | * | |
2293 | * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times). | |
2294 | * | |
2295 | * In theory, it might try unlimited time here, but it should | |
2296 | * be very rare case. */ | |
2297 | op_data->op_fid2 = body->fid1; | |
2298 | ptlrpc_req_finished(*request); | |
2299 | *request = NULL; | |
2300 | ||
2301 | goto retry; | |
2302 | } | |
2303 | ||
2304 | static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage) | |
2305 | { | |
2306 | struct lmv_obd *lmv = &obd->u.lmv; | |
d7e09d03 PT |
2307 | |
2308 | switch (stage) { | |
2309 | case OBD_CLEANUP_EARLY: | |
2310 | /* XXX: here should be calling obd_precleanup() down to | |
2311 | * stack. */ | |
2312 | break; | |
2313 | case OBD_CLEANUP_EXPORTS: | |
2314 | fld_client_proc_fini(&lmv->lmv_fld); | |
2315 | lprocfs_obd_cleanup(obd); | |
2316 | break; | |
2317 | default: | |
2318 | break; | |
2319 | } | |
5ed57d6d | 2320 | return 0; |
d7e09d03 PT |
2321 | } |
2322 | ||
2323 | static int lmv_get_info(const struct lu_env *env, struct obd_export *exp, | |
2324 | __u32 keylen, void *key, __u32 *vallen, void *val, | |
2325 | struct lov_stripe_md *lsm) | |
2326 | { | |
2327 | struct obd_device *obd; | |
2328 | struct lmv_obd *lmv; | |
2329 | int rc = 0; | |
d7e09d03 PT |
2330 | |
2331 | obd = class_exp2obd(exp); | |
2332 | if (obd == NULL) { | |
55f5a824 | 2333 | CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n", |
d7e09d03 | 2334 | exp->exp_handle.h_cookie); |
0a3bdb00 | 2335 | return -EINVAL; |
d7e09d03 PT |
2336 | } |
2337 | ||
2338 | lmv = &obd->u.lmv; | |
2339 | if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) { | |
2340 | struct lmv_tgt_desc *tgt; | |
2341 | int i; | |
2342 | ||
2343 | rc = lmv_check_connect(obd); | |
2344 | if (rc) | |
0a3bdb00 | 2345 | return rc; |
d7e09d03 PT |
2346 | |
2347 | LASSERT(*vallen == sizeof(__u32)); | |
2348 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
2349 | tgt = lmv->tgts[i]; | |
2350 | /* | |
2351 | * All tgts should be connected when this gets called. | |
2352 | */ | |
2353 | if (tgt == NULL || tgt->ltd_exp == NULL) | |
2354 | continue; | |
2355 | ||
2356 | if (!obd_get_info(env, tgt->ltd_exp, keylen, key, | |
2357 | vallen, val, NULL)) | |
0a3bdb00 | 2358 | return 0; |
d7e09d03 | 2359 | } |
0a3bdb00 | 2360 | return -EINVAL; |
44779340 BB |
2361 | } else if (KEY_IS(KEY_MAX_EASIZE) || |
2362 | KEY_IS(KEY_DEFAULT_EASIZE) || | |
2363 | KEY_IS(KEY_MAX_COOKIESIZE) || | |
2364 | KEY_IS(KEY_DEFAULT_COOKIESIZE) || | |
2365 | KEY_IS(KEY_CONN_DATA)) { | |
d7e09d03 PT |
2366 | rc = lmv_check_connect(obd); |
2367 | if (rc) | |
0a3bdb00 | 2368 | return rc; |
d7e09d03 PT |
2369 | |
2370 | /* | |
2371 | * Forwarding this request to first MDS, it should know LOV | |
2372 | * desc. | |
2373 | */ | |
2374 | rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key, | |
2375 | vallen, val, NULL); | |
2376 | if (!rc && KEY_IS(KEY_CONN_DATA)) | |
2377 | exp->exp_connect_data = *(struct obd_connect_data *)val; | |
0a3bdb00 | 2378 | return rc; |
d7e09d03 PT |
2379 | } else if (KEY_IS(KEY_TGT_COUNT)) { |
2380 | *((int *)val) = lmv->desc.ld_tgt_count; | |
0a3bdb00 | 2381 | return 0; |
d7e09d03 PT |
2382 | } |
2383 | ||
2384 | CDEBUG(D_IOCTL, "Invalid key\n"); | |
0a3bdb00 | 2385 | return -EINVAL; |
d7e09d03 PT |
2386 | } |
2387 | ||
5dc8d7b4 LC |
2388 | static int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp, |
2389 | u32 keylen, void *key, u32 vallen, | |
2390 | void *val, struct ptlrpc_request_set *set) | |
d7e09d03 PT |
2391 | { |
2392 | struct lmv_tgt_desc *tgt; | |
2393 | struct obd_device *obd; | |
2394 | struct lmv_obd *lmv; | |
2395 | int rc = 0; | |
d7e09d03 PT |
2396 | |
2397 | obd = class_exp2obd(exp); | |
2398 | if (obd == NULL) { | |
55f5a824 | 2399 | CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n", |
d7e09d03 | 2400 | exp->exp_handle.h_cookie); |
0a3bdb00 | 2401 | return -EINVAL; |
d7e09d03 PT |
2402 | } |
2403 | lmv = &obd->u.lmv; | |
2404 | ||
2405 | if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) { | |
2406 | int i, err = 0; | |
2407 | ||
2408 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
2409 | tgt = lmv->tgts[i]; | |
2410 | ||
2411 | if (tgt == NULL || tgt->ltd_exp == NULL) | |
2412 | continue; | |
2413 | ||
2414 | err = obd_set_info_async(env, tgt->ltd_exp, | |
2415 | keylen, key, vallen, val, set); | |
2416 | if (err && rc == 0) | |
2417 | rc = err; | |
2418 | } | |
2419 | ||
0a3bdb00 | 2420 | return rc; |
d7e09d03 PT |
2421 | } |
2422 | ||
0a3bdb00 | 2423 | return -EINVAL; |
d7e09d03 PT |
2424 | } |
2425 | ||
5dc8d7b4 LC |
2426 | static int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp, |
2427 | struct lov_stripe_md *lsm) | |
d7e09d03 PT |
2428 | { |
2429 | struct obd_device *obd = class_exp2obd(exp); | |
2430 | struct lmv_obd *lmv = &obd->u.lmv; | |
2431 | struct lmv_stripe_md *meap; | |
2432 | struct lmv_stripe_md *lsmp; | |
2433 | int mea_size; | |
2434 | int i; | |
d7e09d03 PT |
2435 | |
2436 | mea_size = lmv_get_easize(lmv); | |
2437 | if (!lmmp) | |
0a3bdb00 | 2438 | return mea_size; |
d7e09d03 PT |
2439 | |
2440 | if (*lmmp && !lsm) { | |
2441 | OBD_FREE_LARGE(*lmmp, mea_size); | |
2442 | *lmmp = NULL; | |
0a3bdb00 | 2443 | return 0; |
d7e09d03 PT |
2444 | } |
2445 | ||
2446 | if (*lmmp == NULL) { | |
2447 | OBD_ALLOC_LARGE(*lmmp, mea_size); | |
2448 | if (*lmmp == NULL) | |
0a3bdb00 | 2449 | return -ENOMEM; |
d7e09d03 PT |
2450 | } |
2451 | ||
2452 | if (!lsm) | |
0a3bdb00 | 2453 | return mea_size; |
d7e09d03 PT |
2454 | |
2455 | lsmp = (struct lmv_stripe_md *)lsm; | |
2456 | meap = (struct lmv_stripe_md *)*lmmp; | |
2457 | ||
2458 | if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR && | |
2459 | lsmp->mea_magic != MEA_MAGIC_ALL_CHARS) | |
0a3bdb00 | 2460 | return -EINVAL; |
d7e09d03 PT |
2461 | |
2462 | meap->mea_magic = cpu_to_le32(lsmp->mea_magic); | |
2463 | meap->mea_count = cpu_to_le32(lsmp->mea_count); | |
2464 | meap->mea_master = cpu_to_le32(lsmp->mea_master); | |
2465 | ||
2466 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
2467 | meap->mea_ids[i] = lsmp->mea_ids[i]; | |
2468 | fid_cpu_to_le(&meap->mea_ids[i], &lsmp->mea_ids[i]); | |
2469 | } | |
2470 | ||
0a3bdb00 | 2471 | return mea_size; |
d7e09d03 PT |
2472 | } |
2473 | ||
5dc8d7b4 LC |
2474 | static int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp, |
2475 | struct lov_mds_md *lmm, int lmm_size) | |
d7e09d03 PT |
2476 | { |
2477 | struct obd_device *obd = class_exp2obd(exp); | |
2478 | struct lmv_stripe_md **tmea = (struct lmv_stripe_md **)lsmp; | |
2479 | struct lmv_stripe_md *mea = (struct lmv_stripe_md *)lmm; | |
2480 | struct lmv_obd *lmv = &obd->u.lmv; | |
2481 | int mea_size; | |
2482 | int i; | |
2483 | __u32 magic; | |
d7e09d03 PT |
2484 | |
2485 | mea_size = lmv_get_easize(lmv); | |
2486 | if (lsmp == NULL) | |
2487 | return mea_size; | |
2488 | ||
2489 | if (*lsmp != NULL && lmm == NULL) { | |
2490 | OBD_FREE_LARGE(*tmea, mea_size); | |
2491 | *lsmp = NULL; | |
0a3bdb00 | 2492 | return 0; |
d7e09d03 PT |
2493 | } |
2494 | ||
2495 | LASSERT(mea_size == lmm_size); | |
2496 | ||
2497 | OBD_ALLOC_LARGE(*tmea, mea_size); | |
2498 | if (*tmea == NULL) | |
0a3bdb00 | 2499 | return -ENOMEM; |
d7e09d03 PT |
2500 | |
2501 | if (!lmm) | |
0a3bdb00 | 2502 | return mea_size; |
d7e09d03 PT |
2503 | |
2504 | if (mea->mea_magic == MEA_MAGIC_LAST_CHAR || | |
2505 | mea->mea_magic == MEA_MAGIC_ALL_CHARS || | |
9d0b2b7a | 2506 | mea->mea_magic == MEA_MAGIC_HASH_SEGMENT) { |
d7e09d03 PT |
2507 | magic = le32_to_cpu(mea->mea_magic); |
2508 | } else { | |
2509 | /* | |
2510 | * Old mea is not handled here. | |
2511 | */ | |
2512 | CERROR("Old not supportable EA is found\n"); | |
2513 | LBUG(); | |
2514 | } | |
2515 | ||
2516 | (*tmea)->mea_magic = magic; | |
2517 | (*tmea)->mea_count = le32_to_cpu(mea->mea_count); | |
2518 | (*tmea)->mea_master = le32_to_cpu(mea->mea_master); | |
2519 | ||
2520 | for (i = 0; i < (*tmea)->mea_count; i++) { | |
2521 | (*tmea)->mea_ids[i] = mea->mea_ids[i]; | |
2522 | fid_le_to_cpu(&(*tmea)->mea_ids[i], &(*tmea)->mea_ids[i]); | |
2523 | } | |
0a3bdb00 | 2524 | return mea_size; |
d7e09d03 PT |
2525 | } |
2526 | ||
2527 | static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid, | |
2528 | ldlm_policy_data_t *policy, ldlm_mode_t mode, | |
2529 | ldlm_cancel_flags_t flags, void *opaque) | |
2530 | { | |
2531 | struct obd_device *obd = exp->exp_obd; | |
2532 | struct lmv_obd *lmv = &obd->u.lmv; | |
2533 | int rc = 0; | |
2534 | int err; | |
2535 | int i; | |
d7e09d03 PT |
2536 | |
2537 | LASSERT(fid != NULL); | |
2538 | ||
2539 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
2540 | if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL || | |
2541 | lmv->tgts[i]->ltd_active == 0) | |
2542 | continue; | |
2543 | ||
2544 | err = md_cancel_unused(lmv->tgts[i]->ltd_exp, fid, | |
2545 | policy, mode, flags, opaque); | |
2546 | if (!rc) | |
2547 | rc = err; | |
2548 | } | |
0a3bdb00 | 2549 | return rc; |
d7e09d03 PT |
2550 | } |
2551 | ||
5dc8d7b4 LC |
2552 | static int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data, |
2553 | __u64 *bits) | |
d7e09d03 PT |
2554 | { |
2555 | struct lmv_obd *lmv = &exp->exp_obd->u.lmv; | |
2556 | int rc; | |
d7e09d03 PT |
2557 | |
2558 | rc = md_set_lock_data(lmv->tgts[0]->ltd_exp, lockh, data, bits); | |
0a3bdb00 | 2559 | return rc; |
d7e09d03 PT |
2560 | } |
2561 | ||
5dc8d7b4 LC |
2562 | static ldlm_mode_t lmv_lock_match(struct obd_export *exp, __u64 flags, |
2563 | const struct lu_fid *fid, ldlm_type_t type, | |
2564 | ldlm_policy_data_t *policy, ldlm_mode_t mode, | |
2565 | struct lustre_handle *lockh) | |
d7e09d03 PT |
2566 | { |
2567 | struct obd_device *obd = exp->exp_obd; | |
2568 | struct lmv_obd *lmv = &obd->u.lmv; | |
2569 | ldlm_mode_t rc; | |
2570 | int i; | |
d7e09d03 PT |
2571 | |
2572 | CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid)); | |
2573 | ||
2574 | /* | |
2575 | * With CMD every object can have two locks in different namespaces: | |
2576 | * lookup lock in space of mds storing direntry and update/open lock in | |
2577 | * space of mds storing inode. Thus we check all targets, not only that | |
2578 | * one fid was created in. | |
2579 | */ | |
2580 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
2581 | if (lmv->tgts[i] == NULL || | |
2582 | lmv->tgts[i]->ltd_exp == NULL || | |
2583 | lmv->tgts[i]->ltd_active == 0) | |
2584 | continue; | |
2585 | ||
2586 | rc = md_lock_match(lmv->tgts[i]->ltd_exp, flags, fid, | |
2587 | type, policy, mode, lockh); | |
2588 | if (rc) | |
0a3bdb00 | 2589 | return rc; |
d7e09d03 PT |
2590 | } |
2591 | ||
0a3bdb00 | 2592 | return 0; |
d7e09d03 PT |
2593 | } |
2594 | ||
5dc8d7b4 LC |
2595 | static int lmv_get_lustre_md(struct obd_export *exp, |
2596 | struct ptlrpc_request *req, | |
2597 | struct obd_export *dt_exp, | |
2598 | struct obd_export *md_exp, | |
2599 | struct lustre_md *md) | |
d7e09d03 PT |
2600 | { |
2601 | struct lmv_obd *lmv = &exp->exp_obd->u.lmv; | |
2602 | ||
2603 | return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md); | |
2604 | } | |
2605 | ||
5dc8d7b4 | 2606 | static int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md) |
d7e09d03 PT |
2607 | { |
2608 | struct obd_device *obd = exp->exp_obd; | |
2609 | struct lmv_obd *lmv = &obd->u.lmv; | |
d7e09d03 PT |
2610 | |
2611 | if (md->mea) | |
2612 | obd_free_memmd(exp, (void *)&md->mea); | |
0a3bdb00 | 2613 | return md_free_lustre_md(lmv->tgts[0]->ltd_exp, md); |
d7e09d03 PT |
2614 | } |
2615 | ||
5dc8d7b4 LC |
2616 | static int lmv_set_open_replay_data(struct obd_export *exp, |
2617 | struct obd_client_handle *och, | |
2618 | struct lookup_intent *it) | |
d7e09d03 PT |
2619 | { |
2620 | struct obd_device *obd = exp->exp_obd; | |
2621 | struct lmv_obd *lmv = &obd->u.lmv; | |
2622 | struct lmv_tgt_desc *tgt; | |
d7e09d03 PT |
2623 | |
2624 | tgt = lmv_find_target(lmv, &och->och_fid); | |
2625 | if (IS_ERR(tgt)) | |
0a3bdb00 | 2626 | return PTR_ERR(tgt); |
d7e09d03 | 2627 | |
63d42578 | 2628 | return md_set_open_replay_data(tgt->ltd_exp, och, it); |
d7e09d03 PT |
2629 | } |
2630 | ||
5dc8d7b4 LC |
2631 | static int lmv_clear_open_replay_data(struct obd_export *exp, |
2632 | struct obd_client_handle *och) | |
d7e09d03 PT |
2633 | { |
2634 | struct obd_device *obd = exp->exp_obd; | |
2635 | struct lmv_obd *lmv = &obd->u.lmv; | |
2636 | struct lmv_tgt_desc *tgt; | |
d7e09d03 PT |
2637 | |
2638 | tgt = lmv_find_target(lmv, &och->och_fid); | |
2639 | if (IS_ERR(tgt)) | |
0a3bdb00 | 2640 | return PTR_ERR(tgt); |
d7e09d03 | 2641 | |
0a3bdb00 | 2642 | return md_clear_open_replay_data(tgt->ltd_exp, och); |
d7e09d03 PT |
2643 | } |
2644 | ||
2645 | static int lmv_get_remote_perm(struct obd_export *exp, | |
2646 | const struct lu_fid *fid, | |
2647 | struct obd_capa *oc, __u32 suppgid, | |
2648 | struct ptlrpc_request **request) | |
2649 | { | |
2650 | struct obd_device *obd = exp->exp_obd; | |
2651 | struct lmv_obd *lmv = &obd->u.lmv; | |
2652 | struct lmv_tgt_desc *tgt; | |
2653 | int rc; | |
d7e09d03 PT |
2654 | |
2655 | rc = lmv_check_connect(obd); | |
2656 | if (rc) | |
0a3bdb00 | 2657 | return rc; |
d7e09d03 PT |
2658 | |
2659 | tgt = lmv_find_target(lmv, fid); | |
2660 | if (IS_ERR(tgt)) | |
0a3bdb00 | 2661 | return PTR_ERR(tgt); |
d7e09d03 PT |
2662 | |
2663 | rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request); | |
0a3bdb00 | 2664 | return rc; |
d7e09d03 PT |
2665 | } |
2666 | ||
2667 | static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc, | |
2668 | renew_capa_cb_t cb) | |
2669 | { | |
2670 | struct obd_device *obd = exp->exp_obd; | |
2671 | struct lmv_obd *lmv = &obd->u.lmv; | |
2672 | struct lmv_tgt_desc *tgt; | |
2673 | int rc; | |
d7e09d03 PT |
2674 | |
2675 | rc = lmv_check_connect(obd); | |
2676 | if (rc) | |
0a3bdb00 | 2677 | return rc; |
d7e09d03 PT |
2678 | |
2679 | tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid); | |
2680 | if (IS_ERR(tgt)) | |
0a3bdb00 | 2681 | return PTR_ERR(tgt); |
d7e09d03 PT |
2682 | |
2683 | rc = md_renew_capa(tgt->ltd_exp, oc, cb); | |
0a3bdb00 | 2684 | return rc; |
d7e09d03 PT |
2685 | } |
2686 | ||
5dc8d7b4 LC |
2687 | static int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req, |
2688 | const struct req_msg_field *field, | |
2689 | struct obd_capa **oc) | |
d7e09d03 PT |
2690 | { |
2691 | struct lmv_obd *lmv = &exp->exp_obd->u.lmv; | |
2692 | ||
2693 | return md_unpack_capa(lmv->tgts[0]->ltd_exp, req, field, oc); | |
2694 | } | |
2695 | ||
5dc8d7b4 LC |
2696 | static int lmv_intent_getattr_async(struct obd_export *exp, |
2697 | struct md_enqueue_info *minfo, | |
2698 | struct ldlm_enqueue_info *einfo) | |
d7e09d03 PT |
2699 | { |
2700 | struct md_op_data *op_data = &minfo->mi_data; | |
2701 | struct obd_device *obd = exp->exp_obd; | |
2702 | struct lmv_obd *lmv = &obd->u.lmv; | |
2703 | struct lmv_tgt_desc *tgt = NULL; | |
2704 | int rc; | |
d7e09d03 PT |
2705 | |
2706 | rc = lmv_check_connect(obd); | |
2707 | if (rc) | |
0a3bdb00 | 2708 | return rc; |
d7e09d03 PT |
2709 | |
2710 | tgt = lmv_find_target(lmv, &op_data->op_fid1); | |
2711 | if (IS_ERR(tgt)) | |
0a3bdb00 | 2712 | return PTR_ERR(tgt); |
d7e09d03 PT |
2713 | |
2714 | rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo); | |
0a3bdb00 | 2715 | return rc; |
d7e09d03 PT |
2716 | } |
2717 | ||
5dc8d7b4 LC |
2718 | static int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it, |
2719 | struct lu_fid *fid, __u64 *bits) | |
d7e09d03 PT |
2720 | { |
2721 | struct obd_device *obd = exp->exp_obd; | |
2722 | struct lmv_obd *lmv = &obd->u.lmv; | |
2723 | struct lmv_tgt_desc *tgt; | |
2724 | int rc; | |
d7e09d03 PT |
2725 | |
2726 | rc = lmv_check_connect(obd); | |
2727 | if (rc) | |
0a3bdb00 | 2728 | return rc; |
d7e09d03 PT |
2729 | |
2730 | tgt = lmv_find_target(lmv, fid); | |
2731 | if (IS_ERR(tgt)) | |
0a3bdb00 | 2732 | return PTR_ERR(tgt); |
d7e09d03 PT |
2733 | |
2734 | rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits); | |
0a3bdb00 | 2735 | return rc; |
d7e09d03 PT |
2736 | } |
2737 | ||
2738 | /** | |
2739 | * For lmv, only need to send request to master MDT, and the master MDT will | |
2740 | * process with other slave MDTs. The only exception is Q_GETOQUOTA for which | |
2741 | * we directly fetch data from the slave MDTs. | |
2742 | */ | |
5dc8d7b4 LC |
2743 | static int lmv_quotactl(struct obd_device *unused, struct obd_export *exp, |
2744 | struct obd_quotactl *oqctl) | |
d7e09d03 PT |
2745 | { |
2746 | struct obd_device *obd = class_exp2obd(exp); | |
2747 | struct lmv_obd *lmv = &obd->u.lmv; | |
2748 | struct lmv_tgt_desc *tgt = lmv->tgts[0]; | |
2749 | int rc = 0, i; | |
2750 | __u64 curspace, curinodes; | |
d7e09d03 PT |
2751 | |
2752 | if (!lmv->desc.ld_tgt_count || !tgt->ltd_active) { | |
2753 | CERROR("master lmv inactive\n"); | |
0a3bdb00 | 2754 | return -EIO; |
d7e09d03 PT |
2755 | } |
2756 | ||
2757 | if (oqctl->qc_cmd != Q_GETOQUOTA) { | |
2758 | rc = obd_quotactl(tgt->ltd_exp, oqctl); | |
0a3bdb00 | 2759 | return rc; |
d7e09d03 PT |
2760 | } |
2761 | ||
2762 | curspace = curinodes = 0; | |
2763 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
2764 | int err; | |
2765 | tgt = lmv->tgts[i]; | |
2766 | ||
2767 | if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0) | |
2768 | continue; | |
2769 | if (!tgt->ltd_active) { | |
2770 | CDEBUG(D_HA, "mdt %d is inactive.\n", i); | |
2771 | continue; | |
2772 | } | |
2773 | ||
2774 | err = obd_quotactl(tgt->ltd_exp, oqctl); | |
2775 | if (err) { | |
2776 | CERROR("getquota on mdt %d failed. %d\n", i, err); | |
2777 | if (!rc) | |
2778 | rc = err; | |
2779 | } else { | |
2780 | curspace += oqctl->qc_dqblk.dqb_curspace; | |
2781 | curinodes += oqctl->qc_dqblk.dqb_curinodes; | |
2782 | } | |
2783 | } | |
2784 | oqctl->qc_dqblk.dqb_curspace = curspace; | |
2785 | oqctl->qc_dqblk.dqb_curinodes = curinodes; | |
2786 | ||
0a3bdb00 | 2787 | return rc; |
d7e09d03 PT |
2788 | } |
2789 | ||
5dc8d7b4 LC |
2790 | static int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp, |
2791 | struct obd_quotactl *oqctl) | |
d7e09d03 PT |
2792 | { |
2793 | struct obd_device *obd = class_exp2obd(exp); | |
2794 | struct lmv_obd *lmv = &obd->u.lmv; | |
2795 | struct lmv_tgt_desc *tgt; | |
2796 | int i, rc = 0; | |
d7e09d03 PT |
2797 | |
2798 | for (i = 0; i < lmv->desc.ld_tgt_count; i++) { | |
2799 | int err; | |
2800 | tgt = lmv->tgts[i]; | |
2801 | if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) { | |
2802 | CERROR("lmv idx %d inactive\n", i); | |
0a3bdb00 | 2803 | return -EIO; |
d7e09d03 PT |
2804 | } |
2805 | ||
2806 | err = obd_quotacheck(tgt->ltd_exp, oqctl); | |
2807 | if (err && !rc) | |
2808 | rc = err; | |
2809 | } | |
2810 | ||
0a3bdb00 | 2811 | return rc; |
d7e09d03 PT |
2812 | } |
2813 | ||
5dc8d7b4 | 2814 | static struct obd_ops lmv_obd_ops = { |
d7e09d03 PT |
2815 | .o_owner = THIS_MODULE, |
2816 | .o_setup = lmv_setup, | |
2817 | .o_cleanup = lmv_cleanup, | |
2818 | .o_precleanup = lmv_precleanup, | |
2819 | .o_process_config = lmv_process_config, | |
2820 | .o_connect = lmv_connect, | |
2821 | .o_disconnect = lmv_disconnect, | |
2822 | .o_statfs = lmv_statfs, | |
2823 | .o_get_info = lmv_get_info, | |
2824 | .o_set_info_async = lmv_set_info_async, | |
2825 | .o_packmd = lmv_packmd, | |
2826 | .o_unpackmd = lmv_unpackmd, | |
2827 | .o_notify = lmv_notify, | |
2828 | .o_get_uuid = lmv_get_uuid, | |
2829 | .o_iocontrol = lmv_iocontrol, | |
2830 | .o_quotacheck = lmv_quotacheck, | |
2831 | .o_quotactl = lmv_quotactl | |
2832 | }; | |
2833 | ||
5dc8d7b4 | 2834 | static struct md_ops lmv_md_ops = { |
d7e09d03 PT |
2835 | .m_getstatus = lmv_getstatus, |
2836 | .m_null_inode = lmv_null_inode, | |
2837 | .m_find_cbdata = lmv_find_cbdata, | |
2838 | .m_close = lmv_close, | |
2839 | .m_create = lmv_create, | |
2840 | .m_done_writing = lmv_done_writing, | |
2841 | .m_enqueue = lmv_enqueue, | |
2842 | .m_getattr = lmv_getattr, | |
2843 | .m_getxattr = lmv_getxattr, | |
2844 | .m_getattr_name = lmv_getattr_name, | |
2845 | .m_intent_lock = lmv_intent_lock, | |
2846 | .m_link = lmv_link, | |
2847 | .m_rename = lmv_rename, | |
2848 | .m_setattr = lmv_setattr, | |
2849 | .m_setxattr = lmv_setxattr, | |
2850 | .m_sync = lmv_sync, | |
2851 | .m_readpage = lmv_readpage, | |
2852 | .m_unlink = lmv_unlink, | |
2853 | .m_init_ea_size = lmv_init_ea_size, | |
2854 | .m_cancel_unused = lmv_cancel_unused, | |
2855 | .m_set_lock_data = lmv_set_lock_data, | |
2856 | .m_lock_match = lmv_lock_match, | |
2857 | .m_get_lustre_md = lmv_get_lustre_md, | |
2858 | .m_free_lustre_md = lmv_free_lustre_md, | |
2859 | .m_set_open_replay_data = lmv_set_open_replay_data, | |
2860 | .m_clear_open_replay_data = lmv_clear_open_replay_data, | |
2861 | .m_renew_capa = lmv_renew_capa, | |
2862 | .m_unpack_capa = lmv_unpack_capa, | |
2863 | .m_get_remote_perm = lmv_get_remote_perm, | |
2864 | .m_intent_getattr_async = lmv_intent_getattr_async, | |
2865 | .m_revalidate_lock = lmv_revalidate_lock | |
2866 | }; | |
2867 | ||
5dc8d7b4 | 2868 | static int __init lmv_init(void) |
d7e09d03 PT |
2869 | { |
2870 | struct lprocfs_static_vars lvars; | |
2871 | int rc; | |
2872 | ||
2873 | lprocfs_lmv_init_vars(&lvars); | |
2874 | ||
2875 | rc = class_register_type(&lmv_obd_ops, &lmv_md_ops, | |
2876 | lvars.module_vars, LUSTRE_LMV_NAME, NULL); | |
2877 | return rc; | |
2878 | } | |
2879 | ||
2880 | static void lmv_exit(void) | |
2881 | { | |
2882 | class_unregister_type(LUSTRE_LMV_NAME); | |
2883 | } | |
2884 | ||
2885 | MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>"); | |
2886 | MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver"); | |
2887 | MODULE_LICENSE("GPL"); | |
2888 | ||
2889 | module_init(lmv_init); | |
2890 | module_exit(lmv_exit); |