Revision cad2422f src/um/Quota.cc

View differences:

src/um/Quota.cc
80 80
/* -------------------------------------------------------------------------- */
81 81
/* -------------------------------------------------------------------------- */
82 82

  
83
int Quota::set(vector<Attribute*> * new_quotas, string& error)
83
int Quota::set(vector<Attribute*> * new_quotas, bool default_allowed, string& error)
84 84
{
85 85
    vector<Attribute *>::iterator  it;
86 86

  
......
108 108
        {
109 109
            VectorAttribute * nq;
110 110

  
111
            if ((nq = new_quota(iq)) == 0)
111
            if ((nq = new_quota(iq, default_allowed)) == 0)
112 112
            {
113 113
                goto error_limits;
114 114
            }
......
117 117
        }
118 118
        else
119 119
        {
120
            if (update_limits(tq, iq) != 0)
120
            if (update_limits(tq, iq, default_allowed) != 0)
121 121
            {
122 122
                goto error_limits;
123 123
            } 
......
368 368
/* -------------------------------------------------------------------------- */
369 369
/* -------------------------------------------------------------------------- */
370 370

  
371
int Quota::update_limits(VectorAttribute * quota, const VectorAttribute * va)
372
{        
371
int Quota::update_limits(
372
        VectorAttribute *       quota,
373
        const VectorAttribute * va,
374
        bool                    default_allowed)
375
{
373 376
    string limit;
374 377
    float  limit_i;
375 378

  
......
377 380
    {
378 381
        limit = va->vector_value_str(metrics[i], limit_i);
379 382

  
380
        //No quota, NaN or negative. -1 is allowed, it means default limit
381
        if ( limit_i < -1 ||
382
            ( limit_i == -1 && limit == "" ))
383
        //No quota, NaN or negative
384
        if ((default_allowed &&
385
                ( limit_i < -1 || ( limit_i == -1 && limit == "" ))) ||
386
            (!default_allowed && limit_i < 0) )
383 387
        {
384 388
            return -1;
385 389
        }
......
395 399
/* -------------------------------------------------------------------------- */
396 400
/* -------------------------------------------------------------------------- */
397 401

  
398
VectorAttribute * Quota::new_quota(VectorAttribute * va)
402
VectorAttribute * Quota::new_quota(VectorAttribute * va, bool default_allowed)
399 403
{
400 404
    map<string,string> limits;
401 405

  
......
409 413
        metrics_used += "_USED";
410 414

  
411 415
        limit = va->vector_value_str(metrics[i], limit_i);
412
        
413
        if ( limit_i < 0 ) //No quota, NaN or negative
416

  
417
        //No quota, NaN or negative
418
        if ( (default_allowed && limit_i < -1) ||
419
             (!default_allowed && limit_i < 0) )
414 420
        {
415 421
            limit = "0";
416 422
        }

Also available in: Unified diff