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

To: "Vincent Hanquez" <vincent@xxxxxxxxxxxxx>
Subject: Re: [Xen-devel] Regarding Xenstore/Xenbus
From: "Umar Farooq Minhas" <umarfm13@xxxxxxxxxxx>
Date: Thu, 23 Nov 2006 15:22:24 -0500
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Fri, 24 Nov 2006 01:28:03 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
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/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Kindly, ignore my previous message. I figured out what was wrong with the code. I don't need to call "xs_directory" function because I learned that when you access Xenstore from inside domU it has an implicit root at "/local/domain/<domid>" so in-order to read "/local/domain/<domid>/memory/target" I just need to pass "memory/target" to "xs_read" as path.

The thing that I want to know now is that can a userspace tool register and be notified of watches on xenstore or is it allowed for kernel level drivers only? Apparently, the later seems to be the case because when I try to call "xs_watch" from domU it returns with an unknown error. Is there a workaround this? If not, I can always setup a loop that polls the path periodically to detect changes. I just want to be notified of changes to the path "memory/target".

Thanks for your help.

----- Original Message ----- From: "Umar Farooq Minhas" <umarfm13@xxxxxxxxxxx>
To: "Vincent Hanquez" <vincent@xxxxxxxxxxxxx>
Cc: <xen-devel@xxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, November 22, 2006 7:56 PM
Subject: Re: [Xen-devel] Regarding Xenstore/Xenbus


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" <vincent@xxxxxxxxxxxxx>
To: "Umar Farooq Minhas" <umarfm13@xxxxxxxxxxx>
Cc: <aball@xxxxxxxxxxxxxxxxxx>; <xen-devel@xxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, November 22, 2006 10:52 AM
Subject: Re: [Xen-devel] Regarding Xenstore/Xenbus


On Mon, Nov 20, 2006 at 08:21:20PM -0500, Umar Farooq Minhas wrote:
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,
--
Vincent Hanquez




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

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