From: Wei Liu <wei.liu2@citrix.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Jim Fehlig <jfehlig@suse.com>, Wei Liu <wei.liu2@citrix.com>,
Ian Campbell <Ian.Campbell@citrix.com>,
"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH RFC] libxl: set disk defaults in remove/destroy functions
Date: Mon, 2 Feb 2015 18:00:28 +0000 [thread overview]
Message-ID: <20150202180028.GA5530@zion.uk.xensource.com> (raw)
In-Reply-To: <21711.42984.152730.493299@mariner.uk.xensource.com>
On Mon, Feb 02, 2015 at 04:38:00PM +0000, Ian Jackson wrote:
> Wei Liu writes ("Re: [Xen-devel] [PATCH RFC] libxl: set disk defaults in remove/destroy functions"):
> > FWIW xl block-detach calls libxl_vdev_to_device_disk to convert a vdev
> > to disk. That function reads xenstore to get the actual backend of that
> > specific vdev. Don't know how useful it is to libvirt though.
> >
> > Maybe we should look up disk's backend in libxl_device_disk_remove? Not
> > sure what's the best approach.
>
> libxl_device_disk_remove should definitely not require the caller to
> do what xl currently does.
>
I come up with something like this (only compile tested).
---8<---
>From d2913eb11788db23a1e1541c86e9ffe1a2cb9a30 Mon Sep 17 00:00:00 2001
From: Wei Liu <wei.liu2@citrix.com>
Date: Mon, 2 Feb 2015 17:56:47 +0000
Subject: [PATCH] libxl: libxl__device_from_disk should retrieve backend from
xenstore
Also change the function to use goto idiom while I was there.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
---
tools/libxl/libxl.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 42 insertions(+), 3 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 82227e8..eff68f2 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2264,12 +2264,49 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
{
libxl_ctx *ctx = libxl__gc_owner(gc);
int devid;
+ int rc = 0;
devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
if (devid==-1) {
LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
" virtual disk identifier %s", disk->vdev);
- return ERROR_INVAL;
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ if (disk->backend == LIBXL_DISK_BACKEND_UNKNOWN) {
+ char *dompath, *be_path, *be_string;
+
+ dompath = libxl__xs_get_dompath(gc, domid);
+ if (!dompath) {
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ be_path = libxl__xs_read(gc, XBT_NULL,
+ GCSPRINTF("%s/device/vbd/%d/backend",
+ dompath, devid));
+ if (!be_path) {
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ rc = sscanf(be_path, "/local/domain/%d/", &disk->backend_domid);
+ if (rc != 1) {
+ LOG(ERROR, "Unable to fetch device backend domid from %s",
+ be_path);
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ be_string = libxl__xs_read(gc, XBT_NULL,
+ GCSPRINTF("%s/type", be_path));
+ if (!be_string) {
+ LOG(ERROR, "Missing xenstore node %s/type", be_path);
+ rc = ERROR_FAIL;
+ goto out;
+ }
+ libxl_string_to_backend(ctx, be_string, &disk->backend);
}
device->backend_domid = disk->backend_domid;
@@ -2288,14 +2325,16 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
default:
LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type: %d\n",
disk->backend);
- return ERROR_INVAL;
+ rc = ERROR_INVAL;
+ goto out;
}
device->domid = domid;
device->devid = devid;
device->kind = LIBXL__DEVICE_KIND_VBD;
- return 0;
+out:
+ return rc;
}
/* Specific function called directly only by local disk attach,
--
1.9.1
next prev parent reply other threads:[~2015-02-02 18:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-26 23:14 [PATCH RFC] libxl: set disk defaults in remove/destroy functions Jim Fehlig
2015-02-02 13:27 ` Ian Campbell
2015-02-02 13:36 ` Ian Campbell
2015-02-02 13:41 ` Ian Jackson
2015-02-02 16:32 ` Wei Liu
2015-02-02 16:38 ` Ian Jackson
2015-02-02 18:00 ` Wei Liu [this message]
2015-02-02 18:06 ` Ian Jackson
2015-02-02 18:13 ` Wei Liu
2015-02-03 11:27 ` Ian Jackson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150202180028.GA5530@zion.uk.xensource.com \
--to=wei.liu2@citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=jfehlig@suse.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.