[OpenWrt-Devel] fstools: factory reset on power failure during startup

Florian Eckert eckert.florian at googlemail.com
Fri Nov 27 07:17:02 EST 2015


Hi,

I have tested your patch since last day when I got the patch from you.
I am using an programmable dc/dc power supply, who switches the power
between startup randomly.
I will run the test during the weekend. And then I will see what
happend on Monday morning.
But for now i havn't lost the configuration anymore.

Flo


2015-11-26 14:25 GMT+01:00 Florian Eckert <eckert.florian at googlemail.com>:
> Hi,
>
> thank your very much for your fast reply and the fix :-).
> I will try it and give you an respond.
>
> flo
>
> 2015-11-26 14:05 GMT+01:00 Felix Fietkau <nbd at openwrt.org>:
>> On 2015-11-26 09:24, Florian Eckert wrote:
>>> Hi,
>>>
>>> I am using openwrt CC and an ubifs filesystem on top of ubi.
>>> If I plug off the power during startup, some times my configuration
>>> get lost and i am back to factory reset.
>>>
>>> In the package fstools there is the bin "mount_root" it is called
>>> twice during startup.
>>> 1. S10boot at line 10
>>> 2. S95done at line 6
>>>
>>> this calles edit the ./fs_state link
>>>
>>> S10boot/S95done:
>>> ---
>>> Because ubifs is doing filesystem handling in a background process
>>> "ubi_bgt0d", could it be possible,
>>> that (see code) ./.fs_state is not rewritten written anymore?
>>> So that at next boot the system thinks he is in upgrade mode?
>>>
>>> If I add a sleep(10) between unlink and symlink function call i can
>>> reproduce the failure if i unplug the power.
>>> I think the first think what should be done is to call
>>> "snprintf(valstr, sizeof(valstr), "%d", state);" before "unlink(path).
>>>
>>> Or this this a deeper Problem?
>> I think you're right that there's a race here. When I wrote this code,
>> I never actually intended for the file to get re-written after the
>> first boot, it seems that I simply forgot to add the necessary check
>> for it.
>> Please test if this fstools patch fixes the problem:
>> ---
>> --- a/libfstools/overlay.c
>> +++ b/libfstools/overlay.c
>> @@ -311,6 +311,9 @@ int fs_state_set(const char *dir, enum fs_state state)
>>         char valstr[16];
>>         char *path;
>>
>> +       if (fs_state_get(dir) == state)
>> +               return 0;
>> +
>>         path = alloca(strlen(dir) + 1 + sizeof("/.fs_state"));
>>         sprintf(path, "%s/.fs_state", dir);
>>         unlink(path);
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list