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);
56 cfs_atomic_set(&set->set_finish_checked, 0);
58 CFS_INIT_LIST_HEAD(&set->set_list);
59 cfs_atomic_set(&set->set_refcount, 1);
60 cfs_waitq_init(&set->set_waitq);
61 cfs_spin_lock_init(&set->set_lock);
64 void lov_finish_set(struct lov_request_set *set)
70 cfs_list_for_each_safe(pos, n, &set->set_list) {
71 struct lov_request *req = cfs_list_entry(pos,
74 cfs_list_del_init(&req->rq_link);
77 OBDO_FREE(req->rq_oi.oi_oa);
79 OBD_FREE_LARGE(req->rq_oi.oi_md, req->rq_buflen);
80 if (req->rq_oi.oi_osfs)
81 OBD_FREE(req->rq_oi.oi_osfs,
82 sizeof(*req->rq_oi.oi_osfs));
83 OBD_FREE(req, sizeof(*req));
87 int len = set->set_oabufs * sizeof(*set->set_pga);
88 OBD_FREE_LARGE(set->set_pga, len);
91 lov_llh_put(set->set_lockh);
93 OBD_FREE(set, sizeof(*set));
97 int lov_set_finished(struct lov_request_set *set, int idempotent)
99 int completes = cfs_atomic_read(&set->set_completes);
101 CDEBUG(D_INFO, "check set %d/%d\n", completes, set->set_count);
103 if (completes == set->set_count) {
106 if (cfs_atomic_inc_return(&set->set_finish_checked) == 1)
112 void lov_update_set(struct lov_request_set *set,
113 struct lov_request *req, int rc)
115 req->rq_complete = 1;
118 cfs_atomic_inc(&set->set_completes);
120 cfs_atomic_inc(&set->set_success);
122 cfs_waitq_signal(&set->set_waitq);
125 int lov_update_common_set(struct lov_request_set *set,
126 struct lov_request *req, int rc)
128 struct lov_obd *lov = &set->set_exp->exp_obd->u.lov;
131 lov_update_set(set, req, rc);
133 /* grace error on inactive ost */
134 if (rc && !(lov->lov_tgts[req->rq_idx] &&
135 lov->lov_tgts[req->rq_idx]->ltd_active))
138 /* FIXME in raid1 regime, should return 0 */
142 void lov_set_add_req(struct lov_request *req, struct lov_request_set *set)
144 cfs_list_add_tail(&req->rq_link, &set->set_list);
149 extern void osc_update_enqueue(struct lustre_handle *lov_lockhp,
150 struct lov_oinfo *loi, int flags,
151 struct ost_lvb *lvb, __u32 mode, int rc);
153 static int lov_update_enqueue_lov(struct obd_export *exp,
154 struct lustre_handle *lov_lockhp,
155 struct lov_oinfo *loi, int flags, int idx,
158 struct lov_obd *lov = &exp->exp_obd->u.lov;
160 if (rc != ELDLM_OK &&
161 !(rc == ELDLM_LOCK_ABORTED && (flags & LDLM_FL_HAS_INTENT))) {
162 memset(lov_lockhp, 0, sizeof(*lov_lockhp));
163 if (lov->lov_tgts[idx] && lov->lov_tgts[idx]->ltd_active) {
164 /* -EUSERS used by OST to report file contention */
165 if (rc != -EINTR && rc != -EUSERS)
166 CERROR("enqueue objid "LPX64" subobj "
167 LPX64" on OST idx %d: rc %d\n",
168 oid, loi->loi_id, loi->loi_ost_idx, rc);
175 int lov_update_enqueue_set(struct lov_request *req, __u32 mode, int rc)
177 struct lov_request_set *set = req->rq_rqset;
178 struct lustre_handle *lov_lockhp;
179 struct obd_info *oi = set->set_oi;
180 struct lov_oinfo *loi;
185 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
186 loi = oi->oi_md->lsm_oinfo[req->rq_stripe];
188 /* XXX LOV STACKING: OSC gets a copy, created in lov_prep_enqueue_set
189 * and that copy can be arbitrarily out of date.
191 * The LOV API is due for a serious rewriting anyways, and this
192 * can be addressed then. */
194 lov_stripe_lock(oi->oi_md);
195 osc_update_enqueue(lov_lockhp, loi, oi->oi_flags,
196 &req->rq_oi.oi_md->lsm_oinfo[0]->loi_lvb, mode, rc);
197 if (rc == ELDLM_LOCK_ABORTED && (oi->oi_flags & LDLM_FL_HAS_INTENT))
198 memset(lov_lockhp, 0, sizeof *lov_lockhp);
199 rc = lov_update_enqueue_lov(set->set_exp, lov_lockhp, loi, oi->oi_flags,
200 req->rq_idx, oi->oi_md->lsm_object_id, rc);
201 lov_stripe_unlock(oi->oi_md);
202 lov_update_set(set, req, rc);
206 /* The callback for osc_enqueue that updates lov info for every OSC request. */
207 static int cb_update_enqueue(void *cookie, int rc)
209 struct obd_info *oinfo = cookie;
210 struct ldlm_enqueue_info *einfo;
211 struct lov_request *lovreq;
213 lovreq = container_of(oinfo, struct lov_request, rq_oi);
214 einfo = lovreq->rq_rqset->set_ei;
215 return lov_update_enqueue_set(lovreq, einfo->ei_mode, rc);
218 static int enqueue_done(struct lov_request_set *set, __u32 mode)
220 struct lov_request *req;
221 struct lov_obd *lov = &set->set_exp->exp_obd->u.lov;
222 int completes = cfs_atomic_read(&set->set_completes);
226 /* enqueue/match success, just return */
227 if (completes && completes == cfs_atomic_read(&set->set_success))
230 /* cancel enqueued/matched locks */
231 cfs_list_for_each_entry(req, &set->set_list, rq_link) {
232 struct lustre_handle *lov_lockhp;
234 if (!req->rq_complete || req->rq_rc)
237 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
239 if (!lustre_handle_is_used(lov_lockhp))
242 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
243 req->rq_oi.oi_md, mode, lov_lockhp);
244 if (rc && lov->lov_tgts[req->rq_idx] &&
245 lov->lov_tgts[req->rq_idx]->ltd_active)
246 CERROR("cancelling obdjid "LPX64" on OST "
247 "idx %d error: rc = %d\n",
248 req->rq_oi.oi_md->lsm_object_id,
252 lov_llh_put(set->set_lockh);
256 int lov_fini_enqueue_set(struct lov_request_set *set, __u32 mode, int rc,
257 struct ptlrpc_request_set *rqset)
264 LASSERT(set->set_exp);
265 /* Do enqueue_done only for sync requests and if any request
269 cfs_atomic_set(&set->set_completes, 0);
270 ret = enqueue_done(set, mode);
271 } else if (set->set_lockh)
272 lov_llh_put(set->set_lockh);
276 RETURN(rc ? rc : ret);
279 static void lov_llh_addref(void *llhp)
281 struct lov_lock_handles *llh = llhp;
283 cfs_atomic_inc(&llh->llh_refcount);
284 CDEBUG(D_INFO, "GETting llh %p : new refcount %d\n", llh,
285 cfs_atomic_read(&llh->llh_refcount));
288 static struct portals_handle_ops lov_handle_ops = {
289 .hop_addref = lov_llh_addref,
293 static struct lov_lock_handles *lov_llh_new(struct lov_stripe_md *lsm)
295 struct lov_lock_handles *llh;
297 OBD_ALLOC(llh, sizeof *llh +
298 sizeof(*llh->llh_handles) * lsm->lsm_stripe_count);
302 cfs_atomic_set(&llh->llh_refcount, 2);
303 llh->llh_stripe_count = lsm->lsm_stripe_count;
304 CFS_INIT_LIST_HEAD(&llh->llh_handle.h_link);
305 class_handle_hash(&llh->llh_handle, &lov_handle_ops);
310 int lov_prep_enqueue_set(struct obd_export *exp, struct obd_info *oinfo,
311 struct ldlm_enqueue_info *einfo,
312 struct lov_request_set **reqset)
314 struct lov_obd *lov = &exp->exp_obd->u.lov;
315 struct lov_request_set *set;
319 OBD_ALLOC(set, sizeof(*set));
327 set->set_lockh = lov_llh_new(oinfo->oi_md);
328 if (set->set_lockh == NULL)
329 GOTO(out_set, rc = -ENOMEM);
330 oinfo->oi_lockh->cookie = set->set_lockh->llh_handle.h_cookie;
332 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
333 struct lov_oinfo *loi;
334 struct lov_request *req;
337 loi = oinfo->oi_md->lsm_oinfo[i];
338 if (!lov_stripe_intersects(oinfo->oi_md, i,
339 oinfo->oi_policy.l_extent.start,
340 oinfo->oi_policy.l_extent.end,
344 if (!lov->lov_tgts[loi->loi_ost_idx] ||
345 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
346 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
350 OBD_ALLOC(req, sizeof(*req));
352 GOTO(out_set, rc = -ENOMEM);
354 req->rq_buflen = sizeof(*req->rq_oi.oi_md) +
355 sizeof(struct lov_oinfo *) +
356 sizeof(struct lov_oinfo);
357 OBD_ALLOC_LARGE(req->rq_oi.oi_md, req->rq_buflen);
358 if (req->rq_oi.oi_md == NULL) {
359 OBD_FREE(req, sizeof(*req));
360 GOTO(out_set, rc = -ENOMEM);
362 req->rq_oi.oi_md->lsm_oinfo[0] =
363 ((void *)req->rq_oi.oi_md) + sizeof(*req->rq_oi.oi_md) +
364 sizeof(struct lov_oinfo *);
366 /* Set lov request specific parameters. */
367 req->rq_oi.oi_lockh = set->set_lockh->llh_handles + i;
368 req->rq_oi.oi_cb_up = cb_update_enqueue;
369 req->rq_oi.oi_flags = oinfo->oi_flags;
371 LASSERT(req->rq_oi.oi_lockh);
373 req->rq_oi.oi_policy.l_extent.gid =
374 oinfo->oi_policy.l_extent.gid;
375 req->rq_oi.oi_policy.l_extent.start = start;
376 req->rq_oi.oi_policy.l_extent.end = end;
378 req->rq_idx = loi->loi_ost_idx;
381 /* XXX LOV STACKING: submd should be from the subobj */
382 req->rq_oi.oi_md->lsm_object_id = loi->loi_id;
383 req->rq_oi.oi_md->lsm_object_seq = loi->loi_seq;
384 req->rq_oi.oi_md->lsm_stripe_count = 0;
385 req->rq_oi.oi_md->lsm_oinfo[0]->loi_kms_valid =
387 req->rq_oi.oi_md->lsm_oinfo[0]->loi_kms = loi->loi_kms;
388 req->rq_oi.oi_md->lsm_oinfo[0]->loi_lvb = loi->loi_lvb;
390 lov_set_add_req(req, set);
393 GOTO(out_set, rc = -EIO);
397 lov_fini_enqueue_set(set, einfo->ei_mode, rc, NULL);
401 int lov_fini_match_set(struct lov_request_set *set, __u32 mode, int flags)
408 LASSERT(set->set_exp);
409 rc = enqueue_done(set, mode);
410 if ((set->set_count == cfs_atomic_read(&set->set_success)) &&
411 (flags & LDLM_FL_TEST_LOCK))
412 lov_llh_put(set->set_lockh);
419 int lov_prep_match_set(struct obd_export *exp, struct obd_info *oinfo,
420 struct lov_stripe_md *lsm, ldlm_policy_data_t *policy,
421 __u32 mode, struct lustre_handle *lockh,
422 struct lov_request_set **reqset)
424 struct lov_obd *lov = &exp->exp_obd->u.lov;
425 struct lov_request_set *set;
429 OBD_ALLOC(set, sizeof(*set));
436 set->set_oi->oi_md = lsm;
437 set->set_lockh = lov_llh_new(lsm);
438 if (set->set_lockh == NULL)
439 GOTO(out_set, rc = -ENOMEM);
440 lockh->cookie = set->set_lockh->llh_handle.h_cookie;
442 for (i = 0; i < lsm->lsm_stripe_count; i++){
443 struct lov_oinfo *loi;
444 struct lov_request *req;
447 loi = lsm->lsm_oinfo[i];
448 if (!lov_stripe_intersects(lsm, i, policy->l_extent.start,
449 policy->l_extent.end, &start, &end))
452 /* FIXME raid1 should grace this error */
453 if (!lov->lov_tgts[loi->loi_ost_idx] ||
454 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
455 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
456 GOTO(out_set, rc = -EIO);
459 OBD_ALLOC(req, sizeof(*req));
461 GOTO(out_set, rc = -ENOMEM);
463 req->rq_buflen = sizeof(*req->rq_oi.oi_md);
464 OBD_ALLOC_LARGE(req->rq_oi.oi_md, req->rq_buflen);
465 if (req->rq_oi.oi_md == NULL) {
466 OBD_FREE(req, sizeof(*req));
467 GOTO(out_set, rc = -ENOMEM);
470 req->rq_oi.oi_policy.l_extent.start = start;
471 req->rq_oi.oi_policy.l_extent.end = end;
472 req->rq_oi.oi_policy.l_extent.gid = policy->l_extent.gid;
474 req->rq_idx = loi->loi_ost_idx;
477 /* XXX LOV STACKING: submd should be from the subobj */
478 req->rq_oi.oi_md->lsm_object_id = loi->loi_id;
479 req->rq_oi.oi_md->lsm_object_seq = loi->loi_seq;
480 req->rq_oi.oi_md->lsm_stripe_count = 0;
482 lov_set_add_req(req, set);
485 GOTO(out_set, rc = -EIO);
489 lov_fini_match_set(set, mode, 0);
493 int lov_fini_cancel_set(struct lov_request_set *set)
501 LASSERT(set->set_exp);
503 lov_llh_put(set->set_lockh);
510 int lov_prep_cancel_set(struct obd_export *exp, struct obd_info *oinfo,
511 struct lov_stripe_md *lsm, __u32 mode,
512 struct lustre_handle *lockh,
513 struct lov_request_set **reqset)
515 struct lov_request_set *set;
519 OBD_ALLOC(set, sizeof(*set));
526 set->set_oi->oi_md = lsm;
527 set->set_lockh = lov_handle2llh(lockh);
528 if (set->set_lockh == NULL) {
529 CERROR("LOV: invalid lov lock handle %p\n", lockh);
530 GOTO(out_set, rc = -EINVAL);
532 lockh->cookie = set->set_lockh->llh_handle.h_cookie;
534 for (i = 0; i < lsm->lsm_stripe_count; i++){
535 struct lov_request *req;
536 struct lustre_handle *lov_lockhp;
537 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
539 lov_lockhp = set->set_lockh->llh_handles + i;
540 if (!lustre_handle_is_used(lov_lockhp)) {
541 CDEBUG(D_INFO, "lov idx %d subobj "LPX64" no lock\n",
542 loi->loi_ost_idx, loi->loi_id);
546 OBD_ALLOC(req, sizeof(*req));
548 GOTO(out_set, rc = -ENOMEM);
550 req->rq_buflen = sizeof(*req->rq_oi.oi_md);
551 OBD_ALLOC_LARGE(req->rq_oi.oi_md, req->rq_buflen);
552 if (req->rq_oi.oi_md == NULL) {
553 OBD_FREE(req, sizeof(*req));
554 GOTO(out_set, rc = -ENOMEM);
557 req->rq_idx = loi->loi_ost_idx;
560 /* XXX LOV STACKING: submd should be from the subobj */
561 req->rq_oi.oi_md->lsm_object_id = loi->loi_id;
562 req->rq_oi.oi_md->lsm_object_seq = loi->loi_seq;
563 req->rq_oi.oi_md->lsm_stripe_count = 0;
565 lov_set_add_req(req, set);
568 GOTO(out_set, rc = -EIO);
572 lov_fini_cancel_set(set);
576 static int lov_update_create_set(struct lov_request_set *set,
577 struct lov_request *req, int rc)
579 struct obd_trans_info *oti = set->set_oti;
580 struct lov_stripe_md *lsm = set->set_oi->oi_md;
581 struct lov_oinfo *loi;
582 struct lov_obd *lov = &set->set_exp->exp_obd->u.lov;
585 if (rc && lov->lov_tgts[req->rq_idx] &&
586 lov->lov_tgts[req->rq_idx]->ltd_active) {
587 /* Pre-creating objects may timeout via -ETIMEDOUT or
588 * -ENOTCONN both are always non-critical events. */
589 CDEBUG(rc == -ETIMEDOUT || rc == -ENOTCONN ? D_HA : D_ERROR,
590 "error creating fid "LPX64" sub-object "
591 "on OST idx %d/%d: rc = %d\n",
592 set->set_oi->oi_oa->o_id, req->rq_idx,
593 lsm->lsm_stripe_count, rc);
595 CERROR("obd_create returned invalid err %d\n", rc);
600 cfs_spin_lock(&set->set_lock);
601 req->rq_stripe = cfs_atomic_read(&set->set_success);
602 loi = lsm->lsm_oinfo[req->rq_stripe];
606 lov_update_set(set, req, rc);
607 cfs_spin_unlock(&set->set_lock);
611 loi->loi_id = req->rq_oi.oi_oa->o_id;
612 loi->loi_seq = req->rq_oi.oi_oa->o_seq;
613 loi->loi_ost_idx = req->rq_idx;
616 if (oti && set->set_cookies)
617 ++oti->oti_logcookies;
618 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLCOOKIE)
619 set->set_cookie_sent++;
621 lov_update_set(set, req, rc);
622 cfs_spin_unlock(&set->set_lock);
624 CDEBUG(D_INODE, "objid "LPX64" has subobj "LPX64"/"LPU64" at idx %d\n",
625 lsm->lsm_object_id, loi->loi_id, loi->loi_id, req->rq_idx);
629 static int create_done(struct obd_export *exp, struct lov_request_set *set,
630 struct lov_stripe_md **lsmp)
632 struct lov_obd *lov = &exp->exp_obd->u.lov;
633 struct obd_trans_info *oti = set->set_oti;
634 struct obdo *src_oa = set->set_oi->oi_oa;
635 struct lov_request *req;
636 struct obdo *ret_oa = NULL;
637 int success, attrset = 0, rc = 0;
640 LASSERT(cfs_atomic_read(&set->set_completes));
642 /* try alloc objects on other osts if osc_create fails for
643 * exceptions: RPC failure, ENOSPC, etc */
644 if (set->set_count != cfs_atomic_read(&set->set_success)) {
645 cfs_list_for_each_entry (req, &set->set_list, rq_link) {
649 cfs_atomic_dec(&set->set_completes);
650 req->rq_complete = 0;
652 rc = qos_remedy_create(set, req);
653 lov_update_create_set(set, req, rc);
657 success = cfs_atomic_read(&set->set_success);
658 /* no successful creates */
662 if (set->set_count != success) {
663 set->set_count = success;
669 GOTO(cleanup, rc = -ENOMEM);
671 cfs_list_for_each_entry(req, &set->set_list, rq_link) {
672 if (!req->rq_complete || req->rq_rc)
674 lov_merge_attrs(ret_oa, req->rq_oi.oi_oa,
675 req->rq_oi.oi_oa->o_valid, set->set_oi->oi_md,
676 req->rq_stripe, &attrset);
678 if (src_oa->o_valid & OBD_MD_FLSIZE &&
679 ret_oa->o_size != src_oa->o_size) {
680 CERROR("original size "LPU64" isn't new object size "LPU64"\n",
681 src_oa->o_size, ret_oa->o_size);
684 ret_oa->o_id = src_oa->o_id;
685 ret_oa->o_seq = src_oa->o_seq;
686 ret_oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP;
687 memcpy(src_oa, ret_oa, sizeof(*src_oa));
690 *lsmp = set->set_oi->oi_md;
694 cfs_list_for_each_entry(req, &set->set_list, rq_link) {
695 struct obd_export *sub_exp;
698 if (!req->rq_complete || req->rq_rc)
701 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
702 err = obd_destroy(NULL, sub_exp, req->rq_oi.oi_oa, NULL, oti,
705 CERROR("Failed to uncreate objid "LPX64" subobj "
706 LPX64" on OST idx %d: rc = %d\n",
707 src_oa->o_id, req->rq_oi.oi_oa->o_id,
711 obd_free_memmd(exp, &set->set_oi->oi_md);
713 if (oti && set->set_cookies) {
714 oti->oti_logcookies = set->set_cookies;
715 if (!set->set_cookie_sent) {
716 oti_free_cookies(oti);
717 src_oa->o_valid &= ~OBD_MD_FLCOOKIE;
719 src_oa->o_valid |= OBD_MD_FLCOOKIE;
725 int lov_fini_create_set(struct lov_request_set *set,struct lov_stripe_md **lsmp)
732 LASSERT(set->set_exp);
733 if (cfs_atomic_read(&set->set_completes))
734 rc = create_done(set->set_exp, set, lsmp);
740 int cb_create_update(void *cookie, int rc)
742 struct obd_info *oinfo = cookie;
743 struct lov_request *lovreq;
745 lovreq = container_of(oinfo, struct lov_request, rq_oi);
747 if (CFS_FAIL_CHECK(OBD_FAIL_MDS_OSC_CREATE_FAIL))
748 if (lovreq->rq_idx == cfs_fail_val)
751 rc = lov_update_create_set(lovreq->rq_rqset, lovreq, rc);
752 if (lov_set_finished(lovreq->rq_rqset, 0))
753 lov_put_reqset(lovreq->rq_rqset);
757 int lov_prep_create_set(struct obd_export *exp, struct obd_info *oinfo,
758 struct lov_stripe_md **lsmp, struct obdo *src_oa,
759 struct obd_trans_info *oti,
760 struct lov_request_set **reqset)
762 struct lov_request_set *set;
766 OBD_ALLOC(set, sizeof(*set));
773 set->set_oi->oi_md = *lsmp;
774 set->set_oi->oi_oa = src_oa;
778 rc = qos_prep_create(exp, set);
779 /* qos_shrink_lsm() may have allocated a new lsm */
780 *lsmp = oinfo->oi_md;
782 lov_fini_create_set(set, lsmp);
790 static int common_attr_done(struct lov_request_set *set)
793 struct lov_request *req;
795 int rc = 0, attrset = 0;
798 LASSERT(set->set_oi != NULL);
800 if (set->set_oi->oi_oa == NULL)
803 if (!cfs_atomic_read(&set->set_success))
808 GOTO(out, rc = -ENOMEM);
810 cfs_list_for_each (pos, &set->set_list) {
811 req = cfs_list_entry(pos, struct lov_request, rq_link);
813 if (!req->rq_complete || req->rq_rc)
815 if (req->rq_oi.oi_oa->o_valid == 0) /* inactive stripe */
817 lov_merge_attrs(tmp_oa, req->rq_oi.oi_oa,
818 req->rq_oi.oi_oa->o_valid,
819 set->set_oi->oi_md, req->rq_stripe, &attrset);
822 CERROR("No stripes had valid attrs\n");
825 if ((set->set_oi->oi_oa->o_valid & OBD_MD_FLEPOCH) &&
826 (set->set_oi->oi_md->lsm_stripe_count != attrset)) {
827 /* When we take attributes of some epoch, we require all the
828 * ost to be active. */
829 CERROR("Not all the stripes had valid attrs\n");
830 GOTO(out, rc = -EIO);
833 tmp_oa->o_id = set->set_oi->oi_oa->o_id;
834 memcpy(set->set_oi->oi_oa, tmp_oa, sizeof(*set->set_oi->oi_oa));
842 static int brw_done(struct lov_request_set *set)
844 struct lov_stripe_md *lsm = set->set_oi->oi_md;
845 struct lov_oinfo *loi = NULL;
847 struct lov_request *req;
850 cfs_list_for_each (pos, &set->set_list) {
851 req = cfs_list_entry(pos, struct lov_request, rq_link);
853 if (!req->rq_complete || req->rq_rc)
856 loi = lsm->lsm_oinfo[req->rq_stripe];
858 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLBLOCKS)
859 loi->loi_lvb.lvb_blocks = req->rq_oi.oi_oa->o_blocks;
865 int lov_fini_brw_set(struct lov_request_set *set)
872 LASSERT(set->set_exp);
873 if (cfs_atomic_read(&set->set_completes)) {
875 /* FIXME update qos data here */
882 int lov_prep_brw_set(struct obd_export *exp, struct obd_info *oinfo,
883 obd_count oa_bufs, struct brw_page *pga,
884 struct obd_trans_info *oti,
885 struct lov_request_set **reqset)
892 struct lov_request_set *set;
893 struct lov_obd *lov = &exp->exp_obd->u.lov;
894 int rc = 0, i, shift;
897 OBD_ALLOC(set, sizeof(*set));
905 set->set_oabufs = oa_bufs;
906 OBD_ALLOC_LARGE(set->set_pga, oa_bufs * sizeof(*set->set_pga));
908 GOTO(out, rc = -ENOMEM);
910 OBD_ALLOC_LARGE(info, sizeof(*info) * oinfo->oi_md->lsm_stripe_count);
912 GOTO(out, rc = -ENOMEM);
914 /* calculate the page count for each stripe */
915 for (i = 0; i < oa_bufs; i++) {
916 int stripe = lov_stripe_number(oinfo->oi_md, pga[i].off);
917 info[stripe].count++;
920 /* alloc and initialize lov request */
922 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++){
923 struct lov_oinfo *loi = NULL;
924 struct lov_request *req;
926 if (info[i].count == 0)
929 loi = oinfo->oi_md->lsm_oinfo[i];
930 if (!lov->lov_tgts[loi->loi_ost_idx] ||
931 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
932 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
933 GOTO(out, rc = -EIO);
936 OBD_ALLOC(req, sizeof(*req));
938 GOTO(out, rc = -ENOMEM);
940 OBDO_ALLOC(req->rq_oi.oi_oa);
941 if (req->rq_oi.oi_oa == NULL) {
942 OBD_FREE(req, sizeof(*req));
943 GOTO(out, rc = -ENOMEM);
947 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
948 sizeof(*req->rq_oi.oi_oa));
950 req->rq_oi.oi_oa->o_id = loi->loi_id;
951 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
952 req->rq_oi.oi_oa->o_stripe_idx = i;
954 req->rq_buflen = sizeof(*req->rq_oi.oi_md);
955 OBD_ALLOC_LARGE(req->rq_oi.oi_md, req->rq_buflen);
956 if (req->rq_oi.oi_md == NULL) {
957 OBDO_FREE(req->rq_oi.oi_oa);
958 OBD_FREE(req, sizeof(*req));
959 GOTO(out, rc = -ENOMEM);
962 req->rq_idx = loi->loi_ost_idx;
965 /* XXX LOV STACKING */
966 req->rq_oi.oi_md->lsm_object_id = loi->loi_id;
967 req->rq_oi.oi_md->lsm_object_seq = loi->loi_seq;
968 req->rq_oabufs = info[i].count;
969 req->rq_pgaidx = shift;
970 shift += req->rq_oabufs;
972 /* remember the index for sort brw_page array */
973 info[i].index = req->rq_pgaidx;
975 req->rq_oi.oi_capa = oinfo->oi_capa;
977 lov_set_add_req(req, set);
980 GOTO(out, rc = -EIO);
982 /* rotate & sort the brw_page array */
983 for (i = 0; i < oa_bufs; i++) {
984 int stripe = lov_stripe_number(oinfo->oi_md, pga[i].off);
986 shift = info[stripe].index + info[stripe].off;
987 LASSERT(shift < oa_bufs);
988 set->set_pga[shift] = pga[i];
989 lov_stripe_offset(oinfo->oi_md, pga[i].off, stripe,
990 &set->set_pga[shift].off);
996 sizeof(*info) * oinfo->oi_md->lsm_stripe_count);
1001 lov_fini_brw_set(set);
1006 int lov_fini_getattr_set(struct lov_request_set *set)
1013 LASSERT(set->set_exp);
1014 if (cfs_atomic_read(&set->set_completes))
1015 rc = common_attr_done(set);
1017 lov_put_reqset(set);
1022 /* The callback for osc_getattr_async that finilizes a request info when a
1023 * response is received. */
1024 static int cb_getattr_update(void *cookie, int rc)
1026 struct obd_info *oinfo = cookie;
1027 struct lov_request *lovreq;
1028 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1029 return lov_update_common_set(lovreq->rq_rqset, lovreq, rc);
1032 int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo,
1033 struct lov_request_set **reqset)
1035 struct lov_request_set *set;
1036 struct lov_obd *lov = &exp->exp_obd->u.lov;
1040 OBD_ALLOC(set, sizeof(*set));
1046 set->set_oi = oinfo;
1048 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
1049 struct lov_oinfo *loi;
1050 struct lov_request *req;
1052 loi = oinfo->oi_md->lsm_oinfo[i];
1053 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1054 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1055 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1056 if (oinfo->oi_oa->o_valid & OBD_MD_FLEPOCH)
1057 /* SOM requires all the OSTs to be active. */
1058 GOTO(out_set, rc = -EIO);
1062 OBD_ALLOC(req, sizeof(*req));
1064 GOTO(out_set, rc = -ENOMEM);
1067 req->rq_idx = loi->loi_ost_idx;
1069 OBDO_ALLOC(req->rq_oi.oi_oa);
1070 if (req->rq_oi.oi_oa == NULL) {
1071 OBD_FREE(req, sizeof(*req));
1072 GOTO(out_set, rc = -ENOMEM);
1074 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
1075 sizeof(*req->rq_oi.oi_oa));
1076 req->rq_oi.oi_oa->o_id = loi->loi_id;
1077 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
1078 req->rq_oi.oi_cb_up = cb_getattr_update;
1079 req->rq_oi.oi_capa = oinfo->oi_capa;
1081 lov_set_add_req(req, set);
1083 if (!set->set_count)
1084 GOTO(out_set, rc = -EIO);
1088 lov_fini_getattr_set(set);
1092 int lov_fini_destroy_set(struct lov_request_set *set)
1098 LASSERT(set->set_exp);
1099 if (cfs_atomic_read(&set->set_completes)) {
1100 /* FIXME update qos data here */
1103 lov_put_reqset(set);
1108 int lov_prep_destroy_set(struct obd_export *exp, struct obd_info *oinfo,
1109 struct obdo *src_oa, struct lov_stripe_md *lsm,
1110 struct obd_trans_info *oti,
1111 struct lov_request_set **reqset)
1113 struct lov_request_set *set;
1114 struct lov_obd *lov = &exp->exp_obd->u.lov;
1118 OBD_ALLOC(set, sizeof(*set));
1124 set->set_oi = oinfo;
1125 set->set_oi->oi_md = lsm;
1126 set->set_oi->oi_oa = src_oa;
1128 if (oti != NULL && src_oa->o_valid & OBD_MD_FLCOOKIE)
1129 set->set_cookies = oti->oti_logcookies;
1131 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1132 struct lov_oinfo *loi;
1133 struct lov_request *req;
1135 loi = lsm->lsm_oinfo[i];
1136 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1137 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1138 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1142 OBD_ALLOC(req, sizeof(*req));
1144 GOTO(out_set, rc = -ENOMEM);
1147 req->rq_idx = loi->loi_ost_idx;
1149 OBDO_ALLOC(req->rq_oi.oi_oa);
1150 if (req->rq_oi.oi_oa == NULL) {
1151 OBD_FREE(req, sizeof(*req));
1152 GOTO(out_set, rc = -ENOMEM);
1154 memcpy(req->rq_oi.oi_oa, src_oa, sizeof(*req->rq_oi.oi_oa));
1155 req->rq_oi.oi_oa->o_id = loi->loi_id;
1156 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
1157 lov_set_add_req(req, set);
1159 if (!set->set_count)
1160 GOTO(out_set, rc = -EIO);
1164 lov_fini_destroy_set(set);
1168 int lov_fini_setattr_set(struct lov_request_set *set)
1175 LASSERT(set->set_exp);
1176 if (cfs_atomic_read(&set->set_completes)) {
1177 rc = common_attr_done(set);
1178 /* FIXME update qos data here */
1181 lov_put_reqset(set);
1185 int lov_update_setattr_set(struct lov_request_set *set,
1186 struct lov_request *req, int rc)
1188 struct lov_obd *lov = &req->rq_rqset->set_exp->exp_obd->u.lov;
1189 struct lov_stripe_md *lsm = req->rq_rqset->set_oi->oi_md;
1192 lov_update_set(set, req, rc);
1194 /* grace error on inactive ost */
1195 if (rc && !(lov->lov_tgts[req->rq_idx] &&
1196 lov->lov_tgts[req->rq_idx]->ltd_active))
1200 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLCTIME)
1201 lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_ctime =
1202 req->rq_oi.oi_oa->o_ctime;
1203 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLMTIME)
1204 lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_mtime =
1205 req->rq_oi.oi_oa->o_mtime;
1206 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLATIME)
1207 lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_atime =
1208 req->rq_oi.oi_oa->o_atime;
1214 /* The callback for osc_setattr_async that finilizes a request info when a
1215 * response is received. */
1216 static int cb_setattr_update(void *cookie, int rc)
1218 struct obd_info *oinfo = cookie;
1219 struct lov_request *lovreq;
1220 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1221 return lov_update_setattr_set(lovreq->rq_rqset, lovreq, rc);
1224 int lov_prep_setattr_set(struct obd_export *exp, struct obd_info *oinfo,
1225 struct obd_trans_info *oti,
1226 struct lov_request_set **reqset)
1228 struct lov_request_set *set;
1229 struct lov_obd *lov = &exp->exp_obd->u.lov;
1233 OBD_ALLOC(set, sizeof(*set));
1240 set->set_oi = oinfo;
1241 if (oti != NULL && oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1242 set->set_cookies = oti->oti_logcookies;
1244 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
1245 struct lov_oinfo *loi = oinfo->oi_md->lsm_oinfo[i];
1246 struct lov_request *req;
1248 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1249 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1250 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1254 OBD_ALLOC(req, sizeof(*req));
1256 GOTO(out_set, rc = -ENOMEM);
1258 req->rq_idx = loi->loi_ost_idx;
1260 OBDO_ALLOC(req->rq_oi.oi_oa);
1261 if (req->rq_oi.oi_oa == NULL) {
1262 OBD_FREE(req, sizeof(*req));
1263 GOTO(out_set, rc = -ENOMEM);
1265 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
1266 sizeof(*req->rq_oi.oi_oa));
1267 req->rq_oi.oi_oa->o_id = loi->loi_id;
1268 req->rq_oi.oi_oa->o_seq= loi->loi_seq;
1269 req->rq_oi.oi_oa->o_stripe_idx = i;
1270 req->rq_oi.oi_cb_up = cb_setattr_update;
1271 req->rq_oi.oi_capa = oinfo->oi_capa;
1273 if (oinfo->oi_oa->o_valid & OBD_MD_FLSIZE) {
1274 int off = lov_stripe_offset(oinfo->oi_md,
1275 oinfo->oi_oa->o_size, i,
1276 &req->rq_oi.oi_oa->o_size);
1278 if (off < 0 && req->rq_oi.oi_oa->o_size)
1279 req->rq_oi.oi_oa->o_size--;
1281 CDEBUG(D_INODE, "stripe %d has size "LPU64"/"LPU64"\n",
1282 i, req->rq_oi.oi_oa->o_size,
1283 oinfo->oi_oa->o_size);
1285 lov_set_add_req(req, set);
1287 if (!set->set_count)
1288 GOTO(out_set, rc = -EIO);
1292 lov_fini_setattr_set(set);
1296 int lov_fini_punch_set(struct lov_request_set *set)
1303 LASSERT(set->set_exp);
1304 if (cfs_atomic_read(&set->set_completes)) {
1306 /* FIXME update qos data here */
1307 if (cfs_atomic_read(&set->set_success))
1308 rc = common_attr_done(set);
1311 lov_put_reqset(set);
1316 int lov_update_punch_set(struct lov_request_set *set,
1317 struct lov_request *req, int rc)
1319 struct lov_obd *lov = &req->rq_rqset->set_exp->exp_obd->u.lov;
1320 struct lov_stripe_md *lsm = req->rq_rqset->set_oi->oi_md;
1323 lov_update_set(set, req, rc);
1325 /* grace error on inactive ost */
1326 if (rc && !lov->lov_tgts[req->rq_idx]->ltd_active)
1330 lov_stripe_lock(lsm);
1331 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLBLOCKS) {
1332 lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_blocks =
1333 req->rq_oi.oi_oa->o_blocks;
1336 /* Do we need to update lvb_size here? It needn't because
1337 * it have been done in ll_truncate(). -jay */
1338 lov_stripe_unlock(lsm);
1344 /* The callback for osc_punch that finilizes a request info when a response
1346 static int cb_update_punch(void *cookie, int rc)
1348 struct obd_info *oinfo = cookie;
1349 struct lov_request *lovreq;
1350 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1351 return lov_update_punch_set(lovreq->rq_rqset, lovreq, rc);
1354 int lov_prep_punch_set(struct obd_export *exp, struct obd_info *oinfo,
1355 struct obd_trans_info *oti,
1356 struct lov_request_set **reqset)
1358 struct lov_request_set *set;
1359 struct lov_obd *lov = &exp->exp_obd->u.lov;
1363 OBD_ALLOC(set, sizeof(*set));
1368 set->set_oi = oinfo;
1371 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
1372 struct lov_oinfo *loi = oinfo->oi_md->lsm_oinfo[i];
1373 struct lov_request *req;
1376 if (!lov_stripe_intersects(oinfo->oi_md, i,
1377 oinfo->oi_policy.l_extent.start,
1378 oinfo->oi_policy.l_extent.end,
1382 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1383 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1384 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1385 GOTO(out_set, rc = -EIO);
1388 OBD_ALLOC(req, sizeof(*req));
1390 GOTO(out_set, rc = -ENOMEM);
1392 req->rq_idx = loi->loi_ost_idx;
1394 OBDO_ALLOC(req->rq_oi.oi_oa);
1395 if (req->rq_oi.oi_oa == NULL) {
1396 OBD_FREE(req, sizeof(*req));
1397 GOTO(out_set, rc = -ENOMEM);
1399 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
1400 sizeof(*req->rq_oi.oi_oa));
1401 req->rq_oi.oi_oa->o_id = loi->loi_id;
1402 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
1403 req->rq_oi.oi_oa->o_valid |= OBD_MD_FLGROUP;
1405 req->rq_oi.oi_oa->o_stripe_idx = i;
1406 req->rq_oi.oi_cb_up = cb_update_punch;
1408 req->rq_oi.oi_policy.l_extent.start = rs;
1409 req->rq_oi.oi_policy.l_extent.end = re;
1410 req->rq_oi.oi_policy.l_extent.gid = -1;
1412 req->rq_oi.oi_capa = oinfo->oi_capa;
1414 lov_set_add_req(req, set);
1416 if (!set->set_count)
1417 GOTO(out_set, rc = -EIO);
1421 lov_fini_punch_set(set);
1425 int lov_fini_sync_set(struct lov_request_set *set)
1432 LASSERT(set->set_exp);
1433 if (cfs_atomic_read(&set->set_completes)) {
1434 if (!cfs_atomic_read(&set->set_success))
1436 /* FIXME update qos data here */
1439 lov_put_reqset(set);
1444 /* The callback for osc_sync that finilizes a request info when a
1445 * response is recieved. */
1446 static int cb_sync_update(void *cookie, int rc)
1448 struct obd_info *oinfo = cookie;
1449 struct lov_request *lovreq;
1451 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1452 return lov_update_common_set(lovreq->rq_rqset, lovreq, rc);
1455 int lov_prep_sync_set(struct obd_export *exp, struct obd_info *oinfo,
1456 obd_off start, obd_off end,
1457 struct lov_request_set **reqset)
1459 struct lov_request_set *set;
1460 struct lov_obd *lov = &exp->exp_obd->u.lov;
1470 set->set_oi = oinfo;
1472 for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
1473 struct lov_oinfo *loi = oinfo->oi_md->lsm_oinfo[i];
1474 struct lov_request *req;
1477 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1478 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1479 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1483 if (!lov_stripe_intersects(oinfo->oi_md, i, start, end, &rs,
1489 GOTO(out_set, rc = -ENOMEM);
1491 req->rq_idx = loi->loi_ost_idx;
1493 OBDO_ALLOC(req->rq_oi.oi_oa);
1494 if (req->rq_oi.oi_oa == NULL) {
1495 OBD_FREE(req, sizeof(*req));
1496 GOTO(out_set, rc = -ENOMEM);
1498 *req->rq_oi.oi_oa = *oinfo->oi_oa;
1499 req->rq_oi.oi_oa->o_id = loi->loi_id;
1500 req->rq_oi.oi_oa->o_seq = loi->loi_seq;
1501 req->rq_oi.oi_oa->o_stripe_idx = i;
1503 req->rq_oi.oi_policy.l_extent.start = rs;
1504 req->rq_oi.oi_policy.l_extent.end = re;
1505 req->rq_oi.oi_policy.l_extent.gid = -1;
1506 req->rq_oi.oi_cb_up = cb_sync_update;
1508 lov_set_add_req(req, set);
1510 if (!set->set_count)
1511 GOTO(out_set, rc = -EIO);
1515 lov_fini_sync_set(set);
1519 #define LOV_U64_MAX ((__u64)~0ULL)
1520 #define LOV_SUM_MAX(tot, add) \
1522 if ((tot) + (add) < (tot)) \
1523 (tot) = LOV_U64_MAX; \
1528 int lov_fini_statfs(struct obd_device *obd, struct obd_statfs *osfs,int success)
1533 __u32 expected_stripes = lov_get_stripecnt(&obd->u.lov,
1535 if (osfs->os_files != LOV_U64_MAX)
1536 lov_do_div64(osfs->os_files, expected_stripes);
1537 if (osfs->os_ffree != LOV_U64_MAX)
1538 lov_do_div64(osfs->os_ffree, expected_stripes);
1540 cfs_spin_lock(&obd->obd_osfs_lock);
1541 memcpy(&obd->obd_osfs, osfs, sizeof(*osfs));
1542 obd->obd_osfs_age = cfs_time_current_64();
1543 cfs_spin_unlock(&obd->obd_osfs_lock);
1550 int lov_fini_statfs_set(struct lov_request_set *set)
1558 if (cfs_atomic_read(&set->set_completes)) {
1559 rc = lov_fini_statfs(set->set_obd, set->set_oi->oi_osfs,
1560 cfs_atomic_read(&set->set_success));
1562 lov_put_reqset(set);
1566 void lov_update_statfs(struct obd_statfs *osfs, struct obd_statfs *lov_sfs,
1569 int shift = 0, quit = 0;
1573 memcpy(osfs, lov_sfs, sizeof(*lov_sfs));
1575 if (osfs->os_bsize != lov_sfs->os_bsize) {
1576 /* assume all block sizes are always powers of 2 */
1577 /* get the bits difference */
1578 tmp = osfs->os_bsize | lov_sfs->os_bsize;
1579 for (shift = 0; shift <= 64; ++shift) {
1591 if (osfs->os_bsize < lov_sfs->os_bsize) {
1592 osfs->os_bsize = lov_sfs->os_bsize;
1594 osfs->os_bfree >>= shift;
1595 osfs->os_bavail >>= shift;
1596 osfs->os_blocks >>= shift;
1597 } else if (shift != 0) {
1598 lov_sfs->os_bfree >>= shift;
1599 lov_sfs->os_bavail >>= shift;
1600 lov_sfs->os_blocks >>= shift;
1603 /* Sandia requested that df (and so, statfs) only
1604 returned minimal available space on
1605 a single OST, so people would be able to
1606 write this much data guaranteed. */
1607 if (osfs->os_bavail > lov_sfs->os_bavail) {
1608 /* Presumably if new bavail is smaller,
1609 new bfree is bigger as well */
1610 osfs->os_bfree = lov_sfs->os_bfree;
1611 osfs->os_bavail = lov_sfs->os_bavail;
1614 osfs->os_bfree += lov_sfs->os_bfree;
1615 osfs->os_bavail += lov_sfs->os_bavail;
1617 osfs->os_blocks += lov_sfs->os_blocks;
1618 /* XXX not sure about this one - depends on policy.
1619 * - could be minimum if we always stripe on all OBDs
1620 * (but that would be wrong for any other policy,
1621 * if one of the OBDs has no more objects left)
1622 * - could be sum if we stripe whole objects
1623 * - could be average, just to give a nice number
1625 * To give a "reasonable" (if not wholly accurate)
1626 * number, we divide the total number of free objects
1627 * by expected stripe count (watch out for overflow).
1629 LOV_SUM_MAX(osfs->os_files, lov_sfs->os_files);
1630 LOV_SUM_MAX(osfs->os_ffree, lov_sfs->os_ffree);
1634 /* The callback for osc_statfs_async that finilizes a request info when a
1635 * response is received. */
1636 static int cb_statfs_update(void *cookie, int rc)
1638 struct obd_info *oinfo = cookie;
1639 struct lov_request *lovreq;
1640 struct lov_request_set *set;
1641 struct obd_statfs *osfs, *lov_sfs;
1642 struct lov_obd *lov;
1643 struct lov_tgt_desc *tgt;
1644 struct obd_device *lovobd, *tgtobd;
1648 lovreq = container_of(oinfo, struct lov_request, rq_oi);
1649 set = lovreq->rq_rqset;
1650 lovobd = set->set_obd;
1651 lov = &lovobd->u.lov;
1652 osfs = set->set_oi->oi_osfs;
1653 lov_sfs = oinfo->oi_osfs;
1654 success = cfs_atomic_read(&set->set_success);
1655 /* XXX: the same is done in lov_update_common_set, however
1656 lovset->set_exp is not initialized. */
1657 lov_update_set(set, lovreq, rc);
1662 tgt = lov->lov_tgts[lovreq->rq_idx];
1663 if (!tgt || !tgt->ltd_active)
1664 GOTO(out_update, rc);
1666 tgtobd = class_exp2obd(tgt->ltd_exp);
1667 cfs_spin_lock(&tgtobd->obd_osfs_lock);
1668 memcpy(&tgtobd->obd_osfs, lov_sfs, sizeof(*lov_sfs));
1669 if ((oinfo->oi_flags & OBD_STATFS_FROM_CACHE) == 0)
1670 tgtobd->obd_osfs_age = cfs_time_current_64();
1671 cfs_spin_unlock(&tgtobd->obd_osfs_lock);
1674 lov_update_statfs(osfs, lov_sfs, success);
1679 if (set->set_oi->oi_flags & OBD_STATFS_PTLRPCD &&
1680 lov_set_finished(set, 0)) {
1681 lov_statfs_interpret(NULL, set, set->set_count !=
1682 cfs_atomic_read(&set->set_success));
1683 if (lov->lov_qos.lq_statfs_in_progress)
1684 qos_statfs_done(lov);
1690 int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
1691 struct lov_request_set **reqset)
1693 struct lov_request_set *set;
1694 struct lov_obd *lov = &obd->u.lov;
1698 OBD_ALLOC(set, sizeof(*set));
1704 set->set_oi = oinfo;
1706 /* We only get block data from the OBD */
1707 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1708 struct lov_request *req;
1710 if (!lov->lov_tgts[i] || (!lov->lov_tgts[i]->ltd_active
1711 && (oinfo->oi_flags & OBD_STATFS_NODELAY))) {
1712 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1716 /* skip targets that have been explicitely disabled by the
1718 if (!lov->lov_tgts[i]->ltd_exp) {
1719 CDEBUG(D_HA, "lov idx %d administratively disabled\n", i);
1723 OBD_ALLOC(req, sizeof(*req));
1725 GOTO(out_set, rc = -ENOMEM);
1727 OBD_ALLOC(req->rq_oi.oi_osfs, sizeof(*req->rq_oi.oi_osfs));
1728 if (req->rq_oi.oi_osfs == NULL) {
1729 OBD_FREE(req, sizeof(*req));
1730 GOTO(out_set, rc = -ENOMEM);
1734 req->rq_oi.oi_cb_up = cb_statfs_update;
1735 req->rq_oi.oi_flags = oinfo->oi_flags;
1737 lov_set_add_req(req, set);
1739 if (!set->set_count)
1740 GOTO(out_set, rc = -EIO);
1744 lov_fini_statfs_set(set);