Whamcloud - gitweb
LU-5624 tests: ignore bad lfsck performance for ZFS backend
[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 #include <libcfs/libcfs.h>
40
41 #include <obd_class.h>
42 #include <lustre/lustre_idl.h>
43
44 #include "lov_internal.h"
45
46 static void lov_init_set(struct lov_request_set *set)
47 {
48         set->set_count = 0;
49         atomic_set(&set->set_completes, 0);
50         atomic_set(&set->set_success, 0);
51         atomic_set(&set->set_finish_checked, 0);
52         set->set_cookies = 0;
53         INIT_LIST_HEAD(&set->set_list);
54         atomic_set(&set->set_refcount, 1);
55         init_waitqueue_head(&set->set_waitq);
56 }
57
58 void lov_finish_set(struct lov_request_set *set)
59 {
60         struct list_head *pos, *n;
61         struct lov_request *req;
62         ENTRY;
63
64         LASSERT(set != NULL);
65         list_for_each_safe(pos, n, &set->set_list) {
66                 req = list_entry(pos, struct lov_request, rq_link);
67                 list_del_init(&req->rq_link);
68
69                 if (req->rq_oi.oi_oa != NULL)
70                         OBDO_FREE(req->rq_oi.oi_oa);
71
72                 if (req->rq_oi.oi_osfs != NULL)
73                         OBD_FREE_PTR(req->rq_oi.oi_osfs);
74
75                 OBD_FREE_PTR(req);
76         }
77
78         OBD_FREE_PTR(set);
79         EXIT;
80 }
81
82 int lov_set_finished(struct lov_request_set *set, int idempotent)
83 {
84         int completes = atomic_read(&set->set_completes);
85
86         CDEBUG(D_INFO, "check set %d/%d\n", completes, set->set_count);
87
88         if (completes == set->set_count) {
89                 if (idempotent)
90                         return 1;
91                 if (atomic_inc_return(&set->set_finish_checked) == 1)
92                         return 1;
93         }
94         return 0;
95 }
96
97 void lov_update_set(struct lov_request_set *set,
98                     struct lov_request *req, int rc)
99 {
100         req->rq_complete = 1;
101         req->rq_rc = rc;
102
103         atomic_inc(&set->set_completes);
104         if (rc == 0)
105                 atomic_inc(&set->set_success);
106
107         wake_up(&set->set_waitq);
108 }
109
110 int lov_update_common_set(struct lov_request_set *set,
111                           struct lov_request *req, int rc)
112 {
113         struct lov_obd *lov = &set->set_exp->exp_obd->u.lov;
114         ENTRY;
115
116         lov_update_set(set, req, rc);
117
118         /* grace error on inactive ost */
119         if (rc && !(lov->lov_tgts[req->rq_idx] &&
120                     lov->lov_tgts[req->rq_idx]->ltd_active))
121                 rc = 0;
122
123         /* FIXME in raid1 regime, should return 0 */
124         RETURN(rc);
125 }
126
127 void lov_set_add_req(struct lov_request *req, struct lov_request_set *set)
128 {
129         list_add_tail(&req->rq_link, &set->set_list);
130         set->set_count++;
131         req->rq_rqset = set;
132 }
133
134 static int lov_check_set(struct lov_obd *lov, int idx)
135 {
136         int rc = 0;
137         mutex_lock(&lov->lov_lock);
138
139         if (lov->lov_tgts[idx] == NULL ||
140             lov->lov_tgts[idx]->ltd_active ||
141             (lov->lov_tgts[idx]->ltd_exp != NULL &&
142              class_exp2cliimp(lov->lov_tgts[idx]->ltd_exp)->imp_connect_tried))
143                 rc = 1;
144
145         mutex_unlock(&lov->lov_lock);
146         return rc;
147 }
148
149 /* Check if the OSC connection exists and is active.
150  * If the OSC has not yet had a chance to connect to the OST the first time,
151  * wait once for it to connect instead of returning an error.
152  */
153 int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx)
154 {
155         wait_queue_head_t waitq;
156         struct l_wait_info lwi;
157         struct lov_tgt_desc *tgt;
158         int rc = 0;
159
160         mutex_lock(&lov->lov_lock);
161
162         tgt = lov->lov_tgts[ost_idx];
163
164         if (unlikely(tgt == NULL))
165                 GOTO(out, rc = 0);
166
167         if (likely(tgt->ltd_active))
168                 GOTO(out, rc = 1);
169
170         if (tgt->ltd_exp && class_exp2cliimp(tgt->ltd_exp)->imp_connect_tried)
171                 GOTO(out, rc = 0);
172
173         mutex_unlock(&lov->lov_lock);
174
175         init_waitqueue_head(&waitq);
176         lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(obd_timeout),
177                                    cfs_time_seconds(1), NULL, NULL);
178
179         rc = l_wait_event(waitq, lov_check_set(lov, ost_idx), &lwi);
180         if (tgt->ltd_active)
181                 return 1;
182
183         return 0;
184
185 out:
186         mutex_unlock(&lov->lov_lock);
187         return rc;
188 }
189
190 static int common_attr_done(struct lov_request_set *set)
191 {
192         struct list_head *pos;
193         struct lov_request *req;
194         struct obdo *tmp_oa;
195         int rc = 0, attrset = 0;
196         ENTRY;
197
198         LASSERT(set->set_oi != NULL);
199
200         if (set->set_oi->oi_oa == NULL)
201                 RETURN(0);
202
203         if (!atomic_read(&set->set_success))
204                 RETURN(-EIO);
205
206         OBDO_ALLOC(tmp_oa);
207         if (tmp_oa == NULL)
208                 GOTO(out, rc = -ENOMEM);
209
210         list_for_each(pos, &set->set_list) {
211                 req = list_entry(pos, struct lov_request, rq_link);
212
213                 if (!req->rq_complete || req->rq_rc)
214                         continue;
215                 if (req->rq_oi.oi_oa->o_valid == 0)   /* inactive stripe */
216                         continue;
217                 lov_merge_attrs(tmp_oa, req->rq_oi.oi_oa,
218                                 req->rq_oi.oi_oa->o_valid,
219                                 set->set_oi->oi_md, req->rq_stripe, &attrset);
220         }
221         if (!attrset) {
222                 CERROR("No stripes had valid attrs\n");
223                 rc = -EIO;
224         }
225         if ((set->set_oi->oi_oa->o_valid & OBD_MD_FLEPOCH) &&
226             (set->set_oi->oi_md->lsm_stripe_count != attrset)) {
227                 /* When we take attributes of some epoch, we require all the
228                  * ost to be active. */
229                 CERROR("Not all the stripes had valid attrs\n");
230                 GOTO(out, rc = -EIO);
231         }
232
233         tmp_oa->o_oi = set->set_oi->oi_oa->o_oi;
234         memcpy(set->set_oi->oi_oa, tmp_oa, sizeof(*set->set_oi->oi_oa));
235 out:
236         if (tmp_oa)
237                 OBDO_FREE(tmp_oa);
238         RETURN(rc);
239
240 }
241
242 int lov_fini_getattr_set(struct lov_request_set *set)
243 {
244         int rc = 0;
245         ENTRY;
246
247         if (set == NULL)
248                 RETURN(0);
249         LASSERT(set->set_exp);
250         if (atomic_read(&set->set_completes))
251                 rc = common_attr_done(set);
252
253         lov_put_reqset(set);
254
255         RETURN(rc);
256 }
257
258 /* The callback for osc_getattr_async that finilizes a request info when a
259  * response is received. */
260 static int cb_getattr_update(void *cookie, int rc)
261 {
262         struct obd_info *oinfo = cookie;
263         struct lov_request *lovreq;
264         lovreq = container_of(oinfo, struct lov_request, rq_oi);
265         return lov_update_common_set(lovreq->rq_rqset, lovreq, rc);
266 }
267
268 int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo,
269                          struct lov_request_set **reqset)
270 {
271         struct lov_request_set *set;
272         struct lov_obd *lov = &exp->exp_obd->u.lov;
273         int rc = 0, i;
274         ENTRY;
275
276         OBD_ALLOC(set, sizeof(*set));
277         if (set == NULL)
278                 RETURN(-ENOMEM);
279         lov_init_set(set);
280
281         set->set_exp = exp;
282         set->set_oi = oinfo;
283
284         for (i = 0; i < oinfo->oi_md->lsm_stripe_count; i++) {
285                 struct lov_oinfo *loi;
286                 struct lov_request *req;
287
288                 loi = oinfo->oi_md->lsm_oinfo[i];
289                 if (lov_oinfo_is_dummy(loi))
290                         continue;
291
292                 if (!lov_check_and_wait_active(lov, loi->loi_ost_idx)) {
293                         CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
294                         if (oinfo->oi_oa->o_valid & OBD_MD_FLEPOCH)
295                                 /* SOM requires all the OSTs to be active. */
296                                 GOTO(out_set, rc = -EIO);
297                         continue;
298                 }
299
300                 OBD_ALLOC(req, sizeof(*req));
301                 if (req == NULL)
302                         GOTO(out_set, rc = -ENOMEM);
303
304                 req->rq_stripe = i;
305                 req->rq_idx = loi->loi_ost_idx;
306
307                 OBDO_ALLOC(req->rq_oi.oi_oa);
308                 if (req->rq_oi.oi_oa == NULL) {
309                         OBD_FREE(req, sizeof(*req));
310                         GOTO(out_set, rc = -ENOMEM);
311                 }
312                 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
313                        sizeof(*req->rq_oi.oi_oa));
314                 req->rq_oi.oi_oa->o_oi = loi->loi_oi;
315                 req->rq_oi.oi_cb_up = cb_getattr_update;
316                 req->rq_oi.oi_capa = oinfo->oi_capa;
317
318                 lov_set_add_req(req, set);
319         }
320         if (!set->set_count)
321                 GOTO(out_set, rc = -EIO);
322         *reqset = set;
323         RETURN(rc);
324 out_set:
325         lov_fini_getattr_set(set);
326         RETURN(rc);
327 }
328
329 int lov_fini_destroy_set(struct lov_request_set *set)
330 {
331         ENTRY;
332
333         if (set == NULL)
334                 RETURN(0);
335         LASSERT(set->set_exp);
336         if (atomic_read(&set->set_completes)) {
337                 /* FIXME update qos data here */
338         }
339
340         lov_put_reqset(set);
341
342         RETURN(0);
343 }
344
345 int lov_prep_destroy_set(struct obd_export *exp, struct obd_info *oinfo,
346                          struct obdo *src_oa, struct lov_stripe_md *lsm,
347                          struct obd_trans_info *oti,
348                          struct lov_request_set **reqset)
349 {
350         struct lov_request_set *set;
351         struct lov_obd *lov = &exp->exp_obd->u.lov;
352         int rc = 0, i;
353         ENTRY;
354
355         OBD_ALLOC(set, sizeof(*set));
356         if (set == NULL)
357                 RETURN(-ENOMEM);
358         lov_init_set(set);
359
360         set->set_exp = exp;
361         set->set_oi = oinfo;
362         set->set_oi->oi_md = lsm;
363         set->set_oi->oi_oa = src_oa;
364         if (oti != NULL && src_oa->o_valid & OBD_MD_FLCOOKIE)
365                 set->set_cookies = oti->oti_logcookies;
366
367         for (i = 0; i < lsm->lsm_stripe_count; i++) {
368                 struct lov_oinfo *loi;
369                 struct lov_request *req;
370
371                 loi = lsm->lsm_oinfo[i];
372                 if (lov_oinfo_is_dummy(loi))
373                         continue;
374
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 (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_oinfo_is_dummy(loi))
485                         continue;
486
487                 if (!lov_check_and_wait_active(lov, loi->loi_ost_idx)) {
488                         CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
489                         continue;
490                 }
491
492                 OBD_ALLOC(req, sizeof(*req));
493                 if (req == NULL)
494                         GOTO(out_set, rc = -ENOMEM);
495                 req->rq_stripe = i;
496                 req->rq_idx = loi->loi_ost_idx;
497
498                 OBDO_ALLOC(req->rq_oi.oi_oa);
499                 if (req->rq_oi.oi_oa == NULL) {
500                         OBD_FREE(req, sizeof(*req));
501                         GOTO(out_set, rc = -ENOMEM);
502                 }
503                 memcpy(req->rq_oi.oi_oa, oinfo->oi_oa,
504                        sizeof(*req->rq_oi.oi_oa));
505                 req->rq_oi.oi_oa->o_oi = loi->loi_oi;
506                 req->rq_oi.oi_oa->o_stripe_idx = i;
507                 req->rq_oi.oi_cb_up = cb_setattr_update;
508                 req->rq_oi.oi_capa = oinfo->oi_capa;
509
510                 if (oinfo->oi_oa->o_valid & OBD_MD_FLSIZE) {
511                         int off = lov_stripe_offset(oinfo->oi_md,
512                                                     oinfo->oi_oa->o_size, i,
513                                                     &req->rq_oi.oi_oa->o_size);
514
515                         if (off < 0 && req->rq_oi.oi_oa->o_size)
516                                 req->rq_oi.oi_oa->o_size--;
517
518                         CDEBUG(D_INODE, "stripe %d has size "LPU64"/"LPU64"\n",
519                                i, req->rq_oi.oi_oa->o_size,
520                                oinfo->oi_oa->o_size);
521                 }
522                 lov_set_add_req(req, set);
523         }
524         if (!set->set_count)
525                 GOTO(out_set, rc = -EIO);
526         *reqset = set;
527         RETURN(rc);
528 out_set:
529         lov_fini_setattr_set(set);
530         RETURN(rc);
531 }
532
533 #define LOV_U64_MAX ((__u64)~0ULL)
534 #define LOV_SUM_MAX(tot, add)                                           \
535         do {                                                            \
536                 if ((tot) + (add) < (tot))                              \
537                         (tot) = LOV_U64_MAX;                            \
538                 else                                                    \
539                         (tot) += (add);                                 \
540         } while(0)
541
542 int lov_fini_statfs(struct obd_device *obd, struct obd_statfs *osfs,int success)
543 {
544         ENTRY;
545
546         if (success) {
547                 __u32 expected_stripes = lov_get_stripecnt(&obd->u.lov,
548                                                            LOV_MAGIC, 0);
549                 if (osfs->os_files != LOV_U64_MAX)
550                         lov_do_div64(osfs->os_files, expected_stripes);
551                 if (osfs->os_ffree != LOV_U64_MAX)
552                         lov_do_div64(osfs->os_ffree, expected_stripes);
553
554                 spin_lock(&obd->obd_osfs_lock);
555                 memcpy(&obd->obd_osfs, osfs, sizeof(*osfs));
556                 obd->obd_osfs_age = cfs_time_current_64();
557                 spin_unlock(&obd->obd_osfs_lock);
558                 RETURN(0);
559         }
560
561         RETURN(-EIO);
562 }
563
564 int lov_fini_statfs_set(struct lov_request_set *set)
565 {
566         int rc = 0;
567         ENTRY;
568
569         if (set == NULL)
570                 RETURN(0);
571
572         if (atomic_read(&set->set_completes)) {
573                 rc = lov_fini_statfs(set->set_obd, set->set_oi->oi_osfs,
574                                      atomic_read(&set->set_success));
575         }
576         lov_put_reqset(set);
577         RETURN(rc);
578 }
579
580 void lov_update_statfs(struct obd_statfs *osfs, struct obd_statfs *lov_sfs,
581                        int success)
582 {
583         int shift = 0, quit = 0;
584         __u64 tmp;
585
586         if (success == 0) {
587                 memcpy(osfs, lov_sfs, sizeof(*lov_sfs));
588         } else {
589                 if (osfs->os_bsize != lov_sfs->os_bsize) {
590                         /* assume all block sizes are always powers of 2 */
591                         /* get the bits difference */
592                         tmp = osfs->os_bsize | lov_sfs->os_bsize;
593                         for (shift = 0; shift <= 64; ++shift) {
594                                 if (tmp & 1) {
595                                         if (quit)
596                                                 break;
597                                         else
598                                                 quit = 1;
599                                         shift = 0;
600                                 }
601                                 tmp >>= 1;
602                         }
603                 }
604
605                 if (osfs->os_bsize < lov_sfs->os_bsize) {
606                         osfs->os_bsize = lov_sfs->os_bsize;
607
608                         osfs->os_bfree  >>= shift;
609                         osfs->os_bavail >>= shift;
610                         osfs->os_blocks >>= shift;
611                 } else if (shift != 0) {
612                         lov_sfs->os_bfree  >>= shift;
613                         lov_sfs->os_bavail >>= shift;
614                         lov_sfs->os_blocks >>= shift;
615                 }
616 #ifdef MIN_DF
617                 /* Sandia requested that df (and so, statfs) only
618                    returned minimal available space on
619                    a single OST, so people would be able to
620                    write this much data guaranteed. */
621                 if (osfs->os_bavail > lov_sfs->os_bavail) {
622                         /* Presumably if new bavail is smaller,
623                            new bfree is bigger as well */
624                         osfs->os_bfree = lov_sfs->os_bfree;
625                         osfs->os_bavail = lov_sfs->os_bavail;
626                 }
627 #else
628                 osfs->os_bfree += lov_sfs->os_bfree;
629                 osfs->os_bavail += lov_sfs->os_bavail;
630 #endif
631                 osfs->os_blocks += lov_sfs->os_blocks;
632                 /* XXX not sure about this one - depends on policy.
633                  *   - could be minimum if we always stripe on all OBDs
634                  *     (but that would be wrong for any other policy,
635                  *     if one of the OBDs has no more objects left)
636                  *   - could be sum if we stripe whole objects
637                  *   - could be average, just to give a nice number
638                  *
639                  * To give a "reasonable" (if not wholly accurate)
640                  * number, we divide the total number of free objects
641                  * by expected stripe count (watch out for overflow).
642                  */
643                 LOV_SUM_MAX(osfs->os_files, lov_sfs->os_files);
644                 LOV_SUM_MAX(osfs->os_ffree, lov_sfs->os_ffree);
645         }
646 }
647
648 /* The callback for osc_statfs_async that finilizes a request info when a
649  * response is received. */
650 static int cb_statfs_update(void *cookie, int rc)
651 {
652         struct obd_info *oinfo = cookie;
653         struct lov_request *lovreq;
654         struct lov_request_set *set;
655         struct obd_statfs *osfs, *lov_sfs;
656         struct lov_obd *lov;
657         struct lov_tgt_desc *tgt;
658         struct obd_device *lovobd, *tgtobd;
659         int success;
660         ENTRY;
661
662         lovreq = container_of(oinfo, struct lov_request, rq_oi);
663         set = lovreq->rq_rqset;
664         lovobd = set->set_obd;
665         lov = &lovobd->u.lov;
666         osfs = set->set_oi->oi_osfs;
667         lov_sfs = oinfo->oi_osfs;
668         success = atomic_read(&set->set_success);
669         /* XXX: the same is done in lov_update_common_set, however
670            lovset->set_exp is not initialized. */
671         lov_update_set(set, lovreq, rc);
672         if (rc)
673                 GOTO(out, rc);
674
675         obd_getref(lovobd);
676         tgt = lov->lov_tgts[lovreq->rq_idx];
677         if (!tgt || !tgt->ltd_active)
678                 GOTO(out_update, rc);
679
680         tgtobd = class_exp2obd(tgt->ltd_exp);
681         spin_lock(&tgtobd->obd_osfs_lock);
682         memcpy(&tgtobd->obd_osfs, lov_sfs, sizeof(*lov_sfs));
683         if ((oinfo->oi_flags & OBD_STATFS_FROM_CACHE) == 0)
684                 tgtobd->obd_osfs_age = cfs_time_current_64();
685         spin_unlock(&tgtobd->obd_osfs_lock);
686
687 out_update:
688         lov_update_statfs(osfs, lov_sfs, success);
689         obd_putref(lovobd);
690
691 out:
692         if (set->set_oi->oi_flags & OBD_STATFS_PTLRPCD &&
693             lov_set_finished(set, 0)) {
694                 lov_statfs_interpret(NULL, set, set->set_count !=
695                                      atomic_read(&set->set_success));
696         }
697
698         RETURN(0);
699 }
700
701 int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
702                         struct lov_request_set **reqset)
703 {
704         struct lov_request_set *set;
705         struct lov_obd *lov = &obd->u.lov;
706         int rc = 0, i;
707         ENTRY;
708
709         OBD_ALLOC(set, sizeof(*set));
710         if (set == NULL)
711                 RETURN(-ENOMEM);
712         lov_init_set(set);
713
714         set->set_obd = obd;
715         set->set_oi = oinfo;
716
717         /* We only get block data from the OBD */
718         for (i = 0; i < lov->desc.ld_tgt_count; i++) {
719                 struct lov_request *req;
720
721                 if (lov->lov_tgts[i] == NULL ||
722                     (oinfo->oi_flags & OBD_STATFS_NODELAY &&
723                      !lov->lov_tgts[i]->ltd_active)) {
724                         CDEBUG(D_HA, "lov idx %d inactive\n", i);
725                         continue;
726                 }
727
728                 if (!lov->lov_tgts[i]->ltd_active)
729                         lov_check_and_wait_active(lov, i);
730
731                 /* skip targets that have been explicitely disabled by the
732                  * administrator */
733                 if (!lov->lov_tgts[i]->ltd_exp) {
734                         CDEBUG(D_HA, "lov idx %d administratively disabled\n", i);
735                         continue;
736                 }
737
738                 OBD_ALLOC(req, sizeof(*req));
739                 if (req == NULL)
740                         GOTO(out_set, rc = -ENOMEM);
741
742                 OBD_ALLOC(req->rq_oi.oi_osfs, sizeof(*req->rq_oi.oi_osfs));
743                 if (req->rq_oi.oi_osfs == NULL) {
744                         OBD_FREE(req, sizeof(*req));
745                         GOTO(out_set, rc = -ENOMEM);
746                 }
747
748                 req->rq_idx = i;
749                 req->rq_oi.oi_cb_up = cb_statfs_update;
750                 req->rq_oi.oi_flags = oinfo->oi_flags;
751
752                 lov_set_add_req(req, set);
753         }
754         if (!set->set_count)
755                 GOTO(out_set, rc = -EIO);
756         *reqset = set;
757         RETURN(rc);
758 out_set:
759         lov_fini_statfs_set(set);
760         RETURN(rc);
761 }