>From 3e74234e11b00ad78e9e0dc9f285e8c51ae3da37 Mon Sep 17 00:00:00 2001
From: Dan Winship <[email protected]>
Date: Mon, 14 Nov 2011 14:52:40 -0500
Subject: [PATCH] Infiniband: add transport-mode property

Add transport-mode property to NMSettingInfiniband (and parse it
correctly in ifcfg-rh), and set it up properly on the device in
NMDeviceInfiniband.
---
 include/NetworkManager.h               |    3 ++
 libnm-util/libnm-util.ver              |    1 +
 libnm-util/nm-setting-infiniband.c     |   55 ++++++++++++++++++++++++++++++++
 libnm-util/nm-setting-infiniband.h     |    6 ++-
 src/nm-device-infiniband.c             |   49 ++++++++++++++++++++++++++++
 src/nm-device.c                        |    2 +
 src/settings/plugins/ifcfg-rh/reader.c |    3 ++
 7 files changed, 117 insertions(+), 2 deletions(-)

diff --git a/include/NetworkManager.h b/include/NetworkManager.h
index 79cad05..3f97e28 100644
--- a/include/NetworkManager.h
+++ b/include/NetworkManager.h
@@ -479,6 +479,9 @@ typedef enum {
        /* GSM Modem's SIM wrong */
        NM_DEVICE_STATE_REASON_GSM_SIM_WRONG = 48,
 
+       /* Infiniband device does not support connected mode */
+       NM_DEVICE_STATE_REASON_INFINIBAND_MODE = 49,
+
        /* Unused */
        NM_DEVICE_STATE_REASON_LAST = 0xFFFF
 } NMDeviceStateReason;
diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index 84ef039..d2c4318 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -242,6 +242,7 @@ global:
        nm_setting_infiniband_error_quark;
        nm_setting_infiniband_get_mac_address;
        nm_setting_infiniband_get_mtu;
+       nm_setting_infiniband_get_transport_mode;
        nm_setting_infiniband_get_type;
        nm_setting_infiniband_new;
        nm_setting_ip4_config_add_address;
diff --git a/libnm-util/nm-setting-infiniband.c 
b/libnm-util/nm-setting-infiniband.c
index 10a20ad..9e8ec9a 100644
--- a/libnm-util/nm-setting-infiniband.c
+++ b/libnm-util/nm-setting-infiniband.c
@@ -81,6 +81,7 @@ G_DEFINE_TYPE (NMSettingInfiniband, nm_setting_infiniband, 
NM_TYPE_SETTING)
 
 typedef struct {
        GByteArray *mac_address;
+       char *transport_mode;
        guint32 mtu;
 } NMSettingInfinibandPrivate;
 
@@ -88,6 +89,7 @@ enum {
        PROP_0,
        PROP_MAC_ADDRESS,
        PROP_MTU,
+       PROP_TRANSPORT_MODE,
 
        LAST_PROP
 };
@@ -133,6 +135,23 @@ nm_setting_infiniband_get_mtu (NMSettingInfiniband 
*setting)
        return NM_SETTING_INFINIBAND_GET_PRIVATE (setting)->mtu;
 }
 
+/**
+ * nm_setting_infiniband_get_transport_mode:
+ * @setting: the #NMSettingInfiniband
+ *
+ * Returns the transport mode for this device. Either 'datagram' or
+ * 'connected'.
+ *
+ * Returns: the IPoIB transport mode
+ **/
+const char *
+nm_setting_infiniband_get_transport_mode (NMSettingInfiniband *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_INFINIBAND (setting), NULL);
+
+       return NM_SETTING_INFINIBAND_GET_PRIVATE (setting)->transport_mode;
+}
+
 
 static gboolean
 verify (NMSetting *setting, GSList *all_settings, GError **error)
@@ -147,6 +166,20 @@ verify (NMSetting *setting, GSList *all_settings, GError 
**error)
                return FALSE;
        }
 
+       if (!g_strcmp0 (priv->transport_mode, "datagram")) {
+               if (priv->mtu > 2044)
+                       priv->mtu = 2044;
+       } else if (!g_strcmp0 (priv->transport_mode, "connected")) {
+               if (priv->mtu > 65520)
+                       priv->mtu = 65520;
+       } else {
+               g_set_error (error,
+                            NM_SETTING_INFINIBAND_ERROR,
+                            NM_SETTING_INFINIBAND_ERROR_INVALID_PROPERTY,
+                            NM_SETTING_INFINIBAND_TRANSPORT_MODE);
+               return FALSE;
+       }
+
        return TRUE;
 }
 
@@ -161,6 +194,7 @@ finalize (GObject *object)
 {
        NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE 
(object);
 
+       g_free (priv->transport_mode);
        if (priv->mac_address)
                g_byte_array_free (priv->mac_address, TRUE);
 
@@ -182,6 +216,10 @@ set_property (GObject *object, guint prop_id,
        case PROP_MTU:
                priv->mtu = g_value_get_uint (value);
                break;
+       case PROP_TRANSPORT_MODE:
+               g_free (priv->transport_mode);
+               priv->transport_mode = g_value_dup_string (value);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -201,6 +239,9 @@ get_property (GObject *object, guint prop_id,
        case PROP_MTU:
                g_value_set_uint (value, nm_setting_infiniband_get_mtu 
(setting));
                break;
+       case PROP_TRANSPORT_MODE:
+               g_value_set_string (value, 
nm_setting_infiniband_get_transport_mode (setting));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -255,5 +296,19 @@ nm_setting_infiniband_class_init (NMSettingInfinibandClass 
*setting_class)
                                    "multiple frames.",
                                    0, G_MAXUINT32, 0,
                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT | 
NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_FUZZY_IGNORE));
+
+       /**
+        * NMSettingInfiniband:transport-mode:
+        *
+        * The IP-over-Inifiniband transport mode. Either 'datagram' or
+        * 'connected'.
+        **/
+       g_object_class_install_property
+               (object_class, PROP_TRANSPORT_MODE,
+                g_param_spec_string (NM_SETTING_INFINIBAND_TRANSPORT_MODE,
+                                                         "Transport Mode",
+                                                         "The IPoIB transport 
mode. Either 'datagram' or 'connected'.",
+                                                         "datagram",
+                                                         G_PARAM_READWRITE | 
G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
 }
 
diff --git a/libnm-util/nm-setting-infiniband.h 
b/libnm-util/nm-setting-infiniband.h
index 4707cb9..8d1831b 100644
--- a/libnm-util/nm-setting-infiniband.h
+++ b/libnm-util/nm-setting-infiniband.h
@@ -54,8 +54,9 @@ GType nm_setting_infiniband_error_get_type (void);
 #define NM_SETTING_INFINIBAND_ERROR nm_setting_infiniband_error_quark ()
 GQuark nm_setting_infiniband_error_quark (void);
 
-#define NM_SETTING_INFINIBAND_MAC_ADDRESS "mac-address"
-#define NM_SETTING_INFINIBAND_MTU         "mtu"
+#define NM_SETTING_INFINIBAND_MAC_ADDRESS    "mac-address"
+#define NM_SETTING_INFINIBAND_MTU            "mtu"
+#define NM_SETTING_INFINIBAND_TRANSPORT_MODE "transport-mode"
 
 typedef struct {
        NMSetting parent;
@@ -76,6 +77,7 @@ GType nm_setting_infiniband_get_type (void);
 NMSetting *       nm_setting_infiniband_new                (void);
 const GByteArray *nm_setting_infiniband_get_mac_address    
(NMSettingInfiniband *setting);
 guint32           nm_setting_infiniband_get_mtu            
(NMSettingInfiniband *setting);
+const char *      nm_setting_infiniband_get_transport_mode 
(NMSettingInfiniband *setting);
 
 G_END_DECLS
 
diff --git a/src/nm-device-infiniband.c b/src/nm-device-infiniband.c
index 822d4ce..46ee1cc 100644
--- a/src/nm-device-infiniband.c
+++ b/src/nm-device-infiniband.c
@@ -217,6 +217,54 @@ real_get_best_auto_connection (NMDevice *dev,
        return NULL;
 }
 
+static NMActStageReturn
+real_act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
+{
+       NMActRequest *req;
+       NMConnection *connection;
+       NMSettingInfiniband *s_infiniband;
+       const char *transport_mode;
+       char *mode_path, *mode_value;
+       gboolean ok;
+
+       g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
+
+       req = nm_device_get_act_request (dev);
+       g_return_val_if_fail (req != NULL, NM_ACT_STAGE_RETURN_FAILURE);
+
+       connection = nm_act_request_get_connection (req);
+       g_assert (connection);
+       s_infiniband = nm_connection_get_setting_infiniband (connection);
+       g_assert (s_infiniband);
+
+       transport_mode = nm_setting_infiniband_get_transport_mode 
(s_infiniband);
+
+       mode_path = g_strdup_printf ("/sys/class/net/%s/mode",
+                                                                
nm_device_get_iface (dev));
+       if (!g_file_test (mode_path, G_FILE_TEST_EXISTS)) {
+               g_free (mode_path);
+
+               if (!strcmp (transport_mode, "datagram"))
+                       return NM_ACT_STAGE_RETURN_SUCCESS;
+               else {
+                       *reason = NM_DEVICE_STATE_REASON_INFINIBAND_MODE;
+                       return NM_ACT_STAGE_RETURN_FAILURE;
+               }
+       }
+
+       mode_value = g_strdup_printf ("%s\n", transport_mode);
+       ok = nm_utils_do_sysctl (mode_path, mode_value);
+       g_free (mode_value);
+       g_free (mode_path);
+
+       if (!ok) {
+               *reason = NM_DEVICE_STATE_REASON_CONFIG_FAILED;
+               return NM_ACT_STAGE_RETURN_FAILURE;
+       }
+
+       return NM_ACT_STAGE_RETURN_SUCCESS;
+}
+
 static void
 real_ip4_config_pre_commit (NMDevice *self, NMIP4Config *config)
 {
@@ -434,6 +482,7 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass 
*klass)
        parent_class->check_connection_compatible = 
real_check_connection_compatible;
        parent_class->complete_connection = real_complete_connection;
 
+       parent_class->act_stage1_prepare = real_act_stage1_prepare;
        parent_class->ip4_config_pre_commit = real_ip4_config_pre_commit;
        parent_class->spec_match_list = spec_match_list;
        parent_class->connection_match_config = connection_match_config;
diff --git a/src/nm-device.c b/src/nm-device.c
index ced8ff3..704b7b7 100644
--- a/src/nm-device.c
+++ b/src/nm-device.c
@@ -4065,6 +4065,8 @@ reason_to_string (NMDeviceStateReason reason)
                return "gsm-sim-puk-required";
        case NM_DEVICE_STATE_REASON_GSM_SIM_WRONG:
                return "gsm-sim-wrong";
+       case NM_DEVICE_STATE_REASON_INFINIBAND_MODE:
+               return "infiniband-mode";
        default:
                break;
        }
diff --git a/src/settings/plugins/ifcfg-rh/reader.c 
b/src/settings/plugins/ifcfg-rh/reader.c
index 521a9d0..9a9be91 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -3362,6 +3362,9 @@ make_infiniband_setting (shvarFile *ifcfg,
                return NULL;
        }
 
+       if (svTrueValue (ifcfg, "CONNECTED_MODE", FALSE))
+               g_object_set (s_infiniband, 
NM_SETTING_INFINIBAND_TRANSPORT_MODE, "connected", NULL);
+
        if (!nm_controlled && !*unmanaged) {
                /* If NM_CONTROLLED=no but there wasn't a MAC address, notify
                   the user that the device cannot be unmanaged.
-- 
1.7.7.3

_______________________________________________
networkmanager-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to