Skip to content

Storage: Fix FATFileSystem unmount issue #14137

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

Merged
merged 1 commit into from
Jan 20, 2021

Conversation

rajkan01
Copy link
Contributor

@rajkan01 rajkan01 commented Jan 11, 2021

Summary of changes

f_mount() (http://www.elm-chan.org/fsw/ff/00index_e.html - third party libary) API is called from both mount() and unmount() Mbed OS APIs.

f_mount() is doing both initializing (via find_volume() -> disk_initialize() where disk_initialize API calls Mbed OS block device init() function) underlying block device and register filesystem but in case of "unmount" calls, this f_mount is doing deregister filesystem and missed to a deinitializing block device.

So added the Mbed OS "deint()" call in unmount API to deinitialize block device as f_mount API doesn't have a way to call deinit().

fixes #12621

Impact of changes

With these changes, Unmount API will do both deregistering filesystem and deinitializing the underlaying block device.

Migration actions required

None.

Documentation

None.


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[x] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


@rajkan01 rajkan01 changed the title Storage: Fix FATFileSystem unmount issue Storage: Fix FATFileSystem unmount issue (Do not merge) Jan 11, 2021
@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Jan 11, 2021
@ciarmcom ciarmcom requested review from a team January 11, 2021 19:30
@ciarmcom
Copy link
Member

@rajkan01, thank you for your changes.
@ARMmbed/mbed-os-core @ARMmbed/mbed-os-maintainers please review.

@rajkan01 rajkan01 marked this pull request as draft January 11, 2021 19:47
@0xc0170 0xc0170 changed the title Storage: Fix FATFileSystem unmount issue (Do not merge) WIP: Storage: Fix FATFileSystem unmount issue (Do not merge) Jan 12, 2021
evedon
evedon previously requested changes Jan 12, 2021
@@ -330,8 +330,14 @@ int FATFileSystem::unmount()
}

FRESULT res = f_mount(NULL, _fsid, 0);
_ffs[_id] = NULL;
_id = -1;
if (!res) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

res is of type FRESULT not boolean, so check if res != FR_OK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done the rework in this PR, please re-review

@idea--list
Copy link
Contributor

idea--list commented Jan 14, 2021

f_mount() is doing both register filesystem and also initializing underlying block device, but in case of umount calls f_mount is doing deregister filesystem and it is not deinitializing block device

Yes, this is rather confusing. Even the documentation does not mention mount() would also initialize the blockdevice. I guess even those who wrote the examples just forgot about bd->deinit();
Lost a whole day googling for a solution. Just created #14150

Actually i am for adding bd->deinit() to fs.unmount(). That way also bd->deinit() would happen automatically, after which we need to call fs.mount(bd); anyway if we want to access the file system once again. At least i can not think of any use case where binding bd->deinit() to fs.unmount() would break the code.

@rajkan01 rajkan01 force-pushed the fix_fatfilesytem_unmount branch from a5ef032 to 1f94a5c Compare January 15, 2021 11:56
@mergify mergify bot dismissed evedon’s stale review January 15, 2021 11:56

Pull request has been modified.

@rajkan01 rajkan01 requested a review from evedon January 15, 2021 12:02
…y libary) API is called from both mount() and unmount() Mbed OS APIs.

f_mount() is doing both initializing (via find_volume() -> disk_initialize() where disk_initialize api calls Mbed OS init() function)
underlying block device and register filesystem but in case of "unmount" calls this f_mount is doing deregister filesystem
and missed to a deinitializing block device. So added the Mbed OS "deint()" call in unmount API to deinitialize block device
as f_mount API doesn't have a way to call deinit().
@rajkan01 rajkan01 force-pushed the fix_fatfilesytem_unmount branch from 1f94a5c to a29e3cd Compare January 15, 2021 12:05
@rajkan01 rajkan01 changed the title WIP: Storage: Fix FATFileSystem unmount issue (Do not merge) Storage: Fix FATFileSystem unmount issue Jan 15, 2021
@mergify mergify bot added needs: CI and removed needs: work labels Jan 15, 2021
@rajkan01 rajkan01 marked this pull request as ready for review January 17, 2021 10:40
@rajkan01
Copy link
Contributor Author

@0xc0170 This PR is ready for CI, could you please review and start the CI

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 19, 2021

CI started

@mergify mergify bot added needs: work and removed needs: CI labels Jan 20, 2021
@mbed-ci
Copy link

mbed-ci commented Jan 20, 2021

Jenkins CI Test : ❌ FAILED

Build Number: 3 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️

@rajkan01
Copy link
Contributor Author

@0xc0170 CI failure related to mbed deploy command failed with mbed os AWS example, please restart the CI

[2021-01-20T01:02:15.268Z] + python -u ../mbed-os/tools/test/examples/examples.py -c ./cloud_examples.json deploy

[2021-01-20T01:02:15.268Z] 

[2021-01-20T01:02:15.268Z] Deploying example repos....

[2021-01-20T01:02:15.268Z] 

[2021-01-20T01:02:15.268Z] [EXAMPLES]> INFO     In folder 'mbed-os-example-for-aws'

[2021-01-20T01:02:15.268Z] [EXAMPLES]> INFO     Executing command 'mbed-cli deploy'...

[2021-01-20T01:02:15.524Z] [mbed] ERROR: Unable to clone repository (https://github.com/ARMmbed/mbed-client-for-aws.git/#5f422c9449e5882855b84a26fb55fcc40edb5e6a)

[2021-01-20T01:02:15.524Z] ---

[2021-01-20T01:02:15.524Z] [mbed] Working path "/builds/workspace/mbed-os-ci_build-cloud-example-ARM/cloud-examples/mbed-os-example-for-aws" (program)

[2021-01-20T01:02:15.524Z] [mbed] Adding library "mbed-client-for-aws" from "https://github.com/ARMmbed/mbed-client-for-aws.git" at rev #5f422c9449e5

[2021-01-20T01:02:15.524Z] [EXAMPLES]> ERROR    mbed-cli deploy command failed for 'mbed-os-example-for-aws'

script returned exit code 1

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 20, 2021

Restarted

@mbed-ci
Copy link

mbed-ci commented Jan 20, 2021

Jenkins CI Test : ❌ FAILED

Build Number: 4 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM
jenkins-ci/mbed-os-ci_build-example-ARM
jenkins-ci/mbed-os-ci_build-example-GCC_ARM

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 20, 2021

CI restarted

@mbed-ci
Copy link

mbed-ci commented Jan 20, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 5 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️

@0xc0170 0xc0170 merged commit aeabb93 into ARMmbed:master Jan 20, 2021
@mergify mergify bot removed the ready for merge label Jan 20, 2021
@mbedmain mbedmain added release-version: 6.7.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FATFileSystem might call BlockDevice::init() multiple times when storage device is failing.
7 participants