@@ -136,9 +136,20 @@ func (ctx *domainContext) publishAssignableAdapters() {
136
136
ctx .pubAssignableAdapters .Publish ("global" , * ctx .assignableAdapters )
137
137
}
138
138
139
+ var currentHypervisor hypervisor.Hypervisor
140
+ var currentHypervisorMutex sync.Mutex
139
141
var logger * logrus.Logger
140
142
var log * base.LogObject
141
143
144
+ // CurrentHypervisor returns the current hypervisor
145
+ func CurrentHypervisor () hypervisor.Hypervisor {
146
+ currentHypervisorMutex .Lock ()
147
+ hv := currentHypervisor
148
+ currentHypervisorMutex .Unlock ()
149
+
150
+ return hv
151
+ }
152
+
142
153
func Run (ps * pubsub.PubSub , loggerArg * logrus.Logger , logArg * base.LogObject , arguments []string ) int {
143
154
logger = loggerArg
144
155
log = logArg
@@ -168,14 +179,17 @@ func Run(ps *pubsub.PubSub, loggerArg *logrus.Logger, logArg *base.LogObject, ar
168
179
fmt .Printf ("%s: %s\n " , agentName , Version )
169
180
return 0
170
181
}
182
+ currentHypervisorMutex .Lock ()
183
+ currentHypervisor , err = hypervisor .GetHypervisor (* domainCtx .hypervisorPtr )
184
+ currentHypervisorMutex .Unlock ()
171
185
if err != nil {
172
186
log .Fatal (err )
173
187
}
174
188
175
189
if err := pidfile .CheckAndCreatePidfile (log , agentName ); err != nil {
176
190
log .Fatal (err )
177
191
}
178
- log .Functionf ("Starting %s with %s hypervisor backend" , agentName , hypervisor . CurrentHypervisor ().Name ())
192
+ log .Functionf ("Starting %s with %s hypervisor backend" , agentName , CurrentHypervisor ().Name ())
179
193
180
194
// Run a periodic timer so we always update StillRunning
181
195
stillRunning := time .NewTicker (25 * time .Second )
@@ -472,15 +486,15 @@ func Run(ps *pubsub.PubSub, loggerArg *logrus.Logger, logArg *base.LogObject, ar
472
486
473
487
capabilitiesSent := false
474
488
capabilitiesTicker := time .NewTicker (5 * time .Second )
475
- if err := getAndPublishCapabilities (& domainCtx , hypervisor . CurrentHypervisor ()); err != nil {
489
+ if err := getAndPublishCapabilities (& domainCtx , CurrentHypervisor ()); err != nil {
476
490
log .Warnf ("getAndPublishCapabilities: %v" , err )
477
491
} else {
478
492
capabilitiesSent = true
479
493
capabilitiesTicker .Stop ()
480
494
}
481
495
482
496
log .Functionf ("Creating %s at %s" , "metricsTimerTask" , agentlog .GetMyStack ())
483
- go metricsTimerTask (& domainCtx , hypervisor . CurrentHypervisor ())
497
+ go metricsTimerTask (& domainCtx , CurrentHypervisor ())
484
498
485
499
// Before starting to process DomainConfig, domainmgr should (in this order):
486
500
// 1. wait for NIM to publish DNS to learn which ports are used for management
@@ -516,7 +530,7 @@ func Run(ps *pubsub.PubSub, loggerArg *logrus.Logger, logArg *base.LogObject, ar
516
530
publishProcessesHandler (& domainCtx )
517
531
518
532
case <- capabilitiesTicker .C :
519
- if err := getAndPublishCapabilities (& domainCtx , hypervisor . CurrentHypervisor ()); err != nil {
533
+ if err := getAndPublishCapabilities (& domainCtx , CurrentHypervisor ()); err != nil {
520
534
log .Warnf ("getAndPublishCapabilities: %v" , err )
521
535
} else {
522
536
capabilitiesSent = true
@@ -542,7 +556,7 @@ func Run(ps *pubsub.PubSub, loggerArg *logrus.Logger, logArg *base.LogObject, ar
542
556
var resources types.HostMemory
543
557
for i := 0 ; true ; i ++ {
544
558
delay := 10
545
- resources , err = hypervisor . CurrentHypervisor ().GetHostCPUMem ()
559
+ resources , err = CurrentHypervisor ().GetHostCPUMem ()
546
560
if err == nil {
547
561
break
548
562
}
@@ -930,7 +944,7 @@ func verifyStatus(ctx *domainContext, status *types.DomainStatus) {
930
944
configActivate = true
931
945
}
932
946
933
- domainID , domainStatus , err := hypervisor . CurrentHypervisor ().Task (status ).Info (status .DomainName )
947
+ domainID , domainStatus , err := CurrentHypervisor ().Task (status ).Info (status .DomainName )
934
948
if err != nil || domainStatus == types .HALTED {
935
949
if status .Activated && configActivate {
936
950
if err == nil {
@@ -963,10 +977,10 @@ func verifyStatus(ctx *domainContext, status *types.DomainStatus) {
963
977
}
964
978
965
979
//cleanup app instance tasks
966
- if err := hypervisor . CurrentHypervisor ().Task (status ).Delete (status .DomainName ); err != nil {
980
+ if err := CurrentHypervisor ().Task (status ).Delete (status .DomainName ); err != nil {
967
981
log .Errorf ("failed to delete domain: %s (%v)" , status .DomainName , err )
968
982
}
969
- if err := hypervisor . CurrentHypervisor ().Task (status ).Cleanup (status .DomainName ); err != nil {
983
+ if err := CurrentHypervisor ().Task (status ).Cleanup (status .DomainName ); err != nil {
970
984
log .Errorf ("failed to cleanup domain: %s (%v)" , status .DomainName , err )
971
985
}
972
986
}
@@ -1104,7 +1118,7 @@ func maybeRetryBoot(ctx *domainContext, status *types.DomainStatus) {
1104
1118
}
1105
1119
defer file .Close ()
1106
1120
1107
- if err := hypervisor . CurrentHypervisor ().Task (status ).Setup (* status , * config , ctx .assignableAdapters , nil , file ); err != nil {
1121
+ if err := CurrentHypervisor ().Task (status ).Setup (* status , * config , ctx .assignableAdapters , nil , file ); err != nil {
1108
1122
//it is retry, so omit error
1109
1123
log .Errorf ("Failed to create DomainStatus from %v: %s" ,
1110
1124
config , err )
@@ -1383,14 +1397,14 @@ func doAssignIoAdaptersToDomain(ctx *domainContext, config types.DomainConfig,
1383
1397
1384
1398
}
1385
1399
for i , long := range assignmentsPci {
1386
- err := hypervisor . CurrentHypervisor ().PCIReserve (long )
1400
+ err := CurrentHypervisor ().PCIReserve (long )
1387
1401
if err != nil {
1388
1402
// Undo what we assigned
1389
1403
for j , long := range assignmentsPci {
1390
1404
if j >= i {
1391
1405
break
1392
1406
}
1393
- hypervisor . CurrentHypervisor ().PCIRelease (long )
1407
+ CurrentHypervisor ().PCIRelease (long )
1394
1408
}
1395
1409
if publishAssignableAdapters {
1396
1410
ctx .publishAssignableAdapters ()
@@ -1567,7 +1581,7 @@ func doActivate(ctx *domainContext, config types.DomainConfig,
1567
1581
defer file .Close ()
1568
1582
1569
1583
globalConfig := agentlog .GetGlobalConfig (log , ctx .subGlobalConfig )
1570
- if err := hypervisor . CurrentHypervisor ().Task (status ).Setup (* status , config , ctx .assignableAdapters , globalConfig , file ); err != nil {
1584
+ if err := CurrentHypervisor ().Task (status ).Setup (* status , config , ctx .assignableAdapters , globalConfig , file ); err != nil {
1571
1585
log .Errorf ("Failed to create DomainStatus from %v: %s" ,
1572
1586
config , err )
1573
1587
status .SetErrorNow (err .Error ())
@@ -1626,17 +1640,17 @@ func doActivateTail(ctx *domainContext, status *types.DomainStatus,
1626
1640
status .State = types .BOOTING
1627
1641
publishDomainStatus (ctx , status )
1628
1642
1629
- err := hypervisor . CurrentHypervisor ().Task (status ).Start (status .DomainName )
1643
+ err := CurrentHypervisor ().Task (status ).Start (status .DomainName )
1630
1644
if err != nil {
1631
1645
log .Errorf ("domain start for %s: %s" , status .DomainName , err )
1632
1646
status .SetErrorNow (err .Error ())
1633
1647
1634
1648
// Delete
1635
- if err := hypervisor . CurrentHypervisor ().Task (status ).Delete (status .DomainName ); err != nil {
1649
+ if err := CurrentHypervisor ().Task (status ).Delete (status .DomainName ); err != nil {
1636
1650
log .Errorf ("failed to delete domain: %s (%v)" , status .DomainName , err )
1637
1651
}
1638
1652
// Cleanup
1639
- if err := hypervisor . CurrentHypervisor ().Task (status ).Cleanup (status .DomainName ); err != nil {
1653
+ if err := CurrentHypervisor ().Task (status ).Cleanup (status .DomainName ); err != nil {
1640
1654
log .Errorf ("failed to cleanup domain: %s (%v)" , status .DomainName , err )
1641
1655
}
1642
1656
@@ -1650,7 +1664,7 @@ func doActivateTail(ctx *domainContext, status *types.DomainStatus,
1650
1664
status .VifList = checkIfEmu (status .VifList )
1651
1665
1652
1666
status .State = types .RUNNING
1653
- domainID , state , err := hypervisor . CurrentHypervisor ().Task (status ).Info (status .DomainName )
1667
+ domainID , state , err := CurrentHypervisor ().Task (status ).Info (status .DomainName )
1654
1668
1655
1669
if err != nil {
1656
1670
// Immediate failure treat as above
@@ -1661,11 +1675,11 @@ func doActivateTail(ctx *domainContext, status *types.DomainStatus,
1661
1675
log .Errorf ("doActivateTail(%v) failed for %s: %s" ,
1662
1676
status .UUIDandVersion , status .DisplayName , err )
1663
1677
// Delete
1664
- if err := hypervisor . CurrentHypervisor ().Task (status ).Delete (status .DomainName ); err != nil {
1678
+ if err := CurrentHypervisor ().Task (status ).Delete (status .DomainName ); err != nil {
1665
1679
log .Errorf ("failed to delete domain: %s (%v)" , status .DomainName , err )
1666
1680
}
1667
1681
// Cleanup
1668
- if err := hypervisor . CurrentHypervisor ().Task (status ).Cleanup (status .DomainName ); err != nil {
1682
+ if err := CurrentHypervisor ().Task (status ).Cleanup (status .DomainName ); err != nil {
1669
1683
log .Errorf ("failed to cleanup domain: %s (%v)" , status .DomainName , err )
1670
1684
}
1671
1685
return
@@ -1710,7 +1724,7 @@ func doInactivate(ctx *domainContext, status *types.DomainStatus, impatient bool
1710
1724
1711
1725
log .Functionf ("doInactivate(%v) for %s domainId %d" ,
1712
1726
status .UUIDandVersion , status .DisplayName , status .DomainId )
1713
- domainID , _ , err := hypervisor . CurrentHypervisor ().Task (status ).Info (status .DomainName )
1727
+ domainID , _ , err := CurrentHypervisor ().Task (status ).Info (status .DomainName )
1714
1728
if err == nil && domainID != status .DomainId {
1715
1729
status .DomainId = domainID
1716
1730
status .BootTime = time .Now ()
@@ -1784,7 +1798,7 @@ func doInactivate(ctx *domainContext, status *types.DomainStatus, impatient bool
1784
1798
}
1785
1799
1786
1800
if status .DomainId != 0 {
1787
- if err := hypervisor . CurrentHypervisor ().Task (status ).Delete (status .DomainName ); err != nil {
1801
+ if err := CurrentHypervisor ().Task (status ).Delete (status .DomainName ); err != nil {
1788
1802
log .Errorf ("Failed to delete domain %s (%v)" , status .DomainName , err )
1789
1803
} else {
1790
1804
log .Functionf ("doInactivate(%v) for %s: Delete succeeded" ,
@@ -1802,7 +1816,7 @@ func doInactivate(ctx *domainContext, status *types.DomainStatus, impatient bool
1802
1816
}
1803
1817
1804
1818
func doCleanup (ctx * domainContext , status * types.DomainStatus ) {
1805
- if err := hypervisor . CurrentHypervisor ().Task (status ).Cleanup (status .DomainName ); err != nil {
1819
+ if err := CurrentHypervisor ().Task (status ).Cleanup (status .DomainName ); err != nil {
1806
1820
log .Errorf ("failed to cleanup domain: %s (%v)" , status .DomainName , err )
1807
1821
}
1808
1822
@@ -1906,7 +1920,7 @@ func releaseAdapters(ctx *domainContext, ioAdapterList []types.IoAdapter,
1906
1920
checkIoBundleAll (ctx )
1907
1921
}
1908
1922
for _ , long := range assignments {
1909
- err := hypervisor . CurrentHypervisor ().PCIRelease (long )
1923
+ err := CurrentHypervisor ().PCIRelease (long )
1910
1924
if err != nil && ! ignoreErrors {
1911
1925
status .SetErrorNow (err .Error ())
1912
1926
}
@@ -2275,7 +2289,7 @@ func waitForDomainGone(status types.DomainStatus, maxDelay time.Duration) bool {
2275
2289
time .Sleep (delay )
2276
2290
waited += delay
2277
2291
}
2278
- _ , state , err := hypervisor . CurrentHypervisor ().Task (& status ).Info (status .DomainName )
2292
+ _ , state , err := CurrentHypervisor ().Task (& status ).Info (status .DomainName )
2279
2293
if err != nil {
2280
2294
log .Errorf ("waitForDomainGone(%v) for %s error %s state %s" ,
2281
2295
status .UUIDandVersion , status .DisplayName ,
@@ -2363,7 +2377,7 @@ func DomainCreate(ctx *domainContext, status types.DomainStatus) (int, error) {
2363
2377
log .Errorf ("DomainCreate(%s) no DomainConfig" , status .Key ())
2364
2378
return 0 , fmt .Errorf ("DomainCreate(%s) no DomainConfig" , status .Key ())
2365
2379
}
2366
- domainID , err = hypervisor . CurrentHypervisor ().Task (& status ).Create (status .DomainName , filename , config )
2380
+ domainID , err = CurrentHypervisor ().Task (& status ).Create (status .DomainName , filename , config )
2367
2381
2368
2382
return domainID , err
2369
2383
}
@@ -2376,7 +2390,7 @@ func DomainShutdown(status types.DomainStatus, force bool) error {
2376
2390
2377
2391
// Stop the domain
2378
2392
log .Functionf ("Stopping domain - %s" , status .DomainName )
2379
- err = hypervisor . CurrentHypervisor ().Task (& status ).Stop (status .DomainName , force )
2393
+ err = CurrentHypervisor ().Task (& status ).Stop (status .DomainName , force )
2380
2394
2381
2395
return err
2382
2396
}
@@ -2833,7 +2847,7 @@ func handlePhysicalIOAdapterListImpl(ctxArg interface{}, key string,
2833
2847
len (aa .IoBundleList ))
2834
2848
2835
2849
// check for mismatched PCI-ids and assignment groups and mark as errors
2836
- aa .CheckBadAssignmentGroups (log , hypervisor . CurrentHypervisor ().PCISameController )
2850
+ aa .CheckBadAssignmentGroups (log , CurrentHypervisor ().PCISameController )
2837
2851
for i := range aa .IoBundleList {
2838
2852
ib := & aa .IoBundleList [i ]
2839
2853
log .Functionf ("handlePhysicalIOAdapterListImpl: new Adapter: %+v" ,
@@ -2878,7 +2892,7 @@ func handlePhysicalIOAdapterListImpl(ctxArg interface{}, key string,
2878
2892
aa .AddOrUpdateIoBundle (log , * ib )
2879
2893
2880
2894
// check for mismatched PCI-ids and assignment groups and mark as errors
2881
- aa .CheckBadAssignmentGroups (log , hypervisor . CurrentHypervisor ().PCISameController )
2895
+ aa .CheckBadAssignmentGroups (log , CurrentHypervisor ().PCISameController )
2882
2896
// Lookup since it could have changed
2883
2897
ib = aa .LookupIoBundlePhylabel (ib .Phylabel )
2884
2898
updatePortAndPciBackIoBundle (ctx , ib )
@@ -2979,7 +2993,7 @@ func updatePortAndPciBackIoBundle(ctx *domainContext, ib *types.IoBundle) (chang
2979
2993
// expand list to include other PCI functions on the same PCI controller
2980
2994
// since they need to be treated as part of the same bundle even if the
2981
2995
// EVE controller doesn't know it
2982
- list = aa .ExpandControllers (log , list , hypervisor . CurrentHypervisor ().PCISameController )
2996
+ list = aa .ExpandControllers (log , list , CurrentHypervisor ().PCISameController )
2983
2997
for _ , ib := range list {
2984
2998
if types .IsPort (ctx .deviceNetworkStatus , ib .Ifname ) {
2985
2999
isPort = true
@@ -3065,7 +3079,7 @@ func updatePortAndPciBackIoMember(ctx *domainContext, ib *types.IoBundle, isPort
3065
3079
if ib .PciLong != "" {
3066
3080
log .Functionf ("updatePortAndPciBackIoMember: Removing %s (%s) from pciback" ,
3067
3081
ib .Phylabel , ib .PciLong )
3068
- err = hypervisor . CurrentHypervisor ().PCIRelease (ib .PciLong )
3082
+ err = CurrentHypervisor ().PCIRelease (ib .PciLong )
3069
3083
if err != nil {
3070
3084
err = fmt .Errorf ("adapter %s (group %s, type %d) PCI ID %s; not released by hypervisor: %v" ,
3071
3085
ib .Phylabel , ib .AssignmentGroup , ib .Type ,
@@ -3112,7 +3126,7 @@ func updatePortAndPciBackIoMember(ctx *domainContext, ib *types.IoBundle, isPort
3112
3126
} else if ib .PciLong != "" && ib .UsbAddr == "" {
3113
3127
log .Noticef ("Assigning %s (%s) to pciback" ,
3114
3128
ib .Phylabel , ib .PciLong )
3115
- err := hypervisor . CurrentHypervisor ().PCIReserve (ib .PciLong )
3129
+ err := CurrentHypervisor ().PCIReserve (ib .PciLong )
3116
3130
if err != nil {
3117
3131
return changed , err
3118
3132
}
@@ -3353,7 +3367,7 @@ func handleIBDelete(ctx *domainContext, phylabel string) {
3353
3367
log .Functionf ("handleIBDelete: Assigning %s (%s) back" ,
3354
3368
ib .Phylabel , ib .PciLong )
3355
3369
if ib .PciLong != "" {
3356
- err := hypervisor . CurrentHypervisor ().PCIRelease (ib .PciLong )
3370
+ err := CurrentHypervisor ().PCIRelease (ib .PciLong )
3357
3371
if err != nil {
3358
3372
log .Errorf ("handleIBDelete(%d %s %s) PCIRelease %s failed %v" ,
3359
3373
ib .Type , ib .Phylabel , ib .AssignmentGroup , ib .PciLong , err )
0 commit comments