forked from libvirt/libvirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibvirt-host.c
1480 lines (1269 loc) · 43 KB
/
libvirt-host.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* libvirt-host.c: entry points for vir{Connect,Node}Ptr APIs
*
* Copyright (C) 2006-2015 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <sys/stat.h>
#include "datatypes.h"
#include "viralloc.h"
#include "virlog.h"
#include "virtypedparam.h"
VIR_LOG_INIT("libvirt.host");
#define VIR_FROM_THIS VIR_FROM_DOMAIN
/**
* virConnectRef:
* @conn: the connection to hold a reference on
*
* Increment the reference count on the connection. For each
* additional call to this method, there shall be a corresponding
* call to virConnectClose to release the reference count, once
* the caller no longer needs the reference to this object.
*
* This method is typically useful for applications where multiple
* threads are using a connection, and it is required that the
* connection remain open until all threads have finished using
* it. ie, each new thread using a connection would increment
* the reference count.
*
* Returns 0 in case of success, -1 in case of failure
*/
int
virConnectRef(virConnectPtr conn)
{
VIR_DEBUG("conn=%p refs=%d", conn, conn ? conn->object.parent.u.s.refs : 0);
virResetLastError();
virCheckConnectReturn(conn, -1);
virObjectRef(conn);
return 0;
}
/*
* Not for public use. This function is part of the internal
* implementation of driver features in the remote case.
*/
int
virConnectSupportsFeature(virConnectPtr conn, int feature)
{
int ret;
VIR_DEBUG("conn=%p, feature=%d", conn, feature);
virResetLastError();
virCheckConnectReturn(conn, -1);
if (!conn->driver->connectSupportsFeature)
ret = 0;
else
ret = conn->driver->connectSupportsFeature(conn, feature);
if (ret < 0)
virDispatchError(conn);
return ret;
}
/**
* virConnectGetType:
* @conn: pointer to the hypervisor connection
*
* Get the name of the Hypervisor driver used. This is merely the driver
* name; for example, both KVM and QEMU guests are serviced by the
* driver for the qemu:// URI, so a return of "QEMU" does not indicate
* whether KVM acceleration is present. For more details about the
* hypervisor, use virConnectGetCapabilities().
*
* Returns NULL in case of error, a static zero terminated string otherwise.
*
* See also:
* http://www.redhat.com/archives/libvir-list/2007-February/msg00096.html
*/
const char *
virConnectGetType(virConnectPtr conn)
{
const char *ret;
VIR_DEBUG("conn=%p", conn);
virResetLastError();
virCheckConnectReturn(conn, NULL);
if (conn->driver->connectGetType) {
ret = conn->driver->connectGetType(conn);
if (ret) return ret;
}
return conn->driver->name;
}
/**
* virConnectGetVersion:
* @conn: pointer to the hypervisor connection
* @hvVer: return value for the version of the running hypervisor (OUT)
*
* Get the version level of the Hypervisor running. This may work only with
* hypervisor call, i.e. with privileged access to the hypervisor, not
* with a Read-Only connection.
*
* Returns -1 in case of error, 0 otherwise. if the version can't be
* extracted by lack of capacities returns 0 and @hvVer is 0, otherwise
* @hvVer value is major * 1,000,000 + minor * 1,000 + release
*/
int
virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer)
{
VIR_DEBUG("conn=%p, hvVer=%p", conn, hvVer);
virResetLastError();
virCheckConnectReturn(conn, -1);
virCheckNonNullArgGoto(hvVer, error);
if (conn->driver->connectGetVersion) {
int ret = conn->driver->connectGetVersion(conn, hvVer);
if (ret < 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return -1;
}
/**
* virConnectGetLibVersion:
* @conn: pointer to the hypervisor connection
* @libVer: returns the libvirt library version used on the connection (OUT)
*
* Provides @libVer, which is the version of libvirt used by the
* daemon running on the @conn host
*
* Returns -1 in case of failure, 0 otherwise, and values for @libVer have
* the format major * 1,000,000 + minor * 1,000 + release.
*/
int
virConnectGetLibVersion(virConnectPtr conn, unsigned long *libVer)
{
int ret = -1;
VIR_DEBUG("conn=%p, libVir=%p", conn, libVer);
virResetLastError();
virCheckConnectReturn(conn, -1);
virCheckNonNullArgGoto(libVer, error);
if (conn->driver->connectGetLibVersion) {
ret = conn->driver->connectGetLibVersion(conn, libVer);
if (ret < 0)
goto error;
return ret;
}
*libVer = LIBVIR_VERSION_NUMBER;
return 0;
error:
virDispatchError(conn);
return ret;
}
/**
* virConnectGetHostname:
* @conn: pointer to a hypervisor connection
*
* This returns a system hostname on which the hypervisor is
* running (based on the result of the gethostname system call, but
* possibly expanded to a fully-qualified domain name via getaddrinfo).
* If we are connected to a remote system, then this returns the
* hostname of the remote system.
*
* Returns the hostname which must be freed by the caller, or
* NULL if there was an error.
*/
char *
virConnectGetHostname(virConnectPtr conn)
{
VIR_DEBUG("conn=%p", conn);
virResetLastError();
virCheckConnectReturn(conn, NULL);
if (conn->driver->connectGetHostname) {
char *ret = conn->driver->connectGetHostname(conn);
if (!ret)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return NULL;
}
/**
* virConnectGetURI:
* @conn: pointer to a hypervisor connection
*
* This returns the URI (name) of the hypervisor connection.
* Normally this is the same as or similar to the string passed
* to the virConnectOpen/virConnectOpenReadOnly call, but
* the driver may make the URI canonical. If name == NULL
* was passed to virConnectOpen, then the driver will return
* a non-NULL URI which can be used to connect to the same
* hypervisor later.
*
* Returns the URI string which must be freed by the caller, or
* NULL if there was an error.
*/
char *
virConnectGetURI(virConnectPtr conn)
{
char *name;
VIR_DEBUG("conn=%p", conn);
virResetLastError();
virCheckConnectReturn(conn, NULL);
if (!(name = virURIFormat(conn->uri)))
goto error;
return name;
error:
virDispatchError(conn);
return NULL;
}
/**
* virConnectGetSysinfo:
* @conn: pointer to a hypervisor connection
* @flags: extra flags; not used yet, so callers should always pass 0
*
* This returns the XML description of the sysinfo details for the
* host on which the hypervisor is running, in the same format as the
* <sysinfo> element of a domain XML. This information is generally
* available only for hypervisors running with root privileges.
*
* Returns the XML string which must be freed by the caller, or
* NULL if there was an error.
*/
char *
virConnectGetSysinfo(virConnectPtr conn, unsigned int flags)
{
VIR_DEBUG("conn=%p, flags=%x", conn, flags);
virResetLastError();
virCheckConnectReturn(conn, NULL);
if (conn->driver->connectGetSysinfo) {
char *ret = conn->driver->connectGetSysinfo(conn, flags);
if (!ret)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return NULL;
}
/**
* virConnectGetMaxVcpus:
* @conn: pointer to the hypervisor connection
* @type: value of the 'type' attribute in the <domain> element
*
* Provides the maximum number of virtual CPUs supported for a guest VM of a
* specific type. The 'type' parameter here corresponds to the 'type'
* attribute in the <domain> element of the XML.
*
* Returns the maximum of virtual CPU or -1 in case of error.
*/
int
virConnectGetMaxVcpus(virConnectPtr conn,
const char *type)
{
VIR_DEBUG("conn=%p, type=%s", conn, NULLSTR(type));
virResetLastError();
virCheckConnectReturn(conn, -1);
if (conn->driver->connectGetMaxVcpus) {
int ret = conn->driver->connectGetMaxVcpus(conn, type);
if (ret < 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return -1;
}
/**
* virNodeGetInfo:
* @conn: pointer to the hypervisor connection
* @info: pointer to a virNodeInfo structure allocated by the user
*
* Extract hardware information about the node.
*
* Returns 0 in case of success and -1 in case of failure.
*/
int
virNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
{
VIR_DEBUG("conn=%p, info=%p", conn, info);
virResetLastError();
virCheckConnectReturn(conn, -1);
virCheckNonNullArgGoto(info, error);
if (conn->driver->nodeGetInfo) {
int ret;
ret = conn->driver->nodeGetInfo(conn, info);
if (ret < 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return -1;
}
/**
* virConnectGetCapabilities:
* @conn: pointer to the hypervisor connection
*
* Provides capabilities of the hypervisor / driver.
*
* Returns NULL in case of error, or an XML string
* defining the capabilities.
* The client must free the returned string after use.
*/
char *
virConnectGetCapabilities(virConnectPtr conn)
{
VIR_DEBUG("conn=%p", conn);
virResetLastError();
virCheckConnectReturn(conn, NULL);
if (conn->driver->connectGetCapabilities) {
char *ret;
ret = conn->driver->connectGetCapabilities(conn);
if (!ret)
goto error;
VIR_DEBUG("conn=%p ret=%s", conn, ret);
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return NULL;
}
/**
* virNodeGetCPUStats:
* @conn: pointer to the hypervisor connection.
* @cpuNum: number of node cpu. (VIR_NODE_CPU_STATS_ALL_CPUS means total cpu
* statistics)
* @params: pointer to node cpu time parameter objects
* @nparams: number of node cpu time parameter (this value should be same or
* less than the number of parameters supported)
* @flags: extra flags; not used yet, so callers should always pass 0
*
* This function provides individual cpu statistics of the node.
* If you want to get total cpu statistics of the node, you must specify
* VIR_NODE_CPU_STATS_ALL_CPUS to @cpuNum.
* The @params array will be filled with the values equal to the number of
* parameters suggested by @nparams
*
* As the value of @nparams is dynamic, call the API setting @nparams to 0 and
* @params as NULL, the API returns the number of parameters supported by the
* HV by updating @nparams on SUCCESS. The caller should then allocate @params
* array, i.e. (sizeof(@virNodeCPUStats) * @nparams) bytes and call
* the API again.
*
* Here is a sample code snippet:
*
* if (virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, 0) == 0 &&
* nparams != 0) {
* if ((params = malloc(sizeof(virNodeCPUStats) * nparams)) == NULL)
* goto error;
* memset(params, 0, sizeof(virNodeCPUStats) * nparams);
* if (virNodeGetCPUStats(conn, cpuNum, params, &nparams, 0))
* goto error;
* }
*
* This function doesn't require privileged access to the hypervisor.
* This function expects the caller to allocate the @params.
*
* CPU time Statistics:
*
* VIR_NODE_CPU_STATS_KERNEL:
* The cumulative CPU time which spends by kernel,
* when the node booting up.(nanoseconds)
* VIR_NODE_CPU_STATS_USER:
* The cumulative CPU time which spends by user processes,
* when the node booting up.(nanoseconds)
* VIR_NODE_CPU_STATS_IDLE:
* The cumulative idle CPU time, when the node booting up.(nanoseconds)
* VIR_NODE_CPU_STATS_IOWAIT:
* The cumulative I/O wait CPU time, when the node booting up.(nanoseconds)
* VIR_NODE_CPU_STATS_UTILIZATION:
* The CPU utilization. The usage value is in percent and 100%
* represents all CPUs on the server.
*
* Returns -1 in case of error, 0 in case of success.
*/
int
virNodeGetCPUStats(virConnectPtr conn,
int cpuNum,
virNodeCPUStatsPtr params,
int *nparams, unsigned int flags)
{
VIR_DEBUG("conn=%p, cpuNum=%d, params=%p, nparams=%d, flags=%x",
conn, cpuNum, params, nparams ? *nparams : -1, flags);
virResetLastError();
virCheckConnectReturn(conn, -1);
virCheckNonNullArgGoto(nparams, error);
virCheckNonNegativeArgGoto(*nparams, error);
if (cpuNum < 0 && cpuNum != VIR_NODE_CPU_STATS_ALL_CPUS) {
virReportInvalidArg(cpuNum,
_("cpuNum in %s only accepts %d as a negative "
"value"),
__FUNCTION__, VIR_NODE_CPU_STATS_ALL_CPUS);
goto error;
}
if (conn->driver->nodeGetCPUStats) {
int ret;
ret = conn->driver->nodeGetCPUStats(conn, cpuNum, params, nparams, flags);
if (ret < 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return -1;
}
/**
* virNodeGetMemoryStats:
* @conn: pointer to the hypervisor connection.
* @cellNum: number of node cell. (VIR_NODE_MEMORY_STATS_ALL_CELLS means total
* cell statistics)
* @params: pointer to node memory stats objects
* @nparams: number of node memory stats (this value should be same or
* less than the number of stats supported)
* @flags: extra flags; not used yet, so callers should always pass 0
*
* This function provides memory stats of the node.
* If you want to get total memory statistics of the node, you must specify
* VIR_NODE_MEMORY_STATS_ALL_CELLS to @cellNum.
* The @params array will be filled with the values equal to the number of
* stats suggested by @nparams
*
* As the value of @nparams is dynamic, call the API setting @nparams to 0 and
* @params as NULL, the API returns the number of parameters supported by the
* HV by updating @nparams on SUCCESS. The caller should then allocate @params
* array, i.e. (sizeof(@virNodeMemoryStats) * @nparams) bytes and call
* the API again.
*
* Here is the sample code snippet:
*
* if (virNodeGetMemoryStats(conn, cellNum, NULL, &nparams, 0) == 0 &&
* nparams != 0) {
* if ((params = malloc(sizeof(virNodeMemoryStats) * nparams)) == NULL)
* goto error;
* memset(params, cellNum, 0, sizeof(virNodeMemoryStats) * nparams);
* if (virNodeGetMemoryStats(conn, params, &nparams, 0))
* goto error;
* }
*
* This function doesn't require privileged access to the hypervisor.
* This function expects the caller to allocate the @params.
*
* Memory Stats:
*
* VIR_NODE_MEMORY_STATS_TOTAL:
* The total memory usage.(KB)
* VIR_NODE_MEMORY_STATS_FREE:
* The free memory usage.(KB)
* On linux, this usage includes buffers and cached.
* VIR_NODE_MEMORY_STATS_BUFFERS:
* The buffers memory usage.(KB)
* VIR_NODE_MEMORY_STATS_CACHED:
* The cached memory usage.(KB)
*
* Returns -1 in case of error, 0 in case of success.
*/
int
virNodeGetMemoryStats(virConnectPtr conn,
int cellNum,
virNodeMemoryStatsPtr params,
int *nparams, unsigned int flags)
{
VIR_DEBUG("conn=%p, cellNum=%d, params=%p, nparams=%d, flags=%x",
conn, cellNum, params, nparams ? *nparams : -1, flags);
virResetLastError();
virCheckConnectReturn(conn, -1);
virCheckNonNullArgGoto(nparams, error);
virCheckNonNegativeArgGoto(*nparams, error);
if (cellNum < 0 && cellNum != VIR_NODE_MEMORY_STATS_ALL_CELLS) {
virReportInvalidArg(cpuNum,
_("cellNum in %s only accepts %d as a negative "
"value"),
__FUNCTION__, VIR_NODE_MEMORY_STATS_ALL_CELLS);
goto error;
}
if (conn->driver->nodeGetMemoryStats) {
int ret;
ret = conn->driver->nodeGetMemoryStats(conn, cellNum, params, nparams, flags);
if (ret < 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return -1;
}
/**
* virNodeGetFreeMemory:
* @conn: pointer to the hypervisor connection
*
* provides the free memory available on the Node
* Note: most libvirt APIs provide memory sizes in kibibytes, but in this
* function the returned value is in bytes. Divide by 1024 as necessary.
*
* Returns the available free memory in bytes or 0 in case of error
*/
unsigned long long
virNodeGetFreeMemory(virConnectPtr conn)
{
VIR_DEBUG("conn=%p", conn);
virResetLastError();
virCheckConnectReturn(conn, 0);
if (conn->driver->nodeGetFreeMemory) {
unsigned long long ret;
ret = conn->driver->nodeGetFreeMemory(conn);
if (ret == 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return 0;
}
/**
* virNodeSuspendForDuration:
* @conn: pointer to the hypervisor connection
* @target: the state to which the host must be suspended to,
* such as: VIR_NODE_SUSPEND_TARGET_MEM (Suspend-to-RAM)
* VIR_NODE_SUSPEND_TARGET_DISK (Suspend-to-Disk)
* VIR_NODE_SUSPEND_TARGET_HYBRID (Hybrid-Suspend,
* which is a combination of the former modes).
* @duration: the time duration in seconds for which the host
* has to be suspended
* @flags: extra flags; not used yet, so callers should always pass 0
*
* Attempt to suspend the node (host machine) for the given duration of
* time in the specified state (Suspend-to-RAM, Suspend-to-Disk or
* Hybrid-Suspend). Schedule the node's Real-Time-Clock interrupt to
* resume the node after the duration is complete.
*
* Returns 0 on success (i.e., the node will be suspended after a short
* delay), -1 on failure (the operation is not supported, or an attempted
* suspend is already underway).
*/
int
virNodeSuspendForDuration(virConnectPtr conn,
unsigned int target,
unsigned long long duration,
unsigned int flags)
{
VIR_DEBUG("conn=%p, target=%d, duration=%lld, flags=%x",
conn, target, duration, flags);
virResetLastError();
virCheckConnectReturn(conn, -1);
virCheckReadOnlyGoto(conn->flags, error);
if (conn->driver->nodeSuspendForDuration) {
int ret;
ret = conn->driver->nodeSuspendForDuration(conn, target,
duration, flags);
if (ret < 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return -1;
}
/*
* virNodeGetMemoryParameters:
* @conn: pointer to the hypervisor connection
* @params: pointer to memory parameter object
* (return value, allocated by the caller)
* @nparams: pointer to number of memory parameters; input and output
* @flags: extra flags; not used yet, so callers should always pass 0
*
* Get all node memory parameters (parameters unsupported by OS will be
* omitted). On input, @nparams gives the size of the @params array;
* on output, @nparams gives how many slots were filled with parameter
* information, which might be less but will not exceed the input value.
*
* As a special case, calling with @params as NULL and @nparams as 0 on
* input will cause @nparams on output to contain the number of parameters
* supported by the hypervisor. The caller should then allocate @params
* array, i.e. (sizeof(@virTypedParameter) * @nparams) bytes and call the API
* again. See virDomainGetMemoryParameters() for an equivalent usage
* example.
*
* Returns 0 in case of success, and -1 in case of failure.
*/
int
virNodeGetMemoryParameters(virConnectPtr conn,
virTypedParameterPtr params,
int *nparams,
unsigned int flags)
{
VIR_DEBUG("conn=%p, params=%p, nparams=%p, flags=%x",
conn, params, nparams, flags);
virResetLastError();
virCheckConnectReturn(conn, -1);
virCheckNonNullArgGoto(nparams, error);
virCheckNonNegativeArgGoto(*nparams, error);
if (*nparams != 0)
virCheckNonNullArgGoto(params, error);
if (VIR_DRV_SUPPORTS_FEATURE(conn->driver, conn,
VIR_DRV_FEATURE_TYPED_PARAM_STRING))
flags |= VIR_TYPED_PARAM_STRING_OKAY;
if (conn->driver->nodeGetMemoryParameters) {
int ret;
ret = conn->driver->nodeGetMemoryParameters(conn, params,
nparams, flags);
if (ret < 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return -1;
}
/*
* virNodeSetMemoryParameters:
* @conn: pointer to the hypervisor connection
* @params: pointer to scheduler parameter objects
* @nparams: number of scheduler parameter objects
* (this value can be the same or less than the returned
* value nparams of virDomainGetSchedulerType)
* @flags: extra flags; not used yet, so callers should always pass 0
*
* Change all or a subset of the node memory tunables. The function
* fails if not all of the tunables are supported.
*
* Note that it's not recommended to use this function while the
* outside tuning program is running (such as ksmtuned under Linux),
* as they could change the tunables in parallel, which could cause
* conflicts.
*
* This function may require privileged access to the hypervisor.
*
* Returns 0 in case of success, -1 in case of failure.
*/
int
virNodeSetMemoryParameters(virConnectPtr conn,
virTypedParameterPtr params,
int nparams,
unsigned int flags)
{
VIR_DEBUG("conn=%p, params=%p, nparams=%d, flags=%x",
conn, params, nparams, flags);
VIR_TYPED_PARAMS_DEBUG(params, nparams);
virResetLastError();
virCheckConnectReturn(conn, -1);
virCheckReadOnlyGoto(conn->flags, error);
virCheckNonNullArgGoto(params, error);
virCheckNonNegativeArgGoto(nparams, error);
if (virTypedParameterValidateSet(conn, params, nparams) < 0)
goto error;
if (conn->driver->nodeSetMemoryParameters) {
int ret;
ret = conn->driver->nodeSetMemoryParameters(conn, params,
nparams, flags);
if (ret < 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return -1;
}
/**
* virNodeGetSecurityModel:
* @conn: a connection object
* @secmodel: pointer to a virSecurityModel structure
*
* Extract the security model of a hypervisor. The 'model' field
* in the @secmodel argument may be initialized to the empty
* string if the driver has not activated a security model.
*
* Returns 0 in case of success, -1 in case of failure
*/
int
virNodeGetSecurityModel(virConnectPtr conn, virSecurityModelPtr secmodel)
{
VIR_DEBUG("conn=%p secmodel=%p", conn, secmodel);
virResetLastError();
virCheckConnectReturn(conn, -1);
virCheckNonNullArgGoto(secmodel, error);
if (conn->driver->nodeGetSecurityModel) {
int ret;
ret = conn->driver->nodeGetSecurityModel(conn, secmodel);
if (ret < 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return -1;
}
/**
* virNodeGetCellsFreeMemory:
* @conn: pointer to the hypervisor connection
* @freeMems: pointer to the array of unsigned long long
* @startCell: index of first cell to return freeMems info on.
* @maxCells: Maximum number of cells for which freeMems information can
* be returned.
*
* This call returns the amount of free memory in one or more NUMA cells.
* The @freeMems array must be allocated by the caller and will be filled
* with the amount of free memory in bytes for each cell requested,
* starting with startCell (in freeMems[0]), up to either
* (startCell + maxCells), or the number of additional cells in the node,
* whichever is smaller.
*
* Returns the number of entries filled in freeMems, or -1 in case of error.
*/
int
virNodeGetCellsFreeMemory(virConnectPtr conn, unsigned long long *freeMems,
int startCell, int maxCells)
{
VIR_DEBUG("conn=%p, freeMems=%p, startCell=%d, maxCells=%d",
conn, freeMems, startCell, maxCells);
virResetLastError();
virCheckConnectReturn(conn, -1);
virCheckNonNullArgGoto(freeMems, error);
virCheckPositiveArgGoto(maxCells, error);
virCheckNonNegativeArgGoto(startCell, error);
if (conn->driver->nodeGetCellsFreeMemory) {
int ret;
ret = conn->driver->nodeGetCellsFreeMemory(conn, freeMems, startCell, maxCells);
if (ret < 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return -1;
}
/**
* virConnectIsEncrypted:
* @conn: pointer to the connection object
*
* Determine if the connection to the hypervisor is encrypted
*
* Returns 1 if encrypted, 0 if not encrypted, -1 on error
*/
int
virConnectIsEncrypted(virConnectPtr conn)
{
VIR_DEBUG("conn=%p", conn);
virResetLastError();
virCheckConnectReturn(conn, -1);
if (conn->driver->connectIsEncrypted) {
int ret;
ret = conn->driver->connectIsEncrypted(conn);
if (ret < 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return -1;
}
/**
* virConnectIsSecure:
* @conn: pointer to the connection object
*
* Determine if the connection to the hypervisor is secure
*
* A connection will be classed as secure if it is either
* encrypted, or running over a channel which is not exposed
* to eavesdropping (eg a UNIX domain socket, or pipe)
*
* Returns 1 if secure, 0 if not secure, -1 on error
*/
int
virConnectIsSecure(virConnectPtr conn)
{
VIR_DEBUG("conn=%p", conn);
virResetLastError();
virCheckConnectReturn(conn, -1);
if (conn->driver->connectIsSecure) {
int ret;
ret = conn->driver->connectIsSecure(conn);
if (ret < 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return -1;
}
/**
* virConnectCompareCPU:
* @conn: virConnect connection
* @xmlDesc: XML describing the CPU to compare with host CPU
* @flags: bitwise-OR of virConnectCompareCPUFlags
*
* Compares the given CPU description with the host CPU
*
* Returns comparison result according to enum virCPUCompareResult. If
* VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE is used and @xmlDesc CPU is
* incompatible with host CPU, this function will return VIR_CPU_COMPARE_ERROR
* (instead of VIR_CPU_COMPARE_INCOMPATIBLE) and the error will use the
* VIR_ERR_CPU_INCOMPATIBLE code with a message providing more details about
* the incompatibility.
*/
int
virConnectCompareCPU(virConnectPtr conn,
const char *xmlDesc,
unsigned int flags)
{
VIR_DEBUG("conn=%p, xmlDesc=%s, flags=%x", conn, NULLSTR(xmlDesc), flags);
virResetLastError();
virCheckConnectReturn(conn, VIR_CPU_COMPARE_ERROR);
virCheckNonNullArgGoto(xmlDesc, error);
if (conn->driver->connectCompareCPU) {
int ret;
ret = conn->driver->connectCompareCPU(conn, xmlDesc, flags);
if (ret == VIR_CPU_COMPARE_ERROR)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return VIR_CPU_COMPARE_ERROR;
}
/**
* virConnectGetCPUModelNames:
*
* @conn: virConnect connection
* @arch: Architecture
* @models: Pointer to a variable to store the NULL-terminated array of the
* CPU models supported for the specified architecture. Each element
* and the array itself must be freed by the caller with free. Pass
* NULL if only the list length is needed.