[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v2 22/23] COLO nic: export colo nic APIs
From: |
Yang Hongyang |
Subject: |
[Qemu-devel] [RFC PATCH v2 22/23] COLO nic: export colo nic APIs |
Date: |
Tue, 23 Sep 2014 17:23:54 +0800 |
export colo nic APIs:
colo_configure_nic()
colo_teardown_nic()
Signed-off-by: Yang Hongyang <address@hidden>
---
include/net/colo-nic.h | 2 ++
net/colo-nic.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/include/net/colo-nic.h b/include/net/colo-nic.h
index fe6874b..66d2dcc 100644
--- a/include/net/colo-nic.h
+++ b/include/net/colo-nic.h
@@ -14,5 +14,7 @@
void colo_add_nic_devices(NetClientState *nc);
void colo_remove_nic_devices(NetClientState *nc);
+int colo_configure_nic(bool is_slave);
+void colo_teardown_nic(bool is_slave);
#endif
diff --git a/net/colo-nic.c b/net/colo-nic.c
index d661d8b..5d6d352 100644
--- a/net/colo-nic.c
+++ b/net/colo-nic.c
@@ -11,6 +11,7 @@
#include "net/net.h"
#include "net/colo-nic.h"
#include "qemu/error-report.h"
+#include "migration/migration-colo.h"
typedef struct nic_device {
NetClientState *nc;
@@ -131,6 +132,35 @@ static int nic_configure(NetClientState *nc, bool up, bool
is_slave)
return ret;
}
+static int configure_one_nic(NetClientState *nc, bool up, bool is_slave)
+{
+ struct nic_device *nic;
+
+ if (!nc) {
+ return -1;
+ }
+
+ QTAILQ_FOREACH(nic, &nic_devices, next) {
+ if (nic->nc == nc) {
+ if (!nic->support_colo || !nic->support_colo(nic->nc)
+ || !nic->configure) {
+ return -1;
+ }
+ if (up == nic->is_up) {
+ return 0;
+ }
+
+ if (nic->configure(nic->nc, up, is_slave) && up) {
+ return -1;
+ }
+ nic->is_up = up;
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
void colo_add_nic_devices(NetClientState *nc)
{
struct nic_device *nic = g_malloc0(sizeof(*nic));
@@ -158,9 +188,40 @@ void colo_remove_nic_devices(NetClientState *nc)
QTAILQ_FOREACH_SAFE(nic, &nic_devices, next, next_nic) {
if (nic->nc == nc) {
- /* TODO: teardown colo nic */
+ if (colo_is_slave()) {
+ configure_one_nic(nc, 0, 1);
+ }
+ if (colo_is_master()) {
+ configure_one_nic(nc, 0, 0);
+ }
QTAILQ_REMOVE(&nic_devices, nic, next);
g_free(nic);
}
}
}
+
+int colo_configure_nic(bool is_slave)
+{
+ struct nic_device *nic;
+
+ if (QTAILQ_EMPTY(&nic_devices)) {
+ return -1;
+ }
+
+ QTAILQ_FOREACH(nic, &nic_devices, next) {
+ if (configure_one_nic(nic->nc, 1, is_slave)) {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+void colo_teardown_nic(bool is_slave)
+{
+ struct nic_device *nic;
+
+ QTAILQ_FOREACH(nic, &nic_devices, next) {
+ configure_one_nic(nic->nc, 0, is_slave);
+ }
+}
--
1.9.1
- [Qemu-devel] [RFC PATCH v2 13/23] COLO ctl: implement colo save, (continued)
- [Qemu-devel] [RFC PATCH v2 13/23] COLO ctl: implement colo save, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 14/23] COLO ctl: implement colo restore, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 16/23] COLO ram cache: implement colo ram cache on slave, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 17/23] HACK: trigger checkpoint every 500ms, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 15/23] COLO save: reuse migration bitmap under colo checkpoint, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 18/23] COLO nic: add command line switch, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 19/23] COLO nic: init/remove colo nic devices when add/cleanup tap devices, Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 20/23] COLO nic: implement colo nic device interface support_colo(), Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 21/23] COLO nic: implement colo nic device interface configure(), Yang Hongyang, 2014/09/23
- [Qemu-devel] [RFC PATCH v2 22/23] COLO nic: export colo nic APIs,
Yang Hongyang <=
- [Qemu-devel] [RFC PATCH v2 23/23] COLO nic: setup/teardown colo nic devices, Yang Hongyang, 2014/09/23