| 405 | |
| 406 | |
| 407 | static int get_dst_load(struct lb_resource **res, unsigned int res_no, |
| 408 | struct lb_dst *dst, unsigned int flags, int *load) |
| 409 | { |
| 410 | unsigned int k, l; |
| 411 | int av; |
| 412 | |
| 413 | /* iterate through requested resources */ |
| 414 | for( k=0 ; k<res_no ; k++ ) { |
| 415 | for (l=0 ; l<dst->rmap_no ; l++ ) |
| 416 | if( res[k] == dst->rmap[l].resource ) |
| 417 | break; |
| 418 | if( l == dst->rmap_no ) { |
| 419 | LM_CRIT("bug - cannot find request resource in dst\n"); |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | av = 0; |
| 424 | if( flags & LB_FLAGS_RELATIVE ) { |
| 425 | if( dst->rmap[l].max_load ) |
| 426 | av = 100 - (100 * lb_dlg_binds.get_profile_size(res[k]->profile, &dst->profile_id) / dst->rmap[l].max_load); |
| 427 | } else { |
| 428 | av = dst->rmap[l].max_load - lb_dlg_binds.get_profile_size(res[k]->profile, &dst->profile_id); |
| 429 | } |
| 430 | |
| 431 | if( (k == 0/*first iteration*/) || (av < *load ) ) |
| 432 | *load = av; |
| 433 | /* |
| 434 | we possibly could have negative avaliability for any resource, |
| 435 | because we could use LB_FLAGS_NEGATIVE or manually increment resource |
| 436 | with lb_count_call() |
| 437 | */ |
| 438 | } |
| 439 | return (k > 0); /* load initialized */ |
| 440 | } |
| 441 | |
| 442 | |
| 443 | /* Performce the LB logic. It may return: |