Patches for the 'commit to os' function in linux.

This commit is contained in:
Joel Andres Granados Moreno 2009-08-31 12:34:18 +00:00
parent eb24deea49
commit d8621345e2
4 changed files with 413 additions and 2 deletions

View File

@ -0,0 +1,44 @@
From 50898ea17a25c92c3b0ab3c0f12ea867a6ff1ff9 Mon Sep 17 00:00:00 2001
From: Joel Granados Moreno <jgranado@redhat.com>
Date: Mon, 31 Aug 2009 13:42:47 +0200
Subject: [PATCH 2/3] Commit without close
---
libparted/disk.c | 20 ++++++++++++++++++--
1 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/libparted/disk.c b/libparted/disk.c
index 27611eb..b01ac70 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -513,9 +513,25 @@ error:
int
ped_disk_commit (PedDisk* disk)
{
+ /* Open the device here, so that the underlying fd is not closed
+ between commit_to_dev and commit_to_os (closing causes unwanted
+ udev events to be send under Linux). */
+ if (!ped_device_open (disk->dev))
+ goto error;
+
if (!ped_disk_commit_to_dev (disk))
- return 0;
- return ped_disk_commit_to_os (disk);
+ goto error_close_dev;
+
+ if (!ped_disk_commit_to_os (disk))
+ goto error_close_dev;
+
+ ped_device_close (disk->dev);
+ return 1;
+
+error_close_dev:
+ ped_device_close (disk->dev);
+error:
+ return 0;
}
/**
--
1.6.4

View File

@ -0,0 +1,94 @@
From a8dc525bdab612551a5859b8a8bd2b944a259766 Mon Sep 17 00:00:00 2001
From: Joel Granados Moreno <jgranado@redhat.com>
Date: Mon, 31 Aug 2009 13:44:02 +0200
Subject: [PATCH 3/3] Dont touch part nodes
---
libparted/arch/linux.c | 47 ++++++++++++++++++++++++++++++++---------------
1 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index e47030f..1d4fc7e 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -586,6 +586,19 @@ _get_linux_version ()
return kver = KERNEL_VERSION (major, minor, teeny);
}
+static int
+_have_kern26 ()
+{
+ static int have_kern26 = -1;
+ int kver;
+
+ if (have_kern26 != -1)
+ return have_kern26;
+
+ kver = _get_linux_version();
+ return have_kern26 = kver >= KERNEL_VERSION (2,6,0) ? 1 : 0;
+}
+
static void
_device_set_sector_size (PedDevice* dev)
{
@@ -1354,8 +1367,8 @@ linux_is_busy (PedDevice* dev)
return 0;
}
-/* we need to flush the master device, and all the partition devices,
- * because there is no coherency between the caches.
+/* we need to flush the master device, and with kernel < 2.6 all the partition
+ * devices, because there is no coherency between the caches with old kernels.
* We should only flush unmounted partition devices, because:
* - there is never a need to flush them (we're not doing IO there)
* - flushing a device that is mounted causes unnecessary IO, and can
@@ -1373,21 +1386,23 @@ _flush_cache (PedDevice* dev)
ioctl (arch_specific->fd, BLKFLSBUF);
- for (i = 1; i < 16; i++) {
- char* name;
- int fd;
+ if (!_have_kern26()) {
+ for (i = 1; i < 16; i++) {
+ char* name;
+ int fd;
- name = _device_get_part_path (dev, i);
- if (!name)
- break;
- if (!_partition_is_mounted_by_path (name)) {
- fd = open (name, WR_MODE, 0);
- if (fd > 0) {
- ioctl (fd, BLKFLSBUF);
- close (fd);
+ name = _device_get_part_path (dev, i);
+ if (!name)
+ break;
+ if (!_partition_is_mounted_by_path (name)) {
+ fd = open (name, WR_MODE, 0);
+ if (fd > 0) {
+ ioctl (fd, BLKFLSBUF);
+ close (fd);
+ }
}
+ free (name);
}
- free (name);
}
}
@@ -1428,7 +1443,9 @@ retry:
dev->read_only = 0;
}
- _flush_cache (dev);
+ /* With kernels < 2.6 flush cache for cache coherence issues */
+ if (!_have_kern26())
+ _flush_cache (dev);
return 1;
}
--
1.6.4

264
parted-1.9.0-no-BLKPG.patch Normal file
View File

@ -0,0 +1,264 @@
From ead3330dfadfcb2bd53a136916d4087cc725ef42 Mon Sep 17 00:00:00 2001
From: Joel Granados Moreno <jgranado@redhat.com>
Date: Mon, 31 Aug 2009 13:41:06 +0200
Subject: [PATCH 1/3] No BLKPG
---
libparted/arch/linux.c | 213 ------------------------------------------------
1 files changed, 0 insertions(+), 213 deletions(-)
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 8f220e0..e47030f 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -41,7 +41,6 @@
#include <libdevmapper.h>
#endif
-#include "blkpg.h"
#include "../architecture.h"
#include "dirname.h"
@@ -587,22 +586,6 @@ _get_linux_version ()
return kver = KERNEL_VERSION (major, minor, teeny);
}
-static int
-_have_devfs ()
-{
- static int have_devfs = -1;
- struct stat sb;
-
- if (have_devfs != -1)
- return have_devfs;
-
- /* the presence of /dev/.devfsd implies that DevFS is active */
- if (stat("/dev/.devfsd", &sb) < 0)
- return have_devfs = 0;
-
- return have_devfs = S_ISCHR(sb.st_mode) ? 1 : 0;
-}
-
static void
_device_set_sector_size (PedDevice* dev)
{
@@ -2189,176 +2172,6 @@ linux_partition_is_busy (const PedPartition* part)
return 0;
}
-static int
-_blkpg_part_command (PedDevice* dev, struct blkpg_partition* part, int op)
-{
- LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev);
- struct blkpg_ioctl_arg ioctl_arg;
-
- ioctl_arg.op = op;
- ioctl_arg.flags = 0;
- ioctl_arg.datalen = sizeof (struct blkpg_partition);
- ioctl_arg.data = (void*) part;
-
- return ioctl (arch_specific->fd, BLKPG, &ioctl_arg) == 0;
-}
-
-static int
-_blkpg_add_partition (PedDisk* disk, const PedPartition *part)
-{
- struct blkpg_partition linux_part;
- const char* vol_name;
- char* dev_name;
-
- PED_ASSERT(disk != NULL, return 0);
- PED_ASSERT(disk->dev->sector_size % PED_SECTOR_SIZE_DEFAULT == 0,
- return 0);
-
- if (ped_disk_type_check_feature (disk->type,
- PED_DISK_TYPE_PARTITION_NAME))
- vol_name = ped_partition_get_name (part);
- else
- vol_name = NULL;
-
- dev_name = _device_get_part_path (disk->dev, part->num);
- if (!dev_name)
- return 0;
-
- memset (&linux_part, 0, sizeof (linux_part));
- linux_part.start = part->geom.start * disk->dev->sector_size;
- /* see fs/partitions/msdos.c:msdos_partition(): "leave room for LILO" */
- if (part->type & PED_PARTITION_EXTENDED)
- linux_part.length = part->geom.length == 1 ? 512 : 1024;
- else
- linux_part.length = part->geom.length * disk->dev->sector_size;
- linux_part.pno = part->num;
- strncpy (linux_part.devname, dev_name, BLKPG_DEVNAMELTH);
- if (vol_name)
- strncpy (linux_part.volname, vol_name, BLKPG_VOLNAMELTH);
-
- free (dev_name);
-
- if (!_blkpg_part_command (disk->dev, &linux_part,
- BLKPG_ADD_PARTITION)) {
- return ped_exception_throw (
- PED_EXCEPTION_ERROR,
- PED_EXCEPTION_IGNORE_CANCEL,
- _("Error informing the kernel about modifications to "
- "partition %s -- %s. This means Linux won't know "
- "about any changes you made to %s until you reboot "
- "-- so you shouldn't mount it or use it in any way "
- "before rebooting."),
- linux_part.devname,
- strerror (errno),
- linux_part.devname)
- == PED_EXCEPTION_IGNORE;
- }
-
- return 1;
-}
-
-static int
-_blkpg_remove_partition (PedDisk* disk, int n)
-{
- struct blkpg_partition linux_part;
-
- memset (&linux_part, 0, sizeof (linux_part));
- linux_part.pno = n;
- return _blkpg_part_command (disk->dev, &linux_part,
- BLKPG_DEL_PARTITION);
-}
-
-/*
- * The number of partitions that a device can have depends on the kernel.
- * If we don't find this value in /sys/block/DEV/range, we will use our own
- * value.
- */
-static unsigned int
-_device_get_partition_range(PedDevice* dev)
-{
- int range, r;
- char path[128];
- FILE* fp;
- bool ok;
-
- r = snprintf(path, sizeof(path), "/sys/block/%s/range",
- last_component(dev->path));
- if(r < 0 || r >= sizeof(path))
- return MAX_NUM_PARTS;
-
- fp = fopen(path, "r");
- if(!fp)
- return MAX_NUM_PARTS;
-
- ok = fscanf(fp, "%d", &range) == 1;
- fclose(fp);
-
- /* (range <= 0) is none sense.*/
- return ok && range > 0 ? range : MAX_NUM_PARTS;
-}
-
-/*
- * Sync the partition table in two step process:
- * 1. Remove all of the partitions from the kernel's tables, but do not attempt
- * removal of any partition for which the corresponding ioctl call fails.
- * 2. Add all the partitions that we hold in disk.
- *
- * To achieve this two step process we must calculate the minimum number of
- * maximum possible partitions between what linux supports and what the label
- * type supports. EX:
- *
- * number=MIN(max_parts_supported_in_linux,max_parts_supported_in_msdos_tables)
- */
-static int
-_disk_sync_part_table (PedDisk* disk)
-{
- PED_ASSERT(disk != NULL, return 0);
- PED_ASSERT(disk->dev != NULL, return 0);
- int lpn;
-
- /* lpn = largest partition number. */
- if(ped_disk_get_max_supported_partition_count(disk, &lpn))
- lpn = PED_MIN(lpn, _device_get_partition_range(disk->dev));
- else
- lpn = _device_get_partition_range(disk->dev);
-
- /* Its not possible to support largest_partnum < 0.
- * largest_partnum == 0 would mean does not support partitions.
- * */
- if(lpn < 0)
- return 0;
-
- int *rets = ped_malloc(sizeof(int) * lpn);
- int *errnums = ped_malloc(sizeof(int) * lpn);
- int ret = 1;
- int i;
-
- for (i = 1; i <= lpn; i++) {
- rets[i - 1] = _blkpg_remove_partition (disk, i);
- errnums[i - 1] = errno;
- }
-
- for (i = 1; i <= lpn; i++) {
- const PedPartition *part = ped_disk_get_partition (disk, i);
- if (part) {
- /* busy... so we won't (can't!) disturb ;) Prolly
- * doesn't matter anyway, because users shouldn't be
- * changing mounted partitions anyway...
- */
- if (!rets[i - 1] && errnums[i - 1] == EBUSY)
- continue;
-
- /* add the (possibly modified or new) partition */
- if (!_blkpg_add_partition (disk, part))
- ret = 0;
- }
- }
-
- free (rets);
- free (errnums);
- return ret;
-}
-
#ifdef ENABLE_DEVICE_MAPPER
static int
_dm_remove_map_name(char *name)
@@ -2601,19 +2414,6 @@ _kernel_reread_part_table (PedDevice* dev)
}
static int
-_have_blkpg ()
-{
- static int have_blkpg = -1;
- int kver;
-
- if (have_blkpg != -1)
- return have_blkpg;
-
- kver = _get_linux_version();
- return have_blkpg = kver >= KERNEL_VERSION (2,4,0) ? 1 : 0;
-}
-
-static int
linux_disk_commit (PedDisk* disk)
{
#ifdef ENABLE_DEVICE_MAPPER
@@ -2621,19 +2421,6 @@ linux_disk_commit (PedDisk* disk)
return _dm_reread_part_table (disk);
#endif
if (disk->dev->type != PED_DEVICE_FILE) {
- /* The ioctl() command BLKPG_ADD_PARTITION does not notify
- * the devfs system; consequently, /proc/partitions will not
- * be up to date, and the proper links in /dev are not
- * created. Therefore, if using DevFS, we must get the kernel
- * to re-read and grok the partition table.
- */
- /* Work around kernel dasd problem so we really do BLKRRPART */
- if (disk->dev->type != PED_DEVICE_DASD &&
- _have_blkpg () && !_have_devfs ()) {
- if (_disk_sync_part_table (disk))
- return 1;
- }
-
return _kernel_reread_part_table (disk->dev);
}
--
1.6.4

View File

@ -4,7 +4,7 @@
Summary: The GNU disk partition manipulation program
Name: parted
Version: 1.9.0
Release: 13%{?dist}
Release: 14%{?dist}
License: GPLv3+
Group: Applications/System
URL: http://www.gnu.org/software/parted
@ -22,6 +22,9 @@ Patch9: %{name}-1.9.0-new-duplicate.patch
Patch10: %{name}-1.9.0-handle-dup-error.patch
Patch11: %{name}-1.9.0-swap-flag.patch
Patch12: %{name}-1.9.0-volkeysize.patch
Patch13: %{name}-1.9.0-no-BLKPG.patch
Patch14: %{name}-1.9.0-commit-without-close.patch
Patch15: %{name}-1.9.0-dont-touch-part-nodes.patch
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: e2fsprogs-devel
@ -70,7 +73,10 @@ Parted library, you need to install this package.
%patch9 -p1 -b .new-duplicate
%patch10 -p1 -b .handle-dup-error
%patch11 -p1 -b .swap-flag
%patch12 -p1 -b .volkey-size^^
%patch12 -p1 -b .volkeysize
%patch13 -p1 -b .no-BLKPG
%patch14 -p1 -b .commit-without-close
%patch15 -p1 -b .dont-touch-part-nodes
%build
@ -131,6 +137,9 @@ fi
%{_exec_prefix}/%{_lib}/pkgconfig/libparted.pc
%changelog
* Mon Aug 31 2009 Joel Granados <jgranado@redhat.com> 1.9.0-14
- Patchs for 'commit to os' for linux. Thx to hansg.
* Fri Aug 28 2009 Karsten Hopp <karsten@redhat.com> 1.9.0-13
- volkey is only 4 chars, don't overflow destination buffer with 84 chars