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>
34 #include <linux/namei.h>
36 #include <liblustre.h>
38 #include <linux/ext2_fs.h>
40 #include <linux/obd_support.h>
41 #include <linux/lustre_lib.h>
42 #include <linux/lustre_net.h>
43 #include <linux/lustre_idl.h>
44 #include <linux/lustre_dlm.h>
45 #include <linux/lustre_mds.h>
46 #include <linux/obd_class.h>
47 #include <linux/obd_ost.h>
48 #include <linux/lprocfs_status.h>
49 #include <linux/lustre_fsfilt.h>
50 #include <linux/obd_lmv.h>
51 #include <linux/lustre_lite.h>
52 #include "lmv_internal.h"
54 /* not defined for liblustre building */
55 #if !defined(ATOMIC_INIT)
56 #define ATOMIC_INIT(val) { (val) }
60 kmem_cache_t *obj_cache;
61 atomic_t obj_cache_count = ATOMIC_INIT(0);
63 static void lmv_activate_target(struct lmv_obd *lmv,
64 struct lmv_tgt_desc *tgt,
67 if (tgt->active == activate)
70 tgt->active = activate;
71 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
76 * -EINVAL : UUID can't be found in the LMV's target list
77 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
78 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
80 static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid,
83 struct lmv_tgt_desc *tgt;
84 struct obd_device *obd;
88 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
89 lmv, uuid->uuid, activate);
91 spin_lock(&lmv->lmv_lock);
92 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
93 if (tgt->ltd_exp == NULL)
96 CDEBUG(D_INFO, "lmv idx %d is %s conn "LPX64"\n",
97 i, tgt->uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
99 if (obd_uuid_equals(uuid, &tgt->uuid))
103 if (i == lmv->desc.ld_tgt_count)
104 GOTO(out_lmv_lock, rc = -EINVAL);
106 obd = class_exp2obd(tgt->ltd_exp);
108 GOTO(out_lmv_lock, rc = -ENOTCONN);
110 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
111 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
112 obd->obd_type->typ_name, i);
113 LASSERT(strcmp(obd->obd_type->typ_name, OBD_MDC_DEVICENAME) == 0);
115 if (tgt->active == activate) {
116 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
117 activate ? "" : "in");
118 GOTO(out_lmv_lock, rc);
121 CDEBUG(D_INFO, "Marking OBD %p %sactive\n",
122 obd, activate ? "" : "in");
124 lmv_activate_target(lmv, tgt, activate);
129 spin_unlock(&lmv->lmv_lock);
133 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
134 int active, void *data)
136 struct obd_uuid *uuid;
140 if (strcmp(watched->obd_type->typ_name, OBD_MDC_DEVICENAME)) {
141 CERROR("unexpected notification of %s %s!\n",
142 watched->obd_type->typ_name,
146 uuid = &watched->u.cli.cl_import->imp_target_uuid;
148 /* Set MDC as active before notifying the observer, so the observer can
149 * use the MDC normally.
151 rc = lmv_set_mdc_active(&obd->u.lmv, uuid, active);
153 CERROR("%sactivation of %s failed: %d\n",
154 active ? "" : "de", uuid->uuid, rc);
158 if (obd->obd_observer)
159 /* Pass the notification up the chain. */
160 rc = obd_notify(obd->obd_observer, watched, active, data);
165 static int lmv_attach(struct obd_device *dev, obd_count len, void *data)
167 struct lprocfs_static_vars lvars;
171 lprocfs_init_vars(lmv, &lvars);
172 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
175 struct proc_dir_entry *entry;
177 entry = create_proc_entry("target_obd_status", 0444,
178 dev->obd_proc_entry);
181 entry->proc_fops = &lmv_proc_target_fops;
188 static int lmv_detach(struct obd_device *dev)
190 return lprocfs_obd_detach(dev);
193 /* this is fake connect function. Its purpose is to initialize lmv and say
194 * caller that everything is okay. Real connection will be performed later. */
195 static int lmv_connect(struct lustre_handle *conn, struct obd_device *obd,
196 struct obd_uuid *cluuid, struct obd_connect_data *data,
200 struct proc_dir_entry *lmv_proc_dir;
202 struct lmv_obd *lmv = &obd->u.lmv;
203 struct obd_export *exp;
207 rc = class_connect(conn, obd, cluuid);
209 CERROR("class_connection() returned %d\n", rc);
213 exp = class_conn2export(conn);
215 /* we don't want to actually do the underlying connections more than
216 * once, so keep track. */
218 if (lmv->refcount > 1) {
219 class_export_put(exp);
225 lmv->cluuid = *cluuid;
226 lmv->connect_flags = flags;
227 sema_init(&lmv->init_sem, 1);
229 memcpy(&lmv->conn_data, data, sizeof(*data));
232 lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
234 if (IS_ERR(lmv_proc_dir)) {
235 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
236 obd->obd_type->typ_name, obd->obd_name);
242 * all real clients shouls perform actual connection rightaway, because
243 * it is possible, that LMV will not have opportunity to connect
244 * targets, as MDC stuff will bit called directly, for instance while
245 * reading ../mdc/../kbytesfree procfs file, etc.
247 if (flags & OBD_OPT_REAL_CLIENT)
248 rc = lmv_check_connect(obd);
253 lprocfs_remove(lmv_proc_dir);
260 static void lmv_set_timeouts(struct obd_device *obd)
262 struct lmv_tgt_desc *tgts;
267 if (lmv->server_timeout == 0)
270 if (lmv->connected == 0)
273 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) {
274 if (tgts->ltd_exp == NULL)
277 obd_set_info(tgts->ltd_exp, strlen("inter_mds"),
278 "inter_mds", 0, NULL);
282 #define MAX_STRING_SIZE 128
284 /* performs a check if passed obd is connected. If no - connect it. */
285 int lmv_check_connect(struct obd_device *obd)
288 struct proc_dir_entry *lmv_proc_dir;
290 struct lmv_obd *lmv = &obd->u.lmv;
291 struct lmv_tgt_desc *tgts;
292 struct obd_uuid *cluuid;
293 struct obd_export *exp;
300 down(&lmv->init_sem);
301 if (lmv->connected) {
306 cluuid = &lmv->cluuid;
309 CDEBUG(D_OTHER, "time to connect %s to %s\n",
310 cluuid->uuid, obd->obd_name);
312 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) {
313 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
314 struct lustre_handle conn = {0, };
315 struct obd_device *tgt_obd;
317 LASSERT(tgts != NULL);
319 tgt_obd = class_find_client_obd(&tgts->uuid, OBD_MDC_DEVICENAME,
322 CERROR("target %s not attached\n", tgts->uuid.uuid);
323 GOTO(out_disc, rc = -EINVAL);
326 /* for MDS: don't connect to yourself */
327 if (obd_uuid_equals(&tgts->uuid, cluuid)) {
328 CDEBUG(D_OTHER, "don't connect back to %s\n",
330 tgts->ltd_exp = NULL;
334 CDEBUG(D_OTHER, "connect to %s(%s) - %s, %s FOR %s\n",
335 tgt_obd->obd_name, tgt_obd->obd_uuid.uuid,
336 tgts->uuid.uuid, obd->obd_uuid.uuid,
339 if (!tgt_obd->obd_set_up) {
340 CERROR("target %s not set up\n", tgts->uuid.uuid);
341 GOTO(out_disc, rc = -EINVAL);
344 rc = obd_connect(&conn, tgt_obd, &lmv_mdc_uuid, &lmv->conn_data,
347 CERROR("target %s connect error %d\n",
348 tgts->uuid.uuid, rc);
351 tgts->ltd_exp = class_conn2export(&conn);
353 obd_init_ea_size(tgts->ltd_exp, lmv->max_easize,
354 lmv->max_cookiesize);
356 rc = obd_register_observer(tgt_obd, obd);
358 CERROR("target %s register_observer error %d\n",
359 tgts->uuid.uuid, rc);
360 obd_disconnect(tgts->ltd_exp, 0);
364 lmv->desc.ld_active_tgt_count++;
367 CDEBUG(D_OTHER, "connected to %s(%s) successfully (%d)\n",
368 tgt_obd->obd_name, tgt_obd->obd_uuid.uuid,
369 atomic_read(&obd->obd_refcount));
372 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
374 struct obd_device *mdc_obd = class_conn2obd(&conn);
375 struct proc_dir_entry *mdc_symlink;
376 char name[MAX_STRING_SIZE + 1];
378 LASSERT(mdc_obd != NULL);
379 LASSERT(mdc_obd->obd_type != NULL);
380 LASSERT(mdc_obd->obd_type->typ_name != NULL);
381 name[MAX_STRING_SIZE] = '\0';
382 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
383 mdc_obd->obd_type->typ_name,
385 mdc_symlink = proc_symlink(mdc_obd->obd_name,
387 if (mdc_symlink == NULL) {
388 CERROR("could not register LMV target "
389 "/proc/fs/lustre/%s/%s/target_obds/%s.",
390 obd->obd_type->typ_name, obd->obd_name,
392 lprocfs_remove(lmv_proc_dir);
399 lmv_set_timeouts(obd);
400 class_export_put(exp);
407 struct obd_uuid uuid;
409 --lmv->desc.ld_active_tgt_count;
411 /* save for CERROR below; (we know it's terminated) */
413 rc2 = obd_disconnect(tgts->ltd_exp, 0);
415 CERROR("error: LMV target %s disconnect on MDC idx %d: "
416 "error %d\n", uuid.uuid, i, rc2);
418 class_disconnect(exp, 0);
423 static int lmv_disconnect(struct obd_export *exp, unsigned long flags)
425 struct obd_device *obd = class_exp2obd(exp);
426 struct lmv_obd *lmv = &obd->u.lmv;
429 struct proc_dir_entry *lmv_proc_dir;
437 /* Only disconnect the underlying layers on the final disconnect. */
439 if (lmv->refcount != 0)
443 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
446 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
447 struct obd_device *mdc_obd;
449 if (lmv->tgts[i].ltd_exp == NULL)
452 mdc_obd = class_exp2obd(lmv->tgts[i].ltd_exp);
455 mdc_obd->obd_no_recov = obd->obd_no_recov;
459 struct proc_dir_entry *mdc_symlink;
461 mdc_symlink = lprocfs_srch(lmv_proc_dir, mdc_obd->obd_name);
463 lprocfs_remove(mdc_symlink);
465 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing\n",
466 obd->obd_type->typ_name, obd->obd_name,
471 CDEBUG(D_OTHER, "disconnected from %s(%s) successfully\n",
472 lmv->tgts[i].ltd_exp->exp_obd->obd_name,
473 lmv->tgts[i].ltd_exp->exp_obd->obd_uuid.uuid);
475 obd_register_observer(lmv->tgts[i].ltd_exp->exp_obd, NULL);
476 rc = obd_disconnect(lmv->tgts[i].ltd_exp, flags);
478 if (lmv->tgts[i].active) {
479 CERROR("Target %s disconnect error %d\n",
480 lmv->tgts[i].uuid.uuid, rc);
485 lmv_activate_target(lmv, &lmv->tgts[i], 0);
486 lmv->tgts[i].ltd_exp = NULL;
491 lprocfs_remove(lmv_proc_dir);
493 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
494 obd->obd_type->typ_name, obd->obd_name);
499 /* this is the case when no real connection is established by
500 * lmv_check_connect(). */
502 class_export_put(exp);
503 rc = class_disconnect(exp, 0);
504 if (lmv->refcount == 0)
509 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
510 int len, void *karg, void *uarg)
512 struct obd_device *obddev = class_exp2obd(exp);
513 struct lmv_obd *lmv = &obddev->u.lmv;
514 int i, rc = 0, set = 0;
517 if (lmv->desc.ld_tgt_count == 0)
520 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
523 if (lmv->tgts[i].ltd_exp == NULL)
526 err = obd_iocontrol(cmd, lmv->tgts[i].ltd_exp, len, karg, uarg);
528 if (lmv->tgts[i].active) {
529 CERROR("error: iocontrol MDC %s on MDT"
530 "idx %d: err = %d\n",
531 lmv->tgts[i].uuid.uuid, i, err);
544 static int lmv_setup(struct obd_device *obd, obd_count len, void *buf)
547 struct lmv_desc *desc;
548 struct obd_uuid *uuids;
549 struct lmv_tgt_desc *tgts;
550 struct obd_device *tgt_obd;
551 struct lustre_cfg *lcfg = buf;
552 struct lmv_obd *lmv = &obd->u.lmv;
555 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
556 CERROR("LMV setup requires a descriptor\n");
560 if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) {
561 CERROR("LMV setup requires an MDT UUID list\n");
565 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
566 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
567 CERROR("descriptor size wrong: %d > %d\n",
568 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
572 uuids = (struct obd_uuid *)lustre_cfg_buf(lcfg, 2);
573 if (sizeof(*uuids) * desc->ld_tgt_count != LUSTRE_CFG_BUFLEN(lcfg, 2)) {
574 CERROR("UUID array size wrong: %u * %u != %u\n",
575 sizeof(*uuids), desc->ld_tgt_count, LUSTRE_CFG_BUFLEN(lcfg, 2));
579 lmv->tgts_size = sizeof(struct lmv_tgt_desc) * desc->ld_tgt_count;
580 OBD_ALLOC(lmv->tgts, lmv->tgts_size);
581 if (lmv->tgts == NULL) {
582 CERROR("Out of memory\n");
587 spin_lock_init(&lmv->lmv_lock);
589 for (i = 0, tgts = lmv->tgts; i < desc->ld_tgt_count; i++, tgts++)
590 tgts->uuid = uuids[i];
592 lmv->max_cookiesize = 0;
594 lmv->max_easize = sizeof(struct lustre_id) *
595 desc->ld_tgt_count + sizeof(struct mea);
597 rc = lmv_setup_mgr(obd);
599 CERROR("Can't setup LMV object manager, "
601 OBD_FREE(lmv->tgts, lmv->tgts_size);
604 tgt_obd = class_find_client_obd(&lmv->tgts->uuid, OBD_MDC_DEVICENAME,
607 CERROR("Target %s not attached\n", lmv->tgts->uuid.uuid);
614 static int lmv_cleanup(struct obd_device *obd, int flags)
616 struct lmv_obd *lmv = &obd->u.lmv;
619 lmv_cleanup_mgr(obd);
620 OBD_FREE(lmv->tgts, lmv->tgts_size);
625 static int lmv_statfs(struct obd_device *obd, struct obd_statfs *osfs,
626 unsigned long max_age)
628 struct lmv_obd *lmv = &obd->u.lmv;
629 struct obd_statfs *temp;
633 rc = lmv_check_connect(obd);
637 OBD_ALLOC(temp, sizeof(*temp));
641 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
642 if (lmv->tgts[i].ltd_exp == NULL)
645 rc = obd_statfs(lmv->tgts[i].ltd_exp->exp_obd, temp, max_age);
647 CERROR("can't stat MDS #%d (%s), error %d\n", i,
648 lmv->tgts[i].ltd_exp->exp_obd->obd_name,
650 GOTO(out_free_temp, rc);
653 memcpy(osfs, temp, sizeof(*temp));
655 osfs->os_bavail += temp->os_bavail;
656 osfs->os_blocks += temp->os_blocks;
657 osfs->os_ffree += temp->os_ffree;
658 osfs->os_files += temp->os_files;
664 OBD_FREE(temp, sizeof(*temp));
668 static int lmv_getstatus(struct obd_export *exp, struct lustre_id *id)
670 struct obd_device *obd = exp->exp_obd;
671 struct lmv_obd *lmv = &obd->u.lmv;
675 rc = lmv_check_connect(obd);
679 rc = md_getstatus(lmv->tgts[0].ltd_exp, id);
685 static int lmv_getattr(struct obd_export *exp, struct lustre_id *id,
686 __u64 valid, const char *ea_name, int ea_namelen,
687 unsigned int ea_size, struct ptlrpc_request **request)
689 struct obd_device *obd = exp->exp_obd;
690 struct lmv_obd *lmv = &obd->u.lmv;
691 int rc, i = id_group(id);
695 rc = lmv_check_connect(obd);
699 LASSERT(i < lmv->desc.ld_tgt_count);
702 rc = md_getattr(lmv->tgts[i].ltd_exp, id, valid,
703 ea_name, ea_namelen, ea_size, request);
707 obj = lmv_grab_obj(obd, id);
709 CDEBUG(D_OTHER, "GETATTR for "DLID4" %s\n",
710 OLID4(id), obj ? "(splitted)" : "");
713 * if object is splitted, then we loop over all the slaves and gather
714 * size attribute. In ideal world we would have to gather also mds field
715 * from all slaves, as object is spread over the cluster and this is
716 * definitely interesting information and it is not good to loss it,
720 struct mds_body *body;
722 if (*request == NULL) {
727 body = lustre_msg_buf((*request)->rq_repmsg, 0,
729 LASSERT(body != NULL);
733 for (i = 0; i < obj->objcount; i++) {
735 if (lmv->tgts[i].ltd_exp == NULL) {
736 CWARN("%s: NULL export for %d\n",
741 /* skip master obj. */
742 if (id_equal_fid(&obj->id, &obj->objs[i].id))
745 body->size += obj->objs[i].size;
755 static int lmv_access_check(struct obd_export *exp,
756 struct lustre_id *id,
757 struct ptlrpc_request **request)
759 struct obd_device *obd = exp->exp_obd;
760 struct lmv_obd *lmv = &obd->u.lmv;
761 int rc, i = id_group(id);
764 rc = lmv_check_connect(obd);
768 LASSERT(i < lmv->desc.ld_tgt_count);
769 rc = md_access_check(lmv->tgts[i].ltd_exp, id, request);
773 static int lmv_change_cbdata(struct obd_export *exp,
774 struct lustre_id *id,
778 struct obd_device *obd = exp->exp_obd;
779 struct lmv_obd *lmv = &obd->u.lmv;
783 rc = lmv_check_connect(obd);
787 CDEBUG(D_OTHER, "CBDATA for "DLID4"\n", OLID4(id));
788 LASSERT(id_group(id) < lmv->desc.ld_tgt_count);
790 rc = md_change_cbdata(lmv->tgts[id_group(id)].ltd_exp,
796 static int lmv_change_cbdata_name(struct obd_export *exp,
797 struct lustre_id *pid,
799 struct lustre_id *cid,
803 struct obd_device *obd = exp->exp_obd;
804 struct lmv_obd *lmv = &obd->u.lmv;
805 struct lustre_id rcid = *cid;
810 rc = lmv_check_connect(obd);
814 LASSERT(id_group(pid) < lmv->desc.ld_tgt_count);
815 LASSERT(id_group(cid) < lmv->desc.ld_tgt_count);
817 CDEBUG(D_OTHER, "CBDATA for "DLID4":%*s -> "DLID4"\n",
818 OLID4(pid), len, name, OLID4(cid));
820 /* this is default mds for directory name belongs to. */
822 obj = lmv_grab_obj(obd, pid);
824 /* directory is splitted. look for right mds for this name. */
825 mds = raw_name2idx(obj->hashtype, obj->objcount, name, len);
826 rcid = obj->objs[mds].id;
827 mds = id_group(&rcid);
830 rc = md_change_cbdata(lmv->tgts[mds].ltd_exp, &rcid, it, data);
834 static int lmv_valid_attrs(struct obd_export *exp, struct lustre_id *id)
836 struct obd_device *obd = exp->exp_obd;
837 struct lmv_obd *lmv = &obd->u.lmv;
841 rc = lmv_check_connect(obd);
845 CDEBUG(D_OTHER, "validate "DLID4"\n", OLID4(id));
846 LASSERT(id_group(id) < lmv->desc.ld_tgt_count);
847 rc = md_valid_attrs(lmv->tgts[id_group(id)].ltd_exp, id);
851 static int lmv_close(struct obd_export *exp, struct obdo *obdo,
852 struct obd_client_handle *och,
853 struct ptlrpc_request **request)
855 struct obd_device *obd = exp->exp_obd;
856 struct lmv_obd *lmv = &obd->u.lmv;
857 int rc, i = obdo->o_mds;
860 rc = lmv_check_connect(obd);
864 LASSERT(i < lmv->desc.ld_tgt_count);
865 CDEBUG(D_OTHER, "CLOSE %lu/%lu/%lu\n", (unsigned long)obdo->o_mds,
866 (unsigned long)obdo->o_id, (unsigned long)obdo->o_generation);
867 rc = md_close(lmv->tgts[i].ltd_exp, obdo, och, request);
871 int lmv_get_mea_and_update_object(struct obd_export *exp,
872 struct lustre_id *id)
874 struct obd_device *obd = exp->exp_obd;
875 struct lmv_obd *lmv = &obd->u.lmv;
876 struct ptlrpc_request *req = NULL;
884 mealen = MEA_SIZE_LMV(lmv);
886 valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA | OBD_MD_MEA;
888 /* time to update mea of parent id */
889 rc = md_getattr(lmv->tgts[id_group(id)].ltd_exp,
890 id, valid, NULL, 0, mealen, &req);
892 CERROR("md_getattr() failed, error %d\n", rc);
896 rc = mdc_req2lustre_md(exp, req, 0, NULL, &md);
898 CERROR("mdc_req2lustre_md() failed, error %d\n", rc);
903 GOTO(cleanup, rc = -ENODATA);
905 obj = lmv_create_obj(exp, id, md.mea);
911 obd_free_memmd(exp, (struct lov_stripe_md **)&md.mea);
916 ptlrpc_req_finished(req);
920 int lmv_create(struct obd_export *exp, struct mdc_op_data *op_data,
921 const void *data, int datalen, int mode, __u32 uid,
922 __u32 gid, __u64 rdev, struct ptlrpc_request **request)
924 struct obd_device *obd = exp->exp_obd;
925 struct lmv_obd *lmv = &obd->u.lmv;
926 struct mds_body *body;
928 int rc, mds, loop = 0;
931 rc = lmv_check_connect(obd);
935 if (!lmv->desc.ld_active_tgt_count)
938 LASSERT(++loop <= 2);
939 obj = lmv_grab_obj(obd, &op_data->id1);
941 mds = raw_name2idx(obj->hashtype, obj->objcount,
942 op_data->name, op_data->namelen);
943 op_data->id1 = obj->objs[mds].id;
947 CDEBUG(D_OTHER, "CREATE '%*s' on "DLID4"\n", op_data->namelen,
948 op_data->name, OLID4(&op_data->id1));
950 rc = md_create(lmv->tgts[id_group(&op_data->id1)].ltd_exp,
951 op_data, data, datalen, mode, uid, gid, rdev,
954 if (*request == NULL)
957 body = lustre_msg_buf((*request)->rq_repmsg, 0,
962 CDEBUG(D_OTHER, "created. "DLID4"\n", OLID4(&op_data->id1));
963 } else if (rc == -ERESTART) {
965 * directory got splitted. time to update local object and
966 * repeat the request with proper MDS.
968 rc = lmv_get_mea_and_update_object(exp, &op_data->id1);
970 ptlrpc_req_finished(*request);
977 static int lmv_done_writing(struct obd_export *exp, struct obdo *obdo)
979 struct obd_device *obd = exp->exp_obd;
980 struct lmv_obd *lmv = &obd->u.lmv;
984 rc = lmv_check_connect(obd);
988 /* FIXME: choose right MDC here */
989 CWARN("this method isn't implemented yet\n");
990 rc = md_done_writing(lmv->tgts[0].ltd_exp, obdo);
995 lmv_enqueue_slaves(struct obd_export *exp, int locktype,
996 struct lookup_intent *it, int lockmode,
997 struct mdc_op_data *data, struct lustre_handle *lockh,
998 void *lmm, int lmmsize, ldlm_completion_callback cb_compl,
999 ldlm_blocking_callback cb_blocking, void *cb_data)
1001 struct obd_device *obd = exp->exp_obd;
1002 struct lmv_obd *lmv = &obd->u.lmv;
1003 struct mea *mea = data->mea1;
1004 struct mdc_op_data *data2;
1008 OBD_ALLOC(data2, sizeof(*data2));
1012 LASSERT(mea != NULL);
1013 for (i = 0; i < mea->mea_count; i++) {
1014 memset(data2, 0, sizeof(*data2));
1015 data2->id1 = mea->mea_ids[i];
1016 mds = id_group(&data2->id1);
1018 if (lmv->tgts[mds].ltd_exp == NULL)
1021 rc = md_enqueue(lmv->tgts[mds].ltd_exp, locktype, it,
1022 lockmode, data2, lockh + i, lmm, lmmsize,
1023 cb_compl, cb_blocking, cb_data);
1025 CDEBUG(D_OTHER, "take lock on slave "DLID4" -> %d/%d\n",
1026 OLID4(&mea->mea_ids[i]), rc, LUSTRE_IT(it)->it_status);
1029 if (LUSTRE_IT(it)->it_data) {
1030 struct ptlrpc_request *req;
1031 req = (struct ptlrpc_request *) LUSTRE_IT(it)->it_data;
1032 ptlrpc_req_finished(req);
1035 if (LUSTRE_IT(it)->it_status)
1036 GOTO(cleanup, rc = LUSTRE_IT(it)->it_status);
1039 OBD_FREE(data2, sizeof(*data2));
1042 OBD_FREE(data2, sizeof(*data2));
1044 /* drop all taken locks */
1046 if (lockh[i].cookie)
1047 ldlm_lock_decref(lockh + i, lockmode);
1048 lockh[i].cookie = 0;
1054 lmv_enqueue_remote(struct obd_export *exp, int lock_type,
1055 struct lookup_intent *it, int lock_mode,
1056 struct mdc_op_data *data, struct lustre_handle *lockh,
1057 void *lmm, int lmmsize, ldlm_completion_callback cb_compl,
1058 ldlm_blocking_callback cb_blocking, void *cb_data)
1060 struct ptlrpc_request *req = LUSTRE_IT(it)->it_data;
1061 struct obd_device *obd = exp->exp_obd;
1062 struct lmv_obd *lmv = &obd->u.lmv;
1063 struct lustre_handle plock;
1064 struct mdc_op_data rdata;
1065 struct mds_body *body = NULL;
1069 body = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*body));
1070 LASSERT(body != NULL);
1072 if (!(body->valid & OBD_MD_MDS))
1075 CDEBUG(D_OTHER, "ENQUEUE '%s' on "DLID4" -> "DLID4"\n",
1076 LL_IT2STR(it), OLID4(&data->id1), OLID4(&body->id1));
1078 /* we got LOOKUP lock, but we really need attrs */
1079 pmode = LUSTRE_IT(it)->it_lock_mode;
1080 LASSERT(pmode != 0);
1081 memcpy(&plock, lockh, sizeof(plock));
1082 LUSTRE_IT(it)->it_lock_mode = 0;
1083 LUSTRE_IT(it)->it_data = NULL;
1084 LASSERT((body->valid & OBD_MD_FID) != 0);
1086 memcpy(&rdata, data, sizeof(rdata));
1087 rdata.id1 = body->id1;
1091 LUSTRE_IT(it)->it_disposition &= ~DISP_ENQ_COMPLETE;
1092 ptlrpc_req_finished(req);
1094 rc = md_enqueue(lmv->tgts[id_group(&rdata.id1)].ltd_exp,
1095 lock_type, it, lock_mode, &rdata, lockh, lmm,
1096 lmmsize, cb_compl, cb_blocking, cb_data);
1097 ldlm_lock_decref(&plock, pmode);
1102 lmv_enqueue(struct obd_export *exp, int lock_type,
1103 struct lookup_intent *it, int lock_mode,
1104 struct mdc_op_data *data, struct lustre_handle *lockh,
1105 void *lmm, int lmmsize, ldlm_completion_callback cb_compl,
1106 ldlm_blocking_callback cb_blocking, void *cb_data)
1108 struct obd_device *obd = exp->exp_obd;
1109 struct lmv_obd *lmv = &obd->u.lmv;
1110 struct lmv_obj *obj;
1114 rc = lmv_check_connect(obd);
1118 if (data->mea1 && it->it_op == IT_UNLINK) {
1119 rc = lmv_enqueue_slaves(exp, lock_type, it, lock_mode,
1120 data, lockh, lmm, lmmsize,
1121 cb_compl, cb_blocking, cb_data);
1125 if (data->namelen) {
1126 obj = lmv_grab_obj(obd, &data->id1);
1128 /* directory is splitted. look for right mds for this
1130 mds = raw_name2idx(obj->hashtype, obj->objcount,
1131 (char *)data->name, data->namelen);
1132 data->id1 = obj->objs[mds].id;
1136 CDEBUG(D_OTHER, "ENQUEUE '%s' on "DLID4"\n", LL_IT2STR(it),
1139 rc = md_enqueue(lmv->tgts[id_group(&data->id1)].ltd_exp,
1140 lock_type, it, lock_mode, data, lockh, lmm,
1141 lmmsize, cb_compl, cb_blocking, cb_data);
1142 if (rc == 0 && it->it_op == IT_OPEN)
1143 rc = lmv_enqueue_remote(exp, lock_type, it, lock_mode,
1144 data, lockh, lmm, lmmsize,
1145 cb_compl, cb_blocking, cb_data);
1150 lmv_getattr_lock(struct obd_export *exp, struct lustre_id *id,
1151 char *filename, int namelen, __u64 valid,
1152 unsigned int ea_size, struct ptlrpc_request **request)
1154 int rc, mds = id_group(id), loop = 0;
1155 struct obd_device *obd = exp->exp_obd;
1156 struct lmv_obd *lmv = &obd->u.lmv;
1157 struct lustre_id rid = *id;
1158 struct mds_body *body;
1159 struct lmv_obj *obj;
1162 rc = lmv_check_connect(obd);
1166 LASSERT(++loop <= 2);
1167 obj = lmv_grab_obj(obd, id);
1169 /* directory is splitted. look for right mds for this name */
1170 mds = raw_name2idx(obj->hashtype, obj->objcount,
1171 filename, namelen - 1);
1172 rid = obj->objs[mds].id;
1176 CDEBUG(D_OTHER, "getattr_lock for %*s on "DLID4" -> "DLID4"\n",
1177 namelen, filename, OLID4(id), OLID4(&rid));
1179 rc = md_getattr_lock(lmv->tgts[id_group(&rid)].ltd_exp,
1180 &rid, filename, namelen,
1181 valid == OBD_MD_FLID ? valid : valid | OBD_MD_FID,
1185 * this could be cross-node reference. in this case all we have
1186 * right now is lustre_id triple. we'd like to find other
1189 body = lustre_msg_buf((*request)->rq_repmsg, 0, sizeof(*body));
1190 LASSERT(body != NULL);
1191 LASSERT((body->valid & OBD_MD_FID) != 0
1192 || body->valid == OBD_MD_FLID);
1194 if (body->valid & OBD_MD_MDS) {
1195 struct ptlrpc_request *req = NULL;
1198 CDEBUG(D_OTHER, "request attrs for "DLID4"\n", OLID4(&rid));
1200 rc = md_getattr_lock(lmv->tgts[id_group(&rid)].ltd_exp,
1201 &rid, NULL, 1, valid, ea_size, &req);
1202 ptlrpc_req_finished(*request);
1205 } else if (rc == -ERESTART) {
1206 /* directory got splitted. time to update local object and
1207 * repeat the request with proper MDS */
1208 rc = lmv_get_mea_and_update_object(exp, &rid);
1210 ptlrpc_req_finished(*request);
1218 * llite passes id of an target inode in data->id1 and id of directory in
1221 static int lmv_link(struct obd_export *exp, struct mdc_op_data *data,
1222 struct ptlrpc_request **request)
1224 struct obd_device *obd = exp->exp_obd;
1225 struct lmv_obd *lmv = &obd->u.lmv;
1226 struct lmv_obj *obj;
1230 rc = lmv_check_connect(obd);
1234 if (data->namelen != 0) {
1235 /* usual link request */
1236 obj = lmv_grab_obj(obd, &data->id2);
1238 rc = raw_name2idx(obj->hashtype, obj->objcount,
1239 data->name, data->namelen);
1240 data->id2 = obj->objs[rc].id;
1244 mds = id_group(&data->id2);
1246 CDEBUG(D_OTHER,"link "DLID4":%*s to "DLID4"\n",
1247 OLID4(&data->id2), data->namelen, data->name,
1250 mds = id_group(&data->id1);
1252 /* request from MDS to acquire i_links for inode by id1 */
1253 CDEBUG(D_OTHER, "inc i_nlinks for "DLID4"\n",
1257 CDEBUG(D_OTHER, "forward to MDS #%u ("DLID4")\n",
1258 mds, OLID4(&data->id1));
1259 rc = md_link(lmv->tgts[mds].ltd_exp, data, request);
1264 static int lmv_rename(struct obd_export *exp, struct mdc_op_data *data,
1265 const char *old, int oldlen, const char *new, int newlen,
1266 struct ptlrpc_request **request)
1268 struct obd_device *obd = exp->exp_obd;
1269 struct lmv_obd *lmv = &obd->u.lmv;
1270 struct lmv_obj *obj;
1274 CDEBUG(D_OTHER, "rename %*s in "DLID4" to %*s in "DLID4"\n",
1275 oldlen, old, OLID4(&data->id1), newlen, new,
1278 rc = lmv_check_connect(obd);
1284 * MDS with old dir entry is asking another MDS to create name
1288 "create %*s(%d/%d) in "DLID4" pointing "
1289 "to "DLID4"\n", newlen, new, oldlen, newlen,
1290 OLID4(&data->id2), OLID4(&data->id1));
1292 mds = id_group(&data->id2);
1295 * target directory can be splitted, sowe should forward request
1298 obj = lmv_grab_obj(obd, &data->id2);
1300 mds = raw_name2idx(obj->hashtype, obj->objcount,
1301 (char *)new, newlen);
1302 data->id2 = obj->objs[mds].id;
1303 CDEBUG(D_OTHER, "forward to MDS #%u ("DLID4")\n", mds,
1310 obj = lmv_grab_obj(obd, &data->id1);
1313 * directory is already splitted, so we have to forward request
1316 mds = raw_name2idx(obj->hashtype, obj->objcount,
1317 (char *)old, oldlen);
1318 data->id1 = obj->objs[mds].id;
1319 CDEBUG(D_OTHER, "forward to MDS #%u ("DLID4")\n", mds,
1324 obj = lmv_grab_obj(obd, &data->id2);
1327 * directory is already splitted, so we have to forward request
1330 mds = raw_name2idx(obj->hashtype, obj->objcount,
1331 (char *)new, newlen);
1333 data->id2 = obj->objs[mds].id;
1334 CDEBUG(D_OTHER, "forward to MDS #%u ("DLID4")\n", mds,
1339 mds = id_group(&data->id1);
1342 if (id_group(&data->id1) != id_group(&data->id2)) {
1343 CDEBUG(D_OTHER,"cross-node rename "DLID4"/%*s to "DLID4"/%*s\n",
1344 OLID4(&data->id1), oldlen, old, OLID4(&data->id2),
1348 rc = md_rename(lmv->tgts[mds].ltd_exp, data, old, oldlen,
1349 new, newlen, request);
1353 static int lmv_setattr(struct obd_export *exp, struct mdc_op_data *data,
1354 struct iattr *iattr, void *ea, int ealen, void *ea2,
1355 int ea2len, struct ptlrpc_request **request)
1357 struct obd_device *obd = exp->exp_obd;
1358 struct lmv_obd *lmv = &obd->u.lmv;
1359 struct ptlrpc_request *req;
1360 struct mds_body *body;
1361 struct lmv_obj *obj;
1365 rc = lmv_check_connect(obd);
1369 obj = lmv_grab_obj(obd, &data->id1);
1371 CDEBUG(D_OTHER, "SETATTR for "DLID4", valid 0x%x%s\n",
1372 OLID4(&data->id1), iattr->ia_valid, obj ? ", splitted" : "");
1375 for (i = 0; i < obj->objcount; i++) {
1376 data->id1 = obj->objs[i].id;
1378 rc = md_setattr(lmv->tgts[id_group(&data->id1)].ltd_exp,
1379 data, iattr, ea, ealen, ea2, ea2len, &req);
1381 if (id_equal_fid(&obj->id, &obj->objs[i].id)) {
1383 * this is master object and this request should
1384 * be returned back to llite.
1388 ptlrpc_req_finished(req);
1396 LASSERT(id_group(&data->id1) < lmv->desc.ld_tgt_count);
1397 rc = md_setattr(lmv->tgts[id_group(&data->id1)].ltd_exp,
1398 data, iattr, ea, ealen, ea2, ea2len, request);
1400 body = lustre_msg_buf((*request)->rq_repmsg, 0,
1402 LASSERT(body != NULL);
1403 LASSERT((body->valid & OBD_MD_FID) != 0);
1404 LASSERT(id_group(&body->id1) == id_group(&data->id1));
1410 static int lmv_sync(struct obd_export *exp, struct lustre_id *id,
1411 struct ptlrpc_request **request)
1413 struct obd_device *obd = exp->exp_obd;
1414 struct lmv_obd *lmv = &obd->u.lmv;
1418 rc = lmv_check_connect(obd);
1422 rc = md_sync(lmv->tgts[id_group(id)].ltd_exp,
1427 int lmv_dirobj_blocking_ast(struct ldlm_lock *lock,
1428 struct ldlm_lock_desc *desc,
1429 void *data, int flag)
1431 struct lustre_handle lockh;
1432 struct lmv_obj *obj;
1437 case LDLM_CB_BLOCKING:
1438 ldlm_lock2handle(lock, &lockh);
1439 rc = ldlm_cli_cancel(&lockh);
1441 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
1445 case LDLM_CB_CANCELING:
1446 /* time to drop cached attrs for dirobj */
1447 obj = lock->l_ast_data;
1449 CDEBUG(D_OTHER, "cancel %s on "LPU64"/"LPU64
1450 ", master "DLID4"\n",
1451 lock->l_resource->lr_name.name[3] == 1 ?
1452 "LOOKUP" : "UPDATE",
1453 lock->l_resource->lr_name.name[0],
1454 lock->l_resource->lr_name.name[1],
1465 static void lmv_remove_dots(struct page *page)
1467 unsigned limit = PAGE_CACHE_SIZE;
1468 char *kaddr = page_address(page);
1469 struct ext2_dir_entry_2 *p;
1470 unsigned offs, rec_len;
1472 for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
1473 p = (struct ext2_dir_entry_2 *)(kaddr + offs);
1474 rec_len = le16_to_cpu(p->rec_len);
1476 if ((p->name_len == 1 && p->name[0] == '.') ||
1477 (p->name_len == 2 && p->name[0] == '.' && p->name[1] == '.'))
1482 static int lmv_readpage(struct obd_export *exp, struct lustre_id *id,
1483 __u64 offset, struct page *page,
1484 struct ptlrpc_request **request)
1486 struct obd_device *obd = exp->exp_obd;
1487 struct lmv_obd *lmv = &obd->u.lmv;
1488 struct lustre_id rid = *id;
1489 struct lmv_obj *obj;
1493 #warning "we need well-desgined readdir() implementation"
1494 rc = lmv_check_connect(obd);
1498 LASSERT(id_group(id) < lmv->desc.ld_tgt_count);
1499 CDEBUG(D_OTHER, "READPAGE at %llu from "DLID4"\n",
1500 offset, OLID4(&rid));
1502 obj = lmv_grab_obj(obd, id);
1506 /* find dirobj containing page with requested offset. */
1507 for (i = 0; i < obj->objcount; i++) {
1508 if (offset < obj->objs[i].size)
1510 offset -= obj->objs[i].size;
1512 rid = obj->objs[i].id;
1514 lmv_unlock_obj(obj);
1517 CDEBUG(D_OTHER, "forward to "DLID4" with offset %lu\n",
1518 OLID4(&rid), (unsigned long)offset);
1520 rc = md_readpage(lmv->tgts[id_group(&rid)].ltd_exp, &rid,
1521 offset, page, request);
1523 if (rc == 0 && !id_equal_fid(&rid, id))
1524 /* this page isn't from master object. To avoid "." and ".."
1525 * duplication in directory, we have to remove them from all
1527 lmv_remove_dots(page);
1532 static int lmv_unlink_slaves(struct obd_export *exp, struct mdc_op_data *data,
1533 struct ptlrpc_request **req)
1535 struct obd_device *obd = exp->exp_obd;
1536 struct lmv_obd *lmv = &obd->u.lmv;
1537 struct mea *mea = data->mea1;
1538 struct mdc_op_data *data2;
1542 OBD_ALLOC(data2, sizeof(*data2));
1546 LASSERT(mea != NULL);
1547 for (i = 0; i < mea->mea_count; i++) {
1548 memset(data2, 0, sizeof(*data2));
1549 data2->id1 = mea->mea_ids[i];
1550 data2->create_mode = MDS_MODE_DONT_LOCK | S_IFDIR;
1552 if (lmv->tgts[id_group(&data2->id1)].ltd_exp == NULL)
1555 rc = md_unlink(lmv->tgts[id_group(&data2->id1)].ltd_exp,
1558 CDEBUG(D_OTHER, "unlink slave "DLID4" -> %d\n",
1559 OLID4(&mea->mea_ids[i]), rc);
1562 ptlrpc_req_finished(*req);
1568 OBD_FREE(data2, sizeof(*data2));
1572 static int lmv_delete_inode(struct obd_export *exp, struct lustre_id *id)
1577 if (lmv_delete_obj(exp, id)) {
1578 CDEBUG(D_OTHER, "lmv object "DLID4" is destroyed.\n",
1584 static int lmv_unlink(struct obd_export *exp, struct mdc_op_data *data,
1585 struct ptlrpc_request **request)
1587 struct obd_device *obd = exp->exp_obd;
1588 struct lmv_obd *lmv = &obd->u.lmv;
1592 rc = lmv_check_connect(obd);
1596 if (data->namelen == 0 && data->mea1 != NULL) {
1597 /* mds asks to remove slave objects */
1598 rc = lmv_unlink_slaves(exp, data, request);
1602 if (data->namelen != 0) {
1603 struct lmv_obj *obj;
1605 obj = lmv_grab_obj(obd, &data->id1);
1607 i = raw_name2idx(obj->hashtype, obj->objcount,
1608 data->name, data->namelen);
1609 data->id1 = obj->objs[i].id;
1612 CDEBUG(D_OTHER, "unlink '%*s' in "DLID4" -> %u\n",
1613 data->namelen, data->name, OLID4(&data->id1),
1616 CDEBUG(D_OTHER, "drop i_nlink on "DLID4"\n",
1619 rc = md_unlink(lmv->tgts[id_group(&data->id1)].ltd_exp,
1624 static struct obd_device *lmv_get_real_obd(struct obd_export *exp,
1625 struct lustre_id *id)
1627 struct obd_device *obd = exp->exp_obd;
1628 struct lmv_obd *lmv = &obd->u.lmv;
1632 rc = lmv_check_connect(obd);
1634 RETURN(ERR_PTR(rc));
1635 obd = lmv->tgts[id_group(id)].ltd_exp->exp_obd;
1641 static int lmv_init_ea_size(struct obd_export *exp, int easize,
1644 struct obd_device *obd = exp->exp_obd;
1645 struct lmv_obd *lmv = &obd->u.lmv;
1646 int i, rc = 0, change = 0;
1649 if (lmv->max_easize < easize) {
1650 lmv->max_easize = easize;
1653 if (lmv->max_cookiesize < cookiesize) {
1654 lmv->max_cookiesize = cookiesize;
1660 if (lmv->connected == 0)
1663 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1664 if (lmv->tgts[i].ltd_exp == NULL) {
1665 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
1669 rc = obd_init_ea_size(lmv->tgts[i].ltd_exp, easize, cookiesize);
1671 CERROR("obd_init_ea_size() failed on MDT target %d, "
1672 "error %d.\n", i, rc);
1679 static int lmv_obd_create_single(struct obd_export *exp, struct obdo *oa,
1680 void *acl, int acl_size,
1681 struct lov_stripe_md **ea,
1682 struct obd_trans_info *oti)
1684 struct obd_device *obd = exp->exp_obd;
1685 struct lmv_obd *lmv = &obd->u.lmv;
1686 struct lov_stripe_md obj_md;
1687 struct lov_stripe_md *obj_mdp = &obj_md;
1691 LASSERT(ea == NULL);
1692 LASSERT(oa->o_mds < lmv->desc.ld_tgt_count);
1694 rc = obd_create(lmv->tgts[oa->o_mds].ltd_exp, oa,
1695 acl, acl_size, &obj_mdp, oti);
1701 * to be called from MDS only. @oa should have correct store cookie and o_fid
1702 * values for "master" object, as it will be used.
1704 int lmv_obd_create(struct obd_export *exp, struct obdo *oa,
1705 void *acl, int acl_size,
1706 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1708 struct obd_device *obd = exp->exp_obd;
1709 struct lmv_obd *lmv = &obd->u.lmv;
1710 struct lustre_id mid;
1715 rc = lmv_check_connect(obd);
1719 LASSERT(oa != NULL);
1722 rc = lmv_obd_create_single(exp, oa, acl, acl_size, NULL, oti);
1724 CERROR("Can't create object, rc = %d\n", rc);
1728 /* acl is only suppied when mds create single remote obj */
1729 LASSERT(acl == NULL && acl_size == 0);
1732 rc = obd_alloc_diskmd(exp, (struct lov_mds_md **)ea);
1734 CERROR("obd_alloc_diskmd() failed, error %d\n",
1745 * here we should take care about splitted dir, so store cookie and fid
1746 * for "master" object should already be allocated and passed in @oa.
1748 LASSERT(oa->o_id != 0);
1749 LASSERT(oa->o_fid != 0);
1751 /* save "master" object id */
1754 mea = (struct mea *)*ea;
1755 mea->mea_master = -1;
1756 mea->mea_magic = MEA_MAGIC_ALL_CHARS;
1758 if (!mea->mea_count || mea->mea_count > lmv->desc.ld_tgt_count)
1759 mea->mea_count = lmv->desc.ld_tgt_count;
1761 for (i = 0, c = 0; c < mea->mea_count && i < lmv->desc.ld_tgt_count; i++) {
1762 struct lov_stripe_md obj_md;
1763 struct lov_stripe_md *obj_mdp = &obj_md;
1765 if (lmv->tgts[i].ltd_exp == NULL) {
1766 /* this is "master" MDS */
1767 mea->mea_master = i;
1768 mea->mea_ids[c] = mid;
1774 * "master" MDS should always be part of stripped dir,
1777 if (mea->mea_master == -1 && c == mea->mea_count - 1)
1780 oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLTYPE | OBD_MD_FLMODE |
1781 OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLID;
1783 rc = obd_create(lmv->tgts[c].ltd_exp, oa, NULL, 0,
1786 CERROR("obd_create() failed on MDT target %d, "
1787 "error %d\n", c, rc);
1791 CDEBUG(D_OTHER, "dirobj at mds %d: "LPU64"/%u\n",
1792 i, oa->o_id, oa->o_generation);
1796 * here, when object is created (or it is master and was passed
1797 * from caller) on desired MDS we save its fid to local mea_ids.
1802 * store cookie should be defined here for both cases (master
1803 * object and not master), because master is already created.
1807 /* fill mea by store cookie and fid */
1808 obdo2id(&mea->mea_ids[c], oa);
1811 LASSERT(c == mea->mea_count);
1813 CDEBUG(D_OTHER, "%d dirobjects created\n",
1814 (int)mea->mea_count);
1819 static int lmv_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
1820 struct obd_device *tgt, int count,
1821 struct llog_catid *logid)
1823 struct llog_ctxt *ctxt;
1827 rc = obd_llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1830 ctxt = llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT);
1831 ctxt->loc_imp = tgt->u.cli.cl_import;
1837 static int lmv_llog_finish(struct obd_device *obd,
1838 struct obd_llogs *llogs, int count)
1843 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT));
1847 static int lmv_get_info(struct obd_export *exp, __u32 keylen,
1848 void *key, __u32 *vallen, void *val)
1850 struct obd_device *obd;
1851 struct lmv_obd *lmv;
1855 obd = class_exp2obd(exp);
1857 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1858 exp->exp_handle.h_cookie);
1863 if (keylen == 6 && memcmp(key, "mdsize", 6) == 0) {
1864 __u32 *mdsize = val;
1865 *vallen = sizeof(__u32);
1866 *mdsize = sizeof(struct lustre_id) * lmv->desc.ld_tgt_count
1867 + sizeof(struct mea);
1869 } else if (keylen == 6 && memcmp(key, "mdsnum", 6) == 0) {
1870 struct obd_uuid *cluuid = &lmv->cluuid;
1871 struct lmv_tgt_desc *tgts;
1872 __u32 *mdsnum = val;
1875 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) {
1876 if (obd_uuid_equals(&tgts->uuid, cluuid)) {
1877 *vallen = sizeof(__u32);
1883 } else if (keylen == 6 && memcmp(key, "rootid", 6) == 0) {
1884 rc = lmv_check_connect(obd);
1888 /* getting rootid from first MDS. */
1889 rc = obd_get_info(lmv->tgts[0].ltd_exp, keylen, key,
1892 } else if (keylen >= strlen("lmvdesc") && strcmp(key, "lmvdesc") == 0) {
1893 struct lmv_desc *desc_ret = val;
1894 *desc_ret = lmv->desc;
1896 } else if (keylen == strlen("remote_flag") &&
1897 !strcmp(key, "remote_flag")) {
1898 struct lmv_tgt_desc *tgts;
1901 rc = lmv_check_connect(obd);
1905 LASSERT(*vallen == sizeof(__u32));
1906 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count;
1909 /* all tgts should be connected when this get called. */
1910 if (!tgts || !tgts->ltd_exp) {
1911 CERROR("target not setup?\n");
1915 if (!obd_get_info(tgts->ltd_exp, keylen, key,
1920 } else if (keylen >= strlen("lovdesc") && strcmp(key, "lovdesc") == 0) {
1921 rc = lmv_check_connect(obd);
1925 /* forwarding this request to first MDS, it should know LOV
1927 rc = obd_get_info(lmv->tgts[0].ltd_exp, keylen, key,
1932 CDEBUG(D_IOCTL, "invalid key\n");
1936 int lmv_set_info(struct obd_export *exp, obd_count keylen,
1937 void *key, obd_count vallen, void *val)
1939 struct lmv_tgt_desc *tgt;
1940 struct obd_device *obd;
1941 struct lmv_obd *lmv;
1944 obd = class_exp2obd(exp);
1946 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1947 exp->exp_handle.h_cookie);
1952 if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
1953 lmv->server_timeout = 1;
1954 lmv_set_timeouts(obd);
1958 /* maybe this could be default */
1959 if ((keylen == strlen("sec") && strcmp(key, "sec") == 0) ||
1960 (keylen == strlen("sec_flags") && strcmp(key, "sec_flags") == 0) ||
1961 (keylen == strlen("nllu") && strcmp(key, "nllu") == 0)) {
1962 struct obd_export *exp;
1965 spin_lock(&lmv->lmv_lock);
1966 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count;
1969 /* during setup time the connections to mdc might
1970 * haven't been established.
1973 struct obd_device *tgt_obd;
1975 tgt_obd = class_find_client_obd(&tgt->uuid,
1979 CERROR("can't set info %s, "
1980 "device %s not attached?\n",
1981 (char *) key, tgt->uuid.uuid);
1985 exp = tgt_obd->obd_self_export;
1988 err = obd_set_info(exp, keylen, key, vallen, val);
1992 spin_unlock(&lmv->lmv_lock);
1997 if ((keylen == strlen("flush_cred") &&
1998 strcmp(key, "flush_cred") == 0)) {
2001 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count;
2005 rc = obd_set_info(tgt->ltd_exp,
2006 keylen, key, vallen, val);
2017 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2018 struct lov_stripe_md *lsm)
2020 struct obd_device *obd = class_exp2obd(exp);
2021 struct lmv_obd *lmv = &obd->u.lmv;
2022 struct mea *meap, *lsmp;
2026 mea_size = (sizeof(struct lustre_id) *
2027 lmv->desc.ld_tgt_count) + sizeof(struct mea);
2031 if (*lmmp && !lsm) {
2032 OBD_FREE(*lmmp, mea_size);
2037 if (*lmmp == NULL) {
2038 OBD_ALLOC(*lmmp, mea_size);
2046 lsmp = (struct mea *)lsm;
2047 meap = (struct mea *)*lmmp;
2049 if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR &&
2050 lsmp->mea_magic != MEA_MAGIC_ALL_CHARS)
2053 meap->mea_magic = cpu_to_le32(lsmp->mea_magic);
2054 meap->mea_count = cpu_to_le32(lsmp->mea_count);
2055 meap->mea_master = cpu_to_le32(lsmp->mea_master);
2057 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2058 meap->mea_ids[i] = meap->mea_ids[i];
2059 id_cpu_to_le(&meap->mea_ids[i]);
2065 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2066 struct lov_mds_md *lmm, int lmm_size)
2068 struct obd_device *obd = class_exp2obd(exp);
2069 struct mea **tmea = (struct mea **)lsmp;
2070 struct mea *mea = (struct mea *)lmm;
2071 struct lmv_obd *lmv = &obd->u.lmv;
2072 int mea_size, i, rc = 0;
2076 mea_size = sizeof(struct lustre_id) *
2077 lmv->desc.ld_tgt_count + sizeof(struct mea);
2082 if (*lsmp != NULL && lmm == NULL) {
2083 OBD_FREE(*tmea, mea_size);
2087 LASSERT(mea_size == lmm_size);
2089 OBD_ALLOC(*tmea, mea_size);
2096 if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
2097 mea->mea_magic == MEA_MAGIC_ALL_CHARS)
2099 magic = le32_to_cpu(mea->mea_magic);
2101 struct mea_old *old = (struct mea_old *)lmm;
2103 mea_size = sizeof(struct lustre_id) * old->mea_count +
2104 sizeof(struct mea_old);
2106 if (old->mea_count > 256 || old->mea_master > 256 ||
2107 lmm_size < mea_size || old->mea_master > old->mea_count) {
2108 CWARN("bad MEA: count %u, master %u, size %u\n",
2109 old->mea_count, old->mea_master, mea_size);
2110 GOTO(out_free_mea, rc = -EINVAL);
2112 magic = MEA_MAGIC_LAST_CHAR;
2115 (*tmea)->mea_magic = magic;
2116 (*tmea)->mea_count = le32_to_cpu(mea->mea_count);
2117 (*tmea)->mea_master = le32_to_cpu(mea->mea_master);
2119 for (i = 0; i < (*tmea)->mea_count; i++) {
2120 (*tmea)->mea_ids[i] = mea->mea_ids[i];
2121 id_le_to_cpu(&(*tmea)->mea_ids[i]);
2126 OBD_FREE(*tmea, mea_size);
2130 int lmv_brw(int rw, struct obd_export *exp, struct obdo *oa,
2131 struct lov_stripe_md *ea, obd_count oa_bufs,
2132 struct brw_page *pgarr, struct obd_trans_info *oti)
2134 struct obd_device *obd = exp->exp_obd;
2135 struct lmv_obd *lmv = &obd->u.lmv;
2136 struct mea *mea = (struct mea *) ea;
2139 LASSERT(oa != NULL);
2140 LASSERT(ea != NULL);
2141 LASSERT(pgarr != NULL);
2142 LASSERT(oa->o_mds < lmv->desc.ld_tgt_count);
2144 oa->o_gr = id_gen(&mea->mea_ids[oa->o_mds]);
2145 oa->o_id = id_ino(&mea->mea_ids[oa->o_mds]);
2146 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
2148 err = obd_brw(rw, lmv->tgts[oa->o_mds].ltd_exp,
2149 oa, NULL, oa_bufs, pgarr, oti);
2153 static int lmv_cancel_unused(struct obd_export *exp,
2154 struct lov_stripe_md *lsm,
2155 int flags, void *opaque)
2157 struct obd_device *obd = exp->exp_obd;
2158 struct lmv_obd *lmv = &obd->u.lmv;
2162 LASSERT(lsm == NULL);
2164 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2165 if (!lmv->tgts[i].ltd_exp || !lmv->tgts[i].active)
2168 err = obd_cancel_unused(lmv->tgts[i].ltd_exp,
2169 NULL, flags, opaque);
2176 struct obd_ops lmv_obd_ops = {
2177 .o_owner = THIS_MODULE,
2178 .o_attach = lmv_attach,
2179 .o_detach = lmv_detach,
2180 .o_setup = lmv_setup,
2181 .o_cleanup = lmv_cleanup,
2182 .o_connect = lmv_connect,
2183 .o_disconnect = lmv_disconnect,
2184 .o_statfs = lmv_statfs,
2185 .o_llog_init = lmv_llog_init,
2186 .o_llog_finish = lmv_llog_finish,
2187 .o_get_info = lmv_get_info,
2188 .o_set_info = lmv_set_info,
2189 .o_create = lmv_obd_create,
2190 .o_packmd = lmv_packmd,
2191 .o_unpackmd = lmv_unpackmd,
2193 .o_init_ea_size = lmv_init_ea_size,
2194 .o_notify = lmv_notify,
2195 .o_iocontrol = lmv_iocontrol,
2196 .o_cancel_unused = lmv_cancel_unused,
2199 struct md_ops lmv_md_ops = {
2200 .m_getstatus = lmv_getstatus,
2201 .m_getattr = lmv_getattr,
2202 .m_change_cbdata = lmv_change_cbdata,
2203 .m_change_cbdata_name = lmv_change_cbdata_name,
2204 .m_close = lmv_close,
2205 .m_create = lmv_create,
2206 .m_done_writing = lmv_done_writing,
2207 .m_enqueue = lmv_enqueue,
2208 .m_getattr_lock = lmv_getattr_lock,
2209 .m_intent_lock = lmv_intent_lock,
2211 .m_rename = lmv_rename,
2212 .m_setattr = lmv_setattr,
2214 .m_readpage = lmv_readpage,
2215 .m_unlink = lmv_unlink,
2216 .m_get_real_obd = lmv_get_real_obd,
2217 .m_valid_attrs = lmv_valid_attrs,
2218 .m_delete_inode = lmv_delete_inode,
2219 .m_access_check = lmv_access_check,
2222 int __init lmv_init(void)
2224 struct lprocfs_static_vars lvars;
2227 obj_cache = kmem_cache_create("lmv_objects",
2228 sizeof(struct lmv_obj),
2231 CERROR("error allocating lmv objects cache\n");
2235 lprocfs_init_vars(lmv, &lvars);
2236 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
2238 OBD_LMV_DEVICENAME);
2240 kmem_cache_destroy(obj_cache);
2246 static void lmv_exit(void)
2248 class_unregister_type(OBD_LMV_DEVICENAME);
2250 LASSERTF(kmem_cache_destroy(obj_cache) == 0,
2251 "can't free lmv objects cache, %d object(s)"
2252 "still in use\n", atomic_read(&obj_cache_count));
2255 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2256 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
2257 MODULE_LICENSE("GPL");
2259 module_init(lmv_init);
2260 module_exit(lmv_exit);