4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 # define EXPORT_SYMTAB
40 #define DEBUG_SUBSYSTEM S_LOV
43 #include <libcfs/libcfs.h>
45 #include <liblustre.h>
48 #include <obd_class.h>
50 #include <lustre/lustre_idl.h>
52 #include "lov_internal.h"
54 static void lov_init_set(struct lov_request_set *set)
57 cfs_atomic_set(&set->set_completes, 0);
58 cfs_atomic_set(&set->set_success, 0);
60 CFS_INIT_LIST_HEAD(&set->set_list);
61 cfs_atomic_set(&set->set_refcount, 1);
62 cfs_waitq_init(&set->set_waitq);
63 cfs_spin_lock_init(&set->set_lock);
66 void lov_finish_set(struct lov_request_set *set)
72 cfs_list_for_each_safe(pos, n, &set->set_list) {
73 struct lov_request *req = cfs_list_entry(pos,
76 cfs_list_del_init(&req->rq_link);
79 OBDO_FREE(req->rq_oi.oi_oa);
81 OBD_FREE_LARGE(req->rq_oi.oi_md, req->rq_buflen);
82 if (req->rq_oi.oi_osfs)
83 OBD_FREE(req->rq_oi.oi_osfs,
84 sizeof(*req->rq_oi.oi_osfs));
85 OBD_FREE(req, sizeof(*req));
89 int len = set->set_oabufs * sizeof(*set->set_pga);
90 OBD_FREE_LARGE(set->set_pga, len);
93 lov_llh_put(set->set_lockh);
95 OBD_FREE(set, sizeof(*set));
99 int lov_finished_set(struct lov_request_set *set)
101 int completes = cfs_atomic_read(&set->set_completes);
103 CDEBUG(D_INFO, "check set %d/%d\n", completes,
105 return completes == set->set_count;
108 void lov_update_set(struct lov_request_set *set,
109 struct lov_request *req, int rc)
111 req->rq_complete = 1;
114 cfs_atomic_inc(&set->set_completes);
116 cfs_atomic_inc(&set->set_success);
118 cfs_waitq_signal(&set->set_waitq);
121 int lov_update_common_set(struct lov_request_set *set,
122 struct lov_request *req, int rc)
124 struct lov_obd *lov = &set->set_exp->exp_obd->u.lov;
127 lov_update_set(set, req, rc);
129 /* grace error on inactive ost */
130 if (rc && !(lov->lov_tgts[req->rq_idx] &&
131 lov->lov_tgts[req->rq_idx]->ltd_active))
134 /* FIXME in raid1 regime, should return 0 */
138 void lov_set_add_req(struct lov_request *req, struct lov_request_set *set)
140 cfs_list_add_tail(&req->rq_link, &set->set_list);
145 extern void osc_update_enqueue(struct lustre_handle *lov_lockhp,
146 struct lov_oinfo *loi, int flags,
147 struct ost_lvb *lvb, __u32 mode, int rc);
149 static int lov_update_enqueue_lov(struct obd_export *exp,
150 struct lustre_handle *lov_lockhp,
151 struct lov_oinfo *loi, int flags, int idx,
154 struct lov_obd *lov = &exp->exp_obd->u.lov;
156 if (rc != ELDLM_OK &&
157 !(rc == ELDLM_LOCK_ABORTED && (flags & LDLM_FL_HAS_INTENT))) {
158 memset(lov_lockhp, 0, sizeof(*lov_lockhp));
159 if (lov->lov_tgts[idx] && lov->lov_tgts[idx]->ltd_active) {
160 /* -EUSERS used by OST to report file contention */
161 if (rc != -EINTR && rc != -EUSERS)
162 CERROR("enqueue objid "LPX64" subobj "
163 LPX64" on OST idx %d: rc %d\n",
164 oid, loi->loi_id, loi->loi_ost_idx, rc);
171 int lov_update_enqueue_set(struct lov_request *req, __u32 mode, int rc)
173 struct lov_request_set *set = req->rq_rqset;
174 struct lustre_handle *lov_lockhp;
175 struct obd_info *oi = set->set_oi;
176 struct lov_oinfo *loi;
181 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
182 loi = oi->oi_md->lsm_oinfo[req->rq_stripe];
184 /* XXX LOV STACKING: OSC gets a copy, created in lov_prep_enqueue_set
185 * and that copy can be arbitrarily out of date.
187 * The LOV API is due for a serious rewriting anyways, and this
188 * can be addressed then. */
190 lov_stripe_lock(oi->oi_md);
191 osc_update_enqueue(lov_lockhp, loi, oi->oi_flags,
192 &req->rq_oi.oi_md->lsm_oinfo[0]->loi_lvb, mode, rc);
193 if (rc == ELDLM_LOCK_ABORTED && (oi->oi_flags & LDLM_FL_HAS_INTENT))
194 memset(lov_lockhp, 0, sizeof *lov_lockhp);
195 rc = lov_update_enqueue_lov(set->set_exp, lov_lockhp, loi, oi->oi_flags,
196 req->rq_idx, oi->oi_md->lsm_object_id, rc);
197 lov_stripe_unlock(oi->oi_md);
198 lov_update_set(set, req, rc);
202 /* The callback for osc_enqueue that updates lov info for every OSC request. */
203 static int cb_update_enqueue(void *cookie, int rc)
205 struct obd_info *oinfo = cookie;
206 struct ldlm_enqueue_info *einfo;
207 struct lov_request *lovreq;
209 lovreq = container_of(oinfo, struct lov_request, rq_oi);
210 einfo = lovreq->rq_rqset->set_ei;
211 return lov_update_enqueue_set(lovreq, einfo->ei_mode, rc);
214 static int enqueue_done(struct lov_request_set *set, __u32 mode)
216 struct lov_request *req;
217 struct lov_obd *lov = &set->set_exp->exp_obd->u.lov;
218 int completes = cfs_atomic_read(&set->set_completes);
222 /* enqueue/match success, just return */
223 if (completes && completes == cfs_atomic_read(&set->set_success))
226 /* cancel enqueued/matched locks */
227 cfs_list_for_each_entry(req, &set->set_list, rq_link) {
228 struct lustre_handle *lov_lockhp;
230 if (!req->rq_complete || req->rq_rc)
233 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
235 if (!lustre_handle_is_used(lov_lockhp))
238 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
239 req->rq_oi.oi_md, mode, lov_lockhp);
240 if (rc && lov->lov_tgts[req->rq_idx] &&
241 lov->lov_tgts[req->rq_idx]->ltd_active)
242 CERROR("cancelling obdjid "LPX64" on OST "
243 "idx %d error: rc = %d\n",
244 req->rq_oi.oi_md->lsm_object_id,
248 lov_llh_put(set->set_lockh);
252 int lov_fini_enqueue_set(struct lov_request_set *set, __u32 mode, int rc,
253 struct ptlrpc_request_set *rqset)
260 LASSERT(set->set_exp);
261 /* Do enqueue_done only for sync requests and if any request
265 cfs_atomic_set(&set->set_completes, 0);
266 ret = enqueue_done(set, mode);
267 } else if (set->set_lockh)
268 lov_llh_put(set->set_lockh);
272 RETURN(rc ? rc : ret);
275 static void lov_llh_addref(void *llhp)
277 struct lov_lock_handles *llh = llhp;
279 cfs_atomic_inc(&llh->llh_refcount);
280 CDEBUG(D_INFO, "GETting llh %p : new refcount %d\n", llh,
281 cfs_atomic_read(&llh->llh_refcount));
284 static struct portals_handle_ops lov_handle_ops = {
285 .hop_addref = lov_llh_addref,
289 static struct lov_lock_handles *lov_llh_new(struct lov_stripe_md *lsm)
291 struct lov_lock_handles *llh;
293 OBD_ALLOC(llh, sizeof *llh +
294 sizeof(*llh->llh_handles) * lsm->lsm_stripe_count);
298 cfs_atomic_set(&llh->llh_refcount, 2);
299 llh->llh_stripe_count = lsm->lsm_stripe_count;
300 CFS_INIT_LIST_HEAD(&llh->llh_handle.h_link);
301 class_handle_hash(&llh->llh_handle, &lov_handle_ops);
306 int lov_prep_enqueue_set(struct obd_export *exp, struct obd_info *oinfo,
307 struct ldlm_enqueue_info *einfo,
308 struct lov_request_set **reqset)
310 struct lov_obd *lov = &exp->exp_obd->u.lov;
311 struct lov_request_set *set;
315 OBD_ALLOC(set, sizeof(*set));
323 set->set_lockh = lov_llh_new(oinfo->oi_md);
324 if (set->set_lockh == NULL)
325 GOTO(out_set, rc = -ENOMEM);
326 oinfo->oi_lockh->cookie = set->set_lockh->llh_handle.h_cookie;
328 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
329 struct lov_oinfo *loi;
330 struct lov_request *req;
333 loi = oinfo->oi_md->lsm_oinfo[i];
334 if (!lov_stripe_intersects(oinfo->oi_md, i,
335 oinfo->oi_policy.l_extent.start,
336 oinfo->oi_policy.l_extent.end,
340 if (!lov->lov_tgts[loi->loi_ost_idx] ||
341 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
342 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
346 OBD_ALLOC(req, sizeof(*req));
348 GOTO(out_set, rc = -ENOMEM);
350 req->rq_buflen = sizeof(*req->rq_oi.oi_md) +
351 sizeof(struct lov_oinfo *) +
352 sizeof(struct lov_oinfo);
353 OBD_ALLOC_LARGE(req->rq_oi.oi_md, req->rq_buflen);
354 if (req->rq_oi.oi_md == NULL) {
355 OBD_FREE(req, sizeof(*req));
356 GOTO(out_set, rc = -ENOMEM);
358 req->rq_oi.oi_md->lsm_oinfo[0] =
359 ((void *)req->rq_oi.oi_md) + sizeof(*req->rq_oi.oi_md) +
360 sizeof(struct lov_oinfo *);
362 /* Set lov request specific parameters. */
363 req->rq_oi.oi_lockh = set->set_lockh->llh_handles + i;
364 req->rq_oi.oi_cb_up = cb_update_enqueue;
365 req->rq_oi.oi_flags = oinfo->oi_flags;
367 LASSERT(req->rq_oi.oi_lockh);
369 req->rq_oi.oi_policy.l_extent.gid =
370 oinfo->oi_policy.l_extent.gid;
371 req->rq_oi.oi_policy.l_extent.start = start;
372 req->rq_oi.oi_policy.l_extent.end = end;
374 req->rq_idx = loi->loi_ost_idx;
377 /* XXX LOV STACKING: submd should be from the subobj */
378 req->rq_oi.oi_md->lsm_object_id = loi->loi_id;
379 req->rq_oi.oi_md->lsm_object_seq = loi->loi_seq;
380 req->rq_oi.oi_md->lsm_stripe_count = 0;
381 req->rq_oi.oi_md->lsm_oinfo[0]->loi_kms_valid =
383 req->rq_oi.oi_md->lsm_oinfo[0]->loi_kms = loi->loi_kms;
384 req->rq_oi.oi_md->lsm_oinfo[0]->loi_lvb = loi->loi_lvb;
386 lov_set_add_req(req, set);
389 GOTO(out_set, rc = -EIO);
393 lov_fini_enqueue_set(set, einfo->ei_mode, rc, NULL);
397 int lov_fini_match_set(struct lov_request_set *set, __u32 mode, int flags)
404 LASSERT(set->set_exp);
405 rc = enqueue_done(set, mode);
406 if ((set->set_count == cfs_atomic_read(&set->set_success)) &&
407 (flags & LDLM_FL_TEST_LOCK))
408 lov_llh_put(set->set_lockh);
415 int lov_prep_match_set(struct obd_export *exp, struct obd_info *oinfo,
416 struct lov_stripe_md *lsm, ldlm_policy_data_t *policy,
417 __u32 mode, struct lustre_handle *lockh,
418 struct lov_request_set **reqset)
420 struct lov_obd *lov = &exp->exp_obd->u.lov;
421 struct lov_request_set *set;
425 OBD_ALLOC(set, sizeof(*set));
432 set->set_oi->oi_md = lsm;
433 set->set_lockh = lov_llh_new(lsm);
434 if (set->set_lockh == NULL)
435 GOTO(out_set, rc = -ENOMEM);
436 lockh->cookie = set->set_lockh->llh_handle.h_cookie;
438 for (i = 0; i < lsm->lsm_stripe_count; i++){
439 struct lov_oinfo *loi;
440 struct lov_request *req;
443 loi = lsm->lsm_oinfo[i];
444 if (!lov_stripe_intersects(lsm, i, policy->l_extent.start,
445 policy->l_extent.end, &start, &end))
448 /* FIXME raid1 should grace this error */
449 if (!lov->lov_tgts[loi->loi_ost_idx] ||
450 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
451 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
452 GOTO(out_set, rc = -EIO);
455 OBD_ALLOC(req, sizeof(*req));
457 GOTO(out_set, rc = -ENOMEM);
459 req->rq_buflen = sizeof(*req->rq_oi.oi_md);
460 OBD_ALLOC_LARGE(req->rq_oi.oi_md, req->rq_buflen);
461 if (req->rq_oi.oi_md == NULL) {
462 OBD_FREE(req, sizeof(*req));
463 GOTO(out_set, rc = -ENOMEM);
466 req->rq_oi.oi_policy.l_extent.start = start;
467 req->rq_oi.oi_policy.l_extent.end = end;
468 req->rq_oi.oi_policy.l_extent.gid = policy->l_extent.gid;
470 req->rq_idx = loi->loi_ost_idx;
473 /* XXX LOV STACKING: submd should be from the subobj */
474 req->rq_oi.oi_md->lsm_object_id = loi->loi_id;
475 req->rq_oi.oi_md->lsm_object_seq = loi->loi_seq;
476 req->rq_oi.oi_md->lsm_stripe_count = 0;
478 lov_set_add_req(req, set);
481 GOTO(out_set, rc = -EIO);
485 lov_fini_match_set(set, mode, 0);
489 int lov_fini_cancel_set(struct lov_request_set *set)
497 LASSERT(set->set_exp);
499 lov_llh_put(set->set_lockh);
506 int lov_prep_cancel_set(struct obd_export *exp, struct obd_info *oinfo,
507 struct lov_stripe_md *lsm, __u32 mode,
508 struct lustre_handle *lockh,
509 struct lov_request_set **reqset)
511 struct lov_request_set *set;
515 OBD_ALLOC(set, sizeof(*set));
522 set->set_oi->oi_md = lsm;
523 set->set_lockh = lov_handle2llh(lockh);
524 if (set->set_lockh == NULL) {
525 CERROR("LOV: invalid lov lock handle %p\n", lockh);
526 GOTO(out_set, rc = -EINVAL);
528 lockh->cookie = set->set_lockh->llh_handle.h_cookie;
530 for (i = 0; i < lsm->lsm_stripe_count; i++){
531 struct lov_request *req;
532 struct lustre_handle *lov_lockhp;
533 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
535 lov_lockhp = set->set_lockh->llh_handles + i;
536 if (!lustre_handle_is_used(lov_lockhp)) {
537 CDEBUG(D_INFO, "lov idx %d subobj "LPX64" no lock\n",
538 loi->loi_ost_idx, loi->loi_id);
542 OBD_ALLOC(req, sizeof(*req));
544 GOTO(out_set, rc = -ENOMEM);
546 req->rq_buflen = sizeof(*req->rq_oi.oi_md);
547 OBD_ALLOC_LARGE(req->rq_oi.oi_md, req->rq_buflen);
548 if (req->rq_oi.oi_md == NULL) {
549 OBD_FREE(req, sizeof(*req));
550 GOTO(out_set, rc = -ENOMEM);
553 req->rq_idx = loi->loi_ost_idx;
556 /* XXX LOV STACKING: submd should be from the subobj */
557 req->rq_oi.oi_md->lsm_object_id = loi->loi_id;
558 req->rq_oi.oi_md->lsm_object_seq = loi->loi_seq;
559 req->rq_oi.oi_md->lsm_stripe_count = 0;
561 lov_set_add_req(req, set);
564 GOTO(out_set, rc = -EIO);
568 lov_fini_cancel_set(set);
572 static int lov_update_create_set(struct lov_request_set *set,
573 struct lov_request *req, int rc)
575 struct obd_trans_info *oti = set->set_oti;
576 struct lov_stripe_md *lsm = set->set_oi->oi_md;
577 struct lov_oinfo *loi;
578 struct lov_obd *lov = &set->set_exp->exp_obd->u.lov;
581 if (rc && lov->lov_tgts[req->rq_idx] &&
582 lov->lov_tgts[req->rq_idx]->ltd_active) {
583 /* Pre-creating objects may timeout via -ETIMEDOUT or
584 * -ENOTCONN both are always non-critical events. */
585 CDEBUG(rc == -ETIMEDOUT || rc == -ENOTCONN ? D_HA : D_ERROR,
586 "error creating fid "LPX64" sub-object "
587 "on OST idx %d/%d: rc = %d\n",
588 set->set_oi->oi_oa->o_id, req->rq_idx,
589 lsm->lsm_stripe_count, rc);
591 CERROR("obd_create returned invalid err %d\n", rc);
596 cfs_spin_lock(&set->set_lock);
597 req->rq_stripe = cfs_atomic_read(&set->set_success);
598 loi = lsm->lsm_oinfo[req->rq_stripe];
602 lov_update_set(set, req, rc);
603 cfs_spin_unlock(&set->set_lock);
607 loi->loi_id = req->rq_oi.oi_oa->o_id;
608 loi->loi_seq = req->rq_oi.oi_oa->o_seq;
609 loi->loi_ost_idx = req->rq_idx;
612 if (oti && set->set_cookies)
613 ++oti->oti_logcookies;
614 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLCOOKIE)
615 set->set_cookie_sent++;
617 lov_update_set(set, req, rc);
618 cfs_spin_unlock(&set->set_lock);
620 CDEBUG(D_INODE, "objid "LPX64" has subobj "LPX64"/"LPU64" at idx %d\n",
621 lsm->lsm_object_id, loi->loi_id, loi->loi_id, req->rq_idx);
625 static int create_done(struct obd_export *exp, struct lov_request_set *set,
626 struct lov_stripe_md **lsmp)
628 struct lov_obd *lov = &exp->exp_obd->u.lov;
629 struct obd_trans_info *oti = set->set_oti;
630 struct obdo *src_oa = set->set_oi->oi_oa;
631 struct lov_request *req;
632 struct obdo *ret_oa = NULL;
633 int success, attrset = 0, rc = 0;
636 LASSERT(cfs_atomic_read(&set->set_completes));
638 /* try alloc objects on other osts if osc_create fails for
639 * exceptions: RPC failure, ENOSPC, etc */
640 if (set->set_count != cfs_atomic_read(&set->set_success)) {
641 cfs_list_for_each_entry (req, &set->set_list, rq_link) {
645 cfs_atomic_dec(&set->set_completes);
646 req->rq_complete = 0;
648 rc = qos_remedy_create(set, req);
649 lov_update_create_set(set, req, rc);
653 success = cfs_atomic_read(&set->set_success);
654 /* no successful creates */
658 if (set->set_count != success) {
659 set->set_count = success;
665 GOTO(cleanup, rc = -ENOMEM);
667 cfs_list_for_each_entry(req, &set->set_list, rq_link) {
668 if (!req->rq_complete || req->rq_rc)
670 lov_merge_attrs(ret_oa, req->rq_oi.oi_oa,
671 req->rq_oi.oi_oa->o_valid, set->set_oi->oi_md,
672 req->rq_stripe, &attrset);
674 if (src_oa->o_valid & OBD_MD_FLSIZE &&
675 ret_oa->o_size != src_oa->o_size) {
676 CERROR("original size "LPU64" isn't new object size "LPU64"\n",
677 src_oa->o_size, ret_oa->o_size);
680 ret_oa->o_id = src_oa->o_id;
681 ret_oa->o_seq = src_oa->o_seq;
682 ret_oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP;
683 memcpy(src_oa, ret_oa, sizeof(*src_oa));
686 *lsmp = set->set_oi->oi_md;
690 cfs_list_for_each_entry(req, &set->set_list, rq_link) {
691 struct obd_export *sub_exp;
694 if (!req->rq_complete || req->rq_rc)
697 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
698 err = obd_destroy(NULL, sub_exp, req->rq_oi.oi_oa, NULL, oti,
701 CERROR("Failed to uncreate objid "LPX64" subobj "
702 LPX64" on OST idx %d: rc = %d\n",
703 src_oa->o_id, req->rq_oi.oi_oa->o_id,
707 obd_free_memmd(exp, &set->set_oi->oi_md);
709 if (oti && set->set_cookies) {
710 oti->oti_logcookies = set->set_cookies;
711 if (!set->set_cookie_sent) {
712 oti_free_cookies(oti);
713 src_oa->o_valid &= ~OBD_MD_FLCOOKIE;
715 src_oa->o_valid |= OBD_MD_FLCOOKIE;
721 int lov_fini_create_set(struct lov_request_set *set,struct lov_stripe_md **lsmp)
728 LASSERT(set->set_exp);
729 if (cfs_atomic_read(&set->set_completes))
730 rc = create_done(set->set_exp, set, lsmp);
736 int cb_create_update(void *cookie, int rc)
738 struct obd_info *oinfo = cookie;
739 struct lov_request *lovreq;
741 lovreq = container_of(oinfo, struct lov_request, rq_oi);
743 if (CFS_FAIL_CHECK(OBD_FAIL_MDS_OSC_CREATE_FAIL))
744 if (lovreq->rq_idx == cfs_fail_val)
747 rc= lov_update_create_set(lovreq->rq_rqset, lovreq, rc);
748 if (lov_finished_set(lovreq->rq_rqset))
749 lov_put_reqset(lovreq->rq_rqset);
753 int lov_prep_create_set(struct obd_export *exp, struct obd_info *oinfo,
754 struct lov_stripe_md **lsmp, struct obdo *src_oa,
755 struct obd_trans_info *oti,
756 struct lov_request_set **reqset)
758 struct lov_request_set *set;
762 OBD_ALLOC(set, sizeof(*set));
769 set->set_oi->oi_md = *lsmp;
770 set->set_oi->oi_oa = src_oa;
774 rc = qos_prep_create(exp, set);
775 /* qos_shrink_lsm() may have allocated a new lsm */
776 *lsmp = oinfo->oi_md;
778 lov_fini_create_set(set, lsmp);
786 static int common_attr_done(struct lov_request_set *set)
789 struct lov_request *req;
791 int rc = 0, attrset = 0;
794 LASSERT(set->set_oi != NULL);
796 if (set->set_oi->oi_oa == NULL)
799 if (!cfs_atomic_read(&set->set_success))
804 GOTO(out, rc = -ENOMEM);
806 cfs_list_for_each (pos, &set->set_list) {
807 req = cfs_list_entry(pos, struct lov_request, rq_link);
809 if (!req->rq_complete || req->rq_rc)
811 if (req->rq_oi.oi_oa->o_valid == 0) /* inactive stripe */
813 lov_merge_attrs(tmp_oa, req->rq_oi.oi_oa,
814 req->rq_oi.oi_oa->o_valid,
815 set->set_oi->oi_md, req->rq_stripe, &attrset);
818 CERROR("No stripes had valid attrs\n");
821 if ((set->set_oi->oi_oa->o_valid & OBD_MD_FLEPOCH) &&
822 (set->set_oi->oi_md->lsm_stripe_count != attrset)) {
823 /* When we take attributes of some epoch, we require all the
824 * ost to be active. */
825 CERROR("Not all the stripes had valid attrs\n");
826 GOTO(out, rc = -EIO);
829 tmp_oa->o_id = set->set_oi->oi_oa->o_id;
830 memcpy(set->set_oi->oi_oa, tmp_oa, sizeof(*set->set_oi->oi_oa));
838 static int brw_done(struct lov_request_set *set)
840 struct lov_stripe_md *lsm = set->set_oi->oi_md;
841 struct lov_oinfo *loi = NULL;
843 struct lov_request *req;
846 cfs_list_for_each (pos, &set->set_list) {
847 req = cfs_list_entry(pos, struct lov_request, rq_link);
849 if (!req->rq_complete || req->rq_rc)
852 loi = lsm->lsm_oinfo[req->rq_stripe];
854 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLBLOCKS)
855 loi->loi_lvb.lvb_blocks = req->rq_oi.oi_oa->o_blocks;
861 int lov_fini_brw_set(struct lov_request_set *set)
868 LASSERT(set->set_exp);
869 if (cfs_atomic_read(&set->set_completes)) {
871 /* FIXME update qos data here */
878 int lov_prep_brw_set(struct obd_export *exp, struct obd_info *oinfo,
879 obd_count oa_bufs, struct brw_page *pga,
880 struct obd_trans_info *oti,
881 struct lov_request_set **reqset)
888 struct lov_request_set *set;
889 struct lov_obd *lov = &exp->exp_obd->u.lov;
890 int rc = 0, i, shift;
893 OBD_ALLOC(set, sizeof(*set));
901 set->set_oabufs = oa_bufs;
902 OBD_ALLOC_LARGE(set->set_pga, oa_bufs * sizeof(*set->set_pga));
904 GOTO(out, rc = -ENOMEM);
906 OBD_ALLOC_LARGE(info, sizeof(*info) * oinfo->oi_md->lsm_stripe_count);
908 GOTO(out, rc = -ENOMEM);
910 /* calculate the page count for each stripe */
911 for (i = 0; i < oa_bufs; i++) {
912 int stripe = lov_stripe_number(oinfo->oi_md, pga[i].off);
913 info[stripe].count++;
916 /* alloc and initialize lov request */
918 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++){
919 struct lov_oinfo *loi = NULL;
920 struct lov_request *req;
922 if (info[i].count == 0)
925 loi = oinfo->oi_md->lsm_oinfo[i];
926 if (!lov->lov_tgts[loi->loi_ost_idx] ||
927 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
928 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
929 GOTO(out, rc = -EIO);
932 OBD_ALLOC(req, sizeof(*req));
934 GOTO(out, rc = -ENOMEM);
936 OBDO_ALLOC(req->rq_oi.oi_oa);
937 if (req->rq_oi.oi_oa == NULL) {
938 OBD_FREE(req, sizeof(*req));
939 GOTO(out, rc = -ENOMEM);
943 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
944 sizeof(*req->rq_oi.oi_oa));
946 req->rq_oi.oi_oa->o_id = loi->loi_id;
947 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
948 req->rq_oi.oi_oa->o_stripe_idx = i;
950 req->rq_buflen = sizeof(*req->rq_oi.oi_md);
951 OBD_ALLOC_LARGE(req->rq_oi.oi_md, req->rq_buflen);
952 if (req->rq_oi.oi_md == NULL) {
953 OBDO_FREE(req->rq_oi.oi_oa);
954 OBD_FREE(req, sizeof(*req));
955 GOTO(out, rc = -ENOMEM);
958 req->rq_idx = loi->loi_ost_idx;
961 /* XXX LOV STACKING */
962 req->rq_oi.oi_md->lsm_object_id = loi->loi_id;
963 req->rq_oi.oi_md->lsm_object_seq = loi->loi_seq;
964 req->rq_oabufs = info[i].count;
965 req->rq_pgaidx = shift;
966 shift += req->rq_oabufs;
968 /* remember the index for sort brw_page array */
969 info[i].index = req->rq_pgaidx;
971 req->rq_oi.oi_capa = oinfo->oi_capa;
973 lov_set_add_req(req, set);
976 GOTO(out, rc = -EIO);
978 /* rotate & sort the brw_page array */
979 for (i = 0; i < oa_bufs; i++) {
980 int stripe = lov_stripe_number(oinfo->oi_md, pga[i].off);
982 shift = info[stripe].index + info[stripe].off;
983 LASSERT(shift < oa_bufs);
984 set->set_pga[shift] = pga[i];
985 lov_stripe_offset(oinfo->oi_md, pga[i].off, stripe,
986 &set->set_pga[shift].off);
992 sizeof(*info) * oinfo->oi_md->lsm_stripe_count);
997 lov_fini_brw_set(set);
1002 int lov_fini_getattr_set(struct lov_request_set *set)
1009 LASSERT(set->set_exp);
1010 if (cfs_atomic_read(&set->set_completes))
1011 rc = common_attr_done(set);
1013 lov_put_reqset(set);
1018 /* The callback for osc_getattr_async that finilizes a request info when a
1019 * response is received. */
1020 static int cb_getattr_update(void *cookie, int rc)
1022 struct obd_info *oinfo = cookie;
1023 struct lov_request *lovreq;
1024 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1025 return lov_update_common_set(lovreq->rq_rqset, lovreq, rc);
1028 int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo,
1029 struct lov_request_set **reqset)
1031 struct lov_request_set *set;
1032 struct lov_obd *lov = &exp->exp_obd->u.lov;
1036 OBD_ALLOC(set, sizeof(*set));
1042 set->set_oi = oinfo;
1044 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
1045 struct lov_oinfo *loi;
1046 struct lov_request *req;
1048 loi = oinfo->oi_md->lsm_oinfo[i];
1049 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1050 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1051 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1052 if (oinfo->oi_oa->o_valid & OBD_MD_FLEPOCH)
1053 /* SOM requires all the OSTs to be active. */
1054 GOTO(out_set, rc = -EIO);
1058 OBD_ALLOC(req, sizeof(*req));
1060 GOTO(out_set, rc = -ENOMEM);
1063 req->rq_idx = loi->loi_ost_idx;
1065 OBDO_ALLOC(req->rq_oi.oi_oa);
1066 if (req->rq_oi.oi_oa == NULL) {
1067 OBD_FREE(req, sizeof(*req));
1068 GOTO(out_set, rc = -ENOMEM);
1070 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
1071 sizeof(*req->rq_oi.oi_oa));
1072 req->rq_oi.oi_oa->o_id = loi->loi_id;
1073 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
1074 req->rq_oi.oi_cb_up = cb_getattr_update;
1075 req->rq_oi.oi_capa = oinfo->oi_capa;
1077 lov_set_add_req(req, set);
1079 if (!set->set_count)
1080 GOTO(out_set, rc = -EIO);
1084 lov_fini_getattr_set(set);
1088 int lov_fini_destroy_set(struct lov_request_set *set)
1094 LASSERT(set->set_exp);
1095 if (cfs_atomic_read(&set->set_completes)) {
1096 /* FIXME update qos data here */
1099 lov_put_reqset(set);
1104 int lov_prep_destroy_set(struct obd_export *exp, struct obd_info *oinfo,
1105 struct obdo *src_oa, struct lov_stripe_md *lsm,
1106 struct obd_trans_info *oti,
1107 struct lov_request_set **reqset)
1109 struct lov_request_set *set;
1110 struct lov_obd *lov = &exp->exp_obd->u.lov;
1114 OBD_ALLOC(set, sizeof(*set));
1120 set->set_oi = oinfo;
1121 set->set_oi->oi_md = lsm;
1122 set->set_oi->oi_oa = src_oa;
1124 if (oti != NULL && src_oa->o_valid & OBD_MD_FLCOOKIE)
1125 set->set_cookies = oti->oti_logcookies;
1127 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1128 struct lov_oinfo *loi;
1129 struct lov_request *req;
1131 loi = lsm->lsm_oinfo[i];
1132 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1133 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1134 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1138 OBD_ALLOC(req, sizeof(*req));
1140 GOTO(out_set, rc = -ENOMEM);
1143 req->rq_idx = loi->loi_ost_idx;
1145 OBDO_ALLOC(req->rq_oi.oi_oa);
1146 if (req->rq_oi.oi_oa == NULL) {
1147 OBD_FREE(req, sizeof(*req));
1148 GOTO(out_set, rc = -ENOMEM);
1150 memcpy(req->rq_oi.oi_oa, src_oa, sizeof(*req->rq_oi.oi_oa));
1151 req->rq_oi.oi_oa->o_id = loi->loi_id;
1152 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
1153 lov_set_add_req(req, set);
1155 if (!set->set_count)
1156 GOTO(out_set, rc = -EIO);
1160 lov_fini_destroy_set(set);
1164 int lov_fini_setattr_set(struct lov_request_set *set)
1171 LASSERT(set->set_exp);
1172 if (cfs_atomic_read(&set->set_completes)) {
1173 rc = common_attr_done(set);
1174 /* FIXME update qos data here */
1177 lov_put_reqset(set);
1181 int lov_update_setattr_set(struct lov_request_set *set,
1182 struct lov_request *req, int rc)
1184 struct lov_obd *lov = &req->rq_rqset->set_exp->exp_obd->u.lov;
1185 struct lov_stripe_md *lsm = req->rq_rqset->set_oi->oi_md;
1188 lov_update_set(set, req, rc);
1190 /* grace error on inactive ost */
1191 if (rc && !(lov->lov_tgts[req->rq_idx] &&
1192 lov->lov_tgts[req->rq_idx]->ltd_active))
1196 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLCTIME)
1197 lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_ctime =
1198 req->rq_oi.oi_oa->o_ctime;
1199 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLMTIME)
1200 lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_mtime =
1201 req->rq_oi.oi_oa->o_mtime;
1202 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLATIME)
1203 lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_atime =
1204 req->rq_oi.oi_oa->o_atime;
1210 /* The callback for osc_setattr_async that finilizes a request info when a
1211 * response is received. */
1212 static int cb_setattr_update(void *cookie, int rc)
1214 struct obd_info *oinfo = cookie;
1215 struct lov_request *lovreq;
1216 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1217 return lov_update_setattr_set(lovreq->rq_rqset, lovreq, rc);
1220 int lov_prep_setattr_set(struct obd_export *exp, struct obd_info *oinfo,
1221 struct obd_trans_info *oti,
1222 struct lov_request_set **reqset)
1224 struct lov_request_set *set;
1225 struct lov_obd *lov = &exp->exp_obd->u.lov;
1229 OBD_ALLOC(set, sizeof(*set));
1236 set->set_oi = oinfo;
1237 if (oti != NULL && oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1238 set->set_cookies = oti->oti_logcookies;
1240 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
1241 struct lov_oinfo *loi = oinfo->oi_md->lsm_oinfo[i];
1242 struct lov_request *req;
1244 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1245 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1246 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1250 OBD_ALLOC(req, sizeof(*req));
1252 GOTO(out_set, rc = -ENOMEM);
1254 req->rq_idx = loi->loi_ost_idx;
1256 OBDO_ALLOC(req->rq_oi.oi_oa);
1257 if (req->rq_oi.oi_oa == NULL) {
1258 OBD_FREE(req, sizeof(*req));
1259 GOTO(out_set, rc = -ENOMEM);
1261 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
1262 sizeof(*req->rq_oi.oi_oa));
1263 req->rq_oi.oi_oa->o_id = loi->loi_id;
1264 req->rq_oi.oi_oa->o_seq= loi->loi_seq;
1265 req->rq_oi.oi_oa->o_stripe_idx = i;
1266 req->rq_oi.oi_cb_up = cb_setattr_update;
1267 req->rq_oi.oi_capa = oinfo->oi_capa;
1269 if (oinfo->oi_oa->o_valid & OBD_MD_FLSIZE) {
1270 int off = lov_stripe_offset(oinfo->oi_md,
1271 oinfo->oi_oa->o_size, i,
1272 &req->rq_oi.oi_oa->o_size);
1274 if (off < 0 && req->rq_oi.oi_oa->o_size)
1275 req->rq_oi.oi_oa->o_size--;
1277 CDEBUG(D_INODE, "stripe %d has size "LPU64"/"LPU64"\n",
1278 i, req->rq_oi.oi_oa->o_size,
1279 oinfo->oi_oa->o_size);
1281 lov_set_add_req(req, set);
1283 if (!set->set_count)
1284 GOTO(out_set, rc = -EIO);
1288 lov_fini_setattr_set(set);
1292 int lov_fini_punch_set(struct lov_request_set *set)
1299 LASSERT(set->set_exp);
1300 if (cfs_atomic_read(&set->set_completes)) {
1302 /* FIXME update qos data here */
1303 if (cfs_atomic_read(&set->set_success))
1304 rc = common_attr_done(set);
1307 lov_put_reqset(set);
1312 int lov_update_punch_set(struct lov_request_set *set,
1313 struct lov_request *req, int rc)
1315 struct lov_obd *lov = &req->rq_rqset->set_exp->exp_obd->u.lov;
1316 struct lov_stripe_md *lsm = req->rq_rqset->set_oi->oi_md;
1319 lov_update_set(set, req, rc);
1321 /* grace error on inactive ost */
1322 if (rc && !lov->lov_tgts[req->rq_idx]->ltd_active)
1326 lov_stripe_lock(lsm);
1327 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLBLOCKS) {
1328 lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_blocks =
1329 req->rq_oi.oi_oa->o_blocks;
1332 /* Do we need to update lvb_size here? It needn't because
1333 * it have been done in ll_truncate(). -jay */
1334 lov_stripe_unlock(lsm);
1340 /* The callback for osc_punch that finilizes a request info when a response
1342 static int cb_update_punch(void *cookie, int rc)
1344 struct obd_info *oinfo = cookie;
1345 struct lov_request *lovreq;
1346 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1347 return lov_update_punch_set(lovreq->rq_rqset, lovreq, rc);
1350 int lov_prep_punch_set(struct obd_export *exp, struct obd_info *oinfo,
1351 struct obd_trans_info *oti,
1352 struct lov_request_set **reqset)
1354 struct lov_request_set *set;
1355 struct lov_obd *lov = &exp->exp_obd->u.lov;
1359 OBD_ALLOC(set, sizeof(*set));
1364 set->set_oi = oinfo;
1367 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
1368 struct lov_oinfo *loi = oinfo->oi_md->lsm_oinfo[i];
1369 struct lov_request *req;
1372 if (!lov_stripe_intersects(oinfo->oi_md, i,
1373 oinfo->oi_policy.l_extent.start,
1374 oinfo->oi_policy.l_extent.end,
1378 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1379 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1380 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1381 GOTO(out_set, rc = -EIO);
1384 OBD_ALLOC(req, sizeof(*req));
1386 GOTO(out_set, rc = -ENOMEM);
1388 req->rq_idx = loi->loi_ost_idx;
1390 OBDO_ALLOC(req->rq_oi.oi_oa);
1391 if (req->rq_oi.oi_oa == NULL) {
1392 OBD_FREE(req, sizeof(*req));
1393 GOTO(out_set, rc = -ENOMEM);
1395 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
1396 sizeof(*req->rq_oi.oi_oa));
1397 req->rq_oi.oi_oa->o_id = loi->loi_id;
1398 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
1399 req->rq_oi.oi_oa->o_valid |= OBD_MD_FLGROUP;
1401 req->rq_oi.oi_oa->o_stripe_idx = i;
1402 req->rq_oi.oi_cb_up = cb_update_punch;
1404 req->rq_oi.oi_policy.l_extent.start = rs;
1405 req->rq_oi.oi_policy.l_extent.end = re;
1406 req->rq_oi.oi_policy.l_extent.gid = -1;
1408 req->rq_oi.oi_capa = oinfo->oi_capa;
1410 lov_set_add_req(req, set);
1412 if (!set->set_count)
1413 GOTO(out_set, rc = -EIO);
1417 lov_fini_punch_set(set);
1421 int lov_fini_sync_set(struct lov_request_set *set)
1428 LASSERT(set->set_exp);
1429 if (cfs_atomic_read(&set->set_completes)) {
1430 if (!cfs_atomic_read(&set->set_success))
1432 /* FIXME update qos data here */
1435 lov_put_reqset(set);
1440 /* The callback for osc_sync that finilizes a request info when a
1441 * response is recieved. */
1442 static int cb_sync_update(void *cookie, int rc)
1444 struct obd_info *oinfo = cookie;
1445 struct lov_request *lovreq;
1447 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1448 return lov_update_common_set(lovreq->rq_rqset, lovreq, rc);
1451 int lov_prep_sync_set(struct obd_export *exp, struct obd_info *oinfo,
1452 obd_off start, obd_off end,
1453 struct lov_request_set **reqset)
1455 struct lov_request_set *set;
1456 struct lov_obd *lov = &exp->exp_obd->u.lov;
1466 set->set_oi = oinfo;
1468 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
1469 struct lov_oinfo *loi = oinfo->oi_md->lsm_oinfo[i];
1470 struct lov_request *req;
1473 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1474 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1475 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1479 if (!lov_stripe_intersects(oinfo->oi_md, i, start, end, &rs,
1485 GOTO(out_set, rc = -ENOMEM);
1487 req->rq_idx = loi->loi_ost_idx;
1489 OBDO_ALLOC(req->rq_oi.oi_oa);
1490 if (req->rq_oi.oi_oa == NULL) {
1491 OBD_FREE(req, sizeof(*req));
1492 GOTO(out_set, rc = -ENOMEM);
1494 *req->rq_oi.oi_oa = *oinfo->oi_oa;
1495 req->rq_oi.oi_oa->o_id = loi->loi_id;
1496 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
1497 req->rq_oi.oi_oa->o_stripe_idx = i;
1499 req->rq_oi.oi_policy.l_extent.start = rs;
1500 req->rq_oi.oi_policy.l_extent.end = re;
1501 req->rq_oi.oi_policy.l_extent.gid = -1;
1502 req->rq_oi.oi_cb_up = cb_sync_update;
1504 lov_set_add_req(req, set);
1506 if (!set->set_count)
1507 GOTO(out_set, rc = -EIO);
1511 lov_fini_sync_set(set);
1515 #define LOV_U64_MAX ((__u64)~0ULL)
1516 #define LOV_SUM_MAX(tot, add) \
1518 if ((tot) + (add) < (tot)) \
1519 (tot) = LOV_U64_MAX; \
1524 int lov_fini_statfs(struct obd_device *obd, struct obd_statfs *osfs,int success)
1529 __u32 expected_stripes = lov_get_stripecnt(&obd->u.lov,
1531 if (osfs->os_files != LOV_U64_MAX)
1532 lov_do_div64(osfs->os_files, expected_stripes);
1533 if (osfs->os_ffree != LOV_U64_MAX)
1534 lov_do_div64(osfs->os_ffree, expected_stripes);
1536 cfs_spin_lock(&obd->obd_osfs_lock);
1537 memcpy(&obd->obd_osfs, osfs, sizeof(*osfs));
1538 obd->obd_osfs_age = cfs_time_current_64();
1539 cfs_spin_unlock(&obd->obd_osfs_lock);
1546 int lov_fini_statfs_set(struct lov_request_set *set)
1554 if (cfs_atomic_read(&set->set_completes)) {
1555 rc = lov_fini_statfs(set->set_obd, set->set_oi->oi_osfs,
1556 cfs_atomic_read(&set->set_success));
1558 lov_put_reqset(set);
1562 void lov_update_statfs(struct obd_statfs *osfs, struct obd_statfs *lov_sfs,
1565 int shift = 0, quit = 0;
1569 memcpy(osfs, lov_sfs, sizeof(*lov_sfs));
1571 if (osfs->os_bsize != lov_sfs->os_bsize) {
1572 /* assume all block sizes are always powers of 2 */
1573 /* get the bits difference */
1574 tmp = osfs->os_bsize | lov_sfs->os_bsize;
1575 for (shift = 0; shift <= 64; ++shift) {
1587 if (osfs->os_bsize < lov_sfs->os_bsize) {
1588 osfs->os_bsize = lov_sfs->os_bsize;
1590 osfs->os_bfree >>= shift;
1591 osfs->os_bavail >>= shift;
1592 osfs->os_blocks >>= shift;
1593 } else if (shift != 0) {
1594 lov_sfs->os_bfree >>= shift;
1595 lov_sfs->os_bavail >>= shift;
1596 lov_sfs->os_blocks >>= shift;
1599 /* Sandia requested that df (and so, statfs) only
1600 returned minimal available space on
1601 a single OST, so people would be able to
1602 write this much data guaranteed. */
1603 if (osfs->os_bavail > lov_sfs->os_bavail) {
1604 /* Presumably if new bavail is smaller,
1605 new bfree is bigger as well */
1606 osfs->os_bfree = lov_sfs->os_bfree;
1607 osfs->os_bavail = lov_sfs->os_bavail;
1610 osfs->os_bfree += lov_sfs->os_bfree;
1611 osfs->os_bavail += lov_sfs->os_bavail;
1613 osfs->os_blocks += lov_sfs->os_blocks;
1614 /* XXX not sure about this one - depends on policy.
1615 * - could be minimum if we always stripe on all OBDs
1616 * (but that would be wrong for any other policy,
1617 * if one of the OBDs has no more objects left)
1618 * - could be sum if we stripe whole objects
1619 * - could be average, just to give a nice number
1621 * To give a "reasonable" (if not wholly accurate)
1622 * number, we divide the total number of free objects
1623 * by expected stripe count (watch out for overflow).
1625 LOV_SUM_MAX(osfs->os_files, lov_sfs->os_files);
1626 LOV_SUM_MAX(osfs->os_ffree, lov_sfs->os_ffree);
1630 /* The callback for osc_statfs_async that finilizes a request info when a
1631 * response is received. */
1632 static int cb_statfs_update(void *cookie, int rc)
1634 struct obd_info *oinfo = cookie;
1635 struct lov_request *lovreq;
1636 struct lov_request_set *set;
1637 struct obd_statfs *osfs, *lov_sfs;
1638 struct lov_obd *lov;
1639 struct lov_tgt_desc *tgt;
1640 struct obd_device *lovobd, *tgtobd;
1644 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1645 set = lovreq->rq_rqset;
1646 lovobd = set->set_obd;
1647 lov = &lovobd->u.lov;
1648 osfs = set->set_oi->oi_osfs;
1649 lov_sfs = oinfo->oi_osfs;
1650 success = cfs_atomic_read(&set->set_success);
1651 /* XXX: the same is done in lov_update_common_set, however
1652 lovset->set_exp is not initialized. */
1653 lov_update_set(set, lovreq, rc);
1658 tgt = lov->lov_tgts[lovreq->rq_idx];
1659 if (!tgt || !tgt->ltd_active)
1660 GOTO(out_update, rc);
1662 tgtobd = class_exp2obd(tgt->ltd_exp);
1663 cfs_spin_lock(&tgtobd->obd_osfs_lock);
1664 memcpy(&tgtobd->obd_osfs, lov_sfs, sizeof(*lov_sfs));
1665 if ((oinfo->oi_flags & OBD_STATFS_FROM_CACHE) == 0)
1666 tgtobd->obd_osfs_age = cfs_time_current_64();
1667 cfs_spin_unlock(&tgtobd->obd_osfs_lock);
1670 lov_update_statfs(osfs, lov_sfs, success);
1675 if (set->set_oi->oi_flags & OBD_STATFS_PTLRPCD &&
1676 lov_finished_set(set)) {
1677 lov_statfs_interpret(NULL, set, set->set_count !=
1678 cfs_atomic_read(&set->set_success));
1679 if (lov->lov_qos.lq_statfs_in_progress)
1680 qos_statfs_done(lov);
1686 int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
1687 struct lov_request_set **reqset)
1689 struct lov_request_set *set;
1690 struct lov_obd *lov = &obd->u.lov;
1694 OBD_ALLOC(set, sizeof(*set));
1700 set->set_oi = oinfo;
1702 /* We only get block data from the OBD */
1703 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1704 struct lov_request *req;
1706 if (!lov->lov_tgts[i] || (!lov->lov_tgts[i]->ltd_active
1707 && (oinfo->oi_flags & OBD_STATFS_NODELAY))) {
1708 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1712 /* skip targets that have been explicitely disabled by the
1714 if (!lov->lov_tgts[i]->ltd_exp) {
1715 CDEBUG(D_HA, "lov idx %d administratively disabled\n", i);
1719 OBD_ALLOC(req, sizeof(*req));
1721 GOTO(out_set, rc = -ENOMEM);
1723 OBD_ALLOC(req->rq_oi.oi_osfs, sizeof(*req->rq_oi.oi_osfs));
1724 if (req->rq_oi.oi_osfs == NULL) {
1725 OBD_FREE(req, sizeof(*req));
1726 GOTO(out_set, rc = -ENOMEM);
1730 req->rq_oi.oi_cb_up = cb_statfs_update;
1731 req->rq_oi.oi_flags = oinfo->oi_flags;
1733 lov_set_add_req(req, set);
1735 if (!set->set_count)
1736 GOTO(out_set, rc = -EIO);
1740 lov_fini_statfs_set(set);