04e847
From e039516b103eb9749a3e261c5ee1a9bc110676cf Mon Sep 17 00:00:00 2001
04e847
From: Tomas Bzatek <tbzatek@redhat.com>
04e847
Date: Fri, 26 Jun 2020 17:42:32 +0200
04e847
Subject: [PATCH 1/8] daemon: Always flush interface property changes
04e847
04e847
Setting properties on a GDBusInterfaceSkeleton from the main thread
04e847
as a result of uevent is somewhat racy to clients that are waiting
04e847
for a method call to return that is processed in a separate thread
04e847
by the daemon. Perhaps there's a race in the GDBus worker thread
04e847
that processes changes from both threads and send them out on the bus.
04e847
04e847
Explicit flush on GDBusInterfaceSkeleton interfaces seems to fix
04e847
the issue. Such approach was used before on some places, this change
04e847
adds explicit flushes at all places where properties may change.
04e847
---
04e847
 src/udiskslinuxblock.c          | 2 ++
04e847
 src/udiskslinuxdrive.c          | 1 +
04e847
 src/udiskslinuxdriveata.c       | 5 +++++
04e847
 src/udiskslinuxencrypted.c      | 5 +++++
04e847
 src/udiskslinuxfilesystem.c     | 3 +++
04e847
 src/udiskslinuxloop.c           | 1 +
04e847
 src/udiskslinuxmdraid.c         | 1 +
04e847
 src/udiskslinuxpartition.c      | 2 ++
04e847
 src/udiskslinuxpartitiontable.c | 1 +
04e847
 src/udiskslinuxswapspace.c      | 1 +
04e847
 10 files changed, 22 insertions(+)
04e847
04e847
diff --git a/src/udiskslinuxblock.c b/src/udiskslinuxblock.c
04e847
index ddc7fe1f..34d73f0e 100644
04e847
--- a/src/udiskslinuxblock.c
04e847
+++ b/src/udiskslinuxblock.c
04e847
@@ -893,6 +893,7 @@ update_configuration (UDisksLinuxBlock  *block,
04e847
       configuration = g_variant_new ("a(sa{sv})", NULL);
04e847
     }
04e847
   udisks_block_set_configuration (UDISKS_BLOCK (block), configuration);
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (block));
04e847
 }
04e847
 
04e847
 #ifdef HAVE_LIBMOUNT_UTAB
04e847
@@ -1280,6 +1281,7 @@ udisks_linux_block_update (UDisksLinuxBlock       *block,
04e847
   update_mdraid (block, device, drive, object_manager);
04e847
 
04e847
  out:
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (block));
04e847
   if (device != NULL)
04e847
     g_object_unref (device);
04e847
   if (drive != NULL)
04e847
diff --git a/src/udiskslinuxdrive.c b/src/udiskslinuxdrive.c
04e847
index e9dd7117..28a90ce9 100644
04e847
--- a/src/udiskslinuxdrive.c
04e847
+++ b/src/udiskslinuxdrive.c
04e847
@@ -950,6 +950,7 @@ udisks_linux_drive_update (UDisksLinuxDrive       *drive,
04e847
   ret = update_configuration (drive, object);
04e847
 
04e847
  out:
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (drive));
04e847
   if (device != NULL)
04e847
     g_clear_object (&device);
04e847
 
04e847
diff --git a/src/udiskslinuxdriveata.c b/src/udiskslinuxdriveata.c
04e847
index d65f3254..4ba66d09 100644
04e847
--- a/src/udiskslinuxdriveata.c
04e847
+++ b/src/udiskslinuxdriveata.c
04e847
@@ -339,6 +339,8 @@ udisks_linux_drive_ata_update (UDisksLinuxDriveAta    *drive,
04e847
   update_security (drive, device);
04e847
 
04e847
  out:
04e847
+  /* ensure property changes are sent before the method return */
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (drive));
04e847
   if (device != NULL)
04e847
     g_object_unref (device);
04e847
 
04e847
@@ -681,6 +683,9 @@ udisks_linux_drive_ata_refresh_smart_sync (UDisksLinuxDriveAta  *drive,
04e847
   /* update stats again to account for the IO we just did to read the SMART info */
04e847
   update_io_stats (drive, device);
04e847
 
04e847
+  /* ensure property changes are sent before the method return */
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (drive));
04e847
+
04e847
  out:
04e847
   g_clear_object (&device);
04e847
   if (d != NULL)
04e847
diff --git a/src/udiskslinuxencrypted.c b/src/udiskslinuxencrypted.c
04e847
index 73c78873..8a230fda 100644
04e847
--- a/src/udiskslinuxencrypted.c
04e847
+++ b/src/udiskslinuxencrypted.c
04e847
@@ -237,6 +237,8 @@ udisks_linux_encrypted_update (UDisksLinuxEncrypted   *encrypted,
04e847
     update_metadata_size (encrypted, object);
04e847
 
04e847
   udisks_linux_block_encrypted_unlock (block);
04e847
+
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (encrypted));
04e847
 }
04e847
 
04e847
 /* ---------------------------------------------------------------------------------------------------- */
04e847
@@ -630,6 +632,9 @@ handle_unlock (UDisksEncrypted        *encrypted,
04e847
                                         g_udev_device_get_sysfs_attr (cleartext_device->udev_device, "dm/uuid"),
04e847
                                         caller_uid);
04e847
 
04e847
+  /* ensure property changes are sent before the method return */
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (encrypted));
04e847
+
04e847
   udisks_encrypted_complete_unlock (encrypted,
04e847
                                     invocation,
04e847
                                     g_dbus_object_get_object_path (G_DBUS_OBJECT (cleartext_object)));
04e847
diff --git a/src/udiskslinuxfilesystem.c b/src/udiskslinuxfilesystem.c
04e847
index 669fc40b..3ae11c32 100644
04e847
--- a/src/udiskslinuxfilesystem.c
04e847
+++ b/src/udiskslinuxfilesystem.c
04e847
@@ -277,6 +277,8 @@ udisks_linux_filesystem_update (UDisksLinuxFilesystem  *filesystem,
04e847
   if (! skip_fs_size)
04e847
     udisks_filesystem_set_size (UDISKS_FILESYSTEM (filesystem), get_filesystem_size (object));
04e847
 
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (filesystem));
04e847
+
04e847
   g_object_unref (device);
04e847
 }
04e847
 
04e847
@@ -1865,6 +1867,7 @@ handle_resize (UDisksFilesystem      *filesystem,
04e847
                                                  UDISKS_DEFAULT_WAIT_TIMEOUT);
04e847
 
04e847
   udisks_filesystem_set_size (filesystem, get_filesystem_size (UDISKS_LINUX_BLOCK_OBJECT (object)));
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (filesystem));
04e847
   udisks_filesystem_complete_resize (filesystem, invocation);
04e847
   udisks_simple_job_complete (UDISKS_SIMPLE_JOB (job), TRUE, NULL);
04e847
 
04e847
diff --git a/src/udiskslinuxloop.c b/src/udiskslinuxloop.c
04e847
index 6c8a4561..5d7e3553 100644
04e847
--- a/src/udiskslinuxloop.c
04e847
+++ b/src/udiskslinuxloop.c
04e847
@@ -187,6 +187,7 @@ udisks_linux_loop_update (UDisksLinuxLoop        *loop,
04e847
     }
04e847
   udisks_loop_set_setup_by_uid (UDISKS_LOOP (loop), setup_by_uid);
04e847
 
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (loop));
04e847
   g_object_unref (device);
04e847
 }
04e847
 
04e847
diff --git a/src/udiskslinuxmdraid.c b/src/udiskslinuxmdraid.c
04e847
index 85fc2a3b..7eca9764 100644
04e847
--- a/src/udiskslinuxmdraid.c
04e847
+++ b/src/udiskslinuxmdraid.c
04e847
@@ -512,6 +512,7 @@ udisks_linux_mdraid_update (UDisksLinuxMDRaid       *mdraid,
04e847
                                                                                 uuid));
04e847
 
04e847
  out:
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (mdraid));
04e847
   if (raid_data)
04e847
       bd_md_examine_data_free (raid_data);
04e847
   g_free (sync_completed);
04e847
diff --git a/src/udiskslinuxpartition.c b/src/udiskslinuxpartition.c
04e847
index 97ba02fe..ff0fdfc0 100644
04e847
--- a/src/udiskslinuxpartition.c
04e847
+++ b/src/udiskslinuxpartition.c
04e847
@@ -312,6 +312,8 @@ udisks_linux_partition_update (UDisksLinuxPartition   *partition,
04e847
   udisks_partition_set_is_container (UDISKS_PARTITION (partition), is_container);
04e847
   udisks_partition_set_is_contained (UDISKS_PARTITION (partition), is_contained);
04e847
 
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (partition));
04e847
+
04e847
   g_free (name);
04e847
   g_clear_object (&device);
04e847
   g_clear_object (&disk_block_object);
04e847
diff --git a/src/udiskslinuxpartitiontable.c b/src/udiskslinuxpartitiontable.c
04e847
index b26849bc..e43a0708 100644
04e847
--- a/src/udiskslinuxpartitiontable.c
04e847
+++ b/src/udiskslinuxpartitiontable.c
04e847
@@ -146,6 +146,7 @@ udisks_linux_partition_table_update (UDisksLinuxPartitionTable  *table,
04e847
 
04e847
   udisks_partition_table_set_partitions (UDISKS_PARTITION_TABLE (table),
04e847
                                          partition_object_paths);
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (table));
04e847
 
04e847
 
04e847
   g_free (partition_object_paths);
04e847
diff --git a/src/udiskslinuxswapspace.c b/src/udiskslinuxswapspace.c
04e847
index ee103528..bb47f3d4 100644
04e847
--- a/src/udiskslinuxswapspace.c
04e847
+++ b/src/udiskslinuxswapspace.c
04e847
@@ -127,6 +127,7 @@ udisks_linux_swapspace_update (UDisksLinuxSwapspace   *swapspace,
04e847
     active = TRUE;
04e847
   udisks_swapspace_set_active (UDISKS_SWAPSPACE (swapspace), active);
04e847
 
04e847
+  g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (swapspace));
04e847
   g_object_unref (device);
04e847
 }
04e847
 
04e847
-- 
04e847
2.26.2
04e847