[PATCH v3 2/9] ch: Pass net ids explicitly during vm creation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Pass "net_<index>" as net id to CH. This is to have better control over
the network configs. This id can be further used in performing
operations like restore etc.

Signed-off-by: Purna Pavan Chandra <paekkaladevi@xxxxxxxxxxxxxxxxxxx>
---
 src/ch/ch_monitor.c | 7 ++++++-
 src/ch/ch_monitor.h | 4 +++-
 src/ch/ch_process.c | 2 +-
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c
index 7b6b77de1c..6af5b29d82 100644
--- a/src/ch/ch_monitor.c
+++ b/src/ch/ch_monitor.c
@@ -278,18 +278,23 @@ virCHMonitorBuildDisksJson(virJSONValue *content, virDomainDef *vmdef)
 /**
  * virCHMonitorBuildNetJson:
  * @net: pointer to a guest network definition
+ * @netindex: index of the guest network definition
  * @jsonstr: returned network json
  *
  * Build net json to send to CH
  * Returns 0 on success or -1 in case of error
  */
 int
-virCHMonitorBuildNetJson(virDomainNetDef *net, char **jsonstr)
+virCHMonitorBuildNetJson(virDomainNetDef *net, int netindex, char **jsonstr)
 {
     char macaddr[VIR_MAC_STRING_BUFLEN];
     g_autoptr(virJSONValue) net_json = virJSONValueNewObject();
     virDomainNetType actualType = virDomainNetGetActualType(net);
 
+    g_autofree char *id = g_strdup_printf("%s_%d", CH_NET_ID_PREFIX, netindex);
+    if (virJSONValueObjectAppendString(net_json, "id", id) < 0)
+        return -1;
+
     if (actualType == VIR_DOMAIN_NET_TYPE_ETHERNET &&
         net->guestIP.nips == 1) {
         const virNetDevIPAddr *ip;
diff --git a/src/ch/ch_monitor.h b/src/ch/ch_monitor.h
index ea6b2a771b..bac80b5fcb 100644
--- a/src/ch/ch_monitor.h
+++ b/src/ch/ch_monitor.h
@@ -42,6 +42,8 @@
 
 #define VIRCH_THREAD_NAME_LEN   16
 
+#define CH_NET_ID_PREFIX "net"
+
 typedef enum {
     virCHThreadTypeEmulator,
     virCHThreadTypeVcpu,
@@ -125,4 +127,4 @@ size_t virCHMonitorGetThreadInfo(virCHMonitor *mon, bool refresh,
 int virCHMonitorGetIOThreads(virCHMonitor *mon,
                              virDomainIOThreadInfo ***iothreads);
 int
-virCHMonitorBuildNetJson(virDomainNetDef *netdef, char **jsonstr);
+virCHMonitorBuildNetJson(virDomainNetDef *netdef, int netindex, char **jsonstr);
diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c
index 6f99fec900..5907a6e81f 100644
--- a/src/ch/ch_process.c
+++ b/src/ch/ch_process.c
@@ -621,7 +621,7 @@ chProcessAddNetworkDevices(virCHDriver *driver,
                                          nicindexes, nnicindexes) < 0)
             return -1;
 
-        if (virCHMonitorBuildNetJson(vmdef->nets[i], &payload) < 0) {
+        if (virCHMonitorBuildNetJson(vmdef->nets[i], i, &payload) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Failed to build net json"));
             return -1;
-- 
2.34.1



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux