Skip to contentSkip to conversation

Regarding Xenstore/Xenbus

DISCUSSION Umar Farooq Minhas 3 participants 5 messages Nov 19, 2006 – Nov 23, 2006

lore
Share & tools
lore
#0 lore raw

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
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

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

Quoted 27 lines · Umar Farooq Minhas

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
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw

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" <[email protected]>
To: "Umar Farooq Minhas" <[email protected]>
Cc: <[email protected]>
Sent: Monday, November 20, 2006 5:02 PM
Subject: Re: [Xen-devel] Regarding Xenstore/Xenbus

Quoted 37 lines

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

Quoted 27 lines · Umar Farooq Minhas

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
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 10 lines · Umar Farooq Minhas

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.

you need to use "domain_open" instead of "daemon_open" in domU.

daemon_open is using a direct unix socket to communicate with xenstored. this socket is only accessible to dom0. domU need to use the other way to communicate with xenstored.

Cheers,

Signature · 1 line
Vincent Hanquez
#4 lore raw

Once again thanks for replying, I appreciate your patience.

Actually I already realized that mistake and replaced "daemon_open" with "domain_open". But getting the "unknown error" has now changed into a "segmentation fault" and apparently it occurs after i execute the "xs_directory" function to get the path in buf2 variable (line31 below). I checked the value of 'len' variable after the call and it turns out to be arbitrarily large. What am I doing wrong here ? After replacing "daemon_open" with "domain_open" all the rest of the calls to xs.h functions remain the same or are there specific "daemon" and "domain" versions of functions? (apparently its the former case)

A few related questions:

-Are there any specific initializations/calls that need to be made from inside domU to first initialize and then access xenstore ? Or the functions exposed by xs.h are the only thing required ? Apparently xenstore is initialized by dom0 once at startup only.

-Does ability to communicate with xenstore depend on whether the ethernet interface b/w dom0 and domU is working or not (since it uses sockets)? Currently my domU can't ping dom0 or any one else for that matter.

-I am trying to only read the xenstore(which is allowed to all domains by default), does my problem in anyway relate to xenstore access permissions ?

-Are you aware of any user-space management tools available that access xenstore from within domU?

Sorry for a detailed mail but I am just a beginner and dont know a lot of stuff.

I'll appreciate your help once again.

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

1   #include <xs.h>
2   #include <sys/types.h>
3   #include <stdio.h>
4   #include <string.h>

5
6 void main(int argc, char *argv[])
7 {
8

9      struct xs_handle *xs;
10     xs_transaction_t th;
11     char *path;
12     int fd;
13     fd_set set;
14     int er;
15     struct timeval tv = {.tv_sec = 0, .tv_usec = 0 };
16     char **vec;
17     unsigned int num;
18     char * buf;
19     char ** buf2;
20     unsigned int len;

21
22 unsigned int domid;
23
24 printf("Msg1\n");
25

26     /* Get a connection to the daemon */
27     xs = xs_domain_open();
28     if ( xs == NULL ) error();

29
30 th = xs_transaction_start(xs);
31 buf2 = xs_directory(xs, th,"/local/domain", &len);
32 xs_transaction_end(xs, th, true);
33
34 int i=0;
35
36 for(i=0;i<len;i++)
37 {
38 printf("%s\n",buf2[i]);
39 }
40
41
42 // I am running dom0 and oly 1 domU so this condition chooses one of them
43 if(len>1)
44 domid = atoi(buf2[1]);
45 if(len==1)
46 domid = atoi(buf2[0]);
47 //sprintf( domid, "%ui", buf2[0] );
48
49 printf("Domid: %i\n", domid);
50

51     /* Get the local domain path */
52     path = xs_get_domain_path(xs, domid);
53     if ( path == NULL ) error();
54
55     printf("Msg3\n");
56
57     /* Make space for our node on the path */
58     path = realloc(path, strlen(path) + strlen("/memory/target") + 1);
59     if ( path == NULL ) error();
60     strcat(path, "/memory/target");
61
62     /* Create a watch on /local/domain/%d/mynode. */
63     er = xs_watch(xs, path, "mytoken");
64     if ( er == 0 ) error();

65
66 /* We are notified of read availability on the watch via the
67 * file descriptor.
68 */
69 fd = xs_fileno(xs);
70
71 while (1)
72 {
73 FD_ZERO(&set);
74 FD_SET(fd, &set);
75
76 /* Poll for data. */
77 if ( select(fd + 1, &set, NULL, NULL, &tv) > 0
78 && FD_ISSET(fd, &set))
79 {

80             /* I am not sure how num works -- please describe. */
81             vec = xs_read_watch(xs, &num);
82             if ( !vec ) error();
83             printf("vec contents: %s|%s\n", vec[XS_WATCH_PATH],

84 vec[XS_WATCH_TOKEN]);
85
86 /* Prepare a transaction and do a read. */
87 th = xs_transaction_start(xs);
88 buf = xs_read(xs, th, vec[XS_WATCH_PATH], &len);

89             xs_transaction_end(xs, th, true);
90             if ( buf )
91             {

92 printf("buflen: %d\nbuf: %s\n", len, buf);
93 }
94
95 /* Prepare a transaction and do a write. */
96 /*th = xs_transaction_start(xs);
97
98 er = xs_write(xs, th, path, "somestuff", strlen("somestuff"));
99 xs_transaction_end(xs, th, true);
100 if ( er == 0 ) error();*/
101 }
102 }
103

104    /* Cleanup */
105    close(fd);
106    xs_daemon_close(xs);
107    free(path);

108
109 }
----- Original Message ----- From: "Vincent Hanquez" <[email protected]>
To: "Umar Farooq Minhas" <[email protected]>
Cc: <[email protected]>; <[email protected]>
Sent: Wednesday, November 22, 2006 10:52 AM
Subject: Re: [Xen-devel] Regarding Xenstore/Xenbus

Quoted 22 lines · Umar Farooq Minhas
Quoted 10 lines

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.

you need to use "domain_open" instead of "daemon_open" in domU.

daemon_open is using a direct unix socket to communicate with xenstored. this socket is only accessible to dom0. domU need to use the other way to communicate with xenstored.

Cheers,

Signature · 1 line
Vincent Hanquez