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