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] Re: hvmloader/xenbus.c: How to modify or add a key-value pai

To: Xen Devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] Re: hvmloader/xenbus.c: How to modify or add a key-value pair in xenstore
From: Bei Guan <gbtju85@xxxxxxxxx>
Date: Sat, 13 Aug 2011 17:37:53 +0800
Cc: Ian Campbell <Ian.Campbell@xxxxxxxxxxxxx>, Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Sat, 13 Aug 2011 02:38:49 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=OYb1QbwSIDHw4Eei2fl7/Xd2Tw+t6y7ialNFGrBaH2A=; b=c4Lh6m2QDqy2fhmmqXH6Q412FG/v/yBU0sM9fUddYodAlsuGxhPLkubSbbl4uI8W5a eUiguxz2lU9hEjWd5ibN2ZzUa5+NxS4qaVyuUskVdneztp7aPtkp44mt2kk3c/hDSrQv S8/h4nrr1BM4VngdZRG6JJYD47FLQvV6oLiaU=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <CAEQjb-RKsd0zPrb7g20CgZ3YWogerWQY0u96rKDRwMMAbUDKrQ@xxxxxxxxxxxxxx>
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>
References: <CAEQjb-RKsd0zPrb7g20CgZ3YWogerWQY0u96rKDRwMMAbUDKrQ@xxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx


2011/8/13 Bei Guan <gbtju85@xxxxxxxxx>
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@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel