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_iocontrol(unsigned int cmd, struct obd_export *exp,
734 int len, void *karg, void *uarg)
736 struct obd_device *obddev = class_exp2obd(exp);
737 struct lmv_obd *lmv = &obddev->u.lmv;
741 int count = lmv->desc.ld_tgt_count;
748 case IOC_OBD_STATFS: {
749 struct obd_ioctl_data *data = karg;
750 struct obd_device *mdc_obd;
751 struct obd_statfs stat_buf = {0};
754 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
755 if ((index >= count))
758 if (lmv->tgts[index] == NULL ||
759 lmv->tgts[index]->ltd_active == 0)
762 mdc_obd = class_exp2obd(lmv->tgts[index]->ltd_exp);
767 if (cfs_copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
768 min((int) data->ioc_plen2,
769 (int) sizeof(struct obd_uuid))))
772 rc = obd_statfs(NULL, lmv->tgts[index]->ltd_exp, &stat_buf,
773 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
777 if (cfs_copy_to_user(data->ioc_pbuf1, &stat_buf,
778 min((int) data->ioc_plen1,
779 (int) sizeof(stat_buf))))
783 case OBD_IOC_QUOTACTL: {
784 struct if_quotactl *qctl = karg;
785 struct lmv_tgt_desc *tgt = NULL;
786 struct obd_quotactl *oqctl;
788 if (qctl->qc_valid == QC_MDTIDX) {
789 if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
792 tgt = lmv->tgts[qctl->qc_idx];
793 if (tgt == NULL || tgt->ltd_exp == NULL)
795 } else if (qctl->qc_valid == QC_UUID) {
796 for (i = 0; i < count; i++) {
800 if (!obd_uuid_equals(&tgt->ltd_uuid,
804 if (tgt->ltd_exp == NULL)
816 LASSERT(tgt && tgt->ltd_exp);
817 OBD_ALLOC_PTR(oqctl);
821 QCTL_COPY(oqctl, qctl);
822 rc = obd_quotactl(tgt->ltd_exp, oqctl);
824 QCTL_COPY(qctl, oqctl);
825 qctl->qc_valid = QC_MDTIDX;
826 qctl->obd_uuid = tgt->ltd_uuid;
831 case OBD_IOC_CHANGELOG_SEND:
832 case OBD_IOC_CHANGELOG_CLEAR: {
833 struct ioc_changelog *icc = karg;
835 if (icc->icc_mdtindex >= count)
838 if (lmv->tgts[icc->icc_mdtindex] == NULL ||
839 lmv->tgts[icc->icc_mdtindex]->ltd_exp == NULL ||
840 lmv->tgts[icc->icc_mdtindex]->ltd_active == 0)
842 rc = obd_iocontrol(cmd, lmv->tgts[icc->icc_mdtindex]->ltd_exp,
843 sizeof(*icc), icc, NULL);
846 case LL_IOC_GET_CONNECT_FLAGS: {
847 if (lmv->tgts[0] == NULL)
849 rc = obd_iocontrol(cmd, lmv->tgts[0]->ltd_exp, len, karg, uarg);
852 case OBD_IOC_FID2PATH: {
853 struct getinfo_fid2path *gf;
854 struct lmv_tgt_desc *tgt;
856 gf = (struct getinfo_fid2path *)karg;
857 tgt = lmv_find_target(lmv, &gf->gf_fid);
859 RETURN(PTR_ERR(tgt));
860 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
863 case LL_IOC_HSM_STATE_GET:
864 case LL_IOC_HSM_STATE_SET:
865 case LL_IOC_HSM_ACTION:
866 case LL_IOC_LOV_SWAP_LAYOUTS: {
867 struct md_op_data *op_data = karg;
868 struct lmv_tgt_desc *tgt;
870 tgt = lmv_find_target(lmv, &op_data->op_fid1);
874 rc = obd_iocontrol(cmd, lmv->tgts[0]->ltd_exp, len, karg, uarg);
878 for (i = 0; i < count; i++) {
879 struct obd_device *mdc_obd;
882 if (lmv->tgts[i] == NULL ||
883 lmv->tgts[i]->ltd_exp == NULL)
885 /* ll_umount_begin() sets force flag but for lmv, not
886 * mdc. Let's pass it through */
887 mdc_obd = class_exp2obd(lmv->tgts[i]->ltd_exp);
888 mdc_obd->obd_force = obddev->obd_force;
889 err = obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, len,
891 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
894 if (lmv->tgts[i]->ltd_active) {
895 CERROR("error: iocontrol MDC %s on MDT"
896 "idx %d cmd %x: err = %d\n",
897 lmv->tgts[i]->ltd_uuid.uuid,
912 static int lmv_all_chars_policy(int count, const char *name,
923 static int lmv_nid_policy(struct lmv_obd *lmv)
925 struct obd_import *imp;
929 * XXX: To get nid we assume that underlying obd device is mdc.
931 imp = class_exp2cliimp(lmv->tgts[0].ltd_exp);
932 id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32);
933 return id % lmv->desc.ld_tgt_count;
936 static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
937 placement_policy_t placement)
940 case PLACEMENT_CHAR_POLICY:
941 return lmv_all_chars_policy(lmv->desc.ld_tgt_count,
943 op_data->op_namelen);
944 case PLACEMENT_NID_POLICY:
945 return lmv_nid_policy(lmv);
951 CERROR("Unsupported placement policy %x\n", placement);
957 * This is _inode_ placement policy function (not name).
959 static int lmv_placement_policy(struct obd_device *obd,
960 struct md_op_data *op_data,
963 struct lmv_obd *lmv = &obd->u.lmv;
966 LASSERT(mds != NULL);
968 if (lmv->desc.ld_tgt_count == 1) {
974 * If stripe_offset is provided during setdirstripe
975 * (setdirstripe -i xx), xx MDS will be choosen.
977 if (op_data->op_cli_flags & CLI_SET_MEA) {
978 struct lmv_user_md *lum;
980 lum = (struct lmv_user_md *)op_data->op_data;
981 if (lum->lum_type == LMV_STRIPE_TYPE &&
982 lum->lum_stripe_offset != -1) {
983 if (lum->lum_stripe_offset >= lmv->desc.ld_tgt_count) {
984 CERROR("%s: Stripe_offset %d > MDT count %d:"
985 " rc = %d\n", obd->obd_name,
986 lum->lum_stripe_offset,
987 lmv->desc.ld_tgt_count, -ERANGE);
990 *mds = lum->lum_stripe_offset;
995 /* Allocate new fid on target according to operation type and parent
997 *mds = op_data->op_mds;
1001 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
1004 struct lmv_tgt_desc *tgt;
1008 tgt = lmv_get_target(lmv, mds);
1011 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1012 * on server that seq in new allocated fid is not yet known.
1014 mutex_lock(&tgt->ltd_fid_mutex);
1016 if (tgt == NULL || tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1017 GOTO(out, rc = -ENODEV);
1020 * Asking underlaying tgt layer to allocate new fid.
1022 rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL);
1024 LASSERT(fid_is_sane(fid));
1030 mutex_unlock(&tgt->ltd_fid_mutex);
1034 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1035 struct md_op_data *op_data)
1037 struct obd_device *obd = class_exp2obd(exp);
1038 struct lmv_obd *lmv = &obd->u.lmv;
1043 LASSERT(op_data != NULL);
1044 LASSERT(fid != NULL);
1046 rc = lmv_placement_policy(obd, op_data, &mds);
1048 CERROR("Can't get target for allocating fid, "
1053 rc = __lmv_fid_alloc(lmv, fid, mds);
1055 CERROR("Can't alloc new fid, rc %d\n", rc);
1062 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1064 struct lmv_obd *lmv = &obd->u.lmv;
1065 struct lprocfs_static_vars lvars;
1066 struct lmv_desc *desc;
1070 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1071 CERROR("LMV setup requires a descriptor\n");
1075 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1076 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1077 CERROR("Lmv descriptor size wrong: %d > %d\n",
1078 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1082 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * 32);
1083 if (lmv->tgts == NULL)
1085 lmv->tgts_size = 32;
1087 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1088 lmv->desc.ld_tgt_count = 0;
1089 lmv->desc.ld_active_tgt_count = 0;
1090 lmv->max_cookiesize = 0;
1091 lmv->max_def_easize = 0;
1092 lmv->max_easize = 0;
1093 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1095 spin_lock_init(&lmv->lmv_lock);
1096 mutex_init(&lmv->init_mutex);
1098 lprocfs_lmv_init_vars(&lvars);
1100 lprocfs_obd_setup(obd, lvars.obd_vars);
1103 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1104 0444, &lmv_proc_target_fops, obd);
1106 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1110 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1111 LUSTRE_CLI_FLD_HASH_DHT);
1113 CERROR("Can't init FLD, err %d\n", rc);
1123 static int lmv_cleanup(struct obd_device *obd)
1125 struct lmv_obd *lmv = &obd->u.lmv;
1128 fld_client_fini(&lmv->lmv_fld);
1129 if (lmv->tgts != NULL) {
1131 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1132 if (lmv->tgts[i] == NULL)
1134 lmv_del_target(lmv, i);
1136 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1142 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
1144 struct lustre_cfg *lcfg = buf;
1145 struct obd_uuid obd_uuid;
1151 switch (lcfg->lcfg_command) {
1153 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1154 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1155 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1156 GOTO(out, rc = -EINVAL);
1158 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1160 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
1161 GOTO(out, rc = -EINVAL);
1162 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1163 GOTO(out, rc = -EINVAL);
1164 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1167 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1168 GOTO(out, rc = -EINVAL);
1174 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1175 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1177 struct obd_device *obd = class_exp2obd(exp);
1178 struct lmv_obd *lmv = &obd->u.lmv;
1179 struct obd_statfs *temp;
1184 rc = lmv_check_connect(obd);
1188 OBD_ALLOC(temp, sizeof(*temp));
1192 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1193 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1196 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1199 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1200 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1202 GOTO(out_free_temp, rc);
1207 /* If the statfs is from mount, it will needs
1208 * retrieve necessary information from MDT0.
1209 * i.e. mount does not need the merged osfs
1211 * And also clients can be mounted as long as
1212 * MDT0 is in service*/
1213 if (flags & OBD_STATFS_FOR_MDT0)
1214 GOTO(out_free_temp, rc);
1216 osfs->os_bavail += temp->os_bavail;
1217 osfs->os_blocks += temp->os_blocks;
1218 osfs->os_ffree += temp->os_ffree;
1219 osfs->os_files += temp->os_files;
1225 OBD_FREE(temp, sizeof(*temp));
1229 static int lmv_getstatus(struct obd_export *exp,
1231 struct obd_capa **pc)
1233 struct obd_device *obd = exp->exp_obd;
1234 struct lmv_obd *lmv = &obd->u.lmv;
1238 rc = lmv_check_connect(obd);
1242 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
1246 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1247 struct obd_capa *oc, obd_valid valid, const char *name,
1248 const char *input, int input_size, int output_size,
1249 int flags, struct ptlrpc_request **request)
1251 struct obd_device *obd = exp->exp_obd;
1252 struct lmv_obd *lmv = &obd->u.lmv;
1253 struct lmv_tgt_desc *tgt;
1257 rc = lmv_check_connect(obd);
1261 tgt = lmv_find_target(lmv, fid);
1263 RETURN(PTR_ERR(tgt));
1265 rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1266 input_size, output_size, flags, request);
1271 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1272 struct obd_capa *oc, obd_valid valid, const char *name,
1273 const char *input, int input_size, int output_size,
1274 int flags, __u32 suppgid,
1275 struct ptlrpc_request **request)
1277 struct obd_device *obd = exp->exp_obd;
1278 struct lmv_obd *lmv = &obd->u.lmv;
1279 struct lmv_tgt_desc *tgt;
1283 rc = lmv_check_connect(obd);
1287 tgt = lmv_find_target(lmv, fid);
1289 RETURN(PTR_ERR(tgt));
1291 rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1292 input_size, output_size, flags, suppgid,
1298 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1299 struct ptlrpc_request **request)
1301 struct obd_device *obd = exp->exp_obd;
1302 struct lmv_obd *lmv = &obd->u.lmv;
1303 struct lmv_tgt_desc *tgt;
1307 rc = lmv_check_connect(obd);
1311 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1313 RETURN(PTR_ERR(tgt));
1315 if (op_data->op_flags & MF_GET_MDT_IDX) {
1316 op_data->op_mds = tgt->ltd_idx;
1320 rc = md_getattr(tgt->ltd_exp, op_data, request);
1325 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1327 struct obd_device *obd = exp->exp_obd;
1328 struct lmv_obd *lmv = &obd->u.lmv;
1333 rc = lmv_check_connect(obd);
1337 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1340 * With DNE every object can have two locks in different namespaces:
1341 * lookup lock in space of MDT storing direntry and update/open lock in
1342 * space of MDT storing inode.
1344 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1345 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1347 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1353 static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1354 ldlm_iterator_t it, void *data)
1356 struct obd_device *obd = exp->exp_obd;
1357 struct lmv_obd *lmv = &obd->u.lmv;
1362 rc = lmv_check_connect(obd);
1366 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1369 * With DNE every object can have two locks in different namespaces:
1370 * lookup lock in space of MDT storing direntry and update/open lock in
1371 * space of MDT storing inode.
1373 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1374 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1376 rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1385 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1386 struct md_open_data *mod, struct ptlrpc_request **request)
1388 struct obd_device *obd = exp->exp_obd;
1389 struct lmv_obd *lmv = &obd->u.lmv;
1390 struct lmv_tgt_desc *tgt;
1394 rc = lmv_check_connect(obd);
1398 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1400 RETURN(PTR_ERR(tgt));
1402 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1403 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1408 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1411 struct lmv_tgt_desc *tgt;
1413 tgt = lmv_find_target(lmv, fid);
1414 op_data->op_mds = tgt->ltd_idx;
1419 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1420 const void *data, int datalen, int mode, __u32 uid,
1421 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1422 struct ptlrpc_request **request)
1424 struct obd_device *obd = exp->exp_obd;
1425 struct lmv_obd *lmv = &obd->u.lmv;
1426 struct lmv_tgt_desc *tgt;
1430 rc = lmv_check_connect(obd);
1434 if (!lmv->desc.ld_active_tgt_count)
1437 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1439 RETURN(PTR_ERR(tgt));
1441 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1445 CDEBUG(D_INODE, "CREATE '%*s' on "DFID" -> mds #%x\n",
1446 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1449 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1450 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1451 cap_effective, rdev, request);
1454 if (*request == NULL)
1456 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1461 static int lmv_done_writing(struct obd_export *exp,
1462 struct md_op_data *op_data,
1463 struct md_open_data *mod)
1465 struct obd_device *obd = exp->exp_obd;
1466 struct lmv_obd *lmv = &obd->u.lmv;
1467 struct lmv_tgt_desc *tgt;
1471 rc = lmv_check_connect(obd);
1475 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1477 RETURN(PTR_ERR(tgt));
1479 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1484 lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1485 struct lookup_intent *it, struct md_op_data *op_data,
1486 struct lustre_handle *lockh, void *lmm, int lmmsize,
1487 int extra_lock_flags)
1489 struct ptlrpc_request *req = it->d.lustre.it_data;
1490 struct obd_device *obd = exp->exp_obd;
1491 struct lmv_obd *lmv = &obd->u.lmv;
1492 struct lustre_handle plock;
1493 struct lmv_tgt_desc *tgt;
1494 struct md_op_data *rdata;
1496 struct mdt_body *body;
1501 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1502 LASSERT(body != NULL);
1504 if (!(body->valid & OBD_MD_MDS))
1507 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1508 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1511 * We got LOOKUP lock, but we really need attrs.
1513 pmode = it->d.lustre.it_lock_mode;
1514 LASSERT(pmode != 0);
1515 memcpy(&plock, lockh, sizeof(plock));
1516 it->d.lustre.it_lock_mode = 0;
1517 it->d.lustre.it_data = NULL;
1520 it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
1521 ptlrpc_req_finished(req);
1523 tgt = lmv_find_target(lmv, &fid1);
1525 GOTO(out, rc = PTR_ERR(tgt));
1527 OBD_ALLOC_PTR(rdata);
1529 GOTO(out, rc = -ENOMEM);
1531 rdata->op_fid1 = fid1;
1532 rdata->op_bias = MDS_CROSS_REF;
1534 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1535 lmm, lmmsize, NULL, extra_lock_flags);
1536 OBD_FREE_PTR(rdata);
1539 ldlm_lock_decref(&plock, pmode);
1544 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1545 struct lookup_intent *it, struct md_op_data *op_data,
1546 struct lustre_handle *lockh, void *lmm, int lmmsize,
1547 struct ptlrpc_request **req, __u64 extra_lock_flags)
1549 struct obd_device *obd = exp->exp_obd;
1550 struct lmv_obd *lmv = &obd->u.lmv;
1551 struct lmv_tgt_desc *tgt;
1555 rc = lmv_check_connect(obd);
1559 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1560 LL_IT2STR(it), PFID(&op_data->op_fid1));
1562 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1564 RETURN(PTR_ERR(tgt));
1566 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1567 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1569 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1570 lmm, lmmsize, req, extra_lock_flags);
1572 if (rc == 0 && it && it->it_op == IT_OPEN) {
1573 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1574 lmm, lmmsize, extra_lock_flags);
1580 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1581 struct ptlrpc_request **request)
1583 struct ptlrpc_request *req = NULL;
1584 struct obd_device *obd = exp->exp_obd;
1585 struct lmv_obd *lmv = &obd->u.lmv;
1586 struct lmv_tgt_desc *tgt;
1587 struct mdt_body *body;
1591 rc = lmv_check_connect(obd);
1595 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1597 RETURN(PTR_ERR(tgt));
1599 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1600 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1603 rc = md_getattr_name(tgt->ltd_exp, op_data, request);
1607 body = req_capsule_server_get(&(*request)->rq_pill,
1609 LASSERT(body != NULL);
1611 if (body->valid & OBD_MD_MDS) {
1612 struct lu_fid rid = body->fid1;
1613 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1616 tgt = lmv_find_target(lmv, &rid);
1618 ptlrpc_req_finished(*request);
1619 RETURN(PTR_ERR(tgt));
1622 op_data->op_fid1 = rid;
1623 op_data->op_valid |= OBD_MD_FLCROSSREF;
1624 op_data->op_namelen = 0;
1625 op_data->op_name = NULL;
1626 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1627 ptlrpc_req_finished(*request);
1634 #define md_op_data_fid(op_data, fl) \
1635 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1636 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1637 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1638 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1641 static int lmv_early_cancel(struct obd_export *exp, struct md_op_data *op_data,
1642 int op_tgt, ldlm_mode_t mode, int bits, int flag)
1644 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1645 struct obd_device *obd = exp->exp_obd;
1646 struct lmv_obd *lmv = &obd->u.lmv;
1647 struct lmv_tgt_desc *tgt;
1648 ldlm_policy_data_t policy = {{0}};
1652 if (!fid_is_sane(fid))
1655 tgt = lmv_find_target(lmv, fid);
1657 RETURN(PTR_ERR(tgt));
1659 if (tgt->ltd_idx != op_tgt) {
1660 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1661 policy.l_inodebits.bits = bits;
1662 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1663 mode, LCF_ASYNC, NULL);
1666 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1668 op_data->op_flags |= flag;
1676 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1679 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1680 struct ptlrpc_request **request)
1682 struct obd_device *obd = exp->exp_obd;
1683 struct lmv_obd *lmv = &obd->u.lmv;
1684 struct lmv_tgt_desc *tgt;
1688 rc = lmv_check_connect(obd);
1692 LASSERT(op_data->op_namelen != 0);
1694 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1695 PFID(&op_data->op_fid2), op_data->op_namelen,
1696 op_data->op_name, PFID(&op_data->op_fid1));
1698 op_data->op_fsuid = cfs_curproc_fsuid();
1699 op_data->op_fsgid = cfs_curproc_fsgid();
1700 op_data->op_cap = cfs_curproc_cap_pack();
1701 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1703 RETURN(PTR_ERR(tgt));
1706 * Cancel UPDATE lock on child (fid1).
1708 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1709 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
1710 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1714 rc = md_link(tgt->ltd_exp, op_data, request);
1719 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1720 const char *old, int oldlen, const char *new, int newlen,
1721 struct ptlrpc_request **request)
1723 struct obd_device *obd = exp->exp_obd;
1724 struct lmv_obd *lmv = &obd->u.lmv;
1725 struct lmv_tgt_desc *src_tgt;
1726 struct lmv_tgt_desc *tgt_tgt;
1730 LASSERT(oldlen != 0);
1732 CDEBUG(D_INODE, "RENAME %*s in "DFID" to %*s in "DFID"\n",
1733 oldlen, old, PFID(&op_data->op_fid1),
1734 newlen, new, PFID(&op_data->op_fid2));
1736 rc = lmv_check_connect(obd);
1740 op_data->op_fsuid = cfs_curproc_fsuid();
1741 op_data->op_fsgid = cfs_curproc_fsgid();
1742 op_data->op_cap = cfs_curproc_cap_pack();
1743 src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1744 if (IS_ERR(src_tgt))
1745 RETURN(PTR_ERR(src_tgt));
1747 tgt_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1748 if (IS_ERR(tgt_tgt))
1749 RETURN(PTR_ERR(tgt_tgt));
1751 * LOOKUP lock on src child (fid3) should also be cancelled for
1752 * src_tgt in mdc_rename.
1754 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
1757 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
1760 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1761 LCK_EX, MDS_INODELOCK_UPDATE,
1762 MF_MDC_CANCEL_FID2);
1765 * Cancel LOOKUP locks on tgt child (fid4) for parent tgt_tgt.
1768 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1769 LCK_EX, MDS_INODELOCK_LOOKUP,
1770 MF_MDC_CANCEL_FID4);
1774 * Cancel all the locks on tgt child (fid4).
1777 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1778 LCK_EX, MDS_INODELOCK_FULL,
1779 MF_MDC_CANCEL_FID4);
1782 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen,
1783 new, newlen, request);
1787 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
1788 void *ea, int ealen, void *ea2, int ea2len,
1789 struct ptlrpc_request **request,
1790 struct md_open_data **mod)
1792 struct obd_device *obd = exp->exp_obd;
1793 struct lmv_obd *lmv = &obd->u.lmv;
1794 struct lmv_tgt_desc *tgt;
1798 rc = lmv_check_connect(obd);
1802 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
1803 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
1805 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1806 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1808 RETURN(PTR_ERR(tgt));
1810 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
1811 ea2len, request, mod);
1816 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
1817 struct obd_capa *oc, struct ptlrpc_request **request)
1819 struct obd_device *obd = exp->exp_obd;
1820 struct lmv_obd *lmv = &obd->u.lmv;
1821 struct lmv_tgt_desc *tgt;
1825 rc = lmv_check_connect(obd);
1829 tgt = lmv_find_target(lmv, fid);
1831 RETURN(PTR_ERR(tgt));
1833 rc = md_sync(tgt->ltd_exp, fid, oc, request);
1837 static int lmv_readpage(struct obd_export *exp, struct md_op_data *op_data,
1838 struct page **pages, struct ptlrpc_request **request)
1840 struct obd_device *obd = exp->exp_obd;
1841 struct lmv_obd *lmv = &obd->u.lmv;
1842 __u64 offset = op_data->op_offset;
1845 /* number of pages read, in CFS_PAGE_SIZE */
1847 /* number of pages transferred in LU_PAGE_SIZE */
1849 struct lmv_tgt_desc *tgt;
1850 struct lu_dirpage *dp;
1851 struct lu_dirent *ent;
1854 rc = lmv_check_connect(obd);
1858 CDEBUG(D_INODE, "READPAGE at "LPX64" from "DFID"\n",
1859 offset, PFID(&op_data->op_fid1));
1862 * This case handle directory lookup in clustered metadata case (i.e.
1863 * split directory is located on multiple md servers.)
1864 * each server keeps directory entries for certain range of hashes.
1865 * E.g. we have N server and suppose hash range is 0 to MAX_HASH.
1866 * first server will keep records with hashes [ 0 ... MAX_HASH /N - 1],
1867 * second one with hashes [MAX_HASH / N ... 2 * MAX_HASH / N] and
1869 * readdir can simply start reading entries from 0 - N server in
1870 * order but that will not scale well as all client will request dir in
1871 * to server in same order.
1872 * Following algorithm does optimization:
1873 * Instead of doing readdir in 1, 2, ...., N order, client with a
1874 * rank R does readdir in R, R + 1, ..., N, 1, ... R - 1 order.
1875 * (every client has rank R)
1876 * But ll_readdir() expect offset range [0 to MAX_HASH/N) but
1877 * since client ask dir from MDS{R} client has pages with offsets
1878 * [R*MAX_HASH/N ... (R + 1)*MAX_HASH/N] there for we do hash_adj
1879 * on hash values that we get.
1880 * Since these codes might be still useful for sharded directory, so
1881 * Keeping this code for further reference
1884 seg_size = MAX_HASH_SIZE;
1885 do_div(seg_size, nr);
1886 los = obj->lo_stripes;
1887 tgt = lmv_get_target(lmv, los[0].ls_mds);
1888 rank = lmv_node_rank(tgt->ltd_exp, fid) % nr;
1890 do_div(tgt_tmp, seg_size);
1891 tgt0_idx = do_div(tgt_tmp, nr);
1892 tgt_idx = (tgt0_idx + rank) % nr;
1894 if (tgt_idx < tgt0_idx)
1897 * Last segment has unusual length due to division
1899 hash_adj = MAX_HASH_SIZE - seg_size * nr;
1903 hash_adj += rank * seg_size;
1905 CDEBUG(D_INODE, "Readpage hash adjustment: %x "LPX64" "
1906 LPX64"/%x -> "LPX64"/%x\n", rank, hash_adj,
1907 offset, tgt0_idx, offset + hash_adj, tgt_idx);
1909 offset = (offset + hash_adj) & MAX_HASH_SIZE;
1910 rid = lsm->mea_oinfo[tgt_idx].lmo_fid;
1911 tgt = lmv_get_target(lmv, lsm->mea_oinfo[tgt_idx].lmo_mds);
1913 CDEBUG(D_INODE, "Forward to "DFID" with offset %lu i %d\n",
1914 PFID(&rid), (unsigned long)offset, tgt_idx);
1917 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1919 RETURN(PTR_ERR(tgt));
1921 rc = md_readpage(tgt->ltd_exp, op_data, pages, request);
1925 nrdpgs = ((*request)->rq_bulk->bd_nob_transferred + CFS_PAGE_SIZE - 1)
1927 nlupgs = (*request)->rq_bulk->bd_nob_transferred >> LU_PAGE_SHIFT;
1928 LASSERT(!((*request)->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK));
1929 LASSERT(nrdpgs > 0 && nrdpgs <= op_data->op_npages);
1931 CDEBUG(D_INODE, "read %d(%d)/%d pages\n", nrdpgs, nlupgs,
1932 op_data->op_npages);
1934 for (i = 0; i < nrdpgs; i++) {
1935 #if CFS_PAGE_SIZE > LU_PAGE_SIZE
1936 struct lu_dirpage *first;
1940 struct lu_dirent *tmp = NULL;
1942 dp = cfs_kmap(pages[i]);
1943 ent = lu_dirent_start(dp);
1944 #if CFS_PAGE_SIZE > LU_PAGE_SIZE
1946 hash_end = dp->ldp_hash_end;
1951 for (tmp = ent; ent != NULL;
1952 tmp = ent, ent = lu_dirent_next(ent));
1953 #if CFS_PAGE_SIZE > LU_PAGE_SIZE
1954 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
1955 if (((unsigned long)dp & ~CFS_PAGE_MASK) && nlupgs > 0) {
1956 ent = lu_dirent_start(dp);
1959 /* enlarge the end entry lde_reclen from 0 to
1960 * first entry of next lu_dirpage, in this way
1961 * several lu_dirpages can be stored into one
1962 * client page on client. */
1963 tmp = ((void *)tmp) +
1964 le16_to_cpu(tmp->lde_reclen);
1966 cpu_to_le16((char *)(dp->ldp_entries) -
1971 first->ldp_hash_end = hash_end;
1972 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
1973 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
1975 SET_BUT_UNUSED(tmp);
1977 cfs_kunmap(pages[i]);
1982 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
1983 struct ptlrpc_request **request)
1985 struct obd_device *obd = exp->exp_obd;
1986 struct lmv_obd *lmv = &obd->u.lmv;
1987 struct lmv_tgt_desc *tgt = NULL;
1988 struct mdt_body *body;
1992 rc = lmv_check_connect(obd);
1996 /* Send unlink requests to the MDT where the child is located */
1997 if (likely(!fid_is_zero(&op_data->op_fid2)))
1998 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2000 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2002 RETURN(PTR_ERR(tgt));
2004 op_data->op_fsuid = cfs_curproc_fsuid();
2005 op_data->op_fsgid = cfs_curproc_fsgid();
2006 op_data->op_cap = cfs_curproc_cap_pack();
2009 * If child's fid is given, cancel unused locks for it if it is from
2010 * another export than parent.
2012 * LOOKUP lock for child (fid3) should also be cancelled on parent
2013 * tgt_tgt in mdc_unlink().
2015 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2018 * Cancel FULL locks on child (fid3).
2020 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
2021 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2026 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n",
2027 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2029 rc = md_unlink(tgt->ltd_exp, op_data, request);
2030 if (rc != 0 && rc != -EREMOTE)
2033 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2037 /* Not cross-ref case, just get out of here. */
2038 if (likely(!(body->valid & OBD_MD_MDS)))
2041 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2042 exp->exp_obd->obd_name, PFID(&body->fid1));
2044 /* This is a remote object, try remote MDT, Note: it may
2045 * try more than 1 time here, Considering following case
2046 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2047 * 1. Initially A does not know where remote1 is, it send
2048 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2049 * resend unlink RPC to MDT1 (retry 1st time).
2051 * 2. During the unlink RPC in flight,
2052 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2053 * and create new remote1, but on MDT0
2055 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2056 * /mnt/lustre, then lookup get fid of remote1, and find
2057 * it is remote dir again, and replay -EREMOTE again.
2059 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2061 * In theory, it might try unlimited time here, but it should
2062 * be very rare case. */
2063 op_data->op_fid2 = body->fid1;
2064 ptlrpc_req_finished(*request);
2070 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2072 struct lmv_obd *lmv = &obd->u.lmv;
2076 case OBD_CLEANUP_EARLY:
2077 /* XXX: here should be calling obd_precleanup() down to
2080 case OBD_CLEANUP_EXPORTS:
2081 fld_client_proc_fini(&lmv->lmv_fld);
2082 lprocfs_obd_cleanup(obd);
2090 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2091 __u32 keylen, void *key, __u32 *vallen, void *val,
2092 struct lov_stripe_md *lsm)
2094 struct obd_device *obd;
2095 struct lmv_obd *lmv;
2099 obd = class_exp2obd(exp);
2101 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2102 exp->exp_handle.h_cookie);
2107 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2108 struct lmv_tgt_desc *tgt;
2111 rc = lmv_check_connect(obd);
2115 LASSERT(*vallen == sizeof(__u32));
2116 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2119 * All tgts should be connected when this gets called.
2121 if (tgt == NULL || tgt->ltd_exp == NULL)
2124 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2129 } else if (KEY_IS(KEY_MAX_EASIZE) || KEY_IS(KEY_CONN_DATA)) {
2130 rc = lmv_check_connect(obd);
2135 * Forwarding this request to first MDS, it should know LOV
2138 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2140 if (!rc && KEY_IS(KEY_CONN_DATA))
2141 exp->exp_connect_data = *(struct obd_connect_data *)val;
2143 } else if (KEY_IS(KEY_TGT_COUNT)) {
2144 *((int *)val) = lmv->desc.ld_tgt_count;
2148 CDEBUG(D_IOCTL, "Invalid key\n");
2152 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2153 obd_count keylen, void *key, obd_count vallen,
2154 void *val, struct ptlrpc_request_set *set)
2156 struct lmv_tgt_desc *tgt;
2157 struct obd_device *obd;
2158 struct lmv_obd *lmv;
2162 obd = class_exp2obd(exp);
2164 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2165 exp->exp_handle.h_cookie);
2170 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) {
2173 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2176 if (tgt == NULL || tgt->ltd_exp == NULL)
2179 err = obd_set_info_async(env, tgt->ltd_exp,
2180 keylen, key, vallen, val, set);
2191 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2192 struct lov_stripe_md *lsm)
2194 struct obd_device *obd = class_exp2obd(exp);
2195 struct lmv_obd *lmv = &obd->u.lmv;
2196 struct lmv_stripe_md *meap;
2197 struct lmv_stripe_md *lsmp;
2202 mea_size = lmv_get_easize(lmv);
2206 if (*lmmp && !lsm) {
2207 OBD_FREE_LARGE(*lmmp, mea_size);
2212 if (*lmmp == NULL) {
2213 OBD_ALLOC_LARGE(*lmmp, mea_size);
2221 lsmp = (struct lmv_stripe_md *)lsm;
2222 meap = (struct lmv_stripe_md *)*lmmp;
2224 if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR &&
2225 lsmp->mea_magic != MEA_MAGIC_ALL_CHARS)
2228 meap->mea_magic = cpu_to_le32(lsmp->mea_magic);
2229 meap->mea_count = cpu_to_le32(lsmp->mea_count);
2230 meap->mea_master = cpu_to_le32(lsmp->mea_master);
2232 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2233 meap->mea_ids[i] = meap->mea_ids[i];
2234 fid_cpu_to_le(&meap->mea_ids[i], &meap->mea_ids[i]);
2240 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2241 struct lov_mds_md *lmm, int lmm_size)
2243 struct obd_device *obd = class_exp2obd(exp);
2244 struct lmv_stripe_md **tmea = (struct lmv_stripe_md **)lsmp;
2245 struct lmv_stripe_md *mea = (struct lmv_stripe_md *)lmm;
2246 struct lmv_obd *lmv = &obd->u.lmv;
2252 mea_size = lmv_get_easize(lmv);
2256 if (*lsmp != NULL && lmm == NULL) {
2257 OBD_FREE_LARGE(*tmea, mea_size);
2262 LASSERT(mea_size == lmm_size);
2264 OBD_ALLOC_LARGE(*tmea, mea_size);
2271 if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
2272 mea->mea_magic == MEA_MAGIC_ALL_CHARS ||
2273 mea->mea_magic == MEA_MAGIC_HASH_SEGMENT)
2275 magic = le32_to_cpu(mea->mea_magic);
2278 * Old mea is not handled here.
2280 CERROR("Old not supportable EA is found\n");
2284 (*tmea)->mea_magic = magic;
2285 (*tmea)->mea_count = le32_to_cpu(mea->mea_count);
2286 (*tmea)->mea_master = le32_to_cpu(mea->mea_master);
2288 for (i = 0; i < (*tmea)->mea_count; i++) {
2289 (*tmea)->mea_ids[i] = mea->mea_ids[i];
2290 fid_le_to_cpu(&(*tmea)->mea_ids[i], &(*tmea)->mea_ids[i]);
2295 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2296 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2297 ldlm_cancel_flags_t flags, void *opaque)
2299 struct obd_device *obd = exp->exp_obd;
2300 struct lmv_obd *lmv = &obd->u.lmv;
2306 LASSERT(fid != NULL);
2308 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2309 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL ||
2310 lmv->tgts[i]->ltd_active == 0)
2313 err = md_cancel_unused(lmv->tgts[i]->ltd_exp, fid,
2314 policy, mode, flags, opaque);
2321 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
2324 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2328 rc = md_set_lock_data(lmv->tgts[0]->ltd_exp, lockh, data, bits);
2332 ldlm_mode_t lmv_lock_match(struct obd_export *exp, __u64 flags,
2333 const struct lu_fid *fid, ldlm_type_t type,
2334 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2335 struct lustre_handle *lockh)
2337 struct obd_device *obd = exp->exp_obd;
2338 struct lmv_obd *lmv = &obd->u.lmv;
2343 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2346 * With CMD every object can have two locks in different namespaces:
2347 * lookup lock in space of mds storing direntry and update/open lock in
2348 * space of mds storing inode. Thus we check all targets, not only that
2349 * one fid was created in.
2351 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2352 if (lmv->tgts[i] == NULL ||
2353 lmv->tgts[i]->ltd_exp == NULL ||
2354 lmv->tgts[i]->ltd_active == 0)
2357 rc = md_lock_match(lmv->tgts[i]->ltd_exp, flags, fid,
2358 type, policy, mode, lockh);
2366 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2367 struct obd_export *dt_exp, struct obd_export *md_exp,
2368 struct lustre_md *md)
2370 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2372 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
2375 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2377 struct obd_device *obd = exp->exp_obd;
2378 struct lmv_obd *lmv = &obd->u.lmv;
2382 obd_free_memmd(exp, (void *)&md->mea);
2383 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
2386 int lmv_set_open_replay_data(struct obd_export *exp,
2387 struct obd_client_handle *och,
2388 struct ptlrpc_request *open_req)
2390 struct obd_device *obd = exp->exp_obd;
2391 struct lmv_obd *lmv = &obd->u.lmv;
2392 struct lmv_tgt_desc *tgt;
2395 tgt = lmv_find_target(lmv, &och->och_fid);
2397 RETURN(PTR_ERR(tgt));
2399 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, open_req));
2402 int lmv_clear_open_replay_data(struct obd_export *exp,
2403 struct obd_client_handle *och)
2405 struct obd_device *obd = exp->exp_obd;
2406 struct lmv_obd *lmv = &obd->u.lmv;
2407 struct lmv_tgt_desc *tgt;
2410 tgt = lmv_find_target(lmv, &och->och_fid);
2412 RETURN(PTR_ERR(tgt));
2414 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
2417 static int lmv_get_remote_perm(struct obd_export *exp,
2418 const struct lu_fid *fid,
2419 struct obd_capa *oc, __u32 suppgid,
2420 struct ptlrpc_request **request)
2422 struct obd_device *obd = exp->exp_obd;
2423 struct lmv_obd *lmv = &obd->u.lmv;
2424 struct lmv_tgt_desc *tgt;
2428 rc = lmv_check_connect(obd);
2432 tgt = lmv_find_target(lmv, fid);
2434 RETURN(PTR_ERR(tgt));
2436 rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
2440 static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
2443 struct obd_device *obd = exp->exp_obd;
2444 struct lmv_obd *lmv = &obd->u.lmv;
2445 struct lmv_tgt_desc *tgt;
2449 rc = lmv_check_connect(obd);
2453 tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
2455 RETURN(PTR_ERR(tgt));
2457 rc = md_renew_capa(tgt->ltd_exp, oc, cb);
2461 int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
2462 const struct req_msg_field *field, struct obd_capa **oc)
2464 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2466 return md_unpack_capa(lmv->tgts[0]->ltd_exp, req, field, oc);
2469 int lmv_intent_getattr_async(struct obd_export *exp,
2470 struct md_enqueue_info *minfo,
2471 struct ldlm_enqueue_info *einfo)
2473 struct md_op_data *op_data = &minfo->mi_data;
2474 struct obd_device *obd = exp->exp_obd;
2475 struct lmv_obd *lmv = &obd->u.lmv;
2476 struct lmv_tgt_desc *tgt = NULL;
2480 rc = lmv_check_connect(obd);
2484 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2486 RETURN(PTR_ERR(tgt));
2488 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
2492 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
2493 struct lu_fid *fid, __u64 *bits)
2495 struct obd_device *obd = exp->exp_obd;
2496 struct lmv_obd *lmv = &obd->u.lmv;
2497 struct lmv_tgt_desc *tgt;
2501 rc = lmv_check_connect(obd);
2505 tgt = lmv_find_target(lmv, fid);
2507 RETURN(PTR_ERR(tgt));
2509 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
2514 * For lmv, only need to send request to master MDT, and the master MDT will
2515 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
2516 * we directly fetch data from the slave MDTs.
2518 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
2519 struct obd_quotactl *oqctl)
2521 struct obd_device *obd = class_exp2obd(exp);
2522 struct lmv_obd *lmv = &obd->u.lmv;
2523 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2525 __u64 curspace, curinodes;
2528 if (!lmv->desc.ld_tgt_count || !tgt->ltd_active) {
2529 CERROR("master lmv inactive\n");
2533 if (oqctl->qc_cmd != Q_GETOQUOTA) {
2534 rc = obd_quotactl(tgt->ltd_exp, oqctl);
2538 curspace = curinodes = 0;
2539 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2543 if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0)
2545 if (!tgt->ltd_active) {
2546 CDEBUG(D_HA, "mdt %d is inactive.\n", i);
2550 err = obd_quotactl(tgt->ltd_exp, oqctl);
2552 CERROR("getquota on mdt %d failed. %d\n", i, err);
2556 curspace += oqctl->qc_dqblk.dqb_curspace;
2557 curinodes += oqctl->qc_dqblk.dqb_curinodes;
2560 oqctl->qc_dqblk.dqb_curspace = curspace;
2561 oqctl->qc_dqblk.dqb_curinodes = curinodes;
2566 int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
2567 struct obd_quotactl *oqctl)
2569 struct obd_device *obd = class_exp2obd(exp);
2570 struct lmv_obd *lmv = &obd->u.lmv;
2571 struct lmv_tgt_desc *tgt;
2575 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2578 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
2579 CERROR("lmv idx %d inactive\n", i);
2583 err = obd_quotacheck(tgt->ltd_exp, oqctl);
2591 struct obd_ops lmv_obd_ops = {
2592 .o_owner = THIS_MODULE,
2593 .o_setup = lmv_setup,
2594 .o_cleanup = lmv_cleanup,
2595 .o_precleanup = lmv_precleanup,
2596 .o_process_config = lmv_process_config,
2597 .o_connect = lmv_connect,
2598 .o_disconnect = lmv_disconnect,
2599 .o_statfs = lmv_statfs,
2600 .o_get_info = lmv_get_info,
2601 .o_set_info_async = lmv_set_info_async,
2602 .o_packmd = lmv_packmd,
2603 .o_unpackmd = lmv_unpackmd,
2604 .o_notify = lmv_notify,
2605 .o_get_uuid = lmv_get_uuid,
2606 .o_iocontrol = lmv_iocontrol,
2607 .o_quotacheck = lmv_quotacheck,
2608 .o_quotactl = lmv_quotactl
2611 struct md_ops lmv_md_ops = {
2612 .m_getstatus = lmv_getstatus,
2613 .m_null_inode = lmv_null_inode,
2614 .m_find_cbdata = lmv_find_cbdata,
2615 .m_close = lmv_close,
2616 .m_create = lmv_create,
2617 .m_done_writing = lmv_done_writing,
2618 .m_enqueue = lmv_enqueue,
2619 .m_getattr = lmv_getattr,
2620 .m_getxattr = lmv_getxattr,
2621 .m_getattr_name = lmv_getattr_name,
2622 .m_intent_lock = lmv_intent_lock,
2624 .m_rename = lmv_rename,
2625 .m_setattr = lmv_setattr,
2626 .m_setxattr = lmv_setxattr,
2628 .m_readpage = lmv_readpage,
2629 .m_unlink = lmv_unlink,
2630 .m_init_ea_size = lmv_init_ea_size,
2631 .m_cancel_unused = lmv_cancel_unused,
2632 .m_set_lock_data = lmv_set_lock_data,
2633 .m_lock_match = lmv_lock_match,
2634 .m_get_lustre_md = lmv_get_lustre_md,
2635 .m_free_lustre_md = lmv_free_lustre_md,
2636 .m_set_open_replay_data = lmv_set_open_replay_data,
2637 .m_clear_open_replay_data = lmv_clear_open_replay_data,
2638 .m_renew_capa = lmv_renew_capa,
2639 .m_unpack_capa = lmv_unpack_capa,
2640 .m_get_remote_perm = lmv_get_remote_perm,
2641 .m_intent_getattr_async = lmv_intent_getattr_async,
2642 .m_revalidate_lock = lmv_revalidate_lock
2645 int __init lmv_init(void)
2647 struct lprocfs_static_vars lvars;
2650 lprocfs_lmv_init_vars(&lvars);
2652 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
2653 lvars.module_vars, LUSTRE_LMV_NAME, NULL);
2658 static void lmv_exit(void)
2660 class_unregister_type(LUSTRE_LMV_NAME);
2663 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2664 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
2665 MODULE_LICENSE("GPL");
2667 module_init(lmv_init);
2668 module_exit(lmv_exit);