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,
33 struct ptlrpc_request *req;
34 struct lov_obd *lov = &obd->u.lov;
35 struct client_obd *mdc = &lov->mdcobd->u.cli;
36 struct lov_desc *desc = &lov->desc;
37 struct lustre_handle mdc_conn;
38 obd_uuid_t *uuidarray;
43 rc = class_connect(conn, obd, cluuid);
49 /* retrieve LOV metadata from MDS */
50 rc = obd_connect(&mdc_conn, lov->mdcobd, NULL);
52 CERROR("cannot connect to mdc: rc = %d\n", rc);
53 GOTO(out, rc = -EINVAL);
56 rc = mdc_getlovinfo(obd, &mdc_conn, &req);
57 rc2 = obd_disconnect(&mdc_conn);
59 CERROR("cannot get lov info or disconnect %d/%d\n", rc, rc2);
60 GOTO(out, (rc) ? rc : rc2 );
64 if (req->rq_repmsg->bufcount < 2 ||
65 req->rq_repmsg->buflens[0] < sizeof(*desc)) {
66 CERROR("LOV desc: invalid descriptor returned\n");
67 GOTO(out, rc = -EINVAL);
70 memcpy(desc, lustre_msg_buf(req->rq_repmsg, 0), sizeof(*desc));
73 if (req->rq_repmsg->buflens[1] < sizeof(*uuidarray)*desc->ld_tgt_count){
74 CERROR("LOV desc: invalid uuid array returned\n");
75 GOTO(out, rc = -EINVAL);
78 mdc->cl_max_mds_easize = lov_mds_md_size(desc->ld_tgt_count);
79 mdc->cl_max_ost_easize = lov_stripe_md_size(desc->ld_tgt_count);
81 if (memcmp(obd->obd_uuid, desc->ld_uuid, sizeof(desc->ld_uuid))) {
82 CERROR("LOV desc: uuid %s not on mds device (%s)\n",
83 obd->obd_uuid, desc->ld_uuid);
84 GOTO(out, rc = -EINVAL);
87 if (desc->ld_tgt_count > 1000) {
88 CERROR("LOV desc: target count > 1000 (%d)\n",
90 GOTO(out, rc = -EINVAL);
93 if (desc->ld_default_stripe_count == 0)
94 desc->ld_default_stripe_count = desc->ld_tgt_count;
96 /* Because of 64-bit divide/mod operations only work with a 32-bit
97 * divisor in a 32-bit kernel, we cannot support a stripe width
100 if (desc->ld_default_stripe_size * desc->ld_tgt_count > ~0UL) {
101 CERROR("LOV desc: stripe width > %lu on 32-bit system\n",
103 GOTO(out, rc = -EINVAL);
106 lov->bufsize = sizeof(struct lov_tgt_desc) * desc->ld_tgt_count;
107 OBD_ALLOC(lov->tgts, lov->bufsize);
109 CERROR("Out of memory\n");
110 GOTO(out, rc = -ENOMEM);
113 uuidarray = lustre_msg_buf(req->rq_repmsg, 1);
114 for (i = 0 ; i < desc->ld_tgt_count; i++)
115 memcpy(lov->tgts[i].uuid, uuidarray[i], sizeof(*uuidarray));
117 for (i = 0 ; i < desc->ld_tgt_count; i++) {
118 struct obd_device *tgt = class_uuid2obd(uuidarray[i]);
120 CERROR("Target %s not attached\n", uuidarray[i]);
121 GOTO(out_mem, rc = -EINVAL);
123 if (!(tgt->obd_flags & OBD_SET_UP)) {
124 CERROR("Target %s not set up\n", uuidarray[i]);
125 GOTO(out_mem, rc = -EINVAL);
127 rc = obd_connect(&lov->tgts[i].conn, tgt, NULL);
129 CERROR("Target %s connect error %d\n",
137 for (i = 0 ; i < desc->ld_tgt_count; i++) {
138 rc2 = obd_disconnect(&lov->tgts[i].conn);
140 CERROR("BAD: Target %s disconnect error %d\n",
143 OBD_FREE(lov->tgts, lov->bufsize);
147 class_disconnect(conn);
148 ptlrpc_free_req(req);
152 static int lov_disconnect(struct lustre_handle *conn)
154 struct obd_device *obd = class_conn2obd(conn);
155 struct lov_obd *lov = &obd->u.lov;
162 for (i = 0 ; i < lov->desc.ld_tgt_count; i++) {
163 rc = obd_disconnect(&lov->tgts[i].conn);
165 CERROR("Target %s disconnect error %d\n",
166 lov->tgts[i].uuid, rc);
170 OBD_FREE(lov->tgts, lov->bufsize);
175 rc = class_disconnect(conn);
181 static int lov_setup(struct obd_device *obd, obd_count len, void *buf)
183 struct obd_ioctl_data* data = buf;
184 struct lov_obd *lov = &obd->u.lov;
188 if (data->ioc_inllen1 < 1) {
189 CERROR("osc setup requires an MDC UUID\n");
193 if (data->ioc_inllen1 > 37) {
194 CERROR("mdc UUID must be 36 characters or less\n");
198 lov->mdcobd = class_uuid2obd(data->ioc_inlbuf1);
200 CERROR("LOV %s cannot locate MDC %s\n", obd->obd_uuid,
208 /* the LOV expects oa->o_id to be set to the LOV object id */
209 static int lov_create(struct lustre_handle *conn, struct obdo *oa,
210 struct lov_stripe_md **ea)
212 struct obd_export *export = class_conn2export(conn);
214 struct lov_stripe_md *lsm;
215 struct lov_oinfo *loi;
216 int sub_offset, stripe_offset;
222 CERROR("lov_create needs ea\n");
229 lov = &export->exp_obd->u.lov;
230 ost_count = lov->desc.ld_tgt_count;
231 oa->o_easize = lov_stripe_md_size(ost_count);
233 OBD_ALLOC(*ea, oa->o_easize);
239 LASSERT(oa->o_valid & OBD_MD_FLID);
240 lsm->lsm_magic = LOV_MAGIC;
241 lsm->lsm_mds_easize = lov_mds_md_size(ost_count);
242 lsm->lsm_object_id = oa->o_id;
243 if (!lsm->lsm_stripe_count)
244 lsm->lsm_stripe_count = lov->desc.ld_default_stripe_count;
246 if (!lsm->lsm_stripe_size)
247 lsm->lsm_stripe_size = lov->desc.ld_default_stripe_size;
249 lsm->lsm_ost_count = ost_count;
250 stripe_offset = (((int)lsm->lsm_object_id * lsm->lsm_stripe_count) %
252 sub_offset = ((int)lsm->lsm_object_id*lsm->lsm_stripe_count/ost_count)%
253 lsm->lsm_stripe_count;
254 lsm->lsm_stripe_offset = stripe_offset + sub_offset;
256 CDEBUG(D_INODE, "allocating %d subobjs for objid "LPX64" at idx %d\n",
257 lsm->lsm_stripe_count,lsm->lsm_object_id,lsm->lsm_stripe_offset);
259 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
260 struct lov_stripe_md obj_md;
261 struct lov_stripe_md *obj_mdp = &obj_md;
263 int ost_idx = (((sub_offset + i) % lsm->lsm_stripe_count) +
264 stripe_offset) % ost_count;
266 /* create data objects with "parent" OA */
267 memcpy(&tmp, oa, sizeof(tmp));
268 tmp.o_easize = sizeof(struct lov_stripe_md);
269 rc = obd_create(&lov->tgts[ost_idx].conn, &tmp, &obj_mdp);
271 CERROR("error creating objid "LPX64" sub-object on "
272 "OST idx %d: rc = %d\n", oa->o_id, ost_idx, rc);
273 GOTO(out_cleanup, rc);
275 loi->loi_id = tmp.o_id;
276 loi->loi_size = tmp.o_size;
277 loi->loi_ost_idx = ost_idx;
278 CDEBUG(D_INODE, "objid "LPX64" has subobj "LPX64" at idx %d\n",
279 lsm->lsm_object_id, loi->loi_id, ost_idx);
289 /* destroy already created objects here */
290 memcpy(&tmp, oa, sizeof(tmp));
291 tmp.o_id = loi->loi_id;
292 err = obd_destroy(&lov->tgts[loi->loi_ost_idx].conn,
295 CERROR("Failed to remove objid "LPX64" subobj "
296 LPX64" on OST idx %d: rc = %d\n",
297 oa->o_id, loi->loi_id, loi->loi_ost_idx,
304 static int lov_destroy(struct lustre_handle *conn, struct obdo *oa,
305 struct lov_stripe_md *lsm)
308 struct obd_export *export = class_conn2export(conn);
310 struct lov_oinfo *loi;
315 CERROR("LOV requires striping ea for destruction\n");
319 if (lsm->lsm_magic != LOV_MAGIC) {
320 CERROR("LOV striping magic bad %#lx != %#lx\n",
321 lsm->lsm_magic, LOV_MAGIC);
325 if (!export || !export->exp_obd)
328 lov = &export->exp_obd->u.lov;
329 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
330 /* create data objects with "parent" OA */
331 memcpy(&tmp, oa, sizeof(tmp));
332 tmp.o_id = loi->loi_id;
333 rc = obd_destroy(&lov->tgts[loi->loi_ost_idx].conn, &tmp, NULL);
335 CERROR("Error destroying objid "LPX64" subobj "LPX64
336 " on OST idx %d\n: rc = %d",
337 oa->o_id, loi->loi_id, loi->loi_ost_idx, rc);
342 static int lov_getattr(struct lustre_handle *conn, struct obdo *oa,
343 struct lov_stripe_md *lsm)
346 struct obd_export *export = class_conn2export(conn);
348 struct lov_oinfo *loi;
354 CERROR("LOV requires striping ea\n");
358 if (lsm->lsm_magic != LOV_MAGIC) {
359 CERROR("LOV striping magic bad %#lx != %#lx\n",
360 lsm->lsm_magic, LOV_MAGIC);
364 if (!export || !export->exp_obd)
367 lov = &export->exp_obd->u.lov;
370 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
373 if (loi->loi_id == 0)
376 /* create data objects with "parent" OA */
377 memcpy(&tmp, oa, sizeof(tmp));
378 tmp.o_id = loi->loi_id;
380 err = obd_getattr(&lov->tgts[loi->loi_ost_idx].conn, &tmp,NULL);
382 CERROR("Error getattr objid "LPX64" subobj "LPX64
383 " on OST idx %d: rc = %d\n",
384 oa->o_id, loi->loi_id, loi->loi_ost_idx, err);
387 continue; /* XXX or break? */
390 obdo_cpy_md(oa, &tmp, tmp.o_valid);
393 #warning FIXME: the size needs to be fixed for sparse files
394 if (tmp.o_valid & OBD_MD_FLSIZE)
395 oa->o_size += tmp.o_size;
396 if (tmp.o_valid & OBD_MD_FLBLOCKS)
397 oa->o_blocks += tmp.o_blocks;
398 if (tmp.o_valid & OBD_MD_FLCTIME &&
399 oa->o_ctime < tmp.o_ctime)
400 oa->o_ctime = tmp.o_ctime;
401 if (tmp.o_valid & OBD_MD_FLMTIME &&
402 oa->o_mtime < tmp.o_mtime)
403 oa->o_mtime = tmp.o_mtime;
409 static int lov_setattr(struct lustre_handle *conn, struct obdo *oa,
410 struct lov_stripe_md *lsm)
414 struct obd_export *export = class_conn2export(conn);
416 struct lov_oinfo *loi;
420 CERROR("LOV requires striping ea\n");
424 if (lsm->lsm_magic != LOV_MAGIC) {
425 CERROR("LOV striping magic bad %#lx != %#lx\n",
426 lsm->lsm_magic, LOV_MAGIC);
430 if (!export || !export->exp_obd)
433 if (oa->o_valid & OBD_MD_FLSIZE)
434 CERROR("setting size on an LOV object is totally broken\n");
436 lov = &export->exp_obd->u.lov;
437 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
440 /* create data objects with "parent" OA */
441 memcpy(&tmp, oa, sizeof(tmp));
442 tmp.o_id = loi->loi_id;
444 err = obd_setattr(&lov->tgts[loi->loi_ost_idx].conn, &tmp,NULL);
446 CERROR("Error setattr objid "LPX64" subobj "LPX64
447 " on OST idx %d: rc = %d\n",
448 oa->o_id, loi->loi_id, loi->loi_ost_idx, err);
456 static int lov_open(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;
467 CERROR("LOV requires striping ea for opening\n");
471 if (lsm->lsm_magic != LOV_MAGIC) {
472 CERROR("LOV striping magic bad %#lx != %#lx\n",
473 lsm->lsm_magic, LOV_MAGIC);
477 if (!export || !export->exp_obd)
480 lov = &export->exp_obd->u.lov;
481 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
484 /* create data objects with "parent" OA */
485 memcpy(&tmp, oa, sizeof(tmp));
486 tmp.o_id = loi->loi_id;
488 err = obd_open(&lov->tgts[loi->loi_ost_idx].conn, &tmp, NULL);
490 CERROR("Error open objid "LPX64" subobj "LPX64
491 " on OST idx %d: rc = %d\n",
492 oa->o_id, lsm->lsm_oinfo[i].loi_id,
493 loi->loi_ost_idx, rc);
498 /* FIXME: returning an error, but having opened some objects is a bad
499 * idea, since they will likely never be closed. We either
500 * need to not return an error if _some_ objects could be
501 * opened, and leave it to read/write to return -EIO (with
502 * hopefully partial error status) or close all opened objects
503 * and return an error.
508 static int lov_close(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;
519 CERROR("LOV requires striping ea\n");
523 if (lsm->lsm_magic != LOV_MAGIC) {
524 CERROR("LOV striping magic bad %#lx != %#lx\n",
525 lsm->lsm_magic, LOV_MAGIC);
529 if (!export || !export->exp_obd)
532 lov = &export->exp_obd->u.lov;
533 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
536 /* create data objects with "parent" OA */
537 memcpy(&tmp, oa, sizeof(tmp));
538 tmp.o_id = loi->loi_id;
540 err = obd_close(&lov->tgts[loi->loi_ost_idx].conn, &tmp, NULL);
542 CERROR("Error close objid "LPX64" subobj "LPX64
543 " on OST idx %d: rc = %d\n",
544 oa->o_id, loi->loi_id, loi->loi_ost_idx, err);
553 #define log2(n) ffz(~(n))
556 #warning FIXME: merge these two functions now that they are nearly the same
558 /* compute ost offset in stripe "stripeno" corresponding to offset "lov_off" */
559 static __u64 lov_offset(struct lov_stripe_md *lsm, __u64 lov_off, int stripeno)
561 unsigned long ssize = lsm->lsm_stripe_size;
562 unsigned long swidth = ssize * lsm->lsm_stripe_count;
563 unsigned long stripe_off;
565 if (lov_off == OBD_PUNCH_EOF)
566 return OBD_PUNCH_EOF;
568 /* do_div(a, b) returns a % b, and a = a / b */
569 stripe_off = do_div(lov_off, swidth);
571 if (stripe_off < stripeno * ssize)
574 stripe_off -= stripeno * ssize;
576 return lov_off * ssize + stripe_off;
579 /* compute which stripe offset "lov_off" will be written into */
580 static int lov_stripe_which(struct lov_stripe_md *lsm, __u64 lov_off)
582 unsigned long ssize = lsm->lsm_stripe_size;
583 unsigned long swidth = ssize * lsm->lsm_stripe_count;
584 unsigned long stripe_off;
586 stripe_off = do_div(lov_off, swidth);
588 return stripe_off / ssize;
592 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
593 * we can send this 'punch' to just the authoritative node and the nodes
594 * that the punch will affect. */
595 static int lov_punch(struct lustre_handle *conn, struct obdo *oa,
596 struct lov_stripe_md *lsm,
597 obd_off start, obd_off end)
600 struct obd_export *export = class_conn2export(conn);
602 struct lov_oinfo *loi;
607 CERROR("LOV requires striping ea\n");
611 if (lsm->lsm_magic != LOV_MAGIC) {
612 CERROR("LOV striping magic bad %#lx != %#lx\n",
613 lsm->lsm_magic, LOV_MAGIC);
617 if (!export || !export->exp_obd)
620 lov = &export->exp_obd->u.lov;
621 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
622 __u64 starti = lov_offset(lsm, start, i);
623 __u64 endi = lov_offset(lsm, end, i);
628 /* create data objects with "parent" OA */
629 memcpy(&tmp, oa, sizeof(tmp));
630 tmp.o_id = loi->loi_id;
632 err = obd_punch(&lov->tgts[loi->loi_ost_idx].conn, &tmp, NULL,
635 CERROR("Error punch objid "LPX64" subobj "LPX64
636 " on OST idx %d: rc = %d\n",
637 oa->o_id, loi->loi_id, loi->loi_ost_idx, err);
645 static int lov_osc_brw_callback(struct io_cb_data *cbd, int err, int phase)
650 if (phase == CB_PHASE_START)
653 if (phase == CB_PHASE_FINISH) {
656 if (atomic_dec_and_test(&cbd->refcount))
657 ret = cbd->cb(cbd->data, cbd->err, phase);
665 static inline int lov_brw(int cmd, struct lustre_handle *conn,
666 struct lov_stripe_md *lsm, obd_count oa_bufs,
667 struct brw_page *pga,
668 brw_callback_t callback, struct io_cb_data *cbd)
670 int stripe_count = lsm->lsm_stripe_count;
671 struct obd_export *export = class_conn2export(conn);
677 struct lov_stripe_md lsm;
679 } *stripeinfo, *si, *si_last;
680 struct brw_page *ioarr;
682 struct io_cb_data *our_cb;
683 struct lov_oinfo *loi;
688 CERROR("LOV requires striping ea\n");
692 if (lsm->lsm_magic != LOV_MAGIC) {
693 CERROR("LOV striping magic bad %#lx != %#lx\n",
694 lsm->lsm_magic, LOV_MAGIC);
698 lov = &export->exp_obd->u.lov;
700 our_cb = ll_init_cb();
704 OBD_ALLOC(stripeinfo, stripe_count * sizeof(*stripeinfo));
706 GOTO(out_cbdata, rc = -ENOMEM);
708 OBD_ALLOC(where, sizeof(*where) * oa_bufs);
710 GOTO(out_sinfo, rc = -ENOMEM);
712 OBD_ALLOC(ioarr, sizeof(*ioarr) * oa_bufs);
714 GOTO(out_where, rc = -ENOMEM);
716 /* This is the only race-free way I can think of to get the refcount
718 atomic_set(&our_cb->refcount, 0);
719 our_cb->cb = callback;
722 for (i = 0; i < oa_bufs; i++) {
723 where[i] = lov_stripe_which(lsm, pga[i].off);
724 if (stripeinfo[where[i]].bufct++ == 0)
725 atomic_inc(&our_cb->refcount);
728 for (i = 0, loi = lsm->lsm_oinfo, si_last = si = stripeinfo;
729 i < stripe_count; i++, loi++, si_last = si, si++) {
731 si->index = si_last->index + si_last->bufct;
732 si->lsm.lsm_object_id = loi->loi_id;
733 si->ost_idx = loi->loi_ost_idx;
736 for (i = 0; i < oa_bufs; i++) {
737 int which = where[i];
740 shift = stripeinfo[which].index + stripeinfo[which].subcount;
741 LASSERT(shift < oa_bufs);
742 ioarr[shift] = pga[i];
743 ioarr[shift].off = lov_offset(lsm, pga[i].off, which);
744 stripeinfo[which].subcount++;
747 for (i = 0, si = stripeinfo; i < stripe_count; i++, si++) {
748 int shift = si->index;
751 LASSERT(shift < oa_bufs);
752 obd_brw(cmd, &lov->tgts[si->ost_idx].conn,
753 &si->lsm, si->bufct, &ioarr[shift],
754 lov_osc_brw_callback, our_cb);
758 rc = callback(cbd, 0, CB_PHASE_START);
760 OBD_FREE(ioarr, sizeof(*ioarr) * oa_bufs);
762 OBD_FREE(where, sizeof(*where) * oa_bufs);
764 OBD_FREE(stripeinfo, stripe_count * sizeof(*stripeinfo));
766 OBD_FREE(our_cb, sizeof(*our_cb));
770 static int lov_enqueue(struct lustre_handle *conn, struct lov_stripe_md *lsm,
771 struct lustre_handle *parent_lock,
772 __u32 type, void *cookie, int cookielen, __u32 mode,
773 int *flags, void *cb, void *data, int datalen,
774 struct lustre_handle *lockhs)
776 struct obd_export *export = class_conn2export(conn);
778 struct lov_oinfo *loi;
783 CERROR("LOV requires striping ea\n");
787 if (lsm->lsm_magic != LOV_MAGIC) {
788 CERROR("LOV striping magic bad %#lx != %#lx\n",
789 lsm->lsm_magic, LOV_MAGIC);
793 if (!export || !export->exp_obd)
796 lov = &export->exp_obd->u.lov;
797 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
798 struct ldlm_extent *extent = (struct ldlm_extent *)cookie;
799 struct ldlm_extent sub_ext;
800 struct lov_stripe_md submd;
802 sub_ext.start = lov_offset(lsm, extent->start, i);
803 sub_ext.end = lov_offset(lsm, extent->end, i);
804 if (sub_ext.start == sub_ext.end)
807 submd.lsm_object_id = loi->loi_id;
808 /* XXX submd lsm_mds_easize should be that from the subobj,
809 * and the subobj should get it opaquely from the LOV.
811 submd.lsm_mds_easize = lov_mds_md_size(lsm->lsm_ost_count);
812 submd.lsm_stripe_count = 0;
813 /* XXX submd is not fully initialized here */
814 rc = obd_enqueue(&(lov->tgts[loi->loi_ost_idx].conn), &submd,
815 parent_lock, type, &sub_ext, sizeof(sub_ext),
816 mode, flags, cb, data, datalen, &(lockhs[i]));
817 // XXX add a lock debug statement here
819 CERROR("Error enqueue objid "LPX64" subobj "LPX64
820 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
821 loi->loi_id, loi->loi_ost_idx, rc);
826 static int lov_cancel(struct lustre_handle *conn, struct lov_stripe_md *lsm,
827 __u32 mode, struct lustre_handle *lockhs)
829 struct obd_export *export = class_conn2export(conn);
831 struct lov_oinfo *loi;
836 CERROR("LOV requires striping ea\n");
840 if (lsm->lsm_magic != LOV_MAGIC) {
841 CERROR("LOV striping magic bad %#lx != %#lx\n",
842 lsm->lsm_magic, LOV_MAGIC);
846 if (!export || !export->exp_obd)
849 lov = &export->exp_obd->u.lov;
850 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
851 struct lov_stripe_md submd;
853 if (lockhs[i].addr == 0)
856 submd.lsm_object_id = loi->loi_id;
857 submd.lsm_mds_easize = lov_mds_md_size(lsm->lsm_ost_count);
858 submd.lsm_stripe_count = 0;
859 rc = obd_cancel(&lov->tgts[loi->loi_ost_idx].conn, &submd,
862 CERROR("Error cancel objid "LPX64" subobj "LPX64
863 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
864 loi->loi_id, loi->loi_ost_idx, rc);
869 static int lov_cancel_unused(struct lustre_handle *conn,
870 struct lov_stripe_md *lsm)
872 struct obd_export *export = class_conn2export(conn);
874 struct lov_oinfo *loi;
879 CERROR("LOV requires striping ea for lock cancellation\n");
883 if (!export || !export->exp_obd)
886 lov = &export->exp_obd->u.lov;
887 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
888 struct lov_stripe_md submd;
890 submd.lsm_object_id = loi->loi_id;
891 submd.lsm_mds_easize = lov_mds_md_size(lsm->lsm_ost_count);
892 submd.lsm_stripe_count = 0;
893 rc = obd_cancel_unused(&lov->tgts[loi->loi_ost_idx].conn,
896 CERROR("Error cancel unused objid "LPX64" subobj "LPX64
897 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
898 loi->loi_id, loi->loi_ost_idx, rc);
903 static int lov_statfs(struct lustre_handle *conn, struct obd_statfs *osfs)
905 struct obd_export *export = class_conn2export(conn);
907 struct obd_statfs lov_sfs;
913 if (!export || !export->exp_obd)
916 lov = &export->exp_obd->u.lov;
918 /* We only get block data from the OBD */
919 for (i = 0 ; i < lov->desc.ld_tgt_count; i++) {
922 err = obd_statfs(&lov->tgts[i].conn, &lov_sfs);
924 CERROR("Error statfs OSC %s idx %d: err = %d\n",
925 lov->tgts[i].uuid, i, err);
928 continue; /* XXX or break? - probably OK to continue */
931 memcpy(osfs, &lov_sfs, sizeof(lov_sfs));
934 osfs->os_bfree += lov_sfs.os_bfree;
935 osfs->os_bavail += lov_sfs.os_bavail;
936 osfs->os_blocks += lov_sfs.os_blocks;
937 /* XXX not sure about this one - depends on policy.
938 * - could be minimum if we always stripe on all OBDs
939 * (but that would be wrong for any other policy,
940 * if one of the OBDs has no more objects left)
941 * - could be sum if we stripe whole objects
942 * - could be average, just to give a nice number
943 * - we just pick first OST and hope it is enough
944 sfs->f_ffree += lov_sfs.f_ffree;
952 struct obd_ops lov_obd_ops = {
954 o_connect: lov_connect,
955 o_disconnect: lov_disconnect,
956 o_create: lov_create,
957 o_destroy: lov_destroy,
958 o_getattr: lov_getattr,
959 o_setattr: lov_setattr,
960 o_statfs: lov_statfs,
965 o_enqueue: lov_enqueue,
966 o_cancel: lov_cancel,
967 o_cancel_unused: lov_cancel_unused
971 #define LOV_VERSION "v0.1"
973 static int __init lov_init(void)
975 printk(KERN_INFO "Lustre Logical Object Volume driver " LOV_VERSION
976 ", info@clusterfs.com\n");
977 return class_register_type(&lov_obd_ops, OBD_LOV_DEVICENAME);
980 static void __exit lov_exit(void)
982 class_unregister_type(OBD_LOV_DEVICENAME);
985 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
986 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver v0.1");
987 MODULE_LICENSE("GPL");
989 module_init(lov_init);
990 module_exit(lov_exit);