* Wed May 15 2024 Tomas Bzatek <tbzatek@redhat.com> - 2.9.4-11

- udiskslinuxblockobject: Try issuing BLKRRPART ioctl harder
- lvm2: Refactor udisks_daemon_util_lvm2_wipe_block()

Resolves: RHEL-8031
This commit is contained in:
Tomas Bzatek 2024-05-15 14:37:22 +02:00
parent b17a38bacf
commit a49c9510f6
3 changed files with 214 additions and 1 deletions

View File

@ -0,0 +1,30 @@
diff -up udisks-2.9.4/src/udiskslinuxblockobject.c.bak udisks-2.9.4/src/udiskslinuxblockobject.c
--- udisks-2.9.4/src/udiskslinuxblockobject.c.bak 2021-09-29 18:00:31.000000000 +0200
+++ udisks-2.9.4/src/udiskslinuxblockobject.c 2024-05-15 14:29:38.637194092 +0200
@@ -1059,16 +1059,24 @@ udisks_linux_block_object_reread_partiti
/* acquire an exclusive BSD lock to prevent udev probes.
* See also https://systemd.io/BLOCK_DEVICE_LOCKING
*/
+ num_tries = 10;
while (flock (fd, LOCK_EX | LOCK_NB) != 0)
{
g_usleep (100 * 1000); /* microseconds */
- if (num_tries++ > 5)
+ if (num_tries-- < 0)
break;
}
- if (ioctl (fd, BLKRRPART) != 0)
+ num_tries = 5;
+ while (ioctl (fd, BLKRRPART) != 0)
{
+ if (errno == EBUSY && num_tries-- >= 0)
+ {
+ g_usleep (200 * 1000); /* microseconds */
+ continue;
+ }
udisks_warning ("Error issuing BLKRRPART to %s: %m", device_file);
+ break;
}
close (fd);
}

View File

@ -0,0 +1,176 @@
diff -up udisks-2.9.4/modules/lvm2/udiskslvm2daemonutil.c.bak udisks-2.9.4/modules/lvm2/udiskslvm2daemonutil.c
--- udisks-2.9.4/modules/lvm2/udiskslvm2daemonutil.c.bak 2021-09-29 18:00:31.000000000 +0200
+++ udisks-2.9.4/modules/lvm2/udiskslvm2daemonutil.c 2024-05-15 14:51:50.641652449 +0200
@@ -35,6 +35,7 @@
#include <sys/ioctl.h>
#include <linux/fs.h>
+#include <blockdev/fs.h>
#include <blockdev/lvm.h>
#include <limits.h>
@@ -79,63 +80,6 @@ udisks_daemon_util_lvm2_block_is_unused
return TRUE;
}
-static gboolean
-run_sync (const gchar *prog, ...)
-{
- va_list ap;
- GError **error;
- enum { max_argc = 20 };
- const gchar *argv[max_argc+1];
- int argc = 0;
- const gchar *arg;
- gchar *standard_output;
- gchar *standard_error;
- gint exit_status;
-
- argv[argc++] = prog;
- va_start (ap, prog);
- while ((arg = va_arg (ap, const gchar *)))
- {
- if (argc < max_argc)
- argv[argc] = arg;
- argc++;
- }
- error = va_arg (ap, GError **);
- va_end (ap);
-
- if (argc > max_argc)
- {
- g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED,
- "Too many arguments.");
- return FALSE;
- }
-
- argv[argc] = NULL;
- if (!g_spawn_sync (NULL,
- (gchar **)argv,
- NULL,
- G_SPAWN_SEARCH_PATH,
- NULL,
- NULL,
- &standard_output,
- &standard_error,
- &exit_status,
- error))
- return FALSE;
-
- if (!g_spawn_check_exit_status (exit_status, error))
- {
- g_prefix_error (error, "stdout: '%s', stderr: '%s', ", standard_output, standard_error);
- g_free (standard_output);
- g_free (standard_error);
- return FALSE;
- }
-
- g_free (standard_output);
- g_free (standard_error);
- return TRUE;
-}
-
gboolean
udisks_daemon_util_lvm2_wipe_block (UDisksDaemon *daemon,
UDisksBlock *block,
@@ -148,18 +92,19 @@ udisks_daemon_util_lvm2_wipe_block (UDis
UDisksVolumeGroup *volume_group;
gchar *volume_group_name = NULL;
gboolean was_partitioned;
-
const gchar *device_file;
- int fd = -1;
- gchar zeroes[512];
gboolean ret = TRUE;
GError *local_error = NULL;
/* Find the name of the volume group that this device is a physical
* member of, if any. Easy.
*/
-
- block_object = UDISKS_OBJECT (g_dbus_interface_get_object (G_DBUS_INTERFACE (block)));
+ block_object = udisks_daemon_util_dup_object (block, error);
+ if (block_object == NULL)
+ {
+ ret = FALSE;
+ goto out;
+ }
physical_volume = udisks_object_peek_physical_volume (block_object);
if (physical_volume)
{
@@ -177,48 +122,22 @@ udisks_daemon_util_lvm2_wipe_block (UDis
device_file = udisks_block_get_device (block);
- /* Remove partition table */
- memset (zeroes, 0, 512);
- fd = open (device_file, O_RDWR | O_EXCL);
- if (fd < 0)
+ if (!bd_fs_clean (device_file, &local_error))
{
g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED,
- "Error opening device %s for wiping: %m",
- device_file);
- ret = FALSE;
- goto out;
- }
-
- if (write (fd, zeroes, 512) != 512)
- {
- g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED,
- "Error erasing device %s: %m",
- device_file);
- ret = FALSE;
- goto out;
- }
-
- if (was_partitioned && ioctl (fd, BLKRRPART, NULL) < 0)
- {
- g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED,
- "Error removing partition devices of %s: %m",
- device_file);
+ "%s", local_error->message);
+ g_clear_error (&local_error);
ret = FALSE;
goto out;
}
- close (fd);
- fd = -1;
- /* wipe other labels */
- if (!run_sync ("wipefs", "-a", device_file, NULL, error))
- {
- ret = FALSE;
- goto out;
- }
+ if (was_partitioned)
+ udisks_linux_block_object_reread_partition_table (UDISKS_LINUX_BLOCK_OBJECT (block_object));
/* Try to bring affected volume group back into consistency. */
- if (volume_group_name != NULL)
- if (!bd_lvm_vgreduce (volume_group_name, NULL /* device */, NULL /* extra */, &local_error)) {
+ if (volume_group_name != NULL &&
+ !bd_lvm_vgreduce (volume_group_name, NULL /* device */, NULL /* extra */, &local_error))
+ {
udisks_warning ("%s", local_error->message);
g_clear_error (&local_error);
}
@@ -230,16 +149,15 @@ udisks_daemon_util_lvm2_wipe_block (UDis
*
* https://bugzilla.redhat.com/show_bug.cgi?id=1063813
*/
- if (!run_sync ("pvscan", "--cache", device_file, NULL, &local_error))
+ if (!bd_lvm_pvscan (device_file, TRUE, NULL, &local_error))
{
udisks_warning ("%s", local_error->message);
g_clear_error (&local_error);
}
out:
- if (fd >= 0)
- close (fd);
g_clear_object (&volume_group_object);
+ g_clear_object (&block_object);
g_free (volume_group_name);
return ret;
}

View File

@ -48,7 +48,7 @@
Name: udisks2 Name: udisks2
Summary: Disk Manager Summary: Disk Manager
Version: 2.9.4 Version: 2.9.4
Release: 10%{?dist} Release: 11%{?dist}
License: GPLv2+ License: GPLv2+
URL: https://github.com/storaged-project/udisks URL: https://github.com/storaged-project/udisks
Source0: https://github.com/storaged-project/udisks/releases/download/udisks-%{version}/udisks-%{version}.tar.bz2 Source0: https://github.com/storaged-project/udisks/releases/download/udisks-%{version}/udisks-%{version}.tar.bz2
@ -87,6 +87,9 @@ Patch20: udisks-2.9.4-tests_job_unstable.patch
Patch21: udisks-2.10.0-iscsi-ibft-chap-auth.patch Patch21: udisks-2.10.0-iscsi-ibft-chap-auth.patch
# https://issues.redhat.com/browse/RHEL-16229 # https://issues.redhat.com/browse/RHEL-16229
Patch22: udisks-2.11.0-targetcli_config_attr_fix.patch Patch22: udisks-2.11.0-targetcli_config_attr_fix.patch
# https://issues.redhat.com/browse/RHEL-8031
Patch23: udisks-2.11.0-lvm2_refactor_wipe.patch
Patch24: udisks-2.11.0-BLKRRPART-harder.patch
BuildRequires: make BuildRequires: make
BuildRequires: glib2-devel >= %{glib2_version} BuildRequires: glib2-devel >= %{glib2_version}
@ -462,6 +465,10 @@ fi
%endif %endif
%changelog %changelog
* Wed May 15 2024 Tomas Bzatek <tbzatek@redhat.com> - 2.9.4-11
- udiskslinuxblockobject: Try issuing BLKRRPART ioctl harder
- lvm2: Refactor udisks_daemon_util_lvm2_wipe_block()
* Tue Nov 28 2023 Tomas Bzatek <tbzatek@redhat.com> - 2.9.4-10 * Tue Nov 28 2023 Tomas Bzatek <tbzatek@redhat.com> - 2.9.4-10
- tests: Fix targetcli_config.json (RHEL-16229) - tests: Fix targetcli_config.json (RHEL-16229)