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 int lmv_connect(struct obd_device *obd)
111 struct lmv_obd *lmv = &obd->u.lmv;
112 struct obd_uuid *cluuid;
113 struct lmv_tgt_desc *tgts;
114 struct obd_export *exp;
122 cluuid = &lmv->cluuid;
124 CDEBUG(D_OTHER, "time to connect %s to %s\n",
125 cluuid->uuid, obd->obd_name);
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_get_mea_and_update_object(struct obd_export *exp, struct ll_fid *fid)
455 struct obd_device *obd = exp->exp_obd;
456 struct lmv_obd *lmv = &obd->u.lmv;
457 struct ptlrpc_request *req = NULL;
462 mealen = MEA_SIZE_LMV(lmv);
464 /* time to update mea of parent fid */
465 rc = md_getattr(lmv->tgts[fid->mds].exp, fid,
466 OBD_MD_FLEASIZE, mealen, &req);
469 rc = mdc_req2lustre_md(req, 0, NULL, exp, &md);
473 GOTO(cleanup, rc = -ENODATA);
474 rc = lmv_create_obj_from_attrs(exp, fid, md.mea);
475 obd_free_memmd(exp, (struct lov_stripe_md **) &md.mea);
479 ptlrpc_req_finished(req);
483 int lmv_create(struct obd_export *exp, struct mdc_op_data *op_data,
484 const void *data, int datalen, int mode, __u32 uid,
485 __u32 gid, __u64 rdev, struct ptlrpc_request **request)
487 struct obd_device *obd = exp->exp_obd;
488 struct lmv_obd *lmv = &obd->u.lmv;
489 struct mds_body *mds_body;
496 obj = lmv_grab_obj(obd, &op_data->fid1, 0);
498 mds = raw_name2idx(obj->objcount, op_data->name,
500 op_data->fid1 = obj->objs[mds].fid;
504 CDEBUG(D_OTHER, "CREATE '%*s' on %lu/%lu/%lu\n",
505 op_data->namelen, op_data->name,
506 (unsigned long) op_data->fid1.mds,
507 (unsigned long) op_data->fid1.id,
508 (unsigned long) op_data->fid1.generation);
509 rc = md_create(lmv->tgts[op_data->fid1.mds].exp, op_data, data,
510 datalen, mode, uid, gid, rdev, request);
512 if (*request == NULL)
514 mds_body = lustre_msg_buf((*request)->rq_repmsg, 0,
516 LASSERT(mds_body != NULL);
517 CDEBUG(D_OTHER, "created. id = %lu, generation = %lu, mds = %d\n",
518 (unsigned long) mds_body->fid1.id,
519 (unsigned long) mds_body->fid1.generation,
521 LASSERT(mds_body->valid & OBD_MD_MDS ||
522 mds_body->mds == op_data->fid1.mds);
523 } else if (rc == -ERESTART) {
524 /* directory got splitted. time to update local object
525 * and repeat the request with proper MDS */
526 rc = lmv_get_mea_and_update_object(exp, &op_data->fid1);
528 ptlrpc_req_finished(*request);
535 int lmv_done_writing(struct obd_export *exp, struct obdo *obdo)
537 struct obd_device *obd = exp->exp_obd;
538 struct lmv_obd *lmv = &obd->u.lmv;
542 /* FIXME: choose right MDC here */
543 rc = md_done_writing(lmv->tgts[0].exp, obdo);
547 int lmv_enqueue(struct obd_export *exp, int lock_type,
548 struct lookup_intent *it, int lock_mode,
549 struct mdc_op_data *data, struct lustre_handle *lockh,
550 void *lmm, int lmmsize,
551 ldlm_completion_callback cb_completion,
552 ldlm_blocking_callback cb_blocking, void *cb_data)
554 struct obd_device *obd = exp->exp_obd;
555 struct lmv_obd *lmv = &obd->u.lmv;
561 obj = lmv_grab_obj(obd, &data->fid1, 0);
563 /* directory is splitted. look for
564 * right mds for this name */
565 mds = raw_name2idx(obj->objcount, data->name,
567 data->fid1 = obj->objs[mds].fid;
571 CDEBUG(D_OTHER, "ENQUEUE '%s' on %lu/%lu\n",
572 LL_IT2STR(it), (unsigned long) data->fid1.id,
573 (unsigned long) data->fid1.generation);
574 rc = md_enqueue(lmv->tgts[data->fid1.mds].exp, lock_type, it,
575 lock_mode, data, lockh, lmm, lmmsize, cb_completion,
576 cb_blocking, cb_data);
581 int lmv_getattr_name(struct obd_export *exp, struct ll_fid *fid,
582 char *filename, int namelen, unsigned long valid,
583 unsigned int ea_size, struct ptlrpc_request **request)
585 struct obd_device *obd = exp->exp_obd;
586 struct lmv_obd *lmv = &obd->u.lmv;
587 struct ll_fid rfid = *fid;
588 int rc, mds = fid->mds;
592 CDEBUG(D_OTHER, "getattr_name for %*s on %lu/%lu/%lu\n",
593 namelen, filename, (unsigned long) fid->mds,
594 (unsigned long) fid->id, (unsigned long) fid->generation);
595 obj = lmv_grab_obj(obd, fid, 0);
597 /* directory is splitted. look for right mds for this name */
598 mds = raw_name2idx(obj->objcount, filename, namelen);
599 rfid = obj->objs[mds].fid;
602 rc = md_getattr_name(lmv->tgts[mds].exp, &rfid, filename, namelen,
603 valid, ea_size, request);
609 * llite passes fid of an target inode in data->fid1 and
610 * fid of directory in data->fid2
612 int lmv_link(struct obd_export *exp, struct mdc_op_data *data,
613 struct ptlrpc_request **request)
615 struct obd_device *obd = exp->exp_obd;
616 struct lmv_obd *lmv = &obd->u.lmv;
621 if (data->namelen != 0) {
622 /* usual link request */
623 obj = lmv_grab_obj(obd, &data->fid1, 0);
625 rc = raw_name2idx(obj->objcount, data->name,
627 data->fid1 = obj->objs[rc].fid;
630 CDEBUG(D_OTHER,"link %u/%u/%u:%*s to %u/%u/%u mds %d\n",
631 (unsigned) data->fid2.mds, (unsigned) data->fid2.id,
632 (unsigned) data->fid2.generation, data->namelen,
633 data->name, (unsigned) data->fid1.mds,
634 (unsigned) data->fid1.id,
635 (unsigned) data->fid1.generation, data->fid1.mds);
637 /* request from MDS to acquire i_links for inode by fid1 */
638 CDEBUG(D_OTHER, "inc i_nlinks for %u/%u/%u\n",
639 (unsigned) data->fid1.mds, (unsigned) data->fid1.id,
640 (unsigned) data->fid1.generation);
643 rc = md_link(lmv->tgts[data->fid1.mds].exp, data, request);
647 int lmv_rename(struct obd_export *exp, struct mdc_op_data *data,
648 const char *old, int oldlen, const char *new, int newlen,
649 struct ptlrpc_request **request)
651 struct obd_device *obd = exp->exp_obd;
652 struct lmv_obd *lmv = &obd->u.lmv;
657 CDEBUG(D_OTHER, "rename %*s in %lu/%lu/%lu to %*s in %lu/%lu/%lu\n",
658 oldlen, old, (unsigned long) data->fid1.mds,
659 (unsigned long) data->fid1.id,
660 (unsigned long) data->fid1.generation,
661 newlen, new, (unsigned long) data->fid2.mds,
662 (unsigned long) data->fid2.id,
663 (unsigned long) data->fid2.generation);
668 /* MDS with old dir entry is asking another MDS
669 * to create name there */
671 "create %*s(%d/%d) in %lu/%lu/%lu pointing to %lu/%lu/%lu\n",
672 newlen, new, oldlen, newlen,
673 (unsigned long) data->fid2.mds,
674 (unsigned long) data->fid2.id,
675 (unsigned long) data->fid2.generation,
676 (unsigned long) data->fid1.mds,
677 (unsigned long) data->fid1.id,
678 (unsigned long) data->fid1.generation);
679 mds = data->fid2.mds;
683 obj = lmv_grab_obj(obd, &data->fid1, 0);
685 /* directory is already splitted, so we have to forward
686 * request to the right MDS */
687 mds = raw_name2idx(obj->objcount, old, oldlen);
688 data->fid1 = obj->objs[mds].fid;
689 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
690 (unsigned long) obj->objs[mds].fid.mds,
691 (unsigned long) obj->objs[mds].fid.id,
692 (unsigned long) obj->objs[mds].fid.generation);
696 obj = lmv_grab_obj(obd, &data->fid2, 0);
698 /* directory is already splitted, so we have to forward
699 * request to the right MDS */
700 mds = raw_name2idx(obj->objcount, new, newlen);
701 data->fid2 = obj->objs[mds].fid;
702 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
703 (unsigned long) obj->objs[mds].fid.mds,
704 (unsigned long) obj->objs[mds].fid.id,
705 (unsigned long) obj->objs[mds].fid.generation);
709 mds = data->fid1.mds;
712 rc = md_rename(lmv->tgts[mds].exp, data, old, oldlen,
713 new, newlen, request);
717 int lmv_setattr(struct obd_export *exp, struct mdc_op_data *data,
718 struct iattr *iattr, void *ea, int ealen, void *ea2, int ea2len,
719 struct ptlrpc_request **request)
721 struct obd_device *obd = exp->exp_obd;
722 struct lmv_obd *lmv = &obd->u.lmv;
723 int rc = 0, i = data->fid1.mds;
724 struct ptlrpc_request *req;
725 struct mds_body *mds_body;
729 obj = lmv_grab_obj(obd, &data->fid1, 0);
730 CDEBUG(D_OTHER, "SETATTR for %lu/%lu/%lu, valid 0x%x%s\n",
731 (unsigned long) data->fid1.mds,
732 (unsigned long) data->fid1.id,
733 (unsigned long) data->fid1.generation, iattr->ia_valid,
734 obj ? ", splitted" : "");
736 for (i = 0; i < obj->objcount; i++) {
737 data->fid1 = obj->objs[i].fid;
738 rc = md_setattr(lmv->tgts[i].exp, data, iattr, ea,
739 ealen, ea2, ea2len, &req);
741 if (fid_equal(&obj->fid, &obj->objs[i].fid)) {
742 /* this is master object and this request
743 * should be returned back to llite */
746 ptlrpc_req_finished(req);
751 LASSERT(data->fid1.mds < lmv->count);
752 rc = md_setattr(lmv->tgts[i].exp, data, iattr, ea, ealen,
753 ea2, ea2len, request);
755 mds_body = lustre_msg_buf((*request)->rq_repmsg, 0,
757 LASSERT(mds_body != NULL);
758 LASSERT(mds_body->mds == i);
764 int lmv_sync(struct obd_export *exp, struct ll_fid *fid,
765 struct ptlrpc_request **request)
767 struct obd_device *obd = exp->exp_obd;
768 struct lmv_obd *lmv = &obd->u.lmv;
772 rc = md_sync(lmv->tgts[0].exp, fid, request);
776 int lmv_dirobj_blocking_ast(struct ldlm_lock *lock,
777 struct ldlm_lock_desc *desc, void *data, int flag)
779 struct lustre_handle lockh;
785 case LDLM_CB_BLOCKING:
786 ldlm_lock2handle(lock, &lockh);
787 rc = ldlm_cli_cancel(&lockh);
789 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
793 case LDLM_CB_CANCELING:
794 /* time to drop cached attrs for dirobj */
795 obj = lock->l_ast_data;
799 CDEBUG(D_OTHER, "cancel %s on %lu/%lu, master %lu/%lu/%lu\n",
800 lock->l_resource->lr_name.name[3] == 1 ?
802 (unsigned long) lock->l_resource->lr_name.name[0],
803 (unsigned long) lock->l_resource->lr_name.name[1],
804 (unsigned long) obj->fid.mds,
805 (unsigned long) obj->fid.id,
806 (unsigned long) obj->fid.generation);
814 void lmv_remove_dots(struct page *page)
816 char *kaddr = page_address(page);
817 unsigned limit = PAGE_CACHE_SIZE;
818 unsigned offs, rec_len;
819 struct ext2_dir_entry_2 *p;
821 for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
822 p = (struct ext2_dir_entry_2 *)(kaddr + offs);
823 rec_len = le16_to_cpu(p->rec_len);
825 if ((p->name_len == 1 && p->name[0] == '.') ||
826 (p->name_len == 2 && p->name[0] == '.' && p->name[1] == '.'))
831 int lmv_readpage(struct obd_export *exp, struct ll_fid *mdc_fid,
832 __u64 offset, struct page *page,
833 struct ptlrpc_request **request)
835 struct obd_device *obd = exp->exp_obd;
836 struct lmv_obd *lmv = &obd->u.lmv;
837 struct ll_fid rfid = *mdc_fid;
843 LASSERT(mdc_fid->mds < lmv->count);
844 CDEBUG(D_OTHER, "READPAGE at %llu from %lu/%lu/%lu\n",
845 offset, (unsigned long) rfid.mds,
846 (unsigned long) rfid.id,
847 (unsigned long) rfid.generation);
849 obj = lmv_grab_obj(obd, mdc_fid, 0);
851 /* find dirobj containing page with requested offset */
852 /* FIXME: what about protecting cached attrs here? */
853 for (i = 0; i < obj->objcount; i++) {
854 if (offset < obj->objs[i].size)
856 offset -= obj->objs[i].size;
858 rfid = obj->objs[i].fid;
859 CDEBUG(D_OTHER, "forward to %lu/%lu/%lu with offset %lu\n",
860 (unsigned long) rfid.mds,
861 (unsigned long) rfid.id,
862 (unsigned long) rfid.generation,
863 (unsigned long) offset);
865 rc = md_readpage(lmv->tgts[rfid.mds].exp, &rfid, offset, page, request);
866 if (rc == 0 && !fid_equal(&rfid, mdc_fid)) {
867 /* this page isn't from master object. to avoid
868 * ./.. duplication in directory, we have to remove them
869 * from all slave objects */
870 lmv_remove_dots(page);
878 int lmv_unlink(struct obd_export *exp, struct mdc_op_data *data,
879 struct ptlrpc_request **request)
881 struct obd_device *obd = exp->exp_obd;
882 struct lmv_obd *lmv = &obd->u.lmv;
886 if (data->namelen != 0) {
888 obj = lmv_grab_obj(obd, &data->fid1, 0);
890 i = raw_name2idx(obj->objcount, data->name,
892 data->fid1 = obj->objs[i].fid;
895 CDEBUG(D_OTHER, "unlink '%*s' in %lu/%lu/%lu -> %u\n",
896 data->namelen, data->name,
897 (unsigned long) data->fid1.mds,
898 (unsigned long) data->fid1.id,
899 (unsigned long) data->fid1.generation, i);
901 CDEBUG(D_OTHER, "drop i_nlink on %lu/%lu/%lu\n",
902 (unsigned long) data->fid1.mds,
903 (unsigned long) data->fid1.id,
904 (unsigned long) data->fid1.generation);
906 rc = md_unlink(lmv->tgts[data->fid1.mds].exp, data, request);
910 struct obd_device *lmv_get_real_obd(struct obd_export *exp,
913 struct obd_device *obd = exp->exp_obd;
914 struct lmv_obd *lmv = &obd->u.lmv;
917 obd = lmv->tgts[0].exp->exp_obd;
922 int lmv_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
924 struct obd_device *obd = exp->exp_obd;
925 struct lmv_obd *lmv = &obd->u.lmv;
926 int i, rc = 0, change = 0;
929 if (lmv->max_easize < easize) {
930 lmv->max_easize = easize;
933 if (lmv->max_cookiesize < cookiesize) {
934 lmv->max_cookiesize = cookiesize;
940 if (lmv->connected == 0)
943 /* FIXME: error handling? */
944 for (i = 0; i < lmv->count; i++)
945 rc = obd_init_ea_size(lmv->tgts[i].exp, easize, cookiesize);
949 int lmv_obd_create_single(struct obd_export *exp, struct obdo *oa,
950 struct lov_stripe_md **ea, struct obd_trans_info *oti)
952 struct obd_device *obd = exp->exp_obd;
953 struct lmv_obd *lmv = &obd->u.lmv;
954 struct lov_stripe_md obj_md;
955 struct lov_stripe_md *obj_mdp = &obj_md;
961 LASSERT(oa->o_mds < lmv->count);
963 rc = obd_create(lmv->tgts[oa->o_mds].exp, oa, &obj_mdp, oti);
970 * to be called from MDS only
972 int lmv_obd_create(struct obd_export *exp, struct obdo *oa,
973 struct lov_stripe_md **ea, struct obd_trans_info *oti)
975 struct obd_device *obd = exp->exp_obd;
976 struct lmv_obd *lmv = &obd->u.lmv;
986 rc = lmv_obd_create_single(exp, oa, NULL, oti);
991 rc = obd_alloc_diskmd(exp, (struct lov_mds_md **) ea);
992 LASSERT(*ea != NULL);
995 mea = (struct mea *) *ea;
997 mfid.generation = oa->o_generation;
999 if (!mea->mea_count || mea->mea_count > lmv->count)
1000 mea->mea_count = lmv->count;
1002 mea->mea_master = -1;
1004 /* FIXME: error handling? */
1005 for (i = 0, c = 0; c < mea->mea_count && i < lmv->count; i++) {
1006 struct lov_stripe_md obj_md;
1007 struct lov_stripe_md *obj_mdp = &obj_md;
1009 if (lmv->tgts[i].exp == NULL) {
1010 /* this is master MDS */
1011 mea->mea_fids[c].id = mfid.id;
1012 mea->mea_fids[c].generation = mfid.generation;
1013 mea->mea_fids[c].mds = i;
1014 mea->mea_master = i;
1019 /* "Master" MDS should always be part of stripped dir, so
1021 if (mea->mea_master == -1 && c == mea->mea_count - 1)
1024 oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLTYPE | OBD_MD_FLMODE
1025 | OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLID;
1027 rc = obd_create(lmv->tgts[c].exp, oa, &obj_mdp, oti);
1028 /* FIXME: error handling here */
1031 mea->mea_fids[c].id = oa->o_id;
1032 mea->mea_fids[c].generation = oa->o_generation;
1033 mea->mea_fids[c].mds = i;
1035 CDEBUG(D_OTHER, "dirobj at mds %d: "LPU64"/%u\n",
1036 i, oa->o_id, oa->o_generation);
1038 LASSERT(c == mea->mea_count);
1039 CDEBUG(D_OTHER, "%d dirobjects created\n", (int) mea->mea_count);
1044 static int lmv_get_info(struct obd_export *exp, __u32 keylen,
1045 void *key, __u32 *vallen, void *val)
1047 struct obd_device *obd;
1048 struct lmv_obd *lmv;
1051 obd = class_exp2obd(exp);
1053 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1054 exp->exp_handle.h_cookie);
1059 if (keylen == 6 && memcmp(key, "mdsize", 6) == 0) {
1060 __u32 *mdsize = val;
1061 *vallen = sizeof(__u32);
1062 *mdsize = sizeof(struct ll_fid) * lmv->count
1063 + sizeof(struct mea);
1065 } else if (keylen == 6 && memcmp(key, "mdsnum", 6) == 0) {
1066 struct obd_uuid *cluuid = &lmv->cluuid;
1067 struct lmv_tgt_desc *tgts;
1068 __u32 *mdsnum = val;
1071 for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
1072 if (obd_uuid_equals(&tgts->uuid, cluuid)) {
1073 *vallen = sizeof(__u32);
1081 CDEBUG(D_IOCTL, "invalid key\n");
1085 int lmv_set_info(struct obd_export *exp, obd_count keylen,
1086 void *key, obd_count vallen, void *val)
1088 struct obd_device *obd;
1089 struct lmv_obd *lmv;
1092 obd = class_exp2obd(exp);
1094 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1095 exp->exp_handle.h_cookie);
1101 if (keylen >= strlen("client") && strcmp(key, "client") == 0) {
1102 struct lmv_tgt_desc *tgts;
1105 for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
1106 rc = obd_set_info(tgts->exp, keylen, key, vallen, val);
1116 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
1117 struct lov_stripe_md *lsm)
1119 struct obd_device *obd = class_exp2obd(exp);
1120 struct lmv_obd *lmv = &obd->u.lmv;
1124 mea_size = sizeof(struct ll_fid) * lmv->count + sizeof(struct mea);
1128 if (*lmmp && !lsm) {
1129 OBD_FREE(*lmmp, mea_size);
1135 OBD_ALLOC(*lmmp, mea_size);
1143 #warning "MEA packing/convertation must be here! -bzzz"
1144 memcpy(*lmmp, lsm, mea_size);
1148 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **mem_tgt,
1149 struct lov_mds_md *disk_src, int mdsize)
1151 struct obd_device *obd = class_exp2obd(exp);
1152 struct lmv_obd *lmv = &obd->u.lmv;
1153 struct mea **tmea = (struct mea **) mem_tgt;
1154 struct mea *mea = (void *) disk_src;
1158 mea_size = sizeof(struct ll_fid) * lmv->count + sizeof(struct mea);
1159 if (mem_tgt == NULL)
1162 if (*mem_tgt != NULL && disk_src == NULL) {
1163 OBD_FREE(*tmea, mea_size);
1167 LASSERT(mea_size == mdsize);
1169 OBD_ALLOC(*tmea, mea_size);
1170 /* FIXME: error handling here */
1171 LASSERT(*tmea != NULL);
1176 #warning "MEA unpacking/convertation must be here! -bzzz"
1177 memcpy(*tmea, mea, mdsize);
1181 int lmv_brw(int rw, struct obd_export *exp, struct obdo *oa,
1182 struct lov_stripe_md *ea, obd_count oa_bufs,
1183 struct brw_page *pgarr, struct obd_trans_info *oti)
1185 struct obd_device *obd = exp->exp_obd;
1186 struct lmv_obd *lmv = &obd->u.lmv;
1187 struct mea *mea = (struct mea *) ea;
1190 LASSERT(oa != NULL);
1191 LASSERT(ea != NULL);
1192 LASSERT(pgarr != NULL);
1193 LASSERT(oa->o_mds < lmv->count);
1195 oa->o_gr = mea->mea_fids[oa->o_mds].generation;
1196 oa->o_id = mea->mea_fids[oa->o_mds].id;
1197 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1198 err = obd_brw(rw, lmv->tgts[oa->o_mds].exp, oa,
1199 NULL, oa_bufs, pgarr, oti);
1203 struct obd_ops lmv_obd_ops = {
1204 o_owner: THIS_MODULE,
1205 o_attach: lmv_attach,
1206 o_detach: lmv_detach,
1208 o_cleanup: lmv_cleanup,
1209 o_connect: lmv_connect_fake,
1210 o_disconnect: lmv_disconnect,
1211 o_statfs: lmv_statfs,
1212 o_get_info: lmv_get_info,
1213 o_set_info: lmv_set_info,
1214 o_create: lmv_obd_create,
1215 o_packmd: lmv_packmd,
1216 o_unpackmd: lmv_unpackmd,
1218 o_init_ea_size: lmv_init_ea_size,
1221 struct md_ops lmv_md_ops = {
1222 m_getstatus: lmv_getstatus,
1223 m_getattr: lmv_getattr,
1224 m_change_cbdata: lmv_change_cbdata,
1225 m_change_cbdata_name: lmv_change_cbdata_name,
1227 m_create: lmv_create,
1228 m_done_writing: lmv_done_writing,
1229 m_enqueue: lmv_enqueue,
1230 m_getattr_name: lmv_getattr_name,
1231 m_intent_lock: lmv_intent_lock,
1233 m_rename: lmv_rename,
1234 m_setattr: lmv_setattr,
1236 m_readpage: lmv_readpage,
1237 m_unlink: lmv_unlink,
1238 m_get_real_obd: lmv_get_real_obd,
1239 m_valid_attrs: lmv_valid_attrs,
1243 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
1244 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
1246 LPROCFS_INIT_VARS(lmv, lprocfs_module_vars, lprocfs_obd_vars)
1248 int __init lmv_init(void)
1250 struct lprocfs_static_vars lvars;
1253 lprocfs_init_vars(lmv, &lvars);
1254 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
1255 lvars.module_vars, OBD_LMV_DEVICENAME);
1259 static void lmv_exit(void)
1261 class_unregister_type(OBD_LMV_DEVICENAME);
1265 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1266 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
1267 MODULE_LICENSE("GPL");
1269 module_init(lmv_init);
1270 module_exit(lmv_exit);