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