675
689
if (!name || name[0] == '\0') {
676
690
char *defname = getenv("LIBVIRT_DEFAULT_URI");
677
691
if (defname && *defname) {
678
DEBUG("Using LIBVIRT_DEFAULT_URI %s", defname);
692
DEBUG("Using LIBVIRT_DEFAULT_URI %s", defname);
681
const char *use = NULL;
684
for (i = 0; i < virNetworkDriverTabCount; i++) {
685
if ((virDriverTab[i]->probe != NULL) &&
686
((latest = virDriverTab[i]->probe()) != NULL)) {
695
const char *use = NULL;
698
for (i = 0; i < virNetworkDriverTabCount; i++) {
699
if ((virDriverTab[i]->probe != NULL) &&
700
((latest = virDriverTab[i]->probe()) != NULL)) {
689
DEBUG("Probed %s", latest);
691
* if running a xen kernel, give it priority over
694
if (STREQ(latest, "xen:///"))
696
else if (use == NULL)
702
DEBUG("Could not probe any hypervisor defaulting to %s",
706
DEBUG("Using %s as default URI, %d hypervisor found",
703
DEBUG("Probed %s", latest);
705
* if running a xen kernel, give it priority over
708
if (STREQ(latest, "xen:///"))
710
else if (use == NULL)
716
DEBUG("Could not probe any hypervisor defaulting to %s",
720
DEBUG("Using %s as default URI, %d hypervisor found",
712
726
/* Convert xen -> xen:/// for back compat */
713
if (!strcasecmp(name, "xen"))
727
if (STRCASEEQ(name, "xen"))
714
728
name = "xen:///";
716
730
/* Convert xen:// -> xen:/// because xmlParseURI cannot parse the
2590
* virDomainBlockPeek:
2591
* @dom: pointer to the domain object
2592
* @path: path to the block device
2593
* @offset: offset within block device
2594
* @size: size to read
2595
* @buffer: return buffer (must be at least size bytes)
2596
* @flags: unused, always pass 0
2598
* This function allows you to read the contents of a domain's
2601
* Typical uses for this are to determine if the domain has
2602
* written a Master Boot Record (indicating that the domain
2603
* has completed installation), or to try to work out the state
2604
* of the domain's filesystems.
2606
* (Note that in the local case you might try to open the
2607
* block device or file directly, but that won't work in the
2608
* remote case, nor if you don't have sufficient permission.
2609
* Hence the need for this call).
2611
* 'path' must be a device or file corresponding to the domain.
2612
* In other words it must be the precise string returned in
2613
* a <disk><source dev='...'/></disk> from
2614
* virDomainGetXMLDesc.
2616
* 'offset' and 'size' represent an area which must lie entirely
2617
* within the device or file. 'size' may be 0 to test if the
2618
* call would succeed.
2620
* 'buffer' is the return buffer and must be at least 'size' bytes.
2622
* NB. The remote driver imposes a 64K byte limit on 'size'.
2623
* For your program to be able to work reliably over a remote
2624
* connection you should split large requests to <= 65536 bytes.
2626
* Returns: 0 in case of success or -1 in case of failure.
2629
virDomainBlockPeek (virDomainPtr dom,
2631
unsigned long long offset /* really 64 bits */,
2637
DEBUG("domain=%p, path=%s, offset=%lld, size=%zi, buffer=%p",
2638
dom, path, offset, size, buffer);
2640
if (!VIR_IS_CONNECTED_DOMAIN (dom)) {
2641
virLibDomainError (NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
2647
virLibDomainError (dom, VIR_ERR_INVALID_ARG,
2653
virLibDomainError (dom, VIR_ERR_INVALID_ARG,
2654
_("flags must be zero"));
2658
/* Allow size == 0 as an access test. */
2659
if (size > 0 && !buffer) {
2660
virLibDomainError (dom, VIR_ERR_INVALID_ARG,
2661
_("buffer is NULL"));
2665
if (conn->driver->domainBlockPeek)
2666
return conn->driver->domainBlockPeek (dom, path, offset, size,
2669
virLibDomainError (dom, VIR_ERR_NO_SUPPORT, __FUNCTION__);
2674
* virDomainMemoryPeek:
2675
* @dom: pointer to the domain object
2676
* @start: start of memory to peek
2677
* @size: size of memory to peek
2678
* @buffer: return buffer (must be at least size bytes)
2679
* @flags: flags, see below
2681
* This function allows you to read the contents of a domain's
2684
* The memory which is read is controlled by the 'start', 'size'
2685
* and 'flags' parameters.
2687
* If 'flags' is VIR_MEMORY_VIRTUAL then the 'start' and 'size'
2688
* parameters are interpreted as virtual memory addresses for
2689
* whichever task happens to be running on the domain at the
2690
* moment. Although this sounds haphazard it is in fact what
2691
* you want in order to read Linux kernel state, because it
2692
* ensures that pointers in the kernel image can be interpreted
2695
* 'buffer' is the return buffer and must be at least 'size' bytes.
2696
* 'size' may be 0 to test if the call would succeed.
2698
* NB. The remote driver imposes a 64K byte limit on 'size'.
2699
* For your program to be able to work reliably over a remote
2700
* connection you should split large requests to <= 65536 bytes.
2702
* Returns: 0 in case of success or -1 in case of failure.
2705
virDomainMemoryPeek (virDomainPtr dom,
2706
unsigned long long start /* really 64 bits */,
2712
DEBUG ("domain=%p, start=%lld, size=%zi, buffer=%p, flags=%d",
2713
dom, start, size, buffer, flags);
2715
if (!VIR_IS_CONNECTED_DOMAIN (dom)) {
2716
virLibDomainError (NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
2721
/* Flags must be VIR_MEMORY_VIRTUAL at the moment.
2723
* Note on access to physical memory: A VIR_MEMORY_PHYSICAL flag is
2724
* a possibility. However it isn't really useful unless the caller
2725
* can also access registers, particularly CR3 on x86 in order to
2726
* get the Page Table Directory. Since registers are different on
2727
* every architecture, that would imply another call to get the
2728
* machine registers.
2730
* The QEMU driver handles only VIR_MEMORY_VIRTUAL, mapping it
2731
* to the qemu 'memsave' command which does the virtual to physical
2732
* mapping inside qemu.
2734
* At time of writing there is no Xen driver. However the Xen
2735
* hypervisor only lets you map physical pages from other domains,
2736
* and so the Xen driver would have to do the virtual to physical
2737
* mapping by chasing 2, 3 or 4-level page tables from the PTD.
2738
* There is example code in libxc (xc_translate_foreign_address)
2739
* which does this, although we cannot copy this code directly
2740
* because of incompatible licensing.
2742
if (flags != VIR_MEMORY_VIRTUAL) {
2743
virLibDomainError (dom, VIR_ERR_INVALID_ARG,
2744
_("flags parameter must be VIR_MEMORY_VIRTUAL"));
2748
/* Allow size == 0 as an access test. */
2749
if (size > 0 && !buffer) {
2750
virLibDomainError (dom, VIR_ERR_INVALID_ARG,
2751
_("buffer is NULL but size is non-zero"));
2755
if (conn->driver->domainMemoryPeek)
2756
return conn->driver->domainMemoryPeek (dom, start, size,
2759
virLibDomainError (dom, VIR_ERR_NO_SUPPORT, __FUNCTION__);
2582
2764
/************************************************************************