1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 # define EXPORT_SYMTAB
40 #define DEBUG_SUBSYSTEM S_LMV
42 #include <linux/slab.h>
43 #include <linux/module.h>
44 #include <linux/init.h>
45 #include <linux/slab.h>
46 #include <linux/pagemap.h>
48 #include <asm/div64.h>
49 #include <linux/seq_file.h>
50 #include <linux/namei.h>
52 #include <liblustre.h>
55 #include <lustre/lustre_idl.h>
56 #include <lustre_log.h>
57 #include <obd_support.h>
58 #include <lustre_lib.h>
59 #include <lustre_net.h>
60 #include <obd_class.h>
61 #include <lprocfs_status.h>
62 #include <lustre_lite.h>
63 #include <lustre_fid.h>
64 #include "lmv_internal.h"
67 cfs_mem_cache_t *lmv_object_cache;
68 cfs_atomic_t lmv_object_count = CFS_ATOMIC_INIT(0);
70 static void lmv_activate_target(struct lmv_obd *lmv,
71 struct lmv_tgt_desc *tgt,
74 if (tgt->ltd_active == activate)
77 tgt->ltd_active = activate;
78 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
84 * -EINVAL : UUID can't be found in the LMV's target list
85 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
86 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
88 static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid,
91 struct lmv_tgt_desc *tgt;
92 struct obd_device *obd;
97 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
98 lmv, uuid->uuid, activate);
100 cfs_spin_lock(&lmv->lmv_lock);
101 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
102 if (tgt->ltd_exp == NULL)
105 CDEBUG(D_INFO, "Target idx %d is %s conn "LPX64"\n",
106 i, tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
108 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
112 if (i == lmv->desc.ld_tgt_count)
113 GOTO(out_lmv_lock, rc = -EINVAL);
115 obd = class_exp2obd(tgt->ltd_exp);
117 GOTO(out_lmv_lock, rc = -ENOTCONN);
119 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
120 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
121 obd->obd_type->typ_name, i);
122 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
124 if (tgt->ltd_active == activate) {
125 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
126 activate ? "" : "in");
127 GOTO(out_lmv_lock, rc);
130 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
131 activate ? "" : "in");
132 lmv_activate_target(lmv, tgt, activate);
136 cfs_spin_unlock(&lmv->lmv_lock);
140 static int lmv_set_mdc_data(struct lmv_obd *lmv, struct obd_uuid *uuid,
141 struct obd_connect_data *data)
143 struct lmv_tgt_desc *tgt;
147 LASSERT(data != NULL);
149 cfs_spin_lock(&lmv->lmv_lock);
150 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
151 if (tgt->ltd_exp == NULL)
154 if (obd_uuid_equals(uuid, &tgt->ltd_uuid)) {
155 lmv->datas[tgt->ltd_idx] = *data;
159 cfs_spin_unlock(&lmv->lmv_lock);
163 struct obd_uuid *lmv_get_uuid(struct obd_export *exp) {
164 struct obd_device *obd = exp->exp_obd;
165 struct lmv_obd *lmv = &obd->u.lmv;
166 return obd_get_uuid(lmv->tgts[0].ltd_exp);
169 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
170 enum obd_notify_event ev, void *data)
172 struct obd_connect_data *conn_data;
173 struct lmv_obd *lmv = &obd->u.lmv;
174 struct obd_uuid *uuid;
178 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
179 CERROR("unexpected notification of %s %s!\n",
180 watched->obd_type->typ_name,
185 uuid = &watched->u.cli.cl_target_uuid;
186 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
188 * Set MDC as active before notifying the observer, so the
189 * observer can use the MDC normally.
191 rc = lmv_set_mdc_active(lmv, uuid,
192 ev == OBD_NOTIFY_ACTIVE);
194 CERROR("%sactivation of %s failed: %d\n",
195 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
199 } else if (ev == OBD_NOTIFY_OCD) {
200 conn_data = &watched->u.cli.cl_import->imp_connect_data;
203 * Set connect data to desired target, update exp_connect_flags.
205 rc = lmv_set_mdc_data(lmv, uuid, conn_data);
207 CERROR("can't set connect data to target %s, rc %d\n",
213 * XXX: Make sure that ocd_connect_flags from all targets are
214 * the same. Otherwise one of MDTs runs wrong version or
215 * something like this. --umka
217 obd->obd_self_export->exp_connect_flags =
218 conn_data->ocd_connect_flags;
221 else if (ev == OBD_NOTIFY_DISCON) {
223 * For disconnect event, flush fld cache for failout MDS case.
225 fld_client_flush(&lmv->lmv_fld);
229 * Pass the notification up the chain.
231 if (obd->obd_observer)
232 rc = obd_notify(obd->obd_observer, watched, ev, data);
238 * This is fake connect function. Its purpose is to initialize lmv and say
239 * caller that everything is okay. Real connection will be performed later.
241 static int lmv_connect(const struct lu_env *env,
242 struct obd_export **exp, struct obd_device *obd,
243 struct obd_uuid *cluuid, struct obd_connect_data *data,
247 struct proc_dir_entry *lmv_proc_dir;
249 struct lmv_obd *lmv = &obd->u.lmv;
250 struct lustre_handle conn = { 0 };
255 * We don't want to actually do the underlying connections more than
256 * once, so keep track.
259 if (lmv->refcount > 1) {
264 rc = class_connect(&conn, obd, cluuid);
266 CERROR("class_connection() returned %d\n", rc);
270 *exp = class_conn2export(&conn);
271 class_export_get(*exp);
275 lmv->cluuid = *cluuid;
278 lmv->conn_data = *data;
281 lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
283 if (IS_ERR(lmv_proc_dir)) {
284 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
285 obd->obd_type->typ_name, obd->obd_name);
291 * All real clients should perform actual connection right away, because
292 * it is possible, that LMV will not have opportunity to connect targets
293 * and MDC stuff will be called directly, for instance while reading
294 * ../mdc/../kbytesfree procfs file, etc.
296 if (data->ocd_connect_flags & OBD_CONNECT_REAL)
297 rc = lmv_check_connect(obd);
302 lprocfs_remove(&lmv_proc_dir);
309 static void lmv_set_timeouts(struct obd_device *obd)
311 struct lmv_tgt_desc *tgts;
316 if (lmv->server_timeout == 0)
319 if (lmv->connected == 0)
322 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) {
323 if (tgts->ltd_exp == NULL)
326 obd_set_info_async(tgts->ltd_exp, sizeof(KEY_INTERMDS),
327 KEY_INTERMDS, 0, NULL, NULL);
331 static int lmv_init_ea_size(struct obd_export *exp, int easize,
332 int def_easize, int cookiesize)
334 struct obd_device *obd = exp->exp_obd;
335 struct lmv_obd *lmv = &obd->u.lmv;
341 if (lmv->max_easize < easize) {
342 lmv->max_easize = easize;
345 if (lmv->max_def_easize < def_easize) {
346 lmv->max_def_easize = def_easize;
349 if (lmv->max_cookiesize < cookiesize) {
350 lmv->max_cookiesize = cookiesize;
356 if (lmv->connected == 0)
359 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
360 if (lmv->tgts[i].ltd_exp == NULL) {
361 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
365 rc = md_init_ea_size(lmv->tgts[i].ltd_exp, easize, def_easize,
368 CERROR("obd_init_ea_size() failed on MDT target %d, "
369 "error %d.\n", i, rc);
376 #define MAX_STRING_SIZE 128
378 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
381 struct proc_dir_entry *lmv_proc_dir;
383 struct lmv_obd *lmv = &obd->u.lmv;
384 struct obd_uuid *cluuid = &lmv->cluuid;
385 struct obd_connect_data *mdc_data = NULL;
386 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
387 struct obd_device *mdc_obd;
388 struct obd_export *mdc_exp;
389 struct lu_fld_target target;
393 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
396 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
400 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
401 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
402 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
405 if (!mdc_obd->obd_set_up) {
406 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
410 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
411 &lmv->conn_data, NULL);
413 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
418 * Init fid sequence client for this mdc and add new fld target.
420 rc = obd_fid_init(mdc_exp);
424 target.ft_srv = NULL;
425 target.ft_exp = mdc_exp;
426 target.ft_idx = tgt->ltd_idx;
428 fld_client_add_target(&lmv->lmv_fld, &target);
430 mdc_data = &class_exp2cliimp(mdc_exp)->imp_connect_data;
432 rc = obd_register_observer(mdc_obd, obd);
434 obd_disconnect(mdc_exp);
435 CERROR("target %s register_observer error %d\n",
436 tgt->ltd_uuid.uuid, rc);
440 if (obd->obd_observer) {
442 * Tell the observer about the new target.
444 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
445 OBD_NOTIFY_ACTIVE, (void *)(tgt - lmv->tgts));
447 obd_disconnect(mdc_exp);
453 tgt->ltd_exp = mdc_exp;
454 lmv->desc.ld_active_tgt_count++;
457 * Copy connect data, it may be used later.
459 lmv->datas[tgt->ltd_idx] = *mdc_data;
461 md_init_ea_size(tgt->ltd_exp, lmv->max_easize,
462 lmv->max_def_easize, lmv->max_cookiesize);
464 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
465 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
466 cfs_atomic_read(&obd->obd_refcount));
469 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
471 struct proc_dir_entry *mdc_symlink;
472 char name[MAX_STRING_SIZE + 1];
474 LASSERT(mdc_obd->obd_type != NULL);
475 LASSERT(mdc_obd->obd_type->typ_name != NULL);
476 name[MAX_STRING_SIZE] = '\0';
477 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
478 mdc_obd->obd_type->typ_name,
480 mdc_symlink = proc_symlink(mdc_obd->obd_name,
482 if (mdc_symlink == NULL) {
483 CERROR("Could not register LMV target "
484 "/proc/fs/lustre/%s/%s/target_obds/%s.",
485 obd->obd_type->typ_name, obd->obd_name,
487 lprocfs_remove(&lmv_proc_dir);
495 int lmv_add_target(struct obd_device *obd, struct obd_uuid *tgt_uuid)
497 struct lmv_obd *lmv = &obd->u.lmv;
498 struct lmv_tgt_desc *tgt;
502 CDEBUG(D_CONFIG, "Target uuid: %s.\n", tgt_uuid->uuid);
506 if (lmv->desc.ld_active_tgt_count >= LMV_MAX_TGT_COUNT) {
507 lmv_init_unlock(lmv);
508 CERROR("Can't add %s, LMV module compiled for %d MDCs. "
509 "That many MDCs already configured.\n",
510 tgt_uuid->uuid, LMV_MAX_TGT_COUNT);
513 if (lmv->desc.ld_tgt_count == 0) {
514 struct obd_device *mdc_obd;
516 mdc_obd = class_find_client_obd(tgt_uuid, LUSTRE_MDC_NAME,
519 lmv_init_unlock(lmv);
520 CERROR("Target %s not attached\n", tgt_uuid->uuid);
524 rc = obd_llog_init(obd, &obd->obd_olg, mdc_obd, NULL);
526 lmv_init_unlock(lmv);
527 CERROR("lmv failed to setup llogging subsystems\n");
530 cfs_spin_lock(&lmv->lmv_lock);
531 tgt = lmv->tgts + lmv->desc.ld_tgt_count++;
532 tgt->ltd_uuid = *tgt_uuid;
533 cfs_spin_unlock(&lmv->lmv_lock);
535 if (lmv->connected) {
536 rc = lmv_connect_mdc(obd, tgt);
538 cfs_spin_lock(&lmv->lmv_lock);
539 lmv->desc.ld_tgt_count--;
540 memset(tgt, 0, sizeof(*tgt));
541 cfs_spin_unlock(&lmv->lmv_lock);
543 int easize = sizeof(struct lmv_stripe_md) +
544 lmv->desc.ld_tgt_count *
545 sizeof(struct lu_fid);
546 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
550 lmv_init_unlock(lmv);
554 int lmv_check_connect(struct obd_device *obd)
556 struct lmv_obd *lmv = &obd->u.lmv;
557 struct lmv_tgt_desc *tgt;
567 if (lmv->connected) {
568 lmv_init_unlock(lmv);
572 if (lmv->desc.ld_tgt_count == 0) {
573 CERROR("%s: no targets configured.\n", obd->obd_name);
577 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
578 lmv->cluuid.uuid, obd->obd_name);
580 LASSERT(lmv->tgts != NULL);
582 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
583 rc = lmv_connect_mdc(obd, tgt);
588 lmv_set_timeouts(obd);
589 class_export_put(lmv->exp);
591 easize = lmv_get_easize(lmv);
592 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
593 lmv_init_unlock(lmv);
602 --lmv->desc.ld_active_tgt_count;
603 rc2 = obd_disconnect(tgt->ltd_exp);
605 CERROR("LMV target %s disconnect on "
606 "MDC idx %d: error %d\n",
607 tgt->ltd_uuid.uuid, i, rc2);
611 class_disconnect(lmv->exp);
612 lmv_init_unlock(lmv);
616 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
619 struct proc_dir_entry *lmv_proc_dir;
621 struct lmv_obd *lmv = &obd->u.lmv;
622 struct obd_device *mdc_obd;
626 LASSERT(tgt != NULL);
627 LASSERT(obd != NULL);
629 mdc_obd = class_exp2obd(tgt->ltd_exp);
632 mdc_obd->obd_no_recov = obd->obd_no_recov;
635 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
637 struct proc_dir_entry *mdc_symlink;
639 mdc_symlink = lprocfs_srch(lmv_proc_dir, mdc_obd->obd_name);
641 lprocfs_remove(&mdc_symlink);
643 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing\n",
644 obd->obd_type->typ_name, obd->obd_name,
649 rc = obd_fid_fini(tgt->ltd_exp);
651 CERROR("Can't finanize fids factory\n");
653 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
654 tgt->ltd_exp->exp_obd->obd_name,
655 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
657 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
658 rc = obd_disconnect(tgt->ltd_exp);
660 if (tgt->ltd_active) {
661 CERROR("Target %s disconnect error %d\n",
662 tgt->ltd_uuid.uuid, rc);
666 lmv_activate_target(lmv, tgt, 0);
671 static int lmv_disconnect(struct obd_export *exp)
673 struct obd_device *obd = class_exp2obd(exp);
675 struct proc_dir_entry *lmv_proc_dir;
677 struct lmv_obd *lmv = &obd->u.lmv;
686 * Only disconnect the underlying layers on the final disconnect.
689 if (lmv->refcount != 0)
692 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
693 if (lmv->tgts[i].ltd_exp == NULL)
695 lmv_disconnect_mdc(obd, &lmv->tgts[i]);
699 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
701 lprocfs_remove(&lmv_proc_dir);
703 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
704 obd->obd_type->typ_name, obd->obd_name);
710 * This is the case when no real connection is established by
711 * lmv_check_connect().
714 class_export_put(exp);
715 rc = class_disconnect(exp);
716 if (lmv->refcount == 0)
721 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
722 int len, void *karg, void *uarg)
724 struct obd_device *obddev = class_exp2obd(exp);
725 struct lmv_obd *lmv = &obddev->u.lmv;
729 int count = lmv->desc.ld_tgt_count;
736 case IOC_OBD_STATFS: {
737 struct obd_ioctl_data *data = karg;
738 struct obd_device *mdc_obd;
739 struct obd_statfs stat_buf = {0};
742 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
743 LASSERT(data->ioc_plen1 == sizeof(struct obd_statfs));
745 if ((index >= count))
748 if (!lmv->tgts[index].ltd_active)
751 mdc_obd = class_exp2obd(lmv->tgts[index].ltd_exp);
755 rc = obd_statfs(mdc_obd, &stat_buf,
756 cfs_time_current_64() - CFS_HZ, 0);
759 if (cfs_copy_to_user(data->ioc_pbuf1, &stat_buf,
762 if (cfs_copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
767 case OBD_IOC_QUOTACTL: {
768 struct if_quotactl *qctl = karg;
769 struct lmv_tgt_desc *tgt = NULL;
770 struct obd_quotactl *oqctl;
772 if (qctl->qc_valid == QC_MDTIDX) {
773 if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
776 tgt = &lmv->tgts[qctl->qc_idx];
779 } else if (qctl->qc_valid == QC_UUID) {
780 for (i = 0; i < count; i++) {
782 if (!obd_uuid_equals(&tgt->ltd_uuid,
786 if (tgt->ltd_exp == NULL)
798 LASSERT(tgt && tgt->ltd_exp);
799 OBD_ALLOC_PTR(oqctl);
803 QCTL_COPY(oqctl, qctl);
804 rc = obd_quotactl(tgt->ltd_exp, oqctl);
806 QCTL_COPY(qctl, oqctl);
807 qctl->qc_valid = QC_MDTIDX;
808 qctl->obd_uuid = tgt->ltd_uuid;
813 case OBD_IOC_CHANGELOG_CLEAR: {
814 struct ioc_changelog_clear *icc = karg;
816 if (icc->icc_mdtindex >= count)
819 rc = obd_iocontrol(cmd, lmv->tgts[icc->icc_mdtindex].ltd_exp,
820 sizeof(*icc), icc, NULL);
825 for (i = 0; i < count; i++) {
828 if (lmv->tgts[i].ltd_exp == NULL)
831 err = obd_iocontrol(cmd, lmv->tgts[i].ltd_exp, len,
833 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
836 if (lmv->tgts[i].ltd_active) {
837 CERROR("error: iocontrol MDC %s on MDT"
838 "idx %d cmd %x: err = %d\n",
839 lmv->tgts[i].ltd_uuid.uuid,
854 static int lmv_all_chars_policy(int count, const char *name,
865 static int lmv_nid_policy(struct lmv_obd *lmv)
867 struct obd_import *imp;
871 * XXX: To get nid we assume that underlying obd device is mdc.
873 imp = class_exp2cliimp(lmv->tgts[0].ltd_exp);
874 id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32);
875 return id % lmv->desc.ld_tgt_count;
878 static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
879 placement_policy_t placement)
882 case PLACEMENT_CHAR_POLICY:
883 return lmv_all_chars_policy(lmv->desc.ld_tgt_count,
885 op_data->op_namelen);
886 case PLACEMENT_NID_POLICY:
887 return lmv_nid_policy(lmv);
893 CERROR("Unsupported placement policy %x\n", placement);
898 * This is _inode_ placement policy function (not name).
900 static int lmv_placement_policy(struct obd_device *obd,
901 struct md_op_data *op_data,
904 struct lmv_obd *lmv = &obd->u.lmv;
905 struct lmv_object *obj;
909 LASSERT(mds != NULL);
911 if (lmv->desc.ld_tgt_count == 1) {
917 * Allocate new fid on target according to operation type and parent
920 obj = lmv_object_find(obd, &op_data->op_fid1);
921 if (obj != NULL || op_data->op_name == NULL ||
922 op_data->op_opc != LUSTRE_OPC_MKDIR) {
924 * Allocate fid for non-dir or for null name or for case parent
931 * If we have this flag turned on, and we see that
932 * parent dir is split, this means, that caller did not
933 * notice split yet. This is race and we would like to
934 * let caller know that.
936 if (op_data->op_bias & MDS_CHECK_SPLIT)
941 * Allocate new fid on same mds where parent fid is located and
942 * where operation will be sent. In case of split dir, ->op_fid1
943 * and ->op_mds here will contain fid and mds of slave directory
944 * object (assigned by caller).
946 *mds = op_data->op_mds;
950 * Parent directory is not split and we want to create a
951 * directory in it. Let's calculate where to place it according
952 * to operation data @op_data.
954 *mds = lmv_choose_mds(lmv, op_data, lmv->lmv_placement);
959 CERROR("Can't choose MDS, err = %d\n", rc);
961 LASSERT(*mds < lmv->desc.ld_tgt_count);
967 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
970 struct lmv_tgt_desc *tgt;
974 tgt = lmv_get_target(lmv, mds);
977 * New seq alloc and FLD setup should be atomic. Otherwise we may find
978 * on server that seq in new allocated fid is not yet known.
980 cfs_down(&tgt->ltd_fid_sem);
982 if (!tgt->ltd_active)
983 GOTO(out, rc = -ENODEV);
986 * Asking underlaying tgt layer to allocate new fid.
988 rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL);
990 LASSERT(fid_is_sane(fid));
996 cfs_up(&tgt->ltd_fid_sem);
1000 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1001 struct md_op_data *op_data)
1003 struct obd_device *obd = class_exp2obd(exp);
1004 struct lmv_obd *lmv = &obd->u.lmv;
1009 LASSERT(op_data != NULL);
1010 LASSERT(fid != NULL);
1012 rc = lmv_placement_policy(obd, op_data, &mds);
1014 CERROR("Can't get target for allocating fid, "
1019 rc = __lmv_fid_alloc(lmv, fid, mds);
1021 CERROR("Can't alloc new fid, rc %d\n", rc);
1028 static int lmv_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
1031 LASSERT(exp != NULL && fid != NULL);
1032 if (lmv_object_delete(exp, fid)) {
1033 CDEBUG(D_INODE, "Object "DFID" is destroyed.\n",
1039 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1041 struct lmv_obd *lmv = &obd->u.lmv;
1042 struct lprocfs_static_vars lvars;
1043 struct lmv_desc *desc;
1048 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1049 CERROR("LMV setup requires a descriptor\n");
1053 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1054 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1055 CERROR("Lmv descriptor size wrong: %d > %d\n",
1056 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1060 lmv->tgts_size = LMV_MAX_TGT_COUNT * sizeof(struct lmv_tgt_desc);
1062 OBD_ALLOC(lmv->tgts, lmv->tgts_size);
1063 if (lmv->tgts == NULL)
1066 for (i = 0; i < LMV_MAX_TGT_COUNT; i++) {
1067 cfs_sema_init(&lmv->tgts[i].ltd_fid_sem, 1);
1068 lmv->tgts[i].ltd_idx = i;
1071 lmv->datas_size = LMV_MAX_TGT_COUNT * sizeof(struct obd_connect_data);
1073 OBD_ALLOC(lmv->datas, lmv->datas_size);
1074 if (lmv->datas == NULL)
1075 GOTO(out_free_tgts, rc = -ENOMEM);
1077 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1078 lmv->desc.ld_tgt_count = 0;
1079 lmv->desc.ld_active_tgt_count = 0;
1080 lmv->max_cookiesize = 0;
1081 lmv->max_def_easize = 0;
1082 lmv->max_easize = 0;
1083 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1085 cfs_spin_lock_init(&lmv->lmv_lock);
1086 cfs_sema_init(&lmv->init_sem, 1);
1088 rc = lmv_object_setup(obd);
1090 CERROR("Can't setup LMV object manager, error %d.\n", rc);
1091 GOTO(out_free_datas, rc);
1094 lprocfs_lmv_init_vars(&lvars);
1095 lprocfs_obd_setup(obd, lvars.obd_vars);
1098 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd_status",
1099 0444, &lmv_proc_target_fops, obd);
1101 CWARN("Error adding target_obd_stats file (%d)\n", rc);
1104 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1105 LUSTRE_CLI_FLD_HASH_DHT);
1107 CERROR("Can't init FLD, err %d\n", rc);
1108 GOTO(out_free_datas, rc);
1114 OBD_FREE(lmv->datas, lmv->datas_size);
1117 OBD_FREE(lmv->tgts, lmv->tgts_size);
1122 static int lmv_cleanup(struct obd_device *obd)
1124 struct lmv_obd *lmv = &obd->u.lmv;
1127 fld_client_fini(&lmv->lmv_fld);
1128 lprocfs_obd_cleanup(obd);
1129 lmv_object_cleanup(obd);
1130 OBD_FREE(lmv->datas, lmv->datas_size);
1131 OBD_FREE(lmv->tgts, lmv->tgts_size);
1136 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
1138 struct lustre_cfg *lcfg = buf;
1139 struct obd_uuid tgt_uuid;
1143 switch(lcfg->lcfg_command) {
1145 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(tgt_uuid.uuid))
1146 GOTO(out, rc = -EINVAL);
1148 obd_str2uuid(&tgt_uuid, lustre_cfg_string(lcfg, 1));
1149 rc = lmv_add_target(obd, &tgt_uuid);
1152 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1153 GOTO(out, rc = -EINVAL);
1160 static int lmv_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1161 __u64 max_age, __u32 flags)
1163 struct lmv_obd *lmv = &obd->u.lmv;
1164 struct obd_statfs *temp;
1169 rc = lmv_check_connect(obd);
1173 OBD_ALLOC(temp, sizeof(*temp));
1177 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1178 if (lmv->tgts[i].ltd_exp == NULL)
1181 rc = obd_statfs(lmv->tgts[i].ltd_exp->exp_obd, temp,
1184 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1185 lmv->tgts[i].ltd_exp->exp_obd->obd_name,
1187 GOTO(out_free_temp, rc);
1192 osfs->os_bavail += temp->os_bavail;
1193 osfs->os_blocks += temp->os_blocks;
1194 osfs->os_ffree += temp->os_ffree;
1195 osfs->os_files += temp->os_files;
1201 OBD_FREE(temp, sizeof(*temp));
1205 static int lmv_getstatus(struct obd_export *exp,
1207 struct obd_capa **pc)
1209 struct obd_device *obd = exp->exp_obd;
1210 struct lmv_obd *lmv = &obd->u.lmv;
1214 rc = lmv_check_connect(obd);
1218 rc = md_getstatus(lmv->tgts[0].ltd_exp, fid, pc);
1222 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1223 struct obd_capa *oc, obd_valid valid, const char *name,
1224 const char *input, int input_size, int output_size,
1225 int flags, struct ptlrpc_request **request)
1227 struct obd_device *obd = exp->exp_obd;
1228 struct lmv_obd *lmv = &obd->u.lmv;
1229 struct lmv_tgt_desc *tgt;
1233 rc = lmv_check_connect(obd);
1237 tgt = lmv_find_target(lmv, fid);
1239 RETURN(PTR_ERR(tgt));
1241 rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1242 input_size, output_size, flags, request);
1247 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1248 struct obd_capa *oc, obd_valid valid, const char *name,
1249 const char *input, int input_size, int output_size,
1250 int flags, __u32 suppgid,
1251 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_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1268 input_size, output_size, flags, suppgid,
1274 static int lmv_getattr(struct obd_export *exp, const struct lu_fid *fid,
1275 struct obd_capa *oc, obd_valid valid, int ea_size,
1276 struct ptlrpc_request **request)
1278 struct obd_device *obd = exp->exp_obd;
1279 struct lmv_obd *lmv = &obd->u.lmv;
1280 struct lmv_tgt_desc *tgt;
1281 struct lmv_object *obj;
1286 rc = lmv_check_connect(obd);
1290 tgt = lmv_find_target(lmv, fid);
1292 RETURN(PTR_ERR(tgt));
1294 rc = md_getattr(tgt->ltd_exp, fid, oc, valid, ea_size, request);
1298 obj = lmv_object_find_lock(obd, fid);
1300 CDEBUG(D_INODE, "GETATTR for "DFID" %s\n", PFID(fid),
1301 obj ? "(split)" : "");
1304 * If object is split, then we loop over all the slaves and gather size
1305 * attribute. In ideal world we would have to gather also mds field from
1306 * all slaves, as object is spread over the cluster and this is
1307 * definitely interesting information and it is not good to loss it,
1311 struct mdt_body *body;
1313 if (*request == NULL) {
1314 lmv_object_put(obj);
1318 body = req_capsule_server_get(&(*request)->rq_pill,
1320 LASSERT(body != NULL);
1322 for (i = 0; i < obj->lo_objcount; i++) {
1323 if (lmv->tgts[i].ltd_exp == NULL) {
1324 CWARN("%s: NULL export for %d\n",
1330 * Skip master object.
1332 if (lu_fid_eq(&obj->lo_fid, &obj->lo_stripes[i].ls_fid))
1335 body->size += obj->lo_stripes[i].ls_size;
1338 lmv_object_put_unlock(obj);
1344 static int lmv_change_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1345 ldlm_iterator_t it, void *data)
1347 struct obd_device *obd = exp->exp_obd;
1348 struct lmv_obd *lmv = &obd->u.lmv;
1353 rc = lmv_check_connect(obd);
1357 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1360 * With CMD every object can have two locks in different namespaces:
1361 * lookup lock in space of mds storing direntry and update/open lock in
1362 * space of mds storing inode.
1364 for (i = 0; i < lmv->desc.ld_tgt_count; i++)
1365 md_change_cbdata(lmv->tgts[i].ltd_exp, fid, it, data);
1370 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1371 struct md_open_data *mod, struct ptlrpc_request **request)
1373 struct obd_device *obd = exp->exp_obd;
1374 struct lmv_obd *lmv = &obd->u.lmv;
1375 struct lmv_tgt_desc *tgt;
1379 rc = lmv_check_connect(obd);
1383 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1385 RETURN(PTR_ERR(tgt));
1387 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1388 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1393 * Called in the case MDS returns -ERESTART on create on open, what means that
1394 * directory is split and its LMV presentation object has to be updated.
1396 int lmv_handle_split(struct obd_export *exp, const struct lu_fid *fid)
1398 struct obd_device *obd = exp->exp_obd;
1399 struct lmv_obd *lmv = &obd->u.lmv;
1400 struct ptlrpc_request *req = NULL;
1401 struct lmv_tgt_desc *tgt;
1402 struct lmv_object *obj;
1403 struct lustre_md md;
1410 mealen = lmv_get_easize(lmv);
1412 valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA | OBD_MD_MEA;
1414 tgt = lmv_find_target(lmv, fid);
1416 RETURN(PTR_ERR(tgt));
1419 * Time to update mea of parent fid.
1421 rc = md_getattr(tgt->ltd_exp, fid, NULL, valid, mealen, &req);
1423 CERROR("md_getattr() failed, error %d\n", rc);
1427 rc = md_get_lustre_md(tgt->ltd_exp, req, NULL, exp, &md);
1429 CERROR("md_get_lustre_md() failed, error %d\n", rc);
1434 GOTO(cleanup, rc = -ENODATA);
1436 obj = lmv_object_create(exp, fid, md.mea);
1440 lmv_object_put(obj);
1442 obd_free_memmd(exp, (void *)&md.mea);
1446 ptlrpc_req_finished(req);
1450 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1451 const void *data, int datalen, int mode, __u32 uid,
1452 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1453 struct ptlrpc_request **request)
1455 struct obd_device *obd = exp->exp_obd;
1456 struct lmv_obd *lmv = &obd->u.lmv;
1457 struct lmv_tgt_desc *tgt;
1458 struct lmv_object *obj;
1464 rc = lmv_check_connect(obd);
1468 if (!lmv->desc.ld_active_tgt_count)
1474 obj = lmv_object_find(obd, &op_data->op_fid1);
1476 sidx = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1477 op_data->op_name, op_data->op_namelen);
1478 op_data->op_fid1 = obj->lo_stripes[sidx].ls_fid;
1479 op_data->op_bias &= ~MDS_CHECK_SPLIT;
1480 op_data->op_mds = obj->lo_stripes[sidx].ls_mds;
1481 tgt = lmv_get_target(lmv, op_data->op_mds);
1482 lmv_object_put(obj);
1484 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1485 op_data->op_bias |= MDS_CHECK_SPLIT;
1486 op_data->op_mds = tgt->ltd_idx;
1490 RETURN(PTR_ERR(tgt));
1492 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1493 if (rc == -ERESTART)
1498 CDEBUG(D_INODE, "CREATE '%*s' on "DFID" -> mds #%x\n",
1499 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1502 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1503 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1504 cap_effective, rdev, request);
1506 if (*request == NULL)
1508 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1509 } else if (rc == -ERESTART) {
1510 LASSERT(*request != NULL);
1511 DEBUG_REQ(D_WARNING|D_RPCTRACE, *request,
1512 "Got -ERESTART during create!\n");
1513 ptlrpc_req_finished(*request);
1517 * Directory got split. Time to update local object and repeat
1518 * the request with proper MDS.
1520 rc = lmv_handle_split(exp, &op_data->op_fid1);
1522 rc = lmv_allocate_slaves(obd, &op_data->op_fid1,
1523 op_data, &op_data->op_fid2);
1532 static int lmv_done_writing(struct obd_export *exp,
1533 struct md_op_data *op_data,
1534 struct md_open_data *mod)
1536 struct obd_device *obd = exp->exp_obd;
1537 struct lmv_obd *lmv = &obd->u.lmv;
1538 struct lmv_tgt_desc *tgt;
1542 rc = lmv_check_connect(obd);
1546 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1548 RETURN(PTR_ERR(tgt));
1550 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1555 lmv_enqueue_slaves(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1556 struct lookup_intent *it, struct md_op_data *op_data,
1557 struct lustre_handle *lockh, void *lmm, int lmmsize)
1559 struct obd_device *obd = exp->exp_obd;
1560 struct lmv_obd *lmv = &obd->u.lmv;
1561 struct lmv_stripe_md *mea = op_data->op_mea1;
1562 struct md_op_data *op_data2;
1563 struct lmv_tgt_desc *tgt;
1568 OBD_ALLOC_PTR(op_data2);
1569 if (op_data2 == NULL)
1572 LASSERT(mea != NULL);
1573 for (i = 0; i < mea->mea_count; i++) {
1574 memset(op_data2, 0, sizeof(*op_data2));
1575 op_data2->op_fid1 = mea->mea_ids[i];
1576 op_data2->op_bias = 0;
1578 tgt = lmv_find_target(lmv, &op_data2->op_fid1);
1580 GOTO(cleanup, rc = PTR_ERR(tgt));
1582 if (tgt->ltd_exp == NULL)
1585 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data2,
1586 lockh + i, lmm, lmmsize, NULL, 0);
1588 CDEBUG(D_INODE, "Take lock on slave "DFID" -> %d/%d\n",
1589 PFID(&mea->mea_ids[i]), rc, it->d.lustre.it_status);
1594 if (it->d.lustre.it_data) {
1595 struct ptlrpc_request *req;
1596 req = (struct ptlrpc_request *)it->d.lustre.it_data;
1597 ptlrpc_req_finished(req);
1600 if (it->d.lustre.it_status)
1601 GOTO(cleanup, rc = it->d.lustre.it_status);
1606 OBD_FREE_PTR(op_data2);
1610 * Drop all taken locks.
1613 if (lockh[i].cookie)
1614 ldlm_lock_decref(lockh + i, einfo->ei_mode);
1615 lockh[i].cookie = 0;
1622 lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1623 struct lookup_intent *it, struct md_op_data *op_data,
1624 struct lustre_handle *lockh, void *lmm, int lmmsize,
1625 int extra_lock_flags)
1627 struct ptlrpc_request *req = it->d.lustre.it_data;
1628 struct obd_device *obd = exp->exp_obd;
1629 struct lmv_obd *lmv = &obd->u.lmv;
1630 struct lustre_handle plock;
1631 struct lmv_tgt_desc *tgt;
1632 struct md_op_data *rdata;
1634 struct mdt_body *body;
1639 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1640 LASSERT(body != NULL);
1642 if (!(body->valid & OBD_MD_MDS))
1645 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1646 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1649 * We got LOOKUP lock, but we really need attrs.
1651 pmode = it->d.lustre.it_lock_mode;
1652 LASSERT(pmode != 0);
1653 memcpy(&plock, lockh, sizeof(plock));
1654 it->d.lustre.it_lock_mode = 0;
1655 it->d.lustre.it_data = NULL;
1658 it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
1659 ptlrpc_req_finished(req);
1661 tgt = lmv_find_target(lmv, &fid1);
1663 GOTO(out, rc = PTR_ERR(tgt));
1665 OBD_ALLOC_PTR(rdata);
1667 GOTO(out, rc = -ENOMEM);
1669 rdata->op_fid1 = fid1;
1670 rdata->op_bias = MDS_CROSS_REF;
1672 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1673 lmm, lmmsize, NULL, extra_lock_flags);
1674 OBD_FREE_PTR(rdata);
1677 ldlm_lock_decref(&plock, pmode);
1682 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1683 struct lookup_intent *it, struct md_op_data *op_data,
1684 struct lustre_handle *lockh, void *lmm, int lmmsize,
1685 struct ptlrpc_request **req, int extra_lock_flags)
1687 struct obd_device *obd = exp->exp_obd;
1688 struct lmv_obd *lmv = &obd->u.lmv;
1689 struct lmv_tgt_desc *tgt;
1690 struct lmv_object *obj;
1695 rc = lmv_check_connect(obd);
1699 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1700 LL_IT2STR(it), PFID(&op_data->op_fid1));
1702 if (op_data->op_mea1 && it && it->it_op == IT_UNLINK) {
1703 rc = lmv_enqueue_slaves(exp, einfo, it, op_data,
1704 lockh, lmm, lmmsize);
1708 obj = lmv_object_find(obd, &op_data->op_fid1);
1709 if (obj && op_data->op_namelen) {
1710 sidx = raw_name2idx(obj->lo_hashtype,
1712 (char *)op_data->op_name,
1713 op_data->op_namelen);
1714 op_data->op_fid1 = obj->lo_stripes[sidx].ls_fid;
1715 tgt = lmv_get_target(lmv, obj->lo_stripes[sidx].ls_mds);
1717 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1720 lmv_object_put(obj);
1723 RETURN(PTR_ERR(tgt));
1725 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1726 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1728 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1729 lmm, lmmsize, req, extra_lock_flags);
1731 if (rc == 0 && it && it->it_op == IT_OPEN) {
1732 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1733 lmm, lmmsize, extra_lock_flags);
1739 lmv_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
1740 struct obd_capa *oc, const char *name, int namelen,
1741 obd_valid valid, int ea_size, __u32 suppgid,
1742 struct ptlrpc_request **request)
1744 struct ptlrpc_request *req = NULL;
1745 struct obd_device *obd = exp->exp_obd;
1746 struct lmv_obd *lmv = &obd->u.lmv;
1747 struct lu_fid rid = *fid;
1748 struct lmv_tgt_desc *tgt;
1749 struct mdt_body *body;
1750 struct lmv_object *obj;
1756 rc = lmv_check_connect(obd);
1763 obj = lmv_object_find(obd, &rid);
1765 sidx = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1767 rid = obj->lo_stripes[sidx].ls_fid;
1768 tgt = lmv_get_target(lmv, obj->lo_stripes[sidx].ls_mds);
1769 valid &= ~OBD_MD_FLCKSPLIT;
1770 lmv_object_put(obj);
1772 tgt = lmv_find_target(lmv, &rid);
1773 valid |= OBD_MD_FLCKSPLIT;
1776 RETURN(PTR_ERR(tgt));
1778 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" - "DFID" -> mds #%d\n",
1779 namelen, name, PFID(fid), PFID(&rid), tgt->ltd_idx);
1781 rc = md_getattr_name(tgt->ltd_exp, &rid, oc, name, namelen, valid,
1782 ea_size, suppgid, request);
1784 body = req_capsule_server_get(&(*request)->rq_pill,
1786 LASSERT(body != NULL);
1788 if (body->valid & OBD_MD_MDS) {
1790 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1793 tgt = lmv_find_target(lmv, &rid);
1795 ptlrpc_req_finished(*request);
1796 RETURN(PTR_ERR(tgt));
1799 rc = md_getattr_name(tgt->ltd_exp, &rid, NULL, NULL,
1800 1, valid | OBD_MD_FLCROSSREF,
1801 ea_size, suppgid, &req);
1802 ptlrpc_req_finished(*request);
1805 } else if (rc == -ERESTART) {
1806 LASSERT(*request != NULL);
1807 DEBUG_REQ(D_WARNING|D_RPCTRACE, *request,
1808 "Got -ERESTART during getattr!\n");
1809 ptlrpc_req_finished(*request);
1813 * Directory got split. Time to update local object and repeat
1814 * the request with proper MDS.
1816 rc = lmv_handle_split(exp, &rid);
1823 #define md_op_data_fid(op_data, fl) \
1824 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1825 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1826 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1827 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1830 static int lmv_early_cancel_slaves(struct obd_export *exp,
1831 struct md_op_data *op_data, int op_tgt,
1832 ldlm_mode_t mode, int bits, int flag)
1834 struct obd_device *obd = exp->exp_obd;
1835 struct lmv_obd *lmv = &obd->u.lmv;
1836 ldlm_policy_data_t policy = {{0}};
1837 struct lu_fid *op_fid;
1838 struct lu_fid *st_fid;
1839 struct lmv_tgt_desc *tgt;
1840 struct lmv_object *obj;
1845 op_fid = md_op_data_fid(op_data, flag);
1846 if (!fid_is_sane(op_fid))
1849 obj = lmv_object_find(obd, op_fid);
1853 policy.l_inodebits.bits = bits;
1854 for (i = 0; i < obj->lo_objcount; i++) {
1855 tgt = lmv_get_target(lmv, obj->lo_stripes[i].ls_mds);
1856 st_fid = &obj->lo_stripes[i].ls_fid;
1857 if (op_tgt != tgt->ltd_idx) {
1858 CDEBUG(D_INODE, "EARLY_CANCEL slave "DFID" -> mds #%d\n",
1859 PFID(st_fid), tgt->ltd_idx);
1860 rc = md_cancel_unused(tgt->ltd_exp, st_fid, &policy,
1861 mode, LDLM_FL_ASYNC, NULL);
1863 GOTO(out_put_obj, rc);
1866 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1867 op_tgt, PFID(st_fid));
1869 * Do not cancel locks for operation target, they will
1870 * be handled later in underlaying layer when calling
1871 * function we run on behalf of.
1874 op_data->op_flags |= flag;
1879 lmv_object_put(obj);
1883 static int lmv_early_cancel(struct obd_export *exp, struct md_op_data *op_data,
1884 int op_tgt, ldlm_mode_t mode, int bits, int flag)
1886 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1887 struct obd_device *obd = exp->exp_obd;
1888 struct lmv_obd *lmv = &obd->u.lmv;
1889 struct lmv_tgt_desc *tgt;
1890 ldlm_policy_data_t policy = {{0}};
1891 struct lmv_object *obj;
1895 if (!fid_is_sane(fid))
1898 obj = lmv_object_find(obd, fid);
1900 rc = lmv_early_cancel_slaves(exp, op_data, op_tgt, mode,
1902 lmv_object_put(obj);
1904 tgt = lmv_find_target(lmv, fid);
1906 RETURN(PTR_ERR(tgt));
1908 if (tgt->ltd_idx != op_tgt) {
1909 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1910 policy.l_inodebits.bits = bits;
1911 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1912 mode, LDLM_FL_ASYNC, NULL);
1915 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1917 op_data->op_flags |= flag;
1926 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1929 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1930 struct ptlrpc_request **request)
1932 struct obd_device *obd = exp->exp_obd;
1933 struct lmv_obd *lmv = &obd->u.lmv;
1934 struct lmv_tgt_desc *tgt;
1935 struct lmv_object *obj;
1942 rc = lmv_check_connect(obd);
1949 LASSERT(op_data->op_namelen != 0);
1951 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1952 PFID(&op_data->op_fid2), op_data->op_namelen,
1953 op_data->op_name, PFID(&op_data->op_fid1));
1955 obj = lmv_object_find(obd, &op_data->op_fid2);
1957 sidx = raw_name2idx(obj->lo_hashtype,
1960 op_data->op_namelen);
1961 op_data->op_fid2 = obj->lo_stripes[sidx].ls_fid;
1962 mds = obj->lo_stripes[sidx].ls_mds;
1963 lmv_object_put(obj);
1965 rc = lmv_fld_lookup(lmv, &op_data->op_fid2, &mds);
1970 CDEBUG(D_INODE, "Forward to mds #%x ("DFID")\n",
1971 mds, PFID(&op_data->op_fid1));
1973 op_data->op_fsuid = current->fsuid;
1974 op_data->op_fsgid = current->fsgid;
1975 op_data->op_cap = cfs_curproc_cap_pack();
1976 tgt = lmv_get_target(lmv, mds);
1979 * Cancel UPDATE lock on child (fid1).
1981 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1982 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
1983 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1985 rc = md_link(tgt->ltd_exp, op_data, request);
1986 if (rc == -ERESTART) {
1987 LASSERT(*request != NULL);
1988 DEBUG_REQ(D_WARNING|D_RPCTRACE, *request,
1989 "Got -ERESTART during link!\n");
1990 ptlrpc_req_finished(*request);
1994 * Directory got split. Time to update local object and repeat
1995 * the request with proper MDS.
1997 rc = lmv_handle_split(exp, &op_data->op_fid2);
2005 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
2006 const char *old, int oldlen, const char *new, int newlen,
2007 struct ptlrpc_request **request)
2009 struct obd_device *obd = exp->exp_obd;
2010 struct lmv_obd *lmv = &obd->u.lmv;
2011 struct lmv_tgt_desc *src_tgt;
2012 struct lmv_tgt_desc *tgt_tgt;
2016 struct lmv_object *obj;
2021 LASSERT(oldlen != 0);
2023 CDEBUG(D_INODE, "RENAME %*s in "DFID" to %*s in "DFID"\n",
2024 oldlen, old, PFID(&op_data->op_fid1),
2025 newlen, new, PFID(&op_data->op_fid2));
2027 rc = lmv_check_connect(obd);
2034 obj = lmv_object_find(obd, &op_data->op_fid1);
2036 sidx = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
2037 (char *)old, oldlen);
2038 op_data->op_fid1 = obj->lo_stripes[sidx].ls_fid;
2039 mds1 = obj->lo_stripes[sidx].ls_mds;
2040 CDEBUG(D_INODE, "Parent obj "DFID"\n", PFID(&op_data->op_fid1));
2041 lmv_object_put(obj);
2043 rc = lmv_fld_lookup(lmv, &op_data->op_fid1, &mds1);
2048 obj = lmv_object_find(obd, &op_data->op_fid2);
2051 * Directory is already split, so we have to forward request to
2054 sidx = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
2055 (char *)new, newlen);
2057 mds2 = obj->lo_stripes[sidx].ls_mds;
2058 op_data->op_fid2 = obj->lo_stripes[sidx].ls_fid;
2059 CDEBUG(D_INODE, "Parent obj "DFID"\n", PFID(&op_data->op_fid2));
2060 lmv_object_put(obj);
2062 rc = lmv_fld_lookup(lmv, &op_data->op_fid2, &mds2);
2067 op_data->op_fsuid = current->fsuid;
2068 op_data->op_fsgid = current->fsgid;
2069 op_data->op_cap = cfs_curproc_cap_pack();
2071 src_tgt = lmv_get_target(lmv, mds1);
2072 tgt_tgt = lmv_get_target(lmv, mds2);
2075 * LOOKUP lock on src child (fid3) should also be cancelled for
2076 * src_tgt in mdc_rename.
2078 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2081 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
2084 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
2085 LCK_EX, MDS_INODELOCK_UPDATE,
2086 MF_MDC_CANCEL_FID2);
2089 * Cancel LOOKUP locks on tgt child (fid4) for parent tgt_tgt.
2092 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
2093 LCK_EX, MDS_INODELOCK_LOOKUP,
2094 MF_MDC_CANCEL_FID4);
2098 * Cancel all the locks on tgt child (fid4).
2101 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
2102 LCK_EX, MDS_INODELOCK_FULL,
2103 MF_MDC_CANCEL_FID4);
2106 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen,
2107 new, newlen, request);
2109 if (rc == -ERESTART) {
2110 LASSERT(*request != NULL);
2111 DEBUG_REQ(D_WARNING|D_RPCTRACE, *request,
2112 "Got -ERESTART during rename!\n");
2113 ptlrpc_req_finished(*request);
2117 * Directory got split. Time to update local object and repeat
2118 * the request with proper MDS.
2120 rc = lmv_handle_split(exp, &op_data->op_fid1);
2127 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2128 void *ea, int ealen, void *ea2, int ea2len,
2129 struct ptlrpc_request **request,
2130 struct md_open_data **mod)
2132 struct obd_device *obd = exp->exp_obd;
2133 struct lmv_obd *lmv = &obd->u.lmv;
2134 struct ptlrpc_request *req;
2135 struct lmv_tgt_desc *tgt;
2136 struct lmv_object *obj;
2141 rc = lmv_check_connect(obd);
2145 obj = lmv_object_find(obd, &op_data->op_fid1);
2147 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x%s\n",
2148 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid,
2149 obj ? ", split" : "");
2151 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2153 for (i = 0; i < obj->lo_objcount; i++) {
2154 op_data->op_fid1 = obj->lo_stripes[i].ls_fid;
2156 tgt = lmv_get_target(lmv, obj->lo_stripes[i].ls_mds);
2162 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen,
2163 ea2, ea2len, &req, mod);
2165 if (lu_fid_eq(&obj->lo_fid, &obj->lo_stripes[i].ls_fid)) {
2167 * This is master object and this request should
2168 * be returned back to llite.
2172 ptlrpc_req_finished(req);
2178 lmv_object_put(obj);
2180 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2182 RETURN(PTR_ERR(tgt));
2184 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
2185 ea2len, request, mod);
2190 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
2191 struct obd_capa *oc, struct ptlrpc_request **request)
2193 struct obd_device *obd = exp->exp_obd;
2194 struct lmv_obd *lmv = &obd->u.lmv;
2195 struct lmv_tgt_desc *tgt;
2199 rc = lmv_check_connect(obd);
2203 tgt = lmv_find_target(lmv, fid);
2205 RETURN(PTR_ERR(tgt));
2207 rc = md_sync(tgt->ltd_exp, fid, oc, request);
2212 * Main purpose of LMV blocking ast is to remove split directory LMV
2213 * presentation object (struct lmv_object) attached to the lock being revoked.
2215 int lmv_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2216 void *data, int flag)
2218 struct lustre_handle lockh;
2219 struct lmv_object *obj;
2224 case LDLM_CB_BLOCKING:
2225 ldlm_lock2handle(lock, &lockh);
2226 rc = ldlm_cli_cancel(&lockh);
2228 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
2232 case LDLM_CB_CANCELING:
2234 * Time to drop cached attrs for split directory object
2236 obj = lock->l_ast_data;
2238 CDEBUG(D_INODE, "Cancel %s on "LPU64"/"LPU64
2239 ", master "DFID"\n",
2240 lock->l_resource->lr_name.name[3] == 1 ?
2241 "LOOKUP" : "UPDATE",
2242 lock->l_resource->lr_name.name[0],
2243 lock->l_resource->lr_name.name[1],
2244 PFID(&obj->lo_fid));
2245 lmv_object_put(obj);
2254 static void lmv_hash_adjust(__u64 *hash, __u64 hash_adj)
2258 val = le64_to_cpu(*hash);
2260 val += MAX_HASH_SIZE;
2261 if (val != DIR_END_OFF)
2262 *hash = cpu_to_le64(val - hash_adj);
2265 static __u32 lmv_node_rank(struct obd_export *exp, const struct lu_fid *fid)
2268 struct obd_import *imp;
2271 * XXX: to get nid we assume that underlying obd device is mdc.
2273 imp = class_exp2cliimp(exp);
2274 id = imp->imp_connection->c_self + fid_flatten(fid);
2276 CDEBUG(D_INODE, "Readpage node rank: "LPX64" "DFID" "LPX64" "LPX64"\n",
2277 imp->imp_connection->c_self, PFID(fid), id, id ^ (id >> 32));
2279 return id ^ (id >> 32);
2282 static int lmv_readpage(struct obd_export *exp, const struct lu_fid *fid,
2283 struct obd_capa *oc, __u64 offset64, struct page *page,
2284 struct ptlrpc_request **request)
2286 struct obd_device *obd = exp->exp_obd;
2287 struct lmv_obd *lmv = &obd->u.lmv;
2288 struct lu_fid rid = *fid;
2289 struct lmv_object *obj;
2299 struct lmv_stripe *los;
2300 struct lmv_tgt_desc *tgt;
2301 struct lu_dirpage *dp;
2302 struct lu_dirent *ent;
2307 rc = lmv_check_connect(obd);
2311 CDEBUG(D_INODE, "READPAGE at "LPX64" from "DFID"\n", offset, PFID(&rid));
2314 * This case handle directory lookup in clustered metadata case (i.e.
2315 * split directory is located on multiple md servers.)
2316 * each server keeps directory entries for certain range of hashes.
2317 * E.g. we have N server and suppose hash range is 0 to MAX_HASH.
2318 * first server will keep records with hashes [ 0 ... MAX_HASH / N - 1],
2319 * second one with hashes [MAX_HASH / N ... 2 * MAX_HASH / N] and
2321 * readdir can simply start reading entries from 0 - N server in
2322 * order but that will not scale well as all client will request dir in
2323 * to server in same order.
2324 * Following algorithm does optimization:
2325 * Instead of doing readdir in 1, 2, ...., N order, client with a
2326 * rank R does readdir in R, R + 1, ..., N, 1, ... R - 1 order.
2327 * (every client has rank R)
2328 * But ll_readdir() expect offset range [0 to MAX_HASH/N) but
2329 * since client ask dir from MDS{R} client has pages with offsets
2330 * [R*MAX_HASH/N ... (R + 1)*MAX_HASH/N] there for we do hash_adj
2331 * on hash values that we get.
2333 obj = lmv_object_find_lock(obd, fid);
2335 nr = obj->lo_objcount;
2337 seg_size = MAX_HASH_SIZE;
2338 do_div(seg_size, nr);
2339 los = obj->lo_stripes;
2340 tgt = lmv_get_target(lmv, los[0].ls_mds);
2341 rank = lmv_node_rank(tgt->ltd_exp, fid) % nr;
2343 do_div(tgt_tmp, seg_size);
2344 tgt0_idx = do_div(tgt_tmp, nr);
2345 tgt_idx = (tgt0_idx + rank) % nr;
2347 if (tgt_idx < tgt0_idx)
2351 * Last segment has unusual length due to division
2354 hash_adj = MAX_HASH_SIZE - seg_size * nr;
2358 hash_adj += rank * seg_size;
2360 CDEBUG(D_INODE, "Readpage hash adjustment: %x "LPX64" "
2361 LPX64"/%x -> "LPX64"/%x\n", rank, hash_adj,
2362 offset, tgt0_idx, offset + hash_adj, tgt_idx);
2364 offset = (offset + hash_adj) & MAX_HASH_SIZE;
2365 rid = obj->lo_stripes[tgt_idx].ls_fid;
2366 tgt = lmv_get_target(lmv, los[tgt_idx].ls_mds);
2368 CDEBUG(D_INODE, "Forward to "DFID" with offset %lu i %d\n",
2369 PFID(&rid), (unsigned long)offset, tgt_idx);
2371 tgt = lmv_find_target(lmv, &rid);
2374 GOTO(cleanup, rc = PTR_ERR(tgt));
2376 rc = md_readpage(tgt->ltd_exp, &rid, oc, offset, page, request);
2380 dp = cfs_kmap(page);
2382 lmv_hash_adjust(&dp->ldp_hash_start, hash_adj);
2383 lmv_hash_adjust(&dp->ldp_hash_end, hash_adj);
2384 LASSERT(le64_to_cpu(dp->ldp_hash_start) <= offset64);
2386 for (ent = lu_dirent_start(dp); ent != NULL;
2387 ent = lu_dirent_next(ent))
2388 lmv_hash_adjust(&ent->lde_hash, hash_adj);
2390 if (tgt0_idx != nr - 1) {
2393 end = le64_to_cpu(dp->ldp_hash_end);
2394 if (end == DIR_END_OFF) {
2395 dp->ldp_hash_end = cpu_to_le32(seg_size *
2398 ""DFID" reset end "LPX64" tgt %d\n",
2400 le64_to_cpu(dp->ldp_hash_end), tgt_idx);
2408 lmv_object_put_unlock(obj);
2412 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2413 struct ptlrpc_request **request)
2415 struct obd_device *obd = exp->exp_obd;
2416 struct lmv_obd *lmv = &obd->u.lmv;
2417 struct lmv_tgt_desc *tgt = NULL;
2418 struct lmv_object *obj;
2424 rc = lmv_check_connect(obd);
2431 LASSERT(op_data->op_namelen != 0);
2433 obj = lmv_object_find(obd, &op_data->op_fid1);
2435 sidx = raw_name2idx(obj->lo_hashtype,
2438 op_data->op_namelen);
2439 op_data->op_bias &= ~MDS_CHECK_SPLIT;
2440 op_data->op_fid1 = obj->lo_stripes[sidx].ls_fid;
2441 tgt = lmv_get_target(lmv,
2442 obj->lo_stripes[sidx].ls_mds);
2443 lmv_object_put(obj);
2444 CDEBUG(D_INODE, "UNLINK '%*s' in "DFID" -> %u\n",
2445 op_data->op_namelen, op_data->op_name,
2446 PFID(&op_data->op_fid1), sidx);
2450 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2452 RETURN(PTR_ERR(tgt));
2453 op_data->op_bias |= MDS_CHECK_SPLIT;
2456 op_data->op_fsuid = current->fsuid;
2457 op_data->op_fsgid = current->fsgid;
2458 op_data->op_cap = cfs_curproc_cap_pack();
2461 * If child's fid is given, cancel unused locks for it if it is from
2462 * another export than parent.
2464 * LOOKUP lock for child (fid3) should also be cancelled on parent
2465 * tgt_tgt in mdc_unlink().
2467 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2470 * Cancel FULL locks on child (fid3).
2472 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
2473 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2476 rc = md_unlink(tgt->ltd_exp, op_data, request);
2478 if (rc == -ERESTART) {
2479 LASSERT(*request != NULL);
2480 DEBUG_REQ(D_WARNING|D_RPCTRACE, *request,
2481 "Got -ERESTART during unlink!\n");
2482 ptlrpc_req_finished(*request);
2486 * Directory got split. Time to update local object and repeat
2487 * the request with proper MDS.
2489 rc = lmv_handle_split(exp, &op_data->op_fid1);
2496 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2501 case OBD_CLEANUP_EARLY:
2502 /* XXX: here should be calling obd_precleanup() down to
2505 case OBD_CLEANUP_EXPORTS:
2506 rc = obd_llog_finish(obd, 0);
2508 CERROR("failed to cleanup llogging subsystems\n");
2516 static int lmv_get_info(struct obd_export *exp, __u32 keylen,
2517 void *key, __u32 *vallen, void *val,
2518 struct lov_stripe_md *lsm)
2520 struct obd_device *obd;
2521 struct lmv_obd *lmv;
2525 obd = class_exp2obd(exp);
2527 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2528 exp->exp_handle.h_cookie);
2533 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2534 struct lmv_tgt_desc *tgts;
2537 rc = lmv_check_connect(obd);
2541 LASSERT(*vallen == sizeof(__u32));
2542 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count;
2546 * All tgts should be connected when this gets called.
2548 if (!tgts || !tgts->ltd_exp) {
2549 CERROR("target not setup?\n");
2553 if (!obd_get_info(tgts->ltd_exp, keylen, key,
2558 } else if (KEY_IS(KEY_MAX_EASIZE) || KEY_IS(KEY_CONN_DATA)) {
2559 rc = lmv_check_connect(obd);
2564 * Forwarding this request to first MDS, it should know LOV
2567 rc = obd_get_info(lmv->tgts[0].ltd_exp, keylen, key,
2569 if (!rc && KEY_IS(KEY_CONN_DATA)) {
2570 exp->exp_connect_flags =
2571 ((struct obd_connect_data *)val)->ocd_connect_flags;
2576 CDEBUG(D_IOCTL, "Invalid key\n");
2580 int lmv_set_info_async(struct obd_export *exp, obd_count keylen,
2581 void *key, obd_count vallen, void *val,
2582 struct ptlrpc_request_set *set)
2584 struct lmv_tgt_desc *tgt;
2585 struct obd_device *obd;
2586 struct lmv_obd *lmv;
2590 obd = class_exp2obd(exp);
2592 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2593 exp->exp_handle.h_cookie);
2598 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX) ||
2599 KEY_IS(KEY_INIT_RECOV_BACKUP)) {
2602 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2603 tgt = &lmv->tgts[i];
2608 err = obd_set_info_async(tgt->ltd_exp,
2609 keylen, key, vallen, val, set);
2620 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2621 struct lov_stripe_md *lsm)
2623 struct obd_device *obd = class_exp2obd(exp);
2624 struct lmv_obd *lmv = &obd->u.lmv;
2625 struct lmv_stripe_md *meap;
2626 struct lmv_stripe_md *lsmp;
2631 mea_size = lmv_get_easize(lmv);
2635 if (*lmmp && !lsm) {
2636 OBD_FREE(*lmmp, mea_size);
2641 if (*lmmp == NULL) {
2642 OBD_ALLOC(*lmmp, mea_size);
2650 lsmp = (struct lmv_stripe_md *)lsm;
2651 meap = (struct lmv_stripe_md *)*lmmp;
2653 if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR &&
2654 lsmp->mea_magic != MEA_MAGIC_ALL_CHARS)
2657 meap->mea_magic = cpu_to_le32(lsmp->mea_magic);
2658 meap->mea_count = cpu_to_le32(lsmp->mea_count);
2659 meap->mea_master = cpu_to_le32(lsmp->mea_master);
2661 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2662 meap->mea_ids[i] = meap->mea_ids[i];
2663 fid_cpu_to_le(&meap->mea_ids[i], &meap->mea_ids[i]);
2669 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2670 struct lov_mds_md *lmm, int lmm_size)
2672 struct obd_device *obd = class_exp2obd(exp);
2673 struct lmv_stripe_md **tmea = (struct lmv_stripe_md **)lsmp;
2674 struct lmv_stripe_md *mea = (struct lmv_stripe_md *)lmm;
2675 struct lmv_obd *lmv = &obd->u.lmv;
2681 mea_size = lmv_get_easize(lmv);
2685 if (*lsmp != NULL && lmm == NULL) {
2686 OBD_FREE(*tmea, mea_size);
2691 LASSERT(mea_size == lmm_size);
2693 OBD_ALLOC(*tmea, mea_size);
2700 if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
2701 mea->mea_magic == MEA_MAGIC_ALL_CHARS ||
2702 mea->mea_magic == MEA_MAGIC_HASH_SEGMENT)
2704 magic = le32_to_cpu(mea->mea_magic);
2707 * Old mea is not handled here.
2709 CERROR("Old not supportable EA is found\n");
2713 (*tmea)->mea_magic = magic;
2714 (*tmea)->mea_count = le32_to_cpu(mea->mea_count);
2715 (*tmea)->mea_master = le32_to_cpu(mea->mea_master);
2717 for (i = 0; i < (*tmea)->mea_count; i++) {
2718 (*tmea)->mea_ids[i] = mea->mea_ids[i];
2719 fid_le_to_cpu(&(*tmea)->mea_ids[i], &(*tmea)->mea_ids[i]);
2724 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2725 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2726 int flags, void *opaque)
2728 struct obd_device *obd = exp->exp_obd;
2729 struct lmv_obd *lmv = &obd->u.lmv;
2735 LASSERT(fid != NULL);
2737 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2738 if (!lmv->tgts[i].ltd_exp || !lmv->tgts[i].ltd_active)
2741 err = md_cancel_unused(lmv->tgts[i].ltd_exp, fid,
2742 policy, mode, flags, opaque);
2749 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
2752 struct obd_device *obd = exp->exp_obd;
2753 struct lmv_obd *lmv = &obd->u.lmv;
2757 rc = md_set_lock_data(lmv->tgts[0].ltd_exp, lockh, data, bits);
2761 ldlm_mode_t lmv_lock_match(struct obd_export *exp, int flags,
2762 const struct lu_fid *fid, ldlm_type_t type,
2763 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2764 struct lustre_handle *lockh)
2766 struct obd_device *obd = exp->exp_obd;
2767 struct lmv_obd *lmv = &obd->u.lmv;
2772 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2775 * With CMD every object can have two locks in different namespaces:
2776 * lookup lock in space of mds storing direntry and update/open lock in
2777 * space of mds storing inode. Thus we check all targets, not only that
2778 * one fid was created in.
2780 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2781 rc = md_lock_match(lmv->tgts[i].ltd_exp, flags, fid,
2782 type, policy, mode, lockh);
2790 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2791 struct obd_export *dt_exp, struct obd_export *md_exp,
2792 struct lustre_md *md)
2794 struct obd_device *obd = exp->exp_obd;
2795 struct lmv_obd *lmv = &obd->u.lmv;
2798 rc = md_get_lustre_md(lmv->tgts[0].ltd_exp, req, dt_exp, md_exp, md);
2802 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2804 struct obd_device *obd = exp->exp_obd;
2805 struct lmv_obd *lmv = &obd->u.lmv;
2809 obd_free_memmd(exp, (void *)&md->mea);
2810 RETURN(md_free_lustre_md(lmv->tgts[0].ltd_exp, md));
2813 int lmv_set_open_replay_data(struct obd_export *exp,
2814 struct obd_client_handle *och,
2815 struct ptlrpc_request *open_req)
2817 struct obd_device *obd = exp->exp_obd;
2818 struct lmv_obd *lmv = &obd->u.lmv;
2819 struct lmv_tgt_desc *tgt;
2822 tgt = lmv_find_target(lmv, &och->och_fid);
2824 RETURN(PTR_ERR(tgt));
2826 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, open_req));
2829 int lmv_clear_open_replay_data(struct obd_export *exp,
2830 struct obd_client_handle *och)
2832 struct obd_device *obd = exp->exp_obd;
2833 struct lmv_obd *lmv = &obd->u.lmv;
2834 struct lmv_tgt_desc *tgt;
2837 tgt = lmv_find_target(lmv, &och->och_fid);
2839 RETURN(PTR_ERR(tgt));
2841 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
2844 static int lmv_get_remote_perm(struct obd_export *exp,
2845 const struct lu_fid *fid,
2846 struct obd_capa *oc, __u32 suppgid,
2847 struct ptlrpc_request **request)
2849 struct obd_device *obd = exp->exp_obd;
2850 struct lmv_obd *lmv = &obd->u.lmv;
2851 struct lmv_tgt_desc *tgt;
2855 rc = lmv_check_connect(obd);
2859 tgt = lmv_find_target(lmv, fid);
2861 RETURN(PTR_ERR(tgt));
2863 rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
2867 static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
2870 struct obd_device *obd = exp->exp_obd;
2871 struct lmv_obd *lmv = &obd->u.lmv;
2872 struct lmv_tgt_desc *tgt;
2876 rc = lmv_check_connect(obd);
2880 tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
2882 RETURN(PTR_ERR(tgt));
2884 rc = md_renew_capa(tgt->ltd_exp, oc, cb);
2888 int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
2889 const struct req_msg_field *field, struct obd_capa **oc)
2891 struct obd_device *obd = exp->exp_obd;
2892 struct lmv_obd *lmv = &obd->u.lmv;
2896 rc = md_unpack_capa(lmv->tgts[0].ltd_exp, req, field, oc);
2900 int lmv_intent_getattr_async(struct obd_export *exp,
2901 struct md_enqueue_info *minfo,
2902 struct ldlm_enqueue_info *einfo)
2904 struct md_op_data *op_data = &minfo->mi_data;
2905 struct obd_device *obd = exp->exp_obd;
2906 struct lmv_obd *lmv = &obd->u.lmv;
2907 struct lmv_object *obj;
2908 struct lmv_tgt_desc *tgt;
2913 rc = lmv_check_connect(obd);
2917 if (!fid_is_sane(&op_data->op_fid2)) {
2918 obj = lmv_object_find(obd, &op_data->op_fid1);
2919 if (obj && op_data->op_namelen) {
2920 sidx = raw_name2idx(obj->lo_hashtype,
2922 (char *)op_data->op_name,
2923 op_data->op_namelen);
2924 op_data->op_fid1 = obj->lo_stripes[sidx].ls_fid;
2925 tgt = lmv_get_target(lmv,
2926 obj->lo_stripes[sidx].ls_mds);
2928 "Choose slave dir ("DFID") -> mds #%d\n",
2929 PFID(&op_data->op_fid1), tgt->ltd_idx);
2931 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2934 lmv_object_put(obj);
2936 op_data->op_fid1 = op_data->op_fid2;
2937 tgt = lmv_find_target(lmv, &op_data->op_fid2);
2938 op_data->op_bias = MDS_CROSS_REF;
2940 * Unfortunately, we have to lie to MDC/MDS to retrieve
2941 * attributes llite needs.
2943 if (minfo->mi_it.it_op & IT_LOOKUP)
2944 minfo->mi_it.it_op = IT_GETATTR;
2948 RETURN(PTR_ERR(tgt));
2950 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
2954 int lmv_revalidate_lock(struct obd_export *exp,
2955 struct lookup_intent *it,
2958 struct obd_device *obd = exp->exp_obd;
2959 struct lmv_obd *lmv = &obd->u.lmv;
2960 struct lmv_tgt_desc *tgt;
2964 rc = lmv_check_connect(obd);
2968 tgt = lmv_find_target(lmv, fid);
2970 RETURN(PTR_ERR(tgt));
2972 rc = md_revalidate_lock(tgt->ltd_exp, it, fid);
2977 struct obd_ops lmv_obd_ops = {
2978 .o_owner = THIS_MODULE,
2979 .o_setup = lmv_setup,
2980 .o_cleanup = lmv_cleanup,
2981 .o_precleanup = lmv_precleanup,
2982 .o_process_config = lmv_process_config,
2983 .o_connect = lmv_connect,
2984 .o_disconnect = lmv_disconnect,
2985 .o_statfs = lmv_statfs,
2986 .o_get_info = lmv_get_info,
2987 .o_set_info_async = lmv_set_info_async,
2988 .o_packmd = lmv_packmd,
2989 .o_unpackmd = lmv_unpackmd,
2990 .o_notify = lmv_notify,
2991 .o_get_uuid = lmv_get_uuid,
2992 .o_iocontrol = lmv_iocontrol,
2993 .o_fid_delete = lmv_fid_delete
2996 struct md_ops lmv_md_ops = {
2997 .m_getstatus = lmv_getstatus,
2998 .m_change_cbdata = lmv_change_cbdata,
2999 .m_close = lmv_close,
3000 .m_create = lmv_create,
3001 .m_done_writing = lmv_done_writing,
3002 .m_enqueue = lmv_enqueue,
3003 .m_getattr = lmv_getattr,
3004 .m_getxattr = lmv_getxattr,
3005 .m_getattr_name = lmv_getattr_name,
3006 .m_intent_lock = lmv_intent_lock,
3008 .m_rename = lmv_rename,
3009 .m_setattr = lmv_setattr,
3010 .m_setxattr = lmv_setxattr,
3012 .m_readpage = lmv_readpage,
3013 .m_unlink = lmv_unlink,
3014 .m_init_ea_size = lmv_init_ea_size,
3015 .m_cancel_unused = lmv_cancel_unused,
3016 .m_set_lock_data = lmv_set_lock_data,
3017 .m_lock_match = lmv_lock_match,
3018 .m_get_lustre_md = lmv_get_lustre_md,
3019 .m_free_lustre_md = lmv_free_lustre_md,
3020 .m_set_open_replay_data = lmv_set_open_replay_data,
3021 .m_clear_open_replay_data = lmv_clear_open_replay_data,
3022 .m_renew_capa = lmv_renew_capa,
3023 .m_unpack_capa = lmv_unpack_capa,
3024 .m_get_remote_perm = lmv_get_remote_perm,
3025 .m_intent_getattr_async = lmv_intent_getattr_async,
3026 .m_revalidate_lock = lmv_revalidate_lock
3029 static quota_interface_t *quota_interface;
3030 extern quota_interface_t lmv_quota_interface;
3032 int __init lmv_init(void)
3034 struct lprocfs_static_vars lvars;
3037 lmv_object_cache = cfs_mem_cache_create("lmv_objects",
3038 sizeof(struct lmv_object),
3040 if (!lmv_object_cache) {
3041 CERROR("Error allocating lmv objects cache\n");
3045 lprocfs_lmv_init_vars(&lvars);
3047 cfs_request_module("lquota");
3048 quota_interface = PORTAL_SYMBOL_GET(lmv_quota_interface);
3049 init_obd_quota_ops(quota_interface, &lmv_obd_ops);
3051 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
3052 lvars.module_vars, LUSTRE_LMV_NAME, NULL);
3054 if (quota_interface)
3055 PORTAL_SYMBOL_PUT(lmv_quota_interface);
3056 cfs_mem_cache_destroy(lmv_object_cache);
3063 static void lmv_exit(void)
3065 if (quota_interface)
3066 PORTAL_SYMBOL_PUT(lmv_quota_interface);
3068 class_unregister_type(LUSTRE_LMV_NAME);
3070 LASSERTF(cfs_atomic_read(&lmv_object_count) == 0,
3071 "Can't free lmv objects cache, %d object(s) busy\n",
3072 cfs_atomic_read(&lmv_object_count));
3073 cfs_mem_cache_destroy(lmv_object_cache);
3076 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3077 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
3078 MODULE_LICENSE("GPL");
3080 module_init(lmv_init);
3081 module_exit(lmv_exit);