Whamcloud - gitweb
LU-2675 lov: remove unused lov obd functions
[fs/lustre-release.git] / 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, 2013, 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 #ifdef __KERNEL__
40 #include <libcfs/libcfs.h>
41 #else
42 #include <liblustre.h>
43 #endif
44
45 #include <obd_class.h>
46 #include <obd_lov.h>
47 #include <obd_ost.h>
48 #include <lustre/lustre_idl.h>
49
50 #include "lov_internal.h"
51
52 static void lov_init_set(struct lov_request_set *set)
53 {
54         set->set_count = 0;
55         cfs_atomic_set(&set->set_completes, 0);
56         cfs_atomic_set(&set->set_success, 0);
57         cfs_atomic_set(&set->set_finish_checked, 0);
58         set->set_cookies = 0;
59         CFS_INIT_LIST_HEAD(&set->set_list);
60         cfs_atomic_set(&set->set_refcount, 1);
61         init_waitqueue_head(&set->set_waitq);
62 }
63
64 void lov_finish_set(struct lov_request_set *set)
65 {
66         struct list_head *pos, *n;
67         struct lov_request *req;
68         ENTRY;
69
70         LASSERT(set != NULL);
71         list_for_each_safe(pos, n, &set->set_list) {
72                 req = list_entry(pos, struct lov_request, rq_link);
73                 list_del_init(&req->rq_link);
74
75                 if (req->rq_oi.oi_oa != NULL)
76                         OBDO_FREE(req->rq_oi.oi_oa);
77
78                 if (req->rq_oi.oi_osfs != NULL)
79                         OBD_FREE_PTR(req->rq_oi.oi_osfs);
80
81                 OBD_FREE_PTR(req);
82         }
83
84         OBD_FREE_PTR(set);
85         EXIT;
86 }
87
88 int lov_set_finished(struct lov_request_set *set, int idempotent)
89 {
90         int completes = cfs_atomic_read(&set->set_completes);
91
92         CDEBUG(D_INFO, "check set %d/%d\n", completes, set->set_count);
93
94         if (completes == set->set_count) {
95                 if (idempotent)
96                         return 1;
97                 if (cfs_atomic_inc_return(&set->set_finish_checked) == 1)
98                         return 1;
99         }
100         return 0;
101 }
102
103 void lov_update_set(struct lov_request_set *set,
104                     struct lov_request *req, int rc)
105 {
106         req->rq_complete = 1;
107         req->rq_rc = rc;
108
109         cfs_atomic_inc(&set->set_completes);
110         if (rc == 0)
111                 cfs_atomic_inc(&set->set_success);
112
113         wake_up(&set->set_waitq);
114 }
115
116 int lov_update_common_set(struct lov_request_set *set,
117                           struct lov_request *req, int rc)
118 {
119         struct lov_obd *lov = &set->set_exp->exp_obd->u.lov;
120         ENTRY;
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         cfs_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 = 0;
143         mutex_lock(&lov->lov_lock);
144
145         if (lov->lov_tgts[idx] == NULL ||
146             lov->lov_tgts[idx]->ltd_active ||
147             (lov->lov_tgts[idx]->ltd_exp != NULL &&
148              class_exp2cliimp(lov->lov_tgts[idx]->ltd_exp)->imp_connect_tried))
149                 rc = 1;
150
151         mutex_unlock(&lov->lov_lock);
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->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         cfs_list_t *pos;
199         struct lov_request *req;
200         struct obdo *tmp_oa;
201         int rc = 0, attrset = 0;
202         ENTRY;
203
204         LASSERT(set->set_oi != NULL);
205
206         if (set->set_oi->oi_oa == NULL)
207                 RETURN(0);
208
209         if (!cfs_atomic_read(&set->set_success))
210                 RETURN(-EIO);
211
212         OBDO_ALLOC(tmp_oa);
213         if (tmp_oa == NULL)
214                 GOTO(out, rc = -ENOMEM);
215
216         cfs_list_for_each (pos, &set->set_list) {
217                 req = cfs_list_entry(pos, struct lov_request, rq_link);
218
219                 if (!req->rq_complete || req->rq_rc)
220                         continue;
221                 if (req->rq_oi.oi_oa->o_valid == 0)   /* inactive stripe */
222                         continue;
223                 lov_merge_attrs(tmp_oa, req->rq_oi.oi_oa,
224                                 req->rq_oi.oi_oa->o_valid,
225                                 set->set_oi->oi_md, req->rq_stripe, &attrset);
226         }
227         if (!attrset) {
228                 CERROR("No stripes had valid attrs\n");
229                 rc = -EIO;
230         }
231         if ((set->set_oi->oi_oa->o_valid & OBD_MD_FLEPOCH) &&
232             (set->set_oi->oi_md->lsm_stripe_count != attrset)) {
233                 /* When we take attributes of some epoch, we require all the
234                  * ost to be active. */
235                 CERROR("Not all the stripes had valid attrs\n");
236                 GOTO(out, rc = -EIO);
237         }
238
239         tmp_oa->o_oi = set->set_oi->oi_oa->o_oi;
240         memcpy(set->set_oi->oi_oa, tmp_oa, sizeof(*set->set_oi->oi_oa));
241 out:
242         if (tmp_oa)
243                 OBDO_FREE(tmp_oa);
244         RETURN(rc);
245
246 }
247
248 int lov_fini_getattr_set(struct lov_request_set *set)
249 {
250         int rc = 0;
251         ENTRY;
252
253         if (set == NULL)
254                 RETURN(0);
255         LASSERT(set->set_exp);
256         if (cfs_atomic_read(&set->set_completes))
257                 rc = common_attr_done(set);
258
259         lov_put_reqset(set);
260
261         RETURN(rc);
262 }
263
264 /* The callback for osc_getattr_async that finilizes a request info when a
265  * response is received. */
266 static int cb_getattr_update(void *cookie, int rc)
267 {
268         struct obd_info *oinfo = cookie;
269         struct lov_request *lovreq;
270         lovreq = container_of(oinfo, struct lov_request, rq_oi);
271         return lov_update_common_set(lovreq->rq_rqset, lovreq, rc);
272 }
273
274 int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo,
275                          struct lov_request_set **reqset)
276 {
277         struct lov_request_set *set;
278         struct lov_obd *lov = &exp->exp_obd->u.lov;
279         int rc = 0, i;
280         ENTRY;
281
282         OBD_ALLOC(set, sizeof(*set));
283         if (set == NULL)
284                 RETURN(-ENOMEM);
285         lov_init_set(set);
286
287         set->set_exp = exp;
288         set->set_oi = oinfo;
289
290         for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
291                 struct lov_oinfo *loi;
292                 struct lov_request *req;
293
294                 loi = oinfo->oi_md->lsm_oinfo[i];
295                 if (!lov_check_and_wait_active(lov, loi->loi_ost_idx)) {
296                         CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
297                         if (oinfo->oi_oa->o_valid & OBD_MD_FLEPOCH)
298                                 /* SOM requires all the OSTs to be active. */
299                                 GOTO(out_set, rc = -EIO);
300                         continue;
301                 }
302
303                 OBD_ALLOC(req, sizeof(*req));
304                 if (req == NULL)
305                         GOTO(out_set, rc = -ENOMEM);
306
307                 req->rq_stripe = i;
308                 req->rq_idx = loi->loi_ost_idx;
309
310                 OBDO_ALLOC(req->rq_oi.oi_oa);
311                 if (req->rq_oi.oi_oa == NULL) {
312                         OBD_FREE(req, sizeof(*req));
313                         GOTO(out_set, rc = -ENOMEM);
314                 }
315                 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
316                        sizeof(*req->rq_oi.oi_oa));
317                 req->rq_oi.oi_oa->o_oi = loi->loi_oi;
318                 req->rq_oi.oi_cb_up = cb_getattr_update;
319                 req->rq_oi.oi_capa = oinfo->oi_capa;
320
321                 lov_set_add_req(req, set);
322         }
323         if (!set->set_count)
324                 GOTO(out_set, rc = -EIO);
325         *reqset = set;
326         RETURN(rc);
327 out_set:
328         lov_fini_getattr_set(set);
329         RETURN(rc);
330 }
331
332 int lov_fini_destroy_set(struct lov_request_set *set)
333 {
334         ENTRY;
335
336         if (set == NULL)
337                 RETURN(0);
338         LASSERT(set->set_exp);
339         if (cfs_atomic_read(&set->set_completes)) {
340                 /* FIXME update qos data here */
341         }
342
343         lov_put_reqset(set);
344
345         RETURN(0);
346 }
347
348 int lov_prep_destroy_set(struct obd_export *exp, struct obd_info *oinfo,
349                          struct obdo *src_oa, struct lov_stripe_md *lsm,
350                          struct obd_trans_info *oti,
351                          struct lov_request_set **reqset)
352 {
353         struct lov_request_set *set;
354         struct lov_obd *lov = &exp->exp_obd->u.lov;
355         int rc = 0, i;
356         ENTRY;
357
358         OBD_ALLOC(set, sizeof(*set));
359         if (set == NULL)
360                 RETURN(-ENOMEM);
361         lov_init_set(set);
362
363         set->set_exp = exp;
364         set->set_oi = oinfo;
365         set->set_oi->oi_md = lsm;
366         set->set_oi->oi_oa = src_oa;
367         if (oti != NULL && src_oa->o_valid & OBD_MD_FLCOOKIE)
368                 set->set_cookies = oti->oti_logcookies;
369
370         for (i = 0; i < lsm->lsm_stripe_count; i++) {
371                 struct lov_oinfo *loi;
372                 struct lov_request *req;
373
374                 loi = lsm->lsm_oinfo[i];
375                 if (!lov_check_and_wait_active(lov, loi->loi_ost_idx)) {
376                         CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
377                         continue;
378                 }
379
380                 OBD_ALLOC(req, sizeof(*req));
381                 if (req == NULL)
382                         GOTO(out_set, rc = -ENOMEM);
383
384                 req->rq_stripe = i;
385                 req->rq_idx = loi->loi_ost_idx;
386
387                 OBDO_ALLOC(req->rq_oi.oi_oa);
388                 if (req->rq_oi.oi_oa == NULL) {
389                         OBD_FREE(req, sizeof(*req));
390                         GOTO(out_set, rc = -ENOMEM);
391                 }
392                 memcpy(req->rq_oi.oi_oa, src_oa, sizeof(*req->rq_oi.oi_oa));
393                 req->rq_oi.oi_oa->o_oi = loi->loi_oi;
394                 lov_set_add_req(req, set);
395         }
396         if (!set->set_count)
397                 GOTO(out_set, rc = -EIO);
398         *reqset = set;
399         RETURN(rc);
400 out_set:
401         lov_fini_destroy_set(set);
402         RETURN(rc);
403 }
404
405 int lov_fini_setattr_set(struct lov_request_set *set)
406 {
407         int rc = 0;
408         ENTRY;
409
410         if (set == NULL)
411                 RETURN(0);
412         LASSERT(set->set_exp);
413         if (cfs_atomic_read(&set->set_completes)) {
414                 rc = common_attr_done(set);
415                 /* FIXME update qos data here */
416         }
417
418         lov_put_reqset(set);
419         RETURN(rc);
420 }
421
422 int lov_update_setattr_set(struct lov_request_set *set,
423                            struct lov_request *req, int rc)
424 {
425         struct lov_obd *lov = &req->rq_rqset->set_exp->exp_obd->u.lov;
426         struct lov_stripe_md *lsm = req->rq_rqset->set_oi->oi_md;
427         ENTRY;
428
429         lov_update_set(set, req, rc);
430
431         /* grace error on inactive ost */
432         if (rc && !(lov->lov_tgts[req->rq_idx] &&
433                     lov->lov_tgts[req->rq_idx]->ltd_active))
434                 rc = 0;
435
436         if (rc == 0) {
437                 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLCTIME)
438                         lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_ctime =
439                                 req->rq_oi.oi_oa->o_ctime;
440                 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLMTIME)
441                         lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_mtime =
442                                 req->rq_oi.oi_oa->o_mtime;
443                 if (req->rq_oi.oi_oa->o_valid & OBD_MD_FLATIME)
444                         lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_atime =
445                                 req->rq_oi.oi_oa->o_atime;
446         }
447
448         RETURN(rc);
449 }
450
451 /* The callback for osc_setattr_async that finilizes a request info when a
452  * response is received. */
453 static int cb_setattr_update(void *cookie, int rc)
454 {
455         struct obd_info *oinfo = cookie;
456         struct lov_request *lovreq;
457         lovreq = container_of(oinfo, struct lov_request, rq_oi);
458         return lov_update_setattr_set(lovreq->rq_rqset, lovreq, rc);
459 }
460
461 int lov_prep_setattr_set(struct obd_export *exp, struct obd_info *oinfo,
462                          struct obd_trans_info *oti,
463                          struct lov_request_set **reqset)
464 {
465         struct lov_request_set *set;
466         struct lov_obd *lov = &exp->exp_obd->u.lov;
467         int rc = 0, i;
468         ENTRY;
469
470         OBD_ALLOC(set, sizeof(*set));
471         if (set == NULL)
472                 RETURN(-ENOMEM);
473         lov_init_set(set);
474
475         set->set_exp = exp;
476         set->set_oi = oinfo;
477         if (oti != NULL && oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
478                 set->set_cookies = oti->oti_logcookies;
479
480         for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
481                 struct lov_oinfo *loi = oinfo->oi_md->lsm_oinfo[i];
482                 struct lov_request *req;
483
484                 if (!lov_check_and_wait_active(lov, loi->loi_ost_idx)) {
485                         CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
486                         continue;
487                 }
488
489                 OBD_ALLOC(req, sizeof(*req));
490                 if (req == NULL)
491                         GOTO(out_set, rc = -ENOMEM);
492                 req->rq_stripe = i;
493                 req->rq_idx = loi->loi_ost_idx;
494
495                 OBDO_ALLOC(req->rq_oi.oi_oa);
496                 if (req->rq_oi.oi_oa == NULL) {
497                         OBD_FREE(req, sizeof(*req));
498                         GOTO(out_set, rc = -ENOMEM);
499                 }
500                 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
501                        sizeof(*req->rq_oi.oi_oa));
502                 req->rq_oi.oi_oa->o_oi = loi->loi_oi;
503                 req->rq_oi.oi_oa->o_stripe_idx = i;
504                 req->rq_oi.oi_cb_up = cb_setattr_update;
505                 req->rq_oi.oi_capa = oinfo->oi_capa;
506
507                 if (oinfo->oi_oa->o_valid & OBD_MD_FLSIZE) {
508                         int off = lov_stripe_offset(oinfo->oi_md,
509                                                     oinfo->oi_oa->o_size, i,
510                                                     &req->rq_oi.oi_oa->o_size);
511
512                         if (off < 0 && req->rq_oi.oi_oa->o_size)
513                                 req->rq_oi.oi_oa->o_size--;
514
515                         CDEBUG(D_INODE, "stripe %d has size "LPU64"/"LPU64"\n",
516                                i, req->rq_oi.oi_oa->o_size,
517                                oinfo->oi_oa->o_size);
518                 }
519                 lov_set_add_req(req, set);
520         }
521         if (!set->set_count)
522                 GOTO(out_set, rc = -EIO);
523         *reqset = set;
524         RETURN(rc);
525 out_set:
526         lov_fini_setattr_set(set);
527         RETURN(rc);
528 }
529
530 #define LOV_U64_MAX ((__u64)~0ULL)
531 #define LOV_SUM_MAX(tot, add)                                           \
532         do {                                                            \
533                 if ((tot) + (add) < (tot))                              \
534                         (tot) = LOV_U64_MAX;                            \
535                 else                                                    \
536                         (tot) += (add);                                 \
537         } while(0)
538
539 int lov_fini_statfs(struct obd_device *obd, struct obd_statfs *osfs,int success)
540 {
541         ENTRY;
542
543         if (success) {
544                 __u32 expected_stripes = lov_get_stripecnt(&obd->u.lov,
545                                                            LOV_MAGIC, 0);
546                 if (osfs->os_files != LOV_U64_MAX)
547                         lov_do_div64(osfs->os_files, expected_stripes);
548                 if (osfs->os_ffree != LOV_U64_MAX)
549                         lov_do_div64(osfs->os_ffree, expected_stripes);
550
551                 spin_lock(&obd->obd_osfs_lock);
552                 memcpy(&obd->obd_osfs, osfs, sizeof(*osfs));
553                 obd->obd_osfs_age = cfs_time_current_64();
554                 spin_unlock(&obd->obd_osfs_lock);
555                 RETURN(0);
556         }
557
558         RETURN(-EIO);
559 }
560
561 int lov_fini_statfs_set(struct lov_request_set *set)
562 {
563         int rc = 0;
564         ENTRY;
565
566         if (set == NULL)
567                 RETURN(0);
568
569         if (cfs_atomic_read(&set->set_completes)) {
570                 rc = lov_fini_statfs(set->set_obd, set->set_oi->oi_osfs,
571                                      cfs_atomic_read(&set->set_success));
572         }
573         lov_put_reqset(set);
574         RETURN(rc);
575 }
576
577 void lov_update_statfs(struct obd_statfs *osfs, struct obd_statfs *lov_sfs,
578                        int success)
579 {
580         int shift = 0, quit = 0;
581         __u64 tmp;
582
583         if (success == 0) {
584                 memcpy(osfs, lov_sfs, sizeof(*lov_sfs));
585         } else {
586                 if (osfs->os_bsize != lov_sfs->os_bsize) {
587                         /* assume all block sizes are always powers of 2 */
588                         /* get the bits difference */
589                         tmp = osfs->os_bsize | lov_sfs->os_bsize;
590                         for (shift = 0; shift <= 64; ++shift) {
591                                 if (tmp & 1) {
592                                         if (quit)
593                                                 break;
594                                         else
595                                                 quit = 1;
596                                         shift = 0;
597                                 }
598                                 tmp >>= 1;
599                         }
600                 }
601
602                 if (osfs->os_bsize < lov_sfs->os_bsize) {
603                         osfs->os_bsize = lov_sfs->os_bsize;
604
605                         osfs->os_bfree  >>= shift;
606                         osfs->os_bavail >>= shift;
607                         osfs->os_blocks >>= shift;
608                 } else if (shift != 0) {
609                         lov_sfs->os_bfree  >>= shift;
610                         lov_sfs->os_bavail >>= shift;
611                         lov_sfs->os_blocks >>= shift;
612                 }
613 #ifdef MIN_DF
614                 /* Sandia requested that df (and so, statfs) only
615                    returned minimal available space on
616                    a single OST, so people would be able to
617                    write this much data guaranteed. */
618                 if (osfs->os_bavail > lov_sfs->os_bavail) {
619                         /* Presumably if new bavail is smaller,
620                            new bfree is bigger as well */
621                         osfs->os_bfree = lov_sfs->os_bfree;
622                         osfs->os_bavail = lov_sfs->os_bavail;
623                 }
624 #else
625                 osfs->os_bfree += lov_sfs->os_bfree;
626                 osfs->os_bavail += lov_sfs->os_bavail;
627 #endif
628                 osfs->os_blocks += lov_sfs->os_blocks;
629                 /* XXX not sure about this one - depends on policy.
630                  *   - could be minimum if we always stripe on all OBDs
631                  *     (but that would be wrong for any other policy,
632                  *     if one of the OBDs has no more objects left)
633                  *   - could be sum if we stripe whole objects
634                  *   - could be average, just to give a nice number
635                  *
636                  * To give a "reasonable" (if not wholly accurate)
637                  * number, we divide the total number of free objects
638                  * by expected stripe count (watch out for overflow).
639                  */
640                 LOV_SUM_MAX(osfs->os_files, lov_sfs->os_files);
641                 LOV_SUM_MAX(osfs->os_ffree, lov_sfs->os_ffree);
642         }
643 }
644
645 /* The callback for osc_statfs_async that finilizes a request info when a
646  * response is received. */
647 static int cb_statfs_update(void *cookie, int rc)
648 {
649         struct obd_info *oinfo = cookie;
650         struct lov_request *lovreq;
651         struct lov_request_set *set;
652         struct obd_statfs *osfs, *lov_sfs;
653         struct lov_obd *lov;
654         struct lov_tgt_desc *tgt;
655         struct obd_device *lovobd, *tgtobd;
656         int success;
657         ENTRY;
658
659         lovreq = container_of(oinfo, struct lov_request, rq_oi);
660         set = lovreq->rq_rqset;
661         lovobd = set->set_obd;
662         lov = &lovobd->u.lov;
663         osfs = set->set_oi->oi_osfs;
664         lov_sfs = oinfo->oi_osfs;
665         success = cfs_atomic_read(&set->set_success);
666         /* XXX: the same is done in lov_update_common_set, however
667            lovset->set_exp is not initialized. */
668         lov_update_set(set, lovreq, rc);
669         if (rc)
670                 GOTO(out, rc);
671
672         obd_getref(lovobd);
673         tgt = lov->lov_tgts[lovreq->rq_idx];
674         if (!tgt || !tgt->ltd_active)
675                 GOTO(out_update, rc);
676
677         tgtobd = class_exp2obd(tgt->ltd_exp);
678         spin_lock(&tgtobd->obd_osfs_lock);
679         memcpy(&tgtobd->obd_osfs, lov_sfs, sizeof(*lov_sfs));
680         if ((oinfo->oi_flags & OBD_STATFS_FROM_CACHE) == 0)
681                 tgtobd->obd_osfs_age = cfs_time_current_64();
682         spin_unlock(&tgtobd->obd_osfs_lock);
683
684 out_update:
685         lov_update_statfs(osfs, lov_sfs, success);
686         obd_putref(lovobd);
687
688 out:
689         if (set->set_oi->oi_flags & OBD_STATFS_PTLRPCD &&
690             lov_set_finished(set, 0)) {
691                 lov_statfs_interpret(NULL, set, set->set_count !=
692                                      cfs_atomic_read(&set->set_success));
693         }
694
695         RETURN(0);
696 }
697
698 int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
699                         struct lov_request_set **reqset)
700 {
701         struct lov_request_set *set;
702         struct lov_obd *lov = &obd->u.lov;
703         int rc = 0, i;
704         ENTRY;
705
706         OBD_ALLOC(set, sizeof(*set));
707         if (set == NULL)
708                 RETURN(-ENOMEM);
709         lov_init_set(set);
710
711         set->set_obd = obd;
712         set->set_oi = oinfo;
713
714         /* We only get block data from the OBD */
715         for (i = 0; i < lov->desc.ld_tgt_count; i++) {
716                 struct lov_request *req;
717
718                 if (lov->lov_tgts[i] == NULL ||
719                     (oinfo->oi_flags & OBD_STATFS_NODELAY &&
720                      !lov->lov_tgts[i]->ltd_active)) {
721                         CDEBUG(D_HA, "lov idx %d inactive\n", i);
722                         continue;
723                 }
724
725                 if (!lov->lov_tgts[i]->ltd_active)
726                         lov_check_and_wait_active(lov, i);
727
728                 /* skip targets that have been explicitely disabled by the
729                  * administrator */
730                 if (!lov->lov_tgts[i]->ltd_exp) {
731                         CDEBUG(D_HA, "lov idx %d administratively disabled\n", i);
732                         continue;
733                 }
734
735                 OBD_ALLOC(req, sizeof(*req));
736                 if (req == NULL)
737                         GOTO(out_set, rc = -ENOMEM);
738
739                 OBD_ALLOC(req->rq_oi.oi_osfs, sizeof(*req->rq_oi.oi_osfs));
740                 if (req->rq_oi.oi_osfs == NULL) {
741                         OBD_FREE(req, sizeof(*req));
742                         GOTO(out_set, rc = -ENOMEM);
743                 }
744
745                 req->rq_idx = i;
746                 req->rq_oi.oi_cb_up = cb_statfs_update;
747                 req->rq_oi.oi_flags = oinfo->oi_flags;
748
749                 lov_set_add_req(req, set);
750         }
751         if (!set->set_count)
752                 GOTO(out_set, rc = -EIO);
753         *reqset = set;
754         RETURN(rc);
755 out_set:
756         lov_fini_statfs_set(set);
757         RETURN(rc);
758 }