Bei Guan
2011-Aug-13 05:22 UTC
[Xen-devel] hvmloader/xenbus.c: How to modify or add a key-value pair in xenstore
Hi, In hvmloader/xenbus.c, a simple implementation of xenbus, the function xenbus_send() (see the prototype below) can be used to read a value from xenstore. static int xenbus_send(uint32_t type, uint32_t len, const char *data, uint32_t *reply_len, const char **reply_data) Now, I want to modify a key-value existed in xenstore or add a new key-value pair into xenstore, so I write a new function xenbus_write_send(), which is changed from xenbus_send(). It is pasted in the following. The red part is what have changed. However, this function doesn''t work well. The "path"=>"value" can be updated or added into xenstore. Is there anything problem with this function? Any reply is appreciated. struct reqs{ const char *data; unsigned len; }; /* This method can be used to modify the old value of "path" to "value"; And add a new "path"=>"value" pair into xenstore. */ static int xenbus_write_send(uint32_t type, const char *path, const char *value, uint32_t *reply_len, const char **reply_data) { struct xsd_sockmsg hdr; evtchn_send_t send; int i; int p, len, nr_req; /* Not acceptable to use xenbus before setting it up */ ASSERT(rings != NULL); struct reqs req[] = { {path, strlen(path) + 1}, {value, strlen(value)}, }; len = strlen(path) + 1 + strlen(value); nr_req = 2; /* Put the request on the ring */ hdr.type = type; hdr.req_id = 0; /* We only ever issue one request at a time */ hdr.tx_id = 0; /* We never use transactions */ hdr.len = len; ring_write((char *) &hdr, sizeof hdr); for (p = 0; p < nr_req; p++) { ring_write(req[p].data, req[p].len); } /* Tell the other end about the request */ send.port = event; hypercall_event_channel_op(EVTCHNOP_send, &send); /* Properly we should poll the event channel now but that involves * mapping the shared-info page and handling the bitmaps. */ /* Pull the reply off the ring */ ring_read((char *) &hdr, sizeof(hdr)); ring_read(payload, hdr.len); /* For sanity''s sake, nul-terminate the answer */ payload[hdr.len] = ''\0''; /* Handle errors */ if ( hdr.type == XS_ERROR ) { *reply_len = 0; for ( i = 0; i < ((sizeof xsd_errors) / (sizeof xsd_errors[0])); i++ ) if ( !strcmp(xsd_errors[i].errstring, payload) ) return xsd_errors[i].errnum; /* Default error value if we couldn''t decode the ASCII error */ return EIO; } *reply_data = NULL; *reply_len = hdr.len; return 0; } Best Regards, Bei Guan _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Bei Guan
2011-Aug-13 09:37 UTC
[Xen-devel] Re: hvmloader/xenbus.c: How to modify or add a key-value pair in xenstore
2011/8/13 Bei Guan <gbtju85@gmail.com>> Hi, > > In hvmloader/xenbus.c, a simple implementation of xenbus, the function > xenbus_send() (see the prototype below) can be used to read a value from > xenstore. > static int xenbus_send(uint32_t type, uint32_t len, const char *data, > uint32_t *reply_len, const char **reply_data) > > Now, I want to modify a key-value existed in xenstore or add a new > key-value pair into xenstore, so I write a new function > xenbus_write_send(), which is changed from xenbus_send(). It is pasted in > the following. The red part is what have changed. However, this function > doesn''t work well. The "path"=>"value" can be updated or added into > xenstore. Is there anything problem with this function? Any reply is > appreciated. > > struct reqs{ > const char *data; > unsigned len; > }; > > /* > This method can be used to modify the old value of "path" to "value"; > And add a new "path"=>"value" pair into xenstore. > */ > static int xenbus_write_send(uint32_t type, const char *path, const char > *value, > uint32_t *reply_len, const char **reply_data) > { > struct xsd_sockmsg hdr; > evtchn_send_t send; > int i; > int p, len, nr_req; > > /* Not acceptable to use xenbus before setting it up */ > ASSERT(rings != NULL); > > struct reqs req[] = { > {path, strlen(path) + 1}, > {value, strlen(value)}, > }; > len = strlen(path) + 1 + strlen(value); > nr_req = 2; > > /* Put the request on the ring */ > hdr.type = type; > hdr.req_id = 0; /* We only ever issue one request at a time */ > hdr.tx_id = 0; /* We never use transactions */ > hdr.len = len; > ring_write((char *) &hdr, sizeof hdr); > > for (p = 0; p < nr_req; p++) { > ring_write(req[p].data, req[p].len); > } > > /* Tell the other end about the request */ > send.port = event; > hypercall_event_channel_op(EVTCHNOP_send, &send); > > /* Properly we should poll the event channel now but that involves > * mapping the shared-info page and handling the bitmaps. */ > > /* Pull the reply off the ring */ > ring_read((char *) &hdr, sizeof(hdr)); > ring_read(payload, hdr.len); >The error message here is EACCES.> /* For sanity''s sake, nul-terminate the answer */ > payload[hdr.len] = ''\0''; > > /* Handle errors */ > if ( hdr.type == XS_ERROR ) > { > *reply_len = 0; > for ( i = 0; i < ((sizeof xsd_errors) / (sizeof xsd_errors[0])); > i++ ) > if ( !strcmp(xsd_errors[i].errstring, payload) ) > return xsd_errors[i].errnum; > /* Default error value if we couldn''t decode the ASCII error */ > return EIO; > } > > *reply_data = NULL; > *reply_len = hdr.len; > return 0; > } > > Best Regards, > Bei Guan > > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Tim Deegan
2011-Aug-15 09:43 UTC
Re: [Xen-devel] hvmloader/xenbus.c: How to modify or add a key-value pair in xenstore
Hi, At 13:22 +0800 on 13 Aug (1313241740), Bei Guan wrote:> In hvmloader/xenbus.c, a simple implementation of xenbus, the function > xenbus_send() (see the prototype below) can be used to read a value from > xenstore. > static int xenbus_send(uint32_t type, uint32_t len, const char *data, > uint32_t *reply_len, const char **reply_data) > > Now, I want to modify a key-value existed in xenstore or add a new key-value > pair into xenstore, so I write a new function xenbus_write_send(), which is > changed from xenbus_send().I think you should make a xenbus_write() function based on xenbus_read(), rather than duplicating all of xenbus_send(). Tim. -- Tim Deegan <tim@xen.org> Principal Software Engineer, Xen Platform Team Citrix Systems UK Ltd. (Company #02937203, SL9 0BG) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Tim Deegan
2011-Aug-15 09:44 UTC
Re: [Xen-devel] Re: hvmloader/xenbus.c: How to modify or add a key-value pair in xenstore
At 17:37 +0800 on 13 Aug (1313257073), Bei Guan wrote:> The error message here is EACCES.Uh-huh. So, what key and value are you trying to write? Does your VM have write permissions to that part of the store? Tim. -- Tim Deegan <tim@xen.org> Principal Software Engineer, Xen Platform Team Citrix Systems UK Ltd. (Company #02937203, SL9 0BG) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Bei Guan
2011-Aug-15 15:20 UTC
Re: [Xen-devel] Re: hvmloader/xenbus.c: How to modify or add a key-value pair in xenstore
2011/8/15 Tim Deegan <tim@xen.org>> At 17:37 +0800 on 13 Aug (1313257073), Bei Guan wrote: > > The error message here is EACCES. > > Uh-huh. So, what key and value are you trying to write? Does your VM > have write permissions to that part of the store? >I try to write some new key-value pairs or modify some existed key in the the DomU''s xenstore tree, such as /local/domain/<DomId>/<key>. The <DomId> is the ID of the DomainU. Maybe the VM doesn''t have the permission to write its own key in Xenstore. So, how to make the VM to have the permission to write the key and value in Xenstore? Thanks, Bei Guan> > Tim. > > -- > Tim Deegan <tim@xen.org> > Principal Software Engineer, Xen Platform Team > Citrix Systems UK Ltd. (Company #02937203, SL9 0BG) >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Tim Deegan
2011-Aug-16 09:10 UTC
Re: [Xen-devel] Re: hvmloader/xenbus.c: How to modify or add a key-value pair in xenstore
At 23:20 +0800 on 15 Aug (1313450426), Bei Guan wrote:> 2011/8/15 Tim Deegan <tim@xen.org> > > > At 17:37 +0800 on 13 Aug (1313257073), Bei Guan wrote: > > > The error message here is EACCES. > > > > Uh-huh. So, what key and value are you trying to write? Does your VM > > have write permissions to that part of the store? > > > I try to write some new key-value pairs or modify some existed key in the > the DomU''s xenstore tree, such as /local/domain/<DomId>/<key>. The <DomId> > is the ID of the DomainU. > Maybe the VM doesn''t have the permission to write its own key in Xenstore. > So, how to make the VM to have the permission to write the key and value in > Xenstore?xenstore-ls -p will show you the ACLs on the various keys and xenstore-chmod will let you change them, for testing. Tim. -- Tim Deegan <tim@xen.org> Principal Software Engineer, Xen Platform Team Citrix Systems UK Ltd. (Company #02937203, SL9 0BG) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2011-Aug-16 09:17 UTC
Re: [Xen-devel] Re: hvmloader/xenbus.c: How to modify or add a key-value pair in xenstore
On Mon, 2011-08-15 at 16:20 +0100, Bei Guan wrote:> Maybe the VM doesn''t have the permission to write its own key in > Xenstore.It is quite common for keys in xenstore to be ro for the guest (only the backend or toolstack domain can write to them). Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Bei Guan
2011-Aug-16 15:32 UTC
Re: [Xen-devel] Re: hvmloader/xenbus.c: How to modify or add a key-value pair in xenstore
Many thanks to all of you. I see there are some functions in mini-os/xenbus/xenbus.c, such as xenbus_write() and xenbus_rm(). All of them seem to change the keys and values in xenstore. I have tried these functions and found that they have no effect on the keys and values in xenstore. So, do these functions can really work? What special things need I to do to make them work? Thanks, Bei Guan 2011/8/16 Ian Campbell <Ian.Campbell@eu.citrix.com>> On Mon, 2011-08-15 at 16:20 +0100, Bei Guan wrote: > > Maybe the VM doesn''t have the permission to write its own key in > > Xenstore. > > It is quite common for keys in xenstore to be ro for the guest (only the > backend or toolstack domain can write to them). > > Ian. > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2011-Aug-16 15:37 UTC
Re: [Xen-devel] Re: hvmloader/xenbus.c: How to modify or add a key-value pair in xenstore
(please do not top post) On Tue, 2011-08-16 at 16:32 +0100, Bei Guan wrote:> Many thanks to all of you. > I see there are some functions in mini-os/xenbus/xenbus.c, such as > xenbus_write() and xenbus_rm(). All of them seem to change the keys > and values in xenstore. I have tried these functions and found that > they have no effect on the keys and values in xenstore.Tried in the context of mini-os or tried by ripping them out and into hvmloader?> So, do these functions can really work?mini-os''s frontend drivers presumably use them so I''d expect so.> What special things need I to do to make them work?Which specific path are you trying to write?> > > > > Thanks, > Bei Guan > > > 2011/8/16 Ian Campbell <Ian.Campbell@eu.citrix.com> > On Mon, 2011-08-15 at 16:20 +0100, Bei Guan wrote: > > Maybe the VM doesn''t have the permission to write its own > key in > > Xenstore. > > > It is quite common for keys in xenstore to be ro for the guest > (only the > backend or toolstack domain can write to them). > > Ian. > > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Bei Guan
2011-Aug-16 16:42 UTC
Re: [Xen-devel] Re: hvmloader/xenbus.c: How to modify or add a key-value pair in xenstore
2011/8/16 Ian Campbell <Ian.Campbell@eu.citrix.com>> (please do not top post) > > On Tue, 2011-08-16 at 16:32 +0100, Bei Guan wrote: > > Many thanks to all of you. > > I see there are some functions in mini-os/xenbus/xenbus.c, such as > > xenbus_write() and xenbus_rm(). All of them seem to change the keys > > and values in xenstore. I have tried these functions and found that > > they have no effect on the keys and values in xenstore. > > Tried in the context of mini-os or tried by ripping them out and into > hvmloader? >I tried in the context of mini-os. I use the test function in mini-os/xenbus/xenbus.c, such as do_write_test("device/vif/0/flibble", "flobble"). Also I comment out the do_rm_test("device/vif/0/flibble"). When the mini-os starts to run, I use the xenstore-ls to see the keys and values, but I cannot find the key /local/domain/<domId>/device/vif/0/flibble and its value.> > > So, do these functions can really work? > > mini-os''s frontend drivers presumably use them so I''d expect so. >Yes, I saw the frontend drivers use these functions. But, it seems all the keys are created by dom0 or other tools instead of mini-os itself. When I change the key name in the front driver that is going to be create by method xenbus_printf(), such as change from err = xenbus_printf(xbt, nodename, "ring-ref","%u", dev->ring_ref); to err = xenbus_printf(xbt, nodename, "ring-ref-0","%u", dev->ring_ref); I cannot find the ring-ref-0 in xenstore, when mini-os is running.> > > What special things need I to do to make them work? > > Which specific path are you trying to write? >I am not sure if the domain can operate any keys and values in /local/domain/<Id of this domain>/, such as change "name" to another one, add a new key-value /local/domain/<Id of this domain>/new-key = new-value. Thanks, Bei Gua> > > > > > > > > > > Thanks, > > Bei Guan > > > > > > 2011/8/16 Ian Campbell <Ian.Campbell@eu.citrix.com> > > On Mon, 2011-08-15 at 16:20 +0100, Bei Guan wrote: > > > Maybe the VM doesn''t have the permission to write its own > > key in > > > Xenstore. > > > > > > It is quite common for keys in xenstore to be ro for the guest > > (only the > > backend or toolstack domain can write to them). > > > > Ian. > > > > > > > > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel