manager: downgrade error message for missing dependencies

At startup the manager tries to create virtual devices without a
specific order and spits warnings when a device can't be realized
because the parent device is not yet created. These failures are not
something the user should worry about because the creation will be
retried when the parent appears.

A better approach is to return an error code from the device's
create_and_realize() telling that it failed because the parent doesn't
exist. In this way, the manager knows that the device isn't ready and
can avoid printing warning messages.
This commit is contained in:
Beniamino Galvani
2017-09-14 09:26:51 +02:00
parent 74845f80ec
commit 41b0e8c5a5
7 changed files with 20 additions and 10 deletions

View File

@@ -143,6 +143,8 @@ GQuark nm_crypto_error_quark (void);
* activation request (eg, the #NMAccessPoint or #NMWimaxNsp) was not * activation request (eg, the #NMAccessPoint or #NMWimaxNsp) was not
* found. * found.
* @NM_DEVICE_ERROR_VERSION_ID_MISMATCH: the version id did not match. * @NM_DEVICE_ERROR_VERSION_ID_MISMATCH: the version id did not match.
* @NM_DEVICE_ERROR_MISSING_DEPENDENCIES: the requested operation could not
* be completed due to missing dependencies.
* *
* Device-related errors. * Device-related errors.
* *
@@ -160,6 +162,7 @@ typedef enum {
NM_DEVICE_ERROR_NOT_ALLOWED, /*< nick=NotAllowed >*/ NM_DEVICE_ERROR_NOT_ALLOWED, /*< nick=NotAllowed >*/
NM_DEVICE_ERROR_SPECIFIC_OBJECT_NOT_FOUND, /*< nick=SpecificObjectNotFound >*/ NM_DEVICE_ERROR_SPECIFIC_OBJECT_NOT_FOUND, /*< nick=SpecificObjectNotFound >*/
NM_DEVICE_ERROR_VERSION_ID_MISMATCH, /*< nick=VersionIdMismatch >*/ NM_DEVICE_ERROR_VERSION_ID_MISMATCH, /*< nick=VersionIdMismatch >*/
NM_DEVICE_ERROR_MISSING_DEPENDENCIES, /*< nick=MissingDependencies >*/
} NMDeviceError; } NMDeviceError;
#define NM_DEVICE_ERROR nm_device_error_quark () #define NM_DEVICE_ERROR nm_device_error_quark ()

View File

@@ -269,13 +269,13 @@ create_and_realize (NMDevice *device,
} }
if (!parent) { if (!parent) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_MISSING_DEPENDENCIES,
"InfiniBand partitions can not be created without a parent interface"); "InfiniBand partitions can not be created without a parent interface");
return FALSE; return FALSE;
} }
if (!NM_IS_DEVICE_INFINIBAND (parent)) { if (!NM_IS_DEVICE_INFINIBAND (parent)) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_MISSING_DEPENDENCIES,
"Parent interface %s must be an InfiniBand interface", "Parent interface %s must be an InfiniBand interface",
nm_device_get_iface (parent)); nm_device_get_iface (parent));
return FALSE; return FALSE;
@@ -283,7 +283,7 @@ create_and_realize (NMDevice *device,
priv->parent_ifindex = nm_device_get_ifindex (parent); priv->parent_ifindex = nm_device_get_ifindex (parent);
if (priv->parent_ifindex <= 0) { if (priv->parent_ifindex <= 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_MISSING_DEPENDENCIES,
"failed to get InfiniBand parent %s ifindex", "failed to get InfiniBand parent %s ifindex",
nm_device_get_iface (parent)); nm_device_get_iface (parent));
return FALSE; return FALSE;

View File

@@ -692,7 +692,7 @@ create_and_realize (NMDevice *device,
g_assert (s_macsec); g_assert (s_macsec);
if (!parent) { if (!parent) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_MISSING_DEPENDENCIES,
"MACsec devices can not be created without a parent interface"); "MACsec devices can not be created without a parent interface");
return FALSE; return FALSE;
} }

View File

@@ -234,7 +234,7 @@ create_and_realize (NMDevice *device,
parent_ifindex = parent ? nm_device_get_ifindex (parent) : 0; parent_ifindex = parent ? nm_device_get_ifindex (parent) : 0;
if (parent_ifindex <= 0) { if (parent_ifindex <= 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_MISSING_DEPENDENCIES,
"MACVLAN devices can not be created without a parent interface"); "MACVLAN devices can not be created without a parent interface");
g_return_val_if_fail (!parent, FALSE); g_return_val_if_fail (!parent, FALSE);
return FALSE; return FALSE;

View File

@@ -209,7 +209,7 @@ create_and_realize (NMDevice *device,
int parent_ifindex; int parent_ifindex;
if (!parent) { if (!parent) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_MISSING_DEPENDENCIES,
"PPP devices can not be created without a parent interface"); "PPP devices can not be created without a parent interface");
return FALSE; return FALSE;
} }

View File

@@ -231,14 +231,14 @@ create_and_realize (NMDevice *device,
g_assert (s_vlan); g_assert (s_vlan);
if (!parent) { if (!parent) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_MISSING_DEPENDENCIES,
"VLAN devices can not be created without a parent interface"); "VLAN devices can not be created without a parent interface");
return FALSE; return FALSE;
} }
parent_ifindex = nm_device_get_ifindex (parent); parent_ifindex = nm_device_get_ifindex (parent);
if (parent_ifindex <= 0) { if (parent_ifindex <= 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_MISSING_DEPENDENCIES,
"cannot retrieve ifindex of interface %s (%s): skip VLAN creation for now", "cannot retrieve ifindex of interface %s (%s): skip VLAN creation for now",
nm_device_get_iface (parent), nm_device_get_iface (parent),
nm_device_get_type_desc (parent)); nm_device_get_type_desc (parent));

View File

@@ -1301,6 +1301,7 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
gs_free char *iface = NULL; gs_free char *iface = NULL;
NMDevice *device = NULL, *parent = NULL; NMDevice *device = NULL, *parent = NULL;
GError *error = NULL; GError *error = NULL;
NMLogLevel log_level;
g_return_val_if_fail (NM_IS_MANAGER (self), NULL); g_return_val_if_fail (NM_IS_MANAGER (self), NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
@@ -1381,8 +1382,14 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
/* Create any backing resources the device needs */ /* Create any backing resources the device needs */
if (!nm_device_create_and_realize (device, connection, parent, &error)) { if (!nm_device_create_and_realize (device, connection, parent, &error)) {
_LOG3W (LOGD_DEVICE, connection, "couldn't create the device: %s", log_level = g_error_matches (error,
error->message); NM_DEVICE_ERROR,
NM_DEVICE_ERROR_MISSING_DEPENDENCIES)
? LOGL_DEBUG
: LOGL_ERR;
_NMLOG3 (log_level, LOGD_DEVICE, connection,
"couldn't create the device: %s",
error->message);
g_error_free (error); g_error_free (error);
remove_device (self, device, FALSE, TRUE); remove_device (self, device, FALSE, TRUE);
return NULL; return NULL;