2 * libvirt.c: Main interfaces for the libvirt library to handle virtualization
3 * domains from a process running in domain 0
5 * Copyright (C) 2005-2006, 2008-2010 Red Hat, Inc.
7 * See COPYING.LIB for the License of this software
9 * Daniel Veillard <veillard@redhat.com>
17 #include <sys/types.h>
25 #include <libxml/parser.h>
26 #include <libxml/xpath.h>
27 #include <libxml/uri.h>
30 #ifdef HAVE_WINSOCK2_H
31 # include <winsock2.h>
34 #include "virterror_internal.h"
36 #include "datatypes.h"
43 #ifndef WITH_DRIVER_MODULES
45 # include "test/test_driver.h"
48 # include "xen/xen_driver.h"
51 # include "remote/remote_driver.h"
54 # include "openvz/openvz_driver.h"
57 # include "phyp/phyp_driver.h"
60 # include "vbox/vbox_driver.h"
63 # include "esx/esx_driver.h"
66 # include "xenapi/xenapi_driver.h"
70 #define VIR_FROM_THIS VIR_FROM_NONE
74 * - use lock to protect against concurrent accesses ?
75 * - use reference counting to guarantee coherent pointer state ?
78 #define MAX_DRIVERS 10
80 static virDriverPtr virDriverTab
[MAX_DRIVERS
];
81 static int virDriverTabCount
= 0;
82 static virNetworkDriverPtr virNetworkDriverTab
[MAX_DRIVERS
];
83 static int virNetworkDriverTabCount
= 0;
84 static virInterfaceDriverPtr virInterfaceDriverTab
[MAX_DRIVERS
];
85 static int virInterfaceDriverTabCount
= 0;
86 static virStorageDriverPtr virStorageDriverTab
[MAX_DRIVERS
];
87 static int virStorageDriverTabCount
= 0;
88 static virDeviceMonitorPtr virDeviceMonitorTab
[MAX_DRIVERS
];
89 static int virDeviceMonitorTabCount
= 0;
90 static virSecretDriverPtr virSecretDriverTab
[MAX_DRIVERS
];
91 static int virSecretDriverTabCount
= 0;
92 static virNWFilterDriverPtr virNWFilterDriverTab
[MAX_DRIVERS
];
93 static int virNWFilterDriverTabCount
= 0;
95 static virStateDriverPtr virStateDriverTab
[MAX_DRIVERS
];
96 static int virStateDriverTabCount
= 0;
98 static int initialized
= 0;
100 #if defined(POLKIT_AUTH)
101 static int virConnectAuthGainPolkit(const char *privilege
) {
102 const char *const args
[] = {
103 POLKIT_AUTH
, "--obtain", privilege
, NULL
105 int childpid
, status
, ret
;
107 /* Root has all rights */
111 if ((childpid
= fork()) < 0)
115 execvp(args
[0], (char **)args
);
119 while ((ret
= waitpid(childpid
, &status
, 0) == -1) && errno
== EINTR
);
124 if (!WIFEXITED(status
) ||
125 (WEXITSTATUS(status
) != 0 && WEXITSTATUS(status
) != 1)) {
133 static int virConnectAuthCallbackDefault(virConnectCredentialPtr cred
,
135 void *cbdata ATTRIBUTE_UNUSED
) {
138 for (i
= 0 ; i
< ncred
; i
++) {
143 switch (cred
[i
].type
) {
144 case VIR_CRED_EXTERNAL
: {
145 if (STRNEQ(cred
[i
].challenge
, "PolicyKit"))
148 #if defined(POLKIT_AUTH)
149 if (virConnectAuthGainPolkit(cred
[i
].prompt
) < 0)
153 * Ignore & carry on. Although we can't auth
154 * directly, the user may have authenticated
155 * themselves already outside context of libvirt
161 case VIR_CRED_USERNAME
:
162 case VIR_CRED_AUTHNAME
:
163 case VIR_CRED_ECHOPROMPT
:
165 if (printf("%s: ", cred
[i
].prompt
) < 0)
167 if (fflush(stdout
) != 0)
170 if (!fgets(buf
, sizeof(buf
), stdin
)) {
171 if (feof(stdin
)) { /* Treat EOF as "" */
178 if (len
!= 0 && buf
[len
-1] == '\n')
182 case VIR_CRED_PASSPHRASE
:
183 case VIR_CRED_NOECHOPROMPT
:
184 if (printf("%s: ", cred
[i
].prompt
) < 0)
186 if (fflush(stdout
) != 0)
189 bufptr
= getpass("");
198 if (cred
[i
].type
!= VIR_CRED_EXTERNAL
) {
199 if (STREQ(bufptr
, "") && cred
[i
].defresult
)
200 cred
[i
].result
= strdup(cred
[i
].defresult
);
202 cred
[i
].result
= strdup(bufptr
);
205 cred
[i
].resultlen
= strlen(cred
[i
].result
);
212 /* Don't typically want VIR_CRED_USERNAME. It enables you to authenticate
213 * as one user, and act as another. It just results in annoying
214 * prompts for the username twice & is very rarely what you want
216 static int virConnectCredTypeDefault
[] = {
221 VIR_CRED_NOECHOPROMPT
,
225 static virConnectAuth virConnectAuthDefault
= {
226 virConnectCredTypeDefault
,
227 sizeof(virConnectCredTypeDefault
)/sizeof(int),
228 virConnectAuthCallbackDefault
,
233 * virConnectAuthPtrDefault
235 * A default implementation of the authentication callbacks. This
236 * implementation is suitable for command line based tools. It will
237 * prompt for username, passwords, realm and one time keys as needed.
238 * It will print on STDOUT, and read from STDIN. If this is not
239 * suitable for the application's needs an alternative implementation
240 * should be provided.
242 virConnectAuthPtr virConnectAuthPtrDefault
= &virConnectAuthDefault
;
248 WORD winsock_version
, err
;
249 WSADATA winsock_data
;
251 /* http://msdn2.microsoft.com/en-us/library/ms742213.aspx */
252 winsock_version
= MAKEWORD (2, 2);
253 err
= WSAStartup (winsock_version
, &winsock_data
);
254 return err
== 0 ? 0 : -1;
258 static int virTLSMutexInit (void **priv
)
260 virMutexPtr lock
= NULL
;
262 if (VIR_ALLOC(lock
) < 0)
265 if (virMutexInit(lock
) < 0) {
274 static int virTLSMutexDestroy(void **priv
)
276 virMutexPtr lock
= *priv
;
277 virMutexDestroy(lock
);
282 static int virTLSMutexLock(void **priv
)
284 virMutexPtr lock
= *priv
;
289 static int virTLSMutexUnlock(void **priv
)
291 virMutexPtr lock
= *priv
;
292 virMutexUnlock(lock
);
296 static struct gcry_thread_cbs virTLSThreadImpl
= {
297 /* GCRY_THREAD_OPTION_VERSION was added in gcrypt 1.4.2 */
298 #ifdef GCRY_THREAD_OPTION_VERSION
299 (GCRY_THREAD_OPTION_PTHREAD
| (GCRY_THREAD_OPTION_VERSION
<< 8)),
301 GCRY_THREAD_OPTION_PTHREAD
,
308 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
315 * Initialize the library. It's better to call this routine at startup
316 * in multithreaded applications to avoid potential race when initializing
319 * Returns 0 in case of success, -1 in case of error
329 if (virThreadInitialize() < 0 ||
330 virErrorInitialize() < 0 ||
331 virRandomInitialize(time(NULL
) ^ getpid()))
334 gcry_control(GCRYCTL_SET_THREAD_CBS
, &virTLSThreadImpl
);
335 gcry_check_version(NULL
);
339 DEBUG0("register drivers");
342 if (winsock_init () == -1) return -1;
345 if (!bindtextdomain(GETTEXT_PACKAGE
, LOCALEBASEDIR
))
349 * Note that the order is important: the first ones have a higher
350 * priority when calling virConnectOpen.
352 #ifdef WITH_DRIVER_MODULES
353 /* We don't care if any of these fail, because the whole point
354 * is to allow users to only install modules they want to use.
355 * If they try to open a connection for a module that
356 * is not loaded they'll get a suitable error at that point
359 virDriverLoadModule("test");
362 virDriverLoadModule("xen");
365 virDriverLoadModule("openvz");
368 virDriverLoadModule("vbox");
371 virDriverLoadModule("esx");
374 virDriverLoadModule("xenapi");
377 virDriverLoadModule("remote");
381 if (testRegister() == -1) return -1;
384 if (xenRegister () == -1) return -1;
387 if (openvzRegister() == -1) return -1;
390 if (phypRegister() == -1) return -1;
393 if (vboxRegister() == -1) return -1;
396 if (esxRegister() == -1) return -1;
399 if (xenapiRegister() == -1) return -1;
402 if (remoteRegister () == -1) return -1;
411 DllMain (HINSTANCE instance
, DWORD reason
, LPVOID ignore
);
414 DllMain (HINSTANCE instance ATTRIBUTE_UNUSED
,
416 LPVOID ignore ATTRIBUTE_UNUSED
)
419 case DLL_PROCESS_ATTACH
:
423 case DLL_THREAD_ATTACH
:
424 /* Nothing todo in libvirt yet */
427 case DLL_THREAD_DETACH
:
428 /* Release per-thread local data */
432 case DLL_PROCESS_DETACH
:
433 /* Don't bother releasing per-thread data
434 since (hopefully) windows cleans up
435 everything on process exit */
446 * @conn: the connection if available
447 * @error: the error number
448 * @info: extra information string
450 * Handle an error at the connection level
453 virLibConnError(virConnectPtr conn
, virErrorNumber error
, const char *info
)
457 if (error
== VIR_ERR_OK
)
460 errmsg
= virErrorMsg(error
, info
);
461 virRaiseError(conn
, NULL
, NULL
, VIR_FROM_NONE
, error
, VIR_ERR_ERROR
,
462 errmsg
, info
, NULL
, 0, 0, errmsg
, info
);
467 * @conn: the connection if available
468 * @error: the error number
469 * @info: extra information string
471 * Handle an error at the connection level
474 virLibConnWarning(virConnectPtr conn
, virErrorNumber error
, const char *info
)
478 if (error
== VIR_ERR_OK
)
481 errmsg
= virErrorMsg(error
, info
);
482 virRaiseError(conn
, NULL
, NULL
, VIR_FROM_NONE
, error
, VIR_ERR_WARNING
,
483 errmsg
, info
, NULL
, 0, 0, errmsg
, info
);
488 * @domain: the domain if available
489 * @error: the error number
490 * @info: extra information string
492 * Handle an error at the connection level
495 virLibDomainError(virDomainPtr domain
, virErrorNumber error
,
498 virConnectPtr conn
= NULL
;
501 if (error
== VIR_ERR_OK
)
504 errmsg
= virErrorMsg(error
, info
);
505 if (error
!= VIR_ERR_INVALID_DOMAIN
) {
508 virRaiseError(conn
, domain
, NULL
, VIR_FROM_DOM
, error
, VIR_ERR_ERROR
,
509 errmsg
, info
, NULL
, 0, 0, errmsg
, info
);
513 * virLibNetworkError:
514 * @conn: the connection if available
515 * @error: the error number
516 * @info: extra information string
518 * Handle an error at the connection level
521 virLibNetworkError(virNetworkPtr network
, virErrorNumber error
,
524 virConnectPtr conn
= NULL
;
527 if (error
== VIR_ERR_OK
)
530 errmsg
= virErrorMsg(error
, info
);
531 if (error
!= VIR_ERR_INVALID_NETWORK
) {
532 conn
= network
->conn
;
534 virRaiseError(conn
, NULL
, network
, VIR_FROM_NET
, error
, VIR_ERR_ERROR
,
535 errmsg
, info
, NULL
, 0, 0, errmsg
, info
);
539 * virLibInterfaceError:
540 * @conn: the connection if available
541 * @error: the error number
542 * @info: extra information string
544 * Handle an error at the connection level
547 virLibInterfaceError(virInterfacePtr iface
, virErrorNumber error
,
550 virConnectPtr conn
= NULL
;
553 if (error
== VIR_ERR_OK
)
556 errmsg
= virErrorMsg(error
, info
);
557 if (error
!= VIR_ERR_INVALID_INTERFACE
) {
560 virRaiseError(conn
, NULL
, NULL
, VIR_FROM_INTERFACE
, error
, VIR_ERR_ERROR
,
561 errmsg
, info
, NULL
, 0, 0, errmsg
, info
);
565 * virLibStoragePoolError:
566 * @conn: the connection if available
567 * @error: the error number
568 * @info: extra information string
570 * Handle an error at the connection level
573 virLibStoragePoolError(virStoragePoolPtr pool
, virErrorNumber error
,
576 virConnectPtr conn
= NULL
;
579 if (error
== VIR_ERR_OK
)
582 errmsg
= virErrorMsg(error
, info
);
583 if (error
!= VIR_ERR_INVALID_STORAGE_POOL
)
586 virRaiseError(conn
, NULL
, NULL
, VIR_FROM_STORAGE
, error
, VIR_ERR_ERROR
,
587 errmsg
, info
, NULL
, 0, 0, errmsg
, info
);
591 * virLibStorageVolError:
592 * @conn: the connection if available
593 * @error: the error number
594 * @info: extra information string
596 * Handle an error at the connection level
599 virLibStorageVolError(virStorageVolPtr vol
, virErrorNumber error
,
602 virConnectPtr conn
= NULL
;
605 if (error
== VIR_ERR_OK
)
608 errmsg
= virErrorMsg(error
, info
);
609 if (error
!= VIR_ERR_INVALID_STORAGE_VOL
)
612 virRaiseError(conn
, NULL
, NULL
, VIR_FROM_STORAGE
, error
, VIR_ERR_ERROR
,
613 errmsg
, info
, NULL
, 0, 0, errmsg
, info
);
617 * virLibNodeDeviceError:
618 * @dev: the device if available
619 * @error: the error number
620 * @info: extra information string
622 * Handle an error at the node device level
625 virLibNodeDeviceError(virNodeDevicePtr dev
, virErrorNumber error
,
628 virConnectPtr conn
= NULL
;
631 if (error
== VIR_ERR_OK
)
634 errmsg
= virErrorMsg(error
, info
);
635 if (error
!= VIR_ERR_INVALID_NODE_DEVICE
)
638 virRaiseError(conn
, NULL
, NULL
, VIR_FROM_NODEDEV
, error
, VIR_ERR_ERROR
,
639 errmsg
, info
, NULL
, 0, 0, errmsg
, info
);
642 #define virLibStreamError(conn, code, ...) \
643 virReportErrorHelper(conn, VIR_FROM_NONE, code, __FILE__, \
644 __FUNCTION__, __LINE__, __VA_ARGS__)
648 * @secret: the secret if available
649 * @error: the error number
650 * @info: extra information string
652 * Handle an error at the secret level
655 virLibSecretError(virSecretPtr secret
, virErrorNumber error
, const char *info
)
657 virConnectPtr conn
= NULL
;
660 if (error
== VIR_ERR_OK
)
663 errmsg
= virErrorMsg(error
, info
);
664 if (error
!= VIR_ERR_INVALID_SECRET
)
667 virRaiseError(conn
, NULL
, NULL
, VIR_FROM_SECRET
, error
, VIR_ERR_ERROR
,
668 errmsg
, info
, NULL
, 0, 0, errmsg
, info
);
672 * virLibNWFilterError:
673 * @conn: the connection if available
674 * @error: the error number
675 * @info: extra information string
677 * Handle an error at the connection level
680 virLibNWFilterError(virNWFilterPtr pool
, virErrorNumber error
,
683 virConnectPtr conn
= NULL
;
686 if (error
== VIR_ERR_OK
)
689 errmsg
= virErrorMsg(error
, info
);
690 if (error
!= VIR_ERR_INVALID_NWFILTER
)
693 virRaiseError(conn
, NULL
, NULL
, VIR_FROM_NWFILTER
, error
, VIR_ERR_ERROR
,
694 errmsg
, info
, NULL
, 0, 0, errmsg
, info
);
698 * virLibDomainSnapshotError:
699 * @snapshot: the snapshot if available
700 * @error: the error number
701 * @info: extra information string
703 * Handle an error at the domain snapshot level
706 virLibDomainSnapshotError(virDomainSnapshotPtr snapshot
, virErrorNumber error
, const char *info
)
708 virConnectPtr conn
= NULL
;
711 if (error
== VIR_ERR_OK
)
714 errmsg
= virErrorMsg(error
, info
);
715 if (error
!= VIR_ERR_INVALID_DOMAIN_SNAPSHOT
)
716 conn
= snapshot
->domain
->conn
;
718 virRaiseError(conn
, NULL
, NULL
, VIR_FROM_DOMAIN_SNAPSHOT
, error
, VIR_ERR_ERROR
,
719 errmsg
, info
, NULL
, 0, 0, errmsg
, info
);
723 * virRegisterNetworkDriver:
724 * @driver: pointer to a network driver block
726 * Register a network virtualization driver
728 * Returns the driver priority or -1 in case of error.
731 virRegisterNetworkDriver(virNetworkDriverPtr driver
)
733 if (virInitialize() < 0)
736 if (driver
== NULL
) {
737 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
741 if (virNetworkDriverTabCount
>= MAX_DRIVERS
) {
742 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
746 DEBUG ("registering %s as network driver %d",
747 driver
->name
, virNetworkDriverTabCount
);
749 virNetworkDriverTab
[virNetworkDriverTabCount
] = driver
;
750 return virNetworkDriverTabCount
++;
754 * virRegisterInterfaceDriver:
755 * @driver: pointer to an interface driver block
757 * Register an interface virtualization driver
759 * Returns the driver priority or -1 in case of error.
762 virRegisterInterfaceDriver(virInterfaceDriverPtr driver
)
764 if (virInitialize() < 0)
767 if (driver
== NULL
) {
768 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
772 if (virInterfaceDriverTabCount
>= MAX_DRIVERS
) {
773 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
777 DEBUG ("registering %s as interface driver %d",
778 driver
->name
, virInterfaceDriverTabCount
);
780 virInterfaceDriverTab
[virInterfaceDriverTabCount
] = driver
;
781 return virInterfaceDriverTabCount
++;
785 * virRegisterStorageDriver:
786 * @driver: pointer to a storage driver block
788 * Register a storage virtualization driver
790 * Returns the driver priority or -1 in case of error.
793 virRegisterStorageDriver(virStorageDriverPtr driver
)
795 if (virInitialize() < 0)
798 if (driver
== NULL
) {
799 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
803 if (virStorageDriverTabCount
>= MAX_DRIVERS
) {
804 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
808 DEBUG ("registering %s as storage driver %d",
809 driver
->name
, virStorageDriverTabCount
);
811 virStorageDriverTab
[virStorageDriverTabCount
] = driver
;
812 return virStorageDriverTabCount
++;
816 * virRegisterDeviceMonitor:
817 * @driver: pointer to a device monitor block
819 * Register a device monitor
821 * Returns the driver priority or -1 in case of error.
824 virRegisterDeviceMonitor(virDeviceMonitorPtr driver
)
826 if (virInitialize() < 0)
829 if (driver
== NULL
) {
830 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
834 if (virDeviceMonitorTabCount
>= MAX_DRIVERS
) {
835 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
839 DEBUG ("registering %s as device driver %d",
840 driver
->name
, virDeviceMonitorTabCount
);
842 virDeviceMonitorTab
[virDeviceMonitorTabCount
] = driver
;
843 return virDeviceMonitorTabCount
++;
847 * virRegisterSecretDriver:
848 * @driver: pointer to a secret driver block
850 * Register a secret driver
852 * Returns the driver priority or -1 in case of error.
855 virRegisterSecretDriver(virSecretDriverPtr driver
)
857 if (virInitialize() < 0)
860 if (driver
== NULL
) {
861 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
865 if (virSecretDriverTabCount
>= MAX_DRIVERS
) {
866 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
870 DEBUG ("registering %s as secret driver %d",
871 driver
->name
, virSecretDriverTabCount
);
873 virSecretDriverTab
[virSecretDriverTabCount
] = driver
;
874 return virSecretDriverTabCount
++;
878 * virRegisterNWFilterDriver:
879 * @driver: pointer to a network filter driver block
881 * Register a network filter virtualization driver
883 * Returns the driver priority or -1 in case of error.
886 virRegisterNWFilterDriver(virNWFilterDriverPtr driver
)
888 if (virInitialize() < 0)
891 if (driver
== NULL
) {
892 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
896 if (virNWFilterDriverTabCount
>= MAX_DRIVERS
) {
897 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
901 DEBUG ("registering %s as network filter driver %d",
902 driver
->name
, virNWFilterDriverTabCount
);
904 virNWFilterDriverTab
[virNWFilterDriverTabCount
] = driver
;
905 return virNWFilterDriverTabCount
++;
911 * @driver: pointer to a driver block
913 * Register a virtualization driver
915 * Returns the driver priority or -1 in case of error.
918 virRegisterDriver(virDriverPtr driver
)
920 if (virInitialize() < 0)
923 if (driver
== NULL
) {
924 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
928 if (virDriverTabCount
>= MAX_DRIVERS
) {
929 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
933 if (driver
->no
< 0) {
935 (NULL
, VIR_ERR_INVALID_ARG
,
936 "virRegisterDriver: tried to register an internal Xen driver");
940 DEBUG ("registering %s as driver %d",
941 driver
->name
, virDriverTabCount
);
943 virDriverTab
[virDriverTabCount
] = driver
;
944 return virDriverTabCount
++;
949 * virRegisterStateDriver:
950 * @driver: pointer to a driver block
952 * Register a virtualization driver
954 * Returns the driver priority or -1 in case of error.
957 virRegisterStateDriver(virStateDriverPtr driver
)
959 if (virInitialize() < 0)
962 if (driver
== NULL
) {
963 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
967 if (virStateDriverTabCount
>= MAX_DRIVERS
) {
968 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
972 virStateDriverTab
[virStateDriverTabCount
] = driver
;
973 return virStateDriverTabCount
++;
977 * virStateInitialize:
978 * @privileged: set to 1 if running with root priviledge, 0 otherwise
980 * Initialize all virtualization drivers.
982 * Returns 0 if all succeed, -1 upon any failure.
984 int virStateInitialize(int privileged
) {
987 if (virInitialize() < 0)
990 for (i
= 0 ; i
< virStateDriverTabCount
; i
++) {
991 if (virStateDriverTab
[i
]->initialize
&&
992 virStateDriverTab
[i
]->initialize(privileged
) < 0) {
993 VIR_ERROR(_("Initialization of %s state driver failed"),
994 virStateDriverTab
[i
]->name
);
1004 * Run each virtualization driver's cleanup method.
1006 * Returns 0 if all succeed, -1 upon any failure.
1008 int virStateCleanup(void) {
1011 for (i
= 0 ; i
< virStateDriverTabCount
; i
++) {
1012 if (virStateDriverTab
[i
]->cleanup
&&
1013 virStateDriverTab
[i
]->cleanup() < 0)
1022 * Run each virtualization driver's reload method.
1024 * Returns 0 if all succeed, -1 upon any failure.
1026 int virStateReload(void) {
1029 for (i
= 0 ; i
< virStateDriverTabCount
; i
++) {
1030 if (virStateDriverTab
[i
]->reload
&&
1031 virStateDriverTab
[i
]->reload() < 0)
1040 * Run each virtualization driver's "active" method.
1042 * Returns 0 if none are active, 1 if at least one is.
1044 int virStateActive(void) {
1047 for (i
= 0 ; i
< virStateDriverTabCount
; i
++) {
1048 if (virStateDriverTab
[i
]->active
&&
1049 virStateDriverTab
[i
]->active())
1061 * @libVer: return value for the library version (OUT)
1062 * @type: the type of connection/driver looked at
1063 * @typeVer: return value for the version of the hypervisor (OUT)
1065 * Provides two information back, @libVer is the version of the library
1066 * while @typeVer will be the version of the hypervisor type @type against
1067 * which the library was compiled. If @type is NULL, "Xen" is assumed, if
1068 * @type is unknown or not available, an error code will be returned and
1069 * @typeVer will be 0.
1071 * Returns -1 in case of failure, 0 otherwise, and values for @libVer and
1072 * @typeVer have the format major * 1,000,000 + minor * 1,000 + release.
1075 virGetVersion(unsigned long *libVer
, const char *type
,
1076 unsigned long *typeVer
)
1078 DEBUG("libVir=%p, type=%s, typeVer=%p", libVer
, type
, typeVer
);
1081 if (virInitialize() < 0)
1086 *libVer
= LIBVIR_VERSION_NUMBER
;
1088 if (typeVer
!= NULL
) {
1092 /* FIXME: Add _proper_ type version handling for loadable driver modules... */
1093 #ifdef WITH_DRIVER_MODULES
1094 *typeVer
= LIBVIR_VERSION_NUMBER
;
1099 if (STRCASEEQ(type
, "Xen"))
1100 *typeVer
= xenUnifiedVersion();
1103 if (STRCASEEQ(type
, "Test"))
1104 *typeVer
= LIBVIR_VERSION_NUMBER
;
1107 if (STRCASEEQ(type
, "QEMU"))
1108 *typeVer
= LIBVIR_VERSION_NUMBER
;
1111 if (STRCASEEQ(type
, "LXC"))
1112 *typeVer
= LIBVIR_VERSION_NUMBER
;
1115 if (STRCASEEQ(type
, "phyp"))
1116 *typeVer
= LIBVIR_VERSION_NUMBER
;
1119 if (STRCASEEQ(type
, "OpenVZ"))
1120 *typeVer
= LIBVIR_VERSION_NUMBER
;
1123 if (STRCASEEQ(type
, "VBox"))
1124 *typeVer
= LIBVIR_VERSION_NUMBER
;
1127 if (STRCASEEQ(type
, "UML"))
1128 *typeVer
= LIBVIR_VERSION_NUMBER
;
1131 if (STRCASEEQ(type
, "ONE"))
1132 *typeVer
= LIBVIR_VERSION_NUMBER
;
1135 if (STRCASEEQ(type
, "ESX"))
1136 *typeVer
= LIBVIR_VERSION_NUMBER
;
1139 if (STRCASEEQ(type
, "XenAPI"))
1140 *typeVer
= LIBVIR_VERSION_NUMBER
;
1143 if (STRCASEEQ(type
, "Remote"))
1144 *typeVer
= remoteVersion();
1146 if (*typeVer
== 0) {
1147 virLibConnError(NULL
, VIR_ERR_NO_SUPPORT
, type
);
1150 #endif /* WITH_DRIVER_MODULES */
1155 virDispatchError(NULL
);
1159 static virConnectPtr
1160 do_open (const char *name
,
1161 virConnectAuthPtr auth
,
1167 virResetLastError();
1169 ret
= virGetConnect();
1174 * If no URI is passed, then check for an environment string if not
1175 * available probe the compiled in drivers to find a default hypervisor
1178 if (!name
|| name
[0] == '\0') {
1179 char *defname
= getenv("LIBVIRT_DEFAULT_URI");
1180 if (defname
&& *defname
) {
1181 DEBUG("Using LIBVIRT_DEFAULT_URI %s", defname
);
1189 /* Convert xen -> xen:/// for back compat */
1190 if (STRCASEEQ(name
, "xen"))
1193 /* Convert xen:// -> xen:/// because xmlParseURI cannot parse the
1194 * former. This allows URIs such as xen://localhost to work.
1196 if (STREQ (name
, "xen://"))
1199 ret
->uri
= xmlParseURI (name
);
1201 virLibConnError (ret
, VIR_ERR_INVALID_ARG
,
1202 _("could not parse connection URI"));
1206 DEBUG("name \"%s\" to URI components:\n"
1215 NULLSTR(ret
->uri
->scheme
), NULLSTR(ret
->uri
->opaque
),
1216 NULLSTR(ret
->uri
->authority
), NULLSTR(ret
->uri
->server
),
1217 NULLSTR(ret
->uri
->user
), ret
->uri
->port
,
1218 NULLSTR(ret
->uri
->path
));
1220 DEBUG0("no name, allowing driver auto-select");
1223 /* Cleansing flags */
1224 ret
->flags
= flags
& VIR_CONNECT_RO
;
1226 for (i
= 0; i
< virDriverTabCount
; i
++) {
1227 /* We're going to probe the remote driver next. So we have already
1228 * probed all other client-side-only driver before, but none of them
1230 * If the scheme corresponds to a known but disabled client-side-only
1231 * driver then report a useful error, instead of a cryptic one about
1232 * not being able to connect to libvirtd or not being able to find
1234 if (virDriverTab
[i
]->no
== VIR_DRV_REMOTE
&&
1235 ret
->uri
!= NULL
&& ret
->uri
->scheme
!= NULL
&&
1238 STRCASEEQ(ret
->uri
->scheme
, "phyp") ||
1241 STRCASEEQ(ret
->uri
->scheme
, "vpx") ||
1242 STRCASEEQ(ret
->uri
->scheme
, "esx") ||
1243 STRCASEEQ(ret
->uri
->scheme
, "gsx") ||
1246 STRCASEEQ(ret
->uri
->scheme
, "xenapi") ||
1249 virReportErrorHelper(NULL
, VIR_FROM_NONE
, VIR_ERR_INVALID_ARG
,
1250 __FILE__
, __FUNCTION__
, __LINE__
,
1251 _("libvirt was built without the '%s' driver"),
1256 DEBUG("trying driver %d (%s) ...",
1257 i
, virDriverTab
[i
]->name
);
1258 res
= virDriverTab
[i
]->open (ret
, auth
, flags
);
1259 DEBUG("driver %d %s returned %s",
1260 i
, virDriverTab
[i
]->name
,
1261 res
== VIR_DRV_OPEN_SUCCESS
? "SUCCESS" :
1262 (res
== VIR_DRV_OPEN_DECLINED
? "DECLINED" :
1263 (res
== VIR_DRV_OPEN_ERROR
? "ERROR" : "unknown status")));
1264 if (res
== VIR_DRV_OPEN_ERROR
) goto failed
;
1265 else if (res
== VIR_DRV_OPEN_SUCCESS
) {
1266 ret
->driver
= virDriverTab
[i
];
1272 /* If we reach here, then all drivers declined the connection. */
1273 virLibConnError (NULL
, VIR_ERR_NO_CONNECT
, name
);
1277 for (i
= 0; i
< virNetworkDriverTabCount
; i
++) {
1278 res
= virNetworkDriverTab
[i
]->open (ret
, auth
, flags
);
1279 DEBUG("network driver %d %s returned %s",
1280 i
, virNetworkDriverTab
[i
]->name
,
1281 res
== VIR_DRV_OPEN_SUCCESS
? "SUCCESS" :
1282 (res
== VIR_DRV_OPEN_DECLINED
? "DECLINED" :
1283 (res
== VIR_DRV_OPEN_ERROR
? "ERROR" : "unknown status")));
1284 if (res
== VIR_DRV_OPEN_ERROR
) {
1285 if (STREQ(virNetworkDriverTab
[i
]->name
, "remote")) {
1286 virLibConnWarning (NULL
, VIR_WAR_NO_NETWORK
,
1287 "Is the daemon running ?");
1290 } else if (res
== VIR_DRV_OPEN_SUCCESS
) {
1291 ret
->networkDriver
= virNetworkDriverTab
[i
];
1296 for (i
= 0; i
< virInterfaceDriverTabCount
; i
++) {
1297 res
= virInterfaceDriverTab
[i
]->open (ret
, auth
, flags
);
1298 DEBUG("interface driver %d %s returned %s",
1299 i
, virInterfaceDriverTab
[i
]->name
,
1300 res
== VIR_DRV_OPEN_SUCCESS
? "SUCCESS" :
1301 (res
== VIR_DRV_OPEN_DECLINED
? "DECLINED" :
1302 (res
== VIR_DRV_OPEN_ERROR
? "ERROR" : "unknown status")));
1303 if (res
== VIR_DRV_OPEN_ERROR
) {
1304 if (STREQ(virInterfaceDriverTab
[i
]->name
, "remote")) {
1305 virLibConnWarning (NULL
, VIR_WAR_NO_INTERFACE
,
1306 "Is the daemon running ?");
1309 } else if (res
== VIR_DRV_OPEN_SUCCESS
) {
1310 ret
->interfaceDriver
= virInterfaceDriverTab
[i
];
1315 /* Secondary driver for storage. Optional */
1316 for (i
= 0; i
< virStorageDriverTabCount
; i
++) {
1317 res
= virStorageDriverTab
[i
]->open (ret
, auth
, flags
);
1318 DEBUG("storage driver %d %s returned %s",
1319 i
, virStorageDriverTab
[i
]->name
,
1320 res
== VIR_DRV_OPEN_SUCCESS
? "SUCCESS" :
1321 (res
== VIR_DRV_OPEN_DECLINED
? "DECLINED" :
1322 (res
== VIR_DRV_OPEN_ERROR
? "ERROR" : "unknown status")));
1323 if (res
== VIR_DRV_OPEN_ERROR
) {
1324 if (STREQ(virStorageDriverTab
[i
]->name
, "remote")) {
1325 virLibConnWarning (NULL
, VIR_WAR_NO_STORAGE
,
1326 "Is the daemon running ?");
1329 } else if (res
== VIR_DRV_OPEN_SUCCESS
) {
1330 ret
->storageDriver
= virStorageDriverTab
[i
];
1335 /* Node driver (optional) */
1336 for (i
= 0; i
< virDeviceMonitorTabCount
; i
++) {
1337 res
= virDeviceMonitorTab
[i
]->open (ret
, auth
, flags
);
1338 DEBUG("node driver %d %s returned %s",
1339 i
, virDeviceMonitorTab
[i
]->name
,
1340 res
== VIR_DRV_OPEN_SUCCESS
? "SUCCESS" :
1341 (res
== VIR_DRV_OPEN_DECLINED
? "DECLINED" :
1342 (res
== VIR_DRV_OPEN_ERROR
? "ERROR" : "unknown status")));
1343 if (res
== VIR_DRV_OPEN_ERROR
) {
1344 if (STREQ(virDeviceMonitorTab
[i
]->name
, "remote")) {
1345 virLibConnWarning (NULL
, VIR_WAR_NO_NODE
,
1346 "Is the libvirtd daemon running ?");
1349 if (virAsprintf(&msg
, "Is the %s daemon running?",
1350 virDeviceMonitorTab
[i
]->name
) > 0) {
1351 virLibConnWarning (NULL
, VIR_WAR_NO_NODE
, msg
);
1356 } else if (res
== VIR_DRV_OPEN_SUCCESS
) {
1357 ret
->deviceMonitor
= virDeviceMonitorTab
[i
];
1362 /* Secret manipulation driver. Optional */
1363 for (i
= 0; i
< virSecretDriverTabCount
; i
++) {
1364 res
= virSecretDriverTab
[i
]->open (ret
, auth
, flags
);
1365 DEBUG("secret driver %d %s returned %s",
1366 i
, virSecretDriverTab
[i
]->name
,
1367 res
== VIR_DRV_OPEN_SUCCESS
? "SUCCESS" :
1368 (res
== VIR_DRV_OPEN_DECLINED
? "DECLINED" :
1369 (res
== VIR_DRV_OPEN_ERROR
? "ERROR" : "unknown status")));
1370 if (res
== VIR_DRV_OPEN_ERROR
) {
1371 if (STREQ(virSecretDriverTab
[i
]->name
, "remote")) {
1372 virLibConnWarning (NULL
, VIR_WAR_NO_SECRET
,
1373 "Is the daemon running ?");
1376 } else if (res
== VIR_DRV_OPEN_SUCCESS
) {
1377 ret
->secretDriver
= virSecretDriverTab
[i
];
1382 /* Network filter driver. Optional */
1383 for (i
= 0; i
< virNWFilterDriverTabCount
; i
++) {
1384 res
= virNWFilterDriverTab
[i
]->open (ret
, auth
, flags
);
1385 DEBUG("nwfilter driver %d %s returned %s",
1386 i
, virNWFilterDriverTab
[i
]->name
,
1387 res
== VIR_DRV_OPEN_SUCCESS
? "SUCCESS" :
1388 (res
== VIR_DRV_OPEN_DECLINED
? "DECLINED" :
1389 (res
== VIR_DRV_OPEN_ERROR
? "ERROR" : "unknown status")));
1390 if (res
== VIR_DRV_OPEN_ERROR
) {
1391 if (STREQ(virNWFilterDriverTab
[i
]->name
, "remote")) {
1392 virLibConnWarning (NULL
, VIR_WAR_NO_NWFILTER
,
1393 _("Is the daemon running ?"));
1396 } else if (res
== VIR_DRV_OPEN_SUCCESS
) {
1397 ret
->nwfilterDriver
= virNWFilterDriverTab
[i
];
1405 virUnrefConnect(ret
);
1412 * @name: URI of the hypervisor
1414 * This function should be called first to get a connection to the
1415 * Hypervisor and xen store
1417 * Returns a pointer to the hypervisor connection or NULL in case of error
1419 * If @name is NULL then probing will be done to determine a suitable
1420 * default driver to activate. This involves trying each hypervisor
1421 * in turn until one successfully opens. If the LIBVIRT_DEFAULT_URI
1422 * environment variable is set, then it will be used in preference
1423 * to probing for a driver.
1425 * If connecting to an unprivileged hypervisor driver which requires
1426 * the libvirtd daemon to be active, it will automatically be launched
1427 * if not already running. This can be prevented by setting the
1428 * environment variable LIBVIRT_AUTOSTART=0
1430 * URIs are documented at http://libvirt.org/uri.html
1433 virConnectOpen (const char *name
)
1435 virConnectPtr ret
= NULL
;
1437 if (virInitialize() < 0)
1440 DEBUG("name=%s", name
);
1441 ret
= do_open (name
, NULL
, 0);
1447 virDispatchError(NULL
);
1452 * virConnectOpenReadOnly:
1453 * @name: URI of the hypervisor
1455 * This function should be called first to get a restricted connection to the
1456 * library functionalities. The set of APIs usable are then restricted
1457 * on the available methods to control the domains.
1459 * See virConnectOpen for notes about environment variables which can
1460 * have an effect on opening drivers
1462 * Returns a pointer to the hypervisor connection or NULL in case of error
1464 * URIs are documented at http://libvirt.org/uri.html
1467 virConnectOpenReadOnly(const char *name
)
1469 virConnectPtr ret
= NULL
;
1471 if (virInitialize() < 0)
1474 DEBUG("name=%s", name
);
1475 ret
= do_open (name
, NULL
, VIR_CONNECT_RO
);
1481 virDispatchError(NULL
);
1486 * virConnectOpenAuth:
1487 * @name: URI of the hypervisor
1488 * @auth: Authenticate callback parameters
1489 * @flags: Open flags
1491 * This function should be called first to get a connection to the
1492 * Hypervisor. If necessary, authentication will be performed fetching
1493 * credentials via the callback
1495 * See virConnectOpen for notes about environment variables which can
1496 * have an effect on opening drivers
1498 * Returns a pointer to the hypervisor connection or NULL in case of error
1500 * URIs are documented at http://libvirt.org/uri.html
1503 virConnectOpenAuth(const char *name
,
1504 virConnectAuthPtr auth
,
1507 virConnectPtr ret
= NULL
;
1509 if (virInitialize() < 0)
1512 DEBUG("name=%s, auth=%p, flags=%d", NULLSTR(name
), auth
, flags
);
1513 ret
= do_open (name
, auth
, flags
);
1519 virDispatchError(NULL
);
1525 * @conn: pointer to the hypervisor connection
1527 * This function closes the connection to the Hypervisor. This should
1528 * not be called if further interaction with the Hypervisor are needed
1529 * especially if there is running domain which need further monitoring by
1532 * Returns 0 in case of success or -1 in case of error.
1535 virConnectClose(virConnectPtr conn
)
1538 DEBUG("conn=%p", conn
);
1540 virResetLastError();
1542 if (!VIR_IS_CONNECT(conn
)) {
1543 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
1547 ret
= virUnrefConnect(conn
);
1553 virDispatchError(NULL
);
1559 * @conn: the connection to hold a reference on
1561 * Increment the reference count on the connection. For each
1562 * additional call to this method, there shall be a corresponding
1563 * call to virConnectClose to release the reference count, once
1564 * the caller no longer needs the reference to this object.
1566 * This method is typically useful for applications where multiple
1567 * threads are using a connection, and it is required that the
1568 * connection remain open until all threads have finished using
1569 * it. ie, each new thread using a connection would increment
1570 * the reference count.
1572 * Returns 0 in case of success, -1 in case of failure
1575 virConnectRef(virConnectPtr conn
)
1577 if ((!VIR_IS_CONNECT(conn
))) {
1578 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
1579 virDispatchError(NULL
);
1582 virMutexLock(&conn
->lock
);
1583 DEBUG("conn=%p refs=%d", conn
, conn
->refs
);
1585 virMutexUnlock(&conn
->lock
);
1590 * Not for public use. This function is part of the internal
1591 * implementation of driver features in the remote case.
1594 virDrvSupportsFeature (virConnectPtr conn
, int feature
)
1597 DEBUG("conn=%p, feature=%d", conn
, feature
);
1599 virResetLastError();
1601 if (!VIR_IS_CONNECT(conn
)) {
1602 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
1603 virDispatchError(NULL
);
1607 ret
= VIR_DRV_SUPPORTS_FEATURE (conn
->driver
, conn
, feature
);
1610 virDispatchError(conn
);
1616 * virConnectGetType:
1617 * @conn: pointer to the hypervisor connection
1619 * Get the name of the Hypervisor software used.
1621 * Returns NULL in case of error, a static zero terminated string otherwise.
1624 * http://www.redhat.com/archives/libvir-list/2007-February/msg00096.html
1627 virConnectGetType(virConnectPtr conn
)
1630 DEBUG("conn=%p", conn
);
1632 virResetLastError();
1634 if (!VIR_IS_CONNECT(conn
)) {
1635 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
1636 virDispatchError(NULL
);
1640 if (conn
->driver
->type
) {
1641 ret
= conn
->driver
->type (conn
);
1642 if (ret
) return ret
;
1644 return conn
->driver
->name
;
1648 * virConnectGetVersion:
1649 * @conn: pointer to the hypervisor connection
1650 * @hvVer: return value for the version of the running hypervisor (OUT)
1652 * Get the version level of the Hypervisor running. This may work only with
1653 * hypervisor call, i.e. with privileged access to the hypervisor, not
1654 * with a Read-Only connection.
1656 * Returns -1 in case of error, 0 otherwise. if the version can't be
1657 * extracted by lack of capacities returns 0 and @hvVer is 0, otherwise
1658 * @hvVer value is major * 1,000,000 + minor * 1,000 + release
1661 virConnectGetVersion(virConnectPtr conn
, unsigned long *hvVer
)
1663 DEBUG("conn=%p, hvVer=%p", conn
, hvVer
);
1665 virResetLastError();
1667 if (!VIR_IS_CONNECT(conn
)) {
1668 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
1669 virDispatchError(NULL
);
1673 if (hvVer
== NULL
) {
1674 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
1678 if (conn
->driver
->version
) {
1679 int ret
= conn
->driver
->version (conn
, hvVer
);
1685 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
1688 virDispatchError(conn
);
1693 * virConnectGetLibVersion:
1694 * @conn: pointer to the hypervisor connection
1695 * @libVer: returns the libvirt library version used on the connection (OUT)
1697 * Provides @libVer, which is the version of libvirt used by the
1698 * daemon running on the @conn host
1700 * Returns -1 in case of failure, 0 otherwise, and values for @libVer have
1701 * the format major * 1,000,000 + minor * 1,000 + release.
1704 virConnectGetLibVersion(virConnectPtr conn
, unsigned long *libVer
)
1707 DEBUG("conn=%p, libVir=%p", conn
, libVer
);
1709 virResetLastError();
1711 if (!VIR_IS_CONNECT(conn
)) {
1712 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
1713 virDispatchError(NULL
);
1717 if (libVer
== NULL
) {
1718 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
1722 if (conn
->driver
->libvirtVersion
) {
1723 ret
= conn
->driver
->libvirtVersion(conn
, libVer
);
1729 *libVer
= LIBVIR_VERSION_NUMBER
;
1733 virDispatchError(conn
);
1738 * virConnectGetHostname:
1739 * @conn: pointer to a hypervisor connection
1741 * This returns the system hostname on which the hypervisor is
1742 * running (the result of the gethostname system call). If
1743 * we are connected to a remote system, then this returns the
1744 * hostname of the remote system.
1746 * Returns the hostname which must be freed by the caller, or
1747 * NULL if there was an error.
1750 virConnectGetHostname (virConnectPtr conn
)
1752 DEBUG("conn=%p", conn
);
1754 virResetLastError();
1756 if (!VIR_IS_CONNECT(conn
)) {
1757 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
1758 virDispatchError(NULL
);
1762 if (conn
->driver
->getHostname
) {
1763 char *ret
= conn
->driver
->getHostname (conn
);
1769 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
1772 virDispatchError(conn
);
1778 * @conn: pointer to a hypervisor connection
1780 * This returns the URI (name) of the hypervisor connection.
1781 * Normally this is the same as or similar to the string passed
1782 * to the virConnectOpen/virConnectOpenReadOnly call, but
1783 * the driver may make the URI canonical. If name == NULL
1784 * was passed to virConnectOpen, then the driver will return
1785 * a non-NULL URI which can be used to connect to the same
1788 * Returns the URI string which must be freed by the caller, or
1789 * NULL if there was an error.
1792 virConnectGetURI (virConnectPtr conn
)
1795 DEBUG("conn=%p", conn
);
1797 virResetLastError();
1799 if (!VIR_IS_CONNECT(conn
)) {
1800 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
1801 virDispatchError(NULL
);
1805 name
= (char *)xmlSaveUri(conn
->uri
);
1807 virReportOOMError();
1813 virDispatchError(conn
);
1818 * virConnectGetMaxVcpus:
1819 * @conn: pointer to the hypervisor connection
1820 * @type: value of the 'type' attribute in the <domain> element
1822 * Provides the maximum number of virtual CPUs supported for a guest VM of a
1823 * specific type. The 'type' parameter here corresponds to the 'type'
1824 * attribute in the <domain> element of the XML.
1826 * Returns the maximum of virtual CPU or -1 in case of error.
1829 virConnectGetMaxVcpus(virConnectPtr conn
,
1832 DEBUG("conn=%p, type=%s", conn
, type
);
1834 virResetLastError();
1836 if (!VIR_IS_CONNECT(conn
)) {
1837 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
1838 virDispatchError(NULL
);
1842 if (conn
->driver
->getMaxVcpus
) {
1843 int ret
= conn
->driver
->getMaxVcpus (conn
, type
);
1849 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
1851 virDispatchError(conn
);
1856 * virConnectListDomains:
1857 * @conn: pointer to the hypervisor connection
1858 * @ids: array to collect the list of IDs of active domains
1859 * @maxids: size of @ids
1861 * Collect the list of active domains, and store their ID in @maxids
1863 * Returns the number of domain found or -1 in case of error
1866 virConnectListDomains(virConnectPtr conn
, int *ids
, int maxids
)
1868 DEBUG("conn=%p, ids=%p, maxids=%d", conn
, ids
, maxids
);
1870 virResetLastError();
1872 if (!VIR_IS_CONNECT(conn
)) {
1873 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
1874 virDispatchError(NULL
);
1878 if ((ids
== NULL
) || (maxids
< 0)) {
1879 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
1883 if (conn
->driver
->listDomains
) {
1884 int ret
= conn
->driver
->listDomains (conn
, ids
, maxids
);
1890 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
1892 virDispatchError(conn
);
1897 * virConnectNumOfDomains:
1898 * @conn: pointer to the hypervisor connection
1900 * Provides the number of active domains.
1902 * Returns the number of domain found or -1 in case of error
1905 virConnectNumOfDomains(virConnectPtr conn
)
1907 DEBUG("conn=%p", conn
);
1909 virResetLastError();
1911 if (!VIR_IS_CONNECT(conn
)) {
1912 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
1913 virDispatchError(NULL
);
1917 if (conn
->driver
->numOfDomains
) {
1918 int ret
= conn
->driver
->numOfDomains (conn
);
1924 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
1926 virDispatchError(conn
);
1931 * virDomainGetConnect:
1932 * @dom: pointer to a domain
1934 * Provides the connection pointer associated with a domain. The
1935 * reference counter on the connection is not increased by this
1938 * WARNING: When writing libvirt bindings in other languages, do
1939 * not use this function. Instead, store the connection and
1940 * the domain object together.
1942 * Returns the virConnectPtr or NULL in case of failure.
1945 virDomainGetConnect (virDomainPtr dom
)
1947 DEBUG("dom=%p", dom
);
1949 virResetLastError();
1951 if (!VIR_IS_CONNECTED_DOMAIN (dom
)) {
1952 virLibDomainError (NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
1953 virDispatchError(NULL
);
1960 * virDomainCreateXML:
1961 * @conn: pointer to the hypervisor connection
1962 * @xmlDesc: string containing an XML description of the domain
1963 * @flags: bitwise-or of supported virDomainCreateFlags
1965 * Launch a new guest domain, based on an XML description similar
1966 * to the one returned by virDomainGetXMLDesc()
1967 * This function may requires privileged access to the hypervisor.
1968 * The domain is not persistent, so its definition will disappear when it
1969 * is destroyed, or if the host is restarted (see virDomainDefineXML() to
1970 * define persistent domains).
1972 * Returns a new domain object or NULL in case of failure
1975 virDomainCreateXML(virConnectPtr conn
, const char *xmlDesc
,
1978 DEBUG("conn=%p, xmlDesc=%s, flags=%d", conn
, xmlDesc
, flags
);
1980 virResetLastError();
1982 if (!VIR_IS_CONNECT(conn
)) {
1983 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
1984 virDispatchError(NULL
);
1987 if (xmlDesc
== NULL
) {
1988 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
1991 if (conn
->flags
& VIR_CONNECT_RO
) {
1992 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
1996 if (conn
->driver
->domainCreateXML
) {
1998 ret
= conn
->driver
->domainCreateXML (conn
, xmlDesc
, flags
);
2004 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2006 virDispatchError(conn
);
2011 * virDomainCreateLinux:
2012 * @conn: pointer to the hypervisor connection
2013 * @xmlDesc: string containing an XML description of the domain
2014 * @flags: callers should always pass 0
2016 * Deprecated after 0.4.6.
2017 * Renamed to virDomainCreateXML() providing identical functionality.
2018 * This existing name will left indefinitely for API compatibility.
2020 * Returns a new domain object or NULL in case of failure
2023 virDomainCreateLinux(virConnectPtr conn
, const char *xmlDesc
,
2026 return(virDomainCreateXML(conn
, xmlDesc
, flags
));
2030 * virDomainLookupByID:
2031 * @conn: pointer to the hypervisor connection
2032 * @id: the domain ID number
2034 * Try to find a domain based on the hypervisor ID number
2035 * Note that this won't work for inactive domains which have an ID of -1,
2036 * in that case a lookup based on the Name or UUId need to be done instead.
2038 * Returns a new domain object or NULL in case of failure. If the
2039 * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
2042 virDomainLookupByID(virConnectPtr conn
, int id
)
2044 DEBUG("conn=%p, id=%d", conn
, id
);
2046 virResetLastError();
2048 if (!VIR_IS_CONNECT(conn
)) {
2049 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
2050 virDispatchError(NULL
);
2054 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
2058 if (conn
->driver
->domainLookupByID
) {
2060 ret
= conn
->driver
->domainLookupByID (conn
, id
);
2066 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2069 virDispatchError(conn
);
2074 * virDomainLookupByUUID:
2075 * @conn: pointer to the hypervisor connection
2076 * @uuid: the raw UUID for the domain
2078 * Try to lookup a domain on the given hypervisor based on its UUID.
2080 * Returns a new domain object or NULL in case of failure. If the
2081 * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
2084 virDomainLookupByUUID(virConnectPtr conn
, const unsigned char *uuid
)
2086 DEBUG("conn=%p, uuid=%s", conn
, uuid
);
2088 virResetLastError();
2090 if (!VIR_IS_CONNECT(conn
)) {
2091 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
2092 virDispatchError(NULL
);
2096 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
2100 if (conn
->driver
->domainLookupByUUID
) {
2102 ret
= conn
->driver
->domainLookupByUUID (conn
, uuid
);
2108 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2111 virDispatchError(conn
);
2116 * virDomainLookupByUUIDString:
2117 * @conn: pointer to the hypervisor connection
2118 * @uuidstr: the string UUID for the domain
2120 * Try to lookup a domain on the given hypervisor based on its UUID.
2122 * Returns a new domain object or NULL in case of failure. If the
2123 * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
2126 virDomainLookupByUUIDString(virConnectPtr conn
, const char *uuidstr
)
2128 unsigned char uuid
[VIR_UUID_BUFLEN
];
2129 DEBUG("conn=%p, uuidstr=%s", conn
, uuidstr
);
2131 virResetLastError();
2133 if (!VIR_IS_CONNECT(conn
)) {
2134 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
2135 virDispatchError(NULL
);
2138 if (uuidstr
== NULL
) {
2139 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
2143 if (virUUIDParse(uuidstr
, uuid
) < 0) {
2144 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
2148 return virDomainLookupByUUID(conn
, &uuid
[0]);
2151 virDispatchError(conn
);
2156 * virDomainLookupByName:
2157 * @conn: pointer to the hypervisor connection
2158 * @name: name for the domain
2160 * Try to lookup a domain on the given hypervisor based on its name.
2162 * Returns a new domain object or NULL in case of failure. If the
2163 * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
2166 virDomainLookupByName(virConnectPtr conn
, const char *name
)
2168 DEBUG("conn=%p, name=%s", conn
, name
);
2170 virResetLastError();
2172 if (!VIR_IS_CONNECT(conn
)) {
2173 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
2174 virDispatchError(NULL
);
2178 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
2182 if (conn
->driver
->domainLookupByName
) {
2184 dom
= conn
->driver
->domainLookupByName (conn
, name
);
2190 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2193 virDispatchError(conn
);
2199 * @domain: a domain object
2201 * Destroy the domain object. The running instance is shutdown if not down
2202 * already and all resources used by it are given back to the hypervisor. This
2203 * does not free the associated virDomainPtr object.
2204 * This function may require privileged access
2206 * Returns 0 in case of success and -1 in case of failure.
2209 virDomainDestroy(virDomainPtr domain
)
2213 DEBUG("domain=%p", domain
);
2215 virResetLastError();
2217 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
2218 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2219 virDispatchError(NULL
);
2223 conn
= domain
->conn
;
2224 if (conn
->flags
& VIR_CONNECT_RO
) {
2225 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
2229 if (conn
->driver
->domainDestroy
) {
2231 ret
= conn
->driver
->domainDestroy (domain
);
2237 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2240 virDispatchError(conn
);
2246 * @domain: a domain object
2248 * Free the domain object. The running instance is kept alive.
2249 * The data structure is freed and should not be used thereafter.
2251 * Returns 0 in case of success and -1 in case of failure.
2254 virDomainFree(virDomainPtr domain
)
2256 DEBUG("domain=%p", domain
);
2258 virResetLastError();
2260 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
2261 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2262 virDispatchError(NULL
);
2265 if (virUnrefDomain(domain
) < 0) {
2266 virDispatchError(NULL
);
2274 * @domain: the domain to hold a reference on
2276 * Increment the reference count on the domain. For each
2277 * additional call to this method, there shall be a corresponding
2278 * call to virDomainFree to release the reference count, once
2279 * the caller no longer needs the reference to this object.
2281 * This method is typically useful for applications where multiple
2282 * threads are using a connection, and it is required that the
2283 * connection remain open until all threads have finished using
2284 * it. ie, each new thread using a domain would increment
2285 * the reference count.
2287 * Returns 0 in case of success and -1 in case of failure.
2290 virDomainRef(virDomainPtr domain
)
2292 if ((!VIR_IS_CONNECTED_DOMAIN(domain
))) {
2293 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
2294 virDispatchError(NULL
);
2297 virMutexLock(&domain
->conn
->lock
);
2298 DEBUG("domain=%p refs=%d", domain
, domain
->refs
);
2300 virMutexUnlock(&domain
->conn
->lock
);
2307 * @domain: a domain object
2309 * Suspends an active domain, the process is frozen without further access
2310 * to CPU resources and I/O but the memory used by the domain at the
2311 * hypervisor level will stay allocated. Use virDomainResume() to reactivate
2313 * This function may requires privileged access.
2315 * Returns 0 in case of success and -1 in case of failure.
2318 virDomainSuspend(virDomainPtr domain
)
2321 DEBUG("domain=%p", domain
);
2323 virResetLastError();
2325 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
2326 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2327 virDispatchError(NULL
);
2330 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
2331 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
2335 conn
= domain
->conn
;
2337 if (conn
->driver
->domainSuspend
) {
2339 ret
= conn
->driver
->domainSuspend (domain
);
2345 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2348 virDispatchError(domain
->conn
);
2354 * @domain: a domain object
2356 * Resume a suspended domain, the process is restarted from the state where
2357 * it was frozen by calling virSuspendDomain().
2358 * This function may requires privileged access
2360 * Returns 0 in case of success and -1 in case of failure.
2363 virDomainResume(virDomainPtr domain
)
2366 DEBUG("domain=%p", domain
);
2368 virResetLastError();
2370 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
2371 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2372 virDispatchError(NULL
);
2375 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
2376 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
2380 conn
= domain
->conn
;
2382 if (conn
->driver
->domainResume
) {
2384 ret
= conn
->driver
->domainResume (domain
);
2390 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2393 virDispatchError(domain
->conn
);
2399 * @domain: a domain object
2400 * @to: path for the output file
2402 * This method will suspend a domain and save its memory contents to
2403 * a file on disk. After the call, if successful, the domain is not
2404 * listed as running anymore (this may be a problem).
2405 * Use virDomainRestore() to restore a domain after saving.
2407 * Returns 0 in case of success and -1 in case of failure.
2410 virDomainSave(virDomainPtr domain
, const char *to
)
2412 char filepath
[4096];
2414 DEBUG("domain=%p, to=%s", domain
, to
);
2416 virResetLastError();
2418 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
2419 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2420 virDispatchError(NULL
);
2423 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
2424 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
2427 conn
= domain
->conn
;
2429 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
2434 * We must absolutize the file path as the save is done out of process
2435 * TODO: check for URI when libxml2 is linked in.
2438 unsigned int len
, t
;
2441 if (getcwd(filepath
, sizeof(filepath
) - (t
+ 3)) == NULL
)
2443 len
= strlen(filepath
);
2444 /* that should be covered by getcwd() semantic, but be 100% sure */
2445 if (len
> sizeof(filepath
) - (t
+ 3))
2447 filepath
[len
] = '/';
2448 strcpy(&filepath
[len
+ 1], to
);
2453 if (conn
->driver
->domainSave
) {
2455 ret
= conn
->driver
->domainSave (domain
, to
);
2461 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2464 virDispatchError(domain
->conn
);
2470 * @conn: pointer to the hypervisor connection
2471 * @from: path to the
2473 * This method will restore a domain saved to disk by virDomainSave().
2475 * Returns 0 in case of success and -1 in case of failure.
2478 virDomainRestore(virConnectPtr conn
, const char *from
)
2480 char filepath
[4096];
2481 DEBUG("conn=%p, from=%s", conn
, from
);
2483 virResetLastError();
2485 if (!VIR_IS_CONNECT(conn
)) {
2486 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
2487 virDispatchError(NULL
);
2490 if (conn
->flags
& VIR_CONNECT_RO
) {
2491 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
2495 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
2500 * We must absolutize the file path as the restore is done out of process
2501 * TODO: check for URI when libxml2 is linked in.
2503 if (from
[0] != '/') {
2504 unsigned int len
, t
;
2507 if (getcwd(filepath
, sizeof(filepath
) - (t
+ 3)) == NULL
) {
2508 virLibConnError(conn
, VIR_ERR_SYSTEM_ERROR
,
2509 _("cannot get working directory"));
2512 len
= strlen(filepath
);
2513 /* that should be covered by getcwd() semantic, but be 100% sure */
2514 if (len
> sizeof(filepath
) - (t
+ 3)) {
2515 virLibConnError(conn
, VIR_ERR_INTERNAL_ERROR
,
2516 _("path too long"));
2519 filepath
[len
] = '/';
2520 strcpy(&filepath
[len
+ 1], from
);
2521 from
= &filepath
[0];
2524 if (conn
->driver
->domainRestore
) {
2526 ret
= conn
->driver
->domainRestore (conn
, from
);
2532 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2535 virDispatchError(conn
);
2540 * virDomainCoreDump:
2541 * @domain: a domain object
2542 * @to: path for the core file
2543 * @flags: extra flags, currently unused
2545 * This method will dump the core of a domain on a given file for analysis.
2546 * Note that for remote Xen Daemon the file path will be interpreted in
2549 * Returns 0 in case of success and -1 in case of failure.
2552 virDomainCoreDump(virDomainPtr domain
, const char *to
, int flags
)
2554 char filepath
[4096];
2556 DEBUG("domain=%p, to=%s, flags=%d", domain
, to
, flags
);
2558 virResetLastError();
2560 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
2561 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2562 virDispatchError(NULL
);
2565 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
2566 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
2569 conn
= domain
->conn
;
2571 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
2576 * We must absolutize the file path as the save is done out of process
2577 * TODO: check for URI when libxml2 is linked in.
2580 unsigned int len
, t
;
2583 if (getcwd(filepath
, sizeof(filepath
) - (t
+ 3)) == NULL
) {
2584 virLibDomainError(domain
, VIR_ERR_SYSTEM_ERROR
,
2585 _("cannot get current directory"));
2588 len
= strlen(filepath
);
2589 /* that should be covered by getcwd() semantic, but be 100% sure */
2590 if (len
> sizeof(filepath
) - (t
+ 3)) {
2591 virLibDomainError(domain
, VIR_ERR_INTERNAL_ERROR
,
2592 _("path too long"));
2595 filepath
[len
] = '/';
2596 strcpy(&filepath
[len
+ 1], to
);
2601 if (conn
->driver
->domainCoreDump
) {
2603 ret
= conn
->driver
->domainCoreDump (domain
, to
, flags
);
2609 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2612 virDispatchError(domain
->conn
);
2617 * virDomainShutdown:
2618 * @domain: a domain object
2620 * Shutdown a domain, the domain object is still usable there after but
2621 * the domain OS is being stopped. Note that the guest OS may ignore the
2624 * TODO: should we add an option for reboot, knowing it may not be doable
2625 * in the general case ?
2627 * Returns 0 in case of success and -1 in case of failure.
2630 virDomainShutdown(virDomainPtr domain
)
2633 DEBUG("domain=%p", domain
);
2635 virResetLastError();
2637 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
2638 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2639 virDispatchError(NULL
);
2642 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
2643 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
2647 conn
= domain
->conn
;
2649 if (conn
->driver
->domainShutdown
) {
2651 ret
= conn
->driver
->domainShutdown (domain
);
2657 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2660 virDispatchError(domain
->conn
);
2666 * @domain: a domain object
2667 * @flags: extra flags for the reboot operation, not used yet
2669 * Reboot a domain, the domain object is still usable there after but
2670 * the domain OS is being stopped for a restart.
2671 * Note that the guest OS may ignore the request.
2673 * Returns 0 in case of success and -1 in case of failure.
2676 virDomainReboot(virDomainPtr domain
, unsigned int flags
)
2679 DEBUG("domain=%p, flags=%u", domain
, flags
);
2681 virResetLastError();
2683 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
2684 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2685 virDispatchError(NULL
);
2688 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
2689 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
2693 conn
= domain
->conn
;
2695 if (conn
->driver
->domainReboot
) {
2697 ret
= conn
->driver
->domainReboot (domain
, flags
);
2703 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2706 virDispatchError(domain
->conn
);
2712 * @domain: a domain object
2714 * Get the public name for that domain
2716 * Returns a pointer to the name or NULL, the string need not be deallocated
2717 * its lifetime will be the same as the domain object.
2720 virDomainGetName(virDomainPtr domain
)
2722 DEBUG("domain=%p", domain
);
2724 virResetLastError();
2726 if (!VIR_IS_DOMAIN(domain
)) {
2727 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2728 virDispatchError(NULL
);
2731 return (domain
->name
);
2736 * @domain: a domain object
2737 * @uuid: pointer to a VIR_UUID_BUFLEN bytes array
2739 * Get the UUID for a domain
2741 * Returns -1 in case of error, 0 in case of success
2744 virDomainGetUUID(virDomainPtr domain
, unsigned char *uuid
)
2746 DEBUG("domain=%p, uuid=%p", domain
, uuid
);
2748 virResetLastError();
2750 if (!VIR_IS_DOMAIN(domain
)) {
2751 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2752 virDispatchError(NULL
);
2756 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
2757 virDispatchError(domain
->conn
);
2761 memcpy(uuid
, &domain
->uuid
[0], VIR_UUID_BUFLEN
);
2767 * virDomainGetUUIDString:
2768 * @domain: a domain object
2769 * @buf: pointer to a VIR_UUID_STRING_BUFLEN bytes array
2771 * Get the UUID for a domain as string. For more information about
2774 * Returns -1 in case of error, 0 in case of success
2777 virDomainGetUUIDString(virDomainPtr domain
, char *buf
)
2779 unsigned char uuid
[VIR_UUID_BUFLEN
];
2780 DEBUG("domain=%p, buf=%p", domain
, buf
);
2782 virResetLastError();
2784 if (!VIR_IS_DOMAIN(domain
)) {
2785 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2786 virDispatchError(NULL
);
2790 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
2794 if (virDomainGetUUID(domain
, &uuid
[0]))
2797 virUUIDFormat(uuid
, buf
);
2801 virDispatchError(domain
->conn
);
2807 * @domain: a domain object
2809 * Get the hypervisor ID number for the domain
2811 * Returns the domain ID number or (unsigned int) -1 in case of error
2814 virDomainGetID(virDomainPtr domain
)
2816 DEBUG("domain=%p", domain
);
2818 virResetLastError();
2820 if (!VIR_IS_DOMAIN(domain
)) {
2821 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2822 virDispatchError(NULL
);
2823 return ((unsigned int) -1);
2825 return (domain
->id
);
2829 * virDomainGetOSType:
2830 * @domain: a domain object
2832 * Get the type of domain operation system.
2834 * Returns the new string or NULL in case of error, the string must be
2835 * freed by the caller.
2838 virDomainGetOSType(virDomainPtr domain
)
2841 DEBUG("domain=%p", domain
);
2843 virResetLastError();
2845 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
2846 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2847 virDispatchError(NULL
);
2851 conn
= domain
->conn
;
2853 if (conn
->driver
->domainGetOSType
) {
2855 ret
= conn
->driver
->domainGetOSType (domain
);
2861 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2864 virDispatchError(domain
->conn
);
2869 * virDomainGetMaxMemory:
2870 * @domain: a domain object or NULL
2872 * Retrieve the maximum amount of physical memory allocated to a
2873 * domain. If domain is NULL, then this get the amount of memory reserved
2874 * to Domain0 i.e. the domain where the application runs.
2876 * Returns the memory size in kilobytes or 0 in case of error.
2879 virDomainGetMaxMemory(virDomainPtr domain
)
2882 DEBUG("domain=%p", domain
);
2884 virResetLastError();
2886 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
2887 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2888 virDispatchError(NULL
);
2892 conn
= domain
->conn
;
2894 if (conn
->driver
->domainGetMaxMemory
) {
2896 ret
= conn
->driver
->domainGetMaxMemory (domain
);
2902 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2905 virDispatchError(domain
->conn
);
2910 * virDomainSetMaxMemory:
2911 * @domain: a domain object or NULL
2912 * @memory: the memory size in kilobytes
2914 * Dynamically change the maximum amount of physical memory allocated to a
2915 * domain. If domain is NULL, then this change the amount of memory reserved
2916 * to Domain0 i.e. the domain where the application runs.
2917 * This function requires privileged access to the hypervisor.
2919 * This command only changes the runtime configuration of the domain,
2920 * so can only be called on an active domain.
2922 * Returns 0 in case of success and -1 in case of failure.
2925 virDomainSetMaxMemory(virDomainPtr domain
, unsigned long memory
)
2928 DEBUG("domain=%p, memory=%lu", domain
, memory
);
2930 virResetLastError();
2932 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
2933 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2934 virDispatchError(NULL
);
2937 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
2938 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
2941 if (memory
< 4096) {
2942 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
2945 conn
= domain
->conn
;
2947 if (conn
->driver
->domainSetMaxMemory
) {
2949 ret
= conn
->driver
->domainSetMaxMemory (domain
, memory
);
2955 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
2958 virDispatchError(domain
->conn
);
2963 * virDomainSetMemory:
2964 * @domain: a domain object or NULL
2965 * @memory: the memory size in kilobytes
2967 * Dynamically change the target amount of physical memory allocated to a
2968 * domain. If domain is NULL, then this change the amount of memory reserved
2969 * to Domain0 i.e. the domain where the application runs.
2970 * This function may requires privileged access to the hypervisor.
2972 * This command only changes the runtime configuration of the domain,
2973 * so can only be called on an active domain.
2975 * Returns 0 in case of success and -1 in case of failure.
2978 virDomainSetMemory(virDomainPtr domain
, unsigned long memory
)
2981 DEBUG("domain=%p, memory=%lu", domain
, memory
);
2983 virResetLastError();
2985 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
2986 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
2987 virDispatchError(NULL
);
2990 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
2991 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
2994 if (memory
< 4096) {
2995 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
2999 conn
= domain
->conn
;
3001 if (conn
->driver
->domainSetMemory
) {
3003 ret
= conn
->driver
->domainSetMemory (domain
, memory
);
3009 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3012 virDispatchError(domain
->conn
);
3017 * virDomainSetMemoryParameters:
3018 * @domain: pointer to domain object
3019 * @params: pointer to memory parameter objects
3020 * @nparams: number of memory parameter (this value should be same or
3021 * less than the number of parameters supported)
3022 * @flags: currently unused, for future extension
3024 * Change the memory tunables
3025 * This function requires privileged access to the hypervisor.
3027 * Returns -1 in case of error, 0 in case of success.
3030 virDomainSetMemoryParameters(virDomainPtr domain
,
3031 virMemoryParameterPtr params
,
3032 int nparams
, unsigned int flags
)
3035 DEBUG("domain=%p, params=%p, nparams=%d, flags=%u", domain
, params
, nparams
, flags
);
3037 virResetLastError();
3039 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
3040 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
3041 virDispatchError(NULL
);
3044 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
3045 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
3048 if ((nparams
<= 0) || (params
== NULL
)) {
3049 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
3052 conn
= domain
->conn
;
3054 if (conn
->driver
->domainSetMemoryParameters
) {
3056 ret
= conn
->driver
->domainSetMemoryParameters (domain
, params
, nparams
, flags
);
3062 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3065 virDispatchError(domain
->conn
);
3070 * virDomainGetMemoryParameters:
3071 * @domain: pointer to domain object
3072 * @params: pointer to memory parameter object
3073 * (return value, allocated by the caller)
3074 * @nparams: pointer to number of memory parameters
3075 * @flags: currently unused, for future extension
3077 * Get the memory parameters, the @params array will be filled with the values
3078 * equal to the number of parameters suggested by @nparams
3080 * As the value of @nparams is dynamic, call the API setting @nparams to 0 and
3081 * @params as NULL, the API returns the number of parameters supported by the
3082 * HV by updating @nparams on SUCCESS. The caller should then allocate @params
3083 * array, i.e. (sizeof(@virMemoryParameter) * @nparams) bytes and call the API
3086 * Here is the sample code snippet:
3088 * if ((virDomainGetMemoryParameters(dom, NULL, &nparams, 0) == 0) &&
3090 * params = vshMalloc(ctl, sizeof(virMemoryParameter) * nparams);
3091 * memset(params, 0, sizeof(virMemoryParameter) * nparams);
3092 * if (virDomainGetMemoryParameters(dom, params, &nparams, 0)) {
3093 * vshError(ctl, "%s", _("Unable to get memory parameters"));
3098 * This function requires privileged access to the hypervisor. This function
3099 * expects the caller to allocate the @param
3101 * Returns -1 in case of error, 0 in case of success.
3104 virDomainGetMemoryParameters(virDomainPtr domain
,
3105 virMemoryParameterPtr params
,
3106 int *nparams
, unsigned int flags
)
3109 DEBUG("domain=%p, params=%p, nparams=%d, flags=%u", domain
, params
, (nparams
)?*nparams
:-1, flags
);
3111 virResetLastError();
3113 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
3114 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
3115 virDispatchError(NULL
);
3118 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
3119 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
3122 if ((nparams
== NULL
) || (*nparams
< 0)) {
3123 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
3126 conn
= domain
->conn
;
3128 if (conn
->driver
->domainGetMemoryParameters
) {
3130 ret
= conn
->driver
->domainGetMemoryParameters (domain
, params
, nparams
, flags
);
3135 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3138 virDispatchError(domain
->conn
);
3144 * @domain: a domain object
3145 * @info: pointer to a virDomainInfo structure allocated by the user
3147 * Extract information about a domain. Note that if the connection
3148 * used to get the domain is limited only a partial set of the information
3151 * Returns 0 in case of success and -1 in case of failure.
3154 virDomainGetInfo(virDomainPtr domain
, virDomainInfoPtr info
)
3157 DEBUG("domain=%p, info=%p", domain
, info
);
3159 virResetLastError();
3161 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
3162 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
3163 virDispatchError(NULL
);
3167 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
3171 memset(info
, 0, sizeof(virDomainInfo
));
3173 conn
= domain
->conn
;
3175 if (conn
->driver
->domainGetInfo
) {
3177 ret
= conn
->driver
->domainGetInfo (domain
, info
);
3183 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3186 virDispatchError(domain
->conn
);
3191 * virDomainGetXMLDesc:
3192 * @domain: a domain object
3193 * @flags: an OR'ed set of virDomainXMLFlags
3195 * Provide an XML description of the domain. The description may be reused
3196 * later to relaunch the domain with virDomainCreateXML().
3198 * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
3199 * the caller must free() the returned value.
3202 virDomainGetXMLDesc(virDomainPtr domain
, int flags
)
3205 DEBUG("domain=%p, flags=%d", domain
, flags
);
3207 virResetLastError();
3209 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
3210 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
3211 virDispatchError(NULL
);
3215 conn
= domain
->conn
;
3217 if ((conn
->flags
& VIR_CONNECT_RO
) && (flags
& VIR_DOMAIN_XML_SECURE
)) {
3218 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
,
3219 _("virDomainGetXMLDesc with secure flag"));
3223 flags
&= VIR_DOMAIN_XML_FLAGS_MASK
;
3225 if (conn
->driver
->domainDumpXML
) {
3227 ret
= conn
->driver
->domainDumpXML (domain
, flags
);
3233 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3236 virDispatchError(domain
->conn
);
3241 * virConnectDomainXMLFromNative:
3242 * @conn: a connection object
3243 * @nativeFormat: configuration format importing from
3244 * @nativeConfig: the configuration data to import
3245 * @flags: currently unused, pass 0
3247 * Reads native configuration data describing a domain, and
3248 * generates libvirt domain XML. The format of the native
3249 * data is hypervisor dependant.
3251 * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
3252 * the caller must free() the returned value.
3254 char *virConnectDomainXMLFromNative(virConnectPtr conn
,
3255 const char *nativeFormat
,
3256 const char *nativeConfig
,
3259 DEBUG("conn=%p, format=%s config=%s flags=%u", conn
, nativeFormat
, nativeConfig
, flags
);
3261 virResetLastError();
3263 if (!VIR_IS_CONNECT(conn
)) {
3264 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
3265 virDispatchError(NULL
);
3269 if (nativeFormat
== NULL
|| nativeConfig
== NULL
) {
3270 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
3274 if (conn
->driver
->domainXMLFromNative
) {
3276 ret
= conn
->driver
->domainXMLFromNative (conn
,
3285 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3288 virDispatchError(conn
);
3293 * virConnectDomainXMLToNative:
3294 * @conn: a connection object
3295 * @nativeFormat: configuration format exporting to
3296 * @domainXml: the domain configuration to export
3297 * @flags: currently unused, pass 0
3299 * Reads a domain XML configuration document, and generates
3300 * generates a native configuration file describing the domain.
3301 * The format of the native data is hypervisor dependant.
3303 * Returns a 0 terminated UTF-8 encoded native config datafile, or NULL in case of error.
3304 * the caller must free() the returned value.
3306 char *virConnectDomainXMLToNative(virConnectPtr conn
,
3307 const char *nativeFormat
,
3308 const char *domainXml
,
3311 DEBUG("conn=%p, format=%s xml=%s flags=%u", conn
, nativeFormat
, domainXml
, flags
);
3313 virResetLastError();
3315 if (!VIR_IS_CONNECT(conn
)) {
3316 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
3317 virDispatchError(NULL
);
3321 if (nativeFormat
== NULL
|| domainXml
== NULL
) {
3322 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
3326 if (conn
->driver
->domainXMLToNative
) {
3328 ret
= conn
->driver
->domainXMLToNative(conn
,
3337 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3340 virDispatchError(conn
);
3346 virDomainMigrateVersion1 (virDomainPtr domain
,
3347 virConnectPtr dconn
,
3348 unsigned long flags
,
3351 unsigned long bandwidth
)
3353 virDomainPtr ddomain
= NULL
;
3354 char *uri_out
= NULL
;
3355 char *cookie
= NULL
;
3356 int cookielen
= 0, ret
;
3359 ret
= virDomainGetInfo (domain
, &info
);
3360 if (ret
== 0 && info
.state
== VIR_DOMAIN_PAUSED
) {
3361 flags
|= VIR_MIGRATE_PAUSED
;
3364 /* Prepare the migration.
3366 * The destination host may return a cookie, or leave cookie as
3369 * The destination host MUST set uri_out if uri_in is NULL.
3371 * If uri_in is non-NULL, then the destination host may modify
3372 * the URI by setting uri_out. If it does not wish to modify
3373 * the URI, it should leave uri_out as NULL.
3375 if (dconn
->driver
->domainMigratePrepare
3376 (dconn
, &cookie
, &cookielen
, uri
, &uri_out
, flags
, dname
,
3380 if (uri
== NULL
&& uri_out
== NULL
) {
3381 virLibConnError (domain
->conn
, VIR_ERR_INTERNAL_ERROR
,
3382 _("domainMigratePrepare did not set uri"));
3386 uri
= uri_out
; /* Did domainMigratePrepare change URI? */
3387 assert (uri
!= NULL
);
3389 /* Perform the migration. The driver isn't supposed to return
3390 * until the migration is complete.
3392 if (domain
->conn
->driver
->domainMigratePerform
3393 (domain
, cookie
, cookielen
, uri
, flags
, dname
, bandwidth
) == -1)
3396 /* Get the destination domain and return it or error.
3397 * 'domain' no longer actually exists at this point
3398 * (or so we hope), but we still use the object in memory
3399 * in order to get the name.
3401 dname
= dname
? dname
: domain
->name
;
3402 if (dconn
->driver
->domainMigrateFinish
)
3403 ddomain
= dconn
->driver
->domainMigrateFinish
3404 (dconn
, dname
, cookie
, cookielen
, uri
, flags
);
3406 ddomain
= virDomainLookupByName (dconn
, dname
);
3415 virDomainMigrateVersion2 (virDomainPtr domain
,
3416 virConnectPtr dconn
,
3417 unsigned long flags
,
3420 unsigned long bandwidth
)
3422 virDomainPtr ddomain
= NULL
;
3423 char *uri_out
= NULL
;
3424 char *cookie
= NULL
;
3425 char *dom_xml
= NULL
;
3426 int cookielen
= 0, ret
;
3428 virErrorPtr orig_err
= NULL
;
3430 /* Prepare the migration.
3432 * The destination host may return a cookie, or leave cookie as
3435 * The destination host MUST set uri_out if uri_in is NULL.
3437 * If uri_in is non-NULL, then the destination host may modify
3438 * the URI by setting uri_out. If it does not wish to modify
3439 * the URI, it should leave uri_out as NULL.
3442 /* In version 2 of the protocol, the prepare step is slightly
3443 * different. We fetch the domain XML of the source domain
3444 * and pass it to Prepare2.
3446 if (!domain
->conn
->driver
->domainDumpXML
) {
3447 virLibConnError (domain
->conn
, VIR_ERR_INTERNAL_ERROR
, __FUNCTION__
);
3448 virDispatchError(domain
->conn
);
3451 dom_xml
= domain
->conn
->driver
->domainDumpXML (domain
,
3452 VIR_DOMAIN_XML_SECURE
|
3453 VIR_DOMAIN_XML_UPDATE_CPU
);
3457 ret
= virDomainGetInfo (domain
, &info
);
3458 if (ret
== 0 && info
.state
== VIR_DOMAIN_PAUSED
) {
3459 flags
|= VIR_MIGRATE_PAUSED
;
3462 ret
= dconn
->driver
->domainMigratePrepare2
3463 (dconn
, &cookie
, &cookielen
, uri
, &uri_out
, flags
, dname
,
3464 bandwidth
, dom_xml
);
3469 if (uri
== NULL
&& uri_out
== NULL
) {
3470 virLibConnError (domain
->conn
, VIR_ERR_INTERNAL_ERROR
,
3471 _("domainMigratePrepare2 did not set uri"));
3472 virDispatchError(domain
->conn
);
3476 uri
= uri_out
; /* Did domainMigratePrepare2 change URI? */
3477 assert (uri
!= NULL
);
3479 /* Perform the migration. The driver isn't supposed to return
3480 * until the migration is complete.
3482 ret
= domain
->conn
->driver
->domainMigratePerform
3483 (domain
, cookie
, cookielen
, uri
, flags
, dname
, bandwidth
);
3485 /* Perform failed. Make sure Finish doesn't overwrite the error */
3487 orig_err
= virSaveLastError();
3489 /* In version 2 of the migration protocol, we pass the
3490 * status code from the sender to the destination host,
3491 * so it can do any cleanup if the migration failed.
3493 dname
= dname
? dname
: domain
->name
;
3494 ddomain
= dconn
->driver
->domainMigrateFinish2
3495 (dconn
, dname
, cookie
, cookielen
, uri
, flags
, ret
);
3499 virSetError(orig_err
);
3500 virFreeError(orig_err
);
3509 * This is sort of a migration v3
3511 * In this version, the client does not talk to the destination
3512 * libvirtd. The source libvirtd will still try to talk to the
3513 * destination libvirtd though, and will do the prepare/perform/finish
3517 virDomainMigratePeer2Peer (virDomainPtr domain
,
3518 unsigned long flags
,
3521 unsigned long bandwidth
)
3523 if (!domain
->conn
->driver
->domainMigratePerform
) {
3524 virLibConnError (domain
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3525 virDispatchError(domain
->conn
);
3529 /* Perform the migration. The driver isn't supposed to return
3530 * until the migration is complete.
3532 return domain
->conn
->driver
->domainMigratePerform(domain
,
3543 * This is a variation on v1 & 2 migration
3545 * This is for hypervisors which can directly handshake
3546 * without any libvirtd involvement on destination either
3547 * from client, or source libvirt.
3549 * eg, XenD can talk direct to XenD, so libvirtd on dest
3550 * does not need to be involved at all, or even running
3553 virDomainMigrateDirect (virDomainPtr domain
,
3554 unsigned long flags
,
3557 unsigned long bandwidth
)
3559 if (!domain
->conn
->driver
->domainMigratePerform
) {
3560 virLibConnError (domain
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3561 virDispatchError(domain
->conn
);
3565 /* Perform the migration. The driver isn't supposed to return
3566 * until the migration is complete.
3568 return domain
->conn
->driver
->domainMigratePerform(domain
,
3580 * @domain: a domain object
3581 * @dconn: destination host (a connection object)
3583 * @dname: (optional) rename domain to this at destination
3584 * @uri: (optional) dest hostname/URI as seen from the source host
3585 * @bandwidth: (optional) specify migration bandwidth limit in Mbps
3587 * Migrate the domain object from its current host to the destination
3588 * host given by dconn (a connection to the destination host).
3590 * Flags may be one of more of the following:
3591 * VIR_MIGRATE_LIVE Do not pause the VM during migration
3592 * VIR_MIGRATE_PEER2PEER Direct connection between source & destination hosts
3593 * VIR_MIGRATE_TUNNELLED Tunnel migration data over the libvirt RPC channel
3594 * VIR_MIGRATE_PERSIST_DEST If the migration is successful, persist the domain
3595 * on the destination host.
3596 * VIR_MIGRATE_UNDEFINE_SOURCE If the migration is successful, undefine the
3597 * domain on the source host.
3598 * VIR_MIGRATE_PAUSED Leave the domain suspended on the remote side.
3600 * VIR_MIGRATE_TUNNELLED requires that VIR_MIGRATE_PEER2PEER be set.
3601 * Applications using the VIR_MIGRATE_PEER2PEER flag will probably
3602 * prefer to invoke virDomainMigrateToURI, avoiding the need to
3603 * open connection to the destination host themselves.
3605 * If a hypervisor supports renaming domains during migration,
3606 * then you may set the dname parameter to the new name (otherwise
3607 * it keeps the same name). If this is not supported by the
3608 * hypervisor, dname must be NULL or else you will get an error.
3610 * If the VIR_MIGRATE_PEER2PEER flag is set, the uri parameter
3611 * must be a valid libvirt connection URI, by which the source
3612 * libvirt driver can connect to the destination libvirt. If
3613 * omitted, the dconn connection object will be queried for its
3616 * If the VIR_MIGRATE_PEER2PEER flag is NOT set, the URI parameter
3617 * takes a hypervisor specific format. The hypervisor capabilities
3618 * XML includes details of the support URI schemes. If omitted
3619 * the dconn will be asked for a default URI.
3621 * In either case it is typically only necessary to specify a
3622 * URI if the destination host has multiple interfaces and a
3623 * specific interface is required to transmit migration data.
3625 * The maximum bandwidth (in Mbps) that will be used to do migration
3626 * can be specified with the bandwidth parameter. If set to 0,
3627 * libvirt will choose a suitable default. Some hypervisors do
3628 * not support this feature and will return an error if bandwidth
3631 * To see which features are supported by the current hypervisor,
3632 * see virConnectGetCapabilities, /capabilities/host/migration_features.
3634 * There are many limitations on migration imposed by the underlying
3635 * technology - for example it may not be possible to migrate between
3636 * different processors even with the same architecture, or between
3637 * different types of hypervisor.
3639 * Returns the new domain object if the migration was successful,
3640 * or NULL in case of error. Note that the new domain object
3641 * exists in the scope of the destination connection (dconn).
3644 virDomainMigrate (virDomainPtr domain
,
3645 virConnectPtr dconn
,
3646 unsigned long flags
,
3649 unsigned long bandwidth
)
3651 virDomainPtr ddomain
= NULL
;
3652 DEBUG("domain=%p, dconn=%p, flags=%lu, dname=%s, uri=%s, bandwidth=%lu",
3653 domain
, dconn
, flags
, NULLSTR(dname
), NULLSTR(uri
), bandwidth
);
3655 virResetLastError();
3657 /* First checkout the source */
3658 if (!VIR_IS_CONNECTED_DOMAIN (domain
)) {
3659 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
3660 virDispatchError(NULL
);
3663 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
3664 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
3668 /* Now checkout the destination */
3669 if (!VIR_IS_CONNECT(dconn
)) {
3670 virLibConnError(domain
->conn
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
3673 if (dconn
->flags
& VIR_CONNECT_RO
) {
3674 /* NB, deliberately report error against source object, not dest */
3675 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
3679 if (flags
& VIR_MIGRATE_PEER2PEER
) {
3680 if (VIR_DRV_SUPPORTS_FEATURE (domain
->conn
->driver
, domain
->conn
,
3681 VIR_DRV_FEATURE_MIGRATION_P2P
)) {
3682 char *dstURI
= NULL
;
3684 dstURI
= virConnectGetURI(dconn
);
3689 if (virDomainMigratePeer2Peer(domain
, flags
, dname
, uri
? uri
: dstURI
, bandwidth
) < 0) {
3695 ddomain
= virDomainLookupByName (dconn
, dname
? dname
: domain
->name
);
3697 /* This driver does not support peer to peer migration */
3698 virLibConnError (domain
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3702 if (flags
& VIR_MIGRATE_TUNNELLED
) {
3703 virLibConnError(domain
->conn
, VIR_ERR_OPERATION_INVALID
,
3704 _("cannot perform tunnelled migration without using peer2peer flag"));
3708 /* Check that migration is supported by both drivers. */
3709 if (VIR_DRV_SUPPORTS_FEATURE(domain
->conn
->driver
, domain
->conn
,
3710 VIR_DRV_FEATURE_MIGRATION_V1
) &&
3711 VIR_DRV_SUPPORTS_FEATURE(dconn
->driver
, dconn
,
3712 VIR_DRV_FEATURE_MIGRATION_V1
))
3713 ddomain
= virDomainMigrateVersion1(domain
, dconn
, flags
, dname
, uri
, bandwidth
);
3714 else if (VIR_DRV_SUPPORTS_FEATURE(domain
->conn
->driver
, domain
->conn
,
3715 VIR_DRV_FEATURE_MIGRATION_V2
) &&
3716 VIR_DRV_SUPPORTS_FEATURE(dconn
->driver
, dconn
,
3717 VIR_DRV_FEATURE_MIGRATION_V2
))
3718 ddomain
= virDomainMigrateVersion2(domain
, dconn
, flags
, dname
, uri
, bandwidth
);
3720 /* This driver does not support any migration method */
3721 virLibConnError(domain
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3726 if (ddomain
== NULL
)
3732 virDispatchError(domain
->conn
);
3738 * virDomainMigrateToURI:
3739 * @domain: a domain object
3740 * @duri: mandatory URI for the destination host
3742 * @dname: (optional) rename domain to this at destination
3743 * @bandwidth: (optional) specify migration bandwidth limit in Mbps
3745 * Migrate the domain object from its current host to the destination
3746 * host given by duri.
3748 * Flags may be one of more of the following:
3749 * VIR_MIGRATE_LIVE Do not pause the VM during migration
3750 * VIR_MIGRATE_PEER2PEER Direct connection between source & destination hosts
3751 * VIR_MIGRATE_TUNNELLED Tunnel migration data over the libvirt RPC channel
3752 * VIR_MIGRATE_PERSIST_DEST If the migration is successful, persist the domain
3753 * on the destination host.
3754 * VIR_MIGRATE_UNDEFINE_SOURCE If the migration is successful, undefine the
3755 * domain on the source host.
3757 * The operation of this API hinges on the VIR_MIGRATE_PEER2PEER flag.
3758 * If the VIR_MIGRATE_PEER2PEER flag is NOT set, the duri parameter
3759 * takes a hypervisor specific format. The uri_transports element of the
3760 * hypervisor capabilities XML includes details of the supported URI
3761 * schemes. Not all hypervisors will support this mode of migration, so
3762 * if the VIR_MIGRATE_PEER2PEER flag is not set, then it may be necessary
3763 * to use the alternative virDomainMigrate API providing and explicit
3764 * virConnectPtr for the destination host.
3766 * If the VIR_MIGRATE_PEER2PEER flag IS set, the duri parameter
3767 * must be a valid libvirt connection URI, by which the source
3768 * libvirt driver can connect to the destination libvirt.
3770 * VIR_MIGRATE_TUNNELLED requires that VIR_MIGRATE_PEER2PEER be set.
3772 * If a hypervisor supports renaming domains during migration,
3773 * the dname parameter specifies the new name for the domain.
3774 * Setting dname to NULL keeps the domain name the same. If domain
3775 * renaming is not supported by the hypervisor, dname must be NULL or
3776 * else an error will be returned.
3778 * The maximum bandwidth (in Mbps) that will be used to do migration
3779 * can be specified with the bandwidth parameter. If set to 0,
3780 * libvirt will choose a suitable default. Some hypervisors do
3781 * not support this feature and will return an error if bandwidth
3784 * To see which features are supported by the current hypervisor,
3785 * see virConnectGetCapabilities, /capabilities/host/migration_features.
3787 * There are many limitations on migration imposed by the underlying
3788 * technology - for example it may not be possible to migrate between
3789 * different processors even with the same architecture, or between
3790 * different types of hypervisor.
3792 * Returns 0 if the migration succeeded, -1 upon error.
3795 virDomainMigrateToURI (virDomainPtr domain
,
3797 unsigned long flags
,
3799 unsigned long bandwidth
)
3801 DEBUG("domain=%p, duri=%p, flags=%lu, dname=%s, bandwidth=%lu",
3802 domain
, NULLSTR(duri
), flags
, NULLSTR(dname
), bandwidth
);
3804 virResetLastError();
3806 /* First checkout the source */
3807 if (!VIR_IS_CONNECTED_DOMAIN (domain
)) {
3808 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
3809 virDispatchError(NULL
);
3812 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
3813 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
3818 virLibConnError (domain
->conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
3822 if (flags
& VIR_MIGRATE_PEER2PEER
) {
3823 if (VIR_DRV_SUPPORTS_FEATURE (domain
->conn
->driver
, domain
->conn
,
3824 VIR_DRV_FEATURE_MIGRATION_P2P
)) {
3825 if (virDomainMigratePeer2Peer (domain
, flags
, dname
, duri
, bandwidth
) < 0)
3828 /* No peer to peer migration supported */
3829 virLibConnError (domain
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3833 if (VIR_DRV_SUPPORTS_FEATURE (domain
->conn
->driver
, domain
->conn
,
3834 VIR_DRV_FEATURE_MIGRATION_DIRECT
)) {
3835 if (virDomainMigrateDirect (domain
, flags
, dname
, duri
, bandwidth
) < 0)
3838 /* Cannot do a migration with only the perform step */
3839 virLibConnError (domain
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3847 virDispatchError(domain
->conn
);
3853 * Not for public use. This function is part of the internal
3854 * implementation of migration in the remote case.
3857 virDomainMigratePrepare (virConnectPtr dconn
,
3862 unsigned long flags
,
3864 unsigned long bandwidth
)
3866 VIR_DEBUG("dconn=%p, cookie=%p, cookielen=%p, uri_in=%s, uri_out=%p, "
3867 "flags=%lu, dname=%s, bandwidth=%lu", dconn
, cookie
, cookielen
,
3868 NULLSTR(uri_in
), uri_out
, flags
, NULLSTR(dname
), bandwidth
);
3870 virResetLastError();
3872 if (!VIR_IS_CONNECT (dconn
)) {
3873 virLibConnError (NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
3874 virDispatchError(NULL
);
3878 if (dconn
->flags
& VIR_CONNECT_RO
) {
3879 virLibConnError(dconn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
3883 if (dconn
->driver
->domainMigratePrepare
) {
3885 ret
= dconn
->driver
->domainMigratePrepare (dconn
, cookie
, cookielen
,
3887 flags
, dname
, bandwidth
);
3893 virLibConnError (dconn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3896 virDispatchError(dconn
);
3901 * Not for public use. This function is part of the internal
3902 * implementation of migration in the remote case.
3905 virDomainMigratePerform (virDomainPtr domain
,
3909 unsigned long flags
,
3911 unsigned long bandwidth
)
3914 VIR_DEBUG("domain=%p, cookie=%p, cookielen=%d, uri=%s, flags=%lu, "
3915 "dname=%s, bandwidth=%lu", domain
, cookie
, cookielen
, uri
, flags
,
3916 NULLSTR(dname
), bandwidth
);
3918 virResetLastError();
3920 if (!VIR_IS_CONNECTED_DOMAIN (domain
)) {
3921 virLibDomainError (NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
3922 virDispatchError(NULL
);
3925 conn
= domain
->conn
;
3927 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
3928 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
3932 if (conn
->driver
->domainMigratePerform
) {
3934 ret
= conn
->driver
->domainMigratePerform (domain
, cookie
, cookielen
,
3936 flags
, dname
, bandwidth
);
3942 virLibDomainError (domain
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3945 virDispatchError(domain
->conn
);
3950 * Not for public use. This function is part of the internal
3951 * implementation of migration in the remote case.
3954 virDomainMigrateFinish (virConnectPtr dconn
,
3959 unsigned long flags
)
3961 VIR_DEBUG("dconn=%p, dname=%s, cookie=%p, cookielen=%d, uri=%s, "
3962 "flags=%lu", dconn
, NULLSTR(dname
), cookie
, cookielen
,
3965 virResetLastError();
3967 if (!VIR_IS_CONNECT (dconn
)) {
3968 virLibConnError (NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
3969 virDispatchError(NULL
);
3973 if (dconn
->flags
& VIR_CONNECT_RO
) {
3974 virLibConnError(dconn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
3978 if (dconn
->driver
->domainMigrateFinish
) {
3980 ret
= dconn
->driver
->domainMigrateFinish (dconn
, dname
,
3988 virLibConnError (dconn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
3991 virDispatchError(dconn
);
3997 * Not for public use. This function is part of the internal
3998 * implementation of migration in the remote case.
4001 virDomainMigratePrepare2 (virConnectPtr dconn
,
4006 unsigned long flags
,
4008 unsigned long bandwidth
,
4009 const char *dom_xml
)
4011 VIR_DEBUG("dconn=%p, cookie=%p, cookielen=%p, uri_in=%s, uri_out=%p,"
4012 "flags=%lu, dname=%s, bandwidth=%lu, dom_xml=%s", dconn
,
4013 cookie
, cookielen
, uri_in
, uri_out
, flags
, NULLSTR(dname
),
4014 bandwidth
, dom_xml
);
4016 virResetLastError();
4018 if (!VIR_IS_CONNECT (dconn
)) {
4019 virLibConnError (NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
4020 virDispatchError(NULL
);
4024 if (dconn
->flags
& VIR_CONNECT_RO
) {
4025 virLibConnError(dconn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
4029 if (dconn
->driver
->domainMigratePrepare2
) {
4031 ret
= dconn
->driver
->domainMigratePrepare2 (dconn
, cookie
, cookielen
,
4033 flags
, dname
, bandwidth
,
4040 virLibConnError (dconn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4043 virDispatchError(dconn
);
4048 * Not for public use. This function is part of the internal
4049 * implementation of migration in the remote case.
4052 virDomainMigrateFinish2 (virConnectPtr dconn
,
4057 unsigned long flags
,
4060 VIR_DEBUG("dconn=%p, dname=%s, cookie=%p, cookielen=%d, uri=%s, "
4061 "flags=%lu, retcode=%d", dconn
, NULLSTR(dname
), cookie
,
4062 cookielen
, uri
, flags
, retcode
);
4064 virResetLastError();
4066 if (!VIR_IS_CONNECT (dconn
)) {
4067 virLibConnError (NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
4068 virDispatchError(NULL
);
4072 if (dconn
->flags
& VIR_CONNECT_RO
) {
4073 virLibConnError(dconn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
4077 if (dconn
->driver
->domainMigrateFinish2
) {
4079 ret
= dconn
->driver
->domainMigrateFinish2 (dconn
, dname
,
4088 virLibConnError (dconn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4091 virDispatchError(dconn
);
4097 * Not for public use. This function is part of the internal
4098 * implementation of migration in the remote case.
4101 virDomainMigratePrepareTunnel(virConnectPtr conn
,
4103 unsigned long flags
,
4105 unsigned long bandwidth
,
4106 const char *dom_xml
)
4109 VIR_DEBUG("conn=%p, stream=%p, flags=%lu, dname=%s, "
4110 "bandwidth=%lu, dom_xml=%s", conn
, st
, flags
,
4111 NULLSTR(dname
), bandwidth
, dom_xml
);
4113 virResetLastError();
4115 if (!VIR_IS_CONNECT(conn
)) {
4116 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
4117 virDispatchError(NULL
);
4121 if (conn
->flags
& VIR_CONNECT_RO
) {
4122 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
4126 if (conn
!= st
->conn
) {
4127 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
4131 if (conn
->driver
->domainMigratePrepareTunnel
) {
4132 int rv
= conn
->driver
->domainMigratePrepareTunnel(conn
, st
,
4134 bandwidth
, dom_xml
);
4140 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4143 virDispatchError(conn
);
4150 * @conn: pointer to the hypervisor connection
4151 * @info: pointer to a virNodeInfo structure allocated by the user
4153 * Extract hardware information about the node.
4155 * Returns 0 in case of success and -1 in case of failure.
4158 virNodeGetInfo(virConnectPtr conn
, virNodeInfoPtr info
)
4160 DEBUG("conn=%p, info=%p", conn
, info
);
4162 virResetLastError();
4164 if (!VIR_IS_CONNECT(conn
)) {
4165 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
4166 virDispatchError(NULL
);
4170 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
4174 if (conn
->driver
->nodeGetInfo
) {
4176 ret
= conn
->driver
->nodeGetInfo (conn
, info
);
4182 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4185 virDispatchError(conn
);
4190 * virConnectGetCapabilities:
4191 * @conn: pointer to the hypervisor connection
4193 * Provides capabilities of the hypervisor / driver.
4195 * Returns NULL in case of error, or an XML string
4196 * defining the capabilities.
4197 * The client must free the returned string after use.
4200 virConnectGetCapabilities (virConnectPtr conn
)
4202 DEBUG("conn=%p", conn
);
4204 virResetLastError();
4206 if (!VIR_IS_CONNECT (conn
)) {
4207 virLibConnError (NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
4208 virDispatchError(NULL
);
4212 if (conn
->driver
->getCapabilities
) {
4214 ret
= conn
->driver
->getCapabilities (conn
);
4217 DEBUG("conn=%p ret=%s", conn
, ret
);
4221 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4224 virDispatchError(conn
);
4229 * virNodeGetFreeMemory:
4230 * @conn: pointer to the hypervisor connection
4232 * provides the free memory available on the Node
4233 * Note: most libvirt APIs provide memory sizes in kilobytes, but in this
4234 * function the returned value is in bytes. Divide by 1024 as necessary.
4236 * Returns the available free memory in bytes or 0 in case of error
4239 virNodeGetFreeMemory(virConnectPtr conn
)
4241 DEBUG("conn=%p", conn
);
4243 virResetLastError();
4245 if (!VIR_IS_CONNECT (conn
)) {
4246 virLibConnError (NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
4247 virDispatchError(NULL
);
4251 if (conn
->driver
->getFreeMemory
) {
4252 unsigned long long ret
;
4253 ret
= conn
->driver
->getFreeMemory (conn
);
4259 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4262 virDispatchError(conn
);
4267 * virDomainGetSchedulerType:
4268 * @domain: pointer to domain object
4269 * @nparams: number of scheduler parameters(return value)
4271 * Get the scheduler type.
4273 * Returns NULL in case of error. The caller must free the returned string.
4276 virDomainGetSchedulerType(virDomainPtr domain
, int *nparams
)
4280 DEBUG("domain=%p, nparams=%p", domain
, nparams
);
4282 virResetLastError();
4284 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
4285 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
4286 virDispatchError(NULL
);
4289 conn
= domain
->conn
;
4291 if (conn
->driver
->domainGetSchedulerType
){
4292 schedtype
= conn
->driver
->domainGetSchedulerType (domain
, nparams
);
4298 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4301 virDispatchError(domain
->conn
);
4307 * virDomainGetSchedulerParameters:
4308 * @domain: pointer to domain object
4309 * @params: pointer to scheduler parameter object
4311 * @nparams: pointer to number of scheduler parameter
4312 * (this value should be same than the returned value
4313 * nparams of virDomainGetSchedulerType)
4315 * Get the scheduler parameters, the @params array will be filled with the
4318 * Returns -1 in case of error, 0 in case of success.
4321 virDomainGetSchedulerParameters(virDomainPtr domain
,
4322 virSchedParameterPtr params
, int *nparams
)
4325 DEBUG("domain=%p, params=%p, nparams=%p", domain
, params
, nparams
);
4327 virResetLastError();
4329 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
4330 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
4331 virDispatchError(NULL
);
4334 conn
= domain
->conn
;
4336 if (conn
->driver
->domainGetSchedulerParameters
) {
4338 ret
= conn
->driver
->domainGetSchedulerParameters (domain
, params
, nparams
);
4344 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4347 virDispatchError(domain
->conn
);
4352 * virDomainSetSchedulerParameters:
4353 * @domain: pointer to domain object
4354 * @params: pointer to scheduler parameter objects
4355 * @nparams: number of scheduler parameter
4356 * (this value should be same or less than the returned value
4357 * nparams of virDomainGetSchedulerType)
4359 * Change the scheduler parameters
4361 * Returns -1 in case of error, 0 in case of success.
4364 virDomainSetSchedulerParameters(virDomainPtr domain
,
4365 virSchedParameterPtr params
, int nparams
)
4368 DEBUG("domain=%p, params=%p, nparams=%d", domain
, params
, nparams
);
4370 virResetLastError();
4372 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
4373 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
4374 virDispatchError(NULL
);
4377 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
4378 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
4381 conn
= domain
->conn
;
4383 if (conn
->driver
->domainSetSchedulerParameters
) {
4385 ret
= conn
->driver
->domainSetSchedulerParameters (domain
, params
, nparams
);
4391 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4394 virDispatchError(domain
->conn
);
4400 * virDomainBlockStats:
4401 * @dom: pointer to the domain object
4402 * @path: path to the block device
4403 * @stats: block device stats (returned)
4404 * @size: size of stats structure
4406 * This function returns block device (disk) stats for block
4407 * devices attached to the domain.
4409 * The path parameter is the name of the block device. Get this
4410 * by calling virDomainGetXMLDesc and finding the <target dev='...'>
4411 * attribute within //domain/devices/disk. (For example, "xvda").
4413 * Domains may have more than one block device. To get stats for
4414 * each you should make multiple calls to this function.
4416 * Individual fields within the stats structure may be returned
4417 * as -1, which indicates that the hypervisor does not support
4418 * that particular statistic.
4420 * Returns: 0 in case of success or -1 in case of failure.
4423 virDomainBlockStats (virDomainPtr dom
, const char *path
,
4424 virDomainBlockStatsPtr stats
, size_t size
)
4427 struct _virDomainBlockStats stats2
= { -1, -1, -1, -1, -1 };
4428 DEBUG("domain=%p, path=%s, stats=%p, size=%zi", dom
, path
, stats
, size
);
4430 virResetLastError();
4432 if (!VIR_IS_CONNECTED_DOMAIN (dom
)) {
4433 virLibDomainError (NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
4434 virDispatchError(NULL
);
4437 if (!path
|| !stats
|| size
> sizeof stats2
) {
4438 virLibDomainError (dom
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
4443 if (conn
->driver
->domainBlockStats
) {
4444 if (conn
->driver
->domainBlockStats (dom
, path
, &stats2
) == -1)
4447 memcpy (stats
, &stats2
, size
);
4451 virLibDomainError (dom
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4454 virDispatchError(dom
->conn
);
4459 * virDomainInterfaceStats:
4460 * @dom: pointer to the domain object
4461 * @path: path to the interface
4462 * @stats: network interface stats (returned)
4463 * @size: size of stats structure
4465 * This function returns network interface stats for interfaces
4466 * attached to the domain.
4468 * The path parameter is the name of the network interface.
4470 * Domains may have more than one network interface. To get stats for
4471 * each you should make multiple calls to this function.
4473 * Individual fields within the stats structure may be returned
4474 * as -1, which indicates that the hypervisor does not support
4475 * that particular statistic.
4477 * Returns: 0 in case of success or -1 in case of failure.
4480 virDomainInterfaceStats (virDomainPtr dom
, const char *path
,
4481 virDomainInterfaceStatsPtr stats
, size_t size
)
4484 struct _virDomainInterfaceStats stats2
= { -1, -1, -1, -1,
4486 DEBUG("domain=%p, path=%s, stats=%p, size=%zi", dom
, path
, stats
, size
);
4488 virResetLastError();
4490 if (!VIR_IS_CONNECTED_DOMAIN (dom
)) {
4491 virLibDomainError (NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
4492 virDispatchError(NULL
);
4495 if (!path
|| !stats
|| size
> sizeof stats2
) {
4496 virLibDomainError (dom
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
4501 if (conn
->driver
->domainInterfaceStats
) {
4502 if (conn
->driver
->domainInterfaceStats (dom
, path
, &stats2
) == -1)
4505 memcpy (stats
, &stats2
, size
);
4509 virLibDomainError (dom
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4512 virDispatchError(dom
->conn
);
4517 * virDomainMemoryStats:
4518 * @dom: pointer to the domain object
4519 * @stats: nr_stats-sized array of stat structures (returned)
4520 * @nr_stats: number of memory statistics requested
4521 * @flags: unused, always pass 0
4523 * This function provides memory statistics for the domain.
4525 * Up to 'nr_stats' elements of 'stats' will be populated with memory statistics
4526 * from the domain. Only statistics supported by the domain, the driver, and
4527 * this version of libvirt will be returned.
4529 * Memory Statistics:
4531 * VIR_DOMAIN_MEMORY_STAT_SWAP_IN:
4532 * The total amount of data read from swap space (in kb).
4533 * VIR_DOMAIN_MEMORY_STAT_SWAP_OUT:
4534 * The total amount of memory written out to swap space (in kb).
4535 * VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT:
4536 * The number of page faults that required disk IO to service.
4537 * VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT:
4538 * The number of page faults serviced without disk IO.
4539 * VIR_DOMAIN_MEMORY_STAT_UNUSED:
4540 * The amount of memory which is not being used for any purpose (in kb).
4541 * VIR_DOMAIN_MEMORY_STAT_AVAILABLE:
4542 * The total amount of memory available to the domain's OS (in kb).
4544 * Returns: The number of stats provided or -1 in case of failure.
4546 int virDomainMemoryStats (virDomainPtr dom
, virDomainMemoryStatPtr stats
,
4547 unsigned int nr_stats
, unsigned int flags
)
4550 unsigned long nr_stats_ret
= 0;
4551 DEBUG("domain=%p, stats=%p, nr_stats=%u", dom
, stats
, nr_stats
);
4554 virLibDomainError (dom
, VIR_ERR_INVALID_ARG
,
4555 _("flags must be zero"));
4559 virResetLastError();
4561 if (!VIR_IS_CONNECTED_DOMAIN (dom
)) {
4562 virLibDomainError (NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
4563 virDispatchError(NULL
);
4566 if (!stats
|| nr_stats
== 0)
4569 if (nr_stats
> VIR_DOMAIN_MEMORY_STAT_NR
)
4570 nr_stats
= VIR_DOMAIN_MEMORY_STAT_NR
;
4573 if (conn
->driver
->domainMemoryStats
) {
4574 nr_stats_ret
= conn
->driver
->domainMemoryStats (dom
, stats
, nr_stats
);
4575 if (nr_stats_ret
== -1)
4577 return nr_stats_ret
;
4580 virLibDomainError (dom
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4583 virDispatchError(dom
->conn
);
4588 * virDomainBlockPeek:
4589 * @dom: pointer to the domain object
4590 * @path: path to the block device
4591 * @offset: offset within block device
4592 * @size: size to read
4593 * @buffer: return buffer (must be at least size bytes)
4594 * @flags: unused, always pass 0
4596 * This function allows you to read the contents of a domain's
4599 * Typical uses for this are to determine if the domain has
4600 * written a Master Boot Record (indicating that the domain
4601 * has completed installation), or to try to work out the state
4602 * of the domain's filesystems.
4604 * (Note that in the local case you might try to open the
4605 * block device or file directly, but that won't work in the
4606 * remote case, nor if you don't have sufficient permission.
4607 * Hence the need for this call).
4609 * 'path' must be a device or file corresponding to the domain.
4610 * In other words it must be the precise string returned in
4611 * a <disk><source dev='...'/></disk> from
4612 * virDomainGetXMLDesc.
4614 * 'offset' and 'size' represent an area which must lie entirely
4615 * within the device or file. 'size' may be 0 to test if the
4616 * call would succeed.
4618 * 'buffer' is the return buffer and must be at least 'size' bytes.
4620 * NB. The remote driver imposes a 64K byte limit on 'size'.
4621 * For your program to be able to work reliably over a remote
4622 * connection you should split large requests to <= 65536 bytes.
4624 * Returns: 0 in case of success or -1 in case of failure.
4627 virDomainBlockPeek (virDomainPtr dom
,
4629 unsigned long long offset
/* really 64 bits */,
4635 DEBUG("domain=%p, path=%s, offset=%lld, size=%zi, buffer=%p",
4636 dom
, path
, offset
, size
, buffer
);
4638 virResetLastError();
4640 if (!VIR_IS_CONNECTED_DOMAIN (dom
)) {
4641 virLibDomainError (NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
4642 virDispatchError(NULL
);
4647 if (dom
->conn
->flags
& VIR_CONNECT_RO
) {
4648 virLibDomainError(dom
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
4653 virLibDomainError (dom
, VIR_ERR_INVALID_ARG
,
4659 virLibDomainError (dom
, VIR_ERR_INVALID_ARG
,
4660 _("flags must be zero"));
4664 /* Allow size == 0 as an access test. */
4665 if (size
> 0 && !buffer
) {
4666 virLibDomainError (dom
, VIR_ERR_INVALID_ARG
,
4667 _("buffer is NULL"));
4671 if (conn
->driver
->domainBlockPeek
) {
4673 ret
=conn
->driver
->domainBlockPeek (dom
, path
, offset
, size
,
4680 virLibDomainError (dom
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4683 virDispatchError(dom
->conn
);
4688 * virDomainMemoryPeek:
4689 * @dom: pointer to the domain object
4690 * @start: start of memory to peek
4691 * @size: size of memory to peek
4692 * @buffer: return buffer (must be at least size bytes)
4693 * @flags: flags, see below
4695 * This function allows you to read the contents of a domain's
4698 * The memory which is read is controlled by the 'start', 'size'
4699 * and 'flags' parameters.
4701 * If 'flags' is VIR_MEMORY_VIRTUAL then the 'start' and 'size'
4702 * parameters are interpreted as virtual memory addresses for
4703 * whichever task happens to be running on the domain at the
4704 * moment. Although this sounds haphazard it is in fact what
4705 * you want in order to read Linux kernel state, because it
4706 * ensures that pointers in the kernel image can be interpreted
4709 * 'buffer' is the return buffer and must be at least 'size' bytes.
4710 * 'size' may be 0 to test if the call would succeed.
4712 * NB. The remote driver imposes a 64K byte limit on 'size'.
4713 * For your program to be able to work reliably over a remote
4714 * connection you should split large requests to <= 65536 bytes.
4716 * Returns: 0 in case of success or -1 in case of failure.
4719 virDomainMemoryPeek (virDomainPtr dom
,
4720 unsigned long long start
/* really 64 bits */,
4726 DEBUG ("domain=%p, start=%lld, size=%zi, buffer=%p, flags=%d",
4727 dom
, start
, size
, buffer
, flags
);
4729 virResetLastError();
4731 if (!VIR_IS_CONNECTED_DOMAIN (dom
)) {
4732 virLibDomainError (NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
4733 virDispatchError(NULL
);
4738 if (dom
->conn
->flags
& VIR_CONNECT_RO
) {
4739 virLibDomainError(dom
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
4743 /* Note on access to physical memory: A VIR_MEMORY_PHYSICAL flag is
4744 * a possibility. However it isn't really useful unless the caller
4745 * can also access registers, particularly CR3 on x86 in order to
4746 * get the Page Table Directory. Since registers are different on
4747 * every architecture, that would imply another call to get the
4748 * machine registers.
4750 * The QEMU driver handles VIR_MEMORY_VIRTUAL, mapping it
4751 * to the qemu 'memsave' command which does the virtual to physical
4752 * mapping inside qemu.
4754 * The QEMU driver also handles VIR_MEMORY_PHYSICAL, mapping it
4755 * to the qemu 'pmemsave' command.
4757 * At time of writing there is no Xen driver. However the Xen
4758 * hypervisor only lets you map physical pages from other domains,
4759 * and so the Xen driver would have to do the virtual to physical
4760 * mapping by chasing 2, 3 or 4-level page tables from the PTD.
4761 * There is example code in libxc (xc_translate_foreign_address)
4762 * which does this, although we cannot copy this code directly
4763 * because of incompatible licensing.
4766 if (flags
!= VIR_MEMORY_VIRTUAL
&& flags
!= VIR_MEMORY_PHYSICAL
) {
4767 virLibDomainError (dom
, VIR_ERR_INVALID_ARG
,
4768 _("flags parameter must be VIR_MEMORY_VIRTUAL or VIR_MEMORY_PHYSICAL"));
4772 /* Allow size == 0 as an access test. */
4773 if (size
> 0 && !buffer
) {
4774 virLibDomainError (dom
, VIR_ERR_INVALID_ARG
,
4775 _("buffer is NULL but size is non-zero"));
4779 if (conn
->driver
->domainMemoryPeek
) {
4781 ret
= conn
->driver
->domainMemoryPeek (dom
, start
, size
,
4788 virLibDomainError (dom
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4791 virDispatchError(dom
->conn
);
4797 * virDomainGetBlockInfo:
4798 * @domain: a domain object
4799 * @path: path to the block device or file
4800 * @info: pointer to a virDomainBlockInfo structure allocated by the user
4801 * @flags: currently unused, pass zero
4803 * Extract information about a domain's block device.
4805 * Returns 0 in case of success and -1 in case of failure.
4808 virDomainGetBlockInfo(virDomainPtr domain
, const char *path
, virDomainBlockInfoPtr info
, unsigned int flags
)
4811 DEBUG("domain=%p, info=%p flags=%u", domain
, info
, flags
);
4813 virResetLastError();
4815 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
4816 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
4817 virDispatchError(NULL
);
4821 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
4825 memset(info
, 0, sizeof(virDomainBlockInfo
));
4827 conn
= domain
->conn
;
4829 if (conn
->driver
->domainGetBlockInfo
) {
4831 ret
= conn
->driver
->domainGetBlockInfo (domain
, path
, info
, flags
);
4837 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4840 virDispatchError(domain
->conn
);
4845 /************************************************************************
4847 * Handling of defined but not running domains *
4849 ************************************************************************/
4852 * virDomainDefineXML:
4853 * @conn: pointer to the hypervisor connection
4854 * @xml: the XML description for the domain, preferably in UTF-8
4856 * Define a domain, but does not start it.
4857 * This definition is persistent, until explicitly undefined with
4858 * virDomainUndefine(). A previous definition for this domain would be
4859 * overriden if it already exists.
4861 * Returns NULL in case of error, a pointer to the domain otherwise
4864 virDomainDefineXML(virConnectPtr conn
, const char *xml
) {
4865 DEBUG("conn=%p, xml=%s", conn
, xml
);
4867 virResetLastError();
4869 if (!VIR_IS_CONNECT(conn
)) {
4870 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
4871 virDispatchError(NULL
);
4874 if (conn
->flags
& VIR_CONNECT_RO
) {
4875 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
4879 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
4883 if (conn
->driver
->domainDefineXML
) {
4885 ret
= conn
->driver
->domainDefineXML (conn
, xml
);
4891 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4894 virDispatchError(conn
);
4899 * virDomainUndefine:
4900 * @domain: pointer to a defined domain
4902 * Undefine a domain but does not stop it if it is running
4904 * Returns 0 in case of success, -1 in case of error
4907 virDomainUndefine(virDomainPtr domain
) {
4909 DEBUG("domain=%p", domain
);
4911 virResetLastError();
4913 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
4914 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
4915 virDispatchError(NULL
);
4918 conn
= domain
->conn
;
4919 if (conn
->flags
& VIR_CONNECT_RO
) {
4920 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
4924 if (conn
->driver
->domainUndefine
) {
4926 ret
= conn
->driver
->domainUndefine (domain
);
4932 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4935 virDispatchError(domain
->conn
);
4940 * virConnectNumOfDefinedDomains:
4941 * @conn: pointer to the hypervisor connection
4943 * Provides the number of defined but inactive domains.
4945 * Returns the number of domain found or -1 in case of error
4948 virConnectNumOfDefinedDomains(virConnectPtr conn
)
4950 DEBUG("conn=%p", conn
);
4952 virResetLastError();
4954 if (!VIR_IS_CONNECT(conn
)) {
4955 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
4956 virDispatchError(NULL
);
4960 if (conn
->driver
->numOfDefinedDomains
) {
4962 ret
= conn
->driver
->numOfDefinedDomains (conn
);
4968 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
4971 virDispatchError(conn
);
4976 * virConnectListDefinedDomains:
4977 * @conn: pointer to the hypervisor connection
4978 * @names: pointer to an array to store the names
4979 * @maxnames: size of the array
4981 * list the defined but inactive domains, stores the pointers to the names
4984 * Returns the number of names provided in the array or -1 in case of error
4987 virConnectListDefinedDomains(virConnectPtr conn
, char **const names
,
4989 DEBUG("conn=%p, names=%p, maxnames=%d", conn
, names
, maxnames
);
4991 virResetLastError();
4993 if (!VIR_IS_CONNECT(conn
)) {
4994 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
4995 virDispatchError(NULL
);
4999 if ((names
== NULL
) || (maxnames
< 0)) {
5000 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
5004 if (conn
->driver
->listDefinedDomains
) {
5006 ret
= conn
->driver
->listDefinedDomains (conn
, names
, maxnames
);
5012 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5015 virDispatchError(conn
);
5021 * @domain: pointer to a defined domain
5023 * Launch a defined domain. If the call succeeds the domain moves from the
5024 * defined to the running domains pools.
5026 * Returns 0 in case of success, -1 in case of error
5029 virDomainCreate(virDomainPtr domain
) {
5031 DEBUG("domain=%p", domain
);
5033 virResetLastError();
5035 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5036 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5037 virDispatchError(NULL
);
5040 conn
= domain
->conn
;
5041 if (conn
->flags
& VIR_CONNECT_RO
) {
5042 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
5046 if (conn
->driver
->domainCreate
) {
5048 ret
= conn
->driver
->domainCreate (domain
);
5054 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5057 virDispatchError(domain
->conn
);
5062 * virDomainCreateWithFlags:
5063 * @domain: pointer to a defined domain
5064 * @flags: bitwise-or of supported virDomainCreateFlags
5066 * Launch a defined domain. If the call succeeds the domain moves from the
5067 * defined to the running domains pools.
5069 * Returns 0 in case of success, -1 in case of error
5072 virDomainCreateWithFlags(virDomainPtr domain
, unsigned int flags
) {
5074 DEBUG("domain=%p, flags=%d", domain
, flags
);
5076 virResetLastError();
5078 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5079 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5080 virDispatchError(NULL
);
5083 conn
= domain
->conn
;
5084 if (conn
->flags
& VIR_CONNECT_RO
) {
5085 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
5089 if (conn
->driver
->domainCreateWithFlags
) {
5091 ret
= conn
->driver
->domainCreateWithFlags (domain
, flags
);
5097 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5100 virDispatchError(domain
->conn
);
5105 * virDomainGetAutostart:
5106 * @domain: a domain object
5107 * @autostart: the value returned
5109 * Provides a boolean value indicating whether the domain
5110 * configured to be automatically started when the host
5113 * Returns -1 in case of error, 0 in case of success
5116 virDomainGetAutostart(virDomainPtr domain
,
5120 DEBUG("domain=%p, autostart=%p", domain
, autostart
);
5122 virResetLastError();
5124 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5125 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5126 virDispatchError(NULL
);
5130 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
5134 conn
= domain
->conn
;
5136 if (conn
->driver
->domainGetAutostart
) {
5138 ret
= conn
->driver
->domainGetAutostart (domain
, autostart
);
5144 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5147 virDispatchError(domain
->conn
);
5152 * virDomainSetAutostart:
5153 * @domain: a domain object
5154 * @autostart: whether the domain should be automatically started 0 or 1
5156 * Configure the domain to be automatically started
5157 * when the host machine boots.
5159 * Returns -1 in case of error, 0 in case of success
5162 virDomainSetAutostart(virDomainPtr domain
,
5166 DEBUG("domain=%p, autostart=%d", domain
, autostart
);
5168 virResetLastError();
5170 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5171 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5172 virDispatchError(NULL
);
5176 conn
= domain
->conn
;
5178 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
5179 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
5183 if (conn
->driver
->domainSetAutostart
) {
5185 ret
= conn
->driver
->domainSetAutostart (domain
, autostart
);
5191 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5194 virDispatchError(domain
->conn
);
5199 * virDomainSetVcpus:
5200 * @domain: pointer to domain object, or NULL for Domain0
5201 * @nvcpus: the new number of virtual CPUs for this domain
5203 * Dynamically change the number of virtual CPUs used by the domain.
5204 * Note that this call may fail if the underlying virtualization hypervisor
5205 * does not support it or if growing the number is arbitrary limited.
5206 * This function requires privileged access to the hypervisor.
5208 * This command only changes the runtime configuration of the domain,
5209 * so can only be called on an active domain. It is hypervisor-dependent
5210 * whether it also affects persistent configuration; for more control,
5211 * use virDomainSetVcpusFlags().
5213 * Returns 0 in case of success, -1 in case of failure.
5217 virDomainSetVcpus(virDomainPtr domain
, unsigned int nvcpus
)
5220 DEBUG("domain=%p, nvcpus=%u", domain
, nvcpus
);
5222 virResetLastError();
5224 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5225 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5226 virDispatchError(NULL
);
5229 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
5230 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
5235 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
5238 conn
= domain
->conn
;
5240 if (conn
->driver
->domainSetVcpus
) {
5242 ret
= conn
->driver
->domainSetVcpus (domain
, nvcpus
);
5248 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5251 virDispatchError(domain
->conn
);
5256 * virDomainSetVcpusFlags:
5257 * @domain: pointer to domain object, or NULL for Domain0
5258 * @nvcpus: the new number of virtual CPUs for this domain, must be at least 1
5259 * @flags: an OR'ed set of virDomainVcpuFlags
5261 * Dynamically change the number of virtual CPUs used by the domain.
5262 * Note that this call may fail if the underlying virtualization hypervisor
5263 * does not support it or if growing the number is arbitrary limited.
5264 * This function requires privileged access to the hypervisor.
5266 * @flags must include VIR_DOMAIN_VCPU_LIVE to affect a running
5267 * domain (which may fail if domain is not active), or
5268 * VIR_DOMAIN_VCPU_CONFIG to affect the next boot via the XML
5269 * description of the domain. Both flags may be set.
5271 * If @flags includes VIR_DOMAIN_VCPU_MAXIMUM, then
5272 * VIR_DOMAIN_VCPU_LIVE must be clear, and only the maximum virtual
5273 * CPU limit is altered; generally, this value must be less than or
5274 * equal to virConnectGetMaxVcpus(). Otherwise, this call affects the
5275 * current virtual CPU limit, which must be less than or equal to the
5278 * Returns 0 in case of success, -1 in case of failure.
5282 virDomainSetVcpusFlags(virDomainPtr domain
, unsigned int nvcpus
,
5286 DEBUG("domain=%p, nvcpus=%u, flags=%u", domain
, nvcpus
, flags
);
5288 virResetLastError();
5290 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5291 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5292 virDispatchError(NULL
);
5295 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
5296 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
5300 /* Perform some argument validation common to all implementations. */
5301 if (nvcpus
< 1 || (unsigned short) nvcpus
!= nvcpus
||
5302 (flags
& (VIR_DOMAIN_VCPU_LIVE
| VIR_DOMAIN_VCPU_CONFIG
)) == 0) {
5303 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
5306 conn
= domain
->conn
;
5308 if (conn
->driver
->domainSetVcpusFlags
) {
5310 ret
= conn
->driver
->domainSetVcpusFlags (domain
, nvcpus
, flags
);
5316 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5319 virDispatchError(domain
->conn
);
5324 * virDomainGetVcpusFlags:
5325 * @domain: pointer to domain object, or NULL for Domain0
5326 * @flags: an OR'ed set of virDomainVcpuFlags
5328 * Query the number of virtual CPUs used by the domain. Note that
5329 * this call may fail if the underlying virtualization hypervisor does
5330 * not support it. This function requires privileged access to the
5333 * @flags must include either VIR_DOMAIN_VCPU_ACTIVE to query a
5334 * running domain (which will fail if domain is not active), or
5335 * VIR_DOMAIN_VCPU_PERSISTENT to query the XML description of the
5336 * domain. It is an error to set both flags.
5338 * If @flags includes VIR_DOMAIN_VCPU_MAXIMUM, then the maximum
5339 * virtual CPU limit is queried. Otherwise, this call queries the
5340 * current virtual CPU limit.
5342 * Returns 0 in case of success, -1 in case of failure.
5346 virDomainGetVcpusFlags(virDomainPtr domain
, unsigned int flags
)
5349 DEBUG("domain=%p, flags=%u", domain
, flags
);
5351 virResetLastError();
5353 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5354 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5355 virDispatchError(NULL
);
5359 /* Exactly one of these two flags should be set. */
5360 if (!(flags
& VIR_DOMAIN_VCPU_LIVE
) == !(flags
& VIR_DOMAIN_VCPU_CONFIG
)) {
5361 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
5364 conn
= domain
->conn
;
5366 if (conn
->driver
->domainGetVcpusFlags
) {
5368 ret
= conn
->driver
->domainGetVcpusFlags (domain
, flags
);
5374 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5377 virDispatchError(domain
->conn
);
5383 * @domain: pointer to domain object, or NULL for Domain0
5384 * @vcpu: virtual CPU number
5385 * @cpumap: pointer to a bit map of real CPUs (in 8-bit bytes) (IN)
5386 * Each bit set to 1 means that corresponding CPU is usable.
5387 * Bytes are stored in little-endian order: CPU0-7, 8-15...
5388 * In each byte, lowest CPU number is least significant bit.
5389 * @maplen: number of bytes in cpumap, from 1 up to size of CPU map in
5390 * underlying virtualization system (Xen...).
5391 * If maplen < size, missing bytes are set to zero.
5392 * If maplen > size, failure code is returned.
5394 * Dynamically change the real CPUs which can be allocated to a virtual CPU.
5395 * This function requires privileged access to the hypervisor.
5397 * This command only changes the runtime configuration of the domain,
5398 * so can only be called on an active domain.
5400 * Returns 0 in case of success, -1 in case of failure.
5403 virDomainPinVcpu(virDomainPtr domain
, unsigned int vcpu
,
5404 unsigned char *cpumap
, int maplen
)
5407 DEBUG("domain=%p, vcpu=%u, cpumap=%p, maplen=%d", domain
, vcpu
, cpumap
, maplen
);
5409 virResetLastError();
5411 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5412 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5413 virDispatchError(NULL
);
5416 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
5417 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
5421 if ((vcpu
> 32000) || (cpumap
== NULL
) || (maplen
< 1)) {
5422 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
5426 conn
= domain
->conn
;
5428 if (conn
->driver
->domainPinVcpu
) {
5430 ret
= conn
->driver
->domainPinVcpu (domain
, vcpu
, cpumap
, maplen
);
5436 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5439 virDispatchError(domain
->conn
);
5444 * virDomainGetVcpus:
5445 * @domain: pointer to domain object, or NULL for Domain0
5446 * @info: pointer to an array of virVcpuInfo structures (OUT)
5447 * @maxinfo: number of structures in info array
5448 * @cpumaps: pointer to a bit map of real CPUs for all vcpus of this
5449 * domain (in 8-bit bytes) (OUT)
5450 * If cpumaps is NULL, then no cpumap information is returned by the API.
5451 * It's assumed there is <maxinfo> cpumap in cpumaps array.
5452 * The memory allocated to cpumaps must be (maxinfo * maplen) bytes
5453 * (ie: calloc(maxinfo, maplen)).
5454 * One cpumap inside cpumaps has the format described in
5455 * virDomainPinVcpu() API.
5456 * @maplen: number of bytes in one cpumap, from 1 up to size of CPU map in
5457 * underlying virtualization system (Xen...).
5458 * Must be zero when cpumaps is NULL and positive when it is non-NULL.
5460 * Extract information about virtual CPUs of domain, store it in info array
5461 * and also in cpumaps if this pointer isn't NULL.
5463 * Returns the number of info filled in case of success, -1 in case of failure.
5466 virDomainGetVcpus(virDomainPtr domain
, virVcpuInfoPtr info
, int maxinfo
,
5467 unsigned char *cpumaps
, int maplen
)
5470 DEBUG("domain=%p, info=%p, maxinfo=%d, cpumaps=%p, maplen=%d", domain
, info
, maxinfo
, cpumaps
, maplen
);
5472 virResetLastError();
5474 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5475 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5476 virDispatchError(NULL
);
5479 if ((info
== NULL
) || (maxinfo
< 1)) {
5480 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
5484 /* Ensure that domainGetVcpus (aka remoteDomainGetVcpus) does not
5485 try to memcpy anything into a NULL pointer. */
5486 if ((cpumaps
== NULL
&& maplen
!= 0)
5487 || (cpumaps
&& maplen
<= 0)) {
5488 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
5492 conn
= domain
->conn
;
5494 if (conn
->driver
->domainGetVcpus
) {
5496 ret
= conn
->driver
->domainGetVcpus (domain
, info
, maxinfo
,
5503 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5506 virDispatchError(domain
->conn
);
5511 * virDomainGetMaxVcpus:
5512 * @domain: pointer to domain object
5514 * Provides the maximum number of virtual CPUs supported for
5515 * the guest VM. If the guest is inactive, this is basically
5516 * the same as virConnectGetMaxVcpus(). If the guest is running
5517 * this will reflect the maximum number of virtual CPUs the
5518 * guest was booted with. For more details, see virDomainGetVcpusFlags().
5520 * Returns the maximum of virtual CPU or -1 in case of error.
5523 virDomainGetMaxVcpus(virDomainPtr domain
)
5526 DEBUG("domain=%p", domain
);
5528 virResetLastError();
5530 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5531 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5532 virDispatchError(NULL
);
5536 conn
= domain
->conn
;
5538 if (conn
->driver
->domainGetMaxVcpus
) {
5540 ret
= conn
->driver
->domainGetMaxVcpus (domain
);
5546 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5549 virDispatchError(domain
->conn
);
5554 * virDomainGetSecurityLabel:
5555 * @domain: a domain object
5556 * @seclabel: pointer to a virSecurityLabel structure
5558 * Extract security label of an active domain. The 'label' field
5559 * in the @seclabel argument will be initialized to the empty
5560 * string if the domain is not running under a security model.
5562 * Returns 0 in case of success, -1 in case of failure
5565 virDomainGetSecurityLabel(virDomainPtr domain
, virSecurityLabelPtr seclabel
)
5569 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5570 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5571 virDispatchError(NULL
);
5575 if (seclabel
== NULL
) {
5576 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
5580 conn
= domain
->conn
;
5582 if (conn
->driver
->domainGetSecurityLabel
) {
5584 ret
= conn
->driver
->domainGetSecurityLabel(domain
, seclabel
);
5590 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5593 virDispatchError(domain
->conn
);
5598 * virNodeGetSecurityModel:
5599 * @conn: a connection object
5600 * @secmodel: pointer to a virSecurityModel structure
5602 * Extract the security model of a hypervisor. The 'model' field
5603 * in the @secmodel argument may be initialized to the empty
5604 * string if the driver has not activated a security model.
5606 * Returns 0 in case of success, -1 in case of failure
5609 virNodeGetSecurityModel(virConnectPtr conn
, virSecurityModelPtr secmodel
)
5611 if (!VIR_IS_CONNECT(conn
)) {
5612 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
5613 virDispatchError(NULL
);
5617 if (secmodel
== NULL
) {
5618 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
5622 if (conn
->driver
->nodeGetSecurityModel
) {
5624 ret
= conn
->driver
->nodeGetSecurityModel(conn
, secmodel
);
5630 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5633 virDispatchError(conn
);
5638 * virDomainAttachDevice:
5639 * @domain: pointer to domain object
5640 * @xml: pointer to XML description of one device
5642 * Create a virtual device attachment to backend. This function,
5643 * having hotplug semantics, is only allowed on an active domain.
5645 * For compatibility, this method can also be used to change the media
5646 * in an existing CDROM/Floppy device, however, applications are
5647 * recommended to use the virDomainUpdateDeviceFlag method instead.
5649 * Returns 0 in case of success, -1 in case of failure.
5652 virDomainAttachDevice(virDomainPtr domain
, const char *xml
)
5655 DEBUG("domain=%p, xml=%s", domain
, xml
);
5657 virResetLastError();
5659 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5660 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5661 virDispatchError(NULL
);
5664 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
5665 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
5668 conn
= domain
->conn
;
5670 if (conn
->driver
->domainAttachDevice
) {
5672 ret
= conn
->driver
->domainAttachDevice (domain
, xml
);
5678 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5681 virDispatchError(domain
->conn
);
5686 * virDomainAttachDeviceFlags:
5687 * @domain: pointer to domain object
5688 * @xml: pointer to XML description of one device
5689 * @flags: an OR'ed set of virDomainDeviceModifyFlags
5691 * Attach a virtual device to a domain, using the flags parameter
5692 * to control how the device is attached. VIR_DOMAIN_DEVICE_MODIFY_CURRENT
5693 * specifies that the device allocation is made based on current domain
5694 * state. VIR_DOMAIN_DEVICE_MODIFY_LIVE specifies that the device shall be
5695 * allocated to the active domain instance only and is not added to the
5696 * persisted domain configuration. VIR_DOMAIN_DEVICE_MODIFY_CONFIG
5697 * specifies that the device shall be allocated to the persisted domain
5698 * configuration only. Note that the target hypervisor must return an
5699 * error if unable to satisfy flags. E.g. the hypervisor driver will
5700 * return failure if LIVE is specified but it only supports modifying the
5701 * persisted device allocation.
5703 * For compatibility, this method can also be used to change the media
5704 * in an existing CDROM/Floppy device, however, applications are
5705 * recommended to use the virDomainUpdateDeviceFlag method instead.
5707 * Returns 0 in case of success, -1 in case of failure.
5710 virDomainAttachDeviceFlags(virDomainPtr domain
,
5711 const char *xml
, unsigned int flags
)
5714 DEBUG("domain=%p, xml=%s, flags=%d", domain
, xml
, flags
);
5716 virResetLastError();
5718 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5719 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5722 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
5723 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
5726 conn
= domain
->conn
;
5728 if (conn
->driver
->domainAttachDeviceFlags
) {
5730 ret
= conn
->driver
->domainAttachDeviceFlags(domain
, xml
, flags
);
5736 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5739 virDispatchError(domain
->conn
);
5744 * virDomainDetachDevice:
5745 * @domain: pointer to domain object
5746 * @xml: pointer to XML description of one device
5748 * Destroy a virtual device attachment to backend. This function,
5749 * having hot-unplug semantics, is only allowed on an active domain.
5751 * Returns 0 in case of success, -1 in case of failure.
5754 virDomainDetachDevice(virDomainPtr domain
, const char *xml
)
5757 DEBUG("domain=%p, xml=%s", domain
, xml
);
5759 virResetLastError();
5761 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5762 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5763 virDispatchError(NULL
);
5766 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
5767 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
5770 conn
= domain
->conn
;
5772 if (conn
->driver
->domainDetachDevice
) {
5774 ret
= conn
->driver
->domainDetachDevice (domain
, xml
);
5780 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5783 virDispatchError(domain
->conn
);
5788 * virDomainDetachDeviceFlags:
5789 * @domain: pointer to domain object
5790 * @xml: pointer to XML description of one device
5791 * @flags: an OR'ed set of virDomainDeviceModifyFlags
5793 * Detach a virtual device from a domain, using the flags parameter
5794 * to control how the device is detached. VIR_DOMAIN_DEVICE_MODIFY_CURRENT
5795 * specifies that the device allocation is removed based on current domain
5796 * state. VIR_DOMAIN_DEVICE_MODIFY_LIVE specifies that the device shall be
5797 * deallocated from the active domain instance only and is not from the
5798 * persisted domain configuration. VIR_DOMAIN_DEVICE_MODIFY_CONFIG
5799 * specifies that the device shall be deallocated from the persisted domain
5800 * configuration only. Note that the target hypervisor must return an
5801 * error if unable to satisfy flags. E.g. the hypervisor driver will
5802 * return failure if LIVE is specified but it only supports removing the
5803 * persisted device allocation.
5805 * Returns 0 in case of success, -1 in case of failure.
5808 virDomainDetachDeviceFlags(virDomainPtr domain
,
5809 const char *xml
, unsigned int flags
)
5812 DEBUG("domain=%p, xml=%s, flags=%d", domain
, xml
, flags
);
5814 virResetLastError();
5816 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5817 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5820 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
5821 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
5824 conn
= domain
->conn
;
5826 if (conn
->driver
->domainDetachDeviceFlags
) {
5828 ret
= conn
->driver
->domainDetachDeviceFlags(domain
, xml
, flags
);
5834 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5837 virDispatchError(domain
->conn
);
5842 * virDomainUpdateDeviceFlags:
5843 * @domain: pointer to domain object
5844 * @xml: pointer to XML description of one device
5845 * @flags: an OR'ed set of virDomainDeviceModifyFlags
5847 * Change a virtual device on a domain, using the flags parameter
5848 * to control how the device is changed. VIR_DOMAIN_DEVICE_MODIFY_CURRENT
5849 * specifies that the device change is made based on current domain
5850 * state. VIR_DOMAIN_DEVICE_MODIFY_LIVE specifies that the device shall be
5851 * changed on the active domain instance only and is not added to the
5852 * persisted domain configuration. VIR_DOMAIN_DEVICE_MODIFY_CONFIG
5853 * specifies that the device shall be changed on the persisted domain
5854 * configuration only. Note that the target hypervisor must return an
5855 * error if unable to satisfy flags. E.g. the hypervisor driver will
5856 * return failure if LIVE is specified but it only supports modifying the
5857 * persisted device allocation.
5859 * This method is used for actions such changing CDROM/Floppy device
5860 * media, altering the graphics configuration such as password,
5861 * reconfiguring the NIC device backend connectivity, etc.
5863 * Returns 0 in case of success, -1 in case of failure.
5866 virDomainUpdateDeviceFlags(virDomainPtr domain
,
5867 const char *xml
, unsigned int flags
)
5870 DEBUG("domain=%p, xml=%s, flags=%d", domain
, xml
, flags
);
5872 virResetLastError();
5874 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
5875 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
5878 if (domain
->conn
->flags
& VIR_CONNECT_RO
) {
5879 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
5882 conn
= domain
->conn
;
5884 if (conn
->driver
->domainUpdateDeviceFlags
) {
5886 ret
= conn
->driver
->domainUpdateDeviceFlags(domain
, xml
, flags
);
5892 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5895 virDispatchError(domain
->conn
);
5900 * virNodeGetCellsFreeMemory:
5901 * @conn: pointer to the hypervisor connection
5902 * @freeMems: pointer to the array of unsigned long long
5903 * @startCell: index of first cell to return freeMems info on.
5904 * @maxCells: Maximum number of cells for which freeMems information can
5907 * This call returns the amount of free memory in one or more NUMA cells.
5908 * The @freeMems array must be allocated by the caller and will be filled
5909 * with the amount of free memory in bytes for each cell requested,
5910 * starting with startCell (in freeMems[0]), up to either
5911 * (startCell + maxCells), or the number of additional cells in the node,
5912 * whichever is smaller.
5914 * Returns the number of entries filled in freeMems, or -1 in case of error.
5918 virNodeGetCellsFreeMemory(virConnectPtr conn
, unsigned long long *freeMems
,
5919 int startCell
, int maxCells
)
5921 DEBUG("conn=%p, freeMems=%p, startCell=%d, maxCells=%d",
5922 conn
, freeMems
, startCell
, maxCells
);
5924 virResetLastError();
5926 if (!VIR_IS_CONNECT(conn
)) {
5927 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
5928 virDispatchError(NULL
);
5932 if ((freeMems
== NULL
) || (maxCells
<= 0) || (startCell
< 0)) {
5933 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
5937 if (conn
->driver
->nodeGetCellsFreeMemory
) {
5939 ret
= conn
->driver
->nodeGetCellsFreeMemory (conn
, freeMems
, startCell
, maxCells
);
5945 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
5948 virDispatchError(conn
);
5953 * virNetworkGetConnect:
5954 * @net: pointer to a network
5956 * Provides the connection pointer associated with a network. The
5957 * reference counter on the connection is not increased by this
5960 * WARNING: When writing libvirt bindings in other languages, do
5961 * not use this function. Instead, store the connection and
5962 * the network object together.
5964 * Returns the virConnectPtr or NULL in case of failure.
5967 virNetworkGetConnect (virNetworkPtr net
)
5969 DEBUG("net=%p", net
);
5971 virResetLastError();
5973 if (!VIR_IS_CONNECTED_NETWORK (net
)) {
5974 virLibNetworkError (NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
5975 virDispatchError(NULL
);
5982 * virConnectNumOfNetworks:
5983 * @conn: pointer to the hypervisor connection
5985 * Provides the number of active networks.
5987 * Returns the number of network found or -1 in case of error
5990 virConnectNumOfNetworks(virConnectPtr conn
)
5992 DEBUG("conn=%p", conn
);
5994 virResetLastError();
5996 if (!VIR_IS_CONNECT(conn
)) {
5997 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
5998 virDispatchError(NULL
);
6002 if (conn
->networkDriver
&& conn
->networkDriver
->numOfNetworks
) {
6004 ret
= conn
->networkDriver
->numOfNetworks (conn
);
6010 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6013 virDispatchError(conn
);
6018 * virConnectListNetworks:
6019 * @conn: pointer to the hypervisor connection
6020 * @names: array to collect the list of names of active networks
6021 * @maxnames: size of @names
6023 * Collect the list of active networks, and store their names in @names
6025 * Returns the number of networks found or -1 in case of error
6028 virConnectListNetworks(virConnectPtr conn
, char **const names
, int maxnames
)
6030 DEBUG("conn=%p, names=%p, maxnames=%d", conn
, names
, maxnames
);
6032 virResetLastError();
6034 if (!VIR_IS_CONNECT(conn
)) {
6035 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
6036 virDispatchError(NULL
);
6040 if ((names
== NULL
) || (maxnames
< 0)) {
6041 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6045 if (conn
->networkDriver
&& conn
->networkDriver
->listNetworks
) {
6047 ret
= conn
->networkDriver
->listNetworks (conn
, names
, maxnames
);
6053 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6056 virDispatchError(conn
);
6061 * virConnectNumOfDefinedNetworks:
6062 * @conn: pointer to the hypervisor connection
6064 * Provides the number of inactive networks.
6066 * Returns the number of networks found or -1 in case of error
6069 virConnectNumOfDefinedNetworks(virConnectPtr conn
)
6071 DEBUG("conn=%p", conn
);
6073 virResetLastError();
6075 if (!VIR_IS_CONNECT(conn
)) {
6076 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
6077 virDispatchError(NULL
);
6081 if (conn
->networkDriver
&& conn
->networkDriver
->numOfDefinedNetworks
) {
6083 ret
= conn
->networkDriver
->numOfDefinedNetworks (conn
);
6089 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6092 virDispatchError(conn
);
6097 * virConnectListDefinedNetworks:
6098 * @conn: pointer to the hypervisor connection
6099 * @names: pointer to an array to store the names
6100 * @maxnames: size of the array
6102 * list the inactive networks, stores the pointers to the names in @names
6104 * Returns the number of names provided in the array or -1 in case of error
6107 virConnectListDefinedNetworks(virConnectPtr conn
, char **const names
,
6110 DEBUG("conn=%p, names=%p, maxnames=%d", conn
, names
, maxnames
);
6112 virResetLastError();
6114 if (!VIR_IS_CONNECT(conn
)) {
6115 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
6116 virDispatchError(NULL
);
6120 if ((names
== NULL
) || (maxnames
< 0)) {
6121 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6125 if (conn
->networkDriver
&& conn
->networkDriver
->listDefinedNetworks
) {
6127 ret
= conn
->networkDriver
->listDefinedNetworks (conn
,
6134 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6137 virDispatchError(conn
);
6142 * virNetworkLookupByName:
6143 * @conn: pointer to the hypervisor connection
6144 * @name: name for the network
6146 * Try to lookup a network on the given hypervisor based on its name.
6148 * Returns a new network object or NULL in case of failure. If the
6149 * network cannot be found, then VIR_ERR_NO_NETWORK error is raised.
6152 virNetworkLookupByName(virConnectPtr conn
, const char *name
)
6154 DEBUG("conn=%p, name=%s", conn
, name
);
6156 virResetLastError();
6158 if (!VIR_IS_CONNECT(conn
)) {
6159 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
6160 virDispatchError(NULL
);
6164 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6168 if (conn
->networkDriver
&& conn
->networkDriver
->networkLookupByName
) {
6170 ret
= conn
->networkDriver
->networkLookupByName (conn
, name
);
6176 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6179 virDispatchError(conn
);
6184 * virNetworkLookupByUUID:
6185 * @conn: pointer to the hypervisor connection
6186 * @uuid: the raw UUID for the network
6188 * Try to lookup a network on the given hypervisor based on its UUID.
6190 * Returns a new network object or NULL in case of failure. If the
6191 * network cannot be found, then VIR_ERR_NO_NETWORK error is raised.
6194 virNetworkLookupByUUID(virConnectPtr conn
, const unsigned char *uuid
)
6196 DEBUG("conn=%p, uuid=%s", conn
, uuid
);
6198 virResetLastError();
6200 if (!VIR_IS_CONNECT(conn
)) {
6201 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
6202 virDispatchError(NULL
);
6206 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6210 if (conn
->networkDriver
&& conn
->networkDriver
->networkLookupByUUID
){
6212 ret
= conn
->networkDriver
->networkLookupByUUID (conn
, uuid
);
6218 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6221 virDispatchError(conn
);
6226 * virNetworkLookupByUUIDString:
6227 * @conn: pointer to the hypervisor connection
6228 * @uuidstr: the string UUID for the network
6230 * Try to lookup a network on the given hypervisor based on its UUID.
6232 * Returns a new network object or NULL in case of failure. If the
6233 * network cannot be found, then VIR_ERR_NO_NETWORK error is raised.
6236 virNetworkLookupByUUIDString(virConnectPtr conn
, const char *uuidstr
)
6238 unsigned char uuid
[VIR_UUID_BUFLEN
];
6239 DEBUG("conn=%p, uuidstr=%s", conn
, uuidstr
);
6241 virResetLastError();
6243 if (!VIR_IS_CONNECT(conn
)) {
6244 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
6245 virDispatchError(NULL
);
6248 if (uuidstr
== NULL
) {
6249 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6253 if (virUUIDParse(uuidstr
, uuid
) < 0) {
6254 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6258 return virNetworkLookupByUUID(conn
, &uuid
[0]);
6261 virDispatchError(conn
);
6266 * virNetworkCreateXML:
6267 * @conn: pointer to the hypervisor connection
6268 * @xmlDesc: an XML description of the network
6270 * Create and start a new virtual network, based on an XML description
6271 * similar to the one returned by virNetworkGetXMLDesc()
6273 * Returns a new network object or NULL in case of failure
6276 virNetworkCreateXML(virConnectPtr conn
, const char *xmlDesc
)
6278 DEBUG("conn=%p, xmlDesc=%s", conn
, xmlDesc
);
6280 virResetLastError();
6282 if (!VIR_IS_CONNECT(conn
)) {
6283 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
6284 virDispatchError(NULL
);
6287 if (xmlDesc
== NULL
) {
6288 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6291 if (conn
->flags
& VIR_CONNECT_RO
) {
6292 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
6296 if (conn
->networkDriver
&& conn
->networkDriver
->networkCreateXML
) {
6298 ret
= conn
->networkDriver
->networkCreateXML (conn
, xmlDesc
);
6304 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6307 virDispatchError(conn
);
6312 * virNetworkDefineXML:
6313 * @conn: pointer to the hypervisor connection
6314 * @xml: the XML description for the network, preferably in UTF-8
6316 * Define a network, but does not create it
6318 * Returns NULL in case of error, a pointer to the network otherwise
6321 virNetworkDefineXML(virConnectPtr conn
, const char *xml
)
6323 DEBUG("conn=%p, xml=%s", conn
, xml
);
6325 virResetLastError();
6327 if (!VIR_IS_CONNECT(conn
)) {
6328 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
6329 virDispatchError(NULL
);
6332 if (conn
->flags
& VIR_CONNECT_RO
) {
6333 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
6337 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6341 if (conn
->networkDriver
&& conn
->networkDriver
->networkDefineXML
) {
6343 ret
= conn
->networkDriver
->networkDefineXML (conn
, xml
);
6349 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6352 virDispatchError(conn
);
6357 * virNetworkUndefine:
6358 * @network: pointer to a defined network
6360 * Undefine a network but does not stop it if it is running
6362 * Returns 0 in case of success, -1 in case of error
6365 virNetworkUndefine(virNetworkPtr network
) {
6367 DEBUG("network=%p", network
);
6369 virResetLastError();
6371 if (!VIR_IS_CONNECTED_NETWORK(network
)) {
6372 virLibNetworkError(NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
6373 virDispatchError(NULL
);
6376 conn
= network
->conn
;
6377 if (conn
->flags
& VIR_CONNECT_RO
) {
6378 virLibNetworkError(network
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
6382 if (conn
->networkDriver
&& conn
->networkDriver
->networkUndefine
) {
6384 ret
= conn
->networkDriver
->networkUndefine (network
);
6390 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6393 virDispatchError(network
->conn
);
6399 * @network: pointer to a defined network
6401 * Create and start a defined network. If the call succeed the network
6402 * moves from the defined to the running networks pools.
6404 * Returns 0 in case of success, -1 in case of error
6407 virNetworkCreate(virNetworkPtr network
)
6410 DEBUG("network=%p", network
);
6412 virResetLastError();
6414 if (!VIR_IS_CONNECTED_NETWORK(network
)) {
6415 virLibNetworkError(NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
6416 virDispatchError(NULL
);
6419 conn
= network
->conn
;
6420 if (conn
->flags
& VIR_CONNECT_RO
) {
6421 virLibNetworkError(network
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
6425 if (conn
->networkDriver
&& conn
->networkDriver
->networkCreate
) {
6427 ret
= conn
->networkDriver
->networkCreate (network
);
6433 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6436 virDispatchError(network
->conn
);
6441 * virNetworkDestroy:
6442 * @network: a network object
6444 * Destroy the network object. The running instance is shutdown if not down
6445 * already and all resources used by it are given back to the hypervisor. This
6446 * does not free the associated virNetworkPtr object.
6447 * This function may require privileged access
6449 * Returns 0 in case of success and -1 in case of failure.
6452 virNetworkDestroy(virNetworkPtr network
)
6455 DEBUG("network=%p", network
);
6457 virResetLastError();
6459 if (!VIR_IS_CONNECTED_NETWORK(network
)) {
6460 virLibNetworkError(NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
6461 virDispatchError(NULL
);
6465 conn
= network
->conn
;
6466 if (conn
->flags
& VIR_CONNECT_RO
) {
6467 virLibNetworkError(network
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
6471 if (conn
->networkDriver
&& conn
->networkDriver
->networkDestroy
) {
6473 ret
= conn
->networkDriver
->networkDestroy (network
);
6479 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6482 virDispatchError(network
->conn
);
6488 * @network: a network object
6490 * Free the network object. The running instance is kept alive.
6491 * The data structure is freed and should not be used thereafter.
6493 * Returns 0 in case of success and -1 in case of failure.
6496 virNetworkFree(virNetworkPtr network
)
6498 DEBUG("network=%p", network
);
6500 virResetLastError();
6502 if (!VIR_IS_CONNECTED_NETWORK(network
)) {
6503 virLibNetworkError(NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
6504 virDispatchError(NULL
);
6507 if (virUnrefNetwork(network
) < 0) {
6508 virDispatchError(NULL
);
6516 * @network: the network to hold a reference on
6518 * Increment the reference count on the network. For each
6519 * additional call to this method, there shall be a corresponding
6520 * call to virNetworkFree to release the reference count, once
6521 * the caller no longer needs the reference to this object.
6523 * This method is typically useful for applications where multiple
6524 * threads are using a connection, and it is required that the
6525 * connection remain open until all threads have finished using
6526 * it. ie, each new thread using a network would increment
6527 * the reference count.
6529 * Returns 0 in case of success, -1 in case of failure.
6532 virNetworkRef(virNetworkPtr network
)
6534 if ((!VIR_IS_CONNECTED_NETWORK(network
))) {
6535 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6536 virDispatchError(NULL
);
6539 virMutexLock(&network
->conn
->lock
);
6540 DEBUG("network=%p refs=%d", network
, network
->refs
);
6542 virMutexUnlock(&network
->conn
->lock
);
6547 * virNetworkGetName:
6548 * @network: a network object
6550 * Get the public name for that network
6552 * Returns a pointer to the name or NULL, the string need not be deallocated
6553 * its lifetime will be the same as the network object.
6556 virNetworkGetName(virNetworkPtr network
)
6558 DEBUG("network=%p", network
);
6560 virResetLastError();
6562 if (!VIR_IS_NETWORK(network
)) {
6563 virLibNetworkError(NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
6564 virDispatchError(NULL
);
6567 return (network
->name
);
6571 * virNetworkGetUUID:
6572 * @network: a network object
6573 * @uuid: pointer to a VIR_UUID_BUFLEN bytes array
6575 * Get the UUID for a network
6577 * Returns -1 in case of error, 0 in case of success
6580 virNetworkGetUUID(virNetworkPtr network
, unsigned char *uuid
)
6582 DEBUG("network=%p, uuid=%p", network
, uuid
);
6584 virResetLastError();
6586 if (!VIR_IS_NETWORK(network
)) {
6587 virLibNetworkError(NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
6588 virDispatchError(NULL
);
6592 virLibNetworkError(network
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6596 memcpy(uuid
, &network
->uuid
[0], VIR_UUID_BUFLEN
);
6601 virDispatchError(network
->conn
);
6606 * virNetworkGetUUIDString:
6607 * @network: a network object
6608 * @buf: pointer to a VIR_UUID_STRING_BUFLEN bytes array
6610 * Get the UUID for a network as string. For more information about
6613 * Returns -1 in case of error, 0 in case of success
6616 virNetworkGetUUIDString(virNetworkPtr network
, char *buf
)
6618 unsigned char uuid
[VIR_UUID_BUFLEN
];
6619 DEBUG("network=%p, buf=%p", network
, buf
);
6621 virResetLastError();
6623 if (!VIR_IS_NETWORK(network
)) {
6624 virLibNetworkError(NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
6625 virDispatchError(NULL
);
6629 virLibNetworkError(network
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6633 if (virNetworkGetUUID(network
, &uuid
[0]))
6636 virUUIDFormat(uuid
, buf
);
6640 virDispatchError(network
->conn
);
6645 * virNetworkGetXMLDesc:
6646 * @network: a network object
6647 * @flags: an OR'ed set of extraction flags, not used yet
6649 * Provide an XML description of the network. The description may be reused
6650 * later to relaunch the network with virNetworkCreateXML().
6652 * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
6653 * the caller must free() the returned value.
6656 virNetworkGetXMLDesc(virNetworkPtr network
, int flags
)
6659 DEBUG("network=%p, flags=%d", network
, flags
);
6661 virResetLastError();
6663 if (!VIR_IS_CONNECTED_NETWORK(network
)) {
6664 virLibNetworkError(NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
6665 virDispatchError(NULL
);
6669 virLibNetworkError(network
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6673 conn
= network
->conn
;
6675 if (conn
->networkDriver
&& conn
->networkDriver
->networkDumpXML
) {
6677 ret
= conn
->networkDriver
->networkDumpXML (network
, flags
);
6683 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6686 virDispatchError(network
->conn
);
6691 * virNetworkGetBridgeName:
6692 * @network: a network object
6694 * Provides a bridge interface name to which a domain may connect
6695 * a network interface in order to join the network.
6697 * Returns a 0 terminated interface name, or NULL in case of error.
6698 * the caller must free() the returned value.
6701 virNetworkGetBridgeName(virNetworkPtr network
)
6704 DEBUG("network=%p", network
);
6706 virResetLastError();
6708 if (!VIR_IS_CONNECTED_NETWORK(network
)) {
6709 virLibNetworkError(NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
6710 virDispatchError(NULL
);
6714 conn
= network
->conn
;
6716 if (conn
->networkDriver
&& conn
->networkDriver
->networkGetBridgeName
) {
6718 ret
= conn
->networkDriver
->networkGetBridgeName (network
);
6724 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6727 virDispatchError(network
->conn
);
6732 * virNetworkGetAutostart:
6733 * @network: a network object
6734 * @autostart: the value returned
6736 * Provides a boolean value indicating whether the network
6737 * configured to be automatically started when the host
6740 * Returns -1 in case of error, 0 in case of success
6743 virNetworkGetAutostart(virNetworkPtr network
,
6747 DEBUG("network=%p, autostart=%p", network
, autostart
);
6749 virResetLastError();
6751 if (!VIR_IS_CONNECTED_NETWORK(network
)) {
6752 virLibNetworkError(NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
6753 virDispatchError(NULL
);
6757 virLibNetworkError(network
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6761 conn
= network
->conn
;
6763 if (conn
->networkDriver
&& conn
->networkDriver
->networkGetAutostart
) {
6765 ret
= conn
->networkDriver
->networkGetAutostart (network
, autostart
);
6771 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6774 virDispatchError(network
->conn
);
6779 * virNetworkSetAutostart:
6780 * @network: a network object
6781 * @autostart: whether the network should be automatically started 0 or 1
6783 * Configure the network to be automatically started
6784 * when the host machine boots.
6786 * Returns -1 in case of error, 0 in case of success
6789 virNetworkSetAutostart(virNetworkPtr network
,
6793 DEBUG("network=%p, autostart=%d", network
, autostart
);
6795 virResetLastError();
6797 if (!VIR_IS_CONNECTED_NETWORK(network
)) {
6798 virLibNetworkError(NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
6799 virDispatchError(NULL
);
6803 if (network
->conn
->flags
& VIR_CONNECT_RO
) {
6804 virLibNetworkError(network
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
6808 conn
= network
->conn
;
6810 if (conn
->networkDriver
&& conn
->networkDriver
->networkSetAutostart
) {
6812 ret
= conn
->networkDriver
->networkSetAutostart (network
, autostart
);
6818 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6821 virDispatchError(network
->conn
);
6826 * virInterfaceGetConnect:
6827 * @iface: pointer to an interface
6829 * Provides the connection pointer associated with an interface. The
6830 * reference counter on the connection is not increased by this
6833 * WARNING: When writing libvirt bindings in other languages, do
6834 * not use this function. Instead, store the connection and
6835 * the interface object together.
6837 * Returns the virConnectPtr or NULL in case of failure.
6840 virInterfaceGetConnect (virInterfacePtr iface
)
6842 DEBUG("iface=%p", iface
);
6844 virResetLastError();
6846 if (!VIR_IS_CONNECTED_INTERFACE (iface
)) {
6847 virLibInterfaceError (NULL
, VIR_ERR_INVALID_INTERFACE
, __FUNCTION__
);
6848 virDispatchError(NULL
);
6855 * virConnectNumOfInterfaces:
6856 * @conn: pointer to the hypervisor connection
6858 * Provides the number of active interfaces on the physical host.
6860 * Returns the number of active interfaces found or -1 in case of error
6863 virConnectNumOfInterfaces(virConnectPtr conn
)
6865 DEBUG("conn=%p", conn
);
6867 virResetLastError();
6869 if (!VIR_IS_CONNECT(conn
)) {
6870 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
6871 virDispatchError(NULL
);
6875 if (conn
->interfaceDriver
&& conn
->interfaceDriver
->numOfInterfaces
) {
6877 ret
= conn
->interfaceDriver
->numOfInterfaces (conn
);
6883 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6886 virDispatchError(conn
);
6891 * virConnectListInterfaces:
6892 * @conn: pointer to the hypervisor connection
6893 * @names: array to collect the list of names of interfaces
6894 * @maxnames: size of @names
6896 * Collect the list of active physical host interfaces,
6897 * and store their names in @names
6899 * Returns the number of interfaces found or -1 in case of error
6902 virConnectListInterfaces(virConnectPtr conn
, char **const names
, int maxnames
)
6904 DEBUG("conn=%p, names=%p, maxnames=%d", conn
, names
, maxnames
);
6906 virResetLastError();
6908 if (!VIR_IS_CONNECT(conn
)) {
6909 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
6910 virDispatchError(NULL
);
6914 if ((names
== NULL
) || (maxnames
< 0)) {
6915 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
6919 if (conn
->interfaceDriver
&& conn
->interfaceDriver
->listInterfaces
) {
6921 ret
= conn
->interfaceDriver
->listInterfaces (conn
, names
, maxnames
);
6927 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6930 virDispatchError(conn
);
6935 * virConnectNumOfDefinedInterfaces:
6936 * @conn: pointer to the hypervisor connection
6938 * Provides the number of defined (inactive) interfaces on the physical host.
6940 * Returns the number of defined interface found or -1 in case of error
6943 virConnectNumOfDefinedInterfaces(virConnectPtr conn
)
6945 DEBUG("conn=%p", conn
);
6947 virResetLastError();
6949 if (!VIR_IS_CONNECT(conn
)) {
6950 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
6951 virDispatchError(NULL
);
6955 if (conn
->interfaceDriver
&& conn
->interfaceDriver
->numOfDefinedInterfaces
) {
6957 ret
= conn
->interfaceDriver
->numOfDefinedInterfaces (conn
);
6963 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
6966 virDispatchError(conn
);
6971 * virConnectListDefinedInterfaces:
6972 * @conn: pointer to the hypervisor connection
6973 * @names: array to collect the list of names of interfaces
6974 * @maxnames: size of @names
6976 * Collect the list of defined (inactive) physical host interfaces,
6977 * and store their names in @names.
6979 * Returns the number of interfaces found or -1 in case of error
6982 virConnectListDefinedInterfaces(virConnectPtr conn
,
6986 DEBUG("conn=%p, names=%p, maxnames=%d", conn
, names
, maxnames
);
6988 virResetLastError();
6990 if (!VIR_IS_CONNECT(conn
)) {
6991 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
6992 virDispatchError(NULL
);
6996 if ((names
== NULL
) || (maxnames
< 0)) {
6997 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7001 if (conn
->interfaceDriver
&& conn
->interfaceDriver
->listDefinedInterfaces
) {
7003 ret
= conn
->interfaceDriver
->listDefinedInterfaces (conn
, names
, maxnames
);
7009 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7012 virDispatchError(conn
);
7017 * virInterfaceLookupByName:
7018 * @conn: pointer to the hypervisor connection
7019 * @name: name for the interface
7021 * Try to lookup an interface on the given hypervisor based on its name.
7023 * Returns a new interface object or NULL in case of failure. If the
7024 * interface cannot be found, then VIR_ERR_NO_INTERFACE error is raised.
7027 virInterfaceLookupByName(virConnectPtr conn
, const char *name
)
7029 DEBUG("conn=%p, name=%s", conn
, name
);
7031 virResetLastError();
7033 if (!VIR_IS_CONNECT(conn
)) {
7034 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7035 virDispatchError(NULL
);
7039 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7043 if (conn
->interfaceDriver
&& conn
->interfaceDriver
->interfaceLookupByName
) {
7044 virInterfacePtr ret
;
7045 ret
= conn
->interfaceDriver
->interfaceLookupByName (conn
, name
);
7051 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7054 virDispatchError(conn
);
7059 * virInterfaceLookupByMACString:
7060 * @conn: pointer to the hypervisor connection
7061 * @macstr: the MAC for the interface (null-terminated ASCII format)
7063 * Try to lookup an interface on the given hypervisor based on its MAC.
7065 * Returns a new interface object or NULL in case of failure. If the
7066 * interface cannot be found, then VIR_ERR_NO_INTERFACE error is raised.
7069 virInterfaceLookupByMACString(virConnectPtr conn
, const char *macstr
)
7071 DEBUG("conn=%p, macstr=%s", conn
, macstr
);
7073 virResetLastError();
7075 if (!VIR_IS_CONNECT(conn
)) {
7076 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7077 virDispatchError(NULL
);
7080 if (macstr
== NULL
) {
7081 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7085 if (conn
->interfaceDriver
&& conn
->interfaceDriver
->interfaceLookupByMACString
) {
7086 virInterfacePtr ret
;
7087 ret
= conn
->interfaceDriver
->interfaceLookupByMACString (conn
, macstr
);
7093 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7096 virDispatchError(conn
);
7101 * virInterfaceGetName:
7102 * @iface: an interface object
7104 * Get the public name for that interface
7106 * Returns a pointer to the name or NULL, the string need not be deallocated
7107 * its lifetime will be the same as the interface object.
7110 virInterfaceGetName(virInterfacePtr iface
)
7112 DEBUG("iface=%p", iface
);
7114 virResetLastError();
7116 if (!VIR_IS_INTERFACE(iface
)) {
7117 virLibInterfaceError(NULL
, VIR_ERR_INVALID_INTERFACE
, __FUNCTION__
);
7118 virDispatchError(NULL
);
7121 return (iface
->name
);
7125 * virInterfaceGetMACString:
7126 * @iface: an interface object
7128 * Get the MAC for an interface as string. For more information about
7131 * Returns a pointer to the MAC address (in null-terminated ASCII
7132 * format) or NULL, the string need not be deallocated its lifetime
7133 * will be the same as the interface object.
7136 virInterfaceGetMACString(virInterfacePtr iface
)
7138 DEBUG("iface=%p", iface
);
7140 virResetLastError();
7142 if (!VIR_IS_INTERFACE(iface
)) {
7143 virLibInterfaceError(NULL
, VIR_ERR_INVALID_INTERFACE
, __FUNCTION__
);
7144 virDispatchError(NULL
);
7147 return (iface
->mac
);
7151 * virInterfaceGetXMLDesc:
7152 * @iface: an interface object
7153 * @flags: an OR'ed set of extraction flags. Current valid bits:
7155 * VIR_INTERFACE_XML_INACTIVE - return the static configuration,
7156 * suitable for use redefining the
7157 * interface via virInterfaceDefineXML()
7159 * Provide an XML description of the interface. If
7160 * VIR_INTERFACE_XML_INACTIVE is set, the description may be reused
7161 * later to redefine the interface with virInterfaceDefineXML(). If it
7162 * is not set, the ip address and netmask will be the current live
7163 * setting of the interface, not the settings from the config files.
7165 * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
7166 * the caller must free() the returned value.
7169 virInterfaceGetXMLDesc(virInterfacePtr iface
, unsigned int flags
)
7172 DEBUG("iface=%p, flags=%d", iface
, flags
);
7174 virResetLastError();
7176 if (!VIR_IS_CONNECTED_INTERFACE(iface
)) {
7177 virLibInterfaceError(NULL
, VIR_ERR_INVALID_INTERFACE
, __FUNCTION__
);
7178 virDispatchError(NULL
);
7181 if ((flags
& ~VIR_INTERFACE_XML_INACTIVE
) != 0) {
7182 virLibInterfaceError(iface
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7188 if (conn
->interfaceDriver
&& conn
->interfaceDriver
->interfaceGetXMLDesc
) {
7190 ret
= conn
->interfaceDriver
->interfaceGetXMLDesc (iface
, flags
);
7196 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7199 virDispatchError(iface
->conn
);
7204 * virInterfaceDefineXML:
7205 * @conn: pointer to the hypervisor connection
7206 * @xml: the XML description for the interface, preferably in UTF-8
7207 * @flags: and OR'ed set of extraction flags, not used yet
7209 * Define an interface (or modify existing interface configuration)
7211 * Returns NULL in case of error, a pointer to the interface otherwise
7214 virInterfaceDefineXML(virConnectPtr conn
, const char *xml
, unsigned int flags
)
7216 DEBUG("conn=%p, xml=%s, flags=%d", conn
, xml
, flags
);
7218 virResetLastError();
7220 if (!VIR_IS_CONNECT(conn
)) {
7221 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7222 virDispatchError(NULL
);
7225 if (conn
->flags
& VIR_CONNECT_RO
) {
7226 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
7230 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7234 if (conn
->interfaceDriver
&& conn
->interfaceDriver
->interfaceDefineXML
) {
7235 virInterfacePtr ret
;
7236 ret
= conn
->interfaceDriver
->interfaceDefineXML (conn
, xml
, flags
);
7242 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7245 virDispatchError(conn
);
7250 * virInterfaceUndefine:
7251 * @iface: pointer to a defined interface
7253 * Undefine an interface, ie remove it from the config.
7254 * This does not free the associated virInterfacePtr object.
7256 * Returns 0 in case of success, -1 in case of error
7259 virInterfaceUndefine(virInterfacePtr iface
) {
7261 DEBUG("iface=%p", iface
);
7263 virResetLastError();
7265 if (!VIR_IS_CONNECTED_INTERFACE(iface
)) {
7266 virLibInterfaceError(NULL
, VIR_ERR_INVALID_INTERFACE
, __FUNCTION__
);
7267 virDispatchError(NULL
);
7271 if (conn
->flags
& VIR_CONNECT_RO
) {
7272 virLibInterfaceError(iface
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
7276 if (conn
->interfaceDriver
&& conn
->interfaceDriver
->interfaceUndefine
) {
7278 ret
= conn
->interfaceDriver
->interfaceUndefine (iface
);
7284 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7287 virDispatchError(iface
->conn
);
7292 * virInterfaceCreate:
7293 * @iface: pointer to a defined interface
7294 * @flags: and OR'ed set of extraction flags, not used yet
7296 * Activate an interface (ie call "ifup")
7298 * Returns 0 in case of success, -1 in case of error
7301 virInterfaceCreate(virInterfacePtr iface
, unsigned int flags
)
7304 DEBUG("iface=%p, flags=%d", iface
, flags
);
7306 virResetLastError();
7308 if (!VIR_IS_CONNECTED_INTERFACE(iface
)) {
7309 virLibInterfaceError(NULL
, VIR_ERR_INVALID_INTERFACE
, __FUNCTION__
);
7310 virDispatchError(NULL
);
7314 if (conn
->flags
& VIR_CONNECT_RO
) {
7315 virLibInterfaceError(iface
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
7319 if (conn
->interfaceDriver
&& conn
->interfaceDriver
->interfaceCreate
) {
7321 ret
= conn
->interfaceDriver
->interfaceCreate (iface
, flags
);
7327 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7330 virDispatchError(iface
->conn
);
7335 * virInterfaceDestroy:
7336 * @iface: an interface object
7337 * @flags: and OR'ed set of extraction flags, not used yet
7339 * deactivate an interface (ie call "ifdown")
7340 * This does not remove the interface from the config, and
7341 * does not free the associated virInterfacePtr object.
7343 * Returns 0 in case of success and -1 in case of failure.
7346 virInterfaceDestroy(virInterfacePtr iface
, unsigned int flags
)
7349 DEBUG("iface=%p, flags=%d", iface
, flags
);
7351 virResetLastError();
7353 if (!VIR_IS_CONNECTED_INTERFACE(iface
)) {
7354 virLibInterfaceError(NULL
, VIR_ERR_INVALID_INTERFACE
, __FUNCTION__
);
7355 virDispatchError(NULL
);
7360 if (conn
->flags
& VIR_CONNECT_RO
) {
7361 virLibInterfaceError(iface
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
7365 if (conn
->interfaceDriver
&& conn
->interfaceDriver
->interfaceDestroy
) {
7367 ret
= conn
->interfaceDriver
->interfaceDestroy (iface
, flags
);
7373 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7376 virDispatchError(iface
->conn
);
7382 * @iface: the interface to hold a reference on
7384 * Increment the reference count on the interface. For each
7385 * additional call to this method, there shall be a corresponding
7386 * call to virInterfaceFree to release the reference count, once
7387 * the caller no longer needs the reference to this object.
7389 * This method is typically useful for applications where multiple
7390 * threads are using a connection, and it is required that the
7391 * connection remain open until all threads have finished using
7392 * it. ie, each new thread using an interface would increment
7393 * the reference count.
7395 * Returns 0 in case of success, -1 in case of failure.
7398 virInterfaceRef(virInterfacePtr iface
)
7400 if ((!VIR_IS_CONNECTED_INTERFACE(iface
))) {
7401 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7402 virDispatchError(NULL
);
7405 virMutexLock(&iface
->conn
->lock
);
7406 DEBUG("iface=%p refs=%d", iface
, iface
->refs
);
7408 virMutexUnlock(&iface
->conn
->lock
);
7414 * @iface: an interface object
7416 * Free the interface object. The interface itself is unaltered.
7417 * The data structure is freed and should not be used thereafter.
7419 * Returns 0 in case of success and -1 in case of failure.
7422 virInterfaceFree(virInterfacePtr iface
)
7424 DEBUG("iface=%p", iface
);
7426 virResetLastError();
7428 if (!VIR_IS_CONNECTED_INTERFACE(iface
)) {
7429 virLibInterfaceError(NULL
, VIR_ERR_INVALID_INTERFACE
, __FUNCTION__
);
7430 virDispatchError(NULL
);
7433 if (virUnrefInterface(iface
) < 0) {
7434 virDispatchError(NULL
);
7442 * virStoragePoolGetConnect:
7443 * @pool: pointer to a pool
7445 * Provides the connection pointer associated with a storage pool. The
7446 * reference counter on the connection is not increased by this
7449 * WARNING: When writing libvirt bindings in other languages, do
7450 * not use this function. Instead, store the connection and
7451 * the pool object together.
7453 * Returns the virConnectPtr or NULL in case of failure.
7456 virStoragePoolGetConnect (virStoragePoolPtr pool
)
7458 DEBUG("pool=%p", pool
);
7460 virResetLastError();
7462 if (!VIR_IS_CONNECTED_STORAGE_POOL (pool
)) {
7463 virLibStoragePoolError (NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
7464 virDispatchError(NULL
);
7471 * virConnectNumOfStoragePools:
7472 * @conn: pointer to hypervisor connection
7474 * Provides the number of active storage pools
7476 * Returns the number of pools found, or -1 on error
7479 virConnectNumOfStoragePools (virConnectPtr conn
)
7481 DEBUG("conn=%p", conn
);
7483 virResetLastError();
7485 if (!VIR_IS_CONNECT(conn
)) {
7486 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7487 virDispatchError(NULL
);
7491 if (conn
->storageDriver
&& conn
->storageDriver
->numOfPools
) {
7493 ret
= conn
->storageDriver
->numOfPools (conn
);
7499 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7502 virDispatchError(conn
);
7507 * virConnectListStoragePools:
7508 * @conn: pointer to hypervisor connection
7509 * @names: array of char * to fill with pool names (allocated by caller)
7510 * @maxnames: size of the names array
7512 * Provides the list of names of active storage pools
7513 * upto maxnames. If there are more than maxnames, the
7514 * remaining names will be silently ignored.
7516 * Returns 0 on success, -1 on error
7519 virConnectListStoragePools (virConnectPtr conn
,
7523 DEBUG("conn=%p, names=%p, maxnames=%d", conn
, names
, maxnames
);
7525 virResetLastError();
7527 if (!VIR_IS_CONNECT(conn
)) {
7528 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7529 virDispatchError(NULL
);
7533 if ((names
== NULL
) || (maxnames
< 0)) {
7534 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7538 if (conn
->storageDriver
&& conn
->storageDriver
->listPools
) {
7540 ret
= conn
->storageDriver
->listPools (conn
, names
, maxnames
);
7546 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7549 virDispatchError(conn
);
7555 * virConnectNumOfDefinedStoragePools:
7556 * @conn: pointer to hypervisor connection
7558 * Provides the number of inactive storage pools
7560 * Returns the number of pools found, or -1 on error
7563 virConnectNumOfDefinedStoragePools(virConnectPtr conn
)
7565 DEBUG("conn=%p", conn
);
7567 virResetLastError();
7569 if (!VIR_IS_CONNECT(conn
)) {
7570 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7571 virDispatchError(NULL
);
7575 if (conn
->storageDriver
&& conn
->storageDriver
->numOfDefinedPools
) {
7577 ret
= conn
->storageDriver
->numOfDefinedPools (conn
);
7583 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7586 virDispatchError(conn
);
7592 * virConnectListDefinedStoragePools:
7593 * @conn: pointer to hypervisor connection
7594 * @names: array of char * to fill with pool names (allocated by caller)
7595 * @maxnames: size of the names array
7597 * Provides the list of names of inactive storage pools
7598 * upto maxnames. If there are more than maxnames, the
7599 * remaining names will be silently ignored.
7601 * Returns 0 on success, -1 on error
7604 virConnectListDefinedStoragePools(virConnectPtr conn
,
7608 DEBUG("conn=%p, names=%p, maxnames=%d", conn
, names
, maxnames
);
7610 virResetLastError();
7612 if (!VIR_IS_CONNECT(conn
)) {
7613 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7614 virDispatchError(NULL
);
7618 if ((names
== NULL
) || (maxnames
< 0)) {
7619 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7623 if (conn
->storageDriver
&& conn
->storageDriver
->listDefinedPools
) {
7625 ret
= conn
->storageDriver
->listDefinedPools (conn
, names
, maxnames
);
7631 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7634 virDispatchError(conn
);
7640 * virConnectFindStoragePoolSources:
7641 * @conn: pointer to hypervisor connection
7642 * @type: type of storage pool sources to discover
7643 * @srcSpec: XML document specifying discovery source
7644 * @flags: flags for discovery (unused, pass 0)
7646 * Talks to a storage backend and attempts to auto-discover the set of
7647 * available storage pool sources. e.g. For iSCSI this would be a set of
7648 * iSCSI targets. For NFS this would be a list of exported paths. The
7649 * srcSpec (optional for some storage pool types, e.g. local ones) is
7650 * an instance of the storage pool's source element specifying where
7651 * to look for the pools.
7653 * srcSpec is not required for some types (e.g., those querying
7654 * local storage resources only)
7656 * Returns an xml document consisting of a SourceList element
7657 * containing a source document appropriate to the given pool
7658 * type for each discovered source.
7661 virConnectFindStoragePoolSources(virConnectPtr conn
,
7663 const char *srcSpec
,
7666 DEBUG("conn=%p, type=%s, src=%s, flags=%u", conn
, type
? type
: "", srcSpec
? srcSpec
: "", flags
);
7668 virResetLastError();
7670 if (!VIR_IS_CONNECT(conn
)) {
7671 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7672 virDispatchError(NULL
);
7676 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7680 if (conn
->flags
& VIR_CONNECT_RO
) {
7681 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
7685 if (conn
->storageDriver
&& conn
->storageDriver
->findPoolSources
) {
7687 ret
= conn
->storageDriver
->findPoolSources(conn
, type
, srcSpec
, flags
);
7693 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7696 virDispatchError(conn
);
7702 * virStoragePoolLookupByName:
7703 * @conn: pointer to hypervisor connection
7704 * @name: name of pool to fetch
7706 * Fetch a storage pool based on its unique name
7708 * Returns a virStoragePoolPtr object, or NULL if no matching pool is found
7711 virStoragePoolLookupByName(virConnectPtr conn
,
7714 DEBUG("conn=%p, name=%s", conn
, name
);
7716 virResetLastError();
7718 if (!VIR_IS_CONNECT(conn
)) {
7719 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7720 virDispatchError(NULL
);
7724 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7728 if (conn
->storageDriver
&& conn
->storageDriver
->poolLookupByName
) {
7729 virStoragePoolPtr ret
;
7730 ret
= conn
->storageDriver
->poolLookupByName (conn
, name
);
7736 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7739 virDispatchError(conn
);
7745 * virStoragePoolLookupByUUID:
7746 * @conn: pointer to hypervisor connection
7747 * @uuid: globally unique id of pool to fetch
7749 * Fetch a storage pool based on its globally unique id
7751 * Returns a virStoragePoolPtr object, or NULL if no matching pool is found
7754 virStoragePoolLookupByUUID(virConnectPtr conn
,
7755 const unsigned char *uuid
)
7757 DEBUG("conn=%p, uuid=%s", conn
, uuid
);
7759 virResetLastError();
7761 if (!VIR_IS_CONNECT(conn
)) {
7762 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7763 virDispatchError(NULL
);
7767 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7771 if (conn
->storageDriver
&& conn
->storageDriver
->poolLookupByUUID
) {
7772 virStoragePoolPtr ret
;
7773 ret
= conn
->storageDriver
->poolLookupByUUID (conn
, uuid
);
7779 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7782 virDispatchError(conn
);
7788 * virStoragePoolLookupByUUIDString:
7789 * @conn: pointer to hypervisor connection
7790 * @uuidstr: globally unique id of pool to fetch
7792 * Fetch a storage pool based on its globally unique id
7794 * Returns a virStoragePoolPtr object, or NULL if no matching pool is found
7797 virStoragePoolLookupByUUIDString(virConnectPtr conn
,
7798 const char *uuidstr
)
7800 unsigned char uuid
[VIR_UUID_BUFLEN
];
7801 DEBUG("conn=%p, uuidstr=%s", conn
, uuidstr
);
7803 virResetLastError();
7805 if (!VIR_IS_CONNECT(conn
)) {
7806 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7807 virDispatchError(NULL
);
7810 if (uuidstr
== NULL
) {
7811 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7815 if (virUUIDParse(uuidstr
, uuid
) < 0) {
7816 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7820 return virStoragePoolLookupByUUID(conn
, uuid
);
7823 virDispatchError(conn
);
7829 * virStoragePoolLookupByVolume:
7830 * @vol: pointer to storage volume
7832 * Fetch a storage pool which contains a particular volume
7834 * Returns a virStoragePoolPtr object, or NULL if no matching pool is found
7837 virStoragePoolLookupByVolume(virStorageVolPtr vol
)
7839 DEBUG("vol=%p", vol
);
7841 virResetLastError();
7843 if (!VIR_IS_CONNECTED_STORAGE_VOL(vol
)) {
7844 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7845 virDispatchError(NULL
);
7849 if (vol
->conn
->storageDriver
&& vol
->conn
->storageDriver
->poolLookupByVolume
) {
7850 virStoragePoolPtr ret
;
7851 ret
= vol
->conn
->storageDriver
->poolLookupByVolume (vol
);
7857 virLibConnError (vol
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7860 virDispatchError(vol
->conn
);
7865 * virStoragePoolCreateXML:
7866 * @conn: pointer to hypervisor connection
7867 * @xmlDesc: XML description for new pool
7868 * @flags: future flags, use 0 for now
7870 * Create a new storage based on its XML description. The
7871 * pool is not persistent, so its definition will disappear
7872 * when it is destroyed, or if the host is restarted
7874 * Returns a virStoragePoolPtr object, or NULL if creation failed
7877 virStoragePoolCreateXML(virConnectPtr conn
,
7878 const char *xmlDesc
,
7881 DEBUG("conn=%p, xmlDesc=%s", conn
, xmlDesc
);
7883 virResetLastError();
7885 if (!VIR_IS_CONNECT(conn
)) {
7886 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7887 virDispatchError(NULL
);
7890 if (xmlDesc
== NULL
) {
7891 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7894 if (conn
->flags
& VIR_CONNECT_RO
) {
7895 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
7899 if (conn
->storageDriver
&& conn
->storageDriver
->poolCreateXML
) {
7900 virStoragePoolPtr ret
;
7901 ret
= conn
->storageDriver
->poolCreateXML (conn
, xmlDesc
, flags
);
7907 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7910 virDispatchError(conn
);
7915 * virStoragePoolDefineXML:
7916 * @conn: pointer to hypervisor connection
7917 * @xml: XML description for new pool
7918 * @flags: future flags, use 0 for now
7920 * Define a new inactive storage pool based on its XML description. The
7921 * pool is persistent, until explicitly undefined.
7923 * Returns a virStoragePoolPtr object, or NULL if creation failed
7926 virStoragePoolDefineXML(virConnectPtr conn
,
7930 DEBUG("conn=%p, xml=%s", conn
, xml
);
7932 virResetLastError();
7934 if (!VIR_IS_CONNECT(conn
)) {
7935 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
7936 virDispatchError(NULL
);
7939 if (conn
->flags
& VIR_CONNECT_RO
) {
7940 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
7944 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
7948 if (conn
->storageDriver
&& conn
->storageDriver
->poolDefineXML
) {
7949 virStoragePoolPtr ret
;
7950 ret
= conn
->storageDriver
->poolDefineXML (conn
, xml
, flags
);
7956 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
7959 virDispatchError(conn
);
7964 * virStoragePoolBuild:
7965 * @pool: pointer to storage pool
7966 * @flags: future flags, use 0 for now
7968 * Build the underlying storage pool
7970 * Returns 0 on success, or -1 upon failure
7973 virStoragePoolBuild(virStoragePoolPtr pool
,
7977 DEBUG("pool=%p, flags=%u", pool
, flags
);
7979 virResetLastError();
7981 if (!VIR_IS_CONNECTED_STORAGE_POOL(pool
)) {
7982 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
7983 virDispatchError(NULL
);
7987 if (conn
->flags
& VIR_CONNECT_RO
) {
7988 virLibStoragePoolError(pool
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
7992 if (conn
->storageDriver
&& conn
->storageDriver
->poolBuild
) {
7994 ret
= conn
->storageDriver
->poolBuild (pool
, flags
);
8000 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8003 virDispatchError(pool
->conn
);
8009 * virStoragePoolUndefine:
8010 * @pool: pointer to storage pool
8012 * Undefine an inactive storage pool
8014 * Returns 0 on success, -1 on failure
8017 virStoragePoolUndefine(virStoragePoolPtr pool
)
8020 DEBUG("pool=%p", pool
);
8022 virResetLastError();
8024 if (!VIR_IS_CONNECTED_STORAGE_POOL(pool
)) {
8025 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_NETWORK
, __FUNCTION__
);
8026 virDispatchError(NULL
);
8030 if (conn
->flags
& VIR_CONNECT_RO
) {
8031 virLibStoragePoolError(pool
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
8035 if (conn
->storageDriver
&& conn
->storageDriver
->poolUndefine
) {
8037 ret
= conn
->storageDriver
->poolUndefine (pool
);
8043 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8046 virDispatchError(pool
->conn
);
8052 * virStoragePoolCreate:
8053 * @pool: pointer to storage pool
8054 * @flags: future flags, use 0 for now
8056 * Starts an inactive storage pool
8058 * Returns 0 on success, or -1 if it could not be started
8061 virStoragePoolCreate(virStoragePoolPtr pool
,
8065 DEBUG("pool=%p", pool
);
8067 virResetLastError();
8069 if (!VIR_IS_CONNECTED_STORAGE_POOL(pool
)) {
8070 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8071 virDispatchError(NULL
);
8075 if (conn
->flags
& VIR_CONNECT_RO
) {
8076 virLibStoragePoolError(pool
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
8080 if (conn
->storageDriver
&& conn
->storageDriver
->poolCreate
) {
8082 ret
= conn
->storageDriver
->poolCreate (pool
, flags
);
8088 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8091 virDispatchError(pool
->conn
);
8097 * virStoragePoolDestroy:
8098 * @pool: pointer to storage pool
8100 * Destroy an active storage pool. This will deactivate the
8101 * pool on the host, but keep any persistent config associated
8102 * with it. If it has a persistent config it can later be
8103 * restarted with virStoragePoolCreate(). This does not free
8104 * the associated virStoragePoolPtr object.
8106 * Returns 0 on success, or -1 if it could not be destroyed
8109 virStoragePoolDestroy(virStoragePoolPtr pool
)
8112 DEBUG("pool=%p", pool
);
8114 virResetLastError();
8116 if (!VIR_IS_CONNECTED_STORAGE_POOL(pool
)) {
8117 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8118 virDispatchError(NULL
);
8123 if (conn
->flags
& VIR_CONNECT_RO
) {
8124 virLibStoragePoolError(pool
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
8128 if (conn
->storageDriver
&& conn
->storageDriver
->poolDestroy
) {
8130 ret
= conn
->storageDriver
->poolDestroy (pool
);
8136 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8139 virDispatchError(pool
->conn
);
8144 * virStoragePoolDelete:
8145 * @pool: pointer to storage pool
8146 * @flags: flags for obliteration process
8148 * Delete the underlying pool resources. This is
8149 * a non-recoverable operation. The virStoragePoolPtr object
8150 * itself is not free'd.
8152 * Returns 0 on success, or -1 if it could not be obliterate
8155 virStoragePoolDelete(virStoragePoolPtr pool
,
8159 DEBUG("pool=%p, flags=%u", pool
, flags
);
8161 virResetLastError();
8163 if (!VIR_IS_CONNECTED_STORAGE_POOL(pool
)) {
8164 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8165 virDispatchError(NULL
);
8170 if (conn
->flags
& VIR_CONNECT_RO
) {
8171 virLibStoragePoolError(pool
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
8175 if (conn
->storageDriver
&& conn
->storageDriver
->poolDelete
) {
8177 ret
= conn
->storageDriver
->poolDelete (pool
, flags
);
8183 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8186 virDispatchError(pool
->conn
);
8192 * virStoragePoolFree:
8193 * @pool: pointer to storage pool
8195 * Free a storage pool object, releasing all memory associated with
8196 * it. Does not change the state of the pool on the host.
8198 * Returns 0 on success, or -1 if it could not be free'd.
8201 virStoragePoolFree(virStoragePoolPtr pool
)
8203 DEBUG("pool=%p", pool
);
8205 virResetLastError();
8207 if (!VIR_IS_CONNECTED_STORAGE_POOL(pool
)) {
8208 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8209 virDispatchError(NULL
);
8212 if (virUnrefStoragePool(pool
) < 0) {
8213 virDispatchError(NULL
);
8222 * virStoragePoolRef:
8223 * @pool: the pool to hold a reference on
8225 * Increment the reference count on the pool. For each
8226 * additional call to this method, there shall be a corresponding
8227 * call to virStoragePoolFree to release the reference count, once
8228 * the caller no longer needs the reference to this object.
8230 * This method is typically useful for applications where multiple
8231 * threads are using a connection, and it is required that the
8232 * connection remain open until all threads have finished using
8233 * it. ie, each new thread using a pool would increment
8234 * the reference count.
8236 * Returns 0 in case of success, -1 in case of failure.
8239 virStoragePoolRef(virStoragePoolPtr pool
)
8241 if ((!VIR_IS_CONNECTED_STORAGE_POOL(pool
))) {
8242 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
8243 virDispatchError(NULL
);
8246 virMutexLock(&pool
->conn
->lock
);
8247 DEBUG("pool=%p refs=%d", pool
, pool
->refs
);
8249 virMutexUnlock(&pool
->conn
->lock
);
8254 * virStoragePoolRefresh:
8255 * @pool: pointer to storage pool
8256 * @flags: flags to control refresh behaviour (currently unused, use 0)
8258 * Request that the pool refresh its list of volumes. This may
8259 * involve communicating with a remote server, and/or initializing
8260 * new devices at the OS layer
8262 * Returns 0 if the volume list was refreshed, -1 on failure
8265 virStoragePoolRefresh(virStoragePoolPtr pool
,
8269 DEBUG("pool=%p flags=%u", pool
, flags
);
8271 virResetLastError();
8273 if (!VIR_IS_CONNECTED_STORAGE_POOL(pool
)) {
8274 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8275 virDispatchError(NULL
);
8280 if (conn
->flags
& VIR_CONNECT_RO
) {
8281 virLibStoragePoolError(pool
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
8285 if (conn
->storageDriver
&& conn
->storageDriver
->poolRefresh
) {
8287 ret
= conn
->storageDriver
->poolRefresh (pool
, flags
);
8293 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8296 virDispatchError(pool
->conn
);
8302 * virStoragePoolGetName:
8303 * @pool: pointer to storage pool
8305 * Fetch the locally unique name of the storage pool
8307 * Returns the name of the pool, or NULL on error
8310 virStoragePoolGetName(virStoragePoolPtr pool
)
8312 DEBUG("pool=%p", pool
);
8314 virResetLastError();
8316 if (!VIR_IS_STORAGE_POOL(pool
)) {
8317 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8318 virDispatchError(NULL
);
8321 return (pool
->name
);
8326 * virStoragePoolGetUUID:
8327 * @pool: pointer to storage pool
8328 * @uuid: buffer of VIR_UUID_BUFLEN bytes in size
8330 * Fetch the globally unique ID of the storage pool
8332 * Returns 0 on success, or -1 on error;
8335 virStoragePoolGetUUID(virStoragePoolPtr pool
,
8336 unsigned char *uuid
)
8338 DEBUG("pool=%p, uuid=%p", pool
, uuid
);
8340 virResetLastError();
8342 if (!VIR_IS_STORAGE_POOL(pool
)) {
8343 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8344 virDispatchError(NULL
);
8348 virLibStoragePoolError(pool
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
8352 memcpy(uuid
, &pool
->uuid
[0], VIR_UUID_BUFLEN
);
8357 virDispatchError(pool
->conn
);
8362 * virStoragePoolGetUUIDString:
8363 * @pool: pointer to storage pool
8364 * @buf: buffer of VIR_UUID_STRING_BUFLEN bytes in size
8366 * Fetch the globally unique ID of the storage pool as a string
8368 * Returns 0 on success, or -1 on error;
8371 virStoragePoolGetUUIDString(virStoragePoolPtr pool
,
8374 unsigned char uuid
[VIR_UUID_BUFLEN
];
8375 DEBUG("pool=%p, buf=%p", pool
, buf
);
8377 virResetLastError();
8379 if (!VIR_IS_STORAGE_POOL(pool
)) {
8380 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8381 virDispatchError(NULL
);
8385 virLibStoragePoolError(pool
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
8389 if (virStoragePoolGetUUID(pool
, &uuid
[0]))
8392 virUUIDFormat(uuid
, buf
);
8396 virDispatchError(pool
->conn
);
8402 * virStoragePoolGetInfo:
8403 * @pool: pointer to storage pool
8404 * @info: pointer at which to store info
8406 * Get volatile information about the storage pool
8407 * such as free space / usage summary
8409 * Returns 0 on success, or -1 on failure.
8412 virStoragePoolGetInfo(virStoragePoolPtr pool
,
8413 virStoragePoolInfoPtr info
)
8416 DEBUG("pool=%p, info=%p", pool
, info
);
8418 virResetLastError();
8420 if (!VIR_IS_CONNECTED_STORAGE_POOL(pool
)) {
8421 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8422 virDispatchError(NULL
);
8426 virLibStoragePoolError(pool
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
8430 memset(info
, 0, sizeof(virStoragePoolInfo
));
8434 if (conn
->storageDriver
->poolGetInfo
) {
8436 ret
= conn
->storageDriver
->poolGetInfo (pool
, info
);
8442 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8445 virDispatchError(pool
->conn
);
8451 * virStoragePoolGetXMLDesc:
8452 * @pool: pointer to storage pool
8453 * @flags: flags for XML format options (set of virDomainXMLFlags)
8455 * Fetch an XML document describing all aspects of the
8456 * storage pool. This is suitable for later feeding back
8457 * into the virStoragePoolCreateXML method.
8459 * Returns a XML document, or NULL on error
8462 virStoragePoolGetXMLDesc(virStoragePoolPtr pool
,
8466 DEBUG("pool=%p, flags=%u", pool
, flags
);
8468 virResetLastError();
8470 if (!VIR_IS_CONNECTED_STORAGE_POOL(pool
)) {
8471 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8472 virDispatchError(NULL
);
8476 virLibStoragePoolError(pool
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
8482 if (conn
->storageDriver
&& conn
->storageDriver
->poolGetXMLDesc
) {
8484 ret
= conn
->storageDriver
->poolGetXMLDesc (pool
, flags
);
8490 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8493 virDispatchError(pool
->conn
);
8499 * virStoragePoolGetAutostart:
8500 * @pool: pointer to storage pool
8501 * @autostart: location in which to store autostart flag
8503 * Fetches the value of the autostart flag, which determines
8504 * whether the pool is automatically started at boot time
8506 * Returns 0 on success, -1 on failure
8509 virStoragePoolGetAutostart(virStoragePoolPtr pool
,
8513 DEBUG("pool=%p, autostart=%p", pool
, autostart
);
8515 virResetLastError();
8517 if (!VIR_IS_CONNECTED_STORAGE_POOL(pool
)) {
8518 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8519 virDispatchError(NULL
);
8523 virLibStoragePoolError(pool
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
8529 if (conn
->storageDriver
&& conn
->storageDriver
->poolGetAutostart
) {
8531 ret
= conn
->storageDriver
->poolGetAutostart (pool
, autostart
);
8537 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8540 virDispatchError(pool
->conn
);
8546 * virStoragePoolSetAutostart:
8547 * @pool: pointer to storage pool
8548 * @autostart: new flag setting
8550 * Sets the autostart flag
8552 * Returns 0 on success, -1 on failure
8555 virStoragePoolSetAutostart(virStoragePoolPtr pool
,
8559 DEBUG("pool=%p, autostart=%d", pool
, autostart
);
8561 virResetLastError();
8563 if (!VIR_IS_CONNECTED_STORAGE_POOL(pool
)) {
8564 virLibStoragePoolError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8565 virDispatchError(NULL
);
8569 if (pool
->conn
->flags
& VIR_CONNECT_RO
) {
8570 virLibStoragePoolError(pool
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
8576 if (conn
->storageDriver
&& conn
->storageDriver
->poolSetAutostart
) {
8578 ret
= conn
->storageDriver
->poolSetAutostart (pool
, autostart
);
8584 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8587 virDispatchError(pool
->conn
);
8593 * virStoragePoolNumOfVolumes:
8594 * @pool: pointer to storage pool
8596 * Fetch the number of storage volumes within a pool
8598 * Returns the number of storage pools, or -1 on failure
8601 virStoragePoolNumOfVolumes(virStoragePoolPtr pool
)
8603 DEBUG("pool=%p", pool
);
8605 virResetLastError();
8607 if (!VIR_IS_STORAGE_POOL(pool
)) {
8608 virLibConnError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8609 virDispatchError(NULL
);
8613 if (pool
->conn
->storageDriver
&& pool
->conn
->storageDriver
->poolNumOfVolumes
) {
8615 ret
= pool
->conn
->storageDriver
->poolNumOfVolumes (pool
);
8621 virLibConnError (pool
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8624 virDispatchError(pool
->conn
);
8630 * virStoragePoolListVolumes:
8631 * @pool: pointer to storage pool
8632 * @names: array in which to storage volume names
8633 * @maxnames: size of names array
8635 * Fetch list of storage volume names, limiting to
8638 * Returns the number of names fetched, or -1 on error
8641 virStoragePoolListVolumes(virStoragePoolPtr pool
,
8645 DEBUG("pool=%p, names=%p, maxnames=%d", pool
, names
, maxnames
);
8647 virResetLastError();
8649 if (!VIR_IS_STORAGE_POOL(pool
)) {
8650 virLibConnError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8651 virDispatchError(NULL
);
8655 if ((names
== NULL
) || (maxnames
< 0)) {
8656 virLibConnError(pool
->conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
8660 if (pool
->conn
->storageDriver
&& pool
->conn
->storageDriver
->poolListVolumes
) {
8662 ret
= pool
->conn
->storageDriver
->poolListVolumes (pool
, names
, maxnames
);
8668 virLibConnError (pool
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8671 virDispatchError(pool
->conn
);
8677 * virStorageVolGetConnect:
8678 * @vol: pointer to a pool
8680 * Provides the connection pointer associated with a storage volume. The
8681 * reference counter on the connection is not increased by this
8684 * WARNING: When writing libvirt bindings in other languages, do
8685 * not use this function. Instead, store the connection and
8686 * the volume object together.
8688 * Returns the virConnectPtr or NULL in case of failure.
8691 virStorageVolGetConnect (virStorageVolPtr vol
)
8693 DEBUG("vol=%p", vol
);
8695 virResetLastError();
8697 if (!VIR_IS_STORAGE_VOL (vol
)) {
8698 virLibStoragePoolError (NULL
, VIR_ERR_INVALID_STORAGE_VOL
, __FUNCTION__
);
8699 virDispatchError(NULL
);
8707 * virStorageVolLookupByName:
8708 * @pool: pointer to storage pool
8709 * @name: name of storage volume
8711 * Fetch a pointer to a storage volume based on its name
8714 * Returns a storage volume, or NULL if not found / error
8717 virStorageVolLookupByName(virStoragePoolPtr pool
,
8720 DEBUG("pool=%p, name=%s", pool
, name
);
8722 virResetLastError();
8724 if (!VIR_IS_STORAGE_POOL(pool
)) {
8725 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
8726 virDispatchError(NULL
);
8730 virLibConnError(pool
->conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
8734 if (pool
->conn
->storageDriver
&& pool
->conn
->storageDriver
->volLookupByName
) {
8735 virStorageVolPtr ret
;
8736 ret
= pool
->conn
->storageDriver
->volLookupByName (pool
, name
);
8742 virLibConnError (pool
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8745 virDispatchError(pool
->conn
);
8752 * virStorageVolLookupByKey:
8753 * @conn: pointer to hypervisor connection
8754 * @key: globally unique key
8756 * Fetch a pointer to a storage volume based on its
8757 * globally unique key
8759 * Returns a storage volume, or NULL if not found / error
8762 virStorageVolLookupByKey(virConnectPtr conn
,
8765 DEBUG("conn=%p, key=%s", conn
, key
);
8767 virResetLastError();
8769 if (!VIR_IS_CONNECT(conn
)) {
8770 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
8771 virDispatchError(NULL
);
8775 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
8779 if (conn
->storageDriver
&& conn
->storageDriver
->volLookupByKey
) {
8780 virStorageVolPtr ret
;
8781 ret
= conn
->storageDriver
->volLookupByKey (conn
, key
);
8787 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8790 virDispatchError(conn
);
8795 * virStorageVolLookupByPath:
8796 * @conn: pointer to hypervisor connection
8797 * @path: locally unique path
8799 * Fetch a pointer to a storage volume based on its
8800 * locally (host) unique path
8802 * Returns a storage volume, or NULL if not found / error
8805 virStorageVolLookupByPath(virConnectPtr conn
,
8808 DEBUG("conn=%p, path=%s", conn
, path
);
8810 virResetLastError();
8812 if (!VIR_IS_CONNECT(conn
)) {
8813 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
8814 virDispatchError(NULL
);
8818 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
8822 if (conn
->storageDriver
&& conn
->storageDriver
->volLookupByPath
) {
8823 virStorageVolPtr ret
;
8824 ret
= conn
->storageDriver
->volLookupByPath (conn
, path
);
8830 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8833 virDispatchError(conn
);
8839 * virStorageVolGetName:
8840 * @vol: pointer to storage volume
8842 * Fetch the storage volume name. This is unique
8843 * within the scope of a pool
8845 * Returns the volume name, or NULL on error
8848 virStorageVolGetName(virStorageVolPtr vol
)
8850 DEBUG("vol=%p", vol
);
8852 virResetLastError();
8854 if (!VIR_IS_STORAGE_VOL(vol
)) {
8855 virLibStorageVolError(NULL
, VIR_ERR_INVALID_STORAGE_VOL
, __FUNCTION__
);
8856 virDispatchError(NULL
);
8864 * virStorageVolGetKey:
8865 * @vol: pointer to storage volume
8867 * Fetch the storage volume key. This is globally
8868 * unique, so the same volume will have the same
8869 * key no matter what host it is accessed from
8871 * Returns the volume key, or NULL on error
8874 virStorageVolGetKey(virStorageVolPtr vol
)
8876 DEBUG("vol=%p", vol
);
8878 virResetLastError();
8880 if (!VIR_IS_STORAGE_VOL(vol
)) {
8881 virLibStorageVolError(NULL
, VIR_ERR_INVALID_STORAGE_VOL
, __FUNCTION__
);
8882 virDispatchError(NULL
);
8890 * virStorageVolCreateXML:
8891 * @pool: pointer to storage pool
8892 * @xmldesc: description of volume to create
8893 * @flags: flags for creation (unused, pass 0)
8895 * Create a storage volume within a pool based
8896 * on an XML description. Not all pools support
8897 * creation of volumes
8899 * Returns the storage volume, or NULL on error
8902 virStorageVolCreateXML(virStoragePoolPtr pool
,
8903 const char *xmldesc
,
8906 DEBUG("pool=%p, flags=%u", pool
, flags
);
8908 virResetLastError();
8910 if (!VIR_IS_STORAGE_POOL(pool
)) {
8911 virLibConnError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8912 virDispatchError(NULL
);
8916 if (pool
->conn
->flags
& VIR_CONNECT_RO
) {
8917 virLibConnError(pool
->conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
8921 if (pool
->conn
->storageDriver
&& pool
->conn
->storageDriver
->volCreateXML
) {
8922 virStorageVolPtr ret
;
8923 ret
= pool
->conn
->storageDriver
->volCreateXML (pool
, xmldesc
, flags
);
8929 virLibConnError (pool
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8932 virDispatchError(pool
->conn
);
8938 * virStorageVolCreateXMLFrom:
8939 * @pool: pointer to parent pool for the new volume
8940 * @xmldesc: description of volume to create
8941 * @clonevol: storage volume to use as input
8942 * @flags: flags for creation (unused, pass 0)
8944 * Create a storage volume in the parent pool, using the
8945 * 'clonevol' volume as input. Information for the new
8946 * volume (name, perms) are passed via a typical volume
8949 * Returns the storage volume, or NULL on error
8952 virStorageVolCreateXMLFrom(virStoragePoolPtr pool
,
8953 const char *xmldesc
,
8954 virStorageVolPtr clonevol
,
8957 DEBUG("pool=%p, flags=%u, clonevol=%p", pool
, flags
, clonevol
);
8959 virResetLastError();
8961 if (!VIR_IS_STORAGE_POOL(pool
)) {
8962 virLibConnError(NULL
, VIR_ERR_INVALID_STORAGE_POOL
, __FUNCTION__
);
8963 virDispatchError(NULL
);
8967 if (!VIR_IS_STORAGE_VOL(clonevol
)) {
8968 virLibConnError(NULL
, VIR_ERR_INVALID_STORAGE_VOL
, __FUNCTION__
);
8972 if (pool
->conn
->flags
& VIR_CONNECT_RO
||
8973 clonevol
->conn
->flags
& VIR_CONNECT_RO
) {
8974 virLibConnError(pool
->conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
8978 if (pool
->conn
->storageDriver
&&
8979 pool
->conn
->storageDriver
->volCreateXMLFrom
) {
8980 virStorageVolPtr ret
;
8981 ret
= pool
->conn
->storageDriver
->volCreateXMLFrom (pool
, xmldesc
,
8988 virLibConnError (pool
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
8991 virDispatchError(pool
->conn
);
8997 * virStorageVolDelete:
8998 * @vol: pointer to storage volume
8999 * @flags: future flags, use 0 for now
9001 * Delete the storage volume from the pool
9003 * Returns 0 on success, or -1 on error
9006 virStorageVolDelete(virStorageVolPtr vol
,
9010 DEBUG("vol=%p, flags=%u", vol
, flags
);
9012 virResetLastError();
9014 if (!VIR_IS_CONNECTED_STORAGE_VOL(vol
)) {
9015 virLibStorageVolError(NULL
, VIR_ERR_INVALID_STORAGE_VOL
, __FUNCTION__
);
9016 virDispatchError(NULL
);
9021 if (conn
->flags
& VIR_CONNECT_RO
) {
9022 virLibStorageVolError(vol
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
9026 if (conn
->storageDriver
&& conn
->storageDriver
->volDelete
) {
9028 ret
= conn
->storageDriver
->volDelete (vol
, flags
);
9034 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9037 virDispatchError(vol
->conn
);
9043 * virStorageVolWipe:
9044 * @vol: pointer to storage volume
9045 * @flags: future flags, use 0 for now
9047 * Ensure data previously on a volume is not accessible to future reads
9049 * Returns 0 on success, or -1 on error
9052 virStorageVolWipe(virStorageVolPtr vol
,
9056 VIR_DEBUG("vol=%p, flags=%u", vol
, flags
);
9058 virResetLastError();
9060 if (!VIR_IS_CONNECTED_STORAGE_VOL(vol
)) {
9061 virLibStorageVolError(NULL
, VIR_ERR_INVALID_STORAGE_VOL
, __FUNCTION__
);
9062 virDispatchError(NULL
);
9067 if (conn
->flags
& VIR_CONNECT_RO
) {
9068 virLibStorageVolError(vol
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
9072 if (conn
->storageDriver
&& conn
->storageDriver
->volWipe
) {
9074 ret
= conn
->storageDriver
->volWipe(vol
, flags
);
9081 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9084 virDispatchError(vol
->conn
);
9090 * virStorageVolFree:
9091 * @vol: pointer to storage volume
9093 * Release the storage volume handle. The underlying
9094 * storage volume continues to exist.
9096 * Returns 0 on success, or -1 on error
9099 virStorageVolFree(virStorageVolPtr vol
)
9101 DEBUG("vol=%p", vol
);
9103 virResetLastError();
9105 if (!VIR_IS_STORAGE_VOL(vol
)) {
9106 virLibStorageVolError(NULL
, VIR_ERR_INVALID_STORAGE_VOL
, __FUNCTION__
);
9107 virDispatchError(NULL
);
9110 if (virUnrefStorageVol(vol
) < 0) {
9111 virDispatchError(NULL
);
9120 * @vol: the vol to hold a reference on
9122 * Increment the reference count on the vol. For each
9123 * additional call to this method, there shall be a corresponding
9124 * call to virStorageVolFree to release the reference count, once
9125 * the caller no longer needs the reference to this object.
9127 * This method is typically useful for applications where multiple
9128 * threads are using a connection, and it is required that the
9129 * connection remain open until all threads have finished using
9130 * it. ie, each new thread using a vol would increment
9131 * the reference count.
9133 * Returns 0 in case of success, -1 in case of failure.
9136 virStorageVolRef(virStorageVolPtr vol
)
9138 if ((!VIR_IS_CONNECTED_STORAGE_VOL(vol
))) {
9139 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
9140 virDispatchError(NULL
);
9143 virMutexLock(&vol
->conn
->lock
);
9144 DEBUG("vol=%p refs=%d", vol
, vol
->refs
);
9146 virMutexUnlock(&vol
->conn
->lock
);
9151 * virStorageVolGetInfo:
9152 * @vol: pointer to storage volume
9153 * @info: pointer at which to store info
9155 * Fetches volatile information about the storage
9156 * volume such as its current allocation
9158 * Returns 0 on success, or -1 on failure
9161 virStorageVolGetInfo(virStorageVolPtr vol
,
9162 virStorageVolInfoPtr info
)
9165 DEBUG("vol=%p, info=%p", vol
, info
);
9167 virResetLastError();
9169 if (!VIR_IS_CONNECTED_STORAGE_VOL(vol
)) {
9170 virLibStorageVolError(NULL
, VIR_ERR_INVALID_STORAGE_VOL
, __FUNCTION__
);
9171 virDispatchError(NULL
);
9175 virLibStorageVolError(vol
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
9179 memset(info
, 0, sizeof(virStorageVolInfo
));
9183 if (conn
->storageDriver
->volGetInfo
){
9185 ret
= conn
->storageDriver
->volGetInfo (vol
, info
);
9191 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9194 virDispatchError(vol
->conn
);
9200 * virStorageVolGetXMLDesc:
9201 * @vol: pointer to storage volume
9202 * @flags: flags for XML generation (unused, pass 0)
9204 * Fetch an XML document describing all aspects of
9205 * the storage volume
9207 * Returns the XML document, or NULL on error
9210 virStorageVolGetXMLDesc(virStorageVolPtr vol
,
9214 DEBUG("vol=%p, flags=%u", vol
, flags
);
9216 virResetLastError();
9218 if (!VIR_IS_STORAGE_VOL(vol
)) {
9219 virLibStorageVolError(NULL
, VIR_ERR_INVALID_STORAGE_VOL
, __FUNCTION__
);
9220 virDispatchError(NULL
);
9224 virLibStorageVolError(vol
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
9230 if (conn
->storageDriver
&& conn
->storageDriver
->volGetXMLDesc
) {
9232 ret
= conn
->storageDriver
->volGetXMLDesc (vol
, flags
);
9238 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9241 virDispatchError(vol
->conn
);
9247 * virStorageVolGetPath:
9248 * @vol: pointer to storage volume
9250 * Fetch the storage volume path. Depending on the pool
9251 * configuration this is either persistent across hosts,
9252 * or dynamically assigned at pool startup. Consult
9253 * pool documentation for information on getting the
9256 * Returns the storage volume path, or NULL on error
9259 virStorageVolGetPath(virStorageVolPtr vol
)
9262 DEBUG("vol=%p", vol
);
9264 virResetLastError();
9266 if (!VIR_IS_STORAGE_VOL(vol
)) {
9267 virLibStorageVolError(NULL
, VIR_ERR_INVALID_STORAGE_VOL
, __FUNCTION__
);
9268 virDispatchError(NULL
);
9274 if (conn
->storageDriver
&& conn
->storageDriver
->volGetPath
) {
9276 ret
= conn
->storageDriver
->volGetPath (vol
);
9282 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9285 virDispatchError(vol
->conn
);
9291 * virNodeNumOfDevices:
9292 * @conn: pointer to the hypervisor connection
9293 * @cap: capability name
9294 * @flags: flags (unused, pass 0)
9296 * Provides the number of node devices.
9298 * If the optional 'cap' argument is non-NULL, then the count
9299 * will be restricted to devices with the specified capability
9301 * Returns the number of node devices or -1 in case of error
9304 virNodeNumOfDevices(virConnectPtr conn
, const char *cap
, unsigned int flags
)
9306 DEBUG("conn=%p, cap=%s, flags=%d", conn
, NULLSTR(cap
), flags
);
9308 virResetLastError();
9310 if (!VIR_IS_CONNECT(conn
)) {
9311 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
9312 virDispatchError(NULL
);
9316 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
9320 if (conn
->deviceMonitor
&& conn
->deviceMonitor
->numOfDevices
) {
9322 ret
= conn
->deviceMonitor
->numOfDevices (conn
, cap
, flags
);
9328 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9331 virDispatchError(conn
);
9337 * virNodeListDevices:
9338 * @conn: pointer to the hypervisor connection
9339 * @cap: capability name
9340 * @names: array to collect the list of node device names
9341 * @maxnames: size of @names
9342 * @flags: flags (unused, pass 0)
9344 * Collect the list of node devices, and store their names in @names
9346 * If the optional 'cap' argument is non-NULL, then the count
9347 * will be restricted to devices with the specified capability
9349 * Returns the number of node devices found or -1 in case of error
9352 virNodeListDevices(virConnectPtr conn
,
9354 char **const names
, int maxnames
,
9357 DEBUG("conn=%p, cap=%s, names=%p, maxnames=%d, flags=%d",
9358 conn
, cap
, names
, maxnames
, flags
);
9360 virResetLastError();
9362 if (!VIR_IS_CONNECT(conn
)) {
9363 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
9364 virDispatchError(NULL
);
9367 if ((flags
!= 0) || (names
== NULL
) || (maxnames
< 0)) {
9368 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
9372 if (conn
->deviceMonitor
&& conn
->deviceMonitor
->listDevices
) {
9374 ret
= conn
->deviceMonitor
->listDevices (conn
, cap
, names
, maxnames
, flags
);
9380 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9383 virDispatchError(conn
);
9389 * virNodeDeviceLookupByName:
9390 * @conn: pointer to the hypervisor connection
9391 * @name: unique device name
9393 * Lookup a node device by its name.
9395 * Returns a virNodeDevicePtr if found, NULL otherwise.
9397 virNodeDevicePtr
virNodeDeviceLookupByName(virConnectPtr conn
, const char *name
)
9399 DEBUG("conn=%p, name=%p", conn
, name
);
9401 virResetLastError();
9403 if (!VIR_IS_CONNECT(conn
)) {
9404 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
9405 virDispatchError(NULL
);
9410 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
9414 if (conn
->deviceMonitor
&& conn
->deviceMonitor
->deviceLookupByName
) {
9415 virNodeDevicePtr ret
;
9416 ret
= conn
->deviceMonitor
->deviceLookupByName (conn
, name
);
9422 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9425 virDispatchError(conn
);
9431 * virNodeDeviceGetXMLDesc:
9432 * @dev: pointer to the node device
9433 * @flags: flags for XML generation (unused, pass 0)
9435 * Fetch an XML document describing all aspects of
9438 * Returns the XML document, or NULL on error
9440 char *virNodeDeviceGetXMLDesc(virNodeDevicePtr dev
, unsigned int flags
)
9442 DEBUG("dev=%p, conn=%p", dev
, dev
? dev
->conn
: NULL
);
9444 virResetLastError();
9446 if (!VIR_IS_CONNECTED_NODE_DEVICE(dev
)) {
9447 virLibNodeDeviceError(NULL
, VIR_ERR_INVALID_NODE_DEVICE
, __FUNCTION__
);
9448 virDispatchError(NULL
);
9452 if (dev
->conn
->deviceMonitor
&& dev
->conn
->deviceMonitor
->deviceDumpXML
) {
9454 ret
= dev
->conn
->deviceMonitor
->deviceDumpXML (dev
, flags
);
9460 virLibConnError (dev
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9463 virDispatchError(dev
->conn
);
9469 * virNodeDeviceGetName:
9472 * Just return the device name
9474 * Returns the device name or NULL in case of error
9476 const char *virNodeDeviceGetName(virNodeDevicePtr dev
)
9478 DEBUG("dev=%p, conn=%p", dev
, dev
? dev
->conn
: NULL
);
9480 if (!VIR_IS_CONNECTED_NODE_DEVICE(dev
)) {
9481 virLibNodeDeviceError(NULL
, VIR_ERR_INVALID_NODE_DEVICE
, __FUNCTION__
);
9482 virDispatchError(NULL
);
9490 * virNodeDeviceGetParent:
9493 * Accessor for the parent of the device
9495 * Returns the name of the device's parent, or NULL if the
9496 * device has no parent.
9498 const char *virNodeDeviceGetParent(virNodeDevicePtr dev
)
9500 DEBUG("dev=%p, conn=%p", dev
, dev
? dev
->conn
: NULL
);
9502 virResetLastError();
9504 if (!VIR_IS_CONNECTED_NODE_DEVICE(dev
)) {
9505 virLibNodeDeviceError(NULL
, VIR_ERR_INVALID_NODE_DEVICE
, __FUNCTION__
);
9506 virDispatchError(NULL
);
9511 if (dev
->conn
->deviceMonitor
&& dev
->conn
->deviceMonitor
->deviceGetParent
) {
9512 dev
->parent
= dev
->conn
->deviceMonitor
->deviceGetParent (dev
);
9514 virLibConnError (dev
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9515 virDispatchError(dev
->conn
);
9523 * virNodeDeviceNumOfCaps:
9526 * Accessor for the number of capabilities supported by the device.
9528 * Returns the number of capabilities supported by the device.
9530 int virNodeDeviceNumOfCaps(virNodeDevicePtr dev
)
9532 DEBUG("dev=%p, conn=%p", dev
, dev
? dev
->conn
: NULL
);
9534 virResetLastError();
9536 if (!VIR_IS_CONNECTED_NODE_DEVICE(dev
)) {
9537 virLibNodeDeviceError(NULL
, VIR_ERR_INVALID_NODE_DEVICE
, __FUNCTION__
);
9538 virDispatchError(NULL
);
9542 if (dev
->conn
->deviceMonitor
&& dev
->conn
->deviceMonitor
->deviceNumOfCaps
) {
9544 ret
= dev
->conn
->deviceMonitor
->deviceNumOfCaps (dev
);
9550 virLibConnError (dev
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9553 virDispatchError(dev
->conn
);
9558 * virNodeDeviceListCaps:
9560 * @names: array to collect the list of capability names
9561 * @maxnames: size of @names
9563 * Lists the names of the capabilities supported by the device.
9565 * Returns the number of capability names listed in @names.
9567 int virNodeDeviceListCaps(virNodeDevicePtr dev
,
9571 DEBUG("dev=%p, conn=%p, names=%p, maxnames=%d",
9572 dev
, dev
? dev
->conn
: NULL
, names
, maxnames
);
9574 virResetLastError();
9576 if (!VIR_IS_CONNECTED_NODE_DEVICE(dev
)) {
9577 virLibNodeDeviceError(NULL
, VIR_ERR_INVALID_NODE_DEVICE
, __FUNCTION__
);
9578 virDispatchError(NULL
);
9582 if (dev
->conn
->deviceMonitor
&& dev
->conn
->deviceMonitor
->deviceListCaps
) {
9584 ret
= dev
->conn
->deviceMonitor
->deviceListCaps (dev
, names
, maxnames
);
9590 virLibConnError (dev
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9593 virDispatchError(dev
->conn
);
9599 * virNodeDeviceFree:
9600 * @dev: pointer to the node device
9602 * Drops a reference to the node device, freeing it if
9603 * this was the last reference.
9605 * Returns the 0 for success, -1 for error.
9607 int virNodeDeviceFree(virNodeDevicePtr dev
)
9609 DEBUG("dev=%p, conn=%p", dev
, dev
? dev
->conn
: NULL
);
9611 virResetLastError();
9613 if (!VIR_IS_CONNECTED_NODE_DEVICE(dev
)) {
9614 virLibNodeDeviceError(NULL
, VIR_ERR_INVALID_NODE_DEVICE
, __FUNCTION__
);
9615 virDispatchError(NULL
);
9618 if (virUnrefNodeDevice(dev
) < 0) {
9619 virDispatchError(NULL
);
9628 * @dev: the dev to hold a reference on
9630 * Increment the reference count on the dev. For each
9631 * additional call to this method, there shall be a corresponding
9632 * call to virNodeDeviceFree to release the reference count, once
9633 * the caller no longer needs the reference to this object.
9635 * This method is typically useful for applications where multiple
9636 * threads are using a connection, and it is required that the
9637 * connection remain open until all threads have finished using
9638 * it. ie, each new thread using a dev would increment
9639 * the reference count.
9641 * Returns 0 in case of success, -1 in case of failure.
9644 virNodeDeviceRef(virNodeDevicePtr dev
)
9646 if ((!VIR_IS_CONNECTED_NODE_DEVICE(dev
))) {
9647 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
9648 virDispatchError(NULL
);
9651 virMutexLock(&dev
->conn
->lock
);
9652 DEBUG("dev=%p refs=%d", dev
, dev
->refs
);
9654 virMutexUnlock(&dev
->conn
->lock
);
9659 * virNodeDeviceDettach:
9660 * @dev: pointer to the node device
9662 * Dettach the node device from the node itself so that it may be
9663 * assigned to a guest domain.
9665 * Depending on the hypervisor, this may involve operations such
9666 * as unbinding any device drivers from the device, binding the
9667 * device to a dummy device driver and resetting the device.
9669 * If the device is currently in use by the node, this method may
9672 * Once the device is not assigned to any guest, it may be re-attached
9673 * to the node using the virNodeDeviceReattach() method.
9675 * Returns 0 in case of success, -1 in case of failure.
9678 virNodeDeviceDettach(virNodeDevicePtr dev
)
9680 DEBUG("dev=%p, conn=%p", dev
, dev
? dev
->conn
: NULL
);
9682 virResetLastError();
9684 if (!VIR_IS_CONNECTED_NODE_DEVICE(dev
)) {
9685 virLibNodeDeviceError(NULL
, VIR_ERR_INVALID_NODE_DEVICE
, __FUNCTION__
);
9686 virDispatchError(NULL
);
9690 if (dev
->conn
->driver
->nodeDeviceDettach
) {
9692 ret
= dev
->conn
->driver
->nodeDeviceDettach (dev
);
9698 virLibConnError(dev
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9701 virDispatchError(dev
->conn
);
9706 * virNodeDeviceReAttach:
9707 * @dev: pointer to the node device
9709 * Re-attach a previously dettached node device to the node so that it
9710 * may be used by the node again.
9712 * Depending on the hypervisor, this may involve operations such
9713 * as resetting the device, unbinding it from a dummy device driver
9714 * and binding it to its appropriate driver.
9716 * If the device is currently in use by a guest, this method may fail.
9718 * Returns 0 in case of success, -1 in case of failure.
9721 virNodeDeviceReAttach(virNodeDevicePtr dev
)
9723 DEBUG("dev=%p, conn=%p", dev
, dev
? dev
->conn
: NULL
);
9725 virResetLastError();
9727 if (!VIR_IS_CONNECTED_NODE_DEVICE(dev
)) {
9728 virLibNodeDeviceError(NULL
, VIR_ERR_INVALID_NODE_DEVICE
, __FUNCTION__
);
9729 virDispatchError(NULL
);
9733 if (dev
->conn
->driver
->nodeDeviceReAttach
) {
9735 ret
= dev
->conn
->driver
->nodeDeviceReAttach (dev
);
9741 virLibConnError(dev
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9744 virDispatchError(dev
->conn
);
9749 * virNodeDeviceReset:
9750 * @dev: pointer to the node device
9752 * Reset a previously dettached node device to the node before or
9753 * after assigning it to a guest.
9755 * The exact reset semantics depends on the hypervisor and device
9756 * type but, for example, KVM will attempt to reset PCI devices with
9757 * a Function Level Reset, Secondary Bus Reset or a Power Management
9760 * If the reset will affect other devices which are currently in use,
9761 * this function may fail.
9763 * Returns 0 in case of success, -1 in case of failure.
9766 virNodeDeviceReset(virNodeDevicePtr dev
)
9768 DEBUG("dev=%p, conn=%p", dev
, dev
? dev
->conn
: NULL
);
9770 virResetLastError();
9772 if (!VIR_IS_CONNECTED_NODE_DEVICE(dev
)) {
9773 virLibNodeDeviceError(NULL
, VIR_ERR_INVALID_NODE_DEVICE
, __FUNCTION__
);
9774 virDispatchError(NULL
);
9778 if (dev
->conn
->driver
->nodeDeviceReset
) {
9780 ret
= dev
->conn
->driver
->nodeDeviceReset (dev
);
9786 virLibConnError(dev
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9789 virDispatchError(dev
->conn
);
9795 * virNodeDeviceCreateXML:
9796 * @conn: pointer to the hypervisor connection
9797 * @xmlDesc: string containing an XML description of the device to be created
9798 * @flags: callers should always pass 0
9800 * Create a new device on the VM host machine, for example, virtual
9801 * HBAs created using vport_create.
9803 * Returns a node device object if successful, NULL in case of failure
9806 virNodeDeviceCreateXML(virConnectPtr conn
,
9807 const char *xmlDesc
,
9810 VIR_DEBUG("conn=%p, xmlDesc=%s, flags=%d", conn
, xmlDesc
, flags
);
9812 virResetLastError();
9814 if (!VIR_IS_CONNECT(conn
)) {
9815 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
9816 virDispatchError(NULL
);
9820 if (conn
->flags
& VIR_CONNECT_RO
) {
9821 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
9825 if (xmlDesc
== NULL
) {
9826 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
9830 if (conn
->deviceMonitor
&&
9831 conn
->deviceMonitor
->deviceCreateXML
) {
9832 virNodeDevicePtr dev
= conn
->deviceMonitor
->deviceCreateXML(conn
, xmlDesc
, flags
);
9838 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9841 virDispatchError(conn
);
9847 * virNodeDeviceDestroy:
9848 * @dev: a device object
9850 * Destroy the device object. The virtual device is removed from the host operating system.
9851 * This function may require privileged access
9853 * Returns 0 in case of success and -1 in case of failure.
9856 virNodeDeviceDestroy(virNodeDevicePtr dev
)
9858 DEBUG("dev=%p", dev
);
9860 virResetLastError();
9862 if (!VIR_IS_CONNECTED_NODE_DEVICE(dev
)) {
9863 virLibNodeDeviceError(NULL
, VIR_ERR_INVALID_NODE_DEVICE
, __FUNCTION__
);
9864 virDispatchError(NULL
);
9868 if (dev
->conn
->flags
& VIR_CONNECT_RO
) {
9869 virLibConnError(dev
->conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
9873 if (dev
->conn
->deviceMonitor
&&
9874 dev
->conn
->deviceMonitor
->deviceDestroy
) {
9875 int retval
= dev
->conn
->deviceMonitor
->deviceDestroy(dev
);
9883 virLibConnError (dev
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9886 virDispatchError(dev
->conn
);
9892 * Domain Event Notification
9896 * virConnectDomainEventRegister:
9897 * @conn: pointer to the connection
9898 * @cb: callback to the function handling domain events
9899 * @opaque: opaque data to pass on to the callback
9900 * @freecb: optional function to deallocate opaque when not used anymore
9902 * Adds a callback to receive notifications of domain lifecycle events
9903 * occurring on a connection
9905 * Use of this method is no longer recommended. Instead applications
9906 * should try virConnectDomainEventRegisterAny which has a more flexible
9909 * The virDomainPtr object handle passed into the callback upon delivery
9910 * of an event is only valid for the duration of execution of the callback.
9911 * If the callback wishes to keep the domain object after the callback
9912 * returns, it shall take a reference to it, by calling virDomainRef.
9913 * The reference can be released once the object is no longer required
9914 * by calling virDomainFree.
9916 * Returns 0 on success, -1 on failure
9919 virConnectDomainEventRegister(virConnectPtr conn
,
9920 virConnectDomainEventCallback cb
,
9922 virFreeCallback freecb
)
9924 DEBUG("conn=%p, cb=%p, opaque=%p, freecb=%p", conn
, cb
, opaque
, freecb
);
9925 virResetLastError();
9927 if (!VIR_IS_CONNECT(conn
)) {
9928 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
9929 virDispatchError(NULL
);
9933 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
9937 if ((conn
->driver
) && (conn
->driver
->domainEventRegister
)) {
9939 ret
= conn
->driver
->domainEventRegister (conn
, cb
, opaque
, freecb
);
9945 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9947 virDispatchError(conn
);
9952 * virConnectDomainEventDeregister:
9953 * @conn: pointer to the connection
9954 * @cb: callback to the function handling domain events
9956 * Removes a callback previously registered with the virConnectDomainEventRegister
9959 * Use of this method is no longer recommended. Instead applications
9960 * should try virConnectDomainEventUnregisterAny which has a more flexible
9963 * Returns 0 on success, -1 on failure
9966 virConnectDomainEventDeregister(virConnectPtr conn
,
9967 virConnectDomainEventCallback cb
)
9969 DEBUG("conn=%p, cb=%p", conn
, cb
);
9971 virResetLastError();
9973 if (!VIR_IS_CONNECT(conn
)) {
9974 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
9975 virDispatchError(NULL
);
9979 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
9982 if ((conn
->driver
) && (conn
->driver
->domainEventDeregister
)) {
9984 ret
= conn
->driver
->domainEventDeregister (conn
, cb
);
9990 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
9992 virDispatchError(conn
);
9997 * virSecretGetConnect:
9998 * @secret: A virSecret secret
10000 * Provides the connection pointer associated with a secret. The reference
10001 * counter on the connection is not increased by this call.
10003 * WARNING: When writing libvirt bindings in other languages, do not use this
10004 * function. Instead, store the connection and the secret object together.
10006 * Returns the virConnectPtr or NULL in case of failure.
10009 virSecretGetConnect (virSecretPtr secret
)
10011 DEBUG("secret=%p", secret
);
10013 virResetLastError();
10015 if (!VIR_IS_CONNECTED_SECRET (secret
)) {
10016 virLibSecretError (NULL
, VIR_ERR_INVALID_SECRET
, __FUNCTION__
);
10017 virDispatchError(NULL
);
10020 return secret
->conn
;
10024 * virConnectNumOfSecrets:
10025 * @conn: virConnect connection
10027 * Fetch number of currently defined secrets.
10029 * Returns the number currently defined secrets.
10032 virConnectNumOfSecrets(virConnectPtr conn
)
10034 VIR_DEBUG("conn=%p", conn
);
10036 virResetLastError();
10038 if (!VIR_IS_CONNECT(conn
)) {
10039 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
10040 virDispatchError(NULL
);
10044 if (conn
->secretDriver
!= NULL
&&
10045 conn
->secretDriver
->numOfSecrets
!= NULL
) {
10048 ret
= conn
->secretDriver
->numOfSecrets(conn
);
10054 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
10057 virDispatchError(conn
);
10062 * virConnectListSecrets:
10063 * @conn: virConnect connection
10064 * @uuids: Pointer to an array to store the UUIDs
10065 * @maxuuids: size of the array.
10067 * List UUIDs of defined secrets, store pointers to names in uuids.
10069 * Returns the number of UUIDs provided in the array, or -1 on failure.
10072 virConnectListSecrets(virConnectPtr conn
, char **uuids
, int maxuuids
)
10074 VIR_DEBUG("conn=%p, uuids=%p, maxuuids=%d", conn
, uuids
, maxuuids
);
10076 virResetLastError();
10078 if (!VIR_IS_CONNECT(conn
)) {
10079 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
10080 virDispatchError(NULL
);
10083 if (uuids
== NULL
|| maxuuids
< 0) {
10084 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
10088 if (conn
->secretDriver
!= NULL
&& conn
->secretDriver
->listSecrets
!= NULL
) {
10091 ret
= conn
->secretDriver
->listSecrets(conn
, uuids
, maxuuids
);
10097 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
10100 virDispatchError(conn
);
10105 * virSecretLookupByUUID:
10106 * @conn: pointer to the hypervisor connection
10107 * @uuid: the raw UUID for the secret
10109 * Try to lookup a secret on the given hypervisor based on its UUID.
10110 * Uses the 16 bytes of raw data to describe the UUID
10112 * Returns a new secret object or NULL in case of failure. If the
10113 * secret cannot be found, then VIR_ERR_NO_SECRET error is raised.
10116 virSecretLookupByUUID(virConnectPtr conn
, const unsigned char *uuid
)
10118 DEBUG("conn=%p, uuid=%s", conn
, uuid
);
10120 virResetLastError();
10122 if (!VIR_IS_CONNECT(conn
)) {
10123 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
10124 virDispatchError(NULL
);
10127 if (uuid
== NULL
) {
10128 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
10132 if (conn
->secretDriver
&&
10133 conn
->secretDriver
->lookupByUUID
) {
10135 ret
= conn
->secretDriver
->lookupByUUID (conn
, uuid
);
10141 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
10144 virDispatchError(conn
);
10149 * virSecretLookupByUUIDString:
10150 * @conn: pointer to the hypervisor connection
10151 * @uuidstr: the string UUID for the secret
10153 * Try to lookup a secret on the given hypervisor based on its UUID.
10154 * Uses the printable string value to describe the UUID
10156 * Returns a new secret object or NULL in case of failure. If the
10157 * secret cannot be found, then VIR_ERR_NO_SECRET error is raised.
10160 virSecretLookupByUUIDString(virConnectPtr conn
, const char *uuidstr
)
10162 unsigned char uuid
[VIR_UUID_BUFLEN
];
10163 DEBUG("conn=%p, uuidstr=%s", conn
, uuidstr
);
10165 virResetLastError();
10167 if (!VIR_IS_CONNECT(conn
)) {
10168 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
10169 virDispatchError(NULL
);
10172 if (uuidstr
== NULL
) {
10173 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
10177 if (virUUIDParse(uuidstr
, uuid
) < 0) {
10178 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
10182 return virSecretLookupByUUID(conn
, &uuid
[0]);
10185 virDispatchError(conn
);
10191 * virSecretLookupByUsage:
10192 * @conn: pointer to the hypervisor connection
10193 * @usageType: the type of secret usage
10194 * @usageID: identifier of the object using the secret
10196 * Try to lookup a secret on the given hypervisor based on its usage
10197 * The usageID is unique within the set of secrets sharing the
10198 * same usageType value.
10200 * Returns a new secret object or NULL in case of failure. If the
10201 * secret cannot be found, then VIR_ERR_NO_SECRET error is raised.
10204 virSecretLookupByUsage(virConnectPtr conn
,
10206 const char *usageID
)
10208 DEBUG("conn=%p, usageType=%d usageID=%s", conn
, usageType
, NULLSTR(usageID
));
10210 virResetLastError();
10212 if (!VIR_IS_CONNECT(conn
)) {
10213 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
10214 virDispatchError(NULL
);
10217 if (usageID
== NULL
) {
10218 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
10222 if (conn
->secretDriver
&&
10223 conn
->secretDriver
->lookupByUsage
) {
10225 ret
= conn
->secretDriver
->lookupByUsage (conn
, usageType
, usageID
);
10231 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
10234 virDispatchError(conn
);
10240 * virSecretDefineXML:
10241 * @conn: virConnect connection
10242 * @xml: XML describing the secret.
10243 * @flags: flags, use 0 for now
10245 * If XML specifies a UUID, locates the specified secret and replaces all
10246 * attributes of the secret specified by UUID by attributes specified in xml
10247 * (any attributes not specified in xml are discarded).
10249 * Otherwise, creates a new secret with an automatically chosen UUID, and
10250 * initializes its attributes from xml.
10252 * Returns a the secret on success, NULL on failure.
10255 virSecretDefineXML(virConnectPtr conn
, const char *xml
, unsigned int flags
)
10257 VIR_DEBUG("conn=%p, xml=%s, flags=%u", conn
, xml
, flags
);
10259 virResetLastError();
10261 if (!VIR_IS_CONNECT(conn
)) {
10262 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
10263 virDispatchError(NULL
);
10266 if (conn
->flags
& VIR_CONNECT_RO
) {
10267 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
10271 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
10275 if (conn
->secretDriver
!= NULL
&& conn
->secretDriver
->defineXML
!= NULL
) {
10278 ret
= conn
->secretDriver
->defineXML(conn
, xml
, flags
);
10284 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
10287 virDispatchError(conn
);
10292 * virSecretGetUUID:
10293 * @secret: A virSecret secret
10294 * @uuid: buffer of VIR_UUID_BUFLEN bytes in size
10296 * Fetches the UUID of the secret.
10298 * Returns 0 on success with the uuid buffer being filled, or
10302 virSecretGetUUID(virSecretPtr secret
, unsigned char *uuid
)
10304 VIR_DEBUG("secret=%p", secret
);
10306 virResetLastError();
10308 if (!VIR_IS_CONNECTED_SECRET(secret
)) {
10309 virLibSecretError(NULL
, VIR_ERR_INVALID_SECRET
, __FUNCTION__
);
10310 virDispatchError(NULL
);
10313 if (uuid
== NULL
) {
10314 virLibSecretError(secret
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
10315 virDispatchError(secret
->conn
);
10319 memcpy(uuid
, &secret
->uuid
[0], VIR_UUID_BUFLEN
);
10325 * virSecretGetUUIDString:
10326 * @secret: a secret object
10327 * @buf: pointer to a VIR_UUID_STRING_BUFLEN bytes array
10329 * Get the UUID for a secret as string. For more information about
10330 * UUID see RFC4122.
10332 * Returns -1 in case of error, 0 in case of success
10335 virSecretGetUUIDString(virSecretPtr secret
, char *buf
)
10337 unsigned char uuid
[VIR_UUID_BUFLEN
];
10338 DEBUG("secret=%p, buf=%p", secret
, buf
);
10340 virResetLastError();
10342 if (!VIR_IS_SECRET(secret
)) {
10343 virLibSecretError(NULL
, VIR_ERR_INVALID_SECRET
, __FUNCTION__
);
10344 virDispatchError(NULL
);
10348 virLibSecretError(secret
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
10352 if (virSecretGetUUID(secret
, &uuid
[0]))
10355 virUUIDFormat(uuid
, buf
);
10359 virDispatchError(secret
->conn
);
10364 * virSecretGetUsageType:
10365 * @secret: a secret object
10367 * Get the type of object which uses this secret. The returned
10368 * value is one of the constants defined in the virSecretUsageType
10369 * enumeration. More values may be added to this enumeration in
10370 * the future, so callers should expect to see usage types they
10371 * do not explicitly know about.
10373 * Returns a positive integer identifying the type of object,
10374 * or -1 upon error.
10377 virSecretGetUsageType(virSecretPtr secret
)
10379 DEBUG("secret=%p", secret
);
10381 virResetLastError();
10383 if (!VIR_IS_SECRET(secret
)) {
10384 virLibSecretError(NULL
, VIR_ERR_INVALID_SECRET
, __FUNCTION__
);
10385 virDispatchError(NULL
);
10388 return (secret
->usageType
);
10392 * virSecretGetUsageID:
10393 * @secret: a secret object
10395 * Get the unique identifier of the object with which this
10396 * secret is to be used. The format of the identifier is
10397 * dependant on the usage type of the secret. For a secret
10398 * with a usage type of VIR_SECRET_USAGE_TYPE_VOLUME the
10399 * identifier will be a fully qualfied path name. The
10400 * identifiers are intended to be unique within the set of
10401 * all secrets sharing the same usage type. ie, there shall
10402 * only ever be one secret for each volume path.
10404 * Returns a string identifying the object using the secret,
10405 * or NULL upon error
10408 virSecretGetUsageID(virSecretPtr secret
)
10410 DEBUG("secret=%p", secret
);
10412 virResetLastError();
10414 if (!VIR_IS_SECRET(secret
)) {
10415 virLibSecretError(NULL
, VIR_ERR_INVALID_SECRET
, __FUNCTION__
);
10416 virDispatchError(NULL
);
10419 return (secret
->usageID
);
10424 * virSecretGetXMLDesc:
10425 * @secret: A virSecret secret
10426 * @flags: flags, use 0 for now
10428 * Fetches an XML document describing attributes of the secret.
10430 * Returns the XML document on success, NULL on failure. The caller must
10434 virSecretGetXMLDesc(virSecretPtr secret
, unsigned int flags
)
10436 virConnectPtr conn
;
10438 VIR_DEBUG("secret=%p, flags=%u", secret
, flags
);
10440 virResetLastError();
10442 if (!VIR_IS_CONNECTED_SECRET(secret
)) {
10443 virLibSecretError(NULL
, VIR_ERR_INVALID_SECRET
, __FUNCTION__
);
10444 virDispatchError(NULL
);
10448 conn
= secret
->conn
;
10449 if (conn
->secretDriver
!= NULL
&& conn
->secretDriver
->getXMLDesc
!= NULL
) {
10452 ret
= conn
->secretDriver
->getXMLDesc(secret
, flags
);
10458 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
10461 virDispatchError(conn
);
10466 * virSecretSetValue:
10467 * @secret: A virSecret secret
10468 * @value: Value of the secret
10469 * @value_size: Size of the value
10470 * @flags: flags, use 0 for now
10472 * Sets the value of a secret.
10474 * Returns 0 on success, -1 on failure.
10477 virSecretSetValue(virSecretPtr secret
, const unsigned char *value
,
10478 size_t value_size
, unsigned int flags
)
10480 virConnectPtr conn
;
10482 VIR_DEBUG("secret=%p, value=%p, value_size=%zu, flags=%u", secret
, value
,
10483 value_size
, flags
);
10485 virResetLastError();
10487 if (!VIR_IS_CONNECTED_SECRET(secret
)) {
10488 virLibSecretError(NULL
, VIR_ERR_INVALID_SECRET
, __FUNCTION__
);
10489 virDispatchError(NULL
);
10492 conn
= secret
->conn
;
10493 if (conn
->flags
& VIR_CONNECT_RO
) {
10494 virLibSecretError(secret
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
10497 if (value
== NULL
) {
10498 virLibSecretError(secret
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
10502 if (conn
->secretDriver
!= NULL
&& conn
->secretDriver
->setValue
!= NULL
) {
10505 ret
= conn
->secretDriver
->setValue(secret
, value
, value_size
, flags
);
10511 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
10514 virDispatchError(conn
);
10519 * virSecretGetValue:
10520 * @secret: A virSecret connection
10521 * @value_size: Place for storing size of the secret value
10522 * @flags: flags, use 0 for now
10524 * Fetches the value of a secret.
10526 * Returns the secret value on success, NULL on failure. The caller must
10527 * free() the secret value.
10530 virSecretGetValue(virSecretPtr secret
, size_t *value_size
, unsigned int flags
)
10532 virConnectPtr conn
;
10534 VIR_DEBUG("secret=%p, value_size=%p, flags=%u", secret
, value_size
, flags
);
10536 virResetLastError();
10538 if (!VIR_IS_CONNECTED_SECRET(secret
)) {
10539 virLibSecretError(NULL
, VIR_ERR_INVALID_SECRET
, __FUNCTION__
);
10540 virDispatchError(NULL
);
10543 conn
= secret
->conn
;
10544 if (conn
->flags
& VIR_CONNECT_RO
) {
10545 virLibSecretError(secret
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
10548 if (value_size
== NULL
) {
10549 virLibSecretError(secret
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
10553 flags
&= VIR_SECRET_GET_VALUE_FLAGS_MASK
;
10555 if (conn
->secretDriver
!= NULL
&& conn
->secretDriver
->getValue
!= NULL
) {
10556 unsigned char *ret
;
10558 ret
= conn
->secretDriver
->getValue(secret
, value_size
, flags
);
10564 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
10567 virDispatchError(conn
);
10572 * virSecretUndefine:
10573 * @secret: A virSecret secret
10575 * Deletes the specified secret. This does not free the associated
10576 * virSecretPtr object.
10578 * Returns 0 on success, -1 on failure.
10581 virSecretUndefine(virSecretPtr secret
)
10583 virConnectPtr conn
;
10585 VIR_DEBUG("secret=%p", secret
);
10587 virResetLastError();
10589 if (!VIR_IS_CONNECTED_SECRET(secret
)) {
10590 virLibSecretError(NULL
, VIR_ERR_INVALID_SECRET
, __FUNCTION__
);
10591 virDispatchError(NULL
);
10594 conn
= secret
->conn
;
10595 if (conn
->flags
& VIR_CONNECT_RO
) {
10596 virLibSecretError(secret
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
10600 if (conn
->secretDriver
!= NULL
&& conn
->secretDriver
->undefine
!= NULL
) {
10603 ret
= conn
->secretDriver
->undefine(secret
);
10609 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
10612 virDispatchError(conn
);
10618 * @secret: the secret to hold a reference on
10620 * Increment the reference count on the secret. For each additional call to
10621 * this method, there shall be a corresponding call to virSecretFree to release
10622 * the reference count, once the caller no longer needs the reference to this
10625 * This method is typically useful for applications where multiple threads are
10626 * using a connection, and it is required that the connection remain open until
10627 * all threads have finished using it. ie, each new thread using a secret would
10628 * increment the reference count.
10630 * Returns 0 in case of success, -1 in case of failure.
10633 virSecretRef(virSecretPtr secret
)
10635 if (!VIR_IS_CONNECTED_SECRET(secret
)) {
10636 virLibSecretError(NULL
, VIR_ERR_INVALID_SECRET
, __FUNCTION__
);
10637 virDispatchError(NULL
);
10640 virMutexLock(&secret
->conn
->lock
);
10641 DEBUG("secret=%p refs=%d", secret
, secret
->refs
);
10643 virMutexUnlock(&secret
->conn
->lock
);
10649 * @secret: pointer to a secret
10651 * Release the secret handle. The underlying secret continues to exist.
10653 * Returns 0 on success, or -1 on error
10656 virSecretFree(virSecretPtr secret
)
10658 DEBUG("secret=%p", secret
);
10660 virResetLastError();
10662 if (!VIR_IS_CONNECTED_SECRET(secret
)) {
10663 virLibSecretError(NULL
, VIR_ERR_INVALID_SECRET
, __FUNCTION__
);
10664 virDispatchError(NULL
);
10667 if (virUnrefSecret(secret
) < 0) {
10668 virDispatchError(NULL
);
10677 * @conn: pointer to the connection
10678 * @flags: control features of the stream
10680 * Creates a new stream object which can be used to perform
10681 * streamed I/O with other public API function.
10683 * When no longer needed, a stream object must be released
10684 * with virStreamFree. If a data stream has been used,
10685 * then the application must call virStreamFinish or
10686 * virStreamAbort before free'ing to, in order to notify
10687 * the driver of termination.
10689 * If a non-blocking data stream is required passed
10690 * VIR_STREAM_NONBLOCK for flags, otherwise pass 0.
10692 * Returns the new stream, or NULL upon error
10695 virStreamNew(virConnectPtr conn
,
10696 unsigned int flags
)
10700 DEBUG("conn=%p, flags=%u", conn
, flags
);
10702 virResetLastError();
10704 if (!VIR_IS_CONNECT(conn
)) {
10705 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
10706 virDispatchError(NULL
);
10710 st
= virGetStream(conn
);
10720 * @stream: pointer to the stream
10722 * Increment the reference count on the stream. For each
10723 * additional call to this method, there shall be a corresponding
10724 * call to virStreamFree to release the reference count, once
10725 * the caller no longer needs the reference to this object.
10727 * Returns 0 in case of success, -1 in case of failure
10730 virStreamRef(virStreamPtr stream
)
10732 if ((!VIR_IS_CONNECTED_STREAM(stream
))) {
10733 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
10734 virDispatchError(NULL
);
10737 virMutexLock(&stream
->conn
->lock
);
10738 DEBUG("stream=%p refs=%d", stream
, stream
->refs
);
10740 virMutexUnlock(&stream
->conn
->lock
);
10747 * @stream: pointer to the stream object
10748 * @data: buffer to write to stream
10749 * @nbytes: size of @data buffer
10751 * Write a series of bytes to the stream. This method may
10752 * block the calling application for an arbitrary amount
10753 * of time. Once an application has finished sending data
10754 * it should call virStreamFinish to wait for successful
10755 * confirmation from the driver, or detect any error
10757 * This method may not be used if a stream source has been
10760 * Errors are not guaranteed to be reported synchronously
10761 * with the call, but may instead be delayed until a
10764 * An example using this with a hypothetical file upload
10767 * virStreamPtr st = virStreamNew(conn, 0);
10768 * int fd = open("demo.iso", O_RDONLY)
10770 * virConnectUploadFile(conn, "demo.iso", st);
10774 * int got = read(fd, buf, 1024);
10776 * virStreamAbort(st);
10780 * virStreamFinish(st);
10784 * while (offset < got) {
10785 * int sent = virStreamSend(st, buf+offset, got-offset)
10787 * virStreamAbort(st);
10793 * if (virStreamFinish(st) < 0)
10794 * ... report an error ....
10796 * virStreamFree(st);
10799 * Returns the number of bytes written, which may be less
10802 * Returns -1 upon error, at which time the stream will
10803 * be marked as aborted, and the caller should now release
10804 * the stream with virStreamFree.
10806 * Returns -2 if the outgoing transmit buffers are full &
10807 * the stream is marked as non-blocking.
10809 int virStreamSend(virStreamPtr stream
,
10813 DEBUG("stream=%p, data=%p, nbytes=%zi", stream
, data
, nbytes
);
10815 virResetLastError();
10817 if (!VIR_IS_CONNECTED_STREAM(stream
)) {
10818 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
10819 virDispatchError(NULL
);
10823 if (stream
->driver
&&
10824 stream
->driver
->streamSend
) {
10826 ret
= (stream
->driver
->streamSend
)(stream
, data
, nbytes
);
10834 virLibConnError(stream
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
10837 virDispatchError(stream
->conn
);
10844 * @stream: pointer to the stream object
10845 * @data: buffer to write to stream
10846 * @nbytes: size of @data buffer
10848 * Write a series of bytes to the stream. This method may
10849 * block the calling application for an arbitrary amount
10852 * Errors are not guaranteed to be reported synchronously
10853 * with the call, but may instead be delayed until a
10856 * An example using this with a hypothetical file download
10859 * virStreamPtr st = virStreamNew(conn, 0);
10860 * int fd = open("demo.iso", O_WRONLY, 0600)
10862 * virConnectDownloadFile(conn, "demo.iso", st);
10866 * int got = virStreamRecv(st, buf, 1024);
10870 * virStreamFinish(st);
10874 * while (offset < got) {
10875 * int sent = write(fd, buf+offset, got-offset)
10877 * virStreamAbort(st);
10883 * if (virStreamFinish(st) < 0)
10884 * ... report an error ....
10886 * virStreamFree(st);
10890 * Returns the number of bytes read, which may be less
10893 * Returns 0 when the end of the stream is reached, at
10894 * which time the caller should invoke virStreamFinish()
10895 * to get confirmation of stream completion.
10897 * Returns -1 upon error, at which time the stream will
10898 * be marked as aborted, and the caller should now release
10899 * the stream with virStreamFree.
10901 * Returns -2 if there is no data pending to be read & the
10902 * stream is marked as non-blocking.
10904 int virStreamRecv(virStreamPtr stream
,
10908 DEBUG("stream=%p, data=%p, nbytes=%zi", stream
, data
, nbytes
);
10910 virResetLastError();
10912 if (!VIR_IS_CONNECTED_STREAM(stream
)) {
10913 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
10914 virDispatchError(NULL
);
10918 if (stream
->driver
&&
10919 stream
->driver
->streamRecv
) {
10921 ret
= (stream
->driver
->streamRecv
)(stream
, data
, nbytes
);
10929 virLibConnError(stream
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
10932 virDispatchError(stream
->conn
);
10938 * virStreamSendAll:
10939 * @stream: pointer to the stream object
10940 * @handler: source callback for reading data from application
10941 * @opaque: application defined data
10943 * Send the entire data stream, reading the data from the
10944 * requested data source. This is simply a convenient alternative
10945 * to virStreamSend, for apps that do blocking-I/o.
10947 * An example using this with a hypothetical file upload
10950 * int mysource(virStreamPtr st, char *buf, int nbytes, void *opaque) {
10951 * int *fd = opaque;
10953 * return read(*fd, buf, nbytes);
10956 * virStreamPtr st = virStreamNew(conn, 0);
10957 * int fd = open("demo.iso", O_RDONLY)
10959 * virConnectUploadFile(conn, st);
10960 * if (virStreamSendAll(st, mysource, &fd) < 0) {
10961 * ...report an error ...
10964 * if (virStreamFinish(st) < 0)
10965 * ...report an error...
10966 * virStreamFree(st);
10969 * Returns 0 if all the data was successfully sent. The caller
10970 * should invoke virStreamFinish(st) to flush the stream upon
10971 * success and then virStreamFree
10973 * Returns -1 upon any error, with virStreamAbort() already
10974 * having been called, so the caller need only call
10977 int virStreamSendAll(virStreamPtr stream
,
10978 virStreamSourceFunc handler
,
10981 char *bytes
= NULL
;
10982 int want
= 1024*64;
10984 DEBUG("stream=%p, handler=%p, opaque=%p", stream
, handler
, opaque
);
10986 virResetLastError();
10988 if (!VIR_IS_CONNECTED_STREAM(stream
)) {
10989 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
10990 virDispatchError(NULL
);
10994 if (stream
->flags
& VIR_STREAM_NONBLOCK
) {
10995 virLibConnError(NULL
, VIR_ERR_OPERATION_INVALID
,
10996 _("data sources cannot be used for non-blocking streams"));
11000 if (VIR_ALLOC_N(bytes
, want
) < 0) {
11001 virReportOOMError();
11006 int got
, offset
= 0;
11007 got
= (handler
)(stream
, bytes
, want
, opaque
);
11009 virStreamAbort(stream
);
11014 while (offset
< got
) {
11016 done
= virStreamSend(stream
, bytes
+ offset
, got
- offset
);
11028 virDispatchError(stream
->conn
);
11035 * virStreamRecvAll:
11036 * @stream: pointer to the stream object
11037 * @handler: sink callback for writing data to application
11038 * @opaque: application defined data
11040 * Receive the entire data stream, sending the data to the
11041 * requested data sink. This is simply a convenient alternative
11042 * to virStreamRecv, for apps that do blocking-I/o.
11044 * An example using this with a hypothetical file download
11047 * int mysink(virStreamPtr st, const char *buf, int nbytes, void *opaque) {
11048 * int *fd = opaque;
11050 * return write(*fd, buf, nbytes);
11053 * virStreamPtr st = virStreamNew(conn, 0);
11054 * int fd = open("demo.iso", O_WRONLY)
11056 * virConnectUploadFile(conn, st);
11057 * if (virStreamRecvAll(st, mysink, &fd) < 0) {
11058 * ...report an error ...
11061 * if (virStreamFinish(st) < 0)
11062 * ...report an error...
11063 * virStreamFree(st);
11066 * Returns 0 if all the data was successfully received. The caller
11067 * should invoke virStreamFinish(st) to flush the stream upon
11068 * success and then virStreamFree
11070 * Returns -1 upon any error, with virStreamAbort() already
11071 * having been called, so the caller need only call
11074 int virStreamRecvAll(virStreamPtr stream
,
11075 virStreamSinkFunc handler
,
11078 char *bytes
= NULL
;
11079 int want
= 1024*64;
11081 DEBUG("stream=%p, handler=%p, opaque=%p", stream
, handler
, opaque
);
11083 virResetLastError();
11085 if (!VIR_IS_CONNECTED_STREAM(stream
)) {
11086 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11087 virDispatchError(NULL
);
11091 if (stream
->flags
& VIR_STREAM_NONBLOCK
) {
11092 virLibConnError(NULL
, VIR_ERR_OPERATION_INVALID
,
11093 _("data sinks cannot be used for non-blocking streams"));
11098 if (VIR_ALLOC_N(bytes
, want
) < 0) {
11099 virReportOOMError();
11104 int got
, offset
= 0;
11105 got
= virStreamRecv(stream
, bytes
, want
);
11110 while (offset
< got
) {
11112 done
= (handler
)(stream
, bytes
+ offset
, got
- offset
, opaque
);
11114 virStreamAbort(stream
);
11126 virDispatchError(stream
->conn
);
11133 * virStreamEventAddCallback:
11134 * @stream: pointer to the stream object
11135 * @events: set of events to monitor
11136 * @cb: callback to invoke when an event occurs
11137 * @opaque: application defined data
11138 * @ff: callback to free @opaque data
11140 * Register a callback to be notified when a stream
11141 * becomes writable, or readable. This is most commonly
11142 * used in conjunction with non-blocking data streams
11143 * to integrate into an event loop
11145 * Returns 0 on success, -1 upon error
11147 int virStreamEventAddCallback(virStreamPtr stream
,
11149 virStreamEventCallback cb
,
11151 virFreeCallback ff
)
11153 DEBUG("stream=%p, events=%d, cb=%p, opaque=%p, ff=%p", stream
, events
, cb
, opaque
, ff
);
11155 virResetLastError();
11157 if (!VIR_IS_CONNECTED_STREAM(stream
)) {
11158 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11159 virDispatchError(NULL
);
11163 if (stream
->driver
&&
11164 stream
->driver
->streamAddCallback
) {
11166 ret
= (stream
->driver
->streamAddCallback
)(stream
, events
, cb
, opaque
, ff
);
11172 virLibConnError(stream
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11175 virDispatchError(stream
->conn
);
11181 * virStreamEventUpdateCallback:
11182 * @stream: pointer to the stream object
11183 * @events: set of events to monitor
11185 * Changes the set of events to monitor for a stream. This allows
11186 * for event notification to be changed without having to
11187 * unregister & register the callback completely. This method
11188 * is guarenteed to succeed if a callback is already registered
11190 * Returns 0 on success, -1 if no callback is registered
11192 int virStreamEventUpdateCallback(virStreamPtr stream
,
11195 DEBUG("stream=%p, events=%d", stream
, events
);
11197 virResetLastError();
11199 if (!VIR_IS_CONNECTED_STREAM(stream
)) {
11200 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11201 virDispatchError(NULL
);
11205 if (stream
->driver
&&
11206 stream
->driver
->streamUpdateCallback
) {
11208 ret
= (stream
->driver
->streamUpdateCallback
)(stream
, events
);
11214 virLibConnError (stream
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11217 virDispatchError(stream
->conn
);
11222 * virStreamEventRemoveCallback:
11223 * @stream: pointer to the stream object
11225 * Remove an event callback from the stream
11227 * Returns 0 on success, -1 on error
11229 int virStreamEventRemoveCallback(virStreamPtr stream
)
11231 DEBUG("stream=%p", stream
);
11233 virResetLastError();
11235 if (!VIR_IS_CONNECTED_STREAM(stream
)) {
11236 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11237 virDispatchError(NULL
);
11241 if (stream
->driver
&&
11242 stream
->driver
->streamRemoveCallback
) {
11244 ret
= (stream
->driver
->streamRemoveCallback
)(stream
);
11250 virLibConnError (stream
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11253 virDispatchError(stream
->conn
);
11259 * @stream: pointer to the stream object
11261 * Indicate that there is no further data is to be transmitted
11262 * on the stream. For output streams this should be called once
11263 * all data has been written. For input streams this should be
11264 * called once virStreamRecv returns end-of-file.
11266 * This method is a synchronization point for all asynchronous
11267 * errors, so if this returns a success code the application can
11268 * be sure that all data has been successfully processed.
11270 * Returns 0 on success, -1 upon error
11272 int virStreamFinish(virStreamPtr stream
)
11274 DEBUG("stream=%p", stream
);
11276 virResetLastError();
11278 if (!VIR_IS_CONNECTED_STREAM(stream
)) {
11279 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11280 virDispatchError(NULL
);
11284 if (stream
->driver
&&
11285 stream
->driver
->streamFinish
) {
11287 ret
= (stream
->driver
->streamFinish
)(stream
);
11293 virLibConnError (stream
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11296 virDispatchError(stream
->conn
);
11302 * @stream: pointer to the stream object
11304 * Request that the in progress data transfer be cancelled
11305 * abnormally before the end of the stream has been reached.
11306 * For output streams this can be used to inform the driver
11307 * that the stream is being terminated early. For input
11308 * streams this can be used to inform the driver that it
11309 * should stop sending data.
11311 * Returns 0 on success, -1 upon error
11313 int virStreamAbort(virStreamPtr stream
)
11315 DEBUG("stream=%p", stream
);
11317 virResetLastError();
11319 if (!VIR_IS_CONNECTED_STREAM(stream
)) {
11320 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11321 virDispatchError(NULL
);
11325 if (stream
->driver
&&
11326 stream
->driver
->streamAbort
) {
11328 ret
= (stream
->driver
->streamAbort
)(stream
);
11334 virLibConnError (stream
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11337 virDispatchError(stream
->conn
);
11343 * @stream: pointer to the stream object
11345 * Decrement the reference count on a stream, releasing
11346 * the stream object if the reference count has hit zero.
11348 * There must not be an active data transfer in progress
11349 * when releasing the stream. If a stream needs to be
11350 * disposed of prior to end of stream being reached, then
11351 * the virStreamAbort function should be called first.
11353 * Returns 0 upon success, or -1 on error
11355 int virStreamFree(virStreamPtr stream
)
11357 DEBUG("stream=%p", stream
);
11359 virResetLastError();
11361 if (!VIR_IS_CONNECTED_STREAM(stream
)) {
11362 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11363 virDispatchError(NULL
);
11367 /* XXX Enforce shutdown before free'ing resources ? */
11369 if (virUnrefStream(stream
) < 0) {
11370 virDispatchError(NULL
);
11378 * virDomainIsActive:
11379 * @dom: pointer to the domain object
11381 * Determine if the domain is currently running
11383 * Returns 1 if running, 0 if inactive, -1 on error
11385 int virDomainIsActive(virDomainPtr dom
)
11387 DEBUG("dom=%p", dom
);
11389 virResetLastError();
11391 if (!VIR_IS_CONNECTED_DOMAIN(dom
)) {
11392 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11393 virDispatchError(NULL
);
11396 if (dom
->conn
->driver
->domainIsActive
) {
11398 ret
= dom
->conn
->driver
->domainIsActive(dom
);
11404 virLibConnError(dom
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11406 virDispatchError(dom
->conn
);
11411 * virDomainIsPersistent:
11412 * @dom: pointer to the domain object
11414 * Determine if the domain has a persistent configuration
11415 * which means it will still exist after shutting down
11417 * Returns 1 if persistent, 0 if transient, -1 on error
11419 int virDomainIsPersistent(virDomainPtr dom
)
11421 DEBUG("dom=%p", dom
);
11423 virResetLastError();
11425 if (!VIR_IS_CONNECTED_DOMAIN(dom
)) {
11426 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11427 virDispatchError(NULL
);
11430 if (dom
->conn
->driver
->domainIsPersistent
) {
11432 ret
= dom
->conn
->driver
->domainIsPersistent(dom
);
11438 virLibConnError(dom
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11440 virDispatchError(dom
->conn
);
11445 * virNetworkIsActive:
11446 * @net: pointer to the network object
11448 * Determine if the network is currently running
11450 * Returns 1 if running, 0 if inactive, -1 on error
11452 int virNetworkIsActive(virNetworkPtr net
)
11454 DEBUG("net=%p", net
);
11456 virResetLastError();
11458 if (!VIR_IS_CONNECTED_NETWORK(net
)) {
11459 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11460 virDispatchError(NULL
);
11463 if (net
->conn
->networkDriver
->networkIsActive
) {
11465 ret
= net
->conn
->networkDriver
->networkIsActive(net
);
11471 virLibConnError(net
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11473 virDispatchError(net
->conn
);
11479 * virNetworkIsPersistent:
11480 * @net: pointer to the network object
11482 * Determine if the network has a persistent configuration
11483 * which means it will still exist after shutting down
11485 * Returns 1 if persistent, 0 if transient, -1 on error
11487 int virNetworkIsPersistent(virNetworkPtr net
)
11489 DEBUG("net=%p", net
);
11491 virResetLastError();
11493 if (!VIR_IS_CONNECTED_NETWORK(net
)) {
11494 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11495 virDispatchError(NULL
);
11498 if (net
->conn
->networkDriver
->networkIsPersistent
) {
11500 ret
= net
->conn
->networkDriver
->networkIsPersistent(net
);
11506 virLibConnError(net
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11508 virDispatchError(net
->conn
);
11514 * virStoragePoolIsActive:
11515 * @pool: pointer to the storage pool object
11517 * Determine if the storage pool is currently running
11519 * Returns 1 if running, 0 if inactive, -1 on error
11521 int virStoragePoolIsActive(virStoragePoolPtr pool
)
11523 DEBUG("pool=%p", pool
);
11525 virResetLastError();
11527 if (!VIR_IS_CONNECTED_STORAGE_POOL(pool
)) {
11528 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11529 virDispatchError(NULL
);
11532 if (pool
->conn
->storageDriver
->poolIsActive
) {
11534 ret
= pool
->conn
->storageDriver
->poolIsActive(pool
);
11540 virLibConnError(pool
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11542 virDispatchError(pool
->conn
);
11548 * virStoragePoolIsPersistent:
11549 * @pool: pointer to the storage pool object
11551 * Determine if the storage pool has a persistent configuration
11552 * which means it will still exist after shutting down
11554 * Returns 1 if persistent, 0 if transient, -1 on error
11556 int virStoragePoolIsPersistent(virStoragePoolPtr pool
)
11558 DEBUG("pool=%p", pool
);
11560 virResetLastError();
11562 if (!VIR_IS_CONNECTED_STORAGE_POOL(pool
)) {
11563 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11564 virDispatchError(NULL
);
11567 if (pool
->conn
->storageDriver
->poolIsPersistent
) {
11569 ret
= pool
->conn
->storageDriver
->poolIsPersistent(pool
);
11575 virLibConnError(pool
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11577 virDispatchError(pool
->conn
);
11584 * virConnectNumOfNWFilters:
11585 * @conn: pointer to the hypervisor connection
11587 * Provides the number of nwfilters.
11589 * Returns the number of nwfilters found or -1 in case of error
11592 virConnectNumOfNWFilters(virConnectPtr conn
)
11594 DEBUG("conn=%p", conn
);
11596 virResetLastError();
11598 if (!VIR_IS_CONNECT(conn
)) {
11599 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11600 virDispatchError(NULL
);
11604 if (conn
->nwfilterDriver
&& conn
->nwfilterDriver
->numOfNWFilters
) {
11606 ret
= conn
->nwfilterDriver
->numOfNWFilters (conn
);
11612 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11615 virDispatchError(conn
);
11621 * virConnectListNWFilters:
11622 * @conn: pointer to the hypervisor connection
11623 * @names: array to collect the list of names of network filters
11624 * @maxnames: size of @names
11626 * Collect the list of network filters, and store their names in @names
11628 * Returns the number of network filters found or -1 in case of error
11631 virConnectListNWFilters(virConnectPtr conn
, char **const names
, int maxnames
)
11633 DEBUG("conn=%p, names=%p, maxnames=%d", conn
, names
, maxnames
);
11635 virResetLastError();
11637 if (!VIR_IS_CONNECT(conn
)) {
11638 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11639 virDispatchError(NULL
);
11643 if ((names
== NULL
) || (maxnames
< 0)) {
11644 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
11648 if (conn
->nwfilterDriver
&& conn
->nwfilterDriver
->listNWFilters
) {
11650 ret
= conn
->nwfilterDriver
->listNWFilters (conn
, names
, maxnames
);
11656 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11659 virDispatchError(conn
);
11665 * virNWFilterLookupByName:
11666 * @conn: pointer to the hypervisor connection
11667 * @name: name for the network filter
11669 * Try to lookup a network filter on the given hypervisor based on its name.
11671 * Returns a new nwfilter object or NULL in case of failure. If the
11672 * network filter cannot be found, then VIR_ERR_NO_NWFILTER error is raised.
11675 virNWFilterLookupByName(virConnectPtr conn
, const char *name
)
11677 DEBUG("conn=%p, name=%s", conn
, name
);
11679 virResetLastError();
11681 if (!VIR_IS_CONNECT(conn
)) {
11682 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11683 virDispatchError(NULL
);
11686 if (name
== NULL
) {
11687 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
11691 if (conn
->nwfilterDriver
&& conn
->nwfilterDriver
->nwfilterLookupByName
) {
11692 virNWFilterPtr ret
;
11693 ret
= conn
->nwfilterDriver
->nwfilterLookupByName (conn
, name
);
11699 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11702 virDispatchError(conn
);
11707 * virNWFilterLookupByUUID:
11708 * @conn: pointer to the hypervisor connection
11709 * @uuid: the raw UUID for the network filter
11711 * Try to lookup a network filter on the given hypervisor based on its UUID.
11713 * Returns a new nwfilter object or NULL in case of failure. If the
11714 * nwfdilter cannot be found, then VIR_ERR_NO_NWFILTER error is raised.
11717 virNWFilterLookupByUUID(virConnectPtr conn
, const unsigned char *uuid
)
11719 DEBUG("conn=%p, uuid=%s", conn
, uuid
);
11721 virResetLastError();
11723 if (!VIR_IS_CONNECT(conn
)) {
11724 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11725 virDispatchError(NULL
);
11728 if (uuid
== NULL
) {
11729 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
11733 if (conn
->nwfilterDriver
&& conn
->nwfilterDriver
->nwfilterLookupByUUID
){
11734 virNWFilterPtr ret
;
11735 ret
= conn
->nwfilterDriver
->nwfilterLookupByUUID (conn
, uuid
);
11741 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11744 virDispatchError(conn
);
11749 * virNWFilterLookupByUUIDString:
11750 * @conn: pointer to the hypervisor connection
11751 * @uuidstr: the string UUID for the nwfilter
11753 * Try to lookup an nwfilter on the given hypervisor based on its UUID.
11755 * Returns a new nwfilter object or NULL in case of failure. If the
11756 * nwfilter cannot be found, then VIR_ERR_NO_NWFILTER error is raised.
11759 virNWFilterLookupByUUIDString(virConnectPtr conn
, const char *uuidstr
)
11761 unsigned char uuid
[VIR_UUID_BUFLEN
];
11762 DEBUG("conn=%p, uuidstr=%s", conn
, uuidstr
);
11764 virResetLastError();
11766 if (!VIR_IS_CONNECT(conn
)) {
11767 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11768 virDispatchError(NULL
);
11771 if (uuidstr
== NULL
) {
11772 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
11776 if (virUUIDParse(uuidstr
, uuid
) < 0) {
11777 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
11781 return virNWFilterLookupByUUID(conn
, &uuid
[0]);
11784 virDispatchError(conn
);
11790 * @nwfilter: a nwfilter object
11792 * Free the nwfilter object. The running instance is kept alive.
11793 * The data structure is freed and should not be used thereafter.
11795 * Returns 0 in case of success and -1 in case of failure.
11798 virNWFilterFree(virNWFilterPtr nwfilter
)
11800 DEBUG("nwfilter=%p", nwfilter
);
11802 virResetLastError();
11804 if (!VIR_IS_CONNECTED_NWFILTER(nwfilter
)) {
11805 virLibNWFilterError(NULL
, VIR_ERR_INVALID_NWFILTER
, __FUNCTION__
);
11806 virDispatchError(NULL
);
11809 if (virUnrefNWFilter(nwfilter
) < 0) {
11810 virDispatchError(NULL
);
11817 * virNWFilterGetName:
11818 * @nwfilter: a nwfilter object
11820 * Get the public name for the network filter
11822 * Returns a pointer to the name or NULL, the string need not be deallocated
11823 * its lifetime will be the same as the nwfilter object.
11826 virNWFilterGetName(virNWFilterPtr nwfilter
)
11828 DEBUG("nwfilter=%p", nwfilter
);
11830 virResetLastError();
11832 if (!VIR_IS_NWFILTER(nwfilter
)) {
11833 virLibNWFilterError(NULL
, VIR_ERR_INVALID_NWFILTER
, __FUNCTION__
);
11834 virDispatchError(NULL
);
11837 return (nwfilter
->name
);
11841 * virNWFilterGetUUID:
11842 * @nwfilter: a nwfilter object
11843 * @uuid: pointer to a VIR_UUID_BUFLEN bytes array
11845 * Get the UUID for a network filter
11847 * Returns -1 in case of error, 0 in case of success
11850 virNWFilterGetUUID(virNWFilterPtr nwfilter
, unsigned char *uuid
)
11852 DEBUG("nwfilter=%p, uuid=%p", nwfilter
, uuid
);
11854 virResetLastError();
11856 if (!VIR_IS_NWFILTER(nwfilter
)) {
11857 virLibNWFilterError(NULL
, VIR_ERR_INVALID_NWFILTER
, __FUNCTION__
);
11858 virDispatchError(NULL
);
11861 if (uuid
== NULL
) {
11862 virLibNWFilterError(nwfilter
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
11866 memcpy(uuid
, &nwfilter
->uuid
[0], VIR_UUID_BUFLEN
);
11871 virDispatchError(nwfilter
->conn
);
11876 * virNWFilterGetUUIDString:
11877 * @nwfilter: a nwfilter object
11878 * @buf: pointer to a VIR_UUID_STRING_BUFLEN bytes array
11880 * Get the UUID for a network filter as string. For more information about
11881 * UUID see RFC4122.
11883 * Returns -1 in case of error, 0 in case of success
11886 virNWFilterGetUUIDString(virNWFilterPtr nwfilter
, char *buf
)
11888 unsigned char uuid
[VIR_UUID_BUFLEN
];
11889 DEBUG("nwfilter=%p, buf=%p", nwfilter
, buf
);
11891 virResetLastError();
11893 if (!VIR_IS_NWFILTER(nwfilter
)) {
11894 virLibNWFilterError(NULL
, VIR_ERR_INVALID_NWFILTER
, __FUNCTION__
);
11895 virDispatchError(NULL
);
11899 virLibNWFilterError(nwfilter
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
11903 if (virNWFilterGetUUID(nwfilter
, &uuid
[0]))
11906 virUUIDFormat(uuid
, buf
);
11910 virDispatchError(nwfilter
->conn
);
11916 * virNWFilterDefineXML:
11917 * @conn: pointer to the hypervisor connection
11918 * @xmlDesc: an XML description of the nwfilter
11920 * Define a new network filter, based on an XML description
11921 * similar to the one returned by virNWFilterGetXMLDesc()
11923 * Returns a new nwfilter object or NULL in case of failure
11926 virNWFilterDefineXML(virConnectPtr conn
, const char *xmlDesc
)
11928 DEBUG("conn=%p, xmlDesc=%s", conn
, xmlDesc
);
11930 virResetLastError();
11932 if (!VIR_IS_CONNECT(conn
)) {
11933 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
11934 virDispatchError(NULL
);
11937 if (xmlDesc
== NULL
) {
11938 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
11941 if (conn
->flags
& VIR_CONNECT_RO
) {
11942 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
11946 if (conn
->nwfilterDriver
&& conn
->nwfilterDriver
->defineXML
) {
11947 virNWFilterPtr ret
;
11948 ret
= conn
->nwfilterDriver
->defineXML (conn
, xmlDesc
, 0);
11954 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
11957 virDispatchError(conn
);
11963 * virNWFilterUndefine:
11964 * @nwfilter: a nwfilter object
11966 * Undefine the nwfilter object. This call will not succeed if
11967 * a running VM is referencing the filter. This does not free the
11968 * associated virNWFilterPtr object.
11970 * Returns 0 in case of success and -1 in case of failure.
11973 virNWFilterUndefine(virNWFilterPtr nwfilter
)
11975 virConnectPtr conn
;
11976 DEBUG("nwfilter=%p", nwfilter
);
11978 virResetLastError();
11980 if (!VIR_IS_CONNECTED_NWFILTER(nwfilter
)) {
11981 virLibNWFilterError(NULL
, VIR_ERR_INVALID_NWFILTER
, __FUNCTION__
);
11982 virDispatchError(NULL
);
11986 conn
= nwfilter
->conn
;
11987 if (conn
->flags
& VIR_CONNECT_RO
) {
11988 virLibNWFilterError(nwfilter
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
11992 if (conn
->nwfilterDriver
&& conn
->nwfilterDriver
->undefine
) {
11994 ret
= conn
->nwfilterDriver
->undefine (nwfilter
);
12000 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12003 virDispatchError(nwfilter
->conn
);
12009 * virNWFilterGetXMLDesc:
12010 * @nwfilter: a nwfilter object
12011 * @flags: an OR'ed set of extraction flags, not used yet
12013 * Provide an XML description of the network filter. The description may be
12014 * reused later to redefine the network filter with virNWFilterCreateXML().
12016 * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
12017 * the caller must free() the returned value.
12020 virNWFilterGetXMLDesc(virNWFilterPtr nwfilter
, int flags
)
12022 virConnectPtr conn
;
12023 DEBUG("nwfilter=%p, flags=%d", nwfilter
, flags
);
12025 virResetLastError();
12027 if (!VIR_IS_CONNECTED_NWFILTER(nwfilter
)) {
12028 virLibNWFilterError(NULL
, VIR_ERR_INVALID_NWFILTER
, __FUNCTION__
);
12029 virDispatchError(NULL
);
12033 virLibNWFilterError(nwfilter
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
12037 conn
= nwfilter
->conn
;
12039 if (conn
->nwfilterDriver
&& conn
->nwfilterDriver
->getXMLDesc
) {
12041 ret
= conn
->nwfilterDriver
->getXMLDesc (nwfilter
, flags
);
12047 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12050 virDispatchError(nwfilter
->conn
);
12057 * @nwfilter: the nwfilter to hold a reference on
12059 * Increment the reference count on the nwfilter. For each
12060 * additional call to this method, there shall be a corresponding
12061 * call to virNWFilterFree to release the reference count, once
12062 * the caller no longer needs the reference to this object.
12064 * This method is typically useful for applications where multiple
12065 * threads are using a connection, and it is required that the
12066 * connection remain open until all threads have finished using
12067 * it. ie, each new thread using an nwfilter would increment
12068 * the reference count.
12070 * Returns 0 in case of success, -1 in case of failure.
12073 virNWFilterRef(virNWFilterPtr nwfilter
)
12075 if ((!VIR_IS_CONNECTED_NWFILTER(nwfilter
))) {
12076 virLibConnError(NULL
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
12077 virDispatchError(NULL
);
12080 virMutexLock(&nwfilter
->conn
->lock
);
12081 DEBUG("nwfilter=%p refs=%d", nwfilter
, nwfilter
->refs
);
12083 virMutexUnlock(&nwfilter
->conn
->lock
);
12089 * virInterfaceIsActive:
12090 * @iface: pointer to the interface object
12092 * Determine if the interface is currently running
12094 * Returns 1 if running, 0 if inactive, -1 on error
12096 int virInterfaceIsActive(virInterfacePtr iface
)
12098 DEBUG("iface=%p", iface
);
12100 virResetLastError();
12102 if (!VIR_IS_CONNECTED_INTERFACE(iface
)) {
12103 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
12104 virDispatchError(NULL
);
12107 if (iface
->conn
->interfaceDriver
->interfaceIsActive
) {
12109 ret
= iface
->conn
->interfaceDriver
->interfaceIsActive(iface
);
12115 virLibConnError(iface
->conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12117 virDispatchError(iface
->conn
);
12123 * virConnectIsEncrypted:
12124 * @conn: pointer to the connection object
12126 * Determine if the connection to the hypervisor is encrypted
12128 * Returns 1 if encrypted, 0 if not encrypted, -1 on error
12130 int virConnectIsEncrypted(virConnectPtr conn
)
12132 DEBUG("conn=%p", conn
);
12134 virResetLastError();
12136 if (!VIR_IS_CONNECT(conn
)) {
12137 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
12138 virDispatchError(NULL
);
12141 if (conn
->driver
->isEncrypted
) {
12143 ret
= conn
->driver
->isEncrypted(conn
);
12149 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12151 virDispatchError(conn
);
12156 * virConnectIsSecure:
12157 * @conn: pointer to the connection object
12159 * Determine if the connection to the hypervisor is secure
12161 * A connection will be classed as secure if it is either
12162 * encrypted, or running over a channel which is not exposed
12163 * to eavesdropping (eg a UNIX domain socket, or pipe)
12165 * Returns 1 if secure, 0 if secure, -1 on error
12167 int virConnectIsSecure(virConnectPtr conn
)
12169 DEBUG("conn=%p", conn
);
12171 virResetLastError();
12173 if (!VIR_IS_CONNECT(conn
)) {
12174 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
12175 virDispatchError(NULL
);
12178 if (conn
->driver
->isSecure
) {
12180 ret
= conn
->driver
->isSecure(conn
);
12186 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12188 virDispatchError(conn
);
12194 * virConnectCompareCPU:
12195 * @conn: virConnect connection
12196 * @xmlDesc: XML describing the CPU to compare with host CPU
12197 * @flags: currently unused, pass 0
12199 * Compares the given CPU description with the host CPU
12201 * Returns comparison result according to enum virCPUCompareResult
12204 virConnectCompareCPU(virConnectPtr conn
,
12205 const char *xmlDesc
,
12206 unsigned int flags
)
12208 VIR_DEBUG("conn=%p, xmlDesc=%s, flags=%u", conn
, xmlDesc
, flags
);
12210 virResetLastError();
12212 if (!VIR_IS_CONNECT(conn
)) {
12213 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
12214 virDispatchError(NULL
);
12215 return VIR_CPU_COMPARE_ERROR
;
12217 if (xmlDesc
== NULL
) {
12218 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
12222 if (conn
->driver
->cpuCompare
) {
12225 ret
= conn
->driver
->cpuCompare(conn
, xmlDesc
, flags
);
12226 if (ret
== VIR_CPU_COMPARE_ERROR
)
12231 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12234 virDispatchError(conn
);
12235 return VIR_CPU_COMPARE_ERROR
;
12240 * virConnectBaselineCPU:
12242 * @conn: virConnect connection
12243 * @xmlCPUs: array of XML descriptions of host CPUs
12244 * @ncpus: number of CPUs in xmlCPUs
12245 * @flags: fine-tuning flags, currently unused, pass 0.
12247 * Computes the most feature-rich CPU which is compatible with all given
12250 * Returns XML description of the computed CPU or NULL on error.
12253 virConnectBaselineCPU(virConnectPtr conn
,
12254 const char **xmlCPUs
,
12255 unsigned int ncpus
,
12256 unsigned int flags
)
12260 VIR_DEBUG("conn=%p, xmlCPUs=%p, ncpus=%u, flags=%u",
12261 conn
, xmlCPUs
, ncpus
, flags
);
12263 for (i
= 0; i
< ncpus
; i
++)
12264 VIR_DEBUG("xmlCPUs[%u]=%s", i
, NULLSTR(xmlCPUs
[i
]));
12267 virResetLastError();
12269 if (!VIR_IS_CONNECT(conn
)) {
12270 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
12271 virDispatchError(NULL
);
12274 if (xmlCPUs
== NULL
) {
12275 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
12279 if (conn
->driver
->cpuBaseline
) {
12282 cpu
= conn
->driver
->cpuBaseline(conn
, xmlCPUs
, ncpus
, flags
);
12288 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12291 virDispatchError(conn
);
12297 * virDomainGetJobInfo:
12298 * @domain: a domain object
12299 * @info: pointer to a virDomainJobInfo structure allocated by the user
12301 * Extract information about progress of a background job on a domain.
12302 * Will return an error if the domain is not active.
12304 * Returns 0 in case of success and -1 in case of failure.
12307 virDomainGetJobInfo(virDomainPtr domain
, virDomainJobInfoPtr info
)
12309 virConnectPtr conn
;
12310 DEBUG("domain=%p, info=%p", domain
, info
);
12312 virResetLastError();
12314 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
12315 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
12316 virDispatchError(NULL
);
12319 if (info
== NULL
) {
12320 virLibDomainError(domain
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
12324 memset(info
, 0, sizeof(virDomainJobInfo
));
12326 conn
= domain
->conn
;
12328 if (conn
->driver
->domainGetJobInfo
) {
12330 ret
= conn
->driver
->domainGetJobInfo (domain
, info
);
12336 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12339 virDispatchError(domain
->conn
);
12345 * virDomainAbortJob:
12346 * @domain: a domain object
12348 * Requests that the current background job be aborted at the
12349 * soonest opportunity. This will block until the job has
12350 * either completed, or aborted.
12352 * Returns 0 in case of success and -1 in case of failure.
12355 virDomainAbortJob(virDomainPtr domain
)
12357 virConnectPtr conn
;
12359 DEBUG("domain=%p", domain
);
12361 virResetLastError();
12363 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
12364 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
12365 virDispatchError(NULL
);
12369 conn
= domain
->conn
;
12370 if (conn
->flags
& VIR_CONNECT_RO
) {
12371 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
12375 if (conn
->driver
->domainAbortJob
) {
12377 ret
= conn
->driver
->domainAbortJob(domain
);
12383 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12386 virDispatchError(conn
);
12392 * virDomainMigrateSetMaxDowntime:
12393 * @domain: a domain object
12394 * @downtime: maximum tolerable downtime for live migration, in milliseconds
12395 * @flags: fine-tuning flags, currently unused, use 0
12397 * Sets maximum tolerable time for which the domain is allowed to be paused
12398 * at the end of live migration. It's supposed to be called while the domain is
12399 * being live-migrated as a reaction to migration progress.
12401 * Returns 0 in case of success, -1 otherwise.
12404 virDomainMigrateSetMaxDowntime(virDomainPtr domain
,
12405 unsigned long long downtime
,
12406 unsigned int flags
)
12408 virConnectPtr conn
;
12410 DEBUG("domain=%p, downtime=%llu, flags=%u", domain
, downtime
, flags
);
12412 virResetLastError();
12414 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
12415 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
12416 virDispatchError(NULL
);
12420 conn
= domain
->conn
;
12421 if (conn
->flags
& VIR_CONNECT_RO
) {
12422 virLibDomainError(domain
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
12426 if (conn
->driver
->domainMigrateSetMaxDowntime
) {
12427 if (conn
->driver
->domainMigrateSetMaxDowntime(domain
, downtime
, flags
) < 0)
12432 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12434 virDispatchError(conn
);
12439 * virConnectDomainEventRegisterAny:
12440 * @conn: pointer to the connection
12441 * @dom: pointer to the domain
12442 * @eventID: the event type to receive
12443 * @cb: callback to the function handling domain events
12444 * @opaque: opaque data to pass on to the callback
12445 * @freecb: optional function to deallocate opaque when not used anymore
12447 * Adds a callback to receive notifications of arbitrary domain events
12448 * occurring on a domain.
12450 * If dom is NULL, then events will be monitored for any domain. If dom
12451 * is non-NULL, then only the specific domain will be monitored
12453 * Most types of event have a callback providing a custom set of parameters
12454 * for the event. When registering an event, it is thus neccessary to use
12455 * the VIR_DOMAIN_EVENT_CALLBACK() macro to cast the supplied function pointer
12456 * to match the signature of this method.
12458 * The virDomainPtr object handle passed into the callback upon delivery
12459 * of an event is only valid for the duration of execution of the callback.
12460 * If the callback wishes to keep the domain object after the callback
12461 * returns, it shall take a reference to it, by calling virDomainRef.
12462 * The reference can be released once the object is no longer required
12463 * by calling virDomainFree.
12465 * The return value from this method is a positive integer identifier
12466 * for the callback. To unregister a callback, this callback ID should
12467 * be passed to the virDomainEventUnregisterAny method
12469 * Returns a callback identifier on success, -1 on failure
12472 virConnectDomainEventRegisterAny(virConnectPtr conn
,
12475 virConnectDomainEventGenericCallback cb
,
12477 virFreeCallback freecb
)
12479 DEBUG("conn=%p dom=%p, eventID=%d, cb=%p, opaque=%p, freecb=%p", conn
, dom
, eventID
, cb
, opaque
, freecb
);
12480 virResetLastError();
12482 if (!VIR_IS_CONNECT(conn
)) {
12483 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
12484 virDispatchError(NULL
);
12488 !(VIR_IS_CONNECTED_DOMAIN(dom
) && dom
->conn
== conn
)) {
12489 virLibConnError(conn
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
12490 virDispatchError(conn
);
12493 if (eventID
< 0 || eventID
>= VIR_DOMAIN_EVENT_ID_LAST
|| cb
== NULL
) {
12494 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
12498 if ((conn
->driver
) && (conn
->driver
->domainEventRegisterAny
)) {
12500 ret
= conn
->driver
->domainEventRegisterAny(conn
, dom
, eventID
, cb
, opaque
, freecb
);
12506 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12508 virDispatchError(conn
);
12513 * virConnectDomainEventDeregisterAny:
12514 * @conn: pointer to the connection
12515 * @callbackID: the callback identifier
12517 * Removes an event callback. The callbackID parameter should be the
12518 * vaule obtained from a previous virDomainEventRegisterAny method.
12520 * Returns 0 on success, -1 on failure
12523 virConnectDomainEventDeregisterAny(virConnectPtr conn
,
12526 DEBUG("conn=%p, callbackID=%d", conn
, callbackID
);
12528 virResetLastError();
12530 if (!VIR_IS_CONNECT(conn
)) {
12531 virLibConnError(NULL
, VIR_ERR_INVALID_CONN
, __FUNCTION__
);
12532 virDispatchError(NULL
);
12535 if (callbackID
< 0) {
12536 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
12539 if ((conn
->driver
) && (conn
->driver
->domainEventDeregisterAny
)) {
12541 ret
= conn
->driver
->domainEventDeregisterAny(conn
, callbackID
);
12547 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12549 virDispatchError(conn
);
12554 * virDomainManagedSave:
12555 * @dom: pointer to the domain
12556 * @flags: optional flags currently unused
12558 * This method will suspend a domain and save its memory contents to
12559 * a file on disk. After the call, if successful, the domain is not
12560 * listed as running anymore.
12561 * The difference from virDomainSave() is that libvirt is keeping track of
12562 * the saved state itself, and will reuse it once the domain is being
12563 * restarted (automatically or via an explicit libvirt call).
12564 * As a result any running domain is sure to not have a managed saved image.
12566 * Returns 0 in case of success or -1 in case of failure
12568 int virDomainManagedSave(virDomainPtr dom
, unsigned int flags
)
12570 virConnectPtr conn
;
12572 VIR_DEBUG("dom=%p, flags=%u", dom
, flags
);
12574 virResetLastError();
12576 if (!VIR_IS_CONNECTED_DOMAIN(dom
)) {
12577 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
12578 virDispatchError(NULL
);
12583 if (conn
->flags
& VIR_CONNECT_RO
) {
12584 virLibDomainError(dom
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
12588 if (conn
->driver
->domainManagedSave
) {
12591 ret
= conn
->driver
->domainManagedSave(dom
, flags
);
12597 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12600 virDispatchError(conn
);
12605 * virDomainHasManagedSaveImage:
12606 * @dom: pointer to the domain
12607 * @flags: optional flags currently unused
12609 * Check if a domain has a managed save image as created by
12610 * virDomainManagedSave(). Note that any running domain should not have
12611 * such an image, as it should have been removed on restart.
12613 * Returns 0 if no image is present, 1 if an image is present, and
12614 * -1 in case of error
12616 int virDomainHasManagedSaveImage(virDomainPtr dom
, unsigned int flags
)
12618 virConnectPtr conn
;
12620 VIR_DEBUG("dom=%p, flags=%u", dom
, flags
);
12622 virResetLastError();
12624 if (!VIR_IS_CONNECTED_DOMAIN(dom
)) {
12625 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
12626 virDispatchError(NULL
);
12632 if (conn
->driver
->domainHasManagedSaveImage
) {
12635 ret
= conn
->driver
->domainHasManagedSaveImage(dom
, flags
);
12641 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12644 virDispatchError(conn
);
12649 * virDomainManagedSaveRemove:
12650 * @dom: pointer to the domain
12651 * @flags: optional flags currently unused
12653 * Remove any managed save image for this domain.
12655 * Returns 0 in case of success, and -1 in case of error
12657 int virDomainManagedSaveRemove(virDomainPtr dom
, unsigned int flags
)
12659 virConnectPtr conn
;
12661 VIR_DEBUG("dom=%p, flags=%u", dom
, flags
);
12663 virResetLastError();
12665 if (!VIR_IS_CONNECTED_DOMAIN(dom
)) {
12666 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
12667 virDispatchError(NULL
);
12672 if (conn
->flags
& VIR_CONNECT_RO
) {
12673 virLibDomainError(dom
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
12677 if (conn
->driver
->domainManagedSaveRemove
) {
12680 ret
= conn
->driver
->domainManagedSaveRemove(dom
, flags
);
12686 virLibConnError(conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12689 virDispatchError(conn
);
12694 * virDomainSnapshotCreateXML:
12695 * @domain: a domain object
12696 * @xmlDesc: string containing an XML description of the domain
12697 * @flags: unused flag parameters; callers should pass 0
12699 * Creates a new snapshot of a domain based on the snapshot xml
12700 * contained in xmlDesc.
12702 * Returns an (opaque) virDomainSnapshotPtr on success, NULL on failure.
12704 virDomainSnapshotPtr
12705 virDomainSnapshotCreateXML(virDomainPtr domain
,
12706 const char *xmlDesc
,
12707 unsigned int flags
)
12709 virConnectPtr conn
;
12711 DEBUG("domain=%p, xmlDesc=%s, flags=%u", domain
, xmlDesc
, flags
);
12713 virResetLastError();
12715 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
12716 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
12717 virDispatchError(NULL
);
12721 conn
= domain
->conn
;
12722 if (conn
->flags
& VIR_CONNECT_RO
) {
12723 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
, __FUNCTION__
);
12727 if (conn
->driver
->domainSnapshotCreateXML
) {
12728 virDomainSnapshotPtr ret
;
12729 ret
= conn
->driver
->domainSnapshotCreateXML(domain
, xmlDesc
, flags
);
12735 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12737 virDispatchError(conn
);
12742 * virDomainSnapshotGetXMLDesc:
12743 * @snapshot: a domain snapshot object
12744 * @flags: unused flag parameters; callers should pass 0
12746 * Provide an XML description of the domain snapshot.
12748 * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
12749 * the caller must free() the returned value.
12752 virDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot
,
12753 unsigned int flags
)
12755 virConnectPtr conn
;
12756 DEBUG("snapshot=%p, flags=%d", snapshot
, flags
);
12758 virResetLastError();
12760 if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot
)) {
12761 virLibDomainSnapshotError(NULL
, VIR_ERR_INVALID_DOMAIN_SNAPSHOT
,
12763 virDispatchError(NULL
);
12767 conn
= snapshot
->domain
->conn
;
12769 if ((conn
->flags
& VIR_CONNECT_RO
) && (flags
& VIR_DOMAIN_XML_SECURE
)) {
12770 virLibConnError(conn
, VIR_ERR_OPERATION_DENIED
,
12771 _("virDomainSnapshotGetXMLDesc with secure flag"));
12775 if (conn
->driver
->domainSnapshotDumpXML
) {
12777 ret
= conn
->driver
->domainSnapshotDumpXML(snapshot
, flags
);
12783 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12785 virDispatchError(conn
);
12790 * virDomainSnapshotNum:
12791 * @domain: a domain object
12792 * @flags: unused flag parameters; callers should pass 0
12794 * Provides the number of domain snapshots for this domain..
12796 * Returns the number of domain snapshost found or -1 in case of error.
12799 virDomainSnapshotNum(virDomainPtr domain
, unsigned int flags
)
12801 virConnectPtr conn
;
12802 DEBUG("domain=%p", domain
);
12804 virResetLastError();
12806 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
12807 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
12808 virDispatchError(NULL
);
12812 conn
= domain
->conn
;
12813 if (conn
->driver
->domainSnapshotNum
) {
12814 int ret
= conn
->driver
->domainSnapshotNum(domain
, flags
);
12820 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12822 virDispatchError(conn
);
12827 * virDomainSnapshotListNames:
12828 * @domain: a domain object
12829 * @names: array to collect the list of names of snapshots
12830 * @nameslen: size of @names
12831 * @flags: unused flag parameters; callers should pass 0
12833 * Collect the list of domain snapshots for the given domain, and store
12834 * their names in @names. Caller is responsible for freeing each member
12837 * Returns the number of domain snapshots found or -1 in case of error.
12840 virDomainSnapshotListNames(virDomainPtr domain
, char **names
, int nameslen
,
12841 unsigned int flags
)
12843 virConnectPtr conn
;
12845 DEBUG("domain=%p, names=%p, nameslen=%d, flags=%u",
12846 domain
, names
, nameslen
, flags
);
12848 virResetLastError();
12850 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
12851 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
12852 virDispatchError(NULL
);
12856 conn
= domain
->conn
;
12858 if ((names
== NULL
) || (nameslen
< 0)) {
12859 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
12863 if (conn
->driver
->domainSnapshotListNames
) {
12864 int ret
= conn
->driver
->domainSnapshotListNames(domain
, names
,
12871 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12873 virDispatchError(conn
);
12878 * virDomainSnapshotLookupByName:
12879 * @domain: a domain object
12880 * @name: name for the domain snapshot
12881 * @flags: unused flag parameters; callers should pass 0
12883 * Try to lookup a domain snapshot based on its name.
12885 * Returns a domain snapshot object or NULL in case of failure. If the
12886 * domain snapshot cannot be found, then the VIR_ERR_NO_DOMAIN_SNAPSHOT
12889 virDomainSnapshotPtr
12890 virDomainSnapshotLookupByName(virDomainPtr domain
,
12892 unsigned int flags
)
12894 virConnectPtr conn
;
12895 DEBUG("domain=%p, name=%s, flags=%u", domain
, name
, flags
);
12897 virResetLastError();
12899 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
12900 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
12901 virDispatchError(NULL
);
12905 conn
= domain
->conn
;
12907 if (name
== NULL
) {
12908 virLibConnError(conn
, VIR_ERR_INVALID_ARG
, __FUNCTION__
);
12912 if (conn
->driver
->domainSnapshotLookupByName
) {
12913 virDomainSnapshotPtr dom
;
12914 dom
= conn
->driver
->domainSnapshotLookupByName(domain
, name
, flags
);
12920 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12922 virDispatchError(conn
);
12927 * virDomainHasCurrentSnapshot:
12928 * @domain: pointer to the domain object
12929 * @flags: unused flag parameters; callers should pass 0
12931 * Determine if the domain has a current snapshot.
12933 * Returns 1 if such snapshot exists, 0 if it doesn't, -1 on error.
12936 virDomainHasCurrentSnapshot(virDomainPtr domain
, unsigned int flags
)
12938 virConnectPtr conn
;
12939 DEBUG("domain=%p, flags=%u", domain
, flags
);
12941 virResetLastError();
12943 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
12944 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
12945 virDispatchError(NULL
);
12949 conn
= domain
->conn
;
12951 if (conn
->driver
->domainHasCurrentSnapshot
) {
12952 int ret
= conn
->driver
->domainHasCurrentSnapshot(domain
, flags
);
12958 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
12960 virDispatchError(conn
);
12965 * virDomainSnapshotCurrent:
12966 * @domain: a domain object
12967 * @flags: unused flag parameters; callers should pass 0
12969 * Get the current snapshot for a domain, if any.
12971 * Returns a domain snapshot object or NULL in case of failure. If the
12972 * current domain snapshot cannot be found, then the VIR_ERR_NO_DOMAIN_SNAPSHOT
12975 virDomainSnapshotPtr
12976 virDomainSnapshotCurrent(virDomainPtr domain
,
12977 unsigned int flags
)
12979 virConnectPtr conn
;
12980 DEBUG("domain=%p, flags=%u", domain
, flags
);
12982 virResetLastError();
12984 if (!VIR_IS_CONNECTED_DOMAIN(domain
)) {
12985 virLibDomainError(NULL
, VIR_ERR_INVALID_DOMAIN
, __FUNCTION__
);
12986 virDispatchError(NULL
);
12990 conn
= domain
->conn
;
12992 if (conn
->driver
->domainSnapshotCurrent
) {
12993 virDomainSnapshotPtr snap
;
12994 snap
= conn
->driver
->domainSnapshotCurrent(domain
, flags
);
13000 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
13002 virDispatchError(conn
);
13007 * virDomainRevertToSnapshot:
13008 * @snapshot: a domain snapshot object
13009 * @flags: unused flag parameters; callers should pass 0
13011 * Revert the domain to a given snapshot.
13013 * Returns 0 if the creation is successful, -1 on error.
13016 virDomainRevertToSnapshot(virDomainSnapshotPtr snapshot
,
13017 unsigned int flags
)
13019 virConnectPtr conn
;
13021 DEBUG("snapshot=%p, flags=%u", snapshot
, flags
);
13023 virResetLastError();
13025 if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot
)) {
13026 virLibDomainSnapshotError(NULL
, VIR_ERR_INVALID_DOMAIN_SNAPSHOT
,
13028 virDispatchError(NULL
);
13032 conn
= snapshot
->domain
->conn
;
13034 if (conn
->driver
->domainRevertToSnapshot
) {
13035 int ret
= conn
->driver
->domainRevertToSnapshot(snapshot
, flags
);
13041 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
13043 virDispatchError(conn
);
13048 * virDomainSnapshotDelete:
13049 * @snapshot: a domain snapshot object
13050 * @flags: flag parameters
13052 * Delete the snapshot.
13054 * If @flags is 0, then just this snapshot is deleted, and changes from
13055 * this snapshot are automatically merged into children snapshots. If
13056 * flags is VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN, then this snapshot
13057 * and any children snapshots are deleted.
13059 * Returns 0 if the snapshot was successfully deleted, -1 on error.
13062 virDomainSnapshotDelete(virDomainSnapshotPtr snapshot
,
13063 unsigned int flags
)
13065 virConnectPtr conn
;
13067 DEBUG("snapshot=%p, flags=%u", snapshot
, flags
);
13069 virResetLastError();
13071 if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot
)) {
13072 virLibDomainSnapshotError(NULL
, VIR_ERR_INVALID_DOMAIN_SNAPSHOT
,
13074 virDispatchError(NULL
);
13078 conn
= snapshot
->domain
->conn
;
13080 if (conn
->driver
->domainSnapshotDelete
) {
13081 int ret
= conn
->driver
->domainSnapshotDelete(snapshot
, flags
);
13087 virLibConnError (conn
, VIR_ERR_NO_SUPPORT
, __FUNCTION__
);
13089 virDispatchError(conn
);
13094 * virDomainSnapshotFree:
13095 * @snapshot: a domain snapshot object
13097 * Free the domain snapshot object. The snapshot itself is not modified.
13098 * The data structure is freed and should not be used thereafter.
13100 * Returns 0 in case of success and -1 in case of failure.
13103 virDomainSnapshotFree(virDomainSnapshotPtr snapshot
)
13105 DEBUG("snapshot=%p", snapshot
);
13107 virResetLastError();
13109 if (!VIR_IS_DOMAIN_SNAPSHOT(snapshot
)) {
13110 virLibDomainSnapshotError(NULL
, VIR_ERR_INVALID_DOMAIN_SNAPSHOT
,
13112 virDispatchError(NULL
);
13115 if (virUnrefDomainSnapshot(snapshot
) < 0) {
13116 virDispatchError(NULL
);