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;
86 rc = class_connect(conn, obd, cluuid);
88 CERROR("class_connection() returned %d\n", rc);
92 lmv->exp = class_conn2export(conn);
93 LASSERT(lmv->exp != NULL);
95 lmv->cluuid = *cluuid;
101 int lmv_connect(struct obd_device *obd)
103 struct lmv_obd *lmv = &obd->u.lmv;
104 struct obd_uuid *cluuid;
105 struct lmv_tgt_desc *tgts;
106 struct obd_export *exp;
114 cluuid = &lmv->cluuid;
116 CDEBUG(D_OTHER, "time to connect %s to %s\n",
117 cluuid->uuid, obd->obd_name);
119 /* We don't want to actually do the underlying connections more than
120 * once, so keep track. */
122 if (lmv->refcount > 1) {
123 class_export_put(exp);
127 for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
128 struct obd_device *tgt_obd;
129 struct obd_uuid lmv_osc_uuid = { "LMV_OSC_UUID" };
130 struct lustre_handle conn = {0, };
132 LASSERT(tgts != NULL);
134 tgt_obd = class_find_client_obd(&tgts->uuid, LUSTRE_MDC_NAME,
137 CERROR("Target %s not attached\n", tgts->uuid.uuid);
138 GOTO(out_disc, rc = -EINVAL);
141 /* for MDS: don't connect to yourself */
142 if (obd_uuid_equals(&tgts->uuid, cluuid)) {
143 CDEBUG(D_OTHER, "don't connect back to %s\n",
149 CDEBUG(D_OTHER, "connect to %s(%s) - %s, %s FOR %s\n",
150 tgt_obd->obd_name, tgt_obd->obd_uuid.uuid,
151 tgts->uuid.uuid, obd->obd_uuid.uuid,
154 if (!tgt_obd->obd_set_up) {
155 CERROR("Target %s not set up\n", tgts->uuid.uuid);
156 GOTO(out_disc, rc = -EINVAL);
159 rc = obd_connect(&conn, tgt_obd, &lmv_osc_uuid);
161 CERROR("Target %s connect error %d\n",
162 tgts->uuid.uuid, rc);
165 tgts->exp = class_conn2export(&conn);
167 obd_init_ea_size(tgts->exp, lmv->max_easize,
168 lmv->max_cookiesize);
170 rc = obd_register_observer(tgt_obd, obd);
172 CERROR("Target %s register_observer error %d\n",
173 tgts->uuid.uuid, rc);
174 obd_disconnect(tgts->exp, 0);
178 CDEBUG(D_OTHER, "connected to %s(%s) successfully (%d)\n",
179 tgt_obd->obd_name, tgt_obd->obd_uuid.uuid,
180 atomic_read(&obd->obd_refcount));
183 class_export_put(exp);
187 /* FIXME: cleanup here */
188 class_disconnect(exp, 0);
192 static int lmv_disconnect(struct obd_export *exp, int flags)
194 struct obd_device *obd = class_exp2obd(exp);
195 struct lmv_obd *lmv = &obd->u.lmv;
202 /* Only disconnect the underlying layers on the final disconnect. */
204 if (lmv->refcount != 0)
207 for (i = 0; i < lmv->count; i++) {
208 if (lmv->tgts[i].exp == NULL)
211 if (obd->obd_no_recov) {
212 /* Pass it on to our clients.
213 * XXX This should be an argument to disconnect,
214 * XXX not a back-door flag on the OBD. Ah well.
216 struct obd_device *mdc_obd;
217 mdc_obd = class_exp2obd(lmv->tgts[i].exp);
219 mdc_obd->obd_no_recov = 1;
222 CDEBUG(D_OTHER, "disconnected from %s(%s) successfully\n",
223 lmv->tgts[i].exp->exp_obd->obd_name,
224 lmv->tgts[i].exp->exp_obd->obd_uuid.uuid);
226 obd_register_observer(lmv->tgts[i].exp->exp_obd, NULL);
228 rc = obd_disconnect(lmv->tgts[i].exp, flags);
229 lmv->tgts[i].exp = NULL;
233 /* FIXME: cleanup here */
235 class_export_put(exp);
236 rc = class_disconnect(exp, 0);
240 static int lmv_setup(struct obd_device *obd, obd_count len, void *buf)
242 struct lustre_cfg *lcfg = buf;
243 struct lmv_desc *desc;
244 struct lmv_obd *lmv = &obd->u.lmv;
245 struct obd_uuid *uuids;
246 struct lmv_tgt_desc *tgts;
252 if (lcfg->lcfg_inllen1 < 1) {
253 CERROR("LMV setup requires a descriptor\n");
257 if (lcfg->lcfg_inllen2 < 1) {
258 CERROR("LMV setup requires an OST UUID list\n");
262 desc = (struct lmv_desc *)lcfg->lcfg_inlbuf1;
263 if (sizeof(*desc) > lcfg->lcfg_inllen1) {
264 CERROR("descriptor size wrong: %d > %d\n",
265 (int)sizeof(*desc), lcfg->lcfg_inllen1);
269 count = desc->ld_count;
270 uuids = (struct obd_uuid *)lcfg->lcfg_inlbuf2;
271 if (sizeof(*uuids) * count != lcfg->lcfg_inllen2) {
272 CERROR("UUID array size wrong: %u * %u != %u\n",
273 sizeof(*uuids), count, lcfg->lcfg_inllen2);
277 lmv->bufsize = sizeof(struct lmv_tgt_desc) * count;
278 OBD_ALLOC(lmv->tgts, lmv->bufsize);
279 if (lmv->tgts == NULL) {
280 CERROR("Out of memory\n");
284 for (i = 0, tgts = lmv->tgts; i < count; i++, tgts++) {
285 tgts->uuid = uuids[i];
289 lmv->max_easize = sizeof(struct ll_fid) * lmv->count
290 + sizeof(struct mea);
291 lmv->max_cookiesize = 0;
296 static int lmv_statfs(struct obd_device *obd, struct obd_statfs *osfs,
297 unsigned long max_age)
299 struct lmv_obd *lmv = &obd->u.lmv;
300 struct obd_statfs temp;
304 for (i = 0; i < lmv->count; i++) {
305 rc = obd_statfs(lmv->tgts[i].exp->exp_obd, &temp, max_age);
307 CERROR("can't stat MDS #%d (%s)\n", i,
308 lmv->tgts[i].exp->exp_obd->obd_name);
312 memcpy(osfs, &temp, sizeof(temp));
314 osfs->os_bavail += temp.os_bavail;
315 osfs->os_blocks += temp.os_blocks;
316 osfs->os_ffree += temp.os_ffree;
317 osfs->os_files += temp.os_files;
323 static int lmv_cleanup(struct obd_device *obd, int flags)
325 struct lmv_obd *lmv = &obd->u.lmv;
327 lmv_cleanup_objs(obd);
328 OBD_FREE(lmv->tgts, lmv->bufsize);
332 static int lmv_getstatus(struct obd_export *exp, struct ll_fid *fid)
334 struct obd_device *obd = exp->exp_obd;
335 struct lmv_obd *lmv = &obd->u.lmv;
339 rc = md_getstatus(lmv->tgts[0].exp, fid);
344 static int lmv_getattr(struct obd_export *exp, struct ll_fid *fid,
345 unsigned long valid, unsigned int ea_size,
346 struct ptlrpc_request **request)
348 struct obd_device *obd = exp->exp_obd;
349 struct lmv_obd *lmv = &obd->u.lmv;
350 int rc, i = fid->mds;
354 obj = lmv_grab_obj(obd, fid, 0);
355 CDEBUG(D_OTHER, "GETATTR for %lu/%lu/%lu %s\n",
356 (unsigned long) fid->mds,
357 (unsigned long) fid->id,
358 (unsigned long) fid->generation,
359 obj ? "(splitted)" : "");
361 LASSERT(fid->mds < lmv->count);
362 rc = md_getattr(lmv->tgts[i].exp, fid,
363 valid, ea_size, request);
364 if (rc == 0 && obj) {
365 /* we have to loop over dirobjs here and gather attrs
366 * for all the slaves */
367 #warning "attrs gathering here"
373 static int lmv_change_cbdata(struct obd_export *exp,
375 ldlm_iterator_t it, void *data)
377 struct obd_device *obd = exp->exp_obd;
378 struct lmv_obd *lmv = &obd->u.lmv;
382 CDEBUG(D_OTHER, "CBDATA for %lu/%lu/%lu\n",
383 (unsigned long) fid->mds,
384 (unsigned long) fid->id,
385 (unsigned long) fid->generation);
386 LASSERT(fid->mds < lmv->count);
387 rc = md_change_cbdata(lmv->tgts[fid->mds].exp, fid, it, data);
391 static int lmv_change_cbdata_name(struct obd_export *exp, struct ll_fid *pfid,
392 char *name, int len, struct ll_fid *cfid,
393 ldlm_iterator_t it, void *data)
395 struct obd_device *obd = exp->exp_obd;
396 struct lmv_obd *lmv = &obd->u.lmv;
401 LASSERT(pfid->mds < lmv->count);
402 LASSERT(cfid->mds < lmv->count);
403 CDEBUG(D_OTHER, "CBDATA for %lu/%lu/%lu:%*s -> %lu/%lu/%lu\n",
404 (unsigned long) pfid->mds, (unsigned long) pfid->id,
405 (unsigned long) pfid->generation, len, name,
406 (unsigned long) cfid->mds, (unsigned long) cfid->id,
407 (unsigned long) cfid->generation);
409 /* this is default mds for directory name belongs to */
411 obj = lmv_grab_obj(obd, pfid, 0);
413 /* directory is splitted. look for right mds for this name */
414 mds = raw_name2idx(obj->objcount, name, len);
417 rc = md_change_cbdata(lmv->tgts[mds].exp, cfid, it, data);
421 static int lmv_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
423 struct obd_device *obd = exp->exp_obd;
424 struct lmv_obd *lmv = &obd->u.lmv;
428 CDEBUG(D_OTHER, "validate %lu/%lu/%lu\n",
429 (unsigned long) fid->mds,
430 (unsigned long) fid->id,
431 (unsigned long) fid->generation);
432 LASSERT(fid->mds < lmv->count);
433 rc = md_valid_attrs(lmv->tgts[fid->mds].exp, fid);
437 int lmv_close(struct obd_export *exp, struct obdo *obdo,
438 struct obd_client_handle *och,
439 struct ptlrpc_request **request)
441 struct obd_device *obd = exp->exp_obd;
442 struct lmv_obd *lmv = &obd->u.lmv;
443 int rc, i = obdo->o_mds;
446 LASSERT(i < lmv->count);
447 CDEBUG(D_OTHER, "CLOSE %lu/%lu/%lu\n", (unsigned long) obdo->o_mds,
448 (unsigned long) obdo->o_id, (unsigned long) obdo->o_generation);
449 rc = md_close(lmv->tgts[i].exp, obdo, och, request);
453 int lmv_create(struct obd_export *exp, struct mdc_op_data *op_data,
454 const void *data, int datalen, int mode, __u32 uid,
455 __u32 gid, __u64 rdev, struct ptlrpc_request **request)
457 struct obd_device *obd = exp->exp_obd;
458 struct lmv_obd *lmv = &obd->u.lmv;
459 struct mea *mea = op_data->mea1;
460 struct mds_body *mds_body;
461 int rc, i, mds, free_mea = 0;
465 /* TODO: where to create new directories?
466 * current design don't support directory on a slave MDS,
467 * but we lookup by name may forward any request in slave
470 obj = lmv_grab_obj(obd, &op_data->fid1, 0);
472 mds = raw_name2idx(obj->objcount, op_data->name,
473 op_data->namelen - 1);
474 op_data->fid1 = obj->objs[mds].fid;
478 CDEBUG(D_OTHER, "CREATE '%*s' on %lu/%lu/%lu (mea 0x%p)\n",
479 op_data->namelen, op_data->name,
480 (unsigned long) op_data->fid1.mds,
481 (unsigned long) op_data->fid1.id,
482 (unsigned long) op_data->fid1.generation, mea);
483 rc = md_create(lmv->tgts[op_data->fid1.mds].exp, op_data, data,
484 datalen, mode, uid, gid, rdev, request);
486 if (*request == NULL)
488 mds_body = lustre_msg_buf((*request)->rq_repmsg, 0,
490 LASSERT(mds_body != NULL);
491 CDEBUG(D_OTHER, "created. id = %lu, generation = %lu, mds = %d\n",
492 (unsigned long) mds_body->fid1.id,
493 (unsigned long) mds_body->fid1.generation,
495 LASSERT(mds_body->valid & OBD_MD_MDS ||
496 mds_body->mds == op_data->fid1.mds);
497 } else if (rc == -ESTALE) {
498 struct ptlrpc_request *req = NULL;
502 LBUG(); /* FIXME ASAP */
503 CDEBUG(D_OTHER, "it seems MDS splitted dir\n");
504 LASSERT(mea == NULL);
506 mealen = sizeof(struct ll_fid)*lmv->count + sizeof(struct mea);
507 /* time to update mea of parent fid */
508 i = op_data->fid1.mds;
509 rc = md_getattr(lmv->tgts[i].exp, &op_data->fid1,
510 OBD_MD_FLEASIZE, mealen, &req);
513 rc = mdc_req2lustre_md(req, 0, NULL, exp, &md);
515 LASSERT(md.mea != NULL);
517 ptlrpc_req_finished(req);
523 obd_free_memmd(exp, (struct lov_stripe_md**) &mea);
527 int lmv_done_writing(struct obd_export *exp, struct obdo *obdo)
529 struct obd_device *obd = exp->exp_obd;
530 struct lmv_obd *lmv = &obd->u.lmv;
534 /* FIXME: choose right MDC here */
535 rc = md_done_writing(lmv->tgts[0].exp, obdo);
539 int lmv_enqueue(struct obd_export *exp, int lock_type,
540 struct lookup_intent *it, int lock_mode,
541 struct mdc_op_data *data, struct lustre_handle *lockh,
542 void *lmm, int lmmsize,
543 ldlm_completion_callback cb_completion,
544 ldlm_blocking_callback cb_blocking, void *cb_data)
546 struct obd_device *obd = exp->exp_obd;
547 struct lmv_obd *lmv = &obd->u.lmv;
553 obj = lmv_grab_obj(obd, &data->fid1, 0);
555 /* directory is splitted. look for
556 * right mds for this name */
557 mds = raw_name2idx(obj->objcount, data->name,
559 data->fid1 = obj->objs[mds].fid;
563 CDEBUG(D_OTHER, "ENQUEUE '%s' on %lu/%lu\n",
564 LL_IT2STR(it), (unsigned long) data->fid1.id,
565 (unsigned long) data->fid1.generation);
566 rc = md_enqueue(lmv->tgts[data->fid1.mds].exp, lock_type, it,
567 lock_mode, data, lockh, lmm, lmmsize, cb_completion,
568 cb_blocking, cb_data);
573 int lmv_getattr_name(struct obd_export *exp, struct ll_fid *fid,
574 char *filename, int namelen, unsigned long valid,
575 unsigned int ea_size, struct ptlrpc_request **request)
577 struct obd_device *obd = exp->exp_obd;
578 struct lmv_obd *lmv = &obd->u.lmv;
579 struct ll_fid rfid = *fid;
580 int rc, mds = fid->mds;
584 CDEBUG(D_OTHER, "getattr_name for %*s on %lu/%lu/%lu\n",
585 namelen - 1, filename, (unsigned long) fid->mds,
586 (unsigned long) fid->id, (unsigned long) fid->generation);
587 obj = lmv_grab_obj(obd, fid, 0);
589 /* directory is splitted. look for right mds for this name */
590 mds = raw_name2idx(obj->objcount, filename, namelen - 1);
591 rfid = obj->objs[mds].fid;
594 rc = md_getattr_name(lmv->tgts[mds].exp, &rfid, filename, namelen,
595 valid, ea_size, request);
601 * llite passes fid of an target inode in data->fid1 and
602 * fid of directory in data->fid2
604 int lmv_link(struct obd_export *exp, struct mdc_op_data *data,
605 struct ptlrpc_request **request)
607 struct obd_device *obd = exp->exp_obd;
608 struct lmv_obd *lmv = &obd->u.lmv;
613 if (data->namelen != 0) {
614 /* usual link request */
615 obj = lmv_grab_obj(obd, &data->fid1, 0);
617 rc = raw_name2idx(obj->objcount, data->name,
619 data->fid1 = obj->objs[rc].fid;
622 CDEBUG(D_OTHER,"link %u/%u/%u:%*s to %u/%u/%u mds %d\n",
623 (unsigned) data->fid2.mds, (unsigned) data->fid2.id,
624 (unsigned) data->fid2.generation, data->namelen,
625 data->name, (unsigned) data->fid1.mds,
626 (unsigned) data->fid1.id,
627 (unsigned) data->fid1.generation, data->fid1.mds);
629 /* request from MDS to acquire i_links for inode by fid1 */
630 CDEBUG(D_OTHER, "inc i_nlinks for %u/%u/%u\n",
631 (unsigned) data->fid1.mds, (unsigned) data->fid1.id,
632 (unsigned) data->fid1.generation);
635 rc = md_link(lmv->tgts[data->fid1.mds].exp, data, request);
639 int lmv_rename(struct obd_export *exp, struct mdc_op_data *data,
640 const char *old, int oldlen, const char *new, int newlen,
641 struct ptlrpc_request **request)
643 struct obd_device *obd = exp->exp_obd;
644 struct lmv_obd *lmv = &obd->u.lmv;
649 CDEBUG(D_OTHER, "rename %*s in %lu/%lu/%lu to %*s in %lu/%lu/%lu\n",
650 oldlen, old, (unsigned long) data->fid1.mds,
651 (unsigned long) data->fid1.id,
652 (unsigned long) data->fid1.generation,
653 newlen, new, (unsigned long) data->fid2.mds,
654 (unsigned long) data->fid2.id,
655 (unsigned long) data->fid2.generation);
660 /* MDS with old dir entry is asking another MDS
661 * to create name there */
663 "create %*s(%d/%d) in %lu/%lu/%lu pointing to %lu/%lu/%lu\n",
664 newlen, new, oldlen, newlen,
665 (unsigned long) data->fid2.mds,
666 (unsigned long) data->fid2.id,
667 (unsigned long) data->fid2.generation,
668 (unsigned long) data->fid1.mds,
669 (unsigned long) data->fid1.id,
670 (unsigned long) data->fid1.generation);
671 mds = data->fid2.mds;
675 obj = lmv_grab_obj(obd, &data->fid1, 0);
677 /* directory is already splitted, so we have to forward
678 * request to the right MDS */
679 mds = raw_name2idx(obj->objcount, old, oldlen);
680 data->fid1 = obj->objs[mds].fid;
681 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
682 (unsigned long) obj->objs[mds].fid.mds,
683 (unsigned long) obj->objs[mds].fid.id,
684 (unsigned long) obj->objs[mds].fid.generation);
688 obj = lmv_grab_obj(obd, &data->fid2, 0);
690 /* directory is already splitted, so we have to forward
691 * request to the right MDS */
692 mds = raw_name2idx(obj->objcount, new, newlen);
693 data->fid2 = obj->objs[mds].fid;
694 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
695 (unsigned long) obj->objs[mds].fid.mds,
696 (unsigned long) obj->objs[mds].fid.id,
697 (unsigned long) obj->objs[mds].fid.generation);
701 mds = data->fid1.mds;
704 rc = md_rename(lmv->tgts[mds].exp, data, old, oldlen,
705 new, newlen, request);
709 int lmv_setattr(struct obd_export *exp, struct mdc_op_data *data,
710 struct iattr *iattr, void *ea, int ealen, void *ea2, int ea2len,
711 struct ptlrpc_request **request)
713 struct obd_device *obd = exp->exp_obd;
714 struct lmv_obd *lmv = &obd->u.lmv;
715 int rc = 0, i = data->fid1.mds;
716 struct ptlrpc_request *req;
717 struct mds_body *mds_body;
721 obj = lmv_grab_obj(obd, &data->fid1, 0);
722 CDEBUG(D_OTHER, "SETATTR for %lu/%lu/%lu, valid 0x%x%s\n",
723 (unsigned long) data->fid1.mds,
724 (unsigned long) data->fid1.id,
725 (unsigned long) data->fid1.generation, iattr->ia_valid,
726 obj ? ", splitted" : "");
728 for (i = 0; i < obj->objcount; i++) {
729 data->fid1 = obj->objs[i].fid;
730 rc = md_setattr(lmv->tgts[i].exp, data, iattr, ea,
731 ealen, ea2, ea2len, &req);
733 if (fid_equal(&obj->fid, &obj->objs[i].fid)) {
734 /* this is master object and this request
735 * should be returned back to llite */
738 ptlrpc_req_finished(req);
743 LASSERT(data->fid1.mds < lmv->count);
744 rc = md_setattr(lmv->tgts[i].exp, data, iattr, ea, ealen,
745 ea2, ea2len, request);
747 mds_body = lustre_msg_buf((*request)->rq_repmsg, 0,
749 LASSERT(mds_body != NULL);
750 LASSERT(mds_body->mds == i);
756 int lmv_sync(struct obd_export *exp, struct ll_fid *fid,
757 struct ptlrpc_request **request)
759 struct obd_device *obd = exp->exp_obd;
760 struct lmv_obd *lmv = &obd->u.lmv;
764 rc = md_sync(lmv->tgts[0].exp, fid, request);
768 int lmv_dirobj_blocking_ast(struct ldlm_lock *lock,
769 struct ldlm_lock_desc *desc, void *data, int flag)
771 struct lustre_handle lockh;
777 case LDLM_CB_BLOCKING:
778 ldlm_lock2handle(lock, &lockh);
779 rc = ldlm_cli_cancel(&lockh);
781 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
785 case LDLM_CB_CANCELING:
786 /* time to drop cached attrs for dirobj */
787 obj = lock->l_ast_data;
791 CDEBUG(D_OTHER, "cancel %s on %lu/%lu, master %lu/%lu/%lu\n",
792 lock->l_resource->lr_name.name[3] == 1 ?
794 (unsigned long) lock->l_resource->lr_name.name[0],
795 (unsigned long) lock->l_resource->lr_name.name[1],
796 (unsigned long) obj->fid.mds,
797 (unsigned long) obj->fid.id,
798 (unsigned long) obj->fid.generation);
806 void lmv_remove_dots(struct page *page)
808 char *kaddr = page_address(page);
809 unsigned limit = PAGE_CACHE_SIZE;
810 unsigned offs, rec_len;
811 struct ext2_dir_entry_2 *p;
813 for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
814 p = (struct ext2_dir_entry_2 *)(kaddr + offs);
815 rec_len = le16_to_cpu(p->rec_len);
817 if ((p->name_len == 1 && p->name[0] == '.') ||
818 (p->name_len == 2 && p->name[0] == '.' && p->name[1] == '.'))
823 int lmv_readpage(struct obd_export *exp, struct ll_fid *mdc_fid,
824 __u64 offset, struct page *page,
825 struct ptlrpc_request **request)
827 struct obd_device *obd = exp->exp_obd;
828 struct lmv_obd *lmv = &obd->u.lmv;
829 struct ll_fid rfid = *mdc_fid;
835 LASSERT(mdc_fid->mds < lmv->count);
836 CDEBUG(D_OTHER, "READPAGE at %llu from %lu/%lu/%lu\n",
837 offset, (unsigned long) rfid.mds,
838 (unsigned long) rfid.id,
839 (unsigned long) rfid.generation);
841 obj = lmv_grab_obj(obd, mdc_fid, 0);
843 /* find dirobj containing page with requested offset */
844 /* FIXME: what about protecting cached attrs here? */
845 for (i = 0; i < obj->objcount; i++) {
846 if (offset < obj->objs[i].size)
848 offset -= obj->objs[i].size;
850 rfid = obj->objs[i].fid;
851 CDEBUG(D_OTHER, "forward to %lu/%lu/%lu with offset %lu\n",
852 (unsigned long) rfid.mds,
853 (unsigned long) rfid.id,
854 (unsigned long) rfid.generation,
855 (unsigned long) offset);
857 rc = md_readpage(lmv->tgts[rfid.mds].exp, &rfid, offset, page, request);
858 if (rc == 0 && !fid_equal(&rfid, mdc_fid)) {
859 /* this page isn't from master object. to avoid
860 * ./.. duplication in directory, we have to remove them
861 * from all slave objects */
862 lmv_remove_dots(page);
870 int lmv_unlink(struct obd_export *exp, struct mdc_op_data *data,
871 struct ptlrpc_request **request)
873 struct obd_device *obd = exp->exp_obd;
874 struct lmv_obd *lmv = &obd->u.lmv;
878 if (data->namelen != 0) {
880 obj = lmv_grab_obj(obd, &data->fid1, 0);
882 i = raw_name2idx(obj->objcount, data->name,
884 data->fid1 = obj->objs[i].fid;
887 CDEBUG(D_OTHER, "unlink '%*s' in %lu/%lu/%lu -> %u\n",
888 data->namelen, data->name,
889 (unsigned long) data->fid1.mds,
890 (unsigned long) data->fid1.id,
891 (unsigned long) data->fid1.generation, i);
893 CDEBUG(D_OTHER, "drop i_nlink on %lu/%lu/%lu\n",
894 (unsigned long) data->fid1.mds,
895 (unsigned long) data->fid1.id,
896 (unsigned long) data->fid1.generation);
898 rc = md_unlink(lmv->tgts[data->fid1.mds].exp, data, request);
902 struct obd_device *lmv_get_real_obd(struct obd_export *exp,
905 struct obd_device *obd = exp->exp_obd;
906 struct lmv_obd *lmv = &obd->u.lmv;
909 obd = lmv->tgts[0].exp->exp_obd;
914 int lmv_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
916 struct obd_device *obd = exp->exp_obd;
917 struct lmv_obd *lmv = &obd->u.lmv;
918 int i, rc = 0, change = 0;
921 if (lmv->max_easize < easize) {
922 lmv->max_easize = easize;
925 if (lmv->max_cookiesize < cookiesize) {
926 lmv->max_cookiesize = cookiesize;
932 if (lmv->connected == 0)
935 /* FIXME: error handling? */
936 for (i = 0; i < lmv->count; i++)
937 rc = obd_init_ea_size(lmv->tgts[i].exp, easize, cookiesize);
941 int lmv_obd_create_single(struct obd_export *exp, struct obdo *oa,
942 struct lov_stripe_md **ea, struct obd_trans_info *oti)
944 struct obd_device *obd = exp->exp_obd;
945 struct lmv_obd *lmv = &obd->u.lmv;
946 struct lov_stripe_md obj_md;
947 struct lov_stripe_md *obj_mdp = &obj_md;
953 LASSERT(oa->o_mds < lmv->count);
955 rc = obd_create(lmv->tgts[oa->o_mds].exp, oa, &obj_mdp, oti);
962 * to be called from MDS only
964 int lmv_obd_create(struct obd_export *exp, struct obdo *oa,
965 struct lov_stripe_md **ea, struct obd_trans_info *oti)
967 struct obd_device *obd = exp->exp_obd;
968 struct lmv_obd *lmv = &obd->u.lmv;
978 rc = lmv_obd_create_single(exp, oa, NULL, oti);
983 rc = obd_alloc_diskmd(exp, (struct lov_mds_md **) ea);
984 LASSERT(*ea != NULL);
987 mea = (struct mea *) *ea;
989 mfid.generation = oa->o_generation;
991 if (!mea->mea_count || mea->mea_count > lmv->count)
992 mea->mea_count = lmv->count;
994 mea->mea_master = -1;
996 /* FIXME: error handling? */
997 for (i = 0, c = 0; c < mea->mea_count && i < lmv->count; i++) {
998 struct lov_stripe_md obj_md;
999 struct lov_stripe_md *obj_mdp = &obj_md;
1001 if (lmv->tgts[i].exp == NULL) {
1002 /* this is master MDS */
1003 mea->mea_fids[c].id = mfid.id;
1004 mea->mea_fids[c].generation = mfid.generation;
1005 mea->mea_fids[c].mds = i;
1006 mea->mea_master = i;
1011 /* "Master" MDS should always be part of stripped dir, so
1013 if (mea->mea_master == -1 && c == mea->mea_count - 1)
1016 oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLTYPE | OBD_MD_FLMODE
1017 | OBD_MD_FLUID | OBD_MD_FLGID;
1019 rc = obd_create(lmv->tgts[c].exp, oa, &obj_mdp, oti);
1020 /* FIXME: error handling here */
1023 mea->mea_fids[c].id = oa->o_id;
1024 mea->mea_fids[c].generation = oa->o_generation;
1025 mea->mea_fids[c].mds = i;
1027 CDEBUG(D_OTHER, "dirobj at mds %d: "LPU64"/%u\n",
1028 i, oa->o_id, oa->o_generation);
1030 LASSERT(c == mea->mea_count);
1031 CDEBUG(D_OTHER, "%d dirobjects created\n", (int) mea->mea_count);
1036 static int lmv_get_info(struct obd_export *exp, __u32 keylen,
1037 void *key, __u32 *vallen, void *val)
1039 struct obd_device *obd;
1040 struct lmv_obd *lmv;
1043 obd = class_exp2obd(exp);
1045 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1046 exp->exp_handle.h_cookie);
1051 if (keylen == 6 && memcmp(key, "mdsize", 6) == 0) {
1052 __u32 *mdsize = val;
1053 *vallen = sizeof(__u32);
1054 *mdsize = sizeof(struct ll_fid) * lmv->count
1055 + sizeof(struct mea);
1057 } else if (keylen == 6 && memcmp(key, "mdsnum", 6) == 0) {
1058 struct obd_uuid *cluuid = &lmv->cluuid;
1059 struct lmv_tgt_desc *tgts;
1060 __u32 *mdsnum = val;
1063 for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
1064 if (obd_uuid_equals(&tgts->uuid, cluuid)) {
1065 *vallen = sizeof(__u32);
1073 CDEBUG(D_IOCTL, "invalid key\n");
1077 int lmv_set_info(struct obd_export *exp, obd_count keylen,
1078 void *key, obd_count vallen, void *val)
1080 struct obd_device *obd;
1081 struct lmv_obd *lmv;
1084 obd = class_exp2obd(exp);
1086 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1087 exp->exp_handle.h_cookie);
1093 if (keylen >= strlen("client") && strcmp(key, "client") == 0) {
1094 struct lmv_tgt_desc *tgts;
1097 for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
1098 rc = obd_set_info(tgts->exp, keylen, key, vallen, val);
1108 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
1109 struct lov_stripe_md *lsm)
1111 struct obd_device *obd = class_exp2obd(exp);
1112 struct lmv_obd *lmv = &obd->u.lmv;
1116 mea_size = sizeof(struct ll_fid) * lmv->count + sizeof(struct mea);
1120 if (*lmmp && !lsm) {
1121 OBD_FREE(*lmmp, mea_size);
1127 OBD_ALLOC(*lmmp, mea_size);
1135 #warning "MEA packing/convertation must be here! -bzzz"
1136 memcpy(*lmmp, lsm, mea_size);
1140 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **mem_tgt,
1141 struct lov_mds_md *disk_src, int mdsize)
1143 struct obd_device *obd = class_exp2obd(exp);
1144 struct lmv_obd *lmv = &obd->u.lmv;
1145 struct mea **tmea = (struct mea **) mem_tgt;
1146 struct mea *mea = (void *) disk_src;
1150 mea_size = sizeof(struct ll_fid) * lmv->count + sizeof(struct mea);
1151 if (mem_tgt == NULL)
1154 if (*mem_tgt != NULL && disk_src == NULL) {
1155 OBD_FREE(*tmea, mea_size);
1159 LASSERT(mea_size == mdsize);
1161 OBD_ALLOC(*tmea, mea_size);
1162 /* FIXME: error handling here */
1163 LASSERT(*tmea != NULL);
1168 #warning "MEA unpacking/convertation must be here! -bzzz"
1169 memcpy(*tmea, mea, mdsize);
1173 int lmv_brw(int rw, struct obd_export *exp, struct obdo *oa,
1174 struct lov_stripe_md *ea, obd_count oa_bufs,
1175 struct brw_page *pgarr, struct obd_trans_info *oti)
1177 struct obd_device *obd = exp->exp_obd;
1178 struct lmv_obd *lmv = &obd->u.lmv;
1179 struct mea *mea = (struct mea *) ea;
1182 LASSERT(oa != NULL);
1183 LASSERT(ea != NULL);
1184 LASSERT(pgarr != NULL);
1185 LASSERT(oa->o_mds < lmv->count);
1187 oa->o_gr = mea->mea_fids[oa->o_mds].generation;
1188 oa->o_id = mea->mea_fids[oa->o_mds].id;
1189 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1190 err = obd_brw(rw, lmv->tgts[oa->o_mds].exp, oa,
1191 NULL, oa_bufs, pgarr, oti);
1195 struct obd_ops lmv_obd_ops = {
1196 o_owner: THIS_MODULE,
1197 o_attach: lmv_attach,
1198 o_detach: lmv_detach,
1200 o_cleanup: lmv_cleanup,
1201 o_connect: lmv_connect_fake,
1202 o_disconnect: lmv_disconnect,
1203 o_statfs: lmv_statfs,
1204 o_get_info: lmv_get_info,
1205 o_set_info: lmv_set_info,
1206 o_create: lmv_obd_create,
1207 o_packmd: lmv_packmd,
1208 o_unpackmd: lmv_unpackmd,
1210 o_init_ea_size: lmv_init_ea_size,
1213 struct md_ops lmv_md_ops = {
1214 m_getstatus: lmv_getstatus,
1215 m_getattr: lmv_getattr,
1216 m_change_cbdata: lmv_change_cbdata,
1217 m_change_cbdata_name: lmv_change_cbdata_name,
1219 m_create: lmv_create,
1220 m_done_writing: lmv_done_writing,
1221 m_enqueue: lmv_enqueue,
1222 m_getattr_name: lmv_getattr_name,
1223 m_intent_lock: lmv_intent_lock,
1225 m_rename: lmv_rename,
1226 m_setattr: lmv_setattr,
1228 m_readpage: lmv_readpage,
1229 m_unlink: lmv_unlink,
1230 m_get_real_obd: lmv_get_real_obd,
1231 m_valid_attrs: lmv_valid_attrs,
1235 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
1236 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
1238 LPROCFS_INIT_VARS(lmv, lprocfs_module_vars, lprocfs_obd_vars)
1240 int __init lmv_init(void)
1242 struct lprocfs_static_vars lvars;
1245 lprocfs_init_vars(lmv, &lvars);
1246 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
1247 lvars.module_vars, OBD_LMV_DEVICENAME);
1251 static void lmv_exit(void)
1253 class_unregister_type(OBD_LMV_DEVICENAME);
1257 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1258 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
1259 MODULE_LICENSE("GPL");
1261 module_init(lmv_init);
1262 module_exit(lmv_exit);