]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/lustre/lustre/lmv/lmv_obd.c
iio: imu: inv_mpu6050: test whoami first and against all known values
[mirror_ubuntu-artful-kernel.git] / drivers / staging / lustre / lustre / lmv / lmv_obd.c
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.gnu.org/licenses/gpl-2.0.html
19 *
20 * GPL HEADER END
21 */
22 /*
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
25 *
26 * Copyright (c) 2011, 2015, Intel Corporation.
27 */
28 /*
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
31 */
32
33 #define DEBUG_SUBSYSTEM S_LMV
34 #include <linux/slab.h>
35 #include <linux/module.h>
36 #include <linux/init.h>
37 #include <linux/pagemap.h>
38 #include <linux/mm.h>
39 #include <asm/div64.h>
40 #include <linux/seq_file.h>
41 #include <linux/namei.h>
42 #include <linux/uaccess.h>
43
44 #include "../include/lustre/lustre_idl.h"
45 #include "../include/obd_support.h"
46 #include "../include/lustre_net.h"
47 #include "../include/obd_class.h"
48 #include "../include/lustre_lmv.h"
49 #include "../include/lprocfs_status.h"
50 #include "../include/cl_object.h"
51 #include "../include/lustre_fid.h"
52 #include "../include/lustre/lustre_ioctl.h"
53 #include "../include/lustre_kernelcomm.h"
54 #include "lmv_internal.h"
55
56 static void lmv_activate_target(struct lmv_obd *lmv,
57 struct lmv_tgt_desc *tgt,
58 int activate)
59 {
60 if (tgt->ltd_active == activate)
61 return;
62
63 tgt->ltd_active = activate;
64 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
65 tgt->ltd_exp->exp_obd->obd_inactive = !activate;
66 }
67
68 /**
69 * Error codes:
70 *
71 * -EINVAL : UUID can't be found in the LMV's target list
72 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
73 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
74 */
75 static int lmv_set_mdc_active(struct lmv_obd *lmv, const struct obd_uuid *uuid,
76 int activate)
77 {
78 struct lmv_tgt_desc *uninitialized_var(tgt);
79 struct obd_device *obd;
80 u32 i;
81 int rc = 0;
82
83 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
84 lmv, uuid->uuid, activate);
85
86 spin_lock(&lmv->lmv_lock);
87 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
88 tgt = lmv->tgts[i];
89 if (!tgt || !tgt->ltd_exp)
90 continue;
91
92 CDEBUG(D_INFO, "Target idx %d is %s conn %#llx\n", i,
93 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
94
95 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
96 break;
97 }
98
99 if (i == lmv->desc.ld_tgt_count) {
100 rc = -EINVAL;
101 goto out_lmv_lock;
102 }
103
104 obd = class_exp2obd(tgt->ltd_exp);
105 if (!obd) {
106 rc = -ENOTCONN;
107 goto out_lmv_lock;
108 }
109
110 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
111 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
112 obd->obd_type->typ_name, i);
113 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
114
115 if (tgt->ltd_active == activate) {
116 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
117 activate ? "" : "in");
118 goto out_lmv_lock;
119 }
120
121 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
122 activate ? "" : "in");
123 lmv_activate_target(lmv, tgt, activate);
124
125 out_lmv_lock:
126 spin_unlock(&lmv->lmv_lock);
127 return rc;
128 }
129
130 static struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
131 {
132 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
133 struct lmv_tgt_desc *tgt = lmv->tgts[0];
134
135 return tgt ? obd_get_uuid(tgt->ltd_exp) : NULL;
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;
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);
150 return -EINVAL;
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);
165 return rc;
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
177 /*
178 * Pass the notification up the chain.
179 */
180 if (obd->obd_observer)
181 rc = obd_notify(obd->obd_observer, watched, ev, data);
182
183 return rc;
184 }
185
186 /**
187 * This is fake connect function. Its purpose is to initialize lmv and say
188 * caller that everything is okay. Real connection will be performed later.
189 */
190 static int lmv_connect(const struct lu_env *env,
191 struct obd_export **exp, struct obd_device *obd,
192 struct obd_uuid *cluuid, struct obd_connect_data *data,
193 void *localdata)
194 {
195 struct lmv_obd *lmv = &obd->u.lmv;
196 struct lustre_handle conn = { 0 };
197 int rc = 0;
198
199 /*
200 * We don't want to actually do the underlying connections more than
201 * once, so keep track.
202 */
203 lmv->refcount++;
204 if (lmv->refcount > 1) {
205 *exp = NULL;
206 return 0;
207 }
208
209 rc = class_connect(&conn, obd, cluuid);
210 if (rc) {
211 CERROR("class_connection() returned %d\n", rc);
212 return rc;
213 }
214
215 *exp = class_conn2export(&conn);
216 class_export_get(*exp);
217
218 lmv->exp = *exp;
219 lmv->connected = 0;
220 lmv->cluuid = *cluuid;
221
222 if (data)
223 lmv->conn_data = *data;
224
225 lmv->lmv_tgts_kobj = kobject_create_and_add("target_obds",
226 &obd->obd_kobj);
227 /*
228 * All real clients should perform actual connection right away, because
229 * it is possible, that LMV will not have opportunity to connect targets
230 * and MDC stuff will be called directly, for instance while reading
231 * ../mdc/../kbytesfree procfs file, etc.
232 */
233 if (data && data->ocd_connect_flags & OBD_CONNECT_REAL)
234 rc = lmv_check_connect(obd);
235
236 if (rc && lmv->lmv_tgts_kobj)
237 kobject_put(lmv->lmv_tgts_kobj);
238
239 return rc;
240 }
241
242 static int lmv_init_ea_size(struct obd_export *exp, u32 easize, u32 def_easize)
243 {
244 struct obd_device *obd = exp->exp_obd;
245 struct lmv_obd *lmv = &obd->u.lmv;
246 u32 i;
247 int rc = 0;
248 int change = 0;
249
250 if (lmv->max_easize < easize) {
251 lmv->max_easize = easize;
252 change = 1;
253 }
254 if (lmv->max_def_easize < def_easize) {
255 lmv->max_def_easize = def_easize;
256 change = 1;
257 }
258
259 if (change == 0)
260 return 0;
261
262 if (lmv->connected == 0)
263 return 0;
264
265 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
266 struct lmv_tgt_desc *tgt = lmv->tgts[i];
267
268 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active) {
269 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
270 continue;
271 }
272
273 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize);
274 if (rc) {
275 CERROR("%s: obd_init_ea_size() failed on MDT target %d: rc = %d\n",
276 obd->obd_name, i, rc);
277 break;
278 }
279 }
280 return rc;
281 }
282
283 #define MAX_STRING_SIZE 128
284
285 static int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
286 {
287 struct lmv_obd *lmv = &obd->u.lmv;
288 struct obd_uuid *cluuid = &lmv->cluuid;
289 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
290 struct obd_device *mdc_obd;
291 struct obd_export *mdc_exp;
292 struct lu_fld_target target;
293 int rc;
294
295 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
296 &obd->obd_uuid);
297 if (!mdc_obd) {
298 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
299 return -EINVAL;
300 }
301
302 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
303 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
304 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid, cluuid->uuid);
305
306 if (!mdc_obd->obd_set_up) {
307 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
308 return -EINVAL;
309 }
310
311 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
312 &lmv->conn_data, NULL);
313 if (rc) {
314 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
315 return rc;
316 }
317
318 /*
319 * Init fid sequence client for this mdc and add new fld target.
320 */
321 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
322 if (rc)
323 return rc;
324
325 target.ft_srv = NULL;
326 target.ft_exp = mdc_exp;
327 target.ft_idx = tgt->ltd_idx;
328
329 fld_client_add_target(&lmv->lmv_fld, &target);
330
331 rc = obd_register_observer(mdc_obd, obd);
332 if (rc) {
333 obd_disconnect(mdc_exp);
334 CERROR("target %s register_observer error %d\n",
335 tgt->ltd_uuid.uuid, rc);
336 return rc;
337 }
338
339 if (obd->obd_observer) {
340 /*
341 * Tell the observer about the new target.
342 */
343 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
344 OBD_NOTIFY_ACTIVE,
345 (void *)(tgt - lmv->tgts[0]));
346 if (rc) {
347 obd_disconnect(mdc_exp);
348 return rc;
349 }
350 }
351
352 tgt->ltd_active = 1;
353 tgt->ltd_exp = mdc_exp;
354 lmv->desc.ld_active_tgt_count++;
355
356 md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize);
357
358 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
359 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
360 atomic_read(&obd->obd_refcount));
361
362 if (lmv->lmv_tgts_kobj)
363 /* Even if we failed to create the link, that's fine */
364 rc = sysfs_create_link(lmv->lmv_tgts_kobj, &mdc_obd->obd_kobj,
365 mdc_obd->obd_name);
366 return 0;
367 }
368
369 static void lmv_del_target(struct lmv_obd *lmv, int index)
370 {
371 if (!lmv->tgts[index])
372 return;
373
374 kfree(lmv->tgts[index]);
375 lmv->tgts[index] = NULL;
376 }
377
378 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
379 __u32 index, int gen)
380 {
381 struct lmv_obd *lmv = &obd->u.lmv;
382 struct obd_device *mdc_obd;
383 struct lmv_tgt_desc *tgt;
384 int orig_tgt_count = 0;
385 int rc = 0;
386
387 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
388
389 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
390 &obd->obd_uuid);
391 if (!mdc_obd) {
392 CERROR("%s: Target %s not attached: rc = %d\n",
393 obd->obd_name, uuidp->uuid, -EINVAL);
394 return -EINVAL;
395 }
396
397 mutex_lock(&lmv->lmv_init_mutex);
398
399 if ((index < lmv->tgts_size) && lmv->tgts[index]) {
400 tgt = lmv->tgts[index];
401 CERROR("%s: UUID %s already assigned at LOV target index %d: rc = %d\n",
402 obd->obd_name,
403 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
404 mutex_unlock(&lmv->lmv_init_mutex);
405 return -EEXIST;
406 }
407
408 if (index >= lmv->tgts_size) {
409 /* We need to reallocate the lmv target array. */
410 struct lmv_tgt_desc **newtgts, **old = NULL;
411 __u32 newsize = 1;
412 __u32 oldsize = 0;
413
414 while (newsize < index + 1)
415 newsize <<= 1;
416 newtgts = kcalloc(newsize, sizeof(*newtgts), GFP_NOFS);
417 if (!newtgts) {
418 mutex_unlock(&lmv->lmv_init_mutex);
419 return -ENOMEM;
420 }
421
422 if (lmv->tgts_size) {
423 memcpy(newtgts, lmv->tgts,
424 sizeof(*newtgts) * lmv->tgts_size);
425 old = lmv->tgts;
426 oldsize = lmv->tgts_size;
427 }
428
429 lmv->tgts = newtgts;
430 lmv->tgts_size = newsize;
431 smp_rmb();
432 kfree(old);
433
434 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
435 lmv->tgts_size);
436 }
437
438 tgt = kzalloc(sizeof(*tgt), GFP_NOFS);
439 if (!tgt) {
440 mutex_unlock(&lmv->lmv_init_mutex);
441 return -ENOMEM;
442 }
443
444 mutex_init(&tgt->ltd_fid_mutex);
445 tgt->ltd_idx = index;
446 tgt->ltd_uuid = *uuidp;
447 tgt->ltd_active = 0;
448 lmv->tgts[index] = tgt;
449 if (index >= lmv->desc.ld_tgt_count) {
450 orig_tgt_count = lmv->desc.ld_tgt_count;
451 lmv->desc.ld_tgt_count = index + 1;
452 }
453
454 if (!lmv->connected) {
455 /* lmv_check_connect() will connect this target. */
456 mutex_unlock(&lmv->lmv_init_mutex);
457 return rc;
458 }
459
460 /* Otherwise let's connect it ourselves */
461 mutex_unlock(&lmv->lmv_init_mutex);
462 rc = lmv_connect_mdc(obd, tgt);
463 if (rc) {
464 spin_lock(&lmv->lmv_lock);
465 if (lmv->desc.ld_tgt_count == index + 1)
466 lmv->desc.ld_tgt_count = orig_tgt_count;
467 memset(tgt, 0, sizeof(*tgt));
468 spin_unlock(&lmv->lmv_lock);
469 } else {
470 int easize = sizeof(struct lmv_stripe_md) +
471 lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
472 lmv_init_ea_size(obd->obd_self_export, easize, 0);
473 }
474
475 return rc;
476 }
477
478 int lmv_check_connect(struct obd_device *obd)
479 {
480 struct lmv_obd *lmv = &obd->u.lmv;
481 struct lmv_tgt_desc *tgt;
482 u32 i;
483 int rc;
484 int easize;
485
486 if (lmv->connected)
487 return 0;
488
489 mutex_lock(&lmv->lmv_init_mutex);
490 if (lmv->connected) {
491 mutex_unlock(&lmv->lmv_init_mutex);
492 return 0;
493 }
494
495 if (lmv->desc.ld_tgt_count == 0) {
496 mutex_unlock(&lmv->lmv_init_mutex);
497 CERROR("%s: no targets configured.\n", obd->obd_name);
498 return -EINVAL;
499 }
500
501 LASSERT(lmv->tgts);
502
503 if (!lmv->tgts[0]) {
504 mutex_unlock(&lmv->lmv_init_mutex);
505 CERROR("%s: no target configured for index 0.\n",
506 obd->obd_name);
507 return -EINVAL;
508 }
509
510 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
511 lmv->cluuid.uuid, obd->obd_name);
512
513 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
514 tgt = lmv->tgts[i];
515 if (!tgt)
516 continue;
517 rc = lmv_connect_mdc(obd, tgt);
518 if (rc)
519 goto out_disc;
520 }
521
522 class_export_put(lmv->exp);
523 lmv->connected = 1;
524 easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
525 lmv_init_ea_size(obd->obd_self_export, easize, 0);
526 mutex_unlock(&lmv->lmv_init_mutex);
527 return 0;
528
529 out_disc:
530 while (i-- > 0) {
531 int rc2;
532
533 tgt = lmv->tgts[i];
534 if (!tgt)
535 continue;
536 tgt->ltd_active = 0;
537 if (tgt->ltd_exp) {
538 --lmv->desc.ld_active_tgt_count;
539 rc2 = obd_disconnect(tgt->ltd_exp);
540 if (rc2) {
541 CERROR("LMV target %s disconnect on MDC idx %d: error %d\n",
542 tgt->ltd_uuid.uuid, i, rc2);
543 }
544 }
545 }
546 class_disconnect(lmv->exp);
547 mutex_unlock(&lmv->lmv_init_mutex);
548 return rc;
549 }
550
551 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
552 {
553 struct lmv_obd *lmv = &obd->u.lmv;
554 struct obd_device *mdc_obd;
555 int rc;
556
557 mdc_obd = class_exp2obd(tgt->ltd_exp);
558
559 if (mdc_obd) {
560 mdc_obd->obd_force = obd->obd_force;
561 mdc_obd->obd_fail = obd->obd_fail;
562 mdc_obd->obd_no_recov = obd->obd_no_recov;
563
564 if (lmv->lmv_tgts_kobj)
565 sysfs_remove_link(lmv->lmv_tgts_kobj,
566 mdc_obd->obd_name);
567 }
568
569 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
570 if (rc)
571 CERROR("Can't finalize fids factory\n");
572
573 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
574 tgt->ltd_exp->exp_obd->obd_name,
575 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
576
577 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
578 rc = obd_disconnect(tgt->ltd_exp);
579 if (rc) {
580 if (tgt->ltd_active) {
581 CERROR("Target %s disconnect error %d\n",
582 tgt->ltd_uuid.uuid, rc);
583 }
584 }
585
586 lmv_activate_target(lmv, tgt, 0);
587 tgt->ltd_exp = NULL;
588 return 0;
589 }
590
591 static int lmv_disconnect(struct obd_export *exp)
592 {
593 struct obd_device *obd = class_exp2obd(exp);
594 struct lmv_obd *lmv = &obd->u.lmv;
595 int rc;
596 u32 i;
597
598 if (!lmv->tgts)
599 goto out_local;
600
601 /*
602 * Only disconnect the underlying layers on the final disconnect.
603 */
604 lmv->refcount--;
605 if (lmv->refcount != 0)
606 goto out_local;
607
608 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
609 if (!lmv->tgts[i] || !lmv->tgts[i]->ltd_exp)
610 continue;
611
612 lmv_disconnect_mdc(obd, lmv->tgts[i]);
613 }
614
615 if (lmv->lmv_tgts_kobj)
616 kobject_put(lmv->lmv_tgts_kobj);
617
618 out_local:
619 /*
620 * This is the case when no real connection is established by
621 * lmv_check_connect().
622 */
623 if (!lmv->connected)
624 class_export_put(exp);
625 rc = class_disconnect(exp);
626 if (lmv->refcount == 0)
627 lmv->connected = 0;
628 return rc;
629 }
630
631 static int lmv_fid2path(struct obd_export *exp, int len, void *karg,
632 void __user *uarg)
633 {
634 struct obd_device *obddev = class_exp2obd(exp);
635 struct lmv_obd *lmv = &obddev->u.lmv;
636 struct getinfo_fid2path *gf;
637 struct lmv_tgt_desc *tgt;
638 struct getinfo_fid2path *remote_gf = NULL;
639 int remote_gf_size = 0;
640 int rc;
641
642 gf = karg;
643 tgt = lmv_find_target(lmv, &gf->gf_fid);
644 if (IS_ERR(tgt))
645 return PTR_ERR(tgt);
646
647 repeat_fid2path:
648 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
649 if (rc != 0 && rc != -EREMOTE)
650 goto out_fid2path;
651
652 /* If remote_gf != NULL, it means just building the
653 * path on the remote MDT, copy this path segment to gf
654 */
655 if (remote_gf) {
656 struct getinfo_fid2path *ori_gf;
657 char *ptr;
658
659 ori_gf = karg;
660 if (strlen(ori_gf->gf_path) +
661 strlen(gf->gf_path) > ori_gf->gf_pathlen) {
662 rc = -EOVERFLOW;
663 goto out_fid2path;
664 }
665
666 ptr = ori_gf->gf_path;
667
668 memmove(ptr + strlen(gf->gf_path) + 1, ptr,
669 strlen(ori_gf->gf_path));
670
671 strncpy(ptr, gf->gf_path, strlen(gf->gf_path));
672 ptr += strlen(gf->gf_path);
673 *ptr = '/';
674 }
675
676 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: %llu ln: %u\n",
677 tgt->ltd_exp->exp_obd->obd_name,
678 gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno,
679 gf->gf_linkno);
680
681 if (rc == 0)
682 goto out_fid2path;
683
684 /* sigh, has to go to another MDT to do path building further */
685 if (!remote_gf) {
686 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
687 remote_gf = kzalloc(remote_gf_size, GFP_NOFS);
688 if (!remote_gf) {
689 rc = -ENOMEM;
690 goto out_fid2path;
691 }
692 remote_gf->gf_pathlen = PATH_MAX;
693 }
694
695 if (!fid_is_sane(&gf->gf_fid)) {
696 CERROR("%s: invalid FID "DFID": rc = %d\n",
697 tgt->ltd_exp->exp_obd->obd_name,
698 PFID(&gf->gf_fid), -EINVAL);
699 rc = -EINVAL;
700 goto out_fid2path;
701 }
702
703 tgt = lmv_find_target(lmv, &gf->gf_fid);
704 if (IS_ERR(tgt)) {
705 rc = -EINVAL;
706 goto out_fid2path;
707 }
708
709 remote_gf->gf_fid = gf->gf_fid;
710 remote_gf->gf_recno = -1;
711 remote_gf->gf_linkno = -1;
712 memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen);
713 gf = remote_gf;
714 goto repeat_fid2path;
715
716 out_fid2path:
717 kfree(remote_gf);
718 return rc;
719 }
720
721 static int lmv_hsm_req_count(struct lmv_obd *lmv,
722 const struct hsm_user_request *hur,
723 const struct lmv_tgt_desc *tgt_mds)
724 {
725 u32 i, nr = 0;
726 struct lmv_tgt_desc *curr_tgt;
727
728 /* count how many requests must be sent to the given target */
729 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
730 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
731 if (IS_ERR(curr_tgt))
732 return PTR_ERR(curr_tgt);
733 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
734 nr++;
735 }
736 return nr;
737 }
738
739 static int lmv_hsm_req_build(struct lmv_obd *lmv,
740 struct hsm_user_request *hur_in,
741 const struct lmv_tgt_desc *tgt_mds,
742 struct hsm_user_request *hur_out)
743 {
744 int i, nr_out;
745 struct lmv_tgt_desc *curr_tgt;
746
747 /* build the hsm_user_request for the given target */
748 hur_out->hur_request = hur_in->hur_request;
749 nr_out = 0;
750 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
751 curr_tgt = lmv_find_target(lmv,
752 &hur_in->hur_user_item[i].hui_fid);
753 if (IS_ERR(curr_tgt))
754 return PTR_ERR(curr_tgt);
755 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
756 hur_out->hur_user_item[nr_out] =
757 hur_in->hur_user_item[i];
758 nr_out++;
759 }
760 }
761 hur_out->hur_request.hr_itemcount = nr_out;
762 memcpy(hur_data(hur_out), hur_data(hur_in),
763 hur_in->hur_request.hr_data_len);
764
765 return 0;
766 }
767
768 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
769 struct lustre_kernelcomm *lk,
770 void __user *uarg)
771 {
772 __u32 i;
773
774 /* unregister request (call from llapi_hsm_copytool_fini) */
775 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
776 struct lmv_tgt_desc *tgt = lmv->tgts[i];
777
778 if (!tgt || !tgt->ltd_exp)
779 continue;
780
781 /* best effort: try to clean as much as possible
782 * (continue on error)
783 */
784 obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, len, lk, uarg);
785 }
786
787 /* Whatever the result, remove copytool from kuc groups.
788 * Unreached coordinators will get EPIPE on next requests
789 * and will unregister automatically.
790 */
791 return libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
792 }
793
794 static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
795 struct lustre_kernelcomm *lk, void __user *uarg)
796 {
797 struct file *filp;
798 __u32 i, j;
799 int err, rc = 0;
800 bool any_set = false;
801 struct kkuc_ct_data kcd = { 0 };
802
803 /* All or nothing: try to register to all MDS.
804 * In case of failure, unregister from previous MDS,
805 * except if it because of inactive target.
806 */
807 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
808 struct lmv_tgt_desc *tgt = lmv->tgts[i];
809
810 if (!tgt || !tgt->ltd_exp)
811 continue;
812
813 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
814 if (err) {
815 if (tgt->ltd_active) {
816 /* permanent error */
817 CERROR("error: iocontrol MDC %s on MDTidx %d cmd %x: err = %d\n",
818 tgt->ltd_uuid.uuid, i, cmd, err);
819 rc = err;
820 lk->lk_flags |= LK_FLG_STOP;
821 /* unregister from previous MDS */
822 for (j = 0; j < i; j++) {
823 tgt = lmv->tgts[j];
824
825 if (!tgt || !tgt->ltd_exp)
826 continue;
827 obd_iocontrol(cmd, tgt->ltd_exp, len,
828 lk, uarg);
829 }
830 return rc;
831 }
832 /* else: transient error.
833 * kuc will register to the missing MDT when it is back
834 */
835 } else {
836 any_set = true;
837 }
838 }
839
840 if (!any_set)
841 /* no registration done: return error */
842 return -ENOTCONN;
843
844 /* at least one registration done, with no failure */
845 filp = fget(lk->lk_wfd);
846 if (!filp)
847 return -EBADF;
848
849 kcd.kcd_magic = KKUC_CT_DATA_MAGIC;
850 kcd.kcd_uuid = lmv->cluuid;
851 kcd.kcd_archive = lk->lk_data;
852
853 rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group,
854 &kcd, sizeof(kcd));
855 if (rc)
856 fput(filp);
857
858 return rc;
859 }
860
861 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
862 int len, void *karg, void __user *uarg)
863 {
864 struct obd_device *obddev = class_exp2obd(exp);
865 struct lmv_obd *lmv = &obddev->u.lmv;
866 struct lmv_tgt_desc *tgt = NULL;
867 u32 i = 0;
868 int rc = 0;
869 int set = 0;
870 u32 count = lmv->desc.ld_tgt_count;
871
872 if (count == 0)
873 return -ENOTTY;
874
875 switch (cmd) {
876 case IOC_OBD_STATFS: {
877 struct obd_ioctl_data *data = karg;
878 struct obd_device *mdc_obd;
879 struct obd_statfs stat_buf = {0};
880 __u32 index;
881
882 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
883 if (index >= count)
884 return -ENODEV;
885
886 tgt = lmv->tgts[index];
887 if (!tgt || !tgt->ltd_active)
888 return -ENODATA;
889
890 mdc_obd = class_exp2obd(tgt->ltd_exp);
891 if (!mdc_obd)
892 return -EINVAL;
893
894 /* copy UUID */
895 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
896 min((int)data->ioc_plen2,
897 (int)sizeof(struct obd_uuid))))
898 return -EFAULT;
899
900 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
901 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
902 0);
903 if (rc)
904 return rc;
905 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
906 min((int)data->ioc_plen1,
907 (int)sizeof(stat_buf))))
908 return -EFAULT;
909 break;
910 }
911 case OBD_IOC_QUOTACTL: {
912 struct if_quotactl *qctl = karg;
913 struct obd_quotactl *oqctl;
914
915 if (qctl->qc_valid == QC_MDTIDX) {
916 if (count <= qctl->qc_idx)
917 return -EINVAL;
918
919 tgt = lmv->tgts[qctl->qc_idx];
920 if (!tgt || !tgt->ltd_exp)
921 return -EINVAL;
922 } else if (qctl->qc_valid == QC_UUID) {
923 for (i = 0; i < count; i++) {
924 tgt = lmv->tgts[i];
925 if (!tgt)
926 continue;
927 if (!obd_uuid_equals(&tgt->ltd_uuid,
928 &qctl->obd_uuid))
929 continue;
930
931 if (!tgt->ltd_exp)
932 return -EINVAL;
933
934 break;
935 }
936 } else {
937 return -EINVAL;
938 }
939
940 if (i >= count)
941 return -EAGAIN;
942
943 LASSERT(tgt && tgt->ltd_exp);
944 oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS);
945 if (!oqctl)
946 return -ENOMEM;
947
948 QCTL_COPY(oqctl, qctl);
949 rc = obd_quotactl(tgt->ltd_exp, oqctl);
950 if (rc == 0) {
951 QCTL_COPY(qctl, oqctl);
952 qctl->qc_valid = QC_MDTIDX;
953 qctl->obd_uuid = tgt->ltd_uuid;
954 }
955 kfree(oqctl);
956 break;
957 }
958 case OBD_IOC_CHANGELOG_SEND:
959 case OBD_IOC_CHANGELOG_CLEAR: {
960 struct ioc_changelog *icc = karg;
961
962 if (icc->icc_mdtindex >= count)
963 return -ENODEV;
964
965 tgt = lmv->tgts[icc->icc_mdtindex];
966 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
967 return -ENODEV;
968 rc = obd_iocontrol(cmd, tgt->ltd_exp, sizeof(*icc), icc, NULL);
969 break;
970 }
971 case LL_IOC_GET_CONNECT_FLAGS: {
972 tgt = lmv->tgts[0];
973
974 if (!tgt || !tgt->ltd_exp)
975 return -ENODATA;
976 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
977 break;
978 }
979 case LL_IOC_FID2MDTIDX: {
980 struct lu_fid *fid = karg;
981 int mdt_index;
982
983 rc = lmv_fld_lookup(lmv, fid, &mdt_index);
984 if (rc)
985 return rc;
986
987 /*
988 * Note: this is from llite(see ll_dir_ioctl()), @uarg does not
989 * point to user space memory for FID2MDTIDX.
990 */
991 *(__u32 *)uarg = mdt_index;
992 break;
993 }
994 case OBD_IOC_FID2PATH: {
995 rc = lmv_fid2path(exp, len, karg, uarg);
996 break;
997 }
998 case LL_IOC_HSM_STATE_GET:
999 case LL_IOC_HSM_STATE_SET:
1000 case LL_IOC_HSM_ACTION: {
1001 struct md_op_data *op_data = karg;
1002
1003 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1004 if (IS_ERR(tgt))
1005 return PTR_ERR(tgt);
1006
1007 if (!tgt->ltd_exp)
1008 return -EINVAL;
1009
1010 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1011 break;
1012 }
1013 case LL_IOC_HSM_PROGRESS: {
1014 const struct hsm_progress_kernel *hpk = karg;
1015
1016 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1017 if (IS_ERR(tgt))
1018 return PTR_ERR(tgt);
1019 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1020 break;
1021 }
1022 case LL_IOC_HSM_REQUEST: {
1023 struct hsm_user_request *hur = karg;
1024 unsigned int reqcount = hur->hur_request.hr_itemcount;
1025
1026 if (reqcount == 0)
1027 return 0;
1028
1029 /* if the request is about a single fid
1030 * or if there is a single MDS, no need to split
1031 * the request.
1032 */
1033 if (reqcount == 1 || count == 1) {
1034 tgt = lmv_find_target(lmv,
1035 &hur->hur_user_item[0].hui_fid);
1036 if (IS_ERR(tgt))
1037 return PTR_ERR(tgt);
1038 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1039 } else {
1040 /* split fid list to their respective MDS */
1041 for (i = 0; i < count; i++) {
1042 struct hsm_user_request *req;
1043 size_t reqlen;
1044 int nr, rc1;
1045
1046 tgt = lmv->tgts[i];
1047 if (!tgt || !tgt->ltd_exp)
1048 continue;
1049
1050 nr = lmv_hsm_req_count(lmv, hur, tgt);
1051 if (nr < 0)
1052 return nr;
1053 if (nr == 0) /* nothing for this MDS */
1054 continue;
1055
1056 /* build a request with fids for this MDS */
1057 reqlen = offsetof(typeof(*hur),
1058 hur_user_item[nr])
1059 + hur->hur_request.hr_data_len;
1060 req = libcfs_kvzalloc(reqlen, GFP_NOFS);
1061 if (!req)
1062 return -ENOMEM;
1063
1064 rc1 = lmv_hsm_req_build(lmv, hur, tgt, req);
1065 if (rc1 < 0)
1066 goto hsm_req_err;
1067
1068 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1069 req, uarg);
1070 hsm_req_err:
1071 if (rc1 != 0 && rc == 0)
1072 rc = rc1;
1073 kvfree(req);
1074 }
1075 }
1076 break;
1077 }
1078 case LL_IOC_LOV_SWAP_LAYOUTS: {
1079 struct md_op_data *op_data = karg;
1080 struct lmv_tgt_desc *tgt1, *tgt2;
1081
1082 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1083 if (IS_ERR(tgt1))
1084 return PTR_ERR(tgt1);
1085
1086 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1087 if (IS_ERR(tgt2))
1088 return PTR_ERR(tgt2);
1089
1090 if (!tgt1->ltd_exp || !tgt2->ltd_exp)
1091 return -EINVAL;
1092
1093 /* only files on same MDT can have their layouts swapped */
1094 if (tgt1->ltd_idx != tgt2->ltd_idx)
1095 return -EPERM;
1096
1097 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1098 break;
1099 }
1100 case LL_IOC_HSM_CT_START: {
1101 struct lustre_kernelcomm *lk = karg;
1102
1103 if (lk->lk_flags & LK_FLG_STOP)
1104 rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
1105 else
1106 rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
1107 break;
1108 }
1109 default:
1110 for (i = 0; i < count; i++) {
1111 struct obd_device *mdc_obd;
1112 int err;
1113
1114 tgt = lmv->tgts[i];
1115 if (!tgt || !tgt->ltd_exp)
1116 continue;
1117 /* ll_umount_begin() sets force flag but for lmv, not
1118 * mdc. Let's pass it through
1119 */
1120 mdc_obd = class_exp2obd(tgt->ltd_exp);
1121 mdc_obd->obd_force = obddev->obd_force;
1122 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1123 if (err) {
1124 if (tgt->ltd_active) {
1125 CERROR("error: iocontrol MDC %s on MDTidx %d cmd %x: err = %d\n",
1126 tgt->ltd_uuid.uuid, i, cmd, err);
1127 if (!rc)
1128 rc = err;
1129 }
1130 } else {
1131 set = 1;
1132 }
1133 }
1134 if (!set && !rc)
1135 rc = -EIO;
1136 }
1137 return rc;
1138 }
1139
1140 /**
1141 * This is _inode_ placement policy function (not name).
1142 */
1143 static int lmv_placement_policy(struct obd_device *obd,
1144 struct md_op_data *op_data, u32 *mds)
1145 {
1146 struct lmv_obd *lmv = &obd->u.lmv;
1147
1148 LASSERT(mds);
1149
1150 if (lmv->desc.ld_tgt_count == 1) {
1151 *mds = 0;
1152 return 0;
1153 }
1154
1155 if (op_data->op_default_stripe_offset != -1) {
1156 *mds = op_data->op_default_stripe_offset;
1157 return 0;
1158 }
1159
1160 /**
1161 * If stripe_offset is provided during setdirstripe
1162 * (setdirstripe -i xx), xx MDS will be chosen.
1163 */
1164 if (op_data->op_cli_flags & CLI_SET_MEA && op_data->op_data) {
1165 struct lmv_user_md *lum;
1166
1167 lum = op_data->op_data;
1168 if (le32_to_cpu(lum->lum_stripe_offset) != (__u32)-1) {
1169 *mds = le32_to_cpu(lum->lum_stripe_offset);
1170 } else {
1171 /*
1172 * -1 means default, which will be in the same MDT with
1173 * the stripe
1174 */
1175 *mds = op_data->op_mds;
1176 lum->lum_stripe_offset = cpu_to_le32(op_data->op_mds);
1177 }
1178 } else {
1179 /*
1180 * Allocate new fid on target according to operation type and
1181 * parent home mds.
1182 */
1183 *mds = op_data->op_mds;
1184 }
1185
1186 return 0;
1187 }
1188
1189 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds)
1190 {
1191 struct lmv_tgt_desc *tgt;
1192 int rc;
1193
1194 tgt = lmv_get_target(lmv, mds, NULL);
1195 if (IS_ERR(tgt))
1196 return PTR_ERR(tgt);
1197
1198 /*
1199 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1200 * on server that seq in new allocated fid is not yet known.
1201 */
1202 mutex_lock(&tgt->ltd_fid_mutex);
1203
1204 if (tgt->ltd_active == 0 || !tgt->ltd_exp) {
1205 rc = -ENODEV;
1206 goto out;
1207 }
1208
1209 /*
1210 * Asking underlaying tgt layer to allocate new fid.
1211 */
1212 rc = obd_fid_alloc(NULL, tgt->ltd_exp, fid, NULL);
1213 if (rc > 0) {
1214 LASSERT(fid_is_sane(fid));
1215 rc = 0;
1216 }
1217
1218 out:
1219 mutex_unlock(&tgt->ltd_fid_mutex);
1220 return rc;
1221 }
1222
1223 int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp,
1224 struct lu_fid *fid, struct md_op_data *op_data)
1225 {
1226 struct obd_device *obd = class_exp2obd(exp);
1227 struct lmv_obd *lmv = &obd->u.lmv;
1228 u32 mds = 0;
1229 int rc;
1230
1231 LASSERT(op_data);
1232 LASSERT(fid);
1233
1234 rc = lmv_placement_policy(obd, op_data, &mds);
1235 if (rc) {
1236 CERROR("Can't get target for allocating fid, rc %d\n",
1237 rc);
1238 return rc;
1239 }
1240
1241 rc = __lmv_fid_alloc(lmv, fid, mds);
1242 if (rc) {
1243 CERROR("Can't alloc new fid, rc %d\n", rc);
1244 return rc;
1245 }
1246
1247 return rc;
1248 }
1249
1250 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1251 {
1252 struct lmv_obd *lmv = &obd->u.lmv;
1253 struct lprocfs_static_vars lvars = { NULL };
1254 struct lmv_desc *desc;
1255 int rc;
1256
1257 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1258 CERROR("LMV setup requires a descriptor\n");
1259 return -EINVAL;
1260 }
1261
1262 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1263 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1264 CERROR("Lmv descriptor size wrong: %d > %d\n",
1265 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1266 return -EINVAL;
1267 }
1268
1269 lmv->tgts_size = 32U;
1270 lmv->tgts = kcalloc(lmv->tgts_size, sizeof(*lmv->tgts), GFP_NOFS);
1271 if (!lmv->tgts)
1272 return -ENOMEM;
1273
1274 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1275 lmv->desc.ld_tgt_count = 0;
1276 lmv->desc.ld_active_tgt_count = 0;
1277 lmv->max_def_easize = 0;
1278 lmv->max_easize = 0;
1279
1280 spin_lock_init(&lmv->lmv_lock);
1281 mutex_init(&lmv->lmv_init_mutex);
1282
1283 lprocfs_lmv_init_vars(&lvars);
1284
1285 lprocfs_obd_setup(obd, lvars.obd_vars, lvars.sysfs_vars);
1286 rc = ldebugfs_seq_create(obd->obd_debugfs_entry, "target_obd",
1287 0444, &lmv_proc_target_fops, obd);
1288 if (rc)
1289 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1290 obd->obd_name, rc);
1291 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1292 LUSTRE_CLI_FLD_HASH_DHT);
1293 if (rc) {
1294 CERROR("Can't init FLD, err %d\n", rc);
1295 goto out;
1296 }
1297
1298 return 0;
1299
1300 out:
1301 return rc;
1302 }
1303
1304 static int lmv_cleanup(struct obd_device *obd)
1305 {
1306 struct lmv_obd *lmv = &obd->u.lmv;
1307
1308 fld_client_fini(&lmv->lmv_fld);
1309 if (lmv->tgts) {
1310 int i;
1311
1312 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1313 if (!lmv->tgts[i])
1314 continue;
1315 lmv_del_target(lmv, i);
1316 }
1317 kfree(lmv->tgts);
1318 lmv->tgts_size = 0;
1319 }
1320 return 0;
1321 }
1322
1323 static int lmv_process_config(struct obd_device *obd, u32 len, void *buf)
1324 {
1325 struct lustre_cfg *lcfg = buf;
1326 struct obd_uuid obd_uuid;
1327 int gen;
1328 __u32 index;
1329 int rc;
1330
1331 switch (lcfg->lcfg_command) {
1332 case LCFG_ADD_MDC:
1333 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1334 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID
1335 */
1336 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid)) {
1337 rc = -EINVAL;
1338 goto out;
1339 }
1340
1341 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1342
1343 if (sscanf(lustre_cfg_buf(lcfg, 2), "%u", &index) != 1) {
1344 rc = -EINVAL;
1345 goto out;
1346 }
1347 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1) {
1348 rc = -EINVAL;
1349 goto out;
1350 }
1351 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1352 goto out;
1353 default:
1354 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1355 rc = -EINVAL;
1356 goto out;
1357 }
1358 out:
1359 return rc;
1360 }
1361
1362 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1363 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1364 {
1365 struct obd_device *obd = class_exp2obd(exp);
1366 struct lmv_obd *lmv = &obd->u.lmv;
1367 struct obd_statfs *temp;
1368 int rc = 0;
1369 u32 i;
1370
1371 rc = lmv_check_connect(obd);
1372 if (rc)
1373 return rc;
1374
1375 temp = kzalloc(sizeof(*temp), GFP_NOFS);
1376 if (!temp)
1377 return -ENOMEM;
1378
1379 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1380 if (!lmv->tgts[i] || !lmv->tgts[i]->ltd_exp)
1381 continue;
1382
1383 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1384 max_age, flags);
1385 if (rc) {
1386 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1387 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1388 rc);
1389 goto out_free_temp;
1390 }
1391
1392 if (i == 0) {
1393 *osfs = *temp;
1394 /* If the statfs is from mount, it will needs
1395 * retrieve necessary information from MDT0.
1396 * i.e. mount does not need the merged osfs
1397 * from all of MDT.
1398 * And also clients can be mounted as long as
1399 * MDT0 is in service
1400 */
1401 if (flags & OBD_STATFS_FOR_MDT0)
1402 goto out_free_temp;
1403 } else {
1404 osfs->os_bavail += temp->os_bavail;
1405 osfs->os_blocks += temp->os_blocks;
1406 osfs->os_ffree += temp->os_ffree;
1407 osfs->os_files += temp->os_files;
1408 }
1409 }
1410
1411 out_free_temp:
1412 kfree(temp);
1413 return rc;
1414 }
1415
1416 static int lmv_getstatus(struct obd_export *exp,
1417 struct lu_fid *fid)
1418 {
1419 struct obd_device *obd = exp->exp_obd;
1420 struct lmv_obd *lmv = &obd->u.lmv;
1421 int rc;
1422
1423 rc = lmv_check_connect(obd);
1424 if (rc)
1425 return rc;
1426
1427 return md_getstatus(lmv->tgts[0]->ltd_exp, fid);
1428 }
1429
1430 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1431 u64 valid, const char *name,
1432 const char *input, int input_size, int output_size,
1433 int flags, struct ptlrpc_request **request)
1434 {
1435 struct obd_device *obd = exp->exp_obd;
1436 struct lmv_obd *lmv = &obd->u.lmv;
1437 struct lmv_tgt_desc *tgt;
1438 int rc;
1439
1440 rc = lmv_check_connect(obd);
1441 if (rc)
1442 return rc;
1443
1444 tgt = lmv_find_target(lmv, fid);
1445 if (IS_ERR(tgt))
1446 return PTR_ERR(tgt);
1447
1448 return md_getxattr(tgt->ltd_exp, fid, valid, name, input,
1449 input_size, output_size, flags, request);
1450 }
1451
1452 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1453 u64 valid, const char *name,
1454 const char *input, int input_size, int output_size,
1455 int flags, __u32 suppgid,
1456 struct ptlrpc_request **request)
1457 {
1458 struct obd_device *obd = exp->exp_obd;
1459 struct lmv_obd *lmv = &obd->u.lmv;
1460 struct lmv_tgt_desc *tgt;
1461 int rc;
1462
1463 rc = lmv_check_connect(obd);
1464 if (rc)
1465 return rc;
1466
1467 tgt = lmv_find_target(lmv, fid);
1468 if (IS_ERR(tgt))
1469 return PTR_ERR(tgt);
1470
1471 return md_setxattr(tgt->ltd_exp, fid, valid, name, input,
1472 input_size, output_size, flags, suppgid,
1473 request);
1474 }
1475
1476 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1477 struct ptlrpc_request **request)
1478 {
1479 struct obd_device *obd = exp->exp_obd;
1480 struct lmv_obd *lmv = &obd->u.lmv;
1481 struct lmv_tgt_desc *tgt;
1482 int rc;
1483
1484 rc = lmv_check_connect(obd);
1485 if (rc)
1486 return rc;
1487
1488 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1489 if (IS_ERR(tgt))
1490 return PTR_ERR(tgt);
1491
1492 if (op_data->op_flags & MF_GET_MDT_IDX) {
1493 op_data->op_mds = tgt->ltd_idx;
1494 return 0;
1495 }
1496
1497 return md_getattr(tgt->ltd_exp, op_data, request);
1498 }
1499
1500 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1501 {
1502 struct obd_device *obd = exp->exp_obd;
1503 struct lmv_obd *lmv = &obd->u.lmv;
1504 u32 i;
1505 int rc;
1506
1507 rc = lmv_check_connect(obd);
1508 if (rc)
1509 return rc;
1510
1511 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1512
1513 /*
1514 * With DNE every object can have two locks in different namespaces:
1515 * lookup lock in space of MDT storing direntry and update/open lock in
1516 * space of MDT storing inode.
1517 */
1518 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1519 if (!lmv->tgts[i] || !lmv->tgts[i]->ltd_exp)
1520 continue;
1521 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1522 }
1523
1524 return 0;
1525 }
1526
1527 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1528 struct md_open_data *mod, struct ptlrpc_request **request)
1529 {
1530 struct obd_device *obd = exp->exp_obd;
1531 struct lmv_obd *lmv = &obd->u.lmv;
1532 struct lmv_tgt_desc *tgt;
1533 int rc;
1534
1535 rc = lmv_check_connect(obd);
1536 if (rc)
1537 return rc;
1538
1539 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1540 if (IS_ERR(tgt))
1541 return PTR_ERR(tgt);
1542
1543 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1544 return md_close(tgt->ltd_exp, op_data, mod, request);
1545 }
1546
1547 /**
1548 * Choosing the MDT by name or FID in @op_data.
1549 * For non-striped directory, it will locate MDT by fid.
1550 * For striped-directory, it will locate MDT by name. And also
1551 * it will reset op_fid1 with the FID of the chosen stripe.
1552 **/
1553 static struct lmv_tgt_desc *
1554 lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
1555 const char *name, int namelen, struct lu_fid *fid,
1556 u32 *mds)
1557 {
1558 const struct lmv_oinfo *oinfo;
1559 struct lmv_tgt_desc *tgt;
1560
1561 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_NAME_HASH)) {
1562 if (cfs_fail_val >= lsm->lsm_md_stripe_count)
1563 return ERR_PTR(-EBADF);
1564 oinfo = &lsm->lsm_md_oinfo[cfs_fail_val];
1565 } else {
1566 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
1567 if (IS_ERR(oinfo))
1568 return ERR_CAST(oinfo);
1569 }
1570
1571 if (fid)
1572 *fid = oinfo->lmo_fid;
1573 if (mds)
1574 *mds = oinfo->lmo_mds;
1575
1576 tgt = lmv_get_target(lmv, oinfo->lmo_mds, NULL);
1577
1578 CDEBUG(D_INFO, "locate on mds %u " DFID "\n", oinfo->lmo_mds,
1579 PFID(&oinfo->lmo_fid));
1580 return tgt;
1581 }
1582
1583 /**
1584 * Locate mds by fid or name
1585 *
1586 * For striped directory (lsm != NULL), it will locate the stripe
1587 * by name hash (see lsm_name_to_stripe_info()). Note: if the hash_type
1588 * is unknown, it will return -EBADFD, and lmv_intent_lookup might need
1589 * walk through all of stripes to locate the entry.
1590 *
1591 * For normal direcotry, it will locate MDS by FID directly.
1592 * \param[in] lmv LMV device
1593 * \param[in] op_data client MD stack parameters, name, namelen
1594 * mds_num etc.
1595 * \param[in] fid object FID used to locate MDS.
1596 *
1597 * retval pointer to the lmv_tgt_desc if succeed.
1598 * ERR_PTR(errno) if failed.
1599 */
1600 struct lmv_tgt_desc*
1601 lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1602 struct lu_fid *fid)
1603 {
1604 struct lmv_stripe_md *lsm = op_data->op_mea1;
1605 struct lmv_tgt_desc *tgt;
1606
1607 /*
1608 * During creating VOLATILE file, it should honor the mdt
1609 * index if the file under striped dir is being restored, see
1610 * ct_restore().
1611 */
1612 if (op_data->op_bias & MDS_CREATE_VOLATILE &&
1613 (int)op_data->op_mds != -1) {
1614 int i;
1615
1616 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
1617 if (IS_ERR(tgt))
1618 return tgt;
1619
1620 if (lsm) {
1621 /* refill the right parent fid */
1622 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1623 struct lmv_oinfo *oinfo;
1624
1625 oinfo = &lsm->lsm_md_oinfo[i];
1626 if (oinfo->lmo_mds == op_data->op_mds) {
1627 *fid = oinfo->lmo_fid;
1628 break;
1629 }
1630 }
1631
1632 if (i == lsm->lsm_md_stripe_count)
1633 *fid = lsm->lsm_md_oinfo[0].lmo_fid;
1634 }
1635
1636 return tgt;
1637 }
1638
1639 if (!lsm || !op_data->op_namelen) {
1640 tgt = lmv_find_target(lmv, fid);
1641 if (IS_ERR(tgt))
1642 return tgt;
1643
1644 op_data->op_mds = tgt->ltd_idx;
1645
1646 return tgt;
1647 }
1648
1649 return lmv_locate_target_for_name(lmv, lsm, op_data->op_name,
1650 op_data->op_namelen, fid,
1651 &op_data->op_mds);
1652 }
1653
1654 static int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1655 const void *data, size_t datalen, umode_t mode,
1656 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1657 __u64 rdev, struct ptlrpc_request **request)
1658 {
1659 struct obd_device *obd = exp->exp_obd;
1660 struct lmv_obd *lmv = &obd->u.lmv;
1661 struct lmv_tgt_desc *tgt;
1662 int rc;
1663
1664 rc = lmv_check_connect(obd);
1665 if (rc)
1666 return rc;
1667
1668 if (!lmv->desc.ld_active_tgt_count)
1669 return -EIO;
1670
1671 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1672 if (IS_ERR(tgt))
1673 return PTR_ERR(tgt);
1674
1675 CDEBUG(D_INODE, "CREATE name '%.*s' on "DFID" -> mds #%x\n",
1676 (int)op_data->op_namelen, op_data->op_name,
1677 PFID(&op_data->op_fid1), op_data->op_mds);
1678
1679 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1680 if (rc)
1681 return rc;
1682
1683 if (exp_connect_flags(exp) & OBD_CONNECT_DIR_STRIPE) {
1684 /*
1685 * Send the create request to the MDT where the object
1686 * will be located
1687 */
1688 tgt = lmv_find_target(lmv, &op_data->op_fid2);
1689 if (IS_ERR(tgt))
1690 return PTR_ERR(tgt);
1691
1692 op_data->op_mds = tgt->ltd_idx;
1693 } else {
1694 CDEBUG(D_CONFIG, "Server doesn't support striped dirs\n");
1695 }
1696
1697 CDEBUG(D_INODE, "CREATE obj "DFID" -> mds #%x\n",
1698 PFID(&op_data->op_fid1), op_data->op_mds);
1699
1700 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1701 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1702 cap_effective, rdev, request);
1703
1704 if (rc == 0) {
1705 if (!*request)
1706 return rc;
1707 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1708 }
1709 return rc;
1710 }
1711
1712 static int
1713 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1714 const union ldlm_policy_data *policy,
1715 struct lookup_intent *it, struct md_op_data *op_data,
1716 struct lustre_handle *lockh, __u64 extra_lock_flags)
1717 {
1718 struct obd_device *obd = exp->exp_obd;
1719 struct lmv_obd *lmv = &obd->u.lmv;
1720 struct lmv_tgt_desc *tgt;
1721 int rc;
1722
1723 rc = lmv_check_connect(obd);
1724 if (rc)
1725 return rc;
1726
1727 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1728 LL_IT2STR(it), PFID(&op_data->op_fid1));
1729
1730 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1731 if (IS_ERR(tgt))
1732 return PTR_ERR(tgt);
1733
1734 CDEBUG(D_INODE, "ENQUEUE '%s' on " DFID " -> mds #%u\n",
1735 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1736
1737 return md_enqueue(tgt->ltd_exp, einfo, policy, it, op_data, lockh,
1738 extra_lock_flags);
1739 }
1740
1741 static int
1742 lmv_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
1743 struct ptlrpc_request **preq)
1744 {
1745 struct ptlrpc_request *req = NULL;
1746 struct obd_device *obd = exp->exp_obd;
1747 struct lmv_obd *lmv = &obd->u.lmv;
1748 struct lmv_tgt_desc *tgt;
1749 struct mdt_body *body;
1750 int rc;
1751
1752 rc = lmv_check_connect(obd);
1753 if (rc)
1754 return rc;
1755
1756 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1757 if (IS_ERR(tgt))
1758 return PTR_ERR(tgt);
1759
1760 CDEBUG(D_INODE, "GETATTR_NAME for %*s on " DFID " -> mds #%u\n",
1761 (int)op_data->op_namelen, op_data->op_name,
1762 PFID(&op_data->op_fid1), tgt->ltd_idx);
1763
1764 rc = md_getattr_name(tgt->ltd_exp, op_data, preq);
1765 if (rc != 0)
1766 return rc;
1767
1768 body = req_capsule_server_get(&(*preq)->rq_pill, &RMF_MDT_BODY);
1769 if (body->mbo_valid & OBD_MD_MDS) {
1770 struct lu_fid rid = body->mbo_fid1;
1771
1772 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1773 PFID(&rid));
1774
1775 tgt = lmv_find_target(lmv, &rid);
1776 if (IS_ERR(tgt)) {
1777 ptlrpc_req_finished(*preq);
1778 *preq = NULL;
1779 return PTR_ERR(tgt);
1780 }
1781
1782 op_data->op_fid1 = rid;
1783 op_data->op_valid |= OBD_MD_FLCROSSREF;
1784 op_data->op_namelen = 0;
1785 op_data->op_name = NULL;
1786 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1787 ptlrpc_req_finished(*preq);
1788 *preq = req;
1789 }
1790
1791 return rc;
1792 }
1793
1794 #define md_op_data_fid(op_data, fl) \
1795 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1796 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1797 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1798 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1799 NULL)
1800
1801 static int lmv_early_cancel(struct obd_export *exp, struct lmv_tgt_desc *tgt,
1802 struct md_op_data *op_data, int op_tgt,
1803 enum ldlm_mode mode, int bits, int flag)
1804 {
1805 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1806 struct obd_device *obd = exp->exp_obd;
1807 struct lmv_obd *lmv = &obd->u.lmv;
1808 union ldlm_policy_data policy = { { 0 } };
1809 int rc = 0;
1810
1811 if (!fid_is_sane(fid))
1812 return 0;
1813
1814 if (!tgt) {
1815 tgt = lmv_find_target(lmv, fid);
1816 if (IS_ERR(tgt))
1817 return PTR_ERR(tgt);
1818 }
1819
1820 if (tgt->ltd_idx != op_tgt) {
1821 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1822 policy.l_inodebits.bits = bits;
1823 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1824 mode, LCF_ASYNC, NULL);
1825 } else {
1826 CDEBUG(D_INODE,
1827 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1828 op_tgt, PFID(fid));
1829 op_data->op_flags |= flag;
1830 rc = 0;
1831 }
1832
1833 return rc;
1834 }
1835
1836 /*
1837 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1838 * op_data->op_fid2
1839 */
1840 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1841 struct ptlrpc_request **request)
1842 {
1843 struct obd_device *obd = exp->exp_obd;
1844 struct lmv_obd *lmv = &obd->u.lmv;
1845 struct lmv_tgt_desc *tgt;
1846 int rc;
1847
1848 rc = lmv_check_connect(obd);
1849 if (rc)
1850 return rc;
1851
1852 LASSERT(op_data->op_namelen != 0);
1853
1854 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1855 PFID(&op_data->op_fid2), (int)op_data->op_namelen,
1856 op_data->op_name, PFID(&op_data->op_fid1));
1857
1858 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1859 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1860 op_data->op_cap = cfs_curproc_cap_pack();
1861 if (op_data->op_mea2) {
1862 struct lmv_stripe_md *lsm = op_data->op_mea2;
1863 const struct lmv_oinfo *oinfo;
1864
1865 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
1866 op_data->op_namelen);
1867 if (IS_ERR(oinfo))
1868 return PTR_ERR(oinfo);
1869
1870 op_data->op_fid2 = oinfo->lmo_fid;
1871 }
1872
1873 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1874 if (IS_ERR(tgt))
1875 return PTR_ERR(tgt);
1876
1877 /*
1878 * Cancel UPDATE lock on child (fid1).
1879 */
1880 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1881 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
1882 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1883 if (rc != 0)
1884 return rc;
1885
1886 return md_link(tgt->ltd_exp, op_data, request);
1887 }
1888
1889 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1890 const char *old, size_t oldlen,
1891 const char *new, size_t newlen,
1892 struct ptlrpc_request **request)
1893 {
1894 struct obd_device *obd = exp->exp_obd;
1895 struct lmv_obd *lmv = &obd->u.lmv;
1896 struct obd_export *target_exp;
1897 struct lmv_tgt_desc *src_tgt;
1898 struct lmv_tgt_desc *tgt_tgt;
1899 struct mdt_body *body;
1900 int rc;
1901
1902 LASSERT(oldlen != 0);
1903
1904 CDEBUG(D_INODE, "RENAME %.*s in "DFID":%d to %.*s in "DFID":%d\n",
1905 (int)oldlen, old, PFID(&op_data->op_fid1),
1906 op_data->op_mea1 ? op_data->op_mea1->lsm_md_stripe_count : 0,
1907 (int)newlen, new, PFID(&op_data->op_fid2),
1908 op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
1909
1910 rc = lmv_check_connect(obd);
1911 if (rc)
1912 return rc;
1913
1914 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1915 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1916 op_data->op_cap = cfs_curproc_cap_pack();
1917
1918 if (op_data->op_cli_flags & CLI_MIGRATE) {
1919 LASSERTF(fid_is_sane(&op_data->op_fid3), "invalid FID "DFID"\n",
1920 PFID(&op_data->op_fid3));
1921
1922 if (op_data->op_mea1) {
1923 struct lmv_stripe_md *lsm = op_data->op_mea1;
1924 struct lmv_tgt_desc *tmp;
1925
1926 /* Fix the parent fid for striped dir */
1927 tmp = lmv_locate_target_for_name(lmv, lsm, old,
1928 oldlen,
1929 &op_data->op_fid1,
1930 NULL);
1931 if (IS_ERR(tmp))
1932 return PTR_ERR(tmp);
1933 }
1934
1935 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1936 if (rc)
1937 return rc;
1938 src_tgt = lmv_find_target(lmv, &op_data->op_fid3);
1939 if (IS_ERR(src_tgt))
1940 return PTR_ERR(src_tgt);
1941
1942 target_exp = src_tgt->ltd_exp;
1943 } else {
1944 if (op_data->op_mea1) {
1945 struct lmv_stripe_md *lsm = op_data->op_mea1;
1946
1947 src_tgt = lmv_locate_target_for_name(lmv, lsm, old,
1948 oldlen,
1949 &op_data->op_fid1,
1950 &op_data->op_mds);
1951 } else {
1952 src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
1953 }
1954 if (IS_ERR(src_tgt))
1955 return PTR_ERR(src_tgt);
1956
1957 if (op_data->op_mea2) {
1958 struct lmv_stripe_md *lsm = op_data->op_mea2;
1959
1960 tgt_tgt = lmv_locate_target_for_name(lmv, lsm, new,
1961 newlen,
1962 &op_data->op_fid2,
1963 &op_data->op_mds);
1964 } else {
1965 tgt_tgt = lmv_find_target(lmv, &op_data->op_fid2);
1966 }
1967 if (IS_ERR(tgt_tgt))
1968 return PTR_ERR(tgt_tgt);
1969
1970 target_exp = tgt_tgt->ltd_exp;
1971 }
1972
1973 /*
1974 * LOOKUP lock on src child (fid3) should also be cancelled for
1975 * src_tgt in mdc_rename.
1976 */
1977 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
1978
1979 /*
1980 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
1981 * own target.
1982 */
1983 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
1984 LCK_EX, MDS_INODELOCK_UPDATE,
1985 MF_MDC_CANCEL_FID2);
1986 if (rc)
1987 return rc;
1988 /*
1989 * Cancel LOOKUP locks on source child (fid3) for parent tgt_tgt.
1990 */
1991 if (fid_is_sane(&op_data->op_fid3)) {
1992 struct lmv_tgt_desc *tgt;
1993
1994 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1995 if (IS_ERR(tgt))
1996 return PTR_ERR(tgt);
1997
1998 /* Cancel LOOKUP lock on its parent */
1999 rc = lmv_early_cancel(exp, tgt, op_data, src_tgt->ltd_idx,
2000 LCK_EX, MDS_INODELOCK_LOOKUP,
2001 MF_MDC_CANCEL_FID3);
2002 if (rc)
2003 return rc;
2004
2005 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2006 LCK_EX, MDS_INODELOCK_FULL,
2007 MF_MDC_CANCEL_FID3);
2008 if (rc)
2009 return rc;
2010 }
2011
2012 retry_rename:
2013 /*
2014 * Cancel all the locks on tgt child (fid4).
2015 */
2016 if (fid_is_sane(&op_data->op_fid4)) {
2017 struct lmv_tgt_desc *tgt;
2018
2019 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2020 LCK_EX, MDS_INODELOCK_FULL,
2021 MF_MDC_CANCEL_FID4);
2022 if (rc)
2023 return rc;
2024
2025 tgt = lmv_find_target(lmv, &op_data->op_fid4);
2026 if (IS_ERR(tgt))
2027 return PTR_ERR(tgt);
2028
2029 /*
2030 * Since the target child might be destroyed, and it might
2031 * become orphan, and we can only check orphan on the local
2032 * MDT right now, so we send rename request to the MDT where
2033 * target child is located. If target child does not exist,
2034 * then it will send the request to the target parent
2035 */
2036 target_exp = tgt->ltd_exp;
2037 }
2038
2039 rc = md_rename(target_exp, op_data, old, oldlen, new, newlen, request);
2040 if (rc && rc != -EREMOTE)
2041 return rc;
2042
2043 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2044 if (!body)
2045 return -EPROTO;
2046
2047 /* Not cross-ref case, just get out of here. */
2048 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2049 return rc;
2050
2051 CDEBUG(D_INODE, "%s: try rename to another MDT for " DFID "\n",
2052 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2053
2054 op_data->op_fid4 = body->mbo_fid1;
2055 ptlrpc_req_finished(*request);
2056 *request = NULL;
2057 goto retry_rename;
2058 }
2059
2060 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2061 void *ea, size_t ealen, struct ptlrpc_request **request)
2062 {
2063 struct obd_device *obd = exp->exp_obd;
2064 struct lmv_obd *lmv = &obd->u.lmv;
2065 struct lmv_tgt_desc *tgt;
2066 int rc;
2067
2068 rc = lmv_check_connect(obd);
2069 if (rc)
2070 return rc;
2071
2072 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2073 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2074
2075 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2076 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2077 if (IS_ERR(tgt))
2078 return PTR_ERR(tgt);
2079
2080 return md_setattr(tgt->ltd_exp, op_data, ea, ealen, request);
2081 }
2082
2083 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
2084 struct ptlrpc_request **request)
2085 {
2086 struct obd_device *obd = exp->exp_obd;
2087 struct lmv_obd *lmv = &obd->u.lmv;
2088 struct lmv_tgt_desc *tgt;
2089 int rc;
2090
2091 rc = lmv_check_connect(obd);
2092 if (rc)
2093 return rc;
2094
2095 tgt = lmv_find_target(lmv, fid);
2096 if (IS_ERR(tgt))
2097 return PTR_ERR(tgt);
2098
2099 return md_sync(tgt->ltd_exp, fid, request);
2100 }
2101
2102 /**
2103 * Get current minimum entry from striped directory
2104 *
2105 * This function will search the dir entry, whose hash value is the
2106 * closest(>=) to @hash_offset, from all of sub-stripes, and it is
2107 * only being called for striped directory.
2108 *
2109 * \param[in] exp export of LMV
2110 * \param[in] op_data parameters transferred beween client MD stack
2111 * stripe_information will be included in this
2112 * parameter
2113 * \param[in] cb_op ldlm callback being used in enqueue in
2114 * mdc_read_page
2115 * \param[in] hash_offset the hash value, which is used to locate
2116 * minum(closet) dir entry
2117 * \param[in|out] stripe_offset the caller use this to indicate the stripe
2118 * index of last entry, so to avoid hash conflict
2119 * between stripes. It will also be used to
2120 * return the stripe index of current dir entry.
2121 * \param[in|out] entp the minum entry and it also is being used
2122 * to input the last dir entry to resolve the
2123 * hash conflict
2124 *
2125 * \param[out] ppage the page which holds the minum entry
2126 *
2127 * \retval = 0 get the entry successfully
2128 * negative errno (< 0) does not get the entry
2129 */
2130 static int lmv_get_min_striped_entry(struct obd_export *exp,
2131 struct md_op_data *op_data,
2132 struct md_callback *cb_op,
2133 __u64 hash_offset, int *stripe_offset,
2134 struct lu_dirent **entp,
2135 struct page **ppage)
2136 {
2137 struct lmv_stripe_md *lsm = op_data->op_mea1;
2138 struct obd_device *obd = exp->exp_obd;
2139 struct lmv_obd *lmv = &obd->u.lmv;
2140 struct lu_dirent *min_ent = NULL;
2141 struct page *min_page = NULL;
2142 struct lmv_tgt_desc *tgt;
2143 int stripe_count;
2144 int min_idx = 0;
2145 int rc = 0;
2146 int i;
2147
2148 stripe_count = lsm->lsm_md_stripe_count;
2149 for (i = 0; i < stripe_count; i++) {
2150 __u64 stripe_hash = hash_offset;
2151 struct lu_dirent *ent = NULL;
2152 struct page *page = NULL;
2153 struct lu_dirpage *dp;
2154
2155 tgt = lmv_get_target(lmv, lsm->lsm_md_oinfo[i].lmo_mds, NULL);
2156 if (IS_ERR(tgt)) {
2157 rc = PTR_ERR(tgt);
2158 goto out;
2159 }
2160
2161 /*
2162 * op_data will be shared by each stripe, so we need
2163 * reset these value for each stripe
2164 */
2165 op_data->op_fid1 = lsm->lsm_md_oinfo[i].lmo_fid;
2166 op_data->op_fid2 = lsm->lsm_md_oinfo[i].lmo_fid;
2167 op_data->op_data = lsm->lsm_md_oinfo[i].lmo_root;
2168 next:
2169 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, stripe_hash,
2170 &page);
2171 if (rc)
2172 goto out;
2173
2174 dp = page_address(page);
2175 for (ent = lu_dirent_start(dp); ent;
2176 ent = lu_dirent_next(ent)) {
2177 /* Skip dummy entry */
2178 if (!le16_to_cpu(ent->lde_namelen))
2179 continue;
2180
2181 if (le64_to_cpu(ent->lde_hash) < hash_offset)
2182 continue;
2183
2184 if (le64_to_cpu(ent->lde_hash) == hash_offset &&
2185 (*entp == ent || i < *stripe_offset))
2186 continue;
2187
2188 /* skip . and .. for other stripes */
2189 if (i && (!strncmp(ent->lde_name, ".",
2190 le16_to_cpu(ent->lde_namelen)) ||
2191 !strncmp(ent->lde_name, "..",
2192 le16_to_cpu(ent->lde_namelen))))
2193 continue;
2194 break;
2195 }
2196
2197 if (!ent) {
2198 stripe_hash = le64_to_cpu(dp->ldp_hash_end);
2199
2200 kunmap(page);
2201 put_page(page);
2202 page = NULL;
2203
2204 /*
2205 * reach the end of current stripe, go to next stripe
2206 */
2207 if (stripe_hash == MDS_DIR_END_OFF)
2208 continue;
2209 else
2210 goto next;
2211 }
2212
2213 if (min_ent) {
2214 if (le64_to_cpu(min_ent->lde_hash) >
2215 le64_to_cpu(ent->lde_hash)) {
2216 min_ent = ent;
2217 kunmap(min_page);
2218 put_page(min_page);
2219 min_idx = i;
2220 min_page = page;
2221 } else {
2222 kunmap(page);
2223 put_page(page);
2224 page = NULL;
2225 }
2226 } else {
2227 min_ent = ent;
2228 min_page = page;
2229 min_idx = i;
2230 }
2231 }
2232
2233 out:
2234 if (*ppage) {
2235 kunmap(*ppage);
2236 put_page(*ppage);
2237 }
2238 *stripe_offset = min_idx;
2239 *entp = min_ent;
2240 *ppage = min_page;
2241 return rc;
2242 }
2243
2244 /**
2245 * Build dir entry page from a striped directory
2246 *
2247 * This function gets one entry by @offset from a striped directory. It will
2248 * read entries from all of stripes, and choose one closest to the required
2249 * offset(&offset). A few notes
2250 * 1. skip . and .. for non-zero stripes, because there can only have one .
2251 * and .. in a directory.
2252 * 2. op_data will be shared by all of stripes, instead of allocating new
2253 * one, so need to restore before reusing.
2254 * 3. release the entry page if that is not being chosen.
2255 *
2256 * \param[in] exp obd export refer to LMV
2257 * \param[in] op_data hold those MD parameters of read_entry
2258 * \param[in] cb_op ldlm callback being used in enqueue in mdc_read_entry
2259 * \param[out] ldp the entry being read
2260 * \param[out] ppage the page holding the entry. Note: because the entry
2261 * will be accessed in upper layer, so we need hold the
2262 * page until the usages of entry is finished, see
2263 * ll_dir_entry_next.
2264 *
2265 * retval =0 if get entry successfully
2266 * <0 cannot get entry
2267 */
2268 static int lmv_read_striped_page(struct obd_export *exp,
2269 struct md_op_data *op_data,
2270 struct md_callback *cb_op,
2271 __u64 offset, struct page **ppage)
2272 {
2273 struct inode *master_inode = op_data->op_data;
2274 struct lu_fid master_fid = op_data->op_fid1;
2275 struct obd_device *obd = exp->exp_obd;
2276 __u64 hash_offset = offset;
2277 struct page *min_ent_page = NULL;
2278 struct page *ent_page = NULL;
2279 struct lu_dirent *min_ent = NULL;
2280 struct lu_dirent *last_ent;
2281 struct lu_dirent *ent;
2282 struct lu_dirpage *dp;
2283 size_t left_bytes;
2284 int ent_idx = 0;
2285 void *area;
2286 int rc;
2287
2288 rc = lmv_check_connect(obd);
2289 if (rc)
2290 return rc;
2291
2292 /*
2293 * Allocate a page and read entries from all of stripes and fill
2294 * the page by hash order
2295 */
2296 ent_page = alloc_page(GFP_KERNEL);
2297 if (!ent_page)
2298 return -ENOMEM;
2299
2300 /* Initialize the entry page */
2301 dp = kmap(ent_page);
2302 memset(dp, 0, sizeof(*dp));
2303 dp->ldp_hash_start = cpu_to_le64(offset);
2304 dp->ldp_flags |= LDF_COLLIDE;
2305
2306 area = dp + 1;
2307 left_bytes = PAGE_SIZE - sizeof(*dp);
2308 ent = area;
2309 last_ent = ent;
2310 do {
2311 __u16 ent_size;
2312
2313 /* Find the minum entry from all sub-stripes */
2314 rc = lmv_get_min_striped_entry(exp, op_data, cb_op, hash_offset,
2315 &ent_idx, &min_ent,
2316 &min_ent_page);
2317 if (rc)
2318 goto out;
2319
2320 /*
2321 * If it can not get minum entry, it means it already reaches
2322 * the end of this directory
2323 */
2324 if (!min_ent) {
2325 last_ent->lde_reclen = 0;
2326 hash_offset = MDS_DIR_END_OFF;
2327 goto out;
2328 }
2329
2330 ent_size = le16_to_cpu(min_ent->lde_reclen);
2331
2332 /*
2333 * the last entry lde_reclen is 0, but it might not
2334 * the end of this entry of this temporay entry
2335 */
2336 if (!ent_size)
2337 ent_size = lu_dirent_calc_size(
2338 le16_to_cpu(min_ent->lde_namelen),
2339 le32_to_cpu(min_ent->lde_attrs));
2340 if (ent_size > left_bytes) {
2341 last_ent->lde_reclen = cpu_to_le16(0);
2342 hash_offset = le64_to_cpu(min_ent->lde_hash);
2343 goto out;
2344 }
2345
2346 memcpy(ent, min_ent, ent_size);
2347
2348 /*
2349 * Replace . with master FID and Replace .. with the parent FID
2350 * of master object
2351 */
2352 if (!strncmp(ent->lde_name, ".",
2353 le16_to_cpu(ent->lde_namelen)) &&
2354 le16_to_cpu(ent->lde_namelen) == 1)
2355 fid_cpu_to_le(&ent->lde_fid, &master_fid);
2356 else if (!strncmp(ent->lde_name, "..",
2357 le16_to_cpu(ent->lde_namelen)) &&
2358 le16_to_cpu(ent->lde_namelen) == 2)
2359 fid_cpu_to_le(&ent->lde_fid, &op_data->op_fid3);
2360
2361 left_bytes -= ent_size;
2362 ent->lde_reclen = cpu_to_le16(ent_size);
2363 last_ent = ent;
2364 ent = (void *)ent + ent_size;
2365 hash_offset = le64_to_cpu(min_ent->lde_hash);
2366 if (hash_offset == MDS_DIR_END_OFF) {
2367 last_ent->lde_reclen = 0;
2368 break;
2369 }
2370 } while (1);
2371 out:
2372 if (min_ent_page) {
2373 kunmap(min_ent_page);
2374 put_page(min_ent_page);
2375 }
2376
2377 if (unlikely(rc)) {
2378 __free_page(ent_page);
2379 ent_page = NULL;
2380 } else {
2381 if (ent == area)
2382 dp->ldp_flags |= LDF_EMPTY;
2383 dp->ldp_flags = cpu_to_le32(dp->ldp_flags);
2384 dp->ldp_hash_end = cpu_to_le64(hash_offset);
2385 }
2386
2387 /*
2388 * We do not want to allocate md_op_data during each
2389 * dir entry reading, so op_data will be shared by every stripe,
2390 * then we need to restore it back to original value before
2391 * return to the upper layer
2392 */
2393 op_data->op_fid1 = master_fid;
2394 op_data->op_fid2 = master_fid;
2395 op_data->op_data = master_inode;
2396
2397 *ppage = ent_page;
2398
2399 return rc;
2400 }
2401
2402 static int lmv_read_page(struct obd_export *exp, struct md_op_data *op_data,
2403 struct md_callback *cb_op, __u64 offset,
2404 struct page **ppage)
2405 {
2406 struct lmv_stripe_md *lsm = op_data->op_mea1;
2407 struct obd_device *obd = exp->exp_obd;
2408 struct lmv_obd *lmv = &obd->u.lmv;
2409 struct lmv_tgt_desc *tgt;
2410 int rc;
2411
2412 rc = lmv_check_connect(obd);
2413 if (rc)
2414 return rc;
2415
2416 if (unlikely(lsm))
2417 return lmv_read_striped_page(exp, op_data, cb_op, offset, ppage);
2418
2419 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2420 if (IS_ERR(tgt))
2421 return PTR_ERR(tgt);
2422
2423 return md_read_page(tgt->ltd_exp, op_data, cb_op, offset, ppage);
2424 }
2425
2426 /**
2427 * Unlink a file/directory
2428 *
2429 * Unlink a file or directory under the parent dir. The unlink request
2430 * usually will be sent to the MDT where the child is located, but if
2431 * the client does not have the child FID then request will be sent to the
2432 * MDT where the parent is located.
2433 *
2434 * If the parent is a striped directory then it also needs to locate which
2435 * stripe the name of the child is located, and replace the parent FID
2436 * (@op->op_fid1) with the stripe FID. Note: if the stripe is unknown,
2437 * it will walk through all of sub-stripes until the child is being
2438 * unlinked finally.
2439 *
2440 * \param[in] exp export refer to LMV
2441 * \param[in] op_data different parameters transferred beween client
2442 * MD stacks, name, namelen, FIDs etc.
2443 * op_fid1 is the parent FID, op_fid2 is the child
2444 * FID.
2445 * \param[out] request point to the request of unlink.
2446 *
2447 * retval 0 if succeed
2448 * negative errno if failed.
2449 */
2450 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2451 struct ptlrpc_request **request)
2452 {
2453 struct lmv_stripe_md *lsm = op_data->op_mea1;
2454 struct obd_device *obd = exp->exp_obd;
2455 struct lmv_obd *lmv = &obd->u.lmv;
2456 struct lmv_tgt_desc *parent_tgt = NULL;
2457 struct lmv_tgt_desc *tgt = NULL;
2458 struct mdt_body *body;
2459 int stripe_index = 0;
2460 int rc;
2461
2462 rc = lmv_check_connect(obd);
2463 if (rc)
2464 return rc;
2465 retry_unlink:
2466 /* For striped dir, we need to locate the parent as well */
2467 if (lsm) {
2468 struct lmv_tgt_desc *tmp;
2469
2470 LASSERT(op_data->op_name && op_data->op_namelen);
2471
2472 tmp = lmv_locate_target_for_name(lmv, lsm,
2473 op_data->op_name,
2474 op_data->op_namelen,
2475 &op_data->op_fid1,
2476 &op_data->op_mds);
2477
2478 /*
2479 * return -EBADFD means unknown hash type, might
2480 * need try all sub-stripe here
2481 */
2482 if (IS_ERR(tmp) && PTR_ERR(tmp) != -EBADFD)
2483 return PTR_ERR(tmp);
2484
2485 /*
2486 * Note: both migrating dir and unknown hash dir need to
2487 * try all of sub-stripes, so we need start search the
2488 * name from stripe 0, but migrating dir is already handled
2489 * inside lmv_locate_target_for_name(), so we only check
2490 * unknown hash type directory here
2491 */
2492 if (!lmv_is_known_hash_type(lsm->lsm_md_hash_type)) {
2493 struct lmv_oinfo *oinfo;
2494
2495 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2496
2497 op_data->op_fid1 = oinfo->lmo_fid;
2498 op_data->op_mds = oinfo->lmo_mds;
2499 }
2500 }
2501
2502 try_next_stripe:
2503 /* Send unlink requests to the MDT where the child is located */
2504 if (likely(!fid_is_zero(&op_data->op_fid2)))
2505 tgt = lmv_find_target(lmv, &op_data->op_fid2);
2506 else if (lsm)
2507 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
2508 else
2509 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2510
2511 if (IS_ERR(tgt))
2512 return PTR_ERR(tgt);
2513
2514 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2515 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2516 op_data->op_cap = cfs_curproc_cap_pack();
2517
2518 /*
2519 * If child's fid is given, cancel unused locks for it if it is from
2520 * another export than parent.
2521 *
2522 * LOOKUP lock for child (fid3) should also be cancelled on parent
2523 * tgt_tgt in mdc_unlink().
2524 */
2525 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2526
2527 /*
2528 * Cancel FULL locks on child (fid3).
2529 */
2530 parent_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2531 if (IS_ERR(parent_tgt))
2532 return PTR_ERR(parent_tgt);
2533
2534 if (parent_tgt != tgt) {
2535 rc = lmv_early_cancel(exp, parent_tgt, op_data, tgt->ltd_idx,
2536 LCK_EX, MDS_INODELOCK_LOOKUP,
2537 MF_MDC_CANCEL_FID3);
2538 }
2539
2540 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2541 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2542 if (rc != 0)
2543 return rc;
2544
2545 CDEBUG(D_INODE, "unlink with fid=" DFID "/" DFID " -> mds #%u\n",
2546 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2547
2548 rc = md_unlink(tgt->ltd_exp, op_data, request);
2549 if (rc != 0 && rc != -EREMOTE && rc != -ENOENT)
2550 return rc;
2551
2552 /* Try next stripe if it is needed. */
2553 if (rc == -ENOENT && lsm && lmv_need_try_all_stripes(lsm)) {
2554 struct lmv_oinfo *oinfo;
2555
2556 stripe_index++;
2557 if (stripe_index >= lsm->lsm_md_stripe_count)
2558 return rc;
2559
2560 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2561
2562 op_data->op_fid1 = oinfo->lmo_fid;
2563 op_data->op_mds = oinfo->lmo_mds;
2564
2565 ptlrpc_req_finished(*request);
2566 *request = NULL;
2567
2568 goto try_next_stripe;
2569 }
2570
2571 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2572 if (!body)
2573 return -EPROTO;
2574
2575 /* Not cross-ref case, just get out of here. */
2576 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2577 return rc;
2578
2579 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2580 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2581
2582 /* This is a remote object, try remote MDT, Note: it may
2583 * try more than 1 time here, Considering following case
2584 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2585 * 1. Initially A does not know where remote1 is, it send
2586 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2587 * resend unlink RPC to MDT1 (retry 1st time).
2588 *
2589 * 2. During the unlink RPC in flight,
2590 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2591 * and create new remote1, but on MDT0
2592 *
2593 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2594 * /mnt/lustre, then lookup get fid of remote1, and find
2595 * it is remote dir again, and replay -EREMOTE again.
2596 *
2597 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2598 *
2599 * In theory, it might try unlimited time here, but it should
2600 * be very rare case.
2601 */
2602 op_data->op_fid2 = body->mbo_fid1;
2603 ptlrpc_req_finished(*request);
2604 *request = NULL;
2605
2606 goto retry_unlink;
2607 }
2608
2609 static int lmv_precleanup(struct obd_device *obd)
2610 {
2611 fld_client_debugfs_fini(&obd->u.lmv.lmv_fld);
2612 lprocfs_obd_cleanup(obd);
2613 return 0;
2614 }
2615
2616 /**
2617 * Get by key a value associated with a LMV device.
2618 *
2619 * Dispatch request to lower-layer devices as needed.
2620 *
2621 * \param[in] env execution environment for this thread
2622 * \param[in] exp export for the LMV device
2623 * \param[in] keylen length of key identifier
2624 * \param[in] key identifier of key to get value for
2625 * \param[in] vallen size of \a val
2626 * \param[out] val pointer to storage location for value
2627 *
2628 * \retval 0 on success
2629 * \retval negative negated errno on failure
2630 */
2631 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2632 __u32 keylen, void *key, __u32 *vallen, void *val)
2633 {
2634 struct obd_device *obd;
2635 struct lmv_obd *lmv;
2636 int rc = 0;
2637
2638 obd = class_exp2obd(exp);
2639 if (!obd) {
2640 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2641 exp->exp_handle.h_cookie);
2642 return -EINVAL;
2643 }
2644
2645 lmv = &obd->u.lmv;
2646 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2647 int i;
2648
2649 rc = lmv_check_connect(obd);
2650 if (rc)
2651 return rc;
2652
2653 LASSERT(*vallen == sizeof(__u32));
2654 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2655 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2656
2657 /*
2658 * All tgts should be connected when this gets called.
2659 */
2660 if (!tgt || !tgt->ltd_exp)
2661 continue;
2662
2663 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2664 vallen, val))
2665 return 0;
2666 }
2667 return -EINVAL;
2668 } else if (KEY_IS(KEY_MAX_EASIZE) ||
2669 KEY_IS(KEY_DEFAULT_EASIZE) ||
2670 KEY_IS(KEY_CONN_DATA)) {
2671 rc = lmv_check_connect(obd);
2672 if (rc)
2673 return rc;
2674
2675 /*
2676 * Forwarding this request to first MDS, it should know LOV
2677 * desc.
2678 */
2679 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2680 vallen, val);
2681 if (!rc && KEY_IS(KEY_CONN_DATA))
2682 exp->exp_connect_data = *(struct obd_connect_data *)val;
2683 return rc;
2684 } else if (KEY_IS(KEY_TGT_COUNT)) {
2685 *((int *)val) = lmv->desc.ld_tgt_count;
2686 return 0;
2687 }
2688
2689 CDEBUG(D_IOCTL, "Invalid key\n");
2690 return -EINVAL;
2691 }
2692
2693 /**
2694 * Asynchronously set by key a value associated with a LMV device.
2695 *
2696 * Dispatch request to lower-layer devices as needed.
2697 *
2698 * \param[in] env execution environment for this thread
2699 * \param[in] exp export for the LMV device
2700 * \param[in] keylen length of key identifier
2701 * \param[in] key identifier of key to store value for
2702 * \param[in] vallen size of value to store
2703 * \param[in] val pointer to data to be stored
2704 * \param[in] set optional list of related ptlrpc requests
2705 *
2706 * \retval 0 on success
2707 * \retval negative negated errno on failure
2708 */
2709 static int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2710 u32 keylen, void *key, u32 vallen,
2711 void *val, struct ptlrpc_request_set *set)
2712 {
2713 struct lmv_tgt_desc *tgt;
2714 struct obd_device *obd;
2715 struct lmv_obd *lmv;
2716 int rc = 0;
2717
2718 obd = class_exp2obd(exp);
2719 if (!obd) {
2720 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2721 exp->exp_handle.h_cookie);
2722 return -EINVAL;
2723 }
2724 lmv = &obd->u.lmv;
2725
2726 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX) ||
2727 KEY_IS(KEY_DEFAULT_EASIZE)) {
2728 int i, err = 0;
2729
2730 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2731 tgt = lmv->tgts[i];
2732
2733 if (!tgt || !tgt->ltd_exp)
2734 continue;
2735
2736 err = obd_set_info_async(env, tgt->ltd_exp,
2737 keylen, key, vallen, val, set);
2738 if (err && rc == 0)
2739 rc = err;
2740 }
2741
2742 return rc;
2743 }
2744
2745 return -EINVAL;
2746 }
2747
2748 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
2749 const struct lmv_mds_md_v1 *lmm1)
2750 {
2751 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2752 int stripe_count;
2753 int rc = 0;
2754 int cplen;
2755 int i;
2756
2757 lsm->lsm_md_magic = le32_to_cpu(lmm1->lmv_magic);
2758 lsm->lsm_md_stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2759 lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index);
2760 if (OBD_FAIL_CHECK(OBD_FAIL_UNKNOWN_LMV_STRIPE))
2761 lsm->lsm_md_hash_type = LMV_HASH_TYPE_UNKNOWN;
2762 else
2763 lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
2764 lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
2765 cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
2766 sizeof(lsm->lsm_md_pool_name));
2767
2768 if (cplen >= sizeof(lsm->lsm_md_pool_name))
2769 return -E2BIG;
2770
2771 CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %d layout_version %d\n",
2772 lsm->lsm_md_stripe_count, lsm->lsm_md_master_mdt_index,
2773 lsm->lsm_md_hash_type, lsm->lsm_md_layout_version);
2774
2775 stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2776 for (i = 0; i < stripe_count; i++) {
2777 fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
2778 &lmm1->lmv_stripe_fids[i]);
2779 rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
2780 &lsm->lsm_md_oinfo[i].lmo_mds);
2781 if (rc)
2782 return rc;
2783 CDEBUG(D_INFO, "unpack fid #%d "DFID"\n", i,
2784 PFID(&lsm->lsm_md_oinfo[i].lmo_fid));
2785 }
2786
2787 return rc;
2788 }
2789
2790 static int lmv_unpackmd(struct obd_export *exp, struct lmv_stripe_md **lsmp,
2791 const union lmv_mds_md *lmm, size_t lmm_size)
2792 {
2793 struct lmv_stripe_md *lsm;
2794 bool allocated = false;
2795 int lsm_size, rc;
2796
2797 LASSERT(lsmp);
2798
2799 lsm = *lsmp;
2800 /* Free memmd */
2801 if (lsm && !lmm) {
2802 int i;
2803
2804 for (i = 1; i < lsm->lsm_md_stripe_count; i++) {
2805 /*
2806 * For migrating inode, the master stripe and master
2807 * object will be the same, so do not need iput, see
2808 * ll_update_lsm_md
2809 */
2810 if (!(lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION &&
2811 !i) && lsm->lsm_md_oinfo[i].lmo_root)
2812 iput(lsm->lsm_md_oinfo[i].lmo_root);
2813 }
2814
2815 kvfree(lsm);
2816 *lsmp = NULL;
2817 return 0;
2818 }
2819
2820 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE)
2821 return -EPERM;
2822
2823 /* Unpack memmd */
2824 if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1 &&
2825 le32_to_cpu(lmm->lmv_magic) != LMV_USER_MAGIC) {
2826 CERROR("%s: invalid lmv magic %x: rc = %d\n",
2827 exp->exp_obd->obd_name, le32_to_cpu(lmm->lmv_magic),
2828 -EIO);
2829 return -EIO;
2830 }
2831
2832 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_V1)
2833 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2834 else
2835 /**
2836 * Unpack default dirstripe(lmv_user_md) to lmv_stripe_md,
2837 * stripecount should be 0 then.
2838 */
2839 lsm_size = lmv_stripe_md_size(0);
2840
2841 if (!lsm) {
2842 lsm = libcfs_kvzalloc(lsm_size, GFP_NOFS);
2843 if (!lsm)
2844 return -ENOMEM;
2845 allocated = true;
2846 *lsmp = lsm;
2847 }
2848
2849 switch (le32_to_cpu(lmm->lmv_magic)) {
2850 case LMV_MAGIC_V1:
2851 rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1);
2852 break;
2853 default:
2854 CERROR("%s: unrecognized magic %x\n", exp->exp_obd->obd_name,
2855 le32_to_cpu(lmm->lmv_magic));
2856 rc = -EINVAL;
2857 break;
2858 }
2859
2860 if (rc && allocated) {
2861 kvfree(lsm);
2862 *lsmp = NULL;
2863 lsm_size = rc;
2864 }
2865 return lsm_size;
2866 }
2867
2868 void lmv_free_memmd(struct lmv_stripe_md *lsm)
2869 {
2870 lmv_unpackmd(NULL, &lsm, NULL, 0);
2871 }
2872 EXPORT_SYMBOL(lmv_free_memmd);
2873
2874 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2875 union ldlm_policy_data *policy,
2876 enum ldlm_mode mode, enum ldlm_cancel_flags flags,
2877 void *opaque)
2878 {
2879 struct obd_device *obd = exp->exp_obd;
2880 struct lmv_obd *lmv = &obd->u.lmv;
2881 int rc = 0;
2882 int err;
2883 u32 i;
2884
2885 LASSERT(fid);
2886
2887 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2888 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2889
2890 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
2891 continue;
2892
2893 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
2894 opaque);
2895 if (!rc)
2896 rc = err;
2897 }
2898 return rc;
2899 }
2900
2901 static int lmv_set_lock_data(struct obd_export *exp,
2902 const struct lustre_handle *lockh,
2903 void *data, __u64 *bits)
2904 {
2905 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2906 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2907
2908 if (!tgt || !tgt->ltd_exp)
2909 return -EINVAL;
2910
2911 return md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
2912 }
2913
2914 static enum ldlm_mode lmv_lock_match(struct obd_export *exp, __u64 flags,
2915 const struct lu_fid *fid,
2916 enum ldlm_type type,
2917 union ldlm_policy_data *policy,
2918 enum ldlm_mode mode,
2919 struct lustre_handle *lockh)
2920 {
2921 struct obd_device *obd = exp->exp_obd;
2922 struct lmv_obd *lmv = &obd->u.lmv;
2923 enum ldlm_mode rc;
2924 int tgt;
2925 u32 i;
2926
2927 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2928
2929 /*
2930 * With DNE every object can have two locks in different namespaces:
2931 * lookup lock in space of MDT storing direntry and update/open lock in
2932 * space of MDT storing inode. Try the MDT that the FID maps to first,
2933 * since this can be easily found, and only try others if that fails.
2934 */
2935 for (i = 0, tgt = lmv_find_target_index(lmv, fid);
2936 i < lmv->desc.ld_tgt_count;
2937 i++, tgt = (tgt + 1) % lmv->desc.ld_tgt_count) {
2938 if (tgt < 0) {
2939 CDEBUG(D_HA, "%s: "DFID" is inaccessible: rc = %d\n",
2940 obd->obd_name, PFID(fid), tgt);
2941 tgt = 0;
2942 }
2943
2944 if (!lmv->tgts[tgt] || !lmv->tgts[tgt]->ltd_exp ||
2945 !lmv->tgts[tgt]->ltd_active)
2946 continue;
2947
2948 rc = md_lock_match(lmv->tgts[tgt]->ltd_exp, flags, fid,
2949 type, policy, mode, lockh);
2950 if (rc)
2951 return rc;
2952 }
2953
2954 return 0;
2955 }
2956
2957 static int lmv_get_lustre_md(struct obd_export *exp,
2958 struct ptlrpc_request *req,
2959 struct obd_export *dt_exp,
2960 struct obd_export *md_exp,
2961 struct lustre_md *md)
2962 {
2963 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2964 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2965
2966 if (!tgt || !tgt->ltd_exp)
2967 return -EINVAL;
2968 return md_get_lustre_md(tgt->ltd_exp, req, dt_exp, md_exp, md);
2969 }
2970
2971 static int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2972 {
2973 struct obd_device *obd = exp->exp_obd;
2974 struct lmv_obd *lmv = &obd->u.lmv;
2975 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2976
2977 if (md->lmv) {
2978 lmv_free_memmd(md->lmv);
2979 md->lmv = NULL;
2980 }
2981 if (!tgt || !tgt->ltd_exp)
2982 return -EINVAL;
2983 return md_free_lustre_md(tgt->ltd_exp, md);
2984 }
2985
2986 static int lmv_set_open_replay_data(struct obd_export *exp,
2987 struct obd_client_handle *och,
2988 struct lookup_intent *it)
2989 {
2990 struct obd_device *obd = exp->exp_obd;
2991 struct lmv_obd *lmv = &obd->u.lmv;
2992 struct lmv_tgt_desc *tgt;
2993
2994 tgt = lmv_find_target(lmv, &och->och_fid);
2995 if (IS_ERR(tgt))
2996 return PTR_ERR(tgt);
2997
2998 return md_set_open_replay_data(tgt->ltd_exp, och, it);
2999 }
3000
3001 static int lmv_clear_open_replay_data(struct obd_export *exp,
3002 struct obd_client_handle *och)
3003 {
3004 struct obd_device *obd = exp->exp_obd;
3005 struct lmv_obd *lmv = &obd->u.lmv;
3006 struct lmv_tgt_desc *tgt;
3007
3008 tgt = lmv_find_target(lmv, &och->och_fid);
3009 if (IS_ERR(tgt))
3010 return PTR_ERR(tgt);
3011
3012 return md_clear_open_replay_data(tgt->ltd_exp, och);
3013 }
3014
3015 static int lmv_intent_getattr_async(struct obd_export *exp,
3016 struct md_enqueue_info *minfo)
3017 {
3018 struct md_op_data *op_data = &minfo->mi_data;
3019 struct obd_device *obd = exp->exp_obd;
3020 struct lmv_obd *lmv = &obd->u.lmv;
3021 struct lmv_tgt_desc *ptgt = NULL;
3022 struct lmv_tgt_desc *ctgt = NULL;
3023 int rc;
3024
3025 if (!fid_is_sane(&op_data->op_fid2))
3026 return -EINVAL;
3027
3028 rc = lmv_check_connect(obd);
3029 if (rc)
3030 return rc;
3031
3032 ptgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
3033 if (IS_ERR(ptgt))
3034 return PTR_ERR(ptgt);
3035
3036 ctgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
3037 if (IS_ERR(ctgt))
3038 return PTR_ERR(ctgt);
3039
3040 /*
3041 * if child is on remote MDT, we need 2 async RPCs to fetch both LOOKUP
3042 * lock on parent, and UPDATE lock on child MDT, which makes all
3043 * complicated. Considering remote dir is rare case, and not supporting
3044 * it in statahead won't cause any issue, drop its support for now.
3045 */
3046 if (ptgt != ctgt)
3047 return -ENOTSUPP;
3048
3049 return md_intent_getattr_async(ptgt->ltd_exp, minfo);
3050 }
3051
3052 static int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3053 struct lu_fid *fid, __u64 *bits)
3054 {
3055 struct obd_device *obd = exp->exp_obd;
3056 struct lmv_obd *lmv = &obd->u.lmv;
3057 struct lmv_tgt_desc *tgt;
3058 int rc;
3059
3060 rc = lmv_check_connect(obd);
3061 if (rc)
3062 return rc;
3063
3064 tgt = lmv_find_target(lmv, fid);
3065 if (IS_ERR(tgt))
3066 return PTR_ERR(tgt);
3067
3068 return md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3069 }
3070
3071 static int
3072 lmv_get_fid_from_lsm(struct obd_export *exp,
3073 const struct lmv_stripe_md *lsm,
3074 const char *name, int namelen, struct lu_fid *fid)
3075 {
3076 const struct lmv_oinfo *oinfo;
3077
3078 LASSERT(lsm);
3079 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
3080 if (IS_ERR(oinfo))
3081 return PTR_ERR(oinfo);
3082
3083 *fid = oinfo->lmo_fid;
3084
3085 return 0;
3086 }
3087
3088 /**
3089 * For lmv, only need to send request to master MDT, and the master MDT will
3090 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
3091 * we directly fetch data from the slave MDTs.
3092 */
3093 static int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3094 struct obd_quotactl *oqctl)
3095 {
3096 struct obd_device *obd = class_exp2obd(exp);
3097 struct lmv_obd *lmv = &obd->u.lmv;
3098 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3099 int rc = 0;
3100 __u64 curspace = 0, curinodes = 0;
3101 u32 i;
3102
3103 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active ||
3104 !lmv->desc.ld_tgt_count) {
3105 CERROR("master lmv inactive\n");
3106 return -EIO;
3107 }
3108
3109 if (oqctl->qc_cmd != Q_GETOQUOTA)
3110 return obd_quotactl(tgt->ltd_exp, oqctl);
3111
3112 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3113 int err;
3114
3115 tgt = lmv->tgts[i];
3116
3117 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
3118 continue;
3119
3120 err = obd_quotactl(tgt->ltd_exp, oqctl);
3121 if (err) {
3122 CERROR("getquota on mdt %d failed. %d\n", i, err);
3123 if (!rc)
3124 rc = err;
3125 } else {
3126 curspace += oqctl->qc_dqblk.dqb_curspace;
3127 curinodes += oqctl->qc_dqblk.dqb_curinodes;
3128 }
3129 }
3130 oqctl->qc_dqblk.dqb_curspace = curspace;
3131 oqctl->qc_dqblk.dqb_curinodes = curinodes;
3132
3133 return rc;
3134 }
3135
3136 static int lmv_merge_attr(struct obd_export *exp,
3137 const struct lmv_stripe_md *lsm,
3138 struct cl_attr *attr,
3139 ldlm_blocking_callback cb_blocking)
3140 {
3141 int rc, i;
3142
3143 rc = lmv_revalidate_slaves(exp, lsm, cb_blocking, 0);
3144 if (rc < 0)
3145 return rc;
3146
3147 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
3148 struct inode *inode = lsm->lsm_md_oinfo[i].lmo_root;
3149
3150 CDEBUG(D_INFO, ""DFID" size %llu, blocks %llu nlink %u, atime %lu ctime %lu, mtime %lu.\n",
3151 PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
3152 i_size_read(inode), (unsigned long long)inode->i_blocks,
3153 inode->i_nlink, LTIME_S(inode->i_atime),
3154 LTIME_S(inode->i_ctime), LTIME_S(inode->i_mtime));
3155
3156 /* for slave stripe, it needs to subtract nlink for . and .. */
3157 if (i)
3158 attr->cat_nlink += inode->i_nlink - 2;
3159 else
3160 attr->cat_nlink = inode->i_nlink;
3161
3162 attr->cat_size += i_size_read(inode);
3163 attr->cat_blocks += inode->i_blocks;
3164
3165 if (attr->cat_atime < LTIME_S(inode->i_atime))
3166 attr->cat_atime = LTIME_S(inode->i_atime);
3167
3168 if (attr->cat_ctime < LTIME_S(inode->i_ctime))
3169 attr->cat_ctime = LTIME_S(inode->i_ctime);
3170
3171 if (attr->cat_mtime < LTIME_S(inode->i_mtime))
3172 attr->cat_mtime = LTIME_S(inode->i_mtime);
3173 }
3174 return 0;
3175 }
3176
3177 static struct obd_ops lmv_obd_ops = {
3178 .owner = THIS_MODULE,
3179 .setup = lmv_setup,
3180 .cleanup = lmv_cleanup,
3181 .precleanup = lmv_precleanup,
3182 .process_config = lmv_process_config,
3183 .connect = lmv_connect,
3184 .disconnect = lmv_disconnect,
3185 .statfs = lmv_statfs,
3186 .get_info = lmv_get_info,
3187 .set_info_async = lmv_set_info_async,
3188 .notify = lmv_notify,
3189 .get_uuid = lmv_get_uuid,
3190 .iocontrol = lmv_iocontrol,
3191 .quotactl = lmv_quotactl
3192 };
3193
3194 static struct md_ops lmv_md_ops = {
3195 .getstatus = lmv_getstatus,
3196 .null_inode = lmv_null_inode,
3197 .close = lmv_close,
3198 .create = lmv_create,
3199 .enqueue = lmv_enqueue,
3200 .getattr = lmv_getattr,
3201 .getxattr = lmv_getxattr,
3202 .getattr_name = lmv_getattr_name,
3203 .intent_lock = lmv_intent_lock,
3204 .link = lmv_link,
3205 .rename = lmv_rename,
3206 .setattr = lmv_setattr,
3207 .setxattr = lmv_setxattr,
3208 .sync = lmv_sync,
3209 .read_page = lmv_read_page,
3210 .unlink = lmv_unlink,
3211 .init_ea_size = lmv_init_ea_size,
3212 .cancel_unused = lmv_cancel_unused,
3213 .set_lock_data = lmv_set_lock_data,
3214 .lock_match = lmv_lock_match,
3215 .get_lustre_md = lmv_get_lustre_md,
3216 .free_lustre_md = lmv_free_lustre_md,
3217 .merge_attr = lmv_merge_attr,
3218 .set_open_replay_data = lmv_set_open_replay_data,
3219 .clear_open_replay_data = lmv_clear_open_replay_data,
3220 .intent_getattr_async = lmv_intent_getattr_async,
3221 .revalidate_lock = lmv_revalidate_lock,
3222 .get_fid_from_lsm = lmv_get_fid_from_lsm,
3223 .unpackmd = lmv_unpackmd,
3224 };
3225
3226 static int __init lmv_init(void)
3227 {
3228 struct lprocfs_static_vars lvars;
3229
3230 lprocfs_lmv_init_vars(&lvars);
3231
3232 return class_register_type(&lmv_obd_ops, &lmv_md_ops,
3233 LUSTRE_LMV_NAME, NULL);
3234 }
3235
3236 static void lmv_exit(void)
3237 {
3238 class_unregister_type(LUSTRE_LMV_NAME);
3239 }
3240
3241 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3242 MODULE_DESCRIPTION("Lustre Logical Metadata Volume");
3243 MODULE_VERSION(LUSTRE_VERSION_STRING);
3244 MODULE_LICENSE("GPL");
3245
3246 module_init(lmv_init);
3247 module_exit(lmv_exit);