1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003 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>
35 #include <liblustre.h>
37 #include <linux/ext2_fs.h>
39 #include <linux/obd_support.h>
40 #include <linux/lustre_lib.h>
41 #include <linux/lustre_net.h>
42 #include <linux/lustre_idl.h>
43 #include <linux/lustre_dlm.h>
44 #include <linux/lustre_mds.h>
45 #include <linux/obd_class.h>
46 #include <linux/obd_ost.h>
47 #include <linux/lprocfs_status.h>
48 #include <linux/lustre_fsfilt.h>
49 #include <linux/obd_lmv.h>
50 #include "lmv_internal.h"
54 * -EINVAL : UUID can't be found in the LMV's target list
55 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
56 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
58 static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid,
61 struct obd_device *obd;
62 struct lmv_tgt_desc *tgt;
66 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
67 lmv, uuid->uuid, activate);
69 spin_lock(&lmv->lmv_lock);
70 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
71 if (tgt->ltd_exp == NULL)
74 CDEBUG(D_INFO, "lmv idx %d is %s conn "LPX64"\n",
75 i, tgt->uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
76 if (strncmp(uuid->uuid, tgt->uuid.uuid, sizeof uuid->uuid) == 0)
80 if (i == lmv->desc.ld_tgt_count)
81 GOTO(out, rc = -EINVAL);
83 obd = class_exp2obd(tgt->ltd_exp);
85 GOTO(out, rc = -ENOTCONN);
87 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
88 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
89 obd->obd_type->typ_name, i);
90 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
92 if (tgt->active == activate) {
93 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
94 activate ? "" : "in");
98 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd, activate ? "" : "in");
100 tgt->active = activate;
102 lmv->desc.ld_active_tgt_count++;
104 lmv->desc.ld_active_tgt_count--;
108 spin_unlock(&lmv->lmv_lock);
112 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
113 int active, void *data)
116 struct obd_uuid *uuid;
118 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
119 CERROR("unexpected notification of %s %s!\n",
120 watched->obd_type->typ_name,
124 uuid = &watched->u.cli.cl_import->imp_target_uuid;
126 /* Set MDC as active before notifying the observer, so the
127 * observer can use the MDC normally.
129 rc = lmv_set_mdc_active(&obd->u.lmv, uuid, active);
131 CERROR("%sactivation of %s failed: %d\n",
132 active ? "" : "de", uuid->uuid, rc);
136 if (obd->obd_observer)
137 /* Pass the notification up the chain. */
138 rc = obd_notify(obd->obd_observer, watched, active, data);
143 int lmv_attach(struct obd_device *dev, obd_count len, void *data)
145 struct lprocfs_static_vars lvars;
149 lprocfs_init_vars(lmv, &lvars);
150 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
153 struct proc_dir_entry *entry;
155 entry = create_proc_entry("target_obd_status", 0444,
156 dev->obd_proc_entry);
159 entry->proc_fops = &lmv_proc_target_fops;
166 int lmv_detach(struct obd_device *dev)
168 return lprocfs_obd_detach(dev);
171 /* This is fake connect function. Its purpose is to initialize lmv and
172 * say caller that everything is okay. Real connection will be performed
174 static int lmv_connect(struct lustre_handle *conn, struct obd_device *obd,
175 struct obd_uuid *cluuid, unsigned long connect_flags)
177 struct lmv_obd *lmv = &obd->u.lmv;
178 struct obd_export *exp;
179 struct proc_dir_entry *lmv_proc_dir;
183 rc = class_connect(conn, obd, cluuid);
185 CERROR("class_connection() returned %d\n", rc);
189 exp = class_conn2export(conn);
190 /* We don't want to actually do the underlying connections more than
191 * once, so keep track. */
193 if (lmv->refcount > 1) {
194 class_export_put(exp);
198 lmv->cluuid = *cluuid;
199 lmv->connect_flags = connect_flags;
202 sema_init(&lmv->init_sem, 1);
204 lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
206 if (IS_ERR(lmv_proc_dir)) {
207 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
208 obd->obd_type->typ_name, obd->obd_name);
216 void lmv_set_timeouts(struct obd_device *obd)
218 struct lmv_tgt_desc *tgts;
223 if (lmv->server_timeout == 0)
226 if (lmv->connected == 0)
229 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) {
230 if (tgts->ltd_exp == NULL)
232 obd_set_info(tgts->ltd_exp, strlen("inter_mds"),
233 "inter_mds", 0, NULL);
237 /* Performs a check if passed obd is connected. If no - connect it. */
238 #define MAX_STRING_SIZE 128
239 int lmv_check_connect(struct obd_device *obd)
241 struct lmv_obd *lmv = &obd->u.lmv;
242 struct obd_uuid *cluuid;
243 struct lmv_tgt_desc *tgts;
244 struct proc_dir_entry *lmv_proc_dir;
245 struct obd_export *exp;
251 down(&lmv->init_sem);
252 if (lmv->connected) {
257 cluuid = &lmv->cluuid;
260 CDEBUG(D_OTHER, "time to connect %s to %s\n",
261 cluuid->uuid, obd->obd_name);
263 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) {
264 struct obd_device *tgt_obd;
265 struct obd_uuid lmv_osc_uuid = { "LMV_OSC_UUID" };
266 struct lustre_handle conn = {0, };
268 LASSERT(tgts != NULL);
270 tgt_obd = class_find_client_obd(&tgts->uuid, LUSTRE_MDC_NAME,
273 CERROR("Target %s not attached\n", tgts->uuid.uuid);
274 GOTO(out_disc, rc = -EINVAL);
277 /* for MDS: don't connect to yourself */
278 if (obd_uuid_equals(&tgts->uuid, cluuid)) {
279 CDEBUG(D_OTHER, "don't connect back to %s\n",
281 tgts->ltd_exp = NULL;
285 CDEBUG(D_OTHER, "connect to %s(%s) - %s, %s FOR %s\n",
286 tgt_obd->obd_name, tgt_obd->obd_uuid.uuid,
287 tgts->uuid.uuid, obd->obd_uuid.uuid,
290 if (!tgt_obd->obd_set_up) {
291 CERROR("Target %s not set up\n", tgts->uuid.uuid);
292 GOTO(out_disc, rc = -EINVAL);
295 rc = obd_connect(&conn, tgt_obd, &lmv_osc_uuid,
298 CERROR("Target %s connect error %d\n",
299 tgts->uuid.uuid, rc);
302 tgts->ltd_exp = class_conn2export(&conn);
304 obd_init_ea_size(tgts->ltd_exp, lmv->max_easize,
305 lmv->max_cookiesize);
307 rc = obd_register_observer(tgt_obd, obd);
309 CERROR("Target %s register_observer error %d\n",
310 tgts->uuid.uuid, rc);
311 obd_disconnect(tgts->ltd_exp, 0);
315 lmv->desc.ld_active_tgt_count++;
318 CDEBUG(D_OTHER, "connected to %s(%s) successfully (%d)\n",
319 tgt_obd->obd_name, tgt_obd->obd_uuid.uuid,
320 atomic_read(&obd->obd_refcount));
322 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
324 struct obd_device *mdc_obd = class_conn2obd(&conn);
325 struct proc_dir_entry *mdc_symlink;
326 char name[MAX_STRING_SIZE + 1];
328 LASSERT(mdc_obd != NULL);
329 LASSERT(mdc_obd->obd_type != NULL);
330 LASSERT(mdc_obd->obd_type->typ_name != NULL);
331 name[MAX_STRING_SIZE] = '\0';
332 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
333 mdc_obd->obd_type->typ_name,
335 mdc_symlink = proc_symlink(mdc_obd->obd_name,
337 if (mdc_symlink == NULL) {
338 CERROR("could not register LMV target "
339 "/proc/fs/lustre/%s/%s/target_obds/%s.",
340 obd->obd_type->typ_name, obd->obd_name,
342 lprocfs_remove(lmv_proc_dir);
348 lmv_set_timeouts(obd);
349 class_export_put(exp);
356 struct obd_uuid uuid;
358 --lmv->desc.ld_active_tgt_count;
360 /* save for CERROR below; (we know it's terminated) */
362 rc2 = obd_disconnect(tgts->ltd_exp, 0);
364 CERROR("error: LMV target %s disconnect on MDT idx %d: "
365 "error %d\n", uuid.uuid, i, rc2);
367 class_disconnect(exp, 0);
372 static int lmv_disconnect(struct obd_export *exp, int flags)
374 struct obd_device *obd = class_exp2obd(exp);
375 struct lmv_obd *lmv = &obd->u.lmv;
376 struct proc_dir_entry *lmv_proc_dir;
383 /* Only disconnect the underlying layers on the final disconnect. */
385 if (lmv->refcount != 0)
388 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
390 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
391 struct obd_device *mdc_obd;
393 if (lmv->tgts[i].ltd_exp == NULL)
396 mdc_obd = class_exp2obd(lmv->tgts[i].ltd_exp);
398 struct proc_dir_entry *mdc_symlink;
400 mdc_symlink = lprocfs_srch(lmv_proc_dir, mdc_obd->obd_name);
402 lprocfs_remove(mdc_symlink);
404 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing\n",
405 obd->obd_type->typ_name, obd->obd_name,
410 if (obd->obd_no_recov) {
411 /* Pass it on to our clients.
412 * XXX This should be an argument to disconnect,
413 * XXX not a back-door flag on the OBD. Ah well.
415 struct obd_device *mdc_obd;
416 mdc_obd = class_exp2obd(lmv->tgts[i].ltd_exp);
418 mdc_obd->obd_no_recov = 1;
421 CDEBUG(D_OTHER, "disconnected from %s(%s) successfully\n",
422 lmv->tgts[i].ltd_exp->exp_obd->obd_name,
423 lmv->tgts[i].ltd_exp->exp_obd->obd_uuid.uuid);
425 obd_register_observer(lmv->tgts[i].ltd_exp->exp_obd, NULL);
427 rc = obd_disconnect(lmv->tgts[i].ltd_exp, flags);
429 if (lmv->tgts[i].active) {
430 CERROR("Target %s disconnect error %d\n",
431 lmv->tgts[i].uuid.uuid, rc);
435 if (lmv->tgts[i].active) {
436 lmv->desc.ld_active_tgt_count--;
437 lmv->tgts[i].active = 0;
439 lmv->tgts[i].ltd_exp = NULL;
443 lprocfs_remove(lmv_proc_dir);
445 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
446 obd->obd_type->typ_name, obd->obd_name);
451 /* this is the case when no real connection is established by
452 * lmv_check_connect(). */
454 class_export_put(exp);
455 rc = class_disconnect(exp, 0);
456 if (lmv->refcount == 0)
461 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
462 int len, void *karg, void *uarg)
464 struct obd_device *obddev = class_exp2obd(exp);
465 struct lmv_obd *lmv = &obddev->u.lmv;
466 int i, rc = 0, set = 0;
470 if (lmv->desc.ld_tgt_count == 0)
473 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
476 if (lmv->tgts[i].ltd_exp == NULL) {
477 CWARN("%s: NULL export for %d\n", obddev->obd_name, i);
481 err = obd_iocontrol(cmd, lmv->tgts[i].ltd_exp, len, karg, uarg);
483 if (lmv->tgts[i].active) {
484 CERROR("error: iocontrol MDC %s on MDT"
485 "idx %d: err = %d\n",
486 lmv->tgts[i].uuid.uuid, i, err);
499 static int lmv_setup(struct obd_device *obd, obd_count len, void *buf)
502 struct lmv_desc *desc;
503 struct obd_uuid *uuids;
504 struct lmv_tgt_desc *tgts;
505 struct obd_device *tgt_obd;
506 struct lustre_cfg *lcfg = buf;
507 struct lmv_obd *lmv = &obd->u.lmv;
510 if (lcfg->lcfg_inllen1 < 1) {
511 CERROR("LMV setup requires a descriptor\n");
515 if (lcfg->lcfg_inllen2 < 1) {
516 CERROR("LMV setup requires an OST UUID list\n");
520 desc = (struct lmv_desc *)lcfg->lcfg_inlbuf1;
521 if (sizeof(*desc) > lcfg->lcfg_inllen1) {
522 CERROR("descriptor size wrong: %d > %d\n",
523 (int)sizeof(*desc), lcfg->lcfg_inllen1);
527 uuids = (struct obd_uuid *)lcfg->lcfg_inlbuf2;
528 if (sizeof(*uuids) * desc->ld_tgt_count != lcfg->lcfg_inllen2) {
529 CERROR("UUID array size wrong: %u * %u != %u\n",
530 sizeof(*uuids), desc->ld_tgt_count, lcfg->lcfg_inllen2);
534 lmv->bufsize = sizeof(struct lmv_tgt_desc) * desc->ld_tgt_count;
535 OBD_ALLOC(lmv->tgts, lmv->bufsize);
536 if (lmv->tgts == NULL) {
537 CERROR("Out of memory\n");
542 spin_lock_init(&lmv->lmv_lock);
544 for (i = 0, tgts = lmv->tgts; i < desc->ld_tgt_count; i++, tgts++)
545 tgts->uuid = uuids[i];
547 lmv->max_cookiesize = 0;
549 lmv->max_easize = sizeof(struct ll_fid) *
550 desc->ld_tgt_count + sizeof(struct mea);
552 rc = lmv_setup_mgr(obd);
554 CERROR("Can't setup LMV object manager, "
556 OBD_FREE(lmv->tgts, lmv->bufsize);
559 tgt_obd = class_find_client_obd(&lmv->tgts->uuid, LUSTRE_MDC_NAME,
562 CERROR("Target %s not attached\n", lmv->tgts->uuid.uuid);
569 static int lmv_statfs(struct obd_device *obd, struct obd_statfs *osfs,
570 unsigned long max_age)
572 struct lmv_obd *lmv = &obd->u.lmv;
573 struct obd_statfs temp;
577 rc = lmv_check_connect(obd);
581 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
582 if (lmv->tgts[i].ltd_exp == NULL) {
583 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
587 rc = obd_statfs(lmv->tgts[i].ltd_exp->exp_obd, &temp, max_age);
589 CERROR("can't stat MDS #%d (%s)\n", i,
590 lmv->tgts[i].ltd_exp->exp_obd->obd_name);
594 memcpy(osfs, &temp, sizeof(temp));
596 osfs->os_bavail += temp.os_bavail;
597 osfs->os_blocks += temp.os_blocks;
598 osfs->os_ffree += temp.os_ffree;
599 osfs->os_files += temp.os_files;
605 static int lmv_cleanup(struct obd_device *obd, int flags)
607 struct lmv_obd *lmv = &obd->u.lmv;
609 lmv_cleanup_mgr(obd);
610 OBD_FREE(lmv->tgts, lmv->bufsize);
614 static int lmv_getstatus(struct obd_export *exp, struct ll_fid *fid)
616 struct obd_device *obd = exp->exp_obd;
617 struct lmv_obd *lmv = &obd->u.lmv;
620 rc = lmv_check_connect(obd);
623 rc = md_getstatus(lmv->tgts[0].ltd_exp, fid);
628 static int lmv_getattr(struct obd_export *exp, struct ll_fid *fid,
629 unsigned long valid, unsigned int ea_size,
630 struct ptlrpc_request **request)
632 struct obd_device *obd = exp->exp_obd;
633 struct lmv_obd *lmv = &obd->u.lmv;
634 int rc, i = fid->mds;
638 rc = lmv_check_connect(obd);
642 LASSERT(i < lmv->desc.ld_tgt_count);
644 rc = md_getattr(lmv->tgts[i].ltd_exp, fid, valid,
649 obj = lmv_grab_obj(obd, fid);
651 CDEBUG(D_OTHER, "GETATTR for %lu/%lu/%lu %s\n",
652 (unsigned long)fid->mds, (unsigned long)fid->id,
653 (unsigned long)fid->generation, obj ? "(splitted)" : "");
655 /* if object is splitted, then we loop over all the slaves and gather
656 * size attribute. In ideal world we would have to gather also mds field
657 * from all slaves, as object is spread over the cluster and this is
658 * definitely interesting information and it is not good to loss it,
661 struct mds_body *body;
663 if (*request == NULL) {
668 body = lustre_msg_buf((*request)->rq_repmsg, 0,
670 LASSERT(body != NULL);
674 for (i = 0; i < obj->objcount; i++) {
676 if (lmv->tgts[i].ltd_exp == NULL) {
677 CWARN("%s: NULL export for %d\n",
682 /* skip master obj. */
683 if (fid_equal(&obj->fid, &obj->objs[i].fid))
686 body->size += obj->objs[i].size;
696 static int lmv_change_cbdata(struct obd_export *exp, struct ll_fid *fid,
697 ldlm_iterator_t it, void *data)
699 struct obd_device *obd = exp->exp_obd;
700 struct lmv_obd *lmv = &obd->u.lmv;
704 rc = lmv_check_connect(obd);
708 CDEBUG(D_OTHER, "CBDATA for %lu/%lu/%lu\n", (unsigned long)fid->mds,
709 (unsigned long)fid->id, (unsigned long)fid->generation);
711 LASSERT(fid->mds < lmv->desc.ld_tgt_count);
713 rc = md_change_cbdata(lmv->tgts[fid->mds].ltd_exp,
719 static int lmv_change_cbdata_name(struct obd_export *exp, struct ll_fid *pfid,
720 char *name, int len, struct ll_fid *cfid,
721 ldlm_iterator_t it, void *data)
723 struct obd_device *obd = exp->exp_obd;
724 struct lmv_obd *lmv = &obd->u.lmv;
729 rc = lmv_check_connect(obd);
733 LASSERT(pfid->mds < lmv->desc.ld_tgt_count);
734 LASSERT(cfid->mds < lmv->desc.ld_tgt_count);
736 CDEBUG(D_OTHER, "CBDATA for %lu/%lu/%lu:%*s -> %lu/%lu/%lu\n",
737 (unsigned long)pfid->mds, (unsigned long)pfid->id,
738 (unsigned long)pfid->generation, len, name,
739 (unsigned long)cfid->mds, (unsigned long)cfid->id,
740 (unsigned long)cfid->generation);
742 /* this is default mds for directory name belongs to. */
744 obj = lmv_grab_obj(obd, pfid);
746 /* directory is splitted. look for right mds for this name. */
747 mds = raw_name2idx(obj->hashtype, obj->objcount, name, len);
748 mds = obj->objs[mds].fid.mds;
751 rc = md_change_cbdata(lmv->tgts[mds].ltd_exp, cfid, it, data);
755 static int lmv_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
757 struct obd_device *obd = exp->exp_obd;
758 struct lmv_obd *lmv = &obd->u.lmv;
761 rc = lmv_check_connect(obd);
764 CDEBUG(D_OTHER, "validate %lu/%lu/%lu\n", (unsigned long) fid->mds,
765 (unsigned long) fid->id, (unsigned long) fid->generation);
766 LASSERT(fid->mds < lmv->desc.ld_tgt_count);
767 rc = md_valid_attrs(lmv->tgts[fid->mds].ltd_exp, fid);
771 int lmv_close(struct obd_export *exp, struct obdo *obdo,
772 struct obd_client_handle *och,
773 struct ptlrpc_request **request)
775 struct obd_device *obd = exp->exp_obd;
776 struct lmv_obd *lmv = &obd->u.lmv;
777 int rc, i = obdo->o_mds;
779 rc = lmv_check_connect(obd);
782 LASSERT(i < lmv->desc.ld_tgt_count);
783 CDEBUG(D_OTHER, "CLOSE %lu/%lu/%lu\n", (unsigned long) obdo->o_mds,
784 (unsigned long) obdo->o_id, (unsigned long) obdo->o_generation);
785 rc = md_close(lmv->tgts[i].ltd_exp, obdo, och, request);
789 int lmv_get_mea_and_update_object(struct obd_export *exp, struct ll_fid *fid)
791 struct obd_device *obd = exp->exp_obd;
792 struct lmv_obd *lmv = &obd->u.lmv;
793 struct ptlrpc_request *req = NULL;
800 mealen = MEA_SIZE_LMV(lmv);
802 valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
804 /* time to update mea of parent fid */
805 rc = md_getattr(lmv->tgts[fid->mds].ltd_exp, fid,
806 valid, mealen, &req);
808 CERROR("md_getattr() failed, error %d\n", rc);
812 rc = mdc_req2lustre_md(exp, req, 0, NULL, &md);
814 CERROR("mdc_req2lustre_md() failed, error %d\n", rc);
819 GOTO(cleanup, rc = -ENODATA);
821 obj = lmv_create_obj(exp, fid, md.mea);
826 obd_free_memmd(exp, (struct lov_stripe_md **)&md.mea);
830 ptlrpc_req_finished(req);
834 int lmv_create(struct obd_export *exp, struct mdc_op_data *op_data,
835 const void *data, int datalen, int mode, __u32 uid,
836 __u32 gid, __u64 rdev, struct ptlrpc_request **request)
838 struct obd_device *obd = exp->exp_obd;
839 struct lmv_obd *lmv = &obd->u.lmv;
840 struct mds_body *body;
842 int rc, mds, loop = 0;
845 rc = lmv_check_connect(obd);
849 if (!lmv->desc.ld_active_tgt_count)
852 LASSERT(++loop <= 2);
853 obj = lmv_grab_obj(obd, &op_data->fid1);
855 mds = raw_name2idx(obj->hashtype, obj->objcount, op_data->name,
857 op_data->fid1 = obj->objs[mds].fid;
861 CDEBUG(D_OTHER, "CREATE '%*s' on %lu/%lu/%lu\n", op_data->namelen,
862 op_data->name, (unsigned long)op_data->fid1.mds,
863 (unsigned long)op_data->fid1.id,
864 (unsigned long)op_data->fid1.generation);
866 rc = md_create(lmv->tgts[op_data->fid1.mds].ltd_exp, op_data, data,
867 datalen, mode, uid, gid, rdev, request);
869 if (*request == NULL)
872 body = lustre_msg_buf((*request)->rq_repmsg, 0,
874 LASSERT(body != NULL);
876 CDEBUG(D_OTHER, "created. id = %lu, generation = %lu, "
877 "mds = %d\n", (unsigned long)body->fid1.id,
878 (unsigned long)body->fid1.generation, op_data->fid1.mds);
880 LASSERT(body->valid & OBD_MD_MDS ||
881 body->mds == op_data->fid1.mds);
882 } else if (rc == -ERESTART) {
883 /* directory got splitted. time to update local object and
884 * repeat the request with proper MDS */
885 rc = lmv_get_mea_and_update_object(exp, &op_data->fid1);
887 ptlrpc_req_finished(*request);
894 int lmv_done_writing(struct obd_export *exp, struct obdo *obdo)
896 struct obd_device *obd = exp->exp_obd;
897 struct lmv_obd *lmv = &obd->u.lmv;
900 rc = lmv_check_connect(obd);
904 /* FIXME: choose right MDC here */
905 CWARN("this method isn't implemented yet\n");
906 rc = md_done_writing(lmv->tgts[0].ltd_exp, obdo);
910 int lmv_enqueue_slaves(struct obd_export *exp, int locktype,
911 struct lookup_intent *it, int lockmode,
912 struct mdc_op_data *data, struct lustre_handle *lockh,
913 void *lmm, int lmmsize, ldlm_completion_callback cb_completion,
914 ldlm_blocking_callback cb_blocking, void *cb_data)
916 struct obd_device *obd = exp->exp_obd;
917 struct lmv_obd *lmv = &obd->u.lmv;
918 struct mea *mea = data->mea1;
919 struct mdc_op_data data2;
923 LASSERT(mea != NULL);
924 for (i = 0; i < mea->mea_count; i++) {
925 memset(&data2, 0, sizeof(data2));
926 data2.fid1 = mea->mea_fids[i];
927 mds = data2.fid1.mds;
929 if (lmv->tgts[mds].ltd_exp == NULL)
932 rc = md_enqueue(lmv->tgts[mds].ltd_exp, locktype, it, lockmode,
933 &data2, lockh + i, lmm, lmmsize, cb_completion,
934 cb_blocking, cb_data);
936 CDEBUG(D_OTHER, "take lock on slave %lu/%lu/%lu -> %d/%d\n",
937 (unsigned long)mea->mea_fids[i].mds,
938 (unsigned long)mea->mea_fids[i].id,
939 (unsigned long)mea->mea_fids[i].generation,
940 rc, it->d.lustre.it_status);
943 if (it->d.lustre.it_data) {
944 struct ptlrpc_request *req;
945 req = (struct ptlrpc_request *) it->d.lustre.it_data;
946 ptlrpc_req_finished(req);
949 if (it->d.lustre.it_status)
950 GOTO(cleanup, rc = it->d.lustre.it_status);
955 /* drop all taken locks */
958 ldlm_lock_decref(lockh + i, lockmode);
964 int lmv_enqueue(struct obd_export *exp, int lock_type,
965 struct lookup_intent *it, int lock_mode,
966 struct mdc_op_data *data, struct lustre_handle *lockh,
967 void *lmm, int lmmsize, ldlm_completion_callback cb_completion,
968 ldlm_blocking_callback cb_blocking, void *cb_data)
970 struct obd_device *obd = exp->exp_obd;
971 struct lmv_obd *lmv = &obd->u.lmv;
976 rc = lmv_check_connect(obd);
980 if (it->it_op == IT_UNLINK) {
981 rc = lmv_enqueue_slaves(exp, lock_type, it, lock_mode,
982 data, lockh, lmm, lmmsize,
983 cb_completion, cb_blocking, cb_data);
988 obj = lmv_grab_obj(obd, &data->fid1);
990 /* directory is splitted. look for right mds for this
992 mds = raw_name2idx(obj->hashtype, obj->objcount,
993 (char *)data->name, data->namelen);
994 data->fid1 = obj->objs[mds].fid;
998 CDEBUG(D_OTHER, "ENQUEUE '%s' on %lu/%lu\n", LL_IT2STR(it),
999 (unsigned long)data->fid1.id, (unsigned long)data->fid1.generation);
1001 rc = md_enqueue(lmv->tgts[data->fid1.mds].ltd_exp, lock_type, it,
1002 lock_mode, data, lockh, lmm, lmmsize, cb_completion,
1003 cb_blocking, cb_data);
1008 int lmv_getattr_name(struct obd_export *exp, struct ll_fid *fid,
1009 char *filename, int namelen, unsigned long valid,
1010 unsigned int ea_size, struct ptlrpc_request **request)
1012 struct obd_device *obd = exp->exp_obd;
1013 struct lmv_obd *lmv = &obd->u.lmv;
1014 struct ll_fid rfid = *fid;
1015 int rc, mds = fid->mds, loop = 0;
1016 struct mds_body *body;
1017 struct lmv_obj *obj;
1019 rc = lmv_check_connect(obd);
1023 LASSERT(++loop <= 2);
1024 obj = lmv_grab_obj(obd, fid);
1026 /* directory is splitted. look for right mds for this name */
1027 mds = raw_name2idx(obj->hashtype, obj->objcount, filename, namelen - 1);
1028 rfid = obj->objs[mds].fid;
1032 CDEBUG(D_OTHER, "getattr_name for %*s on %lu/%lu/%lu -> %lu/%lu/%lu\n",
1033 namelen, filename, (unsigned long)fid->mds,
1034 (unsigned long)fid->id, (unsigned long)fid->generation,
1035 (unsigned long)rfid.mds, (unsigned long)rfid.id,
1036 (unsigned long)rfid.generation);
1038 rc = md_getattr_name(lmv->tgts[rfid.mds].ltd_exp, &rfid, filename,
1039 namelen, valid, ea_size, request);
1041 /* this could be cross-node reference. in this case all we have
1042 * right now is mds/ino/generation triple. we'd like to find
1043 * other attributes */
1044 body = lustre_msg_buf((*request)->rq_repmsg, 0, sizeof(*body));
1045 LASSERT(body != NULL);
1046 if (body->valid & OBD_MD_MDS) {
1047 struct ptlrpc_request *req = NULL;
1049 CDEBUG(D_OTHER, "request attrs for %lu/%lu/%lu\n",
1050 (unsigned long) rfid.mds,
1051 (unsigned long) rfid.id,
1052 (unsigned long) rfid.generation);
1053 rc = md_getattr_name(lmv->tgts[rfid.mds].ltd_exp, &rfid,
1054 NULL, 1, valid, ea_size, &req);
1055 ptlrpc_req_finished(*request);
1058 } else if (rc == -ERESTART) {
1059 /* directory got splitted. time to update local object and
1060 * repeat the request with proper MDS */
1061 rc = lmv_get_mea_and_update_object(exp, &rfid);
1063 ptlrpc_req_finished(*request);
1072 * llite passes fid of an target inode in data->fid1 and fid of directory in
1075 int lmv_link(struct obd_export *exp, struct mdc_op_data *data,
1076 struct ptlrpc_request **request)
1078 struct obd_device *obd = exp->exp_obd;
1079 struct lmv_obd *lmv = &obd->u.lmv;
1080 struct lmv_obj *obj;
1084 rc = lmv_check_connect(obd);
1088 if (data->namelen != 0) {
1089 /* usual link request */
1090 obj = lmv_grab_obj(obd, &data->fid1);
1092 rc = raw_name2idx(obj->hashtype, obj->objcount, data->name,
1094 data->fid1 = obj->objs[rc].fid;
1098 CDEBUG(D_OTHER,"link %lu/%lu/%lu:%*s to %lu/%lu/%lu mds %lu\n",
1099 (unsigned long)data->fid2.mds,
1100 (unsigned long)data->fid2.id,
1101 (unsigned long)data->fid2.generation,
1102 data->namelen, data->name,
1103 (unsigned long)data->fid1.mds,
1104 (unsigned long)data->fid1.id,
1105 (unsigned long)data->fid1.generation,
1106 (unsigned long)data->fid1.mds);
1108 /* request from MDS to acquire i_links for inode by fid1 */
1109 CDEBUG(D_OTHER, "inc i_nlinks for %lu/%lu/%lu\n",
1110 (unsigned long)data->fid1.mds,
1111 (unsigned long)data->fid1.id,
1112 (unsigned long)data->fid1.generation);
1115 rc = md_link(lmv->tgts[data->fid1.mds].ltd_exp, data, request);
1119 int lmv_rename(struct obd_export *exp, struct mdc_op_data *data,
1120 const char *old, int oldlen, const char *new, int newlen,
1121 struct ptlrpc_request **request)
1123 struct obd_device *obd = exp->exp_obd;
1124 struct lmv_obd *lmv = &obd->u.lmv;
1125 struct lmv_obj *obj;
1129 CDEBUG(D_OTHER, "rename %*s in %lu/%lu/%lu to %*s in %lu/%lu/%lu\n",
1130 oldlen, old, (unsigned long)data->fid1.mds,
1131 (unsigned long)data->fid1.id,
1132 (unsigned long)data->fid1.generation,
1133 newlen, new, (unsigned long) data->fid2.mds,
1134 (unsigned long) data->fid2.id,
1135 (unsigned long) data->fid2.generation);
1137 if (!fid_equal(&data->fid1, &data->fid2))
1138 CWARN("cross-node rename %lu/%lu/%lu:%*s to %lu/%lu/%lu:%*s\n",
1139 (unsigned long)data->fid1.mds,
1140 (unsigned long)data->fid1.id,
1141 (unsigned long)data->fid1.generation, oldlen, old,
1142 (unsigned long)data->fid2.mds,
1143 (unsigned long)data->fid2.id,
1144 (unsigned long)data->fid2.generation, newlen, new);
1146 rc = lmv_check_connect(obd);
1151 /* MDS with old dir entry is asking another MDS to create name
1154 "create %*s(%d/%d) in %lu/%lu/%lu pointing to %lu/%lu/%lu\n",
1155 newlen, new, oldlen, newlen,
1156 (unsigned long)data->fid2.mds,
1157 (unsigned long)data->fid2.id,
1158 (unsigned long)data->fid2.generation,
1159 (unsigned long)data->fid1.mds,
1160 (unsigned long)data->fid1.id,
1161 (unsigned long)data->fid1.generation);
1162 mds = data->fid2.mds;
1166 obj = lmv_grab_obj(obd, &data->fid1);
1168 /* directory is already splitted, so we have to forward request
1169 * to the right MDS */
1170 mds = raw_name2idx(obj->hashtype, obj->objcount, (char *)old, oldlen);
1171 data->fid1 = obj->objs[mds].fid;
1172 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
1173 (unsigned long)obj->objs[mds].fid.mds,
1174 (unsigned long)obj->objs[mds].fid.id,
1175 (unsigned long)obj->objs[mds].fid.generation);
1179 obj = lmv_grab_obj(obd, &data->fid2);
1181 /* directory is already splitted, so we have to forward request
1182 * to the right MDS */
1183 mds = raw_name2idx(obj->hashtype, obj->objcount, (char *)new, newlen);
1184 data->fid2 = obj->objs[mds].fid;
1185 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
1186 (unsigned long)obj->objs[mds].fid.mds,
1187 (unsigned long)obj->objs[mds].fid.id,
1188 (unsigned long)obj->objs[mds].fid.generation);
1192 mds = data->fid1.mds;
1195 rc = md_rename(lmv->tgts[mds].ltd_exp, data, old, oldlen,
1196 new, newlen, request);
1200 int lmv_setattr(struct obd_export *exp, struct mdc_op_data *data,
1201 struct iattr *iattr, void *ea, int ealen, void *ea2,
1202 int ea2len, struct ptlrpc_request **request)
1204 struct obd_device *obd = exp->exp_obd;
1205 struct lmv_obd *lmv = &obd->u.lmv;
1206 struct ptlrpc_request *req;
1207 struct mds_body *body;
1208 struct lmv_obj *obj;
1212 rc = lmv_check_connect(obd);
1216 obj = lmv_grab_obj(obd, &data->fid1);
1218 CDEBUG(D_OTHER, "SETATTR for %lu/%lu/%lu, valid 0x%x%s\n",
1219 (unsigned long)data->fid1.mds, (unsigned long)data->fid1.id,
1220 (unsigned long)data->fid1.generation, iattr->ia_valid,
1221 obj ? ", splitted" : "");
1224 for (i = 0; i < obj->objcount; i++) {
1225 data->fid1 = obj->objs[i].fid;
1227 rc = md_setattr(lmv->tgts[data->fid1.mds].ltd_exp, data,
1228 iattr, ea, ealen, ea2, ea2len, &req);
1230 if (fid_equal(&obj->fid, &obj->objs[i].fid)) {
1231 /* this is master object and this request should
1232 * be returned back to llite */
1235 ptlrpc_req_finished(req);
1243 LASSERT(data->fid1.mds < lmv->desc.ld_tgt_count);
1244 rc = md_setattr(lmv->tgts[data->fid1.mds].ltd_exp, data,
1245 iattr, ea, ealen, ea2, ea2len, request);
1247 body = lustre_msg_buf((*request)->rq_repmsg, 0,
1249 LASSERT(body != NULL);
1250 LASSERT(body->mds == data->fid1.mds);
1256 int lmv_sync(struct obd_export *exp, struct ll_fid *fid,
1257 struct ptlrpc_request **request)
1259 struct obd_device *obd = exp->exp_obd;
1260 struct lmv_obd *lmv = &obd->u.lmv;
1264 rc = lmv_check_connect(obd);
1268 rc = md_sync(lmv->tgts[fid->mds].ltd_exp, fid, request);
1272 int lmv_dirobj_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
1273 void *data, int flag)
1275 struct lustre_handle lockh;
1276 struct lmv_obj *obj;
1281 case LDLM_CB_BLOCKING:
1282 ldlm_lock2handle(lock, &lockh);
1283 rc = ldlm_cli_cancel(&lockh);
1285 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
1289 case LDLM_CB_CANCELING:
1290 /* time to drop cached attrs for dirobj */
1291 obj = lock->l_ast_data;
1293 CDEBUG(D_OTHER, "cancel %s on "LPU64"/"LPU64
1294 ", master %u/"LPU64"/%u\n",
1295 lock->l_resource->lr_name.name[3] == 1 ?
1296 "LOOKUP" : "UPDATE",
1297 lock->l_resource->lr_name.name[0],
1298 lock->l_resource->lr_name.name[1], obj->fid.mds,
1299 obj->fid.id, obj->fid.generation);
1309 void lmv_remove_dots(struct page *page)
1311 char *kaddr = page_address(page);
1312 unsigned limit = PAGE_CACHE_SIZE;
1313 unsigned offs, rec_len;
1314 struct ext2_dir_entry_2 *p;
1316 for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
1317 p = (struct ext2_dir_entry_2 *)(kaddr + offs);
1318 rec_len = le16_to_cpu(p->rec_len);
1320 if ((p->name_len == 1 && p->name[0] == '.') ||
1321 (p->name_len == 2 && p->name[0] == '.' && p->name[1] == '.'))
1326 int lmv_readpage(struct obd_export *exp, struct ll_fid *mdc_fid,
1327 __u64 offset, struct page *page,
1328 struct ptlrpc_request **request)
1330 struct obd_device *obd = exp->exp_obd;
1331 struct lmv_obd *lmv = &obd->u.lmv;
1332 struct ll_fid rfid = *mdc_fid;
1333 struct lmv_obj *obj;
1337 rc = lmv_check_connect(obd);
1341 LASSERT(mdc_fid->mds < lmv->desc.ld_tgt_count);
1342 CDEBUG(D_OTHER, "READPAGE at %llu from %lu/%lu/%lu\n",
1343 offset, (unsigned long) rfid.mds,
1344 (unsigned long) rfid.id,
1345 (unsigned long) rfid.generation);
1347 obj = lmv_grab_obj(obd, mdc_fid);
1351 /* find dirobj containing page with requested offset. */
1352 for (i = 0; i < obj->objcount; i++) {
1353 if (offset < obj->objs[i].size)
1355 offset -= obj->objs[i].size;
1357 rfid = obj->objs[i].fid;
1359 lmv_unlock_obj(obj);
1362 CDEBUG(D_OTHER, "forward to %lu/%lu/%lu with offset %lu\n",
1363 (unsigned long)rfid.mds, (unsigned long)rfid.id,
1364 (unsigned long)rfid.generation, (unsigned long)offset);
1366 rc = md_readpage(lmv->tgts[rfid.mds].ltd_exp, &rfid, offset,
1369 if (rc == 0 && !fid_equal(&rfid, mdc_fid))
1370 /* this page isn't from master object. To avoid "." and ".."
1371 * duplication in directory, we have to remove them from all
1373 lmv_remove_dots(page);
1378 int lmv_unlink_slaves(struct obd_export *exp, struct mdc_op_data *data,
1379 struct ptlrpc_request **req)
1381 struct obd_device *obd = exp->exp_obd;
1382 struct lmv_obd *lmv = &obd->u.lmv;
1383 struct mea *mea = data->mea1;
1384 struct mdc_op_data data2;
1388 LASSERT(mea != NULL);
1389 for (i = 0; i < mea->mea_count; i++) {
1390 memset(&data2, 0, sizeof(data2));
1391 data2.fid1 = mea->mea_fids[i];
1392 data2.create_mode = MDS_MODE_DONT_LOCK | S_IFDIR;
1393 mds = data2.fid1.mds;
1395 if (lmv->tgts[mds].ltd_exp == NULL)
1398 rc = md_unlink(lmv->tgts[mds].ltd_exp, &data2, req);
1399 CDEBUG(D_OTHER, "unlink slave %lu/%lu/%lu -> %d\n",
1400 (unsigned long) mea->mea_fids[i].mds,
1401 (unsigned long) mea->mea_fids[i].id,
1402 (unsigned long) mea->mea_fids[i].generation, rc);
1404 ptlrpc_req_finished(*req);
1413 int lmv_delete_object(struct obd_export *exp, struct ll_fid *fid)
1417 if (!lmv_delete_obj(exp, fid)) {
1418 CDEBUG(D_OTHER, "Object %lu/%lu/%lu is not found.\n",
1419 (unsigned long)fid->mds, (unsigned long)fid->id,
1420 (unsigned long)fid->generation);
1426 int lmv_unlink(struct obd_export *exp, struct mdc_op_data *data,
1427 struct ptlrpc_request **request)
1429 struct obd_device *obd = exp->exp_obd;
1430 struct lmv_obd *lmv = &obd->u.lmv;
1434 rc = lmv_check_connect(obd);
1438 if (data->namelen == 0 && data->mea1 != NULL) {
1439 /* mds asks to remove slave objects */
1440 rc = lmv_unlink_slaves(exp, data, request);
1442 } else if (data->namelen != 0) {
1443 struct lmv_obj *obj;
1445 obj = lmv_grab_obj(obd, &data->fid1);
1447 i = raw_name2idx(obj->hashtype, obj->objcount, data->name,
1449 data->fid1 = obj->objs[i].fid;
1452 CDEBUG(D_OTHER, "unlink '%*s' in %lu/%lu/%lu -> %u\n",
1453 data->namelen, data->name,
1454 (unsigned long) data->fid1.mds,
1455 (unsigned long) data->fid1.id,
1456 (unsigned long) data->fid1.generation, i);
1458 CDEBUG(D_OTHER, "drop i_nlink on %lu/%lu/%lu\n",
1459 (unsigned long) data->fid1.mds,
1460 (unsigned long) data->fid1.id,
1461 (unsigned long) data->fid1.generation);
1463 rc = md_unlink(lmv->tgts[data->fid1.mds].ltd_exp, data, request);
1467 struct obd_device *lmv_get_real_obd(struct obd_export *exp,
1468 char *name, int len)
1470 struct obd_device *obd = exp->exp_obd;
1471 struct lmv_obd *lmv = &obd->u.lmv;
1475 rc = lmv_check_connect(obd);
1477 RETURN(ERR_PTR(rc));
1478 #warning "we need well-desgined readdir() implementation to remove this mess"
1479 obd = lmv->tgts[0].ltd_exp->exp_obd;
1484 int lmv_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
1486 struct obd_device *obd = exp->exp_obd;
1487 struct lmv_obd *lmv = &obd->u.lmv;
1488 int i, rc = 0, change = 0;
1491 if (lmv->max_easize < easize) {
1492 lmv->max_easize = easize;
1495 if (lmv->max_cookiesize < cookiesize) {
1496 lmv->max_cookiesize = cookiesize;
1502 if (lmv->connected == 0)
1505 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1506 if (lmv->tgts[i].ltd_exp == NULL) {
1507 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
1511 rc = obd_init_ea_size(lmv->tgts[i].ltd_exp, easize, cookiesize);
1513 CERROR("obd_init_ea_size() failed on MDT target %d, "
1514 "error %d.\n", i, rc);
1521 int lmv_obd_create_single(struct obd_export *exp, struct obdo *oa,
1522 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1524 struct obd_device *obd = exp->exp_obd;
1525 struct lmv_obd *lmv = &obd->u.lmv;
1526 struct lov_stripe_md obj_md;
1527 struct lov_stripe_md *obj_mdp = &obj_md;
1531 LASSERT(ea == NULL);
1532 LASSERT(oa->o_mds < lmv->desc.ld_tgt_count);
1534 rc = obd_create(lmv->tgts[oa->o_mds].ltd_exp, oa, &obj_mdp, oti);
1540 * to be called from MDS only
1542 int lmv_obd_create(struct obd_export *exp, struct obdo *oa,
1543 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1545 struct obd_device *obd = exp->exp_obd;
1546 struct lmv_obd *lmv = &obd->u.lmv;
1553 rc = lmv_check_connect(obd);
1557 LASSERT(oa != NULL);
1560 rc = lmv_obd_create_single(exp, oa, NULL, oti);
1565 rc = obd_alloc_diskmd(exp, (struct lov_mds_md **)ea);
1567 CERROR("obd_alloc_diskmd() failed, error %d\n",
1578 mfid.generation = oa->o_generation;
1580 mea = (struct mea *)*ea;
1581 if (!mea->mea_count || mea->mea_count > lmv->desc.ld_tgt_count)
1582 mea->mea_count = lmv->desc.ld_tgt_count;
1583 mea->mea_magic = MEA_MAGIC_ALL_CHARS;
1585 mea->mea_master = -1;
1586 lcount = lmv->desc.ld_tgt_count;
1587 for (i = 0, c = 0; c < mea->mea_count && i < lcount; i++) {
1588 struct lov_stripe_md obj_md;
1589 struct lov_stripe_md *obj_mdp = &obj_md;
1591 if (lmv->tgts[i].ltd_exp == NULL) {
1592 /* this is master MDS */
1593 mea->mea_fids[c].id = mfid.id;
1594 mea->mea_fids[c].generation = mfid.generation;
1595 mea->mea_fids[c].mds = i;
1596 mea->mea_master = i;
1601 /* "master" MDS should always be part of stripped dir, so scan
1603 if (mea->mea_master == -1 && c == mea->mea_count - 1)
1606 oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLTYPE | OBD_MD_FLMODE
1607 | OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLID;
1609 rc = obd_create(lmv->tgts[c].ltd_exp, oa, &obj_mdp, oti);
1611 CERROR("obd_create() failed on MDT target %d, "
1612 "error %d\n", c, rc);
1616 mea->mea_fids[c].id = oa->o_id;
1617 mea->mea_fids[c].generation = oa->o_generation;
1618 mea->mea_fids[c].mds = i;
1620 CDEBUG(D_OTHER, "dirobj at mds %d: "LPU64"/%u\n",
1621 i, oa->o_id, oa->o_generation);
1623 LASSERT(c == mea->mea_count);
1624 CDEBUG(D_OTHER, "%d dirobjects created\n", (int) mea->mea_count);
1629 static int lmv_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
1630 struct obd_device *tgt, int count,
1631 struct llog_catid *logid)
1633 struct llog_ctxt *ctxt;
1637 rc = obd_llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1640 ctxt = llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT);
1641 ctxt->loc_imp = tgt->u.cli.cl_import;
1647 static int lmv_llog_finish(struct obd_device *obd,
1648 struct obd_llogs *llogs, int count)
1653 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT));
1657 static int lmv_get_info(struct obd_export *exp, __u32 keylen,
1658 void *key, __u32 *vallen, void *val)
1660 struct obd_device *obd;
1661 struct lmv_obd *lmv;
1664 obd = class_exp2obd(exp);
1666 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1667 exp->exp_handle.h_cookie);
1672 if (keylen == 6 && memcmp(key, "mdsize", 6) == 0) {
1673 __u32 *mdsize = val;
1674 *vallen = sizeof(__u32);
1675 *mdsize = sizeof(struct ll_fid) * lmv->desc.ld_tgt_count
1676 + sizeof(struct mea);
1678 } else if (keylen == 6 && memcmp(key, "mdsnum", 6) == 0) {
1679 struct obd_uuid *cluuid = &lmv->cluuid;
1680 struct lmv_tgt_desc *tgts;
1681 __u32 *mdsnum = val;
1684 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) {
1685 if (obd_uuid_equals(&tgts->uuid, cluuid)) {
1686 *vallen = sizeof(__u32);
1694 CDEBUG(D_IOCTL, "invalid key\n");
1698 int lmv_set_info(struct obd_export *exp, obd_count keylen,
1699 void *key, obd_count vallen, void *val)
1701 struct obd_device *obd;
1702 struct lmv_obd *lmv;
1705 obd = class_exp2obd(exp);
1707 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1708 exp->exp_handle.h_cookie);
1713 if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
1714 lmv->server_timeout = 1;
1715 lmv_set_timeouts(obd);
1722 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
1723 struct lov_stripe_md *lsm)
1725 struct obd_device *obd = class_exp2obd(exp);
1726 struct lmv_obd *lmv = &obd->u.lmv;
1730 mea_size = sizeof(struct ll_fid) *
1731 lmv->desc.ld_tgt_count + sizeof(struct mea);
1735 if (*lmmp && !lsm) {
1736 OBD_FREE(*lmmp, mea_size);
1741 if (*lmmp == NULL) {
1742 OBD_ALLOC(*lmmp, mea_size);
1750 #warning "MEA packing/convertation must be here! -bzzz"
1751 memcpy(*lmmp, lsm, mea_size);
1755 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **mem_tgt,
1756 struct lov_mds_md *disk_src, int mdsize)
1758 struct obd_device *obd = class_exp2obd(exp);
1759 struct lmv_obd *lmv = &obd->u.lmv;
1760 struct mea **tmea = (struct mea **) mem_tgt;
1761 struct mea *mea = (void *) disk_src;
1765 mea_size = sizeof(struct ll_fid) *
1766 lmv->desc.ld_tgt_count + sizeof(struct mea);
1767 if (mem_tgt == NULL)
1770 if (*mem_tgt != NULL && disk_src == NULL) {
1771 OBD_FREE(*tmea, mea_size);
1775 LASSERT(mea_size == mdsize);
1777 OBD_ALLOC(*tmea, mea_size);
1784 #warning "MEA unpacking/convertation must be here! -bzzz"
1785 memcpy(*tmea, mea, mdsize);
1789 int lmv_brw(int rw, struct obd_export *exp, struct obdo *oa,
1790 struct lov_stripe_md *ea, obd_count oa_bufs,
1791 struct brw_page *pgarr, struct obd_trans_info *oti)
1793 struct obd_device *obd = exp->exp_obd;
1794 struct lmv_obd *lmv = &obd->u.lmv;
1795 struct mea *mea = (struct mea *) ea;
1798 LASSERT(oa != NULL);
1799 LASSERT(ea != NULL);
1800 LASSERT(pgarr != NULL);
1801 LASSERT(oa->o_mds < lmv->desc.ld_tgt_count);
1803 oa->o_gr = mea->mea_fids[oa->o_mds].generation;
1804 oa->o_id = mea->mea_fids[oa->o_mds].id;
1805 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1806 err = obd_brw(rw, lmv->tgts[oa->o_mds].ltd_exp, oa,
1807 NULL, oa_bufs, pgarr, oti);
1811 struct obd_ops lmv_obd_ops = {
1812 .o_owner = THIS_MODULE,
1813 .o_attach = lmv_attach,
1814 .o_detach = lmv_detach,
1815 .o_setup = lmv_setup,
1816 .o_cleanup = lmv_cleanup,
1817 .o_connect = lmv_connect,
1818 .o_disconnect = lmv_disconnect,
1819 .o_statfs = lmv_statfs,
1820 .o_llog_init = lmv_llog_init,
1821 .o_llog_finish = lmv_llog_finish,
1822 .o_get_info = lmv_get_info,
1823 .o_set_info = lmv_set_info,
1824 .o_create = lmv_obd_create,
1825 .o_packmd = lmv_packmd,
1826 .o_unpackmd = lmv_unpackmd,
1828 .o_init_ea_size = lmv_init_ea_size,
1829 .o_notify = lmv_notify,
1830 .o_iocontrol = lmv_iocontrol,
1833 struct md_ops lmv_md_ops = {
1834 .m_getstatus = lmv_getstatus,
1835 .m_getattr = lmv_getattr,
1836 .m_change_cbdata = lmv_change_cbdata,
1837 .m_change_cbdata_name = lmv_change_cbdata_name,
1838 .m_close = lmv_close,
1839 .m_create = lmv_create,
1840 .m_done_writing = lmv_done_writing,
1841 .m_enqueue = lmv_enqueue,
1842 .m_getattr_name = lmv_getattr_name,
1843 .m_intent_lock = lmv_intent_lock,
1845 .m_rename = lmv_rename,
1846 .m_setattr = lmv_setattr,
1848 .m_readpage = lmv_readpage,
1849 .m_unlink = lmv_unlink,
1850 .m_get_real_obd = lmv_get_real_obd,
1851 .m_valid_attrs = lmv_valid_attrs,
1852 .m_delete_object = lmv_delete_object,
1855 int __init lmv_init(void)
1857 struct lprocfs_static_vars lvars;
1860 lprocfs_init_vars(lmv, &lvars);
1861 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
1862 lvars.module_vars, OBD_LMV_DEVICENAME);
1867 static void lmv_exit(void)
1869 class_unregister_type(OBD_LMV_DEVICENAME);
1872 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1873 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
1874 MODULE_LICENSE("GPL");
1876 module_init(lmv_init);
1877 module_exit(lmv_exit);