[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [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@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |