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: c35633ab23 ("storage: Allow read only backing storage")
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Bjorn Andersson 2019-07-28 13:11:53 -07:00
parent 6d2cfcddfc
commit df6c19d033

View File

@ -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;
}