Skip to contentSkip to conversation

libxl: fix xenstore connection when run in domU

PATCH Jun Zhu (Intern) 6 participants 12 messages Aug 31, 2010 – Sep 1, 2010

lore
Share & tools
lore
#0 lore raw

Hi

There are other places that use the xs_daemon_open in libxl. Is it necessory to change them as follows?

     ctx->xsh = xs_daemon_open();
+    if (!ctx->xsh)
+        ctx->xsh = xs_domain_open();
     if (!ctx->xsh) {
         XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, errno, 
                         "cannot connect to xenstore");

Jun Zhu
Citrix Systems UK

#1 lore raw

Review

Quoted 9 lines · Jun Zhu (Intern)

Hi

There are other places that use the xs_daemon_open in libxl. Is it necessory to change them as follows?

     ctx->xsh = xs_daemon_open();
(quoted diff) +2 -0
+    if (!ctx->xsh)
+        ctx->xsh = xs_domain_open();
     if (!ctx->xsh) {
         XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, errno, 
                         "cannot connect to xenstore");

I think we'd be better off introducing "libxl__xs_open" which does the right thing and make the users to all use it.

Is there any harm in always preferring xs_domain_open, even if the xenstore daemon happens to be co-located in the same domain?

Ian.

#2 lore raw

Hi,

I don't think it is a good idea to let users decide which "open". If we check if it is in Dom0, it uses xs_daemon_open; if in DomU, it uses xs_domain_open. Is it better?

If it is always preferring xs_domain_open, the performance is not better than that of xs_daemon_open when running in Dom0.

Jun Zhu
Citrix Systems UK
________________________________________
From: Ian Campbell
Sent: Tuesday, August 31, 2010 5:15 AM
To: Jun Zhu (Intern)
Cc: [email protected]; [email protected]
Subject: Re: [Xen-devel] Re: [PATCH] libxl: fix xenstore connection when run in domU

Review

Quoted 9 lines · Jun Zhu (Intern)

Hi

There are other places that use the xs_daemon_open in libxl. Is it necessory to change them as follows?

     ctx->xsh = xs_daemon_open();
(quoted diff) +2 -0
+    if (!ctx->xsh)
+        ctx->xsh = xs_domain_open();
     if (!ctx->xsh) {
         XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, errno,
                         "cannot connect to xenstore");

I think we'd be better off introducing "libxl__xs_open" which does the right thing and make the users to all use it.

Is there any harm in always preferring xs_domain_open, even if the xenstore daemon happens to be co-located in the same domain?

Ian.

#3 lore raw
Quoted 3 lines · Jun Zhu (Intern)

I don't think it is a good idea to let users decide which "open". If we check if it is in Dom0, it uses xs_daemon_open; if in DomU, it uses xs_domain_open. Is it better?

I meant all the users internal to libxl, not the users of the library, (note that the libxl__ namespace is internal to the library). This choice should indeed be completely hidden from libxl's users.

Ian.

#4 lore raw
In reply to Ian Campbell
Quoted 11 lines · Ian Campbell

Review

Quoted 9 lines · Jun Zhu (Intern)

Hi

There are other places that use the xs_daemon_open in libxl. Is it necessory to change them as follows?

     ctx->xsh = xs_daemon_open();
(quoted diff) +2 -0
+    if (!ctx->xsh)
+        ctx->xsh = xs_domain_open();
     if (!ctx->xsh) {
         XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, errno, 
                         "cannot connect to xenstore");
Quoted 5 lines

I think we'd be better off introducing "libxl__xs_open" which does the right thing and make the users to all use it.

Is there any harm in always preferring xs_domain_open, even if the xenstore daemon happens to be co-located in the same domain?

I don't think so; even the performance probably won't be that much different. It certainly used to work when we first put Xenstore in its own domain and anything that's broken since then is a regression worth fixing.

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, XenServer Engineering
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#5 lore raw

Yes.
If xenstore runs in a seperate domain, it must use xenbus dev to communicate. If so, the xenstore commands in Xenbus driver are not complete. For example, it does not contain XS_INTRODUCE now.

Jun Zhu
Citrix Systems UK
________________________________________
From: Tim Deegan
Sent: Tuesday, August 31, 2010 6:28 AM
To: Ian Campbell
Cc: Jun Zhu (Intern); [email protected]; [email protected]
Subject: Re: [Xen-devel] Re: [PATCH] libxl: fix xenstore connection when run in domU

Quoted 11 lines · Ian Campbell

Review

Quoted 9 lines · Jun Zhu (Intern)

Hi

There are other places that use the xs_daemon_open in libxl. Is it necessory to change them as follows?

     ctx->xsh = xs_daemon_open();
(quoted diff) +2 -0
+    if (!ctx->xsh)
+        ctx->xsh = xs_domain_open();
     if (!ctx->xsh) {
         XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, errno,
                         "cannot connect to xenstore");
Quoted 5 lines

I think we'd be better off introducing "libxl__xs_open" which does the right thing and make the users to all use it.

Is there any harm in always preferring xs_domain_open, even if the xenstore daemon happens to be co-located in the same domain?

I don't think so; even the performance probably won't be that much different. It certainly used to work when we first put Xenstore in its own domain and anything that's broken since then is a regression worth fixing.

Tim.

--
Tim Deegan <[email protected]>
Principal Software Engineer, XenServer Engineering Citrix Systems UK Ltd. (Company #02937203, SL9 0BG)

#6 lore raw
Quoted 4 lines · Jun Zhu (Intern)

If xenstore runs in a seperate domain, it must use xenbus dev to communicate. If so, the xenstore commands in Xenbus driver are not complete. For example, it does not contain XS_INTRODUCE now.

IIRC Diego's original xenstore-stubdom patch series from way back when (posted to the list by Diego and again later by Alex Zeffertt) included patches to the kernel side xenbus driver to resolve issues like this.

Ian.

#7 lore raw

Which XenBus driver is this? In Linux? I've certainly had no issues running a Mini-OS XenStore stubdom (at least not in regards to missing things like XS_INTRODUCE).

Patrick

Quoted 14 lines · Ian Campbell
Quoted 4 lines · Jun Zhu (Intern)

If xenstore runs in a seperate domain, it must use xenbus dev to communicate. If so, the xenstore commands in Xenbus driver are not complete. For example, it does not contain XS_INTRODUCE now.

IIRC Diego's original xenstore-stubdom patch series from way back when (posted to the list by Diego and again later by Alex Zeffertt) included patches to the kernel side xenbus driver to resolve issues like this.

Ian.

#8 lore raw
Quoted 1 line · Patrick Colp

Which XenBus driver is this? In Linux?

Yes. Specifically pvops Linux domain 0.

Quoted 2 lines

I've certainly had no issues running a Mini-OS XenStore stubdom (at least not in regards to missing things like XS_INTRODUCE).

xenbus_file_write has an explicit whitelist of XS_FOO which are allowed, which doesn't include XS_INTRODUCE.

This seems to be different in linux-2.6.18-xen due to 874:68d582b0ad05 and 876:bd7e30b58d12 which I had forgotten were already applied. I guess those just need porting up to pvops.

Ian.

Quoted 20 lines

Patrick

Quoted 14 lines · Ian Campbell
Quoted 4 lines · Jun Zhu (Intern)

If xenstore runs in a seperate domain, it must use xenbus dev to communicate. If so, the xenstore commands in Xenbus driver are not complete. For example, it does not contain XS_INTRODUCE now.

IIRC Diego's original xenstore-stubdom patch series from way back when (posted to the list by Diego and again later by Alex Zeffertt) included patches to the kernel side xenbus driver to resolve issues like this.

Ian.

#9 lore raw
In reply to Patrick Colp

In pvops, in the function xenbus_file_write of file drivers/xen/xenfs/xenbus.c. In the switch, there is no XS_INTRODUCE which is used to create a new domain. These commands are eliminated here, since in default, a Domu cannot use these commands.

static ssize_t xenbus_file_write(struct file *filp,
const char __user *ubuf, size_t len, loff_t *ppos)

{
	struct xenbus_file_priv *u = filp->private_data;
	uint32_t msg_type;
	int rc = len;
	int ret;
	LIST_HEAD(staging_q);

	/*
	 * We're expecting usermode to be writing properly formed
	 * xenbus messages.  If they write an incomplete message we
	 * buffer it up.  Once it is complete, we act on it.
	 */

	/*
	 * Make sure concurrent writers can't stomp all over each
	 * other's messages and make a mess of our partial message
	 * buffer.  We don't make any attemppt to stop multiple
	 * writers from making a mess of each other's incomplete
	 * messages; we're just trying to guarantee our own internal
	 * consistency and make sure that single writes are handled
	 * atomically.
	 */
	mutex_lock(&u->msgbuffer_mutex);

	/* Get this out of the way early to avoid confusion */
	if (len == 0)
		goto out;

	/* Can't write a xenbus message larger we can buffer */
	if ((len + u->len) > sizeof(u->u.buffer)) {
		/* On error, dump existing buffer */
		u->len = 0;
		rc = -EINVAL;
		goto out;
	}

	ret = copy_from_user(u->u.buffer + u->len, ubuf, len);

	if (ret == len) {
		rc = -EFAULT;
		goto out;
	}

	/* Deal with a partial copy. */
	len -= ret;
	rc = len;

	u->len += len;

	/* Return if we haven't got a full message yet */
	if (u->len < sizeof(u->u.msg))
		goto out;	/* not even the header yet */

	/* If we're expecting a message that's larger than we can
	   possibly send, dump what we have and return an error. */
	if ((sizeof(u->u.msg) + u->u.msg.len) > sizeof(u->u.buffer)) {
		rc = -E2BIG;
		u->len = 0;
		goto out;
	}

	if (u->len < (sizeof(u->u.msg) + u->u.msg.len))
		goto out;	/* incomplete data portion */

	/*
	 * OK, now we have a complete message.  Do something with it.
	 */

	msg_type = u->u.msg.type;

	switch (msg_type) {
	case XS_TRANSACTION_START:
	case XS_TRANSACTION_END:
	case XS_DIRECTORY:
	case XS_READ:
	case XS_GET_PERMS:
	case XS_RELEASE:
	case XS_GET_DOMAIN_PATH:
	case XS_WRITE:
	case XS_MKDIR:
	case XS_RM:
	case XS_SET_PERMS:
		/* Send out a transaction */
		ret = xenbus_write_transaction(msg_type, u);
		break;

	case XS_WATCH:
	case XS_UNWATCH:
		/* (Un)Ask for some path to be watched for changes */
		ret = xenbus_write_watch(msg_type, u);
		break;

	default:
		ret = -EINVAL;
		break;
	}
	if (ret != 0)
		rc = ret;

	/* Buffered message consumed */
	u->len = 0;

out:

	mutex_unlock(&u->msgbuffer_mutex);
	return rc;
}

Jun Zhu
Citrix Systems UK
________________________________________
发件人: Patrick Colp [[email protected]]
发送时间: 2010年8月31日 下午 1:51
收件人: Ian Campbell
抄送: Jun Zhu (Intern); Tim Deegan; [email protected]; [email protected] 主题: Re: [Xen-devel] Re: [PATCH] libxl: fix xenstore connection when run in domU

Which XenBus driver is this? In Linux? I've certainly had no issues running a Mini-OS XenStore stubdom (at least not in regards to missing things like XS_INTRODUCE).

Patrick

Quoted 6 lines · Ian Campbell
Quoted 4 lines · Jun Zhu (Intern)

If xenstore runs in a seperate domain, it must use xenbus dev to communicate. If so, the xenstore commands in Xenbus driver are not complete. For example, it does not contain XS_INTRODUCE now.

Quoted 8 lines

IIRC Diego's original xenstore-stubdom patch series from way back when (posted to the list by Diego and again later by Alex Zeffertt) included patches to the kernel side xenbus driver to resolve issues like this.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#10 lore raw

Re: ????: Re: [PATCH] libxl: fix xenstore connection when run in domU

Quoted 3 lines · Jun Zhu (Intern)

In pvops, in the function xenbus_file_write of file drivers/xen/xenfs/xenbus.c. In the switch, there is no XS_INTRODUCE which is used to create a new domain. These commands are eliminated here, since in default, a Domu cannot use these commands.

As Ian Campbell just said, you need to port changesets 874 and 876 of the linux-2.6.18-xen tree to your pvops kernel:

http://xenbits.xensource.com/linux-2.6.18-xen.hg?rev=876

Cheers,

Tim.

Quoted 29 lines

??????: Patrick Colp [[email protected]]
????????: 2010??8??31?? ???? 1:51
??????: Ian Campbell
????: Jun Zhu (Intern); Tim Deegan; [email protected]; [email protected] ????: Re: [Xen-devel] Re: [PATCH] libxl: fix xenstore connection when run in domU

Which XenBus driver is this? In Linux? I've certainly had no issues running a Mini-OS XenStore stubdom (at least not in regards to missing things like XS_INTRODUCE).

Patrick

Quoted 14 lines · Ian Campbell
Quoted 4 lines · Jun Zhu (Intern)

If xenstore runs in a seperate domain, it must use xenbus dev to communicate. If so, the xenstore commands in Xenbus driver are not complete. For example, it does not contain XS_INTRODUCE now.

IIRC Diego's original xenstore-stubdom patch series from way back when (posted to the list by Diego and again later by Alex Zeffertt) included patches to the kernel side xenbus driver to resolve issues like this.

Ian.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, XenServer Engineering
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#11 lore raw

Re: ????: Re: [PATCH] libxl: fix xenstore connection when run in domU

Quoted 8 lines · Tim Deegan
Quoted 3 lines · Jun Zhu (Intern)

In pvops, in the function xenbus_file_write of file drivers/xen/xenfs/xenbus.c. In the switch, there is no XS_INTRODUCE which is used to create a new domain. These commands are eliminated here, since in default, a Domu cannot use these commands.

As Ian Campbell just said, you need to port changesets 874 and 876 of the linux-2.6.18-xen tree to your pvops kernel:

http://xenbits.xensource.com/linux-2.6.18-xen.hg?rev=876

876 looks pretty hairy, but I just did 874.

J