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>
34 #include <liblustre.h>
36 #include <linux/ext2_fs.h>
38 #include <linux/obd_support.h>
39 #include <linux/lustre_lib.h>
40 #include <linux/lustre_net.h>
41 #include <linux/lustre_idl.h>
42 #include <linux/lustre_dlm.h>
43 #include <linux/lustre_mds.h>
44 #include <linux/obd_class.h>
45 #include <linux/obd_ost.h>
46 #include <linux/seq_file.h>
47 #include <linux/lprocfs_status.h>
48 #include <linux/lustre_fsfilt.h>
49 #include <linux/obd_lmv.h>
50 #include "lmv_internal.h"
52 int lmv_attach(struct obd_device *dev, obd_count len, void *data)
54 struct lprocfs_static_vars lvars;
55 struct proc_dir_entry *entry;
59 lprocfs_init_vars(lmv, &lvars);
60 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
64 entry = create_proc_entry("target_obd", 0444, dev->obd_proc_entry);
67 /* entry->proc_fops = &lmv_proc_target_fops; */
73 int lmv_detach(struct obd_device *dev)
75 return lprocfs_obd_detach(dev);
78 static int lmv_connect_fake(struct lustre_handle *conn,
79 struct obd_device *obd,
80 struct obd_uuid *cluuid)
82 struct lmv_obd *lmv = &obd->u.lmv;
83 struct obd_export *exp;
87 rc = class_connect(conn, obd, cluuid);
89 CERROR("class_connection() returned %d\n", rc);
93 exp = class_conn2export(conn);
94 /* We don't want to actually do the underlying connections more than
95 * once, so keep track. */
97 if (lmv->refcount > 1) {
98 class_export_put(exp);
102 lmv->cluuid = *cluuid;
109 void lmv_set_timeouts(struct obd_device *obd)
111 struct lmv_tgt_desc *tgts;
116 if (lmv->server_timeout == 0)
119 if (lmv->connected == 0)
122 for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
123 if (tgts->exp == NULL)
125 obd_set_info(tgts->exp, strlen("inter_mds"),
126 "inter_mds", 0, NULL);
130 int lmv_connect(struct obd_device *obd)
132 struct lmv_obd *lmv = &obd->u.lmv;
133 struct obd_uuid *cluuid;
134 struct lmv_tgt_desc *tgts;
135 struct obd_export *exp;
143 cluuid = &lmv->cluuid;
145 CDEBUG(D_OTHER, "time to connect %s to %s\n",
146 cluuid->uuid, obd->obd_name);
148 for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
149 struct obd_device *tgt_obd;
150 struct obd_uuid lmv_osc_uuid = { "LMV_OSC_UUID" };
151 struct lustre_handle conn = {0, };
153 LASSERT(tgts != NULL);
155 tgt_obd = class_find_client_obd(&tgts->uuid, LUSTRE_MDC_NAME,
158 CERROR("Target %s not attached\n", tgts->uuid.uuid);
159 GOTO(out_disc, rc = -EINVAL);
162 /* for MDS: don't connect to yourself */
163 if (obd_uuid_equals(&tgts->uuid, cluuid)) {
164 CDEBUG(D_OTHER, "don't connect back to %s\n",
170 CDEBUG(D_OTHER, "connect to %s(%s) - %s, %s FOR %s\n",
171 tgt_obd->obd_name, tgt_obd->obd_uuid.uuid,
172 tgts->uuid.uuid, obd->obd_uuid.uuid,
175 if (!tgt_obd->obd_set_up) {
176 CERROR("Target %s not set up\n", tgts->uuid.uuid);
177 GOTO(out_disc, rc = -EINVAL);
180 rc = obd_connect(&conn, tgt_obd, &lmv_osc_uuid);
182 CERROR("Target %s connect error %d\n",
183 tgts->uuid.uuid, rc);
186 tgts->exp = class_conn2export(&conn);
188 obd_init_ea_size(tgts->exp, lmv->max_easize,
189 lmv->max_cookiesize);
191 rc = obd_register_observer(tgt_obd, obd);
193 CERROR("Target %s register_observer error %d\n",
194 tgts->uuid.uuid, rc);
195 obd_disconnect(tgts->exp, 0);
199 CDEBUG(D_OTHER, "connected to %s(%s) successfully (%d)\n",
200 tgt_obd->obd_name, tgt_obd->obd_uuid.uuid,
201 atomic_read(&obd->obd_refcount));
204 lmv_set_timeouts(obd);
206 class_export_put(exp);
210 /* FIXME: cleanup here */
211 class_disconnect(exp, 0);
215 static int lmv_disconnect(struct obd_export *exp, int flags)
217 struct obd_device *obd = class_exp2obd(exp);
218 struct lmv_obd *lmv = &obd->u.lmv;
225 /* Only disconnect the underlying layers on the final disconnect. */
227 if (lmv->refcount != 0)
230 for (i = 0; i < lmv->count; i++) {
231 if (lmv->tgts[i].exp == NULL)
234 if (obd->obd_no_recov) {
235 /* Pass it on to our clients.
236 * XXX This should be an argument to disconnect,
237 * XXX not a back-door flag on the OBD. Ah well.
239 struct obd_device *mdc_obd;
240 mdc_obd = class_exp2obd(lmv->tgts[i].exp);
242 mdc_obd->obd_no_recov = 1;
245 CDEBUG(D_OTHER, "disconnected from %s(%s) successfully\n",
246 lmv->tgts[i].exp->exp_obd->obd_name,
247 lmv->tgts[i].exp->exp_obd->obd_uuid.uuid);
249 obd_register_observer(lmv->tgts[i].exp->exp_obd, NULL);
251 rc = obd_disconnect(lmv->tgts[i].exp, flags);
252 lmv->tgts[i].exp = NULL;
256 /* FIXME: cleanup here */
258 class_export_put(exp);
259 rc = class_disconnect(exp, 0);
263 static int lmv_setup(struct obd_device *obd, obd_count len, void *buf)
265 struct lustre_cfg *lcfg = buf;
266 struct lmv_desc *desc;
267 struct lmv_obd *lmv = &obd->u.lmv;
268 struct obd_uuid *uuids;
269 struct lmv_tgt_desc *tgts;
275 if (lcfg->lcfg_inllen1 < 1) {
276 CERROR("LMV setup requires a descriptor\n");
280 if (lcfg->lcfg_inllen2 < 1) {
281 CERROR("LMV setup requires an OST UUID list\n");
285 desc = (struct lmv_desc *)lcfg->lcfg_inlbuf1;
286 if (sizeof(*desc) > lcfg->lcfg_inllen1) {
287 CERROR("descriptor size wrong: %d > %d\n",
288 (int)sizeof(*desc), lcfg->lcfg_inllen1);
292 count = desc->ld_count;
293 uuids = (struct obd_uuid *)lcfg->lcfg_inlbuf2;
294 if (sizeof(*uuids) * count != lcfg->lcfg_inllen2) {
295 CERROR("UUID array size wrong: %u * %u != %u\n",
296 sizeof(*uuids), count, lcfg->lcfg_inllen2);
300 lmv->bufsize = sizeof(struct lmv_tgt_desc) * count;
301 OBD_ALLOC(lmv->tgts, lmv->bufsize);
302 if (lmv->tgts == NULL) {
303 CERROR("Out of memory\n");
307 for (i = 0, tgts = lmv->tgts; i < count; i++, tgts++) {
308 tgts->uuid = uuids[i];
312 lmv->max_easize = sizeof(struct ll_fid) * lmv->count
313 + sizeof(struct mea);
314 lmv->max_cookiesize = 0;
319 static int lmv_statfs(struct obd_device *obd, struct obd_statfs *osfs,
320 unsigned long max_age)
322 struct lmv_obd *lmv = &obd->u.lmv;
323 struct obd_statfs temp;
327 for (i = 0; i < lmv->count; i++) {
328 rc = obd_statfs(lmv->tgts[i].exp->exp_obd, &temp, max_age);
330 CERROR("can't stat MDS #%d (%s)\n", i,
331 lmv->tgts[i].exp->exp_obd->obd_name);
335 memcpy(osfs, &temp, sizeof(temp));
337 osfs->os_bavail += temp.os_bavail;
338 osfs->os_blocks += temp.os_blocks;
339 osfs->os_ffree += temp.os_ffree;
340 osfs->os_files += temp.os_files;
346 static int lmv_cleanup(struct obd_device *obd, int flags)
348 struct lmv_obd *lmv = &obd->u.lmv;
350 lmv_cleanup_objs(obd);
351 OBD_FREE(lmv->tgts, lmv->bufsize);
355 static int lmv_getstatus(struct obd_export *exp, struct ll_fid *fid)
357 struct obd_device *obd = exp->exp_obd;
358 struct lmv_obd *lmv = &obd->u.lmv;
362 rc = md_getstatus(lmv->tgts[0].exp, fid);
367 static int lmv_getattr(struct obd_export *exp, struct ll_fid *fid,
368 unsigned long valid, unsigned int ea_size,
369 struct ptlrpc_request **request)
371 struct obd_device *obd = exp->exp_obd;
372 struct lmv_obd *lmv = &obd->u.lmv;
373 int rc, i = fid->mds;
377 obj = lmv_grab_obj(obd, fid, 0);
378 CDEBUG(D_OTHER, "GETATTR for %lu/%lu/%lu %s\n",
379 (unsigned long) fid->mds,
380 (unsigned long) fid->id,
381 (unsigned long) fid->generation,
382 obj ? "(splitted)" : "");
384 LASSERT(fid->mds < lmv->count);
385 rc = md_getattr(lmv->tgts[i].exp, fid,
386 valid, ea_size, request);
387 if (rc == 0 && obj) {
388 /* we have to loop over dirobjs here and gather attrs
389 * for all the slaves */
390 #warning "attrs gathering here"
396 static int lmv_change_cbdata(struct obd_export *exp,
398 ldlm_iterator_t it, void *data)
400 struct obd_device *obd = exp->exp_obd;
401 struct lmv_obd *lmv = &obd->u.lmv;
405 CDEBUG(D_OTHER, "CBDATA for %lu/%lu/%lu\n",
406 (unsigned long) fid->mds,
407 (unsigned long) fid->id,
408 (unsigned long) fid->generation);
409 LASSERT(fid->mds < lmv->count);
410 rc = md_change_cbdata(lmv->tgts[fid->mds].exp, fid, it, data);
414 static int lmv_change_cbdata_name(struct obd_export *exp, struct ll_fid *pfid,
415 char *name, int len, struct ll_fid *cfid,
416 ldlm_iterator_t it, void *data)
418 struct obd_device *obd = exp->exp_obd;
419 struct lmv_obd *lmv = &obd->u.lmv;
424 LASSERT(pfid->mds < lmv->count);
425 LASSERT(cfid->mds < lmv->count);
426 CDEBUG(D_OTHER, "CBDATA for %lu/%lu/%lu:%*s -> %lu/%lu/%lu\n",
427 (unsigned long) pfid->mds, (unsigned long) pfid->id,
428 (unsigned long) pfid->generation, len, name,
429 (unsigned long) cfid->mds, (unsigned long) cfid->id,
430 (unsigned long) cfid->generation);
432 /* this is default mds for directory name belongs to */
434 obj = lmv_grab_obj(obd, pfid, 0);
436 /* directory is splitted. look for right mds for this name */
437 mds = raw_name2idx(obj->objcount, name, len);
440 rc = md_change_cbdata(lmv->tgts[mds].exp, cfid, it, data);
444 static int lmv_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
446 struct obd_device *obd = exp->exp_obd;
447 struct lmv_obd *lmv = &obd->u.lmv;
451 CDEBUG(D_OTHER, "validate %lu/%lu/%lu\n",
452 (unsigned long) fid->mds,
453 (unsigned long) fid->id,
454 (unsigned long) fid->generation);
455 LASSERT(fid->mds < lmv->count);
456 rc = md_valid_attrs(lmv->tgts[fid->mds].exp, fid);
460 int lmv_close(struct obd_export *exp, struct obdo *obdo,
461 struct obd_client_handle *och,
462 struct ptlrpc_request **request)
464 struct obd_device *obd = exp->exp_obd;
465 struct lmv_obd *lmv = &obd->u.lmv;
466 int rc, i = obdo->o_mds;
469 LASSERT(i < lmv->count);
470 CDEBUG(D_OTHER, "CLOSE %lu/%lu/%lu\n", (unsigned long) obdo->o_mds,
471 (unsigned long) obdo->o_id, (unsigned long) obdo->o_generation);
472 rc = md_close(lmv->tgts[i].exp, obdo, och, request);
476 int lmv_get_mea_and_update_object(struct obd_export *exp, struct ll_fid *fid)
478 struct obd_device *obd = exp->exp_obd;
479 struct lmv_obd *lmv = &obd->u.lmv;
480 struct ptlrpc_request *req = NULL;
485 mealen = MEA_SIZE_LMV(lmv);
487 /* time to update mea of parent fid */
488 rc = md_getattr(lmv->tgts[fid->mds].exp, fid,
489 OBD_MD_FLEASIZE, mealen, &req);
492 rc = mdc_req2lustre_md(req, 0, NULL, exp, &md);
496 GOTO(cleanup, rc = -ENODATA);
497 rc = lmv_create_obj_from_attrs(exp, fid, md.mea);
498 obd_free_memmd(exp, (struct lov_stripe_md **) &md.mea);
502 ptlrpc_req_finished(req);
506 int lmv_create(struct obd_export *exp, struct mdc_op_data *op_data,
507 const void *data, int datalen, int mode, __u32 uid,
508 __u32 gid, __u64 rdev, struct ptlrpc_request **request)
510 struct obd_device *obd = exp->exp_obd;
511 struct lmv_obd *lmv = &obd->u.lmv;
512 struct mds_body *mds_body;
519 obj = lmv_grab_obj(obd, &op_data->fid1, 0);
521 mds = raw_name2idx(obj->objcount, op_data->name,
523 op_data->fid1 = obj->objs[mds].fid;
527 CDEBUG(D_OTHER, "CREATE '%*s' on %lu/%lu/%lu\n",
528 op_data->namelen, op_data->name,
529 (unsigned long) op_data->fid1.mds,
530 (unsigned long) op_data->fid1.id,
531 (unsigned long) op_data->fid1.generation);
532 rc = md_create(lmv->tgts[op_data->fid1.mds].exp, op_data, data,
533 datalen, mode, uid, gid, rdev, request);
535 if (*request == NULL)
537 mds_body = lustre_msg_buf((*request)->rq_repmsg, 0,
539 LASSERT(mds_body != NULL);
540 CDEBUG(D_OTHER, "created. id = %lu, generation = %lu, mds = %d\n",
541 (unsigned long) mds_body->fid1.id,
542 (unsigned long) mds_body->fid1.generation,
544 LASSERT(mds_body->valid & OBD_MD_MDS ||
545 mds_body->mds == op_data->fid1.mds);
546 } else if (rc == -ERESTART) {
547 /* directory got splitted. time to update local object
548 * and repeat the request with proper MDS */
549 rc = lmv_get_mea_and_update_object(exp, &op_data->fid1);
551 ptlrpc_req_finished(*request);
558 int lmv_done_writing(struct obd_export *exp, struct obdo *obdo)
560 struct obd_device *obd = exp->exp_obd;
561 struct lmv_obd *lmv = &obd->u.lmv;
565 /* FIXME: choose right MDC here */
566 rc = md_done_writing(lmv->tgts[0].exp, obdo);
570 int lmv_enqueue(struct obd_export *exp, int lock_type,
571 struct lookup_intent *it, int lock_mode,
572 struct mdc_op_data *data, struct lustre_handle *lockh,
573 void *lmm, int lmmsize,
574 ldlm_completion_callback cb_completion,
575 ldlm_blocking_callback cb_blocking, void *cb_data)
577 struct obd_device *obd = exp->exp_obd;
578 struct lmv_obd *lmv = &obd->u.lmv;
584 obj = lmv_grab_obj(obd, &data->fid1, 0);
586 /* directory is splitted. look for
587 * right mds for this name */
588 mds = raw_name2idx(obj->objcount, data->name,
590 data->fid1 = obj->objs[mds].fid;
594 CDEBUG(D_OTHER, "ENQUEUE '%s' on %lu/%lu\n",
595 LL_IT2STR(it), (unsigned long) data->fid1.id,
596 (unsigned long) data->fid1.generation);
597 rc = md_enqueue(lmv->tgts[data->fid1.mds].exp, lock_type, it,
598 lock_mode, data, lockh, lmm, lmmsize, cb_completion,
599 cb_blocking, cb_data);
604 int lmv_getattr_name(struct obd_export *exp, struct ll_fid *fid,
605 char *filename, int namelen, unsigned long valid,
606 unsigned int ea_size, struct ptlrpc_request **request)
608 struct obd_device *obd = exp->exp_obd;
609 struct lmv_obd *lmv = &obd->u.lmv;
610 struct ll_fid rfid = *fid;
611 int rc, mds = fid->mds;
612 struct mds_body *body;
616 obj = lmv_grab_obj(obd, fid, 0);
618 /* directory is splitted. look for right mds for this name */
619 mds = raw_name2idx(obj->objcount, filename, namelen - 1);
620 rfid = obj->objs[mds].fid;
623 CDEBUG(D_OTHER, "getattr_name for %*s on %lu/%lu/%lu -> %lu/%lu/%lu\n",
624 namelen, filename, (unsigned long) fid->mds,
625 (unsigned long) fid->id, (unsigned long) fid->generation,
626 (unsigned long) rfid.mds, (unsigned long) rfid.id,
627 (unsigned long) rfid.generation);
628 rc = md_getattr_name(lmv->tgts[mds].exp, &rfid, filename, namelen,
629 valid, ea_size, request);
631 /* this could be cross-node reference. in this case all
632 * we have right now is mds/ino/generation triple. we'd
633 * like to find other attributes */
634 body = lustre_msg_buf((*request)->rq_repmsg, 0, sizeof(*body));
635 LASSERT(body != NULL);
636 if (body->valid & OBD_MD_MDS) {
637 struct ptlrpc_request *req = NULL;
639 CDEBUG(D_OTHER, "request attrs for %lu/%lu/%lu\n",
640 (unsigned long) rfid.mds,
641 (unsigned long) rfid.id,
642 (unsigned long) rfid.generation);
643 rc = md_getattr_name(lmv->tgts[rfid.mds].exp, &rfid,
644 NULL, 1, valid, ea_size, &req);
645 ptlrpc_req_finished(*request);
654 * llite passes fid of an target inode in data->fid1 and
655 * fid of directory in data->fid2
657 int lmv_link(struct obd_export *exp, struct mdc_op_data *data,
658 struct ptlrpc_request **request)
660 struct obd_device *obd = exp->exp_obd;
661 struct lmv_obd *lmv = &obd->u.lmv;
666 if (data->namelen != 0) {
667 /* usual link request */
668 obj = lmv_grab_obj(obd, &data->fid1, 0);
670 rc = raw_name2idx(obj->objcount, data->name,
672 data->fid1 = obj->objs[rc].fid;
675 CDEBUG(D_OTHER,"link %u/%u/%u:%*s to %u/%u/%u mds %d\n",
676 (unsigned) data->fid2.mds, (unsigned) data->fid2.id,
677 (unsigned) data->fid2.generation, data->namelen,
678 data->name, (unsigned) data->fid1.mds,
679 (unsigned) data->fid1.id,
680 (unsigned) data->fid1.generation, data->fid1.mds);
682 /* request from MDS to acquire i_links for inode by fid1 */
683 CDEBUG(D_OTHER, "inc i_nlinks for %u/%u/%u\n",
684 (unsigned) data->fid1.mds, (unsigned) data->fid1.id,
685 (unsigned) data->fid1.generation);
688 rc = md_link(lmv->tgts[data->fid1.mds].exp, data, request);
692 int lmv_rename(struct obd_export *exp, struct mdc_op_data *data,
693 const char *old, int oldlen, const char *new, int newlen,
694 struct ptlrpc_request **request)
696 struct obd_device *obd = exp->exp_obd;
697 struct lmv_obd *lmv = &obd->u.lmv;
702 CDEBUG(D_OTHER, "rename %*s in %lu/%lu/%lu to %*s in %lu/%lu/%lu\n",
703 oldlen, old, (unsigned long) data->fid1.mds,
704 (unsigned long) data->fid1.id,
705 (unsigned long) data->fid1.generation,
706 newlen, new, (unsigned long) data->fid2.mds,
707 (unsigned long) data->fid2.id,
708 (unsigned long) data->fid2.generation);
709 if (!fid_equal(&data->fid1, &data->fid2))
710 CWARN("cross-node rename %lu/%lu/%lu:%*s to %lu/%lu/%lu:%*s\n",
711 (unsigned long) data->fid1.mds,
712 (unsigned long) data->fid1.id,
713 (unsigned long) data->fid1.generation, oldlen, old,
714 (unsigned long) data->fid2.mds,
715 (unsigned long) data->fid2.id,
716 (unsigned long) data->fid2.generation, newlen, new);
721 /* MDS with old dir entry is asking another MDS
722 * to create name there */
724 "create %*s(%d/%d) in %lu/%lu/%lu pointing to %lu/%lu/%lu\n",
725 newlen, new, oldlen, newlen,
726 (unsigned long) data->fid2.mds,
727 (unsigned long) data->fid2.id,
728 (unsigned long) data->fid2.generation,
729 (unsigned long) data->fid1.mds,
730 (unsigned long) data->fid1.id,
731 (unsigned long) data->fid1.generation);
732 mds = data->fid2.mds;
736 obj = lmv_grab_obj(obd, &data->fid1, 0);
738 /* directory is already splitted, so we have to forward
739 * request to the right MDS */
740 mds = raw_name2idx(obj->objcount, old, oldlen);
741 data->fid1 = obj->objs[mds].fid;
742 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
743 (unsigned long) obj->objs[mds].fid.mds,
744 (unsigned long) obj->objs[mds].fid.id,
745 (unsigned long) obj->objs[mds].fid.generation);
749 obj = lmv_grab_obj(obd, &data->fid2, 0);
751 /* directory is already splitted, so we have to forward
752 * request to the right MDS */
753 mds = raw_name2idx(obj->objcount, new, newlen);
754 data->fid2 = obj->objs[mds].fid;
755 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
756 (unsigned long) obj->objs[mds].fid.mds,
757 (unsigned long) obj->objs[mds].fid.id,
758 (unsigned long) obj->objs[mds].fid.generation);
762 mds = data->fid1.mds;
765 rc = md_rename(lmv->tgts[mds].exp, data, old, oldlen,
766 new, newlen, request);
770 int lmv_setattr(struct obd_export *exp, struct mdc_op_data *data,
771 struct iattr *iattr, void *ea, int ealen, void *ea2, int ea2len,
772 struct ptlrpc_request **request)
774 struct obd_device *obd = exp->exp_obd;
775 struct lmv_obd *lmv = &obd->u.lmv;
776 int rc = 0, i = data->fid1.mds;
777 struct ptlrpc_request *req;
778 struct mds_body *mds_body;
782 obj = lmv_grab_obj(obd, &data->fid1, 0);
783 CDEBUG(D_OTHER, "SETATTR for %lu/%lu/%lu, valid 0x%x%s\n",
784 (unsigned long) data->fid1.mds,
785 (unsigned long) data->fid1.id,
786 (unsigned long) data->fid1.generation, iattr->ia_valid,
787 obj ? ", splitted" : "");
789 for (i = 0; i < obj->objcount; i++) {
790 data->fid1 = obj->objs[i].fid;
791 rc = md_setattr(lmv->tgts[i].exp, data, iattr, ea,
792 ealen, ea2, ea2len, &req);
794 if (fid_equal(&obj->fid, &obj->objs[i].fid)) {
795 /* this is master object and this request
796 * should be returned back to llite */
799 ptlrpc_req_finished(req);
804 LASSERT(data->fid1.mds < lmv->count);
805 rc = md_setattr(lmv->tgts[i].exp, data, iattr, ea, ealen,
806 ea2, ea2len, request);
808 mds_body = lustre_msg_buf((*request)->rq_repmsg, 0,
810 LASSERT(mds_body != NULL);
811 LASSERT(mds_body->mds == i);
817 int lmv_sync(struct obd_export *exp, struct ll_fid *fid,
818 struct ptlrpc_request **request)
820 struct obd_device *obd = exp->exp_obd;
821 struct lmv_obd *lmv = &obd->u.lmv;
825 rc = md_sync(lmv->tgts[0].exp, fid, request);
829 int lmv_dirobj_blocking_ast(struct ldlm_lock *lock,
830 struct ldlm_lock_desc *desc, void *data, int flag)
832 struct lustre_handle lockh;
838 case LDLM_CB_BLOCKING:
839 ldlm_lock2handle(lock, &lockh);
840 rc = ldlm_cli_cancel(&lockh);
842 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
846 case LDLM_CB_CANCELING:
847 /* time to drop cached attrs for dirobj */
848 obj = lock->l_ast_data;
852 CDEBUG(D_OTHER, "cancel %s on %lu/%lu, master %lu/%lu/%lu\n",
853 lock->l_resource->lr_name.name[3] == 1 ?
855 (unsigned long) lock->l_resource->lr_name.name[0],
856 (unsigned long) lock->l_resource->lr_name.name[1],
857 (unsigned long) obj->fid.mds,
858 (unsigned long) obj->fid.id,
859 (unsigned long) obj->fid.generation);
867 void lmv_remove_dots(struct page *page)
869 char *kaddr = page_address(page);
870 unsigned limit = PAGE_CACHE_SIZE;
871 unsigned offs, rec_len;
872 struct ext2_dir_entry_2 *p;
874 for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
875 p = (struct ext2_dir_entry_2 *)(kaddr + offs);
876 rec_len = le16_to_cpu(p->rec_len);
878 if ((p->name_len == 1 && p->name[0] == '.') ||
879 (p->name_len == 2 && p->name[0] == '.' && p->name[1] == '.'))
884 int lmv_readpage(struct obd_export *exp, struct ll_fid *mdc_fid,
885 __u64 offset, struct page *page,
886 struct ptlrpc_request **request)
888 struct obd_device *obd = exp->exp_obd;
889 struct lmv_obd *lmv = &obd->u.lmv;
890 struct ll_fid rfid = *mdc_fid;
896 LASSERT(mdc_fid->mds < lmv->count);
897 CDEBUG(D_OTHER, "READPAGE at %llu from %lu/%lu/%lu\n",
898 offset, (unsigned long) rfid.mds,
899 (unsigned long) rfid.id,
900 (unsigned long) rfid.generation);
902 obj = lmv_grab_obj(obd, mdc_fid, 0);
904 /* find dirobj containing page with requested offset */
905 /* FIXME: what about protecting cached attrs here? */
906 for (i = 0; i < obj->objcount; i++) {
907 if (offset < obj->objs[i].size)
909 offset -= obj->objs[i].size;
911 rfid = obj->objs[i].fid;
912 CDEBUG(D_OTHER, "forward to %lu/%lu/%lu with offset %lu\n",
913 (unsigned long) rfid.mds,
914 (unsigned long) rfid.id,
915 (unsigned long) rfid.generation,
916 (unsigned long) offset);
918 rc = md_readpage(lmv->tgts[rfid.mds].exp, &rfid, offset, page, request);
919 if (rc == 0 && !fid_equal(&rfid, mdc_fid)) {
920 /* this page isn't from master object. to avoid
921 * ./.. duplication in directory, we have to remove them
922 * from all slave objects */
923 lmv_remove_dots(page);
931 int lmv_unlink(struct obd_export *exp, struct mdc_op_data *data,
932 struct ptlrpc_request **request)
934 struct obd_device *obd = exp->exp_obd;
935 struct lmv_obd *lmv = &obd->u.lmv;
939 if (data->namelen != 0) {
941 obj = lmv_grab_obj(obd, &data->fid1, 0);
943 i = raw_name2idx(obj->objcount, data->name,
945 data->fid1 = obj->objs[i].fid;
948 CDEBUG(D_OTHER, "unlink '%*s' in %lu/%lu/%lu -> %u\n",
949 data->namelen, data->name,
950 (unsigned long) data->fid1.mds,
951 (unsigned long) data->fid1.id,
952 (unsigned long) data->fid1.generation, i);
954 CDEBUG(D_OTHER, "drop i_nlink on %lu/%lu/%lu\n",
955 (unsigned long) data->fid1.mds,
956 (unsigned long) data->fid1.id,
957 (unsigned long) data->fid1.generation);
959 rc = md_unlink(lmv->tgts[data->fid1.mds].exp, data, request);
963 struct obd_device *lmv_get_real_obd(struct obd_export *exp,
966 struct obd_device *obd = exp->exp_obd;
967 struct lmv_obd *lmv = &obd->u.lmv;
970 obd = lmv->tgts[0].exp->exp_obd;
975 int lmv_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
977 struct obd_device *obd = exp->exp_obd;
978 struct lmv_obd *lmv = &obd->u.lmv;
979 int i, rc = 0, change = 0;
982 if (lmv->max_easize < easize) {
983 lmv->max_easize = easize;
986 if (lmv->max_cookiesize < cookiesize) {
987 lmv->max_cookiesize = cookiesize;
993 if (lmv->connected == 0)
996 /* FIXME: error handling? */
997 for (i = 0; i < lmv->count; i++)
998 rc = obd_init_ea_size(lmv->tgts[i].exp, easize, cookiesize);
1002 int lmv_obd_create_single(struct obd_export *exp, struct obdo *oa,
1003 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1005 struct obd_device *obd = exp->exp_obd;
1006 struct lmv_obd *lmv = &obd->u.lmv;
1007 struct lov_stripe_md obj_md;
1008 struct lov_stripe_md *obj_mdp = &obj_md;
1013 LASSERT(ea == NULL);
1014 LASSERT(oa->o_mds < lmv->count);
1016 rc = obd_create(lmv->tgts[oa->o_mds].exp, oa, &obj_mdp, oti);
1023 * to be called from MDS only
1025 int lmv_obd_create(struct obd_export *exp, struct obdo *oa,
1026 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1028 struct obd_device *obd = exp->exp_obd;
1029 struct lmv_obd *lmv = &obd->u.lmv;
1036 LASSERT(oa != NULL);
1039 rc = lmv_obd_create_single(exp, oa, NULL, oti);
1044 rc = obd_alloc_diskmd(exp, (struct lov_mds_md **) ea);
1045 LASSERT(*ea != NULL);
1048 mea = (struct mea *) *ea;
1050 mfid.generation = oa->o_generation;
1052 if (!mea->mea_count || mea->mea_count > lmv->count)
1053 mea->mea_count = lmv->count;
1055 mea->mea_master = -1;
1057 /* FIXME: error handling? */
1058 for (i = 0, c = 0; c < mea->mea_count && i < lmv->count; i++) {
1059 struct lov_stripe_md obj_md;
1060 struct lov_stripe_md *obj_mdp = &obj_md;
1062 if (lmv->tgts[i].exp == NULL) {
1063 /* this is master MDS */
1064 mea->mea_fids[c].id = mfid.id;
1065 mea->mea_fids[c].generation = mfid.generation;
1066 mea->mea_fids[c].mds = i;
1067 mea->mea_master = i;
1072 /* "Master" MDS should always be part of stripped dir, so
1074 if (mea->mea_master == -1 && c == mea->mea_count - 1)
1077 oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLTYPE | OBD_MD_FLMODE
1078 | OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLID;
1080 rc = obd_create(lmv->tgts[c].exp, oa, &obj_mdp, oti);
1081 /* FIXME: error handling here */
1084 mea->mea_fids[c].id = oa->o_id;
1085 mea->mea_fids[c].generation = oa->o_generation;
1086 mea->mea_fids[c].mds = i;
1088 CDEBUG(D_OTHER, "dirobj at mds %d: "LPU64"/%u\n",
1089 i, oa->o_id, oa->o_generation);
1091 LASSERT(c == mea->mea_count);
1092 CDEBUG(D_OTHER, "%d dirobjects created\n", (int) mea->mea_count);
1097 static int lmv_get_info(struct obd_export *exp, __u32 keylen,
1098 void *key, __u32 *vallen, void *val)
1100 struct obd_device *obd;
1101 struct lmv_obd *lmv;
1104 obd = class_exp2obd(exp);
1106 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1107 exp->exp_handle.h_cookie);
1112 if (keylen == 6 && memcmp(key, "mdsize", 6) == 0) {
1113 __u32 *mdsize = val;
1114 *vallen = sizeof(__u32);
1115 *mdsize = sizeof(struct ll_fid) * lmv->count
1116 + sizeof(struct mea);
1118 } else if (keylen == 6 && memcmp(key, "mdsnum", 6) == 0) {
1119 struct obd_uuid *cluuid = &lmv->cluuid;
1120 struct lmv_tgt_desc *tgts;
1121 __u32 *mdsnum = val;
1124 for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
1125 if (obd_uuid_equals(&tgts->uuid, cluuid)) {
1126 *vallen = sizeof(__u32);
1134 CDEBUG(D_IOCTL, "invalid key\n");
1138 int lmv_set_info(struct obd_export *exp, obd_count keylen,
1139 void *key, obd_count vallen, void *val)
1141 struct obd_device *obd;
1142 struct lmv_obd *lmv;
1145 obd = class_exp2obd(exp);
1147 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1148 exp->exp_handle.h_cookie);
1153 if (keylen >= strlen("client") && strcmp(key, "client") == 0) {
1154 struct lmv_tgt_desc *tgts;
1158 for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
1159 rc = obd_set_info(tgts->exp, keylen, key, vallen, val);
1164 } else if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
1165 lmv->server_timeout = 1;
1166 lmv_set_timeouts(obd);
1173 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
1174 struct lov_stripe_md *lsm)
1176 struct obd_device *obd = class_exp2obd(exp);
1177 struct lmv_obd *lmv = &obd->u.lmv;
1181 mea_size = sizeof(struct ll_fid) * lmv->count + sizeof(struct mea);
1185 if (*lmmp && !lsm) {
1186 OBD_FREE(*lmmp, mea_size);
1192 OBD_ALLOC(*lmmp, mea_size);
1200 #warning "MEA packing/convertation must be here! -bzzz"
1201 memcpy(*lmmp, lsm, mea_size);
1205 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **mem_tgt,
1206 struct lov_mds_md *disk_src, int mdsize)
1208 struct obd_device *obd = class_exp2obd(exp);
1209 struct lmv_obd *lmv = &obd->u.lmv;
1210 struct mea **tmea = (struct mea **) mem_tgt;
1211 struct mea *mea = (void *) disk_src;
1215 mea_size = sizeof(struct ll_fid) * lmv->count + sizeof(struct mea);
1216 if (mem_tgt == NULL)
1219 if (*mem_tgt != NULL && disk_src == NULL) {
1220 OBD_FREE(*tmea, mea_size);
1224 LASSERT(mea_size == mdsize);
1226 OBD_ALLOC(*tmea, mea_size);
1227 /* FIXME: error handling here */
1228 LASSERT(*tmea != NULL);
1233 #warning "MEA unpacking/convertation must be here! -bzzz"
1234 memcpy(*tmea, mea, mdsize);
1238 int lmv_brw(int rw, struct obd_export *exp, struct obdo *oa,
1239 struct lov_stripe_md *ea, obd_count oa_bufs,
1240 struct brw_page *pgarr, struct obd_trans_info *oti)
1242 struct obd_device *obd = exp->exp_obd;
1243 struct lmv_obd *lmv = &obd->u.lmv;
1244 struct mea *mea = (struct mea *) ea;
1247 LASSERT(oa != NULL);
1248 LASSERT(ea != NULL);
1249 LASSERT(pgarr != NULL);
1250 LASSERT(oa->o_mds < lmv->count);
1252 oa->o_gr = mea->mea_fids[oa->o_mds].generation;
1253 oa->o_id = mea->mea_fids[oa->o_mds].id;
1254 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1255 err = obd_brw(rw, lmv->tgts[oa->o_mds].exp, oa,
1256 NULL, oa_bufs, pgarr, oti);
1260 struct obd_ops lmv_obd_ops = {
1261 o_owner: THIS_MODULE,
1262 o_attach: lmv_attach,
1263 o_detach: lmv_detach,
1265 o_cleanup: lmv_cleanup,
1266 o_connect: lmv_connect_fake,
1267 o_disconnect: lmv_disconnect,
1268 o_statfs: lmv_statfs,
1269 o_get_info: lmv_get_info,
1270 o_set_info: lmv_set_info,
1271 o_create: lmv_obd_create,
1272 o_packmd: lmv_packmd,
1273 o_unpackmd: lmv_unpackmd,
1275 o_init_ea_size: lmv_init_ea_size,
1278 struct md_ops lmv_md_ops = {
1279 m_getstatus: lmv_getstatus,
1280 m_getattr: lmv_getattr,
1281 m_change_cbdata: lmv_change_cbdata,
1282 m_change_cbdata_name: lmv_change_cbdata_name,
1284 m_create: lmv_create,
1285 m_done_writing: lmv_done_writing,
1286 m_enqueue: lmv_enqueue,
1287 m_getattr_name: lmv_getattr_name,
1288 m_intent_lock: lmv_intent_lock,
1290 m_rename: lmv_rename,
1291 m_setattr: lmv_setattr,
1293 m_readpage: lmv_readpage,
1294 m_unlink: lmv_unlink,
1295 m_get_real_obd: lmv_get_real_obd,
1296 m_valid_attrs: lmv_valid_attrs,
1300 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
1301 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
1303 LPROCFS_INIT_VARS(lmv, lprocfs_module_vars, lprocfs_obd_vars)
1305 int __init lmv_init(void)
1307 struct lprocfs_static_vars lvars;
1310 lprocfs_init_vars(lmv, &lvars);
1311 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
1312 lvars.module_vars, OBD_LMV_DEVICENAME);
1316 static void lmv_exit(void)
1318 class_unregister_type(OBD_LMV_DEVICENAME);
1322 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1323 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
1324 MODULE_LICENSE("GPL");
1326 module_init(lmv_init);
1327 module_exit(lmv_exit);