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/
Home Products Support Community News


Re: [Xen-devel] how to read value from xenstore inside kernel

To: James Harper <james.harper@xxxxxxxxxxxxxxxx>
Subject: Re: [Xen-devel] how to read value from xenstore inside kernel
From: Kuriakose Mathew <kmathew123@xxxxxxxxx>
Date: Sat, 29 Aug 2009 21:08:56 +0530
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Sat, 29 Aug 2009 08:39:25 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=yeT01OiqG7uvFZHYk1AIGCOjYX8MgKvqYRt7WJL8xrk=; b=CRU8SbA7INtLMpde62OsjFYhWPQN5uvAeM2V4yx0RqI3BShxFKZOq2HULJkaPr0jd2 I7F/+4p0aBoJ0cfmNtNYoMLFJKINs6LNP7nG8+pbKOlvzrCzOQp8CE6eIEwxn/93fGeZ kJ/kKhX9fcDe1k0C1o0UhADkjRcUqID+/jq/M=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=RlLJ+ELfC2UxqvPnRXzJj5qhVpxhYuxxUrJ9gAz6KS0h0tnCjMHzji69bAGApdCDSr /5M+/KhbDOTCCh7DxKq48lyyEbFhODNtnJWPPmnshr8Pb5n/84O+ySVQbaBqIloshFmU 9oNy7rasChHrupruJ+5yUDqEmQ4+CcyIB8PDg=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <9e81bde0908290801k3c6f29e4w33c29793f1815f4c@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: <9e81bde0908162340h42011f5cn7606c962fda89da4@xxxxxxxxxxxxxx> <AEC6C66638C05B468B556EA548C1A77D0177CE13@trantor> <9e81bde0908280152r35c7b06ck866ab69487e0aa16@xxxxxxxxxxxxxx> <AEC6C66638C05B468B556EA548C1A77D0177CEF6@trantor> <9e81bde0908280441h2961f63bkf858c6812caeb81e@xxxxxxxxxxxxxx> <AEC6C66638C05B468B556EA548C1A77D0177CEF8@trantor> <9e81bde0908280451j5afd68bn2ad99db9866d4276@xxxxxxxxxxxxxx> <AEC6C66638C05B468B556EA548C1A77D0177CEF9@trantor> <9e81bde0908280739o79d119a9sa38e700bda96982a@xxxxxxxxxxxxxx> <9e81bde0908290801k3c6f29e4w33c29793f1815f4c@xxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
How to avoid the callback function  getting called again and again after registration of xenbus_watch?


On Sat, Aug 29, 2009 at 8:31 PM, Kuriakose Mathew <kmathew123@xxxxxxxxx> wrote:
Hi ,

Thanks. I think the registration is happening. I mistook the call trace to be a crash. But now when I write a new value to xenstore memory/target , it is showing some odd behavior like the shell is scrolling up .

I think the callback function is getting called again and again as though some kind of infinite loop.


On Fri, Aug 28, 2009 at 8:09 PM, Kuriakose Mathew <kmathew123@xxxxxxxxx> wrote:
I tried watch in xenbus.c ( connect function)

code is as shown below.

//////////ADDED CODE////////////////////

static struct xenbus_watch target_watch =
    .node = "memory/target"


/* React to a change in the target key */
static void mywatch_target(struct xenbus_watch *watch,
             const char **vec, unsigned int len)
    unsigned long long new_target;
    int err;
    printk(KERN_NOTICE "In netback.c::watch_target called \n");
    err = xenbus_scanf(XBT_NIL, "memory", "target", "%llu", &new_target);
    if (err != 1) {
        /* This is ok (for domain0 at least) - so just return */

    /* The given memory/target value is in KiB, so it needs converting to
     * pages. PAGE_SHIFT converts bytes to pages, hence PAGE_SHIFT - 10.
    //balloon_set_new_target(new_target >> (PAGE_SHIFT - 10));

////////////////////END OF ADD ////////////////////////////

static void connect(struct backend_info *be)
    int err;
    struct xenbus_device *dev = be->dev;

    err = connect_rings(be);
    if (err)

    err = xen_net_read_mac(dev, be->netif->fe_dev_addr);
    if (err) {
        xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename);

    xen_net_read_rate(dev, &be->netif->credit_bytes,
    be->netif->remaining_credit = be->netif->credit_bytes;

    xenbus_switch_state(dev, XenbusStateConnected);

   /////////////////ADDED CODE////////////
    target_watch.callback = mywatch_target;
    printk(KERN_NOTICE "In xenbus.c::connect b4 register \n");

    err = register_xenbus_watch(&target_watch);
    if(IS_ERR(err)) {
              printk(KERN_NOTICE "In xenbus.c::connect Failed to initialize  watcher\n");
        } else {
              printk(KERN_NOTICE " In xenbus.c::connect xenbus watcher initialized\n");
    //////////////END OF ADD//////////////

The crash message is

In xenbus.c::connect b4 register
------------[ cut here ]------------
kernel BUG at /home/saransh/xen-3.1.3/linux-!
invalid opcode: 0000 [#1]
Modules linked in: xt_tcpudp xt_physdev iptable_filter ip_tables x_tables ppdev ac video container button sbs i2c_ec i2c_core asus_acpi battery bridge lp serio_raw parport_pc parport serial_core rtc pcspkr shpchp pci_hotplug ipv6 tsdev evdev ext3 jbd sg sd_mod amd74xx usbhid ehci_hcd ohci_hcd usbcore sata_nv libata scsi_mod forcedeth thermal processor fan fuse
CPU:    1
EIP:    0061:[<c0249306>]    Not tainted VLI
EFLAGS: 00010286   ( #1)
EIP is at register_xenbus_watch+0xc6/0xe0
eax: c0364bd4   ebx: c0364bd4   ecx: c0f2da10   edx: c0364bd4
esi: fffffffe   edi: c1511f03   ebp: ed00cb40   esp: c1511ef4
ds: 007b   es: 007b   ss: 0069
Process xenwatch (pid: 13, ti=c1510000 task=c0446620 task.ti=c1510000)
Stack: c1511f03 c032d562 c0364bd4 43fe0400 34363330 00344442 c0fe0000 fffffffe
       c0fe0400 c02564db c03218b0 ed00c540 c032db45 c030ec5b c1511f5c c032db12
       c031610b c1511f68 c032dc1d c031ac96 c1511f64 00000000 c0fe0408 ed00c540
Call Trace:
 [<c02564db>] frontend_changed+0x4db/0x650
 [<c024a8d8>] otherend_changed+0xa8/0xb0
 [<c0249710>] xenwatch_thread+0x0/0x140
 [<c0248b5a>] xenwatch_handle_callback+0x1a/0x60
 [<c0249840>] xenwatch_thread+0x130/0x140
 [<c0248b40>] xenwatch_handle_callback+0x0/0x60

 [<c0138640>] autoremove_wake_function+0x0/0x40
 [<c0138486>] kthread+0xf6/0x100
 [<c0138390>] kthread+0x0/0x100
 [<c0103005>] kernel_thread_helper+0x5/0x10
Code: 10 00 c7 43 04 00 02 20 00 86 05 e0 3d 36 c0 b8 a8 3e 41 c0 e8 0c 2a ef ff 89 f8 8b 5c 24 18 8b 74 24 1c 8b 7c 24 20 83 c4 24 c3 <0f> 0b 5f 02 6c 03 32 c0 e9 75 ff ff ff 8d b6 00 00 00 00 8d bc
EIP: [<c0249306>] register_xenbus_watch+0xc6/0xe0 SS:ESP 0069:c1511ef4
 <6>Bluetooth: Core ver 2.10


On Fri, Aug 28, 2009 at 5:27 PM, James Harper <james.harper@xxxxxxxxxxxxxxxx> wrote:
> The .node  member I initialized while declaring  and .callback I
> in netbacl init function (just above where I use register_xenbus_watch
> shown below. (used balloon.c as guideline)

Try adding the watch (or just a read as a test) in netback/xenbus.c
inside the connect() function where a lot of other xenbus activity is


Xen-devel mailing list