Re: [PATCH 4/4] rumpdisk: Install as translator when bootstrapping

2020-07-30 Thread Samuel Thibault
Damien Zammit, le mar. 28 juil. 2020 20:08:37 +1000, a ecrit:
> NB: Not sure why this seems to have no effect on /dev/rumpdisk
> Am I setting the translator on the wrong port?

You are doing it too early. It's only after fsys_startup is handled that
you have access to the boostrapped FS. So we'd need another hook in
libmachdev for the translator to do whatever it wants with the root FS.

Samuel



[PATCH 4/4] rumpdisk: Install as translator when bootstrapping

2020-07-28 Thread Damien Zammit
NB: Not sure why this seems to have no effect on /dev/rumpdisk
Am I setting the translator on the wrong port?

---
 rumpdisk/main.c | 29 +
 1 file changed, 29 insertions(+)

diff --git a/rumpdisk/main.c b/rumpdisk/main.c
index 27a8ea38..68fb8be2 100644
--- a/rumpdisk/main.c
+++ b/rumpdisk/main.c
@@ -31,6 +31,8 @@
 #include 
 #include 
 
+#define DEV_RUMPDISK   "/dev/rumpdisk"
+
 /* TODO: Add api to pciaccess to allow selecting backend.
  * For now we pretend to be the arbiter and claim x86 method.
  */
@@ -97,6 +99,28 @@ static struct argp_child empty_argp_children[] = {{0}};
 static struct argp rumpdisk_argp = {options, parse_opt, 0, 0, 
empty_argp_children};
 static const struct argp *rumpdisk_argp_bootup = _argp;
 
+static void
+install_as_translator (mach_port_t rumpdisk_port)
+{
+  error_t err;
+  file_t node;
+
+  node = file_name_lookup (DEV_RUMPDISK, O_NOTRANS, 0);
+  if (! MACH_PORT_VALID (node))
+{
+  if (errno == ENOENT)
+mach_print("Missing DEV_RUMPDISK\n");
+  return;
+}
+
+  err = file_set_translator (node,
+ 0, FS_TRANS_SET, 0,
+ NULL, 0,
+ rumpdisk_port, MACH_MSG_TYPE_COPY_SEND);
+  mach_port_deallocate (mach_task_self (), node);
+  assert_perror_backtrace (err);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -119,10 +143,15 @@ main (int argc, char **argv)
   rump_register_block ();
   machdev_device_init ();
   machdev_trivfs_init (bootstrap_resume_task, "fs", );
+
   err = pthread_create (, NULL, machdev_server, NULL);
   if (err)
 return err;
   pthread_detach (t);
+
+  if (bootstrap != MACH_PORT_NULL)
+install_as_translator (bootstrap);
+
   machdev_trivfs_server (bootstrap);
   return 0;
 }
-- 
2.25.1