Skip to content
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

sys/vfs: add vfs_mount_by_path() #17661

Merged
merged 2 commits into from
Feb 16, 2022
Merged

Conversation

benpicco
Copy link
Contributor

Contribution description

If auto-init of a default mount fs failed (e.g. because an SD card was not inserted on boot) or vfs_auto_mount was disabled, there is no way to mount such an auto-mount fs later manually.

Fix this by introducing a vfs_mount_by_path() function that takes the mount point of a pre-configured mount to trigger the mount procedure at run-time (e.g. when an SD card was inserted).

Testing procedure

I extended the vfs command with a mount sub-command.

vfs mount /

Issues/PRs references

@benpicco benpicco requested a review from chrysn February 15, 2022 15:11
@github-actions github-actions bot added the Area: sys Area: System label Feb 15, 2022
Copy link
Member

@chrysn chrysn left a comment

Choose a reason for hiding this comment

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

Generally looks good and straightforward.

An alternative way of identifying the mount point would be reconstructing the identifier (say, in a VFS_MOUNT_BY_AUTOMOUNT(littlefs2, 0); macro). Given that the boards would rather converge on the paths and not on the file systems and disambiguators, by_path is probably the better of these.

sys/include/vfs.h Outdated Show resolved Hide resolved
sys/include/vfs.h Outdated Show resolved Hide resolved
@@ -135,6 +138,21 @@ static int _df_handler(int argc, char **argv)
return 0;
}

#if IS_USED(VFS_DEFAULT)
Copy link
Member

Choose a reason for hiding this comment

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

Should be VFS_AUTO_MOUNT (it'd work just as well no matter whether these are defaults or set up by the application in a custom setup)

(also above in the corresponding help printf)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about we use XFA_LEN here instead?

Copy link
Member

Choose a reason for hiding this comment

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

Does that work? I figure that if VFS_AUTO_MOUNT is not present, the relevant symbols are not even defined.

If it works, it's probably good enough (given that shell is not something present on the tiniest systems anyway). Note that MOUNTPOINTS_NUMOF gets its const value only really late, when the linker has assigned addresses and the symbols are substituted into the code -- I don't think that on NUMOF == 0, the code behind the check would even be recognized as dead code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I remove the auto-mount:

--- a/boards/native/board_init.c
+++ b/boards/native/board_init.c
@@ -55,7 +55,7 @@ VFS_AUTO_MOUNT(littlefs, VFS_MTD(mtd0_dev), "/nvm", 0);
 #elif defined(MODULE_LITTLEFS2)
 
 #include "fs/littlefs2_fs.h"
-VFS_AUTO_MOUNT(littlefs2, VFS_MTD(mtd0_dev), "/nvm", 0);
+//VFS_AUTO_MOUNT(littlefs2, VFS_MTD(mtd0_dev), "/nvm", 0);
 
 /* spiffs support */
 #elif defined(MODULE_SPIFFS)
> vfs mount
vfs mount
vfs: unsupported sub-command "mount"

Copy link
Member

Choose a reason for hiding this comment

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

Oh work in the sense of runtime it sure does; I was more wondering whether it still builds when VFS_AUTO_MOUNT is not an active module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is examples/filesystem where vfs_auto_mount is not used

Copy link
Member

Choose a reason for hiding this comment

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

Weird, looking into it to fix my understanding.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, found it: The XFA_INIT (and even its user auto_init_vfs) is in immaterial of whether the automounter is set, so whenever VFS is there, that array is too.

Conversely, this probably works even when VFS_DEFAULT is on but VFS_AUTO_MOUNT is off, which is not bad, just unexpected (and not even contradicting the documentation) -- because the macro named VFS_AUTO_MOUNT and the module VFS_AUTO_MOUNT do slightly different things.

@chrysn chrysn added Area: fs Area: File systems Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation and removed Area: sys Area: System labels Feb 15, 2022
@chrysn
Copy link
Member

chrysn commented Feb 16, 2022

It's tangential (and not a proposal for addition here, although it might later share code), but are there any other operations that make sense over all auto-mountpoints? Seeing this in the PR list next to my "enumerate mount points" PR (#17660) makes me wonder if listing them too makes sense, or checking whether a mount is an automount.

vfs df (shifting towards a mixture of POSIX df and mount commands) could then list mountes, say whether they are automounted (which in hindsight is a confusing term, given that on Linux it means "detect insertion and mount then"), and also list (without showing their stats) potential mounts that are currently unmounted. (OK, maybe that would be more fitting to a no-further-arguments vfs mount that is a mixture of Linux's mount and cat /etc/fstab).

@benpicco
Copy link
Contributor Author

I thought about that too, (e.g. vfs_get_mount_by_path() but then after the mount there is no need to differentiate between auto-mounted mounts anymore.

@chrysn
Copy link
Member

chrysn commented Feb 16, 2022

after the mount there is no need to differentiate between auto-mounted mounts anymore.

Mh, not sure -- someone might want to unmount all automounted FSs before going into reboot or deeper sleep; but then again, that's all relatively custom anyway.

But then, so is mounting by a concrete path; maybe the "retry all previously failed automounts" would be a more precise fit for the initial use case you give?

It's all about going one-way from unmounted to mounted, after all -- the unmount that'd clear an SD card for removal would need application specific knowledge of what is actually safe to remove anyway.

@benpicco
Copy link
Contributor Author

maybe the "retry all previously failed automounts" would be a more precise fit for the initial use case you give?

But then we'd need to keep track of which auto-mounts did fail 😉

@chrysn
Copy link
Member

chrysn commented Feb 16, 2022 via email

@benpicco
Copy link
Contributor Author

Yea but it's much easier to use the "SD card inserted" GPIO interrupt and mount the path associated with the SD card then trying to (re-)mount all FSs on that event.

@chrysn
Copy link
Member

chrysn commented Feb 16, 2022 via email

Copy link
Member

@chrysn chrysn left a comment

Choose a reason for hiding this comment

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

For one minor thing I'd like your confirmation that you think it's good -- but once that's in or adjusted, ACK, please squash and go ahead.

/**
* @brief Auto-Mount array
*/
XFA_USE_CONST(vfs_mount_t, vfs_mountpoints_xfa);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
XFA_USE_CONST(vfs_mount_t, vfs_mountpoints_xfa);
XFA_USE(vfs_mount_t, vfs_mountpoints_xfa);

The array is init'd XFA_INIT (and not XFA_INIT_CONST), so I think it should be aligned type-wise (but I'm not sure -- it boils down to an extern being once used with const and once without, and I don't know whether the const is part of the type or just an effect here). I'm happy if you think it's fine. (It works, after all, and no Werrors show.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm I think it's good to use const here to promise that the array is not going to be modified by this file

@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Feb 16, 2022
@chrysn chrysn merged commit 395d031 into RIOT-OS:master Feb 16, 2022
@benpicco benpicco deleted the vfs_mount_path branch February 16, 2022 23:23
@OlegHahm OlegHahm added this to the Release 2022.04 milestone Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: fs Area: File systems Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants