1. 30 Nov, 2020 5 commits
    • Christian Kellner's avatar
      glue: fix memory leak in conv_flags_to_str · 0b97bcaa
      Christian Kellner authored
      The function 'bolt_flags_class_to_string' returns a dynamically
      allocated string. This was previously not freed, creating a memory
      leak. Its ownership is now correctly transferred to the GVariant
      instead.
      0b97bcaa
    • Christian Kellner's avatar
      glue: plug tiny memory leak by freeing custom_id · 27ae4440
      Christian Kellner authored
      The memory for custom_id, to identify a custom conversion, is
      dynamically allocated, but was not freed in bolt_wire_conv_unref.
      Explicitly set it to NULL in the other constructor so we don't
      attempt to free invalid memory.
      27ae4440
    • Christian Kellner's avatar
      guard: ensure guard->path is always freed · 6f7b323f
      Christian Kellner authored
      Normally 'path' gets freed in bolt_guard_remove, which is called
      from the dispose method of the BoltGuard. There is one exception
      though: when the pipe (named fifo) is still active, we do not
      unlink the path, since we want to recover that guard later. In
      that case the memory for path will be leaked. Add an additional
      g_clear_pointer for path in the 'finalize' method to ensure that
      path always gets freed.
      6f7b323f
    • Christian Kellner's avatar
      guard: add pre-condition check in guard_save · 48cdeb20
      Christian Kellner authored
      Ensure that we are not saved already in 'bolt_guard_save'.
      48cdeb20
    • Christian Kellner's avatar
      test: fix various small memory leaks · c4e35871
      Christian Kellner authored
      Add missing g_clear_pointer / g_clear_object calls when a pointer
      was re-used during the tests. In MockSysfs, free the force-power
      path. In test-glue, use g_autoptr for all allocated GParamSpecs.
      c4e35871
  2. 28 Nov, 2020 16 commits
    • Christian Kellner's avatar
      manager: plug tiny leak on finalize · 78fe16e3
      Christian Kellner authored
      Properly unref the config key file when finalizing the object.
      78fe16e3
    • Christian Kellner's avatar
      device: use host ident for host devices · 6a6968a7
      Christian Kellner authored
      If a device is a host device, i.e. does not have a parent device, use
      the new host identification method, which will transparently fall
      back to use the SMBIOS/DMI information, in case the standard
      device information is not available, which is the case on embedded
      thunderbolt controllers.
      6a6968a7
    • Christian Kellner's avatar
      test/sysfs: check host identification · 290143fb
      Christian Kellner authored
      Add a test to check all host identification method code paths,
      including the standard one via 'bolt_sysfs_device_ident' as
      well as the fallback to DMI information.
      290143fb
    • Christian Kellner's avatar
      test/mock: add the ability to mock the DMI id dev · 2dd16dbb
      Christian Kellner authored
      Add the ability to mock the SMBBIOS/DMI sysfs device. For now only
      the sys_vendor, product_{name, version} attributes are supported,
      which is what we us in bolt.
      2dd16dbb
    • Christian Kellner's avatar
      test/mock: remove force power in finalize · 4ab9f056
      Christian Kellner authored
      If the force power device has not yet been removed, do so in the
      'finalize' method of the MockSysfs object. Move the un-ref'ing of
      the umockdev TestBed down so it happens after the hash tables
      are destroyed.
      4ab9f056
    • Christian Kellner's avatar
      test/mock-sysfs: ability to remove the host · dfbcf877
      Christian Kellner authored
      Add a new method that allows to remove a host device, i.e. unplug
      the device and remove it from the associated domain.
      dfbcf877
    • Christian Kellner's avatar
      sysfs: method to perform host identification · de337834
      Christian Kellner authored
      Add a new method to do host identification, which will first check
      if the host device can be identified via the normal device ident
      method. This will fail in case of embedded thunderbolt controller,
      which do not have a DROM and have no device and vendor information
      and thus no corresponding sysfs attributes. In that case we fall
      back to using the SMBIOS/DMI information for the system to ident
      the host.
      de337834
    • Christian Kellner's avatar
      names: add dmi id sysfs path and attribute names · 0defa936
      Christian Kellner authored
      The SMBIOS/DMI information is exported to userspace via sysfs,
      which is convenient, because the information can thus be read
      conveniently and as a non-root user.
      Define constants for relevant information that can be used to
      identify the computer / host, like the product, vendor and the
      general path to the sysfs device providing that information.
      0defa936
    • Christian Kellner's avatar
      test/syfs: check the sysfs_device_ident method · 520ef841
      Christian Kellner authored
      Check the 'bolt_sysfs_device_ident' method and the newly added
      'BoltIdent' structs.
      520ef841
    • Christian Kellner's avatar
      device+sysfs: new device ident struct · 95ef1b8b
      Christian Kellner authored
      Introduce a new BoltIdent struct that holds the name and vendor
      information for a thunderbolt device together with a reference
      to the 'struct udev_device' that provides those information.
      This binds the lifetime of the char pointers directly to the
      struct where they are contained and thus prevent accidental
      bugs where the strings are used after the udev_device is not
      valid anymore (got un-referenced).
      Since the struct holds a reference, define a clear method for
      it and the corresponding auto-cleanup method.
      Use the new BoltIdent struct for 'bolt_device_ident'. Re-factor
      it to not use a loop anymore.
      
      The read_sysattr_name helper, use in 'bolt_device_ident' now
      uses the recently introduced sysattr value getter.
      95ef1b8b
    • Christian Kellner's avatar
      sysfs: new attribute getter with glib style errors · 1adb3d00
      Christian Kellner authored
      Add a new sysfs attribute getter that does error reporting via
      GErrors. This will be convenient in a lot of places where the
      error handling is duplicated. Use it in the existing unique_id
      helper.
      1adb3d00
    • Christian Kellner's avatar
      manager: relabel Dell Inc. → Dell · e3282a50
      Christian Kellner authored
      This is mostly in preparation for the host identification via DMI
      where 'Dell Inc.' is used, whereby the thunderbolt host controller
      usually identifies itself as "Dell". To stay consistent we relabel
      the dmi id one.
      e3282a50
    • Christian Kellner's avatar
      manager: don't de-duplicate host device names · 9094fa36
      Christian Kellner authored
      When labeling a device, we normally do a duplication check, and
      if we find more than once device with the same name, we append
      a number suffix. Let's not do that for host devices, since they
      are arguably represent the same thing, even if technically the
      are different controllers with their own unique id.
      9094fa36
    • Christian Kellner's avatar
      manager: only import hosts with stable uuids · fbde3fd0
      Christian Kellner authored
      We started auto-importing the host device in commit f9205d16, with
      the reason that in non-native enumeration mode, the host device
      will disappear and the generation information will thus not be
      available anymore. But on embedded thunderbolt controller, the
      host device has an unstable unique_id, which means that host device
      will have a different uuid on next boot and thus can not be matched
      with the previously stored one. Thus stale host devices would
      accumulate in the store. Luckily, on embedded thunderbolt, the host
      device does not have device/vendor sysfs attributes, which means
      that currently creating a BoltDevice for it will not work, which is
      a bug, that also prevents stale host devices for now. Once that bug
      will get fixed we were to get stale host records, unless we don't
      store those host devices. To do so we check if the domain of the
      host device is stored which is an indicator of the uuid stability,
      checked via the pci id of the native host interface. If the domain
      is stored we store the host and vice versa.
      fbde3fd0
    • Christian Kellner's avatar
      device: move device identification to sysfs · 09aa6c53
      Christian Kellner authored
      Move the device identification, i.e. name and vendor detection, to
      bolt-sysfs.c as 'bolt_sysfs_device_ident'. This uses the existing
      helper function to first check `${attr}_name` for vendor and name
      attributes and then fall back to plain `${attr}`.
      09aa6c53
    • Christian Kellner's avatar
      device: add domain getter · f653fee2
      Christian Kellner authored
      Add the missing getter for the domain associated with a device, or
      NULL if there is none, i.e. the device is offline.
      f653fee2
  3. 24 Nov, 2020 6 commits
  4. 20 Nov, 2020 5 commits
    • Christian Kellner's avatar
      manager+sysfs: wait for hosts instead of domains · 8be049a5
      Christian Kellner authored
      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.
      8be049a5
    • Christian Kellner's avatar
      manager: better logging for domain de-registration · f3395f9c
      Christian Kellner authored
      Use the LOG_DOM () macro and do not use `bolt_domain_get_id`
      which might return NULL for disconnected domains.
      f3395f9c
    • Christian Kellner's avatar
      test/integration: cleanup stale domains check · 2f9a04d6
      Christian Kellner authored
      Simulate stale domains by creating a store with four domains, one
      of which has a bootacl journal with entries. Since the store does
      not have a 'version' file, an upgrade will be performed which will
      lead to the cleanup of stale domains. All domains, except the one
      with the non-empty bootacl journal should be cleaned up.
      2f9a04d6
    • Christian Kellner's avatar
      manager: clean up stale domains on store upgrade · 9e859394
      Christian Kellner authored
      When the store is upgraded, clean up any stale domains. Previous
      versions of bolt (< 0.9.1) would store domains that did not have
      stable uuids, i.e. their uuid would change on every boot. These
      stored domains would be loaded and exported but would never come
      online, since they can not ever by matched to an online domain.
      When the store cleanup method is executed, in the manager's
      initialization method, the domain controller should either be
      powered (they use runtime power management only and are thus not
      physically powered down on ice lake anyway) or force-powered and
      thus any domain that is not yet online will be removed. This can
      fail if the domain has a boot acl journal with entries, which
      protects the loss of data for domains that are not force-powered,
      maybe because they are even slower, but do have a stable uuid.
      9e859394
    • Christian Kellner's avatar
      manager: correctly report upgraded version · 3ec3e0ef
      Christian Kellner authored
      After the store was upgraded, get the new version from the store
      and report that in the logs, not the old, pre-upgrade version.
      3ec3e0ef
  5. 17 Nov, 2020 1 commit
    • Christian Kellner's avatar
      manager: un-export device in deregister_device · 04c3bb1e
      Christian Kellner authored
      Remove some duplicated code by moving the un-export code for the
      device to a central location: `manager_deregister_device`. This
      method will be called for all devices that can be de-registered,
      i.e. either devices that got disconnected and are not store via
      the `handle_udev_device_removed` udev event handler, or devices
      that got remove from the store and are disconnected. The latter
      is handled via `handle_store_device_removed`. In both cases the
      device should be de-registered and (if exported) be un-exported.
      Thus this is where the un-export code is now moved to.
      04c3bb1e
  6. 10 Nov, 2020 7 commits
    • Christian Kellner's avatar
      test/store: upgrade test · 8ca11b19
      Christian Kellner authored
      Add a store upgrade test: force the store to have version 0 and
      then upgrade it to 1. The only difference between the to is the
      presence of the "version" file (which must contain the version
      info, i.e. "1"). Check that calling the upgrade function again
      does not change anything.
      8ca11b19
    • Christian Kellner's avatar
      test/store: checks for version · 70d27660
      Christian Kellner authored
      Add basic checks for the version property. Check it matches the
      store code version.
      70d27660
    • Christian Kellner's avatar
      manager: upgrade the store · ef6e6d1c
      Christian Kellner authored
      Use the new store upgrade mechanism to upgrade the store. Currently
      nothing is done if an upgrade happens, but it will be used to clean
      up stale domains, which might have accumulated due to the ice lake
      domain uuid instability.
      ef6e6d1c
    • Christian Kellner's avatar
      store: introduce store upgrades · 1b0f7aa9
      Christian Kellner authored
      Add a new function to upgrade the store from version "0" to "1".
      Except the addition of the 'version' file there is no difference
      between the two versions and thus creating said 'version' file
      is all the store upgrade does. This can still be useful, because
      it can be used as a marker, e.g. the manager can use it to clean
      up the store once when upgrading from version 0.
      1b0f7aa9
    • Christian Kellner's avatar
      store: introduce store versioning · f5a7fa0d
      Christian Kellner authored
      Add version information to the on-disk store and expose that
      information via a new "version" store object property. The
      on-disk information is stored in a new 'version' file, that
      is located at the root of the store. In case no such file is
      found, the store version is defined as 0 (zero).
      When a store is opened, and the root of the store is completely
      empty (i.e. no sub-directories or the version file is present),
      the store is assumed to be new and is initialized by creating
      the 'version' containing the BOLT_STORE_VERSION number.
      f5a7fa0d
    • Christian Kellner's avatar
      store: convert to be initable · acd72a98
      Christian Kellner authored
      Convert the store use the GInitable interface. This prepares for
      store on-disk initialization that can fail. Currently, nothing
      is actually done in initialize and thus it will never fail.
      
      Adapt all tests to check for potential store creation errors and
      also convert the manager's store initialization method to handle
      the error.
      acd72a98
    • Christian Kellner's avatar
      manager: extract store initialization · 374bf33b
      Christian Kellner authored
      Instead of initializing the store in the basic object init method,
      create a new method that bundles all store related initialization
      and call that from bolt_manager_initialize. This prepares for the
      possibility that store initialization can fail.
      374bf33b