staging/lustre/lmv: fix potential null pointer dereference
[deliverable/linux.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;
d7e09d03 596
ced41eba
OD
597 if (lmv->lmv_tgts_kobj)
598 sysfs_remove_link(lmv->lmv_tgts_kobj,
599 mdc_obd->obd_name);
600 }
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);
76e4290c 719 if (!remote_gf) {
4d54556f
JL
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;
8cc3792a 1048 req = libcfs_kvzalloc(reqlen, GFP_NOFS);
78eb9092 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;
8cc3792a 1058 kvfree(req);
78eb9092
TL
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);
61e87ab0
DE
1313 rc = ldebugfs_seq_create(obd->obd_debugfs_entry, "target_obd",
1314 0444, &lmv_proc_target_fops, obd);
1315 if (rc)
1316 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1317 obd->obd_name, rc);
d7e09d03
PT
1318 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1319 LUSTRE_CLI_FLD_HASH_DHT);
1320 if (rc) {
1321 CERROR("Can't init FLD, err %d\n", rc);
4d54556f 1322 goto out;
d7e09d03
PT
1323 }
1324
0a3bdb00 1325 return 0;
d7e09d03
PT
1326
1327out:
1328 return rc;
1329}
1330
1331static int lmv_cleanup(struct obd_device *obd)
1332{
1333 struct lmv_obd *lmv = &obd->u.lmv;
d7e09d03
PT
1334
1335 fld_client_fini(&lmv->lmv_fld);
1336 if (lmv->tgts != NULL) {
1337 int i;
1338 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1339 if (lmv->tgts[i] == NULL)
1340 continue;
1341 lmv_del_target(lmv, i);
1342 }
8bcf30c3 1343 kfree(lmv->tgts);
d7e09d03
PT
1344 lmv->tgts_size = 0;
1345 }
0a3bdb00 1346 return 0;
d7e09d03
PT
1347}
1348
21aef7d9 1349static int lmv_process_config(struct obd_device *obd, u32 len, void *buf)
d7e09d03
PT
1350{
1351 struct lustre_cfg *lcfg = buf;
1352 struct obd_uuid obd_uuid;
1353 int gen;
1354 __u32 index;
1355 int rc;
d7e09d03
PT
1356
1357 switch (lcfg->lcfg_command) {
1358 case LCFG_ADD_MDC:
1359 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1360 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
4d54556f
JL
1361 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid)) {
1362 rc = -EINVAL;
1363 goto out;
1364 }
d7e09d03
PT
1365
1366 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1367
4d54556f
JL
1368 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1) {
1369 rc = -EINVAL;
1370 goto out;
1371 }
1372 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1) {
1373 rc = -EINVAL;
1374 goto out;
1375 }
d7e09d03 1376 rc = lmv_add_target(obd, &obd_uuid, index, gen);
4d54556f 1377 goto out;
d7e09d03
PT
1378 default:
1379 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
4d54556f
JL
1380 rc = -EINVAL;
1381 goto out;
d7e09d03
PT
1382 }
1383out:
0a3bdb00 1384 return rc;
d7e09d03
PT
1385}
1386
1387static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1388 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1389{
1390 struct obd_device *obd = class_exp2obd(exp);
1391 struct lmv_obd *lmv = &obd->u.lmv;
1392 struct obd_statfs *temp;
1393 int rc = 0;
1394 int i;
d7e09d03
PT
1395
1396 rc = lmv_check_connect(obd);
1397 if (rc)
0a3bdb00 1398 return rc;
d7e09d03 1399
8bcf30c3 1400 temp = kzalloc(sizeof(*temp), GFP_NOFS);
76e4290c 1401 if (!temp)
0a3bdb00 1402 return -ENOMEM;
d7e09d03
PT
1403
1404 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1405 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1406 continue;
1407
1408 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1409 max_age, flags);
1410 if (rc) {
1411 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1412 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1413 rc);
4d54556f 1414 goto out_free_temp;
d7e09d03
PT
1415 }
1416
1417 if (i == 0) {
1418 *osfs = *temp;
1419 /* If the statfs is from mount, it will needs
1420 * retrieve necessary information from MDT0.
1421 * i.e. mount does not need the merged osfs
1422 * from all of MDT.
1423 * And also clients can be mounted as long as
1424 * MDT0 is in service*/
1425 if (flags & OBD_STATFS_FOR_MDT0)
4d54556f 1426 goto out_free_temp;
d7e09d03
PT
1427 } else {
1428 osfs->os_bavail += temp->os_bavail;
1429 osfs->os_blocks += temp->os_blocks;
1430 osfs->os_ffree += temp->os_ffree;
1431 osfs->os_files += temp->os_files;
1432 }
1433 }
1434
d7e09d03 1435out_free_temp:
8bcf30c3 1436 kfree(temp);
d7e09d03
PT
1437 return rc;
1438}
1439
1440static int lmv_getstatus(struct obd_export *exp,
1441 struct lu_fid *fid,
1442 struct obd_capa **pc)
1443{
1444 struct obd_device *obd = exp->exp_obd;
1445 struct lmv_obd *lmv = &obd->u.lmv;
1446 int rc;
d7e09d03
PT
1447
1448 rc = lmv_check_connect(obd);
1449 if (rc)
0a3bdb00 1450 return rc;
d7e09d03
PT
1451
1452 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
0a3bdb00 1453 return rc;
d7e09d03
PT
1454}
1455
1456static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
21aef7d9 1457 struct obd_capa *oc, u64 valid, const char *name,
d7e09d03
PT
1458 const char *input, int input_size, int output_size,
1459 int flags, struct ptlrpc_request **request)
1460{
1461 struct obd_device *obd = exp->exp_obd;
1462 struct lmv_obd *lmv = &obd->u.lmv;
1463 struct lmv_tgt_desc *tgt;
1464 int rc;
d7e09d03
PT
1465
1466 rc = lmv_check_connect(obd);
1467 if (rc)
0a3bdb00 1468 return rc;
d7e09d03
PT
1469
1470 tgt = lmv_find_target(lmv, fid);
1471 if (IS_ERR(tgt))
0a3bdb00 1472 return PTR_ERR(tgt);
d7e09d03
PT
1473
1474 rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1475 input_size, output_size, flags, request);
1476
0a3bdb00 1477 return rc;
d7e09d03
PT
1478}
1479
1480static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
21aef7d9 1481 struct obd_capa *oc, u64 valid, const char *name,
d7e09d03
PT
1482 const char *input, int input_size, int output_size,
1483 int flags, __u32 suppgid,
1484 struct ptlrpc_request **request)
1485{
1486 struct obd_device *obd = exp->exp_obd;
1487 struct lmv_obd *lmv = &obd->u.lmv;
1488 struct lmv_tgt_desc *tgt;
1489 int rc;
d7e09d03
PT
1490
1491 rc = lmv_check_connect(obd);
1492 if (rc)
0a3bdb00 1493 return rc;
d7e09d03
PT
1494
1495 tgt = lmv_find_target(lmv, fid);
1496 if (IS_ERR(tgt))
0a3bdb00 1497 return PTR_ERR(tgt);
d7e09d03
PT
1498
1499 rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1500 input_size, output_size, flags, suppgid,
1501 request);
1502
0a3bdb00 1503 return rc;
d7e09d03
PT
1504}
1505
1506static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1507 struct ptlrpc_request **request)
1508{
1509 struct obd_device *obd = exp->exp_obd;
1510 struct lmv_obd *lmv = &obd->u.lmv;
1511 struct lmv_tgt_desc *tgt;
1512 int rc;
d7e09d03
PT
1513
1514 rc = lmv_check_connect(obd);
1515 if (rc)
0a3bdb00 1516 return rc;
d7e09d03
PT
1517
1518 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1519 if (IS_ERR(tgt))
0a3bdb00 1520 return PTR_ERR(tgt);
d7e09d03
PT
1521
1522 if (op_data->op_flags & MF_GET_MDT_IDX) {
1523 op_data->op_mds = tgt->ltd_idx;
0a3bdb00 1524 return 0;
d7e09d03
PT
1525 }
1526
1527 rc = md_getattr(tgt->ltd_exp, op_data, request);
1528
0a3bdb00 1529 return rc;
d7e09d03
PT
1530}
1531
1532static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1533{
1534 struct obd_device *obd = exp->exp_obd;
1535 struct lmv_obd *lmv = &obd->u.lmv;
1536 int i;
1537 int rc;
d7e09d03
PT
1538
1539 rc = lmv_check_connect(obd);
1540 if (rc)
0a3bdb00 1541 return rc;
d7e09d03
PT
1542
1543 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1544
1545 /*
1546 * With DNE every object can have two locks in different namespaces:
1547 * lookup lock in space of MDT storing direntry and update/open lock in
1548 * space of MDT storing inode.
1549 */
1550 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1551 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1552 continue;
1553 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1554 }
1555
0a3bdb00 1556 return 0;
d7e09d03
PT
1557}
1558
1559static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1560 ldlm_iterator_t it, void *data)
1561{
1562 struct obd_device *obd = exp->exp_obd;
1563 struct lmv_obd *lmv = &obd->u.lmv;
1564 int i;
1565 int rc;
d7e09d03
PT
1566
1567 rc = lmv_check_connect(obd);
1568 if (rc)
0a3bdb00 1569 return rc;
d7e09d03
PT
1570
1571 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1572
1573 /*
1574 * With DNE every object can have two locks in different namespaces:
1575 * lookup lock in space of MDT storing direntry and update/open lock in
1576 * space of MDT storing inode.
1577 */
1578 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1579 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1580 continue;
1581 rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1582 if (rc)
0a3bdb00 1583 return rc;
d7e09d03
PT
1584 }
1585
0a3bdb00 1586 return rc;
d7e09d03
PT
1587}
1588
1589
1590static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1591 struct md_open_data *mod, struct ptlrpc_request **request)
1592{
1593 struct obd_device *obd = exp->exp_obd;
1594 struct lmv_obd *lmv = &obd->u.lmv;
1595 struct lmv_tgt_desc *tgt;
1596 int rc;
d7e09d03
PT
1597
1598 rc = lmv_check_connect(obd);
1599 if (rc)
0a3bdb00 1600 return rc;
d7e09d03
PT
1601
1602 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1603 if (IS_ERR(tgt))
0a3bdb00 1604 return PTR_ERR(tgt);
d7e09d03
PT
1605
1606 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1607 rc = md_close(tgt->ltd_exp, op_data, mod, request);
0a3bdb00 1608 return rc;
d7e09d03
PT
1609}
1610
1611struct lmv_tgt_desc
1612*lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1613 struct lu_fid *fid)
1614{
1615 struct lmv_tgt_desc *tgt;
1616
1617 tgt = lmv_find_target(lmv, fid);
1618 if (IS_ERR(tgt))
1619 return tgt;
1620
1621 op_data->op_mds = tgt->ltd_idx;
1622
1623 return tgt;
1624}
1625
5dc8d7b4
LC
1626static int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1627 const void *data, int datalen, int mode, __u32 uid,
1628 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1629 struct ptlrpc_request **request)
d7e09d03
PT
1630{
1631 struct obd_device *obd = exp->exp_obd;
1632 struct lmv_obd *lmv = &obd->u.lmv;
1633 struct lmv_tgt_desc *tgt;
1634 int rc;
d7e09d03
PT
1635
1636 rc = lmv_check_connect(obd);
1637 if (rc)
0a3bdb00 1638 return rc;
d7e09d03
PT
1639
1640 if (!lmv->desc.ld_active_tgt_count)
0a3bdb00 1641 return -EIO;
d7e09d03
PT
1642
1643 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1644 if (IS_ERR(tgt))
0a3bdb00 1645 return PTR_ERR(tgt);
d7e09d03
PT
1646
1647 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1648 if (rc)
0a3bdb00 1649 return rc;
d7e09d03
PT
1650
1651 CDEBUG(D_INODE, "CREATE '%*s' on "DFID" -> mds #%x\n",
1652 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1653 op_data->op_mds);
1654
1655 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1656 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1657 cap_effective, rdev, request);
1658
1659 if (rc == 0) {
1660 if (*request == NULL)
0a3bdb00 1661 return rc;
d7e09d03
PT
1662 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1663 }
0a3bdb00 1664 return rc;
d7e09d03
PT
1665}
1666
1667static int lmv_done_writing(struct obd_export *exp,
1668 struct md_op_data *op_data,
1669 struct md_open_data *mod)
1670{
1671 struct obd_device *obd = exp->exp_obd;
1672 struct lmv_obd *lmv = &obd->u.lmv;
1673 struct lmv_tgt_desc *tgt;
1674 int rc;
d7e09d03
PT
1675
1676 rc = lmv_check_connect(obd);
1677 if (rc)
0a3bdb00 1678 return rc;
d7e09d03
PT
1679
1680 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1681 if (IS_ERR(tgt))
0a3bdb00 1682 return PTR_ERR(tgt);
d7e09d03
PT
1683
1684 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
0a3bdb00 1685 return rc;
d7e09d03
PT
1686}
1687
1688static int
1689lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1690 struct lookup_intent *it, struct md_op_data *op_data,
1691 struct lustre_handle *lockh, void *lmm, int lmmsize,
875332d4 1692 __u64 extra_lock_flags)
d7e09d03
PT
1693{
1694 struct ptlrpc_request *req = it->d.lustre.it_data;
1695 struct obd_device *obd = exp->exp_obd;
1696 struct lmv_obd *lmv = &obd->u.lmv;
1697 struct lustre_handle plock;
1698 struct lmv_tgt_desc *tgt;
1699 struct md_op_data *rdata;
1700 struct lu_fid fid1;
1701 struct mdt_body *body;
1702 int rc = 0;
1703 int pmode;
d7e09d03
PT
1704
1705 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1706 LASSERT(body != NULL);
1707
1708 if (!(body->valid & OBD_MD_MDS))
0a3bdb00 1709 return 0;
d7e09d03
PT
1710
1711 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1712 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1713
1714 /*
1715 * We got LOOKUP lock, but we really need attrs.
1716 */
1717 pmode = it->d.lustre.it_lock_mode;
1718 LASSERT(pmode != 0);
1719 memcpy(&plock, lockh, sizeof(plock));
1720 it->d.lustre.it_lock_mode = 0;
1721 it->d.lustre.it_data = NULL;
1722 fid1 = body->fid1;
1723
d7e09d03
PT
1724 ptlrpc_req_finished(req);
1725
1726 tgt = lmv_find_target(lmv, &fid1);
4d54556f
JL
1727 if (IS_ERR(tgt)) {
1728 rc = PTR_ERR(tgt);
1729 goto out;
1730 }
d7e09d03 1731
8bcf30c3 1732 rdata = kzalloc(sizeof(*rdata), GFP_NOFS);
76e4290c 1733 if (!rdata) {
4d54556f
JL
1734 rc = -ENOMEM;
1735 goto out;
1736 }
d7e09d03
PT
1737
1738 rdata->op_fid1 = fid1;
1739 rdata->op_bias = MDS_CROSS_REF;
1740
1741 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1742 lmm, lmmsize, NULL, extra_lock_flags);
8bcf30c3 1743 kfree(rdata);
d7e09d03
PT
1744out:
1745 ldlm_lock_decref(&plock, pmode);
1746 return rc;
1747}
1748
1749static int
1750lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1751 struct lookup_intent *it, struct md_op_data *op_data,
1752 struct lustre_handle *lockh, void *lmm, int lmmsize,
1753 struct ptlrpc_request **req, __u64 extra_lock_flags)
1754{
1755 struct obd_device *obd = exp->exp_obd;
1756 struct lmv_obd *lmv = &obd->u.lmv;
1757 struct lmv_tgt_desc *tgt;
1758 int rc;
d7e09d03
PT
1759
1760 rc = lmv_check_connect(obd);
1761 if (rc)
0a3bdb00 1762 return rc;
d7e09d03
PT
1763
1764 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1765 LL_IT2STR(it), PFID(&op_data->op_fid1));
1766
1767 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1768 if (IS_ERR(tgt))
0a3bdb00 1769 return PTR_ERR(tgt);
d7e09d03
PT
1770
1771 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1772 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1773
1774 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1775 lmm, lmmsize, req, extra_lock_flags);
1776
1777 if (rc == 0 && it && it->it_op == IT_OPEN) {
1778 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1779 lmm, lmmsize, extra_lock_flags);
1780 }
0a3bdb00 1781 return rc;
d7e09d03
PT
1782}
1783
1784static int
1d8cb70c 1785lmv_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
d7e09d03
PT
1786 struct ptlrpc_request **request)
1787{
1788 struct ptlrpc_request *req = NULL;
1789 struct obd_device *obd = exp->exp_obd;
1790 struct lmv_obd *lmv = &obd->u.lmv;
1791 struct lmv_tgt_desc *tgt;
1792 struct mdt_body *body;
1793 int rc;
d7e09d03
PT
1794
1795 rc = lmv_check_connect(obd);
1796 if (rc)
0a3bdb00 1797 return rc;
d7e09d03
PT
1798
1799 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1800 if (IS_ERR(tgt))
0a3bdb00 1801 return PTR_ERR(tgt);
d7e09d03
PT
1802
1803 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1804 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1805 tgt->ltd_idx);
1806
1807 rc = md_getattr_name(tgt->ltd_exp, op_data, request);
1808 if (rc != 0)
0a3bdb00 1809 return rc;
d7e09d03
PT
1810
1811 body = req_capsule_server_get(&(*request)->rq_pill,
1812 &RMF_MDT_BODY);
1813 LASSERT(body != NULL);
1814
1815 if (body->valid & OBD_MD_MDS) {
1816 struct lu_fid rid = body->fid1;
1817 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1818 PFID(&rid));
1819
1820 tgt = lmv_find_target(lmv, &rid);
1821 if (IS_ERR(tgt)) {
1822 ptlrpc_req_finished(*request);
0a3bdb00 1823 return PTR_ERR(tgt);
d7e09d03
PT
1824 }
1825
1826 op_data->op_fid1 = rid;
1827 op_data->op_valid |= OBD_MD_FLCROSSREF;
1828 op_data->op_namelen = 0;
1829 op_data->op_name = NULL;
1830 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1831 ptlrpc_req_finished(*request);
1832 *request = req;
1833 }
1834
0a3bdb00 1835 return rc;
d7e09d03
PT
1836}
1837
1838#define md_op_data_fid(op_data, fl) \
1839 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1840 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1841 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1842 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1843 NULL)
1844
1845static int lmv_early_cancel(struct obd_export *exp, struct md_op_data *op_data,
1846 int op_tgt, ldlm_mode_t mode, int bits, int flag)
1847{
1848 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1849 struct obd_device *obd = exp->exp_obd;
1850 struct lmv_obd *lmv = &obd->u.lmv;
1851 struct lmv_tgt_desc *tgt;
b2952d62 1852 ldlm_policy_data_t policy = { {0} };
d7e09d03 1853 int rc = 0;
d7e09d03
PT
1854
1855 if (!fid_is_sane(fid))
0a3bdb00 1856 return 0;
d7e09d03
PT
1857
1858 tgt = lmv_find_target(lmv, fid);
1859 if (IS_ERR(tgt))
0a3bdb00 1860 return PTR_ERR(tgt);
d7e09d03
PT
1861
1862 if (tgt->ltd_idx != op_tgt) {
1863 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1864 policy.l_inodebits.bits = bits;
1865 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1866 mode, LCF_ASYNC, NULL);
1867 } else {
1868 CDEBUG(D_INODE,
1869 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1870 op_tgt, PFID(fid));
1871 op_data->op_flags |= flag;
1872 rc = 0;
1873 }
1874
0a3bdb00 1875 return rc;
d7e09d03
PT
1876}
1877
1878/*
1879 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1880 * op_data->op_fid2
1881 */
1882static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1883 struct ptlrpc_request **request)
1884{
1885 struct obd_device *obd = exp->exp_obd;
1886 struct lmv_obd *lmv = &obd->u.lmv;
1887 struct lmv_tgt_desc *tgt;
1888 int rc;
d7e09d03
PT
1889
1890 rc = lmv_check_connect(obd);
1891 if (rc)
0a3bdb00 1892 return rc;
d7e09d03
PT
1893
1894 LASSERT(op_data->op_namelen != 0);
1895
1896 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1897 PFID(&op_data->op_fid2), op_data->op_namelen,
1898 op_data->op_name, PFID(&op_data->op_fid1));
1899
4b1a25f0
PT
1900 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1901 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
d7e09d03
PT
1902 op_data->op_cap = cfs_curproc_cap_pack();
1903 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1904 if (IS_ERR(tgt))
0a3bdb00 1905 return PTR_ERR(tgt);
d7e09d03
PT
1906
1907 /*
1908 * Cancel UPDATE lock on child (fid1).
1909 */
1910 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1911 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
1912 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1913 if (rc != 0)
0a3bdb00 1914 return rc;
d7e09d03
PT
1915
1916 rc = md_link(tgt->ltd_exp, op_data, request);
1917
0a3bdb00 1918 return rc;
d7e09d03
PT
1919}
1920
1921static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1922 const char *old, int oldlen, const char *new, int newlen,
1923 struct ptlrpc_request **request)
1924{
1925 struct obd_device *obd = exp->exp_obd;
1926 struct lmv_obd *lmv = &obd->u.lmv;
1927 struct lmv_tgt_desc *src_tgt;
1928 struct lmv_tgt_desc *tgt_tgt;
1929 int rc;
d7e09d03
PT
1930
1931 LASSERT(oldlen != 0);
1932
1933 CDEBUG(D_INODE, "RENAME %*s in "DFID" to %*s in "DFID"\n",
1934 oldlen, old, PFID(&op_data->op_fid1),
1935 newlen, new, PFID(&op_data->op_fid2));
1936
1937 rc = lmv_check_connect(obd);
1938 if (rc)
0a3bdb00 1939 return rc;
d7e09d03 1940
4b1a25f0
PT
1941 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1942 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
d7e09d03
PT
1943 op_data->op_cap = cfs_curproc_cap_pack();
1944 src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1945 if (IS_ERR(src_tgt))
0a3bdb00 1946 return PTR_ERR(src_tgt);
d7e09d03
PT
1947
1948 tgt_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1949 if (IS_ERR(tgt_tgt))
0a3bdb00 1950 return PTR_ERR(tgt_tgt);
d7e09d03
PT
1951 /*
1952 * LOOKUP lock on src child (fid3) should also be cancelled for
1953 * src_tgt in mdc_rename.
1954 */
1955 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
1956
1957 /*
1958 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
1959 * own target.
1960 */
1961 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1962 LCK_EX, MDS_INODELOCK_UPDATE,
1963 MF_MDC_CANCEL_FID2);
1964
1965 /*
1966 * Cancel LOOKUP locks on tgt child (fid4) for parent tgt_tgt.
1967 */
1968 if (rc == 0) {
1969 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1970 LCK_EX, MDS_INODELOCK_LOOKUP,
1971 MF_MDC_CANCEL_FID4);
1972 }
1973
1974 /*
1975 * Cancel all the locks on tgt child (fid4).
1976 */
1977 if (rc == 0)
1978 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1979 LCK_EX, MDS_INODELOCK_FULL,
1980 MF_MDC_CANCEL_FID4);
1981
1982 if (rc == 0)
1983 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen,
1984 new, newlen, request);
0a3bdb00 1985 return rc;
d7e09d03
PT
1986}
1987
1988static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
1989 void *ea, int ealen, void *ea2, int ea2len,
1990 struct ptlrpc_request **request,
1991 struct md_open_data **mod)
1992{
1993 struct obd_device *obd = exp->exp_obd;
1994 struct lmv_obd *lmv = &obd->u.lmv;
1995 struct lmv_tgt_desc *tgt;
a84b7fd5 1996 int rc;
d7e09d03
PT
1997
1998 rc = lmv_check_connect(obd);
1999 if (rc)
0a3bdb00 2000 return rc;
d7e09d03
PT
2001
2002 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2003 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2004
2005 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2006 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2007 if (IS_ERR(tgt))
0a3bdb00 2008 return PTR_ERR(tgt);
d7e09d03
PT
2009
2010 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
2011 ea2len, request, mod);
2012
0a3bdb00 2013 return rc;
d7e09d03
PT
2014}
2015
2016static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
2017 struct obd_capa *oc, struct ptlrpc_request **request)
2018{
2019 struct obd_device *obd = exp->exp_obd;
2020 struct lmv_obd *lmv = &obd->u.lmv;
2021 struct lmv_tgt_desc *tgt;
2022 int rc;
d7e09d03
PT
2023
2024 rc = lmv_check_connect(obd);
2025 if (rc)
0a3bdb00 2026 return rc;
d7e09d03
PT
2027
2028 tgt = lmv_find_target(lmv, fid);
2029 if (IS_ERR(tgt))
0a3bdb00 2030 return PTR_ERR(tgt);
d7e09d03
PT
2031
2032 rc = md_sync(tgt->ltd_exp, fid, oc, request);
0a3bdb00 2033 return rc;
d7e09d03
PT
2034}
2035
2036/*
2037 * Adjust a set of pages, each page containing an array of lu_dirpages,
2038 * so that each page can be used as a single logical lu_dirpage.
2039 *
2040 * A lu_dirpage is laid out as follows, where s = ldp_hash_start,
2041 * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a
2042 * struct lu_dirent. It has size up to LU_PAGE_SIZE. The ldp_hash_end
2043 * value is used as a cookie to request the next lu_dirpage in a
2044 * directory listing that spans multiple pages (two in this example):
2045 * ________
2046 * | |
2047 * .|--------v------- -----.
2048 * |s|e|f|p|ent|ent| ... |ent|
2049 * '--|-------------- -----' Each CFS_PAGE contains a single
2050 * '------. lu_dirpage.
2051 * .---------v------- -----.
2052 * |s|e|f|p|ent| 0 | ... | 0 |
2053 * '----------------- -----'
2054 *
2055 * However, on hosts where the native VM page size (PAGE_CACHE_SIZE) is
2056 * larger than LU_PAGE_SIZE, a single host page may contain multiple
2057 * lu_dirpages. After reading the lu_dirpages from the MDS, the
2058 * ldp_hash_end of the first lu_dirpage refers to the one immediately
2059 * after it in the same CFS_PAGE (arrows simplified for brevity, but
2060 * in general e0==s1, e1==s2, etc.):
2061 *
2062 * .-------------------- -----.
2063 * |s0|e0|f0|p|ent|ent| ... |ent|
2064 * |---v---------------- -----|
2065 * |s1|e1|f1|p|ent|ent| ... |ent|
2066 * |---v---------------- -----| Here, each CFS_PAGE contains
2067 * ... multiple lu_dirpages.
2068 * |---v---------------- -----|
2069 * |s'|e'|f'|p|ent|ent| ... |ent|
2070 * '---|---------------- -----'
2071 * v
2072 * .----------------------------.
2073 * | next CFS_PAGE |
2074 *
2075 * This structure is transformed into a single logical lu_dirpage as follows:
2076 *
2077 * - Replace e0 with e' so the request for the next lu_dirpage gets the page
2078 * labeled 'next CFS_PAGE'.
2079 *
2080 * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether
2081 * a hash collision with the next page exists.
2082 *
2083 * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span
2084 * to the first entry of the next lu_dirpage.
2085 */
2086#if PAGE_CACHE_SIZE > LU_PAGE_SIZE
2087static void lmv_adjust_dirpages(struct page **pages, int ncfspgs, int nlupgs)
2088{
2089 int i;
2090
2091 for (i = 0; i < ncfspgs; i++) {
2092 struct lu_dirpage *dp = kmap(pages[i]);
2093 struct lu_dirpage *first = dp;
2094 struct lu_dirent *end_dirent = NULL;
2095 struct lu_dirent *ent;
2096 __u64 hash_end = dp->ldp_hash_end;
2097 __u32 flags = dp->ldp_flags;
2098
cdb5f710 2099 while (--nlupgs > 0) {
d7e09d03
PT
2100 ent = lu_dirent_start(dp);
2101 for (end_dirent = ent; ent != NULL;
910b551c
MR
2102 end_dirent = ent, ent = lu_dirent_next(ent))
2103 ;
d7e09d03
PT
2104
2105 /* Advance dp to next lu_dirpage. */
2106 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
2107
2108 /* Check if we've reached the end of the CFS_PAGE. */
2109 if (!((unsigned long)dp & ~CFS_PAGE_MASK))
2110 break;
2111
2112 /* Save the hash and flags of this lu_dirpage. */
2113 hash_end = dp->ldp_hash_end;
2114 flags = dp->ldp_flags;
2115
2116 /* Check if lu_dirpage contains no entries. */
2117 if (!end_dirent)
2118 break;
2119
2120 /* Enlarge the end entry lde_reclen from 0 to
2121 * first entry of next lu_dirpage. */
2122 LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0);
2123 end_dirent->lde_reclen =
2124 cpu_to_le16((char *)(dp->ldp_entries) -
2125 (char *)end_dirent);
2126 }
2127
2128 first->ldp_hash_end = hash_end;
2129 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
2130 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
2131
2132 kunmap(pages[i]);
2133 }
cdb5f710 2134 LASSERTF(nlupgs == 0, "left = %d", nlupgs);
d7e09d03
PT
2135}
2136#else
2137#define lmv_adjust_dirpages(pages, ncfspgs, nlupgs) do {} while (0)
2138#endif /* PAGE_CACHE_SIZE > LU_PAGE_SIZE */
2139
2140static int lmv_readpage(struct obd_export *exp, struct md_op_data *op_data,
2141 struct page **pages, struct ptlrpc_request **request)
2142{
2143 struct obd_device *obd = exp->exp_obd;
2144 struct lmv_obd *lmv = &obd->u.lmv;
2145 __u64 offset = op_data->op_offset;
2146 int rc;
2147 int ncfspgs; /* pages read in PAGE_CACHE_SIZE */
2148 int nlupgs; /* pages read in LU_PAGE_SIZE */
2149 struct lmv_tgt_desc *tgt;
d7e09d03
PT
2150
2151 rc = lmv_check_connect(obd);
2152 if (rc)
0a3bdb00 2153 return rc;
d7e09d03 2154
55f5a824 2155 CDEBUG(D_INODE, "READPAGE at %#llx from "DFID"\n",
d7e09d03
PT
2156 offset, PFID(&op_data->op_fid1));
2157
2158 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2159 if (IS_ERR(tgt))
0a3bdb00 2160 return PTR_ERR(tgt);
d7e09d03
PT
2161
2162 rc = md_readpage(tgt->ltd_exp, op_data, pages, request);
2163 if (rc != 0)
0a3bdb00 2164 return rc;
d7e09d03
PT
2165
2166 ncfspgs = ((*request)->rq_bulk->bd_nob_transferred + PAGE_CACHE_SIZE - 1)
2167 >> PAGE_CACHE_SHIFT;
2168 nlupgs = (*request)->rq_bulk->bd_nob_transferred >> LU_PAGE_SHIFT;
2169 LASSERT(!((*request)->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK));
2170 LASSERT(ncfspgs > 0 && ncfspgs <= op_data->op_npages);
2171
2172 CDEBUG(D_INODE, "read %d(%d)/%d pages\n", ncfspgs, nlupgs,
2173 op_data->op_npages);
2174
2175 lmv_adjust_dirpages(pages, ncfspgs, nlupgs);
2176
0a3bdb00 2177 return rc;
d7e09d03
PT
2178}
2179
2180static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2181 struct ptlrpc_request **request)
2182{
2183 struct obd_device *obd = exp->exp_obd;
2184 struct lmv_obd *lmv = &obd->u.lmv;
2185 struct lmv_tgt_desc *tgt = NULL;
2186 struct mdt_body *body;
2187 int rc;
d7e09d03
PT
2188
2189 rc = lmv_check_connect(obd);
2190 if (rc)
0a3bdb00 2191 return rc;
d7e09d03
PT
2192retry:
2193 /* Send unlink requests to the MDT where the child is located */
2194 if (likely(!fid_is_zero(&op_data->op_fid2)))
2195 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2196 else
2197 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2198 if (IS_ERR(tgt))
0a3bdb00 2199 return PTR_ERR(tgt);
d7e09d03 2200
4b1a25f0
PT
2201 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2202 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
d7e09d03
PT
2203 op_data->op_cap = cfs_curproc_cap_pack();
2204
2205 /*
2206 * If child's fid is given, cancel unused locks for it if it is from
2207 * another export than parent.
2208 *
2209 * LOOKUP lock for child (fid3) should also be cancelled on parent
2210 * tgt_tgt in mdc_unlink().
2211 */
2212 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2213
2214 /*
2215 * Cancel FULL locks on child (fid3).
2216 */
2217 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
2218 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2219
2220 if (rc != 0)
0a3bdb00 2221 return rc;
d7e09d03
PT
2222
2223 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n",
2224 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2225
2226 rc = md_unlink(tgt->ltd_exp, op_data, request);
2227 if (rc != 0 && rc != -EREMOTE)
0a3bdb00 2228 return rc;
d7e09d03
PT
2229
2230 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2231 if (body == NULL)
0a3bdb00 2232 return -EPROTO;
d7e09d03
PT
2233
2234 /* Not cross-ref case, just get out of here. */
2235 if (likely(!(body->valid & OBD_MD_MDS)))
0a3bdb00 2236 return 0;
d7e09d03
PT
2237
2238 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2239 exp->exp_obd->obd_name, PFID(&body->fid1));
2240
2241 /* This is a remote object, try remote MDT, Note: it may
2242 * try more than 1 time here, Considering following case
2243 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2244 * 1. Initially A does not know where remote1 is, it send
2245 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2246 * resend unlink RPC to MDT1 (retry 1st time).
2247 *
2248 * 2. During the unlink RPC in flight,
2249 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2250 * and create new remote1, but on MDT0
2251 *
2252 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2253 * /mnt/lustre, then lookup get fid of remote1, and find
2254 * it is remote dir again, and replay -EREMOTE again.
2255 *
2256 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2257 *
2258 * In theory, it might try unlimited time here, but it should
2259 * be very rare case. */
2260 op_data->op_fid2 = body->fid1;
2261 ptlrpc_req_finished(*request);
2262 *request = NULL;
2263
2264 goto retry;
2265}
2266
2267static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2268{
2269 struct lmv_obd *lmv = &obd->u.lmv;
d7e09d03
PT
2270
2271 switch (stage) {
2272 case OBD_CLEANUP_EARLY:
2273 /* XXX: here should be calling obd_precleanup() down to
2274 * stack. */
2275 break;
2276 case OBD_CLEANUP_EXPORTS:
82765049 2277 fld_client_debugfs_fini(&lmv->lmv_fld);
d7e09d03
PT
2278 lprocfs_obd_cleanup(obd);
2279 break;
2280 default:
2281 break;
2282 }
5ed57d6d 2283 return 0;
d7e09d03
PT
2284}
2285
2286static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2287 __u32 keylen, void *key, __u32 *vallen, void *val,
2288 struct lov_stripe_md *lsm)
2289{
2290 struct obd_device *obd;
2291 struct lmv_obd *lmv;
2292 int rc = 0;
d7e09d03
PT
2293
2294 obd = class_exp2obd(exp);
2295 if (obd == NULL) {
55f5a824 2296 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
d7e09d03 2297 exp->exp_handle.h_cookie);
0a3bdb00 2298 return -EINVAL;
d7e09d03
PT
2299 }
2300
2301 lmv = &obd->u.lmv;
2302 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2303 struct lmv_tgt_desc *tgt;
2304 int i;
2305
2306 rc = lmv_check_connect(obd);
2307 if (rc)
0a3bdb00 2308 return rc;
d7e09d03
PT
2309
2310 LASSERT(*vallen == sizeof(__u32));
2311 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2312 tgt = lmv->tgts[i];
2313 /*
2314 * All tgts should be connected when this gets called.
2315 */
2316 if (tgt == NULL || tgt->ltd_exp == NULL)
2317 continue;
2318
2319 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2320 vallen, val, NULL))
0a3bdb00 2321 return 0;
d7e09d03 2322 }
0a3bdb00 2323 return -EINVAL;
44779340
BB
2324 } else if (KEY_IS(KEY_MAX_EASIZE) ||
2325 KEY_IS(KEY_DEFAULT_EASIZE) ||
2326 KEY_IS(KEY_MAX_COOKIESIZE) ||
2327 KEY_IS(KEY_DEFAULT_COOKIESIZE) ||
2328 KEY_IS(KEY_CONN_DATA)) {
d7e09d03
PT
2329 rc = lmv_check_connect(obd);
2330 if (rc)
0a3bdb00 2331 return rc;
d7e09d03
PT
2332
2333 /*
2334 * Forwarding this request to first MDS, it should know LOV
2335 * desc.
2336 */
2337 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2338 vallen, val, NULL);
2339 if (!rc && KEY_IS(KEY_CONN_DATA))
2340 exp->exp_connect_data = *(struct obd_connect_data *)val;
0a3bdb00 2341 return rc;
d7e09d03
PT
2342 } else if (KEY_IS(KEY_TGT_COUNT)) {
2343 *((int *)val) = lmv->desc.ld_tgt_count;
0a3bdb00 2344 return 0;
d7e09d03
PT
2345 }
2346
2347 CDEBUG(D_IOCTL, "Invalid key\n");
0a3bdb00 2348 return -EINVAL;
d7e09d03
PT
2349}
2350
5dc8d7b4
LC
2351static int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2352 u32 keylen, void *key, u32 vallen,
2353 void *val, struct ptlrpc_request_set *set)
d7e09d03
PT
2354{
2355 struct lmv_tgt_desc *tgt;
2356 struct obd_device *obd;
2357 struct lmv_obd *lmv;
2358 int rc = 0;
d7e09d03
PT
2359
2360 obd = class_exp2obd(exp);
2361 if (obd == NULL) {
55f5a824 2362 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
d7e09d03 2363 exp->exp_handle.h_cookie);
0a3bdb00 2364 return -EINVAL;
d7e09d03
PT
2365 }
2366 lmv = &obd->u.lmv;
2367
2368 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) {
2369 int i, err = 0;
2370
2371 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2372 tgt = lmv->tgts[i];
2373
2374 if (tgt == NULL || tgt->ltd_exp == NULL)
2375 continue;
2376
2377 err = obd_set_info_async(env, tgt->ltd_exp,
2378 keylen, key, vallen, val, set);
2379 if (err && rc == 0)
2380 rc = err;
2381 }
2382
0a3bdb00 2383 return rc;
d7e09d03
PT
2384 }
2385
0a3bdb00 2386 return -EINVAL;
d7e09d03
PT
2387}
2388
5dc8d7b4
LC
2389static int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2390 struct lov_stripe_md *lsm)
d7e09d03
PT
2391{
2392 struct obd_device *obd = class_exp2obd(exp);
2393 struct lmv_obd *lmv = &obd->u.lmv;
2394 struct lmv_stripe_md *meap;
2395 struct lmv_stripe_md *lsmp;
2396 int mea_size;
2397 int i;
d7e09d03
PT
2398
2399 mea_size = lmv_get_easize(lmv);
2400 if (!lmmp)
0a3bdb00 2401 return mea_size;
d7e09d03
PT
2402
2403 if (*lmmp && !lsm) {
8cc3792a 2404 kvfree(*lmmp);
d7e09d03 2405 *lmmp = NULL;
0a3bdb00 2406 return 0;
d7e09d03
PT
2407 }
2408
2409 if (*lmmp == NULL) {
8cc3792a 2410 *lmmp = libcfs_kvzalloc(mea_size, GFP_NOFS);
d7e09d03 2411 if (*lmmp == NULL)
0a3bdb00 2412 return -ENOMEM;
d7e09d03
PT
2413 }
2414
2415 if (!lsm)
0a3bdb00 2416 return mea_size;
d7e09d03
PT
2417
2418 lsmp = (struct lmv_stripe_md *)lsm;
2419 meap = (struct lmv_stripe_md *)*lmmp;
2420
2421 if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR &&
2422 lsmp->mea_magic != MEA_MAGIC_ALL_CHARS)
0a3bdb00 2423 return -EINVAL;
d7e09d03
PT
2424
2425 meap->mea_magic = cpu_to_le32(lsmp->mea_magic);
2426 meap->mea_count = cpu_to_le32(lsmp->mea_count);
2427 meap->mea_master = cpu_to_le32(lsmp->mea_master);
2428
2429 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2430 meap->mea_ids[i] = lsmp->mea_ids[i];
2431 fid_cpu_to_le(&meap->mea_ids[i], &lsmp->mea_ids[i]);
2432 }
2433
0a3bdb00 2434 return mea_size;
d7e09d03
PT
2435}
2436
5dc8d7b4
LC
2437static int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2438 struct lov_mds_md *lmm, int lmm_size)
d7e09d03
PT
2439{
2440 struct obd_device *obd = class_exp2obd(exp);
2441 struct lmv_stripe_md **tmea = (struct lmv_stripe_md **)lsmp;
2442 struct lmv_stripe_md *mea = (struct lmv_stripe_md *)lmm;
2443 struct lmv_obd *lmv = &obd->u.lmv;
2444 int mea_size;
2445 int i;
2446 __u32 magic;
d7e09d03
PT
2447
2448 mea_size = lmv_get_easize(lmv);
2449 if (lsmp == NULL)
2450 return mea_size;
2451
2452 if (*lsmp != NULL && lmm == NULL) {
8cc3792a 2453 kvfree(*tmea);
d7e09d03 2454 *lsmp = NULL;
0a3bdb00 2455 return 0;
d7e09d03
PT
2456 }
2457
2458 LASSERT(mea_size == lmm_size);
2459
8cc3792a 2460 *tmea = libcfs_kvzalloc(mea_size, GFP_NOFS);
d7e09d03 2461 if (*tmea == NULL)
0a3bdb00 2462 return -ENOMEM;
d7e09d03
PT
2463
2464 if (!lmm)
0a3bdb00 2465 return mea_size;
d7e09d03
PT
2466
2467 if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
2468 mea->mea_magic == MEA_MAGIC_ALL_CHARS ||
9d0b2b7a 2469 mea->mea_magic == MEA_MAGIC_HASH_SEGMENT) {
d7e09d03
PT
2470 magic = le32_to_cpu(mea->mea_magic);
2471 } else {
2472 /*
2473 * Old mea is not handled here.
2474 */
2475 CERROR("Old not supportable EA is found\n");
2476 LBUG();
2477 }
2478
2479 (*tmea)->mea_magic = magic;
2480 (*tmea)->mea_count = le32_to_cpu(mea->mea_count);
2481 (*tmea)->mea_master = le32_to_cpu(mea->mea_master);
2482
2483 for (i = 0; i < (*tmea)->mea_count; i++) {
2484 (*tmea)->mea_ids[i] = mea->mea_ids[i];
2485 fid_le_to_cpu(&(*tmea)->mea_ids[i], &(*tmea)->mea_ids[i]);
2486 }
0a3bdb00 2487 return mea_size;
d7e09d03
PT
2488}
2489
2490static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2491 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2492 ldlm_cancel_flags_t flags, void *opaque)
2493{
2494 struct obd_device *obd = exp->exp_obd;
2495 struct lmv_obd *lmv = &obd->u.lmv;
2496 int rc = 0;
2497 int err;
2498 int i;
d7e09d03
PT
2499
2500 LASSERT(fid != NULL);
2501
2502 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2503 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL ||
2504 lmv->tgts[i]->ltd_active == 0)
2505 continue;
2506
2507 err = md_cancel_unused(lmv->tgts[i]->ltd_exp, fid,
2508 policy, mode, flags, opaque);
2509 if (!rc)
2510 rc = err;
2511 }
0a3bdb00 2512 return rc;
d7e09d03
PT
2513}
2514
5dc8d7b4
LC
2515static int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
2516 __u64 *bits)
d7e09d03
PT
2517{
2518 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2519 int rc;
d7e09d03
PT
2520
2521 rc = md_set_lock_data(lmv->tgts[0]->ltd_exp, lockh, data, bits);
0a3bdb00 2522 return rc;
d7e09d03
PT
2523}
2524
5dc8d7b4
LC
2525static ldlm_mode_t lmv_lock_match(struct obd_export *exp, __u64 flags,
2526 const struct lu_fid *fid, ldlm_type_t type,
2527 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2528 struct lustre_handle *lockh)
d7e09d03
PT
2529{
2530 struct obd_device *obd = exp->exp_obd;
2531 struct lmv_obd *lmv = &obd->u.lmv;
2532 ldlm_mode_t rc;
2533 int i;
d7e09d03
PT
2534
2535 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2536
2537 /*
2538 * With CMD every object can have two locks in different namespaces:
2539 * lookup lock in space of mds storing direntry and update/open lock in
2540 * space of mds storing inode. Thus we check all targets, not only that
2541 * one fid was created in.
2542 */
2543 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2544 if (lmv->tgts[i] == NULL ||
2545 lmv->tgts[i]->ltd_exp == NULL ||
2546 lmv->tgts[i]->ltd_active == 0)
2547 continue;
2548
2549 rc = md_lock_match(lmv->tgts[i]->ltd_exp, flags, fid,
2550 type, policy, mode, lockh);
2551 if (rc)
0a3bdb00 2552 return rc;
d7e09d03
PT
2553 }
2554
0a3bdb00 2555 return 0;
d7e09d03
PT
2556}
2557
5dc8d7b4
LC
2558static int lmv_get_lustre_md(struct obd_export *exp,
2559 struct ptlrpc_request *req,
2560 struct obd_export *dt_exp,
2561 struct obd_export *md_exp,
2562 struct lustre_md *md)
d7e09d03
PT
2563{
2564 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2565
2566 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
2567}
2568
5dc8d7b4 2569static int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
d7e09d03
PT
2570{
2571 struct obd_device *obd = exp->exp_obd;
2572 struct lmv_obd *lmv = &obd->u.lmv;
d7e09d03
PT
2573
2574 if (md->mea)
2575 obd_free_memmd(exp, (void *)&md->mea);
0a3bdb00 2576 return md_free_lustre_md(lmv->tgts[0]->ltd_exp, md);
d7e09d03
PT
2577}
2578
5dc8d7b4
LC
2579static int lmv_set_open_replay_data(struct obd_export *exp,
2580 struct obd_client_handle *och,
2581 struct lookup_intent *it)
d7e09d03
PT
2582{
2583 struct obd_device *obd = exp->exp_obd;
2584 struct lmv_obd *lmv = &obd->u.lmv;
2585 struct lmv_tgt_desc *tgt;
d7e09d03
PT
2586
2587 tgt = lmv_find_target(lmv, &och->och_fid);
2588 if (IS_ERR(tgt))
0a3bdb00 2589 return PTR_ERR(tgt);
d7e09d03 2590
63d42578 2591 return md_set_open_replay_data(tgt->ltd_exp, och, it);
d7e09d03
PT
2592}
2593
5dc8d7b4
LC
2594static int lmv_clear_open_replay_data(struct obd_export *exp,
2595 struct obd_client_handle *och)
d7e09d03
PT
2596{
2597 struct obd_device *obd = exp->exp_obd;
2598 struct lmv_obd *lmv = &obd->u.lmv;
2599 struct lmv_tgt_desc *tgt;
d7e09d03
PT
2600
2601 tgt = lmv_find_target(lmv, &och->och_fid);
2602 if (IS_ERR(tgt))
0a3bdb00 2603 return PTR_ERR(tgt);
d7e09d03 2604
0a3bdb00 2605 return md_clear_open_replay_data(tgt->ltd_exp, och);
d7e09d03
PT
2606}
2607
2608static int lmv_get_remote_perm(struct obd_export *exp,
2609 const struct lu_fid *fid,
2610 struct obd_capa *oc, __u32 suppgid,
2611 struct ptlrpc_request **request)
2612{
2613 struct obd_device *obd = exp->exp_obd;
2614 struct lmv_obd *lmv = &obd->u.lmv;
2615 struct lmv_tgt_desc *tgt;
2616 int rc;
d7e09d03
PT
2617
2618 rc = lmv_check_connect(obd);
2619 if (rc)
0a3bdb00 2620 return rc;
d7e09d03
PT
2621
2622 tgt = lmv_find_target(lmv, fid);
2623 if (IS_ERR(tgt))
0a3bdb00 2624 return PTR_ERR(tgt);
d7e09d03
PT
2625
2626 rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
0a3bdb00 2627 return rc;
d7e09d03
PT
2628}
2629
2630static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
2631 renew_capa_cb_t cb)
2632{
2633 struct obd_device *obd = exp->exp_obd;
2634 struct lmv_obd *lmv = &obd->u.lmv;
2635 struct lmv_tgt_desc *tgt;
2636 int rc;
d7e09d03
PT
2637
2638 rc = lmv_check_connect(obd);
2639 if (rc)
0a3bdb00 2640 return rc;
d7e09d03
PT
2641
2642 tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
2643 if (IS_ERR(tgt))
0a3bdb00 2644 return PTR_ERR(tgt);
d7e09d03
PT
2645
2646 rc = md_renew_capa(tgt->ltd_exp, oc, cb);
0a3bdb00 2647 return rc;
d7e09d03
PT
2648}
2649
5dc8d7b4
LC
2650static int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
2651 const struct req_msg_field *field,
2652 struct obd_capa **oc)
d7e09d03
PT
2653{
2654 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2655
2656 return md_unpack_capa(lmv->tgts[0]->ltd_exp, req, field, oc);
2657}
2658
5dc8d7b4
LC
2659static int lmv_intent_getattr_async(struct obd_export *exp,
2660 struct md_enqueue_info *minfo,
2661 struct ldlm_enqueue_info *einfo)
d7e09d03
PT
2662{
2663 struct md_op_data *op_data = &minfo->mi_data;
2664 struct obd_device *obd = exp->exp_obd;
2665 struct lmv_obd *lmv = &obd->u.lmv;
2666 struct lmv_tgt_desc *tgt = NULL;
2667 int rc;
d7e09d03
PT
2668
2669 rc = lmv_check_connect(obd);
2670 if (rc)
0a3bdb00 2671 return rc;
d7e09d03
PT
2672
2673 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2674 if (IS_ERR(tgt))
0a3bdb00 2675 return PTR_ERR(tgt);
d7e09d03
PT
2676
2677 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
0a3bdb00 2678 return rc;
d7e09d03
PT
2679}
2680
5dc8d7b4
LC
2681static int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
2682 struct lu_fid *fid, __u64 *bits)
d7e09d03
PT
2683{
2684 struct obd_device *obd = exp->exp_obd;
2685 struct lmv_obd *lmv = &obd->u.lmv;
2686 struct lmv_tgt_desc *tgt;
2687 int rc;
d7e09d03
PT
2688
2689 rc = lmv_check_connect(obd);
2690 if (rc)
0a3bdb00 2691 return rc;
d7e09d03
PT
2692
2693 tgt = lmv_find_target(lmv, fid);
2694 if (IS_ERR(tgt))
0a3bdb00 2695 return PTR_ERR(tgt);
d7e09d03
PT
2696
2697 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
0a3bdb00 2698 return rc;
d7e09d03
PT
2699}
2700
2701/**
2702 * For lmv, only need to send request to master MDT, and the master MDT will
2703 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
2704 * we directly fetch data from the slave MDTs.
2705 */
5dc8d7b4
LC
2706static int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
2707 struct obd_quotactl *oqctl)
d7e09d03
PT
2708{
2709 struct obd_device *obd = class_exp2obd(exp);
2710 struct lmv_obd *lmv = &obd->u.lmv;
2711 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2712 int rc = 0, i;
2713 __u64 curspace, curinodes;
d7e09d03
PT
2714
2715 if (!lmv->desc.ld_tgt_count || !tgt->ltd_active) {
2716 CERROR("master lmv inactive\n");
0a3bdb00 2717 return -EIO;
d7e09d03
PT
2718 }
2719
2720 if (oqctl->qc_cmd != Q_GETOQUOTA) {
2721 rc = obd_quotactl(tgt->ltd_exp, oqctl);
0a3bdb00 2722 return rc;
d7e09d03
PT
2723 }
2724
2725 curspace = curinodes = 0;
2726 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2727 int err;
2728 tgt = lmv->tgts[i];
2729
2730 if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0)
2731 continue;
2732 if (!tgt->ltd_active) {
2733 CDEBUG(D_HA, "mdt %d is inactive.\n", i);
2734 continue;
2735 }
2736
2737 err = obd_quotactl(tgt->ltd_exp, oqctl);
2738 if (err) {
2739 CERROR("getquota on mdt %d failed. %d\n", i, err);
2740 if (!rc)
2741 rc = err;
2742 } else {
2743 curspace += oqctl->qc_dqblk.dqb_curspace;
2744 curinodes += oqctl->qc_dqblk.dqb_curinodes;
2745 }
2746 }
2747 oqctl->qc_dqblk.dqb_curspace = curspace;
2748 oqctl->qc_dqblk.dqb_curinodes = curinodes;
2749
0a3bdb00 2750 return rc;
d7e09d03
PT
2751}
2752
5dc8d7b4
LC
2753static int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
2754 struct obd_quotactl *oqctl)
d7e09d03
PT
2755{
2756 struct obd_device *obd = class_exp2obd(exp);
2757 struct lmv_obd *lmv = &obd->u.lmv;
2758 struct lmv_tgt_desc *tgt;
2759 int i, rc = 0;
d7e09d03
PT
2760
2761 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2762 int err;
2763 tgt = lmv->tgts[i];
2764 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
2765 CERROR("lmv idx %d inactive\n", i);
0a3bdb00 2766 return -EIO;
d7e09d03
PT
2767 }
2768
2769 err = obd_quotacheck(tgt->ltd_exp, oqctl);
2770 if (err && !rc)
2771 rc = err;
2772 }
2773
0a3bdb00 2774 return rc;
d7e09d03
PT
2775}
2776
5dc8d7b4 2777static struct obd_ops lmv_obd_ops = {
d7e09d03
PT
2778 .o_owner = THIS_MODULE,
2779 .o_setup = lmv_setup,
2780 .o_cleanup = lmv_cleanup,
2781 .o_precleanup = lmv_precleanup,
2782 .o_process_config = lmv_process_config,
2783 .o_connect = lmv_connect,
2784 .o_disconnect = lmv_disconnect,
2785 .o_statfs = lmv_statfs,
2786 .o_get_info = lmv_get_info,
2787 .o_set_info_async = lmv_set_info_async,
2788 .o_packmd = lmv_packmd,
2789 .o_unpackmd = lmv_unpackmd,
2790 .o_notify = lmv_notify,
2791 .o_get_uuid = lmv_get_uuid,
2792 .o_iocontrol = lmv_iocontrol,
2793 .o_quotacheck = lmv_quotacheck,
2794 .o_quotactl = lmv_quotactl
2795};
2796
5dc8d7b4 2797static struct md_ops lmv_md_ops = {
d7e09d03
PT
2798 .m_getstatus = lmv_getstatus,
2799 .m_null_inode = lmv_null_inode,
2800 .m_find_cbdata = lmv_find_cbdata,
2801 .m_close = lmv_close,
2802 .m_create = lmv_create,
2803 .m_done_writing = lmv_done_writing,
2804 .m_enqueue = lmv_enqueue,
2805 .m_getattr = lmv_getattr,
2806 .m_getxattr = lmv_getxattr,
2807 .m_getattr_name = lmv_getattr_name,
2808 .m_intent_lock = lmv_intent_lock,
2809 .m_link = lmv_link,
2810 .m_rename = lmv_rename,
2811 .m_setattr = lmv_setattr,
2812 .m_setxattr = lmv_setxattr,
2813 .m_sync = lmv_sync,
2814 .m_readpage = lmv_readpage,
2815 .m_unlink = lmv_unlink,
2816 .m_init_ea_size = lmv_init_ea_size,
2817 .m_cancel_unused = lmv_cancel_unused,
2818 .m_set_lock_data = lmv_set_lock_data,
2819 .m_lock_match = lmv_lock_match,
2820 .m_get_lustre_md = lmv_get_lustre_md,
2821 .m_free_lustre_md = lmv_free_lustre_md,
2822 .m_set_open_replay_data = lmv_set_open_replay_data,
2823 .m_clear_open_replay_data = lmv_clear_open_replay_data,
2824 .m_renew_capa = lmv_renew_capa,
2825 .m_unpack_capa = lmv_unpack_capa,
2826 .m_get_remote_perm = lmv_get_remote_perm,
2827 .m_intent_getattr_async = lmv_intent_getattr_async,
2828 .m_revalidate_lock = lmv_revalidate_lock
2829};
2830
5dc8d7b4 2831static int __init lmv_init(void)
d7e09d03
PT
2832{
2833 struct lprocfs_static_vars lvars;
2834 int rc;
2835
2836 lprocfs_lmv_init_vars(&lvars);
2837
2838 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
2962b440 2839 LUSTRE_LMV_NAME, NULL);
d7e09d03
PT
2840 return rc;
2841}
2842
2843static void lmv_exit(void)
2844{
2845 class_unregister_type(LUSTRE_LMV_NAME);
2846}
2847
2848MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2849MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
2850MODULE_LICENSE("GPL");
2851
2852module_init(lmv_init);
2853module_exit(lmv_exit);
This page took 0.52956 seconds and 5 git commands to generate.