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

[PATCH master 04/13] Wait for activation of specific devices instead of NM



Port from rhel6-branch
Resolves: rhbz#638131
---
 loader/net.c            |   51 +++++++++++++++++++++++++++++++++-------------
 loader/net.h            |    2 +-
 pyanaconda/isys/iface.c |   29 ++++++++++++++++++++++++++
 pyanaconda/isys/iface.h |    2 +
 4 files changed, 68 insertions(+), 16 deletions(-)

diff --git a/loader/net.c b/loader/net.c
index 9829898..58a1c10 100644
--- a/loader/net.c
+++ b/loader/net.c
@@ -498,7 +498,7 @@ int readNetConfig(char * device, iface_t * iface,
             return LOADER_BACK;
         }
 
-        i = get_connection(iface);
+        i = wait_for_iface_activation(iface->device);
         newtPopWindow();
 
         if (i > 0) {
@@ -564,7 +564,7 @@ int readNetConfig(char * device, iface_t * iface,
         return LOADER_BACK;
     }
 
-    i = get_connection(iface);
+    i = wait_for_iface_activation(iface->device);
     newtPopWindow();
 
     if (i > 0) {
@@ -1921,6 +1921,11 @@ int activateDevice(struct loaderData_s * loaderData, iface_t * iface) {
             break;
         } while (1);
 
+        if (is_iface_activated(iface->device)) {
+            logMessage(INFO, "device %s is already activated", iface->device);
+            return 0;
+        }
+
         /* we don't want to end up asking about interface more than once
          * if we're in a kickstart-ish case (#100724) */
         loaderData->netDev_set = 1;
@@ -2003,29 +2008,30 @@ void splitHostname (char *str, char **host, char **port)
 }
 
 /*
- * Start NetworkManager and wait for a valid link, return non-zero on error.
+ * Wait for activation of iface by NetworkManager, return non-zero on error.
  */
-int get_connection(iface_t *iface) {
-    int count = 0;
+int wait_for_iface_activation(char *ifname) {
+    int count = 0, i;
     NMClient *client = NULL;
-    NMState state;
     GMainLoop *loop;
     GMainContext *ctx;
+    const GPtrArray *devices;
+    NMDevice *device = NULL;
 
-    if (iface == NULL) {
+    if (ifname == NULL) {
         return 1;
     }
 
-    logMessage(DEBUGLVL, "configuring device %s", iface->device);
+    logMessage(DEBUGLVL, "activating device %s", ifname);
 
     /* display status */
     if (FL_CMDLINE(flags)) {
         printf(_("Waiting for NetworkManager to configure %s.\n"),
-               iface->device);
+               ifname);
     } else {
         winStatus(55, 3, NULL,
                   _("Waiting for NetworkManager to configure %s.\n"),
-                  iface->device, 0);
+                  ifname, 0);
     }
 
     g_type_init();
@@ -2037,6 +2043,22 @@ int get_connection(iface_t *iface) {
         return 2;
     }
 
+    devices = nm_client_get_devices(client);
+    for (i = 0; i < devices->len; i++) {
+        NMDevice *candidate = g_ptr_array_index(devices, i);
+        const char *name = nm_device_get_iface(candidate);
+        if (!strcmp(name, ifname)) {
+            device = candidate;
+            break;
+        }
+    }
+    if (device == NULL) {
+        logMessage(ERROR, "%s (%d): network device %s not found",
+                   __func__, __LINE__, ifname);
+        g_object_unref(client);
+        return 3;
+    }
+
     /* Create a loop for processing dbus signals */
     loop = g_main_loop_new(NULL, FALSE);
     ctx = g_main_loop_get_context(loop);
@@ -2052,12 +2074,11 @@ int get_connection(iface_t *iface) {
         while (g_main_context_pending (ctx)) {
             g_main_context_iteration (ctx, FALSE);
         }
-        state = nm_client_get_state(client);
-
-        if (state == NM_STATE_CONNECTED) {
-            logMessage(INFO, "%s (%d): NetworkManager connected",
-                       __func__, __LINE__);
+        if (nm_device_get_state(device) == NM_DEVICE_STATE_ACTIVATED) {
+            logMessage(INFO, "%s (%d): device %s activated",
+                       __func__, __LINE__, ifname);
             res_init();
+            g_main_loop_unref(loop);
             g_object_unref(client);
             return 0;
         }
diff --git a/loader/net.h b/loader/net.h
index 690d644..7e3ed16 100644
--- a/loader/net.h
+++ b/loader/net.h
@@ -74,6 +74,6 @@ int kickstartNetworkUp(struct loaderData_s * loaderData,
 int activateDevice(struct loaderData_s * loaderData,
                    iface_t * iface);
 void splitHostname (char *str, char **host, char **port);
-int get_connection(iface_t * iface);
+int wait_for_iface_activation(char * ifname);
 
 #endif
diff --git a/pyanaconda/isys/iface.c b/pyanaconda/isys/iface.c
index 0a9ad6c..391c38e 100644
--- a/pyanaconda/isys/iface.c
+++ b/pyanaconda/isys/iface.c
@@ -443,6 +443,35 @@ gboolean is_nm_running(void) {
     return running;
 }
 
+gboolean is_iface_activated(char * ifname) {
+    int i, state;
+    NMClient *client = NULL;
+    const GPtrArray *devices;
+
+    g_type_init();
+
+    client = nm_client_new();
+    if (!client)
+        return FALSE;
+
+    devices = nm_client_get_devices(client);
+    for (i = 0; i < devices->len; i++) {
+        NMDevice *candidate = g_ptr_array_index(devices, i);
+        const char *devname = nm_device_get_iface(candidate);
+        if (strcmp(ifname, devname))
+            continue;
+        state = nm_device_get_state(candidate);
+        g_object_unref(client);
+        if (state == NM_DEVICE_STATE_ACTIVATED)
+            return TRUE;
+        else
+            return FALSE;
+    }
+
+    g_object_unref(client);
+    return FALSE;
+}
+
 /*
  * Wait for NetworkManager to appear on the system bus
  */
diff --git a/pyanaconda/isys/iface.h b/pyanaconda/isys/iface.h
index b7eaa6f..b76b3a7 100644
--- a/pyanaconda/isys/iface.h
+++ b/pyanaconda/isys/iface.h
@@ -152,6 +152,8 @@ int iface_have_in6_addr(struct in6_addr *addr6);
  */
 gboolean is_nm_connected(void);
 
+gboolean is_iface_activated(char * ifname);
+
 /*
  * Start NetworkManager
  */
-- 
1.7.2


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