1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Copyright (C) 2002 Cluster File Systems, Inc.
7 * Author: Phil Schwan <phil@off.net>
8 * Peter Braam <braam@clusterfs.com>
10 * This code is issued under the GNU General Public License.
11 * See the file COPYING in this distribution
15 #define DEBUG_SUBSYSTEM S_LOV
17 #include <linux/slab.h>
18 #include <linux/module.h>
19 #include <linux/obd_support.h>
20 #include <linux/lustre_lib.h>
21 #include <linux/lustre_net.h>
22 #include <linux/lustre_idl.h>
23 #include <linux/lustre_mds.h>
24 #include <linux/obd_class.h>
25 #include <linux/obd_lov.h>
26 #include <linux/init.h>
27 #include <asm/div64.h>
30 static int lov_connect(struct lustre_handle *conn, struct obd_device *obd,
31 obd_uuid_t cluuid, struct recovd_obd *recovd,
32 ptlrpc_recovery_cb_t recover)
34 struct ptlrpc_request *req = NULL;
35 struct lov_obd *lov = &obd->u.lov;
36 struct client_obd *mdc = &lov->mdcobd->u.cli;
37 struct lov_desc *desc = &lov->desc;
38 struct lustre_handle mdc_conn;
39 obd_uuid_t *uuidarray;
44 rc = class_connect(conn, obd, cluuid);
50 /* retrieve LOV metadata from MDS */
51 rc = obd_connect(&mdc_conn, lov->mdcobd, NULL, recovd, recover);
53 CERROR("cannot connect to mdc: rc = %d\n", rc);
57 rc = mdc_getlovinfo(obd, &mdc_conn, &req);
58 rc2 = obd_disconnect(&mdc_conn);
60 CERROR("cannot get lov info %d\n", rc);
65 CERROR("error disconnecting from MDS %d\n", rc2);
66 GOTO(out_conn, rc = rc2);
70 if (req->rq_repmsg->bufcount < 2 ||
71 req->rq_repmsg->buflens[0] < sizeof(*desc)) {
72 CERROR("LOV desc: invalid descriptor returned\n");
73 GOTO(out_conn, rc = -EINVAL);
76 memcpy(desc, lustre_msg_buf(req->rq_repmsg, 0), sizeof(*desc));
79 if (req->rq_repmsg->buflens[1] < sizeof(*uuidarray)*desc->ld_tgt_count){
80 CERROR("LOV desc: invalid uuid array returned\n");
81 GOTO(out_conn, rc = -EINVAL);
84 mdc->cl_max_mds_easize = lov_mds_md_size(desc->ld_tgt_count);
85 mdc->cl_max_ost_easize = lov_stripe_md_size(desc->ld_tgt_count);
87 if (memcmp(obd->obd_uuid, desc->ld_uuid, sizeof(desc->ld_uuid))) {
88 CERROR("LOV desc: uuid %s not on mds device (%s)\n",
89 obd->obd_uuid, desc->ld_uuid);
90 GOTO(out_conn, rc = -EINVAL);
93 if (desc->ld_tgt_count > 1000) {
94 CERROR("LOV desc: target count > 1000 (%d)\n",
96 GOTO(out_conn, rc = -EINVAL);
99 if (desc->ld_default_stripe_count == 0)
100 desc->ld_default_stripe_count = desc->ld_tgt_count;
102 /* Because of 64-bit divide/mod operations only work with a 32-bit
103 * divisor in a 32-bit kernel, we cannot support a stripe width
106 if (desc->ld_default_stripe_size * desc->ld_tgt_count > ~0UL) {
107 CERROR("LOV desc: stripe width > %lu on 32-bit system\n",
109 GOTO(out_conn, rc = -EINVAL);
112 lov->bufsize = sizeof(struct lov_tgt_desc) * desc->ld_tgt_count;
113 OBD_ALLOC(lov->tgts, lov->bufsize);
115 CERROR("Out of memory\n");
116 GOTO(out_conn, rc = -ENOMEM);
119 uuidarray = lustre_msg_buf(req->rq_repmsg, 1);
120 for (i = 0 ; i < desc->ld_tgt_count; i++)
121 memcpy(lov->tgts[i].uuid, uuidarray[i], sizeof(*uuidarray));
123 for (i = 0 ; i < desc->ld_tgt_count; i++) {
124 struct obd_device *tgt = class_uuid2obd(uuidarray[i]);
126 CERROR("Target %s not attached\n", uuidarray[i]);
127 GOTO(out_disc, rc = -EINVAL);
129 if (!(tgt->obd_flags & OBD_SET_UP)) {
130 CERROR("Target %s not set up\n", uuidarray[i]);
131 GOTO(out_disc, rc = -EINVAL);
133 rc = obd_connect(&lov->tgts[i].conn, tgt, NULL, recovd,
136 CERROR("Target %s connect error %d\n",
143 ptlrpc_req_finished(req);
148 rc2 = obd_disconnect(&lov->tgts[i].conn);
150 CERROR("LOV Target %s disconnect error: rc = %d\n",
153 OBD_FREE(lov->tgts, lov->bufsize);
155 class_disconnect(conn);
159 static int lov_disconnect(struct lustre_handle *conn)
161 struct obd_device *obd = class_conn2obd(conn);
162 struct lov_obd *lov = &obd->u.lov;
169 for (i = 0 ; i < lov->desc.ld_tgt_count; i++) {
170 rc = obd_disconnect(&lov->tgts[i].conn);
172 CERROR("Target %s disconnect error %d\n",
173 lov->tgts[i].uuid, rc);
177 OBD_FREE(lov->tgts, lov->bufsize);
182 rc = class_disconnect(conn);
188 static int lov_setup(struct obd_device *obd, obd_count len, void *buf)
190 struct obd_ioctl_data* data = buf;
191 struct lov_obd *lov = &obd->u.lov;
195 if (data->ioc_inllen1 < 1) {
196 CERROR("osc setup requires an MDC UUID\n");
200 if (data->ioc_inllen1 > 37) {
201 CERROR("mdc UUID must be 36 characters or less\n");
205 lov->mdcobd = class_uuid2obd(data->ioc_inlbuf1);
207 CERROR("LOV %s cannot locate MDC %s\n", obd->obd_uuid,
215 /* the LOV expects oa->o_id to be set to the LOV object id */
216 static int lov_create(struct lustre_handle *conn, struct obdo *oa,
217 struct lov_stripe_md **ea)
219 struct obd_export *export = class_conn2export(conn);
221 struct lov_stripe_md *lsm;
222 struct lov_oinfo *loi;
224 int sub_offset, stripe_offset;
239 lov = &export->exp_obd->u.lov;
240 ost_count = lov->desc.ld_tgt_count;
241 oa->o_easize = lov_stripe_md_size(ost_count);
245 OBD_ALLOC(lsm, oa->o_easize);
247 GOTO(out_tmp, rc = -ENOMEM);
250 LASSERT(oa->o_valid & OBD_MD_FLID);
251 lsm->lsm_magic = LOV_MAGIC;
252 lsm->lsm_mds_easize = lov_mds_md_size(ost_count);
253 lsm->lsm_object_id = oa->o_id;
254 if (!lsm->lsm_stripe_count)
255 lsm->lsm_stripe_count = lov->desc.ld_default_stripe_count;
257 if (!lsm->lsm_stripe_size)
258 lsm->lsm_stripe_size = lov->desc.ld_default_stripe_size;
260 lsm->lsm_ost_count = ost_count;
261 stripe_offset = (((int)lsm->lsm_object_id * lsm->lsm_stripe_count) %
263 sub_offset = ((int)lsm->lsm_object_id*lsm->lsm_stripe_count/ost_count)%
264 lsm->lsm_stripe_count;
265 lsm->lsm_stripe_offset = stripe_offset + sub_offset;
267 CDEBUG(D_INODE, "allocating %d subobjs for objid "LPX64" at idx %d\n",
268 lsm->lsm_stripe_count,lsm->lsm_object_id,lsm->lsm_stripe_offset);
270 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
271 struct lov_stripe_md obj_md;
272 struct lov_stripe_md *obj_mdp = &obj_md;
273 int ost_idx = (((sub_offset + i) % lsm->lsm_stripe_count) +
274 stripe_offset) % ost_count;
276 /* create data objects with "parent" OA */
277 memcpy(tmp, oa, sizeof(*tmp));
278 tmp->o_easize = sizeof(struct lov_stripe_md);
279 rc = obd_create(&lov->tgts[ost_idx].conn, tmp, &obj_mdp);
281 CERROR("error creating objid "LPX64" sub-object on "
282 "OST idx %d: rc = %d\n", oa->o_id, ost_idx, rc);
283 GOTO(out_cleanup, rc);
285 loi->loi_id = tmp->o_id;
286 loi->loi_size = tmp->o_size;
287 loi->loi_ost_idx = ost_idx;
288 CDEBUG(D_INODE, "objid "LPX64" has subobj "LPX64" at idx %d\n",
289 lsm->lsm_object_id, loi->loi_id, ost_idx);
303 /* destroy already created objects here */
304 memcpy(tmp, oa, sizeof(*tmp));
305 tmp->o_id = loi->loi_id;
306 err = obd_destroy(&lov->tgts[loi->loi_ost_idx].conn, tmp, NULL);
308 CERROR("Failed to uncreate objid "LPX64" subobj "
309 LPX64" on OST idx %d: rc = %d\n",
310 oa->o_id, loi->loi_id, loi->loi_ost_idx,
313 OBD_FREE(lsm, oa->o_easize);
317 static int lov_destroy(struct lustre_handle *conn, struct obdo *oa,
318 struct lov_stripe_md *lsm)
321 struct obd_export *export = class_conn2export(conn);
323 struct lov_oinfo *loi;
328 CERROR("LOV requires striping ea for destruction\n");
332 if (lsm->lsm_magic != LOV_MAGIC) {
333 CERROR("LOV striping magic bad %#lx != %#lx\n",
334 lsm->lsm_magic, LOV_MAGIC);
338 if (!export || !export->exp_obd)
341 lov = &export->exp_obd->u.lov;
342 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
343 /* create data objects with "parent" OA */
344 memcpy(&tmp, oa, sizeof(tmp));
345 tmp.o_id = loi->loi_id;
346 rc = obd_destroy(&lov->tgts[loi->loi_ost_idx].conn, &tmp, NULL);
348 CERROR("Error destroying objid "LPX64" subobj "LPX64
349 " on OST idx %d\n: rc = %d",
350 oa->o_id, loi->loi_id, loi->loi_ost_idx, rc);
355 /* compute object size given "stripeno" and the ost size */
356 static obd_size lov_stripe_size(struct lov_stripe_md *lsm, obd_size ost_size,
359 unsigned long ssize = lsm->lsm_stripe_size;
360 unsigned long swidth = ssize * lsm->lsm_stripe_count;
361 unsigned long stripe_size;
367 /* do_div(a, b) returns a % b, and a = a / b */
368 stripe_size = do_div(ost_size, ssize);
371 lov_size = ost_size * swidth + stripeno * ssize + stripe_size;
373 lov_size = (ost_size - 1) * swidth + (stripeno + 1) * ssize;
378 static void lov_merge_attrs(struct obdo *tgt, struct obdo *src, obd_flag valid,
379 struct lov_stripe_md *lsm, int stripeno, int *new)
382 obdo_cpy_md(tgt, src, valid);
383 if (valid & OBD_MD_FLSIZE)
384 tgt->o_size = lov_stripe_size(lsm,src->o_size,stripeno);
387 if (valid & OBD_MD_FLSIZE) {
388 /* this handles sparse files properly */
391 lov_size = lov_stripe_size(lsm, src->o_size, stripeno);
392 if (lov_size > tgt->o_size)
393 tgt->o_size = lov_size;
395 if (valid & OBD_MD_FLBLOCKS)
396 tgt->o_blocks += src->o_blocks;
397 if (valid & OBD_MD_FLCTIME && tgt->o_ctime < src->o_ctime)
398 tgt->o_ctime = src->o_ctime;
399 if (valid & OBD_MD_FLMTIME && tgt->o_mtime < src->o_mtime)
400 tgt->o_mtime = src->o_mtime;
404 static int lov_getattr(struct lustre_handle *conn, struct obdo *oa,
405 struct lov_stripe_md *lsm)
408 struct obd_export *export = class_conn2export(conn);
410 struct lov_oinfo *loi;
416 CERROR("LOV requires striping ea\n");
420 if (lsm->lsm_magic != LOV_MAGIC) {
421 CERROR("LOV striping magic bad %#lx != %#lx\n",
422 lsm->lsm_magic, LOV_MAGIC);
426 if (!export || !export->exp_obd)
429 lov = &export->exp_obd->u.lov;
432 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
435 if (loi->loi_id == 0)
438 /* create data objects with "parent" OA */
439 memcpy(&tmp, oa, sizeof(tmp));
440 tmp.o_id = loi->loi_id;
442 err = obd_getattr(&lov->tgts[loi->loi_ost_idx].conn, &tmp,NULL);
444 CERROR("Error getattr objid "LPX64" subobj "LPX64
445 " on OST idx %d: rc = %d\n",
446 oa->o_id, loi->loi_id, loi->loi_ost_idx, err);
449 continue; /* XXX or break? */
451 lov_merge_attrs(oa, &tmp, tmp.o_valid, lsm, i, &new);
456 static int lov_setattr(struct lustre_handle *conn, struct obdo *oa,
457 struct lov_stripe_md *lsm)
460 struct obd_export *export = class_conn2export(conn);
462 struct lov_oinfo *loi;
466 /* Note that this code is currently unused, hence LBUG(), just
467 * to know when/if it is ever revived that it needs cleanups.
472 CERROR("LOV requires striping ea\n");
476 if (lsm->lsm_magic != LOV_MAGIC) {
477 CERROR("LOV striping magic bad %#lx != %#lx\n",
478 lsm->lsm_magic, LOV_MAGIC);
482 if (!export || !export->exp_obd)
485 /* size changes should go through punch and not setattr */
486 LASSERT(!(oa->o_valid & OBD_MD_FLSIZE));
488 lov = &export->exp_obd->u.lov;
489 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
492 /* create data objects with "parent" OA */
493 memcpy(&tmp, oa, sizeof(tmp));
494 tmp.o_id = loi->loi_id;
496 err = obd_setattr(&lov->tgts[loi->loi_ost_idx].conn, &tmp,NULL);
498 CERROR("Error setattr objid "LPX64" subobj "LPX64
499 " on OST idx %d: rc = %d\n",
500 oa->o_id, loi->loi_id, loi->loi_ost_idx, err);
508 static int lov_open(struct lustre_handle *conn, struct obdo *oa,
509 struct lov_stripe_md *lsm)
512 struct obd_export *export = class_conn2export(conn);
514 struct lov_oinfo *loi;
520 CERROR("LOV requires striping ea for opening\n");
524 if (lsm->lsm_magic != LOV_MAGIC) {
525 CERROR("LOV striping magic bad %#lx != %#lx\n",
526 lsm->lsm_magic, LOV_MAGIC);
530 if (!export || !export->exp_obd)
537 lov = &export->exp_obd->u.lov;
540 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
543 /* create data objects with "parent" OA */
544 memcpy(tmp, oa, sizeof(*tmp));
545 tmp->o_id = loi->loi_id;
547 err = obd_open(&lov->tgts[loi->loi_ost_idx].conn, tmp, NULL);
549 CERROR("Error open objid "LPX64" subobj "LPX64
550 " on OST idx %d: rc = %d\n",
551 oa->o_id, lsm->lsm_oinfo[i].loi_id,
552 loi->loi_ost_idx, rc);
557 lov_merge_attrs(oa, tmp, tmp->o_valid, lsm, i, &new);
559 /* FIXME: returning an error, but having opened some objects is a bad
560 * idea, since they will likely never be closed. We either
561 * need to not return an error if _some_ objects could be
562 * opened, and leave it to read/write to return -EIO (with
563 * hopefully partial error status) or close all opened objects
564 * and return an error. I think the former is preferred.
570 static int lov_close(struct lustre_handle *conn, struct obdo *oa,
571 struct lov_stripe_md *lsm)
574 struct obd_export *export = class_conn2export(conn);
576 struct lov_oinfo *loi;
581 CERROR("LOV requires striping ea\n");
585 if (lsm->lsm_magic != LOV_MAGIC) {
586 CERROR("LOV striping magic bad %#lx != %#lx\n",
587 lsm->lsm_magic, LOV_MAGIC);
591 if (!export || !export->exp_obd)
594 lov = &export->exp_obd->u.lov;
595 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
598 /* create data objects with "parent" OA */
599 memcpy(&tmp, oa, sizeof(tmp));
600 tmp.o_id = loi->loi_id;
602 err = obd_close(&lov->tgts[loi->loi_ost_idx].conn, &tmp, NULL);
604 CERROR("Error close objid "LPX64" subobj "LPX64
605 " on OST idx %d: rc = %d\n",
606 oa->o_id, loi->loi_id, loi->loi_ost_idx, err);
615 #define log2(n) ffz(~(n))
618 #warning FIXME: merge these two functions now that they are nearly the same
620 /* compute ost offset in stripe "stripeno" corresponding to offset "lov_off" */
621 static obd_off lov_stripe_offset(struct lov_stripe_md *lsm, obd_off lov_off,
624 unsigned long ssize = lsm->lsm_stripe_size;
625 unsigned long swidth = ssize * lsm->lsm_stripe_count;
626 unsigned long stripe_off, this_stripe;
628 if (lov_off == OBD_OBJECT_EOF || lov_off == 0)
631 /* do_div(a, b) returns a % b, and a = a / b */
632 stripe_off = do_div(lov_off, swidth);
634 this_stripe = stripeno * ssize;
635 if (stripe_off <= this_stripe)
638 stripe_off -= this_stripe;
640 if (stripe_off > ssize)
645 return lov_off * ssize + stripe_off;
648 /* compute which stripe number "lov_off" will be written into */
649 static int lov_stripe_number(struct lov_stripe_md *lsm, obd_off lov_off)
651 unsigned long ssize = lsm->lsm_stripe_size;
652 unsigned long swidth = ssize * lsm->lsm_stripe_count;
653 unsigned long stripe_off;
655 stripe_off = do_div(lov_off, swidth);
657 return stripe_off / ssize;
661 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
662 * we can send this 'punch' to just the authoritative node and the nodes
663 * that the punch will affect. */
664 static int lov_punch(struct lustre_handle *conn, struct obdo *oa,
665 struct lov_stripe_md *lsm,
666 obd_off start, obd_off end)
669 struct obd_export *export = class_conn2export(conn);
671 struct lov_oinfo *loi;
676 CERROR("LOV requires striping ea\n");
680 if (lsm->lsm_magic != LOV_MAGIC) {
681 CERROR("LOV striping magic bad %#lx != %#lx\n",
682 lsm->lsm_magic, LOV_MAGIC);
686 if (!export || !export->exp_obd)
689 lov = &export->exp_obd->u.lov;
690 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
691 obd_off starti = lov_stripe_offset(lsm, start, i);
692 obd_off endi = lov_stripe_offset(lsm, end, i);
697 /* create data objects with "parent" OA */
698 memcpy(&tmp, oa, sizeof(tmp));
699 tmp.o_id = loi->loi_id;
701 err = obd_punch(&lov->tgts[loi->loi_ost_idx].conn, &tmp, NULL,
704 CERROR("Error punch objid "LPX64" subobj "LPX64
705 " on OST idx %d: rc = %d\n",
706 oa->o_id, loi->loi_id, loi->loi_ost_idx, err);
714 static int lov_osc_brw_callback(struct io_cb_data *cbd, int err, int phase)
719 if (phase == CB_PHASE_START)
722 if (phase == CB_PHASE_FINISH) {
725 if (atomic_dec_and_test(&cbd->refcount))
726 ret = cbd->cb(cbd->data, cbd->err, phase);
734 static inline int lov_brw(int cmd, struct lustre_handle *conn,
735 struct lov_stripe_md *lsm, obd_count oa_bufs,
736 struct brw_page *pga,
737 brw_callback_t callback, struct io_cb_data *cbd)
739 int stripe_count = lsm->lsm_stripe_count;
740 struct obd_export *export = class_conn2export(conn);
746 struct lov_stripe_md lsm;
748 } *stripeinfo, *si, *si_last;
749 struct brw_page *ioarr;
751 struct io_cb_data *our_cb;
752 struct lov_oinfo *loi;
757 CERROR("LOV requires striping ea\n");
761 if (lsm->lsm_magic != LOV_MAGIC) {
762 CERROR("LOV striping magic bad %#lx != %#lx\n",
763 lsm->lsm_magic, LOV_MAGIC);
767 lov = &export->exp_obd->u.lov;
769 our_cb = ll_init_cb();
773 OBD_ALLOC(stripeinfo, stripe_count * sizeof(*stripeinfo));
775 GOTO(out_cbdata, rc = -ENOMEM);
777 OBD_ALLOC(where, sizeof(*where) * oa_bufs);
779 GOTO(out_sinfo, rc = -ENOMEM);
781 OBD_ALLOC(ioarr, sizeof(*ioarr) * oa_bufs);
783 GOTO(out_where, rc = -ENOMEM);
785 /* This is the only race-free way I can think of to get the refcount
787 atomic_set(&our_cb->refcount, 0);
788 our_cb->cb = callback;
791 for (i = 0; i < oa_bufs; i++) {
792 where[i] = lov_stripe_number(lsm, pga[i].off);
793 if (stripeinfo[where[i]].bufct++ == 0)
794 atomic_inc(&our_cb->refcount);
797 for (i = 0, loi = lsm->lsm_oinfo, si_last = si = stripeinfo;
798 i < stripe_count; i++, loi++, si_last = si, si++) {
800 si->index = si_last->index + si_last->bufct;
801 si->lsm.lsm_object_id = loi->loi_id;
802 si->ost_idx = loi->loi_ost_idx;
805 for (i = 0; i < oa_bufs; i++) {
806 int which = where[i];
809 shift = stripeinfo[which].index + stripeinfo[which].subcount;
810 LASSERT(shift < oa_bufs);
811 ioarr[shift] = pga[i];
812 ioarr[shift].off = lov_stripe_offset(lsm, pga[i].off, which);
813 stripeinfo[which].subcount++;
816 for (i = 0, si = stripeinfo; i < stripe_count; i++, si++) {
817 int shift = si->index;
820 LASSERT(shift < oa_bufs);
821 /* XXX handle error returns here */
822 obd_brw(cmd, &lov->tgts[si->ost_idx].conn,
823 &si->lsm, si->bufct, &ioarr[shift],
824 lov_osc_brw_callback, our_cb);
828 rc = callback(cbd, 0, CB_PHASE_START);
830 OBD_FREE(ioarr, sizeof(*ioarr) * oa_bufs);
832 OBD_FREE(where, sizeof(*where) * oa_bufs);
834 OBD_FREE(stripeinfo, stripe_count * sizeof(*stripeinfo));
836 OBD_FREE(our_cb, sizeof(*our_cb));
840 static int lov_enqueue(struct lustre_handle *conn, struct lov_stripe_md *lsm,
841 struct lustre_handle *parent_lock,
842 __u32 type, void *cookie, int cookielen, __u32 mode,
843 int *flags, void *cb, void *data, int datalen,
844 struct lustre_handle *lockhs)
846 struct obd_export *export = class_conn2export(conn);
848 struct lov_oinfo *loi;
853 CERROR("LOV requires striping ea\n");
857 if (lsm->lsm_magic != LOV_MAGIC) {
858 CERROR("LOV striping magic bad %#lx != %#lx\n",
859 lsm->lsm_magic, LOV_MAGIC);
863 if (!export || !export->exp_obd)
866 lov = &export->exp_obd->u.lov;
867 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
868 struct ldlm_extent *extent = (struct ldlm_extent *)cookie;
869 struct ldlm_extent sub_ext;
870 struct lov_stripe_md submd;
872 sub_ext.start = lov_stripe_offset(lsm, extent->start, i);
873 sub_ext.end = lov_stripe_offset(lsm, extent->end, i);
874 if (sub_ext.start == sub_ext.end)
877 submd.lsm_object_id = loi->loi_id;
878 /* XXX submd lsm_mds_easize should be that from the subobj,
879 * and the subobj should get it opaquely from the LOV.
881 submd.lsm_mds_easize = lov_mds_md_size(lsm->lsm_ost_count);
882 submd.lsm_stripe_count = 0;
883 /* XXX submd is not fully initialized here */
884 rc = obd_enqueue(&(lov->tgts[loi->loi_ost_idx].conn), &submd,
885 parent_lock, type, &sub_ext, sizeof(sub_ext),
886 mode, flags, cb, data, datalen, &(lockhs[i]));
887 // XXX add a lock debug statement here
889 CERROR("Error enqueue objid "LPX64" subobj "LPX64
890 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
891 loi->loi_id, loi->loi_ost_idx, rc);
896 static int lov_cancel(struct lustre_handle *conn, struct lov_stripe_md *lsm,
897 __u32 mode, struct lustre_handle *lockhs)
899 struct obd_export *export = class_conn2export(conn);
901 struct lov_oinfo *loi;
906 CERROR("LOV requires striping ea\n");
910 if (lsm->lsm_magic != LOV_MAGIC) {
911 CERROR("LOV striping magic bad %#lx != %#lx\n",
912 lsm->lsm_magic, LOV_MAGIC);
916 if (!export || !export->exp_obd)
919 lov = &export->exp_obd->u.lov;
920 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
921 struct lov_stripe_md submd;
923 if (lockhs[i].addr == 0)
926 submd.lsm_object_id = loi->loi_id;
927 submd.lsm_mds_easize = lov_mds_md_size(lsm->lsm_ost_count);
928 submd.lsm_stripe_count = 0;
929 rc = obd_cancel(&lov->tgts[loi->loi_ost_idx].conn, &submd,
932 CERROR("Error cancel objid "LPX64" subobj "LPX64
933 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
934 loi->loi_id, loi->loi_ost_idx, rc);
939 static int lov_cancel_unused(struct lustre_handle *conn,
940 struct lov_stripe_md *lsm, int local_only)
942 struct obd_export *export = class_conn2export(conn);
944 struct lov_oinfo *loi;
949 CERROR("LOV requires striping ea for lock cancellation\n");
953 if (!export || !export->exp_obd)
956 lov = &export->exp_obd->u.lov;
957 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
958 struct lov_stripe_md submd;
960 submd.lsm_object_id = loi->loi_id;
961 submd.lsm_mds_easize = lov_mds_md_size(lsm->lsm_ost_count);
962 submd.lsm_stripe_count = 0;
963 rc = obd_cancel_unused(&lov->tgts[loi->loi_ost_idx].conn,
966 CERROR("Error cancel unused objid "LPX64" subobj "LPX64
967 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
968 loi->loi_id, loi->loi_ost_idx, rc);
973 static int lov_statfs(struct lustre_handle *conn, struct obd_statfs *osfs)
975 struct obd_export *export = class_conn2export(conn);
977 struct obd_statfs lov_sfs;
983 if (!export || !export->exp_obd)
986 lov = &export->exp_obd->u.lov;
988 /* We only get block data from the OBD */
989 for (i = 0 ; i < lov->desc.ld_tgt_count; i++) {
992 err = obd_statfs(&lov->tgts[i].conn, &lov_sfs);
994 CERROR("Error statfs OSC %s idx %d: err = %d\n",
995 lov->tgts[i].uuid, i, err);
998 continue; /* XXX or break? - probably OK to continue */
1001 memcpy(osfs, &lov_sfs, sizeof(lov_sfs));
1004 osfs->os_bfree += lov_sfs.os_bfree;
1005 osfs->os_bavail += lov_sfs.os_bavail;
1006 osfs->os_blocks += lov_sfs.os_blocks;
1007 /* XXX not sure about this one - depends on policy.
1008 * - could be minimum if we always stripe on all OBDs
1009 * (but that would be wrong for any other policy,
1010 * if one of the OBDs has no more objects left)
1011 * - could be sum if we stripe whole objects
1012 * - could be average, just to give a nice number
1013 * - we just pick first OST and hope it is enough
1014 sfs->f_ffree += lov_sfs.f_ffree;
1022 struct obd_ops lov_obd_ops = {
1024 o_connect: lov_connect,
1025 o_disconnect: lov_disconnect,
1026 o_create: lov_create,
1027 o_destroy: lov_destroy,
1028 o_getattr: lov_getattr,
1029 o_setattr: lov_setattr,
1030 o_statfs: lov_statfs,
1035 o_enqueue: lov_enqueue,
1036 o_cancel: lov_cancel,
1037 o_cancel_unused: lov_cancel_unused
1041 #define LOV_VERSION "v0.1"
1043 static int __init lov_init(void)
1045 printk(KERN_INFO "Lustre Logical Object Volume driver " LOV_VERSION
1046 ", info@clusterfs.com\n");
1047 return class_register_type(&lov_obd_ops, OBD_LOV_DEVICENAME);
1050 static void __exit lov_exit(void)
1052 class_unregister_type(OBD_LOV_DEVICENAME);
1055 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1056 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver v0.1");
1057 MODULE_LICENSE("GPL");
1059 module_init(lov_init);
1060 module_exit(lov_exit);