[elbe-devel] [PATCH 2/4] finetuning: set_partition_type: ignore reread ptable error

Torben Hohn torben.hohn at linutronix.de
Mon Mar 29 16:09:06 CEST 2021


On Mon, Mar 29, 2021 at 02:00:53PM +0200, Bastian Germann wrote:
> Am 29.03.21 um 13:03 schrieb Torben Hohn:
> > When fdisk writes a new partition table, it tries to make the
> > kernel reread it. This does not work for loop devices and
> > makes fdisk return a non-zero return code.
> > 
> > -----------------------------------------------------------------------------------------------------------------------------
> > [CMD] losetup --find --show --partscan "/var/cache/elbe/4f553e2f-e976-426d-8c40-69cfe5ad47fd/sda.img"
> > [CMD] fdisk /dev/loop0
> > 
> > Welcome to fdisk (util-linux 2.33.1).
> > Changes will remain in memory only, until you decide to write them.
> > Be careful before using the write command.
> > 
> > Command (m for help): Partition number (1,2, default 2): Hex code (type L to list all codes):
> > Changed type of partition 'Linux' to 'Hidden FAT16 <32M'.
> > 
> > Command (m for help): The partition table has been altered.
> > Calling ioctl() to re-read partition table.
> > Re-reading the partition table failed.: Device or resource busy
> > 
> > The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).
> > 
> > [CMD] losetup --detach "/dev/loop0"
> > [ERROR] ProjectFinetuning Error, trying to continue anyways
> > Traceback (most recent call last):
> >    File "/var/cache/elbe/devel/elbepack/finetuning.py", line 790, in do_prj_finetuning
> >      action.execute_prj(buildenv, target, builddir)
> >    File "/var/cache/elbe/devel/elbepack/finetuning.py", line 559, in execute_prj
> >      action.execute_img(buildenv, target, builddir, loop_dev)
> >    File "/var/cache/elbe/devel/elbepack/finetuning.py", line 716, in execute_img
> >      do(cmd, stdin=inp)
> >    File "/var/cache/elbe/devel/elbepack/shellhelper.py", line 258, in do
> >      raise CommandError(cmd, p.returncode)
> > elbepack.shellhelper.CommandError: Error: 1 returned from Command fdisk /dev/loop0
> > -----------------------------------------------------------------------------------------------------------------------------
> > 
> > However, the next thing elbe does, is clear the loop mount and
> > the partition layout was not changed anyways. So this error
> > can be safely ignored.
> > 
> > Ignore it.
> > 
> > Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
> > ---
> >   elbepack/finetuning.py | 10 +++++++++-
> >   1 file changed, 9 insertions(+), 1 deletion(-)
> > 
> > diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
> > index 16d07ea8c..d3968bb68 100644
> > --- a/elbepack/finetuning.py
> > +++ b/elbepack/finetuning.py
> > @@ -713,7 +713,15 @@ class SetPartitionTypeAction(ImageFinetuningAction):
> >           cmd = f'fdisk {loop_dev}'
> >           inp = f't\n{part_nr}\n{part_type}\nw\n'
> > -        do(cmd, stdin=inp)
> > +        try:
> > +            do(cmd, stdin=inp)
> > +        except CommandError as e:
> > +            # At the end, fdisk tries to reread the partitiontable
> > +            # and fails. This makes it return 1.
> 
> Is this the only error case that exits as 1? I do not think so.

You are correct.
I think i have also seen it succeed.

We should probably focus on the race triggered by udev which seems to
be running blkid.

i am trying out this now:

------------------------------------------------------------------
root at elbe-daemon:~# cat
/etc/udev/rules.d/59-persistent-storage-no-loop.rules 

KERNEL=="loop*", GOTO="persistent_storage_end"
------------------------------------------------------------------


> 
> > +            #
> > +            # When it returns 1, we can just continue.
> > +            if e.returncode != 1:
> > +                raise
> >   @FinetuningAction.register("unit-tests")
> > 

-- 
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
can be found here): https://linutronix.de/kontakt/Datenschutz.php

Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner


More information about the elbe-devel mailing list