Mini-OS: preparations for 9pfs in xenstore-stubdom
v3 cover Mini-OS: preparations for 9pfs in xenstore-stubdom
This small patch series is doing some preparations for being able to use 9pfs in Xenstore-stubdom.
Changes in V2:
- added patches 2 and 5
Changes in V3:
- rename function to get own domid (patch 2)
Juergen Gross (5):
Mini-OS: make xenstore_buf externally visible
Mini-OS: get own domid
Mini-OS: don't crash if no shutdown node is available
Mini-OS: fix 9pfs stat receive format
Mini-OS: fix 9pfs response receiving
9pfront.c | 13 ++++++++----- events.c | 33 +++++++++++++++++++++++++++++++++ include/lib.h | 3 +++ include/xenbus.h | 2 ++ shutdown.c | 12 ++++-------- xenbus.c | 2 +- 6 files changed, 51 insertions(+), 14 deletions(-)
Signature · 1 line
2.35.3
PATCH v3 1/5 Mini-OS: make xenstore_buf externally visible
For support of the 9pfs frontend in Xenstore-stubdom xenstore_buf needs to be externally visible.
--- include/xenbus.h | 2 ++ xenbus.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
include/xenbus.h +2 -0
@@ -8,12 +8,14 @@ typedef unsigned long xenbus_transaction_t;#ifdef CONFIG_XENBUS extern uint32_t xenbus_evtchn; +extern struct xenstore_domain_interface *xenstore_buf;/* Initialize the XenBus system. */ void init_xenbus (void );void get_xenbus (void *p);#else #define xenbus_evtchn ~0 +#define xenstore_buf NULLstatic inline void init_xenbus (void ) {
xenbus.c +1 -1
@@ -44,7 +44,7 @@ #define DEBUG(_f, _a...) ((void)0)#endif -static struct xenstore_domain_interface *xenstore_buf; +struct xenstore_domain_interface *xenstore_buf;static DECLARE_WAIT_QUEUE_HEAD (xb_waitq);DECLARE_WAIT_QUEUE_HEAD (xenbus_watch_queue); static __DECLARE_SEMAPHORE_GENERIC(xb_write_sem, 1);
Signature · 1 line
2.35.3
PATCH v3 2/5 Mini-OS: get own domid
In reply to Juergen GrossGet the own domid via creation of a temporary event channel. There is no "official" way to read the own domid in PV guests, so use the event channel interface to get it:
- allocate an unbound event channel specifying DOMID_SELF for the other end
- read the event channel status which will contain the own domid in unbound.dom
- close the event channel
---
V2:
- new patch
V3:
- rename function to get_domid() (Julien Grall)
--- events.c | 33 +++++++++++++++++++++++++++++++++ include/lib.h | 3 +++ 2 files changed, 36 insertions(+)
events.c +33 -0
@@ -261,6 +261,39 @@ int evtchn_get_peercontext(evtchn_port_t local_port, char *ctx, int size)return rc; } +/* Replace below when a hypercall is available to get the domid. */ +domid_t get_domid (void ) +{ +int rc; +domid_t domid =DOMID_INVALID ; +evtchn_alloc_unbound_t op; +struct evtchn_status status; +struct evtchn_close close; + + op.dom =DOMID_SELF ; + op.remote_dom =DOMID_SELF ; + rc =HYPERVISOR_event_channel_op (EVTCHNOP_alloc_unbound, &op); +if ( rc ) + { +printk ("ERROR: alloc_unbound failed with rc=%d" , rc); +return domid; + } + + status.dom =DOMID_SELF ; + status.port = op.port; + rc =HYPERVISOR_event_channel_op (EVTCHNOP_status, &status); +if ( rc ) +printk ("ERROR: EVTCHNOP_status failed with rc=%d" , rc); +else + domid = status.u.unbound.dom; + + close.port = op.port; + rc =HYPERVISOR_event_channel_op (EVTCHNOP_close, &close); +if ( rc ) +printk ("WARN: close_port %d failed rc=%d. ignored\n" , close.port, rc); + +return domid; +}/* * Local variables:
include/lib.h +3 -0
@@ -154,6 +154,9 @@ do { \/* Consistency check as much as possible. */ void sanity_check (void ); +/* Get own domid. */ +domid_t get_domid (void ); +#ifdef HAVE_LIBC extern struct wait_queue_head event_queue;
Signature · 1 line
2.35.3
Re: [PATCH v3 2/5] Mini-OS: get own domid
Juergen Gross, le mar. 21 nov. 2023 10:49:50 +0100, a ecrit:
Quoted 7 lines
Get the own domid via creation of a temporary event channel. There is no "official" way to read the own domid in PV guests, so use the event channel interface to get it:
- allocate an unbound event channel specifying
DOMID_SELFfor the other end
Quoted 6 lines
- read the event channel status which will contain the own domid in unbound.dom
- close the event channel
Signed-off-by Juergen Gross <[email protected]
Thanks!
Quoted 72 lines
---
V2:
- new patch
V3:
- rename function toget_domid()(Julien Grall)Signed-off-by Juergen Gross <[email protected]>--- events.c | 33 +++++++++++++++++++++++++++++++++ include/lib.h | 3 +++ 2 files changed, 36 insertions(+)events.c +33
-0@@ -261,6 +261,39 @@ int evtchn_get_peercontext(evtchn_port_t local_port, char *ctx, int size)return rc; } +/* Replace below when a hypercall is available to get the domid. */ +domid_t get_domid (void ) +{ +int rc; +domid_t domid =DOMID_INVALID ; +evtchn_alloc_unbound_t op; +struct evtchn_status status; +struct evtchn_close close; + + op.dom =DOMID_SELF ; + op.remote_dom =DOMID_SELF ; + rc =HYPERVISOR_event_channel_op (EVTCHNOP_alloc_unbound, &op); +if ( rc ) + { +printk ("ERROR: alloc_unbound failed with rc=%d" , rc); +return domid; + } + + status.dom =DOMID_SELF ; + status.port = op.port; + rc =HYPERVISOR_event_channel_op (EVTCHNOP_status, &status); +if ( rc ) +printk ("ERROR: EVTCHNOP_status failed with rc=%d" , rc); +else + domid = status.u.unbound.dom; + + close.port = op.port; + rc =HYPERVISOR_event_channel_op (EVTCHNOP_close, &close); +if ( rc ) +printk ("WARN: close_port %d failed rc=%d. ignored\n" , close.port, rc); + +return domid; +}/* * Local variables: include/lib.h +3
-0@@ -154,6 +154,9 @@ do { \/* Consistency check as much as possible. */ void sanity_check (void ); +/* Get own domid. */ +domid_t get_domid (void ); +#ifdef HAVE_LIBC extern struct wait_queue_head event_queue;Signature · 1 line
2.35.3
Signature · 4 lines
Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.
PATCH v3 3/5 Mini-OS: don't crash if no shutdown node is available
In reply to Juergen GrossIt might be perfectly fine not to have a control/shutdown Xenstore node. If this is the case, don't crash, but just terminate the shutdown thread after issuing a message that shutdown isn't available.
In fini_shutdown() clearing the watch can result in an error now, in case the early exit above was taken. Just ignore this error now.
--- shutdown.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
shutdown.c +4 -8
@@ -75,7 +75,9 @@ static void shutdown_thread(void *p)xenbus_wait_for_watch (&events);if ((err =xenbus_read (XBT_NIL , path, &shutdown))) {free (err); -do_exit (); +free (xenbus_unwatch_path_token (XBT_NIL , path, token)); +printk ("Shutdown Xenstore node not available.\n" ); +return ; }if (end_shutdown_thread)
@@ -117,15 +119,9 @@ void init_shutdown(void)void fini_shutdown (void ) { -char *err; - end_shutdown_thread =1 ;xenbus_release_wait_for_watch (&events); - err =xenbus_unwatch_path_token (XBT_NIL , path, token); -if (err) { -free (err); -do_exit (); - } +free (xenbus_unwatch_path_token (XBT_NIL , path, token)); }#endif
Signature · 1 line
2.35.3
PATCH v3 4/5 Mini-OS: fix 9pfs stat receive format
In reply to Juergen GrossThe format string of the received data for the 9pfs stat command is missing the initial 2 byte total length specifier. Add it.
--- 9pfront.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
9pfront.c +5 -4
@@ -711,6 +711,7 @@ static int p9_create(struct dev_9pfs *dev, uint32_t fid, char *path,static int p9_stat (struct dev_9pfs *dev,uint32_t fid,struct p9_stat *stat) {struct req *req =get_free_req (dev); +uint16_t total;int ret;if ( !req )
@@ -719,10 +720,10 @@ static int p9_stat(struct dev_9pfs *dev, uint32_t fid, struct p9_stat *stat)memset (stat,0 ,sizeof (*stat)); req->cmd =P9_CMD_STAT ;send_9p (dev, req,"U" , fid); -rcv_9p (dev, req,"uuUQUUULSSSSSUUU" , &stat->size, &stat->type, &stat->dev, - stat->qid, &stat->mode, &stat->atime, &stat->mtime, &stat->length, - &stat->name, &stat->uid, &stat->gid, &stat->muid, &stat->extension, - &stat->n_uid, &stat->n_gid, &stat->n_muid); +rcv_9p (dev, req,"uuuUQUUULSSSSSUUU" , &total, &stat->size, &stat->type, + &stat->dev, stat->qid, &stat->mode, &stat->atime, &stat->mtime, + &stat->length, &stat->name, &stat->uid, &stat->gid, &stat->muid, + &stat->extension, &stat->n_uid, &stat->n_gid, &stat->n_muid); ret = req->result;
Signature · 1 line
2.35.3
PATCH v3 5/5 Mini-OS: fix 9pfs response receiving
In reply to Juergen GrossWhen copying a 9pfs response chunk from the ring buffer across the ring end, the local ring pointer and length field are not updated correctly. Fix that.
---
V2:
- new patch
--- 9pfront.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
9pfront.c +3 -1
@@ -386,7 +386,9 @@ static void copy_bufs(unsigned char **buf1, unsigned char **buf2,printk ("9pfs: short copy (dropping %u bytes)\n" , len - *len1); len = *len1; } -memcpy (target, *buf1, *len1); +memcpy (target, *buf1, len); + *buf1 += len; + *len1 -= len; } }
Signature · 1 line
2.35.3
Re: [PATCH v3 5/5] Mini-OS: fix 9pfs response receiving
Juergen Gross, le mar. 21 nov. 2023 10:49:53 +0100, a ecrit:
Quoted 6 lines
When copying a 9pfs response chunk from the ring buffer across the ring end, the local ring pointer and length field are not updated correctly. Fix that.
Fixes 0924fec1de58 ("Mini-OS: add 9pfs transport layer")Signed-off-by Juergen Gross <[email protected]>
Thanks!
Quoted 25 lines
---
V2:
- new patch--- 9pfront.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)9pfront.c +3
-1@@ -386,7 +386,9 @@ static void copy_bufs(unsigned char **buf1, unsigned char **buf2,printk ("9pfs: short copy (dropping %u bytes)\n" , len - *len1); len = *len1; } -memcpy (target, *buf1, *len1); +memcpy (target, *buf1, len); + *buf1 += len; + *len1 -= len; } }Signature · 1 line
2.35.3
Signature · 4 lines
Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.
Quoted 9 lines · Juergen Gross
This small patch series is doing some preparations for being able to use 9pfs in Xenstore-stubdom.
Changes in V2:
- added patches 2 and 5Changes in V3:
- rename function to get own domid (patch 2)
Quoted 6 lines
Juergen Gross (5):
Mini-OS: makexenstore_bufexternally visible
Mini-OS: get own domid
Mini-OS: don't crash if no shutdown node is available
Mini-OS: fix 9pfs stat receive format
Mini-OS: fix 9pfs response receiving
Committed.
I guess you want to patch xen.git to use minios master now?
~Andrew