1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003, 2004, 2005, 2006 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # define EXPORT_SYMTAB
25 #define DEBUG_SUBSYSTEM S_LMV
27 #include <linux/slab.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/slab.h>
31 #include <linux/pagemap.h>
33 #include <asm/div64.h>
34 #include <linux/seq_file.h>
35 #include <linux/namei.h>
37 #include <liblustre.h>
40 #include <linux/ext2_fs.h>
42 #include <lustre/lustre_idl.h>
43 #include <lustre_log.h>
44 #include <obd_support.h>
45 #include <lustre_lib.h>
46 #include <lustre_net.h>
47 #include <obd_class.h>
48 #include <lprocfs_status.h>
49 #include <lustre_lite.h>
50 #include <lustre_fid.h>
51 #include "lmv_internal.h"
53 /* not defined for liblustre building */
54 #if !defined(ATOMIC_INIT)
55 #define ATOMIC_INIT(val) { (val) }
59 cfs_mem_cache_t *obj_cache;
60 atomic_t obj_cache_count = ATOMIC_INIT(0);
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);
75 * -EINVAL : UUID can't be found in the LMV's target list
76 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
77 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
79 static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid,
82 struct lmv_tgt_desc *tgt;
83 struct obd_device *obd;
87 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
88 lmv, uuid->uuid, activate);
90 spin_lock(&lmv->lmv_lock);
91 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
92 if (tgt->ltd_exp == NULL)
95 CDEBUG(D_INFO, "lmv idx %d is %s conn "LPX64"\n",
96 i, tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
98 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
102 if (i == lmv->desc.ld_tgt_count)
103 GOTO(out_lmv_lock, rc = -EINVAL);
105 obd = class_exp2obd(tgt->ltd_exp);
107 GOTO(out_lmv_lock, rc = -ENOTCONN);
109 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
110 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
111 obd->obd_type->typ_name, i);
112 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
114 if (tgt->ltd_active == activate) {
115 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
116 activate ? "" : "in");
117 GOTO(out_lmv_lock, rc);
120 CDEBUG(D_INFO, "Marking OBD %p %sactive\n",
121 obd, activate ? "" : "in");
123 lmv_activate_target(lmv, tgt, activate);
128 spin_unlock(&lmv->lmv_lock);
132 static int lmv_set_mdc_data(struct lmv_obd *lmv, struct obd_uuid *uuid,
133 struct obd_connect_data *data)
135 struct lmv_tgt_desc *tgt;
139 LASSERT(data != NULL);
141 spin_lock(&lmv->lmv_lock);
142 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
143 if (tgt->ltd_exp == NULL)
146 if (obd_uuid_equals(uuid, &tgt->ltd_uuid)) {
147 lmv->datas[tgt->ltd_idx] = *data;
151 spin_unlock(&lmv->lmv_lock);
155 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
156 enum obd_notify_event ev, void *data)
158 struct lmv_obd *lmv = &obd->u.lmv;
159 struct obd_uuid *uuid;
163 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
164 CERROR("unexpected notification of %s %s!\n",
165 watched->obd_type->typ_name,
170 uuid = &watched->u.cli.cl_target_uuid;
171 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
173 * Set MDC as active before notifying the observer, so the
174 * observer can use the MDC normally.
176 rc = lmv_set_mdc_active(lmv, uuid,
177 ev == OBD_NOTIFY_ACTIVE);
179 CERROR("%sactivation of %s failed: %d\n",
180 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
184 } else if (ev == OBD_NOTIFY_OCD) {
185 struct obd_connect_data *conn_data =
186 &watched->u.cli.cl_import->imp_connect_data;
188 /* Set connect data to desired target, update
189 * exp_connect_flags. */
190 rc = lmv_set_mdc_data(lmv, uuid, conn_data);
192 CERROR("can't set connect data to target %s, rc %d\n",
198 * XXX: Make sure that ocd_connect_flags from all targets are
199 * the same. Otherwise one of MDTs runs wrong version or
200 * something like this. --umka
202 obd->obd_self_export->exp_connect_flags =
203 conn_data->ocd_connect_flags;
206 else if (ev == OBD_NOTIFY_DISCON) {
207 /* For disconnect event, flush fld cache for failout MDS case. */
208 fld_client_flush(&lmv->lmv_fld);
211 /* Pass the notification up the chain. */
212 if (obd->obd_observer)
213 rc = obd_notify(obd->obd_observer, watched, ev, data);
218 /* this is fake connect function. Its purpose is to initialize lmv and say
219 * caller that everything is okay. Real connection will be performed later. */
220 static int lmv_connect(const struct lu_env *env,
221 struct lustre_handle *conn, struct obd_device *obd,
222 struct obd_uuid *cluuid, struct obd_connect_data *data)
225 struct proc_dir_entry *lmv_proc_dir;
227 struct lmv_obd *lmv = &obd->u.lmv;
228 struct obd_export *exp;
232 rc = class_connect(conn, obd, cluuid);
234 CERROR("class_connection() returned %d\n", rc);
238 exp = class_conn2export(conn);
240 /* we don't want to actually do the underlying connections more than
241 * once, so keep track. */
243 if (lmv->refcount > 1) {
244 class_export_put(exp);
250 lmv->cluuid = *cluuid;
253 lmv->conn_data = *data;
256 lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
258 if (IS_ERR(lmv_proc_dir)) {
259 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
260 obd->obd_type->typ_name, obd->obd_name);
265 /* all real clients should perform actual connection right away, because
266 * it is possible, that LMV will not have opportunity to connect targets
267 * and MDC stuff will be called directly, for instance while reading
268 * ../mdc/../kbytesfree procfs file, etc. */
269 if (data->ocd_connect_flags & OBD_CONNECT_REAL)
270 rc = lmv_check_connect(obd);
275 lprocfs_remove(&lmv_proc_dir);
282 static void lmv_set_timeouts(struct obd_device *obd)
284 struct lmv_tgt_desc *tgts;
289 if (lmv->server_timeout == 0)
292 if (lmv->connected == 0)
295 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) {
296 if (tgts->ltd_exp == NULL)
299 obd_set_info_async(tgts->ltd_exp, strlen("inter_mds"),
300 "inter_mds", 0, NULL, NULL);
304 static int lmv_init_ea_size(struct obd_export *exp, int easize,
305 int def_easize, int cookiesize)
307 struct obd_device *obd = exp->exp_obd;
308 struct lmv_obd *lmv = &obd->u.lmv;
309 int i, rc = 0, change = 0;
312 if (lmv->max_easize < easize) {
313 lmv->max_easize = easize;
316 if (lmv->max_def_easize < def_easize) {
317 lmv->max_def_easize = def_easize;
320 if (lmv->max_cookiesize < cookiesize) {
321 lmv->max_cookiesize = cookiesize;
327 if (lmv->connected == 0)
330 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
331 if (lmv->tgts[i].ltd_exp == NULL) {
332 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
336 rc = md_init_ea_size(lmv->tgts[i].ltd_exp, easize, def_easize,
339 CERROR("obd_init_ea_size() failed on MDT target %d, "
340 "error %d.\n", i, rc);
347 #define MAX_STRING_SIZE 128
349 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
351 struct lmv_obd *lmv = &obd->u.lmv;
352 struct obd_uuid *cluuid = &lmv->cluuid;
353 struct obd_connect_data *mdc_data = NULL;
354 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
355 struct lustre_handle conn = {0, };
356 struct obd_device *mdc_obd;
357 struct obd_export *mdc_exp;
358 struct lu_fld_target target;
361 struct proc_dir_entry *lmv_proc_dir;
365 /* for MDS: don't connect to yourself */
366 if (obd_uuid_equals(&tgt->ltd_uuid, cluuid)) {
367 CDEBUG(D_CONFIG, "don't connect back to %s\n", cluuid->uuid);
368 /* XXX - the old code didn't increment active tgt count.
373 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
376 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
380 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
381 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
382 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
385 if (!mdc_obd->obd_set_up) {
386 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
390 rc = obd_connect(NULL, &conn, mdc_obd, &lmv_mdc_uuid,
393 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
397 mdc_exp = class_conn2export(&conn);
399 /* Init fid sequence client for this mdc. */
400 rc = obd_fid_init(mdc_exp);
404 /* Add new FLD target. */
405 target.ft_srv = NULL;
406 target.ft_exp = mdc_exp;
407 target.ft_idx = tgt->ltd_idx;
409 fld_client_add_target(&lmv->lmv_fld, &target);
411 mdc_data = &class_exp2cliimp(mdc_exp)->imp_connect_data;
413 rc = obd_register_observer(mdc_obd, obd);
415 obd_disconnect(mdc_exp);
416 CERROR("target %s register_observer error %d\n",
417 tgt->ltd_uuid.uuid, rc);
421 if (obd->obd_observer) {
422 /* tell the mds_lmv about the new target */
423 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
424 OBD_NOTIFY_ACTIVE, (void *)(tgt - lmv->tgts));
426 obd_disconnect(mdc_exp);
432 tgt->ltd_exp = mdc_exp;
433 lmv->desc.ld_active_tgt_count++;
435 /* copy connect data, it may be used later */
436 lmv->datas[tgt->ltd_idx] = *mdc_data;
438 md_init_ea_size(tgt->ltd_exp, lmv->max_easize,
439 lmv->max_def_easize, lmv->max_cookiesize);
441 CDEBUG(D_CONFIG, "connected to %s(%s) successfully (%d)\n",
442 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
443 atomic_read(&obd->obd_refcount));
446 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
448 struct proc_dir_entry *mdc_symlink;
449 char name[MAX_STRING_SIZE + 1];
451 LASSERT(mdc_obd->obd_type != NULL);
452 LASSERT(mdc_obd->obd_type->typ_name != NULL);
453 name[MAX_STRING_SIZE] = '\0';
454 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
455 mdc_obd->obd_type->typ_name,
457 mdc_symlink = proc_symlink(mdc_obd->obd_name,
459 if (mdc_symlink == NULL) {
460 CERROR("could not register LMV target "
461 "/proc/fs/lustre/%s/%s/target_obds/%s.",
462 obd->obd_type->typ_name, obd->obd_name,
464 lprocfs_remove(&lmv_proc_dir);
472 int lmv_add_target(struct obd_device *obd, struct obd_uuid *tgt_uuid)
474 struct lmv_obd *lmv = &obd->u.lmv;
475 struct lmv_tgt_desc *tgt;
479 CDEBUG(D_CONFIG, "tgt_uuid: %s.\n", tgt_uuid->uuid);
483 if (lmv->desc.ld_active_tgt_count >= LMV_MAX_TGT_COUNT) {
484 lmv_init_unlock(lmv);
485 CERROR("can't add %s, LMV module compiled for %d MDCs. "
486 "That many MDCs already configured.\n",
487 tgt_uuid->uuid, LMV_MAX_TGT_COUNT);
490 if (lmv->desc.ld_tgt_count == 0) {
491 struct obd_device *mdc_obd;
493 mdc_obd = class_find_client_obd(tgt_uuid, LUSTRE_MDC_NAME,
496 lmv_init_unlock(lmv);
497 CERROR("Target %s not attached\n", tgt_uuid->uuid);
501 rc = obd_llog_init(obd, NULL, mdc_obd, 0, NULL, tgt_uuid);
503 lmv_init_unlock(lmv);
504 CERROR("lmv failed to setup llogging subsystems\n");
507 spin_lock(&lmv->lmv_lock);
508 tgt = lmv->tgts + lmv->desc.ld_tgt_count++;
509 tgt->ltd_uuid = *tgt_uuid;
510 spin_unlock(&lmv->lmv_lock);
512 if (lmv->connected) {
513 rc = lmv_connect_mdc(obd, tgt);
515 spin_lock(&lmv->lmv_lock);
516 lmv->desc.ld_tgt_count--;
517 memset(tgt, 0, sizeof(*tgt));
518 spin_unlock(&lmv->lmv_lock);
520 int easize = sizeof(struct lmv_stripe_md) +
521 lmv->desc.ld_tgt_count *
522 sizeof(struct lu_fid);
523 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
527 lmv_init_unlock(lmv);
531 /* performs a check if passed obd is connected. If no - connect it. */
532 int lmv_check_connect(struct obd_device *obd)
534 struct lmv_obd *lmv = &obd->u.lmv;
535 struct lmv_tgt_desc *tgt;
543 if (lmv->connected) {
544 lmv_init_unlock(lmv);
548 if (lmv->desc.ld_tgt_count == 0) {
549 CERROR("%s: no targets configured.\n", obd->obd_name);
553 CDEBUG(D_CONFIG, "time to connect %s to %s\n",
554 lmv->cluuid.uuid, obd->obd_name);
556 LASSERT(lmv->tgts != NULL);
558 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
559 rc = lmv_connect_mdc(obd, tgt);
564 lmv_set_timeouts(obd);
565 class_export_put(lmv->exp);
567 easize = lmv_get_easize(lmv);
568 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
569 lmv_init_unlock(lmv);
578 --lmv->desc.ld_active_tgt_count;
579 rc2 = obd_disconnect(tgt->ltd_exp);
581 CERROR("error: LMV target %s disconnect on "
582 "MDC idx %d: error %d\n",
583 tgt->ltd_uuid.uuid, i, rc2);
587 class_disconnect(lmv->exp);
588 lmv_init_unlock(lmv);
592 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
595 struct proc_dir_entry *lmv_proc_dir;
597 struct lmv_obd *lmv = &obd->u.lmv;
598 struct obd_device *mdc_obd;
602 LASSERT(tgt != NULL);
603 LASSERT(obd != NULL);
605 mdc_obd = class_exp2obd(tgt->ltd_exp);
608 mdc_obd->obd_no_recov = obd->obd_no_recov;
611 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
613 struct proc_dir_entry *mdc_symlink;
615 mdc_symlink = lprocfs_srch(lmv_proc_dir, mdc_obd->obd_name);
617 lprocfs_remove(&mdc_symlink);
619 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing\n",
620 obd->obd_type->typ_name, obd->obd_name,
625 rc = obd_fid_fini(tgt->ltd_exp);
627 CERROR("Can't finanize fids factory\n");
629 CDEBUG(D_OTHER, "Disconnected from %s(%s) successfully\n",
630 tgt->ltd_exp->exp_obd->obd_name,
631 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
633 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
634 rc = obd_disconnect(tgt->ltd_exp);
636 if (tgt->ltd_active) {
637 CERROR("Target %s disconnect error %d\n",
638 tgt->ltd_uuid.uuid, rc);
642 lmv_activate_target(lmv, tgt, 0);
647 static int lmv_disconnect(struct obd_export *exp)
649 struct obd_device *obd = class_exp2obd(exp);
651 struct proc_dir_entry *lmv_proc_dir;
653 struct lmv_obd *lmv = &obd->u.lmv;
660 /* Only disconnect the underlying layers on the final disconnect. */
662 if (lmv->refcount != 0)
665 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
666 if (lmv->tgts[i].ltd_exp == NULL)
668 lmv_disconnect_mdc(obd, &lmv->tgts[i]);
672 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
674 lprocfs_remove(&lmv_proc_dir);
676 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
677 obd->obd_type->typ_name, obd->obd_name);
683 * This is the case when no real connection is established by
684 * lmv_check_connect().
687 class_export_put(exp);
688 rc = class_disconnect(exp);
689 if (lmv->refcount == 0)
694 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
695 int len, void *karg, void *uarg)
697 struct obd_device *obddev = class_exp2obd(exp);
698 struct lmv_obd *lmv = &obddev->u.lmv;
699 int i, rc = 0, set = 0;
702 if (lmv->desc.ld_tgt_count == 0)
705 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
708 if (lmv->tgts[i].ltd_exp == NULL)
711 err = obd_iocontrol(cmd, lmv->tgts[i].ltd_exp, len, karg, uarg);
713 if (lmv->tgts[i].ltd_active) {
714 CERROR("error: iocontrol MDC %s on MDT"
715 "idx %d: err = %d\n",
716 lmv->tgts[i].ltd_uuid.uuid, i, err);
734 static int lmv_all_chars_policy(int count, const char *name,
745 static int lmv_nid_policy(struct lmv_obd *lmv)
747 struct obd_import *imp = class_exp2cliimp(lmv->tgts[0].ltd_exp);
750 * XXX Hack: to get nid we assume that underlying obd device is mdc.
752 id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32);
753 return id % lmv->desc.ld_tgt_count;
756 static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
761 return lmv_all_chars_policy(lmv->desc.ld_tgt_count,
763 op_data->op_namelen);
765 return lmv_nid_policy(lmv);
771 CERROR("unsupport type %d \n", type);
775 /* This is _inode_ placement policy function (not name). */
776 static int lmv_placement_policy(struct obd_device *obd,
777 struct md_op_data *op_data,
780 struct lmv_obd *lmv = &obd->u.lmv;
785 LASSERT(mds != NULL);
788 * Allocate new fid on target according to operation type and parent
791 obj = lmv_obj_grab(obd, &op_data->op_fid1);
792 if (obj != NULL || op_data->op_name == NULL ||
793 op_data->op_opc != LUSTRE_OPC_MKDIR) {
795 * Allocate fid for non-dir or for null name or for case parent
802 * If we have this flag turned on, and we see that
803 * parent dir is split, this means, that caller did not
804 * notice split yet. This is race and we would like to
805 * let caller know that.
807 if (op_data->op_bias & MDS_CHECK_SPLIT)
812 * Allocate new fid on same mds where parent fid is located and
813 * where operation will be sent. In case of split dir, ->op_fid1
814 * and ->op_mds here will contain fid and mds of slave directory
815 * object (assigned by caller).
817 *mds = op_data->op_mds;
821 /* XXX: This should be removed later wehn we sure it is not
823 rc = lmv_fld_lookup(lmv, &op_data->op_fid1, mds);
829 * Parent directory is not split and we want to create a
830 * directory in it. Let's calculate where to place it according
833 *mds = lmv_choose_mds(lmv, op_data, NID_TYPE);
841 CERROR("Can't choose MDS, err = %d\n", rc);
843 LASSERT(*mds < lmv->desc.ld_tgt_count);
849 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
852 struct lmv_tgt_desc *tgt = &lmv->tgts[mds];
856 /* New seq alloc and FLD setup should be atomic. */
857 down(&tgt->ltd_fid_sem);
859 /* Asking underlaying tgt layer to allocate new fid. */
860 rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL);
862 LASSERT(fid_is_sane(fid));
864 /* Client switches to new sequence, setup FLD. */
865 rc = fld_client_create(&lmv->lmv_fld, fid_seq(fid),
868 CERROR("Can't create fld entry, rc %d\n", rc);
869 /* Delete just allocated fid sequence */
870 obd_fid_delete(tgt->ltd_exp, NULL);
873 up(&tgt->ltd_fid_sem);
877 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
878 struct md_op_data *op_data)
880 struct obd_device *obd = class_exp2obd(exp);
881 struct lmv_obd *lmv = &obd->u.lmv;
886 LASSERT(op_data != NULL);
887 LASSERT(fid != NULL);
889 rc = lmv_placement_policy(obd, op_data, &mds);
891 CERROR("Can't get target for allocating fid, "
896 rc = __lmv_fid_alloc(lmv, fid, mds);
898 CERROR("Can't alloc new fid, rc %d\n", rc);
905 static int lmv_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
910 if (lmv_obj_delete(exp, fid)) {
911 CDEBUG(D_OTHER, "lmv object "DFID" is destroyed.\n",
917 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
919 struct lmv_obd *lmv = &obd->u.lmv;
920 struct lprocfs_static_vars lvars;
921 struct lmv_desc *desc;
925 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
926 CERROR("LMV setup requires a descriptor\n");
930 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
931 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
932 CERROR("descriptor size wrong: %d > %d\n",
933 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
937 lmv->tgts_size = LMV_MAX_TGT_COUNT * sizeof(struct lmv_tgt_desc);
939 OBD_ALLOC(lmv->tgts, lmv->tgts_size);
940 if (lmv->tgts == NULL)
943 for (i = 0; i < LMV_MAX_TGT_COUNT; i++) {
944 sema_init(&lmv->tgts[i].ltd_fid_sem, 1);
945 lmv->tgts[i].ltd_idx = i;
948 lmv->datas_size = LMV_MAX_TGT_COUNT * sizeof(struct obd_connect_data);
950 OBD_ALLOC(lmv->datas, lmv->datas_size);
951 if (lmv->datas == NULL)
952 GOTO(out_free_tgts, rc = -ENOMEM);
954 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
955 lmv->desc.ld_tgt_count = 0;
956 lmv->desc.ld_active_tgt_count = 0;
957 lmv->max_cookiesize = 0;
958 lmv->max_def_easize = 0;
961 spin_lock_init(&lmv->lmv_lock);
962 sema_init(&lmv->init_sem, 1);
964 rc = lmv_obj_setup(obd);
966 CERROR("Can't setup LMV object manager, "
968 GOTO(out_free_datas, rc);
971 lprocfs_init_vars(lmv, &lvars);
972 lprocfs_obd_setup(obd, lvars.obd_vars);
975 struct proc_dir_entry *entry;
977 entry = create_proc_entry("target_obd_status", 0444,
978 obd->obd_proc_entry);
980 entry->proc_fops = &lmv_proc_target_fops;
985 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
986 LUSTRE_CLI_FLD_HASH_DHT);
988 CERROR("can't init FLD, err %d\n",
990 GOTO(out_free_datas, rc);
996 OBD_FREE(lmv->datas, lmv->datas_size);
999 OBD_FREE(lmv->tgts, lmv->tgts_size);
1004 static int lmv_cleanup(struct obd_device *obd)
1006 struct lmv_obd *lmv = &obd->u.lmv;
1009 fld_client_fini(&lmv->lmv_fld);
1010 lprocfs_obd_cleanup(obd);
1011 lmv_obj_cleanup(obd);
1012 OBD_FREE(lmv->datas, lmv->datas_size);
1013 OBD_FREE(lmv->tgts, lmv->tgts_size);
1018 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
1020 struct lustre_cfg *lcfg = buf;
1021 struct obd_uuid tgt_uuid;
1025 switch(lcfg->lcfg_command) {
1027 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(tgt_uuid.uuid))
1028 GOTO(out, rc = -EINVAL);
1030 obd_str2uuid(&tgt_uuid, lustre_cfg_string(lcfg, 1));
1031 rc = lmv_add_target(obd, &tgt_uuid);
1034 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1035 GOTO(out, rc = -EINVAL);
1042 static int lmv_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1045 struct lmv_obd *lmv = &obd->u.lmv;
1046 struct obd_statfs *temp;
1050 rc = lmv_check_connect(obd);
1054 OBD_ALLOC(temp, sizeof(*temp));
1058 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1059 if (lmv->tgts[i].ltd_exp == NULL)
1062 rc = obd_statfs(lmv->tgts[i].ltd_exp->exp_obd, temp, max_age);
1064 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1065 lmv->tgts[i].ltd_exp->exp_obd->obd_name,
1067 GOTO(out_free_temp, rc);
1072 osfs->os_bavail += temp->os_bavail;
1073 osfs->os_blocks += temp->os_blocks;
1074 osfs->os_ffree += temp->os_ffree;
1075 osfs->os_files += temp->os_files;
1081 OBD_FREE(temp, sizeof(*temp));
1085 static int lmv_getstatus(struct obd_export *exp,
1087 struct obd_capa **pc)
1089 struct obd_device *obd = exp->exp_obd;
1090 struct lmv_obd *lmv = &obd->u.lmv;
1094 rc = lmv_check_connect(obd);
1098 rc = md_getstatus(lmv->tgts[0].ltd_exp, fid, pc);
1103 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1104 struct obd_capa *oc, obd_valid valid, const char *name,
1105 const char *input, int input_size, int output_size,
1106 int flags, struct ptlrpc_request **request)
1108 struct obd_device *obd = exp->exp_obd;
1109 struct lmv_obd *lmv = &obd->u.lmv;
1110 struct obd_export *tgt_exp;
1114 rc = lmv_check_connect(obd);
1118 tgt_exp = lmv_find_export(lmv, fid);
1119 if (IS_ERR(tgt_exp))
1120 RETURN(PTR_ERR(tgt_exp));
1122 rc = md_getxattr(tgt_exp, fid, oc, valid, name, input, input_size,
1123 output_size, flags, request);
1128 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1129 struct obd_capa *oc, obd_valid valid, const char *name,
1130 const char *input, int input_size, int output_size,
1131 int flags, struct ptlrpc_request **request)
1133 struct obd_device *obd = exp->exp_obd;
1134 struct lmv_obd *lmv = &obd->u.lmv;
1135 struct obd_export *tgt_exp;
1139 rc = lmv_check_connect(obd);
1143 tgt_exp = lmv_find_export(lmv, fid);
1144 if (IS_ERR(tgt_exp))
1145 RETURN(PTR_ERR(tgt_exp));
1147 rc = md_setxattr(tgt_exp, fid, oc, valid, name,
1148 input, input_size, output_size, flags, request);
1153 static int lmv_getattr(struct obd_export *exp, const struct lu_fid *fid,
1154 struct obd_capa *oc, obd_valid valid, int ea_size,
1155 struct ptlrpc_request **request)
1157 struct obd_device *obd = exp->exp_obd;
1158 struct lmv_obd *lmv = &obd->u.lmv;
1159 struct obd_export *tgt_exp;
1160 struct lmv_obj *obj;
1164 rc = lmv_check_connect(obd);
1168 tgt_exp = lmv_find_export(lmv, fid);
1169 if (IS_ERR(tgt_exp))
1170 RETURN(PTR_ERR(tgt_exp));
1172 rc = md_getattr(tgt_exp, fid, oc, valid, ea_size, request);
1176 obj = lmv_obj_grab(obd, fid);
1178 CDEBUG(D_OTHER, "GETATTR for "DFID" %s\n", PFID(fid),
1179 obj ? "(split)" : "");
1182 * If object is split, then we loop over all the slaves and gather size
1183 * attribute. In ideal world we would have to gather also mds field from
1184 * all slaves, as object is spread over the cluster and this is
1185 * definitely interesting information and it is not good to loss it,
1189 struct mdt_body *body;
1191 if (*request == NULL) {
1196 body = lustre_msg_buf((*request)->rq_repmsg, REPLY_REC_OFF,
1198 LASSERT(body != NULL);
1199 LASSERT_REPSWABBED((*request), REPLY_REC_OFF);
1203 for (i = 0; i < obj->lo_objcount; i++) {
1204 if (lmv->tgts[i].ltd_exp == NULL) {
1205 CWARN("%s: NULL export for %d\n",
1210 /* skip master obj. */
1211 if (lu_fid_eq(&obj->lo_fid, &obj->lo_inodes[i].li_fid))
1214 lmv_update_body(body, &obj->lo_inodes[i]);
1217 lmv_obj_unlock(obj);
1224 static int lmv_change_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1225 ldlm_iterator_t it, void *data)
1227 struct obd_device *obd = exp->exp_obd;
1228 struct lmv_obd *lmv = &obd->u.lmv;
1232 rc = lmv_check_connect(obd);
1236 CDEBUG(D_OTHER, "CBDATA for "DFID"\n", PFID(fid));
1239 * With CMD every object can have two locks in different namespaces:
1240 * lookup lock in space of mds storing direntry and update/open lock in
1241 * space of mds storing inode.
1243 for (i = 0; i < lmv->desc.ld_tgt_count; i++)
1244 md_change_cbdata(lmv->tgts[i].ltd_exp, fid, it, data);
1249 static int lmv_close(struct obd_export *exp,
1250 struct md_op_data *op_data,
1251 struct obd_client_handle *och,
1252 struct ptlrpc_request **request)
1254 struct obd_device *obd = exp->exp_obd;
1255 struct lmv_obd *lmv = &obd->u.lmv;
1256 struct obd_export *tgt_exp;
1260 rc = lmv_check_connect(obd);
1264 tgt_exp = lmv_find_export(lmv, &op_data->op_fid1);
1265 if (IS_ERR(tgt_exp))
1266 RETURN(PTR_ERR(tgt_exp));
1268 CDEBUG(D_OTHER, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1269 rc = md_close(tgt_exp, op_data, och, request);
1274 * Called in the case MDS returns -ERESTART on create on open, what means that
1275 * directory is split and its LMV presentation object has to be updated.
1277 int lmv_handle_split(struct obd_export *exp, const struct lu_fid *fid)
1279 struct obd_device *obd = exp->exp_obd;
1280 struct lmv_obd *lmv = &obd->u.lmv;
1281 struct ptlrpc_request *req = NULL;
1282 struct obd_export *tgt_exp;
1283 struct lmv_obj *obj;
1284 struct lustre_md md;
1290 mealen = lmv_get_easize(lmv);
1292 valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA | OBD_MD_MEA;
1294 tgt_exp = lmv_find_export(lmv, fid);
1295 if (IS_ERR(tgt_exp))
1296 RETURN(PTR_ERR(tgt_exp));
1298 /* time to update mea of parent fid */
1299 rc = md_getattr(tgt_exp, fid, NULL, valid, mealen, &req);
1301 CERROR("md_getattr() failed, error %d\n", rc);
1305 rc = md_get_lustre_md(tgt_exp, req, 1, NULL, exp, &md);
1307 CERROR("mdc_get_lustre_md() failed, error %d\n", rc);
1312 GOTO(cleanup, rc = -ENODATA);
1314 obj = lmv_obj_create(exp, fid, md.mea);
1320 obd_free_memmd(exp, (struct lov_stripe_md **)&md.mea);
1325 ptlrpc_req_finished(req);
1329 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1330 const void *data, int datalen, int mode, __u32 uid,
1331 __u32 gid, __u32 cap_effective, __u64 rdev,
1332 struct ptlrpc_request **request)
1334 struct obd_device *obd = exp->exp_obd;
1335 struct lmv_obd *lmv = &obd->u.lmv;
1336 struct obd_export *tgt_exp;
1337 struct lmv_obj *obj;
1341 rc = lmv_check_connect(obd);
1345 if (!lmv->desc.ld_active_tgt_count)
1350 obj = lmv_obj_grab(obd, &op_data->op_fid1);
1354 mea_idx = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1355 op_data->op_name, op_data->op_namelen);
1356 op_data->op_fid1 = obj->lo_inodes[mea_idx].li_fid;
1357 op_data->op_bias &= ~MDS_CHECK_SPLIT;
1358 op_data->op_mds = obj->lo_inodes[mea_idx].li_mds;
1359 tgt_exp = lmv_get_export(lmv, op_data->op_mds);
1362 struct lmv_tgt_desc *tgt;
1364 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1365 op_data->op_bias |= MDS_CHECK_SPLIT;
1366 op_data->op_mds = tgt->ltd_idx;
1367 tgt_exp = tgt->ltd_exp;
1370 if (IS_ERR(tgt_exp))
1371 RETURN(PTR_ERR(tgt_exp));
1373 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1374 if (rc == -ERESTART)
1379 CDEBUG(D_OTHER, "CREATE '%*s' on "DFID"\n", op_data->op_namelen,
1380 op_data->op_name, PFID(&op_data->op_fid1));
1382 rc = md_create(tgt_exp, op_data, data, datalen, mode, uid, gid,
1383 cap_effective, rdev, request);
1385 if (*request == NULL)
1387 CDEBUG(D_OTHER, "created - "DFID"\n", PFID(&op_data->op_fid1));
1388 } else if (rc == -ERESTART) {
1389 LASSERT(*request != NULL);
1390 DEBUG_REQ(D_WARNING|D_RPCTRACE, *request,
1391 "Got -ERESTART during create!\n");
1392 ptlrpc_req_finished(*request);
1396 * Directory got split. Time to update local object and repeat
1397 * the request with proper MDS.
1399 rc = lmv_handle_split(exp, &op_data->op_fid1);
1401 rc = lmv_alloc_slave_fids(obd, &op_data->op_fid1,
1402 op_data, &op_data->op_fid2);
1411 static int lmv_done_writing(struct obd_export *exp,
1412 struct md_op_data *op_data,
1413 struct obd_client_handle *och)
1415 struct obd_device *obd = exp->exp_obd;
1416 struct lmv_obd *lmv = &obd->u.lmv;
1417 struct obd_export *tgt_exp;
1421 rc = lmv_check_connect(obd);
1425 tgt_exp = lmv_find_export(lmv, &op_data->op_fid1);
1426 if (IS_ERR(tgt_exp))
1427 RETURN(PTR_ERR(tgt_exp));
1429 rc = md_done_writing(tgt_exp, op_data, och);
1434 lmv_enqueue_slaves(struct obd_export *exp, int locktype,
1435 struct lookup_intent *it, int lockmode,
1436 struct md_op_data *op_data, struct lustre_handle *lockh,
1437 void *lmm, int lmmsize, ldlm_completion_callback cb_compl,
1438 ldlm_blocking_callback cb_blocking, void *cb_data)
1440 struct obd_device *obd = exp->exp_obd;
1441 struct lmv_obd *lmv = &obd->u.lmv;
1442 struct lmv_stripe_md *mea = op_data->op_mea1;
1443 struct md_op_data *op_data2;
1444 struct obd_export *tgt_exp;
1448 OBD_ALLOC_PTR(op_data2);
1449 if (op_data2 == NULL)
1452 LASSERT(mea != NULL);
1453 for (i = 0; i < mea->mea_count; i++) {
1454 memset(op_data2, 0, sizeof(*op_data2));
1455 op_data2->op_fid1 = mea->mea_ids[i];
1456 op_data2->op_bias = 0;
1458 tgt_exp = lmv_find_export(lmv, &op_data2->op_fid1);
1459 if (IS_ERR(tgt_exp))
1460 GOTO(cleanup, rc = PTR_ERR(tgt_exp));
1462 if (tgt_exp == NULL)
1465 rc = md_enqueue(tgt_exp, locktype, it, lockmode, op_data2,
1466 lockh + i, lmm, lmmsize, cb_compl, cb_blocking,
1469 CDEBUG(D_OTHER, "take lock on slave "DFID" -> %d/%d\n",
1470 PFID(&mea->mea_ids[i]), rc, it->d.lustre.it_status);
1475 if (it->d.lustre.it_data) {
1476 struct ptlrpc_request *req;
1477 req = (struct ptlrpc_request *)it->d.lustre.it_data;
1478 ptlrpc_req_finished(req);
1481 if (it->d.lustre.it_status)
1482 GOTO(cleanup, rc = it->d.lustre.it_status);
1487 OBD_FREE_PTR(op_data2);
1490 /* drop all taken locks */
1492 if (lockh[i].cookie)
1493 ldlm_lock_decref(lockh + i, lockmode);
1494 lockh[i].cookie = 0;
1501 lmv_enqueue_remote(struct obd_export *exp, int lock_type,
1502 struct lookup_intent *it, int lock_mode,
1503 struct md_op_data *op_data, struct lustre_handle *lockh,
1504 void *lmm, int lmmsize, ldlm_completion_callback cb_compl,
1505 ldlm_blocking_callback cb_blocking, void *cb_data,
1506 int extra_lock_flags)
1508 struct ptlrpc_request *req = it->d.lustre.it_data;
1509 struct obd_device *obd = exp->exp_obd;
1510 struct lmv_obd *lmv = &obd->u.lmv;
1511 struct lustre_handle plock;
1512 struct obd_export *tgt_exp;
1513 struct md_op_data *rdata;
1514 struct lu_fid fid_copy;
1515 struct mdt_body *body;
1519 body = lustre_msg_buf(req->rq_repmsg,
1520 DLM_REPLY_REC_OFF, sizeof(*body));
1521 LASSERT(body != NULL);
1522 LASSERT_REPSWABBED(req, DLM_REPLY_REC_OFF);
1524 if (!(body->valid & OBD_MD_MDS))
1527 CDEBUG(D_OTHER, "ENQUEUE '%s' on "DFID" -> "DFID"\n",
1528 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1530 /* We got LOOKUP lock, but we really need attrs */
1531 pmode = it->d.lustre.it_lock_mode;
1532 LASSERT(pmode != 0);
1533 memcpy(&plock, lockh, sizeof(plock));
1534 it->d.lustre.it_lock_mode = 0;
1535 it->d.lustre.it_data = NULL;
1536 fid_copy = body->fid1;
1538 it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
1539 ptlrpc_req_finished(req);
1541 tgt_exp = lmv_find_export(lmv, &fid_copy);
1542 if (IS_ERR(tgt_exp))
1543 GOTO(out, rc = PTR_ERR(tgt_exp));
1545 OBD_ALLOC_PTR(rdata);
1547 GOTO(out, rc = -ENOMEM);
1549 rdata->op_fid1 = fid_copy;
1550 rdata->op_bias = MDS_CROSS_REF;
1552 rc = md_enqueue(tgt_exp, lock_type, it, lock_mode, rdata,
1553 lockh, lmm, lmmsize, cb_compl, cb_blocking,
1554 cb_data, extra_lock_flags);
1555 OBD_FREE_PTR(rdata);
1558 ldlm_lock_decref(&plock, pmode);
1563 lmv_enqueue(struct obd_export *exp, int lock_type,
1564 struct lookup_intent *it, int lock_mode,
1565 struct md_op_data *op_data, struct lustre_handle *lockh,
1566 void *lmm, int lmmsize, ldlm_completion_callback cb_compl,
1567 ldlm_blocking_callback cb_blocking, void *cb_data,
1568 int extra_lock_flags)
1570 struct obd_device *obd = exp->exp_obd;
1571 struct lmv_obd *lmv = &obd->u.lmv;
1572 struct obd_export *tgt_exp = NULL;
1573 struct lmv_obj *obj;
1577 rc = lmv_check_connect(obd);
1581 if (op_data->op_mea1 && it->it_op == IT_UNLINK) {
1582 rc = lmv_enqueue_slaves(exp, lock_type, it, lock_mode,
1583 op_data, lockh, lmm, lmmsize,
1584 cb_compl, cb_blocking, cb_data);
1588 if (op_data->op_namelen) {
1589 obj = lmv_obj_grab(obd, &op_data->op_fid1);
1593 /* directory is split. look for right mds for this
1595 mea_idx = raw_name2idx(obj->lo_hashtype,
1597 (char *)op_data->op_name,
1598 op_data->op_namelen);
1599 op_data->op_fid1 = obj->lo_inodes[mea_idx].li_fid;
1600 tgt_exp = lmv_get_export(lmv, obj->lo_inodes[mea_idx].li_mds);
1605 if (tgt_exp == NULL)
1606 tgt_exp = lmv_find_export(lmv, &op_data->op_fid1);
1607 if (IS_ERR(tgt_exp))
1608 RETURN(PTR_ERR(tgt_exp));
1610 CDEBUG(D_OTHER, "ENQUEUE '%s' on "DFID"\n", LL_IT2STR(it),
1611 PFID(&op_data->op_fid1));
1613 rc = md_enqueue(tgt_exp, lock_type, it, lock_mode, op_data, lockh,
1614 lmm, lmmsize, cb_compl, cb_blocking, cb_data,
1617 if (rc == 0 && it->it_op == IT_OPEN)
1618 rc = lmv_enqueue_remote(exp, lock_type, it, lock_mode,
1619 op_data, lockh, lmm, lmmsize,
1620 cb_compl, cb_blocking, cb_data,
1626 lmv_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
1627 struct obd_capa *oc, const char *filename, int namelen,
1628 obd_valid valid, int ea_size, struct ptlrpc_request **request)
1630 struct obd_device *obd = exp->exp_obd;
1631 struct lmv_obd *lmv = &obd->u.lmv;
1632 struct lu_fid rid = *fid;
1633 struct obd_export *tgt_exp;
1634 struct mdt_body *body;
1635 struct lmv_obj *obj;
1639 rc = lmv_check_connect(obd);
1646 obj = lmv_obj_grab(obd, &rid);
1650 /* Directory is split. Look for right mds for this name */
1651 mea_idx = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1652 filename, namelen - 1);
1653 rid = obj->lo_inodes[mea_idx].li_fid;
1654 tgt_exp = lmv_get_export(lmv, obj->lo_inodes[mea_idx].li_mds);
1656 valid &= ~OBD_MD_FLCKSPLIT;
1658 tgt_exp = lmv_find_export(lmv, &rid);
1659 valid |= OBD_MD_FLCKSPLIT;
1661 if (IS_ERR(tgt_exp))
1662 RETURN(PTR_ERR(tgt_exp));
1664 CDEBUG(D_OTHER, "getattr_name for %*s on "DFID" -> "DFID"\n",
1665 namelen, filename, PFID(fid), PFID(&rid));
1667 rc = md_getattr_name(tgt_exp, &rid, oc, filename, namelen, valid,
1670 body = lustre_msg_buf((*request)->rq_repmsg,
1671 REQ_REC_OFF, sizeof(*body));
1672 LASSERT(body != NULL);
1673 LASSERT_REPSWABBED((*request), REQ_REC_OFF);
1675 if (body->valid & OBD_MD_MDS) {
1676 struct ptlrpc_request *req = NULL;
1679 CDEBUG(D_OTHER, "request attrs for "DFID"\n",
1682 tgt_exp = lmv_find_export(lmv, &rid);
1683 if (IS_ERR(tgt_exp)) {
1684 ptlrpc_req_finished(*request);
1685 RETURN(PTR_ERR(tgt_exp));
1688 rc = md_getattr_name(tgt_exp, &rid, NULL, NULL, 1,
1689 valid | OBD_MD_FLCROSSREF,
1691 ptlrpc_req_finished(*request);
1694 } else if (rc == -ERESTART) {
1695 LASSERT(*request != NULL);
1696 DEBUG_REQ(D_WARNING|D_RPCTRACE, *request,
1697 "Got -ERESTART during getattr!\n");
1698 ptlrpc_req_finished(*request);
1702 * Directory got split. Time to update local object and repeat
1703 * the request with proper MDS.
1705 rc = lmv_handle_split(exp, &rid);
1713 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1716 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1717 struct ptlrpc_request **request)
1719 struct obd_device *obd = exp->exp_obd;
1720 struct lmv_obd *lmv = &obd->u.lmv;
1721 struct lmv_obj *obj;
1726 rc = lmv_check_connect(obd);
1733 if (op_data->op_namelen != 0) {
1736 /* Usual link request */
1737 obj = lmv_obj_grab(obd, &op_data->op_fid2);
1739 mea_idx = raw_name2idx(obj->lo_hashtype,
1742 op_data->op_namelen);
1743 op_data->op_fid2 = obj->lo_inodes[mea_idx].li_fid;
1744 mds = obj->lo_inodes[mea_idx].li_mds;
1747 rc = lmv_fld_lookup(lmv, &op_data->op_fid2, &mds);
1752 CDEBUG(D_OTHER,"link "DFID":%*s to "DFID"\n",
1753 PFID(&op_data->op_fid2), op_data->op_namelen,
1754 op_data->op_name, PFID(&op_data->op_fid1));
1756 rc = lmv_fld_lookup(lmv, &op_data->op_fid1, &mds);
1760 /* request from MDS to acquire i_links for inode by fid1 */
1761 CDEBUG(D_OTHER, "inc i_nlinks for "DFID"\n",
1762 PFID(&op_data->op_fid1));
1765 CDEBUG(D_OTHER, "forward to MDS #"LPU64" ("DFID")\n",
1766 mds, PFID(&op_data->op_fid1));
1768 op_data->op_fsuid = current->fsuid;
1769 op_data->op_fsgid = current->fsgid;
1770 op_data->op_cap = current->cap_effective;
1772 rc = md_link(lmv->tgts[mds].ltd_exp, op_data, request);
1773 if (rc == -ERESTART) {
1774 LASSERT(*request != NULL);
1775 DEBUG_REQ(D_WARNING|D_RPCTRACE, *request,
1776 "Got -ERESTART during link!\n");
1777 ptlrpc_req_finished(*request);
1781 * Directory got split. Time to update local object and repeat
1782 * the request with proper MDS.
1784 rc = lmv_handle_split(exp, &op_data->op_fid2);
1792 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1793 const char *old, int oldlen, const char *new, int newlen,
1794 struct ptlrpc_request **request)
1796 struct obd_device *obd = exp->exp_obd;
1797 struct lmv_obd *lmv = &obd->u.lmv;
1798 int rc, mea_idx, loop = 0;
1799 struct lmv_obj *obj;
1803 CDEBUG(D_OTHER, "rename %*s in "DFID" to %*s in "DFID"\n",
1804 oldlen, old, PFID(&op_data->op_fid1),
1805 newlen, new, PFID(&op_data->op_fid2));
1807 rc = lmv_check_connect(obd);
1813 * MDS with old dir entry is asking another MDS to create name
1817 "create %*s(%d/%d) in "DFID" pointing "
1818 "to "DFID"\n", newlen, new, oldlen, newlen,
1819 PFID(&op_data->op_fid2), PFID(&op_data->op_fid1));
1821 rc = lmv_fld_lookup(lmv, &op_data->op_fid2, &mds);
1826 * Target directory can be split, sowe should forward request to
1829 obj = lmv_obj_grab(obd, &op_data->op_fid2);
1831 mea_idx = raw_name2idx(obj->lo_hashtype,
1833 (char *)new, newlen);
1834 op_data->op_fid2 = obj->lo_inodes[mea_idx].li_fid;
1835 CDEBUG(D_OTHER, "Parent obj "DFID"\n",
1836 PFID(&op_data->op_fid2));
1845 obj = lmv_obj_grab(obd, &op_data->op_fid1);
1848 * directory is already split, so we have to forward request to
1851 mea_idx = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1852 (char *)old, oldlen);
1853 op_data->op_fid1 = obj->lo_inodes[mea_idx].li_fid;
1854 mds = obj->lo_inodes[mea_idx].li_mds;
1855 CDEBUG(D_OTHER, "Parent obj "DFID"\n", PFID(&op_data->op_fid1));
1858 rc = lmv_fld_lookup(lmv, &op_data->op_fid1, &mds);
1863 obj = lmv_obj_grab(obd, &op_data->op_fid2);
1866 * Directory is already split, so we have to forward request to
1869 mea_idx = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1870 (char *)new, newlen);
1872 op_data->op_fid2 = obj->lo_inodes[mea_idx].li_fid;
1873 CDEBUG(D_OTHER, "Parent obj "DFID"\n", PFID(&op_data->op_fid2));
1878 op_data->op_fsuid = current->fsuid;
1879 op_data->op_fsgid = current->fsgid;
1880 op_data->op_cap = current->cap_effective;
1882 rc = md_rename(lmv->tgts[mds].ltd_exp, op_data, old, oldlen,
1883 new, newlen, request);
1884 if (rc == -ERESTART) {
1885 LASSERT(*request != NULL);
1886 DEBUG_REQ(D_WARNING|D_RPCTRACE, *request,
1887 "Got -ERESTART during rename!\n");
1888 ptlrpc_req_finished(*request);
1892 * Directory got split. Time to update local object and repeat
1893 * the request with proper MDS.
1895 rc = lmv_handle_split(exp, &op_data->op_fid1);
1902 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
1903 void *ea, int ealen, void *ea2, int ea2len,
1904 struct ptlrpc_request **request)
1906 struct obd_device *obd = exp->exp_obd;
1907 struct lmv_obd *lmv = &obd->u.lmv;
1908 struct ptlrpc_request *req;
1909 struct obd_export *tgt_exp;
1910 struct lmv_obj *obj;
1914 rc = lmv_check_connect(obd);
1918 obj = lmv_obj_grab(obd, &op_data->op_fid1);
1920 CDEBUG(D_OTHER, "SETATTR for "DFID", valid 0x%x%s\n",
1921 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid,
1922 obj ? ", split" : "");
1925 for (i = 0; i < obj->lo_objcount; i++) {
1926 op_data->op_fid1 = obj->lo_inodes[i].li_fid;
1928 tgt_exp = lmv_get_export(lmv, obj->lo_inodes[i].li_mds);
1929 if (IS_ERR(tgt_exp)) {
1930 rc = PTR_ERR(tgt_exp);
1934 rc = md_setattr(tgt_exp, op_data, ea, ealen,
1937 if (lu_fid_eq(&obj->lo_fid, &obj->lo_inodes[i].li_fid)) {
1939 * this is master object and this request should
1940 * be returned back to llite.
1944 ptlrpc_req_finished(req);
1952 tgt_exp = lmv_find_export(lmv, &op_data->op_fid1);
1953 if (IS_ERR(tgt_exp))
1954 RETURN(PTR_ERR(tgt_exp));
1956 rc = md_setattr(tgt_exp, op_data, ea, ealen, ea2,
1962 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
1963 struct obd_capa *oc, struct ptlrpc_request **request)
1965 struct obd_device *obd = exp->exp_obd;
1966 struct lmv_obd *lmv = &obd->u.lmv;
1967 struct obd_export *tgt_exp;
1971 rc = lmv_check_connect(obd);
1975 tgt_exp = lmv_find_export(lmv, fid);
1976 if (IS_ERR(tgt_exp))
1977 RETURN(PTR_ERR(tgt_exp));
1979 rc = md_sync(tgt_exp, fid, oc, request);
1983 /* main purpose of LMV blocking ast is to remove split directory LMV
1984 * presentation object (struct lmv_obj) attached to the lock being revoked. */
1985 int lmv_blocking_ast(struct ldlm_lock *lock,
1986 struct ldlm_lock_desc *desc,
1987 void *data, int flag)
1989 struct lustre_handle lockh;
1990 struct lmv_obj *obj;
1995 case LDLM_CB_BLOCKING:
1996 ldlm_lock2handle(lock, &lockh);
1997 rc = ldlm_cli_cancel(&lockh);
1999 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
2003 case LDLM_CB_CANCELING:
2004 /* time to drop cached attrs for dirobj */
2005 obj = lock->l_ast_data;
2007 CDEBUG(D_OTHER, "cancel %s on "LPU64"/"LPU64
2008 ", master "DFID"\n",
2009 lock->l_resource->lr_name.name[3] == 1 ?
2010 "LOOKUP" : "UPDATE",
2011 lock->l_resource->lr_name.name[0],
2012 lock->l_resource->lr_name.name[1],
2013 PFID(&obj->lo_fid));
2023 static void lmv_hash_adjust(__u32 *hash, __u32 hash_adj)
2027 val = le32_to_cpu(*hash);
2029 val += MAX_HASH_SIZE;
2030 if (val != DIR_END_OFF)
2031 *hash = cpu_to_le32(val - hash_adj);
2034 static __u32 lmv_node_rank(struct obd_export *exp, const struct lu_fid *fid)
2037 struct obd_import *imp;
2040 * XXX Hack: to get nid we assume that underlying obd device is mdc.
2042 imp = class_exp2cliimp(exp);
2043 id = imp->imp_connection->c_self + fid_flatten(fid);
2045 CDEBUG(D_INFO, "node rank: %llx "DFID" %llx %llx\n",
2046 imp->imp_connection->c_self, PFID(fid), id, id ^ (id >> 32));
2048 return id ^ (id >> 32);
2051 static int lmv_readpage(struct obd_export *exp, const struct lu_fid *fid,
2052 struct obd_capa *oc, __u64 offset64, struct page *page,
2053 struct ptlrpc_request **request)
2055 struct obd_device *obd = exp->exp_obd;
2056 struct lmv_obd *lmv = &obd->u.lmv;
2057 struct obd_export *tgt_exp;
2058 struct lu_fid rid = *fid;
2059 struct lmv_obj *obj;
2071 offset0 = offset = offset64;
2073 * Check that offset is representable by 32bit number.
2075 LASSERT((__u64)offset == offset64);
2077 rc = lmv_check_connect(obd);
2081 CDEBUG(D_INFO, "READPAGE at %x from "DFID"\n", offset, PFID(&rid));
2083 obj = lmv_obj_grab(obd, fid);
2085 struct lmv_inode *loi;
2089 nr = obj->lo_objcount;
2091 seg_size = MAX_HASH_SIZE / nr;
2092 loi = obj->lo_inodes;
2093 rank = lmv_node_rank(lmv_get_export(lmv, loi[0].li_mds),
2095 tgt0 = (offset / seg_size) % nr;
2096 tgt = (tgt0 + rank) % nr;
2102 * Last segment has unusual length due to division
2105 hash_adj = MAX_HASH_SIZE - seg_size * nr;
2109 hash_adj += rank * seg_size;
2111 CDEBUG(D_INFO, "hash_adj: %x %x %x/%x -> %x/%x\n",
2112 rank, hash_adj, offset, tgt0, offset + hash_adj, tgt);
2114 offset = (offset + hash_adj) % MAX_HASH_SIZE;
2115 rid = obj->lo_inodes[tgt].li_fid;
2116 tgt_exp = lmv_get_export(lmv, loi[tgt].li_mds);
2118 CDEBUG(D_INFO, "forward to "DFID" with offset %lu i %d\n",
2119 PFID(&rid), (unsigned long)offset, tgt);
2121 tgt_exp = lmv_find_export(lmv, &rid);
2123 if (IS_ERR(tgt_exp))
2124 GOTO(cleanup, rc = PTR_ERR(tgt_exp));
2126 rc = md_readpage(tgt_exp, &rid, oc, offset, page, request);
2130 struct lu_dirpage *dp;
2131 struct lu_dirent *ent;
2133 dp = cfs_kmap(page);
2135 lmv_hash_adjust(&dp->ldp_hash_start, hash_adj);
2136 lmv_hash_adjust(&dp->ldp_hash_end, hash_adj);
2137 LASSERT(cpu_to_le32(dp->ldp_hash_start) <= offset0);
2139 for (ent = lu_dirent_start(dp); ent != NULL;
2140 ent = lu_dirent_next(ent))
2141 lmv_hash_adjust(&ent->lde_hash, hash_adj);
2143 if (tgt0 != nr - 1) {
2146 end = le32_to_cpu(dp->ldp_hash_end);
2147 if (end == DIR_END_OFF) {
2148 dp->ldp_hash_end = cpu_to_le32(seg_size *
2150 CDEBUG(D_INFO, ""DFID" reset end %x tgt %d\n",
2152 le32_to_cpu(dp->ldp_hash_end), tgt);
2158 * Here we could remove "." and ".." from all pages which at not from
2159 * master. But MDS has only "." and ".." for master dir.
2164 lmv_obj_unlock(obj);
2170 static int lmv_unlink_slaves(struct obd_export *exp,
2171 struct md_op_data *op_data,
2172 struct ptlrpc_request **req)
2174 struct obd_device *obd = exp->exp_obd;
2175 struct lmv_obd *lmv = &obd->u.lmv;
2176 struct lmv_stripe_md *mea = op_data->op_mea1;
2177 struct md_op_data *op_data2;
2178 struct obd_export *tgt_exp;
2182 OBD_ALLOC_PTR(op_data2);
2183 if (op_data2 == NULL)
2186 op_data2->op_mode = S_IFDIR;
2187 op_data2->op_fsuid = current->fsuid;
2188 op_data2->op_fsgid = current->fsgid;
2189 op_data2->op_bias = 0;
2191 LASSERT(mea != NULL);
2192 for (i = 0; i < mea->mea_count; i++) {
2193 memset(op_data2, 0, sizeof(*op_data2));
2194 op_data2->op_fid1 = mea->mea_ids[i];
2195 tgt_exp = lmv_find_export(lmv, &op_data2->op_fid1);
2196 if (IS_ERR(tgt_exp))
2197 GOTO(out_free_op_data2, rc = PTR_ERR(tgt_exp));
2199 if (tgt_exp == NULL)
2202 rc = md_unlink(tgt_exp, op_data2, req);
2204 CDEBUG(D_OTHER, "unlink slave "DFID" -> %d\n",
2205 PFID(&mea->mea_ids[i]), rc);
2208 ptlrpc_req_finished(*req);
2212 GOTO(out_free_op_data2, rc);
2217 OBD_FREE_PTR(op_data2);
2221 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2222 struct ptlrpc_request **request)
2224 struct obd_device *obd = exp->exp_obd;
2225 struct lmv_obd *lmv = &obd->u.lmv;
2226 struct obd_export *tgt_exp = NULL;
2230 rc = lmv_check_connect(obd);
2234 if (op_data->op_namelen == 0 && op_data->op_mea1 != NULL) {
2235 /* mds asks to remove slave objects */
2236 rc = lmv_unlink_slaves(exp, op_data, request);
2243 if (op_data->op_namelen != 0) {
2244 struct lmv_obj *obj;
2247 obj = lmv_obj_grab(obd, &op_data->op_fid1);
2249 mea_idx = raw_name2idx(obj->lo_hashtype,
2252 op_data->op_namelen);
2253 op_data->op_bias &= ~MDS_CHECK_SPLIT;
2254 op_data->op_fid1 = obj->lo_inodes[mea_idx].li_fid;
2255 tgt_exp = lmv_get_export(lmv,
2256 obj->lo_inodes[mea_idx].li_mds);
2258 CDEBUG(D_OTHER, "unlink '%*s' in "DFID" -> %u\n",
2259 op_data->op_namelen, op_data->op_name,
2260 PFID(&op_data->op_fid1), mea_idx);
2263 CDEBUG(D_OTHER, "drop i_nlink on "DFID"\n",
2264 PFID(&op_data->op_fid1));
2266 if (tgt_exp == NULL) {
2267 tgt_exp = lmv_find_export(lmv, &op_data->op_fid1);
2268 if (IS_ERR(tgt_exp))
2269 RETURN(PTR_ERR(tgt_exp));
2270 op_data->op_bias |= MDS_CHECK_SPLIT;
2273 op_data->op_fsuid = current->fsuid;
2274 op_data->op_fsgid = current->fsgid;
2275 op_data->op_cap = current->cap_effective;
2277 rc = md_unlink(tgt_exp, op_data, request);
2278 if (rc == -ERESTART) {
2279 LASSERT(*request != NULL);
2280 DEBUG_REQ(D_WARNING|D_RPCTRACE, *request,
2281 "Got -ERESTART during unlink!\n");
2282 ptlrpc_req_finished(*request);
2286 * Directory got split. Time to update local object and repeat
2287 * the request with proper MDS.
2289 rc = lmv_handle_split(exp, &op_data->op_fid1);
2296 static int lmv_llog_init(struct obd_device *obd, struct obd_llogs* llogs,
2297 struct obd_device *tgt, int count,
2298 struct llog_catid *logid, struct obd_uuid *uuid)
2300 struct llog_ctxt *ctxt;
2304 rc = llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
2307 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
2308 ctxt->loc_imp = tgt->u.cli.cl_import;
2314 static int lmv_llog_finish(struct obd_device *obd, int count)
2319 rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
2323 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2328 case OBD_CLEANUP_EARLY:
2329 /* XXX: here should be calling obd_precleanup() down to
2332 case OBD_CLEANUP_SELF_EXP:
2333 rc = obd_llog_finish(obd, 0);
2335 CERROR("failed to cleanup llogging subsystems\n");
2343 static int lmv_get_info(struct obd_export *exp, __u32 keylen,
2344 void *key, __u32 *vallen, void *val)
2346 struct obd_device *obd;
2347 struct lmv_obd *lmv;
2351 obd = class_exp2obd(exp);
2353 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
2354 exp->exp_handle.h_cookie);
2359 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2360 struct lmv_tgt_desc *tgts;
2363 rc = lmv_check_connect(obd);
2367 LASSERT(*vallen == sizeof(__u32));
2368 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count;
2371 /* all tgts should be connected when this get called. */
2372 if (!tgts || !tgts->ltd_exp) {
2373 CERROR("target not setup?\n");
2377 if (!obd_get_info(tgts->ltd_exp, keylen, key,
2382 } else if (KEY_IS(KEY_MAX_EASIZE) || KEY_IS(KEY_CONN_DATA)) {
2383 rc = lmv_check_connect(obd);
2387 /* forwarding this request to first MDS, it should know LOV
2389 rc = obd_get_info(lmv->tgts[0].ltd_exp, keylen, key,
2391 if (!rc && KEY_IS(KEY_CONN_DATA)) {
2392 exp->exp_connect_flags =
2393 ((struct obd_connect_data *)val)->ocd_connect_flags;
2398 CDEBUG(D_IOCTL, "invalid key\n");
2402 int lmv_set_info_async(struct obd_export *exp, obd_count keylen,
2403 void *key, obd_count vallen, void *val,
2404 struct ptlrpc_request_set *set)
2406 struct lmv_tgt_desc *tgt;
2407 struct obd_device *obd;
2408 struct lmv_obd *lmv;
2412 obd = class_exp2obd(exp);
2414 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
2415 exp->exp_handle.h_cookie);
2420 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX) ||
2421 KEY_IS(KEY_INIT_RECOV_BACKUP)) {
2424 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2425 tgt = &lmv->tgts[i];
2430 err = obd_set_info_async(tgt->ltd_exp,
2431 keylen, key, vallen, val, set);
2442 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2443 struct lov_stripe_md *lsm)
2445 struct obd_device *obd = class_exp2obd(exp);
2446 struct lmv_obd *lmv = &obd->u.lmv;
2447 struct lmv_stripe_md *meap, *lsmp;
2451 mea_size = lmv_get_easize(lmv);
2455 if (*lmmp && !lsm) {
2456 OBD_FREE(*lmmp, mea_size);
2461 if (*lmmp == NULL) {
2462 OBD_ALLOC(*lmmp, mea_size);
2470 lsmp = (struct lmv_stripe_md *)lsm;
2471 meap = (struct lmv_stripe_md *)*lmmp;
2473 if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR &&
2474 lsmp->mea_magic != MEA_MAGIC_ALL_CHARS)
2477 meap->mea_magic = cpu_to_le32(lsmp->mea_magic);
2478 meap->mea_count = cpu_to_le32(lsmp->mea_count);
2479 meap->mea_master = cpu_to_le32(lsmp->mea_master);
2481 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2482 meap->mea_ids[i] = meap->mea_ids[i];
2483 fid_cpu_to_le(&meap->mea_ids[i], &meap->mea_ids[i]);
2489 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2490 struct lov_mds_md *lmm, int lmm_size)
2492 struct obd_device *obd = class_exp2obd(exp);
2493 struct lmv_stripe_md **tmea = (struct lmv_stripe_md **)lsmp;
2494 struct lmv_stripe_md *mea = (struct lmv_stripe_md *)lmm;
2495 struct lmv_obd *lmv = &obd->u.lmv;
2500 mea_size = lmv_get_easize(lmv);
2504 if (*lsmp != NULL && lmm == NULL) {
2505 OBD_FREE(*tmea, mea_size);
2510 LASSERT(mea_size == lmm_size);
2512 OBD_ALLOC(*tmea, mea_size);
2519 if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
2520 mea->mea_magic == MEA_MAGIC_ALL_CHARS ||
2521 mea->mea_magic == MEA_MAGIC_HASH_SEGMENT)
2523 magic = le32_to_cpu(mea->mea_magic);
2525 /* old mea is not handled here */
2529 (*tmea)->mea_magic = magic;
2530 (*tmea)->mea_count = le32_to_cpu(mea->mea_count);
2531 (*tmea)->mea_master = le32_to_cpu(mea->mea_master);
2533 for (i = 0; i < (*tmea)->mea_count; i++) {
2534 (*tmea)->mea_ids[i] = mea->mea_ids[i];
2535 fid_le_to_cpu(&(*tmea)->mea_ids[i], &(*tmea)->mea_ids[i]);
2540 static int lmv_cancel_unused(struct obd_export *exp,
2541 const struct lu_fid *fid,
2542 int flags, void *opaque)
2544 struct obd_device *obd = exp->exp_obd;
2545 struct lmv_obd *lmv = &obd->u.lmv;
2549 LASSERT(fid != NULL);
2551 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2552 if (!lmv->tgts[i].ltd_exp || !lmv->tgts[i].ltd_active)
2555 err = md_cancel_unused(lmv->tgts[i].ltd_exp,
2556 fid, flags, opaque);
2563 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data)
2565 struct obd_device *obd = exp->exp_obd;
2566 struct lmv_obd *lmv = &obd->u.lmv;
2569 RETURN(md_set_lock_data(lmv->tgts[0].ltd_exp, lockh, data));
2572 int lmv_lock_match(struct obd_export *exp, int flags,
2573 const struct lu_fid *fid, ldlm_type_t type,
2574 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2575 struct lustre_handle *lockh)
2577 struct obd_device *obd = exp->exp_obd;
2578 struct lmv_obd *lmv = &obd->u.lmv;
2582 CDEBUG(D_OTHER, "lock match for "DFID"\n", PFID(fid));
2584 /* with CMD every object can have two locks in different namespaces:
2585 * lookup lock in space of mds storing direntry and update/open lock in
2586 * space of mds storing inode. Thus we check all targets, not only that
2587 * one fid was created in. */
2588 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2589 rc = md_lock_match(lmv->tgts[i].ltd_exp, flags, fid,
2590 type, policy, mode, lockh);
2598 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2599 int offset, struct obd_export *dt_exp,
2600 struct obd_export *md_exp, struct lustre_md *md)
2602 struct obd_device *obd = exp->exp_obd;
2603 struct lmv_obd *lmv = &obd->u.lmv;
2607 rc = md_get_lustre_md(lmv->tgts[0].ltd_exp, req, offset, dt_exp, md_exp,
2612 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2614 struct obd_device *obd = exp->exp_obd;
2615 struct lmv_obd *lmv = &obd->u.lmv;
2619 obd_free_memmd(exp, (struct lov_stripe_md**)&md->mea);
2620 RETURN(md_free_lustre_md(lmv->tgts[0].ltd_exp, md));
2623 int lmv_set_open_replay_data(struct obd_export *exp,
2624 struct obd_client_handle *och,
2625 struct ptlrpc_request *open_req)
2627 struct obd_device *obd = exp->exp_obd;
2628 struct lmv_obd *lmv = &obd->u.lmv;
2629 struct obd_export *tgt_exp;
2633 tgt_exp = lmv_find_export(lmv, &och->och_fid);
2634 if (IS_ERR(tgt_exp))
2635 RETURN(PTR_ERR(tgt_exp));
2637 RETURN(md_set_open_replay_data(tgt_exp, och, open_req));
2640 int lmv_clear_open_replay_data(struct obd_export *exp,
2641 struct obd_client_handle *och)
2643 struct obd_device *obd = exp->exp_obd;
2644 struct lmv_obd *lmv = &obd->u.lmv;
2645 struct obd_export *tgt_exp;
2648 tgt_exp = lmv_find_export(lmv, &och->och_fid);
2649 if (IS_ERR(tgt_exp))
2650 RETURN(PTR_ERR(tgt_exp));
2652 RETURN(md_clear_open_replay_data(tgt_exp, och));
2655 static int lmv_get_remote_perm(struct obd_export *exp,
2656 const struct lu_fid *fid,
2657 struct obd_capa *oc,
2658 struct ptlrpc_request **request)
2660 struct obd_device *obd = exp->exp_obd;
2661 struct lmv_obd *lmv = &obd->u.lmv;
2662 struct obd_export *tgt_exp;
2667 rc = lmv_check_connect(obd);
2671 tgt_exp = lmv_find_export(lmv, fid);
2672 if (IS_ERR(tgt_exp))
2673 RETURN(PTR_ERR(tgt_exp));
2675 rc = md_get_remote_perm(tgt_exp, fid, oc, request);
2680 static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
2683 struct obd_device *obd = exp->exp_obd;
2684 struct lmv_obd *lmv = &obd->u.lmv;
2685 struct obd_export *tgt_exp;
2689 rc = lmv_check_connect(obd);
2693 tgt_exp = lmv_find_export(lmv, &oc->c_capa.lc_fid);
2694 if (IS_ERR(tgt_exp))
2695 RETURN(PTR_ERR(tgt_exp));
2697 rc = md_renew_capa(tgt_exp, oc, cb);
2701 struct obd_ops lmv_obd_ops = {
2702 .o_owner = THIS_MODULE,
2703 .o_setup = lmv_setup,
2704 .o_cleanup = lmv_cleanup,
2705 .o_precleanup = lmv_precleanup,
2706 .o_process_config = lmv_process_config,
2707 .o_connect = lmv_connect,
2708 .o_disconnect = lmv_disconnect,
2709 .o_statfs = lmv_statfs,
2710 .o_llog_init = lmv_llog_init,
2711 .o_llog_finish = lmv_llog_finish,
2712 .o_get_info = lmv_get_info,
2713 .o_set_info_async = lmv_set_info_async,
2714 .o_packmd = lmv_packmd,
2715 .o_unpackmd = lmv_unpackmd,
2716 .o_notify = lmv_notify,
2717 .o_iocontrol = lmv_iocontrol,
2718 .o_fid_delete = lmv_fid_delete
2721 struct md_ops lmv_md_ops = {
2722 .m_getstatus = lmv_getstatus,
2723 .m_change_cbdata = lmv_change_cbdata,
2724 .m_close = lmv_close,
2725 .m_create = lmv_create,
2726 .m_done_writing = lmv_done_writing,
2727 .m_enqueue = lmv_enqueue,
2728 .m_getattr = lmv_getattr,
2729 .m_getxattr = lmv_getxattr,
2730 .m_getattr_name = lmv_getattr_name,
2731 .m_intent_lock = lmv_intent_lock,
2733 .m_rename = lmv_rename,
2734 .m_setattr = lmv_setattr,
2735 .m_setxattr = lmv_setxattr,
2737 .m_readpage = lmv_readpage,
2738 .m_unlink = lmv_unlink,
2739 .m_init_ea_size = lmv_init_ea_size,
2740 .m_cancel_unused = lmv_cancel_unused,
2741 .m_set_lock_data = lmv_set_lock_data,
2742 .m_lock_match = lmv_lock_match,
2743 .m_get_lustre_md = lmv_get_lustre_md,
2744 .m_free_lustre_md = lmv_free_lustre_md,
2745 .m_set_open_replay_data = lmv_set_open_replay_data,
2746 .m_clear_open_replay_data = lmv_clear_open_replay_data,
2747 .m_get_remote_perm = lmv_get_remote_perm,
2748 .m_renew_capa = lmv_renew_capa
2751 int __init lmv_init(void)
2753 struct lprocfs_static_vars lvars;
2756 obj_cache = cfs_mem_cache_create("lmv_objects",
2757 sizeof(struct lmv_obj),
2760 CERROR("error allocating lmv objects cache\n");
2764 lprocfs_init_vars(lmv, &lvars);
2765 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
2766 lvars.module_vars, LUSTRE_LMV_NAME, NULL);
2768 cfs_mem_cache_destroy(obj_cache);
2774 static void lmv_exit(void)
2778 class_unregister_type(LUSTRE_LMV_NAME);
2780 rc = cfs_mem_cache_destroy(obj_cache);
2782 "can't free lmv objects cache, %d object(s)"
2783 "still in use\n", atomic_read(&obj_cache_count));
2786 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2787 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
2788 MODULE_LICENSE("GPL");
2790 module_init(lmv_init);
2791 module_exit(lmv_exit);