Revision 82f19570 htools/Ganeti/HTools/Node.hs

b/htools/Ganeti/HTools/Node.hs
323 323
                  , pCpu = fromIntegral new_count / tCpu t
324 324
                  , utilLoad = utilLoad t `T.addUtil` Instance.util inst
325 325
                  , pTags = addTags (pTags t) (Instance.tags inst)
326
                  , instSpindles = new_spindles
326 327
                  }
327 328
  where new_count = Instance.applyIfOnline inst (+ Instance.vcpus inst)
328 329
                    (uCpu t )
330
        new_spindles = instSpindles t + if Instance.usesLocalStorage inst
331
                                          then 1 else 0
329 332

  
330 333
-- | Assigns an instance to a node as secondary without other updates.
331 334
setSec :: Node -> Instance.Instance -> Node
332 335
setSec t inst = t { sList = Instance.idx inst:sList t
333 336
                  , utilLoad = old_load { T.dskWeight = T.dskWeight old_load +
334 337
                                          T.dskWeight (Instance.util inst) }
338
                  , instSpindles = new_spindles
335 339
                  }
336 340
  where old_load = utilLoad t
341
        new_spindles = instSpindles t + if Instance.usesLocalStorage inst
342
                                          then 1 else 0
337 343

  
338 344
-- * Update functions
339 345

  
......
353 359
      new_plist = delete iname (pList t)
354 360
      new_mem = incIf i_online (fMem t) (Instance.mem inst)
355 361
      new_dsk = incIf uses_disk (fDsk t) (Instance.dsk inst)
362
      new_spindles = decIf uses_disk (instSpindles t) 1
356 363
      new_mp = fromIntegral new_mem / tMem t
357 364
      new_dp = fromIntegral new_dsk / tDsk t
358 365
      new_failn1 = new_mem <= rMem t
......
362 369
  in t { pList = new_plist, fMem = new_mem, fDsk = new_dsk
363 370
       , failN1 = new_failn1, pMem = new_mp, pDsk = new_dp
364 371
       , uCpu = new_ucpu, pCpu = new_rcpu, utilLoad = new_load
365
       , pTags = delTags (pTags t) (Instance.tags inst) }
372
       , pTags = delTags (pTags t) (Instance.tags inst)
373
       , instSpindles = new_spindles
374
       }
366 375

  
367 376
-- | Removes a secondary instance.
368 377
removeSec :: Node -> Instance.Instance -> Node
......
373 382
      pnode = Instance.pNode inst
374 383
      new_slist = delete iname (sList t)
375 384
      new_dsk = incIf uses_disk cur_dsk (Instance.dsk inst)
385
      new_spindles = decIf uses_disk (instSpindles t) 1
376 386
      old_peers = peers t
377 387
      old_peem = P.find pnode old_peers
378 388
      new_peem = decIf (Instance.usesSecMem inst) old_peem (Instance.mem inst)
......
391 401
                                          T.dskWeight (Instance.util inst) }
392 402
  in t { sList = new_slist, fDsk = new_dsk, peers = new_peers
393 403
       , failN1 = new_failn1, rMem = new_rmem, pDsk = new_dp
394
       , pRem = new_prem, utilLoad = new_load }
404
       , pRem = new_prem, utilLoad = new_load
405
       , instSpindles = new_spindles
406
       }
395 407

  
396 408
-- | Adds a primary instance (basic version).
397 409
addPri :: Node -> Instance.Instance -> T.OpResult Node
......
414 426
      cur_dsk = fDsk t
415 427
      new_mem = decIf i_online (fMem t) (Instance.mem inst)
416 428
      new_dsk = decIf uses_disk cur_dsk (Instance.dsk inst)
429
      new_spindles = incIf uses_disk (instSpindles t) 1
417 430
      new_failn1 = new_mem <= rMem t
418 431
      new_ucpu = incIf i_online (uCpu t) (Instance.vcpus inst)
419 432
      new_pcpu = fromIntegral new_ucpu / tCpu t
......
427 440
       _ | new_mem <= 0 -> T.OpFail T.FailMem
428 441
         | uses_disk && new_dsk <= 0 -> T.OpFail T.FailDisk
429 442
         | uses_disk && mDsk t > new_dp && strict -> T.OpFail T.FailDisk
443
         | uses_disk && new_spindles > hiSpindles t
444
             && strict -> T.OpFail T.FailDisk
430 445
         | new_failn1 && not (failN1 t) && strict -> T.OpFail T.FailMem
431 446
         | l_cpu >= 0 && l_cpu < new_pcpu && strict -> T.OpFail T.FailCPU
432 447
         | rejectAddTags old_tags inst_tags -> T.OpFail T.FailTags
......
437 452
                     , failN1 = new_failn1, pMem = new_mp, pDsk = new_dp
438 453
                     , uCpu = new_ucpu, pCpu = new_pcpu
439 454
                     , utilLoad = new_load
440
                     , pTags = addTags old_tags inst_tags }
455
                     , pTags = addTags old_tags inst_tags
456
                     , instSpindles = new_spindles
457
                     }
441 458
           in T.OpGood r
442 459

  
443 460
-- | Adds a secondary instance (basic version).
......
451 468
      old_peers = peers t
452 469
      old_mem = fMem t
453 470
      new_dsk = fDsk t - Instance.dsk inst
471
      new_spindles = instSpindles t + 1
454 472
      secondary_needed_mem = if Instance.usesSecMem inst
455 473
                               then Instance.mem inst
456 474
                               else 0
......
468 486
       _ | not (Instance.hasSecondary inst) -> T.OpFail T.FailDisk
469 487
         | new_dsk <= 0 -> T.OpFail T.FailDisk
470 488
         | mDsk t > new_dp && strict -> T.OpFail T.FailDisk
489
         | new_spindles > hiSpindles t && strict -> T.OpFail T.FailDisk
471 490
         | secondary_needed_mem >= old_mem && strict -> T.OpFail T.FailMem
472 491
         | new_failn1 && not (failN1 t) && strict -> T.OpFail T.FailMem
473 492
         | otherwise ->
......
475 494
               r = t { sList = new_slist, fDsk = new_dsk
476 495
                     , peers = new_peers, failN1 = new_failn1
477 496
                     , rMem = new_rmem, pDsk = new_dp
478
                     , pRem = new_prem, utilLoad = new_load }
497
                     , pRem = new_prem, utilLoad = new_load
498
                     , instSpindles = new_spindles
499
                     }
479 500
           in T.OpGood r
480 501

  
481 502
-- * Stats functions

Also available in: Unified diff