@ -2814,12 +2815,16 @@ static struct pool *select_balanced(struct pool *cp)
@@ -2814,12 +2815,16 @@ static struct pool *select_balanced(struct pool *cp)
returnret;
}
/* Select any active pool in a rotating fashion when loadbalance is chosen */
staticstructpool*priority_pool(intchoice);
staticboolpool_unusable(structpool*pool);
/* Select any active pool in a rotating fashion when loadbalance is chosen if
*ithasanyquotaleft.*/
staticinlinestructpool*select_pool(boollagging)
{
staticintrotating_pool=0;
structpool*pool,*cp;
inttested;
inttested,i;
cp=current_pool();
@ -2834,17 +2839,37 @@ static inline struct pool *select_pool(bool lagging)
@@ -2834,17 +2839,37 @@ static inline struct pool *select_pool(bool lagging)
/* Try to find the first pool in the rotation that is usable */
tested=0;
while(!pool&&tested++<total_pools){
if(++rotating_pool>=total_pools)
rotating_pool=0;
pool=pools[rotating_pool];
if(pool->quota_used++>=pool->quota){
pool->quota_used=0;
pool=NULL;
if(++rotating_pool>=total_pools)
rotating_pool=0;
continue;
}
if(!pool_unworkable(pool))
break;
pool=NULL;
}
/* If there are no alive pools with quota, choose according to
*priority.*/
if(!pool){
for(i=0;i<total_pools;i++){
structpool*tp=priority_pool(i);
if(!pool_unusable(tp)){
pool=tp;
break;
}
}
}
/* If still nothing is usable, use the current pool */
if(!pool)
pool=cp;
applog(LOG_DEBUG,"Selecting pool %d for work",pool->pool_no);
returnpool;
}
@ -3573,7 +3598,7 @@ void switch_pools(struct pool *selected)
@@ -3573,7 +3598,7 @@ void switch_pools(struct pool *selected)