[parted-devel] [BUG] _disk_sync_part_table() is broken

Jim Meyering jim at meyering.net
Mon Jan 26 18:20:35 UTC 2009


Petr Uzel <petr.uzel at suse.cz> 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.



More information about the parted-devel mailing list