Petr Uzel <[email protected]> wrote: > There's a bug in current development version of parted which causes that the > partition table, as seen by the kernel, is not updated correctly after > deleting > a partition. This bug was introduced in commit > f6bd20573e3ecfb63f62d88c52a0870fb8851b59 (fix computation of largest partition > number). Yes, I know - this patch was proposed by me - sorry for that :) > > Steps to reproduce: > ------------------- > > Start with the empty partition table, create primary partition and then > delete this > partition. The on-disk partition table representation is correct, but the > kernel is > not correctly informed about the change. This might be fixed by running > 'blockdev --rereadpt /dev/hdd' command. > > # ./parted/parted /dev/hdd > GNU Parted 1.8.8.1.90-cc1f > Using /dev/hdd > Welcome to GNU Parted! Type 'help' to view a list of commands. > (parted) print > Model: WDC WD153BA (ide) > Disk /dev/hdd: 15.4GB > Sector size (logical/physical): 512B/512B > Partition Table: msdos > > Number Start End Size Type File system Flags > > (parted) mkpart primary ext2 0 2G > (parted) rm 1 > (parted) print > Model: WDC WD153BA (ide) > Disk /dev/hdd: 15.4GB > Sector size (logical/physical): 512B/512B > Partition Table: msdos > > Number Start End Size Type File system Flags > <SNIP> > > # cat /proc/partitions > <SNIP> > 22 64 15021720 hdd > 22 65 1951866 hdd1 > # blockdev --rereadpt /dev/hdd > # cat /proc/partitions > <SNIP> > 22 64 15021720 hdd > > Analysis: > --------- > > When the partition is deleted, parted first updates its in-memory > representation of partition table [1], then it writes the partition table a > then it commits the changes to OS. On newer kernels, the disk commit is done > by > _disk_sync_part_table() called from linux_disk_commit(). > > This function needs to inform the kernel that partition #1 was deleted. To > find > out what partitions it should iterate over, it uses MIN(16, > ped_disk_get_last_partition_num(disk)). > But the problem is that ped_disk_get_last_partition_num() uses in-memory > representation of partition table, in which the partition table has no > partitions (see [1]), and thus it returns -1. > > The result is that parted does not inform the kernel that partition #1 was > deleted.
Thanks for the test case and analysis! Here's the patch I'm about to push. If you feel like implementing your alternative last_sensible_partition_num-based solution, that might be even better. >From fae811d0967e63ebd17191f033ee843558f4965c Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Mon, 26 Jan 2009 16:24:52 +0100 Subject: [PATCH 2/6] _disk_sync_part_table: revise yet again This fixes a bug whereby parted could leave the kernel with an erroneous view of a partition table. * libparted/arch/linux.c (_disk_sync_part_table): Per analysis in http://thread.gmane.org/gmane.comp.gnu.parted.devel/2297/focus=2307. Patch suggested by Petr Uzel. --- libparted/arch/linux.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c index 83e24c8..3527f5d 100644 --- a/libparted/arch/linux.c +++ b/libparted/arch/linux.c @@ -1,5 +1,5 @@ /* libparted - a library for manipulating disk partitions - Copyright (C) 1999 - 2005, 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 1999 - 2005, 2007, 2008, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -2251,7 +2251,7 @@ _disk_sync_part_table (PedDisk* disk) if (largest_partnum <= 0) return 1; - int last = PED_MIN (largest_partnum, 16); + int last = 16; int* rets = ped_malloc(sizeof(int) * last); int* errnums = ped_malloc(sizeof(int) * last); int ret = 1; -- 1.6.1.1.347.g3f81d _______________________________________________ parted-devel mailing list [email protected] http://lists.alioth.debian.org/mailman/listinfo/parted-devel

