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_connect_data *mdc_data = NULL;
348 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
349 struct obd_device *mdc_obd;
350 struct obd_export *mdc_exp;
351 struct lu_fld_target target;
355 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
358 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
362 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
363 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
364 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
367 if (!mdc_obd->obd_set_up) {
368 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
372 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
373 &lmv->conn_data, NULL);
375 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
380 * Init fid sequence client for this mdc and add new fld target.
382 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
386 target.ft_srv = NULL;
387 target.ft_exp = mdc_exp;
388 target.ft_idx = tgt->ltd_idx;
390 fld_client_add_target(&lmv->lmv_fld, &target);
392 mdc_data = &class_exp2cliimp(mdc_exp)->imp_connect_data;
394 rc = obd_register_observer(mdc_obd, obd);
396 obd_disconnect(mdc_exp);
397 CERROR("target %s register_observer error %d\n",
398 tgt->ltd_uuid.uuid, rc);
402 if (obd->obd_observer) {
404 * Tell the observer about the new target.
406 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
408 (void *)(tgt - lmv->tgts[0]));
410 obd_disconnect(mdc_exp);
416 tgt->ltd_exp = mdc_exp;
417 lmv->desc.ld_active_tgt_count++;
419 md_init_ea_size(tgt->ltd_exp, lmv->max_easize,
420 lmv->max_def_easize, lmv->max_cookiesize);
422 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
423 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
424 cfs_atomic_read(&obd->obd_refcount));
427 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
429 struct proc_dir_entry *mdc_symlink;
431 LASSERT(mdc_obd->obd_type != NULL);
432 LASSERT(mdc_obd->obd_type->typ_name != NULL);
433 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
436 mdc_obd->obd_type->typ_name,
438 if (mdc_symlink == NULL) {
439 CERROR("Could not register LMV target "
440 "/proc/fs/lustre/%s/%s/target_obds/%s.",
441 obd->obd_type->typ_name, obd->obd_name,
443 lprocfs_remove(&lmv_proc_dir);
451 static void lmv_del_target(struct lmv_obd *lmv, int index)
453 if (lmv->tgts[index] == NULL)
456 OBD_FREE_PTR(lmv->tgts[index]);
457 lmv->tgts[index] = NULL;
461 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
462 __u32 index, int gen)
464 struct lmv_obd *lmv = &obd->u.lmv;
465 struct lmv_tgt_desc *tgt;
469 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
473 if (lmv->desc.ld_tgt_count == 0) {
474 struct obd_device *mdc_obd;
476 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
479 lmv_init_unlock(lmv);
480 CERROR("%s: Target %s not attached: rc = %d\n",
481 obd->obd_name, uuidp->uuid, -EINVAL);
486 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
487 tgt = lmv->tgts[index];
488 CERROR("%s: UUID %s already assigned at LOV target index %d:"
489 " rc = %d\n", obd->obd_name,
490 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
491 lmv_init_unlock(lmv);
495 if (index >= lmv->tgts_size) {
496 /* We need to reallocate the lmv target array. */
497 struct lmv_tgt_desc **newtgts, **old = NULL;
501 while (newsize < index + 1)
502 newsize = newsize << 1;
503 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
504 if (newtgts == NULL) {
505 lmv_init_unlock(lmv);
509 if (lmv->tgts_size) {
510 memcpy(newtgts, lmv->tgts,
511 sizeof(*newtgts) * lmv->tgts_size);
513 oldsize = lmv->tgts_size;
517 lmv->tgts_size = newsize;
520 OBD_FREE(old, sizeof(*old) * oldsize);
522 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
528 lmv_init_unlock(lmv);
532 mutex_init(&tgt->ltd_fid_mutex);
533 tgt->ltd_idx = index;
534 tgt->ltd_uuid = *uuidp;
536 lmv->tgts[index] = tgt;
537 if (index >= lmv->desc.ld_tgt_count)
538 lmv->desc.ld_tgt_count = index + 1;
540 if (lmv->connected) {
541 rc = lmv_connect_mdc(obd, tgt);
543 spin_lock(&lmv->lmv_lock);
544 lmv->desc.ld_tgt_count--;
545 memset(tgt, 0, sizeof(*tgt));
546 spin_unlock(&lmv->lmv_lock);
548 int easize = sizeof(struct lmv_stripe_md) +
549 lmv->desc.ld_tgt_count *
550 sizeof(struct lu_fid);
551 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
555 lmv_init_unlock(lmv);
559 int lmv_check_connect(struct obd_device *obd)
561 struct lmv_obd *lmv = &obd->u.lmv;
562 struct lmv_tgt_desc *tgt;
572 if (lmv->connected) {
573 lmv_init_unlock(lmv);
577 if (lmv->desc.ld_tgt_count == 0) {
578 lmv_init_unlock(lmv);
579 CERROR("%s: no targets configured.\n", obd->obd_name);
583 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
584 lmv->cluuid.uuid, obd->obd_name);
586 LASSERT(lmv->tgts != NULL);
588 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
592 rc = lmv_connect_mdc(obd, tgt);
597 lmv_set_timeouts(obd);
598 class_export_put(lmv->exp);
600 easize = lmv_get_easize(lmv);
601 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
602 lmv_init_unlock(lmv);
613 --lmv->desc.ld_active_tgt_count;
614 rc2 = obd_disconnect(tgt->ltd_exp);
616 CERROR("LMV target %s disconnect on "
617 "MDC idx %d: error %d\n",
618 tgt->ltd_uuid.uuid, i, rc2);
622 class_disconnect(lmv->exp);
623 lmv_init_unlock(lmv);
627 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
630 struct proc_dir_entry *lmv_proc_dir;
632 struct lmv_obd *lmv = &obd->u.lmv;
633 struct obd_device *mdc_obd;
637 LASSERT(tgt != NULL);
638 LASSERT(obd != NULL);
640 mdc_obd = class_exp2obd(tgt->ltd_exp);
643 mdc_obd->obd_force = obd->obd_force;
644 mdc_obd->obd_fail = obd->obd_fail;
645 mdc_obd->obd_no_recov = obd->obd_no_recov;
649 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
651 struct proc_dir_entry *mdc_symlink;
653 mdc_symlink = lprocfs_srch(lmv_proc_dir, mdc_obd->obd_name);
655 lprocfs_remove(&mdc_symlink);
657 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing\n",
658 obd->obd_type->typ_name, obd->obd_name,
663 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
665 CERROR("Can't finanize fids factory\n");
667 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
668 tgt->ltd_exp->exp_obd->obd_name,
669 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
671 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
672 rc = obd_disconnect(tgt->ltd_exp);
674 if (tgt->ltd_active) {
675 CERROR("Target %s disconnect error %d\n",
676 tgt->ltd_uuid.uuid, rc);
680 lmv_activate_target(lmv, tgt, 0);
685 static int lmv_disconnect(struct obd_export *exp)
687 struct obd_device *obd = class_exp2obd(exp);
689 struct proc_dir_entry *lmv_proc_dir;
691 struct lmv_obd *lmv = &obd->u.lmv;
700 * Only disconnect the underlying layers on the final disconnect.
703 if (lmv->refcount != 0)
706 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
707 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
710 lmv_disconnect_mdc(obd, lmv->tgts[i]);
714 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
716 lprocfs_remove(&lmv_proc_dir);
718 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
719 obd->obd_type->typ_name, obd->obd_name);
725 * This is the case when no real connection is established by
726 * lmv_check_connect().
729 class_export_put(exp);
730 rc = class_disconnect(exp);
731 if (lmv->refcount == 0)
736 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
737 int len, void *karg, void *uarg)
739 struct obd_device *obddev = class_exp2obd(exp);
740 struct lmv_obd *lmv = &obddev->u.lmv;
744 int count = lmv->desc.ld_tgt_count;
751 case IOC_OBD_STATFS: {
752 struct obd_ioctl_data *data = karg;
753 struct obd_device *mdc_obd;
754 struct obd_statfs stat_buf = {0};
757 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
758 if ((index >= count))
761 if (lmv->tgts[index] == NULL ||
762 lmv->tgts[index]->ltd_active == 0)
765 mdc_obd = class_exp2obd(lmv->tgts[index]->ltd_exp);
770 if (cfs_copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
771 min((int) data->ioc_plen2,
772 (int) sizeof(struct obd_uuid))))
775 rc = obd_statfs(NULL, lmv->tgts[index]->ltd_exp, &stat_buf,
776 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
780 if (cfs_copy_to_user(data->ioc_pbuf1, &stat_buf,
781 min((int) data->ioc_plen1,
782 (int) sizeof(stat_buf))))
786 case OBD_IOC_QUOTACTL: {
787 struct if_quotactl *qctl = karg;
788 struct lmv_tgt_desc *tgt = NULL;
789 struct obd_quotactl *oqctl;
791 if (qctl->qc_valid == QC_MDTIDX) {
792 if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
795 tgt = lmv->tgts[qctl->qc_idx];
796 if (tgt == NULL || tgt->ltd_exp == NULL)
798 } else if (qctl->qc_valid == QC_UUID) {
799 for (i = 0; i < count; i++) {
803 if (!obd_uuid_equals(&tgt->ltd_uuid,
807 if (tgt->ltd_exp == NULL)
819 LASSERT(tgt && tgt->ltd_exp);
820 OBD_ALLOC_PTR(oqctl);
824 QCTL_COPY(oqctl, qctl);
825 rc = obd_quotactl(tgt->ltd_exp, oqctl);
827 QCTL_COPY(qctl, oqctl);
828 qctl->qc_valid = QC_MDTIDX;
829 qctl->obd_uuid = tgt->ltd_uuid;
834 case OBD_IOC_CHANGELOG_SEND:
835 case OBD_IOC_CHANGELOG_CLEAR: {
836 struct ioc_changelog *icc = karg;
838 if (icc->icc_mdtindex >= count)
841 if (lmv->tgts[icc->icc_mdtindex] == NULL ||
842 lmv->tgts[icc->icc_mdtindex]->ltd_exp == NULL ||
843 lmv->tgts[icc->icc_mdtindex]->ltd_active == 0)
845 rc = obd_iocontrol(cmd, lmv->tgts[icc->icc_mdtindex]->ltd_exp,
846 sizeof(*icc), icc, NULL);
849 case LL_IOC_GET_CONNECT_FLAGS: {
850 if (lmv->tgts[0] == NULL)
852 rc = obd_iocontrol(cmd, lmv->tgts[0]->ltd_exp, len, karg, uarg);
855 case OBD_IOC_FID2PATH: {
856 struct getinfo_fid2path *gf;
857 struct lmv_tgt_desc *tgt;
859 gf = (struct getinfo_fid2path *)karg;
860 tgt = lmv_find_target(lmv, &gf->gf_fid);
862 RETURN(PTR_ERR(tgt));
863 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
866 case LL_IOC_HSM_STATE_GET:
867 case LL_IOC_HSM_STATE_SET:
868 case LL_IOC_HSM_ACTION: {
869 struct md_op_data *op_data = karg;
870 struct lmv_tgt_desc *tgt;
872 tgt = lmv_find_target(lmv, &op_data->op_fid1);
876 rc = obd_iocontrol(cmd, lmv->tgts[0]->ltd_exp, len, karg, uarg);
880 for (i = 0; i < count; i++) {
881 struct obd_device *mdc_obd;
884 if (lmv->tgts[i] == NULL ||
885 lmv->tgts[i]->ltd_exp == NULL)
887 /* ll_umount_begin() sets force flag but for lmv, not
888 * mdc. Let's pass it through */
889 mdc_obd = class_exp2obd(lmv->tgts[i]->ltd_exp);
890 mdc_obd->obd_force = obddev->obd_force;
891 err = obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, len,
893 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
896 if (lmv->tgts[i]->ltd_active) {
897 CERROR("error: iocontrol MDC %s on MDT"
898 "idx %d cmd %x: err = %d\n",
899 lmv->tgts[i]->ltd_uuid.uuid,
914 static int lmv_all_chars_policy(int count, const char *name,
925 static int lmv_nid_policy(struct lmv_obd *lmv)
927 struct obd_import *imp;
931 * XXX: To get nid we assume that underlying obd device is mdc.
933 imp = class_exp2cliimp(lmv->tgts[0].ltd_exp);
934 id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32);
935 return id % lmv->desc.ld_tgt_count;
938 static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
939 placement_policy_t placement)
942 case PLACEMENT_CHAR_POLICY:
943 return lmv_all_chars_policy(lmv->desc.ld_tgt_count,
945 op_data->op_namelen);
946 case PLACEMENT_NID_POLICY:
947 return lmv_nid_policy(lmv);
953 CERROR("Unsupported placement policy %x\n", placement);
959 * This is _inode_ placement policy function (not name).
961 static int lmv_placement_policy(struct obd_device *obd,
962 struct md_op_data *op_data,
965 struct lmv_obd *lmv = &obd->u.lmv;
968 LASSERT(mds != NULL);
970 if (lmv->desc.ld_tgt_count == 1) {
976 * If stripe_offset is provided during setdirstripe
977 * (setdirstripe -i xx), xx MDS will be choosen.
979 if (op_data->op_cli_flags & CLI_SET_MEA) {
980 struct lmv_user_md *lum;
982 lum = (struct lmv_user_md *)op_data->op_data;
983 if (lum->lum_type == LMV_STRIPE_TYPE &&
984 lum->lum_stripe_offset != -1) {
985 if (lum->lum_stripe_offset >= lmv->desc.ld_tgt_count) {
986 CERROR("%s: Stripe_offset %d > MDT count %d:"
987 " rc = %d\n", obd->obd_name,
988 lum->lum_stripe_offset,
989 lmv->desc.ld_tgt_count, -ERANGE);
992 *mds = lum->lum_stripe_offset;
997 /* Allocate new fid on target according to operation type and parent
999 *mds = op_data->op_mds;
1003 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
1006 struct lmv_tgt_desc *tgt;
1010 tgt = lmv_get_target(lmv, mds);
1013 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1014 * on server that seq in new allocated fid is not yet known.
1016 mutex_lock(&tgt->ltd_fid_mutex);
1018 if (tgt == NULL || tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1019 GOTO(out, rc = -ENODEV);
1022 * Asking underlaying tgt layer to allocate new fid.
1024 rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL);
1026 LASSERT(fid_is_sane(fid));
1032 mutex_unlock(&tgt->ltd_fid_mutex);
1036 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1037 struct md_op_data *op_data)
1039 struct obd_device *obd = class_exp2obd(exp);
1040 struct lmv_obd *lmv = &obd->u.lmv;
1045 LASSERT(op_data != NULL);
1046 LASSERT(fid != NULL);
1048 rc = lmv_placement_policy(obd, op_data, &mds);
1050 CERROR("Can't get target for allocating fid, "
1055 rc = __lmv_fid_alloc(lmv, fid, mds);
1057 CERROR("Can't alloc new fid, rc %d\n", rc);
1064 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1066 struct lmv_obd *lmv = &obd->u.lmv;
1067 struct lprocfs_static_vars lvars;
1068 struct lmv_desc *desc;
1072 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1073 CERROR("LMV setup requires a descriptor\n");
1077 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1078 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1079 CERROR("Lmv descriptor size wrong: %d > %d\n",
1080 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1084 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * 32);
1085 if (lmv->tgts == NULL)
1087 lmv->tgts_size = 32;
1089 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1090 lmv->desc.ld_tgt_count = 0;
1091 lmv->desc.ld_active_tgt_count = 0;
1092 lmv->max_cookiesize = 0;
1093 lmv->max_def_easize = 0;
1094 lmv->max_easize = 0;
1095 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1097 spin_lock_init(&lmv->lmv_lock);
1098 mutex_init(&lmv->init_mutex);
1100 lprocfs_lmv_init_vars(&lvars);
1102 lprocfs_obd_setup(obd, lvars.obd_vars);
1105 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1106 0444, &lmv_proc_target_fops, obd);
1108 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1112 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1113 LUSTRE_CLI_FLD_HASH_DHT);
1115 CERROR("Can't init FLD, err %d\n", rc);
1125 static int lmv_cleanup(struct obd_device *obd)
1127 struct lmv_obd *lmv = &obd->u.lmv;
1130 fld_client_fini(&lmv->lmv_fld);
1131 if (lmv->tgts != NULL) {
1133 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1134 if (lmv->tgts[i] == NULL)
1136 lmv_del_target(lmv, i);
1138 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1144 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
1146 struct lustre_cfg *lcfg = buf;
1147 struct obd_uuid obd_uuid;
1153 switch (lcfg->lcfg_command) {
1155 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1156 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1157 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1158 GOTO(out, rc = -EINVAL);
1160 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1162 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
1163 GOTO(out, rc = -EINVAL);
1164 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1165 GOTO(out, rc = -EINVAL);
1166 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1169 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1170 GOTO(out, rc = -EINVAL);
1176 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1177 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1179 struct obd_device *obd = class_exp2obd(exp);
1180 struct lmv_obd *lmv = &obd->u.lmv;
1181 struct obd_statfs *temp;
1186 rc = lmv_check_connect(obd);
1190 OBD_ALLOC(temp, sizeof(*temp));
1194 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1195 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1198 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1201 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1202 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1204 GOTO(out_free_temp, rc);
1209 /* If the statfs is from mount, it will needs
1210 * retrieve necessary information from MDT0.
1211 * i.e. mount does not need the merged osfs
1213 * And also clients can be mounted as long as
1214 * MDT0 is in service*/
1215 if (flags & OBD_STATFS_FOR_MDT0)
1216 GOTO(out_free_temp, rc);
1218 osfs->os_bavail += temp->os_bavail;
1219 osfs->os_blocks += temp->os_blocks;
1220 osfs->os_ffree += temp->os_ffree;
1221 osfs->os_files += temp->os_files;
1227 OBD_FREE(temp, sizeof(*temp));
1231 static int lmv_getstatus(struct obd_export *exp,
1233 struct obd_capa **pc)
1235 struct obd_device *obd = exp->exp_obd;
1236 struct lmv_obd *lmv = &obd->u.lmv;
1240 rc = lmv_check_connect(obd);
1244 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
1248 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1249 struct obd_capa *oc, obd_valid valid, const char *name,
1250 const char *input, int input_size, int output_size,
1251 int flags, struct ptlrpc_request **request)
1253 struct obd_device *obd = exp->exp_obd;
1254 struct lmv_obd *lmv = &obd->u.lmv;
1255 struct lmv_tgt_desc *tgt;
1259 rc = lmv_check_connect(obd);
1263 tgt = lmv_find_target(lmv, fid);
1265 RETURN(PTR_ERR(tgt));
1267 rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1268 input_size, output_size, flags, request);
1273 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1274 struct obd_capa *oc, obd_valid valid, const char *name,
1275 const char *input, int input_size, int output_size,
1276 int flags, __u32 suppgid,
1277 struct ptlrpc_request **request)
1279 struct obd_device *obd = exp->exp_obd;
1280 struct lmv_obd *lmv = &obd->u.lmv;
1281 struct lmv_tgt_desc *tgt;
1285 rc = lmv_check_connect(obd);
1289 tgt = lmv_find_target(lmv, fid);
1291 RETURN(PTR_ERR(tgt));
1293 rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1294 input_size, output_size, flags, suppgid,
1300 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1301 struct ptlrpc_request **request)
1303 struct obd_device *obd = exp->exp_obd;
1304 struct lmv_obd *lmv = &obd->u.lmv;
1305 struct lmv_tgt_desc *tgt;
1309 rc = lmv_check_connect(obd);
1313 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1315 RETURN(PTR_ERR(tgt));
1317 if (op_data->op_flags & MF_GET_MDT_IDX) {
1318 op_data->op_mds = tgt->ltd_idx;
1322 rc = md_getattr(tgt->ltd_exp, op_data, request);
1327 static int lmv_change_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1328 ldlm_iterator_t it, void *data)
1330 struct obd_device *obd = exp->exp_obd;
1331 struct lmv_obd *lmv = &obd->u.lmv;
1336 rc = lmv_check_connect(obd);
1340 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1343 * With DNE every object can have two locks in different namespaces:
1344 * lookup lock in space of MDT storing direntry and update/open lock in
1345 * space of MDT storing inode.
1347 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1348 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1350 md_change_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1356 static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1357 ldlm_iterator_t it, void *data)
1359 struct obd_device *obd = exp->exp_obd;
1360 struct lmv_obd *lmv = &obd->u.lmv;
1365 rc = lmv_check_connect(obd);
1369 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1372 * With DNE every object can have two locks in different namespaces:
1373 * lookup lock in space of MDT storing direntry and update/open lock in
1374 * space of MDT storing inode.
1376 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1377 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1379 rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1388 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1389 struct md_open_data *mod, struct ptlrpc_request **request)
1391 struct obd_device *obd = exp->exp_obd;
1392 struct lmv_obd *lmv = &obd->u.lmv;
1393 struct lmv_tgt_desc *tgt;
1397 rc = lmv_check_connect(obd);
1401 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1403 RETURN(PTR_ERR(tgt));
1405 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1406 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1411 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1414 struct lmv_tgt_desc *tgt;
1416 tgt = lmv_find_target(lmv, fid);
1417 op_data->op_mds = tgt->ltd_idx;
1422 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1423 const void *data, int datalen, int mode, __u32 uid,
1424 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1425 struct ptlrpc_request **request)
1427 struct obd_device *obd = exp->exp_obd;
1428 struct lmv_obd *lmv = &obd->u.lmv;
1429 struct lmv_tgt_desc *tgt;
1433 rc = lmv_check_connect(obd);
1437 if (!lmv->desc.ld_active_tgt_count)
1440 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1442 RETURN(PTR_ERR(tgt));
1444 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1448 CDEBUG(D_INODE, "CREATE '%*s' on "DFID" -> mds #%x\n",
1449 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1452 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1453 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1454 cap_effective, rdev, request);
1457 if (*request == NULL)
1459 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1464 static int lmv_done_writing(struct obd_export *exp,
1465 struct md_op_data *op_data,
1466 struct md_open_data *mod)
1468 struct obd_device *obd = exp->exp_obd;
1469 struct lmv_obd *lmv = &obd->u.lmv;
1470 struct lmv_tgt_desc *tgt;
1474 rc = lmv_check_connect(obd);
1478 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1480 RETURN(PTR_ERR(tgt));
1482 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1487 lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1488 struct lookup_intent *it, struct md_op_data *op_data,
1489 struct lustre_handle *lockh, void *lmm, int lmmsize,
1490 int extra_lock_flags)
1492 struct ptlrpc_request *req = it->d.lustre.it_data;
1493 struct obd_device *obd = exp->exp_obd;
1494 struct lmv_obd *lmv = &obd->u.lmv;
1495 struct lustre_handle plock;
1496 struct lmv_tgt_desc *tgt;
1497 struct md_op_data *rdata;
1499 struct mdt_body *body;
1504 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1505 LASSERT(body != NULL);
1507 if (!(body->valid & OBD_MD_MDS))
1510 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1511 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1514 * We got LOOKUP lock, but we really need attrs.
1516 pmode = it->d.lustre.it_lock_mode;
1517 LASSERT(pmode != 0);
1518 memcpy(&plock, lockh, sizeof(plock));
1519 it->d.lustre.it_lock_mode = 0;
1520 it->d.lustre.it_data = NULL;
1523 it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
1524 ptlrpc_req_finished(req);
1526 tgt = lmv_find_target(lmv, &fid1);
1528 GOTO(out, rc = PTR_ERR(tgt));
1530 OBD_ALLOC_PTR(rdata);
1532 GOTO(out, rc = -ENOMEM);
1534 rdata->op_fid1 = fid1;
1535 rdata->op_bias = MDS_CROSS_REF;
1537 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1538 lmm, lmmsize, NULL, extra_lock_flags);
1539 OBD_FREE_PTR(rdata);
1542 ldlm_lock_decref(&plock, pmode);
1547 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1548 struct lookup_intent *it, struct md_op_data *op_data,
1549 struct lustre_handle *lockh, void *lmm, int lmmsize,
1550 struct ptlrpc_request **req, __u64 extra_lock_flags)
1552 struct obd_device *obd = exp->exp_obd;
1553 struct lmv_obd *lmv = &obd->u.lmv;
1554 struct lmv_tgt_desc *tgt;
1558 rc = lmv_check_connect(obd);
1562 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1563 LL_IT2STR(it), PFID(&op_data->op_fid1));
1565 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1567 RETURN(PTR_ERR(tgt));
1569 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1570 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1572 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1573 lmm, lmmsize, req, extra_lock_flags);
1575 if (rc == 0 && it && it->it_op == IT_OPEN) {
1576 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1577 lmm, lmmsize, extra_lock_flags);
1583 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1584 struct ptlrpc_request **request)
1586 struct ptlrpc_request *req = NULL;
1587 struct obd_device *obd = exp->exp_obd;
1588 struct lmv_obd *lmv = &obd->u.lmv;
1589 struct lmv_tgt_desc *tgt;
1590 struct mdt_body *body;
1594 rc = lmv_check_connect(obd);
1598 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1600 RETURN(PTR_ERR(tgt));
1602 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1603 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1606 rc = md_getattr_name(tgt->ltd_exp, op_data, request);
1610 body = req_capsule_server_get(&(*request)->rq_pill,
1612 LASSERT(body != NULL);
1614 if (body->valid & OBD_MD_MDS) {
1615 struct lu_fid rid = body->fid1;
1616 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1619 tgt = lmv_find_target(lmv, &rid);
1621 ptlrpc_req_finished(*request);
1622 RETURN(PTR_ERR(tgt));
1625 op_data->op_fid1 = rid;
1626 op_data->op_valid |= OBD_MD_FLCROSSREF;
1627 op_data->op_namelen = 0;
1628 op_data->op_name = NULL;
1629 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1630 ptlrpc_req_finished(*request);
1637 #define md_op_data_fid(op_data, fl) \
1638 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1639 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1640 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1641 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1644 static int lmv_early_cancel(struct obd_export *exp, struct md_op_data *op_data,
1645 int op_tgt, ldlm_mode_t mode, int bits, int flag)
1647 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1648 struct obd_device *obd = exp->exp_obd;
1649 struct lmv_obd *lmv = &obd->u.lmv;
1650 struct lmv_tgt_desc *tgt;
1651 ldlm_policy_data_t policy = {{0}};
1655 if (!fid_is_sane(fid))
1658 tgt = lmv_find_target(lmv, fid);
1660 RETURN(PTR_ERR(tgt));
1662 if (tgt->ltd_idx != op_tgt) {
1663 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1664 policy.l_inodebits.bits = bits;
1665 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1666 mode, LCF_ASYNC, NULL);
1669 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1671 op_data->op_flags |= flag;
1679 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1682 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1683 struct ptlrpc_request **request)
1685 struct obd_device *obd = exp->exp_obd;
1686 struct lmv_obd *lmv = &obd->u.lmv;
1687 struct lmv_tgt_desc *tgt;
1691 rc = lmv_check_connect(obd);
1695 LASSERT(op_data->op_namelen != 0);
1697 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1698 PFID(&op_data->op_fid2), op_data->op_namelen,
1699 op_data->op_name, PFID(&op_data->op_fid1));
1701 op_data->op_fsuid = cfs_curproc_fsuid();
1702 op_data->op_fsgid = cfs_curproc_fsgid();
1703 op_data->op_cap = cfs_curproc_cap_pack();
1704 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1706 RETURN(PTR_ERR(tgt));
1709 * Cancel UPDATE lock on child (fid1).
1711 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1712 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
1713 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1717 rc = md_link(tgt->ltd_exp, op_data, request);
1722 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1723 const char *old, int oldlen, const char *new, int newlen,
1724 struct ptlrpc_request **request)
1726 struct obd_device *obd = exp->exp_obd;
1727 struct lmv_obd *lmv = &obd->u.lmv;
1728 struct lmv_tgt_desc *src_tgt;
1729 struct lmv_tgt_desc *tgt_tgt;
1733 LASSERT(oldlen != 0);
1735 CDEBUG(D_INODE, "RENAME %*s in "DFID" to %*s in "DFID"\n",
1736 oldlen, old, PFID(&op_data->op_fid1),
1737 newlen, new, PFID(&op_data->op_fid2));
1739 rc = lmv_check_connect(obd);
1743 op_data->op_fsuid = cfs_curproc_fsuid();
1744 op_data->op_fsgid = cfs_curproc_fsgid();
1745 op_data->op_cap = cfs_curproc_cap_pack();
1746 src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1747 if (IS_ERR(src_tgt))
1748 RETURN(PTR_ERR(src_tgt));
1750 tgt_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1751 if (IS_ERR(tgt_tgt))
1752 RETURN(PTR_ERR(tgt_tgt));
1754 * LOOKUP lock on src child (fid3) should also be cancelled for
1755 * src_tgt in mdc_rename.
1757 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
1760 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
1763 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1764 LCK_EX, MDS_INODELOCK_UPDATE,
1765 MF_MDC_CANCEL_FID2);
1768 * Cancel LOOKUP locks on tgt child (fid4) for parent tgt_tgt.
1771 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1772 LCK_EX, MDS_INODELOCK_LOOKUP,
1773 MF_MDC_CANCEL_FID4);
1777 * Cancel all the locks on tgt child (fid4).
1780 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1781 LCK_EX, MDS_INODELOCK_FULL,
1782 MF_MDC_CANCEL_FID4);
1785 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen,
1786 new, newlen, request);
1790 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
1791 void *ea, int ealen, void *ea2, int ea2len,
1792 struct ptlrpc_request **request,
1793 struct md_open_data **mod)
1795 struct obd_device *obd = exp->exp_obd;
1796 struct lmv_obd *lmv = &obd->u.lmv;
1797 struct lmv_tgt_desc *tgt;
1801 rc = lmv_check_connect(obd);
1805 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
1806 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
1808 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1809 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1811 RETURN(PTR_ERR(tgt));
1813 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
1814 ea2len, request, mod);
1819 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
1820 struct obd_capa *oc, struct ptlrpc_request **request)
1822 struct obd_device *obd = exp->exp_obd;
1823 struct lmv_obd *lmv = &obd->u.lmv;
1824 struct lmv_tgt_desc *tgt;
1828 rc = lmv_check_connect(obd);
1832 tgt = lmv_find_target(lmv, fid);
1834 RETURN(PTR_ERR(tgt));
1836 rc = md_sync(tgt->ltd_exp, fid, oc, request);
1840 static int lmv_readpage(struct obd_export *exp, struct md_op_data *op_data,
1841 struct page **pages, struct ptlrpc_request **request)
1843 struct obd_device *obd = exp->exp_obd;
1844 struct lmv_obd *lmv = &obd->u.lmv;
1845 __u64 offset = op_data->op_offset;
1848 /* number of pages read, in CFS_PAGE_SIZE */
1850 /* number of pages transferred in LU_PAGE_SIZE */
1852 struct lmv_tgt_desc *tgt;
1853 struct lu_dirpage *dp;
1854 struct lu_dirent *ent;
1857 rc = lmv_check_connect(obd);
1861 CDEBUG(D_INODE, "READPAGE at "LPX64" from "DFID"\n",
1862 offset, PFID(&op_data->op_fid1));
1865 * This case handle directory lookup in clustered metadata case (i.e.
1866 * split directory is located on multiple md servers.)
1867 * each server keeps directory entries for certain range of hashes.
1868 * E.g. we have N server and suppose hash range is 0 to MAX_HASH.
1869 * first server will keep records with hashes [ 0 ... MAX_HASH /N - 1],
1870 * second one with hashes [MAX_HASH / N ... 2 * MAX_HASH / N] and
1872 * readdir can simply start reading entries from 0 - N server in
1873 * order but that will not scale well as all client will request dir in
1874 * to server in same order.
1875 * Following algorithm does optimization:
1876 * Instead of doing readdir in 1, 2, ...., N order, client with a
1877 * rank R does readdir in R, R + 1, ..., N, 1, ... R - 1 order.
1878 * (every client has rank R)
1879 * But ll_readdir() expect offset range [0 to MAX_HASH/N) but
1880 * since client ask dir from MDS{R} client has pages with offsets
1881 * [R*MAX_HASH/N ... (R + 1)*MAX_HASH/N] there for we do hash_adj
1882 * on hash values that we get.
1883 * Since these codes might be still useful for sharded directory, so
1884 * Keeping this code for further reference
1887 seg_size = MAX_HASH_SIZE;
1888 do_div(seg_size, nr);
1889 los = obj->lo_stripes;
1890 tgt = lmv_get_target(lmv, los[0].ls_mds);
1891 rank = lmv_node_rank(tgt->ltd_exp, fid) % nr;
1893 do_div(tgt_tmp, seg_size);
1894 tgt0_idx = do_div(tgt_tmp, nr);
1895 tgt_idx = (tgt0_idx + rank) % nr;
1897 if (tgt_idx < tgt0_idx)
1900 * Last segment has unusual length due to division
1902 hash_adj = MAX_HASH_SIZE - seg_size * nr;
1906 hash_adj += rank * seg_size;
1908 CDEBUG(D_INODE, "Readpage hash adjustment: %x "LPX64" "
1909 LPX64"/%x -> "LPX64"/%x\n", rank, hash_adj,
1910 offset, tgt0_idx, offset + hash_adj, tgt_idx);
1912 offset = (offset + hash_adj) & MAX_HASH_SIZE;
1913 rid = lsm->mea_oinfo[tgt_idx].lmo_fid;
1914 tgt = lmv_get_target(lmv, lsm->mea_oinfo[tgt_idx].lmo_mds);
1916 CDEBUG(D_INODE, "Forward to "DFID" with offset %lu i %d\n",
1917 PFID(&rid), (unsigned long)offset, tgt_idx);
1920 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1922 RETURN(PTR_ERR(tgt));
1924 rc = md_readpage(tgt->ltd_exp, op_data, pages, request);
1928 nrdpgs = ((*request)->rq_bulk->bd_nob_transferred + CFS_PAGE_SIZE - 1)
1930 nlupgs = (*request)->rq_bulk->bd_nob_transferred >> LU_PAGE_SHIFT;
1931 LASSERT(!((*request)->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK));
1932 LASSERT(nrdpgs > 0 && nrdpgs <= op_data->op_npages);
1934 CDEBUG(D_INODE, "read %d(%d)/%d pages\n", nrdpgs, nlupgs,
1935 op_data->op_npages);
1937 for (i = 0; i < nrdpgs; i++) {
1938 #if CFS_PAGE_SIZE > LU_PAGE_SIZE
1939 struct lu_dirpage *first;
1943 struct lu_dirent *tmp = NULL;
1945 dp = cfs_kmap(pages[i]);
1946 ent = lu_dirent_start(dp);
1947 #if CFS_PAGE_SIZE > LU_PAGE_SIZE
1949 hash_end = dp->ldp_hash_end;
1954 for (tmp = ent; ent != NULL;
1955 tmp = ent, ent = lu_dirent_next(ent));
1956 #if CFS_PAGE_SIZE > LU_PAGE_SIZE
1957 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
1958 if (((unsigned long)dp & ~CFS_PAGE_MASK) && nlupgs > 0) {
1959 ent = lu_dirent_start(dp);
1962 /* enlarge the end entry lde_reclen from 0 to
1963 * first entry of next lu_dirpage, in this way
1964 * several lu_dirpages can be stored into one
1965 * client page on client. */
1966 tmp = ((void *)tmp) +
1967 le16_to_cpu(tmp->lde_reclen);
1969 cpu_to_le16((char *)(dp->ldp_entries) -
1974 first->ldp_hash_end = hash_end;
1975 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
1976 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
1978 SET_BUT_UNUSED(tmp);
1980 cfs_kunmap(pages[i]);
1985 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
1986 struct ptlrpc_request **request)
1988 struct obd_device *obd = exp->exp_obd;
1989 struct lmv_obd *lmv = &obd->u.lmv;
1990 struct lmv_tgt_desc *tgt = NULL;
1991 struct mdt_body *body;
1995 rc = lmv_check_connect(obd);
1999 /* Send unlink requests to the MDT where the child is located */
2000 if (likely(!fid_is_zero(&op_data->op_fid2)))
2001 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2003 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2005 RETURN(PTR_ERR(tgt));
2007 op_data->op_fsuid = cfs_curproc_fsuid();
2008 op_data->op_fsgid = cfs_curproc_fsgid();
2009 op_data->op_cap = cfs_curproc_cap_pack();
2012 * If child's fid is given, cancel unused locks for it if it is from
2013 * another export than parent.
2015 * LOOKUP lock for child (fid3) should also be cancelled on parent
2016 * tgt_tgt in mdc_unlink().
2018 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2021 * Cancel FULL locks on child (fid3).
2023 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
2024 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2029 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n",
2030 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2032 rc = md_unlink(tgt->ltd_exp, op_data, request);
2033 if (rc != 0 && rc != -EREMOTE)
2036 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2040 /* Not cross-ref case, just get out of here. */
2041 if (likely(!(body->valid & OBD_MD_MDS)))
2044 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2045 exp->exp_obd->obd_name, PFID(&body->fid1));
2047 /* This is a remote object, try remote MDT, Note: it may
2048 * try more than 1 time here, Considering following case
2049 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2050 * 1. Initially A does not know where remote1 is, it send
2051 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2052 * resend unlink RPC to MDT1 (retry 1st time).
2054 * 2. During the unlink RPC in flight,
2055 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2056 * and create new remote1, but on MDT0
2058 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2059 * /mnt/lustre, then lookup get fid of remote1, and find
2060 * it is remote dir again, and replay -EREMOTE again.
2062 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2064 * In theory, it might try unlimited time here, but it should
2065 * be very rare case. */
2066 op_data->op_fid2 = body->fid1;
2067 ptlrpc_req_finished(*request);
2073 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2075 struct lmv_obd *lmv = &obd->u.lmv;
2079 case OBD_CLEANUP_EARLY:
2080 /* XXX: here should be calling obd_precleanup() down to
2083 case OBD_CLEANUP_EXPORTS:
2084 fld_client_proc_fini(&lmv->lmv_fld);
2085 lprocfs_obd_cleanup(obd);
2093 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2094 __u32 keylen, void *key, __u32 *vallen, void *val,
2095 struct lov_stripe_md *lsm)
2097 struct obd_device *obd;
2098 struct lmv_obd *lmv;
2102 obd = class_exp2obd(exp);
2104 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2105 exp->exp_handle.h_cookie);
2110 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2111 struct lmv_tgt_desc *tgt;
2114 rc = lmv_check_connect(obd);
2118 LASSERT(*vallen == sizeof(__u32));
2119 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2122 * All tgts should be connected when this gets called.
2124 if (tgt == NULL || tgt->ltd_exp == NULL)
2127 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2132 } else if (KEY_IS(KEY_MAX_EASIZE) || KEY_IS(KEY_CONN_DATA)) {
2133 rc = lmv_check_connect(obd);
2138 * Forwarding this request to first MDS, it should know LOV
2141 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2143 if (!rc && KEY_IS(KEY_CONN_DATA))
2144 exp->exp_connect_data = *(struct obd_connect_data *)val;
2146 } else if (KEY_IS(KEY_TGT_COUNT)) {
2147 *((int *)val) = lmv->desc.ld_tgt_count;
2151 CDEBUG(D_IOCTL, "Invalid key\n");
2155 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2156 obd_count keylen, void *key, obd_count vallen,
2157 void *val, struct ptlrpc_request_set *set)
2159 struct lmv_tgt_desc *tgt;
2160 struct obd_device *obd;
2161 struct lmv_obd *lmv;
2165 obd = class_exp2obd(exp);
2167 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2168 exp->exp_handle.h_cookie);
2173 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) {
2176 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2179 if (tgt == NULL || tgt->ltd_exp == NULL)
2182 err = obd_set_info_async(env, tgt->ltd_exp,
2183 keylen, key, vallen, val, set);
2194 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2195 struct lov_stripe_md *lsm)
2197 struct obd_device *obd = class_exp2obd(exp);
2198 struct lmv_obd *lmv = &obd->u.lmv;
2199 struct lmv_stripe_md *meap;
2200 struct lmv_stripe_md *lsmp;
2205 mea_size = lmv_get_easize(lmv);
2209 if (*lmmp && !lsm) {
2210 OBD_FREE_LARGE(*lmmp, mea_size);
2215 if (*lmmp == NULL) {
2216 OBD_ALLOC_LARGE(*lmmp, mea_size);
2224 lsmp = (struct lmv_stripe_md *)lsm;
2225 meap = (struct lmv_stripe_md *)*lmmp;
2227 if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR &&
2228 lsmp->mea_magic != MEA_MAGIC_ALL_CHARS)
2231 meap->mea_magic = cpu_to_le32(lsmp->mea_magic);
2232 meap->mea_count = cpu_to_le32(lsmp->mea_count);
2233 meap->mea_master = cpu_to_le32(lsmp->mea_master);
2235 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2236 meap->mea_ids[i] = meap->mea_ids[i];
2237 fid_cpu_to_le(&meap->mea_ids[i], &meap->mea_ids[i]);
2243 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2244 struct lov_mds_md *lmm, int lmm_size)
2246 struct obd_device *obd = class_exp2obd(exp);
2247 struct lmv_stripe_md **tmea = (struct lmv_stripe_md **)lsmp;
2248 struct lmv_stripe_md *mea = (struct lmv_stripe_md *)lmm;
2249 struct lmv_obd *lmv = &obd->u.lmv;
2255 mea_size = lmv_get_easize(lmv);
2259 if (*lsmp != NULL && lmm == NULL) {
2260 OBD_FREE_LARGE(*tmea, mea_size);
2265 LASSERT(mea_size == lmm_size);
2267 OBD_ALLOC_LARGE(*tmea, mea_size);
2274 if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
2275 mea->mea_magic == MEA_MAGIC_ALL_CHARS ||
2276 mea->mea_magic == MEA_MAGIC_HASH_SEGMENT)
2278 magic = le32_to_cpu(mea->mea_magic);
2281 * Old mea is not handled here.
2283 CERROR("Old not supportable EA is found\n");
2287 (*tmea)->mea_magic = magic;
2288 (*tmea)->mea_count = le32_to_cpu(mea->mea_count);
2289 (*tmea)->mea_master = le32_to_cpu(mea->mea_master);
2291 for (i = 0; i < (*tmea)->mea_count; i++) {
2292 (*tmea)->mea_ids[i] = mea->mea_ids[i];
2293 fid_le_to_cpu(&(*tmea)->mea_ids[i], &(*tmea)->mea_ids[i]);
2298 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2299 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2300 ldlm_cancel_flags_t flags, void *opaque)
2302 struct obd_device *obd = exp->exp_obd;
2303 struct lmv_obd *lmv = &obd->u.lmv;
2309 LASSERT(fid != NULL);
2311 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2312 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL ||
2313 lmv->tgts[i]->ltd_active == 0)
2316 err = md_cancel_unused(lmv->tgts[i]->ltd_exp, fid,
2317 policy, mode, flags, opaque);
2324 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
2327 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2331 rc = md_set_lock_data(lmv->tgts[0]->ltd_exp, lockh, data, bits);
2335 ldlm_mode_t lmv_lock_match(struct obd_export *exp, __u64 flags,
2336 const struct lu_fid *fid, ldlm_type_t type,
2337 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2338 struct lustre_handle *lockh)
2340 struct obd_device *obd = exp->exp_obd;
2341 struct lmv_obd *lmv = &obd->u.lmv;
2346 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2349 * With CMD every object can have two locks in different namespaces:
2350 * lookup lock in space of mds storing direntry and update/open lock in
2351 * space of mds storing inode. Thus we check all targets, not only that
2352 * one fid was created in.
2354 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2355 if (lmv->tgts[i] == NULL ||
2356 lmv->tgts[i]->ltd_exp == NULL ||
2357 lmv->tgts[i]->ltd_active == 0)
2360 rc = md_lock_match(lmv->tgts[i]->ltd_exp, flags, fid,
2361 type, policy, mode, lockh);
2369 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2370 struct obd_export *dt_exp, struct obd_export *md_exp,
2371 struct lustre_md *md)
2373 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2375 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
2378 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2380 struct obd_device *obd = exp->exp_obd;
2381 struct lmv_obd *lmv = &obd->u.lmv;
2385 obd_free_memmd(exp, (void *)&md->mea);
2386 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
2389 int lmv_set_open_replay_data(struct obd_export *exp,
2390 struct obd_client_handle *och,
2391 struct ptlrpc_request *open_req)
2393 struct obd_device *obd = exp->exp_obd;
2394 struct lmv_obd *lmv = &obd->u.lmv;
2395 struct lmv_tgt_desc *tgt;
2398 tgt = lmv_find_target(lmv, &och->och_fid);
2400 RETURN(PTR_ERR(tgt));
2402 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, open_req));
2405 int lmv_clear_open_replay_data(struct obd_export *exp,
2406 struct obd_client_handle *och)
2408 struct obd_device *obd = exp->exp_obd;
2409 struct lmv_obd *lmv = &obd->u.lmv;
2410 struct lmv_tgt_desc *tgt;
2413 tgt = lmv_find_target(lmv, &och->och_fid);
2415 RETURN(PTR_ERR(tgt));
2417 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
2420 static int lmv_get_remote_perm(struct obd_export *exp,
2421 const struct lu_fid *fid,
2422 struct obd_capa *oc, __u32 suppgid,
2423 struct ptlrpc_request **request)
2425 struct obd_device *obd = exp->exp_obd;
2426 struct lmv_obd *lmv = &obd->u.lmv;
2427 struct lmv_tgt_desc *tgt;
2431 rc = lmv_check_connect(obd);
2435 tgt = lmv_find_target(lmv, fid);
2437 RETURN(PTR_ERR(tgt));
2439 rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
2443 static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
2446 struct obd_device *obd = exp->exp_obd;
2447 struct lmv_obd *lmv = &obd->u.lmv;
2448 struct lmv_tgt_desc *tgt;
2452 rc = lmv_check_connect(obd);
2456 tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
2458 RETURN(PTR_ERR(tgt));
2460 rc = md_renew_capa(tgt->ltd_exp, oc, cb);
2464 int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
2465 const struct req_msg_field *field, struct obd_capa **oc)
2467 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2469 return md_unpack_capa(lmv->tgts[0]->ltd_exp, req, field, oc);
2472 int lmv_intent_getattr_async(struct obd_export *exp,
2473 struct md_enqueue_info *minfo,
2474 struct ldlm_enqueue_info *einfo)
2476 struct md_op_data *op_data = &minfo->mi_data;
2477 struct obd_device *obd = exp->exp_obd;
2478 struct lmv_obd *lmv = &obd->u.lmv;
2479 struct lmv_tgt_desc *tgt = NULL;
2483 rc = lmv_check_connect(obd);
2487 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2489 RETURN(PTR_ERR(tgt));
2491 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
2495 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
2496 struct lu_fid *fid, __u64 *bits)
2498 struct obd_device *obd = exp->exp_obd;
2499 struct lmv_obd *lmv = &obd->u.lmv;
2500 struct lmv_tgt_desc *tgt;
2504 rc = lmv_check_connect(obd);
2508 tgt = lmv_find_target(lmv, fid);
2510 RETURN(PTR_ERR(tgt));
2512 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
2517 * For lmv, only need to send request to master MDT, and the master MDT will
2518 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
2519 * we directly fetch data from the slave MDTs.
2521 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
2522 struct obd_quotactl *oqctl)
2524 struct obd_device *obd = class_exp2obd(exp);
2525 struct lmv_obd *lmv = &obd->u.lmv;
2526 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2528 __u64 curspace, curinodes;
2531 if (!lmv->desc.ld_tgt_count || !tgt->ltd_active) {
2532 CERROR("master lmv inactive\n");
2536 if (oqctl->qc_cmd != Q_GETOQUOTA) {
2537 rc = obd_quotactl(tgt->ltd_exp, oqctl);
2541 curspace = curinodes = 0;
2542 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2546 if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0)
2548 if (!tgt->ltd_active) {
2549 CDEBUG(D_HA, "mdt %d is inactive.\n", i);
2553 err = obd_quotactl(tgt->ltd_exp, oqctl);
2555 CERROR("getquota on mdt %d failed. %d\n", i, err);
2559 curspace += oqctl->qc_dqblk.dqb_curspace;
2560 curinodes += oqctl->qc_dqblk.dqb_curinodes;
2563 oqctl->qc_dqblk.dqb_curspace = curspace;
2564 oqctl->qc_dqblk.dqb_curinodes = curinodes;
2569 int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
2570 struct obd_quotactl *oqctl)
2572 struct obd_device *obd = class_exp2obd(exp);
2573 struct lmv_obd *lmv = &obd->u.lmv;
2574 struct lmv_tgt_desc *tgt;
2578 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2581 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
2582 CERROR("lmv idx %d inactive\n", i);
2586 err = obd_quotacheck(tgt->ltd_exp, oqctl);
2594 struct obd_ops lmv_obd_ops = {
2595 .o_owner = THIS_MODULE,
2596 .o_setup = lmv_setup,
2597 .o_cleanup = lmv_cleanup,
2598 .o_precleanup = lmv_precleanup,
2599 .o_process_config = lmv_process_config,
2600 .o_connect = lmv_connect,
2601 .o_disconnect = lmv_disconnect,
2602 .o_statfs = lmv_statfs,
2603 .o_get_info = lmv_get_info,
2604 .o_set_info_async = lmv_set_info_async,
2605 .o_packmd = lmv_packmd,
2606 .o_unpackmd = lmv_unpackmd,
2607 .o_notify = lmv_notify,
2608 .o_get_uuid = lmv_get_uuid,
2609 .o_iocontrol = lmv_iocontrol,
2610 .o_quotacheck = lmv_quotacheck,
2611 .o_quotactl = lmv_quotactl
2614 struct md_ops lmv_md_ops = {
2615 .m_getstatus = lmv_getstatus,
2616 .m_change_cbdata = lmv_change_cbdata,
2617 .m_find_cbdata = lmv_find_cbdata,
2618 .m_close = lmv_close,
2619 .m_create = lmv_create,
2620 .m_done_writing = lmv_done_writing,
2621 .m_enqueue = lmv_enqueue,
2622 .m_getattr = lmv_getattr,
2623 .m_getxattr = lmv_getxattr,
2624 .m_getattr_name = lmv_getattr_name,
2625 .m_intent_lock = lmv_intent_lock,
2627 .m_rename = lmv_rename,
2628 .m_setattr = lmv_setattr,
2629 .m_setxattr = lmv_setxattr,
2631 .m_readpage = lmv_readpage,
2632 .m_unlink = lmv_unlink,
2633 .m_init_ea_size = lmv_init_ea_size,
2634 .m_cancel_unused = lmv_cancel_unused,
2635 .m_set_lock_data = lmv_set_lock_data,
2636 .m_lock_match = lmv_lock_match,
2637 .m_get_lustre_md = lmv_get_lustre_md,
2638 .m_free_lustre_md = lmv_free_lustre_md,
2639 .m_set_open_replay_data = lmv_set_open_replay_data,
2640 .m_clear_open_replay_data = lmv_clear_open_replay_data,
2641 .m_renew_capa = lmv_renew_capa,
2642 .m_unpack_capa = lmv_unpack_capa,
2643 .m_get_remote_perm = lmv_get_remote_perm,
2644 .m_intent_getattr_async = lmv_intent_getattr_async,
2645 .m_revalidate_lock = lmv_revalidate_lock
2648 int __init lmv_init(void)
2650 struct lprocfs_static_vars lvars;
2653 lprocfs_lmv_init_vars(&lvars);
2655 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
2656 lvars.module_vars, LUSTRE_LMV_NAME, NULL);
2661 static void lmv_exit(void)
2663 class_unregister_type(LUSTRE_LMV_NAME);
2666 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2667 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
2668 MODULE_LICENSE("GPL");
2670 module_init(lmv_init);
2671 module_exit(lmv_exit);