From df6c19d0330d251af0a7c812bf5ddb847962ce2c Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Sun, 28 Jul 2019 13:11:53 -0700 Subject: [PATCH] storage: Track opened files without backing storage Upon populating the shadow_buf the no fd is associated with the rmtfd. Therefor the next open request will conclude that the rmtfd is available and use the same entry. Fix this by checking for both associated fd and shadow_buf in the open call. Fixes: c35633ab2312 ("storage: Allow read only backing storage") Signed-off-by: Bjorn Andersson --- storage.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/storage.c b/storage.c index 1012051..d812419 100644 --- a/storage.c +++ b/storage.c @@ -65,6 +65,7 @@ int storage_init(const char *storage_root, bool read_only, bool use_partitions) for (i = 0; i < MAX_CALLERS; i++) { rmtfds[i].id = i; rmtfds[i].fd = -1; + rmtfds[i].shadow_buf = NULL; } return 0; @@ -93,14 +94,14 @@ struct rmtfd *storage_open(unsigned node, const char *path) found: /* Check if this node already has the requested path open */ for (i = 0; i < MAX_CALLERS; i++) { - if (rmtfds[i].fd != -1 && + if ((rmtfds[i].fd != -1 || rmtfds[i].shadow_buf) && rmtfds[i].node == node && rmtfds[i].partition == part) return &rmtfds[i]; } for (i = 0; i < MAX_CALLERS; i++) { - if (rmtfds[i].fd == -1) { + if (rmtfds[i].fd == -1 && !rmtfds[i].shadow_buf) { rmtfd = &rmtfds[i]; break; }