Skip to content

[WasmFS] Track open files in the Node backend #16432

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 5 commits into from
Mar 9, 2022
Merged

Conversation

tlively
Copy link
Member

@tlively tlively commented Mar 5, 2022

Add callbacks to the DataFile API for notifying backends when files are opened
or closed, and call them from the OpenFileEntry constructor and destructor. In
the Node backend, open and close files on the underlying file system in these
callbacks and track the underlying file descriptor for opened files. This is
sufficient to allow the Node backend to correctly read and write opened files
that have been unlinked.

Open unlinked directories do not yet work correctly on the Node backend because
WasmFS zeroes the parent pointer on a different File object than the one held in
the open file table. Fixing that is left to a follow-on PR.

Add callbacks to the DataFile API for notifying backends when files are opened
or closed, and call them from the OpenFileEntry constructor and destructor. In
the Node backend, open and close files on the underlying file system in these
callbacks and track the underlying file descriptor for opened files. This is
sufficient to allow the Node backend to correctly read and write opened files
that have been unlinked.

Open unlinked directories do not yet work correctly on the Node backend because
WasmFS zeroes the parent pointer on a different File object than the one held in
the open file table. Fixing that is left to a follow-on PR.
@tlively tlively requested review from kripken and sbc100 March 5, 2022 00:30
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

mostly rubberstamp lgtm.. if the tests pass

} catch (e) {
if (!e.code) throw e;
return undefined;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Put the return and wasmfsNodeFixStat call after the try/catch?

$wasmfsNodeFstat: function(fd) {
let stat;
try {
return wasmfsNodeFixStat(fs.fstatSync(fd));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto

@@ -18,6 +18,8 @@ namespace wasmfs {
class MemoryFile : public DataFile {
std::vector<uint8_t> buffer;

void open() override {}
void close() override {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just male these default to empty function rather than pure virtual? (seems like overriding them is optional).

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I expect that all nontrivial backends will need to override these to get the correct behavior for accessing files after they have been unlinked, so I think it would be better to keep these non-optional.

@@ -130,14 +130,33 @@ def metafunc(self, wasmfs):
return metafunc


WASMFS_BACKEND_MAP = {'': 'WASMFS_MEMORY_BACKEND',
'node': 'WASMFS_NODE_BACKEND'}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like maybe exacting this map makes the two metafunc._parameterize below hard to read.. maybe just duplicate it instead? Feel free to disagree ..

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, maybe better to be DAMP than DRY here.

@tlively tlively merged commit 13344fa into main Mar 9, 2022
@tlively tlively deleted the wasmfs-node-unlink branch March 9, 2022 02:08
@dschuff
Copy link
Member

dschuff commented Mar 10, 2022

@tlively
Copy link
Member Author

tlively commented Mar 10, 2022

Ah bummer. I'll just disable it on Windows for now.

@tlively
Copy link
Member Author

tlively commented Mar 10, 2022

#16464

// The state of a file on the underlying Node file system.
class NodeState {
// Map all separate WasmFS opens of a file to a single underlying fd.
size_t openCount = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be atomic? Or does the node backend have some kind of assurance on running in a single thread like the old FS did?

Copy link
Member Author

Choose a reason for hiding this comment

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

Core WasmFS only ever calls backend methods while the corresponding file lock is held, so backends generally don't need to do their own additional synchronization unless they share state between files.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, right, thanks!

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

Successfully merging this pull request may close these issues.

4 participants