WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] hvmloader/xenbus.c: How to modify or add a key-value pair in

To: Xen Devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] hvmloader/xenbus.c: How to modify or add a key-value pair in xenstore
From: Bei Guan <gbtju85@xxxxxxxxx>
Date: Sat, 13 Aug 2011 13:22:20 +0800
Cc: Ian Campbell <Ian.Campbell@xxxxxxxxxxxxx>, Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Fri, 12 Aug 2011 22:23:12 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=paDsCjTTdwqXXis8mFamrO2hQdvmylitpyhdtonlr3w=; b=bmmf1XgZ+PbMw0TMqpvST/2dzolEGjuLDbKWqVoaJeK5o1ymIUpZlFgj0UGFKAw0PM p9ATnPY7Wa/e878ood40ZcmmTRl1B3Q3UcxIhbOnLgvRwbc27Khw9xS+dGxIdfDJsw2e xlvUnajYiYEVQZuJmbSoVMoRCtuttxM0CdRls=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
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