fs: remove AddEvent/HandleEvent, make await OpenInode instead

This commit is contained in:
Fabian 2025-07-09 14:17:08 +07:00
parent 5aeac32af3
commit 007b0d9e71
2 changed files with 11 additions and 52 deletions

View file

@ -322,21 +322,15 @@ Virtio9p.prototype.ReceiveRequest = async function (bufchain) {
dbg_log("[open] fid=" + fid + ", mode=" + mode, LOG_9P); dbg_log("[open] fid=" + fid + ", mode=" + mode, LOG_9P);
var idx = this.fids[fid].inodeid; var idx = this.fids[fid].inodeid;
var inode = this.fs.GetInode(idx); var inode = this.fs.GetInode(idx);
dbg_log("file open " + this.fids[fid].dbg_name, LOG_9P); dbg_log("file open " + this.fids[fid].dbg_name + " tag:"+tag, LOG_9P);
//if (inode.status === STATUS_LOADING) return; await this.fs.OpenInode(idx, mode);
var ret = this.fs.OpenInode(idx, mode);
this.fs.AddEvent(this.fids[fid].inodeid, req = [];
function() { req[0] = inode.qid;
dbg_log("file opened " + this.fids[fid].dbg_name + " tag:"+tag, LOG_9P); req[1] = this.msize - 24;
var req = []; marshall.Marshall(["Q", "w"], req, this.replybuffer, 7);
req[0] = inode.qid; this.BuildReply(id, tag, 13+4);
req[1] = this.msize - 24; this.SendReply(bufchain);
marshall.Marshall(["Q", "w"], req, this.replybuffer, 7);
this.BuildReply(id, tag, 13+4);
this.SendReply(bufchain);
}.bind(this)
);
break; break;
case 70: // link case 70: // link
@ -621,7 +615,7 @@ Virtio9p.prototype.ReceiveRequest = async function (bufchain) {
this.BuildReply(id, tag, 4 + count); this.BuildReply(id, tag, 4 + count);
this.SendReply(bufchain); this.SendReply(bufchain);
} else { } else {
this.fs.OpenInode(this.fids[fid].inodeid, undefined); await this.fs.OpenInode(this.fids[fid].inodeid, undefined);
const inodeid = this.fids[fid].inodeid; const inodeid = this.fids[fid].inodeid;
count = Math.min(count, this.replybuffer.length - (7 + 4)); count = Math.min(count, this.replybuffer.length - (7 + 4));

View file

@ -62,7 +62,6 @@ const texten = new TextEncoder();
export function FS(storage, qidcounter) { export function FS(storage, qidcounter) {
/** @type {Array.<!Inode>} */ /** @type {Array.<!Inode>} */
this.inodes = []; this.inodes = [];
this.events = [];
this.storage = storage; this.storage = storage;
@ -139,39 +138,6 @@ FS.prototype.set_state = function(state)
// ----------------------------------------------------- // -----------------------------------------------------
FS.prototype.AddEvent = function(id, OnEvent) {
var inode = this.inodes[id];
if(inode.status === STATUS_OK || inode.status === STATUS_ON_STORAGE) {
OnEvent();
}
else if(this.is_forwarder(inode))
{
this.follow_fs(inode).AddEvent(inode.foreign_id, OnEvent);
}
else
{
this.events.push({id: id, OnEvent: OnEvent});
}
};
FS.prototype.HandleEvent = function(id) {
const inode = this.inodes[id];
if(this.is_forwarder(inode))
{
this.follow_fs(inode).HandleEvent(inode.foreign_id);
}
//dbg_log("number of events: " + this.events.length, LOG_9P);
var newevents = [];
for(var i=0; i<this.events.length; i++) {
if(this.events[i].id === id) {
this.events[i].OnEvent();
} else {
newevents.push(this.events[i]);
}
}
this.events = newevents;
};
FS.prototype.load_from_json = function(fs) FS.prototype.load_from_json = function(fs)
{ {
dbg_assert(fs, "Invalid fs passed to load_from_json"); dbg_assert(fs, "Invalid fs passed to load_from_json");
@ -695,11 +661,11 @@ FS.prototype.CreateBinaryFile = async function(filename, parentid, buffer) {
}; };
FS.prototype.OpenInode = function(id, mode) { FS.prototype.OpenInode = async function(id, mode) {
var inode = this.inodes[id]; var inode = this.inodes[id];
if(this.is_forwarder(inode)) if(this.is_forwarder(inode))
{ {
return this.follow_fs(inode).OpenInode(inode.foreign_id, mode); return await this.follow_fs(inode).OpenInode(inode.foreign_id, mode);
} }
if((inode.mode&S_IFMT) === S_IFDIR) { if((inode.mode&S_IFMT) === S_IFDIR) {
this.FillDirectory(id); this.FillDirectory(id);
@ -714,7 +680,6 @@ FS.prototype.OpenInode = function(id, mode) {
} }
*/ */
//dbg_log("open:" + this.GetFullPath(id) + " type: " + inode.mode + " status:" + inode.status, LOG_9P); //dbg_log("open:" + this.GetFullPath(id) + " type: " + inode.mode + " status:" + inode.status, LOG_9P);
return true;
}; };
FS.prototype.CloseInode = async function(id) { FS.prototype.CloseInode = async function(id) {