Skip to content

Standardized FileSystem init/deinit/reset to match KVStore API #8700

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
wants to merge 1 commit into from

Conversation

geky
Copy link
Contributor

@geky geky commented Nov 9, 2018

Description

This standardizes init/deinit/reset to match behaviour in KVStore and BlockDevice. This makes init consistent across all three APIs.

Standardized:

  • FileSystem::mount -> FileSystem::init
  • FileSystem::unmount -> FileSystem::deinit
  • FileSystem::reformat -> FileSystem::reset

Note that init/reset do not accept BlockDevice arguments. This paves the way to standardizing classes to be configured only at construction time.

To make this work, recursive init/deinit functions were needed similar to the BlockDevices, and these init/deinit functions are lazily called during the first filesystem operations to match the existing behavior where init/deinit are ignored completely.

Pull request type

[ ] Fix
[ ] Refactor
[ ] Target update
[x] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Related to #8667
cc @armmbed/mbed-os-storage, @deepikabhavnani, @dannybenor, @davidsaada

Standardized:
FileSystem::mount    -> FileSystem::init
FileSystem::unmount  -> FileSystem::deinit
FileSystem::reformat -> FileSystem::reset

Note that init/reset no longer accept BlockDevice arguments. This paves
the way to standardizing classes to be configured only at construction
time.

To make this work, recursive init/deinit functions were needed similar
to the BlockDevices, and these init/deinit functions are lazily called
during the first filesystem operations to match the existing behavior
where init/deinit are ignored completely.
@geky geky force-pushed the fs-consistent-init branch from bcef816 to 833379c Compare November 9, 2018 22:27
Copy link
Contributor

@davidsaada davidsaada left a comment

Choose a reason for hiding this comment

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

Great change, great timing. 👍

Copy link

@deepikabhavnani deepikabhavnani left a comment

Choose a reason for hiding this comment

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

Looks good to me, just few queries for my understanding

}

FATFileSystem::~FATFileSystem()
{
// nop if unmounted
unmount();
// noop if unmounted

Choose a reason for hiding this comment

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

Is the comment still valid? Unmounted - Not initialized?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! The reference counting also handles more deinits than inits:

if (_ref > 0) {
        _ref -= 1;
        if (_ref == 0) {
            res = f_mount(NULL, _fsid, 0);
            _ffs[_id] = NULL;
            _id = -1;
        }
    }
}

*/
virtual int deinit();

/** Reformats the underlying filesystem

Choose a reason for hiding this comment

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

Should we specify explicitly that file system will be initialised and mounted as part of reset call?

}

/* See http://elm-chan.org/fsw/ff/en/mkfs.html for details of f_mkfs() and
* associated arguments. */
int FATFileSystem::format(BlockDevice *bd, bd_size_t cluster_size)
{
FATFileSystem fs;
fs.lock();

Choose a reason for hiding this comment

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

Not sure why locking is removed in format operation..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, it's because I narrowed the scope of the fs instance.

The file system only exists inside this function, so locking didn't have any benefit.

*
* The init function may be called multiple times recursively as long
* as each init has a matching deinit. If not called, the file system
* will be mounted on the first file system operation.

Choose a reason for hiding this comment

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

Reset will be considered as valid call before init?

@dannybenor
Copy link

@geky I need some review here to understand the motivation, will look at this after the weekend

@offirko
Copy link
Contributor

offirko commented Nov 11, 2018

Lazy init() comes with its toll .. lots of copies of "if (_ref == 0) { // make sure we're mounted ..." .. not sure if its avoidable..
Is Lazy init() supposed to handle only cases where the user didn't call init() at all , or also cover cases where the user did call init() but after he did other stuff (maybe timing issue)

I thought of these scenarios e.g. (maybe its not legit or I got it wrong..)

Scenario (A):

  1. Init() : _ref=1
  2. Remove("blabla") : _ref=1
  3. Deinit() : ref=0
    Final state is Deinitialized.

Scenario (B):

  1. Remove("blabla") : _ref=1 (lazy init)
  2. Init() : _ref=2
  3. Deinit() : ref=1
    Final state is Initialized.

@dannybenor
Copy link

@geky This change defines existing API as deprecated and introduces new APIs.
It lacks testing
It is issued at a very late stage of 5.11, therefore I do not think it fits 5.11

@geky
Copy link
Contributor Author

geky commented Nov 12, 2018

@dannybenor, up to you. It would be nice to have the big storage changes in the same release.

@deepikabhavnani
Copy link

It lacks testing

It will be good to have test cases updated in same PR. Apart from that it looks good to me 👍

@adbridge
Copy link
Contributor

@dannybenor @geky Could you please confirm whether you expect this to come into 5.11 or not ? As this is changing APIs including deprecation then if it does not make 5.11 it is delayed to 5.12....

@dannybenor
Copy link

This should be delayed to 5.12. Needs review outside github.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 19, 2018

This should be delayed to 5.12. Needs review outside github.

The version label was updated.

@cmonr
Copy link
Contributor

cmonr commented Dec 14, 2018

@ARMmbed/mbed-os-storage Any progress? This has idled for nearly a month.

@dannybenor
Copy link

@cmonr This needs review outside github. Not sure how to mark it but do expect this to be solved soon

@NirSonnenschein
Copy link
Contributor

@geky , FYI: this now needs a rebase as well.

@cmonr
Copy link
Contributor

cmonr commented Dec 21, 2018

@dannybenor That comment is sufficient. Let us know if the review will end up taking more than two weeks.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 16, 2019

As this is being discussed offlline, we will close this PR. Please reopen with an update

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.

9 participants