diff mbox series

[20/29] tools: add 9pfs device to xenstore-stubdom

Message ID 20231101093325.30302-21-jgross@suse.com (mailing list archive)
State Superseded
Headers show
Series tools: enable xenstore-stubdom to use 9pfs | expand

Commit Message

Jürgen Groß Nov. 1, 2023, 9:33 a.m. UTC
Add a 9pfs device to Xenstore stubdom in order to allow it to do e.g.
logging into a dom0 file.

Use the following parameters for the new device:

- tag = "xen"
- type = "xenlogd"
- path = "/var/lib/xen/xenstore"

For now don't limit allowed file space or number of files.

Add a new libxl function for adding it similar to the function for
adding the console device.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 tools/helpers/init-xenstore-domain.c |  2 ++
 tools/include/libxl.h                | 17 ++++++++++++++++
 tools/libs/light/libxl_9pfs.c        | 29 ++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+)

Comments

Jason Andryuk Nov. 7, 2023, 7:18 p.m. UTC | #1
On Wed, Nov 1, 2023 at 8:23 AM Juergen Gross <jgross@suse.com> wrote:
>
> Add a 9pfs device to Xenstore stubdom in order to allow it to do e.g.
> logging into a dom0 file.
>
> Use the following parameters for the new device:
>
> - tag = "xen"
> - type = "xenlogd"
> - path = "/var/lib/xen/xenstore"
>
> For now don't limit allowed file space or number of files.
>
> Add a new libxl function for adding it similar to the function for
> adding the console device.
>
> Signed-off-by: Juergen Gross <jgross@suse.com>

> diff --git a/tools/libs/light/libxl_9pfs.c b/tools/libs/light/libxl_9pfs.c
> index 0b9d84dce9..3297389493 100644
> --- a/tools/libs/light/libxl_9pfs.c
> +++ b/tools/libs/light/libxl_9pfs.c
> @@ -174,6 +174,35 @@ static void libxl__device_p9_add(libxl__egc *egc, uint32_t domid,
>          aodev->callback(egc, aodev);
>  }
>
> +int libxl_p9_add_xenstore(libxl_ctx *ctx, uint32_t domid, uint32_t backend,
> +                          libxl_p9_type type, char *tag, char *path,
> +                          unsigned int max_space, unsigned int max_files,
> +                          unsigned int max_open_files, bool auto_delete,
> +                          const libxl_asyncop_how *ao_how)
> +{
> +    AO_CREATE(ctx, domid, ao_how);
> +    libxl__ao_device *aodev;
> +    libxl_device_p9 p9 = { .backend_domid = backend,
> +                           .tag = tag,
> +                           .path = path,
> +                           .security_model = "none",

While the xl.cfg man page states that only security_model="none" is
supported, it is possible to use other ones.    The value isn't
inspected and it is just passed through Xenstore to QEMU.  QEMU can
then operate however it operates.  I just tested mapped-xattr and it's
working from some quick testing.  So maybe libxl_p9_add_xenstore()
should take security_model as an argument, and then
init-xenstore-domain can pass in "none"?

Everything else looks good, so either way:
Reviewed-by: Jason Andryuk <jandryuk@gmail.com>
Jürgen Groß Nov. 8, 2023, 6:54 a.m. UTC | #2
On 07.11.23 20:18, Jason Andryuk wrote:
> On Wed, Nov 1, 2023 at 8:23 AM Juergen Gross <jgross@suse.com> wrote:
>>
>> Add a 9pfs device to Xenstore stubdom in order to allow it to do e.g.
>> logging into a dom0 file.
>>
>> Use the following parameters for the new device:
>>
>> - tag = "xen"
>> - type = "xenlogd"
>> - path = "/var/lib/xen/xenstore"
>>
>> For now don't limit allowed file space or number of files.
>>
>> Add a new libxl function for adding it similar to the function for
>> adding the console device.
>>
>> Signed-off-by: Juergen Gross <jgross@suse.com>
> 
>> diff --git a/tools/libs/light/libxl_9pfs.c b/tools/libs/light/libxl_9pfs.c
>> index 0b9d84dce9..3297389493 100644
>> --- a/tools/libs/light/libxl_9pfs.c
>> +++ b/tools/libs/light/libxl_9pfs.c
>> @@ -174,6 +174,35 @@ static void libxl__device_p9_add(libxl__egc *egc, uint32_t domid,
>>           aodev->callback(egc, aodev);
>>   }
>>
>> +int libxl_p9_add_xenstore(libxl_ctx *ctx, uint32_t domid, uint32_t backend,
>> +                          libxl_p9_type type, char *tag, char *path,
>> +                          unsigned int max_space, unsigned int max_files,
>> +                          unsigned int max_open_files, bool auto_delete,
>> +                          const libxl_asyncop_how *ao_how)
>> +{
>> +    AO_CREATE(ctx, domid, ao_how);
>> +    libxl__ao_device *aodev;
>> +    libxl_device_p9 p9 = { .backend_domid = backend,
>> +                           .tag = tag,
>> +                           .path = path,
>> +                           .security_model = "none",
> 
> While the xl.cfg man page states that only security_model="none" is
> supported, it is possible to use other ones.    The value isn't
> inspected and it is just passed through Xenstore to QEMU.  QEMU can
> then operate however it operates.  I just tested mapped-xattr and it's
> working from some quick testing.  So maybe libxl_p9_add_xenstore()
> should take security_model as an argument, and then
> init-xenstore-domain can pass in "none"?

Yes, good idea.

> 
> Everything else looks good, so either way:
> Reviewed-by: Jason Andryuk <jandryuk@gmail.com>

Thanks,

Juergen
diff mbox series

Patch

diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
index 140ed610ae..a65abae2ac 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -543,6 +543,8 @@  int main(int argc, char** argv)
     }
     libxl_console_add_xenstore(ctx, domid, 0, console_evtchn, console_gfn,
                                NULL);
+    libxl_p9_add_xenstore(ctx, domid, 0, LIBXL_P9_TYPE_XENLOGD, "xen",
+                          XEN_LIB_DIR"/xenstore", 0, 0, 0, 0, NULL);
     libxl_ctx_free(ctx);
 
     fd = creat(XEN_RUN_DIR "/xenstored.pid", 0666);
diff --git a/tools/include/libxl.h b/tools/include/libxl.h
index 907aa0a330..ab8a67f50a 100644
--- a/tools/include/libxl.h
+++ b/tools/include/libxl.h
@@ -583,6 +583,13 @@ 
  * libxl_console_add_xenstore() in libxl.
  */
 #define LIBXL_HAVE_CONSOLE_ADD_XENSTORE 1
+
+/*
+ * LIBXL_HAVE_P9_ADD_XENSTORE indicates presence of the function
+ * libxl_p9_add_xenstore() in libxl.
+ */
+#define LIBXL_HAVE_P9_ADD_XENSTORE 1
+
 /*
  * libxl ABI compatibility
  *
@@ -2060,6 +2067,16 @@  int libxl_console_add_xenstore(libxl_ctx *ctx, uint32_t domid, uint32_t backend,
                                const libxl_asyncop_how *ao_how)
                                LIBXL_EXTERNAL_CALLERS_ONLY;
 
+/* libxl_p9_add_xenstore writes the Xenstore entries for a domain's
+ * primary 9pfs device based on domid, backend type and device parameters.
+ */
+int libxl_p9_add_xenstore(libxl_ctx *ctx, uint32_t domid, uint32_t backend,
+                          libxl_p9_type type, char *tag, char *path,
+                          unsigned int max_space, unsigned int max_files,
+                          unsigned int max_open_files, bool auto_delete,
+                          const libxl_asyncop_how *ao_how)
+                          LIBXL_EXTERNAL_CALLERS_ONLY;
+
 /* May be called with info_r == NULL to check for domain's existence.
  * Returns ERROR_DOMAIN_NOTFOUND if domain does not exist (used to return
  * ERROR_INVAL for this scenario). */
diff --git a/tools/libs/light/libxl_9pfs.c b/tools/libs/light/libxl_9pfs.c
index 0b9d84dce9..3297389493 100644
--- a/tools/libs/light/libxl_9pfs.c
+++ b/tools/libs/light/libxl_9pfs.c
@@ -174,6 +174,35 @@  static void libxl__device_p9_add(libxl__egc *egc, uint32_t domid,
         aodev->callback(egc, aodev);
 }
 
+int libxl_p9_add_xenstore(libxl_ctx *ctx, uint32_t domid, uint32_t backend,
+                          libxl_p9_type type, char *tag, char *path,
+                          unsigned int max_space, unsigned int max_files,
+                          unsigned int max_open_files, bool auto_delete,
+                          const libxl_asyncop_how *ao_how)
+{
+    AO_CREATE(ctx, domid, ao_how);
+    libxl__ao_device *aodev;
+    libxl_device_p9 p9 = { .backend_domid = backend,
+                           .tag = tag,
+                           .path = path,
+                           .security_model = "none",
+                           .type = type,
+                           .max_space = max_space,
+                           .max_files = max_files,
+                           .max_open_files = max_open_files,
+                           .auto_delete = auto_delete,
+                         };
+
+    GCNEW(aodev);
+    libxl__prepare_ao_device(ao, aodev);
+    aodev->action = LIBXL__DEVICE_ACTION_ADD;
+    aodev->callback = device_addrm_aocomplete;
+
+    libxl__device_p9_add(egc, domid, &p9, aodev);
+
+    return AO_INPROGRESS;
+}
+
 #define libxl_device_p9_list NULL
 #define libxl_device_p9_compare NULL