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>
32 #include <asm/div64.h>
33 #include <linux/seq_file.h>
34 #include <linux/namei.h>
36 #include <liblustre.h>
38 #include <linux/ext2_fs.h>
40 #include <lustre/lustre_idl.h>
41 #include <lustre_log.h>
42 #include <obd_support.h>
43 #include <lustre_lib.h>
44 #include <lustre_net.h>
45 #include <obd_class.h>
46 #include <lprocfs_status.h>
47 #include <lustre_lite.h>
48 #include "lmv_internal.h"
50 /* not defined for liblustre building */
51 #if !defined(ATOMIC_INIT)
52 #define ATOMIC_INIT(val) { (val) }
56 kmem_cache_t *obj_cache;
57 atomic_t obj_cache_count = ATOMIC_INIT(0);
59 static void lmv_activate_target(struct lmv_obd *lmv,
60 struct lmv_tgt_desc *tgt,
63 if (tgt->active == activate)
66 tgt->active = activate;
67 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
72 * -EINVAL : UUID can't be found in the LMV's target list
73 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
74 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
76 static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid,
79 struct lmv_tgt_desc *tgt;
80 struct obd_device *obd;
84 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
85 lmv, uuid->uuid, activate);
87 spin_lock(&lmv->lmv_lock);
88 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
89 if (tgt->ltd_exp == NULL)
92 CDEBUG(D_INFO, "lmv idx %d is %s conn "LPX64"\n",
93 i, tgt->uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
95 if (obd_uuid_equals(uuid, &tgt->uuid))
99 if (i == lmv->desc.ld_tgt_count)
100 GOTO(out_lmv_lock, rc = -EINVAL);
102 obd = class_exp2obd(tgt->ltd_exp);
104 GOTO(out_lmv_lock, rc = -ENOTCONN);
106 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
107 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
108 obd->obd_type->typ_name, i);
109 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
111 if (tgt->active == activate) {
112 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
113 activate ? "" : "in");
114 GOTO(out_lmv_lock, rc);
117 CDEBUG(D_INFO, "Marking OBD %p %sactive\n",
118 obd, activate ? "" : "in");
120 lmv_activate_target(lmv, tgt, activate);
125 spin_unlock(&lmv->lmv_lock);
129 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
130 enum obd_notify_event ev, void *data)
132 struct obd_uuid *uuid;
136 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
137 CERROR("unexpected notification of %s %s!\n",
138 watched->obd_type->typ_name,
142 uuid = &watched->u.cli.cl_target_uuid;
144 /* Set MDC as active before notifying the observer, so the observer can
145 * use the MDC normally. */
146 rc = lmv_set_mdc_active(&obd->u.lmv, uuid,
147 ev == OBD_NOTIFY_ACTIVE);
149 CERROR("%sactivation of %s failed: %d\n",
150 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
155 if (obd->obd_observer)
156 /* pass the notification up the chain. */
157 rc = obd_notify(obd->obd_observer, watched, ev, data);
162 /* this is fake connect function. Its purpose is to initialize lmv and say
163 * caller that everything is okay. Real connection will be performed later. */
164 static int lmv_connect(const struct lu_context *ctx,
165 struct lustre_handle *conn, struct obd_device *obd,
166 struct obd_uuid *cluuid, struct obd_connect_data *data)
169 struct proc_dir_entry *lmv_proc_dir;
171 struct lmv_obd *lmv = &obd->u.lmv;
172 struct obd_export *exp;
176 rc = class_connect(conn, obd, cluuid);
178 CERROR("class_connection() returned %d\n", rc);
182 exp = class_conn2export(conn);
184 /* we don't want to actually do the underlying connections more than
185 * once, so keep track. */
187 if (lmv->refcount > 1) {
188 class_export_put(exp);
194 lmv->cluuid = *cluuid;
197 lmv->conn_data = *data;
200 lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
202 if (IS_ERR(lmv_proc_dir)) {
203 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
204 obd->obd_type->typ_name, obd->obd_name);
209 /* all real clients should perform actual connection right away, because
210 * it is possible, that LMV will not have opportunity to connect targets
211 * and MDC stuff will be called directly, for instance while reading
212 * ../mdc/../kbytesfree procfs file, etc. */
213 if (data->ocd_connect_flags & OBD_CONNECT_REAL)
214 rc = lmv_check_connect(obd);
219 lprocfs_remove(lmv_proc_dir);
226 static void lmv_set_timeouts(struct obd_device *obd)
228 struct lmv_tgt_desc *tgts;
233 if (lmv->server_timeout == 0)
236 if (lmv->connected == 0)
239 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) {
240 if (tgts->ltd_exp == NULL)
243 obd_set_info_async(tgts->ltd_exp, strlen("inter_mds"),
244 "inter_mds", 0, NULL, NULL);
248 static int lmv_init_ea_size(struct obd_export *exp, int easize,
249 int def_easize, int cookiesize)
251 struct obd_device *obd = exp->exp_obd;
252 struct lmv_obd *lmv = &obd->u.lmv;
253 int i, rc = 0, change = 0;
256 if (lmv->max_easize < easize) {
257 lmv->max_easize = easize;
260 if (lmv->max_def_easize < def_easize) {
261 lmv->max_def_easize = def_easize;
264 if (lmv->max_cookiesize < cookiesize) {
265 lmv->max_cookiesize = cookiesize;
271 if (lmv->connected == 0)
274 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
275 if (lmv->tgts[i].ltd_exp == NULL) {
276 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
280 rc = md_init_ea_size(lmv->tgts[i].ltd_exp, easize, def_easize,
283 CERROR("obd_init_ea_size() failed on MDT target %d, "
284 "error %d.\n", i, rc);
291 #define MAX_STRING_SIZE 128
293 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
295 struct lmv_obd *lmv = &obd->u.lmv;
296 struct obd_uuid *cluuid = &lmv->cluuid;
297 struct obd_connect_data *mdc_data = NULL;
298 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
299 struct lustre_handle conn = {0, };
300 struct obd_device *mdc_obd;
301 struct obd_export *mdc_exp;
304 struct proc_dir_entry *lmv_proc_dir;
308 /* for MDS: don't connect to yourself */
309 if (obd_uuid_equals(&tgt->uuid, cluuid)) {
310 CDEBUG(D_CONFIG, "don't connect back to %s\n", cluuid->uuid);
311 /* XXX - the old code didn't increment active tgt count.
316 mdc_obd = class_find_client_obd(&tgt->uuid, LUSTRE_MDC_NAME,
319 CERROR("target %s not attached\n", tgt->uuid.uuid);
323 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
324 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
325 tgt->uuid.uuid, obd->obd_uuid.uuid,
328 if (!mdc_obd->obd_set_up) {
329 CERROR("target %s not set up\n", tgt->uuid.uuid);
333 rc = obd_connect(NULL, &conn, mdc_obd, &lmv_mdc_uuid, &lmv->conn_data);
335 CERROR("target %s connect error %d\n", tgt->uuid.uuid, rc);
339 mdc_exp = class_conn2export(&conn);
340 fld_client_add_target(&lmv->lmv_fld, mdc_exp);
342 mdc_data = &class_exp2cliimp(mdc_exp)->imp_connect_data;
344 rc = obd_register_observer(mdc_obd, obd);
346 obd_disconnect(mdc_exp);
347 CERROR("target %s register_observer error %d\n",
352 if (obd->obd_observer) {
353 /* tell the mds_lmv about the new target */
354 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
355 OBD_NOTIFY_ACTIVE, (void *)(tgt - lmv->tgts));
357 obd_disconnect(mdc_exp);
363 tgt->ltd_exp = mdc_exp;
364 lmv->desc.ld_active_tgt_count++;
366 /* copy connect data, it may be used later */
367 lmv->datas[tgt->idx] = *mdc_data;
369 md_init_ea_size(tgt->ltd_exp, lmv->max_easize,
370 lmv->max_def_easize, lmv->max_cookiesize);
372 CDEBUG(D_CONFIG, "connected to %s(%s) successfully (%d)\n",
373 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
374 atomic_read(&obd->obd_refcount));
377 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
379 struct proc_dir_entry *mdc_symlink;
380 char name[MAX_STRING_SIZE + 1];
382 LASSERT(mdc_obd->obd_type != NULL);
383 LASSERT(mdc_obd->obd_type->typ_name != NULL);
384 name[MAX_STRING_SIZE] = '\0';
385 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
386 mdc_obd->obd_type->typ_name,
388 mdc_symlink = proc_symlink(mdc_obd->obd_name,
390 if (mdc_symlink == NULL) {
391 CERROR("could not register LMV target "
392 "/proc/fs/lustre/%s/%s/target_obds/%s.",
393 obd->obd_type->typ_name, obd->obd_name,
395 lprocfs_remove(lmv_proc_dir);
403 int lmv_add_target(struct obd_device *obd, struct obd_uuid *tgt_uuid)
405 struct lmv_obd *lmv = &obd->u.lmv;
406 struct lmv_tgt_desc *tgt;
410 CDEBUG(D_CONFIG, "tgt_uuid: %s.\n", tgt_uuid->uuid);
414 if (lmv->desc.ld_active_tgt_count >= LMV_MAX_TGT_COUNT) {
415 lmv_init_unlock(lmv);
416 CERROR("can't add %s, LMV module compiled for %d MDCs. "
417 "That many MDCs already configured.\n",
418 tgt_uuid->uuid, LMV_MAX_TGT_COUNT);
421 if (lmv->desc.ld_tgt_count == 0) {
422 struct obd_device *mdc_obd;
424 mdc_obd = class_find_client_obd(tgt_uuid, LUSTRE_MDC_NAME,
427 lmv_init_unlock(lmv);
428 CERROR("Target %s not attached\n", tgt_uuid->uuid);
432 rc = obd_llog_init(obd, mdc_obd, 0, NULL);
434 lmv_init_unlock(lmv);
435 CERROR("lmv failed to setup llogging subsystems\n");
438 spin_lock(&lmv->lmv_lock);
439 tgt = lmv->tgts + lmv->desc.ld_tgt_count++;
440 tgt->uuid = *tgt_uuid;
441 spin_unlock(&lmv->lmv_lock);
443 if (lmv->connected) {
444 rc = lmv_connect_mdc(obd, tgt);
446 spin_lock(&lmv->lmv_lock);
447 lmv->desc.ld_tgt_count--;
448 memset(tgt, 0, sizeof(*tgt));
449 spin_unlock(&lmv->lmv_lock);
451 int easize = sizeof(struct lmv_stripe_md) +
452 lmv->desc.ld_tgt_count *
453 sizeof(struct lu_fid);
454 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
458 lmv_init_unlock(lmv);
462 /* performs a check if passed obd is connected. If no - connect it. */
463 int lmv_check_connect(struct obd_device *obd)
465 struct lmv_obd *lmv = &obd->u.lmv;
466 struct lmv_tgt_desc *tgt;
474 if (lmv->connected) {
475 lmv_init_unlock(lmv);
479 if (lmv->desc.ld_tgt_count == 0) {
480 CERROR("%s: no targets configured.\n", obd->obd_name);
484 CDEBUG(D_CONFIG, "time to connect %s to %s\n",
485 lmv->cluuid.uuid, obd->obd_name);
487 LASSERT(lmv->tgts != NULL);
489 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
490 rc = lmv_connect_mdc(obd, tgt);
495 lmv_set_timeouts(obd);
496 class_export_put(lmv->exp);
498 easize = lmv_get_easize(lmv);
499 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
500 lmv_init_unlock(lmv);
509 --lmv->desc.ld_active_tgt_count;
510 rc2 = obd_disconnect(tgt->ltd_exp);
512 CERROR("error: LMV target %s disconnect on "
513 "MDC idx %d: error %d\n",
514 tgt->uuid.uuid, i, rc2);
518 class_disconnect(lmv->exp);
519 lmv_init_unlock(lmv);
523 static int lmv_disconnect(struct obd_export *exp)
525 struct obd_device *obd = class_exp2obd(exp);
526 struct lmv_obd *lmv = &obd->u.lmv;
529 struct proc_dir_entry *lmv_proc_dir;
537 /* Only disconnect the underlying layers on the final disconnect. */
539 if (lmv->refcount != 0)
543 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
546 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
547 struct obd_device *mdc_obd;
549 if (lmv->tgts[i].ltd_exp == NULL)
552 mdc_obd = class_exp2obd(lmv->tgts[i].ltd_exp);
555 mdc_obd->obd_no_recov = obd->obd_no_recov;
559 struct proc_dir_entry *mdc_symlink;
561 mdc_symlink = lprocfs_srch(lmv_proc_dir, mdc_obd->obd_name);
563 lprocfs_remove(mdc_symlink);
565 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing\n",
566 obd->obd_type->typ_name, obd->obd_name,
571 CDEBUG(D_OTHER, "disconnected from %s(%s) successfully\n",
572 lmv->tgts[i].ltd_exp->exp_obd->obd_name,
573 lmv->tgts[i].ltd_exp->exp_obd->obd_uuid.uuid);
575 obd_register_observer(lmv->tgts[i].ltd_exp->exp_obd, NULL);
576 rc = obd_disconnect(lmv->tgts[i].ltd_exp);
578 if (lmv->tgts[i].active) {
579 CERROR("Target %s disconnect error %d\n",
580 lmv->tgts[i].uuid.uuid, rc);
585 lmv_activate_target(lmv, &lmv->tgts[i], 0);
586 lmv->tgts[i].ltd_exp = NULL;
591 lprocfs_remove(lmv_proc_dir);
593 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
594 obd->obd_type->typ_name, obd->obd_name);
599 /* this is the case when no real connection is established by
600 * lmv_check_connect(). */
602 class_export_put(exp);
603 rc = class_disconnect(exp);
604 if (lmv->refcount == 0)
609 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
610 int len, void *karg, void *uarg)
612 struct obd_device *obddev = class_exp2obd(exp);
613 struct lmv_obd *lmv = &obddev->u.lmv;
614 int i, rc = 0, set = 0;
617 if (lmv->desc.ld_tgt_count == 0)
620 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
623 if (lmv->tgts[i].ltd_exp == NULL)
626 err = obd_iocontrol(cmd, lmv->tgts[i].ltd_exp, len, karg, uarg);
628 if (lmv->tgts[i].active) {
629 CERROR("error: iocontrol MDC %s on MDT"
630 "idx %d: err = %d\n",
631 lmv->tgts[i].uuid.uuid, i, err);
644 /* assume all is balanced for now */
645 static int lmv_fids_balanced(struct obd_device *obd)
651 static int lmv_all_chars_policy(int count, struct qstr *name)
654 unsigned int len = name->len;
657 c += name->name[-- len];
662 static int lmv_placement_policy(struct obd_device *obd,
663 struct lu_placement_hint *hint,
666 struct lmv_obd *lmv = &obd->u.lmv;
670 LASSERT(mds != NULL);
672 /* here are some policies to allocate new fid */
673 if (lmv_fids_balanced(obd)) {
674 /* allocate new fid basing on its name in the case fids are
675 * balanced, that is all sequences have more or less equal
676 * number of objects created. */
677 if (hint->ph_cname && (hint->ph_opc == LUSTRE_OPC_MKDIR)) {
678 *mds = lmv_all_chars_policy(lmv->desc.ld_tgt_count,
682 /* default policy is to use parent MDS */
683 LASSERT(fid_is_sane(hint->ph_pfid));
684 rc = lmv_fld_lookup(lmv, hint->ph_pfid, mds);
687 /* sequences among all tgts are not well balanced, allocate new
688 * fid taking this into account to balance them. Not implemented
695 CERROR("cannot choose MDS, err = %d\n", rc);
697 LASSERT(*mds < lmv->desc.ld_tgt_count);
703 static int lmv_fid_init(struct obd_export *exp)
705 struct obd_device *obd = class_exp2obd(exp);
706 struct lmv_obd *lmv = &obd->u.lmv;
710 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
711 if (lmv->tgts[i].ltd_exp == NULL)
714 rc = obd_fid_init(lmv->tgts[i].ltd_exp);
721 static int lmv_fid_fini(struct obd_export *exp)
723 struct obd_device *obd = class_exp2obd(exp);
724 struct lmv_obd *lmv = &obd->u.lmv;
728 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
729 if (lmv->tgts[i].ltd_exp == NULL)
732 rc = obd_fid_fini(lmv->tgts[i].ltd_exp);
739 static int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
740 struct lu_placement_hint *hint)
742 struct obd_device *obd = class_exp2obd(exp);
743 struct lmv_obd *lmv = &obd->u.lmv;
748 LASSERT(fid != NULL);
749 LASSERT(hint != NULL);
751 rc = lmv_placement_policy(obd, hint, &mds);
753 CERROR("can't get target for allocating fid, "
758 /* asking underlaying tgt layer to allocate new fid */
759 rc = obd_fid_alloc(lmv->tgts[mds].ltd_exp, fid, hint);
761 /* client switches to new sequence, setup fld */
763 LASSERT(fid_is_sane(fid));
765 rc = fld_client_create(&lmv->lmv_fld, fid_seq(fid),
768 CERROR("can't create fld entry, rc %d\n", rc);
776 static int lmv_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
781 if (lmv_obj_delete(exp, fid)) {
782 CDEBUG(D_OTHER, "lmv object "DFID" is destroyed.\n",
788 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
790 struct lmv_obd *lmv = &obd->u.lmv;
791 struct lprocfs_static_vars lvars;
792 struct lmv_desc *desc;
796 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
797 CERROR("LMV setup requires a descriptor\n");
801 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
802 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
803 CERROR("descriptor size wrong: %d > %d\n",
804 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
808 lmv->tgts_size = LMV_MAX_TGT_COUNT * sizeof(struct lmv_tgt_desc);
810 OBD_ALLOC(lmv->tgts, lmv->tgts_size);
811 if (lmv->tgts == NULL)
814 for (i = 0; i < LMV_MAX_TGT_COUNT; i++)
815 lmv->tgts[i].idx = i;
817 lmv->datas_size = LMV_MAX_TGT_COUNT * sizeof(struct obd_connect_data);
819 OBD_ALLOC(lmv->datas, lmv->datas_size);
820 if (lmv->datas == NULL)
821 GOTO(out_free_tgts, rc = -ENOMEM);
823 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
824 lmv->desc.ld_tgt_count = 0;
825 lmv->desc.ld_active_tgt_count = 0;
826 lmv->max_cookiesize = 0;
827 lmv->max_def_easize = 0;
830 spin_lock_init(&lmv->lmv_lock);
831 sema_init(&lmv->init_sem, 1);
833 rc = lmv_mgr_setup(obd);
835 CERROR("Can't setup LMV object manager, "
837 GOTO(out_free_datas, rc);
840 lprocfs_init_vars(lmv, &lvars);
841 lprocfs_obd_setup(obd, lvars.obd_vars);
844 struct proc_dir_entry *entry;
846 entry = create_proc_entry("target_obd_status", 0444,
847 obd->obd_proc_entry);
849 entry->proc_fops = &lmv_proc_target_fops;
854 rc = fld_client_init(&lmv->lmv_fld,
855 "LMV_UUID", LUSTRE_CLI_FLD_HASH_RRB);
857 CERROR("can't init FLD, err %d\n",
859 GOTO(out_free_datas, rc);
865 OBD_FREE(lmv->datas, lmv->datas_size);
868 OBD_FREE(lmv->tgts, lmv->tgts_size);
873 static int lmv_cleanup(struct obd_device *obd)
875 struct lmv_obd *lmv = &obd->u.lmv;
878 fld_client_fini(&lmv->lmv_fld);
879 lprocfs_obd_cleanup(obd);
880 lmv_mgr_cleanup(obd);
881 OBD_FREE(lmv->datas, lmv->datas_size);
882 OBD_FREE(lmv->tgts, lmv->tgts_size);
887 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
889 struct lustre_cfg *lcfg = buf;
890 struct obd_uuid tgt_uuid;
894 switch(lcfg->lcfg_command) {
896 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(tgt_uuid.uuid))
897 GOTO(out, rc = -EINVAL);
899 obd_str2uuid(&tgt_uuid, lustre_cfg_string(lcfg, 1));
900 rc = lmv_add_target(obd, &tgt_uuid);
903 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
904 GOTO(out, rc = -EINVAL);
911 static int lmv_statfs(struct obd_device *obd, struct obd_statfs *osfs,
914 struct lmv_obd *lmv = &obd->u.lmv;
915 struct obd_statfs *temp;
919 rc = lmv_check_connect(obd);
923 OBD_ALLOC(temp, sizeof(*temp));
927 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
928 if (lmv->tgts[i].ltd_exp == NULL)
931 rc = obd_statfs(lmv->tgts[i].ltd_exp->exp_obd, temp, max_age);
933 CERROR("can't stat MDS #%d (%s), error %d\n", i,
934 lmv->tgts[i].ltd_exp->exp_obd->obd_name,
936 GOTO(out_free_temp, rc);
941 osfs->os_bavail += temp->os_bavail;
942 osfs->os_blocks += temp->os_blocks;
943 osfs->os_ffree += temp->os_ffree;
944 osfs->os_files += temp->os_files;
950 OBD_FREE(temp, sizeof(*temp));
954 static int lmv_getstatus(struct obd_export *exp,
957 struct obd_device *obd = exp->exp_obd;
958 struct lmv_obd *lmv = &obd->u.lmv;
962 rc = lmv_check_connect(obd);
966 rc = md_getstatus(lmv->tgts[0].ltd_exp, fid);
971 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
972 obd_valid valid, const char *name, const char *input,
973 int input_size, int output_size, int flags,
974 struct ptlrpc_request **request)
976 struct obd_device *obd = exp->exp_obd;
977 struct lmv_obd *lmv = &obd->u.lmv;
978 struct obd_export *tgt_exp;
982 rc = lmv_check_connect(obd);
986 tgt_exp = lmv_get_export(lmv, fid);
988 RETURN(PTR_ERR(tgt_exp));
990 rc = md_getxattr(tgt_exp, fid, valid, name, input, input_size,
991 output_size, flags, request);
996 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
997 obd_valid valid, const char *name, const char *input,
998 int input_size, int output_size, int flags,
999 struct ptlrpc_request **request)
1001 struct obd_device *obd = exp->exp_obd;
1002 struct lmv_obd *lmv = &obd->u.lmv;
1003 struct obd_export *tgt_exp;
1007 rc = lmv_check_connect(obd);
1011 tgt_exp = lmv_get_export(lmv, fid);
1012 if (IS_ERR(tgt_exp))
1013 RETURN(PTR_ERR(tgt_exp));
1015 rc = md_setxattr(tgt_exp, fid, valid, name,
1016 input, input_size, output_size, flags, request);
1021 static int lmv_getattr(struct obd_export *exp, const struct lu_fid *fid,
1022 obd_valid valid, int ea_size,
1023 struct ptlrpc_request **request)
1025 struct obd_device *obd = exp->exp_obd;
1026 struct lmv_obd *lmv = &obd->u.lmv;
1027 struct obd_export *tgt_exp;
1028 struct lmv_obj *obj;
1032 rc = lmv_check_connect(obd);
1036 tgt_exp = lmv_get_export(lmv, fid);
1037 if (IS_ERR(tgt_exp))
1038 RETURN(PTR_ERR(tgt_exp));
1040 rc = md_getattr(tgt_exp, fid, valid, ea_size, request);
1044 obj = lmv_obj_grab(obd, fid);
1046 CDEBUG(D_OTHER, "GETATTR for "DFID" %s\n",
1047 PFID(fid), obj ? "(split)" : "");
1049 /* if object is split, then we loop over all the slaves and gather size
1050 * attribute. In ideal world we would have to gather also mds field from
1051 * all slaves, as object is spread over the cluster and this is
1052 * definitely interesting information and it is not good to loss it,
1055 struct mdt_body *body;
1057 if (*request == NULL) {
1062 body = lustre_msg_buf((*request)->rq_repmsg, REQ_REC_OFF,
1064 LASSERT(body != NULL);
1068 for (i = 0; i < obj->lo_objcount; i++) {
1069 if (lmv->tgts[i].ltd_exp == NULL) {
1070 CWARN("%s: NULL export for %d\n",
1075 /* skip master obj. */
1076 if (lu_fid_eq(&obj->lo_fid, &obj->lo_inodes[i].li_fid))
1079 body->size += obj->lo_inodes[i].li_size;
1082 lmv_obj_unlock(obj);
1089 static int lmv_change_cbdata(struct obd_export *exp,
1090 const struct lu_fid *fid,
1094 struct obd_device *obd = exp->exp_obd;
1095 struct lmv_obd *lmv = &obd->u.lmv;
1099 rc = lmv_check_connect(obd);
1103 CDEBUG(D_OTHER, "CBDATA for "DFID"\n", PFID(fid));
1105 /* with CMD every object can have two locks in different namespaces:
1106 * lookup lock in space of mds storing direntry and update/open lock in
1107 * space of mds storing inode */
1108 for (i = 0; i < lmv->desc.ld_tgt_count; i++)
1109 md_change_cbdata(lmv->tgts[i].ltd_exp, fid, it, data);
1114 static int lmv_close(struct obd_export *exp,
1115 struct md_op_data *op_data,
1116 struct obd_client_handle *och,
1117 struct ptlrpc_request **request)
1119 struct obd_device *obd = exp->exp_obd;
1120 struct lmv_obd *lmv = &obd->u.lmv;
1121 struct obd_export *tgt_exp;
1125 rc = lmv_check_connect(obd);
1129 tgt_exp = lmv_get_export(lmv, &op_data->fid1);
1130 if (IS_ERR(tgt_exp))
1131 RETURN(PTR_ERR(tgt_exp));
1133 CDEBUG(D_OTHER, "CLOSE "DFID"\n", PFID(&op_data->fid1));
1134 rc = md_close(tgt_exp, op_data, och, request);
1138 /* called in the case MDS returns -ERESTART on create on open, what means that
1139 * directory is split and its LMV presentation object has to be updated. */
1140 int lmv_handle_split(struct obd_export *exp, const struct lu_fid *fid)
1142 struct obd_device *obd = exp->exp_obd;
1143 struct lmv_obd *lmv = &obd->u.lmv;
1144 struct ptlrpc_request *req = NULL;
1145 struct obd_export *tgt_exp;
1146 struct lmv_obj *obj;
1147 struct lustre_md md;
1153 mealen = lmv_get_easize(lmv);
1155 valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA | OBD_MD_MEA;
1157 tgt_exp = lmv_get_export(lmv, fid);
1158 if (IS_ERR(tgt_exp))
1159 RETURN(PTR_ERR(tgt_exp));
1161 /* time to update mea of parent fid */
1162 rc = md_getattr(tgt_exp, fid, valid, mealen, &req);
1164 CERROR("md_getattr() failed, error %d\n", rc);
1168 rc = md_get_lustre_md(tgt_exp, req, 0, NULL, &md);
1170 CERROR("mdc_get_lustre_md() failed, error %d\n", rc);
1175 GOTO(cleanup, rc = -ENODATA);
1177 obj = lmv_obj_create(exp, fid, md.mea);
1183 obd_free_memmd(exp, (struct lov_stripe_md **)&md.mea);
1188 ptlrpc_req_finished(req);
1192 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1193 const void *data, int datalen, int mode, __u32 uid,
1194 __u32 gid, __u32 cap_effective, __u64 rdev,
1195 struct ptlrpc_request **request)
1197 struct obd_device *obd = exp->exp_obd;
1198 struct lmv_obd *lmv = &obd->u.lmv;
1199 struct obd_export *tgt_exp;
1200 struct mdt_body *body;
1201 struct lmv_obj *obj;
1205 rc = lmv_check_connect(obd);
1209 if (!lmv->desc.ld_active_tgt_count)
1212 LASSERT(++loop <= 2);
1213 obj = lmv_obj_grab(obd, &op_data->fid1);
1217 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1218 op_data->name, op_data->namelen);
1219 op_data->fid1 = obj->lo_inodes[mds].li_fid;
1223 CDEBUG(D_OTHER, "CREATE '%*s' on "DFID"\n", op_data->namelen,
1224 op_data->name, PFID(&op_data->fid1));
1226 tgt_exp = lmv_get_export(lmv, &op_data->fid1);
1227 if (IS_ERR(tgt_exp))
1228 RETURN(PTR_ERR(tgt_exp));
1230 rc = md_create(tgt_exp, op_data, data, datalen, mode, uid, gid,
1231 cap_effective, rdev, request);
1233 if (*request == NULL)
1236 body = lustre_msg_buf((*request)->rq_repmsg, REQ_REC_OFF,
1241 CDEBUG(D_OTHER, "created. "DFID"\n", PFID(&op_data->fid1));
1242 } else if (rc == -ERESTART) {
1243 /* directory got split. time to update local object and repeat
1244 * the request with proper MDS. */
1245 rc = lmv_handle_split(exp, &op_data->fid1);
1247 ptlrpc_req_finished(*request);
1254 static int lmv_done_writing(struct obd_export *exp,
1255 struct md_op_data *op_data)
1257 struct obd_device *obd = exp->exp_obd;
1258 struct lmv_obd *lmv = &obd->u.lmv;
1259 struct obd_export *tgt_exp;
1263 rc = lmv_check_connect(obd);
1267 tgt_exp = lmv_get_export(lmv, &op_data->fid1);
1268 if (IS_ERR(tgt_exp))
1269 RETURN(PTR_ERR(tgt_exp));
1271 rc = md_done_writing(tgt_exp, op_data);
1276 lmv_enqueue_slaves(struct obd_export *exp, int locktype,
1277 struct lookup_intent *it, int lockmode,
1278 struct md_op_data *op_data, struct lustre_handle *lockh,
1279 void *lmm, int lmmsize, ldlm_completion_callback cb_compl,
1280 ldlm_blocking_callback cb_blocking, void *cb_data)
1282 struct obd_device *obd = exp->exp_obd;
1283 struct lmv_obd *lmv = &obd->u.lmv;
1284 struct lmv_stripe_md *mea = op_data->mea1;
1285 struct md_op_data *op_data2;
1286 struct obd_export *tgt_exp;
1290 OBD_ALLOC_PTR(op_data2);
1291 if (op_data2 == NULL)
1294 LASSERT(mea != NULL);
1295 for (i = 0; i < mea->mea_count; i++) {
1296 memset(op_data2, 0, sizeof(*op_data2));
1297 op_data2->fid1 = mea->mea_ids[i];
1299 tgt_exp = lmv_get_export(lmv, &op_data2->fid1);
1300 if (IS_ERR(tgt_exp))
1301 GOTO(cleanup, rc = PTR_ERR(tgt_exp));
1303 if (tgt_exp == NULL)
1306 rc = md_enqueue(tgt_exp, locktype, it, lockmode, op_data2,
1307 lockh + i, lmm, lmmsize, cb_compl, cb_blocking,
1310 CDEBUG(D_OTHER, "take lock on slave "DFID" -> %d/%d\n",
1311 PFID(&mea->mea_ids[i]), rc, it->d.lustre.it_status);
1316 if (it->d.lustre.it_data) {
1317 struct ptlrpc_request *req;
1318 req = (struct ptlrpc_request *)it->d.lustre.it_data;
1319 ptlrpc_req_finished(req);
1322 if (it->d.lustre.it_status)
1323 GOTO(cleanup, rc = it->d.lustre.it_status);
1328 OBD_FREE_PTR(op_data2);
1331 /* drop all taken locks */
1333 if (lockh[i].cookie)
1334 ldlm_lock_decref(lockh + i, lockmode);
1335 lockh[i].cookie = 0;
1342 lmv_enqueue_remote(struct obd_export *exp, int lock_type,
1343 struct lookup_intent *it, int lock_mode,
1344 struct md_op_data *op_data, struct lustre_handle *lockh,
1345 void *lmm, int lmmsize, ldlm_completion_callback cb_compl,
1346 ldlm_blocking_callback cb_blocking, void *cb_data,
1347 int extra_lock_flags)
1349 struct ptlrpc_request *req = it->d.lustre.it_data;
1350 struct obd_device *obd = exp->exp_obd;
1351 struct lmv_obd *lmv = &obd->u.lmv;
1352 struct mdt_body *body = NULL;
1353 struct lustre_handle plock;
1354 struct obd_export *tgt_exp;
1355 struct md_op_data *rdata;
1359 body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body));
1360 LASSERT(body != NULL);
1362 if (!(body->valid & OBD_MD_MDS))
1365 CDEBUG(D_OTHER, "ENQUEUE '%s' on "DFID" -> "DFID"\n",
1366 LL_IT2STR(it), PFID(&op_data->fid1), PFID(&body->fid1));
1368 /* we got LOOKUP lock, but we really need attrs */
1369 pmode = it->d.lustre.it_lock_mode;
1370 LASSERT(pmode != 0);
1371 memcpy(&plock, lockh, sizeof(plock));
1372 it->d.lustre.it_lock_mode = 0;
1373 it->d.lustre.it_data = NULL;
1375 OBD_ALLOC_PTR(rdata);
1378 rdata->fid1 = body->fid1;
1382 it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
1383 ptlrpc_req_finished(req);
1385 tgt_exp = lmv_get_export(lmv, &rdata->fid1);
1386 if (IS_ERR(tgt_exp))
1387 GOTO(out_free_rdata, rc = PTR_ERR(tgt_exp));
1389 rc = md_enqueue(tgt_exp, lock_type, it, lock_mode, rdata,
1390 lockh, lmm, lmmsize, cb_compl, cb_blocking,
1391 cb_data, extra_lock_flags);
1392 ldlm_lock_decref(&plock, pmode);
1396 OBD_FREE_PTR(rdata);
1401 lmv_enqueue(struct obd_export *exp, int lock_type,
1402 struct lookup_intent *it, int lock_mode,
1403 struct md_op_data *op_data, struct lustre_handle *lockh,
1404 void *lmm, int lmmsize, ldlm_completion_callback cb_compl,
1405 ldlm_blocking_callback cb_blocking, void *cb_data,
1406 int extra_lock_flags)
1408 struct obd_device *obd = exp->exp_obd;
1409 struct lmv_obd *lmv = &obd->u.lmv;
1410 struct obd_export *tgt_exp;
1411 struct lmv_obj *obj;
1415 rc = lmv_check_connect(obd);
1419 if (op_data->mea1 && it->it_op == IT_UNLINK) {
1420 rc = lmv_enqueue_slaves(exp, lock_type, it, lock_mode,
1421 op_data, lockh, lmm, lmmsize,
1422 cb_compl, cb_blocking, cb_data);
1426 if (op_data->namelen) {
1427 obj = lmv_obj_grab(obd, &op_data->fid1);
1431 /* directory is split. look for right mds for this
1433 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1434 (char *)op_data->name, op_data->namelen);
1435 op_data->fid1 = obj->lo_inodes[mds].li_fid;
1439 CDEBUG(D_OTHER, "ENQUEUE '%s' on "DFID"\n", LL_IT2STR(it),
1440 PFID(&op_data->fid1));
1442 tgt_exp = lmv_get_export(lmv, &op_data->fid1);
1443 if (IS_ERR(tgt_exp))
1444 RETURN(PTR_ERR(tgt_exp));
1446 rc = md_enqueue(tgt_exp, lock_type, it, lock_mode, op_data, lockh,
1447 lmm, lmmsize, cb_compl, cb_blocking, cb_data,
1450 if (rc == 0 && it->it_op == IT_OPEN)
1451 rc = lmv_enqueue_remote(exp, lock_type, it, lock_mode,
1452 op_data, lockh, lmm, lmmsize,
1453 cb_compl, cb_blocking, cb_data,
1459 lmv_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
1460 const char *filename, int namelen, obd_valid valid,
1461 int ea_size, struct ptlrpc_request **request)
1463 struct obd_device *obd = exp->exp_obd;
1464 struct lmv_obd *lmv = &obd->u.lmv;
1465 struct obd_export *tgt_exp;
1466 struct lu_fid rid = *fid;
1467 struct mdt_body *body;
1468 struct lmv_obj *obj;
1473 rc = lmv_check_connect(obd);
1478 LASSERT(++loop <= 2);
1479 obj = lmv_obj_grab(obd, fid);
1481 /* directory is split. look for right mds for this name */
1482 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1483 filename, namelen - 1);
1484 rid = obj->lo_inodes[mds].li_fid;
1488 CDEBUG(D_OTHER, "getattr_name for %*s on "DFID" -> "DFID"\n",
1489 namelen, filename, PFID(fid), PFID(&rid));
1491 tgt_exp = lmv_get_export(lmv, &rid);
1492 if (IS_ERR(tgt_exp))
1493 RETURN(PTR_ERR(tgt_exp));
1495 rc = md_getattr_name(tgt_exp, &rid, filename, namelen, valid,
1498 body = lustre_msg_buf((*request)->rq_repmsg,
1499 REQ_REC_OFF, sizeof(*body));
1500 LASSERT(body != NULL);
1502 if (body->valid & OBD_MD_MDS) {
1503 struct ptlrpc_request *req = NULL;
1506 CDEBUG(D_OTHER, "request attrs for "DFID"\n",
1509 tgt_exp = lmv_get_export(lmv, &rid);
1510 if (IS_ERR(tgt_exp)) {
1511 ptlrpc_req_finished(*request);
1512 RETURN(PTR_ERR(tgt_exp));
1515 rc = md_getattr_name(tgt_exp, &rid, NULL, 1, valid,
1517 ptlrpc_req_finished(*request);
1520 } else if (rc == -ERESTART) {
1521 /* directory got split. time to update local object and repeat
1522 * the request with proper MDS */
1523 rc = lmv_handle_split(exp, &rid);
1525 ptlrpc_req_finished(*request);
1533 * llite passes fid of an target inode in op_data->fid1 and id of directory in
1536 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1537 struct ptlrpc_request **request)
1539 struct obd_device *obd = exp->exp_obd;
1540 struct lmv_obd *lmv = &obd->u.lmv;
1541 struct lmv_obj *obj;
1546 rc = lmv_check_connect(obd);
1550 if (op_data->namelen != 0) {
1551 /* usual link request */
1552 obj = lmv_obj_grab(obd, &op_data->fid2);
1554 rc = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1555 op_data->name, op_data->namelen);
1556 op_data->fid2 = obj->lo_inodes[rc].li_fid;
1560 rc = lmv_fld_lookup(lmv, &op_data->fid2, &mds);
1564 CDEBUG(D_OTHER,"link "DFID":%*s to "DFID"\n",
1565 PFID(&op_data->fid2), op_data->namelen,
1566 op_data->name, PFID(&op_data->fid1));
1568 rc = lmv_fld_lookup(lmv, &op_data->fid1, &mds);
1572 /* request from MDS to acquire i_links for inode by fid1 */
1573 CDEBUG(D_OTHER, "inc i_nlinks for "DFID"\n",
1574 PFID(&op_data->fid1));
1577 CDEBUG(D_OTHER, "forward to MDS #"LPU64" ("DFID")\n",
1578 mds, PFID(&op_data->fid1));
1580 rc = md_link(lmv->tgts[mds].ltd_exp, op_data, request);
1585 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1586 const char *old, int oldlen, const char *new, int newlen,
1587 struct ptlrpc_request **request)
1589 struct obd_device *obd = exp->exp_obd;
1590 struct lmv_obd *lmv = &obd->u.lmv;
1591 struct lmv_obj *obj;
1596 CDEBUG(D_OTHER, "rename %*s in "DFID" to %*s in "DFID"\n",
1597 oldlen, old, PFID(&op_data->fid1), newlen, new,
1598 PFID(&op_data->fid2));
1600 rc = lmv_check_connect(obd);
1606 * MDS with old dir entry is asking another MDS to create name
1610 "create %*s(%d/%d) in "DFID" pointing "
1611 "to "DFID"\n", newlen, new, oldlen, newlen,
1612 PFID(&op_data->fid2), PFID(&op_data->fid1));
1614 rc = lmv_fld_lookup(lmv, &op_data->fid2, &mds);
1619 * target directory can be split, sowe should forward request to
1622 obj = lmv_obj_grab(obd, &op_data->fid2);
1624 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1625 (char *)new, newlen);
1626 op_data->fid2 = obj->lo_inodes[mds].li_fid;
1627 CDEBUG(D_OTHER, "forward to MDS #"LPU64" ("DFID")\n", mds,
1628 PFID(&op_data->fid2));
1634 obj = lmv_obj_grab(obd, &op_data->fid1);
1637 * directory is already split, so we have to forward request to
1640 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1641 (char *)old, oldlen);
1642 op_data->fid1 = obj->lo_inodes[mds].li_fid;
1643 CDEBUG(D_OTHER, "forward to MDS #"LPU64" ("DFID")\n", mds,
1644 PFID(&op_data->fid1));
1648 obj = lmv_obj_grab(obd, &op_data->fid2);
1651 * directory is already split, so we have to forward request to
1654 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1655 (char *)new, newlen);
1657 op_data->fid2 = obj->lo_inodes[mds].li_fid;
1658 CDEBUG(D_OTHER, "forward to MDS #"LPU64" ("DFID")\n", mds,
1659 PFID(&op_data->fid2));
1663 rc = lmv_fld_lookup(lmv, &op_data->fid1, &mds);
1668 rc = lmv_fld_lookup(lmv, &op_data->fid2, &mds2);
1673 CDEBUG(D_OTHER,"cross-node rename "DFID"/%*s to "DFID"/%*s\n",
1674 PFID(&op_data->fid1), oldlen, old, PFID(&op_data->fid2),
1678 rc = md_rename(lmv->tgts[mds].ltd_exp, op_data, old, oldlen,
1679 new, newlen, request);
1683 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
1684 struct iattr *iattr, void *ea, int ealen, void *ea2,
1685 int ea2len, struct ptlrpc_request **request)
1687 struct obd_device *obd = exp->exp_obd;
1688 struct lmv_obd *lmv = &obd->u.lmv;
1689 struct ptlrpc_request *req;
1690 struct obd_export *tgt_exp;
1691 struct mdt_body *body;
1692 struct lmv_obj *obj;
1696 rc = lmv_check_connect(obd);
1700 obj = lmv_obj_grab(obd, &op_data->fid1);
1702 CDEBUG(D_OTHER, "SETATTR for "DFID", valid 0x%x%s\n",
1703 PFID(&op_data->fid1), iattr->ia_valid, obj ? ", split" : "");
1706 for (i = 0; i < obj->lo_objcount; i++) {
1707 op_data->fid1 = obj->lo_inodes[i].li_fid;
1709 tgt_exp = lmv_get_export(lmv, &op_data->fid1);
1710 if (IS_ERR(tgt_exp)) {
1711 rc = PTR_ERR(tgt_exp);
1715 rc = md_setattr(tgt_exp, op_data, iattr, ea, ealen,
1718 if (lu_fid_eq(&obj->lo_fid, &obj->lo_inodes[i].li_fid)) {
1720 * this is master object and this request should
1721 * be returned back to llite.
1725 ptlrpc_req_finished(req);
1733 tgt_exp = lmv_get_export(lmv, &op_data->fid1);
1734 if (IS_ERR(tgt_exp))
1735 RETURN(PTR_ERR(tgt_exp));
1737 rc = md_setattr(tgt_exp, op_data, iattr, ea, ealen, ea2,
1740 body = lustre_msg_buf((*request)->rq_repmsg, REQ_REC_OFF,
1742 LASSERT(body != NULL);
1748 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
1749 struct ptlrpc_request **request)
1751 struct obd_device *obd = exp->exp_obd;
1752 struct lmv_obd *lmv = &obd->u.lmv;
1753 struct obd_export *tgt_exp;
1757 rc = lmv_check_connect(obd);
1761 tgt_exp = lmv_get_export(lmv, fid);
1762 if (IS_ERR(tgt_exp))
1763 RETURN(PTR_ERR(tgt_exp));
1765 rc = md_sync(tgt_exp, fid, request);
1769 /* main purpose of LMV blocking ast is to remove split directory LMV
1770 * presentation object (struct lmv_obj) attached to the lock being revoked. */
1771 int lmv_blocking_ast(struct ldlm_lock *lock,
1772 struct ldlm_lock_desc *desc,
1773 void *data, int flag)
1775 struct lustre_handle lockh;
1776 struct lmv_obj *obj;
1781 case LDLM_CB_BLOCKING:
1782 ldlm_lock2handle(lock, &lockh);
1783 rc = ldlm_cli_cancel(&lockh);
1785 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
1789 case LDLM_CB_CANCELING:
1790 /* time to drop cached attrs for dirobj */
1791 obj = lock->l_ast_data;
1793 CDEBUG(D_OTHER, "cancel %s on "LPU64"/"LPU64
1794 ", master "DFID"\n",
1795 lock->l_resource->lr_name.name[3] == 1 ?
1796 "LOOKUP" : "UPDATE",
1797 lock->l_resource->lr_name.name[0],
1798 lock->l_resource->lr_name.name[1],
1799 PFID(&obj->lo_fid));
1810 /* not needed for CMD3 because only dir on master has "." and ".." */
1811 static void lmv_remove_dots(struct page *page)
1813 unsigned limit = PAGE_CACHE_SIZE;
1814 char *kaddr = cfs_page_address(page);
1815 struct ext2_dir_entry_2 *p;
1816 unsigned offs, rec_len;
1818 for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
1819 p = (struct ext2_dir_entry_2 *)(kaddr + offs);
1820 rec_len = le16_to_cpu(p->rec_len);
1822 if ((p->name_len == 1 && p->name[0] == '.') ||
1823 (p->name_len == 2 && p->name[0] == '.' && p->name[1] == '.'))
1829 static int lmv_readpage(struct obd_export *exp,
1830 const struct lu_fid *fid,
1831 __u64 offset, struct page *page,
1832 struct ptlrpc_request **request)
1834 struct obd_device *obd = exp->exp_obd;
1835 struct lmv_obd *lmv = &obd->u.lmv;
1836 struct obd_export *tgt_exp;
1837 struct lu_fid rid = *fid;
1838 struct lmv_obj *obj;
1842 rc = lmv_check_connect(obd);
1846 CDEBUG(D_OTHER, "READPAGE at %llu from "DFID"\n",
1847 offset, PFID(&rid));
1849 obj = lmv_obj_grab(obd, fid);
1853 /* find dirobj containing page with requested offset. */
1854 for (i = 0; i < obj->lo_objcount; i++) {
1855 if (offset < obj->lo_inodes[i].li_size)
1857 offset -= obj->lo_inodes[i].li_size;
1859 rid = obj->lo_inodes[i].li_fid;
1861 lmv_obj_unlock(obj);
1864 CDEBUG(D_OTHER, "forward to "DFID" with offset %lu\n",
1865 PFID(&rid), (unsigned long)offset);
1868 tgt_exp = lmv_get_export(lmv, &rid);
1869 if (IS_ERR(tgt_exp))
1870 RETURN(PTR_ERR(tgt_exp));
1872 rc = md_readpage(tgt_exp, &rid, offset, page, request);
1875 if (rc == 0 && !lu_fid_eq(&rid, fid))
1877 * This page isn't from master object. To avoid "." and ".."
1878 * duplication in directory, we have to remove them from all
1881 * XXX this is not needed for cmd3 readdir, because only master
1882 * directory has dot and dotdot.
1884 lmv_remove_dots(page);
1890 static int lmv_unlink_slaves(struct obd_export *exp,
1891 struct md_op_data *op_data,
1892 struct ptlrpc_request **req)
1894 struct obd_device *obd = exp->exp_obd;
1895 struct lmv_obd *lmv = &obd->u.lmv;
1896 struct lmv_stripe_md *mea = op_data->mea1;
1897 struct md_op_data *op_data2;
1898 struct obd_export *tgt_exp;
1902 OBD_ALLOC_PTR(op_data2);
1903 if (op_data2 == NULL)
1906 LASSERT(mea != NULL);
1907 for (i = 0; i < mea->mea_count; i++) {
1908 memset(op_data2, 0, sizeof(*op_data2));
1909 op_data2->fid1 = mea->mea_ids[i];
1910 op_data2->create_mode = MDS_MODE_DONT_LOCK | S_IFDIR;
1912 tgt_exp = lmv_get_export(lmv, &op_data2->fid1);
1913 if (IS_ERR(tgt_exp))
1914 GOTO(out_free_op_data2, rc = PTR_ERR(tgt_exp));
1916 if (tgt_exp == NULL)
1919 rc = md_unlink(tgt_exp, op_data2, req);
1921 CDEBUG(D_OTHER, "unlink slave "DFID" -> %d\n",
1922 PFID(&mea->mea_ids[i]), rc);
1925 ptlrpc_req_finished(*req);
1929 GOTO(out_free_op_data2, rc);
1934 OBD_FREE_PTR(op_data2);
1938 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
1939 struct ptlrpc_request **request)
1941 struct obd_device *obd = exp->exp_obd;
1942 struct lmv_obd *lmv = &obd->u.lmv;
1943 struct obd_export *tgt_exp;
1947 rc = lmv_check_connect(obd);
1951 if (op_data->namelen == 0 && op_data->mea1 != NULL) {
1952 /* mds asks to remove slave objects */
1953 rc = lmv_unlink_slaves(exp, op_data, request);
1957 if (op_data->namelen != 0) {
1958 struct lmv_obj *obj;
1960 obj = lmv_obj_grab(obd, &op_data->fid1);
1962 i = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
1963 op_data->name, op_data->namelen);
1964 op_data->fid1 = obj->lo_inodes[i].li_fid;
1967 CDEBUG(D_OTHER, "unlink '%*s' in "DFID" -> %u\n",
1968 op_data->namelen, op_data->name, PFID(&op_data->fid1),
1971 CDEBUG(D_OTHER, "drop i_nlink on "DFID"\n",
1972 PFID(&op_data->fid1));
1974 tgt_exp = lmv_get_export(lmv, &op_data->fid1);
1975 if (IS_ERR(tgt_exp))
1976 RETURN(PTR_ERR(tgt_exp));
1978 rc = md_unlink(tgt_exp, op_data, request);
1982 static int lmv_llog_init(struct obd_device *obd, struct obd_device *tgt,
1983 int count, struct llog_catid *logid)
1985 struct llog_ctxt *ctxt;
1989 rc = llog_setup(obd, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1992 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1993 ctxt->loc_imp = tgt->u.cli.cl_import;
1999 static int lmv_llog_finish(struct obd_device *obd, int count)
2004 rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
2008 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2013 case OBD_CLEANUP_EARLY:
2014 /* XXX: here should be calling obd_precleanup() down to
2017 case OBD_CLEANUP_SELF_EXP:
2018 rc = obd_llog_finish(obd, 0);
2020 CERROR("failed to cleanup llogging subsystems\n");
2028 static int lmv_get_info(struct obd_export *exp, __u32 keylen,
2029 void *key, __u32 *vallen, void *val)
2031 struct obd_device *obd;
2032 struct lmv_obd *lmv;
2036 obd = class_exp2obd(exp);
2038 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
2039 exp->exp_handle.h_cookie);
2044 if (keylen == strlen("mdsize") && !strcmp(key, "mdsize")) {
2045 __u32 *mdsize = val;
2046 *vallen = sizeof(__u32);
2047 *mdsize = lmv_get_easize(lmv);
2049 } else if (keylen == strlen("mdsnum") && !strcmp(key, "mdsnum")) {
2050 struct obd_uuid *cluuid = &lmv->cluuid;
2051 struct lmv_tgt_desc *tgts;
2052 __u32 *mdsnum = val;
2056 for (i = 0; i < lmv->desc.ld_tgt_count; i++, tgts++) {
2057 if (obd_uuid_equals(&tgts->uuid, cluuid)) {
2058 *vallen = sizeof(__u32);
2064 } else if (keylen == strlen("rootid") && !strcmp(key, "rootid")) {
2065 rc = lmv_check_connect(obd);
2069 /* getting rootid from first MDS. */
2070 rc = obd_get_info(lmv->tgts[0].ltd_exp, keylen, key,
2073 } else if (keylen >= strlen("lmvdesc") && !strcmp(key, "lmvdesc")) {
2074 struct lmv_desc *desc_ret = val;
2075 *desc_ret = lmv->desc;
2077 } else if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2078 struct lmv_tgt_desc *tgts;
2081 rc = lmv_check_connect(obd);
2085 LASSERT(*vallen == sizeof(__u32));
2086 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count;
2089 /* all tgts should be connected when this get called. */
2090 if (!tgts || !tgts->ltd_exp) {
2091 CERROR("target not setup?\n");
2095 if (!obd_get_info(tgts->ltd_exp, keylen, key,
2100 } else if ((keylen >= strlen("lovdesc") && !strcmp(key, "lovdesc")) ||
2101 (keylen >= strlen("max_easize") && !strcmp(key, "max_easize"))) {
2103 rc = lmv_check_connect(obd);
2107 /* forwarding this request to first MDS, it should know LOV
2109 rc = obd_get_info(lmv->tgts[0].ltd_exp, keylen, key,
2112 } /* else if (keylen >= strlen("getext") && !strcmp(key, "getext")) {
2113 struct lmv_tgt_desc *tgts;
2116 rc = lmv_check_connect(obd);
2120 LASSERT(*vallen == sizeof(struct fid_extent));
2121 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count;
2124 if (!tgts || !tgts->ltd_exp) {
2125 CERROR("target not setup?\n");
2129 rc = obd_get_info(tgts->ltd_exp, keylen, key,
2137 CDEBUG(D_IOCTL, "invalid key\n");
2141 int lmv_set_info_async(struct obd_export *exp, obd_count keylen,
2142 void *key, obd_count vallen, void *val,
2143 struct ptlrpc_request_set *set)
2145 struct lmv_tgt_desc *tgt;
2146 struct obd_device *obd;
2147 struct lmv_obd *lmv;
2151 obd = class_exp2obd(exp);
2153 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
2154 exp->exp_handle.h_cookie);
2159 if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
2160 lmv->server_timeout = 1;
2161 lmv_set_timeouts(obd);
2165 /* maybe this could be default */
2166 if ((keylen == strlen("sec") && strcmp(key, "sec") == 0) ||
2167 (keylen == strlen("sec_flags") && strcmp(key, "sec_flags") == 0) ||
2168 (keylen == strlen("nllu") && strcmp(key, "nllu") == 0)) {
2169 struct obd_export *exp;
2172 spin_lock(&lmv->lmv_lock);
2173 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count;
2176 /* during setup time the connections to mdc might
2177 * haven't been established.
2180 struct obd_device *tgt_obd;
2182 tgt_obd = class_find_client_obd(&tgt->uuid,
2186 CERROR("can't set info %s, "
2187 "device %s not attached?\n",
2188 (char *) key, tgt->uuid.uuid);
2192 exp = tgt_obd->obd_self_export;
2195 err = obd_set_info_async(exp, keylen, key, vallen, val, set);
2199 spin_unlock(&lmv->lmv_lock);
2203 if (((keylen == strlen("flush_cred") &&
2204 strcmp(key, "flush_cred") == 0)) ||
2205 ((keylen == strlen("crypto_type") &&
2206 strcmp(key, "crypto_type") == 0))) {
2209 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count;
2213 rc = obd_set_info_async(tgt->ltd_exp,
2214 keylen, key, vallen,
2223 if (keylen == strlen("ids") && memcmp(key, "ids", keylen) == 0) {
2224 struct lu_fid *fid = (struct lu_fid *)val;
2225 struct obd_export *tgt_exp;
2227 rc = lmv_check_connect(obd);
2231 tgt_exp = lmv_get_export(lmv, fid);
2232 if (IS_ERR(tgt_exp))
2233 RETURN(PTR_ERR(tgt_exp));
2235 rc = obd_set_info_async(tgt_exp, keylen, key, vallen,
2240 if (keylen == strlen("chkconnect") &&
2241 memcmp(key, "chkconnect", keylen) == 0) {
2242 rc = lmv_check_connect(obd);
2249 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2250 struct lov_stripe_md *lsm)
2252 struct obd_device *obd = class_exp2obd(exp);
2253 struct lmv_obd *lmv = &obd->u.lmv;
2254 struct lmv_stripe_md *meap, *lsmp;
2258 mea_size = lmv_get_easize(lmv);
2262 if (*lmmp && !lsm) {
2263 OBD_FREE(*lmmp, mea_size);
2268 if (*lmmp == NULL) {
2269 OBD_ALLOC(*lmmp, mea_size);
2277 lsmp = (struct lmv_stripe_md *)lsm;
2278 meap = (struct lmv_stripe_md *)*lmmp;
2280 if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR &&
2281 lsmp->mea_magic != MEA_MAGIC_ALL_CHARS)
2284 meap->mea_magic = cpu_to_le32(lsmp->mea_magic);
2285 meap->mea_count = cpu_to_le32(lsmp->mea_count);
2286 meap->mea_master = cpu_to_le32(lsmp->mea_master);
2288 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2289 meap->mea_ids[i] = meap->mea_ids[i];
2290 fid_cpu_to_le(&meap->mea_ids[i]);
2296 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2297 struct lov_mds_md *lmm, int lmm_size)
2299 struct obd_device *obd = class_exp2obd(exp);
2300 struct lmv_stripe_md **tmea = (struct lmv_stripe_md **)lsmp;
2301 struct lmv_stripe_md *mea = (struct lmv_stripe_md *)lmm;
2302 struct lmv_obd *lmv = &obd->u.lmv;
2307 mea_size = lmv_get_easize(lmv);
2311 if (*lsmp != NULL && lmm == NULL) {
2312 OBD_FREE(*tmea, mea_size);
2316 LASSERT(mea_size == lmm_size);
2318 OBD_ALLOC(*tmea, mea_size);
2325 if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
2326 mea->mea_magic == MEA_MAGIC_ALL_CHARS)
2328 magic = le32_to_cpu(mea->mea_magic);
2330 /* old mea isnot handled here */
2334 (*tmea)->mea_magic = magic;
2335 (*tmea)->mea_count = le32_to_cpu(mea->mea_count);
2336 (*tmea)->mea_master = le32_to_cpu(mea->mea_master);
2338 for (i = 0; i < (*tmea)->mea_count; i++) {
2339 (*tmea)->mea_ids[i] = mea->mea_ids[i];
2340 fid_le_to_cpu(&(*tmea)->mea_ids[i]);
2346 /* lmv_create() and lmv_brw() is needed anymore as they purely server stuff and
2347 * lmv is going to use only on client. */
2348 static int lmv_obd_create_single(struct obd_export *exp, struct obdo *oa,
2349 struct lov_stripe_md **ea,
2350 struct obd_trans_info *oti)
2352 struct obd_device *obd = exp->exp_obd;
2353 struct lmv_obd *lmv = &obd->u.lmv;
2354 struct lov_stripe_md obj_md;
2355 struct lov_stripe_md *obj_mdp = &obj_md;
2359 LASSERT(ea == NULL);
2360 LASSERT(oa->o_mds < lmv->desc.ld_tgt_count);
2362 rc = obd_create(lmv->tgts[oa->o_mds].ltd_exp,
2369 * to be called from MDS only. @oa should have correct store cookie and o_fid
2370 * values for "master" object, as it will be used.
2372 int lmv_obd_create(struct obd_export *exp, struct obdo *oa,
2373 struct lov_stripe_md **ea, struct obd_trans_info *oti)
2375 struct obd_device *obd = exp->exp_obd;
2376 struct lmv_obd *lmv = &obd->u.lmv;
2377 struct lmv_stripe_md *mea;
2382 rc = lmv_check_connect(obd);
2386 LASSERT(oa != NULL);
2389 rc = lmv_obd_create_single(exp, oa, NULL, oti);
2391 CERROR("Can't create object, rc = %d\n", rc);
2396 rc = obd_alloc_diskmd(exp, (struct lov_mds_md **)ea);
2398 CERROR("obd_alloc_diskmd() failed, error %d\n",
2408 /* here we should take care about split dir, so store cookie and fid
2409 * for "master" object should already be allocated and passed in @oa. */
2410 LASSERT(oa->o_id != 0);
2411 LASSERT(oa->o_fid != 0);
2413 /* save "master" object fid */
2416 mea = (struct lmv_stripe_md *)*ea;
2417 mea->mea_master = -1;
2418 mea->mea_magic = MEA_MAGIC_ALL_CHARS;
2420 if (!mea->mea_count || mea->mea_count > lmv->desc.ld_tgt_count)
2421 mea->mea_count = lmv->desc.ld_tgt_count;
2423 for (i = 0, c = 0; c < mea->mea_count && i < lmv->desc.ld_tgt_count; i++) {
2424 struct lov_stripe_md obj_md;
2425 struct lov_stripe_md *obj_mdp = &obj_md;
2427 if (lmv->tgts[i].ltd_exp == NULL) {
2428 /* this is "master" MDS */
2429 mea->mea_master = i;
2430 mea->mea_ids[c] = mid;
2436 * "master" MDS should always be part of stripped dir,
2439 if (mea->mea_master == -1 && c == mea->mea_count - 1)
2442 oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLTYPE | OBD_MD_FLMODE |
2443 OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLID;
2445 rc = obd_create(lmv->tgts[c].ltd_exp, oa, &obj_mdp, oti);
2447 CERROR("obd_create() failed on MDT target %d, "
2448 "error %d\n", c, rc);
2452 CDEBUG(D_OTHER, "dirobj at mds %d: "LPU64"/%u\n",
2453 i, oa->o_id, oa->o_generation);
2457 * here, when object is created (or it is master and was passed
2458 * from caller) on desired MDS we save its fid to local mea_ids.
2463 * store cookie should be defined here for both cases (master
2464 * object and not master), because master is already created.
2468 /* fill mea by store cookie and fid */
2469 obdo2fid(oa, &mea->mea_ids[c]);
2472 LASSERT(c == mea->mea_count);
2474 CDEBUG(D_OTHER, "%d dirobjects created\n",
2475 (int)mea->mea_count);
2480 int lmv_brw(int rw, struct obd_export *exp, struct obdo *oa,
2481 struct lov_stripe_md *ea, obd_count oa_bufs,
2482 struct brw_page *pgarr, struct obd_trans_info *oti)
2484 /* splitting is not needed in lmv */
2485 struct obd_device *obd = exp->exp_obd;
2486 struct lmv_obd *lmv = &obd->u.lmv;
2487 struct lmv_stripe_md *mea = (struct lmv_stripe_md *) ea;
2490 LASSERT(oa != NULL);
2491 LASSERT(ea != NULL);
2492 LASSERT(pgarr != NULL);
2493 LASSERT(oa->o_mds < lmv->desc.ld_tgt_count);
2495 oa->o_gr = id_gen(&mea->mea_ids[oa->o_mds]);
2496 oa->o_id = id_ino(&mea->mea_ids[oa->o_mds]);
2497 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
2499 err = obd_brw(rw, lmv->tgts[oa->o_mds].ltd_exp,
2500 oa, NULL, oa_bufs, pgarr, oti);
2505 static int lmv_cancel_unused(struct obd_export *exp,
2506 const struct lu_fid *fid,
2507 int flags, void *opaque)
2509 struct obd_device *obd = exp->exp_obd;
2510 struct lmv_obd *lmv = &obd->u.lmv;
2514 LASSERT(fid != NULL);
2516 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2517 if (!lmv->tgts[i].ltd_exp || !lmv->tgts[i].active)
2520 err = md_cancel_unused(lmv->tgts[i].ltd_exp,
2521 fid, flags, opaque);
2528 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data)
2530 struct obd_device *obd = exp->exp_obd;
2531 struct lmv_obd *lmv = &obd->u.lmv;
2534 RETURN(md_set_lock_data(lmv->tgts[0].ltd_exp, lockh, data));
2537 int lmv_lock_match(struct obd_export *exp, int flags,
2538 const struct lu_fid *fid, ldlm_type_t type,
2539 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2540 struct lustre_handle *lockh)
2542 struct obd_device *obd = exp->exp_obd;
2543 struct lmv_obd *lmv = &obd->u.lmv;
2547 CDEBUG(D_OTHER, "lock match for "DFID"\n", PFID(fid));
2549 /* with CMD every object can have two locks in different namespaces:
2550 * lookup lock in space of mds storing direntry and update/open lock in
2551 * space of mds storing inode. Thus we check all targets, not only that
2552 * one fid was created in. */
2553 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2554 rc = md_lock_match(lmv->tgts[i].ltd_exp, flags, fid,
2555 type, policy, mode, lockh);
2563 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2564 int offset, struct obd_export *dt_exp, struct lustre_md *md)
2566 struct obd_device *obd = exp->exp_obd;
2567 struct lmv_obd *lmv = &obd->u.lmv;
2571 rc = md_get_lustre_md(lmv->tgts[0].ltd_exp, req, offset, dt_exp, md);
2575 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2577 struct obd_device *obd = exp->exp_obd;
2578 struct lmv_obd *lmv = &obd->u.lmv;
2581 RETURN(md_free_lustre_md(lmv->tgts[0].ltd_exp, md));
2584 int lmv_set_open_replay_data(struct obd_export *exp,
2585 struct obd_client_handle *och,
2586 struct ptlrpc_request *open_req)
2588 struct obd_device *obd = exp->exp_obd;
2589 struct lmv_obd *lmv = &obd->u.lmv;
2592 RETURN(md_set_open_replay_data(lmv->tgts[0].ltd_exp,
2596 int lmv_clear_open_replay_data(struct obd_export *exp,
2597 struct obd_client_handle *och)
2599 struct obd_device *obd = exp->exp_obd;
2600 struct lmv_obd *lmv = &obd->u.lmv;
2603 RETURN(md_clear_open_replay_data(lmv->tgts[0].ltd_exp, och));
2606 struct obd_ops lmv_obd_ops = {
2607 .o_owner = THIS_MODULE,
2608 .o_setup = lmv_setup,
2609 .o_cleanup = lmv_cleanup,
2610 .o_precleanup = lmv_precleanup,
2611 .o_process_config = lmv_process_config,
2612 .o_connect = lmv_connect,
2613 .o_disconnect = lmv_disconnect,
2614 .o_statfs = lmv_statfs,
2615 .o_llog_init = lmv_llog_init,
2616 .o_llog_finish = lmv_llog_finish,
2617 .o_get_info = lmv_get_info,
2618 .o_set_info_async = lmv_set_info_async,
2619 .o_packmd = lmv_packmd,
2620 .o_unpackmd = lmv_unpackmd,
2621 .o_notify = lmv_notify,
2622 .o_fid_init = lmv_fid_init,
2623 .o_fid_fini = lmv_fid_fini,
2624 .o_fid_alloc = lmv_fid_alloc,
2625 .o_fid_delete = lmv_fid_delete,
2626 .o_iocontrol = lmv_iocontrol
2629 struct md_ops lmv_md_ops = {
2630 .m_getstatus = lmv_getstatus,
2631 .m_change_cbdata = lmv_change_cbdata,
2632 .m_close = lmv_close,
2633 .m_create = lmv_create,
2634 .m_done_writing = lmv_done_writing,
2635 .m_enqueue = lmv_enqueue,
2636 .m_getattr = lmv_getattr,
2637 .m_getxattr = lmv_getxattr,
2638 .m_getattr_name = lmv_getattr_name,
2639 .m_intent_lock = lmv_intent_lock,
2641 .m_rename = lmv_rename,
2642 .m_setattr = lmv_setattr,
2643 .m_setxattr = lmv_setxattr,
2645 .m_readpage = lmv_readpage,
2646 .m_unlink = lmv_unlink,
2647 .m_init_ea_size = lmv_init_ea_size,
2648 .m_cancel_unused = lmv_cancel_unused,
2649 .m_set_lock_data = lmv_set_lock_data,
2650 .m_lock_match = lmv_lock_match,
2651 .m_get_lustre_md = lmv_get_lustre_md,
2652 .m_free_lustre_md = lmv_free_lustre_md,
2653 .m_set_open_replay_data = lmv_set_open_replay_data,
2654 .m_clear_open_replay_data = lmv_clear_open_replay_data
2657 int __init lmv_init(void)
2659 struct lprocfs_static_vars lvars;
2662 obj_cache = kmem_cache_create("lmv_objects",
2663 sizeof(struct lmv_obj),
2666 CERROR("error allocating lmv objects cache\n");
2670 lprocfs_init_vars(lmv, &lvars);
2671 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
2672 lvars.module_vars, LUSTRE_LMV_NAME, NULL);
2674 kmem_cache_destroy(obj_cache);
2680 static void lmv_exit(void)
2682 class_unregister_type(LUSTRE_LMV_NAME);
2684 LASSERTF(kmem_cache_destroy(obj_cache) == 0,
2685 "can't free lmv objects cache, %d object(s)"
2686 "still in use\n", atomic_read(&obj_cache_count));
2689 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2690 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
2691 MODULE_LICENSE("GPL");
2693 module_init(lmv_init);
2694 module_exit(lmv_exit);