docs: Update documentation for spapr-vio addresses
[libvirt/ericb.git] / src / libvirt-domain.c
blob509ce5ac8b5970668b9822a1785dae95bfc184cc
1 /*
2 * libvirt-domain.c: entry points for virDomainPtr APIs
4 * Copyright (C) 2006-2015 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
21 #include <config.h>
22 #include <sys/stat.h>
24 #include "intprops.h"
26 #include "datatypes.h"
27 #include "viralloc.h"
28 #include "virfile.h"
29 #include "virlog.h"
30 #include "virtypedparam.h"
32 VIR_LOG_INIT("libvirt.domain");
34 #define VIR_FROM_THIS VIR_FROM_DOMAIN
37 /**
38 * virConnectListDomains:
39 * @conn: pointer to the hypervisor connection
40 * @ids: array to collect the list of IDs of active domains
41 * @maxids: size of @ids
43 * Collect the list of active domains, and store their IDs in array @ids
45 * For inactive domains, see virConnectListDefinedDomains(). For more
46 * control over the results, see virConnectListAllDomains().
48 * Returns the number of domains found or -1 in case of error. Note that
49 * this command is inherently racy; a domain can be started between a
50 * call to virConnectNumOfDomains() and this call; you are only guaranteed
51 * that all currently active domains were listed if the return is less
52 * than @maxids.
54 int
55 virConnectListDomains(virConnectPtr conn, int *ids, int maxids)
57 VIR_DEBUG("conn=%p, ids=%p, maxids=%d", conn, ids, maxids);
59 virResetLastError();
61 virCheckConnectReturn(conn, -1);
62 virCheckNonNullArgGoto(ids, error);
63 virCheckNonNegativeArgGoto(maxids, error);
65 if (conn->driver->connectListDomains) {
66 int ret = conn->driver->connectListDomains(conn, ids, maxids);
67 if (ret < 0)
68 goto error;
69 return ret;
72 virReportUnsupportedError();
73 error:
74 virDispatchError(conn);
75 return -1;
79 /**
80 * virConnectNumOfDomains:
81 * @conn: pointer to the hypervisor connection
83 * Provides the number of active domains.
85 * Returns the number of domain found or -1 in case of error
87 int
88 virConnectNumOfDomains(virConnectPtr conn)
90 VIR_DEBUG("conn=%p", conn);
92 virResetLastError();
94 virCheckConnectReturn(conn, -1);
96 if (conn->driver->connectNumOfDomains) {
97 int ret = conn->driver->connectNumOfDomains(conn);
98 if (ret < 0)
99 goto error;
100 return ret;
103 virReportUnsupportedError();
104 error:
105 virDispatchError(conn);
106 return -1;
111 * virDomainGetConnect:
112 * @dom: pointer to a domain
114 * Provides the connection pointer associated with a domain. The
115 * reference counter on the connection is not increased by this
116 * call.
118 * Returns the virConnectPtr or NULL in case of failure.
120 virConnectPtr
121 virDomainGetConnect(virDomainPtr dom)
123 VIR_DOMAIN_DEBUG(dom);
125 virResetLastError();
127 virCheckDomainReturn(dom, NULL);
129 return dom->conn;
134 * virDomainCreateXML:
135 * @conn: pointer to the hypervisor connection
136 * @xmlDesc: string containing an XML description of the domain
137 * @flags: bitwise-OR of supported virDomainCreateFlags
139 * Launch a new guest domain, based on an XML description similar
140 * to the one returned by virDomainGetXMLDesc()
141 * This function may require privileged access to the hypervisor.
142 * The domain is not persistent, so its definition will disappear when it
143 * is destroyed, or if the host is restarted (see virDomainDefineXML() to
144 * define persistent domains).
146 * If the VIR_DOMAIN_START_PAUSED flag is set, the guest domain
147 * will be started, but its CPUs will remain paused. The CPUs
148 * can later be manually started using virDomainResume.
150 * If the VIR_DOMAIN_START_AUTODESTROY flag is set, the guest
151 * domain will be automatically destroyed when the virConnectPtr
152 * object is finally released. This will also happen if the
153 * client application crashes / loses its connection to the
154 * libvirtd daemon. Any domains marked for auto destroy will
155 * block attempts at migration, save-to-file, or snapshots.
157 * virDomainFree should be used to free the resources after the
158 * domain object is no longer needed.
160 * Returns a new domain object or NULL in case of failure
162 virDomainPtr
163 virDomainCreateXML(virConnectPtr conn, const char *xmlDesc,
164 unsigned int flags)
166 VIR_DEBUG("conn=%p, xmlDesc=%s, flags=0x%x", conn, NULLSTR(xmlDesc), flags);
168 virResetLastError();
170 virCheckConnectReturn(conn, NULL);
171 virCheckNonNullArgGoto(xmlDesc, error);
172 virCheckReadOnlyGoto(conn->flags, error);
174 if (conn->driver->domainCreateXML) {
175 virDomainPtr ret;
176 ret = conn->driver->domainCreateXML(conn, xmlDesc, flags);
177 if (!ret)
178 goto error;
179 return ret;
182 virReportUnsupportedError();
183 error:
184 virDispatchError(conn);
185 return NULL;
190 * virDomainCreateXMLWithFiles:
191 * @conn: pointer to the hypervisor connection
192 * @xmlDesc: string containing an XML description of the domain
193 * @nfiles: number of file descriptors passed
194 * @files: list of file descriptors passed
195 * @flags: bitwise-OR of supported virDomainCreateFlags
197 * Launch a new guest domain, based on an XML description similar
198 * to the one returned by virDomainGetXMLDesc()
199 * This function may require privileged access to the hypervisor.
200 * The domain is not persistent, so its definition will disappear when it
201 * is destroyed, or if the host is restarted (see virDomainDefineXML() to
202 * define persistent domains).
204 * @files provides an array of file descriptors which will be
205 * made available to the 'init' process of the guest. The file
206 * handles exposed to the guest will be renumbered to start
207 * from 3 (ie immediately following stderr). This is only
208 * supported for guests which use container based virtualization
209 * technology.
211 * If the VIR_DOMAIN_START_PAUSED flag is set, the guest domain
212 * will be started, but its CPUs will remain paused. The CPUs
213 * can later be manually started using virDomainResume.
215 * If the VIR_DOMAIN_START_AUTODESTROY flag is set, the guest
216 * domain will be automatically destroyed when the virConnectPtr
217 * object is finally released. This will also happen if the
218 * client application crashes / loses its connection to the
219 * libvirtd daemon. Any domains marked for auto destroy will
220 * block attempts at migration, save-to-file, or snapshots.
222 * virDomainFree should be used to free the resources after the
223 * domain object is no longer needed.
225 * Returns a new domain object or NULL in case of failure
227 virDomainPtr
228 virDomainCreateXMLWithFiles(virConnectPtr conn, const char *xmlDesc,
229 unsigned int nfiles,
230 int *files,
231 unsigned int flags)
233 VIR_DEBUG("conn=%p, xmlDesc=%s, nfiles=%u, files=%p, flags=0x%x",
234 conn, NULLSTR(xmlDesc), nfiles, files, flags);
236 virResetLastError();
238 virCheckConnectReturn(conn, NULL);
239 virCheckNonNullArgGoto(xmlDesc, error);
240 virCheckReadOnlyGoto(conn->flags, error);
242 if (conn->driver->domainCreateXMLWithFiles) {
243 virDomainPtr ret;
244 ret = conn->driver->domainCreateXMLWithFiles(conn, xmlDesc,
245 nfiles, files,
246 flags);
247 if (!ret)
248 goto error;
249 return ret;
252 virReportUnsupportedError();
253 error:
254 virDispatchError(conn);
255 return NULL;
260 * virDomainCreateLinux:
261 * @conn: pointer to the hypervisor connection
262 * @xmlDesc: string containing an XML description of the domain
263 * @flags: extra flags; not used yet, so callers should always pass 0
265 * Deprecated after 0.4.6.
266 * Renamed to virDomainCreateXML() providing identical functionality.
267 * This existing name will be left indefinitely for API compatibility.
269 * Returns a new domain object or NULL in case of failure
271 virDomainPtr
272 virDomainCreateLinux(virConnectPtr conn, const char *xmlDesc,
273 unsigned int flags)
275 return virDomainCreateXML(conn, xmlDesc, flags);
280 * virDomainLookupByID:
281 * @conn: pointer to the hypervisor connection
282 * @id: the domain ID number
284 * Try to find a domain based on the hypervisor ID number
285 * Note that this won't work for inactive domains which have an ID of -1,
286 * in that case a lookup based on the Name or UUId need to be done instead.
288 * virDomainFree should be used to free the resources after the
289 * domain object is no longer needed.
291 * Returns a new domain object or NULL in case of failure. If the
292 * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
294 virDomainPtr
295 virDomainLookupByID(virConnectPtr conn, int id)
297 VIR_DEBUG("conn=%p, id=%d", conn, id);
299 virResetLastError();
301 virCheckConnectReturn(conn, NULL);
302 virCheckNonNegativeArgGoto(id, error);
304 if (conn->driver->domainLookupByID) {
305 virDomainPtr ret;
306 ret = conn->driver->domainLookupByID(conn, id);
307 if (!ret)
308 goto error;
309 return ret;
312 virReportUnsupportedError();
314 error:
315 virDispatchError(conn);
316 return NULL;
321 * virDomainLookupByUUID:
322 * @conn: pointer to the hypervisor connection
323 * @uuid: the raw UUID for the domain
325 * Try to lookup a domain on the given hypervisor based on its UUID.
327 * virDomainFree should be used to free the resources after the
328 * domain object is no longer needed.
330 * Returns a new domain object or NULL in case of failure. If the
331 * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
333 virDomainPtr
334 virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
336 VIR_UUID_DEBUG(conn, uuid);
338 virResetLastError();
340 virCheckConnectReturn(conn, NULL);
341 virCheckNonNullArgGoto(uuid, error);
343 if (conn->driver->domainLookupByUUID) {
344 virDomainPtr ret;
345 ret = conn->driver->domainLookupByUUID(conn, uuid);
346 if (!ret)
347 goto error;
348 return ret;
351 virReportUnsupportedError();
353 error:
354 virDispatchError(conn);
355 return NULL;
360 * virDomainLookupByUUIDString:
361 * @conn: pointer to the hypervisor connection
362 * @uuidstr: the string UUID for the domain
364 * Try to lookup a domain on the given hypervisor based on its UUID.
366 * virDomainFree should be used to free the resources after the
367 * domain object is no longer needed.
369 * Returns a new domain object or NULL in case of failure. If the
370 * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
372 virDomainPtr
373 virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
375 unsigned char uuid[VIR_UUID_BUFLEN];
376 VIR_DEBUG("conn=%p, uuidstr=%s", conn, NULLSTR(uuidstr));
378 virResetLastError();
380 virCheckConnectReturn(conn, NULL);
381 virCheckNonNullArgGoto(uuidstr, error);
383 if (virUUIDParse(uuidstr, uuid) < 0) {
384 virReportInvalidArg(uuidstr, "%s", _("Invalid UUID"));
385 goto error;
388 return virDomainLookupByUUID(conn, &uuid[0]);
390 error:
391 virDispatchError(conn);
392 return NULL;
397 * virDomainLookupByName:
398 * @conn: pointer to the hypervisor connection
399 * @name: name for the domain
401 * Try to lookup a domain on the given hypervisor based on its name.
403 * virDomainFree should be used to free the resources after the
404 * domain object is no longer needed.
406 * Returns a new domain object or NULL in case of failure. If the
407 * domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised.
409 virDomainPtr
410 virDomainLookupByName(virConnectPtr conn, const char *name)
412 VIR_DEBUG("conn=%p, name=%s", conn, NULLSTR(name));
414 virResetLastError();
416 virCheckConnectReturn(conn, NULL);
417 virCheckNonNullArgGoto(name, error);
419 if (conn->driver->domainLookupByName) {
420 virDomainPtr dom;
421 dom = conn->driver->domainLookupByName(conn, name);
422 if (!dom)
423 goto error;
424 return dom;
427 virReportUnsupportedError();
429 error:
430 virDispatchError(conn);
431 return NULL;
436 * virDomainDestroy:
437 * @domain: a domain object
439 * Destroy the domain object. The running instance is shutdown if not down
440 * already and all resources used by it are given back to the hypervisor. This
441 * does not free the associated virDomainPtr object.
442 * This function may require privileged access.
444 * virDomainDestroy first requests that a guest terminate
445 * (e.g. SIGTERM), then waits for it to comply. After a reasonable
446 * timeout, if the guest still exists, virDomainDestroy will
447 * forcefully terminate the guest (e.g. SIGKILL) if necessary (which
448 * may produce undesirable results, for example unflushed disk cache
449 * in the guest). To avoid this possibility, it's recommended to
450 * instead call virDomainDestroyFlags, sending the
451 * VIR_DOMAIN_DESTROY_GRACEFUL flag.
453 * If the domain is transient and has any snapshot metadata (see
454 * virDomainSnapshotNum()), then that metadata will automatically
455 * be deleted when the domain quits.
457 * Returns 0 in case of success and -1 in case of failure.
460 virDomainDestroy(virDomainPtr domain)
462 virConnectPtr conn;
464 VIR_DOMAIN_DEBUG(domain);
466 virResetLastError();
468 virCheckDomainReturn(domain, -1);
469 conn = domain->conn;
471 virCheckReadOnlyGoto(conn->flags, error);
473 if (conn->driver->domainDestroy) {
474 int ret;
475 ret = conn->driver->domainDestroy(domain);
476 if (ret < 0)
477 goto error;
478 return ret;
481 virReportUnsupportedError();
483 error:
484 virDispatchError(conn);
485 return -1;
490 * virDomainDestroyFlags:
491 * @domain: a domain object
492 * @flags: bitwise-OR of virDomainDestroyFlagsValues
494 * Destroy the domain object. The running instance is shutdown if not down
495 * already and all resources used by it are given back to the hypervisor.
496 * This does not free the associated virDomainPtr object.
497 * This function may require privileged access.
499 * Calling this function with no @flags set (equal to zero) is
500 * equivalent to calling virDomainDestroy, and after a reasonable
501 * timeout will forcefully terminate the guest (e.g. SIGKILL) if
502 * necessary (which may produce undesirable results, for example
503 * unflushed disk cache in the guest). Including
504 * VIR_DOMAIN_DESTROY_GRACEFUL in the flags will prevent the forceful
505 * termination of the guest, and virDomainDestroyFlags will instead
506 * return an error if the guest doesn't terminate by the end of the
507 * timeout; at that time, the management application can decide if
508 * calling again without VIR_DOMAIN_DESTROY_GRACEFUL is appropriate.
510 * Another alternative which may produce cleaner results for the
511 * guest's disks is to use virDomainShutdown() instead, but that
512 * depends on guest support (some hypervisor/guest combinations may
513 * ignore the shutdown request).
516 * Returns 0 in case of success and -1 in case of failure.
519 virDomainDestroyFlags(virDomainPtr domain,
520 unsigned int flags)
522 virConnectPtr conn;
524 VIR_DOMAIN_DEBUG(domain, "flags=0x%x", flags);
526 virResetLastError();
528 virCheckDomainReturn(domain, -1);
529 conn = domain->conn;
531 virCheckReadOnlyGoto(conn->flags, error);
533 if (conn->driver->domainDestroyFlags) {
534 int ret;
535 ret = conn->driver->domainDestroyFlags(domain, flags);
536 if (ret < 0)
537 goto error;
538 return ret;
541 virReportUnsupportedError();
543 error:
544 virDispatchError(conn);
545 return -1;
550 * virDomainFree:
551 * @domain: a domain object
553 * Free the domain object. The running instance is kept alive.
554 * The data structure is freed and should not be used thereafter.
556 * Returns 0 in case of success and -1 in case of failure.
559 virDomainFree(virDomainPtr domain)
561 VIR_DOMAIN_DEBUG(domain);
563 virResetLastError();
565 virCheckDomainReturn(domain, -1);
567 virObjectUnref(domain);
568 return 0;
573 * virDomainRef:
574 * @domain: the domain to hold a reference on
576 * Increment the reference count on the domain. For each
577 * additional call to this method, there shall be a corresponding
578 * call to virDomainFree to release the reference count, once
579 * the caller no longer needs the reference to this object.
581 * This method is typically useful for applications where multiple
582 * threads are using a connection, and it is required that the
583 * connection remain open until all threads have finished using
584 * it. ie, each new thread using a domain would increment
585 * the reference count.
587 * Returns 0 in case of success and -1 in case of failure.
590 virDomainRef(virDomainPtr domain)
592 VIR_DOMAIN_DEBUG(domain, "refs=%d", domain ? domain->parent.u.s.refs : 0);
594 virResetLastError();
596 virCheckDomainReturn(domain, -1);
598 virObjectRef(domain);
599 return 0;
604 * virDomainSuspend:
605 * @domain: a domain object
607 * Suspends an active domain, the process is frozen without further access
608 * to CPU resources and I/O but the memory used by the domain at the
609 * hypervisor level will stay allocated. Use virDomainResume() to reactivate
610 * the domain.
611 * This function may require privileged access.
612 * Moreover, suspend may not be supported if domain is in some
613 * special state like VIR_DOMAIN_PMSUSPENDED.
615 * Returns 0 in case of success and -1 in case of failure.
618 virDomainSuspend(virDomainPtr domain)
620 virConnectPtr conn;
622 VIR_DOMAIN_DEBUG(domain);
624 virResetLastError();
626 virCheckDomainReturn(domain, -1);
627 conn = domain->conn;
629 virCheckReadOnlyGoto(conn->flags, error);
631 if (conn->driver->domainSuspend) {
632 int ret;
633 ret = conn->driver->domainSuspend(domain);
634 if (ret < 0)
635 goto error;
636 return ret;
639 virReportUnsupportedError();
641 error:
642 virDispatchError(domain->conn);
643 return -1;
648 * virDomainResume:
649 * @domain: a domain object
651 * Resume a suspended domain, the process is restarted from the state where
652 * it was frozen by calling virDomainSuspend().
653 * This function may require privileged access
654 * Moreover, resume may not be supported if domain is in some
655 * special state like VIR_DOMAIN_PMSUSPENDED.
657 * Returns 0 in case of success and -1 in case of failure.
660 virDomainResume(virDomainPtr domain)
662 virConnectPtr conn;
664 VIR_DOMAIN_DEBUG(domain);
666 virResetLastError();
668 virCheckDomainReturn(domain, -1);
669 conn = domain->conn;
671 virCheckReadOnlyGoto(conn->flags, error);
673 if (conn->driver->domainResume) {
674 int ret;
675 ret = conn->driver->domainResume(domain);
676 if (ret < 0)
677 goto error;
678 return ret;
681 virReportUnsupportedError();
683 error:
684 virDispatchError(domain->conn);
685 return -1;
690 * virDomainPMSuspendForDuration:
691 * @dom: a domain object
692 * @target: a value from virNodeSuspendTarget
693 * @duration: duration in seconds to suspend, or 0 for indefinite
694 * @flags: extra flags; not used yet, so callers should always pass 0
696 * Attempt to have the guest enter the given @target power management
697 * suspension level. If @duration is non-zero, also schedule the guest to
698 * resume normal operation after that many seconds, if nothing else has
699 * resumed it earlier. Some hypervisors require that @duration be 0, for
700 * an indefinite suspension.
702 * Dependent on hypervisor used, this may require a
703 * guest agent to be available, e.g. QEMU.
705 * Beware that at least for QEMU, the domain's process will be terminated
706 * when VIR_NODE_SUSPEND_TARGET_DISK is used and a new process will be
707 * launched when libvirt is asked to wake up the domain. As a result of
708 * this, any runtime changes, such as device hotplug or memory settings,
709 * are lost unless such changes were made with VIR_DOMAIN_AFFECT_CONFIG
710 * flag.
712 * Returns: 0 on success,
713 * -1 on failure.
716 virDomainPMSuspendForDuration(virDomainPtr dom,
717 unsigned int target,
718 unsigned long long duration,
719 unsigned int flags)
721 virConnectPtr conn;
723 VIR_DOMAIN_DEBUG(dom, "target=%u duration=%llu flags=0x%x",
724 target, duration, flags);
726 virResetLastError();
728 virCheckDomainReturn(dom, -1);
729 conn = dom->conn;
731 virCheckReadOnlyGoto(conn->flags, error);
733 if (conn->driver->domainPMSuspendForDuration) {
734 int ret;
735 ret = conn->driver->domainPMSuspendForDuration(dom, target,
736 duration, flags);
737 if (ret < 0)
738 goto error;
739 return ret;
742 virReportUnsupportedError();
744 error:
745 virDispatchError(conn);
746 return -1;
751 * virDomainPMWakeup:
752 * @dom: a domain object
753 * @flags: extra flags; not used yet, so callers should always pass 0
755 * Inject a wakeup into the guest that previously used
756 * virDomainPMSuspendForDuration, rather than waiting for the
757 * previously requested duration (if any) to elapse.
759 * Returns: 0 on success,
760 * -1 on failure.
763 virDomainPMWakeup(virDomainPtr dom,
764 unsigned int flags)
766 virConnectPtr conn;
768 VIR_DOMAIN_DEBUG(dom, "flags=0x%x", flags);
770 virResetLastError();
772 virCheckDomainReturn(dom, -1);
773 conn = dom->conn;
775 virCheckReadOnlyGoto(conn->flags, error);
777 if (conn->driver->domainPMWakeup) {
778 int ret;
779 ret = conn->driver->domainPMWakeup(dom, flags);
780 if (ret < 0)
781 goto error;
782 return ret;
785 virReportUnsupportedError();
787 error:
788 virDispatchError(conn);
789 return -1;
794 * virDomainSave:
795 * @domain: a domain object
796 * @to: path for the output file
798 * This method will suspend a domain and save its memory contents to
799 * a file on disk. After the call, if successful, the domain is not
800 * listed as running anymore (this ends the life of a transient domain).
801 * Use virDomainRestore() to restore a domain after saving.
803 * See virDomainSaveFlags() for more control. Also, a save file can
804 * be inspected or modified slightly with virDomainSaveImageGetXMLDesc()
805 * and virDomainSaveImageDefineXML().
807 * Returns 0 in case of success and -1 in case of failure.
810 virDomainSave(virDomainPtr domain, const char *to)
812 virConnectPtr conn;
814 VIR_DOMAIN_DEBUG(domain, "to=%s", to);
816 virResetLastError();
818 virCheckDomainReturn(domain, -1);
819 conn = domain->conn;
821 virCheckReadOnlyGoto(conn->flags, error);
822 virCheckNonNullArgGoto(to, error);
824 if (conn->driver->domainSave) {
825 int ret;
826 char *absolute_to;
828 /* We must absolutize the file path as the save is done out of process */
829 if (virFileAbsPath(to, &absolute_to) < 0) {
830 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
831 _("could not build absolute output file path"));
832 goto error;
835 ret = conn->driver->domainSave(domain, absolute_to);
837 VIR_FREE(absolute_to);
839 if (ret < 0)
840 goto error;
841 return ret;
844 virReportUnsupportedError();
846 error:
847 virDispatchError(domain->conn);
848 return -1;
853 * virDomainSaveFlags:
854 * @domain: a domain object
855 * @to: path for the output file
856 * @dxml: (optional) XML config for adjusting guest xml used on restore
857 * @flags: bitwise-OR of virDomainSaveRestoreFlags
859 * This method will suspend a domain and save its memory contents to
860 * a file on disk. After the call, if successful, the domain is not
861 * listed as running anymore (this ends the life of a transient domain).
862 * Use virDomainRestore() to restore a domain after saving.
864 * If the hypervisor supports it, @dxml can be used to alter
865 * host-specific portions of the domain XML that will be used when
866 * restoring an image. For example, it is possible to alter the
867 * backing filename that is associated with a disk device, in order to
868 * prepare for file renaming done as part of backing up the disk
869 * device while the domain is stopped.
871 * If @flags includes VIR_DOMAIN_SAVE_BYPASS_CACHE, then libvirt will
872 * attempt to bypass the file system cache while creating the file, or
873 * fail if it cannot do so for the given system; this can allow less
874 * pressure on file system cache, but also risks slowing saves to NFS.
876 * Normally, the saved state file will remember whether the domain was
877 * running or paused, and restore defaults to the same state.
878 * Specifying VIR_DOMAIN_SAVE_RUNNING or VIR_DOMAIN_SAVE_PAUSED in
879 * @flags will override what state gets saved into the file. These
880 * two flags are mutually exclusive.
882 * A save file can be inspected or modified slightly with
883 * virDomainSaveImageGetXMLDesc() and virDomainSaveImageDefineXML().
885 * Some hypervisors may prevent this operation if there is a current
886 * block job running; in that case, use virDomainBlockJobAbort()
887 * to stop the block job first.
889 * Returns 0 in case of success and -1 in case of failure.
892 virDomainSaveFlags(virDomainPtr domain, const char *to,
893 const char *dxml, unsigned int flags)
895 virConnectPtr conn;
897 VIR_DOMAIN_DEBUG(domain, "to=%s, dxml=%s, flags=0x%x",
898 to, NULLSTR(dxml), flags);
900 virResetLastError();
902 virCheckDomainReturn(domain, -1);
903 conn = domain->conn;
905 virCheckReadOnlyGoto(conn->flags, error);
906 virCheckNonNullArgGoto(to, error);
908 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SAVE_RUNNING,
909 VIR_DOMAIN_SAVE_PAUSED,
910 error);
912 if (conn->driver->domainSaveFlags) {
913 int ret;
914 char *absolute_to;
916 /* We must absolutize the file path as the save is done out of process */
917 if (virFileAbsPath(to, &absolute_to) < 0) {
918 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
919 _("could not build absolute output file path"));
920 goto error;
923 ret = conn->driver->domainSaveFlags(domain, absolute_to, dxml, flags);
925 VIR_FREE(absolute_to);
927 if (ret < 0)
928 goto error;
929 return ret;
932 virReportUnsupportedError();
934 error:
935 virDispatchError(domain->conn);
936 return -1;
941 * virDomainRestore:
942 * @conn: pointer to the hypervisor connection
943 * @from: path to the input file
945 * This method will restore a domain saved to disk by virDomainSave().
947 * See virDomainRestoreFlags() for more control.
949 * Returns 0 in case of success and -1 in case of failure.
952 virDomainRestore(virConnectPtr conn, const char *from)
954 VIR_DEBUG("conn=%p, from=%s", conn, NULLSTR(from));
956 virResetLastError();
958 virCheckConnectReturn(conn, -1);
959 virCheckReadOnlyGoto(conn->flags, error);
960 virCheckNonNullArgGoto(from, error);
962 if (conn->driver->domainRestore) {
963 int ret;
964 char *absolute_from;
966 /* We must absolutize the file path as the restore is done out of process */
967 if (virFileAbsPath(from, &absolute_from) < 0) {
968 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
969 _("could not build absolute input file path"));
970 goto error;
973 ret = conn->driver->domainRestore(conn, absolute_from);
975 VIR_FREE(absolute_from);
977 if (ret < 0)
978 goto error;
979 return ret;
982 virReportUnsupportedError();
984 error:
985 virDispatchError(conn);
986 return -1;
991 * virDomainRestoreFlags:
992 * @conn: pointer to the hypervisor connection
993 * @from: path to the input file
994 * @dxml: (optional) XML config for adjusting guest xml used on restore
995 * @flags: bitwise-OR of virDomainSaveRestoreFlags
997 * This method will restore a domain saved to disk by virDomainSave().
999 * If the hypervisor supports it, @dxml can be used to alter
1000 * host-specific portions of the domain XML that will be used when
1001 * restoring an image. For example, it is possible to alter the
1002 * backing filename that is associated with a disk device, in order to
1003 * prepare for file renaming done as part of backing up the disk
1004 * device while the domain is stopped.
1006 * If @flags includes VIR_DOMAIN_SAVE_BYPASS_CACHE, then libvirt will
1007 * attempt to bypass the file system cache while restoring the file, or
1008 * fail if it cannot do so for the given system; this can allow less
1009 * pressure on file system cache, but also risks slowing restores from NFS.
1011 * Normally, the saved state file will remember whether the domain was
1012 * running or paused, and restore defaults to the same state.
1013 * Specifying VIR_DOMAIN_SAVE_RUNNING or VIR_DOMAIN_SAVE_PAUSED in
1014 * @flags will override the default read from the file. These two
1015 * flags are mutually exclusive.
1017 * Returns 0 in case of success and -1 in case of failure.
1020 virDomainRestoreFlags(virConnectPtr conn, const char *from, const char *dxml,
1021 unsigned int flags)
1023 VIR_DEBUG("conn=%p, from=%s, dxml=%s, flags=0x%x",
1024 conn, NULLSTR(from), NULLSTR(dxml), flags);
1026 virResetLastError();
1028 virCheckConnectReturn(conn, -1);
1029 virCheckReadOnlyGoto(conn->flags, error);
1030 virCheckNonNullArgGoto(from, error);
1032 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SAVE_RUNNING,
1033 VIR_DOMAIN_SAVE_PAUSED,
1034 error);
1036 if (conn->driver->domainRestoreFlags) {
1037 int ret;
1038 char *absolute_from;
1040 /* We must absolutize the file path as the restore is done out of process */
1041 if (virFileAbsPath(from, &absolute_from) < 0) {
1042 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
1043 _("could not build absolute input file path"));
1044 goto error;
1047 ret = conn->driver->domainRestoreFlags(conn, absolute_from, dxml,
1048 flags);
1050 VIR_FREE(absolute_from);
1052 if (ret < 0)
1053 goto error;
1054 return ret;
1057 virReportUnsupportedError();
1059 error:
1060 virDispatchError(conn);
1061 return -1;
1066 * virDomainSaveImageGetXMLDesc:
1067 * @conn: pointer to the hypervisor connection
1068 * @file: path to saved state file
1069 * @flags: bitwise-OR of supported virDomainSaveImageXMLFlags
1071 * This method will extract the XML describing the domain at the time
1072 * a saved state file was created. @file must be a file created
1073 * previously by virDomainSave() or virDomainSaveFlags().
1075 * No security-sensitive data will be included unless @flags contains
1076 * VIR_DOMAIN_SAVE_IMAGE_XML_SECURE; this flag is rejected on read-only
1077 * connections.
1079 * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of
1080 * error. The caller must free() the returned value.
1082 char *
1083 virDomainSaveImageGetXMLDesc(virConnectPtr conn, const char *file,
1084 unsigned int flags)
1086 VIR_DEBUG("conn=%p, file=%s, flags=0x%x",
1087 conn, NULLSTR(file), flags);
1089 virResetLastError();
1091 virCheckConnectReturn(conn, NULL);
1092 virCheckNonNullArgGoto(file, error);
1094 if ((conn->flags & VIR_CONNECT_RO) &&
1095 (flags & VIR_DOMAIN_SAVE_IMAGE_XML_SECURE)) {
1096 virReportError(VIR_ERR_OPERATION_DENIED, "%s",
1097 _("virDomainSaveImageGetXMLDesc with secure flag"));
1098 goto error;
1101 if (conn->driver->domainSaveImageGetXMLDesc) {
1102 char *ret;
1103 char *absolute_file;
1105 /* We must absolutize the file path as the read is done out of process */
1106 if (virFileAbsPath(file, &absolute_file) < 0) {
1107 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
1108 _("could not build absolute input file path"));
1109 goto error;
1112 ret = conn->driver->domainSaveImageGetXMLDesc(conn, absolute_file,
1113 flags);
1115 VIR_FREE(absolute_file);
1117 if (!ret)
1118 goto error;
1119 return ret;
1122 virReportUnsupportedError();
1124 error:
1125 virDispatchError(conn);
1126 return NULL;
1131 * virDomainSaveImageDefineXML:
1132 * @conn: pointer to the hypervisor connection
1133 * @file: path to saved state file
1134 * @dxml: XML config for adjusting guest xml used on restore
1135 * @flags: bitwise-OR of virDomainSaveRestoreFlags
1137 * This updates the definition of a domain stored in a saved state
1138 * file. @file must be a file created previously by virDomainSave()
1139 * or virDomainSaveFlags().
1141 * @dxml can be used to alter host-specific portions of the domain XML
1142 * that will be used when restoring an image. For example, it is
1143 * possible to alter the backing filename that is associated with a
1144 * disk device, to match renaming done as part of backing up the disk
1145 * device while the domain is stopped.
1147 * Normally, the saved state file will remember whether the domain was
1148 * running or paused, and restore defaults to the same state.
1149 * Specifying VIR_DOMAIN_SAVE_RUNNING or VIR_DOMAIN_SAVE_PAUSED in
1150 * @flags will override the default saved into the file; omitting both
1151 * leaves the file's default unchanged. These two flags are mutually
1152 * exclusive.
1154 * Returns 0 in case of success and -1 in case of failure.
1157 virDomainSaveImageDefineXML(virConnectPtr conn, const char *file,
1158 const char *dxml, unsigned int flags)
1160 VIR_DEBUG("conn=%p, file=%s, dxml=%s, flags=0x%x",
1161 conn, NULLSTR(file), NULLSTR(dxml), flags);
1163 virResetLastError();
1165 virCheckConnectReturn(conn, -1);
1166 virCheckReadOnlyGoto(conn->flags, error);
1167 virCheckNonNullArgGoto(file, error);
1168 virCheckNonNullArgGoto(dxml, error);
1170 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SAVE_RUNNING,
1171 VIR_DOMAIN_SAVE_PAUSED,
1172 error);
1174 if (conn->driver->domainSaveImageDefineXML) {
1175 int ret;
1176 char *absolute_file;
1178 /* We must absolutize the file path as the read is done out of process */
1179 if (virFileAbsPath(file, &absolute_file) < 0) {
1180 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
1181 _("could not build absolute input file path"));
1182 goto error;
1185 ret = conn->driver->domainSaveImageDefineXML(conn, absolute_file,
1186 dxml, flags);
1188 VIR_FREE(absolute_file);
1190 if (ret < 0)
1191 goto error;
1192 return ret;
1195 virReportUnsupportedError();
1197 error:
1198 virDispatchError(conn);
1199 return -1;
1204 * virDomainCoreDump:
1205 * @domain: a domain object
1206 * @to: path for the core file
1207 * @flags: bitwise-OR of virDomainCoreDumpFlags
1209 * This method will dump the core of a domain on a given file for analysis.
1210 * Note that for remote Xen Daemon the file path will be interpreted in
1211 * the remote host. Hypervisors may require the user to manually ensure
1212 * proper permissions on the file named by @to.
1214 * If @flags includes VIR_DUMP_CRASH, then leave the guest shut off with
1215 * a crashed state after the dump completes. If @flags includes
1216 * VIR_DUMP_LIVE, then make the core dump while continuing to allow
1217 * the guest to run; otherwise, the guest is suspended during the dump.
1218 * VIR_DUMP_RESET flag forces reset of the guest after dump.
1219 * The above three flags are mutually exclusive.
1221 * Additionally, if @flags includes VIR_DUMP_BYPASS_CACHE, then libvirt
1222 * will attempt to bypass the file system cache while creating the file,
1223 * or fail if it cannot do so for the given system; this can allow less
1224 * pressure on file system cache, but also risks slowing saves to NFS.
1226 * For more control over the output format, see virDomainCoreDumpWithFormat().
1228 * Returns 0 in case of success and -1 in case of failure.
1231 virDomainCoreDump(virDomainPtr domain, const char *to, unsigned int flags)
1233 virConnectPtr conn;
1235 VIR_DOMAIN_DEBUG(domain, "to=%s, flags=0x%x", to, flags);
1237 virResetLastError();
1239 virCheckDomainReturn(domain, -1);
1240 conn = domain->conn;
1242 virCheckReadOnlyGoto(conn->flags, error);
1243 virCheckNonNullArgGoto(to, error);
1245 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DUMP_CRASH, VIR_DUMP_LIVE, error);
1246 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DUMP_CRASH, VIR_DUMP_RESET, error);
1247 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DUMP_LIVE, VIR_DUMP_RESET, error);
1249 if (conn->driver->domainCoreDump) {
1250 int ret;
1251 char *absolute_to;
1253 /* We must absolutize the file path as the save is done out of process */
1254 if (virFileAbsPath(to, &absolute_to) < 0) {
1255 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
1256 _("could not build absolute core file path"));
1257 goto error;
1260 ret = conn->driver->domainCoreDump(domain, absolute_to, flags);
1262 VIR_FREE(absolute_to);
1264 if (ret < 0)
1265 goto error;
1266 return ret;
1269 virReportUnsupportedError();
1271 error:
1272 virDispatchError(domain->conn);
1273 return -1;
1277 * virDomainCoreDumpWithFormat:
1278 * @domain: a domain object
1279 * @to: path for the core file
1280 * @dumpformat: format of domain memory's dump (one of virDomainCoreDumpFormat enum)
1281 * @flags: bitwise-OR of virDomainCoreDumpFlags
1283 * This method will dump the core of a domain on a given file for analysis.
1284 * Note that for remote Xen Daemon the file path will be interpreted in
1285 * the remote host. Hypervisors may require the user to manually ensure
1286 * proper permissions on the file named by @to.
1288 * @dumpformat controls which format the dump will have; use of
1289 * VIR_DOMAIN_CORE_DUMP_FORMAT_RAW mirrors what virDomainCoreDump() will
1290 * perform. Not all hypervisors are able to support all formats.
1292 * If @flags includes VIR_DUMP_CRASH, then leave the guest shut off with
1293 * a crashed state after the dump completes. If @flags includes
1294 * VIR_DUMP_LIVE, then make the core dump while continuing to allow
1295 * the guest to run; otherwise, the guest is suspended during the dump.
1296 * VIR_DUMP_RESET flag forces reset of the guest after dump.
1297 * The above three flags are mutually exclusive.
1299 * Additionally, if @flags includes VIR_DUMP_BYPASS_CACHE, then libvirt
1300 * will attempt to bypass the file system cache while creating the file,
1301 * or fail if it cannot do so for the given system; this can allow less
1302 * pressure on file system cache, but also risks slowing saves to NFS.
1304 * Returns 0 in case of success and -1 in case of failure.
1307 virDomainCoreDumpWithFormat(virDomainPtr domain, const char *to,
1308 unsigned int dumpformat, unsigned int flags)
1310 virConnectPtr conn;
1312 VIR_DOMAIN_DEBUG(domain, "to=%s, dumpformat=%u, flags=0x%x",
1313 to, dumpformat, flags);
1315 virResetLastError();
1317 virCheckDomainReturn(domain, -1);
1318 conn = domain->conn;
1320 virCheckReadOnlyGoto(conn->flags, error);
1321 virCheckNonNullArgGoto(to, error);
1323 if (dumpformat >= VIR_DOMAIN_CORE_DUMP_FORMAT_LAST) {
1324 virReportInvalidArg(flags, _("dumpformat '%d' is not supported"),
1325 dumpformat);
1326 goto error;
1329 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DUMP_CRASH, VIR_DUMP_LIVE, error);
1330 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DUMP_CRASH, VIR_DUMP_RESET, error);
1331 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DUMP_LIVE, VIR_DUMP_RESET, error);
1333 if (conn->driver->domainCoreDumpWithFormat) {
1334 int ret;
1335 char *absolute_to;
1337 /* We must absolutize the file path as the save is done out of process */
1338 if (virFileAbsPath(to, &absolute_to) < 0) {
1339 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
1340 _("could not build absolute core file path"));
1341 goto error;
1344 ret = conn->driver->domainCoreDumpWithFormat(domain, absolute_to,
1345 dumpformat, flags);
1347 VIR_FREE(absolute_to);
1349 if (ret < 0)
1350 goto error;
1351 return ret;
1354 virReportUnsupportedError();
1356 error:
1357 virDispatchError(domain->conn);
1358 return -1;
1363 * virDomainScreenshot:
1364 * @domain: a domain object
1365 * @stream: stream to use as output
1366 * @screen: monitor ID to take screenshot from
1367 * @flags: extra flags; not used yet, so callers should always pass 0
1369 * Take a screenshot of current domain console as a stream. The image format
1370 * is hypervisor specific. Moreover, some hypervisors supports multiple
1371 * displays per domain. These can be distinguished by @screen argument.
1373 * This call sets up a stream; subsequent use of stream API is necessary
1374 * to transfer actual data, determine how much data is successfully
1375 * transferred, and detect any errors.
1377 * The screen ID is the sequential number of screen. In case of multiple
1378 * graphics cards, heads are enumerated before devices, e.g. having
1379 * two graphics cards, both with four heads, screen ID 5 addresses
1380 * the second head on the second card.
1382 * Returns a string representing the mime-type of the image format, or
1383 * NULL upon error. The caller must free() the returned value.
1385 char *
1386 virDomainScreenshot(virDomainPtr domain,
1387 virStreamPtr stream,
1388 unsigned int screen,
1389 unsigned int flags)
1391 VIR_DOMAIN_DEBUG(domain, "stream=%p, flags=0x%x", stream, flags);
1393 virResetLastError();
1395 virCheckDomainReturn(domain, NULL);
1396 virCheckStreamGoto(stream, error);
1397 virCheckReadOnlyGoto(domain->conn->flags, error);
1399 if (domain->conn != stream->conn) {
1400 virReportInvalidArg(stream,
1401 _("stream must match connection of domain '%s'"),
1402 domain->name);
1403 goto error;
1406 if (domain->conn->driver->domainScreenshot) {
1407 char *ret;
1408 ret = domain->conn->driver->domainScreenshot(domain, stream,
1409 screen, flags);
1411 if (ret == NULL)
1412 goto error;
1413 return ret;
1416 virReportUnsupportedError();
1418 error:
1419 virDispatchError(domain->conn);
1420 return NULL;
1425 * virDomainShutdown:
1426 * @domain: a domain object
1428 * Shutdown a domain, the domain object is still usable thereafter, but
1429 * the domain OS is being stopped. Note that the guest OS may ignore the
1430 * request. Additionally, the hypervisor may check and support the domain
1431 * 'on_poweroff' XML setting resulting in a domain that reboots instead of
1432 * shutting down. For guests that react to a shutdown request, the differences
1433 * from virDomainDestroy() are that the guests disk storage will be in a
1434 * stable state rather than having the (virtual) power cord pulled, and
1435 * this command returns as soon as the shutdown request is issued rather
1436 * than blocking until the guest is no longer running.
1438 * If the domain is transient and has any snapshot metadata (see
1439 * virDomainSnapshotNum()), then that metadata will automatically
1440 * be deleted when the domain quits.
1442 * Returns 0 in case of success and -1 in case of failure.
1445 virDomainShutdown(virDomainPtr domain)
1447 virConnectPtr conn;
1449 VIR_DOMAIN_DEBUG(domain);
1451 virResetLastError();
1453 virCheckDomainReturn(domain, -1);
1454 conn = domain->conn;
1456 virCheckReadOnlyGoto(conn->flags, error);
1458 if (conn->driver->domainShutdown) {
1459 int ret;
1460 ret = conn->driver->domainShutdown(domain);
1461 if (ret < 0)
1462 goto error;
1463 return ret;
1466 virReportUnsupportedError();
1468 error:
1469 virDispatchError(domain->conn);
1470 return -1;
1475 * virDomainShutdownFlags:
1476 * @domain: a domain object
1477 * @flags: bitwise-OR of virDomainShutdownFlagValues
1479 * Shutdown a domain, the domain object is still usable thereafter but
1480 * the domain OS is being stopped. Note that the guest OS may ignore the
1481 * request. Additionally, the hypervisor may check and support the domain
1482 * 'on_poweroff' XML setting resulting in a domain that reboots instead of
1483 * shutting down. For guests that react to a shutdown request, the differences
1484 * from virDomainDestroy() are that the guest's disk storage will be in a
1485 * stable state rather than having the (virtual) power cord pulled, and
1486 * this command returns as soon as the shutdown request is issued rather
1487 * than blocking until the guest is no longer running.
1489 * If the domain is transient and has any snapshot metadata (see
1490 * virDomainSnapshotNum()), then that metadata will automatically
1491 * be deleted when the domain quits.
1493 * If @flags is set to zero, then the hypervisor will choose the
1494 * method of shutdown it considers best. To have greater control
1495 * pass one or more of the virDomainShutdownFlagValues. The order
1496 * in which the hypervisor tries each shutdown method is undefined,
1497 * and a hypervisor is not required to support all methods.
1499 * To use guest agent (VIR_DOMAIN_SHUTDOWN_GUEST_AGENT) the domain XML
1500 * must have <channel> configured.
1502 * Returns 0 in case of success and -1 in case of failure.
1505 virDomainShutdownFlags(virDomainPtr domain, unsigned int flags)
1507 virConnectPtr conn;
1509 VIR_DOMAIN_DEBUG(domain, "flags=0x%x", flags);
1511 virResetLastError();
1513 virCheckDomainReturn(domain, -1);
1514 conn = domain->conn;
1516 virCheckReadOnlyGoto(conn->flags, error);
1518 if (conn->driver->domainShutdownFlags) {
1519 int ret;
1520 ret = conn->driver->domainShutdownFlags(domain, flags);
1521 if (ret < 0)
1522 goto error;
1523 return ret;
1526 virReportUnsupportedError();
1528 error:
1529 virDispatchError(domain->conn);
1530 return -1;
1535 * virDomainReboot:
1536 * @domain: a domain object
1537 * @flags: bitwise-OR of virDomainRebootFlagValues
1539 * Reboot a domain, the domain object is still usable thereafter, but
1540 * the domain OS is being stopped for a restart.
1541 * Note that the guest OS may ignore the request.
1542 * Additionally, the hypervisor may check and support the domain
1543 * 'on_reboot' XML setting resulting in a domain that shuts down instead
1544 * of rebooting.
1546 * If @flags is set to zero, then the hypervisor will choose the
1547 * method of shutdown it considers best. To have greater control
1548 * pass one or more of the virDomainRebootFlagValues. The order
1549 * in which the hypervisor tries each shutdown method is undefined,
1550 * and a hypervisor is not required to support all methods.
1552 * To use guest agent (VIR_DOMAIN_REBOOT_GUEST_AGENT) the domain XML
1553 * must have <channel> configured.
1555 * Due to implementation limitations in some drivers (the qemu driver,
1556 * for instance) it is not advised to migrate or save a guest that is
1557 * rebooting as a result of this API. Migrating such a guest can lead
1558 * to a plain shutdown on the destination.
1560 * Returns 0 in case of success and -1 in case of failure.
1563 virDomainReboot(virDomainPtr domain, unsigned int flags)
1565 virConnectPtr conn;
1567 VIR_DOMAIN_DEBUG(domain, "flags=0x%x", flags);
1569 virResetLastError();
1571 virCheckDomainReturn(domain, -1);
1572 conn = domain->conn;
1574 virCheckReadOnlyGoto(conn->flags, error);
1576 if (conn->driver->domainReboot) {
1577 int ret;
1578 ret = conn->driver->domainReboot(domain, flags);
1579 if (ret < 0)
1580 goto error;
1581 return ret;
1584 virReportUnsupportedError();
1586 error:
1587 virDispatchError(domain->conn);
1588 return -1;
1593 * virDomainReset:
1594 * @domain: a domain object
1595 * @flags: extra flags; not used yet, so callers should always pass 0
1597 * Reset a domain immediately without any guest OS shutdown.
1598 * Reset emulates the power reset button on a machine, where all
1599 * hardware sees the RST line set and reinitializes internal state.
1601 * Note that there is a risk of data loss caused by reset without any
1602 * guest OS shutdown.
1604 * Returns 0 in case of success and -1 in case of failure.
1607 virDomainReset(virDomainPtr domain, unsigned int flags)
1609 virConnectPtr conn;
1611 VIR_DOMAIN_DEBUG(domain, "flags=0x%x", flags);
1613 virResetLastError();
1615 virCheckDomainReturn(domain, -1);
1616 conn = domain->conn;
1618 virCheckReadOnlyGoto(conn->flags, error);
1620 if (conn->driver->domainReset) {
1621 int ret;
1622 ret = conn->driver->domainReset(domain, flags);
1623 if (ret < 0)
1624 goto error;
1625 return ret;
1628 virReportUnsupportedError();
1630 error:
1631 virDispatchError(domain->conn);
1632 return -1;
1637 * virDomainGetName:
1638 * @domain: a domain object
1640 * Get the public name for that domain
1642 * Returns a pointer to the name or NULL, the string need not be deallocated
1643 * its lifetime will be the same as the domain object.
1645 const char *
1646 virDomainGetName(virDomainPtr domain)
1648 VIR_DEBUG("domain=%p", domain);
1650 virResetLastError();
1652 virCheckDomainReturn(domain, NULL);
1654 return domain->name;
1659 * virDomainGetUUID:
1660 * @domain: a domain object
1661 * @uuid: pointer to a VIR_UUID_BUFLEN bytes array
1663 * Get the UUID for a domain
1665 * Returns -1 in case of error, 0 in case of success
1668 virDomainGetUUID(virDomainPtr domain, unsigned char *uuid)
1670 VIR_DOMAIN_DEBUG(domain, "uuid=%p", uuid);
1672 virResetLastError();
1674 virCheckDomainReturn(domain, -1);
1675 virCheckNonNullArgGoto(uuid, error);
1677 memcpy(uuid, &domain->uuid[0], VIR_UUID_BUFLEN);
1679 return 0;
1681 error:
1682 virDispatchError(domain->conn);
1683 return -1;
1688 * virDomainGetUUIDString:
1689 * @domain: a domain object
1690 * @buf: pointer to a VIR_UUID_STRING_BUFLEN bytes array
1692 * Get the UUID for a domain as string. For more information about
1693 * UUID see RFC4122.
1695 * Returns -1 in case of error, 0 in case of success
1698 virDomainGetUUIDString(virDomainPtr domain, char *buf)
1700 VIR_DOMAIN_DEBUG(domain, "buf=%p", buf);
1702 virResetLastError();
1704 virCheckDomainReturn(domain, -1);
1705 virCheckNonNullArgGoto(buf, error);
1707 virUUIDFormat(domain->uuid, buf);
1708 return 0;
1710 error:
1711 virDispatchError(domain->conn);
1712 return -1;
1717 * virDomainGetID:
1718 * @domain: a domain object
1720 * Get the hypervisor ID number for the domain
1722 * Returns the domain ID number or (unsigned int) -1 in case of error
1724 unsigned int
1725 virDomainGetID(virDomainPtr domain)
1727 VIR_DOMAIN_DEBUG(domain);
1729 virResetLastError();
1731 virCheckDomainReturn(domain, (unsigned int)-1);
1733 return domain->id;
1738 * virDomainGetOSType:
1739 * @domain: a domain object
1741 * Get the type of domain operation system.
1743 * Returns the new string or NULL in case of error, the string must be
1744 * freed by the caller.
1746 char *
1747 virDomainGetOSType(virDomainPtr domain)
1749 virConnectPtr conn;
1751 VIR_DOMAIN_DEBUG(domain);
1753 virResetLastError();
1755 virCheckDomainReturn(domain, NULL);
1756 conn = domain->conn;
1758 if (conn->driver->domainGetOSType) {
1759 char *ret;
1760 ret = conn->driver->domainGetOSType(domain);
1761 if (!ret)
1762 goto error;
1763 return ret;
1766 virReportUnsupportedError();
1768 error:
1769 virDispatchError(domain->conn);
1770 return NULL;
1775 * virDomainGetMaxMemory:
1776 * @domain: a domain object or NULL
1778 * Retrieve the maximum amount of physical memory allocated to a
1779 * domain. If domain is NULL, then this get the amount of memory reserved
1780 * to Domain0 i.e. the domain where the application runs.
1782 * Returns the memory size in kibibytes (blocks of 1024 bytes), or 0 in
1783 * case of error.
1785 unsigned long
1786 virDomainGetMaxMemory(virDomainPtr domain)
1788 virConnectPtr conn;
1790 VIR_DOMAIN_DEBUG(domain);
1792 virResetLastError();
1794 virCheckDomainReturn(domain, 0);
1795 conn = domain->conn;
1797 if (conn->driver->domainGetMaxMemory) {
1798 unsigned long long ret;
1799 ret = conn->driver->domainGetMaxMemory(domain);
1800 if (ret == 0)
1801 goto error;
1802 if ((unsigned long) ret != ret) {
1803 virReportError(VIR_ERR_OVERFLOW, _("result too large: %llu"),
1804 ret);
1805 goto error;
1807 return ret;
1810 virReportUnsupportedError();
1812 error:
1813 virDispatchError(domain->conn);
1814 return 0;
1819 * virDomainSetMaxMemory:
1820 * @domain: a domain object or NULL
1821 * @memory: the memory size in kibibytes (blocks of 1024 bytes)
1823 * Dynamically change the maximum amount of physical memory allocated to a
1824 * domain. If domain is NULL, then this change the amount of memory reserved
1825 * to Domain0 i.e. the domain where the application runs.
1826 * This function may require privileged access to the hypervisor.
1828 * This command is hypervisor-specific for whether active, persistent,
1829 * or both configurations are changed; for more control, use
1830 * virDomainSetMemoryFlags().
1832 * Returns 0 in case of success and -1 in case of failure.
1835 virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
1837 virConnectPtr conn;
1839 VIR_DOMAIN_DEBUG(domain, "memory=%lu", memory);
1841 virResetLastError();
1843 virCheckDomainReturn(domain, -1);
1844 conn = domain->conn;
1846 virCheckReadOnlyGoto(conn->flags, error);
1847 virCheckNonZeroArgGoto(memory, error);
1849 if (virMemoryMaxValue(true) / 1024 <= memory) {
1850 virReportError(VIR_ERR_OVERFLOW, _("input too large: %lu"),
1851 memory);
1852 goto error;
1855 if (conn->driver->domainSetMaxMemory) {
1856 int ret;
1857 ret = conn->driver->domainSetMaxMemory(domain, memory);
1858 if (ret < 0)
1859 goto error;
1860 return ret;
1863 virReportUnsupportedError();
1865 error:
1866 virDispatchError(domain->conn);
1867 return -1;
1872 * virDomainSetMemory:
1873 * @domain: a domain object or NULL
1874 * @memory: the memory size in kibibytes (blocks of 1024 bytes)
1876 * Dynamically change the target amount of physical memory allocated to a
1877 * domain. If domain is NULL, then this change the amount of memory reserved
1878 * to Domain0 i.e. the domain where the application runs.
1879 * This function may require privileged access to the hypervisor.
1881 * This command is hypervisor-specific for whether active, persistent,
1882 * or both configurations are changed; for more control, use
1883 * virDomainSetMemoryFlags().
1885 * Returns 0 in case of success and -1 in case of failure.
1888 virDomainSetMemory(virDomainPtr domain, unsigned long memory)
1890 virConnectPtr conn;
1892 VIR_DOMAIN_DEBUG(domain, "memory=%lu", memory);
1894 virResetLastError();
1896 virCheckDomainReturn(domain, -1);
1897 conn = domain->conn;
1899 virCheckReadOnlyGoto(conn->flags, error);
1900 virCheckNonZeroArgGoto(memory, error);
1902 if (virMemoryMaxValue(true) / 1024 <= memory) {
1903 virReportError(VIR_ERR_OVERFLOW, _("input too large: %lu"),
1904 memory);
1905 goto error;
1908 if (conn->driver->domainSetMemory) {
1909 int ret;
1910 ret = conn->driver->domainSetMemory(domain, memory);
1911 if (ret < 0)
1912 goto error;
1913 return ret;
1916 virReportUnsupportedError();
1918 error:
1919 virDispatchError(domain->conn);
1920 return -1;
1925 * virDomainSetMemoryFlags:
1926 * @domain: a domain object or NULL
1927 * @memory: the memory size in kibibytes (blocks of 1024 bytes)
1928 * @flags: bitwise-OR of virDomainMemoryModFlags
1930 * Dynamically change the target amount of physical memory allocated to a
1931 * domain. If domain is NULL, then this change the amount of memory reserved
1932 * to Domain0 i.e. the domain where the application runs.
1933 * This function may require privileged access to the hypervisor.
1935 * @flags may include VIR_DOMAIN_AFFECT_LIVE or VIR_DOMAIN_AFFECT_CONFIG.
1936 * Both flags may be set. If VIR_DOMAIN_AFFECT_LIVE is set, the change affects
1937 * a running domain and will fail if domain is not active.
1938 * If VIR_DOMAIN_AFFECT_CONFIG is set, the change affects persistent state,
1939 * and will fail for transient domains. If neither flag is specified
1940 * (that is, @flags is VIR_DOMAIN_AFFECT_CURRENT), then an inactive domain
1941 * modifies persistent setup, while an active domain is hypervisor-dependent
1942 * on whether just live or both live and persistent state is changed.
1943 * If VIR_DOMAIN_MEM_MAXIMUM is set, the change affects domain's maximum memory
1944 * size rather than current memory size.
1945 * Not all hypervisors can support all flag combinations.
1947 * Returns 0 in case of success, -1 in case of failure.
1950 virDomainSetMemoryFlags(virDomainPtr domain, unsigned long memory,
1951 unsigned int flags)
1953 virConnectPtr conn;
1955 VIR_DOMAIN_DEBUG(domain, "memory=%lu, flags=0x%x", memory, flags);
1957 virResetLastError();
1959 virCheckDomainReturn(domain, -1);
1960 conn = domain->conn;
1962 virCheckReadOnlyGoto(conn->flags, error);
1963 virCheckNonZeroArgGoto(memory, error);
1965 if (virMemoryMaxValue(true) / 1024 <= memory) {
1966 virReportError(VIR_ERR_OVERFLOW, _("input too large: %lu"),
1967 memory);
1968 goto error;
1971 if (conn->driver->domainSetMemoryFlags) {
1972 int ret;
1973 ret = conn->driver->domainSetMemoryFlags(domain, memory, flags);
1974 if (ret < 0)
1975 goto error;
1976 return ret;
1979 virReportUnsupportedError();
1981 error:
1982 virDispatchError(domain->conn);
1983 return -1;
1988 * virDomainSetMemoryStatsPeriod:
1989 * @domain: a domain object or NULL
1990 * @period: the period in seconds for stats collection
1991 * @flags: bitwise-OR of virDomainMemoryModFlags
1993 * Dynamically change the domain memory balloon driver statistics collection
1994 * period. Use 0 to disable and a positive value to enable.
1996 * @flags may include VIR_DOMAIN_AFFECT_LIVE or VIR_DOMAIN_AFFECT_CONFIG.
1997 * Both flags may be set. If VIR_DOMAIN_AFFECT_LIVE is set, the change affects
1998 * a running domain and will fail if domain is not active.
1999 * If VIR_DOMAIN_AFFECT_CONFIG is set, the change affects persistent state,
2000 * and will fail for transient domains. If neither flag is specified
2001 * (that is, @flags is VIR_DOMAIN_AFFECT_CURRENT), then an inactive domain
2002 * modifies persistent setup, while an active domain is hypervisor-dependent
2003 * on whether just live or both live and persistent state is changed.
2005 * Not all hypervisors can support all flag combinations.
2007 * Returns 0 in case of success, -1 in case of failure.
2010 virDomainSetMemoryStatsPeriod(virDomainPtr domain, int period,
2011 unsigned int flags)
2013 virConnectPtr conn;
2015 VIR_DOMAIN_DEBUG(domain, "period=%d, flags=0x%x", period, flags);
2017 virResetLastError();
2019 virCheckDomainReturn(domain, -1);
2020 conn = domain->conn;
2022 virCheckReadOnlyGoto(conn->flags, error);
2024 /* This must be positive to set the balloon collection period */
2025 virCheckNonNegativeArgGoto(period, error);
2027 if (conn->driver->domainSetMemoryStatsPeriod) {
2028 int ret;
2029 ret = conn->driver->domainSetMemoryStatsPeriod(domain, period, flags);
2030 if (ret < 0)
2031 goto error;
2032 return ret;
2035 virReportUnsupportedError();
2037 error:
2038 virDispatchError(domain->conn);
2039 return -1;
2044 * virDomainSetMemoryParameters:
2045 * @domain: pointer to domain object
2046 * @params: pointer to memory parameter objects
2047 * @nparams: number of memory parameter (this value can be the same or
2048 * less than the number of parameters supported)
2049 * @flags: bitwise-OR of virDomainModificationImpact
2051 * Change all or a subset of the memory tunables.
2052 * This function may require privileged access to the hypervisor.
2054 * Possible values for all *_limit memory tunables are in range from 0 to
2055 * VIR_DOMAIN_MEMORY_PARAM_UNLIMITED.
2057 * Returns -1 in case of error, 0 in case of success.
2060 virDomainSetMemoryParameters(virDomainPtr domain,
2061 virTypedParameterPtr params,
2062 int nparams, unsigned int flags)
2064 virConnectPtr conn;
2066 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d, flags=0x%x",
2067 params, nparams, flags);
2068 VIR_TYPED_PARAMS_DEBUG(params, nparams);
2070 virResetLastError();
2072 virCheckDomainReturn(domain, -1);
2073 conn = domain->conn;
2075 virCheckReadOnlyGoto(conn->flags, error);
2076 virCheckNonNullArgGoto(params, error);
2077 virCheckPositiveArgGoto(nparams, error);
2079 if (virTypedParameterValidateSet(conn, params, nparams) < 0)
2080 goto error;
2082 if (conn->driver->domainSetMemoryParameters) {
2083 int ret;
2084 ret = conn->driver->domainSetMemoryParameters(domain, params, nparams, flags);
2085 if (ret < 0)
2086 goto error;
2087 return ret;
2090 virReportUnsupportedError();
2092 error:
2093 virDispatchError(domain->conn);
2094 return -1;
2099 * virDomainGetMemoryParameters:
2100 * @domain: pointer to domain object
2101 * @params: pointer to memory parameter object
2102 * (return value, allocated by the caller)
2103 * @nparams: pointer to number of memory parameters; input and output
2104 * @flags: bitwise-OR of virDomainModificationImpact and virTypedParameterFlags
2106 * Get all memory parameters. On input, @nparams gives the size of the
2107 * @params array; on output, @nparams gives how many slots were filled
2108 * with parameter information, which might be less but will not exceed
2109 * the input value.
2111 * As a special case, calling with @params as NULL and @nparams as 0 on
2112 * input will cause @nparams on output to contain the number of parameters
2113 * supported by the hypervisor. The caller should then allocate @params
2114 * array, i.e. (sizeof(@virTypedParameter) * @nparams) bytes and call the API
2115 * again.
2117 * Here is a sample code snippet:
2119 * if (virDomainGetMemoryParameters(dom, NULL, &nparams, 0) == 0 &&
2120 * nparams != 0) {
2121 * if ((params = malloc(sizeof(*params) * nparams)) == NULL)
2122 * goto error;
2123 * memset(params, 0, sizeof(*params) * nparams);
2124 * if (virDomainGetMemoryParameters(dom, params, &nparams, 0))
2125 * goto error;
2128 * This function may require privileged access to the hypervisor. This function
2129 * expects the caller to allocate the @params.
2131 * Returns -1 in case of error, 0 in case of success.
2134 virDomainGetMemoryParameters(virDomainPtr domain,
2135 virTypedParameterPtr params,
2136 int *nparams, unsigned int flags)
2138 virConnectPtr conn;
2140 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d, flags=0x%x",
2141 params, (nparams) ? *nparams : -1, flags);
2143 virResetLastError();
2145 virCheckDomainReturn(domain, -1);
2146 virCheckNonNullArgGoto(nparams, error);
2147 virCheckNonNegativeArgGoto(*nparams, error);
2148 if (*nparams != 0)
2149 virCheckNonNullArgGoto(params, error);
2151 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
2152 VIR_DRV_FEATURE_TYPED_PARAM_STRING))
2153 flags |= VIR_TYPED_PARAM_STRING_OKAY;
2155 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_AFFECT_LIVE,
2156 VIR_DOMAIN_AFFECT_CONFIG,
2157 error);
2159 conn = domain->conn;
2161 if (conn->driver->domainGetMemoryParameters) {
2162 int ret;
2163 ret = conn->driver->domainGetMemoryParameters(domain, params, nparams, flags);
2164 if (ret < 0)
2165 goto error;
2166 return ret;
2168 virReportUnsupportedError();
2170 error:
2171 virDispatchError(domain->conn);
2172 return -1;
2177 * virDomainSetNumaParameters:
2178 * @domain: pointer to domain object
2179 * @params: pointer to numa parameter objects
2180 * @nparams: number of numa parameters (this value can be the same or
2181 * less than the number of parameters supported)
2182 * @flags: bitwise-OR of virDomainModificationImpact
2184 * Change all or a subset of the numa tunables.
2185 * This function may require privileged access to the hypervisor.
2187 * Returns -1 in case of error, 0 in case of success.
2190 virDomainSetNumaParameters(virDomainPtr domain,
2191 virTypedParameterPtr params,
2192 int nparams, unsigned int flags)
2194 virConnectPtr conn;
2196 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d, flags=0x%x",
2197 params, nparams, flags);
2198 VIR_TYPED_PARAMS_DEBUG(params, nparams);
2200 virResetLastError();
2202 virCheckDomainReturn(domain, -1);
2203 virCheckReadOnlyGoto(domain->conn->flags, error);
2204 virCheckNonNullArgGoto(params, error);
2205 virCheckPositiveArgGoto(nparams, error);
2206 if (virTypedParameterValidateSet(domain->conn, params, nparams) < 0)
2207 goto error;
2209 conn = domain->conn;
2211 if (conn->driver->domainSetNumaParameters) {
2212 int ret;
2213 ret = conn->driver->domainSetNumaParameters(domain, params, nparams,
2214 flags);
2215 if (ret < 0)
2216 goto error;
2217 return ret;
2220 virReportUnsupportedError();
2222 error:
2223 virDispatchError(domain->conn);
2224 return -1;
2229 * virDomainGetNumaParameters:
2230 * @domain: pointer to domain object
2231 * @params: pointer to numa parameter object
2232 * (return value, allocated by the caller)
2233 * @nparams: pointer to number of numa parameters
2234 * @flags: bitwise-OR of virDomainModificationImpact and virTypedParameterFlags
2236 * Get all numa parameters. On input, @nparams gives the size of the
2237 * @params array; on output, @nparams gives how many slots were filled
2238 * with parameter information, which might be less but will not exceed
2239 * the input value.
2241 * As a special case, calling with @params as NULL and @nparams as 0 on
2242 * input will cause @nparams on output to contain the number of parameters
2243 * supported by the hypervisor. The caller should then allocate @params
2244 * array, i.e. (sizeof(@virTypedParameter) * @nparams) bytes and call the API
2245 * again.
2247 * See virDomainGetMemoryParameters() for an equivalent usage example.
2249 * This function may require privileged access to the hypervisor. This function
2250 * expects the caller to allocate the @params.
2252 * Returns -1 in case of error, 0 in case of success.
2255 virDomainGetNumaParameters(virDomainPtr domain,
2256 virTypedParameterPtr params,
2257 int *nparams, unsigned int flags)
2259 virConnectPtr conn;
2261 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d, flags=0x%x",
2262 params, (nparams) ? *nparams : -1, flags);
2264 virResetLastError();
2266 virCheckDomainReturn(domain, -1);
2267 virCheckNonNullArgGoto(nparams, error);
2268 virCheckNonNegativeArgGoto(*nparams, error);
2269 if (*nparams != 0)
2270 virCheckNonNullArgGoto(params, error);
2272 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
2273 VIR_DRV_FEATURE_TYPED_PARAM_STRING))
2274 flags |= VIR_TYPED_PARAM_STRING_OKAY;
2276 conn = domain->conn;
2278 if (conn->driver->domainGetNumaParameters) {
2279 int ret;
2280 ret = conn->driver->domainGetNumaParameters(domain, params, nparams,
2281 flags);
2282 if (ret < 0)
2283 goto error;
2284 return ret;
2286 virReportUnsupportedError();
2288 error:
2289 virDispatchError(domain->conn);
2290 return -1;
2295 * virDomainSetBlkioParameters:
2296 * @domain: pointer to domain object
2297 * @params: pointer to blkio parameter objects
2298 * @nparams: number of blkio parameters (this value can be the same or
2299 * less than the number of parameters supported)
2300 * @flags: bitwise-OR of virDomainModificationImpact
2302 * Change all or a subset of the blkio tunables.
2303 * This function may require privileged access to the hypervisor.
2305 * Returns -1 in case of error, 0 in case of success.
2308 virDomainSetBlkioParameters(virDomainPtr domain,
2309 virTypedParameterPtr params,
2310 int nparams, unsigned int flags)
2312 virConnectPtr conn;
2314 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d, flags=0x%x",
2315 params, nparams, flags);
2316 VIR_TYPED_PARAMS_DEBUG(params, nparams);
2318 virResetLastError();
2320 virCheckDomainReturn(domain, -1);
2321 conn = domain->conn;
2323 virCheckReadOnlyGoto(conn->flags, error);
2324 virCheckNonNullArgGoto(params, error);
2325 virCheckNonNegativeArgGoto(nparams, error);
2327 if (virTypedParameterValidateSet(conn, params, nparams) < 0)
2328 goto error;
2330 if (conn->driver->domainSetBlkioParameters) {
2331 int ret;
2332 ret = conn->driver->domainSetBlkioParameters(domain, params, nparams, flags);
2333 if (ret < 0)
2334 goto error;
2335 return ret;
2338 virReportUnsupportedError();
2340 error:
2341 virDispatchError(domain->conn);
2342 return -1;
2347 * virDomainGetBlkioParameters:
2348 * @domain: pointer to domain object
2349 * @params: pointer to blkio parameter object
2350 * (return value, allocated by the caller)
2351 * @nparams: pointer to number of blkio parameters; input and output
2352 * @flags: bitwise-OR of virDomainModificationImpact and virTypedParameterFlags
2354 * Get all blkio parameters. On input, @nparams gives the size of the
2355 * @params array; on output, @nparams gives how many slots were filled
2356 * with parameter information, which might be less but will not exceed
2357 * the input value.
2359 * As a special case, calling with @params as NULL and @nparams as 0 on
2360 * input will cause @nparams on output to contain the number of parameters
2361 * supported by the hypervisor. The caller should then allocate @params
2362 * array, i.e. (sizeof(@virTypedParameter) * @nparams) bytes and call the API
2363 * again.
2365 * See virDomainGetMemoryParameters() for an equivalent usage example.
2367 * This function may require privileged access to the hypervisor. This function
2368 * expects the caller to allocate the @params.
2370 * Returns -1 in case of error, 0 in case of success.
2373 virDomainGetBlkioParameters(virDomainPtr domain,
2374 virTypedParameterPtr params,
2375 int *nparams, unsigned int flags)
2377 virConnectPtr conn;
2379 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d, flags=0x%x",
2380 params, (nparams) ? *nparams : -1, flags);
2382 virResetLastError();
2384 virCheckDomainReturn(domain, -1);
2385 virCheckNonNullArgGoto(nparams, error);
2386 virCheckNonNegativeArgGoto(*nparams, error);
2387 if (*nparams != 0)
2388 virCheckNonNullArgGoto(params, error);
2390 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
2391 VIR_DRV_FEATURE_TYPED_PARAM_STRING))
2392 flags |= VIR_TYPED_PARAM_STRING_OKAY;
2394 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_AFFECT_LIVE,
2395 VIR_DOMAIN_AFFECT_CONFIG,
2396 error);
2398 conn = domain->conn;
2400 if (conn->driver->domainGetBlkioParameters) {
2401 int ret;
2402 ret = conn->driver->domainGetBlkioParameters(domain, params, nparams, flags);
2403 if (ret < 0)
2404 goto error;
2405 return ret;
2407 virReportUnsupportedError();
2409 error:
2410 virDispatchError(domain->conn);
2411 return -1;
2416 * virDomainGetInfo:
2417 * @domain: a domain object
2418 * @info: pointer to a virDomainInfo structure allocated by the user
2420 * Extract information about a domain. Note that if the connection
2421 * used to get the domain is limited only a partial set of the information
2422 * can be extracted.
2424 * Returns 0 in case of success and -1 in case of failure.
2427 virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
2429 virConnectPtr conn;
2431 VIR_DOMAIN_DEBUG(domain, "info=%p", info);
2433 virResetLastError();
2435 if (info)
2436 memset(info, 0, sizeof(*info));
2438 virCheckDomainReturn(domain, -1);
2439 virCheckNonNullArgGoto(info, error);
2441 conn = domain->conn;
2443 if (conn->driver->domainGetInfo) {
2444 int ret;
2445 ret = conn->driver->domainGetInfo(domain, info);
2446 if (ret < 0)
2447 goto error;
2448 return ret;
2451 virReportUnsupportedError();
2453 error:
2454 virDispatchError(domain->conn);
2455 return -1;
2460 * virDomainGetState:
2461 * @domain: a domain object
2462 * @state: returned state of the domain (one of virDomainState)
2463 * @reason: returned reason which led to @state (one of virDomain*Reason
2464 * corresponding to the current state); it is allowed to be NULL
2465 * @flags: extra flags; not used yet, so callers should always pass 0
2467 * Extract domain state. Each state can be accompanied with a reason (if known)
2468 * which led to the state.
2470 * Returns 0 in case of success and -1 in case of failure.
2473 virDomainGetState(virDomainPtr domain,
2474 int *state,
2475 int *reason,
2476 unsigned int flags)
2478 virConnectPtr conn;
2480 VIR_DOMAIN_DEBUG(domain, "state=%p, reason=%p, flags=0x%x",
2481 state, reason, flags);
2483 virResetLastError();
2485 virCheckDomainReturn(domain, -1);
2486 virCheckNonNullArgGoto(state, error);
2488 conn = domain->conn;
2489 if (conn->driver->domainGetState) {
2490 int ret;
2491 ret = conn->driver->domainGetState(domain, state, reason, flags);
2492 if (ret < 0)
2493 goto error;
2494 return ret;
2497 virReportUnsupportedError();
2499 error:
2500 virDispatchError(domain->conn);
2501 return -1;
2506 * virDomainGetControlInfo:
2507 * @domain: a domain object
2508 * @info: pointer to a virDomainControlInfo structure allocated by the user
2509 * @flags: extra flags; not used yet, so callers should always pass 0
2511 * Extract details about current state of control interface to a domain.
2513 * Returns 0 in case of success and -1 in case of failure.
2516 virDomainGetControlInfo(virDomainPtr domain,
2517 virDomainControlInfoPtr info,
2518 unsigned int flags)
2520 virConnectPtr conn;
2522 VIR_DOMAIN_DEBUG(domain, "info=%p, flags=0x%x", info, flags);
2524 virResetLastError();
2526 virCheckDomainReturn(domain, -1);
2527 virCheckNonNullArgGoto(info, error);
2529 conn = domain->conn;
2530 if (conn->driver->domainGetControlInfo) {
2531 int ret;
2532 ret = conn->driver->domainGetControlInfo(domain, info, flags);
2533 if (ret < 0)
2534 goto error;
2535 return ret;
2538 virReportUnsupportedError();
2540 error:
2541 virDispatchError(domain->conn);
2542 return -1;
2547 * virDomainGetXMLDesc:
2548 * @domain: a domain object
2549 * @flags: bitwise-OR of virDomainXMLFlags
2551 * Provide an XML description of the domain. The description may be reused
2552 * later to relaunch the domain with virDomainCreateXML().
2554 * No security-sensitive data will be included unless @flags contains
2555 * VIR_DOMAIN_XML_SECURE; this flag is rejected on read-only
2556 * connections. If @flags includes VIR_DOMAIN_XML_INACTIVE, then the
2557 * XML represents the configuration that will be used on the next boot
2558 * of a persistent domain; otherwise, the configuration represents the
2559 * currently running domain. If @flags contains
2560 * VIR_DOMAIN_XML_UPDATE_CPU, then the portion of the domain XML
2561 * describing CPU capabilities is modified to match actual
2562 * capabilities of the host.
2564 * If @flags contains VIR_DOMAIN_XML_MIGRATABLE, the XML is altered to
2565 * assist in migrations, since the source and destination may be
2566 * running different libvirt versions. This may include trimming
2567 * redundant or default information that might confuse an older
2568 * recipient, or exposing internal details that aid a newer recipient;
2569 * this flag is rejected on read-only connections, and the resulting
2570 * XML might not validate against the schema, so it is mainly for
2571 * internal use.
2573 * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case
2574 * of error. The caller must free() the returned value.
2576 char *
2577 virDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
2579 virConnectPtr conn;
2581 VIR_DOMAIN_DEBUG(domain, "flags=0x%x", flags);
2583 virResetLastError();
2585 virCheckDomainReturn(domain, NULL);
2586 conn = domain->conn;
2588 if ((conn->flags & VIR_CONNECT_RO) &&
2589 (flags & (VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_MIGRATABLE))) {
2590 virReportError(VIR_ERR_OPERATION_DENIED, "%s",
2591 _("virDomainGetXMLDesc with secure flag"));
2592 goto error;
2595 if (conn->driver->domainGetXMLDesc) {
2596 char *ret;
2597 ret = conn->driver->domainGetXMLDesc(domain, flags);
2598 if (!ret)
2599 goto error;
2600 return ret;
2603 virReportUnsupportedError();
2605 error:
2606 virDispatchError(domain->conn);
2607 return NULL;
2612 * virConnectDomainXMLFromNative:
2613 * @conn: a connection object
2614 * @nativeFormat: configuration format importing from
2615 * @nativeConfig: the configuration data to import
2616 * @flags: extra flags; not used yet, so callers should always pass 0
2618 * Reads native configuration data describing a domain, and
2619 * generates libvirt domain XML. The format of the native
2620 * data is hypervisor dependent.
2622 * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case
2623 * of error. The caller must free() the returned value.
2625 char *
2626 virConnectDomainXMLFromNative(virConnectPtr conn,
2627 const char *nativeFormat,
2628 const char *nativeConfig,
2629 unsigned int flags)
2631 VIR_DEBUG("conn=%p, format=%s, config=%s, flags=0x%x",
2632 conn, NULLSTR(nativeFormat), NULLSTR(nativeConfig), flags);
2634 virResetLastError();
2636 virCheckConnectReturn(conn, NULL);
2637 virCheckReadOnlyGoto(conn->flags, error);
2639 virCheckNonNullArgGoto(nativeFormat, error);
2640 virCheckNonNullArgGoto(nativeConfig, error);
2642 if (conn->driver->connectDomainXMLFromNative) {
2643 char *ret;
2644 ret = conn->driver->connectDomainXMLFromNative(conn,
2645 nativeFormat,
2646 nativeConfig,
2647 flags);
2648 if (!ret)
2649 goto error;
2650 return ret;
2653 virReportUnsupportedError();
2655 error:
2656 virDispatchError(conn);
2657 return NULL;
2662 * virConnectDomainXMLToNative:
2663 * @conn: a connection object
2664 * @nativeFormat: configuration format exporting to
2665 * @domainXml: the domain configuration to export
2666 * @flags: extra flags; not used yet, so callers should always pass 0
2668 * Reads a domain XML configuration document, and generates
2669 * a native configuration file describing the domain.
2670 * The format of the native data is hypervisor dependent.
2672 * Returns a 0 terminated UTF-8 encoded native config datafile, or
2673 * NULL in case of error. The caller must free() the returned value.
2675 char *
2676 virConnectDomainXMLToNative(virConnectPtr conn,
2677 const char *nativeFormat,
2678 const char *domainXml,
2679 unsigned int flags)
2681 VIR_DEBUG("conn=%p, format=%s, xml=%s, flags=0x%x",
2682 conn, NULLSTR(nativeFormat), NULLSTR(domainXml), flags);
2684 virResetLastError();
2686 virCheckConnectReturn(conn, NULL);
2687 virCheckReadOnlyGoto(conn->flags, error);
2689 virCheckNonNullArgGoto(nativeFormat, error);
2690 virCheckNonNullArgGoto(domainXml, error);
2692 if (conn->driver->connectDomainXMLToNative) {
2693 char *ret;
2694 ret = conn->driver->connectDomainXMLToNative(conn,
2695 nativeFormat,
2696 domainXml,
2697 flags);
2698 if (!ret)
2699 goto error;
2700 return ret;
2703 virReportUnsupportedError();
2705 error:
2706 virDispatchError(conn);
2707 return NULL;
2712 * Sequence v1:
2714 * Dst: Prepare
2715 * - Get ready to accept incoming VM
2716 * - Generate optional cookie to pass to src
2718 * Src: Perform
2719 * - Start migration and wait for send completion
2720 * - Kill off VM if successful, resume if failed
2722 * Dst: Finish
2723 * - Wait for recv completion and check status
2724 * - Kill off VM if unsuccessful
2727 static virDomainPtr
2728 virDomainMigrateVersion1(virDomainPtr domain,
2729 virConnectPtr dconn,
2730 unsigned long flags,
2731 const char *dname,
2732 const char *uri,
2733 unsigned long bandwidth)
2735 virDomainPtr ddomain = NULL;
2736 char *uri_out = NULL;
2737 char *cookie = NULL;
2738 int cookielen = 0, ret;
2739 virDomainInfo info;
2740 unsigned int destflags;
2742 VIR_DOMAIN_DEBUG(domain,
2743 "dconn=%p, flags=0x%lx, dname=%s, uri=%s, bandwidth=%lu",
2744 dconn, flags, NULLSTR(dname), NULLSTR(uri), bandwidth);
2746 ret = virDomainGetInfo(domain, &info);
2747 if (ret == 0 && info.state == VIR_DOMAIN_PAUSED)
2748 flags |= VIR_MIGRATE_PAUSED;
2750 destflags = flags & ~(VIR_MIGRATE_ABORT_ON_ERROR |
2751 VIR_MIGRATE_AUTO_CONVERGE);
2753 /* Prepare the migration.
2755 * The destination host may return a cookie, or leave cookie as
2756 * NULL.
2758 * The destination host MUST set uri_out if uri_in is NULL.
2760 * If uri_in is non-NULL, then the destination host may modify
2761 * the URI by setting uri_out. If it does not wish to modify
2762 * the URI, it should leave uri_out as NULL.
2764 if (dconn->driver->domainMigratePrepare
2765 (dconn, &cookie, &cookielen, uri, &uri_out, destflags, dname,
2766 bandwidth) == -1)
2767 goto done;
2769 if (uri == NULL && uri_out == NULL) {
2770 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
2771 _("domainMigratePrepare did not set uri"));
2772 goto done;
2774 if (uri_out)
2775 uri = uri_out; /* Did domainMigratePrepare change URI? */
2777 /* Perform the migration. The driver isn't supposed to return
2778 * until the migration is complete.
2780 if (domain->conn->driver->domainMigratePerform
2781 (domain, cookie, cookielen, uri, flags, dname, bandwidth) == -1)
2782 goto done;
2784 /* Get the destination domain and return it or error.
2785 * 'domain' no longer actually exists at this point
2786 * (or so we hope), but we still use the object in memory
2787 * in order to get the name.
2789 dname = dname ? dname : domain->name;
2790 if (dconn->driver->domainMigrateFinish)
2791 ddomain = dconn->driver->domainMigrateFinish
2792 (dconn, dname, cookie, cookielen, uri, destflags);
2793 else
2794 ddomain = virDomainLookupByName(dconn, dname);
2796 done:
2797 VIR_FREE(uri_out);
2798 VIR_FREE(cookie);
2799 return ddomain;
2804 * Sequence v2:
2806 * Src: DumpXML
2807 * - Generate XML to pass to dst
2809 * Dst: Prepare
2810 * - Get ready to accept incoming VM
2811 * - Generate optional cookie to pass to src
2813 * Src: Perform
2814 * - Start migration and wait for send completion
2815 * - Kill off VM if successful, resume if failed
2817 * Dst: Finish
2818 * - Wait for recv completion and check status
2819 * - Kill off VM if unsuccessful
2822 static virDomainPtr
2823 virDomainMigrateVersion2(virDomainPtr domain,
2824 virConnectPtr dconn,
2825 unsigned long flags,
2826 const char *dname,
2827 const char *uri,
2828 unsigned long bandwidth)
2830 virDomainPtr ddomain = NULL;
2831 char *uri_out = NULL;
2832 char *cookie = NULL;
2833 char *dom_xml = NULL;
2834 int cookielen = 0, ret;
2835 virDomainInfo info;
2836 virErrorPtr orig_err = NULL;
2837 unsigned int getxml_flags = 0;
2838 int cancelled;
2839 unsigned long destflags;
2841 VIR_DOMAIN_DEBUG(domain,
2842 "dconn=%p, flags=0x%lx, dname=%s, uri=%s, bandwidth=%lu",
2843 dconn, flags, NULLSTR(dname), NULLSTR(uri), bandwidth);
2845 /* Prepare the migration.
2847 * The destination host may return a cookie, or leave cookie as
2848 * NULL.
2850 * The destination host MUST set uri_out if uri_in is NULL.
2852 * If uri_in is non-NULL, then the destination host may modify
2853 * the URI by setting uri_out. If it does not wish to modify
2854 * the URI, it should leave uri_out as NULL.
2857 /* In version 2 of the protocol, the prepare step is slightly
2858 * different. We fetch the domain XML of the source domain
2859 * and pass it to Prepare2.
2861 if (!domain->conn->driver->domainGetXMLDesc) {
2862 virReportUnsupportedError();
2863 return NULL;
2866 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
2867 VIR_DRV_FEATURE_XML_MIGRATABLE)) {
2868 getxml_flags |= VIR_DOMAIN_XML_MIGRATABLE;
2869 } else {
2870 getxml_flags |= VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_UPDATE_CPU;
2873 dom_xml = domain->conn->driver->domainGetXMLDesc(domain, getxml_flags);
2874 if (!dom_xml)
2875 return NULL;
2877 ret = virDomainGetInfo(domain, &info);
2878 if (ret == 0 && info.state == VIR_DOMAIN_PAUSED)
2879 flags |= VIR_MIGRATE_PAUSED;
2881 destflags = flags & ~(VIR_MIGRATE_ABORT_ON_ERROR |
2882 VIR_MIGRATE_AUTO_CONVERGE);
2884 VIR_DEBUG("Prepare2 %p flags=0x%lx", dconn, destflags);
2885 ret = dconn->driver->domainMigratePrepare2
2886 (dconn, &cookie, &cookielen, uri, &uri_out, destflags, dname,
2887 bandwidth, dom_xml);
2888 VIR_FREE(dom_xml);
2889 if (ret == -1)
2890 goto done;
2892 if (uri == NULL && uri_out == NULL) {
2893 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
2894 _("domainMigratePrepare2 did not set uri"));
2895 cancelled = 1;
2896 /* Make sure Finish doesn't overwrite the error */
2897 virErrorPreserveLast(&orig_err);
2898 goto finish;
2900 if (uri_out)
2901 uri = uri_out; /* Did domainMigratePrepare2 change URI? */
2903 /* Perform the migration. The driver isn't supposed to return
2904 * until the migration is complete.
2906 VIR_DEBUG("Perform %p", domain->conn);
2907 ret = domain->conn->driver->domainMigratePerform
2908 (domain, cookie, cookielen, uri, flags, dname, bandwidth);
2910 /* Perform failed. Make sure Finish doesn't overwrite the error */
2911 if (ret < 0)
2912 virErrorPreserveLast(&orig_err);
2914 /* If Perform returns < 0, then we need to cancel the VM
2915 * startup on the destination
2917 cancelled = ret < 0 ? 1 : 0;
2919 finish:
2920 /* In version 2 of the migration protocol, we pass the
2921 * status code from the sender to the destination host,
2922 * so it can do any cleanup if the migration failed.
2924 dname = dname ? dname : domain->name;
2925 VIR_DEBUG("Finish2 %p ret=%d", dconn, ret);
2926 ddomain = dconn->driver->domainMigrateFinish2
2927 (dconn, dname, cookie, cookielen, uri, destflags, cancelled);
2928 if (cancelled && ddomain)
2929 VIR_ERROR(_("finish step ignored that migration was cancelled"));
2931 done:
2932 virErrorRestore(&orig_err);
2933 VIR_FREE(uri_out);
2934 VIR_FREE(cookie);
2935 return ddomain;
2940 * Sequence v3:
2942 * Src: Begin
2943 * - Generate XML to pass to dst
2944 * - Generate optional cookie to pass to dst
2946 * Dst: Prepare
2947 * - Get ready to accept incoming VM
2948 * - Generate optional cookie to pass to src
2950 * Src: Perform
2951 * - Start migration and wait for send completion
2952 * - Generate optional cookie to pass to dst
2954 * Dst: Finish
2955 * - Wait for recv completion and check status
2956 * - Kill off VM if failed, resume if success
2957 * - Generate optional cookie to pass to src
2959 * Src: Confirm
2960 * - Kill off VM if success, resume if failed
2962 * If useParams is true, params and nparams contain migration parameters and
2963 * we know it's safe to call the API which supports extensible parameters.
2964 * Otherwise, we have to use xmlin, dname, uri, and bandwidth and pass them
2965 * to the old-style APIs.
2967 static virDomainPtr
2968 virDomainMigrateVersion3Full(virDomainPtr domain,
2969 virConnectPtr dconn,
2970 const char *xmlin,
2971 const char *dname,
2972 const char *uri,
2973 unsigned long long bandwidth,
2974 virTypedParameterPtr params,
2975 int nparams,
2976 bool useParams,
2977 unsigned int flags)
2979 virDomainPtr ddomain = NULL;
2980 char *uri_out = NULL;
2981 char *cookiein = NULL;
2982 char *cookieout = NULL;
2983 char *dom_xml = NULL;
2984 int cookieinlen = 0;
2985 int cookieoutlen = 0;
2986 int ret;
2987 virDomainInfo info;
2988 virErrorPtr orig_err = NULL;
2989 int cancelled = 1;
2990 unsigned long protection = 0;
2991 bool notify_source = true;
2992 unsigned int destflags;
2993 int state;
2994 virTypedParameterPtr tmp;
2996 VIR_DOMAIN_DEBUG(domain,
2997 "dconn=%p, xmlin=%s, dname=%s, uri=%s, bandwidth=%llu, "
2998 "params=%p, nparams=%d, useParams=%d, flags=0x%x",
2999 dconn, NULLSTR(xmlin), NULLSTR(dname), NULLSTR(uri),
3000 bandwidth, params, nparams, useParams, flags);
3001 VIR_TYPED_PARAMS_DEBUG(params, nparams);
3003 if ((!useParams &&
3004 (!domain->conn->driver->domainMigrateBegin3 ||
3005 !domain->conn->driver->domainMigratePerform3 ||
3006 !domain->conn->driver->domainMigrateConfirm3 ||
3007 !dconn->driver->domainMigratePrepare3 ||
3008 !dconn->driver->domainMigrateFinish3)) ||
3009 (useParams &&
3010 (!domain->conn->driver->domainMigrateBegin3Params ||
3011 !domain->conn->driver->domainMigratePerform3Params ||
3012 !domain->conn->driver->domainMigrateConfirm3Params ||
3013 !dconn->driver->domainMigratePrepare3Params ||
3014 !dconn->driver->domainMigrateFinish3Params))) {
3015 virReportUnsupportedError();
3016 return NULL;
3019 if (virTypedParamsCopy(&tmp, params, nparams) < 0)
3020 return NULL;
3021 params = tmp;
3023 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3024 VIR_DRV_FEATURE_MIGRATE_CHANGE_PROTECTION))
3025 protection = VIR_MIGRATE_CHANGE_PROTECTION;
3027 VIR_DEBUG("Begin3 %p", domain->conn);
3028 if (useParams) {
3029 dom_xml = domain->conn->driver->domainMigrateBegin3Params
3030 (domain, params, nparams, &cookieout, &cookieoutlen,
3031 flags | protection);
3032 } else {
3033 dom_xml = domain->conn->driver->domainMigrateBegin3
3034 (domain, xmlin, &cookieout, &cookieoutlen,
3035 flags | protection, dname, bandwidth);
3037 if (!dom_xml)
3038 goto done;
3040 if (useParams) {
3041 /* If source is new enough to support extensible migration parameters,
3042 * it's certainly new enough to support virDomainGetState. */
3043 ret = virDomainGetState(domain, &state, NULL, 0);
3044 } else {
3045 ret = virDomainGetInfo(domain, &info);
3046 state = info.state;
3048 if (ret == 0 && state == VIR_DOMAIN_PAUSED)
3049 flags |= VIR_MIGRATE_PAUSED;
3051 destflags = flags & ~(VIR_MIGRATE_ABORT_ON_ERROR |
3052 VIR_MIGRATE_AUTO_CONVERGE);
3054 VIR_DEBUG("Prepare3 %p flags=0x%x", dconn, destflags);
3055 VIR_STEAL_PTR(cookiein, cookieout);
3056 cookieinlen = cookieoutlen;
3057 cookieoutlen = 0;
3058 if (useParams) {
3059 if (virTypedParamsReplaceString(&params, &nparams,
3060 VIR_MIGRATE_PARAM_DEST_XML,
3061 dom_xml) < 0)
3062 goto done;
3063 ret = dconn->driver->domainMigratePrepare3Params
3064 (dconn, params, nparams, cookiein, cookieinlen,
3065 &cookieout, &cookieoutlen, &uri_out, destflags);
3066 } else {
3067 ret = dconn->driver->domainMigratePrepare3
3068 (dconn, cookiein, cookieinlen, &cookieout, &cookieoutlen,
3069 uri, &uri_out, destflags, dname, bandwidth, dom_xml);
3071 if (ret == -1) {
3072 if (protection) {
3073 /* Begin already started a migration job so we need to cancel it by
3074 * calling Confirm while making sure it doesn't overwrite the error
3076 virErrorPreserveLast(&orig_err);
3077 goto confirm;
3078 } else {
3079 goto done;
3083 /* Did domainMigratePrepare3 change URI? */
3084 if (uri_out) {
3085 uri = uri_out;
3086 if (useParams &&
3087 virTypedParamsReplaceString(&params, &nparams,
3088 VIR_MIGRATE_PARAM_URI,
3089 uri_out) < 0) {
3090 cancelled = 1;
3091 virErrorPreserveLast(&orig_err);
3092 goto finish;
3094 } else if (!uri &&
3095 virTypedParamsGetString(params, nparams,
3096 VIR_MIGRATE_PARAM_URI, &uri) <= 0) {
3097 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
3098 _("domainMigratePrepare3 did not set uri"));
3099 cancelled = 1;
3100 virErrorPreserveLast(&orig_err);
3101 goto finish;
3104 if (flags & VIR_MIGRATE_OFFLINE) {
3105 VIR_DEBUG("Offline migration, skipping Perform phase");
3106 VIR_FREE(cookieout);
3107 cookieoutlen = 0;
3108 cancelled = 0;
3109 goto finish;
3112 /* Perform the migration. The driver isn't supposed to return
3113 * until the migration is complete. The src VM should remain
3114 * running, but in paused state until the destination can
3115 * confirm migration completion.
3117 VIR_DEBUG("Perform3 %p uri=%s", domain->conn, uri);
3118 VIR_FREE(cookiein);
3119 VIR_STEAL_PTR(cookiein, cookieout);
3120 cookieinlen = cookieoutlen;
3121 cookieoutlen = 0;
3122 /* dconnuri not relevant in non-P2P modes, so left NULL here */
3123 if (useParams) {
3124 ret = domain->conn->driver->domainMigratePerform3Params
3125 (domain, NULL, params, nparams, cookiein, cookieinlen,
3126 &cookieout, &cookieoutlen, flags | protection);
3127 } else {
3128 ret = domain->conn->driver->domainMigratePerform3
3129 (domain, NULL, cookiein, cookieinlen,
3130 &cookieout, &cookieoutlen, NULL,
3131 uri, flags | protection, dname, bandwidth);
3134 /* Perform failed. Make sure Finish doesn't overwrite the error */
3135 if (ret < 0) {
3136 virErrorPreserveLast(&orig_err);
3137 /* Perform failed so we don't need to call confirm to let source know
3138 * about the failure.
3140 notify_source = false;
3143 /* If Perform returns < 0, then we need to cancel the VM
3144 * startup on the destination
3146 cancelled = ret < 0 ? 1 : 0;
3148 finish:
3150 * The status code from the source is passed to the destination.
3151 * The dest can cleanup if the source indicated it failed to
3152 * send all migration data. Returns NULL for ddomain if
3153 * the dest was unable to complete migration.
3155 VIR_DEBUG("Finish3 %p ret=%d", dconn, ret);
3156 VIR_FREE(cookiein);
3157 VIR_STEAL_PTR(cookiein, cookieout);
3158 cookieinlen = cookieoutlen;
3159 cookieoutlen = 0;
3160 if (useParams) {
3161 if (virTypedParamsGetString(params, nparams,
3162 VIR_MIGRATE_PARAM_DEST_NAME, NULL) <= 0 &&
3163 virTypedParamsReplaceString(&params, &nparams,
3164 VIR_MIGRATE_PARAM_DEST_NAME,
3165 domain->name) < 0) {
3166 ddomain = NULL;
3167 } else {
3168 ddomain = dconn->driver->domainMigrateFinish3Params
3169 (dconn, params, nparams, cookiein, cookieinlen,
3170 &cookieout, &cookieoutlen, destflags, cancelled);
3172 } else {
3173 dname = dname ? dname : domain->name;
3174 ddomain = dconn->driver->domainMigrateFinish3
3175 (dconn, dname, cookiein, cookieinlen, &cookieout, &cookieoutlen,
3176 NULL, uri, destflags, cancelled);
3179 if (cancelled) {
3180 if (ddomain) {
3181 VIR_ERROR(_("finish step ignored that migration was cancelled"));
3182 } else {
3183 /* If Finish reported a useful error, use it instead of the
3184 * original "migration unexpectedly failed" error.
3186 * This is ugly but we can't do better with the APIs we have. We
3187 * only replace the error if Finish was called with cancelled == 1
3188 * and reported a real error (old libvirt would report an error
3189 * from RPC instead of MIGRATE_FINISH_OK), which only happens when
3190 * the domain died on destination. To further reduce a possibility
3191 * of false positives we also check that Perform returned
3192 * VIR_ERR_OPERATION_FAILED.
3194 if (orig_err &&
3195 orig_err->domain == VIR_FROM_QEMU &&
3196 orig_err->code == VIR_ERR_OPERATION_FAILED) {
3197 virErrorPtr err = virGetLastError();
3198 if (err &&
3199 err->domain == VIR_FROM_QEMU &&
3200 err->code != VIR_ERR_MIGRATE_FINISH_OK) {
3201 virFreeError(orig_err);
3202 orig_err = NULL;
3208 /* If ddomain is NULL, then we were unable to start
3209 * the guest on the target, and must restart on the
3210 * source. There is a small chance that the ddomain
3211 * is NULL due to an RPC failure, in which case
3212 * ddomain could in fact be running on the dest.
3213 * The lock manager plugins should take care of
3214 * safety in this scenario.
3216 cancelled = ddomain == NULL ? 1 : 0;
3218 /* If finish3 set an error, and we don't have an earlier
3219 * one we need to preserve it in case confirm3 overwrites
3221 if (!orig_err)
3222 virErrorPreserveLast(&orig_err);
3224 confirm:
3226 * If cancelled, then src VM will be restarted, else it will be killed.
3227 * Don't do this if migration failed on source and thus it was already
3228 * cancelled there.
3230 if (notify_source) {
3231 VIR_DEBUG("Confirm3 %p ret=%d domain=%p", domain->conn, ret, domain);
3232 VIR_FREE(cookiein);
3233 VIR_STEAL_PTR(cookiein, cookieout);
3234 cookieinlen = cookieoutlen;
3235 cookieoutlen = 0;
3236 if (useParams) {
3237 ret = domain->conn->driver->domainMigrateConfirm3Params
3238 (domain, params, nparams, cookiein, cookieinlen,
3239 flags | protection, cancelled);
3240 } else {
3241 ret = domain->conn->driver->domainMigrateConfirm3
3242 (domain, cookiein, cookieinlen,
3243 flags | protection, cancelled);
3245 /* If Confirm3 returns -1, there's nothing more we can
3246 * do, but fortunately worst case is that there is a
3247 * domain left in 'paused' state on source.
3249 if (ret < 0) {
3250 VIR_WARN("Guest %s probably left in 'paused' state on source",
3251 domain->name);
3255 done:
3256 virErrorRestore(&orig_err);
3257 VIR_FREE(dom_xml);
3258 VIR_FREE(uri_out);
3259 VIR_FREE(cookiein);
3260 VIR_FREE(cookieout);
3261 virTypedParamsFree(params, nparams);
3262 return ddomain;
3266 static virDomainPtr
3267 virDomainMigrateVersion3(virDomainPtr domain,
3268 virConnectPtr dconn,
3269 const char *xmlin,
3270 unsigned long flags,
3271 const char *dname,
3272 const char *uri,
3273 unsigned long bandwidth)
3275 return virDomainMigrateVersion3Full(domain, dconn, xmlin, dname, uri,
3276 bandwidth, NULL, 0, false, flags);
3280 static virDomainPtr
3281 virDomainMigrateVersion3Params(virDomainPtr domain,
3282 virConnectPtr dconn,
3283 virTypedParameterPtr params,
3284 int nparams,
3285 unsigned int flags)
3287 return virDomainMigrateVersion3Full(domain, dconn, NULL, NULL, NULL, 0,
3288 params, nparams, true, flags);
3292 static int
3293 virDomainMigrateCheckNotLocal(const char *dconnuri)
3295 virURIPtr tempuri = NULL;
3296 int ret = -1;
3298 if (!(tempuri = virURIParse(dconnuri)))
3299 goto cleanup;
3300 if (!tempuri->server || STRPREFIX(tempuri->server, "localhost")) {
3301 virReportInvalidArg(dconnuri, "%s",
3302 _("Attempt to migrate guest to the same host"));
3303 goto cleanup;
3306 ret = 0;
3308 cleanup:
3309 virURIFree(tempuri);
3310 return ret;
3314 static int
3315 virDomainMigrateUnmanagedProto2(virDomainPtr domain,
3316 const char *dconnuri,
3317 virTypedParameterPtr params,
3318 int nparams,
3319 unsigned int flags)
3321 /* uri parameter is added for direct case */
3322 const char *compatParams[] = { VIR_MIGRATE_PARAM_DEST_NAME,
3323 VIR_MIGRATE_PARAM_BANDWIDTH,
3324 VIR_MIGRATE_PARAM_URI };
3325 const char *uri = NULL;
3326 const char *miguri = NULL;
3327 const char *dname = NULL;
3328 unsigned long long bandwidth = 0;
3330 if (!virTypedParamsCheck(params, nparams, compatParams,
3331 ARRAY_CARDINALITY(compatParams))) {
3332 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3333 _("Some parameters are not supported by migration "
3334 "protocol 2"));
3335 return -1;
3338 if (virTypedParamsGetString(params, nparams,
3339 VIR_MIGRATE_PARAM_URI, &miguri) < 0 ||
3340 virTypedParamsGetString(params, nparams,
3341 VIR_MIGRATE_PARAM_DEST_NAME, &dname) < 0 ||
3342 virTypedParamsGetULLong(params, nparams,
3343 VIR_MIGRATE_PARAM_BANDWIDTH, &bandwidth) < 0) {
3344 return -1;
3347 if (flags & VIR_MIGRATE_PEER2PEER) {
3348 if (miguri) {
3349 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
3350 _("Unable to override peer2peer migration URI"));
3351 return -1;
3353 uri = dconnuri;
3354 } else {
3355 uri = miguri;
3358 return domain->conn->driver->domainMigratePerform
3359 (domain, NULL, 0, uri, flags, dname, bandwidth);
3363 static int
3364 virDomainMigrateUnmanagedProto3(virDomainPtr domain,
3365 const char *dconnuri,
3366 virTypedParameterPtr params,
3367 int nparams,
3368 unsigned int flags)
3370 const char *compatParams[] = { VIR_MIGRATE_PARAM_URI,
3371 VIR_MIGRATE_PARAM_DEST_NAME,
3372 VIR_MIGRATE_PARAM_DEST_XML,
3373 VIR_MIGRATE_PARAM_BANDWIDTH };
3374 const char *miguri = NULL;
3375 const char *dname = NULL;
3376 const char *xmlin = NULL;
3377 unsigned long long bandwidth = 0;
3379 if (!virTypedParamsCheck(params, nparams, compatParams,
3380 ARRAY_CARDINALITY(compatParams))) {
3381 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3382 _("Some parameters are not supported by migration "
3383 "protocol 3"));
3384 return -1;
3387 if (virTypedParamsGetString(params, nparams,
3388 VIR_MIGRATE_PARAM_URI, &miguri) < 0 ||
3389 virTypedParamsGetString(params, nparams,
3390 VIR_MIGRATE_PARAM_DEST_NAME, &dname) < 0 ||
3391 virTypedParamsGetString(params, nparams,
3392 VIR_MIGRATE_PARAM_DEST_XML, &xmlin) < 0 ||
3393 virTypedParamsGetULLong(params, nparams,
3394 VIR_MIGRATE_PARAM_BANDWIDTH, &bandwidth) < 0) {
3395 return -1;
3398 return domain->conn->driver->domainMigratePerform3
3399 (domain, xmlin, NULL, 0, NULL, NULL, dconnuri,
3400 miguri, flags, dname, bandwidth);
3405 * In normal migration, the libvirt client co-ordinates communication
3406 * between the 2 libvirtd instances on source & dest hosts.
3408 * This function encapsulates 2 alternatives to the above case.
3410 * 1. peer-2-peer migration, the libvirt client only talks to the source
3411 * libvirtd instance. The source libvirtd then opens its own
3412 * connection to the destination and co-ordinates migration itself.
3414 * 2. direct migration, where there is no requirement for a libvirtd instance
3415 * on the dest host. Eg, XenD can talk direct to XenD, so libvirtd on dest
3416 * does not need to be involved at all, or even running.
3418 static int
3419 virDomainMigrateUnmanagedParams(virDomainPtr domain,
3420 const char *dconnuri,
3421 virTypedParameterPtr params,
3422 int nparams,
3423 unsigned int flags)
3425 VIR_DOMAIN_DEBUG(domain, "dconnuri=%s, params=%p, nparams=%d, flags=0x%x",
3426 NULLSTR(dconnuri), params, nparams, flags);
3427 VIR_TYPED_PARAMS_DEBUG(params, nparams);
3429 if ((flags & VIR_MIGRATE_PEER2PEER) &&
3430 virDomainMigrateCheckNotLocal(dconnuri) < 0)
3431 return -1;
3433 if ((flags & VIR_MIGRATE_PEER2PEER) &&
3434 VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3435 VIR_DRV_FEATURE_MIGRATION_PARAMS)) {
3436 VIR_DEBUG("Using migration protocol 3 with extensible parameters");
3437 if (!domain->conn->driver->domainMigratePerform3Params) {
3438 virReportUnsupportedError();
3439 return -1;
3441 return domain->conn->driver->domainMigratePerform3Params
3442 (domain, dconnuri, params, nparams,
3443 NULL, 0, NULL, NULL, flags);
3444 } else if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3445 VIR_DRV_FEATURE_MIGRATION_V3)) {
3446 VIR_DEBUG("Using migration protocol 3");
3447 if (!domain->conn->driver->domainMigratePerform3) {
3448 virReportUnsupportedError();
3449 return -1;
3451 return virDomainMigrateUnmanagedProto3(domain, dconnuri,
3452 params, nparams, flags);
3453 } else {
3454 VIR_DEBUG("Using migration protocol 2");
3455 if (!domain->conn->driver->domainMigratePerform) {
3456 virReportUnsupportedError();
3457 return -1;
3459 return virDomainMigrateUnmanagedProto2(domain, dconnuri,
3460 params, nparams, flags);
3465 static int
3466 virDomainMigrateUnmanaged(virDomainPtr domain,
3467 const char *xmlin,
3468 unsigned int flags,
3469 const char *dname,
3470 const char *dconnuri,
3471 const char *miguri,
3472 unsigned long long bandwidth)
3474 int ret = -1;
3475 virTypedParameterPtr params = NULL;
3476 int nparams = 0;
3477 int maxparams = 0;
3479 if (miguri &&
3480 virTypedParamsAddString(&params, &nparams, &maxparams,
3481 VIR_MIGRATE_PARAM_URI, miguri) < 0)
3482 goto cleanup;
3483 if (dname &&
3484 virTypedParamsAddString(&params, &nparams, &maxparams,
3485 VIR_MIGRATE_PARAM_DEST_NAME, dname) < 0)
3486 goto cleanup;
3487 if (xmlin &&
3488 virTypedParamsAddString(&params, &nparams, &maxparams,
3489 VIR_MIGRATE_PARAM_DEST_XML, xmlin) < 0)
3490 goto cleanup;
3491 if (virTypedParamsAddULLong(&params, &nparams, &maxparams,
3492 VIR_MIGRATE_PARAM_BANDWIDTH, bandwidth) < 0)
3493 goto cleanup;
3495 ret = virDomainMigrateUnmanagedParams(domain, dconnuri, params,
3496 nparams, flags);
3498 cleanup:
3499 virTypedParamsFree(params, nparams);
3501 return ret;
3506 * virDomainMigrate:
3507 * @domain: a domain object
3508 * @dconn: destination host (a connection object)
3509 * @flags: bitwise-OR of virDomainMigrateFlags
3510 * @dname: (optional) rename domain to this at destination
3511 * @uri: (optional) dest hostname/URI as seen from the source host
3512 * @bandwidth: (optional) specify migration bandwidth limit in MiB/s
3514 * Migrate the domain object from its current host to the destination
3515 * host given by dconn (a connection to the destination host).
3517 * This function is similar to virDomainMigrate3, but it only supports a fixed
3518 * set of parameters: @dname corresponds to VIR_MIGRATE_PARAM_DEST_NAME, @uri
3519 * is VIR_MIGRATE_PARAM_URI, and @bandwidth is VIR_MIGRATE_PARAM_BANDWIDTH.
3521 * virDomainFree should be used to free the resources after the
3522 * returned domain object is no longer needed.
3524 * Returns the new domain object if the migration was successful,
3525 * or NULL in case of error. Note that the new domain object
3526 * exists in the scope of the destination connection (dconn).
3528 virDomainPtr
3529 virDomainMigrate(virDomainPtr domain,
3530 virConnectPtr dconn,
3531 unsigned long flags,
3532 const char *dname,
3533 const char *uri,
3534 unsigned long bandwidth)
3536 virDomainPtr ddomain = NULL;
3538 VIR_DOMAIN_DEBUG(domain,
3539 "dconn=%p, flags=0x%lx, dname=%s, uri=%s, bandwidth=%lu",
3540 dconn, flags, NULLSTR(dname), NULLSTR(uri), bandwidth);
3542 virResetLastError();
3544 /* First checkout the source */
3545 virCheckDomainReturn(domain, NULL);
3546 virCheckReadOnlyGoto(domain->conn->flags, error);
3548 /* Now checkout the destination */
3549 virCheckConnectGoto(dconn, error);
3550 virCheckReadOnlyGoto(dconn->flags, error);
3552 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_MIGRATE_NON_SHARED_DISK,
3553 VIR_MIGRATE_NON_SHARED_INC,
3554 error);
3556 if (flags & VIR_MIGRATE_OFFLINE) {
3557 if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3558 VIR_DRV_FEATURE_MIGRATION_OFFLINE)) {
3559 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3560 _("offline migration is not supported by "
3561 "the source host"));
3562 goto error;
3564 if (!VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
3565 VIR_DRV_FEATURE_MIGRATION_OFFLINE)) {
3566 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3567 _("offline migration is not supported by "
3568 "the destination host"));
3569 goto error;
3573 if (flags & VIR_MIGRATE_PEER2PEER) {
3574 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3575 VIR_DRV_FEATURE_MIGRATION_P2P)) {
3576 char *dstURI = NULL;
3577 if (uri == NULL) {
3578 dstURI = virConnectGetURI(dconn);
3579 if (!dstURI)
3580 return NULL;
3583 VIR_DEBUG("Using peer2peer migration");
3584 if (virDomainMigrateUnmanaged(domain, NULL, flags, dname,
3585 uri ? uri : dstURI, NULL, bandwidth) < 0) {
3586 VIR_FREE(dstURI);
3587 goto error;
3589 VIR_FREE(dstURI);
3591 ddomain = virDomainLookupByName(dconn, dname ? dname : domain->name);
3592 } else {
3593 /* This driver does not support peer to peer migration */
3594 virReportUnsupportedError();
3595 goto error;
3597 } else {
3598 /* Change protection requires support only on source side, and
3599 * is only needed in v3 migration, which automatically re-adds
3600 * the flag for just the source side. We mask it out for
3601 * non-peer2peer to allow migration from newer source to an
3602 * older destination that rejects the flag. */
3603 if (flags & VIR_MIGRATE_CHANGE_PROTECTION &&
3604 !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3605 VIR_DRV_FEATURE_MIGRATE_CHANGE_PROTECTION)) {
3606 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3607 _("cannot enforce change protection"));
3608 goto error;
3610 flags &= ~VIR_MIGRATE_CHANGE_PROTECTION;
3611 if (flags & VIR_MIGRATE_TUNNELLED) {
3612 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
3613 _("cannot perform tunnelled migration without using peer2peer flag"));
3614 goto error;
3617 /* Check that migration is supported by both drivers. */
3618 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3619 VIR_DRV_FEATURE_MIGRATION_V3) &&
3620 VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
3621 VIR_DRV_FEATURE_MIGRATION_V3)) {
3622 VIR_DEBUG("Using migration protocol 3");
3623 ddomain = virDomainMigrateVersion3(domain, dconn, NULL,
3624 flags, dname, uri, bandwidth);
3625 } else if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3626 VIR_DRV_FEATURE_MIGRATION_V2) &&
3627 VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
3628 VIR_DRV_FEATURE_MIGRATION_V2)) {
3629 VIR_DEBUG("Using migration protocol 2");
3630 ddomain = virDomainMigrateVersion2(domain, dconn, flags,
3631 dname, uri, bandwidth);
3632 } else if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3633 VIR_DRV_FEATURE_MIGRATION_V1) &&
3634 VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
3635 VIR_DRV_FEATURE_MIGRATION_V1)) {
3636 VIR_DEBUG("Using migration protocol 1");
3637 ddomain = virDomainMigrateVersion1(domain, dconn, flags,
3638 dname, uri, bandwidth);
3639 } else {
3640 /* This driver does not support any migration method */
3641 virReportUnsupportedError();
3642 goto error;
3646 if (ddomain == NULL)
3647 goto error;
3649 return ddomain;
3651 error:
3652 virDispatchError(domain->conn);
3653 return NULL;
3658 * virDomainMigrate2:
3659 * @domain: a domain object
3660 * @dconn: destination host (a connection object)
3661 * @flags: bitwise-OR of virDomainMigrateFlags
3662 * @dxml: (optional) XML config for launching guest on target
3663 * @dname: (optional) rename domain to this at destination
3664 * @uri: (optional) dest hostname/URI as seen from the source host
3665 * @bandwidth: (optional) specify migration bandwidth limit in MiB/s
3667 * Migrate the domain object from its current host to the destination
3668 * host given by dconn (a connection to the destination host).
3670 * This function is similar to virDomainMigrate3, but it only supports a fixed
3671 * set of parameters: @dxml corresponds to VIR_MIGRATE_PARAM_DEST_XML, @dname
3672 * is VIR_MIGRATE_PARAM_DEST_NAME, @uri is VIR_MIGRATE_PARAM_URI, and
3673 * @bandwidth is VIR_MIGRATE_PARAM_BANDWIDTH.
3675 * virDomainFree should be used to free the resources after the
3676 * returned domain object is no longer needed.
3678 * Returns the new domain object if the migration was successful,
3679 * or NULL in case of error. Note that the new domain object
3680 * exists in the scope of the destination connection (dconn).
3682 virDomainPtr
3683 virDomainMigrate2(virDomainPtr domain,
3684 virConnectPtr dconn,
3685 const char *dxml,
3686 unsigned long flags,
3687 const char *dname,
3688 const char *uri,
3689 unsigned long bandwidth)
3691 virDomainPtr ddomain = NULL;
3693 VIR_DOMAIN_DEBUG(domain,
3694 "dconn=%p, flags=0x%lx, dname=%s, uri=%s, bandwidth=%lu",
3695 dconn, flags, NULLSTR(dname), NULLSTR(uri), bandwidth);
3697 virResetLastError();
3699 /* First checkout the source */
3700 virCheckDomainReturn(domain, NULL);
3701 virCheckReadOnlyGoto(domain->conn->flags, error);
3703 /* Now checkout the destination */
3704 virCheckConnectGoto(dconn, error);
3705 virCheckReadOnlyGoto(dconn->flags, error);
3707 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_MIGRATE_NON_SHARED_DISK,
3708 VIR_MIGRATE_NON_SHARED_INC,
3709 error);
3711 if (flags & VIR_MIGRATE_OFFLINE) {
3712 if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3713 VIR_DRV_FEATURE_MIGRATION_OFFLINE)) {
3714 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3715 _("offline migration is not supported by "
3716 "the source host"));
3717 goto error;
3719 if (!VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
3720 VIR_DRV_FEATURE_MIGRATION_OFFLINE)) {
3721 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3722 _("offline migration is not supported by "
3723 "the destination host"));
3724 goto error;
3728 if (flags & VIR_MIGRATE_PEER2PEER) {
3729 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3730 VIR_DRV_FEATURE_MIGRATION_P2P)) {
3731 char *dstURI = virConnectGetURI(dconn);
3732 if (!dstURI)
3733 return NULL;
3735 VIR_DEBUG("Using peer2peer migration");
3736 if (virDomainMigrateUnmanaged(domain, dxml, flags, dname,
3737 dstURI, uri, bandwidth) < 0) {
3738 VIR_FREE(dstURI);
3739 goto error;
3741 VIR_FREE(dstURI);
3743 ddomain = virDomainLookupByName(dconn, dname ? dname : domain->name);
3744 } else {
3745 /* This driver does not support peer to peer migration */
3746 virReportUnsupportedError();
3747 goto error;
3749 } else {
3750 /* Change protection requires support only on source side, and
3751 * is only needed in v3 migration, which automatically re-adds
3752 * the flag for just the source side. We mask it out for
3753 * non-peer2peer to allow migration from newer source to an
3754 * older destination that rejects the flag. */
3755 if (flags & VIR_MIGRATE_CHANGE_PROTECTION &&
3756 !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3757 VIR_DRV_FEATURE_MIGRATE_CHANGE_PROTECTION)) {
3758 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3759 _("cannot enforce change protection"));
3760 goto error;
3762 flags &= ~VIR_MIGRATE_CHANGE_PROTECTION;
3763 if (flags & VIR_MIGRATE_TUNNELLED) {
3764 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
3765 _("cannot perform tunnelled migration without using peer2peer flag"));
3766 goto error;
3769 /* Check that migration is supported by both drivers. */
3770 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3771 VIR_DRV_FEATURE_MIGRATION_V3) &&
3772 VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
3773 VIR_DRV_FEATURE_MIGRATION_V3)) {
3774 VIR_DEBUG("Using migration protocol 3");
3775 ddomain = virDomainMigrateVersion3(domain, dconn, dxml,
3776 flags, dname, uri, bandwidth);
3777 } else if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3778 VIR_DRV_FEATURE_MIGRATION_V2) &&
3779 VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
3780 VIR_DRV_FEATURE_MIGRATION_V2)) {
3781 VIR_DEBUG("Using migration protocol 2");
3782 if (dxml) {
3783 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3784 _("Unable to change target guest XML during migration"));
3785 goto error;
3787 ddomain = virDomainMigrateVersion2(domain, dconn, flags,
3788 dname, uri, bandwidth);
3789 } else if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3790 VIR_DRV_FEATURE_MIGRATION_V1) &&
3791 VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
3792 VIR_DRV_FEATURE_MIGRATION_V1)) {
3793 VIR_DEBUG("Using migration protocol 1");
3794 if (dxml) {
3795 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3796 _("Unable to change target guest XML during migration"));
3797 goto error;
3799 ddomain = virDomainMigrateVersion1(domain, dconn, flags,
3800 dname, uri, bandwidth);
3801 } else {
3802 /* This driver does not support any migration method */
3803 virReportUnsupportedError();
3804 goto error;
3808 if (ddomain == NULL)
3809 goto error;
3811 return ddomain;
3813 error:
3814 virDispatchError(domain->conn);
3815 return NULL;
3820 * virDomainMigrate3:
3821 * @domain: a domain object
3822 * @dconn: destination host (a connection object)
3823 * @params: (optional) migration parameters
3824 * @nparams: (optional) number of migration parameters in @params
3825 * @flags: bitwise-OR of virDomainMigrateFlags
3827 * Migrate the domain object from its current host to the destination host
3828 * given by dconn (a connection to the destination host).
3830 * See VIR_MIGRATE_PARAM_* and virDomainMigrateFlags for detailed description
3831 * of accepted migration parameters and flags.
3833 * See virDomainMigrateFlags documentation for description of individual flags.
3835 * VIR_MIGRATE_TUNNELLED and VIR_MIGRATE_PEER2PEER are not supported by this
3836 * API, use virDomainMigrateToURI3 instead.
3838 * There are many limitations on migration imposed by the underlying
3839 * technology - for example it may not be possible to migrate between
3840 * different processors even with the same architecture, or between
3841 * different types of hypervisor.
3843 * virDomainFree should be used to free the resources after the
3844 * returned domain object is no longer needed.
3846 * Returns the new domain object if the migration was successful,
3847 * or NULL in case of error. Note that the new domain object
3848 * exists in the scope of the destination connection (dconn).
3850 virDomainPtr
3851 virDomainMigrate3(virDomainPtr domain,
3852 virConnectPtr dconn,
3853 virTypedParameterPtr params,
3854 unsigned int nparams,
3855 unsigned int flags)
3857 virDomainPtr ddomain = NULL;
3858 const char *compatParams[] = { VIR_MIGRATE_PARAM_URI,
3859 VIR_MIGRATE_PARAM_DEST_NAME,
3860 VIR_MIGRATE_PARAM_DEST_XML,
3861 VIR_MIGRATE_PARAM_BANDWIDTH };
3862 const char *uri = NULL;
3863 const char *dname = NULL;
3864 const char *dxml = NULL;
3865 unsigned long long bandwidth = 0;
3867 VIR_DOMAIN_DEBUG(domain, "dconn=%p, params=%p, nparms=%u flags=0x%x",
3868 dconn, params, nparams, flags);
3869 VIR_TYPED_PARAMS_DEBUG(params, nparams);
3871 virResetLastError();
3873 /* First checkout the source */
3874 virCheckDomainReturn(domain, NULL);
3875 virCheckReadOnlyGoto(domain->conn->flags, error);
3877 /* Now checkout the destination */
3878 virCheckReadOnlyGoto(dconn->flags, error);
3880 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_MIGRATE_NON_SHARED_DISK,
3881 VIR_MIGRATE_NON_SHARED_INC,
3882 error);
3884 if (flags & VIR_MIGRATE_PEER2PEER) {
3885 virReportInvalidArg(flags, "%s",
3886 _("use virDomainMigrateToURI3 for peer-to-peer "
3887 "migration"));
3888 goto error;
3890 if (flags & VIR_MIGRATE_TUNNELLED) {
3891 virReportInvalidArg(flags, "%s",
3892 _("cannot perform tunnelled migration "
3893 "without using peer2peer flag"));
3894 goto error;
3897 if (flags & VIR_MIGRATE_OFFLINE) {
3898 if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3899 VIR_DRV_FEATURE_MIGRATION_OFFLINE)) {
3900 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3901 _("offline migration is not supported by "
3902 "the source host"));
3903 goto error;
3905 if (!VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
3906 VIR_DRV_FEATURE_MIGRATION_OFFLINE)) {
3907 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3908 _("offline migration is not supported by "
3909 "the destination host"));
3910 goto error;
3914 /* Change protection requires support only on source side, and
3915 * is only needed in v3 migration, which automatically re-adds
3916 * the flag for just the source side. We mask it out to allow
3917 * migration from newer source to an older destination that
3918 * rejects the flag. */
3919 if (flags & VIR_MIGRATE_CHANGE_PROTECTION &&
3920 !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3921 VIR_DRV_FEATURE_MIGRATE_CHANGE_PROTECTION)) {
3922 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3923 _("cannot enforce change protection"));
3924 goto error;
3926 flags &= ~VIR_MIGRATE_CHANGE_PROTECTION;
3928 /* Prefer extensible API but fall back to older migration APIs if params
3929 * only contains parameters which were supported by the older API. */
3930 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3931 VIR_DRV_FEATURE_MIGRATION_PARAMS) &&
3932 VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
3933 VIR_DRV_FEATURE_MIGRATION_PARAMS)) {
3934 VIR_DEBUG("Using migration protocol 3 with extensible parameters");
3935 ddomain = virDomainMigrateVersion3Params(domain, dconn, params,
3936 nparams, flags);
3937 goto done;
3940 if (!virTypedParamsCheck(params, nparams, compatParams,
3941 ARRAY_CARDINALITY(compatParams))) {
3942 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3943 _("Migration APIs with extensible parameters are not "
3944 "supported but extended parameters were passed"));
3945 goto error;
3948 if (virTypedParamsGetString(params, nparams,
3949 VIR_MIGRATE_PARAM_URI, &uri) < 0 ||
3950 virTypedParamsGetString(params, nparams,
3951 VIR_MIGRATE_PARAM_DEST_NAME, &dname) < 0 ||
3952 virTypedParamsGetString(params, nparams,
3953 VIR_MIGRATE_PARAM_DEST_XML, &dxml) < 0 ||
3954 virTypedParamsGetULLong(params, nparams,
3955 VIR_MIGRATE_PARAM_BANDWIDTH, &bandwidth) < 0) {
3956 goto error;
3959 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3960 VIR_DRV_FEATURE_MIGRATION_V3) &&
3961 VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
3962 VIR_DRV_FEATURE_MIGRATION_V3)) {
3963 VIR_DEBUG("Using migration protocol 3");
3964 ddomain = virDomainMigrateVersion3(domain, dconn, dxml, flags,
3965 dname, uri, bandwidth);
3966 } else if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3967 VIR_DRV_FEATURE_MIGRATION_V2) &&
3968 VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
3969 VIR_DRV_FEATURE_MIGRATION_V2)) {
3970 VIR_DEBUG("Using migration protocol 2");
3971 if (dxml) {
3972 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3973 _("Unable to change target guest XML during "
3974 "migration"));
3975 goto error;
3977 ddomain = virDomainMigrateVersion2(domain, dconn, flags,
3978 dname, uri, bandwidth);
3979 } else if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
3980 VIR_DRV_FEATURE_MIGRATION_V1) &&
3981 VIR_DRV_SUPPORTS_FEATURE(dconn->driver, dconn,
3982 VIR_DRV_FEATURE_MIGRATION_V1)) {
3983 VIR_DEBUG("Using migration protocol 1");
3984 if (dxml) {
3985 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
3986 _("Unable to change target guest XML during "
3987 "migration"));
3988 goto error;
3990 ddomain = virDomainMigrateVersion1(domain, dconn, flags,
3991 dname, uri, bandwidth);
3992 } else {
3993 /* This driver does not support any migration method */
3994 virReportUnsupportedError();
3995 goto error;
3998 done:
3999 if (ddomain == NULL)
4000 goto error;
4002 return ddomain;
4004 error:
4005 virDispatchError(domain->conn);
4006 return NULL;
4010 static
4011 int virDomainMigrateUnmanagedCheckCompat(virDomainPtr domain,
4012 unsigned int flags)
4014 VIR_EXCLUSIVE_FLAGS_RET(VIR_MIGRATE_NON_SHARED_DISK,
4015 VIR_MIGRATE_NON_SHARED_INC,
4016 -1);
4018 if (flags & VIR_MIGRATE_OFFLINE &&
4019 !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
4020 VIR_DRV_FEATURE_MIGRATION_OFFLINE)) {
4021 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
4022 _("offline migration is not supported by "
4023 "the source host"));
4024 return -1;
4027 if (flags & VIR_MIGRATE_PEER2PEER) {
4028 if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
4029 VIR_DRV_FEATURE_MIGRATION_P2P)) {
4030 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
4031 _("p2p migration is not supported by "
4032 "the source host"));
4033 return -1;
4035 } else {
4036 if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
4037 VIR_DRV_FEATURE_MIGRATION_DIRECT)) {
4038 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
4039 _("direct migration is not supported by "
4040 "the source host"));
4041 return -1;
4045 return 0;
4050 * virDomainMigrateToURI:
4051 * @domain: a domain object
4052 * @duri: mandatory URI for the destination host
4053 * @flags: bitwise-OR of virDomainMigrateFlags
4054 * @dname: (optional) rename domain to this at destination
4055 * @bandwidth: (optional) specify migration bandwidth limit in MiB/s
4057 * Migrate the domain object from its current host to the destination
4058 * host given by duri.
4060 * This function is similar to virDomainMigrateToURI3, but it only supports a
4061 * fixed set of parameters: @dname corresponds to VIR_MIGRATE_PARAM_DEST_NAME,
4062 * and @bandwidth corresponds to VIR_MIGRATE_PARAM_BANDWIDTH.
4064 * The operation of this API hinges on the VIR_MIGRATE_PEER2PEER flag.
4066 * If the VIR_MIGRATE_PEER2PEER flag IS set, the @duri parameter must be a
4067 * valid libvirt connection URI, by which the source libvirt driver can connect
4068 * to the destination libvirt. In other words, @duri corresponds to @dconnuri
4069 * of virDomainMigrateToURI3.
4071 * If the VIR_MIGRATE_PEER2PEER flag is NOT set, the @duri parameter takes a
4072 * hypervisor specific URI used to initiate the migration. In this case @duri
4073 * corresponds to VIR_MIGRATE_PARAM_URI of virDomainMigrateToURI3.
4075 * Returns 0 if the migration succeeded, -1 upon error.
4078 virDomainMigrateToURI(virDomainPtr domain,
4079 const char *duri,
4080 unsigned long flags,
4081 const char *dname,
4082 unsigned long bandwidth)
4084 const char *dconnuri = NULL;
4085 const char *miguri = NULL;
4087 VIR_DOMAIN_DEBUG(domain, "duri=%p, flags=0x%lx, dname=%s, bandwidth=%lu",
4088 NULLSTR(duri), flags, NULLSTR(dname), bandwidth);
4090 virResetLastError();
4092 /* First checkout the source */
4093 virCheckDomainReturn(domain, -1);
4094 virCheckReadOnlyGoto(domain->conn->flags, error);
4095 virCheckNonNullArgGoto(duri, error);
4097 if (virDomainMigrateUnmanagedCheckCompat(domain, flags) < 0)
4098 goto error;
4100 if (flags & VIR_MIGRATE_PEER2PEER)
4101 dconnuri = duri;
4102 else
4103 miguri = duri;
4105 if (virDomainMigrateUnmanaged(domain, NULL, flags,
4106 dname, dconnuri, miguri, bandwidth) < 0)
4107 goto error;
4109 return 0;
4111 error:
4112 virDispatchError(domain->conn);
4113 return -1;
4118 * virDomainMigrateToURI2:
4119 * @domain: a domain object
4120 * @dconnuri: (optional) URI for target libvirtd if @flags includes VIR_MIGRATE_PEER2PEER
4121 * @miguri: (optional) URI for invoking the migration, not if @flags includs VIR_MIGRATE_TUNNELLED
4122 * @dxml: (optional) XML config for launching guest on target
4123 * @flags: bitwise-OR of virDomainMigrateFlags
4124 * @dname: (optional) rename domain to this at destination
4125 * @bandwidth: (optional) specify migration bandwidth limit in MiB/s
4127 * Migrate the domain object from its current host to the destination
4128 * host given by @dconnuri.
4130 * This function is similar to virDomainMigrateToURI3, but it only supports a
4131 * fixed set of parameters: @miguri corresponds to VIR_MIGRATE_PARAM_URI, @dxml
4132 * is VIR_MIGRATE_PARAM_DEST_XML, @dname is VIR_MIGRATE_PARAM_DEST_NAME, and
4133 * @bandwidth corresponds to VIR_MIGRATE_PARAM_BANDWIDTH.
4135 * The operation of this API hinges on the VIR_MIGRATE_PEER2PEER flag.
4137 * If the VIR_MIGRATE_PEER2PEER flag IS set, the @dconnuri parameter must be a
4138 * valid libvirt connection URI, by which the source libvirt driver can connect
4139 * to the destination libvirt. In other words, @dconnuri has the same semantics
4140 * as in virDomainMigrateToURI3.
4142 * If the VIR_MIGRATE_PEER2PEER flag is NOT set, the @dconnuri must be NULL
4143 * and the @miguri parameter takes a hypervisor specific URI used to initiate
4144 * the migration. In this case @miguri corresponds to VIR_MIGRATE_PARAM_URI of
4145 * virDomainMigrateToURI3.
4147 * Returns 0 if the migration succeeded, -1 upon error.
4150 virDomainMigrateToURI2(virDomainPtr domain,
4151 const char *dconnuri,
4152 const char *miguri,
4153 const char *dxml,
4154 unsigned long flags,
4155 const char *dname,
4156 unsigned long bandwidth)
4158 VIR_DOMAIN_DEBUG(domain, "dconnuri=%s, miguri=%s, dxml=%s, "
4159 "flags=0x%lx, dname=%s, bandwidth=%lu",
4160 NULLSTR(dconnuri), NULLSTR(miguri), NULLSTR(dxml),
4161 flags, NULLSTR(dname), bandwidth);
4163 virResetLastError();
4165 /* First checkout the source */
4166 virCheckDomainReturn(domain, -1);
4167 virCheckReadOnlyGoto(domain->conn->flags, error);
4169 if (virDomainMigrateUnmanagedCheckCompat(domain, flags) < 0)
4170 goto error;
4172 if (flags & VIR_MIGRATE_PEER2PEER)
4173 virCheckNonNullArgGoto(dconnuri, error);
4174 else
4175 dconnuri = NULL;
4177 if (virDomainMigrateUnmanaged(domain, dxml, flags,
4178 dname, dconnuri, miguri, bandwidth) < 0)
4179 goto error;
4181 return 0;
4183 error:
4184 virDispatchError(domain->conn);
4185 return -1;
4190 * virDomainMigrateToURI3:
4191 * @domain: a domain object
4192 * @dconnuri: (optional) URI for target libvirtd if @flags includes VIR_MIGRATE_PEER2PEER
4193 * @params: (optional) migration parameters
4194 * @nparams: (optional) number of migration parameters in @params
4195 * @flags: bitwise-OR of virDomainMigrateFlags
4197 * Migrate the domain object from its current host to the destination host
4198 * given by URI.
4200 * See VIR_MIGRATE_PARAM_* and virDomainMigrateFlags for detailed description
4201 * of accepted migration parameters and flags.
4203 * The operation of this API hinges on the VIR_MIGRATE_PEER2PEER flag.
4205 * If the VIR_MIGRATE_PEER2PEER flag is set, the @dconnuri parameter must be a
4206 * valid libvirt connection URI, by which the source libvirt daemon can connect
4207 * to the destination libvirt.
4209 * If the VIR_MIGRATE_PEER2PEER flag is NOT set, then @dconnuri must be NULL
4210 * and VIR_MIGRATE_PARAM_URI migration parameter must be filled in with
4211 * hypervisor specific URI used to initiate the migration. The uri_transports
4212 * element of the hypervisor capabilities XML includes supported URI schemes.
4213 * This is called "direct" migration. Not all hypervisors support this mode of
4214 * migration, so if the VIR_MIGRATE_PEER2PEER flag is not set, then it may be
4215 * necessary to use the alternative virDomainMigrate3 API providing an explicit
4216 * virConnectPtr for the destination host.
4218 * There are many limitations on migration imposed by the underlying
4219 * technology - for example it may not be possible to migrate between
4220 * different processors even with the same architecture, or between
4221 * different types of hypervisor.
4223 * Returns 0 if the migration succeeded, -1 upon error.
4226 virDomainMigrateToURI3(virDomainPtr domain,
4227 const char *dconnuri,
4228 virTypedParameterPtr params,
4229 unsigned int nparams,
4230 unsigned int flags)
4232 VIR_DOMAIN_DEBUG(domain, "dconnuri=%s, params=%p, nparms=%u flags=0x%x",
4233 NULLSTR(dconnuri), params, nparams, flags);
4234 VIR_TYPED_PARAMS_DEBUG(params, nparams);
4236 virResetLastError();
4238 /* First checkout the source */
4239 virCheckDomainReturn(domain, -1);
4240 virCheckReadOnlyGoto(domain->conn->flags, error);
4242 if (virDomainMigrateUnmanagedCheckCompat(domain, flags) < 0)
4243 goto error;
4245 if (flags & VIR_MIGRATE_PEER2PEER)
4246 virCheckNonNullArgGoto(dconnuri, error);
4247 else
4248 dconnuri = NULL;
4250 if (virDomainMigrateUnmanagedParams(domain, dconnuri,
4251 params, nparams, flags) < 0)
4252 goto error;
4254 return 0;
4256 error:
4257 virDispatchError(domain->conn);
4258 return -1;
4263 * Not for public use. This function is part of the internal
4264 * implementation of migration in the remote case.
4267 virDomainMigratePrepare(virConnectPtr dconn,
4268 char **cookie,
4269 int *cookielen,
4270 const char *uri_in,
4271 char **uri_out,
4272 unsigned long flags,
4273 const char *dname,
4274 unsigned long bandwidth)
4276 VIR_DEBUG("dconn=%p, cookie=%p, cookielen=%p, uri_in=%s, uri_out=%p, "
4277 "flags=0x%lx, dname=%s, bandwidth=%lu", dconn, cookie, cookielen,
4278 NULLSTR(uri_in), uri_out, flags, NULLSTR(dname), bandwidth);
4280 virResetLastError();
4282 virCheckConnectReturn(dconn, -1);
4283 virCheckReadOnlyGoto(dconn->flags, error);
4285 if (dconn->driver->domainMigratePrepare) {
4286 int ret;
4287 ret = dconn->driver->domainMigratePrepare(dconn, cookie, cookielen,
4288 uri_in, uri_out,
4289 flags, dname, bandwidth);
4290 if (ret < 0)
4291 goto error;
4292 return ret;
4295 virReportUnsupportedError();
4297 error:
4298 virDispatchError(dconn);
4299 return -1;
4304 * Not for public use. This function is part of the internal
4305 * implementation of migration in the remote case.
4308 virDomainMigratePerform(virDomainPtr domain,
4309 const char *cookie,
4310 int cookielen,
4311 const char *uri,
4312 unsigned long flags,
4313 const char *dname,
4314 unsigned long bandwidth)
4316 virConnectPtr conn;
4318 VIR_DOMAIN_DEBUG(domain, "cookie=%p, cookielen=%d, uri=%s, flags=0x%lx, "
4319 "dname=%s, bandwidth=%lu", cookie, cookielen, uri, flags,
4320 NULLSTR(dname), bandwidth);
4322 virResetLastError();
4324 virCheckDomainReturn(domain, -1);
4325 conn = domain->conn;
4327 virCheckReadOnlyGoto(conn->flags, error);
4329 if (conn->driver->domainMigratePerform) {
4330 int ret;
4331 ret = conn->driver->domainMigratePerform(domain, cookie, cookielen,
4332 uri,
4333 flags, dname, bandwidth);
4334 if (ret < 0)
4335 goto error;
4336 return ret;
4339 virReportUnsupportedError();
4341 error:
4342 virDispatchError(domain->conn);
4343 return -1;
4348 * Not for public use. This function is part of the internal
4349 * implementation of migration in the remote case.
4351 virDomainPtr
4352 virDomainMigrateFinish(virConnectPtr dconn,
4353 const char *dname,
4354 const char *cookie,
4355 int cookielen,
4356 const char *uri,
4357 unsigned long flags)
4359 VIR_DEBUG("dconn=%p, dname=%s, cookie=%p, cookielen=%d, uri=%s, "
4360 "flags=0x%lx", dconn, NULLSTR(dname), cookie, cookielen,
4361 NULLSTR(uri), flags);
4363 virResetLastError();
4365 virCheckConnectReturn(dconn, NULL);
4366 virCheckReadOnlyGoto(dconn->flags, error);
4368 if (dconn->driver->domainMigrateFinish) {
4369 virDomainPtr ret;
4370 ret = dconn->driver->domainMigrateFinish(dconn, dname,
4371 cookie, cookielen,
4372 uri, flags);
4373 if (!ret)
4374 goto error;
4375 return ret;
4378 virReportUnsupportedError();
4380 error:
4381 virDispatchError(dconn);
4382 return NULL;
4387 * Not for public use. This function is part of the internal
4388 * implementation of migration in the remote case.
4391 virDomainMigratePrepare2(virConnectPtr dconn,
4392 char **cookie,
4393 int *cookielen,
4394 const char *uri_in,
4395 char **uri_out,
4396 unsigned long flags,
4397 const char *dname,
4398 unsigned long bandwidth,
4399 const char *dom_xml)
4401 VIR_DEBUG("dconn=%p, cookie=%p, cookielen=%p, uri_in=%s, uri_out=%p,"
4402 "flags=0x%lx, dname=%s, bandwidth=%lu, dom_xml=%s", dconn,
4403 cookie, cookielen, NULLSTR(uri_in), uri_out, flags, NULLSTR(dname),
4404 bandwidth, NULLSTR(dom_xml));
4406 virResetLastError();
4408 virCheckConnectReturn(dconn, -1);
4409 virCheckReadOnlyGoto(dconn->flags, error);
4411 if (dconn->driver->domainMigratePrepare2) {
4412 int ret;
4413 ret = dconn->driver->domainMigratePrepare2(dconn, cookie, cookielen,
4414 uri_in, uri_out,
4415 flags, dname, bandwidth,
4416 dom_xml);
4417 if (ret < 0)
4418 goto error;
4419 return ret;
4422 virReportUnsupportedError();
4424 error:
4425 virDispatchError(dconn);
4426 return -1;
4431 * Not for public use. This function is part of the internal
4432 * implementation of migration in the remote case.
4434 virDomainPtr
4435 virDomainMigrateFinish2(virConnectPtr dconn,
4436 const char *dname,
4437 const char *cookie,
4438 int cookielen,
4439 const char *uri,
4440 unsigned long flags,
4441 int retcode)
4443 VIR_DEBUG("dconn=%p, dname=%s, cookie=%p, cookielen=%d, uri=%s, "
4444 "flags=0x%lx, retcode=%d", dconn, NULLSTR(dname), cookie,
4445 cookielen, NULLSTR(uri), flags, retcode);
4447 virResetLastError();
4449 virCheckConnectReturn(dconn, NULL);
4450 virCheckReadOnlyGoto(dconn->flags, error);
4452 if (dconn->driver->domainMigrateFinish2) {
4453 virDomainPtr ret;
4454 ret = dconn->driver->domainMigrateFinish2(dconn, dname,
4455 cookie, cookielen,
4456 uri, flags,
4457 retcode);
4458 if (!ret && !retcode)
4459 goto error;
4460 return ret;
4463 virReportUnsupportedError();
4465 error:
4466 virDispatchError(dconn);
4467 return NULL;
4472 * Not for public use. This function is part of the internal
4473 * implementation of migration in the remote case.
4476 virDomainMigratePrepareTunnel(virConnectPtr conn,
4477 virStreamPtr st,
4478 unsigned long flags,
4479 const char *dname,
4480 unsigned long bandwidth,
4481 const char *dom_xml)
4483 VIR_DEBUG("conn=%p, stream=%p, flags=0x%lx, dname=%s, "
4484 "bandwidth=%lu, dom_xml=%s", conn, st, flags,
4485 NULLSTR(dname), bandwidth, NULLSTR(dom_xml));
4487 virResetLastError();
4489 virCheckConnectReturn(conn, -1);
4490 virCheckReadOnlyGoto(conn->flags, error);
4492 if (conn != st->conn) {
4493 virReportInvalidArg(conn, "%s",
4494 _("conn must match stream connection"));
4495 goto error;
4498 if (conn->driver->domainMigratePrepareTunnel) {
4499 int rv = conn->driver->domainMigratePrepareTunnel(conn, st,
4500 flags, dname,
4501 bandwidth, dom_xml);
4502 if (rv < 0)
4503 goto error;
4504 return rv;
4507 virReportUnsupportedError();
4509 error:
4510 virDispatchError(conn);
4511 return -1;
4516 * Not for public use. This function is part of the internal
4517 * implementation of migration in the remote case.
4519 char *
4520 virDomainMigrateBegin3(virDomainPtr domain,
4521 const char *xmlin,
4522 char **cookieout,
4523 int *cookieoutlen,
4524 unsigned long flags,
4525 const char *dname,
4526 unsigned long bandwidth)
4528 virConnectPtr conn;
4530 VIR_DOMAIN_DEBUG(domain, "xmlin=%s cookieout=%p, cookieoutlen=%p, "
4531 "flags=0x%lx, dname=%s, bandwidth=%lu",
4532 NULLSTR(xmlin), cookieout, cookieoutlen, flags,
4533 NULLSTR(dname), bandwidth);
4535 virResetLastError();
4537 virCheckDomainReturn(domain, NULL);
4538 conn = domain->conn;
4540 virCheckReadOnlyGoto(conn->flags, error);
4542 if (conn->driver->domainMigrateBegin3) {
4543 char *xml;
4544 xml = conn->driver->domainMigrateBegin3(domain, xmlin,
4545 cookieout, cookieoutlen,
4546 flags, dname, bandwidth);
4547 VIR_DEBUG("xml %s", NULLSTR(xml));
4548 if (!xml)
4549 goto error;
4550 return xml;
4553 virReportUnsupportedError();
4555 error:
4556 virDispatchError(domain->conn);
4557 return NULL;
4562 * Not for public use. This function is part of the internal
4563 * implementation of migration in the remote case.
4566 virDomainMigratePrepare3(virConnectPtr dconn,
4567 const char *cookiein,
4568 int cookieinlen,
4569 char **cookieout,
4570 int *cookieoutlen,
4571 const char *uri_in,
4572 char **uri_out,
4573 unsigned long flags,
4574 const char *dname,
4575 unsigned long bandwidth,
4576 const char *dom_xml)
4578 VIR_DEBUG("dconn=%p, cookiein=%p, cookieinlen=%d, cookieout=%p, "
4579 "cookieoutlen=%p, uri_in=%s, uri_out=%p, flags=0x%lx, dname=%s, "
4580 "bandwidth=%lu, dom_xml=%s",
4581 dconn, cookiein, cookieinlen, cookieout, cookieoutlen, NULLSTR(uri_in),
4582 uri_out, flags, NULLSTR(dname), bandwidth, NULLSTR(dom_xml));
4584 virResetLastError();
4586 virCheckConnectReturn(dconn, -1);
4587 virCheckReadOnlyGoto(dconn->flags, error);
4589 if (dconn->driver->domainMigratePrepare3) {
4590 int ret;
4591 ret = dconn->driver->domainMigratePrepare3(dconn,
4592 cookiein, cookieinlen,
4593 cookieout, cookieoutlen,
4594 uri_in, uri_out,
4595 flags, dname, bandwidth,
4596 dom_xml);
4597 if (ret < 0)
4598 goto error;
4599 return ret;
4602 virReportUnsupportedError();
4604 error:
4605 virDispatchError(dconn);
4606 return -1;
4611 * Not for public use. This function is part of the internal
4612 * implementation of migration in the remote case.
4615 virDomainMigratePrepareTunnel3(virConnectPtr conn,
4616 virStreamPtr st,
4617 const char *cookiein,
4618 int cookieinlen,
4619 char **cookieout,
4620 int *cookieoutlen,
4621 unsigned long flags,
4622 const char *dname,
4623 unsigned long bandwidth,
4624 const char *dom_xml)
4626 VIR_DEBUG("conn=%p, stream=%p, cookiein=%p, cookieinlen=%d, cookieout=%p, "
4627 "cookieoutlen=%p, flags=0x%lx, dname=%s, bandwidth=%lu, "
4628 "dom_xml=%s",
4629 conn, st, cookiein, cookieinlen, cookieout, cookieoutlen, flags,
4630 NULLSTR(dname), bandwidth, NULLSTR(dom_xml));
4632 virResetLastError();
4634 virCheckConnectReturn(conn, -1);
4635 virCheckReadOnlyGoto(conn->flags, error);
4637 if (conn != st->conn) {
4638 virReportInvalidArg(conn, "%s",
4639 _("conn must match stream connection"));
4640 goto error;
4643 if (conn->driver->domainMigratePrepareTunnel3) {
4644 int rv = conn->driver->domainMigratePrepareTunnel3(conn, st,
4645 cookiein, cookieinlen,
4646 cookieout, cookieoutlen,
4647 flags, dname,
4648 bandwidth, dom_xml);
4649 if (rv < 0)
4650 goto error;
4651 return rv;
4654 virReportUnsupportedError();
4656 error:
4657 virDispatchError(conn);
4658 return -1;
4663 * Not for public use. This function is part of the internal
4664 * implementation of migration in the remote case.
4667 virDomainMigratePerform3(virDomainPtr domain,
4668 const char *xmlin,
4669 const char *cookiein,
4670 int cookieinlen,
4671 char **cookieout,
4672 int *cookieoutlen,
4673 const char *dconnuri,
4674 const char *uri,
4675 unsigned long flags,
4676 const char *dname,
4677 unsigned long bandwidth)
4679 virConnectPtr conn;
4681 VIR_DOMAIN_DEBUG(domain, "xmlin=%s cookiein=%p, cookieinlen=%d, "
4682 "cookieout=%p, cookieoutlen=%p, dconnuri=%s, "
4683 "uri=%s, flags=0x%lx, dname=%s, bandwidth=%lu",
4684 NULLSTR(xmlin), cookiein, cookieinlen,
4685 cookieout, cookieoutlen, NULLSTR(dconnuri),
4686 NULLSTR(uri), flags, NULLSTR(dname), bandwidth);
4688 virResetLastError();
4690 virCheckDomainReturn(domain, -1);
4691 conn = domain->conn;
4693 virCheckReadOnlyGoto(conn->flags, error);
4695 if (conn->driver->domainMigratePerform3) {
4696 int ret;
4697 ret = conn->driver->domainMigratePerform3(domain, xmlin,
4698 cookiein, cookieinlen,
4699 cookieout, cookieoutlen,
4700 dconnuri, uri,
4701 flags, dname, bandwidth);
4702 if (ret < 0)
4703 goto error;
4704 return ret;
4707 virReportUnsupportedError();
4709 error:
4710 virDispatchError(domain->conn);
4711 return -1;
4716 * Not for public use. This function is part of the internal
4717 * implementation of migration in the remote case.
4719 virDomainPtr
4720 virDomainMigrateFinish3(virConnectPtr dconn,
4721 const char *dname,
4722 const char *cookiein,
4723 int cookieinlen,
4724 char **cookieout,
4725 int *cookieoutlen,
4726 const char *dconnuri,
4727 const char *uri,
4728 unsigned long flags,
4729 int cancelled)
4731 VIR_DEBUG("dconn=%p, dname=%s, cookiein=%p, cookieinlen=%d, cookieout=%p,"
4732 "cookieoutlen=%p, dconnuri=%s, uri=%s, flags=0x%lx, retcode=%d",
4733 dconn, NULLSTR(dname), cookiein, cookieinlen, cookieout,
4734 cookieoutlen, NULLSTR(dconnuri), NULLSTR(uri), flags, cancelled);
4736 virResetLastError();
4738 virCheckConnectReturn(dconn, NULL);
4739 virCheckReadOnlyGoto(dconn->flags, error);
4741 if (dconn->driver->domainMigrateFinish3) {
4742 virDomainPtr ret;
4743 ret = dconn->driver->domainMigrateFinish3(dconn, dname,
4744 cookiein, cookieinlen,
4745 cookieout, cookieoutlen,
4746 dconnuri, uri, flags,
4747 cancelled);
4748 if (!ret && !cancelled)
4749 goto error;
4750 return ret;
4753 virReportUnsupportedError();
4755 error:
4756 virDispatchError(dconn);
4757 return NULL;
4762 * Not for public use. This function is part of the internal
4763 * implementation of migration in the remote case.
4766 virDomainMigrateConfirm3(virDomainPtr domain,
4767 const char *cookiein,
4768 int cookieinlen,
4769 unsigned long flags,
4770 int cancelled)
4772 virConnectPtr conn;
4774 VIR_DOMAIN_DEBUG(domain,
4775 "cookiein=%p, cookieinlen=%d, flags=0x%lx, cancelled=%d",
4776 cookiein, cookieinlen, flags, cancelled);
4778 virResetLastError();
4780 virCheckDomainReturn(domain, -1);
4781 conn = domain->conn;
4783 virCheckReadOnlyGoto(conn->flags, error);
4785 if (conn->driver->domainMigrateConfirm3) {
4786 int ret;
4787 ret = conn->driver->domainMigrateConfirm3(domain,
4788 cookiein, cookieinlen,
4789 flags, cancelled);
4790 if (ret < 0)
4791 goto error;
4792 return ret;
4795 virReportUnsupportedError();
4797 error:
4798 virDispatchError(domain->conn);
4799 return -1;
4804 * Not for public use. This function is part of the internal
4805 * implementation of migration in the remote case.
4807 char *
4808 virDomainMigrateBegin3Params(virDomainPtr domain,
4809 virTypedParameterPtr params,
4810 int nparams,
4811 char **cookieout,
4812 int *cookieoutlen,
4813 unsigned int flags)
4815 virConnectPtr conn;
4817 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d, "
4818 "cookieout=%p, cookieoutlen=%p, flags=0x%x",
4819 params, nparams, cookieout, cookieoutlen, flags);
4820 VIR_TYPED_PARAMS_DEBUG(params, nparams);
4822 virResetLastError();
4824 virCheckDomainReturn(domain, NULL);
4825 conn = domain->conn;
4827 virCheckReadOnlyGoto(conn->flags, error);
4829 if (conn->driver->domainMigrateBegin3Params) {
4830 char *xml;
4831 xml = conn->driver->domainMigrateBegin3Params(domain, params, nparams,
4832 cookieout, cookieoutlen,
4833 flags);
4834 VIR_DEBUG("xml %s", NULLSTR(xml));
4835 if (!xml)
4836 goto error;
4837 return xml;
4840 virReportUnsupportedError();
4842 error:
4843 virDispatchError(domain->conn);
4844 return NULL;
4849 * Not for public use. This function is part of the internal
4850 * implementation of migration in the remote case.
4853 virDomainMigratePrepare3Params(virConnectPtr dconn,
4854 virTypedParameterPtr params,
4855 int nparams,
4856 const char *cookiein,
4857 int cookieinlen,
4858 char **cookieout,
4859 int *cookieoutlen,
4860 char **uri_out,
4861 unsigned int flags)
4863 VIR_DEBUG("dconn=%p, params=%p, nparams=%d, cookiein=%p, cookieinlen=%d, "
4864 "cookieout=%p, cookieoutlen=%p, uri_out=%p, flags=0x%x",
4865 dconn, params, nparams, cookiein, cookieinlen,
4866 cookieout, cookieoutlen, uri_out, flags);
4867 VIR_TYPED_PARAMS_DEBUG(params, nparams);
4869 virResetLastError();
4871 virCheckConnectReturn(dconn, -1);
4872 virCheckReadOnlyGoto(dconn->flags, error);
4874 if (dconn->driver->domainMigratePrepare3Params) {
4875 int ret;
4876 ret = dconn->driver->domainMigratePrepare3Params(dconn, params, nparams,
4877 cookiein, cookieinlen,
4878 cookieout, cookieoutlen,
4879 uri_out, flags);
4880 if (ret < 0)
4881 goto error;
4882 return ret;
4885 virReportUnsupportedError();
4887 error:
4888 virDispatchError(dconn);
4889 return -1;
4894 * Not for public use. This function is part of the internal
4895 * implementation of migration in the remote case.
4898 virDomainMigratePrepareTunnel3Params(virConnectPtr conn,
4899 virStreamPtr st,
4900 virTypedParameterPtr params,
4901 int nparams,
4902 const char *cookiein,
4903 int cookieinlen,
4904 char **cookieout,
4905 int *cookieoutlen,
4906 unsigned int flags)
4908 VIR_DEBUG("conn=%p, stream=%p, params=%p, nparams=%d, cookiein=%p, "
4909 "cookieinlen=%d, cookieout=%p, cookieoutlen=%p, flags=0x%x",
4910 conn, st, params, nparams, cookiein, cookieinlen,
4911 cookieout, cookieoutlen, flags);
4912 VIR_TYPED_PARAMS_DEBUG(params, nparams);
4914 virResetLastError();
4916 virCheckConnectReturn(conn, -1);
4917 virCheckReadOnlyGoto(conn->flags, error);
4919 if (conn != st->conn) {
4920 virReportInvalidArg(conn, "%s",
4921 _("conn must match stream connection"));
4922 goto error;
4925 if (conn->driver->domainMigratePrepareTunnel3Params) {
4926 int rv;
4927 rv = conn->driver->domainMigratePrepareTunnel3Params(
4928 conn, st, params, nparams, cookiein, cookieinlen,
4929 cookieout, cookieoutlen, flags);
4930 if (rv < 0)
4931 goto error;
4932 return rv;
4935 virReportUnsupportedError();
4937 error:
4938 virDispatchError(conn);
4939 return -1;
4944 * Not for public use. This function is part of the internal
4945 * implementation of migration in the remote case.
4948 virDomainMigratePerform3Params(virDomainPtr domain,
4949 const char *dconnuri,
4950 virTypedParameterPtr params,
4951 int nparams,
4952 const char *cookiein,
4953 int cookieinlen,
4954 char **cookieout,
4955 int *cookieoutlen,
4956 unsigned int flags)
4958 virConnectPtr conn;
4960 VIR_DOMAIN_DEBUG(domain, "dconnuri=%s, params=%p, nparams=%d, cookiein=%p, "
4961 "cookieinlen=%d, cookieout=%p, cookieoutlen=%p, flags=0x%x",
4962 NULLSTR(dconnuri), params, nparams, cookiein,
4963 cookieinlen, cookieout, cookieoutlen, flags);
4964 VIR_TYPED_PARAMS_DEBUG(params, nparams);
4966 virResetLastError();
4968 virCheckDomainReturn(domain, -1);
4969 conn = domain->conn;
4971 virCheckReadOnlyGoto(conn->flags, error);
4973 if (conn->driver->domainMigratePerform3Params) {
4974 int ret;
4975 ret = conn->driver->domainMigratePerform3Params(
4976 domain, dconnuri, params, nparams, cookiein, cookieinlen,
4977 cookieout, cookieoutlen, flags);
4978 if (ret < 0)
4979 goto error;
4980 return ret;
4983 virReportUnsupportedError();
4985 error:
4986 virDispatchError(domain->conn);
4987 return -1;
4992 * Not for public use. This function is part of the internal
4993 * implementation of migration in the remote case.
4995 virDomainPtr
4996 virDomainMigrateFinish3Params(virConnectPtr dconn,
4997 virTypedParameterPtr params,
4998 int nparams,
4999 const char *cookiein,
5000 int cookieinlen,
5001 char **cookieout,
5002 int *cookieoutlen,
5003 unsigned int flags,
5004 int cancelled)
5006 VIR_DEBUG("dconn=%p, params=%p, nparams=%d, cookiein=%p, cookieinlen=%d, "
5007 "cookieout=%p, cookieoutlen=%p, flags=0x%x, cancelled=%d",
5008 dconn, params, nparams, cookiein, cookieinlen, cookieout,
5009 cookieoutlen, flags, cancelled);
5010 VIR_TYPED_PARAMS_DEBUG(params, nparams);
5012 virResetLastError();
5014 virCheckConnectReturn(dconn, NULL);
5015 virCheckReadOnlyGoto(dconn->flags, error);
5017 if (dconn->driver->domainMigrateFinish3Params) {
5018 virDomainPtr ret;
5019 ret = dconn->driver->domainMigrateFinish3Params(
5020 dconn, params, nparams, cookiein, cookieinlen,
5021 cookieout, cookieoutlen, flags, cancelled);
5022 if (!ret && !cancelled)
5023 goto error;
5024 return ret;
5027 virReportUnsupportedError();
5029 error:
5030 virDispatchError(dconn);
5031 return NULL;
5036 * Not for public use. This function is part of the internal
5037 * implementation of migration in the remote case.
5040 virDomainMigrateConfirm3Params(virDomainPtr domain,
5041 virTypedParameterPtr params,
5042 int nparams,
5043 const char *cookiein,
5044 int cookieinlen,
5045 unsigned int flags,
5046 int cancelled)
5048 virConnectPtr conn;
5050 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d, cookiein=%p, "
5051 "cookieinlen=%d, flags=0x%x, cancelled=%d",
5052 params, nparams, cookiein, cookieinlen, flags, cancelled);
5053 VIR_TYPED_PARAMS_DEBUG(params, nparams);
5055 virResetLastError();
5057 virCheckDomainReturn(domain, -1);
5058 conn = domain->conn;
5060 virCheckReadOnlyGoto(conn->flags, error);
5062 if (conn->driver->domainMigrateConfirm3Params) {
5063 int ret;
5064 ret = conn->driver->domainMigrateConfirm3Params(
5065 domain, params, nparams,
5066 cookiein, cookieinlen, flags, cancelled);
5067 if (ret < 0)
5068 goto error;
5069 return ret;
5072 virReportUnsupportedError();
5074 error:
5075 virDispatchError(domain->conn);
5076 return -1;
5081 * virDomainGetSchedulerType:
5082 * @domain: pointer to domain object
5083 * @nparams: pointer to number of scheduler parameters, can be NULL
5084 * (return value)
5086 * Get the scheduler type and the number of scheduler parameters.
5088 * Returns NULL in case of error. The caller must free the returned string.
5090 char *
5091 virDomainGetSchedulerType(virDomainPtr domain, int *nparams)
5093 virConnectPtr conn;
5094 char *schedtype;
5096 VIR_DOMAIN_DEBUG(domain, "nparams=%p", nparams);
5098 virResetLastError();
5100 virCheckDomainReturn(domain, NULL);
5101 conn = domain->conn;
5103 if (conn->driver->domainGetSchedulerType) {
5104 schedtype = conn->driver->domainGetSchedulerType(domain, nparams);
5105 if (!schedtype)
5106 goto error;
5107 return schedtype;
5110 virReportUnsupportedError();
5112 error:
5113 virDispatchError(domain->conn);
5114 return NULL;
5119 * virDomainGetSchedulerParameters:
5120 * @domain: pointer to domain object
5121 * @params: pointer to scheduler parameter objects
5122 * (return value)
5123 * @nparams: pointer to number of scheduler parameter objects
5124 * (this value should generally be as large as the returned value
5125 * nparams of virDomainGetSchedulerType()); input and output
5127 * Get all scheduler parameters. On input, @nparams gives the size of the
5128 * @params array; on output, @nparams gives how many slots were filled
5129 * with parameter information, which might be less but will not exceed
5130 * the input value. @nparams cannot be 0.
5132 * It is hypervisor specific whether this returns the live or
5133 * persistent state; for more control, use
5134 * virDomainGetSchedulerParametersFlags().
5136 * Returns -1 in case of error, 0 in case of success.
5139 virDomainGetSchedulerParameters(virDomainPtr domain,
5140 virTypedParameterPtr params, int *nparams)
5142 virConnectPtr conn;
5144 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%p", params, nparams);
5146 virResetLastError();
5148 virCheckDomainReturn(domain, -1);
5150 virCheckNonNullArgGoto(params, error);
5151 virCheckNonNullArgGoto(nparams, error);
5152 virCheckPositiveArgGoto(*nparams, error);
5154 conn = domain->conn;
5156 if (conn->driver->domainGetSchedulerParameters) {
5157 int ret;
5158 ret = conn->driver->domainGetSchedulerParameters(domain, params, nparams);
5159 if (ret < 0)
5160 goto error;
5161 return ret;
5164 virReportUnsupportedError();
5166 error:
5167 virDispatchError(domain->conn);
5168 return -1;
5173 * virDomainGetSchedulerParametersFlags:
5174 * @domain: pointer to domain object
5175 * @params: pointer to scheduler parameter object
5176 * (return value)
5177 * @nparams: pointer to number of scheduler parameter
5178 * (this value should be same than the returned value
5179 * nparams of virDomainGetSchedulerType()); input and output
5180 * @flags: bitwise-OR of virDomainModificationImpact and virTypedParameterFlags
5182 * Get all scheduler parameters. On input, @nparams gives the size of the
5183 * @params array; on output, @nparams gives how many slots were filled
5184 * with parameter information, which might be less but will not exceed
5185 * the input value. @nparams cannot be 0.
5187 * The value of @flags can be exactly VIR_DOMAIN_AFFECT_CURRENT,
5188 * VIR_DOMAIN_AFFECT_LIVE, or VIR_DOMAIN_AFFECT_CONFIG.
5190 * Here is a sample code snippet:
5192 * char *ret = virDomainGetSchedulerType(dom, &nparams);
5193 * if (ret && nparams != 0) {
5194 * if ((params = malloc(sizeof(*params) * nparams)) == NULL)
5195 * goto error;
5196 * memset(params, 0, sizeof(*params) * nparams);
5197 * if (virDomainGetSchedulerParametersFlags(dom, params, &nparams, 0))
5198 * goto error;
5201 * Returns -1 in case of error, 0 in case of success.
5204 virDomainGetSchedulerParametersFlags(virDomainPtr domain,
5205 virTypedParameterPtr params, int *nparams,
5206 unsigned int flags)
5208 virConnectPtr conn;
5210 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%p, flags=0x%x",
5211 params, nparams, flags);
5213 virResetLastError();
5215 virCheckDomainReturn(domain, -1);
5217 virCheckNonNullArgGoto(params, error);
5218 virCheckNonNullArgGoto(nparams, error);
5219 virCheckPositiveArgGoto(*nparams, error);
5221 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
5222 VIR_DRV_FEATURE_TYPED_PARAM_STRING))
5223 flags |= VIR_TYPED_PARAM_STRING_OKAY;
5225 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_AFFECT_LIVE,
5226 VIR_DOMAIN_AFFECT_CONFIG,
5227 error);
5229 conn = domain->conn;
5231 if (conn->driver->domainGetSchedulerParametersFlags) {
5232 int ret;
5233 ret = conn->driver->domainGetSchedulerParametersFlags(domain, params,
5234 nparams, flags);
5235 if (ret < 0)
5236 goto error;
5237 return ret;
5240 virReportUnsupportedError();
5242 error:
5243 virDispatchError(domain->conn);
5244 return -1;
5249 * virDomainSetSchedulerParameters:
5250 * @domain: pointer to domain object
5251 * @params: pointer to scheduler parameter objects
5252 * @nparams: number of scheduler parameter objects
5253 * (this value can be the same or less than the returned value
5254 * nparams of virDomainGetSchedulerType)
5256 * Change all or a subset or the scheduler parameters. It is
5257 * hypervisor-specific whether this sets live, persistent, or both
5258 * settings; for more control, use
5259 * virDomainSetSchedulerParametersFlags.
5261 * Returns -1 in case of error, 0 in case of success.
5264 virDomainSetSchedulerParameters(virDomainPtr domain,
5265 virTypedParameterPtr params, int nparams)
5267 virConnectPtr conn;
5269 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d", params, nparams);
5270 VIR_TYPED_PARAMS_DEBUG(params, nparams);
5272 virResetLastError();
5274 virCheckDomainReturn(domain, -1);
5275 conn = domain->conn;
5277 virCheckReadOnlyGoto(conn->flags, error);
5278 virCheckNonNullArgGoto(params, error);
5279 virCheckNonNegativeArgGoto(nparams, error);
5281 if (virTypedParameterValidateSet(conn, params, nparams) < 0)
5282 goto error;
5284 if (conn->driver->domainSetSchedulerParameters) {
5285 int ret;
5286 ret = conn->driver->domainSetSchedulerParameters(domain, params, nparams);
5287 if (ret < 0)
5288 goto error;
5289 return ret;
5292 virReportUnsupportedError();
5294 error:
5295 virDispatchError(domain->conn);
5296 return -1;
5301 * virDomainSetSchedulerParametersFlags:
5302 * @domain: pointer to domain object
5303 * @params: pointer to scheduler parameter objects
5304 * @nparams: number of scheduler parameter objects
5305 * (this value can be the same or less than the returned value
5306 * nparams of virDomainGetSchedulerType)
5307 * @flags: bitwise-OR of virDomainModificationImpact
5309 * Change a subset or all scheduler parameters. The value of @flags
5310 * should be either VIR_DOMAIN_AFFECT_CURRENT, or a bitwise-or of
5311 * values from VIR_DOMAIN_AFFECT_LIVE and
5312 * VIR_DOMAIN_AFFECT_CURRENT, although hypervisors vary in which
5313 * flags are supported.
5315 * Returns -1 in case of error, 0 in case of success.
5318 virDomainSetSchedulerParametersFlags(virDomainPtr domain,
5319 virTypedParameterPtr params,
5320 int nparams,
5321 unsigned int flags)
5323 virConnectPtr conn;
5325 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d, flags=0x%x",
5326 params, nparams, flags);
5327 VIR_TYPED_PARAMS_DEBUG(params, nparams);
5329 virResetLastError();
5331 virCheckDomainReturn(domain, -1);
5332 conn = domain->conn;
5334 virCheckReadOnlyGoto(conn->flags, error);
5335 virCheckNonNullArgGoto(params, error);
5336 virCheckNonNegativeArgGoto(nparams, error);
5338 if (virTypedParameterValidateSet(conn, params, nparams) < 0)
5339 goto error;
5341 if (conn->driver->domainSetSchedulerParametersFlags) {
5342 int ret;
5343 ret = conn->driver->domainSetSchedulerParametersFlags(domain,
5344 params,
5345 nparams,
5346 flags);
5347 if (ret < 0)
5348 goto error;
5349 return ret;
5352 virReportUnsupportedError();
5354 error:
5355 virDispatchError(domain->conn);
5356 return -1;
5361 * virDomainBlockStats:
5362 * @dom: pointer to the domain object
5363 * @disk: path to the block device, or device shorthand
5364 * @stats: block device stats (returned)
5365 * @size: size of stats structure
5367 * This function returns block device (disk) stats for block
5368 * devices attached to the domain.
5370 * The @disk parameter is either the device target shorthand (the
5371 * <target dev='...'/> sub-element, such as "vda"), or (since 0.9.8)
5372 * an unambiguous source name of the block device (the <source
5373 * file='...'/> sub-element, such as "/path/to/image"). Valid names
5374 * can be found by calling virDomainGetXMLDesc() and inspecting
5375 * elements within //domain/devices/disk. Some drivers might also
5376 * accept the empty string for the @disk parameter, and then yield
5377 * summary stats for the entire domain.
5379 * Domains may have more than one block device. To get stats for
5380 * each you should make multiple calls to this function.
5382 * Individual fields within the stats structure may be returned
5383 * as -1, which indicates that the hypervisor does not support
5384 * that particular statistic.
5386 * Returns: 0 in case of success or -1 in case of failure.
5389 virDomainBlockStats(virDomainPtr dom, const char *disk,
5390 virDomainBlockStatsPtr stats, size_t size)
5392 virConnectPtr conn;
5393 virDomainBlockStatsStruct stats2 = { -1, -1, -1, -1, -1 };
5395 VIR_DOMAIN_DEBUG(dom, "disk=%s, stats=%p, size=%zi", disk, stats, size);
5397 virResetLastError();
5399 virCheckDomainReturn(dom, -1);
5400 virCheckNonNullArgGoto(disk, error);
5401 virCheckNonNullArgGoto(stats, error);
5402 if (size > sizeof(stats2)) {
5403 virReportInvalidArg(size,
5404 _("size must not exceed %zu"),
5405 sizeof(stats2));
5406 goto error;
5408 conn = dom->conn;
5410 if (conn->driver->domainBlockStats) {
5411 if (conn->driver->domainBlockStats(dom, disk, &stats2) == -1)
5412 goto error;
5414 memcpy(stats, &stats2, size);
5415 return 0;
5418 virReportUnsupportedError();
5420 error:
5421 virDispatchError(dom->conn);
5422 return -1;
5427 * virDomainBlockStatsFlags:
5428 * @dom: pointer to domain object
5429 * @disk: path to the block device, or device shorthand
5430 * @params: pointer to block stats parameter object
5431 * (return value, allocated by the caller)
5432 * @nparams: pointer to number of block stats; input and output
5433 * @flags: bitwise-OR of virTypedParameterFlags
5435 * This function is to get block stats parameters for block
5436 * devices attached to the domain.
5438 * The @disk parameter is either the device target shorthand (the
5439 * <target dev='...'/> sub-element, such as "vda"), or (since 0.9.8)
5440 * an unambiguous source name of the block device (the <source
5441 * file='...'/> sub-element, such as "/path/to/image"). Valid names
5442 * can be found by calling virDomainGetXMLDesc() and inspecting
5443 * elements within //domain/devices/disk. Some drivers might also
5444 * accept the empty string for the @disk parameter, and then yield
5445 * summary stats for the entire domain.
5447 * Domains may have more than one block device. To get stats for
5448 * each you should make multiple calls to this function.
5450 * On input, @nparams gives the size of the @params array; on output,
5451 * @nparams gives how many slots were filled with parameter
5452 * information, which might be less but will not exceed the input
5453 * value.
5455 * As a special case, calling with @params as NULL and @nparams as 0 on
5456 * input will cause @nparams on output to contain the number of parameters
5457 * supported by the hypervisor. (Note that block devices of different types
5458 * might support different parameters, so it might be necessary to compute
5459 * @nparams for each block device). The caller should then allocate @params
5460 * array, i.e. (sizeof(@virTypedParameter) * @nparams) bytes and call the API
5461 * again. See virDomainGetMemoryParameters() for more details.
5463 * Returns -1 in case of error, 0 in case of success.
5466 virDomainBlockStatsFlags(virDomainPtr dom,
5467 const char *disk,
5468 virTypedParameterPtr params,
5469 int *nparams,
5470 unsigned int flags)
5472 virConnectPtr conn;
5474 VIR_DOMAIN_DEBUG(dom, "disk=%s, params=%p, nparams=%d, flags=0x%x",
5475 disk, params, nparams ? *nparams : -1, flags);
5477 virResetLastError();
5479 virCheckDomainReturn(dom, -1);
5480 virCheckNonNullArgGoto(disk, error);
5481 virCheckNonNullArgGoto(nparams, error);
5482 virCheckNonNegativeArgGoto(*nparams, error);
5483 if (*nparams != 0)
5484 virCheckNonNullArgGoto(params, error);
5486 if (VIR_DRV_SUPPORTS_FEATURE(dom->conn->driver, dom->conn,
5487 VIR_DRV_FEATURE_TYPED_PARAM_STRING))
5488 flags |= VIR_TYPED_PARAM_STRING_OKAY;
5489 conn = dom->conn;
5491 if (conn->driver->domainBlockStatsFlags) {
5492 int ret;
5493 ret = conn->driver->domainBlockStatsFlags(dom, disk, params, nparams, flags);
5494 if (ret < 0)
5495 goto error;
5496 return ret;
5498 virReportUnsupportedError();
5500 error:
5501 virDispatchError(dom->conn);
5502 return -1;
5507 * virDomainInterfaceStats:
5508 * @dom: pointer to the domain object
5509 * @device: the interface name or MAC address
5510 * @stats: network interface stats (returned)
5511 * @size: size of stats structure
5513 * This function returns network interface stats for interfaces
5514 * attached to the domain.
5516 * The @device parameter is the network interface either by name or MAC
5517 * address.
5519 * Domains may have more than one network interface. To get stats for
5520 * each you should make multiple calls to this function.
5522 * Individual fields within the stats structure may be returned
5523 * as -1, which indicates that the hypervisor does not support
5524 * that particular statistic.
5526 * The returned stats are from domain's point of view.
5528 * Returns: 0 in case of success or -1 in case of failure.
5531 virDomainInterfaceStats(virDomainPtr dom, const char *device,
5532 virDomainInterfaceStatsPtr stats, size_t size)
5534 virConnectPtr conn;
5535 virDomainInterfaceStatsStruct stats2 = { -1, -1, -1, -1,
5536 -1, -1, -1, -1 };
5538 VIR_DOMAIN_DEBUG(dom, "device=%s, stats=%p, size=%zi",
5539 device, stats, size);
5541 virResetLastError();
5543 virCheckDomainReturn(dom, -1);
5544 virCheckNonNullArgGoto(device, error);
5545 virCheckNonNullArgGoto(stats, error);
5546 if (size > sizeof(stats2)) {
5547 virReportInvalidArg(size,
5548 _("size must not exceed %zu"),
5549 sizeof(stats2));
5550 goto error;
5553 conn = dom->conn;
5555 if (conn->driver->domainInterfaceStats) {
5556 if (conn->driver->domainInterfaceStats(dom, device, &stats2) == -1)
5557 goto error;
5559 memcpy(stats, &stats2, size);
5560 return 0;
5563 virReportUnsupportedError();
5565 error:
5566 virDispatchError(dom->conn);
5567 return -1;
5572 * virDomainSetInterfaceParameters:
5573 * @domain: pointer to domain object
5574 * @device: the interface name or mac address
5575 * @params: pointer to interface parameter objects
5576 * @nparams: number of interface parameter (this value can be the same or
5577 * less than the number of parameters supported)
5578 * @flags: bitwise-OR of virDomainModificationImpact
5580 * Change a subset or all parameters of interface; currently this
5581 * includes bandwidth parameters. The value of @flags should be
5582 * either VIR_DOMAIN_AFFECT_CURRENT, or a bitwise-or of values
5583 * VIR_DOMAIN_AFFECT_LIVE and VIR_DOMAIN_AFFECT_CONFIG, although
5584 * hypervisors vary in which flags are supported.
5586 * This function may require privileged access to the hypervisor.
5588 * Returns -1 in case of error, 0 in case of success.
5591 virDomainSetInterfaceParameters(virDomainPtr domain,
5592 const char *device,
5593 virTypedParameterPtr params,
5594 int nparams, unsigned int flags)
5596 virConnectPtr conn;
5598 VIR_DOMAIN_DEBUG(domain, "device=%s, params=%p, nparams=%d, flags=0x%x",
5599 device, params, nparams, flags);
5600 VIR_TYPED_PARAMS_DEBUG(params, nparams);
5602 virResetLastError();
5604 virCheckDomainReturn(domain, -1);
5605 conn = domain->conn;
5607 virCheckReadOnlyGoto(conn->flags, error);
5608 virCheckNonNullArgGoto(params, error);
5609 virCheckPositiveArgGoto(nparams, error);
5611 if (virTypedParameterValidateSet(conn, params, nparams) < 0)
5612 goto error;
5614 if (conn->driver->domainSetInterfaceParameters) {
5615 int ret;
5616 ret = conn->driver->domainSetInterfaceParameters(domain, device,
5617 params, nparams,
5618 flags);
5619 if (ret < 0)
5620 goto error;
5621 return ret;
5624 virReportUnsupportedError();
5626 error:
5627 virDispatchError(domain->conn);
5628 return -1;
5633 * virDomainGetInterfaceParameters:
5634 * @domain: pointer to domain object
5635 * @device: the interface name or mac address
5636 * @params: pointer to interface parameter objects
5637 * (return value, allocated by the caller)
5638 * @nparams: pointer to number of interface parameter; input and output
5639 * @flags: bitwise-OR of virDomainModificationImpact and virTypedParameterFlags
5641 * Get all interface parameters. On input, @nparams gives the size of
5642 * the @params array; on output, @nparams gives how many slots were
5643 * filled with parameter information, which might be less but will not
5644 * exceed the input value.
5646 * As a special case, calling with @params as NULL and @nparams as 0 on
5647 * input will cause @nparams on output to contain the number of parameters
5648 * supported by the hypervisor. The caller should then allocate @params
5649 * array, i.e. (sizeof(@virTypedParameter) * @nparams) bytes and call the
5650 * API again. See virDomainGetMemoryParameters() for an equivalent usage
5651 * example.
5653 * This function may require privileged access to the hypervisor. This function
5654 * expects the caller to allocate the @params.
5656 * Returns -1 in case of error, 0 in case of success.
5659 virDomainGetInterfaceParameters(virDomainPtr domain,
5660 const char *device,
5661 virTypedParameterPtr params,
5662 int *nparams, unsigned int flags)
5664 virConnectPtr conn;
5666 VIR_DOMAIN_DEBUG(domain, "device=%s, params=%p, nparams=%d, flags=0x%x",
5667 device, params, (nparams) ? *nparams : -1, flags);
5669 virResetLastError();
5671 virCheckDomainReturn(domain, -1);
5672 virCheckNonNullArgGoto(nparams, error);
5673 virCheckNonNegativeArgGoto(*nparams, error);
5674 if (*nparams != 0)
5675 virCheckNonNullArgGoto(params, error);
5677 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
5678 VIR_DRV_FEATURE_TYPED_PARAM_STRING))
5679 flags |= VIR_TYPED_PARAM_STRING_OKAY;
5681 conn = domain->conn;
5683 if (conn->driver->domainGetInterfaceParameters) {
5684 int ret;
5685 ret = conn->driver->domainGetInterfaceParameters(domain, device,
5686 params, nparams,
5687 flags);
5688 if (ret < 0)
5689 goto error;
5690 return ret;
5692 virReportUnsupportedError();
5694 error:
5695 virDispatchError(domain->conn);
5696 return -1;
5701 * virDomainMemoryStats:
5702 * @dom: pointer to the domain object
5703 * @stats: nr_stats-sized array of stat structures (returned)
5704 * @nr_stats: number of memory statistics requested
5705 * @flags: extra flags; not used yet, so callers should always pass 0
5707 * This function provides memory statistics for the domain.
5709 * Up to 'nr_stats' elements of 'stats' will be populated with memory statistics
5710 * from the domain. Only statistics supported by the domain, the driver, and
5711 * this version of libvirt will be returned.
5713 * Memory Statistics:
5715 * VIR_DOMAIN_MEMORY_STAT_SWAP_IN:
5716 * The total amount of data read from swap space (in kb).
5717 * VIR_DOMAIN_MEMORY_STAT_SWAP_OUT:
5718 * The total amount of memory written out to swap space (in kb).
5719 * VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT:
5720 * The number of page faults that required disk IO to service.
5721 * VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT:
5722 * The number of page faults serviced without disk IO.
5723 * VIR_DOMAIN_MEMORY_STAT_UNUSED:
5724 * The amount of memory which is not being used for any purpose (in kb).
5725 * VIR_DOMAIN_MEMORY_STAT_AVAILABLE:
5726 * The total amount of memory available to the domain's OS (in kb).
5727 * VIR_DOMAIN_MEMORY_STAT_USABLE:
5728 * How much the balloon can be inflated without pushing the guest system
5729 * to swap, corresponds to 'Available' in /proc/meminfo
5730 * VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON:
5731 * Current balloon value (in kb).
5732 * VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE
5733 * Timestamp of the last statistic
5734 * VIR_DOMAIN_MEMORY_STAT_DISK_CACHES
5735 * Memory that can be reclaimed without additional I/O, typically disk
5736 * caches (in kb).
5737 * VIR_DOMAIN_MEMORY_STAT_HUGETLB_PGALLOC
5738 * The amount of successful huge page allocations from inside the domain
5739 * VIR_DOMAIN_MEMORY_STAT_HUGETLB_PGFAIL
5740 * The amount of failed huge page allocations from inside the domain
5742 * Returns: The number of stats provided or -1 in case of failure.
5745 virDomainMemoryStats(virDomainPtr dom, virDomainMemoryStatPtr stats,
5746 unsigned int nr_stats, unsigned int flags)
5748 virConnectPtr conn;
5749 unsigned long nr_stats_ret = 0;
5751 VIR_DOMAIN_DEBUG(dom, "stats=%p, nr_stats=%u, flags=0x%x",
5752 stats, nr_stats, flags);
5754 virResetLastError();
5756 virCheckDomainReturn(dom, -1);
5758 if (!stats || nr_stats == 0)
5759 return 0;
5761 if (nr_stats > VIR_DOMAIN_MEMORY_STAT_NR)
5762 nr_stats = VIR_DOMAIN_MEMORY_STAT_NR;
5764 conn = dom->conn;
5765 if (conn->driver->domainMemoryStats) {
5766 nr_stats_ret = conn->driver->domainMemoryStats(dom, stats, nr_stats,
5767 flags);
5768 if (nr_stats_ret == -1)
5769 goto error;
5770 return nr_stats_ret;
5773 virReportUnsupportedError();
5775 error:
5776 virDispatchError(dom->conn);
5777 return -1;
5782 * virDomainBlockPeek:
5783 * @dom: pointer to the domain object
5784 * @disk: path to the block device, or device shorthand
5785 * @offset: offset within block device
5786 * @size: size to read
5787 * @buffer: return buffer (must be at least size bytes)
5788 * @flags: extra flags; not used yet, so callers should always pass 0
5790 * This function allows you to read the contents of a domain's
5791 * disk device.
5793 * Typical uses for this are to determine if the domain has
5794 * written a Master Boot Record (indicating that the domain
5795 * has completed installation), or to try to work out the state
5796 * of the domain's filesystems.
5798 * (Note that in the local case you might try to open the
5799 * block device or file directly, but that won't work in the
5800 * remote case, nor if you don't have sufficient permission.
5801 * Hence the need for this call).
5803 * The @disk parameter is either an unambiguous source name of the
5804 * block device (the <source file='...'/> sub-element, such as
5805 * "/path/to/image"), or (since 0.9.5) the device target shorthand
5806 * (the <target dev='...'/> sub-element, such as "vda"). Valid names
5807 * can be found by calling virDomainGetXMLDesc() and inspecting
5808 * elements within //domain/devices/disk.
5810 * 'offset' and 'size' represent an area which must lie entirely
5811 * within the device or file. 'size' may be 0 to test if the
5812 * call would succeed.
5814 * 'buffer' is the return buffer and must be at least 'size' bytes.
5816 * NB. The remote driver imposes a 64K byte limit on 'size'.
5817 * For your program to be able to work reliably over a remote
5818 * connection you should split large requests to <= 65536 bytes.
5819 * However, with 0.9.13 this RPC limit has been raised to 1M byte.
5820 * Starting with version 1.0.6 the RPC limit has been raised again.
5821 * Now large requests up to 16M byte are supported.
5823 * Returns: 0 in case of success or -1 in case of failure.
5826 virDomainBlockPeek(virDomainPtr dom,
5827 const char *disk,
5828 unsigned long long offset,
5829 size_t size,
5830 void *buffer,
5831 unsigned int flags)
5833 virConnectPtr conn;
5835 VIR_DOMAIN_DEBUG(dom, "disk=%s, offset=%lld, size=%zi, buffer=%p, flags=0x%x",
5836 disk, offset, size, buffer, flags);
5838 virResetLastError();
5840 virCheckDomainReturn(dom, -1);
5841 conn = dom->conn;
5843 virCheckReadOnlyGoto(conn->flags, error);
5844 virCheckNonEmptyStringArgGoto(disk, error);
5846 /* Allow size == 0 as an access test. */
5847 if (size > 0)
5848 virCheckNonNullArgGoto(buffer, error);
5850 if (conn->driver->domainBlockPeek) {
5851 int ret;
5852 ret = conn->driver->domainBlockPeek(dom, disk, offset, size,
5853 buffer, flags);
5854 if (ret < 0)
5855 goto error;
5856 return ret;
5859 virReportUnsupportedError();
5861 error:
5862 virDispatchError(dom->conn);
5863 return -1;
5868 * virDomainBlockResize:
5869 * @dom: pointer to the domain object
5870 * @disk: path to the block image, or shorthand
5871 * @size: new size of the block image, see below for unit
5872 * @flags: bitwise-OR of virDomainBlockResizeFlags
5874 * Resize a block device of domain while the domain is running. If
5875 * @flags is 0, then @size is in kibibytes (blocks of 1024 bytes);
5876 * since 0.9.11, if @flags includes VIR_DOMAIN_BLOCK_RESIZE_BYTES,
5877 * @size is in bytes instead. @size is taken directly as the new
5878 * size. Depending on the file format, the hypervisor may round up
5879 * to the next alignment boundary.
5881 * The @disk parameter is either an unambiguous source name of the
5882 * block device (the <source file='...'/> sub-element, such as
5883 * "/path/to/image"), or (since 0.9.5) the device target shorthand
5884 * (the <target dev='...'/> sub-element, such as "vda"). Valid names
5885 * can be found by calling virDomainGetXMLDesc() and inspecting
5886 * elements within //domain/devices/disk.
5888 * Note that this call may fail if the underlying virtualization hypervisor
5889 * does not support it; this call requires privileged access to the
5890 * hypervisor.
5892 * Returns: 0 in case of success or -1 in case of failure.
5895 virDomainBlockResize(virDomainPtr dom,
5896 const char *disk,
5897 unsigned long long size,
5898 unsigned int flags)
5900 virConnectPtr conn;
5902 VIR_DOMAIN_DEBUG(dom, "disk=%s, size=%llu, flags=0x%x", disk, size, flags);
5904 virResetLastError();
5906 virCheckDomainReturn(dom, -1);
5907 conn = dom->conn;
5909 virCheckReadOnlyGoto(conn->flags, error);
5910 virCheckNonNullArgGoto(disk, error);
5912 if (conn->driver->domainBlockResize) {
5913 int ret;
5914 ret = conn->driver->domainBlockResize(dom, disk, size, flags);
5915 if (ret < 0)
5916 goto error;
5917 return ret;
5920 virReportUnsupportedError();
5922 error:
5923 virDispatchError(dom->conn);
5924 return -1;
5929 * virDomainMemoryPeek:
5930 * @dom: pointer to the domain object
5931 * @start: start of memory to peek
5932 * @size: size of memory to peek
5933 * @buffer: return buffer (must be at least size bytes)
5934 * @flags: bitwise-OR of virDomainMemoryFlags
5936 * This function allows you to read the contents of a domain's
5937 * memory.
5939 * The memory which is read is controlled by the 'start', 'size'
5940 * and 'flags' parameters.
5942 * If 'flags' is VIR_MEMORY_VIRTUAL then the 'start' and 'size'
5943 * parameters are interpreted as virtual memory addresses for
5944 * whichever task happens to be running on the domain at the
5945 * moment. Although this sounds haphazard it is in fact what
5946 * you want in order to read Linux kernel state, because it
5947 * ensures that pointers in the kernel image can be interpreted
5948 * coherently.
5950 * 'buffer' is the return buffer and must be at least 'size' bytes.
5951 * 'size' may be 0 to test if the call would succeed.
5953 * NB. The remote driver imposes a 64K byte limit on 'size'.
5954 * For your program to be able to work reliably over a remote
5955 * connection you should split large requests to <= 65536 bytes.
5956 * However, with 0.9.13 this RPC limit has been raised to 1M byte.
5957 * Starting with version 1.0.6 the RPC limit has been raised again.
5958 * Now large requests up to 16M byte are supported.
5960 * Returns: 0 in case of success or -1 in case of failure.
5963 virDomainMemoryPeek(virDomainPtr dom,
5964 unsigned long long start,
5965 size_t size,
5966 void *buffer,
5967 unsigned int flags)
5969 virConnectPtr conn;
5971 VIR_DOMAIN_DEBUG(dom, "start=%lld, size=%zi, buffer=%p, flags=0x%x",
5972 start, size, buffer, flags);
5974 virResetLastError();
5976 virCheckDomainReturn(dom, -1);
5977 conn = dom->conn;
5979 virCheckReadOnlyGoto(conn->flags, error);
5981 /* Note on access to physical memory: A VIR_MEMORY_PHYSICAL flag is
5982 * a possibility. However it isn't really useful unless the caller
5983 * can also access registers, particularly CR3 on x86 in order to
5984 * get the Page Table Directory. Since registers are different on
5985 * every architecture, that would imply another call to get the
5986 * machine registers.
5988 * The QEMU driver handles VIR_MEMORY_VIRTUAL, mapping it
5989 * to the qemu 'memsave' command which does the virtual to physical
5990 * mapping inside qemu.
5992 * The QEMU driver also handles VIR_MEMORY_PHYSICAL, mapping it
5993 * to the qemu 'pmemsave' command.
5995 * At time of writing there is no Xen driver. However the Xen
5996 * hypervisor only lets you map physical pages from other domains,
5997 * and so the Xen driver would have to do the virtual to physical
5998 * mapping by chasing 2, 3 or 4-level page tables from the PTD.
5999 * There is example code in libxc (xc_translate_foreign_address)
6000 * which does this, although we cannot copy this code directly
6001 * because of incompatible licensing.
6004 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_MEMORY_VIRTUAL, VIR_MEMORY_PHYSICAL, error);
6006 /* Allow size == 0 as an access test. */
6007 if (size > 0)
6008 virCheckNonNullArgGoto(buffer, error);
6010 if (conn->driver->domainMemoryPeek) {
6011 int ret;
6012 ret = conn->driver->domainMemoryPeek(dom, start, size,
6013 buffer, flags);
6014 if (ret < 0)
6015 goto error;
6016 return ret;
6019 virReportUnsupportedError();
6021 error:
6022 virDispatchError(dom->conn);
6023 return -1;
6028 * virDomainGetBlockInfo:
6029 * @domain: a domain object
6030 * @disk: path to the block device, or device shorthand
6031 * @info: pointer to a virDomainBlockInfo structure allocated by the user
6032 * @flags: extra flags; not used yet, so callers should always pass 0
6034 * Extract information about a domain's block device.
6036 * The @disk parameter is either an unambiguous source name of the
6037 * block device (the <source file='...'/> sub-element, such as
6038 * "/path/to/image"), or (since 0.9.5) the device target shorthand
6039 * (the <target dev='...'/> sub-element, such as "vda"). Valid names
6040 * can be found by calling virDomainGetXMLDesc() and inspecting
6041 * elements within //domain/devices/disk.
6043 * For QEMU domains, the allocation and physical virDomainBlockInfo
6044 * values returned will generally be the same, except when using a
6045 * non raw, block backing device, such as qcow2 for an active domain.
6046 * When the persistent domain is not active, QEMU will return the
6047 * default which is the same value for allocation and physical.
6049 * Active QEMU domains can return an allocation value which is more
6050 * representative of the currently used blocks by the device compared
6051 * to the physical size of the device. Applications can use/monitor
6052 * the allocation value with the understanding that if the domain
6053 * becomes inactive during an attempt to get the value, the default
6054 * values will be returned. Thus, the application should check
6055 * after the call for the domain being inactive if the values are
6056 * the same. Optionally, the application could be watching for a
6057 * shutdown event and then ignore any values received afterwards.
6058 * This can be an issue when a domain is being migrated and the
6059 * exact timing of the domain being made inactive and check of
6060 * the allocation value results the default being returned. For
6061 * a transient domain in the similar situation, this call will return
6062 * -1 and an error message indicating the "domain is not running".
6064 * The following is some pseudo code illustrating the call sequence:
6066 * ...
6067 * virDomainPtr dom;
6068 * virDomainBlockInfo info;
6069 * char *device;
6070 * ...
6071 * // Either get a list of all domains or a specific domain
6072 * // via a virDomainLookupBy*() call.
6073 * //
6074 * // It's also required to fill in the device pointer, but that's
6075 * // specific to the implementation. For the purposes of this example
6076 * // a qcow2 backed device name string would need to be provided.
6077 * ...
6078 * // If the following call is made on a persistent domain with a
6079 * // qcow2 block backed block device, then it's possible the returned
6080 * // allocation equals the physical value. In that case, the domain
6081 * // that may have been active prior to calling has become inactive,
6082 * // such as is the case during a domain migration. Thus once we
6083 * // get data returned, check for active domain when the values are
6084 * // the same.
6085 * if (virDomainGetBlockInfo(dom, device, &info, 0) < 0)
6086 * goto failure;
6087 * if (info.allocation == info.physical) {
6088 * // If the domain is no longer active,
6089 * // then the defaults are being returned.
6090 * if (!virDomainIsActive())
6091 * goto ignore_return;
6093 * // Do something with the allocation and physical values
6094 * ...
6096 * Returns 0 in case of success and -1 in case of failure.
6099 virDomainGetBlockInfo(virDomainPtr domain, const char *disk,
6100 virDomainBlockInfoPtr info, unsigned int flags)
6102 virConnectPtr conn;
6104 VIR_DOMAIN_DEBUG(domain, "info=%p, flags=0x%x", info, flags);
6106 virResetLastError();
6108 if (info)
6109 memset(info, 0, sizeof(*info));
6111 virCheckDomainReturn(domain, -1);
6112 virCheckNonEmptyStringArgGoto(disk, error);
6113 virCheckNonNullArgGoto(info, error);
6115 conn = domain->conn;
6117 if (conn->driver->domainGetBlockInfo) {
6118 int ret;
6119 ret = conn->driver->domainGetBlockInfo(domain, disk, info, flags);
6120 if (ret < 0)
6121 goto error;
6122 return ret;
6125 virReportUnsupportedError();
6127 error:
6128 virDispatchError(domain->conn);
6129 return -1;
6134 * virDomainDefineXML:
6135 * @conn: pointer to the hypervisor connection
6136 * @xml: the XML description for the domain, preferably in UTF-8
6138 * Define a domain, but does not start it.
6139 * This definition is persistent, until explicitly undefined with
6140 * virDomainUndefine(). A previous definition for this domain would be
6141 * overridden if it already exists.
6143 * virDomainFree should be used to free the resources after the
6144 * domain object is no longer needed.
6146 * Returns NULL in case of error, a pointer to the domain otherwise
6148 virDomainPtr
6149 virDomainDefineXML(virConnectPtr conn, const char *xml)
6151 VIR_DEBUG("conn=%p, xml=%s", conn, NULLSTR(xml));
6153 virResetLastError();
6155 virCheckConnectReturn(conn, NULL);
6156 virCheckReadOnlyGoto(conn->flags, error);
6157 virCheckNonNullArgGoto(xml, error);
6159 if (conn->driver->domainDefineXML) {
6160 virDomainPtr ret;
6161 ret = conn->driver->domainDefineXML(conn, xml);
6162 if (!ret)
6163 goto error;
6164 return ret;
6167 virReportUnsupportedError();
6169 error:
6170 virDispatchError(conn);
6171 return NULL;
6176 * virDomainDefineXMLFlags:
6177 * @conn: pointer to the hypervisor connection
6178 * @xml: the XML description for the domain, preferably in UTF-8
6179 * @flags: bitwise OR of the virDomainDefineFlags constants
6181 * Defines a domain, but does not start it.
6182 * This definition is persistent, until explicitly undefined with
6183 * virDomainUndefine(). A previous definition for this domain would be
6184 * overridden if it already exists.
6186 * virDomainFree should be used to free the resources after the
6187 * domain object is no longer needed.
6189 * Returns NULL in case of error, a pointer to the domain otherwise
6191 virDomainPtr
6192 virDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
6194 VIR_DEBUG("conn=%p, xml=%s flags=0x%x", conn, NULLSTR(xml), flags);
6196 virResetLastError();
6198 virCheckConnectReturn(conn, NULL);
6199 virCheckReadOnlyGoto(conn->flags, error);
6200 virCheckNonNullArgGoto(xml, error);
6202 if (conn->driver->domainDefineXMLFlags) {
6203 virDomainPtr ret;
6204 ret = conn->driver->domainDefineXMLFlags(conn, xml, flags);
6205 if (!ret)
6206 goto error;
6207 return ret;
6210 virReportUnsupportedError();
6212 error:
6213 virDispatchError(conn);
6214 return NULL;
6219 * virDomainUndefine:
6220 * @domain: pointer to a defined domain
6222 * Undefine a domain. If the domain is running, it's converted to
6223 * transient domain, without stopping it. If the domain is inactive,
6224 * the domain configuration is removed.
6226 * If the domain has a managed save image (see
6227 * virDomainHasManagedSaveImage()), or if it is inactive and has any
6228 * snapshot metadata (see virDomainSnapshotNum()), then the undefine will
6229 * fail. See virDomainUndefineFlags() for more control.
6231 * Returns 0 in case of success, -1 in case of error
6234 virDomainUndefine(virDomainPtr domain)
6236 virConnectPtr conn;
6238 VIR_DOMAIN_DEBUG(domain);
6240 virResetLastError();
6242 virCheckDomainReturn(domain, -1);
6243 conn = domain->conn;
6245 virCheckReadOnlyGoto(conn->flags, error);
6247 if (conn->driver->domainUndefine) {
6248 int ret;
6249 ret = conn->driver->domainUndefine(domain);
6250 if (ret < 0)
6251 goto error;
6252 return ret;
6255 virReportUnsupportedError();
6257 error:
6258 virDispatchError(domain->conn);
6259 return -1;
6264 * virDomainUndefineFlags:
6265 * @domain: pointer to a defined domain
6266 * @flags: bitwise-OR of supported virDomainUndefineFlagsValues
6268 * Undefine a domain. If the domain is running, it's converted to
6269 * transient domain, without stopping it. If the domain is inactive,
6270 * the domain configuration is removed.
6272 * If the domain has a managed save image (see virDomainHasManagedSaveImage()),
6273 * then including VIR_DOMAIN_UNDEFINE_MANAGED_SAVE in @flags will also remove
6274 * that file, and omitting the flag will cause the undefine process to fail.
6276 * If the domain is inactive and has any snapshot metadata (see
6277 * virDomainSnapshotNum()), then including
6278 * VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA in @flags will also remove
6279 * that metadata. Omitting the flag will cause the undefine of an
6280 * inactive domain to fail. Active snapshots will retain snapshot
6281 * metadata until the (now-transient) domain halts, regardless of
6282 * whether this flag is present. On hypervisors where snapshots do
6283 * not use libvirt metadata, this flag has no effect.
6285 * If the domain has any nvram specified, the undefine process will fail
6286 * unless VIR_DOMAIN_UNDEFINE_KEEP_NVRAM is specified, or if
6287 * VIR_DOMAIN_UNDEFINE_NVRAM is specified to remove the nvram file.
6289 * Returns 0 in case of success, -1 in case of error
6292 virDomainUndefineFlags(virDomainPtr domain,
6293 unsigned int flags)
6295 virConnectPtr conn;
6297 VIR_DOMAIN_DEBUG(domain, "flags=0x%x", flags);
6299 virResetLastError();
6301 virCheckDomainReturn(domain, -1);
6302 conn = domain->conn;
6304 virCheckReadOnlyGoto(conn->flags, error);
6306 if (conn->driver->domainUndefineFlags) {
6307 int ret;
6308 ret = conn->driver->domainUndefineFlags(domain, flags);
6309 if (ret < 0)
6310 goto error;
6311 return ret;
6314 virReportUnsupportedError();
6316 error:
6317 virDispatchError(domain->conn);
6318 return -1;
6323 * virConnectNumOfDefinedDomains:
6324 * @conn: pointer to the hypervisor connection
6326 * Provides the number of defined but inactive domains.
6328 * Returns the number of domain found or -1 in case of error
6331 virConnectNumOfDefinedDomains(virConnectPtr conn)
6333 VIR_DEBUG("conn=%p", conn);
6335 virResetLastError();
6337 virCheckConnectReturn(conn, -1);
6339 if (conn->driver->connectNumOfDefinedDomains) {
6340 int ret;
6341 ret = conn->driver->connectNumOfDefinedDomains(conn);
6342 if (ret < 0)
6343 goto error;
6344 return ret;
6347 virReportUnsupportedError();
6349 error:
6350 virDispatchError(conn);
6351 return -1;
6356 * virConnectListDefinedDomains:
6357 * @conn: pointer to the hypervisor connection
6358 * @names: pointer to an array to store the names
6359 * @maxnames: size of the array
6361 * list the defined but inactive domains, stores the pointers to the names
6362 * in @names
6364 * For active domains, see virConnectListDomains(). For more control over
6365 * the results, see virConnectListAllDomains().
6367 * Returns the number of names provided in the array or -1 in case of error.
6368 * Note that this command is inherently racy; a domain can be defined between
6369 * a call to virConnectNumOfDefinedDomains() and this call; you are only
6370 * guaranteed that all currently defined domains were listed if the return
6371 * is less than @maxids. The client must call free() on each returned name.
6374 virConnectListDefinedDomains(virConnectPtr conn, char **const names,
6375 int maxnames)
6377 VIR_DEBUG("conn=%p, names=%p, maxnames=%d", conn, names, maxnames);
6379 virResetLastError();
6381 virCheckConnectReturn(conn, -1);
6382 virCheckNonNullArgGoto(names, error);
6383 virCheckNonNegativeArgGoto(maxnames, error);
6385 if (conn->driver->connectListDefinedDomains) {
6386 int ret;
6387 ret = conn->driver->connectListDefinedDomains(conn, names, maxnames);
6388 if (ret < 0)
6389 goto error;
6390 return ret;
6393 virReportUnsupportedError();
6395 error:
6396 virDispatchError(conn);
6397 return -1;
6402 * virConnectListAllDomains:
6403 * @conn: Pointer to the hypervisor connection.
6404 * @domains: Pointer to a variable to store the array containing domain objects
6405 * or NULL if the list is not required (just returns number of guests).
6406 * @flags: bitwise-OR of virConnectListAllDomainsFlags
6408 * Collect a possibly-filtered list of all domains, and return an allocated
6409 * array of information for each. This API solves the race inherent in
6410 * virConnectListDomains() and virConnectListDefinedDomains().
6412 * Normally, all domains are returned; however, @flags can be used to
6413 * filter the results for a smaller list of targeted domains. The valid
6414 * flags are divided into groups, where each group contains bits that
6415 * describe mutually exclusive attributes of a domain, and where all bits
6416 * within a group describe all possible domains. Some hypervisors might
6417 * reject explicit bits from a group where the hypervisor cannot make a
6418 * distinction (for example, not all hypervisors can tell whether domains
6419 * have snapshots). For a group supported by a given hypervisor, the
6420 * behavior when no bits of a group are set is identical to the behavior
6421 * when all bits in that group are set. When setting bits from more than
6422 * one group, it is possible to select an impossible combination (such
6423 * as an inactive transient domain), in that case a hypervisor may return
6424 * either 0 or an error.
6426 * The first group of @flags is VIR_CONNECT_LIST_DOMAINS_ACTIVE (online
6427 * domains) and VIR_CONNECT_LIST_DOMAINS_INACTIVE (offline domains).
6429 * The next group of @flags is VIR_CONNECT_LIST_DOMAINS_PERSISTENT (defined
6430 * domains) and VIR_CONNECT_LIST_DOMAINS_TRANSIENT (running but not defined).
6432 * The next group of @flags covers various domain states:
6433 * VIR_CONNECT_LIST_DOMAINS_RUNNING, VIR_CONNECT_LIST_DOMAINS_PAUSED,
6434 * VIR_CONNECT_LIST_DOMAINS_SHUTOFF, and a catch-all for all other states
6435 * (such as crashed, this catch-all covers the possibility of adding new
6436 * states).
6438 * The remaining groups cover boolean attributes commonly asked about
6439 * domains; they include VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE and
6440 * VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE, for filtering based on whether
6441 * a managed save image exists; VIR_CONNECT_LIST_DOMAINS_AUTOSTART and
6442 * VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART, for filtering based on autostart;
6443 * VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT and
6444 * VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT, for filtering based on whether
6445 * a domain has snapshots.
6447 * Example of usage:
6449 * virDomainPtr *domains;
6450 * size_t i;
6451 * int ret;
6452 * unsigned int flags = VIR_CONNECT_LIST_DOMAINS_RUNNING |
6453 * VIR_CONNECT_LIST_DOMAINS_PERSISTENT;
6454 * ret = virConnectListAllDomains(conn, &domains, flags);
6455 * if (ret < 0)
6456 * error();
6457 * for (i = 0; i < ret; i++) {
6458 * do_something_with_domain(domains[i]);
6459 * //here or in a separate loop if needed
6460 * virDomainFree(domains[i]);
6462 * free(domains);
6464 * Returns the number of domains found or -1 and sets domains to NULL in case of
6465 * error. On success, the array stored into @domains is guaranteed to have an
6466 * extra allocated element set to NULL but not included in the return count, to
6467 * make iteration easier. The caller is responsible for calling virDomainFree()
6468 * on each array element, then calling free() on @domains.
6471 virConnectListAllDomains(virConnectPtr conn,
6472 virDomainPtr **domains,
6473 unsigned int flags)
6475 VIR_DEBUG("conn=%p, domains=%p, flags=0x%x", conn, domains, flags);
6477 virResetLastError();
6479 if (domains)
6480 *domains = NULL;
6482 virCheckConnectReturn(conn, -1);
6484 if (conn->driver->connectListAllDomains) {
6485 int ret;
6486 ret = conn->driver->connectListAllDomains(conn, domains, flags);
6487 if (ret < 0)
6488 goto error;
6489 return ret;
6492 virReportUnsupportedError();
6494 error:
6495 virDispatchError(conn);
6496 return -1;
6501 * virDomainCreate:
6502 * @domain: pointer to a defined domain
6504 * Launch a defined domain. If the call succeeds the domain moves from the
6505 * defined to the running domains pools. The domain will be paused only
6506 * if restoring from managed state created from a paused domain. For more
6507 * control, see virDomainCreateWithFlags().
6509 * Returns 0 in case of success, -1 in case of error
6512 virDomainCreate(virDomainPtr domain)
6514 virConnectPtr conn;
6516 VIR_DOMAIN_DEBUG(domain);
6518 virResetLastError();
6520 virCheckDomainReturn(domain, -1);
6521 conn = domain->conn;
6523 virCheckReadOnlyGoto(conn->flags, error);
6525 if (conn->driver->domainCreate) {
6526 int ret;
6527 ret = conn->driver->domainCreate(domain);
6528 if (ret < 0)
6529 goto error;
6530 return ret;
6533 virReportUnsupportedError();
6535 error:
6536 virDispatchError(domain->conn);
6537 return -1;
6542 * virDomainCreateWithFlags:
6543 * @domain: pointer to a defined domain
6544 * @flags: bitwise-OR of supported virDomainCreateFlags
6546 * Launch a defined domain. If the call succeeds the domain moves from the
6547 * defined to the running domains pools.
6549 * If the VIR_DOMAIN_START_PAUSED flag is set, or if the guest domain
6550 * has a managed save image that requested paused state (see
6551 * virDomainManagedSave()) the guest domain will be started, but its
6552 * CPUs will remain paused. The CPUs can later be manually started
6553 * using virDomainResume(). In all other cases, the guest domain will
6554 * be running.
6556 * If the VIR_DOMAIN_START_AUTODESTROY flag is set, the guest
6557 * domain will be automatically destroyed when the virConnectPtr
6558 * object is finally released. This will also happen if the
6559 * client application crashes / loses its connection to the
6560 * libvirtd daemon. Any domains marked for auto destroy will
6561 * block attempts at migration, save-to-file, or snapshots.
6563 * If the VIR_DOMAIN_START_BYPASS_CACHE flag is set, and there is a
6564 * managed save file for this domain (created by virDomainManagedSave()),
6565 * then libvirt will attempt to bypass the file system cache while restoring
6566 * the file, or fail if it cannot do so for the given system; this can allow
6567 * less pressure on file system cache, but also risks slowing loads from NFS.
6569 * If the VIR_DOMAIN_START_FORCE_BOOT flag is set, then any managed save
6570 * file for this domain is discarded, and the domain boots from scratch.
6572 * Returns 0 in case of success, -1 in case of error
6575 virDomainCreateWithFlags(virDomainPtr domain, unsigned int flags)
6577 virConnectPtr conn;
6579 VIR_DOMAIN_DEBUG(domain, "flags=0x%x", flags);
6581 virResetLastError();
6583 virCheckDomainReturn(domain, -1);
6584 conn = domain->conn;
6586 virCheckReadOnlyGoto(conn->flags, error);
6588 if (conn->driver->domainCreateWithFlags) {
6589 int ret;
6590 ret = conn->driver->domainCreateWithFlags(domain, flags);
6591 if (ret < 0)
6592 goto error;
6593 return ret;
6596 virReportUnsupportedError();
6598 error:
6599 virDispatchError(domain->conn);
6600 return -1;
6605 * virDomainCreateWithFiles:
6606 * @domain: pointer to a defined domain
6607 * @nfiles: number of file descriptors passed
6608 * @files: list of file descriptors passed
6609 * @flags: bitwise-OR of supported virDomainCreateFlags
6611 * Launch a defined domain. If the call succeeds the domain moves from the
6612 * defined to the running domains pools.
6614 * @files provides an array of file descriptors which will be
6615 * made available to the 'init' process of the guest. The file
6616 * handles exposed to the guest will be renumbered to start
6617 * from 3 (ie immediately following stderr). This is only
6618 * supported for guests which use container based virtualization
6619 * technology.
6621 * If the VIR_DOMAIN_START_PAUSED flag is set, or if the guest domain
6622 * has a managed save image that requested paused state (see
6623 * virDomainManagedSave()) the guest domain will be started, but its
6624 * CPUs will remain paused. The CPUs can later be manually started
6625 * using virDomainResume(). In all other cases, the guest domain will
6626 * be running.
6628 * If the VIR_DOMAIN_START_AUTODESTROY flag is set, the guest
6629 * domain will be automatically destroyed when the virConnectPtr
6630 * object is finally released. This will also happen if the
6631 * client application crashes / loses its connection to the
6632 * libvirtd daemon. Any domains marked for auto destroy will
6633 * block attempts at migration, save-to-file, or snapshots.
6635 * If the VIR_DOMAIN_START_BYPASS_CACHE flag is set, and there is a
6636 * managed save file for this domain (created by virDomainManagedSave()),
6637 * then libvirt will attempt to bypass the file system cache while restoring
6638 * the file, or fail if it cannot do so for the given system; this can allow
6639 * less pressure on file system cache, but also risks slowing loads from NFS.
6641 * If the VIR_DOMAIN_START_FORCE_BOOT flag is set, then any managed save
6642 * file for this domain is discarded, and the domain boots from scratch.
6644 * Returns 0 in case of success, -1 in case of error
6647 virDomainCreateWithFiles(virDomainPtr domain, unsigned int nfiles,
6648 int *files, unsigned int flags)
6650 virConnectPtr conn;
6652 VIR_DOMAIN_DEBUG(domain, "nfiles=%u, files=%p, flags=0x%x",
6653 nfiles, files, flags);
6655 virResetLastError();
6657 virCheckDomainReturn(domain, -1);
6658 conn = domain->conn;
6660 virCheckReadOnlyGoto(conn->flags, error);
6662 if (conn->driver->domainCreateWithFiles) {
6663 int ret;
6664 ret = conn->driver->domainCreateWithFiles(domain,
6665 nfiles, files,
6666 flags);
6667 if (ret < 0)
6668 goto error;
6669 return ret;
6672 virReportUnsupportedError();
6674 error:
6675 virDispatchError(domain->conn);
6676 return -1;
6681 * virDomainGetAutostart:
6682 * @domain: a domain object
6683 * @autostart: the value returned
6685 * Provides a boolean value indicating whether the domain
6686 * configured to be automatically started when the host
6687 * machine boots.
6689 * Please note that this might result in unexpected behaviour if
6690 * used for some session URIs. Since the session daemon is started
6691 * with --timeout it comes and goes and as it does so it
6692 * autostarts domains which might have been shut off recently.
6694 * Returns -1 in case of error, 0 in case of success
6697 virDomainGetAutostart(virDomainPtr domain,
6698 int *autostart)
6700 virConnectPtr conn;
6702 VIR_DOMAIN_DEBUG(domain, "autostart=%p", autostart);
6704 virResetLastError();
6706 virCheckDomainReturn(domain, -1);
6707 virCheckNonNullArgGoto(autostart, error);
6709 conn = domain->conn;
6711 if (conn->driver->domainGetAutostart) {
6712 int ret;
6713 ret = conn->driver->domainGetAutostart(domain, autostart);
6714 if (ret < 0)
6715 goto error;
6716 return ret;
6719 virReportUnsupportedError();
6721 error:
6722 virDispatchError(domain->conn);
6723 return -1;
6728 * virDomainSetAutostart:
6729 * @domain: a domain object
6730 * @autostart: whether the domain should be automatically started 0 or 1
6732 * Configure the domain to be automatically started
6733 * when the host machine boots.
6735 * Returns -1 in case of error, 0 in case of success
6738 virDomainSetAutostart(virDomainPtr domain,
6739 int autostart)
6741 virConnectPtr conn;
6743 VIR_DOMAIN_DEBUG(domain, "autostart=%d", autostart);
6745 virResetLastError();
6747 virCheckDomainReturn(domain, -1);
6748 conn = domain->conn;
6750 virCheckReadOnlyGoto(conn->flags, error);
6752 if (conn->driver->domainSetAutostart) {
6753 int ret;
6754 ret = conn->driver->domainSetAutostart(domain, autostart);
6755 if (ret < 0)
6756 goto error;
6757 return ret;
6760 virReportUnsupportedError();
6762 error:
6763 virDispatchError(domain->conn);
6764 return -1;
6769 * virDomainInjectNMI:
6770 * @domain: pointer to domain object, or NULL for Domain0
6771 * @flags: extra flags; not used yet, so callers should always pass 0
6773 * Send NMI to the guest
6775 * Returns 0 in case of success, -1 in case of failure.
6778 virDomainInjectNMI(virDomainPtr domain, unsigned int flags)
6780 virConnectPtr conn;
6781 VIR_DOMAIN_DEBUG(domain, "flags=0x%x", flags);
6783 virResetLastError();
6785 virCheckDomainReturn(domain, -1);
6786 conn = domain->conn;
6788 virCheckReadOnlyGoto(conn->flags, error);
6790 if (conn->driver->domainInjectNMI) {
6791 int ret;
6792 ret = conn->driver->domainInjectNMI(domain, flags);
6793 if (ret < 0)
6794 goto error;
6795 return ret;
6798 virReportUnsupportedError();
6800 error:
6801 virDispatchError(domain->conn);
6802 return -1;
6807 * virDomainSendKey:
6808 * @domain: pointer to domain object, or NULL for Domain0
6809 * @codeset: the code set of keycodes, from virKeycodeSet
6810 * @holdtime: the duration (in milliseconds) that the keys will be held
6811 * @keycodes: array of keycodes
6812 * @nkeycodes: number of keycodes, up to VIR_DOMAIN_SEND_KEY_MAX_KEYS
6813 * @flags: extra flags; not used yet, so callers should always pass 0
6815 * Send key(s) to the guest.
6817 * Returns 0 in case of success, -1 in case of failure.
6820 virDomainSendKey(virDomainPtr domain,
6821 unsigned int codeset,
6822 unsigned int holdtime,
6823 unsigned int *keycodes,
6824 int nkeycodes,
6825 unsigned int flags)
6827 virConnectPtr conn;
6828 VIR_DOMAIN_DEBUG(domain, "codeset=%u, holdtime=%u, nkeycodes=%u, flags=0x%x",
6829 codeset, holdtime, nkeycodes, flags);
6831 virResetLastError();
6833 virCheckDomainReturn(domain, -1);
6834 conn = domain->conn;
6836 virCheckReadOnlyGoto(conn->flags, error);
6837 virCheckNonNullArgGoto(keycodes, error);
6838 virCheckPositiveArgGoto(nkeycodes, error);
6840 if (codeset >= VIR_KEYCODE_SET_LAST) {
6841 virReportInvalidArg(codeset,
6842 _("Unsupported codeset '%d'"),
6843 codeset);
6844 goto error;
6847 if (nkeycodes > VIR_DOMAIN_SEND_KEY_MAX_KEYS) {
6848 virReportInvalidArg(nkeycodes,
6849 _("nkeycodes must be <= %d"),
6850 VIR_DOMAIN_SEND_KEY_MAX_KEYS);
6851 goto error;
6854 if (conn->driver->domainSendKey) {
6855 int ret;
6856 ret = conn->driver->domainSendKey(domain, codeset, holdtime,
6857 keycodes, nkeycodes, flags);
6858 if (ret < 0)
6859 goto error;
6860 return ret;
6863 virReportUnsupportedError();
6865 error:
6866 virDispatchError(domain->conn);
6867 return -1;
6872 * virDomainSendProcessSignal:
6873 * @domain: pointer to domain object
6874 * @pid_value: a positive integer process ID, or negative integer process group ID
6875 * @signum: a signal from the virDomainProcessSignal enum
6876 * @flags: currently unused, pass 0
6878 * Send a signal to the designated process in the guest
6880 * The signal numbers must be taken from the virDomainProcessSignal
6881 * enum. These will be translated to the corresponding signal
6882 * number for the guest OS, by the guest agent delivering the
6883 * signal. If there is no mapping from virDomainProcessSignal to
6884 * the native OS signals, this API will report an error.
6886 * If @pid_value is an integer greater than zero, it is
6887 * treated as a process ID. If @pid_value is an integer
6888 * less than zero, it is treated as a process group ID.
6889 * All the @pid_value numbers are from the container/guest
6890 * namespace. The value zero is not valid.
6892 * Not all hypervisors will support sending signals to
6893 * arbitrary processes or process groups. If this API is
6894 * implemented the minimum requirement is to be able to
6895 * use @pid_value == 1 (i.e. kill init). No other value is
6896 * required to be supported.
6898 * If the @signum is VIR_DOMAIN_PROCESS_SIGNAL_NOP then this
6899 * API will simply report whether the process is running in
6900 * the container/guest.
6902 * Returns 0 in case of success, -1 in case of failure.
6905 virDomainSendProcessSignal(virDomainPtr domain,
6906 long long pid_value,
6907 unsigned int signum,
6908 unsigned int flags)
6910 virConnectPtr conn;
6911 VIR_DOMAIN_DEBUG(domain, "pid=%lld, signum=%u flags=0x%x",
6912 pid_value, signum, flags);
6914 virResetLastError();
6916 virCheckDomainReturn(domain, -1);
6917 conn = domain->conn;
6919 virCheckNonZeroArgGoto(pid_value, error);
6920 virCheckReadOnlyGoto(conn->flags, error);
6922 if (conn->driver->domainSendProcessSignal) {
6923 int ret;
6924 ret = conn->driver->domainSendProcessSignal(domain,
6925 pid_value,
6926 signum,
6927 flags);
6928 if (ret < 0)
6929 goto error;
6930 return ret;
6933 virReportUnsupportedError();
6935 error:
6936 virDispatchError(domain->conn);
6937 return -1;
6942 * virDomainSetVcpus:
6943 * @domain: pointer to domain object, or NULL for Domain0
6944 * @nvcpus: the new number of virtual CPUs for this domain
6946 * Dynamically change the number of virtual CPUs used by the domain.
6947 * Note that this call may fail if the underlying virtualization hypervisor
6948 * does not support it or if growing the number is arbitrarily limited.
6949 * This function may require privileged access to the hypervisor.
6951 * Note that if this call is executed before the guest has finished booting,
6952 * the guest may fail to process the change.
6954 * This command only changes the runtime configuration of the domain,
6955 * so can only be called on an active domain. It is hypervisor-dependent
6956 * whether it also affects persistent configuration; for more control,
6957 * use virDomainSetVcpusFlags().
6959 * Returns 0 in case of success, -1 in case of failure.
6962 virDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
6964 virConnectPtr conn;
6966 VIR_DOMAIN_DEBUG(domain, "nvcpus=%u", nvcpus);
6968 virResetLastError();
6970 virCheckDomainReturn(domain, -1);
6971 conn = domain->conn;
6973 virCheckReadOnlyGoto(conn->flags, error);
6974 virCheckNonZeroArgGoto(nvcpus, error);
6976 if (conn->driver->domainSetVcpus) {
6977 int ret;
6978 ret = conn->driver->domainSetVcpus(domain, nvcpus);
6979 if (ret < 0)
6980 goto error;
6981 return ret;
6984 virReportUnsupportedError();
6986 error:
6987 virDispatchError(domain->conn);
6988 return -1;
6993 * virDomainSetVcpusFlags:
6994 * @domain: pointer to domain object, or NULL for Domain0
6995 * @nvcpus: the new number of virtual CPUs for this domain, must be at least 1
6996 * @flags: bitwise-OR of virDomainVcpuFlags
6998 * Dynamically change the number of virtual CPUs used by the domain.
6999 * Note that this call may fail if the underlying virtualization hypervisor
7000 * does not support it or if growing the number is arbitrarily limited.
7001 * This function may require privileged access to the hypervisor.
7003 * @flags may include VIR_DOMAIN_AFFECT_LIVE to affect a running
7004 * domain (which may fail if domain is not active), or
7005 * VIR_DOMAIN_AFFECT_CONFIG to affect the next boot via the XML
7006 * description of the domain. Both flags may be set.
7007 * If neither flag is specified (that is, @flags is VIR_DOMAIN_AFFECT_CURRENT),
7008 * then an inactive domain modifies persistent setup, while an active domain
7009 * is hypervisor-dependent on whether just live or both live and persistent
7010 * state is changed.
7012 * Note that if this call is executed before the guest has finished booting,
7013 * the guest may fail to process the change.
7015 * If @flags includes VIR_DOMAIN_VCPU_MAXIMUM, then
7016 * VIR_DOMAIN_AFFECT_LIVE must be clear, and only the maximum virtual
7017 * CPU limit is altered; generally, this value must be less than or
7018 * equal to virConnectGetMaxVcpus(). Otherwise, this call affects the
7019 * current virtual CPU limit, which must be less than or equal to the
7020 * maximum limit. Note that hypervisors may not allow changing the maximum
7021 * vcpu count if processor topology is specified.
7023 * If @flags includes VIR_DOMAIN_VCPU_GUEST, then the state of processors is
7024 * modified inside the guest instead of the hypervisor. This flag can only
7025 * be used with live guests and is incompatible with VIR_DOMAIN_VCPU_MAXIMUM.
7026 * The usage of this flag may require a guest agent configured.
7028 * Not all hypervisors can support all flag combinations.
7030 * Returns 0 in case of success, -1 in case of failure.
7033 virDomainSetVcpusFlags(virDomainPtr domain, unsigned int nvcpus,
7034 unsigned int flags)
7036 virConnectPtr conn;
7038 VIR_DOMAIN_DEBUG(domain, "nvcpus=%u, flags=0x%x", nvcpus, flags);
7040 virResetLastError();
7042 virCheckDomainReturn(domain, -1);
7043 virCheckReadOnlyGoto(domain->conn->flags, error);
7045 VIR_REQUIRE_FLAG_GOTO(VIR_DOMAIN_VCPU_MAXIMUM,
7046 VIR_DOMAIN_AFFECT_CONFIG,
7047 error);
7049 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_VCPU_GUEST,
7050 VIR_DOMAIN_AFFECT_CONFIG,
7051 error);
7053 virCheckNonZeroArgGoto(nvcpus, error);
7055 conn = domain->conn;
7057 if (conn->driver->domainSetVcpusFlags) {
7058 int ret;
7059 ret = conn->driver->domainSetVcpusFlags(domain, nvcpus, flags);
7060 if (ret < 0)
7061 goto error;
7062 return ret;
7065 virReportUnsupportedError();
7067 error:
7068 virDispatchError(domain->conn);
7069 return -1;
7074 * virDomainGetVcpusFlags:
7075 * @domain: pointer to domain object, or NULL for Domain0
7076 * @flags: bitwise-OR of virDomainVcpuFlags
7078 * Query the number of virtual CPUs used by the domain. Note that
7079 * this call may fail if the underlying virtualization hypervisor does
7080 * not support it. This function may require privileged access to the
7081 * hypervisor.
7083 * If @flags includes VIR_DOMAIN_AFFECT_LIVE, this will query a
7084 * running domain (which will fail if domain is not active); if
7085 * it includes VIR_DOMAIN_AFFECT_CONFIG, this will query the XML
7086 * description of the domain. It is an error to set both flags.
7087 * If neither flag is set (that is, VIR_DOMAIN_AFFECT_CURRENT),
7088 * then the configuration queried depends on whether the domain
7089 * is currently running.
7091 * If @flags includes VIR_DOMAIN_VCPU_MAXIMUM, then the maximum
7092 * virtual CPU limit is queried. Otherwise, this call queries the
7093 * current virtual CPU count.
7095 * If @flags includes VIR_DOMAIN_VCPU_GUEST, then the state of the processors
7096 * is queried in the guest instead of the hypervisor. This flag is only usable
7097 * on live domains. Guest agent may be needed for this flag to be available.
7099 * Returns the number of vCPUs in case of success, -1 in case of failure.
7102 virDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
7104 virConnectPtr conn;
7106 VIR_DOMAIN_DEBUG(domain, "flags=0x%x", flags);
7108 virResetLastError();
7110 virCheckDomainReturn(domain, -1);
7111 conn = domain->conn;
7113 if (flags & VIR_DOMAIN_VCPU_GUEST)
7114 virCheckReadOnlyGoto(conn->flags, error);
7116 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_AFFECT_LIVE,
7117 VIR_DOMAIN_AFFECT_CONFIG,
7118 error);
7120 if (conn->driver->domainGetVcpusFlags) {
7121 int ret;
7122 ret = conn->driver->domainGetVcpusFlags(domain, flags);
7123 if (ret < 0)
7124 goto error;
7125 return ret;
7128 virReportUnsupportedError();
7130 error:
7131 virDispatchError(domain->conn);
7132 return -1;
7137 * virDomainPinVcpu:
7138 * @domain: pointer to domain object, or NULL for Domain0
7139 * @vcpu: virtual CPU number
7140 * @cpumap: pointer to a bit map of real CPUs (in 8-bit bytes) (IN)
7141 * Each bit set to 1 means that corresponding CPU is usable.
7142 * Bytes are stored in little-endian order: CPU0-7, 8-15...
7143 * In each byte, lowest CPU number is least significant bit.
7144 * @maplen: number of bytes in cpumap, from 1 up to size of CPU map in
7145 * underlying virtualization system (Xen...).
7146 * If maplen < size, missing bytes are set to zero.
7147 * If maplen > size, failure code is returned.
7149 * Dynamically change the real CPUs which can be allocated to a virtual CPU.
7150 * This function may require privileged access to the hypervisor.
7152 * This command only changes the runtime configuration of the domain,
7153 * so can only be called on an active domain.
7155 * Returns 0 in case of success, -1 in case of failure.
7158 virDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
7159 unsigned char *cpumap, int maplen)
7161 virConnectPtr conn;
7163 VIR_DOMAIN_DEBUG(domain, "vcpu=%u, cpumap=%p, maplen=%d",
7164 vcpu, cpumap, maplen);
7166 virResetLastError();
7168 virCheckDomainReturn(domain, -1);
7169 conn = domain->conn;
7171 virCheckReadOnlyGoto(conn->flags, error);
7172 virCheckNonNullArgGoto(cpumap, error);
7173 virCheckPositiveArgGoto(maplen, error);
7175 if (conn->driver->domainPinVcpu) {
7176 int ret;
7177 ret = conn->driver->domainPinVcpu(domain, vcpu, cpumap, maplen);
7178 if (ret < 0)
7179 goto error;
7180 return ret;
7183 virReportUnsupportedError();
7185 error:
7186 virDispatchError(domain->conn);
7187 return -1;
7192 * virDomainPinVcpuFlags:
7193 * @domain: pointer to domain object, or NULL for Domain0
7194 * @vcpu: virtual CPU number
7195 * @cpumap: pointer to a bit map of real CPUs (in 8-bit bytes) (IN)
7196 * Each bit set to 1 means that corresponding CPU is usable.
7197 * Bytes are stored in little-endian order: CPU0-7, 8-15...
7198 * In each byte, lowest CPU number is least significant bit.
7199 * @maplen: number of bytes in cpumap, from 1 up to size of CPU map in
7200 * underlying virtualization system (Xen...).
7201 * If maplen < size, missing bytes are set to zero.
7202 * If maplen > size, failure code is returned.
7203 * @flags: bitwise-OR of virDomainModificationImpact
7205 * Dynamically change the real CPUs which can be allocated to a virtual CPU.
7206 * This function may require privileged access to the hypervisor.
7208 * @flags may include VIR_DOMAIN_AFFECT_LIVE or VIR_DOMAIN_AFFECT_CONFIG.
7209 * Both flags may be set.
7210 * If VIR_DOMAIN_AFFECT_LIVE is set, the change affects a running domain
7211 * and may fail if domain is not alive.
7212 * If VIR_DOMAIN_AFFECT_CONFIG is set, the change affects persistent state,
7213 * and will fail for transient domains. If neither flag is specified (that is,
7214 * @flags is VIR_DOMAIN_AFFECT_CURRENT), then an inactive domain modifies
7215 * persistent setup, while an active domain is hypervisor-dependent on whether
7216 * just live or both live and persistent state is changed.
7217 * Not all hypervisors can support all flag combinations.
7219 * See also virDomainGetVcpuPinInfo for querying this information.
7221 * Returns 0 in case of success, -1 in case of failure.
7225 virDomainPinVcpuFlags(virDomainPtr domain, unsigned int vcpu,
7226 unsigned char *cpumap, int maplen, unsigned int flags)
7228 virConnectPtr conn;
7230 VIR_DOMAIN_DEBUG(domain, "vcpu=%u, cpumap=%p, maplen=%d, flags=0x%x",
7231 vcpu, cpumap, maplen, flags);
7233 virResetLastError();
7235 virCheckDomainReturn(domain, -1);
7236 conn = domain->conn;
7238 virCheckReadOnlyGoto(conn->flags, error);
7239 virCheckNonNullArgGoto(cpumap, error);
7240 virCheckPositiveArgGoto(maplen, error);
7242 if (conn->driver->domainPinVcpuFlags) {
7243 int ret;
7244 ret = conn->driver->domainPinVcpuFlags(domain, vcpu, cpumap, maplen, flags);
7245 if (ret < 0)
7246 goto error;
7247 return ret;
7250 virReportUnsupportedError();
7252 error:
7253 virDispatchError(domain->conn);
7254 return -1;
7259 * virDomainGetVcpuPinInfo:
7260 * @domain: pointer to domain object, or NULL for Domain0
7261 * @ncpumaps: the number of cpumap (listed first to match virDomainGetVcpus)
7262 * @cpumaps: pointer to a bit map of real CPUs for all vcpus of this
7263 * domain (in 8-bit bytes) (OUT)
7264 * It's assumed there is <ncpumaps> cpumap in cpumaps array.
7265 * The memory allocated to cpumaps must be (ncpumaps * maplen) bytes
7266 * (ie: calloc(ncpumaps, maplen)).
7267 * One cpumap inside cpumaps has the format described in
7268 * virDomainPinVcpu() API.
7269 * Must not be NULL.
7270 * @maplen: the number of bytes in one cpumap, from 1 up to size of CPU map.
7271 * Must be positive.
7272 * @flags: bitwise-OR of virDomainModificationImpact
7273 * Must not be VIR_DOMAIN_AFFECT_LIVE and
7274 * VIR_DOMAIN_AFFECT_CONFIG concurrently.
7276 * Query the CPU affinity setting of all virtual CPUs of domain, store it
7277 * in cpumaps.
7279 * Returns the number of virtual CPUs in case of success,
7280 * -1 in case of failure.
7283 virDomainGetVcpuPinInfo(virDomainPtr domain, int ncpumaps,
7284 unsigned char *cpumaps, int maplen, unsigned int flags)
7286 virConnectPtr conn;
7288 VIR_DOMAIN_DEBUG(domain, "ncpumaps=%d, cpumaps=%p, maplen=%d, flags=0x%x",
7289 ncpumaps, cpumaps, maplen, flags);
7291 virResetLastError();
7293 virCheckDomainReturn(domain, -1);
7294 conn = domain->conn;
7296 virCheckNonNullArgGoto(cpumaps, error);
7297 virCheckPositiveArgGoto(ncpumaps, error);
7298 virCheckPositiveArgGoto(maplen, error);
7300 if (INT_MULTIPLY_OVERFLOW(ncpumaps, maplen)) {
7301 virReportError(VIR_ERR_OVERFLOW, _("input too large: %d * %d"),
7302 ncpumaps, maplen);
7303 goto error;
7306 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_AFFECT_LIVE,
7307 VIR_DOMAIN_AFFECT_CONFIG,
7308 error);
7310 if (conn->driver->domainGetVcpuPinInfo) {
7311 int ret;
7312 ret = conn->driver->domainGetVcpuPinInfo(domain, ncpumaps,
7313 cpumaps, maplen, flags);
7314 if (ret < 0)
7315 goto error;
7316 return ret;
7319 virReportUnsupportedError();
7321 error:
7322 virDispatchError(domain->conn);
7323 return -1;
7328 * virDomainPinEmulator:
7329 * @domain: pointer to domain object, or NULL for Domain0
7330 * @cpumap: pointer to a bit map of real CPUs (in 8-bit bytes) (IN)
7331 * Each bit set to 1 means that corresponding CPU is usable.
7332 * Bytes are stored in little-endian order: CPU0-7, 8-15...
7333 * In each byte, lowest CPU number is least significant bit.
7334 * @maplen: number of bytes in cpumap, from 1 up to size of CPU map in
7335 * underlying virtualization system (Xen...).
7336 * If maplen < size, missing bytes are set to zero.
7337 * If maplen > size, failure code is returned.
7338 * @flags: bitwise-OR of virDomainModificationImpact
7340 * Dynamically change the real CPUs which can be allocated to all emulator
7341 * threads. This function may require privileged access to the hypervisor.
7343 * @flags may include VIR_DOMAIN_AFFECT_LIVE or VIR_DOMAIN_AFFECT_CONFIG.
7344 * Both flags may be set.
7345 * If VIR_DOMAIN_AFFECT_LIVE is set, the change affects a running domain
7346 * and may fail if domain is not alive.
7347 * If VIR_DOMAIN_AFFECT_CONFIG is set, the change affects persistent state,
7348 * and will fail for transient domains. If neither flag is specified (that is,
7349 * @flags is VIR_DOMAIN_AFFECT_CURRENT), then an inactive domain modifies
7350 * persistent setup, while an active domain is hypervisor-dependent on whether
7351 * just live or both live and persistent state is changed.
7352 * Not all hypervisors can support all flag combinations.
7354 * See also virDomainGetEmulatorPinInfo for querying this information.
7356 * Returns 0 in case of success, -1 in case of failure.
7360 virDomainPinEmulator(virDomainPtr domain, unsigned char *cpumap,
7361 int maplen, unsigned int flags)
7363 virConnectPtr conn;
7365 VIR_DOMAIN_DEBUG(domain, "cpumap=%p, maplen=%d, flags=0x%x",
7366 cpumap, maplen, flags);
7368 virResetLastError();
7370 virCheckDomainReturn(domain, -1);
7371 conn = domain->conn;
7373 virCheckReadOnlyGoto(conn->flags, error);
7375 virCheckNonNullArgGoto(cpumap, error);
7376 virCheckPositiveArgGoto(maplen, error);
7378 if (conn->driver->domainPinEmulator) {
7379 int ret;
7380 ret = conn->driver->domainPinEmulator(domain, cpumap, maplen, flags);
7381 if (ret < 0)
7382 goto error;
7383 return ret;
7386 virReportUnsupportedError();
7388 error:
7389 virDispatchError(domain->conn);
7390 return -1;
7395 * virDomainGetEmulatorPinInfo:
7396 * @domain: pointer to domain object, or NULL for Domain0
7397 * @cpumap: pointer to a bit map of real CPUs for all emulator threads of
7398 * this domain (in 8-bit bytes) (OUT)
7399 * There is only one cpumap for all emulator threads.
7400 * Must not be NULL.
7401 * @maplen: the number of bytes in one cpumap, from 1 up to size of CPU map.
7402 * Must be positive.
7403 * @flags: bitwise-OR of virDomainModificationImpact
7404 * Must not be VIR_DOMAIN_AFFECT_LIVE and
7405 * VIR_DOMAIN_AFFECT_CONFIG concurrently.
7407 * Query the CPU affinity setting of all emulator threads of domain, store
7408 * it in cpumap.
7410 * Returns 1 in case of success,
7411 * 0 in case of no emulator threads are pined to pcpus,
7412 * -1 in case of failure.
7415 virDomainGetEmulatorPinInfo(virDomainPtr domain, unsigned char *cpumap,
7416 int maplen, unsigned int flags)
7418 virConnectPtr conn;
7420 VIR_DOMAIN_DEBUG(domain, "cpumap=%p, maplen=%d, flags=0x%x",
7421 cpumap, maplen, flags);
7423 virResetLastError();
7425 virCheckDomainReturn(domain, -1);
7427 virCheckNonNullArgGoto(cpumap, error);
7428 virCheckPositiveArgGoto(maplen, error);
7430 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_AFFECT_LIVE,
7431 VIR_DOMAIN_AFFECT_CONFIG,
7432 error);
7434 conn = domain->conn;
7436 if (conn->driver->domainGetEmulatorPinInfo) {
7437 int ret;
7438 ret = conn->driver->domainGetEmulatorPinInfo(domain, cpumap,
7439 maplen, flags);
7440 if (ret < 0)
7441 goto error;
7442 return ret;
7445 virReportUnsupportedError();
7447 error:
7448 virDispatchError(domain->conn);
7449 return -1;
7454 * virDomainGetVcpus:
7455 * @domain: pointer to domain object, or NULL for Domain0
7456 * @info: pointer to an array of virVcpuInfo structures (OUT)
7457 * @maxinfo: number of structures in info array
7458 * @cpumaps: pointer to a bit map of real CPUs for all vcpus of this
7459 * domain (in 8-bit bytes) (OUT)
7460 * If cpumaps is NULL, then no cpumap information is returned by the API.
7461 * It's assumed there is <maxinfo> cpumap in cpumaps array.
7462 * The memory allocated to cpumaps must be (maxinfo * maplen) bytes
7463 * (ie: calloc(maxinfo, maplen)).
7464 * One cpumap inside cpumaps has the format described in
7465 * virDomainPinVcpu() API.
7466 * @maplen: number of bytes in one cpumap, from 1 up to size of CPU map in
7467 * underlying virtualization system (Xen...).
7468 * Must be zero when cpumaps is NULL and positive when it is non-NULL.
7470 * Extract information about virtual CPUs of domain, store it in info array
7471 * and also in cpumaps if this pointer isn't NULL. This call may fail
7472 * on an inactive domain.
7474 * See also virDomainGetVcpuPinInfo for querying just cpumaps, including on
7475 * an inactive domain.
7477 * Returns the number of info filled in case of success, -1 in case of failure.
7480 virDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo,
7481 unsigned char *cpumaps, int maplen)
7483 virConnectPtr conn;
7485 VIR_DOMAIN_DEBUG(domain, "info=%p, maxinfo=%d, cpumaps=%p, maplen=%d",
7486 info, maxinfo, cpumaps, maplen);
7488 virResetLastError();
7490 virCheckDomainReturn(domain, -1);
7491 virCheckNonNullArgGoto(info, error);
7492 virCheckPositiveArgGoto(maxinfo, error);
7494 /* Ensure that domainGetVcpus (aka remoteDomainGetVcpus) does not
7495 try to memcpy anything into a NULL pointer. */
7496 if (cpumaps)
7497 virCheckPositiveArgGoto(maplen, error);
7498 else
7499 virCheckZeroArgGoto(maplen, error);
7501 if (cpumaps && INT_MULTIPLY_OVERFLOW(maxinfo, maplen)) {
7502 virReportError(VIR_ERR_OVERFLOW, _("input too large: %d * %d"),
7503 maxinfo, maplen);
7504 goto error;
7507 conn = domain->conn;
7509 if (conn->driver->domainGetVcpus) {
7510 int ret;
7511 ret = conn->driver->domainGetVcpus(domain, info, maxinfo,
7512 cpumaps, maplen);
7513 if (ret < 0)
7514 goto error;
7515 return ret;
7518 virReportUnsupportedError();
7520 error:
7521 virDispatchError(domain->conn);
7522 return -1;
7527 * virDomainGetMaxVcpus:
7528 * @domain: pointer to domain object
7530 * Provides the maximum number of virtual CPUs supported for
7531 * the guest VM. If the guest is inactive, this is basically
7532 * the same as virConnectGetMaxVcpus(). If the guest is running
7533 * this will reflect the maximum number of virtual CPUs the
7534 * guest was booted with. For more details, see virDomainGetVcpusFlags().
7536 * Returns the maximum of virtual CPU or -1 in case of error.
7539 virDomainGetMaxVcpus(virDomainPtr domain)
7541 virConnectPtr conn;
7543 VIR_DOMAIN_DEBUG(domain);
7545 virResetLastError();
7547 virCheckDomainReturn(domain, -1);
7548 conn = domain->conn;
7550 if (conn->driver->domainGetMaxVcpus) {
7551 int ret;
7552 ret = conn->driver->domainGetMaxVcpus(domain);
7553 if (ret < 0)
7554 goto error;
7555 return ret;
7558 virReportUnsupportedError();
7560 error:
7561 virDispatchError(domain->conn);
7562 return -1;
7567 * virDomainGetIOThreadInfo:
7568 * @dom: a domain object
7569 * @info: pointer to an array of virDomainIOThreadInfo structures (OUT)
7570 * @flags: bitwise-OR of virDomainModificationImpact
7571 * Must not be VIR_DOMAIN_AFFECT_LIVE and
7572 * VIR_DOMAIN_AFFECT_CONFIG concurrently.
7574 * Fetch IOThreads of an active domain including the cpumap information to
7575 * determine on which CPU the IOThread has affinity to run.
7577 * Returns the number of IOThreads or -1 in case of error.
7578 * On success, the array of information is stored into @info. The caller is
7579 * responsible for calling virDomainIOThreadInfoFree() on each array element,
7580 * then calling free() on @info. On error, @info is set to NULL.
7583 virDomainGetIOThreadInfo(virDomainPtr dom,
7584 virDomainIOThreadInfoPtr **info,
7585 unsigned int flags)
7587 VIR_DOMAIN_DEBUG(dom, "info=%p flags=0x%x", info, flags);
7589 virResetLastError();
7591 virCheckDomainReturn(dom, -1);
7592 virCheckNonNullArgGoto(info, error);
7593 *info = NULL;
7595 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_AFFECT_LIVE,
7596 VIR_DOMAIN_AFFECT_CONFIG,
7597 error);
7599 if (dom->conn->driver->domainGetIOThreadInfo) {
7600 int ret;
7601 ret = dom->conn->driver->domainGetIOThreadInfo(dom, info, flags);
7602 if (ret < 0)
7603 goto error;
7604 return ret;
7607 virReportUnsupportedError();
7609 error:
7610 virDispatchError(dom->conn);
7611 return -1;
7616 * virDomainIOThreadInfoFree:
7617 * @info: pointer to a virDomainIOThreadInfo object
7619 * Frees the memory used by @info.
7621 void
7622 virDomainIOThreadInfoFree(virDomainIOThreadInfoPtr info)
7624 if (!info)
7625 return;
7627 VIR_FREE(info->cpumap);
7628 VIR_FREE(info);
7633 * virDomainPinIOThread:
7634 * @domain: a domain object
7635 * @iothread_id: the IOThread ID to set the CPU affinity
7636 * @cpumap: pointer to a bit map of real CPUs (in 8-bit bytes) (IN)
7637 * Each bit set to 1 means that corresponding CPU is usable.
7638 * Bytes are stored in little-endian order: CPU0-7, 8-15...
7639 * In each byte, lowest CPU number is least significant bit.
7640 * @maplen: number of bytes in cpumap, from 1 up to size of CPU map in
7641 * underlying virtualization system (Xen...).
7642 * If maplen < size, missing bytes are set to zero.
7643 * If maplen > size, failure code is returned.
7644 * @flags: bitwise-OR of virDomainModificationImpact
7646 * Dynamically change the real CPUs which can be allocated to an IOThread.
7647 * This function may require privileged access to the hypervisor.
7649 * @flags may include VIR_DOMAIN_AFFECT_LIVE or VIR_DOMAIN_AFFECT_CONFIG.
7650 * Both flags may be set.
7651 * If VIR_DOMAIN_AFFECT_LIVE is set, the change affects a running domain
7652 * and may fail if domain is not alive.
7653 * If VIR_DOMAIN_AFFECT_CONFIG is set, the change affects persistent state,
7654 * and will fail for transient domains. If neither flag is specified (that is,
7655 * @flags is VIR_DOMAIN_AFFECT_CURRENT), then an inactive domain modifies
7656 * persistent setup, while an active domain is hypervisor-dependent on whether
7657 * just live or both live and persistent state is changed.
7658 * Not all hypervisors can support all flag combinations.
7660 * See also virDomainGetIOThreadInfo for querying this information.
7662 * Returns 0 in case of success, -1 in case of failure.
7665 virDomainPinIOThread(virDomainPtr domain,
7666 unsigned int iothread_id,
7667 unsigned char *cpumap,
7668 int maplen,
7669 unsigned int flags)
7671 virConnectPtr conn;
7673 VIR_DOMAIN_DEBUG(domain, "iothread_id=%u, cpumap=%p, maplen=%d",
7674 iothread_id, cpumap, maplen);
7676 virResetLastError();
7678 virCheckDomainReturn(domain, -1);
7679 conn = domain->conn;
7681 virCheckReadOnlyGoto(conn->flags, error);
7682 virCheckNonNullArgGoto(cpumap, error);
7683 virCheckPositiveArgGoto(maplen, error);
7685 if (conn->driver->domainPinIOThread) {
7686 int ret;
7687 ret = conn->driver->domainPinIOThread(domain, iothread_id,
7688 cpumap, maplen, flags);
7689 if (ret < 0)
7690 goto error;
7691 return ret;
7694 virReportUnsupportedError();
7696 error:
7697 virDispatchError(domain->conn);
7698 return -1;
7703 * virDomainAddIOThread:
7704 * @domain: a domain object
7705 * @iothread_id: the specific IOThread ID value to add
7706 * @flags: bitwise-OR of virDomainModificationImpact
7708 * Dynamically add an IOThread to the domain. It is left up to the
7709 * underlying virtual hypervisor to determine the valid range for an
7710 * @iothread_id and determining whether the @iothread_id already exists.
7712 * Note that this call can fail if the underlying virtualization hypervisor
7713 * does not support it or if growing the number is arbitrarily limited.
7714 * This function requires privileged access to the hypervisor.
7716 * @flags may include VIR_DOMAIN_AFFECT_LIVE or VIR_DOMAIN_AFFECT_CONFIG.
7717 * Both flags may be set.
7718 * If VIR_DOMAIN_AFFECT_LIVE is set, the change affects a running domain
7719 * and may fail if domain is not alive.
7720 * If VIR_DOMAIN_AFFECT_CONFIG is set, the change affects persistent state,
7721 * and will fail for transient domains. If neither flag is specified (that is,
7722 * @flags is VIR_DOMAIN_AFFECT_CURRENT), then an inactive domain modifies
7723 * persistent setup, while an active domain is hypervisor-dependent on whether
7724 * just live or both live and persistent state is changed.
7726 * Returns 0 in case of success, -1 in case of failure.
7729 virDomainAddIOThread(virDomainPtr domain,
7730 unsigned int iothread_id,
7731 unsigned int flags)
7733 virConnectPtr conn;
7735 VIR_DOMAIN_DEBUG(domain, "iothread_id=%u, flags=0x%x",
7736 iothread_id, flags);
7738 virResetLastError();
7740 virCheckDomainReturn(domain, -1);
7741 virCheckReadOnlyGoto(domain->conn->flags, error);
7743 conn = domain->conn;
7745 if (conn->driver->domainAddIOThread) {
7746 int ret;
7747 ret = conn->driver->domainAddIOThread(domain, iothread_id, flags);
7748 if (ret < 0)
7749 goto error;
7750 return ret;
7753 virReportUnsupportedError();
7755 error:
7756 virDispatchError(domain->conn);
7757 return -1;
7762 * virDomainDelIOThread:
7763 * @domain: a domain object
7764 * @iothread_id: the specific IOThread ID value to delete
7765 * @flags: bitwise-OR of virDomainModificationImpact
7767 * Dynamically delete an IOThread from the domain. The @iothread_id to be
7768 * deleted must not have a resource associated with it and can be any of
7769 * the currently valid IOThread ID's.
7771 * Note that this call can fail if the underlying virtualization hypervisor
7772 * does not support it or if reducing the number is arbitrarily limited.
7773 * This function requires privileged access to the hypervisor.
7775 * @flags may include VIR_DOMAIN_AFFECT_LIVE or VIR_DOMAIN_AFFECT_CONFIG.
7776 * Both flags may be set.
7777 * If VIR_DOMAIN_AFFECT_LIVE is set, the change affects a running domain
7778 * and may fail if domain is not alive.
7779 * If VIR_DOMAIN_AFFECT_CONFIG is set, the change affects persistent state,
7780 * and will fail for transient domains. If neither flag is specified (that is,
7781 * @flags is VIR_DOMAIN_AFFECT_CURRENT), then an inactive domain modifies
7782 * persistent setup, while an active domain is hypervisor-dependent on whether
7783 * just live or both live and persistent state is changed.
7785 * Returns 0 in case of success, -1 in case of failure.
7788 virDomainDelIOThread(virDomainPtr domain,
7789 unsigned int iothread_id,
7790 unsigned int flags)
7792 virConnectPtr conn;
7794 VIR_DOMAIN_DEBUG(domain, "iothread_id=%u, flags=0x%x", iothread_id, flags);
7796 virResetLastError();
7798 virCheckDomainReturn(domain, -1);
7799 virCheckReadOnlyGoto(domain->conn->flags, error);
7800 virCheckNonZeroArgGoto(iothread_id, error);
7802 conn = domain->conn;
7804 if (conn->driver->domainDelIOThread) {
7805 int ret;
7806 ret = conn->driver->domainDelIOThread(domain, iothread_id, flags);
7807 if (ret < 0)
7808 goto error;
7809 return ret;
7812 virReportUnsupportedError();
7814 error:
7815 virDispatchError(domain->conn);
7816 return -1;
7821 * virDomainSetIOThreadParams:
7822 * @domain: a domain object
7823 * @iothread_id: the specific IOThread ID value to add
7824 * @params: pointer to IOThread parameter objects
7825 * @nparams: number of IOThread parameters
7826 * @flags: bitwise-OR of virDomainModificationImpact and virTypedParameterFlags
7828 * Dynamically set IOThread parameters to the domain. It is left up to
7829 * the underlying virtual hypervisor to determine the valid range for an
7830 * @iothread_id, determining whether the @iothread_id already exists, and
7831 * determining the validity of the provided param values.
7833 * See VIR_DOMAIN_IOTHREAD_* for detailed description of accepted IOThread
7834 * parameters.
7836 * Since the purpose of this API is to dynamically modify the IOThread
7837 * @flags should only include the VIR_DOMAIN_AFFECT_CURRENT and/or
7838 * VIR_DOMAIN_AFFECT_LIVE virDomainMemoryModFlags. Setting other flags
7839 * may cause errors from the hypervisor.
7841 * Note that this call can fail if the underlying virtualization hypervisor
7842 * does not support it or does not support setting the provided values.
7844 * This function requires privileged access to the hypervisor.
7846 * Returns 0 in case of success, -1 in case of failure.
7849 virDomainSetIOThreadParams(virDomainPtr domain,
7850 unsigned int iothread_id,
7851 virTypedParameterPtr params,
7852 int nparams,
7853 unsigned int flags)
7855 virConnectPtr conn;
7857 VIR_DOMAIN_DEBUG(domain, "iothread_id=%u, params=%p, nparams=%d, flags=0x%x",
7858 iothread_id, params, nparams, flags);
7859 VIR_TYPED_PARAMS_DEBUG(params, nparams);
7861 virResetLastError();
7863 virCheckDomainReturn(domain, -1);
7864 conn = domain->conn;
7866 virCheckReadOnlyGoto(conn->flags, error);
7867 virCheckNonNullArgGoto(params, error);
7868 virCheckPositiveArgGoto(nparams, error);
7870 if (virTypedParameterValidateSet(conn, params, nparams) < 0)
7871 goto error;
7873 if (conn->driver->domainSetIOThreadParams) {
7874 int ret;
7875 ret = conn->driver->domainSetIOThreadParams(domain, iothread_id,
7876 params, nparams, flags);
7877 if (ret < 0)
7878 goto error;
7879 return ret;
7882 virReportUnsupportedError();
7884 error:
7885 virDispatchError(domain->conn);
7886 return -1;
7891 * virDomainGetSecurityLabel:
7892 * @domain: a domain object
7893 * @seclabel: pointer to a virSecurityLabel structure
7895 * Extract security label of an active domain. The 'label' field
7896 * in the @seclabel argument will be initialized to the empty
7897 * string if the domain is not running under a security model.
7899 * Returns 0 in case of success, -1 in case of failure
7902 virDomainGetSecurityLabel(virDomainPtr domain, virSecurityLabelPtr seclabel)
7904 virConnectPtr conn;
7906 VIR_DOMAIN_DEBUG(domain, "seclabel=%p", seclabel);
7908 virResetLastError();
7910 virCheckDomainReturn(domain, -1);
7911 conn = domain->conn;
7913 virCheckNonNullArgGoto(seclabel, error);
7915 if (conn->driver->domainGetSecurityLabel) {
7916 int ret;
7917 ret = conn->driver->domainGetSecurityLabel(domain, seclabel);
7918 if (ret < 0)
7919 goto error;
7920 return ret;
7923 virReportUnsupportedError();
7925 error:
7926 virDispatchError(domain->conn);
7927 return -1;
7932 * virDomainGetSecurityLabelList:
7933 * @domain: a domain object
7934 * @seclabels: will be auto-allocated and filled with domains' security labels.
7935 * Caller must free memory on return.
7937 * Extract the security labels of an active domain. The 'label' field
7938 * in the @seclabels argument will be initialized to the empty
7939 * string if the domain is not running under a security model.
7941 * Returns number of elements in @seclabels on success, -1 in case of failure.
7944 virDomainGetSecurityLabelList(virDomainPtr domain,
7945 virSecurityLabelPtr* seclabels)
7947 virConnectPtr conn;
7949 VIR_DOMAIN_DEBUG(domain, "seclabels=%p", seclabels);
7951 virResetLastError();
7953 virCheckDomainReturn(domain, -1);
7955 virCheckNonNullArgGoto(seclabels, error);
7957 conn = domain->conn;
7959 if (conn->driver->domainGetSecurityLabelList) {
7960 int ret;
7961 ret = conn->driver->domainGetSecurityLabelList(domain, seclabels);
7962 if (ret < 0)
7963 goto error;
7964 return ret;
7967 virReportUnsupportedError();
7969 error:
7970 virDispatchError(domain->conn);
7971 return -1;
7976 * virDomainSetMetadata:
7977 * @domain: a domain object
7978 * @type: type of metadata, from virDomainMetadataType
7979 * @metadata: new metadata text
7980 * @key: XML namespace key, or NULL
7981 * @uri: XML namespace URI, or NULL
7982 * @flags: bitwise-OR of virDomainModificationImpact
7984 * Sets the appropriate domain element given by @type to the
7985 * value of @metadata. A @type of VIR_DOMAIN_METADATA_DESCRIPTION
7986 * is free-form text; VIR_DOMAIN_METADATA_TITLE is free-form, but no
7987 * newlines are permitted, and should be short (although the length is
7988 * not enforced). For these two options @key and @uri are irrelevant and
7989 * must be set to NULL.
7991 * For type VIR_DOMAIN_METADATA_ELEMENT @metadata must be well-formed
7992 * XML belonging to namespace defined by @uri with local name @key.
7994 * Passing NULL for @metadata says to remove that element from the
7995 * domain XML (passing the empty string leaves the element present).
7997 * The resulting metadata will be present in virDomainGetXMLDesc(),
7998 * as well as quick access through virDomainGetMetadata().
8000 * @flags controls whether the live domain, persistent configuration,
8001 * or both will be modified.
8003 * Returns 0 on success, -1 in case of failure.
8006 virDomainSetMetadata(virDomainPtr domain,
8007 int type,
8008 const char *metadata,
8009 const char *key,
8010 const char *uri,
8011 unsigned int flags)
8013 virConnectPtr conn;
8015 VIR_DOMAIN_DEBUG(domain,
8016 "type=%d, metadata='%s', key='%s', uri='%s', flags=0x%x",
8017 type, NULLSTR(metadata), NULLSTR(key), NULLSTR(uri),
8018 flags);
8020 virResetLastError();
8022 virCheckDomainReturn(domain, -1);
8023 conn = domain->conn;
8025 virCheckReadOnlyGoto(conn->flags, error);
8027 switch (type) {
8028 case VIR_DOMAIN_METADATA_TITLE:
8029 if (metadata && strchr(metadata, '\n')) {
8030 virReportInvalidArg(metadata, "%s",
8031 _("metadata title can't contain "
8032 "newlines"));
8033 goto error;
8035 ATTRIBUTE_FALLTHROUGH;
8036 case VIR_DOMAIN_METADATA_DESCRIPTION:
8037 virCheckNullArgGoto(uri, error);
8038 virCheckNullArgGoto(key, error);
8039 break;
8040 case VIR_DOMAIN_METADATA_ELEMENT:
8041 virCheckNonNullArgGoto(uri, error);
8042 if (metadata)
8043 virCheckNonNullArgGoto(key, error);
8044 break;
8045 default:
8046 /* For future expansion */
8047 break;
8050 if (conn->driver->domainSetMetadata) {
8051 int ret;
8052 ret = conn->driver->domainSetMetadata(domain, type, metadata, key, uri,
8053 flags);
8054 if (ret < 0)
8055 goto error;
8056 return ret;
8059 virReportUnsupportedError();
8061 error:
8062 virDispatchError(domain->conn);
8063 return -1;
8068 * virDomainGetMetadata:
8069 * @domain: a domain object
8070 * @type: type of metadata, from virDomainMetadataType
8071 * @uri: XML namespace identifier
8072 * @flags: bitwise-OR of virDomainModificationImpact
8074 * Retrieves the appropriate domain element given by @type.
8075 * If VIR_DOMAIN_METADATA_ELEMENT is requested parameter @uri
8076 * must be set to the name of the namespace the requested elements
8077 * belong to, otherwise must be NULL.
8079 * If an element of the domain XML is not present, the resulting
8080 * error will be VIR_ERR_NO_DOMAIN_METADATA. This method forms
8081 * a shortcut for seeing information from virDomainSetMetadata()
8082 * without having to go through virDomainGetXMLDesc().
8084 * @flags controls whether the live domain or persistent
8085 * configuration will be queried.
8087 * Returns the metadata string on success (caller must free),
8088 * or NULL in case of failure.
8090 char *
8091 virDomainGetMetadata(virDomainPtr domain,
8092 int type,
8093 const char *uri,
8094 unsigned int flags)
8096 virConnectPtr conn;
8098 VIR_DOMAIN_DEBUG(domain, "type=%d, uri='%s', flags=0x%x",
8099 type, NULLSTR(uri), flags);
8101 virResetLastError();
8103 virCheckDomainReturn(domain, NULL);
8105 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_AFFECT_LIVE,
8106 VIR_DOMAIN_AFFECT_CONFIG,
8107 error);
8109 switch (type) {
8110 case VIR_DOMAIN_METADATA_TITLE:
8111 case VIR_DOMAIN_METADATA_DESCRIPTION:
8112 virCheckNullArgGoto(uri, error);
8113 break;
8114 case VIR_DOMAIN_METADATA_ELEMENT:
8115 virCheckNonNullArgGoto(uri, error);
8116 break;
8117 default:
8118 /* For future expansion */
8119 break;
8122 conn = domain->conn;
8124 if (conn->driver->domainGetMetadata) {
8125 char *ret;
8126 if (!(ret = conn->driver->domainGetMetadata(domain, type, uri, flags)))
8127 goto error;
8128 return ret;
8131 virReportUnsupportedError();
8133 error:
8134 virDispatchError(domain->conn);
8135 return NULL;
8140 * virDomainAttachDevice:
8141 * @domain: pointer to domain object
8142 * @xml: pointer to XML description of one device
8144 * Create a virtual device attachment to backend. This function,
8145 * having hotplug semantics, is only allowed on an active domain.
8147 * For compatibility, this method can also be used to change the media
8148 * in an existing CDROM/Floppy device, however, applications are
8149 * recommended to use the virDomainUpdateDeviceFlag method instead.
8151 * Be aware that hotplug changes might not persist across a domain going
8152 * into S4 state (also known as hibernation) unless you also modify the
8153 * persistent domain definition.
8155 * Returns 0 in case of success, -1 in case of failure.
8158 virDomainAttachDevice(virDomainPtr domain, const char *xml)
8160 virConnectPtr conn;
8162 VIR_DOMAIN_DEBUG(domain, "xml=%s", xml);
8164 virResetLastError();
8166 virCheckDomainReturn(domain, -1);
8167 conn = domain->conn;
8169 virCheckNonNullArgGoto(xml, error);
8170 virCheckReadOnlyGoto(conn->flags, error);
8172 if (conn->driver->domainAttachDevice) {
8173 int ret;
8174 ret = conn->driver->domainAttachDevice(domain, xml);
8175 if (ret < 0)
8176 goto error;
8177 return ret;
8180 virReportUnsupportedError();
8182 error:
8183 virDispatchError(domain->conn);
8184 return -1;
8189 * virDomainAttachDeviceFlags:
8190 * @domain: pointer to domain object
8191 * @xml: pointer to XML description of one device
8192 * @flags: bitwise-OR of virDomainDeviceModifyFlags
8194 * Attach a virtual device to a domain, using the flags parameter
8195 * to control how the device is attached. VIR_DOMAIN_AFFECT_CURRENT
8196 * specifies that the device allocation is made based on current domain
8197 * state. VIR_DOMAIN_AFFECT_LIVE specifies that the device shall be
8198 * allocated to the active domain instance only and is not added to the
8199 * persisted domain configuration. VIR_DOMAIN_AFFECT_CONFIG
8200 * specifies that the device shall be allocated to the persisted domain
8201 * configuration only. Note that the target hypervisor must return an
8202 * error if unable to satisfy flags. E.g. the hypervisor driver will
8203 * return failure if LIVE is specified but it only supports modifying the
8204 * persisted device allocation.
8206 * For compatibility, this method can also be used to change the media
8207 * in an existing CDROM/Floppy device, however, applications are
8208 * recommended to use the virDomainUpdateDeviceFlag method instead.
8210 * Be aware that hotplug changes might not persist across a domain going
8211 * into S4 state (also known as hibernation) unless you also modify the
8212 * persistent domain definition.
8214 * Returns 0 in case of success, -1 in case of failure.
8217 virDomainAttachDeviceFlags(virDomainPtr domain,
8218 const char *xml, unsigned int flags)
8220 virConnectPtr conn;
8222 VIR_DOMAIN_DEBUG(domain, "xml=%s, flags=0x%x", xml, flags);
8224 virResetLastError();
8226 virCheckDomainReturn(domain, -1);
8227 conn = domain->conn;
8229 virCheckNonNullArgGoto(xml, error);
8230 virCheckReadOnlyGoto(conn->flags, error);
8232 if (conn->driver->domainAttachDeviceFlags) {
8233 int ret;
8234 ret = conn->driver->domainAttachDeviceFlags(domain, xml, flags);
8235 if (ret < 0)
8236 goto error;
8237 return ret;
8240 virReportUnsupportedError();
8242 error:
8243 virDispatchError(domain->conn);
8244 return -1;
8249 * virDomainDetachDevice:
8250 * @domain: pointer to domain object
8251 * @xml: pointer to XML description of one device
8253 * This is an equivalent of virDomainDetachDeviceFlags() when called with
8254 * @flags parameter set to VIR_DOMAIN_AFFECT_LIVE.
8256 * See virDomainDetachDeviceFlags() for more details.
8258 * Returns 0 in case of success, -1 in case of failure.
8261 virDomainDetachDevice(virDomainPtr domain, const char *xml)
8263 virConnectPtr conn;
8265 VIR_DOMAIN_DEBUG(domain, "xml=%s", xml);
8267 virResetLastError();
8269 virCheckDomainReturn(domain, -1);
8270 conn = domain->conn;
8272 virCheckNonNullArgGoto(xml, error);
8273 virCheckReadOnlyGoto(conn->flags, error);
8275 if (conn->driver->domainDetachDevice) {
8276 int ret;
8277 ret = conn->driver->domainDetachDevice(domain, xml);
8278 if (ret < 0)
8279 goto error;
8280 return ret;
8283 virReportUnsupportedError();
8285 error:
8286 virDispatchError(domain->conn);
8287 return -1;
8292 * virDomainDetachDeviceFlags:
8293 * @domain: pointer to domain object
8294 * @xml: pointer to XML description of one device
8295 * @flags: bitwise-OR of virDomainDeviceModifyFlags
8297 * Detach a virtual device from a domain, using the flags parameter
8298 * to control how the device is detached. VIR_DOMAIN_AFFECT_CURRENT
8299 * specifies that the device allocation is removed based on current domain
8300 * state. VIR_DOMAIN_AFFECT_LIVE specifies that the device shall be
8301 * deallocated from the active domain instance only and is not from the
8302 * persisted domain configuration. VIR_DOMAIN_AFFECT_CONFIG
8303 * specifies that the device shall be deallocated from the persisted domain
8304 * configuration only. Note that the target hypervisor must return an
8305 * error if unable to satisfy flags. E.g. the hypervisor driver will
8306 * return failure if LIVE is specified but it only supports removing the
8307 * persisted device allocation.
8309 * Some hypervisors may prevent this operation if there is a current
8310 * block job running operation on the device being detached; in that case,
8311 * use virDomainBlockJobAbort() to stop the block job first.
8313 * Beware that depending on the hypervisor and device type, detaching a device
8314 * from a running domain may be asynchronous. That is, calling
8315 * virDomainDetachDeviceFlags may just request device removal while the device
8316 * is actually removed later (in cooperation with a guest OS). Previously,
8317 * this fact was ignored and the device could have been removed from domain
8318 * configuration before it was actually removed by the hypervisor causing
8319 * various failures on subsequent operations. To check whether the device was
8320 * successfully removed, either recheck domain configuration using
8321 * virDomainGetXMLDesc() or add a handler for the VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED
8322 * event. In case the device is already gone when virDomainDetachDeviceFlags
8323 * returns, the event is delivered before this API call ends. To help existing
8324 * clients work better in most cases, this API will try to transform an
8325 * asynchronous device removal that finishes shortly after the request into
8326 * a synchronous removal. In other words, this API may wait a bit for the
8327 * removal to complete in case it was not synchronous.
8329 * Be aware that hotplug changes might not persist across a domain going
8330 * into S4 state (also known as hibernation) unless you also modify the
8331 * persistent domain definition.
8333 * The supplied XML description of the device should be as specific
8334 * as its definition in the domain XML. The set of attributes used
8335 * to match the device are internal to the drivers. Using a partial definition,
8336 * or attempting to detach a device that is not present in the domain XML,
8337 * but shares some specific attributes with one that is present,
8338 * may lead to unexpected results.
8340 * Returns 0 in case of success, -1 in case of failure.
8343 virDomainDetachDeviceFlags(virDomainPtr domain,
8344 const char *xml, unsigned int flags)
8346 virConnectPtr conn;
8348 VIR_DOMAIN_DEBUG(domain, "xml=%s, flags=0x%x", xml, flags);
8350 virResetLastError();
8352 virCheckDomainReturn(domain, -1);
8353 conn = domain->conn;
8355 virCheckNonNullArgGoto(xml, error);
8356 virCheckReadOnlyGoto(conn->flags, error);
8358 if (conn->driver->domainDetachDeviceFlags) {
8359 int ret;
8360 ret = conn->driver->domainDetachDeviceFlags(domain, xml, flags);
8361 if (ret < 0)
8362 goto error;
8363 return ret;
8366 virReportUnsupportedError();
8368 error:
8369 virDispatchError(domain->conn);
8370 return -1;
8375 * virDomainUpdateDeviceFlags:
8376 * @domain: pointer to domain object
8377 * @xml: pointer to XML description of one device
8378 * @flags: bitwise-OR of virDomainDeviceModifyFlags
8380 * Change a virtual device on a domain, using the flags parameter
8381 * to control how the device is changed. VIR_DOMAIN_AFFECT_CURRENT
8382 * specifies that the device change is made based on current domain
8383 * state. VIR_DOMAIN_AFFECT_LIVE specifies that the device shall be
8384 * changed on the active domain instance only and is not added to the
8385 * persisted domain configuration. VIR_DOMAIN_AFFECT_CONFIG
8386 * specifies that the device shall be changed on the persisted domain
8387 * configuration only. Note that the target hypervisor must return an
8388 * error if unable to satisfy flags. E.g. the hypervisor driver will
8389 * return failure if LIVE is specified but it only supports modifying the
8390 * persisted device allocation.
8392 * This method is used for actions such changing CDROM/Floppy device
8393 * media, altering the graphics configuration such as password,
8394 * reconfiguring the NIC device backend connectivity, etc.
8396 * The supplied XML description of the device should contain all
8397 * the information that is found in the corresponding domain XML.
8398 * Leaving out any piece of information may be treated as a
8399 * request for its removal, which may be denied. For instance,
8400 * when users want to change CDROM media only for live XML, they
8401 * must provide live disk XML as found in the corresponding live
8402 * domain XML with only the disk path changed.
8404 * Returns 0 in case of success, -1 in case of failure.
8407 virDomainUpdateDeviceFlags(virDomainPtr domain,
8408 const char *xml, unsigned int flags)
8410 virConnectPtr conn;
8412 VIR_DOMAIN_DEBUG(domain, "xml=%s, flags=0x%x", xml, flags);
8414 virResetLastError();
8416 virCheckDomainReturn(domain, -1);
8417 conn = domain->conn;
8419 virCheckNonNullArgGoto(xml, error);
8420 virCheckReadOnlyGoto(conn->flags, error);
8422 if (conn->driver->domainUpdateDeviceFlags) {
8423 int ret;
8424 ret = conn->driver->domainUpdateDeviceFlags(domain, xml, flags);
8425 if (ret < 0)
8426 goto error;
8427 return ret;
8430 virReportUnsupportedError();
8432 error:
8433 virDispatchError(domain->conn);
8434 return -1;
8439 * virDomainDetachDeviceAlias:
8440 * @domain: pointer to a domain object
8441 * @alias: device alias
8442 * @flags: bitwise-OR of virDomainDeviceModifyFlags
8444 * Detach a virtual device from a domain, using the alias to
8445 * specify the device. The value of @flags should be either
8446 * VIR_DOMAIN_AFFECT_CURRENT, or a bitwise-or of values from
8447 * VIR_DOMAIN_AFFECT_LIVE and VIR_DOMAIN_AFFECT_CURRENT, although
8448 * hypervisors vary in which flags are supported.
8450 * In contrast to virDomainDetachDeviceFlags() this API is
8451 * asynchronous - it returns immediately after sending the detach
8452 * request to the hypervisor. It's caller's responsibility to
8453 * wait for VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED event to signal
8454 * actual device removal or for
8455 * VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED to signal rejected
8456 * device removal.
8458 * Returns 0 in case of success, -1 in case of failure.
8461 virDomainDetachDeviceAlias(virDomainPtr domain,
8462 const char *alias,
8463 unsigned int flags)
8465 virConnectPtr conn;
8467 VIR_DOMAIN_DEBUG(domain, "alias=%s, flags=0x%x", alias, flags);
8469 virResetLastError();
8471 virCheckDomainReturn(domain, -1);
8472 conn = domain->conn;
8474 virCheckNonNullArgGoto(alias, error);
8475 virCheckReadOnlyGoto(conn->flags, error);
8477 if (conn->driver->domainDetachDeviceAlias) {
8478 int ret;
8479 ret = conn->driver->domainDetachDeviceAlias(domain, alias, flags);
8480 if (ret < 0)
8481 goto error;
8482 return ret;
8485 virReportUnsupportedError();
8487 error:
8488 virDispatchError(domain->conn);
8489 return -1;
8494 * virConnectDomainEventRegister:
8495 * @conn: pointer to the connection
8496 * @cb: callback to the function handling domain events
8497 * @opaque: opaque data to pass on to the callback
8498 * @freecb: optional function to deallocate opaque when not used anymore
8500 * Adds a callback to receive notifications of domain lifecycle events
8501 * occurring on a connection. This function requires that an event loop
8502 * has been previously registered with virEventRegisterImpl() or
8503 * virEventRegisterDefaultImpl().
8505 * Use of this method is no longer recommended. Instead applications
8506 * should try virConnectDomainEventRegisterAny() which has a more flexible
8507 * API contract.
8509 * The virDomainPtr object handle passed into the callback upon delivery
8510 * of an event is only valid for the duration of execution of the callback.
8511 * If the callback wishes to keep the domain object after the callback returns,
8512 * it shall take a reference to it, by calling virDomainRef.
8513 * The reference can be released once the object is no longer required
8514 * by calling virDomainFree.
8516 * Returns 0 on success, -1 on failure. Older versions of some hypervisors
8517 * sometimes returned a positive number on success, but without any reliable
8518 * semantics on what that number represents.
8521 virConnectDomainEventRegister(virConnectPtr conn,
8522 virConnectDomainEventCallback cb,
8523 void *opaque,
8524 virFreeCallback freecb)
8526 VIR_DEBUG("conn=%p, cb=%p, opaque=%p, freecb=%p", conn, cb, opaque, freecb);
8527 virResetLastError();
8529 virCheckConnectReturn(conn, -1);
8530 virCheckNonNullArgGoto(cb, error);
8532 if (conn->driver && conn->driver->connectDomainEventRegister) {
8533 int ret;
8534 ret = conn->driver->connectDomainEventRegister(conn, cb, opaque, freecb);
8535 if (ret < 0)
8536 goto error;
8537 return ret;
8540 virReportUnsupportedError();
8541 error:
8542 virDispatchError(conn);
8543 return -1;
8548 * virConnectDomainEventDeregister:
8549 * @conn: pointer to the connection
8550 * @cb: callback to the function handling domain events
8552 * Removes a callback previously registered with the
8553 * virConnectDomainEventRegister() function.
8555 * Use of this method is no longer recommended. Instead applications
8556 * should try virConnectDomainEventDeregisterAny() which has a more flexible
8557 * API contract
8559 * Returns 0 on success, -1 on failure. Older versions of some hypervisors
8560 * sometimes returned a positive number on success, but without any reliable
8561 * semantics on what that number represents.
8564 virConnectDomainEventDeregister(virConnectPtr conn,
8565 virConnectDomainEventCallback cb)
8567 VIR_DEBUG("conn=%p, cb=%p", conn, cb);
8569 virResetLastError();
8571 virCheckConnectReturn(conn, -1);
8572 virCheckNonNullArgGoto(cb, error);
8574 if (conn->driver && conn->driver->connectDomainEventDeregister) {
8575 int ret;
8576 ret = conn->driver->connectDomainEventDeregister(conn, cb);
8577 if (ret < 0)
8578 goto error;
8579 return ret;
8582 virReportUnsupportedError();
8583 error:
8584 virDispatchError(conn);
8585 return -1;
8590 * virDomainIsActive:
8591 * @dom: pointer to the domain object
8593 * Determine if the domain is currently running
8595 * Returns 1 if running, 0 if inactive, -1 on error
8598 virDomainIsActive(virDomainPtr dom)
8600 VIR_DEBUG("dom=%p", dom);
8602 virResetLastError();
8604 virCheckDomainReturn(dom, -1);
8606 if (dom->conn->driver->domainIsActive) {
8607 int ret;
8608 ret = dom->conn->driver->domainIsActive(dom);
8609 if (ret < 0)
8610 goto error;
8611 return ret;
8614 virReportUnsupportedError();
8615 error:
8616 virDispatchError(dom->conn);
8617 return -1;
8622 * virDomainIsPersistent:
8623 * @dom: pointer to the domain object
8625 * Determine if the domain has a persistent configuration
8626 * which means it will still exist after shutting down
8628 * Returns 1 if persistent, 0 if transient, -1 on error
8631 virDomainIsPersistent(virDomainPtr dom)
8633 VIR_DOMAIN_DEBUG(dom);
8635 virResetLastError();
8637 virCheckDomainReturn(dom, -1);
8639 if (dom->conn->driver->domainIsPersistent) {
8640 int ret;
8641 ret = dom->conn->driver->domainIsPersistent(dom);
8642 if (ret < 0)
8643 goto error;
8644 return ret;
8647 virReportUnsupportedError();
8648 error:
8649 virDispatchError(dom->conn);
8650 return -1;
8654 * virDomainRename:
8655 * @dom: pointer to the domain object
8656 * @new_name: new domain name
8657 * @flags: extra flags; not used yet, so callers should always pass 0
8659 * Rename a domain. New domain name is specified in the second
8660 * argument. Depending on each driver implementation it may be
8661 * required that domain is in a specific state.
8663 * There might be some attributes and/or elements in domain XML that if no
8664 * value provided at XML defining time, libvirt will derive their value from
8665 * the domain name. These are not updated by this API. Users are strongly
8666 * advised to change these after the rename was successful.
8668 * Returns 0 if successfully renamed, -1 on error
8671 virDomainRename(virDomainPtr dom,
8672 const char *new_name,
8673 unsigned int flags)
8675 VIR_DEBUG("dom=%p, new_name=%s", dom, NULLSTR(new_name));
8677 virResetLastError();
8678 virCheckDomainReturn(dom, -1);
8679 virCheckNonEmptyStringArgGoto(new_name, error);
8680 virCheckReadOnlyGoto(dom->conn->flags, error);
8682 if (dom->conn->driver->domainRename) {
8683 int ret = dom->conn->driver->domainRename(dom, new_name, flags);
8684 if (ret < 0)
8685 goto error;
8686 return ret;
8689 virReportUnsupportedError();
8690 error:
8691 virDispatchError(dom->conn);
8692 return -1;
8696 * virDomainIsUpdated:
8697 * @dom: pointer to the domain object
8699 * Determine if the domain has been updated.
8701 * Returns 1 if updated, 0 if not, -1 on error
8704 virDomainIsUpdated(virDomainPtr dom)
8706 VIR_DOMAIN_DEBUG(dom);
8708 virResetLastError();
8710 virCheckDomainReturn(dom, -1);
8712 if (dom->conn->driver->domainIsUpdated) {
8713 int ret;
8714 ret = dom->conn->driver->domainIsUpdated(dom);
8715 if (ret < 0)
8716 goto error;
8717 return ret;
8720 virReportUnsupportedError();
8721 error:
8722 virDispatchError(dom->conn);
8723 return -1;
8728 * virDomainGetJobInfo:
8729 * @domain: a domain object
8730 * @info: pointer to a virDomainJobInfo structure allocated by the user
8732 * Extract information about progress of a background job on a domain.
8733 * Will return an error if the domain is not active.
8735 * This function returns a limited amount of information in comparison
8736 * to virDomainGetJobStats().
8738 * Returns 0 in case of success and -1 in case of failure.
8741 virDomainGetJobInfo(virDomainPtr domain, virDomainJobInfoPtr info)
8743 virConnectPtr conn;
8745 VIR_DOMAIN_DEBUG(domain, "info=%p", info);
8747 virResetLastError();
8749 if (info)
8750 memset(info, 0, sizeof(*info));
8752 virCheckDomainReturn(domain, -1);
8753 virCheckNonNullArgGoto(info, error);
8755 conn = domain->conn;
8757 if (conn->driver->domainGetJobInfo) {
8758 int ret;
8759 ret = conn->driver->domainGetJobInfo(domain, info);
8760 if (ret < 0)
8761 goto error;
8762 return ret;
8765 virReportUnsupportedError();
8767 error:
8768 virDispatchError(domain->conn);
8769 return -1;
8774 * virDomainGetJobStats:
8775 * @domain: a domain object
8776 * @type: where to store the job type (one of virDomainJobType)
8777 * @params: where to store job statistics
8778 * @nparams: number of items in @params
8779 * @flags: bitwise-OR of virDomainGetJobStatsFlags
8781 * Extract information about progress of a background job on a domain.
8782 * Will return an error if the domain is not active. The function returns
8783 * a superset of progress information provided by virDomainGetJobInfo.
8784 * Possible fields returned in @params are defined by VIR_DOMAIN_JOB_*
8785 * macros and new fields will likely be introduced in the future so callers
8786 * may receive fields that they do not understand in case they talk to a
8787 * newer server.
8789 * When @flags contains VIR_DOMAIN_JOB_STATS_COMPLETED, the function will
8790 * return statistics about a recently completed job. Specifically, this
8791 * flag may be used to query statistics of a completed incoming pre-copy
8792 * migration (statistics for post-copy migration are only available on the
8793 * source host). Statistics of a completed job are automatically destroyed
8794 * once read or when libvirtd is restarted. Note that time information
8795 * returned for completed migrations may be completely irrelevant unless both
8796 * source and destination hosts have synchronized time (i.e., NTP daemon is
8797 * running on both of them). The statistics of a completed job can also be
8798 * obtained by listening to a VIR_DOMAIN_EVENT_ID_JOB_COMPLETED event (on the
8799 * source host in case of a migration job).
8801 * Returns 0 in case of success and -1 in case of failure.
8804 virDomainGetJobStats(virDomainPtr domain,
8805 int *type,
8806 virTypedParameterPtr *params,
8807 int *nparams,
8808 unsigned int flags)
8810 virConnectPtr conn;
8812 VIR_DOMAIN_DEBUG(domain, "type=%p, params=%p, nparams=%p, flags=0x%x",
8813 type, params, nparams, flags);
8815 virResetLastError();
8817 virCheckDomainReturn(domain, -1);
8818 virCheckNonNullArgGoto(type, error);
8819 virCheckNonNullArgGoto(params, error);
8820 virCheckNonNullArgGoto(nparams, error);
8822 conn = domain->conn;
8824 if (conn->driver->domainGetJobStats) {
8825 int ret;
8826 ret = conn->driver->domainGetJobStats(domain, type, params,
8827 nparams, flags);
8828 if (ret < 0)
8829 goto error;
8830 return ret;
8833 virReportUnsupportedError();
8835 error:
8836 virDispatchError(domain->conn);
8837 return -1;
8842 * virDomainAbortJob:
8843 * @domain: a domain object
8845 * Requests that the current background job be aborted at the
8846 * soonest opportunity. In case the job is a migration in a post-copy mode,
8847 * virDomainAbortJob will report an error (see virDomainMigrateStartPostCopy
8848 * for more details).
8850 * Returns 0 in case of success and -1 in case of failure.
8853 virDomainAbortJob(virDomainPtr domain)
8855 virConnectPtr conn;
8857 VIR_DOMAIN_DEBUG(domain);
8859 virResetLastError();
8861 virCheckDomainReturn(domain, -1);
8862 conn = domain->conn;
8864 virCheckReadOnlyGoto(conn->flags, error);
8866 if (conn->driver->domainAbortJob) {
8867 int ret;
8868 ret = conn->driver->domainAbortJob(domain);
8869 if (ret < 0)
8870 goto error;
8871 return ret;
8874 virReportUnsupportedError();
8876 error:
8877 virDispatchError(conn);
8878 return -1;
8883 * virDomainMigrateSetMaxDowntime:
8884 * @domain: a domain object
8885 * @downtime: maximum tolerable downtime for live migration, in milliseconds
8886 * @flags: extra flags; not used yet, so callers should always pass 0
8888 * Sets maximum tolerable time for which the domain is allowed to be paused
8889 * at the end of live migration. It's supposed to be called while the domain is
8890 * being live-migrated as a reaction to migration progress.
8892 * Returns 0 in case of success, -1 otherwise.
8895 virDomainMigrateSetMaxDowntime(virDomainPtr domain,
8896 unsigned long long downtime,
8897 unsigned int flags)
8899 virConnectPtr conn;
8901 VIR_DOMAIN_DEBUG(domain, "downtime=%llu, flags=0x%x", downtime, flags);
8903 virResetLastError();
8905 virCheckDomainReturn(domain, -1);
8906 conn = domain->conn;
8908 virCheckReadOnlyGoto(conn->flags, error);
8910 if (conn->driver->domainMigrateSetMaxDowntime) {
8911 if (conn->driver->domainMigrateSetMaxDowntime(domain, downtime, flags) < 0)
8912 goto error;
8913 return 0;
8916 virReportUnsupportedError();
8917 error:
8918 virDispatchError(conn);
8919 return -1;
8924 * virDomainMigrateGetMaxDowntime:
8925 * @domain: a domain object
8926 * @downtime: return value of the maximum tolerable downtime for live
8927 * migration, in milliseconds
8928 * @flags: extra flags; not used yet, so callers should always pass 0
8930 * Gets current maximum tolerable time for which the domain may be paused
8931 * at the end of live migration.
8933 * Returns 0 in case of success, -1 otherwise.
8936 virDomainMigrateGetMaxDowntime(virDomainPtr domain,
8937 unsigned long long *downtime,
8938 unsigned int flags)
8940 virConnectPtr conn;
8942 VIR_DOMAIN_DEBUG(domain, "downtime = %p, flags=0x%x", downtime, flags);
8944 virResetLastError();
8946 virCheckDomainReturn(domain, -1);
8947 conn = domain->conn;
8949 virCheckNonNullArgGoto(downtime, error);
8951 if (conn->driver->domainMigrateGetMaxDowntime) {
8952 if (conn->driver->domainMigrateGetMaxDowntime(domain, downtime, flags) < 0)
8953 goto error;
8954 return 0;
8957 virReportUnsupportedError();
8958 error:
8959 virDispatchError(conn);
8960 return -1;
8965 * virDomainMigrateGetCompressionCache:
8966 * @domain: a domain object
8967 * @cacheSize: return value of current size of the cache (in bytes)
8968 * @flags: extra flags; not used yet, so callers should always pass 0
8970 * Gets current size of the cache (in bytes) used for compressing repeatedly
8971 * transferred memory pages during live migration.
8973 * Returns 0 in case of success, -1 otherwise.
8976 virDomainMigrateGetCompressionCache(virDomainPtr domain,
8977 unsigned long long *cacheSize,
8978 unsigned int flags)
8980 virConnectPtr conn;
8982 VIR_DOMAIN_DEBUG(domain, "cacheSize=%p, flags=0x%x", cacheSize, flags);
8984 virResetLastError();
8986 virCheckDomainReturn(domain, -1);
8987 conn = domain->conn;
8989 virCheckNonNullArgGoto(cacheSize, error);
8991 if (conn->driver->domainMigrateGetCompressionCache) {
8992 if (conn->driver->domainMigrateGetCompressionCache(domain, cacheSize,
8993 flags) < 0)
8994 goto error;
8995 return 0;
8998 virReportUnsupportedError();
8999 error:
9000 virDispatchError(conn);
9001 return -1;
9006 * virDomainMigrateSetCompressionCache:
9007 * @domain: a domain object
9008 * @cacheSize: size of the cache (in bytes) used for compression
9009 * @flags: extra flags; not used yet, so callers should always pass 0
9011 * Sets size of the cache (in bytes) used for compressing repeatedly
9012 * transferred memory pages during live migration. It's supposed to be called
9013 * while the domain is being live-migrated as a reaction to migration progress
9014 * and increasing number of compression cache misses obtained from
9015 * virDomainGetJobStats.
9017 * Returns 0 in case of success, -1 otherwise.
9020 virDomainMigrateSetCompressionCache(virDomainPtr domain,
9021 unsigned long long cacheSize,
9022 unsigned int flags)
9024 virConnectPtr conn;
9026 VIR_DOMAIN_DEBUG(domain, "cacheSize=%llu, flags=0x%x", cacheSize, flags);
9028 virResetLastError();
9030 virCheckDomainReturn(domain, -1);
9031 conn = domain->conn;
9033 virCheckReadOnlyGoto(conn->flags, error);
9035 if (conn->driver->domainMigrateSetCompressionCache) {
9036 if (conn->driver->domainMigrateSetCompressionCache(domain, cacheSize,
9037 flags) < 0)
9038 goto error;
9039 return 0;
9042 virReportUnsupportedError();
9043 error:
9044 virDispatchError(conn);
9045 return -1;
9050 * virDomainMigrateSetMaxSpeed:
9051 * @domain: a domain object
9052 * @bandwidth: migration bandwidth limit in MiB/s
9053 * @flags: bitwise-OR of virDomainMigrateMaxSpeedFlags
9055 * The maximum bandwidth (in MiB/s) that will be used to do migration
9056 * can be specified with the bandwidth parameter. Not all hypervisors
9057 * will support a bandwidth cap. When VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY
9058 * is set in @flags, this API sets the maximum bandwidth for the post-copy
9059 * phase of the migration.
9061 * Returns 0 in case of success, -1 otherwise.
9064 virDomainMigrateSetMaxSpeed(virDomainPtr domain,
9065 unsigned long bandwidth,
9066 unsigned int flags)
9068 virConnectPtr conn;
9070 VIR_DOMAIN_DEBUG(domain, "bandwidth=%lu, flags=0x%x", bandwidth, flags);
9072 virResetLastError();
9074 virCheckDomainReturn(domain, -1);
9075 conn = domain->conn;
9077 virCheckReadOnlyGoto(conn->flags, error);
9079 if (conn->driver->domainMigrateSetMaxSpeed) {
9080 if (conn->driver->domainMigrateSetMaxSpeed(domain, bandwidth, flags) < 0)
9081 goto error;
9082 return 0;
9085 virReportUnsupportedError();
9086 error:
9087 virDispatchError(conn);
9088 return -1;
9093 * virDomainMigrateGetMaxSpeed:
9094 * @domain: a domain object
9095 * @bandwidth: return value of current migration bandwidth limit in MiB/s
9096 * @flags: bitwise-OR of virDomainMigrateMaxSpeedFlags
9098 * Get the current maximum bandwidth (in MiB/s) that will be used if the
9099 * domain is migrated. Not all hypervisors will support a bandwidth limit.
9100 * When VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY is set in @flags, this API
9101 * gets the current maximum bandwidth for the post-copy phase of the
9102 * migration.
9104 * Returns 0 in case of success, -1 otherwise.
9107 virDomainMigrateGetMaxSpeed(virDomainPtr domain,
9108 unsigned long *bandwidth,
9109 unsigned int flags)
9111 virConnectPtr conn;
9113 VIR_DOMAIN_DEBUG(domain, "bandwidth = %p, flags=0x%x", bandwidth, flags);
9115 virResetLastError();
9117 virCheckDomainReturn(domain, -1);
9118 conn = domain->conn;
9120 virCheckNonNullArgGoto(bandwidth, error);
9121 virCheckReadOnlyGoto(conn->flags, error);
9123 if (conn->driver->domainMigrateGetMaxSpeed) {
9124 if (conn->driver->domainMigrateGetMaxSpeed(domain, bandwidth, flags) < 0)
9125 goto error;
9126 return 0;
9129 virReportUnsupportedError();
9130 error:
9131 virDispatchError(conn);
9132 return -1;
9137 * virDomainMigrateStartPostCopy:
9138 * @domain: a domain object
9139 * @flags: extra flags; not used yet, so callers should always pass 0
9141 * Starts post-copy migration. This function has to be called while
9142 * migration (initiated with VIR_MIGRATE_POSTCOPY flag) is in progress.
9144 * Traditional pre-copy migration iteratively walks through guest memory
9145 * pages and migrates those that changed since the previous iteration. The
9146 * iterative phase stops when the number of dirty pages is low enough so that
9147 * the virtual CPUs can be paused, all dirty pages transferred to the
9148 * destination, where the virtual CPUs are unpaused, and all this can happen
9149 * within a predefined downtime period. It's clear that this process may never
9150 * converge if downtime is too short and/or the guest keeps changing a lot of
9151 * memory pages.
9153 * When migration is switched to post-copy mode, the virtual CPUs are paused
9154 * immediately, only a minimum set of pages is transferred, and the CPUs are
9155 * unpaused on destination. The source keeps sending all remaining memory pages
9156 * to the destination while the guest is already running there. Whenever the
9157 * guest tries to read a memory page which has not been migrated yet, the
9158 * hypervisor has to tell the source to transfer that page in a priority
9159 * channel. To minimize such page faults, it is a good idea to run at least one
9160 * iteration of pre-copy migration before switching to post-copy.
9162 * Post-copy migration is guaranteed to converge since each page is transferred
9163 * at most once no matter how fast it changes. On the other hand once the
9164 * guest is running on the destination host, the migration can no longer be
9165 * rolled back because none of the hosts has complete state. If this happens,
9166 * libvirt will leave the domain paused on both hosts with
9167 * VIR_DOMAIN_PAUSED_POSTCOPY_FAILED reason. It's up to the upper layer to
9168 * decide what to do in such case. Because of this, libvirt will refuse to
9169 * cancel post-copy migration via virDomainAbortJob.
9171 * The following domain life cycle events are emitted during post-copy
9172 * migration:
9173 * VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY (on the source) -- migration entered
9174 * post-copy mode.
9175 * VIR_DOMAIN_EVENT_RESUMED_POSTCOPY (on the destination) -- the guest is
9176 * running on the destination host while some of its memory pages still
9177 * remain on the source host; neither the source nor the destination host
9178 * contain a complete guest state from this point until migration
9179 * finishes.
9180 * VIR_DOMAIN_EVENT_RESUMED_MIGRATED (on the destination),
9181 * VIR_DOMAIN_EVENT_STOPPED_MIGRATED (on the source) -- migration finished
9182 * successfully and the destination host holds a complete guest state.
9183 * VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY_FAILED (on the destination) -- emitted
9184 * when migration fails in post-copy mode and it's unclear whether any
9185 * of the hosts has a complete guest state.
9187 * The progress of a post-copy migration can be monitored normally using
9188 * virDomainGetJobStats on the source host. Fetching statistics of a completed
9189 * post-copy migration can also be done on the source host (by calling
9190 * virDomainGetJobStats or listening to VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
9191 * event, but (in contrast to pre-copy migration) the statistics are not
9192 * available on the destination host. Thus, VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
9193 * event is the only way of getting statistics of a completed post-copy
9194 * migration of a transient domain (because the domain is removed after
9195 * migration and there's no domain to run virDomainGetJobStats on).
9197 * Returns 0 in case of success, -1 otherwise.
9200 virDomainMigrateStartPostCopy(virDomainPtr domain,
9201 unsigned int flags)
9203 virConnectPtr conn;
9205 VIR_DOMAIN_DEBUG(domain);
9207 virResetLastError();
9209 virCheckDomainReturn(domain, -1);
9210 conn = domain->conn;
9212 virCheckReadOnlyGoto(conn->flags, error);
9214 if (conn->driver->domainMigrateStartPostCopy) {
9215 if (conn->driver->domainMigrateStartPostCopy(domain, flags) < 0)
9216 goto error;
9217 return 0;
9220 virReportUnsupportedError();
9221 error:
9222 virDispatchError(conn);
9223 return -1;
9228 * virConnectDomainEventRegisterAny:
9229 * @conn: pointer to the connection
9230 * @dom: pointer to the domain
9231 * @eventID: the event type to receive
9232 * @cb: callback to the function handling domain events
9233 * @opaque: opaque data to pass on to the callback
9234 * @freecb: optional function to deallocate opaque when not used anymore
9236 * Adds a callback to receive notifications of arbitrary domain events
9237 * occurring on a domain. This function requires that an event loop
9238 * has been previously registered with virEventRegisterImpl() or
9239 * virEventRegisterDefaultImpl().
9241 * If @dom is NULL, then events will be monitored for any domain. If @dom
9242 * is non-NULL, then only the specific domain will be monitored.
9244 * Most types of event have a callback providing a custom set of parameters
9245 * for the event. When registering an event, it is thus necessary to use
9246 * the VIR_DOMAIN_EVENT_CALLBACK() macro to cast the supplied function pointer
9247 * to match the signature of this method.
9249 * The virDomainPtr object handle passed into the callback upon delivery
9250 * of an event is only valid for the duration of execution of the callback.
9251 * If the callback wishes to keep the domain object after the callback returns,
9252 * it shall take a reference to it, by calling virDomainRef().
9253 * The reference can be released once the object is no longer required
9254 * by calling virDomainFree().
9256 * The return value from this method is a positive integer identifier
9257 * for the callback. To unregister a callback, this callback ID should
9258 * be passed to the virConnectDomainEventDeregisterAny() method.
9260 * Returns a callback identifier on success, -1 on failure.
9263 virConnectDomainEventRegisterAny(virConnectPtr conn,
9264 virDomainPtr dom,
9265 int eventID,
9266 virConnectDomainEventGenericCallback cb,
9267 void *opaque,
9268 virFreeCallback freecb)
9270 VIR_DOMAIN_DEBUG(dom, "conn=%p, eventID=%d, cb=%p, opaque=%p, freecb=%p",
9271 conn, eventID, cb, opaque, freecb);
9273 virResetLastError();
9275 virCheckConnectReturn(conn, -1);
9276 if (dom) {
9277 virCheckDomainGoto(dom, error);
9278 if (dom->conn != conn) {
9279 virReportInvalidArg(dom,
9280 _("domain '%s' must match connection"),
9281 dom->name);
9282 goto error;
9285 virCheckNonNullArgGoto(cb, error);
9286 virCheckNonNegativeArgGoto(eventID, error);
9287 if (eventID >= VIR_DOMAIN_EVENT_ID_LAST) {
9288 virReportInvalidArg(eventID,
9289 _("eventID must be less than %d"),
9290 VIR_DOMAIN_EVENT_ID_LAST);
9291 goto error;
9294 if (conn->driver && conn->driver->connectDomainEventRegisterAny) {
9295 int ret;
9296 ret = conn->driver->connectDomainEventRegisterAny(conn, dom, eventID, cb, opaque, freecb);
9297 if (ret < 0)
9298 goto error;
9299 return ret;
9302 virReportUnsupportedError();
9303 error:
9304 virDispatchError(conn);
9305 return -1;
9310 * virConnectDomainEventDeregisterAny:
9311 * @conn: pointer to the connection
9312 * @callbackID: the callback identifier
9314 * Removes an event callback. The callbackID parameter should be the
9315 * value obtained from a previous virConnectDomainEventRegisterAny() method.
9317 * Returns 0 on success, -1 on failure. Older versions of some hypervisors
9318 * sometimes returned a positive number on success, but without any reliable
9319 * semantics on what that number represents. */
9321 virConnectDomainEventDeregisterAny(virConnectPtr conn,
9322 int callbackID)
9324 VIR_DEBUG("conn=%p, callbackID=%d", conn, callbackID);
9326 virResetLastError();
9328 virCheckConnectReturn(conn, -1);
9329 virCheckNonNegativeArgGoto(callbackID, error);
9331 if (conn->driver && conn->driver->connectDomainEventDeregisterAny) {
9332 int ret;
9333 ret = conn->driver->connectDomainEventDeregisterAny(conn, callbackID);
9334 if (ret < 0)
9335 goto error;
9336 return ret;
9339 virReportUnsupportedError();
9340 error:
9341 virDispatchError(conn);
9342 return -1;
9347 * virDomainManagedSave:
9348 * @dom: pointer to the domain
9349 * @flags: bitwise-OR of virDomainSaveRestoreFlags
9351 * This method will suspend a domain and save its memory contents to
9352 * a file on disk. After the call, if successful, the domain is not
9353 * listed as running anymore.
9354 * The difference from virDomainSave() is that libvirt is keeping track of
9355 * the saved state itself, and will reuse it once the domain is being
9356 * restarted (automatically or via an explicit libvirt call).
9357 * As a result any running domain is sure to not have a managed saved image.
9358 * This also implies that managed save only works on persistent domains,
9359 * since the domain must still exist in order to use virDomainCreate() to
9360 * restart it.
9362 * If @flags includes VIR_DOMAIN_SAVE_BYPASS_CACHE, then libvirt will
9363 * attempt to bypass the file system cache while creating the file, or
9364 * fail if it cannot do so for the given system; this can allow less
9365 * pressure on file system cache, but also risks slowing saves to NFS.
9367 * Normally, the managed saved state will remember whether the domain
9368 * was running or paused, and start will resume to the same state.
9369 * Specifying VIR_DOMAIN_SAVE_RUNNING or VIR_DOMAIN_SAVE_PAUSED in
9370 * @flags will override the default saved into the file. These two
9371 * flags are mutually exclusive.
9373 * Returns 0 in case of success or -1 in case of failure
9376 virDomainManagedSave(virDomainPtr dom, unsigned int flags)
9378 virConnectPtr conn;
9380 VIR_DOMAIN_DEBUG(dom, "flags=0x%x", flags);
9382 virResetLastError();
9384 virCheckDomainReturn(dom, -1);
9385 conn = dom->conn;
9387 virCheckReadOnlyGoto(conn->flags, error);
9389 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SAVE_RUNNING,
9390 VIR_DOMAIN_SAVE_PAUSED,
9391 error);
9393 if (conn->driver->domainManagedSave) {
9394 int ret;
9396 ret = conn->driver->domainManagedSave(dom, flags);
9397 if (ret < 0)
9398 goto error;
9399 return ret;
9402 virReportUnsupportedError();
9404 error:
9405 virDispatchError(conn);
9406 return -1;
9411 * virDomainHasManagedSaveImage:
9412 * @dom: pointer to the domain
9413 * @flags: extra flags; not used yet, so callers should always pass 0
9415 * Check if a domain has a managed save image as created by
9416 * virDomainManagedSave(). Note that any running domain should not have
9417 * such an image, as it should have been removed on restart.
9419 * Returns 0 if no image is present, 1 if an image is present, and
9420 * -1 in case of error
9423 virDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
9425 virConnectPtr conn;
9427 VIR_DOMAIN_DEBUG(dom, "flags=0x%x", flags);
9429 virResetLastError();
9431 virCheckDomainReturn(dom, -1);
9432 conn = dom->conn;
9434 if (conn->driver->domainHasManagedSaveImage) {
9435 int ret;
9437 ret = conn->driver->domainHasManagedSaveImage(dom, flags);
9438 if (ret < 0)
9439 goto error;
9440 return ret;
9443 virReportUnsupportedError();
9445 error:
9446 virDispatchError(conn);
9447 return -1;
9452 * virDomainManagedSaveRemove:
9453 * @dom: pointer to the domain
9454 * @flags: extra flags; not used yet, so callers should always pass 0
9456 * Remove any managed save image for this domain.
9458 * Returns 0 in case of success, and -1 in case of error
9461 virDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags)
9463 virConnectPtr conn;
9465 VIR_DOMAIN_DEBUG(dom, "flags=0x%x", flags);
9467 virResetLastError();
9469 virCheckDomainReturn(dom, -1);
9470 conn = dom->conn;
9472 virCheckReadOnlyGoto(conn->flags, error);
9474 if (conn->driver->domainManagedSaveRemove) {
9475 int ret;
9477 ret = conn->driver->domainManagedSaveRemove(dom, flags);
9478 if (ret < 0)
9479 goto error;
9480 return ret;
9483 virReportUnsupportedError();
9485 error:
9486 virDispatchError(conn);
9487 return -1;
9492 * virDomainManagedSaveGetXMLDesc:
9493 * @domain: a domain object
9494 * @flags: bitwise-OR of supported virDomainSaveImageXMLFlags
9496 * This method will extract the XML description of the managed save
9497 * state file of a domain.
9499 * No security-sensitive data will be included unless @flags contains
9500 * VIR_DOMAIN_SAVE_IMAGE_XML_SECURE; this flag is rejected on read-only
9501 * connections.
9503 * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of
9504 * error. The caller must free() the returned value.
9506 char *
9507 virDomainManagedSaveGetXMLDesc(virDomainPtr domain, unsigned int flags)
9509 virConnectPtr conn;
9511 VIR_DOMAIN_DEBUG(domain, "flags=0x%x", flags);
9513 virResetLastError();
9515 virCheckDomainReturn(domain, NULL);
9516 conn = domain->conn;
9518 if ((conn->flags & VIR_CONNECT_RO) &&
9519 (flags & VIR_DOMAIN_SAVE_IMAGE_XML_SECURE)) {
9520 virReportError(VIR_ERR_OPERATION_DENIED, "%s",
9521 _("virDomainManagedSaveGetXMLDesc with secure flag"));
9522 goto error;
9525 if (conn->driver->domainManagedSaveGetXMLDesc) {
9526 char *ret;
9527 ret = conn->driver->domainManagedSaveGetXMLDesc(domain, flags);
9528 if (!ret)
9529 goto error;
9530 return ret;
9533 virReportUnsupportedError();
9535 error:
9536 virDispatchError(domain->conn);
9537 return NULL;
9542 * virDomainManagedSaveDefineXML:
9543 * @domain: a domain object
9544 * @dxml: XML config for adjusting guest xml used on restore
9545 * @flags: bitwise-OR of virDomainSaveRestoreFlags
9547 * This updates the definition of a domain stored in a saved state
9548 * file.
9550 * @dxml can be used to alter host-specific portions of the domain XML
9551 * that will be used on the next start of the domain. For example, it is
9552 * possible to alter the backing filename that is associated with a
9553 * disk device.
9555 * Normally, the saved state file will remember whether the domain was
9556 * running or paused, and restore defaults to the same state.
9557 * Specifying VIR_DOMAIN_SAVE_RUNNING or VIR_DOMAIN_SAVE_PAUSED in
9558 * @flags will override the default saved into the file; omitting both
9559 * leaves the file's default unchanged. These two flags are mutually
9560 * exclusive.
9562 * Returns 0 in case of success and -1 in case of failure.
9565 virDomainManagedSaveDefineXML(virDomainPtr domain, const char *dxml,
9566 unsigned int flags)
9568 virConnectPtr conn;
9570 VIR_DOMAIN_DEBUG(domain, "flags=0x%x", flags);
9572 virResetLastError();
9574 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SAVE_RUNNING,
9575 VIR_DOMAIN_SAVE_PAUSED,
9576 error);
9578 virCheckDomainReturn(domain, -1);
9579 conn = domain->conn;
9581 if (conn->driver->domainManagedSaveDefineXML) {
9582 int ret;
9583 ret = conn->driver->domainManagedSaveDefineXML(domain, dxml, flags);
9585 if (ret < 0)
9586 goto error;
9587 return ret;
9590 virReportUnsupportedError();
9592 error:
9593 virDispatchError(domain->conn);
9594 return -1;
9599 * virDomainOpenConsole:
9600 * @dom: a domain object
9601 * @dev_name: the console, serial or parallel port device alias, or NULL
9602 * @st: a stream to associate with the console
9603 * @flags: bitwise-OR of virDomainConsoleFlags
9605 * This opens the backend associated with a console, serial or
9606 * parallel port device on a guest, if the backend is supported.
9607 * If the @dev_name is omitted, then the first console or serial
9608 * device is opened. The console is associated with the passed
9609 * in @st stream, which should have been opened in non-blocking
9610 * mode for bi-directional I/O.
9612 * By default, when @flags is 0, the open will fail if libvirt
9613 * detects that the console is already in use by another client;
9614 * passing VIR_DOMAIN_CONSOLE_FORCE will cause libvirt to forcefully
9615 * remove the other client prior to opening this console.
9617 * If flag VIR_DOMAIN_CONSOLE_SAFE the console is opened only in the
9618 * case where the hypervisor driver supports safe (mutually exclusive)
9619 * console handling.
9621 * Older servers did not support either flag, and also did not forbid
9622 * simultaneous clients on a console, with potentially confusing results.
9623 * When passing @flags of 0 in order to support a wider range of server
9624 * versions, it is up to the client to ensure mutual exclusion.
9626 * Returns 0 if the console was opened, -1 on error
9629 virDomainOpenConsole(virDomainPtr dom,
9630 const char *dev_name,
9631 virStreamPtr st,
9632 unsigned int flags)
9634 virConnectPtr conn;
9636 VIR_DOMAIN_DEBUG(dom, "dev_name=%s, st=%p, flags=0x%x",
9637 NULLSTR(dev_name), st, flags);
9639 virResetLastError();
9641 virCheckDomainReturn(dom, -1);
9642 conn = dom->conn;
9644 virCheckStreamGoto(st, error);
9645 virCheckReadOnlyGoto(conn->flags, error);
9647 if (conn != st->conn) {
9648 virReportInvalidArg(st,
9649 _("stream must match connection of domain '%s'"),
9650 dom->name);
9651 goto error;
9654 if (conn->driver->domainOpenConsole) {
9655 int ret;
9656 ret = conn->driver->domainOpenConsole(dom, dev_name, st, flags);
9657 if (ret < 0)
9658 goto error;
9659 return ret;
9662 virReportUnsupportedError();
9664 error:
9665 virDispatchError(conn);
9666 return -1;
9671 * virDomainOpenChannel:
9672 * @dom: a domain object
9673 * @name: the channel name, or NULL
9674 * @st: a stream to associate with the channel
9675 * @flags: bitwise-OR of virDomainChannelFlags
9677 * This opens the host interface associated with a channel device on a
9678 * guest, if the host interface is supported. If @name is given, it
9679 * can match either the device alias (e.g. "channel0"), or the virtio
9680 * target name (e.g. "org.qemu.guest_agent.0"). If @name is omitted,
9681 * then the first channel is opened. The channel is associated with
9682 * the passed in @st stream, which should have been opened in
9683 * non-blocking mode for bi-directional I/O.
9685 * By default, when @flags is 0, the open will fail if libvirt detects
9686 * that the channel is already in use by another client; passing
9687 * VIR_DOMAIN_CHANNEL_FORCE will cause libvirt to forcefully remove the
9688 * other client prior to opening this channel.
9690 * Returns 0 if the channel was opened, -1 on error
9693 virDomainOpenChannel(virDomainPtr dom,
9694 const char *name,
9695 virStreamPtr st,
9696 unsigned int flags)
9698 virConnectPtr conn;
9700 VIR_DOMAIN_DEBUG(dom, "name=%s, st=%p, flags=0x%x",
9701 NULLSTR(name), st, flags);
9703 virResetLastError();
9705 virCheckDomainReturn(dom, -1);
9706 conn = dom->conn;
9708 virCheckStreamGoto(st, error);
9709 virCheckReadOnlyGoto(conn->flags, error);
9711 if (conn != st->conn) {
9712 virReportInvalidArg(st,
9713 _("stream must match connection of domain '%s'"),
9714 dom->name);
9715 goto error;
9718 if (conn->driver->domainOpenChannel) {
9719 int ret;
9720 ret = conn->driver->domainOpenChannel(dom, name, st, flags);
9721 if (ret < 0)
9722 goto error;
9723 return ret;
9726 virReportUnsupportedError();
9728 error:
9729 virDispatchError(conn);
9730 return -1;
9735 * virDomainGetPerfEvents:
9736 * @domain: a domain object
9737 * @params: where to store perf events setting
9738 * @nparams: number of items in @params
9739 * @flags: bitwise-OR of virDomainModificationImpact
9741 * Get all Linux perf events setting. Possible fields returned in
9742 * @params are defined by VIR_PERF_EVENT_* macros and new fields
9743 * will likely be introduced in the future.
9745 * Linux perf events are performance analyzing tool in Linux.
9747 * Returns -1 in case of failure, 0 in case of success.
9749 int virDomainGetPerfEvents(virDomainPtr domain,
9750 virTypedParameterPtr *params,
9751 int *nparams,
9752 unsigned int flags)
9754 virConnectPtr conn;
9756 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%p flags=0x%x",
9757 params, nparams, flags);
9759 virResetLastError();
9761 virCheckDomainReturn(domain, -1);
9762 virCheckNonNullArgGoto(params, error);
9763 virCheckNonNullArgGoto(nparams, error);
9765 conn = domain->conn;
9767 if (conn->driver->domainGetPerfEvents) {
9768 int ret;
9769 ret = conn->driver->domainGetPerfEvents(domain, params,
9770 nparams, flags);
9771 if (ret < 0)
9772 goto error;
9773 return ret;
9775 virReportUnsupportedError();
9777 error:
9778 virDispatchError(domain->conn);
9779 return -1;
9784 * virDomainSetPerfEvents:
9785 * @domain: a domain object
9786 * @params: pointer to perf events parameter object
9787 * @nparams: number of perf event parameters (this value can be the same
9788 * less than the number of parameters supported)
9789 * @flags: bitwise-OR of virDomainModificationImpact
9791 * Enable or disable the particular list of Linux perf events you
9792 * care about. The @params argument should contain any subset of
9793 * VIR_PERF_EVENT_ macros.
9795 * Linux perf events are performance analyzing tool in Linux.
9797 * Returns -1 in case of error, 0 in case of success.
9799 int virDomainSetPerfEvents(virDomainPtr domain,
9800 virTypedParameterPtr params,
9801 int nparams,
9802 unsigned int flags)
9804 virConnectPtr conn;
9806 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d flags=0x%x",
9807 params, nparams, flags);
9808 VIR_TYPED_PARAMS_DEBUG(params, nparams);
9810 virResetLastError();
9812 virCheckDomainReturn(domain, -1);
9813 conn = domain->conn;
9815 virCheckReadOnlyGoto(conn->flags, error);
9816 virCheckNonNullArgGoto(params, error);
9817 virCheckPositiveArgGoto(nparams, error);
9819 if (virTypedParameterValidateSet(conn, params, nparams) < 0)
9820 goto error;
9822 if (conn->driver->domainSetPerfEvents) {
9823 int ret;
9824 ret = conn->driver->domainSetPerfEvents(domain, params,
9825 nparams, flags);
9826 if (ret < 0)
9827 goto error;
9828 return ret;
9831 virReportUnsupportedError();
9833 error:
9834 virDispatchError(domain->conn);
9835 return -1;
9840 * virDomainBlockJobAbort:
9841 * @dom: pointer to domain object
9842 * @disk: path to the block device, or device shorthand
9843 * @flags: bitwise-OR of virDomainBlockJobAbortFlags
9845 * Cancel the active block job on the given disk.
9847 * The @disk parameter is either an unambiguous source name of the
9848 * block device (the <source file='...'/> sub-element, such as
9849 * "/path/to/image"), or (since 0.9.5) the device target shorthand
9850 * (the <target dev='...'/> sub-element, such as "vda"). Valid names
9851 * can be found by calling virDomainGetXMLDesc() and inspecting
9852 * elements within //domain/devices/disk.
9854 * If the current block job for @disk is VIR_DOMAIN_BLOCK_JOB_TYPE_PULL, then
9855 * by default, this function performs a synchronous operation and the caller
9856 * may assume that the operation has completed when 0 is returned. However,
9857 * BlockJob operations may take a long time to cancel, and during this time
9858 * further domain interactions may be unresponsive. To avoid this problem,
9859 * pass VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC in the @flags argument to enable
9860 * asynchronous behavior, returning as soon as possible. When the job has
9861 * been canceled, a BlockJob event will be emitted, with status
9862 * VIR_DOMAIN_BLOCK_JOB_CANCELED (even if the ABORT_ASYNC flag was not
9863 * used); it is also possible to poll virDomainBlockJobInfo() to see if
9864 * the job cancellation is still pending. This type of job can be restarted
9865 * to pick up from where it left off.
9867 * If the current block job for @disk is VIR_DOMAIN_BLOCK_JOB_TYPE_COPY, then
9868 * the default is to abort the mirroring and revert to the source disk;
9869 * likewise, if the current job is VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT,
9870 * the default is to abort without changing the active layer of @disk.
9871 * Adding @flags of VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT causes this call to
9872 * fail with VIR_ERR_BLOCK_COPY_ACTIVE if the copy or commit is not yet
9873 * ready; otherwise it will swap the disk over to the new active image
9874 * to end the mirroring or active commit. An event will be issued when the
9875 * job is ended, and it is possible to use VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC
9876 * to control whether this command waits for the completion of the job.
9877 * Restarting a copy or active commit job requires starting over from the
9878 * beginning of the first phase.
9880 * Returns -1 in case of failure, 0 when successful.
9883 virDomainBlockJobAbort(virDomainPtr dom, const char *disk,
9884 unsigned int flags)
9886 virConnectPtr conn;
9888 VIR_DOMAIN_DEBUG(dom, "disk=%s, flags=0x%x", disk, flags);
9890 virResetLastError();
9892 virCheckDomainReturn(dom, -1);
9893 conn = dom->conn;
9895 virCheckReadOnlyGoto(conn->flags, error);
9896 virCheckNonNullArgGoto(disk, error);
9898 if (conn->driver->domainBlockJobAbort) {
9899 int ret;
9900 ret = conn->driver->domainBlockJobAbort(dom, disk, flags);
9901 if (ret < 0)
9902 goto error;
9903 return ret;
9906 virReportUnsupportedError();
9908 error:
9909 virDispatchError(dom->conn);
9910 return -1;
9915 * virDomainGetBlockJobInfo:
9916 * @dom: pointer to domain object
9917 * @disk: path to the block device, or device shorthand
9918 * @info: pointer to a virDomainBlockJobInfo structure
9919 * @flags: bitwise-OR of virDomainBlockJobInfoFlags
9921 * Request block job information for the given disk. If an operation is active
9922 * @info will be updated with the current progress. The units used for the
9923 * bandwidth field of @info depends on @flags. If @flags includes
9924 * VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES, bandwidth is in bytes/second
9925 * (although this mode can risk failure due to overflow, depending on both
9926 * client and server word size); otherwise, the value is rounded up to MiB/s.
9928 * The @disk parameter is either an unambiguous source name of the
9929 * block device (the <source file='...'/> sub-element, such as
9930 * "/path/to/image"), or (since 0.9.5) the device target shorthand
9931 * (the <target dev='...'/> sub-element, such as "vda"). Valid names
9932 * can be found by calling virDomainGetXMLDesc() and inspecting
9933 * elements within //domain/devices/disk.
9935 * As a corner case underlying hypervisor may report cur == 0 and
9936 * end == 0 when the block job hasn't been started yet. In this
9937 * case libvirt reports cur = 0 and end = 1. However, hypervisor
9938 * may return cur == 0 and end == 0 if the block job has finished
9939 * and was no-op. In this case libvirt reports cur = 1 and end = 1.
9940 * Since 2.3.0.
9942 * Returns -1 in case of failure, 0 when nothing found, 1 when info was found.
9945 virDomainGetBlockJobInfo(virDomainPtr dom, const char *disk,
9946 virDomainBlockJobInfoPtr info, unsigned int flags)
9948 virConnectPtr conn;
9950 VIR_DOMAIN_DEBUG(dom, "disk=%s, info=%p, flags=0x%x", disk, info, flags);
9952 virResetLastError();
9954 if (info)
9955 memset(info, 0, sizeof(*info));
9957 virCheckDomainReturn(dom, -1);
9958 conn = dom->conn;
9960 virCheckNonNullArgGoto(disk, error);
9961 virCheckNonNullArgGoto(info, error);
9963 if (conn->driver->domainGetBlockJobInfo) {
9964 int ret;
9965 ret = conn->driver->domainGetBlockJobInfo(dom, disk, info, flags);
9966 if (ret < 0)
9967 goto error;
9968 return ret;
9971 virReportUnsupportedError();
9973 error:
9974 virDispatchError(dom->conn);
9975 return -1;
9980 * virDomainBlockJobSetSpeed:
9981 * @dom: pointer to domain object
9982 * @disk: path to the block device, or device shorthand
9983 * @bandwidth: specify bandwidth limit; flags determine the unit
9984 * @flags: bitwise-OR of virDomainBlockJobSetSpeedFlags
9986 * Set the maximimum allowable bandwidth that a block job may consume. If
9987 * bandwidth is 0, the limit will revert to the hypervisor default of
9988 * unlimited.
9990 * If @flags contains VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES, @bandwidth
9991 * is in bytes/second; otherwise, it is in MiB/second. Values larger than
9992 * 2^52 bytes/sec may be rejected due to overflow considerations based on
9993 * the word size of both client and server, and values larger than 2^31
9994 * bytes/sec may cause overflow problems if later queried by
9995 * virDomainGetBlockJobInfo() without scaling. Hypervisors may further
9996 * restrict the range of valid bandwidth values.
9998 * The @disk parameter is either an unambiguous source name of the
9999 * block device (the <source file='...'/> sub-element, such as
10000 * "/path/to/image"), or (since 0.9.5) the device target shorthand
10001 * (the <target dev='...'/> sub-element, such as "vda"). Valid names
10002 * can be found by calling virDomainGetXMLDesc() and inspecting
10003 * elements within //domain/devices/disk.
10005 * Returns -1 in case of failure, 0 when successful.
10008 virDomainBlockJobSetSpeed(virDomainPtr dom, const char *disk,
10009 unsigned long bandwidth, unsigned int flags)
10011 virConnectPtr conn;
10013 VIR_DOMAIN_DEBUG(dom, "disk=%s, bandwidth=%lu, flags=0x%x",
10014 disk, bandwidth, flags);
10016 virResetLastError();
10018 virCheckDomainReturn(dom, -1);
10019 conn = dom->conn;
10021 virCheckReadOnlyGoto(conn->flags, error);
10022 virCheckNonNullArgGoto(disk, error);
10024 if (conn->driver->domainBlockJobSetSpeed) {
10025 int ret;
10026 ret = conn->driver->domainBlockJobSetSpeed(dom, disk, bandwidth, flags);
10027 if (ret < 0)
10028 goto error;
10029 return ret;
10032 virReportUnsupportedError();
10034 error:
10035 virDispatchError(dom->conn);
10036 return -1;
10041 * virDomainBlockPull:
10042 * @dom: pointer to domain object
10043 * @disk: path to the block device, or device shorthand
10044 * @bandwidth: (optional) specify bandwidth limit; flags determine the unit
10045 * @flags: bitwise-OR of virDomainBlockPullFlags
10047 * Populate a disk image with data from its backing image. Once all data from
10048 * its backing image has been pulled, the disk no longer depends on a backing
10049 * image. This function pulls data for the entire device in the background.
10050 * Progress of the operation can be checked with virDomainGetBlockJobInfo() and
10051 * the operation can be aborted with virDomainBlockJobAbort(). When finished,
10052 * an asynchronous event is raised to indicate the final status. To move
10053 * data in the opposite direction, see virDomainBlockCommit().
10055 * The @disk parameter is either an unambiguous source name of the
10056 * block device (the <source file='...'/> sub-element, such as
10057 * "/path/to/image"), or (since 0.9.5) the device target shorthand
10058 * (the <target dev='...'/> sub-element, such as "vda"). Valid names
10059 * can be found by calling virDomainGetXMLDesc() and inspecting
10060 * elements within //domain/devices/disk.
10062 * The maximum bandwidth that will be used to do the copy can be
10063 * specified with the @bandwidth parameter. If set to 0, there is no
10064 * limit. If @flags includes VIR_DOMAIN_BLOCK_PULL_BANDWIDTH_BYTES,
10065 * @bandwidth is in bytes/second; otherwise, it is in MiB/second.
10066 * Values larger than 2^52 bytes/sec may be rejected due to overflow
10067 * considerations based on the word size of both client and server,
10068 * and values larger than 2^31 bytes/sec may cause overflow problems
10069 * if later queried by virDomainGetBlockJobInfo() without scaling.
10070 * Hypervisors may further restrict the range of valid bandwidth
10071 * values. Some hypervisors do not support this feature and will
10072 * return an error if bandwidth is not 0; in this case, it might still
10073 * be possible for a later call to virDomainBlockJobSetSpeed() to
10074 * succeed. The actual speed can be determined with
10075 * virDomainGetBlockJobInfo().
10077 * This is shorthand for virDomainBlockRebase() with a NULL base.
10079 * Returns 0 if the operation has started, -1 on failure.
10082 virDomainBlockPull(virDomainPtr dom, const char *disk,
10083 unsigned long bandwidth, unsigned int flags)
10085 virConnectPtr conn;
10087 VIR_DOMAIN_DEBUG(dom, "disk=%s, bandwidth=%lu, flags=0x%x",
10088 disk, bandwidth, flags);
10090 virResetLastError();
10092 virCheckDomainReturn(dom, -1);
10093 conn = dom->conn;
10095 virCheckReadOnlyGoto(conn->flags, error);
10096 virCheckNonNullArgGoto(disk, error);
10098 if (conn->driver->domainBlockPull) {
10099 int ret;
10100 ret = conn->driver->domainBlockPull(dom, disk, bandwidth, flags);
10101 if (ret < 0)
10102 goto error;
10103 return ret;
10106 virReportUnsupportedError();
10108 error:
10109 virDispatchError(dom->conn);
10110 return -1;
10115 * virDomainBlockRebase:
10116 * @dom: pointer to domain object
10117 * @disk: path to the block device, or device shorthand
10118 * @base: path to backing file to keep, or device shorthand,
10119 * or NULL for no backing file
10120 * @bandwidth: (optional) specify bandwidth limit; flags determine the unit
10121 * @flags: bitwise-OR of virDomainBlockRebaseFlags
10123 * Populate a disk image with data from its backing image chain, and
10124 * setting the backing image to @base, or alternatively copy an entire
10125 * backing chain to a new file @base.
10127 * When @flags is 0, this starts a pull, where @base must be the absolute
10128 * path of one of the backing images further up the chain, or NULL to
10129 * convert the disk image so that it has no backing image. Once all
10130 * data from its backing image chain has been pulled, the disk no
10131 * longer depends on those intermediate backing images. This function
10132 * pulls data for the entire device in the background. Progress of
10133 * the operation can be checked with virDomainGetBlockJobInfo() with a
10134 * job type of VIR_DOMAIN_BLOCK_JOB_TYPE_PULL, and the operation can be
10135 * aborted with virDomainBlockJobAbort(). When finished, an asynchronous
10136 * event is raised to indicate the final status, and the job no longer
10137 * exists. If the job is aborted, a new one can be started later to
10138 * resume from the same point.
10140 * If @flags contains VIR_DOMAIN_BLOCK_REBASE_RELATIVE, the name recorded
10141 * into the active disk as the location for @base will be kept relative.
10142 * The operation will fail if libvirt can't infer the name.
10144 * When @flags includes VIR_DOMAIN_BLOCK_REBASE_COPY, this starts a copy,
10145 * where @base must be the name of a new file to copy the chain to. By
10146 * default, the copy will pull the entire source chain into the destination
10147 * file, but if @flags also contains VIR_DOMAIN_BLOCK_REBASE_SHALLOW, then
10148 * only the top of the source chain will be copied (the source and
10149 * destination have a common backing file). By default, @base will be
10150 * created with the same file format as the source, but this can be altered
10151 * by adding VIR_DOMAIN_BLOCK_REBASE_COPY_RAW to force the copy to be raw
10152 * (does not make sense with the shallow flag unless the source is also raw),
10153 * or by using VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT to reuse an existing file
10154 * which was pre-created with the correct format and metadata and sufficient
10155 * size to hold the copy. In case the VIR_DOMAIN_BLOCK_REBASE_SHALLOW flag
10156 * is used the pre-created file has to exhibit the same guest visible contents
10157 * as the backing file of the original image. This allows a management app to
10158 * pre-create files with relative backing file names, rather than the default
10159 * of absolute backing file names; as a security precaution, you should
10160 * generally only use reuse_ext with the shallow flag and a non-raw
10161 * destination file. By default, the copy destination will be treated as
10162 * type='file', but using VIR_DOMAIN_BLOCK_REBASE_COPY_DEV treats the
10163 * destination as type='block' (affecting how virDomainGetBlockInfo() will
10164 * report allocation after pivoting).
10166 * A copy job has two parts; in the first phase, the @bandwidth parameter
10167 * affects how fast the source is pulled into the destination, and the job
10168 * can only be canceled by reverting to the source file; progress in this
10169 * phase can be tracked via the virDomainBlockJobInfo() command, with a
10170 * job type of VIR_DOMAIN_BLOCK_JOB_TYPE_COPY. The job transitions to the
10171 * second phase when the job info states cur == end, and remains alive to
10172 * mirror all further changes to both source and destination. The user
10173 * must call virDomainBlockJobAbort() to end the mirroring while choosing
10174 * whether to revert to source or pivot to the destination. An event is
10175 * issued when the job ends, and depending on the hypervisor, an event may
10176 * also be issued when the job transitions from pulling to mirroring. If
10177 * the job is aborted, a new job will have to start over from the beginning
10178 * of the first phase.
10180 * Some hypervisors will restrict certain actions, such as virDomainSave()
10181 * or virDomainDetachDevice(), while a copy job is active; they may
10182 * also restrict a copy job to transient domains.
10184 * The @disk parameter is either an unambiguous source name of the
10185 * block device (the <source file='...'/> sub-element, such as
10186 * "/path/to/image"), or the device target shorthand (the
10187 * <target dev='...'/> sub-element, such as "vda"). Valid names
10188 * can be found by calling virDomainGetXMLDesc() and inspecting
10189 * elements within //domain/devices/disk.
10191 * The @base parameter can be either a path to a file within the backing
10192 * chain, or the device target shorthand (the <target dev='...'/>
10193 * sub-element, such as "vda") followed by an index to the backing chain
10194 * enclosed in square brackets. Backing chain indexes can be found by
10195 * inspecting //disk//backingStore/@index in the domain XML. Thus, for
10196 * example, "vda[3]" refers to the backing store with index equal to "3"
10197 * in the chain of disk "vda".
10199 * The maximum bandwidth that will be used to do the copy can be
10200 * specified with the @bandwidth parameter. If set to 0, there is no
10201 * limit. If @flags includes VIR_DOMAIN_BLOCK_REBASE_BANDWIDTH_BYTES,
10202 * @bandwidth is in bytes/second; otherwise, it is in MiB/second.
10203 * Values larger than 2^52 bytes/sec may be rejected due to overflow
10204 * considerations based on the word size of both client and server,
10205 * and values larger than 2^31 bytes/sec may cause overflow problems
10206 * if later queried by virDomainGetBlockJobInfo() without scaling.
10207 * Hypervisors may further restrict the range of valid bandwidth
10208 * values. Some hypervisors do not support this feature and will
10209 * return an error if bandwidth is not 0; in this case, it might still
10210 * be possible for a later call to virDomainBlockJobSetSpeed() to
10211 * succeed. The actual speed can be determined with
10212 * virDomainGetBlockJobInfo().
10214 * When @base is NULL and @flags is 0, this is identical to
10215 * virDomainBlockPull(). When @flags contains VIR_DOMAIN_BLOCK_REBASE_COPY,
10216 * this command is shorthand for virDomainBlockCopy() where the destination
10217 * XML encodes @base as a <disk type='file'>, @bandwidth is properly scaled
10218 * and passed as a typed parameter, the shallow and reuse external flags
10219 * are preserved, and remaining flags control whether the XML encodes a
10220 * destination format of raw instead of leaving the destination identical
10221 * to the source format or probed from the reused file.
10223 * Returns 0 if the operation has started, -1 on failure.
10226 virDomainBlockRebase(virDomainPtr dom, const char *disk,
10227 const char *base, unsigned long bandwidth,
10228 unsigned int flags)
10230 virConnectPtr conn;
10232 VIR_DOMAIN_DEBUG(dom, "disk=%s, base=%s, bandwidth=%lu, flags=0x%x",
10233 disk, NULLSTR(base), bandwidth, flags);
10235 virResetLastError();
10237 virCheckDomainReturn(dom, -1);
10238 conn = dom->conn;
10240 virCheckReadOnlyGoto(conn->flags, error);
10241 virCheckNonNullArgGoto(disk, error);
10243 if (flags & VIR_DOMAIN_BLOCK_REBASE_COPY) {
10244 virCheckNonNullArgGoto(base, error);
10245 } else if (flags & (VIR_DOMAIN_BLOCK_REBASE_SHALLOW |
10246 VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT |
10247 VIR_DOMAIN_BLOCK_REBASE_COPY_RAW |
10248 VIR_DOMAIN_BLOCK_REBASE_COPY_DEV)) {
10249 virReportInvalidArg(flags, "%s",
10250 _("use of flags requires a copy job"));
10251 goto error;
10254 if (conn->driver->domainBlockRebase) {
10255 int ret;
10256 ret = conn->driver->domainBlockRebase(dom, disk, base, bandwidth,
10257 flags);
10258 if (ret < 0)
10259 goto error;
10260 return ret;
10263 virReportUnsupportedError();
10265 error:
10266 virDispatchError(dom->conn);
10267 return -1;
10272 * virDomainBlockCopy:
10273 * @dom: pointer to domain object
10274 * @disk: path to the block device, or device shorthand
10275 * @destxml: XML description of the copy destination
10276 * @params: Pointer to block copy parameter objects, or NULL
10277 * @nparams: Number of block copy parameters (this value can be the same or
10278 * less than the number of parameters supported)
10279 * @flags: bitwise-OR of virDomainBlockCopyFlags
10281 * Copy the guest-visible contents of a disk image to a new file described
10282 * by @destxml. The destination XML has a top-level element of <disk>, and
10283 * resembles what is used when hot-plugging a disk via virDomainAttachDevice(),
10284 * except that only sub-elements related to describing the new host resource
10285 * are necessary (sub-elements related to the guest view, such as <target>,
10286 * are ignored). It is strongly recommended to include a <driver type='...'/>
10287 * format designation for the destination, to avoid the potential of any
10288 * security problem that might be caused by probing a file for its format.
10290 * This command starts a long-running copy. By default, the copy will pull
10291 * the entire source chain into the destination file, but if @flags also
10292 * contains VIR_DOMAIN_BLOCK_COPY_SHALLOW, then only the top of the source
10293 * chain will be copied (the source and destination have a common backing
10294 * file). The format of the destination file is controlled by the <driver>
10295 * sub-element of the XML. The destination will be created unless the
10296 * VIR_DOMAIN_BLOCK_COPY_REUSE_EXT flag is present stating that the file
10297 * was pre-created with the correct format and metadata and sufficient
10298 * size to hold the copy. In case the VIR_DOMAIN_BLOCK_COPY_SHALLOW flag
10299 * is used the pre-created file has to exhibit the same guest visible contents
10300 * as the backing file of the original image. This allows a management app to
10301 * pre-create files with relative backing file names, rather than the default
10302 * of absolute backing file names.
10304 * A copy job has two parts; in the first phase, the source is copied into
10305 * the destination, and the job can only be canceled by reverting to the
10306 * source file; progress in this phase can be tracked via the
10307 * virDomainBlockJobInfo() command, with a job type of
10308 * VIR_DOMAIN_BLOCK_JOB_TYPE_COPY. The job transitions to the second
10309 * phase when the block job event with state VIR_DOMAIN_BLOCK_JOB_READY is
10310 * emitted for the given device. This information is also visible in the
10311 * live XML as 'ready="yes"' attribute of the corresponding <mirror> element.
10312 * All further changes are saved to both source and destination. The user must
10313 * call virDomainBlockJobAbort() to end the mirroring while choosing
10314 * whether to revert to source or pivot to the destination. An event is
10315 * issued when the job ends, and depending on the hypervisor, an event may
10316 * also be issued when the job transitions from pulling to mirroring. If
10317 * the job is aborted, a new job will have to start over from the beginning
10318 * of the first phase.
10320 * Some hypervisors will restrict certain actions, such as virDomainSave()
10321 * or virDomainDetachDevice(), while a copy job is active; they may
10322 * also restrict a copy job to transient domains.
10324 * If @flags contains VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB the job will not be
10325 * recoverable if the VM is turned off while job is active. This flag will
10326 * remove the restriction of copy jobs to transient domains. Note that this flag
10327 * is automatically implied if the VM is transient at the time it's started.
10329 * The @disk parameter is either an unambiguous source name of the
10330 * block device (the <source file='...'/> sub-element, such as
10331 * "/path/to/image"), or the device target shorthand (the
10332 * <target dev='...'/> sub-element, such as "vda"). Valid names
10333 * can be found by calling virDomainGetXMLDesc() and inspecting
10334 * elements within //domain/devices/disk.
10336 * The @params and @nparams arguments can be used to set hypervisor-specific
10337 * tuning parameters, such as maximum bandwidth or granularity. For a
10338 * parameter that the hypervisor understands, explicitly specifying 0
10339 * behaves the same as omitting the parameter, to use the hypervisor
10340 * default; however, omitting a parameter is less likely to fail.
10342 * This command is a superset of the older virDomainBlockRebase() when used
10343 * with the VIR_DOMAIN_BLOCK_REBASE_COPY flag, and offers better control
10344 * over the destination format, the ability to copy to a destination that
10345 * is not a local file, and the possibility of additional tuning parameters.
10347 * Returns 0 if the operation has started, -1 on failure.
10350 virDomainBlockCopy(virDomainPtr dom, const char *disk,
10351 const char *destxml,
10352 virTypedParameterPtr params,
10353 int nparams,
10354 unsigned int flags)
10356 virConnectPtr conn;
10358 VIR_DOMAIN_DEBUG(dom,
10359 "disk=%s, destxml=%s, params=%p, nparams=%d, flags=0x%x",
10360 disk, destxml, params, nparams, flags);
10361 VIR_TYPED_PARAMS_DEBUG(params, nparams);
10363 virResetLastError();
10365 virCheckDomainReturn(dom, -1);
10366 conn = dom->conn;
10368 virCheckReadOnlyGoto(conn->flags, error);
10369 virCheckNonNullArgGoto(disk, error);
10370 virCheckNonNullArgGoto(destxml, error);
10371 virCheckNonNegativeArgGoto(nparams, error);
10372 if (nparams)
10373 virCheckNonNullArgGoto(params, error);
10375 if (conn->driver->domainBlockCopy) {
10376 int ret;
10377 ret = conn->driver->domainBlockCopy(dom, disk, destxml,
10378 params, nparams, flags);
10379 if (ret < 0)
10380 goto error;
10381 return ret;
10384 virReportUnsupportedError();
10386 error:
10387 virDispatchError(dom->conn);
10388 return -1;
10393 * virDomainBlockCommit:
10394 * @dom: pointer to domain object
10395 * @disk: path to the block device, or device shorthand
10396 * @base: path to backing file to merge into, or device shorthand,
10397 * or NULL for default
10398 * @top: path to file within backing chain that contains data to be merged,
10399 * or device shorthand, or NULL to merge all possible data
10400 * @bandwidth: (optional) specify bandwidth limit; flags determine the unit
10401 * @flags: bitwise-OR of virDomainBlockCommitFlags
10403 * Commit changes that were made to temporary top-level files within a disk
10404 * image backing file chain into a lower-level base file. In other words,
10405 * take all the difference between @base and @top, and update @base to contain
10406 * that difference; after the commit, any portion of the chain that previously
10407 * depended on @top will now depend on @base, and all files after @base up
10408 * to and including @top will now be invalidated. A typical use of this
10409 * command is to reduce the length of a backing file chain after taking an
10410 * external disk snapshot. To move data in the opposite direction, see
10411 * virDomainBlockPull().
10413 * This command starts a long-running commit block job, whose status may
10414 * be tracked by virDomainBlockJobInfo() with a job type of
10415 * VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT, and the operation can be aborted with
10416 * virDomainBlockJobAbort(). When finished, an asynchronous event is
10417 * raised to indicate the final status, and the job no longer exists. If
10418 * the job is aborted, it is up to the hypervisor whether starting a new
10419 * job will resume from the same point, or start over.
10421 * As a special case, if @top is the active image (or NULL), and @flags
10422 * includes VIR_DOMAIN_BLOCK_COMMIT_ACTIVE, the block job will have a type
10423 * of VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT, and operates in two phases.
10424 * In the first phase, the contents are being committed into @base, and the
10425 * job can only be canceled. The job transitions to the second phase when
10426 * the block job event with state VIR_DOMAIN_BLOCK_JOB_READY is
10427 * emitted for the given device. This information is also visible in the
10428 * live XML as 'ready="yes"' attribute of the corresponding <mirror> element.
10429 * Once in the second phase, the user must choose whether to cancel the job
10430 * (keeping @top as the active image, but now containing only the changes
10431 * since the time the job ended) or to pivot the job (adjusting to @base as
10432 * the active image, and invalidating @top).
10434 * Be aware that this command may invalidate files even if it is aborted;
10435 * the user is cautioned against relying on the contents of invalidated
10436 * intermediate files such as @top (when @top is not the active image)
10437 * without manually rebasing those files to use a backing file of a
10438 * read-only copy of @base prior to the point where the commit operation
10439 * was started (and such a rebase cannot be safely done until the commit
10440 * has successfully completed). However, the domain itself will not have
10441 * any issues; the active layer remains valid throughout the entire commit
10442 * operation.
10444 * Some hypervisors may support a shortcut where if @flags contains
10445 * VIR_DOMAIN_BLOCK_COMMIT_DELETE, then this command will unlink all files
10446 * that were invalidated, after the commit successfully completes.
10448 * If @flags contains VIR_DOMAIN_BLOCK_COMMIT_RELATIVE, the name recorded
10449 * into the overlay of the @top image (if there is such image) as the
10450 * path to the new backing file will be kept relative to other images.
10451 * The operation will fail if libvirt can't infer the name.
10453 * By default, if @base is NULL, the commit target will be the bottom of
10454 * the backing chain; if @flags contains VIR_DOMAIN_BLOCK_COMMIT_SHALLOW,
10455 * then the immediate backing file of @top will be used instead. If @top
10456 * is NULL, the active image at the top of the chain will be used. Some
10457 * hypervisors place restrictions on how much can be committed, and might
10458 * fail if @base is not the immediate backing file of @top, or if @top is
10459 * the active layer in use by a running domain but @flags did not include
10460 * VIR_DOMAIN_BLOCK_COMMIT_ACTIVE, or if @top is not the top-most file;
10461 * restrictions may differ for online vs. offline domains.
10463 * The @disk parameter is either an unambiguous source name of the
10464 * block device (the <source file='...'/> sub-element, such as
10465 * "/path/to/image"), or the device target shorthand (the
10466 * <target dev='...'/> sub-element, such as "vda"). Valid names
10467 * can be found by calling virDomainGetXMLDesc() and inspecting
10468 * elements within //domain/devices/disk.
10470 * The @base and @top parameters can be either paths to files within the
10471 * backing chain, or the device target shorthand (the <target dev='...'/>
10472 * sub-element, such as "vda") followed by an index to the backing chain
10473 * enclosed in square brackets. Backing chain indexes can be found by
10474 * inspecting //disk//backingStore/@index in the domain XML. Thus, for
10475 * example, "vda[3]" refers to the backing store with index equal to "3"
10476 * in the chain of disk "vda".
10478 * The maximum bandwidth that will be used to do the commit can be
10479 * specified with the @bandwidth parameter. If set to 0, there is no
10480 * limit. If @flags includes VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES,
10481 * @bandwidth is in bytes/second; otherwise, it is in MiB/second.
10482 * Values larger than 2^52 bytes/sec may be rejected due to overflow
10483 * considerations based on the word size of both client and server,
10484 * and values larger than 2^31 bytes/sec may cause overflow problems
10485 * if later queried by virDomainGetBlockJobInfo() without scaling.
10486 * Hypervisors may further restrict the range of valid bandwidth
10487 * values. Some hypervisors do not support this feature and will
10488 * return an error if bandwidth is not 0; in this case, it might still
10489 * be possible for a later call to virDomainBlockJobSetSpeed() to
10490 * succeed. The actual speed can be determined with
10491 * virDomainGetBlockJobInfo().
10493 * Returns 0 if the operation has started, -1 on failure.
10496 virDomainBlockCommit(virDomainPtr dom, const char *disk,
10497 const char *base, const char *top,
10498 unsigned long bandwidth, unsigned int flags)
10500 virConnectPtr conn;
10502 VIR_DOMAIN_DEBUG(dom, "disk=%s, base=%s, top=%s, bandwidth=%lu, flags=0x%x",
10503 disk, NULLSTR(base), NULLSTR(top), bandwidth, flags);
10505 virResetLastError();
10507 virCheckDomainReturn(dom, -1);
10508 conn = dom->conn;
10510 virCheckReadOnlyGoto(conn->flags, error);
10511 virCheckNonNullArgGoto(disk, error);
10513 if (conn->driver->domainBlockCommit) {
10514 int ret;
10515 ret = conn->driver->domainBlockCommit(dom, disk, base, top, bandwidth,
10516 flags);
10517 if (ret < 0)
10518 goto error;
10519 return ret;
10522 virReportUnsupportedError();
10524 error:
10525 virDispatchError(dom->conn);
10526 return -1;
10531 * virDomainOpenGraphics:
10532 * @dom: pointer to domain object
10533 * @idx: index of graphics config to open
10534 * @fd: file descriptor to attach graphics to
10535 * @flags: bitwise-OR of virDomainOpenGraphicsFlags
10537 * This will attempt to connect the file descriptor @fd, to
10538 * the graphics backend of @dom. If @dom has multiple graphics
10539 * backends configured, then @idx will determine which one is
10540 * opened, starting from @idx 0.
10542 * To disable any authentication, pass the VIR_DOMAIN_OPEN_GRAPHICS_SKIPAUTH
10543 * constant for @flags.
10545 * The caller should use an anonymous socketpair to open
10546 * @fd before invocation.
10548 * This method can only be used when connected to a local
10549 * libvirt hypervisor, over a UNIX domain socket. Attempts
10550 * to use this method over a TCP connection will always fail
10552 * Returns 0 on success, -1 on failure
10555 virDomainOpenGraphics(virDomainPtr dom,
10556 unsigned int idx,
10557 int fd,
10558 unsigned int flags)
10560 struct stat sb;
10561 VIR_DOMAIN_DEBUG(dom, "idx=%u, fd=%d, flags=0x%x",
10562 idx, fd, flags);
10564 virResetLastError();
10566 virCheckDomainReturn(dom, -1);
10567 virCheckNonNegativeArgGoto(fd, error);
10569 if (fstat(fd, &sb) < 0) {
10570 virReportSystemError(errno,
10571 _("Unable to access file descriptor %d"), fd);
10572 goto error;
10575 if (!S_ISSOCK(sb.st_mode)) {
10576 virReportInvalidArg(fd,
10577 _("fd %d must be a socket"),
10578 fd);
10579 goto error;
10582 virCheckReadOnlyGoto(dom->conn->flags, error);
10584 if (!VIR_DRV_SUPPORTS_FEATURE(dom->conn->driver, dom->conn,
10585 VIR_DRV_FEATURE_FD_PASSING)) {
10586 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
10587 _("fd passing is not supported by this connection"));
10588 goto error;
10591 if (dom->conn->driver->domainOpenGraphics) {
10592 int ret;
10593 ret = dom->conn->driver->domainOpenGraphics(dom, idx, fd, flags);
10594 if (ret < 0)
10595 goto error;
10596 return ret;
10599 virReportUnsupportedError();
10601 error:
10602 virDispatchError(dom->conn);
10603 return -1;
10608 * virDomainOpenGraphicsFD:
10609 * @dom: pointer to domain object
10610 * @idx: index of graphics config to open
10611 * @flags: bitwise-OR of virDomainOpenGraphicsFlags
10613 * This will create a socket pair connected to the graphics backend of @dom.
10614 * One end of the socket will be returned on success, and the other end is
10615 * handed to the hypervisor.
10616 * If @dom has multiple graphics backends configured, then @idx will determine
10617 * which one is opened, starting from @idx 0.
10619 * To disable any authentication, pass the VIR_DOMAIN_OPEN_GRAPHICS_SKIPAUTH
10620 * constant for @flags.
10622 * This method can only be used when connected to a local
10623 * libvirt hypervisor, over a UNIX domain socket. Attempts
10624 * to use this method over a TCP connection will always fail.
10626 * Returns an fd on success, -1 on failure
10629 virDomainOpenGraphicsFD(virDomainPtr dom,
10630 unsigned int idx,
10631 unsigned int flags)
10633 VIR_DOMAIN_DEBUG(dom, "idx=%u, flags=0x%x", idx, flags);
10635 virResetLastError();
10637 virCheckDomainReturn(dom, -1);
10639 virCheckReadOnlyGoto(dom->conn->flags, error);
10641 if (!VIR_DRV_SUPPORTS_FEATURE(dom->conn->driver, dom->conn,
10642 VIR_DRV_FEATURE_FD_PASSING)) {
10643 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
10644 _("fd passing is not supported by this connection"));
10645 goto error;
10648 if (dom->conn->driver->domainOpenGraphicsFD) {
10649 int ret;
10650 ret = dom->conn->driver->domainOpenGraphicsFD(dom, idx, flags);
10651 if (ret < 0)
10652 goto error;
10653 return ret;
10656 virReportUnsupportedError();
10658 error:
10659 virDispatchError(dom->conn);
10660 return -1;
10665 * virDomainSetBlockIoTune:
10666 * @dom: pointer to domain object
10667 * @disk: path to the block device, or device shorthand
10668 * @params: Pointer to blkio parameter objects
10669 * @nparams: Number of blkio parameters (this value can be the same or
10670 * less than the number of parameters supported)
10671 * @flags: bitwise-OR of virDomainModificationImpact
10673 * Change all or a subset of the per-device block IO tunables.
10675 * The @disk parameter is either an unambiguous source name of the
10676 * block device (the <source file='...'/> sub-element, such as
10677 * "/path/to/image"), or the device target shorthand (the <target
10678 * dev='...'/> sub-element, such as "xvda"). Valid names can be found
10679 * by calling virDomainGetXMLDesc() and inspecting elements
10680 * within //domain/devices/disk.
10682 * Returns -1 in case of error, 0 in case of success.
10685 virDomainSetBlockIoTune(virDomainPtr dom,
10686 const char *disk,
10687 virTypedParameterPtr params,
10688 int nparams,
10689 unsigned int flags)
10691 virConnectPtr conn;
10693 VIR_DOMAIN_DEBUG(dom, "disk=%s, params=%p, nparams=%d, flags=0x%x",
10694 disk, params, nparams, flags);
10695 VIR_TYPED_PARAMS_DEBUG(params, nparams);
10697 virResetLastError();
10699 virCheckDomainReturn(dom, -1);
10700 conn = dom->conn;
10702 virCheckReadOnlyGoto(conn->flags, error);
10703 virCheckNonNullArgGoto(disk, error);
10704 virCheckPositiveArgGoto(nparams, error);
10705 virCheckNonNullArgGoto(params, error);
10707 if (virTypedParameterValidateSet(dom->conn, params, nparams) < 0)
10708 goto error;
10710 if (conn->driver->domainSetBlockIoTune) {
10711 int ret;
10712 ret = conn->driver->domainSetBlockIoTune(dom, disk, params, nparams, flags);
10713 if (ret < 0)
10714 goto error;
10715 return ret;
10718 virReportUnsupportedError();
10720 error:
10721 virDispatchError(dom->conn);
10722 return -1;
10727 * virDomainGetBlockIoTune:
10728 * @dom: pointer to domain object
10729 * @disk: path to the block device, or device shorthand
10730 * @params: Pointer to blkio parameter object
10731 * (return value, allocated by the caller)
10732 * @nparams: Pointer to number of blkio parameters
10733 * @flags: bitwise-OR of virDomainModificationImpact and virTypedParameterFlags
10735 * Get all block IO tunable parameters for a given device. On input,
10736 * @nparams gives the size of the @params array; on output, @nparams
10737 * gives how many slots were filled with parameter information, which
10738 * might be less but will not exceed the input value.
10740 * As a special case, calling with @params as NULL and @nparams as 0
10741 * on input will cause @nparams on output to contain the number of
10742 * parameters supported by the hypervisor, either for the given @disk
10743 * (note that block devices of different types might support different
10744 * parameters), or if @disk is NULL, for all possible disks. The
10745 * caller should then allocate @params array,
10746 * i.e. (sizeof(@virTypedParameter) * @nparams) bytes and call the API
10747 * again. See virDomainGetMemoryParameters() for more details.
10749 * The @disk parameter is either an unambiguous source name of the
10750 * block device (the <source file='...'/> sub-element, such as
10751 * "/path/to/image"), or the device target shorthand (the <target
10752 * dev='...'/> sub-element, such as "xvda"). Valid names can be found
10753 * by calling virDomainGetXMLDesc() and inspecting elements
10754 * within //domain/devices/disk. This parameter cannot be NULL
10755 * unless @nparams is 0 on input.
10757 * Returns -1 in case of error, 0 in case of success.
10760 virDomainGetBlockIoTune(virDomainPtr dom,
10761 const char *disk,
10762 virTypedParameterPtr params,
10763 int *nparams,
10764 unsigned int flags)
10766 virConnectPtr conn;
10768 VIR_DOMAIN_DEBUG(dom, "disk=%s, params=%p, nparams=%d, flags=0x%x",
10769 NULLSTR(disk), params, (nparams) ? *nparams : -1, flags);
10771 virResetLastError();
10773 virCheckDomainReturn(dom, -1);
10775 virCheckNonNullArgGoto(nparams, error);
10776 virCheckNonNegativeArgGoto(*nparams, error);
10777 if (*nparams != 0) {
10778 virCheckNonNullArgGoto(params, error);
10779 virCheckNonNullArgGoto(disk, error);
10782 if (VIR_DRV_SUPPORTS_FEATURE(dom->conn->driver, dom->conn,
10783 VIR_DRV_FEATURE_TYPED_PARAM_STRING))
10784 flags |= VIR_TYPED_PARAM_STRING_OKAY;
10786 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_AFFECT_LIVE,
10787 VIR_DOMAIN_AFFECT_CONFIG,
10788 error);
10790 conn = dom->conn;
10792 if (conn->driver->domainGetBlockIoTune) {
10793 int ret;
10794 ret = conn->driver->domainGetBlockIoTune(dom, disk, params, nparams, flags);
10795 if (ret < 0)
10796 goto error;
10797 return ret;
10800 virReportUnsupportedError();
10802 error:
10803 virDispatchError(dom->conn);
10804 return -1;
10809 * virDomainGetCPUStats:
10810 * @domain: domain to query
10811 * @params: array to populate on output
10812 * @nparams: number of parameters per cpu
10813 * @start_cpu: which cpu to start with, or -1 for summary
10814 * @ncpus: how many cpus to query
10815 * @flags: bitwise-OR of virTypedParameterFlags
10817 * Get statistics relating to CPU usage attributable to a single
10818 * domain (in contrast to the statistics returned by
10819 * virNodeGetCPUStats() for all processes on the host). @dom
10820 * must be running (an inactive domain has no attributable cpu
10821 * usage). On input, @params must contain at least @nparams * @ncpus
10822 * entries, allocated by the caller.
10824 * If @start_cpu is -1, then @ncpus must be 1, and the returned
10825 * results reflect the statistics attributable to the entire
10826 * domain (such as user and system time for the process as a
10827 * whole). Otherwise, @start_cpu represents which cpu to start
10828 * with, and @ncpus represents how many consecutive processors to
10829 * query, with statistics attributable per processor (such as
10830 * per-cpu usage). If @ncpus is larger than the number of cpus
10831 * available to query, then the trailing part of the array will
10832 * be unpopulated.
10834 * The remote driver imposes a limit of 128 @ncpus and 16 @nparams;
10835 * the number of parameters per cpu should not exceed 16, but if you
10836 * have a host with more than 128 CPUs, your program should split
10837 * the request into multiple calls.
10839 * As special cases, if @params is NULL and @nparams is 0 and
10840 * @ncpus is 1, and the return value will be how many
10841 * statistics are available for the given @start_cpu. This number
10842 * may be different for @start_cpu of -1 than for any non-negative
10843 * value, but will be the same for all non-negative @start_cpu.
10844 * Likewise, if @params is NULL and @nparams is 0 and @ncpus is 0,
10845 * the number of cpus available to query is returned. From the
10846 * host perspective, this would typically match the cpus member
10847 * of virNodeGetInfo(), but might be less due to host cpu hotplug.
10849 * For now, @flags is unused, and the statistics all relate to the
10850 * usage from the host perspective. It is possible that a future
10851 * version will support a flag that queries the cpu usage from the
10852 * guest's perspective, where the maximum cpu to query would be
10853 * related to virDomainGetVcpusFlags() rather than virNodeGetInfo().
10854 * An individual guest vcpu cannot be reliably mapped back to a
10855 * specific host cpu unless a single-processor vcpu pinning was used,
10856 * but when @start_cpu is -1, any difference in usage between a host
10857 * and guest perspective would serve as a measure of hypervisor overhead.
10859 * Typical use sequence is below.
10861 * getting total stats: set start_cpu as -1, ncpus 1
10863 * virDomainGetCPUStats(dom, NULL, 0, -1, 1, 0); // nparams
10864 * params = calloc(nparams, sizeof(virTypedParameter))
10865 * virDomainGetCPUStats(dom, params, nparams, -1, 1, 0); // total stats.
10867 * getting per-cpu stats:
10869 * virDomainGetCPUStats(dom, NULL, 0, 0, 0, 0); // ncpus
10870 * virDomainGetCPUStats(dom, NULL, 0, 0, 1, 0); // nparams
10871 * params = calloc(ncpus * nparams, sizeof(virTypedParameter));
10872 * virDomainGetCPUStats(dom, params, nparams, 0, ncpus, 0); // per-cpu stats
10874 * Returns -1 on failure, or the number of statistics that were
10875 * populated per cpu on success (this will be less than the total
10876 * number of populated @params, unless @ncpus was 1; and may be
10877 * less than @nparams). The populated parameters start at each
10878 * stride of @nparams, which means the results may be discontiguous;
10879 * any unpopulated parameters will be zeroed on success (this includes
10880 * skipped elements if @nparams is too large, and tail elements if
10881 * @ncpus is too large). The caller is responsible for freeing any
10882 * returned string parameters.
10885 virDomainGetCPUStats(virDomainPtr domain,
10886 virTypedParameterPtr params,
10887 unsigned int nparams,
10888 int start_cpu,
10889 unsigned int ncpus,
10890 unsigned int flags)
10892 virConnectPtr conn;
10894 VIR_DOMAIN_DEBUG(domain,
10895 "params=%p, nparams=%d, start_cpu=%d, ncpus=%u, flags=0x%x",
10896 params, nparams, start_cpu, ncpus, flags);
10897 virResetLastError();
10899 virCheckDomainReturn(domain, -1);
10900 conn = domain->conn;
10902 /* Special cases:
10903 * start_cpu must be non-negative, or else -1
10904 * if start_cpu is -1, ncpus must be 1
10905 * params == NULL must match nparams == 0
10906 * ncpus must be non-zero unless params == NULL
10907 * nparams * ncpus must not overflow (RPC may restrict it even more)
10909 if (start_cpu == -1) {
10910 if (ncpus != 1) {
10911 virReportInvalidArg(start_cpu, "%s",
10912 _("ncpus must be 1 when start_cpu is -1"));
10913 goto error;
10915 } else {
10916 virCheckNonNegativeArgGoto(start_cpu, error);
10918 if (nparams)
10919 virCheckNonNullArgGoto(params, error);
10920 else
10921 virCheckNullArgGoto(params, error);
10922 if (ncpus == 0)
10923 virCheckNullArgGoto(params, error);
10925 if (nparams && ncpus > UINT_MAX / nparams) {
10926 virReportError(VIR_ERR_OVERFLOW, _("input too large: %u * %u"),
10927 nparams, ncpus);
10928 goto error;
10930 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
10931 VIR_DRV_FEATURE_TYPED_PARAM_STRING))
10932 flags |= VIR_TYPED_PARAM_STRING_OKAY;
10934 if (conn->driver->domainGetCPUStats) {
10935 int ret;
10937 ret = conn->driver->domainGetCPUStats(domain, params, nparams,
10938 start_cpu, ncpus, flags);
10939 if (ret < 0)
10940 goto error;
10941 return ret;
10944 virReportUnsupportedError();
10946 error:
10947 virDispatchError(domain->conn);
10948 return -1;
10953 * virDomainGetDiskErrors:
10954 * @dom: a domain object
10955 * @errors: array to populate on output
10956 * @maxerrors: size of @errors array
10957 * @flags: extra flags; not used yet, so callers should always pass 0
10959 * The function populates @errors array with all disks that encountered an
10960 * I/O error. Disks with no error will not be returned in the @errors array.
10961 * Each disk is identified by its target (the dev attribute of target
10962 * subelement in domain XML), such as "vda", and accompanied with the error
10963 * that was seen on it. The caller is also responsible for calling free()
10964 * on each disk name returned.
10966 * In a special case when @errors is NULL and @maxerrors is 0, the function
10967 * returns preferred size of @errors that the caller should use to get all
10968 * disk errors.
10970 * Since calling virDomainGetDiskErrors(dom, NULL, 0, 0) to get preferred size
10971 * of @errors array and getting the errors are two separate operations, new
10972 * disks may be hotplugged to the domain and new errors may be encountered
10973 * between the two calls. Thus, this function may not return all disk errors
10974 * because the supplied array is not large enough. Such errors may, however,
10975 * be detected by listening to domain events.
10977 * Returns number of disks with errors filled in the @errors array or -1 on
10978 * error.
10981 virDomainGetDiskErrors(virDomainPtr dom,
10982 virDomainDiskErrorPtr errors,
10983 unsigned int maxerrors,
10984 unsigned int flags)
10986 VIR_DOMAIN_DEBUG(dom, "errors=%p, maxerrors=%u, flags=0x%x",
10987 errors, maxerrors, flags);
10989 virResetLastError();
10991 virCheckDomainReturn(dom, -1);
10993 if (maxerrors)
10994 virCheckNonNullArgGoto(errors, error);
10995 else
10996 virCheckNullArgGoto(errors, error);
10998 if (dom->conn->driver->domainGetDiskErrors) {
10999 int ret = dom->conn->driver->domainGetDiskErrors(dom, errors,
11000 maxerrors, flags);
11001 if (ret < 0)
11002 goto error;
11003 return ret;
11006 virReportUnsupportedError();
11008 error:
11009 virDispatchError(dom->conn);
11010 return -1;
11015 * virDomainGetHostname:
11016 * @domain: a domain object
11017 * @flags: extra flags; not used yet, so callers should always pass 0
11019 * Get the hostname for that domain.
11021 * Dependent on hypervisor used, this may require a guest agent to be
11022 * available.
11024 * Returns the hostname which must be freed by the caller, or
11025 * NULL if there was an error.
11027 char *
11028 virDomainGetHostname(virDomainPtr domain, unsigned int flags)
11030 virConnectPtr conn;
11032 VIR_DOMAIN_DEBUG(domain, "flags=0x%x", flags);
11034 virResetLastError();
11036 virCheckDomainReturn(domain, NULL);
11037 conn = domain->conn;
11039 virCheckReadOnlyGoto(domain->conn->flags, error);
11041 if (conn->driver->domainGetHostname) {
11042 char *ret;
11043 ret = conn->driver->domainGetHostname(domain, flags);
11044 if (!ret)
11045 goto error;
11046 return ret;
11049 virReportUnsupportedError();
11051 error:
11052 virDispatchError(domain->conn);
11053 return NULL;
11058 * virDomainFSTrim:
11059 * @dom: a domain object
11060 * @mountPoint: which mount point to trim
11061 * @minimum: Minimum contiguous free range to discard in bytes
11062 * @flags: extra flags, not used yet, so callers should always pass 0
11064 * Calls FITRIM within the guest (hence guest agent may be
11065 * required depending on hypervisor used). Either call it on each
11066 * mounted filesystem (@mountPoint is NULL) or just on specified
11067 * @mountPoint. @minimum hints that free ranges smaller than this
11068 * may be ignored (this is a hint and the guest may not respect
11069 * it). By increasing this value, the fstrim operation will
11070 * complete more quickly for filesystems with badly fragmented
11071 * free space, although not all blocks will be discarded.
11072 * If @minimum is not zero, the command may fail.
11074 * Returns 0 on success, -1 otherwise.
11077 virDomainFSTrim(virDomainPtr dom,
11078 const char *mountPoint,
11079 unsigned long long minimum,
11080 unsigned int flags)
11082 VIR_DOMAIN_DEBUG(dom, "mountPoint=%s, minimum=%llu, flags=0x%x",
11083 mountPoint, minimum, flags);
11085 virResetLastError();
11087 virCheckDomainReturn(dom, -1);
11088 virCheckReadOnlyGoto(dom->conn->flags, error);
11090 if (dom->conn->driver->domainFSTrim) {
11091 int ret = dom->conn->driver->domainFSTrim(dom, mountPoint,
11092 minimum, flags);
11093 if (ret < 0)
11094 goto error;
11095 return ret;
11098 virReportUnsupportedError();
11100 error:
11101 virDispatchError(dom->conn);
11102 return -1;
11106 * virDomainFSFreeze:
11107 * @dom: a domain object
11108 * @mountpoints: list of mount points to be frozen
11109 * @nmountpoints: the number of mount points specified in @mountpoints
11110 * @flags: extra flags; not used yet, so callers should always pass 0
11112 * Freeze specified filesystems within the guest (hence guest agent
11113 * may be required depending on hypervisor used). If @mountpoints is NULL and
11114 * @nmountpoints is 0, every mounted filesystem on the guest is frozen.
11115 * In some environments (e.g. QEMU guest with guest agent which doesn't
11116 * support mountpoints argument), @mountpoints may need to be NULL.
11118 * Returns the number of frozen filesystems on success, -1 otherwise.
11121 virDomainFSFreeze(virDomainPtr dom,
11122 const char **mountpoints,
11123 unsigned int nmountpoints,
11124 unsigned int flags)
11126 VIR_DOMAIN_DEBUG(dom, "mountpoints=%p, nmountpoints=%d, flags=0x%x",
11127 mountpoints, nmountpoints, flags);
11129 virResetLastError();
11131 virCheckDomainReturn(dom, -1);
11132 virCheckReadOnlyGoto(dom->conn->flags, error);
11133 if (nmountpoints)
11134 virCheckNonNullArgGoto(mountpoints, error);
11135 else
11136 virCheckNullArgGoto(mountpoints, error);
11138 if (dom->conn->driver->domainFSFreeze) {
11139 int ret = dom->conn->driver->domainFSFreeze(
11140 dom, mountpoints, nmountpoints, flags);
11141 if (ret < 0)
11142 goto error;
11143 return ret;
11146 virReportUnsupportedError();
11148 error:
11149 virDispatchError(dom->conn);
11150 return -1;
11154 * virDomainFSThaw:
11155 * @dom: a domain object
11156 * @mountpoints: list of mount points to be thawed
11157 * @nmountpoints: the number of mount points specified in @mountpoints
11158 * @flags: extra flags; not used yet, so callers should always pass 0
11160 * Thaw specified filesystems within the guest. If @mountpoints is NULL and
11161 * @nmountpoints is 0, every mounted filesystem on the guest is thawed.
11162 * In some drivers (e.g. QEMU driver), @mountpoints may need to be NULL.
11164 * Returns the number of thawed filesystems on success, -1 otherwise.
11167 virDomainFSThaw(virDomainPtr dom,
11168 const char **mountpoints,
11169 unsigned int nmountpoints,
11170 unsigned int flags)
11172 VIR_DOMAIN_DEBUG(dom, "flags=0x%x", flags);
11174 virResetLastError();
11176 virCheckDomainReturn(dom, -1);
11177 virCheckReadOnlyGoto(dom->conn->flags, error);
11178 if (nmountpoints)
11179 virCheckNonNullArgGoto(mountpoints, error);
11180 else
11181 virCheckNullArgGoto(mountpoints, error);
11183 if (dom->conn->driver->domainFSThaw) {
11184 int ret = dom->conn->driver->domainFSThaw(
11185 dom, mountpoints, nmountpoints, flags);
11186 if (ret < 0)
11187 goto error;
11188 return ret;
11191 virReportUnsupportedError();
11193 error:
11194 virDispatchError(dom->conn);
11195 return -1;
11199 * virDomainGetTime:
11200 * @dom: a domain object
11201 * @seconds: domain's time in seconds
11202 * @nseconds: the nanosecond part of @seconds
11203 * @flags: extra flags; not used yet, so callers should always pass 0
11205 * Extract information about guest time and store it into
11206 * @seconds and @nseconds. The @seconds represents the number of
11207 * seconds since the UNIX Epoch of 1970-01-01 00:00:00 in UTC.
11209 * Please note that some hypervisors may require guest agent to
11210 * be configured and running in order to run this API.
11212 * Returns 0 on success, -1 otherwise.
11215 virDomainGetTime(virDomainPtr dom,
11216 long long *seconds,
11217 unsigned int *nseconds,
11218 unsigned int flags)
11220 VIR_DOMAIN_DEBUG(dom, "seconds=%p, nseconds=%p, flags=0x%x",
11221 seconds, nseconds, flags);
11223 virResetLastError();
11225 virCheckDomainReturn(dom, -1);
11226 virCheckReadOnlyGoto(dom->conn->flags, error);
11228 if (dom->conn->driver->domainGetTime) {
11229 int ret = dom->conn->driver->domainGetTime(dom, seconds,
11230 nseconds, flags);
11231 if (ret < 0)
11232 goto error;
11233 return ret;
11236 virReportUnsupportedError();
11238 error:
11239 virDispatchError(dom->conn);
11240 return -1;
11244 * virDomainSetTime:
11245 * @dom: a domain object
11246 * @seconds: time to set
11247 * @nseconds: the nanosecond part of @seconds
11248 * @flags: bitwise-OR of virDomainSetTimeFlags
11250 * When a domain is suspended or restored from a file the
11251 * domain's OS has no idea that there was a big gap in the time.
11252 * Depending on how long the gap was, NTP might not be able to
11253 * resynchronize the guest.
11255 * This API tries to set guest time to the given value. The time
11256 * to set (@seconds and @nseconds) should be in seconds relative
11257 * to the Epoch of 1970-01-01 00:00:00 in UTC.
11259 * Please note that some hypervisors may require guest agent to
11260 * be configured and running in order to be able to run this API.
11262 * Returns 0 on success, -1 otherwise.
11265 virDomainSetTime(virDomainPtr dom,
11266 long long seconds,
11267 unsigned int nseconds,
11268 unsigned int flags)
11270 VIR_DOMAIN_DEBUG(dom, "seconds=%lld, nseconds=%u, flags=0x%x",
11271 seconds, nseconds, flags);
11273 virResetLastError();
11275 virCheckDomainReturn(dom, -1);
11276 virCheckReadOnlyGoto(dom->conn->flags, error);
11278 if (dom->conn->driver->domainSetTime) {
11279 int ret = dom->conn->driver->domainSetTime(dom, seconds,
11280 nseconds, flags);
11281 if (ret < 0)
11282 goto error;
11283 return ret;
11286 virReportUnsupportedError();
11288 error:
11289 virDispatchError(dom->conn);
11290 return -1;
11295 * virDomainSetUserPassword:
11296 * @dom: a domain object
11297 * @user: the username that will get a new password
11298 * @password: the password to set
11299 * @flags: bitwise-OR of virDomainSetUserPasswordFlags
11301 * Sets the @user password to the value specified by @password.
11302 * If @flags contain VIR_DOMAIN_PASSWORD_ENCRYPTED, the password
11303 * is assumed to be encrypted by the method required by the guest OS.
11305 * Please note that some hypervisors may require guest agent to
11306 * be configured and running in order to be able to run this API.
11308 * Returns 0 on success, -1 otherwise.
11311 virDomainSetUserPassword(virDomainPtr dom,
11312 const char *user,
11313 const char *password,
11314 unsigned int flags)
11316 VIR_DOMAIN_DEBUG(dom, "user=%s, password=%s, flags=0x%x",
11317 NULLSTR(user), NULLSTR(password), flags);
11319 virResetLastError();
11321 virCheckDomainReturn(dom, -1);
11322 virCheckReadOnlyGoto(dom->conn->flags, error);
11323 virCheckNonNullArgGoto(user, error);
11324 virCheckNonNullArgGoto(password, error);
11326 if (dom->conn->driver->domainSetUserPassword) {
11327 int ret = dom->conn->driver->domainSetUserPassword(dom, user, password,
11328 flags);
11329 if (ret < 0)
11330 goto error;
11331 return ret;
11334 virReportUnsupportedError();
11336 error:
11337 virDispatchError(dom->conn);
11338 return -1;
11343 * virConnectGetDomainCapabilities:
11344 * @conn: pointer to the hypervisor connection
11345 * @emulatorbin: path to emulator
11346 * @arch: domain architecture
11347 * @machine: machine type
11348 * @virttype: virtualization type
11349 * @flags: extra flags; not used yet, so callers should always pass 0
11351 * Prior creating a domain (for instance via virDomainCreateXML
11352 * or virDomainDefineXML) it may be suitable to know what the
11353 * underlying emulator and/or libvirt is capable of. For
11354 * instance, if host, libvirt and qemu is capable of VFIO
11355 * passthrough and so on.
11357 * Returns NULL in case of error or an XML string
11358 * defining the capabilities.
11360 char *
11361 virConnectGetDomainCapabilities(virConnectPtr conn,
11362 const char *emulatorbin,
11363 const char *arch,
11364 const char *machine,
11365 const char *virttype,
11366 unsigned int flags)
11368 VIR_DEBUG("conn=%p, emulatorbin=%s, arch=%s, "
11369 "machine=%s, virttype=%s, flags=0x%x",
11370 conn, NULLSTR(emulatorbin), NULLSTR(arch),
11371 NULLSTR(machine), NULLSTR(virttype), flags);
11373 virResetLastError();
11375 virCheckConnectReturn(conn, NULL);
11377 if (conn->driver->connectGetDomainCapabilities) {
11378 char *ret;
11379 ret = conn->driver->connectGetDomainCapabilities(conn, emulatorbin,
11380 arch, machine,
11381 virttype, flags);
11382 if (!ret)
11383 goto error;
11384 VIR_DEBUG("conn=%p, ret=%s", conn, ret);
11385 return ret;
11388 virReportUnsupportedError();
11390 error:
11391 virDispatchError(conn);
11392 return NULL;
11397 * virConnectGetAllDomainStats:
11398 * @conn: pointer to the hypervisor connection
11399 * @stats: stats to return, binary-OR of virDomainStatsTypes
11400 * @retStats: Pointer that will be filled with the array of returned stats
11401 * @flags: extra flags; binary-OR of virConnectGetAllDomainStatsFlags
11403 * Query statistics for all domains on a given connection.
11405 * Report statistics of various parameters for a running VM according to @stats
11406 * field. The statistics are returned as an array of structures for each queried
11407 * domain. The structure contains an array of typed parameters containing the
11408 * individual statistics. The typed parameter name for each statistic field
11409 * consists of a dot-separated string containing name of the requested group
11410 * followed by a group specific description of the statistic value.
11412 * The statistic groups are enabled using the @stats parameter which is a
11413 * binary-OR of enum virDomainStatsTypes. The following groups are available
11414 * (although not necessarily implemented for each hypervisor):
11416 * VIR_DOMAIN_STATS_STATE:
11417 * Return domain state and reason for entering that state. The typed
11418 * parameter keys are in this format:
11420 * "state.state" - state of the VM, returned as int from virDomainState enum
11421 * "state.reason" - reason for entering given state, returned as int from
11422 * virDomain*Reason enum corresponding to given state.
11424 * VIR_DOMAIN_STATS_CPU_TOTAL:
11425 * Return CPU statistics and usage information. The typed parameter keys
11426 * are in this format:
11428 * "cpu.time" - total cpu time spent for this domain in nanoseconds
11429 * as unsigned long long.
11430 * "cpu.user" - user cpu time spent in nanoseconds as unsigned long long.
11431 * "cpu.system" - system cpu time spent in nanoseconds as unsigned long
11432 * long.
11433 * "cpu.cache.monitor.count" - the number of cache monitors for this domain
11434 * "cpu.cache.monitor.<num>.name" - the name of cache monitor <num>
11435 * "cpu.cache.monitor.<num>.vcpus" - vcpu list of cache monitor <num>
11436 * "cpu.cache.monitor.<num>.bank.count" - the number of cache banks in
11437 * cache monitor <num>
11438 * "cpu.cache.monitor.<num>.bank.<index>.id" - host allocated cache id for
11439 * bank <index> in cache
11440 * monitor <num>
11441 * "cpu.cache.monitor.<num>.bank.<index>.bytes" - the number of bytes of
11442 * last level cache that the
11443 * domain is using on cache
11444 * bank <index>
11446 * VIR_DOMAIN_STATS_BALLOON:
11447 * Return memory balloon device information.
11448 * The typed parameter keys are in this format:
11450 * "balloon.current" - the memory in kiB currently used
11451 * as unsigned long long.
11452 * "balloon.maximum" - the maximum memory in kiB allowed
11453 * as unsigned long long.
11455 * VIR_DOMAIN_STATS_VCPU:
11456 * Return virtual CPU statistics.
11457 * Due to VCPU hotplug, the vcpu.<num>.* array could be sparse.
11458 * The actual size of the array corresponds to "vcpu.current".
11459 * The array size will never exceed "vcpu.maximum".
11460 * The typed parameter keys are in this format:
11462 * "vcpu.current" - current number of online virtual CPUs as unsigned int.
11463 * "vcpu.maximum" - maximum number of online virtual CPUs as unsigned int.
11464 * "vcpu.<num>.state" - state of the virtual CPU <num>, as int
11465 * from virVcpuState enum.
11466 * "vcpu.<num>.time" - virtual cpu time spent by virtual CPU <num>
11467 * as unsigned long long.
11469 * VIR_DOMAIN_STATS_INTERFACE:
11470 * Return network interface statistics (from domain point of view).
11471 * The typed parameter keys are in this format:
11473 * "net.count" - number of network interfaces on this domain
11474 * as unsigned int.
11475 * "net.<num>.name" - name of the interface <num> as string.
11476 * "net.<num>.rx.bytes" - bytes received as unsigned long long.
11477 * "net.<num>.rx.pkts" - packets received as unsigned long long.
11478 * "net.<num>.rx.errs" - receive errors as unsigned long long.
11479 * "net.<num>.rx.drop" - receive packets dropped as unsigned long long.
11480 * "net.<num>.tx.bytes" - bytes transmitted as unsigned long long.
11481 * "net.<num>.tx.pkts" - packets transmitted as unsigned long long.
11482 * "net.<num>.tx.errs" - transmission errors as unsigned long long.
11483 * "net.<num>.tx.drop" - transmit packets dropped as unsigned long long.
11485 * VIR_DOMAIN_STATS_BLOCK:
11486 * Return block devices statistics. By default,
11487 * this information is limited to the active layer of each <disk> of the
11488 * domain (where block.count is equal to the number of disks), but adding
11489 * VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING to @flags will expand the
11490 * array to cover backing chains (block.count corresponds to the number
11491 * of host resources used together to provide the guest disks).
11492 * The typed parameter keys are in this format:
11494 * "block.count" - number of block devices in the subsequent list,
11495 * as unsigned int.
11496 * "block.<num>.name" - name of the block device <num> as string.
11497 * matches the target name (vda/sda/hda) of the
11498 * block device. If the backing chain is listed,
11499 * this name is the same for all host resources tied
11500 * to the same guest device.
11501 * "block.<num>.backingIndex" - unsigned int giving the <backingStore>
11502 * index, only used when backing images
11503 * are listed.
11504 * "block.<num>.path" - string describing the source of block device <num>,
11505 * if it is a file or block device (omitted for network
11506 * sources and drives with no media inserted).
11507 * "block.<num>.rd.reqs" - number of read requests as unsigned long long.
11508 * "block.<num>.rd.bytes" - number of read bytes as unsigned long long.
11509 * "block.<num>.rd.times" - total time (ns) spent on reads as
11510 * unsigned long long.
11511 * "block.<num>.wr.reqs" - number of write requests as unsigned long long.
11512 * "block.<num>.wr.bytes" - number of written bytes as unsigned long long.
11513 * "block.<num>.wr.times" - total time (ns) spent on writes as
11514 * unsigned long long.
11515 * "block.<num>.fl.reqs" - total flush requests as unsigned long long.
11516 * "block.<num>.fl.times" - total time (ns) spent on cache flushing as
11517 * unsigned long long.
11518 * "block.<num>.errors" - Xen only: the 'oo_req' value as
11519 * unsigned long long.
11520 * "block.<num>.allocation" - offset of the highest written sector
11521 * as unsigned long long.
11522 * "block.<num>.capacity" - logical size in bytes of the block device
11523 * backing image as unsigned long long.
11524 * "block.<num>.physical" - physical size in bytes of the container of the
11525 * backing image as unsigned long long.
11526 * "block.<num>.threshold" - current threshold for delivering the
11527 * VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD
11528 * event in bytes. See virDomainSetBlockThreshold.
11530 * VIR_DOMAIN_STATS_PERF:
11531 * Return perf event statistics.
11532 * The typed parameter keys are in this format:
11534 * "perf.cmt" - the usage of l3 cache (bytes) by applications running on
11535 * the platform as unsigned long long. It is produced by cmt
11536 * perf event.
11537 * "perf.mbmt" - the total system bandwidth (bytes/s) from one level of
11538 * cache to another as unsigned long long. It is produced
11539 * by mbmt perf event.
11540 * "perf.mbml" - the amount of data (bytes/s) sent through the memory
11541 * controller on the socket as unsigned long long. It is
11542 * produced by mbml perf event.
11543 * "perf.cache_misses" - the count of cache misses as unsigned long long.
11544 * It is produced by cache_misses perf event.
11545 * "perf.cache_references" - the count of cache hits as unsigned long long.
11546 * It is produced by cache_references perf event.
11547 * "perf.instructions" - The count of instructions as unsigned long long.
11548 * It is produced by instructions perf event.
11549 * "perf.cpu_cycles" - The count of cpu cycles (total/elapsed) as an
11550 * unsigned long long. It is produced by cpu_cycles
11551 * perf event.
11552 * "perf.branch_instructions" - The count of branch instructions as
11553 * unsigned long long. It is produced by
11554 * branch_instructions perf event.
11555 * "perf.branch_misses" - The count of branch misses as unsigned long
11556 * long. It is produced by branch_misses perf event.
11557 * "perf.bus_cycles" - The count of bus cycles as unsigned long
11558 * long. It is produced by bus_cycles perf event.
11559 * "perf.stalled_cycles_frontend" - The count of stalled cpu cycles in the
11560 * frontend of the instruction processor
11561 * pipeline as unsigned long long. It is
11562 * produced by stalled_cycles_frontend
11563 * perf event.
11564 * "perf.stalled_cycles_backend" - The count of stalled cpu cycles in the
11565 * backend of the instruction processor
11566 * pipeline as unsigned long long. It is
11567 * produced by stalled_cycles_backend
11568 * perf event.
11569 * "perf.ref_cpu_cycles" - The count of total cpu cycles not affected by
11570 * CPU frequency scaling by applications running
11571 * as unsigned long long. It is produced by the
11572 * ref_cpu_cycles perf event.
11573 * "perf.cpu_clock" - The count of cpu clock time as unsigned long long.
11574 * It is produced by the cpu_clock perf event.
11575 * "perf.task_clock" - The count of task clock time as unsigned long long.
11576 * It is produced by the task_clock perf event.
11577 * "perf.page_faults" - The count of page faults as unsigned long long.
11578 * It is produced by the page_faults perf event
11579 * "perf.context_switches" - The count of context switches as unsigned long
11580 * long. It is produced by the context_switches
11581 * perf event.
11582 * "perf.cpu_migrations" - The count of cpu migrations, from one logical
11583 * processor to another, as unsigned long
11584 * long. It is produced by the cpu_migrations
11585 * perf event.
11586 * "perf.page_faults_min" - The count of minor page faults as unsigned
11587 * long long. It is produced by the
11588 * page_faults_min perf event.
11589 * "perf.page_faults_maj" - The count of major page faults as unsigned
11590 * long long. It is produced by the
11591 * page_faults_maj perf event.
11592 * "perf.alignment_faults" - The count of alignment faults as unsigned
11593 * long long. It is produced by the
11594 * alignment_faults perf event
11595 * "perf.emulation_faults" - The count of emulation faults as unsigned
11596 * long long. It is produced by the
11597 * emulation_faults perf event
11599 * VIR_DOMAIN_STATS_IOTHREAD:
11600 * Return IOThread statistics if available. IOThread polling is a
11601 * timing mechanism that allows the hypervisor to generate a longer
11602 * period of time in which the guest will perform operations on the
11603 * CPU being used by the IOThread. The higher the value for poll-max-ns
11604 * the longer the guest will keep the CPU. This may affect other host
11605 * threads using the CPU. The poll-grow and poll-shrink values allow
11606 * the hypervisor to generate a mechanism to add or remove polling time
11607 * within the confines of 0 and poll-max-ns. For QEMU, the poll-grow is
11608 * multiplied by the polling interval, while poll-shrink is used as a
11609 * divisor. When not provided, QEMU may double the polling time until
11610 * poll-max-ns is reached. When poll-shrink is 0 (zero) QEMU may reset
11611 * the polling interval to 0 until it finds its "sweet spot". Setting
11612 * poll-grow too large may cause frequent fluctuation of the time; however,
11613 * this can be tempered by a high poll-shrink to reduce the polling
11614 * interval. For example, a poll-grow of 3 will triple the polling time
11615 * which could quickly exceed poll-max-ns; however, a poll-shrink of
11616 * 10 would cut that polling time more gradually.
11618 * The typed parameter keys are in this format:
11620 * "iothread.cnt" - maximum number of IOThreads in the subsequent list
11621 * as unsigned int. Each IOThread in the list will
11622 * will use it's iothread_id value as the <id>. There
11623 * may be fewer <id> entries than the iothread.cnt
11624 * value if the polling values are not supported.
11625 * "iothread.<id>.poll-max-ns" - maximum polling time in ns as an unsigned
11626 * long long. A 0 (zero) means polling is
11627 * disabled.
11628 * "iothread.<id>.poll-grow" - polling time factor as an unsigned int.
11629 * A 0 (zero) indicates to allow the underlying
11630 * hypervisor to choose how to grow the
11631 * polling time.
11632 * "iothread.<id>.poll-shrink" - polling time divisor as an unsigned int.
11633 * A 0 (zero) indicates to allow the underlying
11634 * hypervisor to choose how to shrink the
11635 * polling time.
11637 * Note that entire stats groups or individual stat fields may be missing from
11638 * the output in case they are not supported by the given hypervisor, are not
11639 * applicable for the current state of the guest domain, or their retrieval
11640 * was not successful.
11642 * Using 0 for @stats returns all stats groups supported by the given
11643 * hypervisor.
11645 * Specifying VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS as @flags makes
11646 * the function return error in case some of the stat types in @stats were
11647 * not recognized by the daemon. However, even with this flag, a hypervisor
11648 * may omit individual fields within a known group if the information is not
11649 * available; as an extreme example, a supported group may produce zero
11650 * fields for offline domains if the statistics are meaningful only for a
11651 * running domain.
11653 * Passing VIR_CONNECT_GET_ALL_DOMAINS_STATS_NOWAIT in
11654 * @flags means when libvirt is unable to fetch stats for any of
11655 * the domains (for whatever reason) only a subset of statistics
11656 * is returned for the domain. That subset being statistics that
11657 * don't involve querying the underlying hypervisor.
11659 * Similarly to virConnectListAllDomains, @flags can contain various flags to
11660 * filter the list of domains to provide stats for.
11662 * VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE selects online domains while
11663 * VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE selects offline ones.
11665 * VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT and
11666 * VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT allow to filter the list
11667 * according to their persistence.
11669 * To filter the list of VMs by domain state @flags can contain
11670 * VIR_CONNECT_GET_ALL_DOMAINS_STATS_RUNNING,
11671 * VIR_CONNECT_GET_ALL_DOMAINS_STATS_PAUSED,
11672 * VIR_CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF and/or
11673 * VIR_CONNECT_GET_ALL_DOMAINS_STATS_OTHER for all other states.
11675 * Returns the count of returned statistics structures on success, -1 on error.
11676 * The requested data are returned in the @retStats parameter. The returned
11677 * array should be freed by the caller. See virDomainStatsRecordListFree.
11680 virConnectGetAllDomainStats(virConnectPtr conn,
11681 unsigned int stats,
11682 virDomainStatsRecordPtr **retStats,
11683 unsigned int flags)
11685 int ret = -1;
11687 VIR_DEBUG("conn=%p, stats=0x%x, retStats=%p, flags=0x%x",
11688 conn, stats, retStats, flags);
11690 virResetLastError();
11692 virCheckConnectReturn(conn, -1);
11693 virCheckNonNullArgGoto(retStats, cleanup);
11695 if (!conn->driver->connectGetAllDomainStats) {
11696 virReportUnsupportedError();
11697 goto cleanup;
11700 ret = conn->driver->connectGetAllDomainStats(conn, NULL, 0, stats,
11701 retStats, flags);
11703 cleanup:
11704 if (ret < 0)
11705 virDispatchError(conn);
11707 return ret;
11712 * virDomainListGetStats:
11713 * @doms: NULL terminated array of domains
11714 * @stats: stats to return, binary-OR of virDomainStatsTypes
11715 * @retStats: Pointer that will be filled with the array of returned stats
11716 * @flags: extra flags; binary-OR of virConnectGetAllDomainStatsFlags
11718 * Query statistics for domains provided by @doms. Note that all domains in
11719 * @doms must share the same connection.
11721 * Report statistics of various parameters for a running VM according to @stats
11722 * field. The statistics are returned as an array of structures for each queried
11723 * domain. The structure contains an array of typed parameters containing the
11724 * individual statistics. The typed parameter name for each statistic field
11725 * consists of a dot-separated string containing name of the requested group
11726 * followed by a group specific description of the statistic value.
11728 * The statistic groups are enabled using the @stats parameter which is a
11729 * binary-OR of enum virDomainStatsTypes. The stats groups are documented
11730 * in virConnectGetAllDomainStats.
11732 * Using 0 for @stats returns all stats groups supported by the given
11733 * hypervisor.
11735 * Specifying VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS as @flags makes
11736 * the function return error in case some of the stat types in @stats were
11737 * not recognized by the daemon. However, even with this flag, a hypervisor
11738 * may omit individual fields within a known group if the information is not
11739 * available; as an extreme example, a supported group may produce zero
11740 * fields for offline domains if the statistics are meaningful only for a
11741 * running domain.
11743 * Passing VIR_CONNECT_GET_ALL_DOMAINS_STATS_NOWAIT in
11744 * @flags means when libvirt is unable to fetch stats for any of
11745 * the domains (for whatever reason) only a subset of statistics
11746 * is returned for the domain. That subset being statistics that
11747 * don't involve querying the underlying hypervisor.
11749 * Note that any of the domain list filtering flags in @flags may be rejected
11750 * by this function.
11752 * Returns the count of returned statistics structures on success, -1 on error.
11753 * The requested data are returned in the @retStats parameter. The returned
11754 * array should be freed by the caller. See virDomainStatsRecordListFree.
11755 * Note that the count of returned stats may be less than the domain count
11756 * provided via @doms.
11759 virDomainListGetStats(virDomainPtr *doms,
11760 unsigned int stats,
11761 virDomainStatsRecordPtr **retStats,
11762 unsigned int flags)
11764 virConnectPtr conn = NULL;
11765 virDomainPtr *nextdom = doms;
11766 unsigned int ndoms = 0;
11767 int ret = -1;
11769 VIR_DEBUG("doms=%p, stats=0x%x, retStats=%p, flags=0x%x",
11770 doms, stats, retStats, flags);
11772 virResetLastError();
11774 virCheckNonNullArgGoto(doms, cleanup);
11775 virCheckNonNullArgGoto(retStats, cleanup);
11777 if (!*doms) {
11778 virReportError(VIR_ERR_INVALID_ARG,
11779 _("doms array in %s must contain at least one domain"),
11780 __FUNCTION__);
11781 goto cleanup;
11784 conn = doms[0]->conn;
11785 virCheckConnectReturn(conn, -1);
11787 if (!conn->driver->connectGetAllDomainStats) {
11788 virReportUnsupportedError();
11789 goto cleanup;
11792 while (*nextdom) {
11793 virDomainPtr dom = *nextdom;
11795 virCheckDomainGoto(dom, cleanup);
11797 if (dom->conn != conn) {
11798 virReportError(VIR_ERR_INVALID_ARG, "%s",
11799 _("domains in 'doms' array must belong to a "
11800 "single connection"));
11801 goto cleanup;
11804 ndoms++;
11805 nextdom++;
11808 ret = conn->driver->connectGetAllDomainStats(conn, doms, ndoms,
11809 stats, retStats, flags);
11811 cleanup:
11812 if (ret < 0)
11813 virDispatchError(conn);
11814 return ret;
11819 * virDomainStatsRecordListFree:
11820 * @stats: NULL terminated array of virDomainStatsRecords to free
11822 * Convenience function to free a list of domain stats returned by
11823 * virDomainListGetStats and virConnectGetAllDomainStats.
11825 void
11826 virDomainStatsRecordListFree(virDomainStatsRecordPtr *stats)
11828 virDomainStatsRecordPtr *next;
11830 if (!stats)
11831 return;
11833 for (next = stats; *next; next++) {
11834 virTypedParamsFree((*next)->params, (*next)->nparams);
11835 virDomainFree((*next)->dom);
11836 VIR_FREE(*next);
11839 VIR_FREE(stats);
11844 * virDomainGetFSInfo:
11845 * @dom: a domain object
11846 * @info: a pointer to a variable to store an array of mount points information
11847 * @flags: extra flags; not used yet, so callers should always pass 0
11849 * Get a list of mapping information for each mounted file systems within the
11850 * specified guest and the disks.
11852 * Returns the number of returned mount points, or -1 in case of error.
11853 * On success, the array of the information is stored into @info. The caller is
11854 * responsible for calling virDomainFSInfoFree() on each array element, then
11855 * calling free() on @info. On error, @info is set to NULL.
11858 virDomainGetFSInfo(virDomainPtr dom,
11859 virDomainFSInfoPtr **info,
11860 unsigned int flags)
11862 VIR_DOMAIN_DEBUG(dom, "info=%p, flags=0x%x", info, flags);
11864 virResetLastError();
11866 virCheckDomainReturn(dom, -1);
11867 virCheckReadOnlyGoto(dom->conn->flags, error);
11868 virCheckNonNullArgGoto(info, error);
11869 *info = NULL;
11871 if (dom->conn->driver->domainGetFSInfo) {
11872 int ret = dom->conn->driver->domainGetFSInfo(dom, info, flags);
11873 if (ret < 0)
11874 goto error;
11875 return ret;
11878 virReportUnsupportedError();
11880 error:
11881 virDispatchError(dom->conn);
11882 return -1;
11887 * virDomainFSInfoFree:
11888 * @info: pointer to a FSInfo object
11890 * Frees all the memory occupied by @info.
11892 void
11893 virDomainFSInfoFree(virDomainFSInfoPtr info)
11895 size_t i;
11897 if (!info)
11898 return;
11900 VIR_FREE(info->mountpoint);
11901 VIR_FREE(info->name);
11902 VIR_FREE(info->fstype);
11904 for (i = 0; i < info->ndevAlias; i++)
11905 VIR_FREE(info->devAlias[i]);
11906 VIR_FREE(info->devAlias);
11908 VIR_FREE(info);
11912 * virDomainInterfaceAddresses:
11913 * @dom: domain object
11914 * @ifaces: pointer to an array of pointers pointing to interface objects
11915 * @source: one of the virDomainInterfaceAddressesSource constants
11916 * @flags: currently unused, pass zero
11918 * Return a pointer to the allocated array of pointers to interfaces
11919 * present in given domain along with their IP and MAC addresses. Note that
11920 * single interface can have multiple or even 0 IP addresses.
11922 * This API dynamically allocates the virDomainInterfacePtr struct based on
11923 * how many interfaces domain @dom has, usually there's 1:1 correlation. The
11924 * count of the interfaces is returned as the return value.
11926 * If @source is VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE, the DHCP lease
11927 * file associated with any virtual networks will be examined to obtain
11928 * the interface addresses. This only returns data for interfaces which
11929 * are connected to virtual networks managed by libvirt.
11931 * If @source is VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT, a configured
11932 * guest agent is needed for successful return from this API. Moreover, if
11933 * guest agent is used then the interface name is the one seen by guest OS.
11934 * To match such interface with the one from @dom XML use MAC address or IP
11935 * range.
11937 * If @source is VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP, the host
11938 * ARP table will be check to obtain the interface addresses. As
11939 * the arp cache refreshes in time, the returned ip address may
11940 * be unreachable. Depending on the route table config of the
11941 * guest, the returned mac address may be duplicated.
11943 * Note that for some @source values some pieces of returned @ifaces
11944 * might be unset (e.g. VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP does not
11945 * set IP address prefix as ARP table does not have any notion of that).
11947 * @ifaces->name and @ifaces->hwaddr are never NULL.
11949 * The caller *must* free @ifaces when no longer needed. Usual use case
11950 * looks like this:
11952 * virDomainInterfacePtr *ifaces = NULL;
11953 * int ifaces_count = 0;
11954 * size_t i, j;
11955 * virDomainPtr dom = ... obtain a domain here ...;
11957 * if ((ifaces_count = virDomainInterfaceAddresses(dom, &ifaces,
11958 * VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE)) < 0)
11959 * goto cleanup;
11961 * ... do something with returned values, for example:
11963 * for (i = 0; i < ifaces_count; i++) {
11964 * printf("name: %s", ifaces[i]->name);
11965 * if (ifaces[i]->hwaddr)
11966 * printf(" hwaddr: %s", ifaces[i]->hwaddr);
11968 * for (j = 0; j < ifaces[i]->naddrs; j++) {
11969 * virDomainIPAddressPtr ip_addr = ifaces[i]->addrs + j;
11970 * printf("[addr: %s prefix: %d type: %d]",
11971 * ip_addr->addr, ip_addr->prefix, ip_addr->type);
11973 * printf("\n");
11976 * cleanup:
11977 * if (ifaces && ifaces_count > 0)
11978 * for (i = 0; i < ifaces_count; i++)
11979 * virDomainInterfaceFree(ifaces[i]);
11980 * free(ifaces);
11982 * Returns the number of interfaces on success, -1 in case of error.
11985 virDomainInterfaceAddresses(virDomainPtr dom,
11986 virDomainInterfacePtr **ifaces,
11987 unsigned int source,
11988 unsigned int flags)
11990 VIR_DOMAIN_DEBUG(dom, "ifaces=%p, source=%d, flags=0x%x", ifaces, source, flags);
11992 virResetLastError();
11994 if (ifaces)
11995 *ifaces = NULL;
11996 virCheckDomainReturn(dom, -1);
11997 virCheckNonNullArgGoto(ifaces, error);
11998 if (source == VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT)
11999 virCheckReadOnlyGoto(dom->conn->flags, error);
12001 if (dom->conn->driver->domainInterfaceAddresses) {
12002 int ret;
12003 ret = dom->conn->driver->domainInterfaceAddresses(dom, ifaces, source, flags);
12004 if (ret < 0)
12005 goto error;
12006 return ret;
12009 virReportError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
12011 error:
12012 virDispatchError(dom->conn);
12013 return -1;
12018 * virDomainInterfaceFree:
12019 * @iface: an interface object
12021 * Free the interface object. The data structure is
12022 * freed and should not be used thereafter. If @iface
12023 * is NULL, then this method has no effect.
12025 void
12026 virDomainInterfaceFree(virDomainInterfacePtr iface)
12028 size_t i;
12030 if (!iface)
12031 return;
12033 VIR_FREE(iface->name);
12034 VIR_FREE(iface->hwaddr);
12036 for (i = 0; i < iface->naddrs; i++)
12037 VIR_FREE(iface->addrs[i].addr);
12038 VIR_FREE(iface->addrs);
12040 VIR_FREE(iface);
12045 * virDomainGetGuestVcpus:
12046 * @domain: pointer to domain object
12047 * @params: pointer that will be filled with an array of typed parameters
12048 * @nparams: pointer filled with number of elements in @params
12049 * @flags: currently unused, callers shall pass 0
12051 * Queries the guest agent for state and information regarding vCPUs from
12052 * guest's perspective. The reported data depends on the guest agent
12053 * implementation.
12055 * Reported fields stored in @params:
12056 * 'vcpus': string containing bitmap representing vCPU ids as reported by the
12057 * guest
12058 * 'online': string containing bitmap representing online vCPUs as reported
12059 * by the guest agent.
12060 * 'offlinable': string containing bitmap representing ids of vCPUs that can be
12061 * offlined
12063 * This API requires the VM to run. The caller is responsible for calling
12064 * virTypedParamsFree to free memory returned in @params.
12066 * Returns 0 on success, -1 on error.
12069 virDomainGetGuestVcpus(virDomainPtr domain,
12070 virTypedParameterPtr *params,
12071 unsigned int *nparams,
12072 unsigned int flags)
12074 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%p, flags=0x%x",
12075 params, nparams, flags);
12077 virResetLastError();
12079 virCheckDomainReturn(domain, -1);
12080 virCheckReadOnlyGoto(domain->conn->flags, error);
12082 virCheckNonNullArgGoto(params, error);
12083 virCheckNonNullArgGoto(nparams, error);
12085 if (domain->conn->driver->domainGetGuestVcpus) {
12086 int ret;
12087 ret = domain->conn->driver->domainGetGuestVcpus(domain, params, nparams,
12088 flags);
12089 if (ret < 0)
12090 goto error;
12091 return ret;
12094 virReportUnsupportedError();
12096 error:
12097 virDispatchError(domain->conn);
12098 return -1;
12103 * virDomainSetGuestVcpus:
12104 * @domain: pointer to domain object
12105 * @cpumap: text representation of a bitmap of vcpus to set
12106 * @state: 0 to disable/1 to enable cpus described by @cpumap
12107 * @flags: currently unused, callers shall pass 0
12109 * Sets state of individual vcpus described by @cpumap via guest agent. Other
12110 * vcpus are not modified.
12112 * This API requires the VM to run. Various hypervisors or guest agent
12113 * implementation may limit to operate on just 1 vCPU per call.
12115 * @cpumap is a list of vCPU numbers. Its syntax is a comma separated list and
12116 * a special markup using '-' and '^' (ex. '0-4', '0-3,^2'). The '-' denotes
12117 * the range and the '^' denotes exclusive. The expression is sequentially
12118 * evaluated, so "0-15,^8" is identical to "9-14,0-7,15" but not identical to
12119 * "^8,0-15".
12121 * Note that OSes (notably Linux) may require vCPU 0 to stay online to support
12122 * low-level features a S3 sleep.
12124 * Returns 0 on success, -1 on error.
12127 virDomainSetGuestVcpus(virDomainPtr domain,
12128 const char *cpumap,
12129 int state,
12130 unsigned int flags)
12132 VIR_DOMAIN_DEBUG(domain, "cpumap='%s' state=%d flags=0x%x",
12133 NULLSTR(cpumap), state, flags);
12135 virResetLastError();
12137 virCheckDomainReturn(domain, -1);
12138 virCheckReadOnlyGoto(domain->conn->flags, error);
12140 virCheckNonNullArgGoto(cpumap, error);
12142 if (domain->conn->driver->domainSetGuestVcpus) {
12143 int ret;
12144 ret = domain->conn->driver->domainSetGuestVcpus(domain, cpumap, state,
12145 flags);
12146 if (ret < 0)
12147 goto error;
12148 return ret;
12151 virReportUnsupportedError();
12153 error:
12154 virDispatchError(domain->conn);
12155 return -1;
12160 * virDomainSetVcpu:
12161 * @domain: pointer to domain object
12162 * @vcpumap: text representation of a bitmap of vcpus to set
12163 * @state: 0 to disable/1 to enable cpus described by @vcpumap
12164 * @flags: bitwise-OR of virDomainModificationImpact
12166 * Enables/disables individual vcpus described by @vcpumap in the hypervisor.
12168 * Various hypervisor implementations may limit to operate on just 1
12169 * hotpluggable entity (which may contain multiple vCPUs on certain platforms).
12171 * Note that OSes and hypervisors may require vCPU 0 to stay online.
12173 * Returns 0 on success, -1 on error.
12176 virDomainSetVcpu(virDomainPtr domain,
12177 const char *vcpumap,
12178 int state,
12179 unsigned int flags)
12181 VIR_DOMAIN_DEBUG(domain, "vcpumap='%s' state=%i flags=0x%x",
12182 NULLSTR(vcpumap), state, flags);
12184 virResetLastError();
12186 virCheckDomainReturn(domain, -1);
12187 virCheckReadOnlyGoto(domain->conn->flags, error);
12189 virCheckNonNullArgGoto(vcpumap, error);
12191 if (domain->conn->driver->domainSetVcpu) {
12192 int ret;
12193 ret = domain->conn->driver->domainSetVcpu(domain, vcpumap, state, flags);
12194 if (ret < 0)
12195 goto error;
12196 return ret;
12199 virReportUnsupportedError();
12201 error:
12202 virDispatchError(domain->conn);
12203 return -1;
12208 * virDomainSetBlockThreshold:
12209 * @domain: pointer to domain object
12210 * @dev: string specifying the block device or backing chain element
12211 * @threshold: threshold in bytes when to fire the event
12212 * @flags: currently unused, callers should pass 0
12214 * Set the threshold level for delivering the
12215 * VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD if the device or backing chain element
12216 * described by @dev is written beyond the set threshold level. The threshold
12217 * level is unset once the event fires. The event might not be delivered at all
12218 * if libvirtd was not running at the moment when the threshold was reached.
12220 * Hypervisors report the last written sector of an image in the bulk stats API
12221 * (virConnectGetAllDomainStats/virDomainListGetStats) as
12222 * "block.<num>.allocation" in the VIR_DOMAIN_STATS_BLOCK group. The current
12223 * threshold value is reported as "block.<num>.threshold".
12225 * This event allows to use thin-provisioned storage which needs management
12226 * tools to grow it without the need for polling of the data.
12228 * Returns 0 if the operation has started, -1 on failure.
12231 virDomainSetBlockThreshold(virDomainPtr domain,
12232 const char *dev,
12233 unsigned long long threshold,
12234 unsigned int flags)
12236 VIR_DOMAIN_DEBUG(domain, "dev='%s' threshold=%llu flags=0x%x",
12237 NULLSTR(dev), threshold, flags);
12239 virResetLastError();
12241 virCheckDomainReturn(domain, -1);
12242 virCheckReadOnlyGoto(domain->conn->flags, error);
12244 virCheckNonNullArgGoto(dev, error);
12246 if (domain->conn->driver->domainSetBlockThreshold) {
12247 int ret;
12248 ret = domain->conn->driver->domainSetBlockThreshold(domain, dev,
12249 threshold, flags);
12250 if (ret < 0)
12251 goto error;
12252 return ret;
12255 virReportUnsupportedError();
12257 error:
12258 virDispatchError(domain->conn);
12259 return -1;
12264 * virDomainSetLifecycleAction:
12265 * @domain: pointer to domain object
12266 * @type: the lifecycle type from virDomainLifecycle
12267 * @action: the action type from virDomainLifecycleAction
12268 * @flags: bitwise-OR of virDomainModificationImpact
12270 * Changes the actions of lifecycle events for domain represented as
12271 * <on_$type>$action</on_$type> in the domain XML.
12273 * QEMU driver has a limitation that if all lifecycle events are set
12274 * to destroy when the domain is started, it's not possible to change
12275 * any action for running domain.
12277 * Returns 0 on success, -1 on failure.
12279 int virDomainSetLifecycleAction(virDomainPtr domain,
12280 unsigned int type,
12281 unsigned int action,
12282 unsigned int flags)
12284 VIR_DOMAIN_DEBUG(domain, "type='%u' action='%u' flags='0x%x'",
12285 type, action, flags);
12287 virResetLastError();
12289 virCheckDomainReturn(domain, -1);
12290 virCheckReadOnlyGoto(domain->conn->flags, error);
12292 if (type >= VIR_DOMAIN_LIFECYCLE_LAST) {
12293 virReportError(VIR_ERR_INVALID_ARG,
12294 _("invalid lifecycle type '%u'"), type);
12295 goto error;
12298 if (action >= VIR_DOMAIN_LIFECYCLE_ACTION_LAST) {
12299 virReportError(VIR_ERR_INVALID_ARG,
12300 _("invalid lifecycle action '%u'"), action);
12301 goto error;
12304 if (domain->conn->driver->domainSetLifecycleAction) {
12305 int ret;
12306 ret = domain->conn->driver->domainSetLifecycleAction(domain,
12307 type,
12308 action,
12309 flags);
12310 if (ret < 0)
12311 goto error;
12312 return ret;
12315 virReportUnsupportedError();
12317 error:
12318 virDispatchError(domain->conn);
12319 return -1;
12323 * virDomainGetLaunchSecurityInfo:
12324 * @domain: a domain object
12325 * @params: where to store security info
12326 * @nparams: number of items in @params
12327 * @flags: currently used, set to 0.
12329 * Get the launch security info. In case of the SEV guest, this will
12330 * return the launch measurement.
12332 * Returns -1 in case of failure, 0 in case of success.
12334 int virDomainGetLaunchSecurityInfo(virDomainPtr domain,
12335 virTypedParameterPtr *params,
12336 int *nparams,
12337 unsigned int flags)
12339 virConnectPtr conn = domain->conn;
12341 VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%p flags=0x%x",
12342 params, nparams, flags);
12344 virResetLastError();
12346 virCheckDomainReturn(domain, -1);
12347 virCheckNonNullArgGoto(params, error);
12348 virCheckNonNullArgGoto(nparams, error);
12349 virCheckReadOnlyGoto(conn->flags, error);
12351 if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
12352 VIR_DRV_FEATURE_TYPED_PARAM_STRING))
12353 flags |= VIR_TYPED_PARAM_STRING_OKAY;
12355 if (conn->driver->domainGetLaunchSecurityInfo) {
12356 int ret;
12357 ret = conn->driver->domainGetLaunchSecurityInfo(domain, params,
12358 nparams, flags);
12359 if (ret < 0)
12360 goto error;
12361 return ret;
12363 virReportUnsupportedError();
12365 error:
12366 virDispatchError(domain->conn);
12367 return -1;