Skip to content

Commit

Permalink
lvm2: Only install results of most recently started update
Browse files Browse the repository at this point in the history
For both vgs_task_func and lvs_task_func.

Fixes storaged-project#966
  • Loading branch information
mvollmer committed Apr 5, 2022
1 parent da6d948 commit 37758b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 11 additions & 1 deletion modules/lvm2/udiskslinuxmodulelvm2.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ struct _UDisksLinuxModuleLVM2 {

gint delayed_update_id;
gboolean coldplug_done;

guint32 update_epoch;
};

typedef struct _UDisksLinuxModuleLVM2Class UDisksLinuxModuleLVM2Class;
Expand Down Expand Up @@ -221,6 +223,12 @@ lvm_update_vgs (GObject *source_obj,
gpointer key, value;
const gchar *vg_name;

if (GPOINTER_TO_INT (user_data) != module->update_epoch)
{
vgs_pvs_data_free (data);
return;
}

if (! data)
{
if (error)
Expand Down Expand Up @@ -303,11 +311,13 @@ lvm_update (UDisksLinuxModuleLVM2 *module)
{
GTask *task;

module->update_epoch++;

/* the callback (lvm_update_vgs) is called in the default main loop (context) */
task = g_task_new (module,
NULL /* cancellable */,
lvm_update_vgs,
NULL /* callback_data */);
GINT_TO_POINTER (module->update_epoch));

/* holds a reference to 'task' until it is finished */
g_task_run_in_thread (task, (GTaskThreadFunc) vgs_task_func);
Expand Down
12 changes: 12 additions & 0 deletions modules/lvm2/udiskslinuxvolumegroupobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct _UDisksLinuxVolumeGroupObject
gchar *name;

GHashTable *logical_volumes;
guint32 update_epoch;
guint32 poll_epoch;
guint poll_timeout_id;
gboolean poll_requested;
Expand Down Expand Up @@ -99,6 +100,7 @@ static void crypttab_changed (UDisksCrypttabMonitor *monitor,
typedef struct {
BDLVMVGdata *vg_info;
GSList *vg_pvs;
gint epoch;
} VGUpdateData;

static void
Expand Down Expand Up @@ -183,6 +185,7 @@ udisks_linux_volume_group_object_set_property (GObject *__object,
static void
udisks_linux_volume_group_object_init (UDisksLinuxVolumeGroupObject *object)
{
object->update_epoch = 0;
object->poll_epoch = 0;
object->poll_timeout_id = 0;
object->poll_requested = FALSE;
Expand Down Expand Up @@ -575,6 +578,12 @@ update_vg (GObject *source_obj,
BDLVMVGdata *vg_info = data->vg_info;
GSList *vg_pvs = data->vg_pvs;

if (data->epoch != object->update_epoch)
{
lv_list_free (lvs);
return;
}

/* free the data container (but not 'vg_info' and 'vg_pvs') */
g_free (data);

Expand Down Expand Up @@ -711,8 +720,11 @@ udisks_linux_volume_group_object_update (UDisksLinuxVolumeGroupObject *object, B
gchar *vg_name = g_strdup (vg_info->name);
GTask *task = NULL;

object->update_epoch++;

data->vg_info = vg_info;
data->vg_pvs = pvs;
data->epoch = object->update_epoch;

/* the callback (update_vg) is called in the default main loop (context) */
task = g_task_new (g_object_ref (object), NULL /* cancellable */, update_vg, data /* callback_data */);
Expand Down

0 comments on commit 37758b2

Please sign in to comment.