Skip to content

lfs_deorphan may enter infinity loop. #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kneko715 opened this issue Sep 13, 2018 · 5 comments
Closed

lfs_deorphan may enter infinity loop. #98

kneko715 opened this issue Sep 13, 2018 · 5 comments

Comments

@kneko715
Copy link

After some unexpected hardware reset, lfs_deorphan() entered an infinite loop and not return forever.
In that time, cwd.pair / cwd.head / cwd.d.tail took following value.

cwd.pair[0]=2; cwd.pair[1]=3;
cwd.head[0]=0; cwd.head[1]=0;
cwd.d.tail[0]=2; cwd.d.tail[1]=3;

I know root cause is unexpected hardware reset, but lfs_deorphan() should detect infinity loop and return error code for caller.

Thank you.

@geky
Copy link
Member

geky commented Sep 19, 2018

Hi @kneko715 thanks for opening an issue. You're right we should probably make that loop terminate.

Although, littlefs should never really end up that state. What do you mean by hardware reset? Even if power is lost in the middle of a filesystem operation littlefs should be able to recover.

If you still have the broken disk image around, could you send me a copy so I can see if I can figure out that cause?

@geky
Copy link
Member

geky commented Sep 19, 2018

Patch here to break out of the inifinite loop #103

Thinking about possible failure cases, it's possible this could have happened if you interrupt lfs_format with a power failure. Do you think that might have been the source of the problem?

@FreddieChopin
Copy link
Contributor

Just a sidenote about the fix in #103 - the fixed behaviour won't be far from "infinite loop" on a very large device (several GB of SD card).

@kneko715
Copy link
Author

kneko715 commented Sep 21, 2018

@getky thanks for reply and creating patch.

Sorry, broken disk image has already lost.

"unexpected hardware reset" means unexpected power failure.
At that time, I was testing littlefs api.
The test case includes lfs_mount, lfs_format and lfs_unmount, so it's possibility that the power failure interrupted lfs_format.

The patch is effective for our device. Thank you.

@geky
Copy link
Member

geky commented Sep 21, 2018

@FreddieChopin, good point. It seems like at least > 4 hours on a 4 GB SD card...

It's the best solution I can think for the short term. At least in 2.0, format will only need to create 1 metadata pair, so it should be no longer possible to create this infinite loop during format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants