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

Re: [Xen-devel] Regarding Xenstore/Xenbus

Thanks for your reply. I was into trying out xenstore acess using 'libxenstore.so'. I have copied the exact code that I am trying to run (most of this comes from xenstore wiki). The issue is that I am able to run this code from dom0 but when I try to run it from inside a domU after the first printf output i.e. "Msg1" it terminates abnormally saying "unknown error". My guess is that its failing when it calls xs_daemon_open(). I can't figure out what am i missing. Some processes need to be started before i can acess xenstore? Are there any packages that need to be installed in domU to access xenstore? I already have 'xen-devel', 'xen-lib' and 'xen-tools' packages installed inside domU. Please help.

-------------------------------------------------------------------------------------------

#include <xs.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>

void main(int argc, char *argv[])
{

   struct xs_handle *xs;
   xs_transaction_t th;
   char *path;
   int fd;
   fd_set set;
   int er;
   struct timeval tv = {.tv_sec = 0, .tv_usec = 0 };
   char **vec;
   unsigned int num;
   char * buf;
   char ** buf2;
   unsigned int len;

   unsigned int domid;

   printf("Msg1\n");

   /* Get a connection to the daemon */
   xs = xs_daemon_open();
   if ( xs == NULL ) error();

   th = xs_transaction_start(xs);
       buf2 = xs_directory(xs, th,"/local/domain", &len);
   xs_transaction_end(xs, th, true);

   int i=0;

   for(i=0;i<len;i++)
   {
       printf("%s\n",buf2[i]);
   }

// I am running dom0 and oly 1 domU so this condition chooses one of them
   if(len>1)
       domid = atoi(buf2[1]);
   if(len==1)
       domid = atoi(buf2[0]);
       //sprintf( domid, "%ui", buf2[0] );

   printf("Domid: %i\n", domid);

   /* Get the local domain path */
   path = xs_get_domain_path(xs, domid);
   if ( path == NULL ) error();

   printf("Msg3\n");

   /* Make space for our node on the path */
   path = realloc(path, strlen(path) + strlen("/memory/target") + 1);
   if ( path == NULL ) error();
   strcat(path, "/memory/target");

   /* Create a watch on /local/domain/%d/mynode. */
   er = xs_watch(xs, path, "mytoken");
   if ( er == 0 ) error();

   /* We are notified of read availability on the watch via the
    * file descriptor.
    */
   fd = xs_fileno(xs);

   while (1)
   {
       FD_ZERO(&set);
       FD_SET(fd, &set);

       /* Poll for data. */
       if ( select(fd + 1, &set, NULL, NULL, &tv) > 0
            && FD_ISSET(fd, &set))
       {
           /* I am not sure how num works -- please describe. */
           vec = xs_read_watch(xs, &num);
           if ( !vec ) error();
           printf("vec contents: %s|%s\n", vec[XS_WATCH_PATH],
                                           vec[XS_WATCH_TOKEN]);

           /* Prepare a transaction and do a read. */
           th = xs_transaction_start(xs);
               buf = xs_read(xs, th, vec[XS_WATCH_PATH], &len);
           xs_transaction_end(xs, th, true);
           if ( buf )
           {
               printf("buflen: %d\nbuf: %s\n", len, buf);
           }

           /* Prepare a transaction and do a write. */
           /*th = xs_transaction_start(xs);
er = xs_write(xs, th, path, "somestuff", strlen("somestuff"));
           xs_transaction_end(xs, th, true);
           if ( er == 0 ) error();*/
       }
   }

   /* Cleanup */
   close(fd);
   xs_daemon_close(xs);
   free(path);

}
-------------------------------------------------------------------------------------------

----- Original Message ----- From: "Andrew D. Ball" <aball@xxxxxxxxxxxxxxxxxx>
To: "Umar Farooq Minhas" <umarfm13@xxxxxxxxxxx>
Cc: <xen-devel@xxxxxxxxxxxxxxxxxxx>
Sent: Monday, November 20, 2006 5:02 PM
Subject: Re: [Xen-devel] Regarding Xenstore/Xenbus


I think that's right.  Look into using libxenstore inside of the domU --
I think there are functions to do what you want there.

Peace.
Andrew


On Sun, 2006-11-19 at 03:09 -0500, Umar Farooq Minhas wrote:
Hi everyone,

I have installed Xen on OpenSUSE Linux 10.1 and am just starting to
develop with Xen. I want to implement a very straightforward
application in domUs which simply gets notified whenever a resource
provisioning change (specifically for cpu/memory allocation) is made
for that particular domU using for example xm mem-set. From the
readings that I have done so far it seems that since xenstore is a
shared database between all the domains which keeps track of domain
specific values(including values of allocated resources) and that it
can be accessed through xenbus from domUs so what I need to do is to
write a program that would access xenstore from withing that domU over
xenbus. Or more specifically I will have to register a 'watch' in
xenstore (just as the balloon driver does) to monitor memory values. I
don't know whether this is true or not. I would greatly appreciate if
someone could verify this understanding or point me in the right
direction. Also if this is true some pointers to start developing with
xenbus/xenstore would be very helpful.

A prompt response will be appreciated as I am running on a deadline :)

Thanks.
-Umar
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel




_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>