[libvirt] [PATCH] qemu: Add network bandwidth settings for ethernet type interfaces

2014-08-31 Thread Anirban Chakraborty
Please apply.

thanks,
Anirban Chakraborty

Signed-off-by: Anirban Chakraborty abc...@juniper.net
---
 src/qemu/qemu_command.c | 5 +
 src/qemu/qemu_hotplug.c | 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2184caa..258c6a7 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7251,6 +7251,11 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
 if (tapfd[0]  0)
 goto cleanup;
 }
+   /* Configure network bandwidth for ethernet type network interfaces */
+   if (actualType == VIR_DOMAIN_NET_TYPE_ETHERNET)
+   if (virNetDevBandwidthSet(net-ifname,
+   virDomainNetGetActualBandwidth(net), false)  0)
+   goto cleanup;

 if ((actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
  actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index a364c52..aeb53c5 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -940,6 +940,9 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
 if (qemuOpenVhostNet(vm-def, net, priv-qemuCaps, vhostfd, 
vhostfdSize)  0)
 goto cleanup;
 } else if (actualType == VIR_DOMAIN_NET_TYPE_ETHERNET) {
+   if (virNetDevBandwidthSet(net-ifname,
+   virDomainNetGetActualBandwidth(net), false)  0)
+   goto cleanup;
 vhostfdSize = 1;
 if (VIR_ALLOC(vhostfd)  0)
 goto cleanup;
-- 
1.8.2.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] virsh: Implement command to rename domain

2014-08-31 Thread Tomas Meszaros
I've recently worked with rather large number of virtual machines
and needed to rename all domains. I couldn't find better way how
to rename domain other than:

virsh dumpxml domain  domain.xml
(change domain name in domain.xml)
virsh undefine domain
virsh define domain.xml

This is rather pain to do every time I want to rename domain.
I think there should be simple way to change domain name.

So, I decided to implement new command which will basically perform
all actions listed above. When running:

virsh rename foo bar

domain foo will be renamed to bar.

Command rename is implemented using cmdUndefine options with addition
of option name-name.

I included opts_undefine into the opts_rename because I couldn't find
any other way how to call cmdUndefine directly from the cmdRename and
not getting vshCommandOpt assertion fails.

In order to hide undefine options, I added VSH_OFLAG_HIDDEN flag to
the Command Option Flags, so options flagged as hidden wont show up
in help and autocompletion results.

But it is still possible to run rename command with undefine flags:

virsh rename foo bar --managed-save

I would like to call cmdUndefine from cmdRename and not having to
use undefine options as a part of rename options but I just don't
know how to do it at this point.
---
 tools/virsh-domain.c | 133 +++
 tools/virsh.c|  10 
 tools/virsh.h|   2 +
 tools/virsh.pod  |  12 +
 4 files changed, 157 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index c75cd73..cd8c663 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5103,6 +5103,133 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd)
 }
 
 /*
+ * rename command
+ */
+static const vshCmdInfo info_rename[] = {
+{.name = help,
+ .data = N_(rename a domain)
+},
+{.name = desc,
+ .data = N_(Change domain name.)
+},
+{.name = NULL}
+};
+
+static const vshCmdOptDef opts_rename[] = {
+{.name = domain,
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_(domain name or uuid)
+},
+{.name = new-name,
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_(new domain name)
+},
+{.name = managed-save,
+ .type = VSH_OT_BOOL,
+ .flags = VSH_OFLAG_HIDDEN,
+},
+{.name = storage,
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_HIDDEN,
+},
+{.name = remove-all-storage,
+ .type = VSH_OT_BOOL,
+ .flags = VSH_OFLAG_HIDDEN,
+},
+{.name = wipe-storage,
+ .type = VSH_OT_BOOL,
+ .flags = VSH_OFLAG_HIDDEN,
+},
+{.name = snapshots-metadata,
+ .type = VSH_OT_BOOL,
+ .flags = VSH_OFLAG_HIDDEN,
+},
+{.name = NULL}
+};
+
+static bool
+cmdRename(vshControl *ctl, const vshCmd *cmd)
+{
+virDomainPtr dom = NULL;
+virDomainPtr new_dom = NULL;
+bool ret = false;
+int dom_state;
+int xml_size;
+char *dom_xml = NULL;
+const char *new_name = NULL;
+xmlDocPtr doc = NULL;
+xmlChar *new_dom_xml = NULL;
+xmlNodePtr name_node = NULL;
+xmlXPathObjectPtr obj = NULL;
+xmlXPathContextPtr ctxt = NULL;
+
+if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+return false;
+
+if (virDomainGetState(dom, dom_state, NULL, 0)  0) {
+vshError(ctl, %s, _(Failed to get domain state));
+goto cleanup;
+}
+
+if (dom_state != VIR_DOMAIN_SHUTOFF) {
+vshError(ctl, _(Please shutdown domain before renaming));
+goto cleanup;
+}
+
+if (vshCommandOptString(cmd, new-name, new_name) = 0) {
+vshError(ctl, _(Failed to parse --new-name parameter));
+goto cleanup;
+}
+
+if (!(dom_xml = virDomainGetXMLDesc(dom, 0)))
+goto cleanup;
+if (!(doc = virXMLParseStringCtxt(dom_xml, NULL, ctxt)))
+goto cleanup;
+
+obj = xmlXPathEval(BAD_CAST /domain/name, ctxt);
+if (obj == NULL || obj-type != XPATH_NODESET || obj-nodesetval == NULL ||
+obj-nodesetval-nodeNr == 0 || obj-nodesetval-nodeTab == NULL) {
+vshError(ctl, _(Failed to extract domain name));
+goto cleanup;
+}
+
+if (!(name_node = obj-nodesetval-nodeTab[0]-children))
+goto cleanup;
+
+xmlNodeSetContent(name_node, BAD_CAST new_name);
+xmlDocDumpMemory(doc, new_dom_xml, xml_size);
+if (new_dom_xml == NULL || xml_size = 0) {
+vshError(ctl, _(Failed to format new XML for domain %s), new_name);
+goto cleanup;
+}
+
+if (!cmdUndefine(ctl, cmd))
+goto cleanup;
+
+if (!(new_dom = virDomainDefineXML(ctl-conn, (char *)new_dom_xml))) {
+vshError(ctl, _(Failed to define domain %s), new_name);
+goto cleanup;
+}
+
+vshPrint(ctl, _(Domain %s has been renamed to %s\n),
+ virDomainGetName(dom), virDomainGetName(new_dom));
+ret = true;
+
+ cleanup:
+virDomainFree(dom);
+if (new_dom)
+virDomainFree(new_dom);
+

Re: [libvirt] [PATCH] conf: Check migration_host is valid or not during libvirt restarts

2014-08-31 Thread chen.fan.f...@cn.fujitsu.com
On Fri, 2014-08-29 at 14:52 +0200, Jiri Denemark wrote: 
 On Fri, Aug 29, 2014 at 19:20:58 +0800, Chen Fan wrote:
  if user specified an invalid strings as migration hostname,
  like setting: migration_host = XXX, libvirt should check
  it and return error during lbivirt restart.
  
  Signed-off-by: Chen Fan chen.fan.f...@cn.fujitsu.com
  ---
   src/qemu/qemu_conf.c | 40 
   1 file changed, 40 insertions(+)
  
  diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
  index e2ec54f..450ac5b 100644
  --- a/src/qemu/qemu_conf.c
  +++ b/src/qemu/qemu_conf.c
  @@ -33,6 +33,7 @@
   #include fcntl.h
   #include sys/wait.h
   #include arpa/inet.h
  +#include netdb.h
   
   #include virerror.h
   #include qemu_conf.h
  @@ -650,6 +651,45 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr 
  cfg,
   GET_VALUE_LONG(seccomp_sandbox, cfg-seccompSandbox);
   
   GET_VALUE_STR(migration_host, cfg-migrateHost);
  +if (cfg-migrateHost) {
  +struct addrinfo hints;
  +struct addrinfo *res;
  +
  +memset(hints, 0, sizeof(hints));
  +hints.ai_flags = AI_ADDRCONFIG;
  +hints.ai_family = AF_UNSPEC;
  +
  +if (getaddrinfo(cfg-migrateHost, NULL, hints, res) != 0) {
  +virReportError(VIR_ERR_CONF_SYNTAX,
  +   _(migration_host: '%s' is not a valid 
  hostname),
  +   cfg-migrateHost);
  +goto cleanup;
  +}
  +
  +if (res == NULL) {
  +virReportError(VIR_ERR_CONF_SYNTAX,
  +   _(No IP address for host '%s' found),
  +   cfg-migrateHost);
  +goto cleanup;
  +}
  +
  +freeaddrinfo(res);
 
 I don't think this is a good idea. What if it's in fact valid and just
 can't be resolved due to a temporary issue? It should only fail at the
 time someone actually tries to migrate a domain.

What are these issues? usually, I think migration hosts always at the
same network, a valid hostname should be resolved by DNS. if can't be
resolved, libvirt should tell user the error at the time of libvirt
restart, Maybe we can output a warning or info to let user know that but
restart failure. what do you think?

Thanks,
Chen


 
  +
  +if (STRPREFIX(cfg-migrateHost, localhost)) {
  +virReportError(VIR_ERR_CONF_SYNTAX, %s,
  +   _(setting migration_host to 'localhost' is not 
  allowed));
  +goto cleanup;
  +}
  +
  +if (STREQ(cfg-migrateHost, 127.0.0.1) ||
  +STREQ(cfg-migrateHost, ::1)) {
  +virReportError(VIR_ERR_CONF_SYNTAX, %s,
  +   _(setting migration_host to '127.0.0.1' or 
  '::1' 
  + is not allowed));
  +goto cleanup;
  +}
  +}
  +
 
 Checking for localhost could make sense.
 
   GET_VALUE_STR(migration_address, cfg-migrationAddress);
   
   GET_VALUE_BOOL(log_timestamp, cfg-logTimestamp);
 
 Jirka


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 10/11] qemu: bulk stats: implement block group

2014-08-31 Thread Li Wei
Hi Francesco,

I notice your patchset is much complete than mine which only focus on
VIR_DOMAIN_STATS_BLOCK[1], but it seems your patch implement block stats
query in a per-block style, this should be a bottleneck when there are
a lot of block devices in a domain.

Could you implement it in a bulk style? so we just need only one qmp-command
for each domain.

[1]: https://www.redhat.com/archives/libvir-list/2014-August/msg01497.html

Thanks,
Li Wei

On 08/29/2014 03:15 PM, Francesco Romani wrote:
 This patch implements the VIR_DOMAIN_STATS_BLOCK
 group of statistics.
 
 Signed-off-by: Francesco Romani from...@redhat.com
 ---
  include/libvirt/libvirt.h.in |  1 +
  src/qemu/qemu_driver.c   | 54 
 
  2 files changed, 55 insertions(+)
 
 diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
 index 8c15583..372e098 100644
 --- a/include/libvirt/libvirt.h.in
 +++ b/include/libvirt/libvirt.h.in
 @@ -2515,6 +2515,7 @@ typedef enum {
  VIR_DOMAIN_STATS_BALLOON = (1  2), /* return domain balloon info */
  VIR_DOMAIN_STATS_VCPU = (1  3), /* return domain virtual CPU info */
  VIR_DOMAIN_STATS_INTERFACE = (1  4), /* return domain interfaces info 
 */
 +VIR_DOMAIN_STATS_BLOCK = (1  5), /* return domain block info */
  } virDomainStatsTypes;
  
  typedef enum {
 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
 index 818fcbc..344b02e 100644
 --- a/src/qemu/qemu_driver.c
 +++ b/src/qemu/qemu_driver.c
 @@ -17552,6 +17552,59 @@ qemuDomainGetStatsInterface(virConnectPtr conn 
 ATTRIBUTE_UNUSED,
  
  #undef QEMU_ADD_NET_PARAM
  
 +#define QEMU_ADD_BLOCK_PARAM(RECORD, MAXPARAMS, BLOCK, NAME, VALUE) \
 +do { \
 +char param_name[NAME_MAX]; \
 +snprintf(param_name, NAME_MAX, block.%s.%s, BLOCK, NAME); \
 +if (virTypedParamsAddLLong(RECORD-params, \
 +   RECORD-nparams, \
 +   MAXPARAMS, \
 +   param_name, \
 +   VALUE)  0) \
 +return -1; \
 +} while (0)
 +
 +static int
 +qemuDomainGetStatsBlock(virConnectPtr conn ATTRIBUTE_UNUSED,
 +virDomainObjPtr dom,
 +virDomainStatsRecordPtr record,
 +int *maxparams,
 +unsigned int privflags ATTRIBUTE_UNUSED)
 +{
 +virQEMUDriverPtr driver = conn-privateData;
 +struct qemuBlockStats stats;
 +size_t i;
 +
 +for (i = 0; i  dom-def-ndisks; i++) {
 +memset(stats, 0, sizeof(stats));
 +
 +if (qemuDiskGetBlockStats(driver, dom, dom-def-disks[i], stats)  
 0)
 +continue;
 +
 +QEMU_ADD_BLOCK_PARAM(record, maxparams, dom-def-disks[i]-dst,
 + rd.reqs, stats.rd_req);
 +QEMU_ADD_BLOCK_PARAM(record, maxparams, dom-def-disks[i]-dst,
 + rd.bytes, stats.rd_bytes);
 +QEMU_ADD_BLOCK_PARAM(record, maxparams, dom-def-disks[i]-dst,
 + rd.times, stats.rd_total_times);
 +QEMU_ADD_BLOCK_PARAM(record, maxparams, dom-def-disks[i]-dst,
 + wr.reqs, stats.wr_req);
 +QEMU_ADD_BLOCK_PARAM(record, maxparams, dom-def-disks[i]-dst,
 + wr.bytes, stats.wr_bytes);
 +QEMU_ADD_BLOCK_PARAM(record, maxparams, dom-def-disks[i]-dst,
 + wr.times, stats.wr_total_times);
 +QEMU_ADD_BLOCK_PARAM(record, maxparams, dom-def-disks[i]-dst,
 + fl.reqs, stats.flush_req);
 +QEMU_ADD_BLOCK_PARAM(record, maxparams, dom-def-disks[i]-dst,
 + fl.times, stats.flush_total_times);
 +}
 +
 +return 0;
 +}
 +
 +#undef QEMU_ADD_BLOCK_PARAM
 +
 +
  typedef int
  (*qemuDomainGetStatsFunc)(virConnectPtr conn,
virDomainObjPtr dom,
 @@ -17570,6 +17623,7 @@ static struct qemuDomainGetStatsWorker 
 qemuDomainGetStatsWorkers[] = {
  { qemuDomainGetStatsBalloon, VIR_DOMAIN_STATS_BALLOON },
  { qemuDomainGetStatsVcpu, VIR_DOMAIN_STATS_VCPU },
  { qemuDomainGetStatsInterface, VIR_DOMAIN_STATS_INTERFACE },
 +{ qemuDomainGetStatsBlock, VIR_DOMAIN_STATS_BLOCK },
  { NULL, 0 }
  };
  
 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2] Fix connection to already running session libvirtd

2014-08-31 Thread Martin Kletzander

On Fri, Aug 29, 2014 at 02:18:59PM +0200, Christophe Fergeau wrote:

Since 1b807f92, connecting with virsh to an already running session
libvirtd fails with:
$ virsh list --all
error: failed to connect to the hypervisor
error: no valid connection
error: Failed to connect socket to
'/run/user/1000/libvirt/libvirt-sock': Transport endpoint is already
connected

This is caused by a logic error in virNetSocketNewConnectUnix: even if
the connection to the daemon socket succeeded, we still try to spawn the
daemon and then connect to it.
This commit changes the logic to not try to spawn libvirtd if we
successfully connected to its socket.

Most of this commit is whitespace changes, use of -w is used to look at
it.
---
Same patch as the previous but with -w for easier review

Christophe



ACK and safe for 1.2.8.

Thank you,
Martin


signature.asc
Description: Digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list