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.
37 #define DEBUG_SUBSYSTEM S_LOV
40 #include <libcfs/libcfs.h>
42 #include <liblustre.h>
45 #include <obd_class.h>
47 #include <lustre/lustre_idl.h>
49 #include "lov_internal.h"
51 static void lov_init_set(struct lov_request_set *set)
54 cfs_atomic_set(&set->set_completes, 0);
55 cfs_atomic_set(&set->set_success, 0);
57 CFS_INIT_LIST_HEAD(&set->set_list);
58 cfs_atomic_set(&set->set_refcount, 1);
59 cfs_waitq_init(&set->set_waitq);
60 cfs_spin_lock_init(&set->set_lock);
63 void lov_finish_set(struct lov_request_set *set)
69 cfs_list_for_each_safe(pos, n, &set->set_list) {
70 struct lov_request *req = cfs_list_entry(pos,
73 cfs_list_del_init(&req->rq_link);
76 OBDO_FREE(req->rq_oi.oi_oa);
78 OBD_FREE_LARGE(req->rq_oi.oi_md, req->rq_buflen);
79 if (req->rq_oi.oi_osfs)
80 OBD_FREE(req->rq_oi.oi_osfs,
81 sizeof(*req->rq_oi.oi_osfs));
82 OBD_FREE(req, sizeof(*req));
86 int len = set->set_oabufs * sizeof(*set->set_pga);
87 OBD_FREE_LARGE(set->set_pga, len);
90 lov_llh_put(set->set_lockh);
92 OBD_FREE(set, sizeof(*set));
96 int lov_finished_set(struct lov_request_set *set)
98 int completes = cfs_atomic_read(&set->set_completes);
100 CDEBUG(D_INFO, "check set %d/%d\n", completes,
102 return completes == set->set_count;
105 void lov_update_set(struct lov_request_set *set,
106 struct lov_request *req, int rc)
108 req->rq_complete = 1;
111 cfs_atomic_inc(&set->set_completes);
113 cfs_atomic_inc(&set->set_success);
115 cfs_waitq_signal(&set->set_waitq);
118 int lov_update_common_set(struct lov_request_set *set,
119 struct lov_request *req, int rc)
121 struct lov_obd *lov = &set->set_exp->exp_obd->u.lov;
124 lov_update_set(set, req, rc);
126 /* grace error on inactive ost */
127 if (rc && !(lov->lov_tgts[req->rq_idx] &&
128 lov->lov_tgts[req->rq_idx]->ltd_active))
131 /* FIXME in raid1 regime, should return 0 */
135 void lov_set_add_req(struct lov_request *req, struct lov_request_set *set)
137 cfs_list_add_tail(&req->rq_link, &set->set_list);
142 extern void osc_update_enqueue(struct lustre_handle *lov_lockhp,
143 struct lov_oinfo *loi, int flags,
144 struct ost_lvb *lvb, __u32 mode, int rc);
146 static int lov_update_enqueue_lov(struct obd_export *exp,
147 struct lustre_handle *lov_lockhp,
148 struct lov_oinfo *loi, int flags, int idx,
151 struct lov_obd *lov = &exp->exp_obd->u.lov;
153 if (rc != ELDLM_OK &&
154 !(rc == ELDLM_LOCK_ABORTED && (flags & LDLM_FL_HAS_INTENT))) {
155 memset(lov_lockhp, 0, sizeof(*lov_lockhp));
156 if (lov->lov_tgts[idx] && lov->lov_tgts[idx]->ltd_active) {
157 /* -EUSERS used by OST to report file contention */
158 if (rc != -EINTR && rc != -EUSERS)
159 CERROR("enqueue objid "LPX64" subobj "
160 LPX64" on OST idx %d: rc %d\n",
161 oid, loi->loi_id, loi->loi_ost_idx, rc);
168 int lov_update_enqueue_set(struct lov_request *req, __u32 mode, int rc)
170 struct lov_request_set *set = req->rq_rqset;
171 struct lustre_handle *lov_lockhp;
172 struct obd_info *oi = set->set_oi;
173 struct lov_oinfo *loi;
178 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
179 loi = oi->oi_md->lsm_oinfo[req->rq_stripe];
181 /* XXX LOV STACKING: OSC gets a copy, created in lov_prep_enqueue_set
182 * and that copy can be arbitrarily out of date.
184 * The LOV API is due for a serious rewriting anyways, and this
185 * can be addressed then. */
187 lov_stripe_lock(oi->oi_md);
188 osc_update_enqueue(lov_lockhp, loi, oi->oi_flags,
189 &req->rq_oi.oi_md->lsm_oinfo[0]->loi_lvb, mode, rc);
190 if (rc == ELDLM_LOCK_ABORTED && (oi->oi_flags & LDLM_FL_HAS_INTENT))
191 memset(lov_lockhp, 0, sizeof *lov_lockhp);
192 rc = lov_update_enqueue_lov(set->set_exp, lov_lockhp, loi, oi->oi_flags,
193 req->rq_idx, oi->oi_md->lsm_object_id, rc);
194 lov_stripe_unlock(oi->oi_md);
195 lov_update_set(set, req, rc);
199 /* The callback for osc_enqueue that updates lov info for every OSC request. */
200 static int cb_update_enqueue(void *cookie, int rc)
202 struct obd_info *oinfo = cookie;
203 struct ldlm_enqueue_info *einfo;
204 struct lov_request *lovreq;
206 lovreq = container_of(oinfo, struct lov_request, rq_oi);
207 einfo = lovreq->rq_rqset->set_ei;
208 return lov_update_enqueue_set(lovreq, einfo->ei_mode, rc);
211 static int enqueue_done(struct lov_request_set *set, __u32 mode)
213 struct lov_request *req;
214 struct lov_obd *lov = &set->set_exp->exp_obd->u.lov;
215 int completes = cfs_atomic_read(&set->set_completes);
219 /* enqueue/match success, just return */
220 if (completes && completes == cfs_atomic_read(&set->set_success))
223 /* cancel enqueued/matched locks */
224 cfs_list_for_each_entry(req, &set->set_list, rq_link) {
225 struct lustre_handle *lov_lockhp;
227 if (!req->rq_complete || req->rq_rc)
230 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
232 if (!lustre_handle_is_used(lov_lockhp))
235 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
236 req->rq_oi.oi_md, mode, lov_lockhp);
237 if (rc && lov->lov_tgts[req->rq_idx] &&
238 lov->lov_tgts[req->rq_idx]->ltd_active)
239 CERROR("cancelling obdjid "LPX64" on OST "
240 "idx %d error: rc = %d\n",
241 req->rq_oi.oi_md->lsm_object_id,
245 lov_llh_put(set->set_lockh);
249 int lov_fini_enqueue_set(struct lov_request_set *set, __u32 mode, int rc,
250 struct ptlrpc_request_set *rqset)
257 LASSERT(set->set_exp);
258 /* Do enqueue_done only for sync requests and if any request
262 cfs_atomic_set(&set->set_completes, 0);
263 ret = enqueue_done(set, mode);
264 } else if (set->set_lockh)
265 lov_llh_put(set->set_lockh);
269 RETURN(rc ? rc : ret);
272 static void lov_llh_addref(void *llhp)
274 struct lov_lock_handles *llh = llhp;
276 cfs_atomic_inc(&llh->llh_refcount);
277 CDEBUG(D_INFO, "GETting llh %p : new refcount %d\n", llh,
278 cfs_atomic_read(&llh->llh_refcount));
281 static struct portals_handle_ops lov_handle_ops = {
282 .hop_addref = lov_llh_addref,
286 static struct lov_lock_handles *lov_llh_new(struct lov_stripe_md *lsm)
288 struct lov_lock_handles *llh;
290 OBD_ALLOC(llh, sizeof *llh +
291 sizeof(*llh->llh_handles) * lsm->lsm_stripe_count);
295 cfs_atomic_set(&llh->llh_refcount, 2);
296 llh->llh_stripe_count = lsm->lsm_stripe_count;
297 CFS_INIT_LIST_HEAD(&llh->llh_handle.h_link);
298 class_handle_hash(&llh->llh_handle, &lov_handle_ops);
303 int lov_prep_enqueue_set(struct obd_export *exp, struct obd_info *oinfo,
304 struct ldlm_enqueue_info *einfo,
305 struct lov_request_set **reqset)
307 struct lov_obd *lov = &exp->exp_obd->u.lov;
308 struct lov_request_set *set;
312 OBD_ALLOC(set, sizeof(*set));
320 set->set_lockh = lov_llh_new(oinfo->oi_md);
321 if (set->set_lockh == NULL)
322 GOTO(out_set, rc = -ENOMEM);
323 oinfo->oi_lockh->cookie = set->set_lockh->llh_handle.h_cookie;
325 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
326 struct lov_oinfo *loi;
327 struct lov_request *req;
330 loi = oinfo->oi_md->lsm_oinfo[i];
331 if (!lov_stripe_intersects(oinfo->oi_md, i,
332 oinfo->oi_policy.l_extent.start,
333 oinfo->oi_policy.l_extent.end,
337 if (!lov->lov_tgts[loi->loi_ost_idx] ||
338 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
339 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
343 OBD_ALLOC(req, sizeof(*req));
345 GOTO(out_set, rc = -ENOMEM);
347 req->rq_buflen = sizeof(*req->rq_oi.oi_md) +
348 sizeof(struct lov_oinfo *) +
349 sizeof(struct lov_oinfo);
350 OBD_ALLOC_LARGE(req->rq_oi.oi_md, req->rq_buflen);
351 if (req->rq_oi.oi_md == NULL) {
352 OBD_FREE(req, sizeof(*req));
353 GOTO(out_set, rc = -ENOMEM);
355 req->rq_oi.oi_md->lsm_oinfo[0] =
356 ((void *)req->rq_oi.oi_md) + sizeof(*req->rq_oi.oi_md) +
357 sizeof(struct lov_oinfo *);
359 /* Set lov request specific parameters. */
360 req->rq_oi.oi_lockh = set->set_lockh->llh_handles + i;
361 req->rq_oi.oi_cb_up = cb_update_enqueue;
362 req->rq_oi.oi_flags = oinfo->oi_flags;
364 LASSERT(req->rq_oi.oi_lockh);
366 req->rq_oi.oi_policy.l_extent.gid =
367 oinfo->oi_policy.l_extent.gid;
368 req->rq_oi.oi_policy.l_extent.start = start;
369 req->rq_oi.oi_policy.l_extent.end = end;
371 req->rq_idx = loi->loi_ost_idx;
374 /* XXX LOV STACKING: submd should be from the subobj */
375 req->rq_oi.oi_md->lsm_object_id = loi->loi_id;
376 req->rq_oi.oi_md->lsm_object_seq = loi->loi_seq;
377 req->rq_oi.oi_md->lsm_stripe_count = 0;
378 req->rq_oi.oi_md->lsm_oinfo[0]->loi_kms_valid =
380 req->rq_oi.oi_md->lsm_oinfo[0]->loi_kms = loi->loi_kms;
381 req->rq_oi.oi_md->lsm_oinfo[0]->loi_lvb = loi->loi_lvb;
383 lov_set_add_req(req, set);
386 GOTO(out_set, rc = -EIO);
390 lov_fini_enqueue_set(set, einfo->ei_mode, rc, NULL);
394 int lov_fini_match_set(struct lov_request_set *set, __u32 mode, int flags)
401 LASSERT(set->set_exp);
402 rc = enqueue_done(set, mode);
403 if ((set->set_count == cfs_atomic_read(&set->set_success)) &&
404 (flags & LDLM_FL_TEST_LOCK))
405 lov_llh_put(set->set_lockh);
412 int lov_prep_match_set(struct obd_export *exp, struct obd_info *oinfo,
413 struct lov_stripe_md *lsm, ldlm_policy_data_t *policy,
414 __u32 mode, struct lustre_handle *lockh,
415 struct lov_request_set **reqset)
417 struct lov_obd *lov = &exp->exp_obd->u.lov;
418 struct lov_request_set *set;
422 OBD_ALLOC(set, sizeof(*set));
429 set->set_oi->oi_md = lsm;
430 set->set_lockh = lov_llh_new(lsm);
431 if (set->set_lockh == NULL)
432 GOTO(out_set, rc = -ENOMEM);
433 lockh->cookie = set->set_lockh->llh_handle.h_cookie;
435 for (i = 0; i < lsm->lsm_stripe_count; i++){
436 struct lov_oinfo *loi;
437 struct lov_request *req;
440 loi = lsm->lsm_oinfo[i];
441 if (!lov_stripe_intersects(lsm, i, policy->l_extent.start,
442 policy->l_extent.end, &start, &end))
445 /* FIXME raid1 should grace this error */
446 if (!lov->lov_tgts[loi->loi_ost_idx] ||
447 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
448 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
449 GOTO(out_set, rc = -EIO);
452 OBD_ALLOC(req, sizeof(*req));
454 GOTO(out_set, rc = -ENOMEM);
456 req->rq_buflen = sizeof(*req->rq_oi.oi_md);
457 OBD_ALLOC_LARGE(req->rq_oi.oi_md, req->rq_buflen);
458 if (req->rq_oi.oi_md == NULL) {
459 OBD_FREE(req, sizeof(*req));
460 GOTO(out_set, rc = -ENOMEM);
463 req->rq_oi.oi_policy.l_extent.start = start;
464 req->rq_oi.oi_policy.l_extent.end = end;
465 req->rq_oi.oi_policy.l_extent.gid = policy->l_extent.gid;
467 req->rq_idx = loi->loi_ost_idx;
470 /* XXX LOV STACKING: submd should be from the subobj */
471 req->rq_oi.oi_md->lsm_object_id = loi->loi_id;
472 req->rq_oi.oi_md->lsm_object_seq = loi->loi_seq;
473 req->rq_oi.oi_md->lsm_stripe_count = 0;
475 lov_set_add_req(req, set);
478 GOTO(out_set, rc = -EIO);
482 lov_fini_match_set(set, mode, 0);
486 int lov_fini_cancel_set(struct lov_request_set *set)
494 LASSERT(set->set_exp);
496 lov_llh_put(set->set_lockh);
503 int lov_prep_cancel_set(struct obd_export *exp, struct obd_info *oinfo,
504 struct lov_stripe_md *lsm, __u32 mode,
505 struct lustre_handle *lockh,
506 struct lov_request_set **reqset)
508 struct lov_request_set *set;
512 OBD_ALLOC(set, sizeof(*set));
519 set->set_oi->oi_md = lsm;
520 set->set_lockh = lov_handle2llh(lockh);
521 if (set->set_lockh == NULL) {
522 CERROR("LOV: invalid lov lock handle %p\n", lockh);
523 GOTO(out_set, rc = -EINVAL);
525 lockh->cookie = set->set_lockh->llh_handle.h_cookie;
527 for (i = 0; i < lsm->lsm_stripe_count; i++){
528 struct lov_request *req;
529 struct lustre_handle *lov_lockhp;
530 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
532 lov_lockhp = set->set_lockh->llh_handles + i;
533 if (!lustre_handle_is_used(lov_lockhp)) {
534 CDEBUG(D_INFO, "lov idx %d subobj "LPX64" no lock\n",
535 loi->loi_ost_idx, loi->loi_id);
539 OBD_ALLOC(req, sizeof(*req));
541 GOTO(out_set, rc = -ENOMEM);
543 req->rq_buflen = sizeof(*req->rq_oi.oi_md);
544 OBD_ALLOC_LARGE(req->rq_oi.oi_md, req->rq_buflen);
545 if (req->rq_oi.oi_md == NULL) {
546 OBD_FREE(req, sizeof(*req));
547 GOTO(out_set, rc = -ENOMEM);
550 req->rq_idx = loi->loi_ost_idx;
553 /* XXX LOV STACKING: submd should be from the subobj */
554 req->rq_oi.oi_md->lsm_object_id = loi->loi_id;
555 req->rq_oi.oi_md->lsm_object_seq = loi->loi_seq;
556 req->rq_oi.oi_md->lsm_stripe_count = 0;
558 lov_set_add_req(req, set);
561 GOTO(out_set, rc = -EIO);
565 lov_fini_cancel_set(set);
569 static int lov_update_create_set(struct lov_request_set *set,
570 struct lov_request *req, int rc)
572 struct obd_trans_info *oti = set->set_oti;
573 struct lov_stripe_md *lsm = set->set_oi->oi_md;
574 struct lov_oinfo *loi;
575 struct lov_obd *lov = &set->set_exp->exp_obd->u.lov;
578 if (rc && lov->lov_tgts[req->rq_idx] &&
579 lov->lov_tgts[req->rq_idx]->ltd_active) {
580 /* Pre-creating objects may timeout via -ETIMEDOUT or
581 * -ENOTCONN both are always non-critical events. */
582 CDEBUG(rc == -ETIMEDOUT || rc == -ENOTCONN ? D_HA : D_ERROR,
583 "error creating fid "LPX64" sub-object "
584 "on OST idx %d/%d: rc = %d\n",
585 set->set_oi->oi_oa->o_id, req->rq_idx,
586 lsm->lsm_stripe_count, rc);
588 CERROR("obd_create returned invalid err %d\n", rc);
593 cfs_spin_lock(&set->set_lock);
594 req->rq_stripe = cfs_atomic_read(&set->set_success);
595 loi = lsm->lsm_oinfo[req->rq_stripe];
599 lov_update_set(set, req, rc);
600 cfs_spin_unlock(&set->set_lock);
604 loi->loi_id = req->rq_oi.oi_oa->o_id;
605 loi->loi_seq = req->rq_oi.oi_oa->o_seq;
606 loi->loi_ost_idx = req->rq_idx;
609 if (oti && set->set_cookies)
610 ++oti->oti_logcookies;
611 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLCOOKIE)
612 set->set_cookie_sent++;
614 lov_update_set(set, req, rc);
615 cfs_spin_unlock(&set->set_lock);
617 CDEBUG(D_INODE, "objid "LPX64" has subobj "LPX64"/"LPU64" at idx %d\n",
618 lsm->lsm_object_id, loi->loi_id, loi->loi_id, req->rq_idx);
622 static int create_done(struct obd_export *exp, struct lov_request_set *set,
623 struct lov_stripe_md **lsmp)
625 struct lov_obd *lov = &exp->exp_obd->u.lov;
626 struct obd_trans_info *oti = set->set_oti;
627 struct obdo *src_oa = set->set_oi->oi_oa;
628 struct lov_request *req;
629 struct obdo *ret_oa = NULL;
630 int success, attrset = 0, rc = 0;
633 LASSERT(cfs_atomic_read(&set->set_completes));
635 /* try alloc objects on other osts if osc_create fails for
636 * exceptions: RPC failure, ENOSPC, etc */
637 if (set->set_count != cfs_atomic_read(&set->set_success)) {
638 cfs_list_for_each_entry (req, &set->set_list, rq_link) {
642 cfs_atomic_dec(&set->set_completes);
643 req->rq_complete = 0;
645 rc = qos_remedy_create(set, req);
646 lov_update_create_set(set, req, rc);
650 success = cfs_atomic_read(&set->set_success);
651 /* no successful creates */
655 if (set->set_count != success) {
656 set->set_count = success;
662 GOTO(cleanup, rc = -ENOMEM);
664 cfs_list_for_each_entry(req, &set->set_list, rq_link) {
665 if (!req->rq_complete || req->rq_rc)
667 lov_merge_attrs(ret_oa, req->rq_oi.oi_oa,
668 req->rq_oi.oi_oa->o_valid, set->set_oi->oi_md,
669 req->rq_stripe, &attrset);
671 if (src_oa->o_valid & OBD_MD_FLSIZE &&
672 ret_oa->o_size != src_oa->o_size) {
673 CERROR("original size "LPU64" isn't new object size "LPU64"\n",
674 src_oa->o_size, ret_oa->o_size);
677 ret_oa->o_id = src_oa->o_id;
678 ret_oa->o_seq = src_oa->o_seq;
679 ret_oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP;
680 memcpy(src_oa, ret_oa, sizeof(*src_oa));
683 *lsmp = set->set_oi->oi_md;
687 cfs_list_for_each_entry(req, &set->set_list, rq_link) {
688 struct obd_export *sub_exp;
691 if (!req->rq_complete || req->rq_rc)
694 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
695 err = obd_destroy(NULL, sub_exp, req->rq_oi.oi_oa, NULL, oti,
698 CERROR("Failed to uncreate objid "LPX64" subobj "
699 LPX64" on OST idx %d: rc = %d\n",
700 src_oa->o_id, req->rq_oi.oi_oa->o_id,
704 obd_free_memmd(exp, &set->set_oi->oi_md);
706 if (oti && set->set_cookies) {
707 oti->oti_logcookies = set->set_cookies;
708 if (!set->set_cookie_sent) {
709 oti_free_cookies(oti);
710 src_oa->o_valid &= ~OBD_MD_FLCOOKIE;
712 src_oa->o_valid |= OBD_MD_FLCOOKIE;
718 int lov_fini_create_set(struct lov_request_set *set,struct lov_stripe_md **lsmp)
725 LASSERT(set->set_exp);
726 if (cfs_atomic_read(&set->set_completes))
727 rc = create_done(set->set_exp, set, lsmp);
733 int cb_create_update(void *cookie, int rc)
735 struct obd_info *oinfo = cookie;
736 struct lov_request *lovreq;
738 lovreq = container_of(oinfo, struct lov_request, rq_oi);
740 if (CFS_FAIL_CHECK(OBD_FAIL_MDS_OSC_CREATE_FAIL))
741 if (lovreq->rq_idx == cfs_fail_val)
744 rc= lov_update_create_set(lovreq->rq_rqset, lovreq, rc);
745 if (lov_finished_set(lovreq->rq_rqset))
746 lov_put_reqset(lovreq->rq_rqset);
750 int lov_prep_create_set(struct obd_export *exp, struct obd_info *oinfo,
751 struct lov_stripe_md **lsmp, struct obdo *src_oa,
752 struct obd_trans_info *oti,
753 struct lov_request_set **reqset)
755 struct lov_request_set *set;
759 OBD_ALLOC(set, sizeof(*set));
766 set->set_oi->oi_md = *lsmp;
767 set->set_oi->oi_oa = src_oa;
771 rc = qos_prep_create(exp, set);
772 /* qos_shrink_lsm() may have allocated a new lsm */
773 *lsmp = oinfo->oi_md;
775 lov_fini_create_set(set, lsmp);
783 static int common_attr_done(struct lov_request_set *set)
786 struct lov_request *req;
788 int rc = 0, attrset = 0;
791 LASSERT(set->set_oi != NULL);
793 if (set->set_oi->oi_oa == NULL)
796 if (!cfs_atomic_read(&set->set_success))
801 GOTO(out, rc = -ENOMEM);
803 cfs_list_for_each (pos, &set->set_list) {
804 req = cfs_list_entry(pos, struct lov_request, rq_link);
806 if (!req->rq_complete || req->rq_rc)
808 if (req->rq_oi.oi_oa->o_valid == 0) /* inactive stripe */
810 lov_merge_attrs(tmp_oa, req->rq_oi.oi_oa,
811 req->rq_oi.oi_oa->o_valid,
812 set->set_oi->oi_md, req->rq_stripe, &attrset);
815 CERROR("No stripes had valid attrs\n");
818 if ((set->set_oi->oi_oa->o_valid & OBD_MD_FLEPOCH) &&
819 (set->set_oi->oi_md->lsm_stripe_count != attrset)) {
820 /* When we take attributes of some epoch, we require all the
821 * ost to be active. */
822 CERROR("Not all the stripes had valid attrs\n");
823 GOTO(out, rc = -EIO);
826 tmp_oa->o_id = set->set_oi->oi_oa->o_id;
827 memcpy(set->set_oi->oi_oa, tmp_oa, sizeof(*set->set_oi->oi_oa));
835 static int brw_done(struct lov_request_set *set)
837 struct lov_stripe_md *lsm = set->set_oi->oi_md;
838 struct lov_oinfo *loi = NULL;
840 struct lov_request *req;
843 cfs_list_for_each (pos, &set->set_list) {
844 req = cfs_list_entry(pos, struct lov_request, rq_link);
846 if (!req->rq_complete || req->rq_rc)
849 loi = lsm->lsm_oinfo[req->rq_stripe];
851 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLBLOCKS)
852 loi->loi_lvb.lvb_blocks = req->rq_oi.oi_oa->o_blocks;
858 int lov_fini_brw_set(struct lov_request_set *set)
865 LASSERT(set->set_exp);
866 if (cfs_atomic_read(&set->set_completes)) {
868 /* FIXME update qos data here */
875 int lov_prep_brw_set(struct obd_export *exp, struct obd_info *oinfo,
876 obd_count oa_bufs, struct brw_page *pga,
877 struct obd_trans_info *oti,
878 struct lov_request_set **reqset)
885 struct lov_request_set *set;
886 struct lov_obd *lov = &exp->exp_obd->u.lov;
887 int rc = 0, i, shift;
890 OBD_ALLOC(set, sizeof(*set));
898 set->set_oabufs = oa_bufs;
899 OBD_ALLOC_LARGE(set->set_pga, oa_bufs * sizeof(*set->set_pga));
901 GOTO(out, rc = -ENOMEM);
903 OBD_ALLOC_LARGE(info, sizeof(*info) * oinfo->oi_md->lsm_stripe_count);
905 GOTO(out, rc = -ENOMEM);
907 /* calculate the page count for each stripe */
908 for (i = 0; i < oa_bufs; i++) {
909 int stripe = lov_stripe_number(oinfo->oi_md, pga[i].off);
910 info[stripe].count++;
913 /* alloc and initialize lov request */
915 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++){
916 struct lov_oinfo *loi = NULL;
917 struct lov_request *req;
919 if (info[i].count == 0)
922 loi = oinfo->oi_md->lsm_oinfo[i];
923 if (!lov->lov_tgts[loi->loi_ost_idx] ||
924 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
925 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
926 GOTO(out, rc = -EIO);
929 OBD_ALLOC(req, sizeof(*req));
931 GOTO(out, rc = -ENOMEM);
933 OBDO_ALLOC(req->rq_oi.oi_oa);
934 if (req->rq_oi.oi_oa == NULL) {
935 OBD_FREE(req, sizeof(*req));
936 GOTO(out, rc = -ENOMEM);
940 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
941 sizeof(*req->rq_oi.oi_oa));
943 req->rq_oi.oi_oa->o_id = loi->loi_id;
944 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
945 req->rq_oi.oi_oa->o_stripe_idx = i;
947 req->rq_buflen = sizeof(*req->rq_oi.oi_md);
948 OBD_ALLOC_LARGE(req->rq_oi.oi_md, req->rq_buflen);
949 if (req->rq_oi.oi_md == NULL) {
950 OBDO_FREE(req->rq_oi.oi_oa);
951 OBD_FREE(req, sizeof(*req));
952 GOTO(out, rc = -ENOMEM);
955 req->rq_idx = loi->loi_ost_idx;
958 /* XXX LOV STACKING */
959 req->rq_oi.oi_md->lsm_object_id = loi->loi_id;
960 req->rq_oi.oi_md->lsm_object_seq = loi->loi_seq;
961 req->rq_oabufs = info[i].count;
962 req->rq_pgaidx = shift;
963 shift += req->rq_oabufs;
965 /* remember the index for sort brw_page array */
966 info[i].index = req->rq_pgaidx;
968 req->rq_oi.oi_capa = oinfo->oi_capa;
970 lov_set_add_req(req, set);
973 GOTO(out, rc = -EIO);
975 /* rotate & sort the brw_page array */
976 for (i = 0; i < oa_bufs; i++) {
977 int stripe = lov_stripe_number(oinfo->oi_md, pga[i].off);
979 shift = info[stripe].index + info[stripe].off;
980 LASSERT(shift < oa_bufs);
981 set->set_pga[shift] = pga[i];
982 lov_stripe_offset(oinfo->oi_md, pga[i].off, stripe,
983 &set->set_pga[shift].off);
989 sizeof(*info) * oinfo->oi_md->lsm_stripe_count);
994 lov_fini_brw_set(set);
999 int lov_fini_getattr_set(struct lov_request_set *set)
1006 LASSERT(set->set_exp);
1007 if (cfs_atomic_read(&set->set_completes))
1008 rc = common_attr_done(set);
1010 lov_put_reqset(set);
1015 /* The callback for osc_getattr_async that finilizes a request info when a
1016 * response is received. */
1017 static int cb_getattr_update(void *cookie, int rc)
1019 struct obd_info *oinfo = cookie;
1020 struct lov_request *lovreq;
1021 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1022 return lov_update_common_set(lovreq->rq_rqset, lovreq, rc);
1025 int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo,
1026 struct lov_request_set **reqset)
1028 struct lov_request_set *set;
1029 struct lov_obd *lov = &exp->exp_obd->u.lov;
1033 OBD_ALLOC(set, sizeof(*set));
1039 set->set_oi = oinfo;
1041 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
1042 struct lov_oinfo *loi;
1043 struct lov_request *req;
1045 loi = oinfo->oi_md->lsm_oinfo[i];
1046 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1047 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1048 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1049 if (oinfo->oi_oa->o_valid & OBD_MD_FLEPOCH)
1050 /* SOM requires all the OSTs to be active. */
1051 GOTO(out_set, rc = -EIO);
1055 OBD_ALLOC(req, sizeof(*req));
1057 GOTO(out_set, rc = -ENOMEM);
1060 req->rq_idx = loi->loi_ost_idx;
1062 OBDO_ALLOC(req->rq_oi.oi_oa);
1063 if (req->rq_oi.oi_oa == NULL) {
1064 OBD_FREE(req, sizeof(*req));
1065 GOTO(out_set, rc = -ENOMEM);
1067 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
1068 sizeof(*req->rq_oi.oi_oa));
1069 req->rq_oi.oi_oa->o_id = loi->loi_id;
1070 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
1071 req->rq_oi.oi_cb_up = cb_getattr_update;
1072 req->rq_oi.oi_capa = oinfo->oi_capa;
1074 lov_set_add_req(req, set);
1076 if (!set->set_count)
1077 GOTO(out_set, rc = -EIO);
1081 lov_fini_getattr_set(set);
1085 int lov_fini_destroy_set(struct lov_request_set *set)
1091 LASSERT(set->set_exp);
1092 if (cfs_atomic_read(&set->set_completes)) {
1093 /* FIXME update qos data here */
1096 lov_put_reqset(set);
1101 int lov_prep_destroy_set(struct obd_export *exp, struct obd_info *oinfo,
1102 struct obdo *src_oa, struct lov_stripe_md *lsm,
1103 struct obd_trans_info *oti,
1104 struct lov_request_set **reqset)
1106 struct lov_request_set *set;
1107 struct lov_obd *lov = &exp->exp_obd->u.lov;
1111 OBD_ALLOC(set, sizeof(*set));
1117 set->set_oi = oinfo;
1118 set->set_oi->oi_md = lsm;
1119 set->set_oi->oi_oa = src_oa;
1121 if (oti != NULL && src_oa->o_valid & OBD_MD_FLCOOKIE)
1122 set->set_cookies = oti->oti_logcookies;
1124 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1125 struct lov_oinfo *loi;
1126 struct lov_request *req;
1128 loi = lsm->lsm_oinfo[i];
1129 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1130 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1131 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1135 OBD_ALLOC(req, sizeof(*req));
1137 GOTO(out_set, rc = -ENOMEM);
1140 req->rq_idx = loi->loi_ost_idx;
1142 OBDO_ALLOC(req->rq_oi.oi_oa);
1143 if (req->rq_oi.oi_oa == NULL) {
1144 OBD_FREE(req, sizeof(*req));
1145 GOTO(out_set, rc = -ENOMEM);
1147 memcpy(req->rq_oi.oi_oa, src_oa, sizeof(*req->rq_oi.oi_oa));
1148 req->rq_oi.oi_oa->o_id = loi->loi_id;
1149 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
1150 lov_set_add_req(req, set);
1152 if (!set->set_count)
1153 GOTO(out_set, rc = -EIO);
1157 lov_fini_destroy_set(set);
1161 int lov_fini_setattr_set(struct lov_request_set *set)
1168 LASSERT(set->set_exp);
1169 if (cfs_atomic_read(&set->set_completes)) {
1170 rc = common_attr_done(set);
1171 /* FIXME update qos data here */
1174 lov_put_reqset(set);
1178 int lov_update_setattr_set(struct lov_request_set *set,
1179 struct lov_request *req, int rc)
1181 struct lov_obd *lov = &req->rq_rqset->set_exp->exp_obd->u.lov;
1182 struct lov_stripe_md *lsm = req->rq_rqset->set_oi->oi_md;
1185 lov_update_set(set, req, rc);
1187 /* grace error on inactive ost */
1188 if (rc && !(lov->lov_tgts[req->rq_idx] &&
1189 lov->lov_tgts[req->rq_idx]->ltd_active))
1193 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLCTIME)
1194 lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_ctime =
1195 req->rq_oi.oi_oa->o_ctime;
1196 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLMTIME)
1197 lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_mtime =
1198 req->rq_oi.oi_oa->o_mtime;
1199 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLATIME)
1200 lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_atime =
1201 req->rq_oi.oi_oa->o_atime;
1207 /* The callback for osc_setattr_async that finilizes a request info when a
1208 * response is received. */
1209 static int cb_setattr_update(void *cookie, int rc)
1211 struct obd_info *oinfo = cookie;
1212 struct lov_request *lovreq;
1213 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1214 return lov_update_setattr_set(lovreq->rq_rqset, lovreq, rc);
1217 int lov_prep_setattr_set(struct obd_export *exp, struct obd_info *oinfo,
1218 struct obd_trans_info *oti,
1219 struct lov_request_set **reqset)
1221 struct lov_request_set *set;
1222 struct lov_obd *lov = &exp->exp_obd->u.lov;
1226 OBD_ALLOC(set, sizeof(*set));
1233 set->set_oi = oinfo;
1234 if (oti != NULL && oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1235 set->set_cookies = oti->oti_logcookies;
1237 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
1238 struct lov_oinfo *loi = oinfo->oi_md->lsm_oinfo[i];
1239 struct lov_request *req;
1241 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1242 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1243 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1247 OBD_ALLOC(req, sizeof(*req));
1249 GOTO(out_set, rc = -ENOMEM);
1251 req->rq_idx = loi->loi_ost_idx;
1253 OBDO_ALLOC(req->rq_oi.oi_oa);
1254 if (req->rq_oi.oi_oa == NULL) {
1255 OBD_FREE(req, sizeof(*req));
1256 GOTO(out_set, rc = -ENOMEM);
1258 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
1259 sizeof(*req->rq_oi.oi_oa));
1260 req->rq_oi.oi_oa->o_id = loi->loi_id;
1261 req->rq_oi.oi_oa->o_seq= loi->loi_seq;
1262 req->rq_oi.oi_oa->o_stripe_idx = i;
1263 req->rq_oi.oi_cb_up = cb_setattr_update;
1264 req->rq_oi.oi_capa = oinfo->oi_capa;
1266 if (oinfo->oi_oa->o_valid & OBD_MD_FLSIZE) {
1267 int off = lov_stripe_offset(oinfo->oi_md,
1268 oinfo->oi_oa->o_size, i,
1269 &req->rq_oi.oi_oa->o_size);
1271 if (off < 0 && req->rq_oi.oi_oa->o_size)
1272 req->rq_oi.oi_oa->o_size--;
1274 CDEBUG(D_INODE, "stripe %d has size "LPU64"/"LPU64"\n",
1275 i, req->rq_oi.oi_oa->o_size,
1276 oinfo->oi_oa->o_size);
1278 lov_set_add_req(req, set);
1280 if (!set->set_count)
1281 GOTO(out_set, rc = -EIO);
1285 lov_fini_setattr_set(set);
1289 int lov_fini_punch_set(struct lov_request_set *set)
1296 LASSERT(set->set_exp);
1297 if (cfs_atomic_read(&set->set_completes)) {
1299 /* FIXME update qos data here */
1300 if (cfs_atomic_read(&set->set_success))
1301 rc = common_attr_done(set);
1304 lov_put_reqset(set);
1309 int lov_update_punch_set(struct lov_request_set *set,
1310 struct lov_request *req, int rc)
1312 struct lov_obd *lov = &req->rq_rqset->set_exp->exp_obd->u.lov;
1313 struct lov_stripe_md *lsm = req->rq_rqset->set_oi->oi_md;
1316 lov_update_set(set, req, rc);
1318 /* grace error on inactive ost */
1319 if (rc && !lov->lov_tgts[req->rq_idx]->ltd_active)
1323 lov_stripe_lock(lsm);
1324 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLBLOCKS) {
1325 lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_blocks =
1326 req->rq_oi.oi_oa->o_blocks;
1329 /* Do we need to update lvb_size here? It needn't because
1330 * it have been done in ll_truncate(). -jay */
1331 lov_stripe_unlock(lsm);
1337 /* The callback for osc_punch that finilizes a request info when a response
1339 static int cb_update_punch(void *cookie, int rc)
1341 struct obd_info *oinfo = cookie;
1342 struct lov_request *lovreq;
1343 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1344 return lov_update_punch_set(lovreq->rq_rqset, lovreq, rc);
1347 int lov_prep_punch_set(struct obd_export *exp, struct obd_info *oinfo,
1348 struct obd_trans_info *oti,
1349 struct lov_request_set **reqset)
1351 struct lov_request_set *set;
1352 struct lov_obd *lov = &exp->exp_obd->u.lov;
1356 OBD_ALLOC(set, sizeof(*set));
1361 set->set_oi = oinfo;
1364 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
1365 struct lov_oinfo *loi = oinfo->oi_md->lsm_oinfo[i];
1366 struct lov_request *req;
1369 if (!lov_stripe_intersects(oinfo->oi_md, i,
1370 oinfo->oi_policy.l_extent.start,
1371 oinfo->oi_policy.l_extent.end,
1375 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1376 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1377 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1378 GOTO(out_set, rc = -EIO);
1381 OBD_ALLOC(req, sizeof(*req));
1383 GOTO(out_set, rc = -ENOMEM);
1385 req->rq_idx = loi->loi_ost_idx;
1387 OBDO_ALLOC(req->rq_oi.oi_oa);
1388 if (req->rq_oi.oi_oa == NULL) {
1389 OBD_FREE(req, sizeof(*req));
1390 GOTO(out_set, rc = -ENOMEM);
1392 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
1393 sizeof(*req->rq_oi.oi_oa));
1394 req->rq_oi.oi_oa->o_id = loi->loi_id;
1395 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
1396 req->rq_oi.oi_oa->o_valid |= OBD_MD_FLGROUP;
1398 req->rq_oi.oi_oa->o_stripe_idx = i;
1399 req->rq_oi.oi_cb_up = cb_update_punch;
1401 req->rq_oi.oi_policy.l_extent.start = rs;
1402 req->rq_oi.oi_policy.l_extent.end = re;
1403 req->rq_oi.oi_policy.l_extent.gid = -1;
1405 req->rq_oi.oi_capa = oinfo->oi_capa;
1407 lov_set_add_req(req, set);
1409 if (!set->set_count)
1410 GOTO(out_set, rc = -EIO);
1414 lov_fini_punch_set(set);
1418 int lov_fini_sync_set(struct lov_request_set *set)
1425 LASSERT(set->set_exp);
1426 if (cfs_atomic_read(&set->set_completes)) {
1427 if (!cfs_atomic_read(&set->set_success))
1429 /* FIXME update qos data here */
1432 lov_put_reqset(set);
1437 /* The callback for osc_sync that finilizes a request info when a
1438 * response is recieved. */
1439 static int cb_sync_update(void *cookie, int rc)
1441 struct obd_info *oinfo = cookie;
1442 struct lov_request *lovreq;
1444 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1445 return lov_update_common_set(lovreq->rq_rqset, lovreq, rc);
1448 int lov_prep_sync_set(struct obd_export *exp, struct obd_info *oinfo,
1449 obd_off start, obd_off end,
1450 struct lov_request_set **reqset)
1452 struct lov_request_set *set;
1453 struct lov_obd *lov = &exp->exp_obd->u.lov;
1463 set->set_oi = oinfo;
1465 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
1466 struct lov_oinfo *loi = oinfo->oi_md->lsm_oinfo[i];
1467 struct lov_request *req;
1470 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1471 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1472 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1476 if (!lov_stripe_intersects(oinfo->oi_md, i, start, end, &rs,
1482 GOTO(out_set, rc = -ENOMEM);
1484 req->rq_idx = loi->loi_ost_idx;
1486 OBDO_ALLOC(req->rq_oi.oi_oa);
1487 if (req->rq_oi.oi_oa == NULL) {
1488 OBD_FREE(req, sizeof(*req));
1489 GOTO(out_set, rc = -ENOMEM);
1491 *req->rq_oi.oi_oa = *oinfo->oi_oa;
1492 req->rq_oi.oi_oa->o_id = loi->loi_id;
1493 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
1494 req->rq_oi.oi_oa->o_stripe_idx = i;
1496 req->rq_oi.oi_policy.l_extent.start = rs;
1497 req->rq_oi.oi_policy.l_extent.end = re;
1498 req->rq_oi.oi_policy.l_extent.gid = -1;
1499 req->rq_oi.oi_cb_up = cb_sync_update;
1501 lov_set_add_req(req, set);
1503 if (!set->set_count)
1504 GOTO(out_set, rc = -EIO);
1508 lov_fini_sync_set(set);
1512 #define LOV_U64_MAX ((__u64)~0ULL)
1513 #define LOV_SUM_MAX(tot, add) \
1515 if ((tot) + (add) < (tot)) \
1516 (tot) = LOV_U64_MAX; \
1521 int lov_fini_statfs(struct obd_device *obd, struct obd_statfs *osfs,int success)
1526 __u32 expected_stripes = lov_get_stripecnt(&obd->u.lov,
1528 if (osfs->os_files != LOV_U64_MAX)
1529 lov_do_div64(osfs->os_files, expected_stripes);
1530 if (osfs->os_ffree != LOV_U64_MAX)
1531 lov_do_div64(osfs->os_ffree, expected_stripes);
1533 cfs_spin_lock(&obd->obd_osfs_lock);
1534 memcpy(&obd->obd_osfs, osfs, sizeof(*osfs));
1535 obd->obd_osfs_age = cfs_time_current_64();
1536 cfs_spin_unlock(&obd->obd_osfs_lock);
1543 int lov_fini_statfs_set(struct lov_request_set *set)
1551 if (cfs_atomic_read(&set->set_completes)) {
1552 rc = lov_fini_statfs(set->set_obd, set->set_oi->oi_osfs,
1553 cfs_atomic_read(&set->set_success));
1555 lov_put_reqset(set);
1559 void lov_update_statfs(struct obd_statfs *osfs, struct obd_statfs *lov_sfs,
1562 int shift = 0, quit = 0;
1566 memcpy(osfs, lov_sfs, sizeof(*lov_sfs));
1568 if (osfs->os_bsize != lov_sfs->os_bsize) {
1569 /* assume all block sizes are always powers of 2 */
1570 /* get the bits difference */
1571 tmp = osfs->os_bsize | lov_sfs->os_bsize;
1572 for (shift = 0; shift <= 64; ++shift) {
1584 if (osfs->os_bsize < lov_sfs->os_bsize) {
1585 osfs->os_bsize = lov_sfs->os_bsize;
1587 osfs->os_bfree >>= shift;
1588 osfs->os_bavail >>= shift;
1589 osfs->os_blocks >>= shift;
1590 } else if (shift != 0) {
1591 lov_sfs->os_bfree >>= shift;
1592 lov_sfs->os_bavail >>= shift;
1593 lov_sfs->os_blocks >>= shift;
1596 /* Sandia requested that df (and so, statfs) only
1597 returned minimal available space on
1598 a single OST, so people would be able to
1599 write this much data guaranteed. */
1600 if (osfs->os_bavail > lov_sfs->os_bavail) {
1601 /* Presumably if new bavail is smaller,
1602 new bfree is bigger as well */
1603 osfs->os_bfree = lov_sfs->os_bfree;
1604 osfs->os_bavail = lov_sfs->os_bavail;
1607 osfs->os_bfree += lov_sfs->os_bfree;
1608 osfs->os_bavail += lov_sfs->os_bavail;
1610 osfs->os_blocks += lov_sfs->os_blocks;
1611 /* XXX not sure about this one - depends on policy.
1612 * - could be minimum if we always stripe on all OBDs
1613 * (but that would be wrong for any other policy,
1614 * if one of the OBDs has no more objects left)
1615 * - could be sum if we stripe whole objects
1616 * - could be average, just to give a nice number
1618 * To give a "reasonable" (if not wholly accurate)
1619 * number, we divide the total number of free objects
1620 * by expected stripe count (watch out for overflow).
1622 LOV_SUM_MAX(osfs->os_files, lov_sfs->os_files);
1623 LOV_SUM_MAX(osfs->os_ffree, lov_sfs->os_ffree);
1627 /* The callback for osc_statfs_async that finilizes a request info when a
1628 * response is received. */
1629 static int cb_statfs_update(void *cookie, int rc)
1631 struct obd_info *oinfo = cookie;
1632 struct lov_request *lovreq;
1633 struct lov_request_set *set;
1634 struct obd_statfs *osfs, *lov_sfs;
1635 struct lov_obd *lov;
1636 struct lov_tgt_desc *tgt;
1637 struct obd_device *lovobd, *tgtobd;
1641 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1642 set = lovreq->rq_rqset;
1643 lovobd = set->set_obd;
1644 lov = &lovobd->u.lov;
1645 osfs = set->set_oi->oi_osfs;
1646 lov_sfs = oinfo->oi_osfs;
1647 success = cfs_atomic_read(&set->set_success);
1648 /* XXX: the same is done in lov_update_common_set, however
1649 lovset->set_exp is not initialized. */
1650 lov_update_set(set, lovreq, rc);
1655 tgt = lov->lov_tgts[lovreq->rq_idx];
1656 if (!tgt || !tgt->ltd_active)
1657 GOTO(out_update, rc);
1659 tgtobd = class_exp2obd(tgt->ltd_exp);
1660 cfs_spin_lock(&tgtobd->obd_osfs_lock);
1661 memcpy(&tgtobd->obd_osfs, lov_sfs, sizeof(*lov_sfs));
1662 if ((oinfo->oi_flags & OBD_STATFS_FROM_CACHE) == 0)
1663 tgtobd->obd_osfs_age = cfs_time_current_64();
1664 cfs_spin_unlock(&tgtobd->obd_osfs_lock);
1667 lov_update_statfs(osfs, lov_sfs, success);
1672 if (set->set_oi->oi_flags & OBD_STATFS_PTLRPCD &&
1673 lov_finished_set(set)) {
1674 lov_statfs_interpret(NULL, set, set->set_count !=
1675 cfs_atomic_read(&set->set_success));
1676 if (lov->lov_qos.lq_statfs_in_progress)
1677 qos_statfs_done(lov);
1683 int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
1684 struct lov_request_set **reqset)
1686 struct lov_request_set *set;
1687 struct lov_obd *lov = &obd->u.lov;
1691 OBD_ALLOC(set, sizeof(*set));
1697 set->set_oi = oinfo;
1699 /* We only get block data from the OBD */
1700 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1701 struct lov_request *req;
1703 if (!lov->lov_tgts[i] || (!lov->lov_tgts[i]->ltd_active
1704 && (oinfo->oi_flags & OBD_STATFS_NODELAY))) {
1705 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1709 /* skip targets that have been explicitely disabled by the
1711 if (!lov->lov_tgts[i]->ltd_exp) {
1712 CDEBUG(D_HA, "lov idx %d administratively disabled\n", i);
1716 OBD_ALLOC(req, sizeof(*req));
1718 GOTO(out_set, rc = -ENOMEM);
1720 OBD_ALLOC(req->rq_oi.oi_osfs, sizeof(*req->rq_oi.oi_osfs));
1721 if (req->rq_oi.oi_osfs == NULL) {
1722 OBD_FREE(req, sizeof(*req));
1723 GOTO(out_set, rc = -ENOMEM);
1727 req->rq_oi.oi_cb_up = cb_statfs_update;
1728 req->rq_oi.oi_flags = oinfo->oi_flags;
1730 lov_set_add_req(req, set);
1732 if (!set->set_count)
1733 GOTO(out_set, rc = -EIO);
1737 lov_fini_statfs_set(set);