race-condition in ram_fs and fs_query?
Guido Witmond
guido at witmond.nl
Mon May 20 13:27:16 CEST 2019
Hi Genodians,
I'm working on my HnH19-project to create a component listening on a
shared filesystem to open each pdf file into a separate instance of
mupdf. Goal is to tie the share to a linux-vm in vbox so firefox and
thunderbird can have a simple 'cp' command to get pdfs rendered outside
that vm.
I add a RAM-FS, FS-QUERY and REPORT-ROM to mupdf.run. The file gets put
in the ram-fs, fs-query should pick that up and report it to the report-rom.
<start name="pdf_share">
<binary name="ram_fs"/>
<resource name="RAM" quantum="128M"/>
<provides> <service name="File_system"/> </provides>
<config verbose="yes">
<default-policy root="/" writeable="yes" />
</config>
</start>
<start name="report_new_pdf">
<binary name="report_rom"/>
<resource name="RAM" quantum="1M"/>
<provides> <service name="Report"/> <service name="ROM"/>
</provides>
<config verbose="yes"/>
</start>
<start name="fs_query">
<resource name="RAM" quantum="1M"/>
<config verbose="yes">
<vfs> <fs writeable="yes"/> </vfs>
<query path="/" content="yes"/>
</config>
</start>
I change the test-scenario to copy a pdf into the share and start the
pdf-viewer. The viewer picks up the pdf and renders it. So far so good.
The problem is that while the 'add'-test copies the file, it gets
detected by fs_query but fs_query thinks it's gone:
[init -> test -> add] --- noux started ---
[init -> fs_query] Error: failed to watch '//foo.pdf'
[init -> fs_query] Warning: could not obtain content of nonexistent file
foo.pdf
(The error comes from gems/vfs.h L556, the warning from fs_query/main.cc
L80.)
Fs_quey does send a new report but does not show the file, it show an
empty directory.
[init -> report_new_pdf] report 'fs_query -> listing'
[init -> report_new_pdf] <listing>
[init -> report_new_pdf] <dir path="/"/>
[init -> report_new_pdf] </listing>
However, a ls -laR shows it's there:
[init -> test -> ls-after] /dest:
[init -> test -> ls-after] total 1
[init -> test -> ls-after] drwxr-xr-x 0 root 0 0 Jan 1 00:00 .
[init -> test -> ls-after] drwxr-xr-x 0 root 0 0 Jan 1 00:00 ..
[init -> test -> ls-after] -rwxrwxrwx 0 root 0 8192 Jan 1 00:00 foo.pdf
Now the race condition:
When I set the fs-query option to show the content to "no", it gives the
same error: failed to watch '//foo.pdf' but it now it does send the file
name to the report:
[init -> report_new_pdf] <file name="foo.pdf"/>
So it seems that somehow that fs_query watch learns there is a file
while the contents are not yet committed. Accessing that triggers a
file-not-found error.
Did I discover a race condition or am I doing something wrong?
With regards, Guido.
PS. I added the complete run-file and logs for completeness. (log-1
shows the contents-flag to no).
PPS. I'm testing with Qemu in a linux VM on my AMD nixos host.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: log.log
Type: text/x-log
Size: 15648 bytes
Desc: not available
URL: <http://lists.genode.org/pipermail/users/attachments/20190520/a2a9d3c0/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: log-1.log
Type: text/x-log
Size: 15289 bytes
Desc: not available
URL: <http://lists.genode.org/pipermail/users/attachments/20190520/a2a9d3c0/attachment-0003.bin>
-------------- next part --------------
set build_components { app/pdf_view server/ram_fs app/fs_query app/sequence }
source ${genode_dir}/repos/base/run/platform_drv.inc
build $build_components
create_boot_directory
import_from_depot \
[depot_user]/pkg/[drivers_interactive_pkg] \
[depot_user]/pkg/motif_wm \
[depot_user]/src/[base_src] \
[depot_user]/src/init \
[depot_user]/src/nitpicker \
[depot_user]/src/coreutils \
[depot_user]/src/bash \
[depot_user]/src/init \
[depot_user]/src/libc \
[depot_user]/src/noux \
[depot_user]/src/posix \
[depot_user]/src/report_rom \
[depot_user]/src/rom_to_file \
[depot_user]/src/vfs \
[depot_user]/src/vfs_import
set config {
<config verbose="yes">
<parent-provides>
<service name="ROM"/>
<service name="IRQ"/>
<service name="IO_MEM"/>
<service name="IO_PORT"/>
<service name="PD"/>
<service name="RM"/>
<service name="CPU"/>
<service name="LOG"/>
</parent-provides>
<default-route>
<service name="Nitpicker"> <child name="wm"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</default-route>
<default caps="100"/>
<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides><service name="Timer"/></provides>
</start>
<start name="drivers" caps="1000">
<resource name="RAM" quantum="32M" constrain_phys="yes"/>
<binary name="init"/>
<route>
<service name="ROM" label="config"> <parent label="drivers.config"/> </service>
<service name="Timer"> <child name="timer"/> </service>
<any-service> <parent/> </any-service>
</route>
<provides>
<service name="Input"/> <service name="Framebuffer"/>
</provides>
</start>
<start name="nitpicker">
<resource name="RAM" quantum="4M"/>
<provides><service name="Nitpicker"/></provides>
<config focus="rom">
<domain name="pointer" layer="1" content="client" label="no" origin="pointer" />
<domain name="default" layer="2" content="client" label="no" hover="always"/>
<policy label_prefix="pointer" domain="pointer"/>
<default-policy domain="default"/>
</config>
</start>
<start name="pointer">
<resource name="RAM" quantum="1M"/>
<route>
<service name="Nitpicker"> <child name="nitpicker"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>
<start name="wm" caps="1000">
<resource name="RAM" quantum="32M"/>
<binary name="init"/>
<provides> <service name="Nitpicker"/> </provides>
<route>
<service name="ROM" label="config"> <parent label="wm.config"/> </service>
<service name="Nitpicker"> <child name="nitpicker"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>
<!-- pdf_share is the filesystem that Linux writes pdf files to. -->
<start name="pdf_share">
<binary name="ram_fs"/>
<resource name="RAM" quantum="128M"/>
<provides> <service name="File_system"/> </provides>
<!--
<route>
<any-service> <parent/> <any-child/> </any-service>
</route>
-->
<config verbose="yes">
<default-policy root="/" writeable="yes" />
</config>
</start>
<!-- report_new_pdf reports to the pdf-viewer when there is a new pdf -->
<start name="report_new_pdf">
<binary name="report_rom"/>
<resource name="RAM" quantum="1M"/>
<provides> <service name="Report"/> <service name="ROM"/> </provides>
<config verbose="yes"/>
</start>
<!-- fs_query monitors the pdf_share for new files and writes a report into report_new_pdf -->
<start name="fs_query">
<resource name="RAM" quantum="1M"/>
<config verbose="yes">
<!-- <vfs> <dir name="fs"> <fs writeable="yes"/> </dir> </vfs> -->
<vfs> <fs writeable="yes"/> </vfs>
<query path="/" content="no"/>
</config>
<!--
<route>
<service name="File_system"> <child name="pdf_share" /> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
-->
</start>
<!-- TODO? rom_to_file picks up the new pdf from the report_new_pdf rom, makes it a file -->
<start name="test" caps="700">
<binary name="sequence"/>
<resource name="RAM" quantum="64M"/>
<config>
<start name="sleep" caps="500">
<binary name="noux"/>
<config stdin="/dev/null" stdout="/dev/log" stderr="/dev/log">
<fstab>
<tar name="coreutils.tar" />
<dir name="dev"> <log/> <null/> </dir>
</fstab>
<start name="/bin/sleep"> <arg value="2"/> </start>
</config>
</start>
<start name="ls-before" caps="500">
<binary name="noux"/>
<config stdin="/dev/null" stdout="/dev/log" stderr="/dev/log">
<fstab>
<tar name="coreutils.tar" />
<dir name="dest"> <fs writeable="yes"/> </dir>
<dir name="dev"> <log/> <null/> </dir>
<dir name="source"> <rom name="test.pdf" /> </dir>
</fstab>
<start name="/bin/ls">
<arg value="-laR" />
<arg value="/source" />
<arg value="/dest" />
</start>
0 </config>
<!--
<route>
<!- - <service name="File_system"> <child name="pdf-view-fs" /> </service>- ->
<service name="File_system"> <parent /> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
-->
</start>
<start name="add" caps="500">
<binary name="noux"/>
<config stdin="/dev/null" stdout="/dev/log" stderr="/dev/log">
<fstab>
<tar name="coreutils.tar" />
<dir name="dest"> <fs writeable="yes"/> </dir>
<dir name="dev"> <log/> <null/> </dir>
<dir name="source"> <rom name="test.pdf" /> </dir>
</fstab>
<start name="/bin/cp">
<arg value="/source/test.pdf" />
<!-- <arg value="/dev/null" /> -->
<arg value="/dest/foo.pdf" />
</start>
</config>
<!--
<route>
<!- - <service name="File_system"> <child name="pdf-view-fs" /> </service>- ->
<service name="File_system"> <parent /> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
-->
</start>
<start name="ls-after" caps="500">
<binary name="noux"/>
<config stdin="/dev/null" stdout="/dev/log" stderr="/dev/log">
<fstab>
<tar name="coreutils.tar" />
<dir name="dest"> <fs writeable="yes"/> </dir>
<dir name="dev"> <log/> <null/> </dir>
<dir name="source"> <rom name="test.pdf" /> </dir>
</fstab>
<start name="/bin/ls">
<arg value="-laR" />
<arg value="/source" />
<arg value="/dest" />
</start>
</config>
<!--
<route>
<!- - <service name="File_system"> <child name="pdf-view-fs" /> </service>- ->
<service name="File_system"> <parent /> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
-->
</start>
<start name="pdf_view" caps="256">
<resource name="RAM" quantum="1G"/>
<config>
<vfs>
<dir name="dev"> <log/> </dir>
<fs /> <!-- points to pdf_share -->
</vfs>
<libc stdout="/dev/log" stderr="/dev/log"/>
</config>
<!--
<route>
<service name="Nitpicker"> <child name="nitpicker" /> </service>
<service name="File_system"> <child name="pdf-view-fs" /> </service>
<!- - /dev/log goes to any service LOG - ->
<any-service> <parent/> <any-child/> </any-service>
</route>
-->
</start>
</config>
<!--
<route>
<service name="File_system"> <child name="pdf_share" /> </service>
<!- - <service name="File_system"> <parent /> </service> - ->
<any-service> <any-child/> <parent/> </any-service>
</route>
-->
</start>
<!--
<start name="rom_to_file">
<resource name="RAM" quantum="2M"/>
<config rom="dynamic_rom"/>
<route>
<service name="ROM" label="dynamic_rom"> <child name="dynamic_rom"/> </service>
<service name="File_system" > <child name="vfs"/> </service>
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>
-->
<!-- TODO: Feed the rom-to-file file to a fresh instance of pdf-view. -->
<!-- start a dynamic sub-init here -->
<!--
<start name="pdf-view-fs">
<binary name="ram_fs"/>
<resource name="RAM" quantum="256M"/>
<provides> <service name="File_system"/> </provides>
<route>
<any-service> <parent/> <any-child/> </any-service>
</route>
<config>
<default-policy root="/" writeable="yes" />
</config>
</start>
<start name="pdf_view" caps="256">
<resource name="RAM" quantum="1G"/>
<config>
<vfs>
<dir name="dev"> <log/> </dir>
<fs /> <!- - points to pdf_share - ->
</vfs>
<libc stdout="/dev/log" stderr="/dev/log"/>
</config>
<route>
<service name="Nitpicker"> <child name="nitpicker" /> </service>
<service name="File_system"> <child name="pdf-view-fs" /> </service>
<!- - /dev/log goes to any service LOG - ->
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>
-->
<!-- end sub-init here -->
<!--
<start name="pdf_view" caps="256">
<resource name="RAM" quantum="1G"/>
<config>
<vfs>
<rom name="test.pdf" />
<dir name="dev"> <log/> </dir>
</vfs>
<libc stdout="/dev/log" stderr="/dev/log"/>
</config>
</start>
-->
</config>
}
install_config $config
#
# Downloadotest PDF file
#
if {![file exist bin/test.pdf]} {
set pdf_url "http://genode-labs.com/publications/genode-fpga-graphics-2009.pdf"
catch { exec wget $pdf_url -O bin/test.pdf }
}
if {![file exist bin/test.pdf]} {
puts stderr "Could not download test PDF from '$pdf_url'"
exit 1
}
#
# Pin the nitpicker focus to the window manager by providing a static focus ROM
#
set fd [open [run_dir]/genode/focus w]
puts $fd "<focus label=\"wm -> focus\"/>"
close $fd
append boot_modules {
libc.lib.so vfs.lib.so libm.lib.so
openjpeg.lib.so freetype.lib.so libpng.lib.so zlib.lib.so jbig2dec.lib.so
mupdf.lib.so jpeg.lib.so
ram_fs
fs_query sequence
pdf_view
test.pdf
}
build_boot_image $boot_modules
append qemu_args " -m 1536"
set env(SDL_VIDEO_X11_DGAMOUSE) 0
run_genode_until forever
More information about the users
mailing list