f57675034b514a3bd24a340097e1f5d13847f3c8
[cascardo/linux.git] / drivers / staging / lustre / lustre / lov / lov_request.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #define DEBUG_SUBSYSTEM S_LOV
38
39 #include "../../include/linux/libcfs/libcfs.h"
40
41 #include "../include/obd_class.h"
42 #include "../include/lustre/lustre_idl.h"
43 #include "lov_internal.h"
44
45 static void lov_init_set(struct lov_request_set *set)
46 {
47         set->set_count = 0;
48         atomic_set(&set->set_completes, 0);
49         atomic_set(&set->set_success, 0);
50         atomic_set(&set->set_finish_checked, 0);
51         set->set_cookies = NULL;
52         INIT_LIST_HEAD(&set->set_list);
53         atomic_set(&set->set_refcount, 1);
54         init_waitqueue_head(&set->set_waitq);
55         spin_lock_init(&set->set_lock);
56 }
57
58 void lov_finish_set(struct lov_request_set *set)
59 {
60         struct list_head *pos, *n;
61
62         LASSERT(set);
63         list_for_each_safe(pos, n, &set->set_list) {
64                 struct lov_request *req = list_entry(pos,
65                                                          struct lov_request,
66                                                          rq_link);
67                 list_del_init(&req->rq_link);
68
69                 if (req->rq_oi.oi_oa)
70                         OBDO_FREE(req->rq_oi.oi_oa);
71                 if (req->rq_oi.oi_md)
72                         OBD_FREE_LARGE(req->rq_oi.oi_md, req->rq_buflen);
73                 if (req->rq_oi.oi_osfs)
74                         OBD_FREE(req->rq_oi.oi_osfs,
75                                  sizeof(*req->rq_oi.oi_osfs));
76                 OBD_FREE(req, sizeof(*req));
77         }
78
79         if (set->set_pga) {
80                 int len = set->set_oabufs * sizeof(*set->set_pga);
81                 OBD_FREE_LARGE(set->set_pga, len);
82         }
83         if (set->set_lockh)
84                 lov_llh_put(set->set_lockh);
85
86         OBD_FREE(set, sizeof(*set));
87 }
88
89 int lov_set_finished(struct lov_request_set *set, int idempotent)
90 {
91         int completes = atomic_read(&set->set_completes);
92
93         CDEBUG(D_INFO, "check set %d/%d\n", completes, set->set_count);
94
95         if (completes == set->set_count) {
96                 if (idempotent)
97                         return 1;
98                 if (atomic_inc_return(&set->set_finish_checked) == 1)
99                         return 1;
100         }
101         return 0;
102 }
103
104 void lov_update_set(struct lov_request_set *set,
105                     struct lov_request *req, int rc)
106 {
107         req->rq_complete = 1;
108         req->rq_rc = rc;
109
110         atomic_inc(&set->set_completes);
111         if (rc == 0)
112                 atomic_inc(&set->set_success);
113
114         wake_up(&set->set_waitq);
115 }
116
117 int lov_update_common_set(struct lov_request_set *set,
118                           struct lov_request *req, int rc)
119 {
120         struct lov_obd *lov = &set->set_exp->exp_obd->u.lov;
121
122         lov_update_set(set, req, rc);
123
124         /* grace error on inactive ost */
125         if (rc && !(lov->lov_tgts[req->rq_idx] &&
126                     lov->lov_tgts[req->rq_idx]->ltd_active))
127                 rc = 0;
128
129         /* FIXME in raid1 regime, should return 0 */
130         return rc;
131 }
132
133 void lov_set_add_req(struct lov_request *req, struct lov_request_set *set)
134 {
135         list_add_tail(&req->rq_link, &set->set_list);
136         set->set_count++;
137         req->rq_rqset = set;
138 }
139
140 static int lov_check_set(struct lov_obd *lov, int idx)
141 {
142         int rc;
143         struct lov_tgt_desc *tgt;
144
145         mutex_lock(&lov->lov_lock);
146         tgt = lov->lov_tgts[idx];
147         rc = !tgt || tgt->ltd_active ||
148                 (tgt->ltd_exp &&
149                  class_exp2cliimp(tgt->ltd_exp)->imp_connect_tried);
150         mutex_unlock(&lov->lov_lock);
151
152         return rc;
153 }
154
155 /* Check if the OSC connection exists and is active.
156  * If the OSC has not yet had a chance to connect to the OST the first time,
157  * wait once for it to connect instead of returning an error.
158  */
159 int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx)
160 {
161         wait_queue_head_t waitq;
162         struct l_wait_info lwi;
163         struct lov_tgt_desc *tgt;
164         int rc = 0;
165
166         mutex_lock(&lov->lov_lock);
167
168         tgt = lov->lov_tgts[ost_idx];
169
170         if (unlikely(tgt == NULL))
171                 GOTO(out, rc = 0);
172
173         if (likely(tgt->ltd_active))
174                 GOTO(out, rc = 1);
175
176         if (tgt->ltd_exp && class_exp2cliimp(tgt->ltd_exp)->imp_connect_tried)
177                 GOTO(out, rc = 0);
178
179         mutex_unlock(&lov->lov_lock);
180
181         init_waitqueue_head(&waitq);
182         lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(obd_timeout),
183                                    cfs_time_seconds(1), NULL, NULL);
184
185         rc = l_wait_event(waitq, lov_check_set(lov, ost_idx), &lwi);
186         if (tgt != NULL && tgt->ltd_active)
187                 return 1;
188
189         return 0;
190
191 out:
192         mutex_unlock(&lov->lov_lock);
193         return rc;
194 }
195
196 static int common_attr_done(struct lov_request_set *set)
197 {
198         struct list_head *pos;
199         struct lov_request *req;
200         struct obdo *tmp_oa;
201         int rc = 0, attrset = 0;
202
203         LASSERT(set->set_oi != NULL);
204
205         if (set->set_oi->oi_oa == NULL)
206                 return 0;
207
208         if (!atomic_read(&set->set_success))
209                 return -EIO;
210
211         OBDO_ALLOC(tmp_oa);
212         if (tmp_oa == NULL)
213                 GOTO(out, rc = -ENOMEM);
214
215         list_for_each(pos, &set->set_list) {
216                 req = list_entry(pos, struct lov_request, rq_link);
217
218                 if (!req->rq_complete || req->rq_rc)
219                         continue;
220                 if (req->rq_oi.oi_oa->o_valid == 0)   /* inactive stripe */
221                         continue;
222                 lov_merge_attrs(tmp_oa, req->rq_oi.oi_oa,
223                                 req->rq_oi.oi_oa->o_valid,
224                                 set->set_oi->oi_md, req->rq_stripe, &attrset);
225         }
226         if (!attrset) {
227                 CERROR("No stripes had valid attrs\n");
228                 rc = -EIO;
229         }
230         if ((set->set_oi->oi_oa->o_valid & OBD_MD_FLEPOCH) &&
231             (set->set_oi->oi_md->lsm_stripe_count != attrset)) {
232                 /* When we take attributes of some epoch, we require all the
233                  * ost to be active. */
234                 CERROR("Not all the stripes had valid attrs\n");
235                 GOTO(out, rc = -EIO);
236         }
237
238         tmp_oa->o_oi = set->set_oi->oi_oa->o_oi;
239         memcpy(set->set_oi->oi_oa, tmp_oa, sizeof(*set->set_oi->oi_oa));
240 out:
241         if (tmp_oa)
242                 OBDO_FREE(tmp_oa);
243         return rc;
244
245 }
246
247 int lov_fini_getattr_set(struct lov_request_set *set)
248 {
249         int rc = 0;
250
251         if (set == NULL)
252                 return 0;
253         LASSERT(set->set_exp);
254         if (atomic_read(&set->set_completes))
255                 rc = common_attr_done(set);
256
257         lov_put_reqset(set);
258
259         return rc;
260 }
261
262 /* The callback for osc_getattr_async that finalizes a request info when a
263  * response is received. */
264 static int cb_getattr_update(void *cookie, int rc)
265 {
266         struct obd_info *oinfo = cookie;
267         struct lov_request *lovreq;
268
269         lovreq = container_of(oinfo, struct lov_request, rq_oi);
270         return lov_update_common_set(lovreq->rq_rqset, lovreq, rc);
271 }
272
273 int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo,
274                          struct lov_request_set **reqset)
275 {
276         struct lov_request_set *set;
277         struct lov_obd *lov = &exp->exp_obd->u.lov;
278         int rc = 0, i;
279
280         OBD_ALLOC(set, sizeof(*set));
281         if (set == NULL)
282                 return -ENOMEM;
283         lov_init_set(set);
284
285         set->set_exp = exp;
286         set->set_oi = oinfo;
287
288         for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
289                 struct lov_oinfo *loi;
290                 struct lov_request *req;
291
292                 loi = oinfo->oi_md->lsm_oinfo[i];
293                 if (!lov_check_and_wait_active(lov, loi->loi_ost_idx)) {
294                         CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
295                         if (oinfo->oi_oa->o_valid & OBD_MD_FLEPOCH)
296                                 /* SOM requires all the OSTs to be active. */
297                                 GOTO(out_set, rc = -EIO);
298                         continue;
299                 }
300
301                 OBD_ALLOC(req, sizeof(*req));
302                 if (req == NULL)
303                         GOTO(out_set, rc = -ENOMEM);
304
305                 req->rq_stripe = i;
306                 req->rq_idx = loi->loi_ost_idx;
307
308                 OBDO_ALLOC(req->rq_oi.oi_oa);
309                 if (req->rq_oi.oi_oa == NULL) {
310                         OBD_FREE(req, sizeof(*req));
311                         GOTO(out_set, rc = -ENOMEM);
312                 }
313                 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
314                        sizeof(*req->rq_oi.oi_oa));
315                 req->rq_oi.oi_oa->o_oi = loi->loi_oi;
316                 req->rq_oi.oi_cb_up = cb_getattr_update;
317                 req->rq_oi.oi_capa = oinfo->oi_capa;
318
319                 lov_set_add_req(req, set);
320         }
321         if (!set->set_count)
322                 GOTO(out_set, rc = -EIO);
323         *reqset = set;
324         return rc;
325 out_set:
326         lov_fini_getattr_set(set);
327         return rc;
328 }
329
330 int lov_fini_destroy_set(struct lov_request_set *set)
331 {
332         if (set == NULL)
333                 return 0;
334         LASSERT(set->set_exp);
335         if (atomic_read(&set->set_completes)) {
336                 /* FIXME update qos data here */
337         }
338
339         lov_put_reqset(set);
340
341         return 0;
342 }
343
344 int lov_prep_destroy_set(struct obd_export *exp, struct obd_info *oinfo,
345                          struct obdo *src_oa, struct lov_stripe_md *lsm,
346                          struct obd_trans_info *oti,
347                          struct lov_request_set **reqset)
348 {
349         struct lov_request_set *set;
350         struct lov_obd *lov = &exp->exp_obd->u.lov;
351         int rc = 0, i;
352
353         OBD_ALLOC(set, sizeof(*set));
354         if (set == NULL)
355                 return -ENOMEM;
356         lov_init_set(set);
357
358         set->set_exp = exp;
359         set->set_oi = oinfo;
360         set->set_oi->oi_md = lsm;
361         set->set_oi->oi_oa = src_oa;
362         set->set_oti = oti;
363         if (oti != NULL && src_oa->o_valid & OBD_MD_FLCOOKIE)
364                 set->set_cookies = oti->oti_logcookies;
365
366         for (i = 0; i < lsm->lsm_stripe_count; i++) {
367                 struct lov_oinfo *loi;
368                 struct lov_request *req;
369
370                 loi = lsm->lsm_oinfo[i];
371                 if (!lov_check_and_wait_active(lov, loi->loi_ost_idx)) {
372                         CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
373                         continue;
374                 }
375
376                 OBD_ALLOC(req, sizeof(*req));
377                 if (req == NULL)
378                         GOTO(out_set, rc = -ENOMEM);
379
380                 req->rq_stripe = i;
381                 req->rq_idx = loi->loi_ost_idx;
382
383                 OBDO_ALLOC(req->rq_oi.oi_oa);
384                 if (req->rq_oi.oi_oa == NULL) {
385                         OBD_FREE(req, sizeof(*req));
386                         GOTO(out_set, rc = -ENOMEM);
387                 }
388                 memcpy(req->rq_oi.oi_oa, src_oa, sizeof(*req->rq_oi.oi_oa));
389                 req->rq_oi.oi_oa->o_oi = loi->loi_oi;
390                 lov_set_add_req(req, set);
391         }
392         if (!set->set_count)
393                 GOTO(out_set, rc = -EIO);
394         *reqset = set;
395         return rc;
396 out_set:
397         lov_fini_destroy_set(set);
398         return rc;
399 }
400
401 int lov_fini_setattr_set(struct lov_request_set *set)
402 {
403         int rc = 0;
404
405         if (set == NULL)
406                 return 0;
407         LASSERT(set->set_exp);
408         if (atomic_read(&set->set_completes)) {
409                 rc = common_attr_done(set);
410                 /* FIXME update qos data here */
411         }
412
413         lov_put_reqset(set);
414         return rc;
415 }
416
417 int lov_update_setattr_set(struct lov_request_set *set,
418                            struct lov_request *req, int rc)
419 {
420         struct lov_obd *lov = &req->rq_rqset->set_exp->exp_obd->u.lov;
421         struct lov_stripe_md *lsm = req->rq_rqset->set_oi->oi_md;
422
423         lov_update_set(set, req, rc);
424
425         /* grace error on inactive ost */
426         if (rc && !(lov->lov_tgts[req->rq_idx] &&
427                     lov->lov_tgts[req->rq_idx]->ltd_active))
428                 rc = 0;
429
430         if (rc == 0) {
431                 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLCTIME)
432                         lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_ctime =
433                                 req->rq_oi.oi_oa->o_ctime;
434                 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLMTIME)
435                         lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_mtime =
436                                 req->rq_oi.oi_oa->o_mtime;
437                 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLATIME)
438                         lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_atime =
439                                 req->rq_oi.oi_oa->o_atime;
440         }
441
442         return rc;
443 }
444
445 /* The callback for osc_setattr_async that finalizes a request info when a
446  * response is received. */
447 static int cb_setattr_update(void *cookie, int rc)
448 {
449         struct obd_info *oinfo = cookie;
450         struct lov_request *lovreq;
451
452         lovreq = container_of(oinfo, struct lov_request, rq_oi);
453         return lov_update_setattr_set(lovreq->rq_rqset, lovreq, rc);
454 }
455
456 int lov_prep_setattr_set(struct obd_export *exp, struct obd_info *oinfo,
457                          struct obd_trans_info *oti,
458                          struct lov_request_set **reqset)
459 {
460         struct lov_request_set *set;
461         struct lov_obd *lov = &exp->exp_obd->u.lov;
462         int rc = 0, i;
463
464         OBD_ALLOC(set, sizeof(*set));
465         if (set == NULL)
466                 return -ENOMEM;
467         lov_init_set(set);
468
469         set->set_exp = exp;
470         set->set_oti = oti;
471         set->set_oi = oinfo;
472         if (oti != NULL && oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
473                 set->set_cookies = oti->oti_logcookies;
474
475         for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
476                 struct lov_oinfo *loi = oinfo->oi_md->lsm_oinfo[i];
477                 struct lov_request *req;
478
479                 if (!lov_check_and_wait_active(lov, loi->loi_ost_idx)) {
480                         CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
481                         continue;
482                 }
483
484                 OBD_ALLOC(req, sizeof(*req));
485                 if (req == NULL)
486                         GOTO(out_set, rc = -ENOMEM);
487                 req->rq_stripe = i;
488                 req->rq_idx = loi->loi_ost_idx;
489
490                 OBDO_ALLOC(req->rq_oi.oi_oa);
491                 if (req->rq_oi.oi_oa == NULL) {
492                         OBD_FREE(req, sizeof(*req));
493                         GOTO(out_set, rc = -ENOMEM);
494                 }
495                 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
496                        sizeof(*req->rq_oi.oi_oa));
497                 req->rq_oi.oi_oa->o_oi = loi->loi_oi;
498                 req->rq_oi.oi_oa->o_stripe_idx = i;
499                 req->rq_oi.oi_cb_up = cb_setattr_update;
500                 req->rq_oi.oi_capa = oinfo->oi_capa;
501
502                 if (oinfo->oi_oa->o_valid & OBD_MD_FLSIZE) {
503                         int off = lov_stripe_offset(oinfo->oi_md,
504                                                     oinfo->oi_oa->o_size, i,
505                                                     &req->rq_oi.oi_oa->o_size);
506
507                         if (off < 0 && req->rq_oi.oi_oa->o_size)
508                                 req->rq_oi.oi_oa->o_size--;
509
510                         CDEBUG(D_INODE, "stripe %d has size %llu/%llu\n",
511                                i, req->rq_oi.oi_oa->o_size,
512                                oinfo->oi_oa->o_size);
513                 }
514                 lov_set_add_req(req, set);
515         }
516         if (!set->set_count)
517                 GOTO(out_set, rc = -EIO);
518         *reqset = set;
519         return rc;
520 out_set:
521         lov_fini_setattr_set(set);
522         return rc;
523 }
524
525 #define LOV_U64_MAX ((__u64)~0ULL)
526 #define LOV_SUM_MAX(tot, add)                                      \
527         do {                                                        \
528                 if ((tot) + (add) < (tot))                            \
529                         (tot) = LOV_U64_MAX;                        \
530                 else                                                \
531                         (tot) += (add);                          \
532         } while (0)
533
534 int lov_fini_statfs(struct obd_device *obd, struct obd_statfs *osfs,
535                     int success)
536 {
537         if (success) {
538                 __u32 expected_stripes = lov_get_stripecnt(&obd->u.lov,
539                                                            LOV_MAGIC, 0);
540                 if (osfs->os_files != LOV_U64_MAX)
541                         lov_do_div64(osfs->os_files, expected_stripes);
542                 if (osfs->os_ffree != LOV_U64_MAX)
543                         lov_do_div64(osfs->os_ffree, expected_stripes);
544
545                 spin_lock(&obd->obd_osfs_lock);
546                 memcpy(&obd->obd_osfs, osfs, sizeof(*osfs));
547                 obd->obd_osfs_age = cfs_time_current_64();
548                 spin_unlock(&obd->obd_osfs_lock);
549                 return 0;
550         }
551
552         return -EIO;
553 }
554
555 int lov_fini_statfs_set(struct lov_request_set *set)
556 {
557         int rc = 0;
558
559         if (set == NULL)
560                 return 0;
561
562         if (atomic_read(&set->set_completes)) {
563                 rc = lov_fini_statfs(set->set_obd, set->set_oi->oi_osfs,
564                                      atomic_read(&set->set_success));
565         }
566         lov_put_reqset(set);
567         return rc;
568 }
569
570 void lov_update_statfs(struct obd_statfs *osfs, struct obd_statfs *lov_sfs,
571                        int success)
572 {
573         int shift = 0, quit = 0;
574         __u64 tmp;
575
576         if (success == 0) {
577                 memcpy(osfs, lov_sfs, sizeof(*lov_sfs));
578         } else {
579                 if (osfs->os_bsize != lov_sfs->os_bsize) {
580                         /* assume all block sizes are always powers of 2 */
581                         /* get the bits difference */
582                         tmp = osfs->os_bsize | lov_sfs->os_bsize;
583                         for (shift = 0; shift <= 64; ++shift) {
584                                 if (tmp & 1) {
585                                         if (quit)
586                                                 break;
587                                         else
588                                                 quit = 1;
589                                         shift = 0;
590                                 }
591                                 tmp >>= 1;
592                         }
593                 }
594
595                 if (osfs->os_bsize < lov_sfs->os_bsize) {
596                         osfs->os_bsize = lov_sfs->os_bsize;
597
598                         osfs->os_bfree  >>= shift;
599                         osfs->os_bavail >>= shift;
600                         osfs->os_blocks >>= shift;
601                 } else if (shift != 0) {
602                         lov_sfs->os_bfree  >>= shift;
603                         lov_sfs->os_bavail >>= shift;
604                         lov_sfs->os_blocks >>= shift;
605                 }
606                 osfs->os_bfree += lov_sfs->os_bfree;
607                 osfs->os_bavail += lov_sfs->os_bavail;
608                 osfs->os_blocks += lov_sfs->os_blocks;
609                 /* XXX not sure about this one - depends on policy.
610                  *   - could be minimum if we always stripe on all OBDs
611                  *     (but that would be wrong for any other policy,
612                  *     if one of the OBDs has no more objects left)
613                  *   - could be sum if we stripe whole objects
614                  *   - could be average, just to give a nice number
615                  *
616                  * To give a "reasonable" (if not wholly accurate)
617                  * number, we divide the total number of free objects
618                  * by expected stripe count (watch out for overflow).
619                  */
620                 LOV_SUM_MAX(osfs->os_files, lov_sfs->os_files);
621                 LOV_SUM_MAX(osfs->os_ffree, lov_sfs->os_ffree);
622         }
623 }
624
625 /* The callback for osc_statfs_async that finalizes a request info when a
626  * response is received. */
627 static int cb_statfs_update(void *cookie, int rc)
628 {
629         struct obd_info *oinfo = cookie;
630         struct lov_request *lovreq;
631         struct lov_request_set *set;
632         struct obd_statfs *osfs, *lov_sfs;
633         struct lov_obd *lov;
634         struct lov_tgt_desc *tgt;
635         struct obd_device *lovobd, *tgtobd;
636         int success;
637
638         lovreq = container_of(oinfo, struct lov_request, rq_oi);
639         set = lovreq->rq_rqset;
640         lovobd = set->set_obd;
641         lov = &lovobd->u.lov;
642         osfs = set->set_oi->oi_osfs;
643         lov_sfs = oinfo->oi_osfs;
644         success = atomic_read(&set->set_success);
645         /* XXX: the same is done in lov_update_common_set, however
646            lovset->set_exp is not initialized. */
647         lov_update_set(set, lovreq, rc);
648         if (rc)
649                 GOTO(out, rc);
650
651         obd_getref(lovobd);
652         tgt = lov->lov_tgts[lovreq->rq_idx];
653         if (!tgt || !tgt->ltd_active)
654                 GOTO(out_update, rc);
655
656         tgtobd = class_exp2obd(tgt->ltd_exp);
657         spin_lock(&tgtobd->obd_osfs_lock);
658         memcpy(&tgtobd->obd_osfs, lov_sfs, sizeof(*lov_sfs));
659         if ((oinfo->oi_flags & OBD_STATFS_FROM_CACHE) == 0)
660                 tgtobd->obd_osfs_age = cfs_time_current_64();
661         spin_unlock(&tgtobd->obd_osfs_lock);
662
663 out_update:
664         lov_update_statfs(osfs, lov_sfs, success);
665         obd_putref(lovobd);
666
667 out:
668         if (set->set_oi->oi_flags & OBD_STATFS_PTLRPCD &&
669             lov_set_finished(set, 0)) {
670                 lov_statfs_interpret(NULL, set, set->set_count !=
671                                      atomic_read(&set->set_success));
672         }
673
674         return 0;
675 }
676
677 int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
678                         struct lov_request_set **reqset)
679 {
680         struct lov_request_set *set;
681         struct lov_obd *lov = &obd->u.lov;
682         int rc = 0, i;
683
684         OBD_ALLOC(set, sizeof(*set));
685         if (set == NULL)
686                 return -ENOMEM;
687         lov_init_set(set);
688
689         set->set_obd = obd;
690         set->set_oi = oinfo;
691
692         /* We only get block data from the OBD */
693         for (i = 0; i < lov->desc.ld_tgt_count; i++) {
694                 struct lov_request *req;
695
696                 if (lov->lov_tgts[i] == NULL ||
697                     (!lov_check_and_wait_active(lov, i) &&
698                      (oinfo->oi_flags & OBD_STATFS_NODELAY))) {
699                         CDEBUG(D_HA, "lov idx %d inactive\n", i);
700                         continue;
701                 }
702
703                 /* skip targets that have been explicitly disabled by the
704                  * administrator */
705                 if (!lov->lov_tgts[i]->ltd_exp) {
706                         CDEBUG(D_HA, "lov idx %d administratively disabled\n", i);
707                         continue;
708                 }
709
710                 OBD_ALLOC(req, sizeof(*req));
711                 if (req == NULL)
712                         GOTO(out_set, rc = -ENOMEM);
713
714                 OBD_ALLOC(req->rq_oi.oi_osfs, sizeof(*req->rq_oi.oi_osfs));
715                 if (req->rq_oi.oi_osfs == NULL) {
716                         OBD_FREE(req, sizeof(*req));
717                         GOTO(out_set, rc = -ENOMEM);
718                 }
719
720                 req->rq_idx = i;
721                 req->rq_oi.oi_cb_up = cb_statfs_update;
722                 req->rq_oi.oi_flags = oinfo->oi_flags;
723
724                 lov_set_add_req(req, set);
725         }
726         if (!set->set_count)
727                 GOTO(out_set, rc = -EIO);
728         *reqset = set;
729         return rc;
730 out_set:
731         lov_fini_statfs_set(set);
732         return rc;
733 }