4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LMV
39 #include <linux/slab.h>
40 #include <linux/module.h>
41 #include <linux/init.h>
42 #include <linux/slab.h>
43 #include <linux/pagemap.h>
45 #include <asm/div64.h>
46 #include <linux/seq_file.h>
47 #include <linux/namei.h>
49 #include <liblustre.h>
52 #include <lustre/lustre_idl.h>
53 #include <obd_support.h>
54 #include <lustre_lib.h>
55 #include <lustre_net.h>
56 #include <obd_class.h>
57 #include <lprocfs_status.h>
58 #include <lustre_lite.h>
59 #include <lustre_fid.h>
60 #include "lmv_internal.h"
62 static void lmv_activate_target(struct lmv_obd *lmv,
63 struct lmv_tgt_desc *tgt,
66 if (tgt->ltd_active == activate)
69 tgt->ltd_active = activate;
70 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
76 * -EINVAL : UUID can't be found in the LMV's target list
77 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
78 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
80 static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid,
83 struct lmv_tgt_desc *tgt;
84 struct obd_device *obd;
89 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
90 lmv, uuid->uuid, activate);
92 spin_lock(&lmv->lmv_lock);
93 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
95 if (tgt == NULL || tgt->ltd_exp == NULL)
98 CDEBUG(D_INFO, "Target idx %d is %s conn "LPX64"\n", i,
99 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
101 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
105 if (i == lmv->desc.ld_tgt_count)
106 GOTO(out_lmv_lock, rc = -EINVAL);
108 obd = class_exp2obd(tgt->ltd_exp);
110 GOTO(out_lmv_lock, rc = -ENOTCONN);
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);
117 if (tgt->ltd_active == activate) {
118 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
119 activate ? "" : "in");
120 GOTO(out_lmv_lock, rc);
123 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
124 activate ? "" : "in");
125 lmv_activate_target(lmv, tgt, activate);
129 spin_unlock(&lmv->lmv_lock);
133 struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
135 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
137 return obd_get_uuid(lmv->tgts[0]->ltd_exp);
140 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
141 enum obd_notify_event ev, void *data)
143 struct obd_connect_data *conn_data;
144 struct lmv_obd *lmv = &obd->u.lmv;
145 struct obd_uuid *uuid;
149 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
150 CERROR("unexpected notification of %s %s!\n",
151 watched->obd_type->typ_name,
156 uuid = &watched->u.cli.cl_target_uuid;
157 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
159 * Set MDC as active before notifying the observer, so the
160 * observer can use the MDC normally.
162 rc = lmv_set_mdc_active(lmv, uuid,
163 ev == OBD_NOTIFY_ACTIVE);
165 CERROR("%sactivation of %s failed: %d\n",
166 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
170 } else if (ev == OBD_NOTIFY_OCD) {
171 conn_data = &watched->u.cli.cl_import->imp_connect_data;
173 * XXX: Make sure that ocd_connect_flags from all targets are
174 * the same. Otherwise one of MDTs runs wrong version or
175 * something like this. --umka
177 obd->obd_self_export->exp_connect_data = *conn_data;
180 else if (ev == OBD_NOTIFY_DISCON) {
182 * For disconnect event, flush fld cache for failout MDS case.
184 fld_client_flush(&lmv->lmv_fld);
188 * Pass the notification up the chain.
190 if (obd->obd_observer)
191 rc = obd_notify(obd->obd_observer, watched, ev, data);
197 * This is fake connect function. Its purpose is to initialize lmv and say
198 * caller that everything is okay. Real connection will be performed later.
200 static int lmv_connect(const struct lu_env *env,
201 struct obd_export **exp, struct obd_device *obd,
202 struct obd_uuid *cluuid, struct obd_connect_data *data,
206 struct proc_dir_entry *lmv_proc_dir;
208 struct lmv_obd *lmv = &obd->u.lmv;
209 struct lustre_handle conn = { 0 };
214 * We don't want to actually do the underlying connections more than
215 * once, so keep track.
218 if (lmv->refcount > 1) {
223 rc = class_connect(&conn, obd, cluuid);
225 CERROR("class_connection() returned %d\n", rc);
229 *exp = class_conn2export(&conn);
230 class_export_get(*exp);
234 lmv->cluuid = *cluuid;
237 lmv->conn_data = *data;
240 lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
242 if (IS_ERR(lmv_proc_dir)) {
243 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
244 obd->obd_type->typ_name, obd->obd_name);
250 * All real clients should perform actual connection right away, because
251 * it is possible, that LMV will not have opportunity to connect targets
252 * and MDC stuff will be called directly, for instance while reading
253 * ../mdc/../kbytesfree procfs file, etc.
255 if (data->ocd_connect_flags & OBD_CONNECT_REAL)
256 rc = lmv_check_connect(obd);
261 lprocfs_remove(&lmv_proc_dir);
268 static void lmv_set_timeouts(struct obd_device *obd)
270 struct lmv_tgt_desc *tgt;
275 if (lmv->server_timeout == 0)
278 if (lmv->connected == 0)
281 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
283 if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0)
286 obd_set_info_async(NULL, tgt->ltd_exp, sizeof(KEY_INTERMDS),
287 KEY_INTERMDS, 0, NULL, NULL);
291 static int lmv_init_ea_size(struct obd_export *exp, int easize,
292 int def_easize, int cookiesize)
294 struct obd_device *obd = exp->exp_obd;
295 struct lmv_obd *lmv = &obd->u.lmv;
301 if (lmv->max_easize < easize) {
302 lmv->max_easize = easize;
305 if (lmv->max_def_easize < def_easize) {
306 lmv->max_def_easize = def_easize;
309 if (lmv->max_cookiesize < cookiesize) {
310 lmv->max_cookiesize = cookiesize;
316 if (lmv->connected == 0)
319 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
320 if (lmv->tgts[i] == NULL ||
321 lmv->tgts[i]->ltd_exp == NULL ||
322 lmv->tgts[i]->ltd_active == 0) {
323 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
327 rc = md_init_ea_size(lmv->tgts[i]->ltd_exp, easize, def_easize,
330 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
331 " rc = %d.\n", obd->obd_name, i, rc);
338 #define MAX_STRING_SIZE 128
340 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
343 struct proc_dir_entry *lmv_proc_dir;
345 struct lmv_obd *lmv = &obd->u.lmv;
346 struct obd_uuid *cluuid = &lmv->cluuid;
347 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
348 struct obd_device *mdc_obd;
349 struct obd_export *mdc_exp;
350 struct lu_fld_target target;
354 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
357 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
361 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
362 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
363 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
366 if (!mdc_obd->obd_set_up) {
367 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
371 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
372 &lmv->conn_data, NULL);
374 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
379 * Init fid sequence client for this mdc and add new fld target.
381 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
385 target.ft_srv = NULL;
386 target.ft_exp = mdc_exp;
387 target.ft_idx = tgt->ltd_idx;
389 fld_client_add_target(&lmv->lmv_fld, &target);
391 rc = obd_register_observer(mdc_obd, obd);
393 obd_disconnect(mdc_exp);
394 CERROR("target %s register_observer error %d\n",
395 tgt->ltd_uuid.uuid, rc);
399 if (obd->obd_observer) {
401 * Tell the observer about the new target.
403 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
405 (void *)(tgt - lmv->tgts[0]));
407 obd_disconnect(mdc_exp);
413 tgt->ltd_exp = mdc_exp;
414 lmv->desc.ld_active_tgt_count++;
416 md_init_ea_size(tgt->ltd_exp, lmv->max_easize,
417 lmv->max_def_easize, lmv->max_cookiesize);
419 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
420 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
421 cfs_atomic_read(&obd->obd_refcount));
424 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
426 struct proc_dir_entry *mdc_symlink;
428 LASSERT(mdc_obd->obd_type != NULL);
429 LASSERT(mdc_obd->obd_type->typ_name != NULL);
430 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
433 mdc_obd->obd_type->typ_name,
435 if (mdc_symlink == NULL) {
436 CERROR("Could not register LMV target "
437 "/proc/fs/lustre/%s/%s/target_obds/%s.",
438 obd->obd_type->typ_name, obd->obd_name,
440 lprocfs_remove(&lmv_proc_dir);
448 static void lmv_del_target(struct lmv_obd *lmv, int index)
450 if (lmv->tgts[index] == NULL)
453 OBD_FREE_PTR(lmv->tgts[index]);
454 lmv->tgts[index] = NULL;
458 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
459 __u32 index, int gen)
461 struct lmv_obd *lmv = &obd->u.lmv;
462 struct lmv_tgt_desc *tgt;
466 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
470 if (lmv->desc.ld_tgt_count == 0) {
471 struct obd_device *mdc_obd;
473 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
476 lmv_init_unlock(lmv);
477 CERROR("%s: Target %s not attached: rc = %d\n",
478 obd->obd_name, uuidp->uuid, -EINVAL);
483 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
484 tgt = lmv->tgts[index];
485 CERROR("%s: UUID %s already assigned at LOV target index %d:"
486 " rc = %d\n", obd->obd_name,
487 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
488 lmv_init_unlock(lmv);
492 if (index >= lmv->tgts_size) {
493 /* We need to reallocate the lmv target array. */
494 struct lmv_tgt_desc **newtgts, **old = NULL;
498 while (newsize < index + 1)
499 newsize = newsize << 1;
500 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
501 if (newtgts == NULL) {
502 lmv_init_unlock(lmv);
506 if (lmv->tgts_size) {
507 memcpy(newtgts, lmv->tgts,
508 sizeof(*newtgts) * lmv->tgts_size);
510 oldsize = lmv->tgts_size;
514 lmv->tgts_size = newsize;
517 OBD_FREE(old, sizeof(*old) * oldsize);
519 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
525 lmv_init_unlock(lmv);
529 mutex_init(&tgt->ltd_fid_mutex);
530 tgt->ltd_idx = index;
531 tgt->ltd_uuid = *uuidp;
533 lmv->tgts[index] = tgt;
534 if (index >= lmv->desc.ld_tgt_count)
535 lmv->desc.ld_tgt_count = index + 1;
537 if (lmv->connected) {
538 rc = lmv_connect_mdc(obd, tgt);
540 spin_lock(&lmv->lmv_lock);
541 lmv->desc.ld_tgt_count--;
542 memset(tgt, 0, sizeof(*tgt));
543 spin_unlock(&lmv->lmv_lock);
545 int easize = sizeof(struct lmv_stripe_md) +
546 lmv->desc.ld_tgt_count *
547 sizeof(struct lu_fid);
548 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
552 lmv_init_unlock(lmv);
556 int lmv_check_connect(struct obd_device *obd)
558 struct lmv_obd *lmv = &obd->u.lmv;
559 struct lmv_tgt_desc *tgt;
569 if (lmv->connected) {
570 lmv_init_unlock(lmv);
574 if (lmv->desc.ld_tgt_count == 0) {
575 lmv_init_unlock(lmv);
576 CERROR("%s: no targets configured.\n", obd->obd_name);
580 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
581 lmv->cluuid.uuid, obd->obd_name);
583 LASSERT(lmv->tgts != NULL);
585 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
589 rc = lmv_connect_mdc(obd, tgt);
594 lmv_set_timeouts(obd);
595 class_export_put(lmv->exp);
597 easize = lmv_get_easize(lmv);
598 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
599 lmv_init_unlock(lmv);
610 --lmv->desc.ld_active_tgt_count;
611 rc2 = obd_disconnect(tgt->ltd_exp);
613 CERROR("LMV target %s disconnect on "
614 "MDC idx %d: error %d\n",
615 tgt->ltd_uuid.uuid, i, rc2);
619 class_disconnect(lmv->exp);
620 lmv_init_unlock(lmv);
624 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
627 struct proc_dir_entry *lmv_proc_dir;
629 struct lmv_obd *lmv = &obd->u.lmv;
630 struct obd_device *mdc_obd;
634 LASSERT(tgt != NULL);
635 LASSERT(obd != NULL);
637 mdc_obd = class_exp2obd(tgt->ltd_exp);
640 mdc_obd->obd_force = obd->obd_force;
641 mdc_obd->obd_fail = obd->obd_fail;
642 mdc_obd->obd_no_recov = obd->obd_no_recov;
646 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
648 struct proc_dir_entry *mdc_symlink;
650 mdc_symlink = lprocfs_srch(lmv_proc_dir, mdc_obd->obd_name);
652 lprocfs_remove(&mdc_symlink);
654 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing\n",
655 obd->obd_type->typ_name, obd->obd_name,
660 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
662 CERROR("Can't finanize fids factory\n");
664 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
665 tgt->ltd_exp->exp_obd->obd_name,
666 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
668 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
669 rc = obd_disconnect(tgt->ltd_exp);
671 if (tgt->ltd_active) {
672 CERROR("Target %s disconnect error %d\n",
673 tgt->ltd_uuid.uuid, rc);
677 lmv_activate_target(lmv, tgt, 0);
682 static int lmv_disconnect(struct obd_export *exp)
684 struct obd_device *obd = class_exp2obd(exp);
686 struct proc_dir_entry *lmv_proc_dir;
688 struct lmv_obd *lmv = &obd->u.lmv;
697 * Only disconnect the underlying layers on the final disconnect.
700 if (lmv->refcount != 0)
703 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
704 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
707 lmv_disconnect_mdc(obd, lmv->tgts[i]);
711 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
713 lprocfs_remove(&lmv_proc_dir);
715 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
716 obd->obd_type->typ_name, obd->obd_name);
722 * This is the case when no real connection is established by
723 * lmv_check_connect().
726 class_export_put(exp);
727 rc = class_disconnect(exp);
728 if (lmv->refcount == 0)
733 static int lmv_fid2path(struct obd_export *exp, int len, void *karg, void *uarg)
735 struct obd_device *obddev = class_exp2obd(exp);
736 struct lmv_obd *lmv = &obddev->u.lmv;
737 struct getinfo_fid2path *gf;
738 struct lmv_tgt_desc *tgt;
739 struct getinfo_fid2path *remote_gf = NULL;
740 int remote_gf_size = 0;
743 gf = (struct getinfo_fid2path *)karg;
744 tgt = lmv_find_target(lmv, &gf->gf_fid);
746 RETURN(PTR_ERR(tgt));
749 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
750 if (rc != 0 && rc != -EREMOTE)
751 GOTO(out_fid2path, rc);
753 /* If remote_gf != NULL, it means just building the
754 * path on the remote MDT, copy this path segement to gf */
755 if (remote_gf != NULL) {
756 struct getinfo_fid2path *ori_gf;
759 ori_gf = (struct getinfo_fid2path *)karg;
760 if (strlen(ori_gf->gf_path) +
761 strlen(gf->gf_path) > ori_gf->gf_pathlen)
762 GOTO(out_fid2path, rc = -EOVERFLOW);
764 ptr = ori_gf->gf_path;
766 memmove(ptr + strlen(gf->gf_path) + 1, ptr,
767 strlen(ori_gf->gf_path));
769 strncpy(ptr, gf->gf_path, strlen(gf->gf_path));
770 ptr += strlen(gf->gf_path);
774 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: "LPU64" ln: %u\n",
775 tgt->ltd_exp->exp_obd->obd_name,
776 gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno,
780 GOTO(out_fid2path, rc);
782 /* sigh, has to go to another MDT to do path building further */
783 if (remote_gf == NULL) {
784 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
785 OBD_ALLOC(remote_gf, remote_gf_size);
786 if (remote_gf == NULL)
787 GOTO(out_fid2path, rc = -ENOMEM);
788 remote_gf->gf_pathlen = PATH_MAX;
791 if (!fid_is_sane(&gf->gf_fid)) {
792 CERROR("%s: invalid FID "DFID": rc = %d\n",
793 tgt->ltd_exp->exp_obd->obd_name,
794 PFID(&gf->gf_fid), -EINVAL);
795 GOTO(out_fid2path, rc = -EINVAL);
798 tgt = lmv_find_target(lmv, &gf->gf_fid);
800 GOTO(out_fid2path, rc = -EINVAL);
802 remote_gf->gf_fid = gf->gf_fid;
803 remote_gf->gf_recno = -1;
804 remote_gf->gf_linkno = -1;
805 memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen);
807 goto repeat_fid2path;
810 if (remote_gf != NULL)
811 OBD_FREE(remote_gf, remote_gf_size);
815 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
816 int len, void *karg, void *uarg)
818 struct obd_device *obddev = class_exp2obd(exp);
819 struct lmv_obd *lmv = &obddev->u.lmv;
823 int count = lmv->desc.ld_tgt_count;
830 case IOC_OBD_STATFS: {
831 struct obd_ioctl_data *data = karg;
832 struct obd_device *mdc_obd;
833 struct obd_statfs stat_buf = {0};
836 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
837 if ((index >= count))
840 if (lmv->tgts[index] == NULL ||
841 lmv->tgts[index]->ltd_active == 0)
844 mdc_obd = class_exp2obd(lmv->tgts[index]->ltd_exp);
849 if (cfs_copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
850 min((int) data->ioc_plen2,
851 (int) sizeof(struct obd_uuid))))
854 rc = obd_statfs(NULL, lmv->tgts[index]->ltd_exp, &stat_buf,
855 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
859 if (cfs_copy_to_user(data->ioc_pbuf1, &stat_buf,
860 min((int) data->ioc_plen1,
861 (int) sizeof(stat_buf))))
865 case OBD_IOC_QUOTACTL: {
866 struct if_quotactl *qctl = karg;
867 struct lmv_tgt_desc *tgt = NULL;
868 struct obd_quotactl *oqctl;
870 if (qctl->qc_valid == QC_MDTIDX) {
871 if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
874 tgt = lmv->tgts[qctl->qc_idx];
875 if (tgt == NULL || tgt->ltd_exp == NULL)
877 } else if (qctl->qc_valid == QC_UUID) {
878 for (i = 0; i < count; i++) {
882 if (!obd_uuid_equals(&tgt->ltd_uuid,
886 if (tgt->ltd_exp == NULL)
898 LASSERT(tgt && tgt->ltd_exp);
899 OBD_ALLOC_PTR(oqctl);
903 QCTL_COPY(oqctl, qctl);
904 rc = obd_quotactl(tgt->ltd_exp, oqctl);
906 QCTL_COPY(qctl, oqctl);
907 qctl->qc_valid = QC_MDTIDX;
908 qctl->obd_uuid = tgt->ltd_uuid;
913 case OBD_IOC_CHANGELOG_SEND:
914 case OBD_IOC_CHANGELOG_CLEAR: {
915 struct ioc_changelog *icc = karg;
917 if (icc->icc_mdtindex >= count)
920 if (lmv->tgts[icc->icc_mdtindex] == NULL ||
921 lmv->tgts[icc->icc_mdtindex]->ltd_exp == NULL ||
922 lmv->tgts[icc->icc_mdtindex]->ltd_active == 0)
924 rc = obd_iocontrol(cmd, lmv->tgts[icc->icc_mdtindex]->ltd_exp,
925 sizeof(*icc), icc, NULL);
928 case LL_IOC_GET_CONNECT_FLAGS: {
929 if (lmv->tgts[0] == NULL)
931 rc = obd_iocontrol(cmd, lmv->tgts[0]->ltd_exp, len, karg, uarg);
934 case OBD_IOC_FID2PATH: {
935 rc = lmv_fid2path(exp, len, karg, uarg);
938 case LL_IOC_HSM_STATE_GET:
939 case LL_IOC_HSM_STATE_SET:
940 case LL_IOC_HSM_ACTION:
941 case LL_IOC_LOV_SWAP_LAYOUTS: {
942 struct md_op_data *op_data = karg;
943 struct lmv_tgt_desc *tgt;
945 tgt = lmv_find_target(lmv, &op_data->op_fid1);
949 rc = obd_iocontrol(cmd, lmv->tgts[0]->ltd_exp, len, karg, uarg);
953 for (i = 0; i < count; i++) {
954 struct obd_device *mdc_obd;
957 if (lmv->tgts[i] == NULL ||
958 lmv->tgts[i]->ltd_exp == NULL)
960 /* ll_umount_begin() sets force flag but for lmv, not
961 * mdc. Let's pass it through */
962 mdc_obd = class_exp2obd(lmv->tgts[i]->ltd_exp);
963 mdc_obd->obd_force = obddev->obd_force;
964 err = obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, len,
966 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
969 if (lmv->tgts[i]->ltd_active) {
970 CERROR("error: iocontrol MDC %s on MDT"
971 "idx %d cmd %x: err = %d\n",
972 lmv->tgts[i]->ltd_uuid.uuid,
987 static int lmv_all_chars_policy(int count, const char *name,
998 static int lmv_nid_policy(struct lmv_obd *lmv)
1000 struct obd_import *imp;
1004 * XXX: To get nid we assume that underlying obd device is mdc.
1006 imp = class_exp2cliimp(lmv->tgts[0].ltd_exp);
1007 id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32);
1008 return id % lmv->desc.ld_tgt_count;
1011 static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1012 placement_policy_t placement)
1014 switch (placement) {
1015 case PLACEMENT_CHAR_POLICY:
1016 return lmv_all_chars_policy(lmv->desc.ld_tgt_count,
1018 op_data->op_namelen);
1019 case PLACEMENT_NID_POLICY:
1020 return lmv_nid_policy(lmv);
1026 CERROR("Unsupported placement policy %x\n", placement);
1032 * This is _inode_ placement policy function (not name).
1034 static int lmv_placement_policy(struct obd_device *obd,
1035 struct md_op_data *op_data,
1038 struct lmv_obd *lmv = &obd->u.lmv;
1041 LASSERT(mds != NULL);
1043 if (lmv->desc.ld_tgt_count == 1) {
1049 * If stripe_offset is provided during setdirstripe
1050 * (setdirstripe -i xx), xx MDS will be choosen.
1052 if (op_data->op_cli_flags & CLI_SET_MEA) {
1053 struct lmv_user_md *lum;
1055 lum = (struct lmv_user_md *)op_data->op_data;
1056 if (lum->lum_type == LMV_STRIPE_TYPE &&
1057 lum->lum_stripe_offset != -1) {
1058 if (lum->lum_stripe_offset >= lmv->desc.ld_tgt_count) {
1059 CERROR("%s: Stripe_offset %d > MDT count %d:"
1060 " rc = %d\n", obd->obd_name,
1061 lum->lum_stripe_offset,
1062 lmv->desc.ld_tgt_count, -ERANGE);
1065 *mds = lum->lum_stripe_offset;
1070 /* Allocate new fid on target according to operation type and parent
1072 *mds = op_data->op_mds;
1076 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
1079 struct lmv_tgt_desc *tgt;
1083 tgt = lmv_get_target(lmv, mds);
1086 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1087 * on server that seq in new allocated fid is not yet known.
1089 mutex_lock(&tgt->ltd_fid_mutex);
1091 if (tgt == NULL || tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1092 GOTO(out, rc = -ENODEV);
1095 * Asking underlaying tgt layer to allocate new fid.
1097 rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL);
1099 LASSERT(fid_is_sane(fid));
1105 mutex_unlock(&tgt->ltd_fid_mutex);
1109 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1110 struct md_op_data *op_data)
1112 struct obd_device *obd = class_exp2obd(exp);
1113 struct lmv_obd *lmv = &obd->u.lmv;
1118 LASSERT(op_data != NULL);
1119 LASSERT(fid != NULL);
1121 rc = lmv_placement_policy(obd, op_data, &mds);
1123 CERROR("Can't get target for allocating fid, "
1128 rc = __lmv_fid_alloc(lmv, fid, mds);
1130 CERROR("Can't alloc new fid, rc %d\n", rc);
1137 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1139 struct lmv_obd *lmv = &obd->u.lmv;
1140 struct lprocfs_static_vars lvars;
1141 struct lmv_desc *desc;
1145 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1146 CERROR("LMV setup requires a descriptor\n");
1150 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1151 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1152 CERROR("Lmv descriptor size wrong: %d > %d\n",
1153 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1157 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * 32);
1158 if (lmv->tgts == NULL)
1160 lmv->tgts_size = 32;
1162 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1163 lmv->desc.ld_tgt_count = 0;
1164 lmv->desc.ld_active_tgt_count = 0;
1165 lmv->max_cookiesize = 0;
1166 lmv->max_def_easize = 0;
1167 lmv->max_easize = 0;
1168 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1170 spin_lock_init(&lmv->lmv_lock);
1171 mutex_init(&lmv->init_mutex);
1173 lprocfs_lmv_init_vars(&lvars);
1175 lprocfs_obd_setup(obd, lvars.obd_vars);
1178 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1179 0444, &lmv_proc_target_fops, obd);
1181 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1185 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1186 LUSTRE_CLI_FLD_HASH_DHT);
1188 CERROR("Can't init FLD, err %d\n", rc);
1198 static int lmv_cleanup(struct obd_device *obd)
1200 struct lmv_obd *lmv = &obd->u.lmv;
1203 fld_client_fini(&lmv->lmv_fld);
1204 if (lmv->tgts != NULL) {
1206 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1207 if (lmv->tgts[i] == NULL)
1209 lmv_del_target(lmv, i);
1211 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1217 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
1219 struct lustre_cfg *lcfg = buf;
1220 struct obd_uuid obd_uuid;
1226 switch (lcfg->lcfg_command) {
1228 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1229 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1230 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1231 GOTO(out, rc = -EINVAL);
1233 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1235 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
1236 GOTO(out, rc = -EINVAL);
1237 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1238 GOTO(out, rc = -EINVAL);
1239 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1242 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1243 GOTO(out, rc = -EINVAL);
1249 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1250 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1252 struct obd_device *obd = class_exp2obd(exp);
1253 struct lmv_obd *lmv = &obd->u.lmv;
1254 struct obd_statfs *temp;
1259 rc = lmv_check_connect(obd);
1263 OBD_ALLOC(temp, sizeof(*temp));
1267 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1268 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1271 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1274 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1275 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1277 GOTO(out_free_temp, rc);
1282 /* If the statfs is from mount, it will needs
1283 * retrieve necessary information from MDT0.
1284 * i.e. mount does not need the merged osfs
1286 * And also clients can be mounted as long as
1287 * MDT0 is in service*/
1288 if (flags & OBD_STATFS_FOR_MDT0)
1289 GOTO(out_free_temp, rc);
1291 osfs->os_bavail += temp->os_bavail;
1292 osfs->os_blocks += temp->os_blocks;
1293 osfs->os_ffree += temp->os_ffree;
1294 osfs->os_files += temp->os_files;
1300 OBD_FREE(temp, sizeof(*temp));
1304 static int lmv_getstatus(struct obd_export *exp,
1306 struct obd_capa **pc)
1308 struct obd_device *obd = exp->exp_obd;
1309 struct lmv_obd *lmv = &obd->u.lmv;
1313 rc = lmv_check_connect(obd);
1317 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
1321 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1322 struct obd_capa *oc, obd_valid valid, const char *name,
1323 const char *input, int input_size, int output_size,
1324 int flags, struct ptlrpc_request **request)
1326 struct obd_device *obd = exp->exp_obd;
1327 struct lmv_obd *lmv = &obd->u.lmv;
1328 struct lmv_tgt_desc *tgt;
1332 rc = lmv_check_connect(obd);
1336 tgt = lmv_find_target(lmv, fid);
1338 RETURN(PTR_ERR(tgt));
1340 rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1341 input_size, output_size, flags, request);
1346 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1347 struct obd_capa *oc, obd_valid valid, const char *name,
1348 const char *input, int input_size, int output_size,
1349 int flags, __u32 suppgid,
1350 struct ptlrpc_request **request)
1352 struct obd_device *obd = exp->exp_obd;
1353 struct lmv_obd *lmv = &obd->u.lmv;
1354 struct lmv_tgt_desc *tgt;
1358 rc = lmv_check_connect(obd);
1362 tgt = lmv_find_target(lmv, fid);
1364 RETURN(PTR_ERR(tgt));
1366 rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1367 input_size, output_size, flags, suppgid,
1373 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1374 struct ptlrpc_request **request)
1376 struct obd_device *obd = exp->exp_obd;
1377 struct lmv_obd *lmv = &obd->u.lmv;
1378 struct lmv_tgt_desc *tgt;
1382 rc = lmv_check_connect(obd);
1386 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1388 RETURN(PTR_ERR(tgt));
1390 if (op_data->op_flags & MF_GET_MDT_IDX) {
1391 op_data->op_mds = tgt->ltd_idx;
1395 rc = md_getattr(tgt->ltd_exp, op_data, request);
1400 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1402 struct obd_device *obd = exp->exp_obd;
1403 struct lmv_obd *lmv = &obd->u.lmv;
1408 rc = lmv_check_connect(obd);
1412 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1415 * With DNE every object can have two locks in different namespaces:
1416 * lookup lock in space of MDT storing direntry and update/open lock in
1417 * space of MDT storing inode.
1419 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1420 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1422 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1428 static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1429 ldlm_iterator_t it, void *data)
1431 struct obd_device *obd = exp->exp_obd;
1432 struct lmv_obd *lmv = &obd->u.lmv;
1437 rc = lmv_check_connect(obd);
1441 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1444 * With DNE every object can have two locks in different namespaces:
1445 * lookup lock in space of MDT storing direntry and update/open lock in
1446 * space of MDT storing inode.
1448 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1449 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1451 rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1460 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1461 struct md_open_data *mod, struct ptlrpc_request **request)
1463 struct obd_device *obd = exp->exp_obd;
1464 struct lmv_obd *lmv = &obd->u.lmv;
1465 struct lmv_tgt_desc *tgt;
1469 rc = lmv_check_connect(obd);
1473 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1475 RETURN(PTR_ERR(tgt));
1477 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1478 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1483 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1486 struct lmv_tgt_desc *tgt;
1488 tgt = lmv_find_target(lmv, fid);
1489 op_data->op_mds = tgt->ltd_idx;
1494 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1495 const void *data, int datalen, int mode, __u32 uid,
1496 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1497 struct ptlrpc_request **request)
1499 struct obd_device *obd = exp->exp_obd;
1500 struct lmv_obd *lmv = &obd->u.lmv;
1501 struct lmv_tgt_desc *tgt;
1505 rc = lmv_check_connect(obd);
1509 if (!lmv->desc.ld_active_tgt_count)
1512 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1514 RETURN(PTR_ERR(tgt));
1516 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1520 CDEBUG(D_INODE, "CREATE '%*s' on "DFID" -> mds #%x\n",
1521 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1524 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1525 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1526 cap_effective, rdev, request);
1529 if (*request == NULL)
1531 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1536 static int lmv_done_writing(struct obd_export *exp,
1537 struct md_op_data *op_data,
1538 struct md_open_data *mod)
1540 struct obd_device *obd = exp->exp_obd;
1541 struct lmv_obd *lmv = &obd->u.lmv;
1542 struct lmv_tgt_desc *tgt;
1546 rc = lmv_check_connect(obd);
1550 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1552 RETURN(PTR_ERR(tgt));
1554 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1559 lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1560 struct lookup_intent *it, struct md_op_data *op_data,
1561 struct lustre_handle *lockh, void *lmm, int lmmsize,
1562 int extra_lock_flags)
1564 struct ptlrpc_request *req = it->d.lustre.it_data;
1565 struct obd_device *obd = exp->exp_obd;
1566 struct lmv_obd *lmv = &obd->u.lmv;
1567 struct lustre_handle plock;
1568 struct lmv_tgt_desc *tgt;
1569 struct md_op_data *rdata;
1571 struct mdt_body *body;
1576 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1577 LASSERT(body != NULL);
1579 if (!(body->valid & OBD_MD_MDS))
1582 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1583 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1586 * We got LOOKUP lock, but we really need attrs.
1588 pmode = it->d.lustre.it_lock_mode;
1589 LASSERT(pmode != 0);
1590 memcpy(&plock, lockh, sizeof(plock));
1591 it->d.lustre.it_lock_mode = 0;
1592 it->d.lustre.it_data = NULL;
1595 it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
1596 ptlrpc_req_finished(req);
1598 tgt = lmv_find_target(lmv, &fid1);
1600 GOTO(out, rc = PTR_ERR(tgt));
1602 OBD_ALLOC_PTR(rdata);
1604 GOTO(out, rc = -ENOMEM);
1606 rdata->op_fid1 = fid1;
1607 rdata->op_bias = MDS_CROSS_REF;
1609 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1610 lmm, lmmsize, NULL, extra_lock_flags);
1611 OBD_FREE_PTR(rdata);
1614 ldlm_lock_decref(&plock, pmode);
1619 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1620 struct lookup_intent *it, struct md_op_data *op_data,
1621 struct lustre_handle *lockh, void *lmm, int lmmsize,
1622 struct ptlrpc_request **req, __u64 extra_lock_flags)
1624 struct obd_device *obd = exp->exp_obd;
1625 struct lmv_obd *lmv = &obd->u.lmv;
1626 struct lmv_tgt_desc *tgt;
1630 rc = lmv_check_connect(obd);
1634 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1635 LL_IT2STR(it), PFID(&op_data->op_fid1));
1637 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1639 RETURN(PTR_ERR(tgt));
1641 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1642 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1644 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1645 lmm, lmmsize, req, extra_lock_flags);
1647 if (rc == 0 && it && it->it_op == IT_OPEN) {
1648 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1649 lmm, lmmsize, extra_lock_flags);
1655 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1656 struct ptlrpc_request **request)
1658 struct ptlrpc_request *req = NULL;
1659 struct obd_device *obd = exp->exp_obd;
1660 struct lmv_obd *lmv = &obd->u.lmv;
1661 struct lmv_tgt_desc *tgt;
1662 struct mdt_body *body;
1666 rc = lmv_check_connect(obd);
1670 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1672 RETURN(PTR_ERR(tgt));
1674 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1675 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1678 rc = md_getattr_name(tgt->ltd_exp, op_data, request);
1682 body = req_capsule_server_get(&(*request)->rq_pill,
1684 LASSERT(body != NULL);
1686 if (body->valid & OBD_MD_MDS) {
1687 struct lu_fid rid = body->fid1;
1688 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1691 tgt = lmv_find_target(lmv, &rid);
1693 ptlrpc_req_finished(*request);
1694 RETURN(PTR_ERR(tgt));
1697 op_data->op_fid1 = rid;
1698 op_data->op_valid |= OBD_MD_FLCROSSREF;
1699 op_data->op_namelen = 0;
1700 op_data->op_name = NULL;
1701 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1702 ptlrpc_req_finished(*request);
1709 #define md_op_data_fid(op_data, fl) \
1710 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1711 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1712 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1713 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1716 static int lmv_early_cancel(struct obd_export *exp, struct md_op_data *op_data,
1717 int op_tgt, ldlm_mode_t mode, int bits, int flag)
1719 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1720 struct obd_device *obd = exp->exp_obd;
1721 struct lmv_obd *lmv = &obd->u.lmv;
1722 struct lmv_tgt_desc *tgt;
1723 ldlm_policy_data_t policy = {{0}};
1727 if (!fid_is_sane(fid))
1730 tgt = lmv_find_target(lmv, fid);
1732 RETURN(PTR_ERR(tgt));
1734 if (tgt->ltd_idx != op_tgt) {
1735 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1736 policy.l_inodebits.bits = bits;
1737 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1738 mode, LCF_ASYNC, NULL);
1741 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1743 op_data->op_flags |= flag;
1751 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1754 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1755 struct ptlrpc_request **request)
1757 struct obd_device *obd = exp->exp_obd;
1758 struct lmv_obd *lmv = &obd->u.lmv;
1759 struct lmv_tgt_desc *tgt;
1763 rc = lmv_check_connect(obd);
1767 LASSERT(op_data->op_namelen != 0);
1769 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1770 PFID(&op_data->op_fid2), op_data->op_namelen,
1771 op_data->op_name, PFID(&op_data->op_fid1));
1773 op_data->op_fsuid = cfs_curproc_fsuid();
1774 op_data->op_fsgid = cfs_curproc_fsgid();
1775 op_data->op_cap = cfs_curproc_cap_pack();
1776 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1778 RETURN(PTR_ERR(tgt));
1781 * Cancel UPDATE lock on child (fid1).
1783 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1784 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
1785 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1789 rc = md_link(tgt->ltd_exp, op_data, request);
1794 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1795 const char *old, int oldlen, const char *new, int newlen,
1796 struct ptlrpc_request **request)
1798 struct obd_device *obd = exp->exp_obd;
1799 struct lmv_obd *lmv = &obd->u.lmv;
1800 struct lmv_tgt_desc *src_tgt;
1801 struct lmv_tgt_desc *tgt_tgt;
1805 LASSERT(oldlen != 0);
1807 CDEBUG(D_INODE, "RENAME %*s in "DFID" to %*s in "DFID"\n",
1808 oldlen, old, PFID(&op_data->op_fid1),
1809 newlen, new, PFID(&op_data->op_fid2));
1811 rc = lmv_check_connect(obd);
1815 op_data->op_fsuid = cfs_curproc_fsuid();
1816 op_data->op_fsgid = cfs_curproc_fsgid();
1817 op_data->op_cap = cfs_curproc_cap_pack();
1818 src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1819 if (IS_ERR(src_tgt))
1820 RETURN(PTR_ERR(src_tgt));
1822 tgt_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1823 if (IS_ERR(tgt_tgt))
1824 RETURN(PTR_ERR(tgt_tgt));
1826 * LOOKUP lock on src child (fid3) should also be cancelled for
1827 * src_tgt in mdc_rename.
1829 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
1832 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
1835 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1836 LCK_EX, MDS_INODELOCK_UPDATE,
1837 MF_MDC_CANCEL_FID2);
1840 * Cancel LOOKUP locks on tgt child (fid4) for parent tgt_tgt.
1843 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1844 LCK_EX, MDS_INODELOCK_LOOKUP,
1845 MF_MDC_CANCEL_FID4);
1849 * Cancel all the locks on tgt child (fid4).
1852 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1853 LCK_EX, MDS_INODELOCK_FULL,
1854 MF_MDC_CANCEL_FID4);
1857 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen,
1858 new, newlen, request);
1862 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
1863 void *ea, int ealen, void *ea2, int ea2len,
1864 struct ptlrpc_request **request,
1865 struct md_open_data **mod)
1867 struct obd_device *obd = exp->exp_obd;
1868 struct lmv_obd *lmv = &obd->u.lmv;
1869 struct lmv_tgt_desc *tgt;
1873 rc = lmv_check_connect(obd);
1877 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
1878 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
1880 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1881 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1883 RETURN(PTR_ERR(tgt));
1885 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
1886 ea2len, request, mod);
1891 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
1892 struct obd_capa *oc, struct ptlrpc_request **request)
1894 struct obd_device *obd = exp->exp_obd;
1895 struct lmv_obd *lmv = &obd->u.lmv;
1896 struct lmv_tgt_desc *tgt;
1900 rc = lmv_check_connect(obd);
1904 tgt = lmv_find_target(lmv, fid);
1906 RETURN(PTR_ERR(tgt));
1908 rc = md_sync(tgt->ltd_exp, fid, oc, request);
1912 static int lmv_readpage(struct obd_export *exp, struct md_op_data *op_data,
1913 struct page **pages, struct ptlrpc_request **request)
1915 struct obd_device *obd = exp->exp_obd;
1916 struct lmv_obd *lmv = &obd->u.lmv;
1917 __u64 offset = op_data->op_offset;
1920 /* number of pages read, in CFS_PAGE_SIZE */
1922 /* number of pages transferred in LU_PAGE_SIZE */
1924 struct lmv_tgt_desc *tgt;
1925 struct lu_dirpage *dp;
1926 struct lu_dirent *ent;
1929 rc = lmv_check_connect(obd);
1933 CDEBUG(D_INODE, "READPAGE at "LPX64" from "DFID"\n",
1934 offset, PFID(&op_data->op_fid1));
1937 * This case handle directory lookup in clustered metadata case (i.e.
1938 * split directory is located on multiple md servers.)
1939 * each server keeps directory entries for certain range of hashes.
1940 * E.g. we have N server and suppose hash range is 0 to MAX_HASH.
1941 * first server will keep records with hashes [ 0 ... MAX_HASH /N - 1],
1942 * second one with hashes [MAX_HASH / N ... 2 * MAX_HASH / N] and
1944 * readdir can simply start reading entries from 0 - N server in
1945 * order but that will not scale well as all client will request dir in
1946 * to server in same order.
1947 * Following algorithm does optimization:
1948 * Instead of doing readdir in 1, 2, ...., N order, client with a
1949 * rank R does readdir in R, R + 1, ..., N, 1, ... R - 1 order.
1950 * (every client has rank R)
1951 * But ll_readdir() expect offset range [0 to MAX_HASH/N) but
1952 * since client ask dir from MDS{R} client has pages with offsets
1953 * [R*MAX_HASH/N ... (R + 1)*MAX_HASH/N] there for we do hash_adj
1954 * on hash values that we get.
1955 * Since these codes might be still useful for sharded directory, so
1956 * Keeping this code for further reference
1959 seg_size = MAX_HASH_SIZE;
1960 do_div(seg_size, nr);
1961 los = obj->lo_stripes;
1962 tgt = lmv_get_target(lmv, los[0].ls_mds);
1963 rank = lmv_node_rank(tgt->ltd_exp, fid) % nr;
1965 do_div(tgt_tmp, seg_size);
1966 tgt0_idx = do_div(tgt_tmp, nr);
1967 tgt_idx = (tgt0_idx + rank) % nr;
1969 if (tgt_idx < tgt0_idx)
1972 * Last segment has unusual length due to division
1974 hash_adj = MAX_HASH_SIZE - seg_size * nr;
1978 hash_adj += rank * seg_size;
1980 CDEBUG(D_INODE, "Readpage hash adjustment: %x "LPX64" "
1981 LPX64"/%x -> "LPX64"/%x\n", rank, hash_adj,
1982 offset, tgt0_idx, offset + hash_adj, tgt_idx);
1984 offset = (offset + hash_adj) & MAX_HASH_SIZE;
1985 rid = lsm->mea_oinfo[tgt_idx].lmo_fid;
1986 tgt = lmv_get_target(lmv, lsm->mea_oinfo[tgt_idx].lmo_mds);
1988 CDEBUG(D_INODE, "Forward to "DFID" with offset %lu i %d\n",
1989 PFID(&rid), (unsigned long)offset, tgt_idx);
1992 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1994 RETURN(PTR_ERR(tgt));
1996 rc = md_readpage(tgt->ltd_exp, op_data, pages, request);
2000 nrdpgs = ((*request)->rq_bulk->bd_nob_transferred + CFS_PAGE_SIZE - 1)
2002 nlupgs = (*request)->rq_bulk->bd_nob_transferred >> LU_PAGE_SHIFT;
2003 LASSERT(!((*request)->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK));
2004 LASSERT(nrdpgs > 0 && nrdpgs <= op_data->op_npages);
2006 CDEBUG(D_INODE, "read %d(%d)/%d pages\n", nrdpgs, nlupgs,
2007 op_data->op_npages);
2009 for (i = 0; i < nrdpgs; i++) {
2010 #if CFS_PAGE_SIZE > LU_PAGE_SIZE
2011 struct lu_dirpage *first;
2015 struct lu_dirent *tmp = NULL;
2017 dp = cfs_kmap(pages[i]);
2018 ent = lu_dirent_start(dp);
2019 #if CFS_PAGE_SIZE > LU_PAGE_SIZE
2021 hash_end = dp->ldp_hash_end;
2026 for (tmp = ent; ent != NULL;
2027 tmp = ent, ent = lu_dirent_next(ent));
2028 #if CFS_PAGE_SIZE > LU_PAGE_SIZE
2029 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
2030 if (((unsigned long)dp & ~CFS_PAGE_MASK) && nlupgs > 0) {
2031 ent = lu_dirent_start(dp);
2034 /* enlarge the end entry lde_reclen from 0 to
2035 * first entry of next lu_dirpage, in this way
2036 * several lu_dirpages can be stored into one
2037 * client page on client. */
2038 tmp = ((void *)tmp) +
2039 le16_to_cpu(tmp->lde_reclen);
2041 cpu_to_le16((char *)(dp->ldp_entries) -
2046 first->ldp_hash_end = hash_end;
2047 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
2048 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
2050 SET_BUT_UNUSED(tmp);
2052 cfs_kunmap(pages[i]);
2057 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2058 struct ptlrpc_request **request)
2060 struct obd_device *obd = exp->exp_obd;
2061 struct lmv_obd *lmv = &obd->u.lmv;
2062 struct lmv_tgt_desc *tgt = NULL;
2063 struct mdt_body *body;
2067 rc = lmv_check_connect(obd);
2071 /* Send unlink requests to the MDT where the child is located */
2072 if (likely(!fid_is_zero(&op_data->op_fid2)))
2073 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2075 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2077 RETURN(PTR_ERR(tgt));
2079 op_data->op_fsuid = cfs_curproc_fsuid();
2080 op_data->op_fsgid = cfs_curproc_fsgid();
2081 op_data->op_cap = cfs_curproc_cap_pack();
2084 * If child's fid is given, cancel unused locks for it if it is from
2085 * another export than parent.
2087 * LOOKUP lock for child (fid3) should also be cancelled on parent
2088 * tgt_tgt in mdc_unlink().
2090 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2093 * Cancel FULL locks on child (fid3).
2095 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
2096 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2101 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n",
2102 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2104 rc = md_unlink(tgt->ltd_exp, op_data, request);
2105 if (rc != 0 && rc != -EREMOTE)
2108 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2112 /* Not cross-ref case, just get out of here. */
2113 if (likely(!(body->valid & OBD_MD_MDS)))
2116 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2117 exp->exp_obd->obd_name, PFID(&body->fid1));
2119 /* This is a remote object, try remote MDT, Note: it may
2120 * try more than 1 time here, Considering following case
2121 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2122 * 1. Initially A does not know where remote1 is, it send
2123 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2124 * resend unlink RPC to MDT1 (retry 1st time).
2126 * 2. During the unlink RPC in flight,
2127 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2128 * and create new remote1, but on MDT0
2130 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2131 * /mnt/lustre, then lookup get fid of remote1, and find
2132 * it is remote dir again, and replay -EREMOTE again.
2134 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2136 * In theory, it might try unlimited time here, but it should
2137 * be very rare case. */
2138 op_data->op_fid2 = body->fid1;
2139 ptlrpc_req_finished(*request);
2145 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2147 struct lmv_obd *lmv = &obd->u.lmv;
2151 case OBD_CLEANUP_EARLY:
2152 /* XXX: here should be calling obd_precleanup() down to
2155 case OBD_CLEANUP_EXPORTS:
2156 fld_client_proc_fini(&lmv->lmv_fld);
2157 lprocfs_obd_cleanup(obd);
2165 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2166 __u32 keylen, void *key, __u32 *vallen, void *val,
2167 struct lov_stripe_md *lsm)
2169 struct obd_device *obd;
2170 struct lmv_obd *lmv;
2174 obd = class_exp2obd(exp);
2176 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2177 exp->exp_handle.h_cookie);
2182 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2183 struct lmv_tgt_desc *tgt;
2186 rc = lmv_check_connect(obd);
2190 LASSERT(*vallen == sizeof(__u32));
2191 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2194 * All tgts should be connected when this gets called.
2196 if (tgt == NULL || tgt->ltd_exp == NULL)
2199 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2204 } else if (KEY_IS(KEY_MAX_EASIZE) || KEY_IS(KEY_CONN_DATA)) {
2205 rc = lmv_check_connect(obd);
2210 * Forwarding this request to first MDS, it should know LOV
2213 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2215 if (!rc && KEY_IS(KEY_CONN_DATA))
2216 exp->exp_connect_data = *(struct obd_connect_data *)val;
2218 } else if (KEY_IS(KEY_TGT_COUNT)) {
2219 *((int *)val) = lmv->desc.ld_tgt_count;
2223 CDEBUG(D_IOCTL, "Invalid key\n");
2227 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2228 obd_count keylen, void *key, obd_count vallen,
2229 void *val, struct ptlrpc_request_set *set)
2231 struct lmv_tgt_desc *tgt;
2232 struct obd_device *obd;
2233 struct lmv_obd *lmv;
2237 obd = class_exp2obd(exp);
2239 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2240 exp->exp_handle.h_cookie);
2245 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) {
2248 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2251 if (tgt == NULL || tgt->ltd_exp == NULL)
2254 err = obd_set_info_async(env, tgt->ltd_exp,
2255 keylen, key, vallen, val, set);
2266 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2267 struct lov_stripe_md *lsm)
2269 struct obd_device *obd = class_exp2obd(exp);
2270 struct lmv_obd *lmv = &obd->u.lmv;
2271 struct lmv_stripe_md *meap;
2272 struct lmv_stripe_md *lsmp;
2277 mea_size = lmv_get_easize(lmv);
2281 if (*lmmp && !lsm) {
2282 OBD_FREE_LARGE(*lmmp, mea_size);
2287 if (*lmmp == NULL) {
2288 OBD_ALLOC_LARGE(*lmmp, mea_size);
2296 lsmp = (struct lmv_stripe_md *)lsm;
2297 meap = (struct lmv_stripe_md *)*lmmp;
2299 if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR &&
2300 lsmp->mea_magic != MEA_MAGIC_ALL_CHARS)
2303 meap->mea_magic = cpu_to_le32(lsmp->mea_magic);
2304 meap->mea_count = cpu_to_le32(lsmp->mea_count);
2305 meap->mea_master = cpu_to_le32(lsmp->mea_master);
2307 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2308 meap->mea_ids[i] = meap->mea_ids[i];
2309 fid_cpu_to_le(&meap->mea_ids[i], &meap->mea_ids[i]);
2315 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2316 struct lov_mds_md *lmm, int lmm_size)
2318 struct obd_device *obd = class_exp2obd(exp);
2319 struct lmv_stripe_md **tmea = (struct lmv_stripe_md **)lsmp;
2320 struct lmv_stripe_md *mea = (struct lmv_stripe_md *)lmm;
2321 struct lmv_obd *lmv = &obd->u.lmv;
2327 mea_size = lmv_get_easize(lmv);
2331 if (*lsmp != NULL && lmm == NULL) {
2332 OBD_FREE_LARGE(*tmea, mea_size);
2337 LASSERT(mea_size == lmm_size);
2339 OBD_ALLOC_LARGE(*tmea, mea_size);
2346 if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
2347 mea->mea_magic == MEA_MAGIC_ALL_CHARS ||
2348 mea->mea_magic == MEA_MAGIC_HASH_SEGMENT)
2350 magic = le32_to_cpu(mea->mea_magic);
2353 * Old mea is not handled here.
2355 CERROR("Old not supportable EA is found\n");
2359 (*tmea)->mea_magic = magic;
2360 (*tmea)->mea_count = le32_to_cpu(mea->mea_count);
2361 (*tmea)->mea_master = le32_to_cpu(mea->mea_master);
2363 for (i = 0; i < (*tmea)->mea_count; i++) {
2364 (*tmea)->mea_ids[i] = mea->mea_ids[i];
2365 fid_le_to_cpu(&(*tmea)->mea_ids[i], &(*tmea)->mea_ids[i]);
2370 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2371 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2372 ldlm_cancel_flags_t flags, void *opaque)
2374 struct obd_device *obd = exp->exp_obd;
2375 struct lmv_obd *lmv = &obd->u.lmv;
2381 LASSERT(fid != NULL);
2383 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2384 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL ||
2385 lmv->tgts[i]->ltd_active == 0)
2388 err = md_cancel_unused(lmv->tgts[i]->ltd_exp, fid,
2389 policy, mode, flags, opaque);
2396 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
2399 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2403 rc = md_set_lock_data(lmv->tgts[0]->ltd_exp, lockh, data, bits);
2407 ldlm_mode_t lmv_lock_match(struct obd_export *exp, __u64 flags,
2408 const struct lu_fid *fid, ldlm_type_t type,
2409 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2410 struct lustre_handle *lockh)
2412 struct obd_device *obd = exp->exp_obd;
2413 struct lmv_obd *lmv = &obd->u.lmv;
2418 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2421 * With CMD every object can have two locks in different namespaces:
2422 * lookup lock in space of mds storing direntry and update/open lock in
2423 * space of mds storing inode. Thus we check all targets, not only that
2424 * one fid was created in.
2426 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2427 if (lmv->tgts[i] == NULL ||
2428 lmv->tgts[i]->ltd_exp == NULL ||
2429 lmv->tgts[i]->ltd_active == 0)
2432 rc = md_lock_match(lmv->tgts[i]->ltd_exp, flags, fid,
2433 type, policy, mode, lockh);
2441 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2442 struct obd_export *dt_exp, struct obd_export *md_exp,
2443 struct lustre_md *md)
2445 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2447 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
2450 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2452 struct obd_device *obd = exp->exp_obd;
2453 struct lmv_obd *lmv = &obd->u.lmv;
2457 obd_free_memmd(exp, (void *)&md->mea);
2458 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
2461 int lmv_set_open_replay_data(struct obd_export *exp,
2462 struct obd_client_handle *och,
2463 struct ptlrpc_request *open_req)
2465 struct obd_device *obd = exp->exp_obd;
2466 struct lmv_obd *lmv = &obd->u.lmv;
2467 struct lmv_tgt_desc *tgt;
2470 tgt = lmv_find_target(lmv, &och->och_fid);
2472 RETURN(PTR_ERR(tgt));
2474 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, open_req));
2477 int lmv_clear_open_replay_data(struct obd_export *exp,
2478 struct obd_client_handle *och)
2480 struct obd_device *obd = exp->exp_obd;
2481 struct lmv_obd *lmv = &obd->u.lmv;
2482 struct lmv_tgt_desc *tgt;
2485 tgt = lmv_find_target(lmv, &och->och_fid);
2487 RETURN(PTR_ERR(tgt));
2489 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
2492 static int lmv_get_remote_perm(struct obd_export *exp,
2493 const struct lu_fid *fid,
2494 struct obd_capa *oc, __u32 suppgid,
2495 struct ptlrpc_request **request)
2497 struct obd_device *obd = exp->exp_obd;
2498 struct lmv_obd *lmv = &obd->u.lmv;
2499 struct lmv_tgt_desc *tgt;
2503 rc = lmv_check_connect(obd);
2507 tgt = lmv_find_target(lmv, fid);
2509 RETURN(PTR_ERR(tgt));
2511 rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
2515 static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
2518 struct obd_device *obd = exp->exp_obd;
2519 struct lmv_obd *lmv = &obd->u.lmv;
2520 struct lmv_tgt_desc *tgt;
2524 rc = lmv_check_connect(obd);
2528 tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
2530 RETURN(PTR_ERR(tgt));
2532 rc = md_renew_capa(tgt->ltd_exp, oc, cb);
2536 int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
2537 const struct req_msg_field *field, struct obd_capa **oc)
2539 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2541 return md_unpack_capa(lmv->tgts[0]->ltd_exp, req, field, oc);
2544 int lmv_intent_getattr_async(struct obd_export *exp,
2545 struct md_enqueue_info *minfo,
2546 struct ldlm_enqueue_info *einfo)
2548 struct md_op_data *op_data = &minfo->mi_data;
2549 struct obd_device *obd = exp->exp_obd;
2550 struct lmv_obd *lmv = &obd->u.lmv;
2551 struct lmv_tgt_desc *tgt = NULL;
2555 rc = lmv_check_connect(obd);
2559 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2561 RETURN(PTR_ERR(tgt));
2563 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
2567 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
2568 struct lu_fid *fid, __u64 *bits)
2570 struct obd_device *obd = exp->exp_obd;
2571 struct lmv_obd *lmv = &obd->u.lmv;
2572 struct lmv_tgt_desc *tgt;
2576 rc = lmv_check_connect(obd);
2580 tgt = lmv_find_target(lmv, fid);
2582 RETURN(PTR_ERR(tgt));
2584 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
2589 * For lmv, only need to send request to master MDT, and the master MDT will
2590 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
2591 * we directly fetch data from the slave MDTs.
2593 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
2594 struct obd_quotactl *oqctl)
2596 struct obd_device *obd = class_exp2obd(exp);
2597 struct lmv_obd *lmv = &obd->u.lmv;
2598 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2600 __u64 curspace, curinodes;
2603 if (!lmv->desc.ld_tgt_count || !tgt->ltd_active) {
2604 CERROR("master lmv inactive\n");
2608 if (oqctl->qc_cmd != Q_GETOQUOTA) {
2609 rc = obd_quotactl(tgt->ltd_exp, oqctl);
2613 curspace = curinodes = 0;
2614 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2618 if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0)
2620 if (!tgt->ltd_active) {
2621 CDEBUG(D_HA, "mdt %d is inactive.\n", i);
2625 err = obd_quotactl(tgt->ltd_exp, oqctl);
2627 CERROR("getquota on mdt %d failed. %d\n", i, err);
2631 curspace += oqctl->qc_dqblk.dqb_curspace;
2632 curinodes += oqctl->qc_dqblk.dqb_curinodes;
2635 oqctl->qc_dqblk.dqb_curspace = curspace;
2636 oqctl->qc_dqblk.dqb_curinodes = curinodes;
2641 int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
2642 struct obd_quotactl *oqctl)
2644 struct obd_device *obd = class_exp2obd(exp);
2645 struct lmv_obd *lmv = &obd->u.lmv;
2646 struct lmv_tgt_desc *tgt;
2650 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2653 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
2654 CERROR("lmv idx %d inactive\n", i);
2658 err = obd_quotacheck(tgt->ltd_exp, oqctl);
2666 struct obd_ops lmv_obd_ops = {
2667 .o_owner = THIS_MODULE,
2668 .o_setup = lmv_setup,
2669 .o_cleanup = lmv_cleanup,
2670 .o_precleanup = lmv_precleanup,
2671 .o_process_config = lmv_process_config,
2672 .o_connect = lmv_connect,
2673 .o_disconnect = lmv_disconnect,
2674 .o_statfs = lmv_statfs,
2675 .o_get_info = lmv_get_info,
2676 .o_set_info_async = lmv_set_info_async,
2677 .o_packmd = lmv_packmd,
2678 .o_unpackmd = lmv_unpackmd,
2679 .o_notify = lmv_notify,
2680 .o_get_uuid = lmv_get_uuid,
2681 .o_iocontrol = lmv_iocontrol,
2682 .o_quotacheck = lmv_quotacheck,
2683 .o_quotactl = lmv_quotactl
2686 struct md_ops lmv_md_ops = {
2687 .m_getstatus = lmv_getstatus,
2688 .m_null_inode = lmv_null_inode,
2689 .m_find_cbdata = lmv_find_cbdata,
2690 .m_close = lmv_close,
2691 .m_create = lmv_create,
2692 .m_done_writing = lmv_done_writing,
2693 .m_enqueue = lmv_enqueue,
2694 .m_getattr = lmv_getattr,
2695 .m_getxattr = lmv_getxattr,
2696 .m_getattr_name = lmv_getattr_name,
2697 .m_intent_lock = lmv_intent_lock,
2699 .m_rename = lmv_rename,
2700 .m_setattr = lmv_setattr,
2701 .m_setxattr = lmv_setxattr,
2703 .m_readpage = lmv_readpage,
2704 .m_unlink = lmv_unlink,
2705 .m_init_ea_size = lmv_init_ea_size,
2706 .m_cancel_unused = lmv_cancel_unused,
2707 .m_set_lock_data = lmv_set_lock_data,
2708 .m_lock_match = lmv_lock_match,
2709 .m_get_lustre_md = lmv_get_lustre_md,
2710 .m_free_lustre_md = lmv_free_lustre_md,
2711 .m_set_open_replay_data = lmv_set_open_replay_data,
2712 .m_clear_open_replay_data = lmv_clear_open_replay_data,
2713 .m_renew_capa = lmv_renew_capa,
2714 .m_unpack_capa = lmv_unpack_capa,
2715 .m_get_remote_perm = lmv_get_remote_perm,
2716 .m_intent_getattr_async = lmv_intent_getattr_async,
2717 .m_revalidate_lock = lmv_revalidate_lock
2720 int __init lmv_init(void)
2722 struct lprocfs_static_vars lvars;
2725 lprocfs_lmv_init_vars(&lvars);
2727 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
2728 lvars.module_vars, LUSTRE_LMV_NAME, NULL);
2733 static void lmv_exit(void)
2735 class_unregister_type(LUSTRE_LMV_NAME);
2738 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2739 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
2740 MODULE_LICENSE("GPL");
2742 module_init(lmv_init);
2743 module_exit(lmv_exit);