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