Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[fs/lustre-release.git] / lustre / obdclass / lu_tgt_descs.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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * This file is part of Lustre, http://www.lustre.org/
24  *
25  * lustre/obdclass/lu_tgt_descs.c
26  *
27  * Lustre target descriptions
28  * These are the only exported functions, they provide some generic
29  * infrastructure for target description management used by LOD/LMV
30  *
31  */
32
33 #define DEBUG_SUBSYSTEM S_CLASS
34
35 #include <linux/module.h>
36 #include <linux/list.h>
37 #include <linux/random.h>
38 #include <libcfs/libcfs.h>
39 #include <libcfs/libcfs_hash.h> /* hash_long() */
40 #include <libcfs/linux/linux-mem.h>
41 #include <obd_class.h>
42 #include <obd_support.h>
43 #include <lustre_disk.h>
44 #include <lustre_fid.h>
45 #include <lu_object.h>
46
47 /**
48  * lu_prandom_u64_max - returns a pseudo-random u64 number in interval
49  * [0, ep_ro)
50  *
51  * \param[in] ep_ro     right open interval endpoint
52  *
53  * \retval a pseudo-random 64-bit number that is in interval [0, ep_ro).
54  */
55 u64 lu_prandom_u64_max(u64 ep_ro)
56 {
57         u64 rand = 0;
58
59         if (ep_ro) {
60 #if BITS_PER_LONG == 32
61                 /*
62                  * If ep_ro > 32-bit, first generate the high
63                  * 32 bits of the random number, then add in the low
64                  * 32 bits (truncated to the upper limit, if needed)
65                  */
66                 if (ep_ro > 0xffffffffULL)
67                         rand = prandom_u32_max((u32)(ep_ro >> 32)) << 32;
68
69                 if (rand == (ep_ro & 0xffffffff00000000ULL))
70                         rand |= prandom_u32_max((u32)ep_ro);
71                 else
72                         rand |= prandom_u32();
73 #else
74                 rand = ((u64)prandom_u32() << 32 | prandom_u32()) % ep_ro;
75 #endif
76         }
77
78         return rand;
79 }
80 EXPORT_SYMBOL(lu_prandom_u64_max);
81
82 void lu_qos_rr_init(struct lu_qos_rr *lqr)
83 {
84         spin_lock_init(&lqr->lqr_alloc);
85         lqr->lqr_dirty = 1;
86 }
87 EXPORT_SYMBOL(lu_qos_rr_init);
88
89 /**
90  * Add a new target to Quality of Service (QoS) target table.
91  *
92  * Add a new MDT/OST target to the structure representing an OSS. Resort the
93  * list of known MDSs/OSSs by the number of MDTs/OSTs attached to each MDS/OSS.
94  * The MDS/OSS list is protected internally and no external locking is required.
95  *
96  * \param[in] qos               lu_qos data
97  * \param[in] tgt               target description
98  *
99  * \retval 0                    on success
100  * \retval -ENOMEM              on error
101  */
102 int lu_qos_add_tgt(struct lu_qos *qos, struct lu_tgt_desc *tgt)
103 {
104         struct lu_svr_qos *svr = NULL;
105         struct lu_svr_qos *tempsvr;
106         struct obd_export *exp = tgt->ltd_exp;
107         int found = 0;
108         __u32 id = 0;
109         int rc = 0;
110
111         ENTRY;
112
113         /* tgt not connected, this function will be called again later */
114         if (!exp)
115                 RETURN(0);
116
117         down_write(&qos->lq_rw_sem);
118         /*
119          * a bit hacky approach to learn NID of corresponding connection
120          * but there is no official API to access information like this
121          * with OSD API.
122          */
123         list_for_each_entry(svr, &qos->lq_svr_list, lsq_svr_list) {
124                 if (obd_uuid_equals(&svr->lsq_uuid,
125                                     &exp->exp_connection->c_remote_uuid)) {
126                         found++;
127                         break;
128                 }
129                 if (svr->lsq_id > id)
130                         id = svr->lsq_id;
131         }
132
133         if (!found) {
134                 OBD_ALLOC_PTR(svr);
135                 if (!svr)
136                         GOTO(out, rc = -ENOMEM);
137                 memcpy(&svr->lsq_uuid, &exp->exp_connection->c_remote_uuid,
138                        sizeof(svr->lsq_uuid));
139                 ++id;
140                 svr->lsq_id = id;
141         } else {
142                 /* Assume we have to move this one */
143                 list_del(&svr->lsq_svr_list);
144         }
145
146         svr->lsq_tgt_count++;
147         tgt->ltd_qos.ltq_svr = svr;
148
149         CDEBUG(D_OTHER, "add tgt %s to server %s (%d targets)\n",
150                obd_uuid2str(&tgt->ltd_uuid), obd_uuid2str(&svr->lsq_uuid),
151                svr->lsq_tgt_count);
152
153         /*
154          * Add sorted by # of tgts.  Find the first entry that we're
155          * bigger than...
156          */
157         list_for_each_entry(tempsvr, &qos->lq_svr_list, lsq_svr_list) {
158                 if (svr->lsq_tgt_count > tempsvr->lsq_tgt_count)
159                         break;
160         }
161         /*
162          * ...and add before it.  If we're the first or smallest, tempsvr
163          * points to the list head, and we add to the end.
164          */
165         list_add_tail(&svr->lsq_svr_list, &tempsvr->lsq_svr_list);
166
167         qos->lq_dirty = 1;
168         qos->lq_rr.lqr_dirty = 1;
169
170 out:
171         up_write(&qos->lq_rw_sem);
172         RETURN(rc);
173 }
174 EXPORT_SYMBOL(lu_qos_add_tgt);
175
176 /**
177  * Remove MDT/OST target from QoS table.
178  *
179  * Removes given MDT/OST target from QoS table and releases related
180  * MDS/OSS structure if no target remain on the MDS/OSS.
181  *
182  * \param[in] qos               lu_qos data
183  * \param[in] ltd               target description
184  *
185  * \retval 0                    on success
186  * \retval -ENOENT              if no server was found
187  */
188 static int lu_qos_del_tgt(struct lu_qos *qos, struct lu_tgt_desc *ltd)
189 {
190         struct lu_svr_qos *svr;
191         int rc = 0;
192
193         ENTRY;
194
195         down_write(&qos->lq_rw_sem);
196         svr = ltd->ltd_qos.ltq_svr;
197         if (!svr)
198                 GOTO(out, rc = -ENOENT);
199
200         svr->lsq_tgt_count--;
201         if (svr->lsq_tgt_count == 0) {
202                 CDEBUG(D_OTHER, "removing server %s\n",
203                        obd_uuid2str(&svr->lsq_uuid));
204                 list_del(&svr->lsq_svr_list);
205                 ltd->ltd_qos.ltq_svr = NULL;
206                 OBD_FREE_PTR(svr);
207         }
208
209         qos->lq_dirty = 1;
210         qos->lq_rr.lqr_dirty = 1;
211 out:
212         up_write(&qos->lq_rw_sem);
213         RETURN(rc);
214 }
215
216 static inline __u64 tgt_statfs_bavail(struct lu_tgt_desc *tgt)
217 {
218         struct obd_statfs *statfs = &tgt->ltd_statfs;
219
220         return statfs->os_bavail * statfs->os_bsize;
221 }
222
223 static inline __u64 tgt_statfs_iavail(struct lu_tgt_desc *tgt)
224 {
225         return tgt->ltd_statfs.os_ffree;
226 }
227
228 /**
229  * Calculate weight for a given tgt.
230  *
231  * The final tgt weight is bavail >> 16 * iavail >> 8 minus the tgt and server
232  * penalties.  See ltd_qos_penalties_calc() for how penalties are calculated.
233  *
234  * \param[in] tgt       target descriptor
235  */
236 void lu_tgt_qos_weight_calc(struct lu_tgt_desc *tgt)
237 {
238         struct lu_tgt_qos *ltq = &tgt->ltd_qos;
239         __u64 temp, temp2;
240
241         temp = (tgt_statfs_bavail(tgt) >> 16) * (tgt_statfs_iavail(tgt) >> 8);
242         temp2 = ltq->ltq_penalty + ltq->ltq_svr->lsq_penalty;
243         if (temp < temp2)
244                 ltq->ltq_weight = 0;
245         else
246                 ltq->ltq_weight = temp - temp2;
247 }
248 EXPORT_SYMBOL(lu_tgt_qos_weight_calc);
249
250 /**
251  * Allocate and initialize target table.
252  *
253  * A helper function to initialize the target table and allocate
254  * a bitmap of the available targets.
255  *
256  * \param[in] ltd               target's table to initialize
257  * \param[in] is_mdt            target table for MDTs
258  *
259  * \retval 0                    on success
260  * \retval negative             negated errno on error
261  **/
262 int lu_tgt_descs_init(struct lu_tgt_descs *ltd, bool is_mdt)
263 {
264         mutex_init(&ltd->ltd_mutex);
265         init_rwsem(&ltd->ltd_rw_sem);
266
267         /*
268          * the tgt array and bitmap are allocated/grown dynamically as tgts are
269          * added to the LOD/LMV, see lu_tgt_descs_add()
270          */
271         ltd->ltd_tgt_bitmap = CFS_ALLOCATE_BITMAP(BITS_PER_LONG);
272         if (!ltd->ltd_tgt_bitmap)
273                 return -ENOMEM;
274
275         ltd->ltd_tgts_size  = BITS_PER_LONG;
276         ltd->ltd_death_row = 0;
277         ltd->ltd_refcount  = 0;
278
279         /* Set up allocation policy (QoS and RR) */
280         INIT_LIST_HEAD(&ltd->ltd_qos.lq_svr_list);
281         init_rwsem(&ltd->ltd_qos.lq_rw_sem);
282         ltd->ltd_qos.lq_dirty = 1;
283         ltd->ltd_qos.lq_reset = 1;
284         /* Default priority is toward free space balance */
285         ltd->ltd_qos.lq_prio_free = 232;
286         /* Default threshold for rr (roughly 17%) */
287         ltd->ltd_qos.lq_threshold_rr = 43;
288         ltd->ltd_is_mdt = is_mdt;
289
290         lu_qos_rr_init(&ltd->ltd_qos.lq_rr);
291
292         return 0;
293 }
294 EXPORT_SYMBOL(lu_tgt_descs_init);
295
296 /**
297  * Free bitmap and target table pages.
298  *
299  * \param[in] ltd       target table
300  */
301 void lu_tgt_descs_fini(struct lu_tgt_descs *ltd)
302 {
303         int i;
304
305         CFS_FREE_BITMAP(ltd->ltd_tgt_bitmap);
306         for (i = 0; i < TGT_PTRS; i++) {
307                 if (ltd->ltd_tgt_idx[i])
308                         OBD_FREE_PTR(ltd->ltd_tgt_idx[i]);
309         }
310         ltd->ltd_tgts_size = 0;
311 }
312 EXPORT_SYMBOL(lu_tgt_descs_fini);
313
314 /**
315  * Expand size of target table.
316  *
317  * When the target table is full, we have to extend the table. To do so,
318  * we allocate new memory with some reserve, move data from the old table
319  * to the new one and release memory consumed by the old table.
320  *
321  * \param[in] ltd               target table
322  * \param[in] newsize           new size of the table
323  *
324  * \retval                      0 on success
325  * \retval                      -ENOMEM if reallocation failed
326  */
327 static int lu_tgt_descs_resize(struct lu_tgt_descs *ltd, __u32 newsize)
328 {
329         struct cfs_bitmap *new_bitmap, *old_bitmap = NULL;
330
331         /* someone else has already resize the array */
332         if (newsize <= ltd->ltd_tgts_size)
333                 return 0;
334
335         new_bitmap = CFS_ALLOCATE_BITMAP(newsize);
336         if (!new_bitmap)
337                 return -ENOMEM;
338
339         if (ltd->ltd_tgts_size > 0) {
340                 /* the bitmap already exists, copy data from old one */
341                 cfs_bitmap_copy(new_bitmap, ltd->ltd_tgt_bitmap);
342                 old_bitmap = ltd->ltd_tgt_bitmap;
343         }
344
345         ltd->ltd_tgts_size  = newsize;
346         ltd->ltd_tgt_bitmap = new_bitmap;
347
348         if (old_bitmap)
349                 CFS_FREE_BITMAP(old_bitmap);
350
351         CDEBUG(D_CONFIG, "tgt size: %d\n", ltd->ltd_tgts_size);
352
353         return 0;
354 }
355
356 /**
357  * Add new target to target table.
358  *
359  * Extend target table if it's full, update target table and bitmap.
360  * Notice we need to take ltd_rw_sem exclusively before entry to ensure
361  * atomic switch.
362  *
363  * \param[in] ltd               target table
364  * \param[in] tgt               new target desc
365  *
366  * \retval                      0 on success
367  * \retval                      -ENOMEM if reallocation failed
368  *                              -EEXIST if target existed
369  */
370 int ltd_add_tgt(struct lu_tgt_descs *ltd, struct lu_tgt_desc *tgt)
371 {
372         __u32 index = tgt->ltd_index;
373         int rc;
374
375         ENTRY;
376
377         if (index >= ltd->ltd_tgts_size) {
378                 __u32 newsize = 1;
379
380                 while (newsize < index + 1)
381                         newsize = newsize << 1;
382
383                 rc = lu_tgt_descs_resize(ltd, newsize);
384                 if (rc)
385                         RETURN(rc);
386         } else if (cfs_bitmap_check(ltd->ltd_tgt_bitmap, index)) {
387                 RETURN(-EEXIST);
388         }
389
390         if (ltd->ltd_tgt_idx[index / TGT_PTRS_PER_BLOCK] == NULL) {
391                 OBD_ALLOC_PTR(ltd->ltd_tgt_idx[index / TGT_PTRS_PER_BLOCK]);
392                 if (ltd->ltd_tgt_idx[index / TGT_PTRS_PER_BLOCK] == NULL)
393                         RETURN(-ENOMEM);
394         }
395
396         LTD_TGT(ltd, tgt->ltd_index) = tgt;
397         cfs_bitmap_set(ltd->ltd_tgt_bitmap, tgt->ltd_index);
398
399         ltd->ltd_lov_desc.ld_tgt_count++;
400         if (tgt->ltd_active)
401                 ltd->ltd_lov_desc.ld_active_tgt_count++;
402
403         RETURN(0);
404 }
405 EXPORT_SYMBOL(ltd_add_tgt);
406
407 /**
408  * Delete target from target table
409  */
410 void ltd_del_tgt(struct lu_tgt_descs *ltd, struct lu_tgt_desc *tgt)
411 {
412         lu_qos_del_tgt(&ltd->ltd_qos, tgt);
413         LTD_TGT(ltd, tgt->ltd_index) = NULL;
414         cfs_bitmap_clear(ltd->ltd_tgt_bitmap, tgt->ltd_index);
415         ltd->ltd_lov_desc.ld_tgt_count--;
416         if (tgt->ltd_active)
417                 ltd->ltd_lov_desc.ld_active_tgt_count--;
418 }
419 EXPORT_SYMBOL(ltd_del_tgt);
420
421 /**
422  * Whether QoS data is up-to-date and QoS can be applied.
423  */
424 bool ltd_qos_is_usable(struct lu_tgt_descs *ltd)
425 {
426         if (!ltd->ltd_qos.lq_dirty && ltd->ltd_qos.lq_same_space)
427                 return false;
428
429         if (ltd->ltd_lov_desc.ld_active_tgt_count < 2)
430                 return false;
431
432         return true;
433 }
434 EXPORT_SYMBOL(ltd_qos_is_usable);
435
436 /**
437  * Calculate penalties per-tgt and per-server
438  *
439  * Re-calculate penalties when the configuration changes, active targets
440  * change and after statfs refresh (all these are reflected by lq_dirty flag).
441  * On every tgt and server: decay the penalty by half for every 8x the update
442  * interval that the device has been idle. That gives lots of time for the
443  * statfs information to be updated (which the penalty is only a proxy for),
444  * and avoids penalizing server/tgt under light load.
445  * See lu_qos_tgt_weight_calc() for how penalties are factored into the weight.
446  *
447  * \param[in] ltd               lu_tgt_descs
448  *
449  * \retval 0            on success
450  * \retval -EAGAIN      the number of tgt isn't enough or all tgt spaces are
451  *                      almost the same
452  */
453 int ltd_qos_penalties_calc(struct lu_tgt_descs *ltd)
454 {
455         struct lu_qos *qos = &ltd->ltd_qos;
456         struct lov_desc *desc = &ltd->ltd_lov_desc;
457         struct lu_tgt_desc *tgt;
458         struct lu_svr_qos *svr;
459         __u64 ba_max, ba_min, ba;
460         __u64 ia_max, ia_min, ia = 1;
461         __u32 num_active;
462         int prio_wide;
463         time64_t now, age;
464         int rc;
465
466         ENTRY;
467
468         if (!qos->lq_dirty)
469                 GOTO(out, rc = 0);
470
471         num_active = desc->ld_active_tgt_count - 1;
472         if (num_active < 1)
473                 GOTO(out, rc = -EAGAIN);
474
475         /* find bavail on each server */
476         list_for_each_entry(svr, &qos->lq_svr_list, lsq_svr_list) {
477                 svr->lsq_bavail = 0;
478                 /* if inode is not counted, set to 1 to ignore */
479                 svr->lsq_iavail = ltd->ltd_is_mdt ? 0 : 1;
480         }
481         qos->lq_active_svr_count = 0;
482
483         /*
484          * How badly user wants to select targets "widely" (not recently chosen
485          * and not on recent MDS's).  As opposed to "freely" (free space avail.)
486          * 0-256
487          */
488         prio_wide = 256 - qos->lq_prio_free;
489
490         ba_min = (__u64)(-1);
491         ba_max = 0;
492         ia_min = (__u64)(-1);
493         ia_max = 0;
494         now = ktime_get_real_seconds();
495
496         /* Calculate server penalty per object */
497         ltd_foreach_tgt(ltd, tgt) {
498                 if (!tgt->ltd_active)
499                         continue;
500
501                 /* when inode is counted, bavail >> 16 to avoid overflow */
502                 ba = tgt_statfs_bavail(tgt);
503                 if (ltd->ltd_is_mdt)
504                         ba >>= 16;
505                 else
506                         ba >>= 8;
507                 if (!ba)
508                         continue;
509
510                 ba_min = min(ba, ba_min);
511                 ba_max = max(ba, ba_max);
512
513                 /* Count the number of usable servers */
514                 if (tgt->ltd_qos.ltq_svr->lsq_bavail == 0)
515                         qos->lq_active_svr_count++;
516                 tgt->ltd_qos.ltq_svr->lsq_bavail += ba;
517
518                 if (ltd->ltd_is_mdt) {
519                         /* iavail >> 8 to avoid overflow */
520                         ia = tgt_statfs_iavail(tgt) >> 8;
521                         if (!ia)
522                                 continue;
523
524                         ia_min = min(ia, ia_min);
525                         ia_max = max(ia, ia_max);
526
527                         tgt->ltd_qos.ltq_svr->lsq_iavail += ia;
528                 }
529
530                 /*
531                  * per-tgt penalty is
532                  * prio * bavail * iavail / (num_tgt - 1) / 2
533                  */
534                 tgt->ltd_qos.ltq_penalty_per_obj = prio_wide * ba * ia;
535                 do_div(tgt->ltd_qos.ltq_penalty_per_obj, num_active);
536                 tgt->ltd_qos.ltq_penalty_per_obj >>= 1;
537
538                 age = (now - tgt->ltd_qos.ltq_used) >> 3;
539                 if (qos->lq_reset || age > 32 * desc->ld_qos_maxage)
540                         tgt->ltd_qos.ltq_penalty = 0;
541                 else if (age > desc->ld_qos_maxage)
542                         /* Decay tgt penalty. */
543                         tgt->ltd_qos.ltq_penalty >>= age / desc->ld_qos_maxage;
544         }
545
546         num_active = qos->lq_active_svr_count - 1;
547         if (num_active < 1) {
548                 /*
549                  * If there's only 1 server, we can't penalize it, so instead
550                  * we have to double the tgt penalty
551                  */
552                 num_active = 1;
553                 ltd_foreach_tgt(ltd, tgt) {
554                         if (!tgt->ltd_active)
555                                 continue;
556
557                         tgt->ltd_qos.ltq_penalty_per_obj <<= 1;
558                 }
559         }
560
561         /*
562          * Per-server penalty is
563          * prio * bavail * iavail / server_tgts / (num_svr - 1) / 2
564          */
565         list_for_each_entry(svr, &qos->lq_svr_list, lsq_svr_list) {
566                 ba = svr->lsq_bavail;
567                 ia = svr->lsq_iavail;
568                 svr->lsq_penalty_per_obj = prio_wide * ba  * ia;
569                 do_div(ba, svr->lsq_tgt_count * num_active);
570                 svr->lsq_penalty_per_obj >>= 1;
571
572                 age = (now - svr->lsq_used) >> 3;
573                 if (qos->lq_reset || age > 32 * desc->ld_qos_maxage)
574                         svr->lsq_penalty = 0;
575                 else if (age > desc->ld_qos_maxage)
576                         /* Decay server penalty. */
577                         svr->lsq_penalty >>= age / desc->ld_qos_maxage;
578         }
579
580         qos->lq_dirty = 0;
581         qos->lq_reset = 0;
582
583         /*
584          * If each tgt has almost same free space, do rr allocation for better
585          * creation performance
586          */
587         qos->lq_same_space = 0;
588         if ((ba_max * (256 - qos->lq_threshold_rr)) >> 8 < ba_min &&
589             (ia_max * (256 - qos->lq_threshold_rr)) >> 8 < ia_min) {
590                 qos->lq_same_space = 1;
591                 /* Reset weights for the next time we enter qos mode */
592                 qos->lq_reset = 1;
593         }
594         rc = 0;
595
596 out:
597         if (!rc && qos->lq_same_space)
598                 RETURN(-EAGAIN);
599
600         RETURN(rc);
601 }
602 EXPORT_SYMBOL(ltd_qos_penalties_calc);
603
604 /**
605  * Re-calculate penalties and weights of all tgts.
606  *
607  * The function is called when some target was used for a new object. In
608  * this case we should re-calculate all the weights to keep new allocations
609  * balanced well.
610  *
611  * \param[in] ltd               lu_tgt_descs
612  * \param[in] tgt               recently used tgt
613  * \param[out] total_wt         new total weight for the pool
614  *
615  * \retval              0
616  */
617 int ltd_qos_update(struct lu_tgt_descs *ltd, struct lu_tgt_desc *tgt,
618                    __u64 *total_wt)
619 {
620         struct lu_qos *qos = &ltd->ltd_qos;
621         struct lu_tgt_qos *ltq;
622         struct lu_svr_qos *svr;
623
624         ENTRY;
625
626         ltq = &tgt->ltd_qos;
627         LASSERT(ltq);
628
629         /* Don't allocate on this device anymore, until the next alloc_qos */
630         ltq->ltq_usable = 0;
631
632         svr = ltq->ltq_svr;
633
634         /*
635          * Decay old penalty by half (we're adding max penalty, and don't
636          * want it to run away.)
637          */
638         ltq->ltq_penalty >>= 1;
639         svr->lsq_penalty >>= 1;
640
641         /* mark the server and tgt as recently used */
642         ltq->ltq_used = svr->lsq_used = ktime_get_real_seconds();
643
644         /* Set max penalties for this tgt and server */
645         ltq->ltq_penalty += ltq->ltq_penalty_per_obj *
646                             ltd->ltd_lov_desc.ld_active_tgt_count;
647         svr->lsq_penalty += svr->lsq_penalty_per_obj *
648                             ltd->ltd_lov_desc.ld_active_tgt_count;
649
650         /* Decrease all MDS penalties */
651         list_for_each_entry(svr, &qos->lq_svr_list, lsq_svr_list) {
652                 if (svr->lsq_penalty < svr->lsq_penalty_per_obj)
653                         svr->lsq_penalty = 0;
654                 else
655                         svr->lsq_penalty -= svr->lsq_penalty_per_obj;
656         }
657
658         *total_wt = 0;
659         /* Decrease all tgt penalties */
660         ltd_foreach_tgt(ltd, tgt) {
661                 if (!tgt->ltd_active)
662                         continue;
663
664                 if (ltq->ltq_penalty < ltq->ltq_penalty_per_obj)
665                         ltq->ltq_penalty = 0;
666                 else
667                         ltq->ltq_penalty -= ltq->ltq_penalty_per_obj;
668
669                 lu_tgt_qos_weight_calc(tgt);
670
671                 /* Recalc the total weight of usable osts */
672                 if (ltq->ltq_usable)
673                         *total_wt += ltq->ltq_weight;
674
675                 CDEBUG(D_OTHER, "recalc tgt %d usable=%d avail=%llu tgtppo=%llu tgtp=%llu svrppo=%llu svrp=%llu wt=%llu\n",
676                           tgt->ltd_index, ltq->ltq_usable,
677                           tgt_statfs_bavail(tgt) >> 10,
678                           ltq->ltq_penalty_per_obj >> 10,
679                           ltq->ltq_penalty >> 10,
680                           ltq->ltq_svr->lsq_penalty_per_obj >> 10,
681                           ltq->ltq_svr->lsq_penalty >> 10,
682                           ltq->ltq_weight >> 10);
683         }
684
685         RETURN(0);
686 }
687 EXPORT_SYMBOL(ltd_qos_update);