From 007b0d9e71b148a60be75990339a56d8a7cc0707 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 9 Jul 2025 14:17:08 +0700 Subject: [PATCH] fs: remove AddEvent/HandleEvent, make await OpenInode instead --- lib/9p.js | 24 +++++++++--------------- lib/filesystem.js | 39 ++------------------------------------- 2 files changed, 11 insertions(+), 52 deletions(-) diff --git a/lib/9p.js b/lib/9p.js index c6ac08cc..246e1084 100644 --- a/lib/9p.js +++ b/lib/9p.js @@ -322,21 +322,15 @@ Virtio9p.prototype.ReceiveRequest = async function (bufchain) { dbg_log("[open] fid=" + fid + ", mode=" + mode, LOG_9P); var idx = this.fids[fid].inodeid; var inode = this.fs.GetInode(idx); - dbg_log("file open " + this.fids[fid].dbg_name, LOG_9P); - //if (inode.status === STATUS_LOADING) return; - var ret = this.fs.OpenInode(idx, mode); + dbg_log("file open " + this.fids[fid].dbg_name + " tag:"+tag, LOG_9P); + await this.fs.OpenInode(idx, mode); - this.fs.AddEvent(this.fids[fid].inodeid, - function() { - dbg_log("file opened " + this.fids[fid].dbg_name + " tag:"+tag, LOG_9P); - var req = []; - req[0] = inode.qid; - req[1] = this.msize - 24; - marshall.Marshall(["Q", "w"], req, this.replybuffer, 7); - this.BuildReply(id, tag, 13+4); - this.SendReply(bufchain); - }.bind(this) - ); + req = []; + req[0] = inode.qid; + req[1] = this.msize - 24; + marshall.Marshall(["Q", "w"], req, this.replybuffer, 7); + this.BuildReply(id, tag, 13+4); + this.SendReply(bufchain); break; case 70: // link @@ -621,7 +615,7 @@ Virtio9p.prototype.ReceiveRequest = async function (bufchain) { this.BuildReply(id, tag, 4 + count); this.SendReply(bufchain); } else { - this.fs.OpenInode(this.fids[fid].inodeid, undefined); + await this.fs.OpenInode(this.fids[fid].inodeid, undefined); const inodeid = this.fids[fid].inodeid; count = Math.min(count, this.replybuffer.length - (7 + 4)); diff --git a/lib/filesystem.js b/lib/filesystem.js index 128cadc3..6d9262aa 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -62,7 +62,6 @@ const texten = new TextEncoder(); export function FS(storage, qidcounter) { /** @type {Array.} */ this.inodes = []; - this.events = []; 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