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