Commit 8be049a5 authored by Christian Kellner's avatar Christian Kellner
Browse files

manager+sysfs: wait for hosts instead of domains

In the manager's initialization, we want to make sure that we have
at least one domain controller online in order detect the security
level. Additionally, now that stale domains are cleaned up on store
upgrades, we also want to make sure that domain controllers are
fully initialized and the corresponding BotlDomain is online, so
that we don't accidentally clean up a non-stale domain. In order
to do so, we wait for at least one host controller to be present,
not just the plain domain. For this we enumerate all domains and
for each domain we enumerate the thunderbolt udev device directly
beneath it (should only be one).
Rename and re-purpose the various `count_domains` functions.
Adapt the test to add host devices to the corresponding domains.
parent f3395f9c
Pipeline #233650 passed with stage
in 6 minutes and 2 seconds
......@@ -2330,7 +2330,7 @@ manager_maybe_power_controller (BoltManager *mgr)
if (can_force_power == FALSE)
return NULL;
n = bolt_udev_count_domains (mgr->udev, &err);
n = bolt_udev_count_hosts (mgr->udev, &err);
if (n < 0)
{
bolt_warn_err (err, LOG_TOPIC ("udev"),
......@@ -2356,7 +2356,7 @@ manager_maybe_power_controller (BoltManager *mgr)
for (int i = 0; i < 25 && n < 1; i++)
{
g_usleep (200000); /* 200 000 us = 0.2s */
n = bolt_udev_count_domains (mgr->udev, NULL);
n = bolt_udev_count_hosts (mgr->udev, NULL);
}
out:
......
......@@ -150,10 +150,44 @@ bolt_sysfs_security_for_device (struct udev_device *udev,
return s;
}
static int
bolt_syfs_count_tb_devices (struct udev *udev,
struct udev_device *parent,
GError **error)
{
struct udev_enumerate *e;
struct udev_list_entry *l, *devices;
int r, count = 0;
e = udev_enumerate_new (udev);
udev_enumerate_add_match_subsystem (e, "thunderbolt");
udev_enumerate_add_match_property (e, "DEVTYPE", "thunderbolt_device");
if (parent)
udev_enumerate_add_match_parent (e, parent);
r = udev_enumerate_scan_devices (e);
if (r < 0)
{
g_set_error (error, BOLT_ERROR, BOLT_ERROR_UDEV,
"failed to scan udev: %s",
g_strerror (-r));
return r;
}
devices = udev_enumerate_get_list_entry (e);
udev_list_entry_foreach (l, devices)
count++;
udev_enumerate_unref (e);
return count;
}
int
bolt_sysfs_count_domains (struct udev *udev,
GError **error)
bolt_sysfs_count_hosts (struct udev *udev,
GError **error)
{
struct udev_enumerate *e;
struct udev_list_entry *l, *devices;
......@@ -175,7 +209,23 @@ bolt_sysfs_count_domains (struct udev *udev,
devices = udev_enumerate_get_list_entry (e);
udev_list_entry_foreach (l, devices)
count++;
{
struct udev_device *udevice = NULL;
const char *syspath;
int n;
syspath = udev_list_entry_get_name (l);
udevice = udev_device_new_from_syspath (udev, syspath);
if (udevice == NULL)
continue;
n = bolt_syfs_count_tb_devices (udev, udevice, NULL);
if (n > 0)
count++;
udev_device_unref (udevice);
}
udev_enumerate_unref (e);
......
......@@ -49,8 +49,8 @@ struct udev_device * bolt_sysfs_domain_for_device (struct udev_device *udev,
BoltSecurity bolt_sysfs_security_for_device (struct udev_device *udev,
GError **error);
int bolt_sysfs_count_domains (struct udev *udev,
GError **error);
int bolt_sysfs_count_hosts (struct udev *udev,
GError **error);
gboolean bolt_sysfs_nhi_id_for_domain (struct udev_device *udev,
guint32 *id,
......
......@@ -407,12 +407,12 @@ bolt_udev_device_new_from_syspath (BoltUdev *udev,
/* thunderbolt specific helpers */
int
bolt_udev_count_domains (BoltUdev *udev,
GError **error)
bolt_udev_count_hosts (BoltUdev *udev,
GError **error)
{
g_return_val_if_fail (BOLT_IS_UDEV (udev), -1);
return bolt_sysfs_count_domains (udev->udev, error);
return bolt_sysfs_count_hosts (udev->udev, error);
}
gboolean
......
......@@ -45,8 +45,8 @@ struct udev_device * bolt_udev_device_new_from_syspath (BoltUdev *udev,
GError **error);
/* thunderbolt specific helpers */
int bolt_udev_count_domains (BoltUdev *udev,
GError **error);
int bolt_udev_count_hosts (BoltUdev *udev,
GError **error);
gboolean bolt_udev_detect_force_power (BoltUdev *udev,
char **path,
......
......@@ -367,7 +367,6 @@ static void
test_sysfs_domains (TestSysfs *tt, gconstpointer user)
{
g_autoptr(GError) err = NULL;
const char *uid = "884c6edd-7118-4b21-b186-b02d396ecca0";
const char *ids[5];
BoltSecurity sl[5] = {BOLT_SECURITY_NONE,
BOLT_SECURITY_DPONLY,
......@@ -379,7 +378,7 @@ test_sysfs_domains (TestSysfs *tt, gconstpointer user)
BoltDomain *iter;
int n;
n = bolt_sysfs_count_domains (tt->udev, &err);
n = bolt_sysfs_count_hosts (tt->udev, &err);
g_assert_no_error (err);
g_assert_cmpint (n, ==, 0);
......@@ -389,14 +388,29 @@ test_sysfs_domains (TestSysfs *tt, gconstpointer user)
g_autoptr(udev_device) udevice = NULL;
g_autoptr(BoltDomain) dom = NULL; /* the list will own reference */
const char *syspath;
char uid[37] = {0, };
MockDevId hostid = {
.vendor_id = 0x42,
.vendor_name = "GNOME.org",
.device_id = 0x42,
.device_name = "Laptop",
.unique_id = (const char *) &uid,
};
g_snprintf (uid, sizeof (uid), "884c6edd-7118-4b21-b186-b02d396ecc%02x",
(unsigned int) i);
ids[i] = mock_sysfs_domain_add (tt->sysfs, sl[i], NULL);
syspath = mock_sysfs_domain_get_syspath (tt->sysfs, ids[i]);
udevice = udev_device_new_from_syspath (tt->udev, syspath);
mock_sysfs_host_add (tt->sysfs, ids[i], &hostid);
g_assert_nonnull (udevice);
g_debug ("uid: %s", uid);
dom = bolt_domain_new_for_udev (udevice, uid, &err);
g_assert_no_error (err);
g_assert_nonnull (dom);
......@@ -415,7 +429,7 @@ test_sysfs_domains (TestSysfs *tt, gconstpointer user)
==,
G_N_ELEMENTS (sl));
g_assert_cmpint (bolt_sysfs_count_domains (tt->udev, NULL),
g_assert_cmpint (bolt_sysfs_count_hosts (tt->udev, NULL),
==,
(int) G_N_ELEMENTS (sl));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment