[systemd-devel] Crash and size problem with systemd-repart
Emmanuel Garette
egarette at cadoles.com
Sun Apr 26 15:12:18 UTC 2020
Hi,
I'm experimenting with the new tool systemd-repart and I think I have
found a bug.
Here is a simple repart.d file:
bash-5.0# cat /usr/lib/repart.d/70-home.conf
[Partition]
Type=home
SizeMinBytes=16M
SizeMaxBytes=32M
If the disk is empty, systemd-repart ends with a segfault:
https://github.com/systemd/systemd/issues/15608
So a create a new partition on the disk:
bash-5.0# parted /dev/sdb
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 322MB 321MB primary
And I run systemd-repart:
bash-5.0# systemd-repart /dev/sdb --dry-run=no
TYPE LABEL UUID FILE NODE SIZE PADDING
home home af89e705-7395-4f23-8261-2f7229fc506b
70-home.conf /dev/sdb2 -> 306.0M -> 0B
linux-generic primary fe7a74f4-8827-4233-94ac-0adbf8e3704d
- /dev/sdb1 306.0M 29.6G -> 29.4G
S = 612.0M S = 29.4G
X---------------------------------------------------------------------------------------------------------------------------XX
`- primary |
`- 70-home.conf
Applying changes.
Storage does not support discarding, not discarding data in new
partition 1.
Successfully wiped file system signatures from partition 1.
Storage does not support discarding, not discarding gap at
beginning of disk.
Creating new partition 1.
Writing new partition table.
Telling kernel to reread partition table.
All done.
As you can see, there is a problem with the partition's size: 300MB
instead of 32MB max.
Parted confirm:
Number Start End Size File system Name Flags
1 1049kB 322MB 321MB primary
2 31.9GB 32.2GB 321MB home
I think the problem is here in src/partition/repart.c:
/* What? Even still some space left (maybe because there was
no preceding partition, or it had a
* size limit), then let's donate it to whoever wants it. */
if (span > 0) {
Partition *p;
LIST_FOREACH(partitions, p, context->partitions) {
uint64_t m, xsz;
if (p->allocated_to_area != a)
continue;
if (PARTITION_IS_FOREIGN(p))
continue;
assert(p->new_size != UINT64_MAX);
m = p->new_size + span;
xsz = partition_max_size(a->after);
if (xsz != UINT64_MAX && m > xsz)
m = xsz;
span = charge_size(span, m - p->new_size);
p->new_size = m;
if (span == 0)
break;
}
}
The problem is in line "xsz = partition_max_size(a->after);"
xsz is the max size of "a->after" instead current partition (so "p").
Am I right? I'll make a PR if yes.
Regards,
--
Emmanuel Garette
Ingénieur en informatique libre
Cadoles (http://www.cadoles.com)
Experts EOLE, Envole et logiciels libres
-------------- next part --------------
A non-text attachment was scrubbed...
Name: egarette.vcf
Type: text/x-vcard
Size: 251 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20200426/91593317/attachment.vcf>
More information about the systemd-devel
mailing list