From: Kuriakose Mathew Subject: Re: how to read value from xenstore inside kernel Date: Sat, 29 Aug 2009 21:08:56 +0530 Message-ID: <9e81bde0908290838g7c02c137oe76b06bf9e665e56@mail.gmail.com> References: <9e81bde0908162340h42011f5cn7606c962fda89da4@mail.gmail.com> <9e81bde0908280152r35c7b06ck866ab69487e0aa16@mail.gmail.com> <9e81bde0908280441h2961f63bkf858c6812caeb81e@mail.gmail.com> <9e81bde0908280451j5afd68bn2ad99db9866d4276@mail.gmail.com> <9e81bde0908280739o79d119a9sa38e700bda96982a@mail.gmail.com> <9e81bde0908290801k3c6f29e4w33c29793f1815f4c@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1367675614==" Return-path: In-Reply-To: <9e81bde0908290801k3c6f29e4w33c29793f1815f4c@mail.gmail.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: James Harper Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============1367675614== Content-Type: multipart/alternative; boundary=0050450175fa4cbd620472499917 --0050450175fa4cbd620472499917 Content-Type: text/plain; charset=ISO-8859-1 How to avoid the callback function getting called again and again after registration of xenbus_watch? -Mathew On Sat, Aug 29, 2009 at 8:31 PM, Kuriakose Mathew 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. > > -Mathew > > > On Fri, Aug 28, 2009 at 8:09 PM, Kuriakose Mathew 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 */ >> 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) >> return; >> >> err = xen_net_read_mac(dev, be->netif->fe_dev_addr); >> if (err) { >> xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename); >> return; >> } >> >> xen_net_read_rate(dev, &be->netif->credit_bytes, >> &be->netif->credit_usec); >> be->netif->remaining_credit = be->netif->credit_bytes; >> >> xenbus_switch_state(dev, XenbusStateConnected); >> >> netif_wake_queue(be->netif->dev); >> >> /////////////////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-2.6.18.8-xen/drivers/xen/xenbus/xenbus_xs.c:607! >> invalid opcode: 0000 [#1] >> SMP >> 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:[] Not tainted VLI >> EFLAGS: 00010286 (2.6.18.8-xen #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: >> [] frontend_changed+0x4db/0x650 >> [] otherend_changed+0xa8/0xb0 >> [] xenwatch_thread+0x0/0x140 >> [] xenwatch_handle_callback+0x1a/0x60 >> [] xenwatch_thread+0x130/0x140 >> [] xenwatch_handle_callback+0x0/0x60 >> [] autoremove_wake_function+0x0/0x40 >> [] kthread+0xf6/0x100 >> [] kthread+0x0/0x100 >> [] 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: [] register_xenbus_watch+0xc6/0xe0 SS:ESP 0069:c1511ef4 >> <6>Bluetooth: Core ver 2.10 >> >> >> Thanks >> Mathew >> >> >> >> On Fri, Aug 28, 2009 at 5:27 PM, James Harper < >> james.harper@bendigoit.com.au> wrote: >> >>> > >>> > The .node member I initialized while declaring and .callback I >>> initialized >>> > in netbacl init function (just above where I use register_xenbus_watch >>> )as >>> > 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 >>> happening >>> >>> James >>> >> >> > --0050450175fa4cbd620472499917 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable How to avoid the callback function=A0 getting called again and again after = registration of xenbus_watch?

-Mathew


On Sat, Aug 29, 2009 at 8:31 PM,= Kuriakose Mathew <kmathew123@gmail.com> wrote:
Hi ,

Thank= s. 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 s= howing some odd behavior like the shell is scrolling up .

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

-Mathew


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

code is as shown below.

////////= //ADDED CODE////////////////////



static struct xenbus_watch target_watch =3D
{
=A0=A0=A0 .= node =3D "memory/target"
=A0=A0=A0
};

/////////////////////////////////////////////= ///

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

=A0=A0=A0 /* The given memory/target value is in KiB, so it ne= eds converting to
=A0=A0=A0 =A0* pages. PAGE_SHIFT converts bytes to pag= es, hence PAGE_SHIFT - 10.
=A0=A0=A0 =A0*/
=A0=A0=A0 //balloon_set_new_target(new_target >> (= PAGE_SHIFT - 10));
}


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


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

=A0=A0=A0 err = =3D connect_rings(be);
=A0=A0=A0 if (err)
=A0=A0=A0 =A0=A0=A0 return;=

=A0=A0=A0 err =3D xen_net_read_mac(dev, be->netif->fe_dev_add= r);
=A0=A0=A0 if (err) {
=A0=A0=A0 =A0=A0=A0 xenbus_dev_fatal(dev, er= r, "parsing %s/mac", dev->nodename);
=A0=A0=A0 =A0=A0=A0 return;
=A0=A0=A0 }

=A0=A0=A0 xen_net_read_ra= te(dev, &be->netif->credit_bytes,
=A0=A0=A0 =A0=A0=A0 =A0=A0= =A0 =A0 &be->netif->credit_usec);
=A0=A0=A0 be->netif->r= emaining_credit =3D be->netif->credit_bytes;

=A0=A0=A0 xenbus_switch_state(dev, XenbusStateConnected);

=A0=A0= =A0 netif_wake_queue(be->netif->dev);
=A0=A0=A0
=A0=A0 ///////= //////////ADDED CODE////////////
=A0=A0=A0 target_watch.callback =3D myw= atch_target;
=A0=A0=A0
=A0=A0=A0 printk(KERN_NOTICE "In xenbus.= c::connect b4 register \n");

=A0=A0=A0 err =3D register_xenbus_watch(&target_watch);
=A0=A0=A0 if= (IS_ERR(err)) {
=A0=A0=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 printk(KERN_NO= TICE "In xenbus.c::connect Failed to initialize=A0 watcher\n");=A0=A0=A0 =A0=A0=A0 } else {
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 printk(= KERN_NOTICE " In xenbus.c::connect xenbus watcher initialized\n")= ;
=A0 =A0=A0=A0 }
=A0=A0=A0 //////////////END OF ADD//////////////
}
The crash message is

In xenbus.c::connect b4 register
-----= -------[ cut here ]------------
kernel BUG at /home/saransh/xen-3.1.3/li= nux-2.6.18.8-xen/drivers/xen/xenbus/xenbus_xs.c:607!
invalid opcode: 0000 [#1]
SMP
Modules linked in: xt_tcpudp xt_physde= v 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 seria= l_core rtc pcspkr shpchp pci_hotplug ipv6 tsdev evdev ext3 jbd sg sd_mod am= d74xx usbhid ehci_hcd ohci_hcd usbcore sata_nv libata scsi_mod forcedeth th= ermal processor fan fuse
CPU:=A0=A0=A0 1
EIP:=A0=A0=A0 0061:[<c0249306>]=A0=A0=A0 Not taint= ed VLI
EFLAGS: 00010286=A0=A0 (2.6.18.8-xen #1)
EIP is at register_x= enbus_watch+0xc6/0xe0
eax: c0364bd4=A0=A0 ebx: c0364bd4=A0=A0 ecx: c0f2d= a10=A0=A0 edx: c0364bd4
esi: fffffffe=A0=A0 edi: c1511f03=A0=A0 ebp: ed0= 0cb40=A0=A0 esp: c1511ef4
ds: 007b=A0=A0 es: 007b=A0=A0 ss: 0069
Process xenwatch (pid: 13, ti=3Dc= 1510000 task=3Dc0446620 task.ti=3Dc1510000)
Stack: c1511f03 c032d562 c03= 64bd4 43fe0400 34363330 00344442 c0fe0000 fffffffe
=A0=A0=A0=A0=A0=A0 c= 0fe0400 c02564db c03218b0 ed00c540 c032db45 c030ec5b c1511f5c c032db12
=A0=A0=A0=A0=A0=A0 c031610b c1511f68 c032dc1d c031ac96 c1511f64 00000000 c0= fe0408 ed00c540
Call Trace:
=A0[<c02564db>] frontend_changed+0= x4db/0x650
=A0[<c024a8d8>] otherend_changed+0xa8/0xb0
=A0[<c= 0249710>] xenwatch_thread+0x0/0x140
=A0[<c0248b5a>] xenwatch_handle_callback+0x1a/0x60
=A0[<c024984= 0>] xenwatch_thread+0x130/0x140
=A0[<c0248b40>] xenwatch_handle= _callback+0x0/0x60

=A0[<c0138640>] autoremove_wake_function+0= x0/0x40
=A0[<c0138486>] kthread+0xf6/0x100
=A0[<c0138390>] kthread+0= x0/0x100
=A0[<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:c1511ef= 4
=A0<6>Bluetooth: Core ver 2.10


Thanks
Mathew



On Fri, Aug 28, 2009 at 5:27 PM, James Harper <james.harper@be= ndigoit.com.au> wrote:
>
> The .node =A0member I initialized while declaring =A0and .callback I initialized
> in netbacl init function (just above where I use register_xenbus_watch=
)as
> 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
happening

James



--0050450175fa4cbd620472499917-- --===============1367675614== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============1367675614==--