[libvirt] new API to get list of *all* interfaces matching a MAC
by Laine Stump
(This probably seems like overanalysis of a simple problem. That's what
I'm best at ;-)
Due to oversight, the function virInterfaceLookupByMACString() can only
return a single interface, but it's possible that a host may have more
than one interface with the same MAC. Since the API had already been
released by the time we realized this, the existing function will remain
and a new one added that can return a list of interfaces. This new API
will need to deal with the fact that the list length is effectively
unbounded. I can see three ways of dealing with this, and want to learn
which is preferred by others before spending time on the implementation.
1) The array containing the list is allocated by libvirt, freed by caller.
int virInterfaceLookupAllByMACString(virConnectPtr conn, const
char *mac, virInterfacePtr **matches);
"matches" will point to an array of virInterfacePtr, and that
array's length will be the return value. This array will be
allocated by libvirt, but must be freed by the application when
it's finished.
Usage (ignoring errors, of course :-):
virInterfacePtr *matches;
int matchCt;
matchCt = virInterfaceLookupAllByMACString(conn,
"00:01:02:03:04:05", &matches);
for (i = 0; i < matchCt; i++) {
/* do something with an interface */
virInterfaceFree(matches[i]);
}
free(matches);
2) The array containing the list is allocated by the application, and
its length sent to libvirt. Libvirt then returns the actual number of
matches, which may be greater than the max length sent by the
application, but only copies as many as the application asked for. If
the application sends 0 as maxMatches and/or a NULL pointer instead of a
pointer to an array, libvirt will return the actual length, but not the
list itself.
For example, if there are 3 interfaces matching, and maxMatches is set
to 2, the function will still return 3, but only set two items in the
matches array.
int virInterfaceLookupAllByMACString(virConnectPtr conn, const
char *mac, virInterfacePtr **matches, int maxMatches);
This puts all the functionality needed in a single API function, but it
will generally need to be called twice - once to learn the length, and
the second (after allocating an array of appropriate size) to retrieve
the list.
virInterfacePtr *matches;
int matchCtA, matchCtB;
matchCtA = virInterfaceLookupAllByMACString(conn,
"00:01:02:03:04:05", NULL, 0);
matches = malloc (matchCt * sizeof(virInterfacePtr));
matchCtB = virInterfaceLookupAllByMACString(conn,
"00:01:02:03:04:05", &matches, matchCt);
for (i = 0; i < min(matchCtA, matchCtB); i++) {
/* do something with an interface */
virInterfaceFree(matches[i]);
}
free(matches);
3) Again, the array containing the list is allocated by the application,
but it learns the proper length to allocate by calling a different API
function. The lookup function itself returns the number of interfaces
delivered in the array, rather than the number of matches it *wanted* to
put in the array.
int virInterfaceCountAllByMACString(virConnectPtr conn, const
char *mac);
int virInterfaceLookupAllByMACString(virConnectPtr conn, const
char *mac, virInterfacePtr **matches, int maxMatches);
Usage:
virInterfacePtr *matches;
int matchCt;
matchCt = virInterfaceCountAllByMACString(conn,
"00:01:02:03:04:05");
matches = malloc (matchCt * sizeof(virInterfacePtr));
matchCt = virInterfaceLookupAllByMACString(conn,
"00:01:02:03:04:05", &matches, matchCt);
for (i = 0; i < matchCt; i++) {
/* do something with an interface */
virInterfaceFree(matches[i]);
}
free(matches);
*******
(3) is closest to behavior of other libvirt APIs, but requires more
functions in the API, and could lead to situations where newly added
interfaces aren't in the list (if a new interface is added between
calling the Count function and the Lookup function) . (2) has a more
compact API (one which matches the netcf API exactly), but has the same
problems with potential bad counts. (1) seems like the cleanest API, but
I don't know what others' opinions are on having libvirt allocate the
array (since that's not how its done for other similar things, eg
virConnectListInterface, virConnectListNetworks, etc), or maybe there's
some limitation of the RPC I haven't considered that makes it unfeasible.
Which should I implement?
15 years, 4 months
[libvirt] Small patch for ruby-libvirt to add api wrapping for DomainAttachDevice and DomainDetachDevice
by Jacob Leaver
--- ext/libvirt/_libvirt.c.orig 2009-01-19 18:24:22.000000000 -0800
+++ ext/libvirt/_libvirt.c 2009-01-19 18:24:39.000000000 -0800
@@ -728,6 +728,21 @@
gen_call_void(virDomainSave, conn(s),
domain_get(s), StringValueCStr(to));
}
+/*
+ * Call
+virDomainAttachDevice+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainAttachDevice]
+ */
+VALUE libvirt_dom_attach_device_xml(VALUE s, VALUE xml) {
+ virDomainPtr dom = domain_get(s);
+ return virDomainAttachDevice(dom, StringValueCStr(xml));
+}
+
+/*
+ * Call
+virDomainDetachDevice+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainDetachDevice]
+ */
+VALUE libvirt_dom_detach_device_xml(VALUE s, VALUE xml) {
+ virDomainPtr dom = domain_get(s);
+ return virDomainDetachDevice(dom, StringValueCStr(xml));
+}
/*
* Call
+virDomainCoreDump+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainCoreDump]
@@ -1921,7 +1936,8 @@
rb_define_method(c_domain, "autostart", libvirt_dom_autostart, 0);
rb_define_method(c_domain, "autostart=",
libvirt_dom_autostart_set, 1);
rb_define_method(c_domain, "free", libvirt_dom_free, 0);
-
+ rb_define_method(c_domain, "attach_device",
libvirt_dom_attach_device_xml, 1);
+ rb_define_method(c_domain, "detach_device",
libvirt_dom_detach_device_xml, 1);
/*
* Class Libvirt::Domain::Info
*/
15 years, 4 months
[libvirt] OS Eject & Removable Media
by Jacob Leaver
Greetings all,
First, I'd like to thank everyone that's working on the libvirt project,
it's certainly making my life a better place.
Second, (there's always a second, eh?) I am using libvirtd 0.6.4 and KVM
qemu-kvm-0.10.5, and when a guest OS ejects media, libvirtd doesn't seem
to pick up the change.
Looking through the API, I don't see a provision to probe for a list of
block devices, so although qemu and kvm know about media changes, I
don't think there's a way for libvirtd to know about them.
I've scanned the list archives, and haven't really seen any discussion
of this, but I'd be more than happy to be directed somewhere.
Also, I have a couple of minor and hackish patches for the ruby bindings
for attaching and removing devices, if someone's interested.
Sincerely,
Jacob Leaver
15 years, 4 months
[libvirt] network not autostarting
by Mariano Absatz
Hi,
I'm using libvirt-bin 0.6.1 from the standard ubuntu repositories under
ubuntu 9.04 (jaunty).
I have, beside the default network, another one called "isolated" using
the following description file:
<network>
<name>isolated</name>
<uuid>51cffbcc-88f5-4edc-a81c-1765c1045691</uuid>
<bridge name='virbr%d' stp='on' forwardDelay='0' />
<ip address='10.3.14.1' netmask='255.255.255.0'>
<dhcp>
<range start='10.3.14.128' end='10.3.14.254' />
</dhcp>
</ip>
</network>
I have configured it with "net-autostart" and the symlink in the
/etc/libvirt/qemu/networks/autostart/ autostart directory is just
fine... however, it isn't starting automatically anymore (and it used to
start up before)...
Any hints on what to look up and where?
TIA.
--
Mariano Absatz - "El Baby"
el.baby(a)gmail.com
www.clueless.com.ar
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
_ |
/ \ |
\ / ASCII RIBBON CAMPAIGN |
X AGAINST HTML MAIL |
/ \ www.asciiribbon.org |
|
|
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* TagZilla 0.066 * http://tagzilla.mozdev.org
15 years, 4 months
[libvirt] Communicating with libvirt from windows
by anuj rampal
Hi,
I have KVM running on one of my machine and I can controle the geues OS
using the virt-manager and Virsh tools.
Now what I want to do is talk to libvirt from my windows machine.
I tried to compile libvirt for windows but couldnt get any success with
that.
Is there a way by which i can talk to libvirt without this client..??
As in can i talk to libvirt over TCP sockets using xml (something like
that)...??
Thanks a lot in advance.
Regards
Anuj
15 years, 4 months
[libvirt] [PATCH] Ignores EOPNOTSUPP when attempting to access an image on an NFS share.
by Darryl L. Pierce
rhbz#517157
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
src/security_selinux.c | 23 ++++++++++++++++-------
1 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/security_selinux.c b/src/security_selinux.c
index 0db9f49..f1e3f17 100644
--- a/src/security_selinux.c
+++ b/src/security_selinux.c
@@ -323,6 +323,8 @@ SELinuxSetFilecon(virConnectPtr conn, const char *path, char *tcon)
VIR_INFO("Setting SELinux context on '%s' to '%s'", path, tcon);
if (setfilecon(path, tcon) < 0) {
+ int setfilecon_errno = errno;
+
if (getfilecon(path, &econ) >= 0) {
if (STREQ(tcon, econ)) {
freecon(econ);
@@ -331,14 +333,21 @@ SELinuxSetFilecon(virConnectPtr conn, const char *path, char *tcon)
}
freecon(econ);
}
- virSecurityReportError(conn, VIR_ERR_ERROR,
- _("%s: unable to set security context "
- "'\%s\' on %s: %s."), __func__,
- tcon,
- path,
- virStrerror(errno, ebuf, sizeof ebuf));
- if (security_getenforce() == 1)
+
+ /* if the error complaint is related to an image hosted on
+ * an nfs mount, then ignore it.
+ * rhbz 517157
+ */
+ if (setfilecon_errno != EOPNOTSUPP) {
+ virSecurityReportError(conn, VIR_ERR_ERROR,
+ _("%s: unable to set security context "
+ "'\%s\' on %s: %s."), __func__,
+ tcon,
+ path,
+ virStrerror(errno, ebuf, sizeof ebuf));
+ if (security_getenforce() == 1)
return -1;
+ }
}
return 0;
}
--
1.6.2.5
15 years, 4 months
[libvirt] error: failed to connect to the hypervisor
by Dominik Klein
Hi
I am running kvm-78 with libvirt 0.6.1 and see the following error from
time to time when my linux-ha cluster tries to run "virsh domstate" to
figure out a virtual machine's state:
error: failed to connect to the hypervisor
In syslog, I see:
libvirtd: 23:39:11.357: error : Failed to set close-on-exec file
descriptor flag
Due to this error, the cluster assumes the machine is not running okay
and reboots it in order to fix things.
This happened twice in 2 months with 10 machines being queried like that
each minute (read: not too well reproducable)
What is this and how could I work around it or is this fixed in newer
versions and so worth an upgrade?
Regards
Dominik
15 years, 4 months