From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xen.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH 05/13] libxl: move libxl_device_nic_add to libxl_device
Date: Wed, 16 May 2012 17:11:48 +0100 [thread overview]
Message-ID: <1337184716-49276-6-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1337184716-49276-1-git-send-email-roger.pau@citrix.com>
Move the code of this function to libxl_device.c so it can be made
asyncronious later on the series. The static function
libxl__device_from_nic also has to be moved to libxl_device and it is
no longer static.
The code will be fixed in a latter patch, replacing libxl__sprintf,
LIBXL_LOG* and lines > 80.
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
---
tools/libxl/libxl.c | 108 +---------------------------------------
tools/libxl/libxl_device.c | 113 ++++++++++++++++++++++++++++++++++++++++++
tools/libxl/libxl_internal.h | 6 ++
3 files changed, 121 insertions(+), 106 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 2d8abd0..d3b6a53 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -1655,117 +1655,13 @@ int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic)
return 0;
}
-static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
- libxl_device_nic *nic,
- libxl__device *device)
-{
- device->backend_devid = nic->devid;
- device->backend_domid = nic->backend_domid;
- device->backend_kind = LIBXL__DEVICE_KIND_VIF;
- device->devid = nic->devid;
- device->domid = domid;
- device->kind = LIBXL__DEVICE_KIND_VIF;
-
- return 0;
-}
-
int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic)
{
GC_INIT(ctx);
- flexarray_t *front;
- flexarray_t *back;
- libxl__device device;
- char *dompath, **l;
- unsigned int nb, rc;
-
- rc = libxl__device_nic_setdefault(gc, nic);
- if (rc) goto out;
-
- front = flexarray_make(16, 1);
- if (!front) {
- rc = ERROR_NOMEM;
- goto out;
- }
- back = flexarray_make(16, 1);
- if (!back) {
- rc = ERROR_NOMEM;
- goto out_free;
- }
-
- if (nic->devid == -1) {
- if (!(dompath = libxl__xs_get_dompath(gc, domid))) {
- rc = ERROR_FAIL;
- goto out_free;
- }
- if (!(l = libxl__xs_directory(gc, XBT_NULL,
- libxl__sprintf(gc, "%s/device/vif", dompath), &nb))) {
- nic->devid = 0;
- } else {
- nic->devid = strtoul(l[nb - 1], NULL, 10) + 1;
- }
- }
-
- rc = libxl__device_from_nic(gc, domid, nic, &device);
- if ( rc != 0 ) goto out_free;
-
- flexarray_append(back, "frontend-id");
- flexarray_append(back, libxl__sprintf(gc, "%d", domid));
- flexarray_append(back, "online");
- flexarray_append(back, "1");
- flexarray_append(back, "state");
- flexarray_append(back, libxl__sprintf(gc, "%d", 1));
- if (nic->script) {
- flexarray_append(back, "script");
- flexarray_append(back, nic->script[0]=='/' ? nic->script
- : libxl__sprintf(gc, "%s/%s",
- libxl__xen_script_dir_path(),
- nic->script));
- }
-
- if (nic->ifname) {
- flexarray_append(back, "vifname");
- flexarray_append(back, nic->ifname);
- }
-
- flexarray_append(back, "mac");
- flexarray_append(back,libxl__sprintf(gc,
- LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
- if (nic->ip) {
- flexarray_append(back, "ip");
- flexarray_append(back, libxl__strdup(gc, nic->ip));
- }
-
- if (nic->rate_interval_usecs > 0) {
- flexarray_append(back, "rate");
- flexarray_append(back, libxl__sprintf(gc, "%"PRIu64",%"PRIu32"",
- nic->rate_bytes_per_interval,
- nic->rate_interval_usecs));
- }
-
- flexarray_append(back, "bridge");
- flexarray_append(back, libxl__strdup(gc, nic->bridge));
- flexarray_append(back, "handle");
- flexarray_append(back, libxl__sprintf(gc, "%d", nic->devid));
+ int rc;
- flexarray_append(front, "backend-id");
- flexarray_append(front, libxl__sprintf(gc, "%d", nic->backend_domid));
- flexarray_append(front, "state");
- flexarray_append(front, libxl__sprintf(gc, "%d", 1));
- flexarray_append(front, "handle");
- flexarray_append(front, libxl__sprintf(gc, "%d", nic->devid));
- flexarray_append(front, "mac");
- flexarray_append(front, libxl__sprintf(gc,
- LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
- libxl__device_generic_add(gc, &device,
- libxl__xs_kvs_of_flexarray(gc, back, back->count),
- libxl__xs_kvs_of_flexarray(gc, front, front->count));
+ rc = libxl__device_nic_add(gc, domid, nic);
- /* FIXME: wait for plug */
- rc = 0;
-out_free:
- flexarray_free(back);
- flexarray_free(front);
-out:
GC_FREE;
return rc;
}
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 304929a..edc4ad1 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -408,6 +408,119 @@ out:
return rc;
}
+int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
+ libxl_device_nic *nic,
+ libxl__device *device)
+{
+ device->backend_devid = nic->devid;
+ device->backend_domid = nic->backend_domid;
+ device->backend_kind = LIBXL__DEVICE_KIND_VIF;
+ device->devid = nic->devid;
+ device->domid = domid;
+ device->kind = LIBXL__DEVICE_KIND_VIF;
+
+ return 0;
+}
+
+int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic)
+{
+ flexarray_t *front;
+ flexarray_t *back;
+ libxl__device device;
+ char *dompath, **l;
+ unsigned int nb, rc;
+
+ rc = libxl__device_nic_setdefault(gc, nic);
+ if (rc) goto out;
+
+ front = flexarray_make(16, 1);
+ if (!front) {
+ rc = ERROR_NOMEM;
+ goto out;
+ }
+ back = flexarray_make(16, 1);
+ if (!back) {
+ rc = ERROR_NOMEM;
+ goto out_free;
+ }
+
+ if (nic->devid == -1) {
+ if (!(dompath = libxl__xs_get_dompath(gc, domid))) {
+ rc = ERROR_FAIL;
+ goto out_free;
+ }
+ if (!(l = libxl__xs_directory(gc, XBT_NULL,
+ libxl__sprintf(gc, "%s/device/vif", dompath), &nb))) {
+ nic->devid = 0;
+ } else {
+ nic->devid = strtoul(l[nb - 1], NULL, 10) + 1;
+ }
+ }
+
+ rc = libxl__device_from_nic(gc, domid, nic, &device);
+ if ( rc != 0 ) goto out_free;
+
+ flexarray_append(back, "frontend-id");
+ flexarray_append(back, libxl__sprintf(gc, "%d", domid));
+ flexarray_append(back, "online");
+ flexarray_append(back, "1");
+ flexarray_append(back, "state");
+ flexarray_append(back, libxl__sprintf(gc, "%d", 1));
+ if (nic->script) {
+ flexarray_append(back, "script");
+ flexarray_append(back, nic->script[0]=='/' ? nic->script
+ : libxl__sprintf(gc, "%s/%s",
+ libxl__xen_script_dir_path(),
+ nic->script));
+ }
+
+ if (nic->ifname) {
+ flexarray_append(back, "vifname");
+ flexarray_append(back, nic->ifname);
+ }
+
+ flexarray_append(back, "mac");
+ flexarray_append(back,libxl__sprintf(gc,
+ LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
+ if (nic->ip) {
+ flexarray_append(back, "ip");
+ flexarray_append(back, libxl__strdup(gc, nic->ip));
+ }
+
+ if (nic->rate_interval_usecs > 0) {
+ flexarray_append(back, "rate");
+ flexarray_append(back, libxl__sprintf(gc, "%"PRIu64",%"PRIu32"",
+ nic->rate_bytes_per_interval,
+ nic->rate_interval_usecs));
+ }
+
+ flexarray_append(back, "bridge");
+ flexarray_append(back, libxl__strdup(gc, nic->bridge));
+ flexarray_append(back, "handle");
+ flexarray_append(back, libxl__sprintf(gc, "%d", nic->devid));
+
+ flexarray_append(front, "backend-id");
+ flexarray_append(front, libxl__sprintf(gc, "%d", nic->backend_domid));
+ flexarray_append(front, "state");
+ flexarray_append(front, libxl__sprintf(gc, "%d", 1));
+ flexarray_append(front, "handle");
+ flexarray_append(front, libxl__sprintf(gc, "%d", nic->devid));
+ flexarray_append(front, "mac");
+ flexarray_append(front, libxl__sprintf(gc,
+ LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
+ libxl__device_generic_add(gc, &device,
+ libxl__xs_kvs_of_flexarray(gc, back, back->count),
+ libxl__xs_kvs_of_flexarray(gc, front, front->count));
+
+ /* FIXME: wait for plug */
+ rc = 0;
+out_free:
+ flexarray_free(back);
+ flexarray_free(front);
+out:
+ return rc;
+}
+
int libxl__device_physdisk_major_minor(const char *physpath, int *major, int *minor)
{
struct stat buf;
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 87c9366..0ddfe72 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -786,6 +786,12 @@ _hidden int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
_hidden int libxl__device_disk_add(libxl__gc *gc, uint32_t domid,
libxl_device_disk *disk);
+_hidden int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
+ libxl_device_nic *nic,
+ libxl__device *device);
+_hidden int libxl__device_nic_add(libxl__gc *gc, uint32_t domid,
+ libxl_device_nic *nic);
+
_hidden int libxl__device_physdisk_major_minor(const char *physpath, int *major, int *minor);
_hidden int libxl__device_disk_dev_number(const char *virtpath,
int *pdisk, int *ppartition);
--
1.7.7.5 (Apple Git-26)
next prev parent reply other threads:[~2012-05-16 16:11 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-16 16:11 [PATCH 0/13] execute hotplug scripts from libxl Roger Pau Monne
2012-05-16 16:11 ` [PATCH 01/13] libxl: pass env vars to libxl__exec Roger Pau Monne
2012-05-18 16:02 ` Ian Jackson
2012-05-16 16:11 ` [PATCH 02/13] libxl: fix libxl__xs_directory usage of transaction Roger Pau Monne
2012-05-18 16:03 ` Ian Jackson
2012-05-16 16:11 ` [PATCH 03/13] libxl: add libxl__xs_path_cleanup Roger Pau Monne
2012-05-18 16:06 ` Ian Jackson
2012-05-16 16:11 ` [PATCH 04/13] libxl: move libxl_device_disk_add to libxl_device Roger Pau Monne
2012-05-16 16:11 ` Roger Pau Monne [this message]
2012-05-16 16:11 ` [PATCH 06/13] libxl: cleanup libxl__device_{disk, nic}_add Roger Pau Monne
2012-05-18 16:07 ` Ian Jackson
2012-05-16 16:11 ` [PATCH 07/13] libxl: convert libxl_domain_destroy to an AO op Roger Pau Monne
2012-05-18 16:19 ` Ian Jackson
2012-05-18 16:24 ` Ian Jackson
2012-05-16 16:11 ` [PATCH 08/13] libxl: convert libxl_device_disk_add to an async operation Roger Pau Monne
2012-05-18 16:33 ` Ian Jackson
2012-05-16 16:11 ` [PATCH 09/13] libxl: convert libxl_device_nic_add " Roger Pau Monne
2012-05-18 16:38 ` Ian Jackson
2012-05-22 13:49 ` Roger Pau Monne
2012-05-22 14:04 ` Ian Jackson
2012-05-16 16:11 ` [PATCH 10/13] libxl: add option to choose who executes hotplug scripts Roger Pau Monne
2012-05-18 16:40 ` Ian Jackson
2012-05-16 16:11 ` [PATCH 11/13] libxl: set nic type to VIF by default Roger Pau Monne
2012-05-18 16:41 ` Ian Jackson
2012-05-21 16:29 ` Roger Pau Monne
2012-05-29 14:40 ` Ian Jackson
2012-05-29 14:46 ` Ian Campbell
2012-05-29 15:02 ` Ian Jackson
2012-05-29 15:06 ` Ian Campbell
2012-05-30 12:03 ` Roger Pau Monne
2012-06-07 14:30 ` Ian Jackson
2012-06-11 14:05 ` Roger Pau Monne
2012-05-16 16:11 ` [PATCH 12/13] libxl: call hotplug scripts for disk devices from libxl Roger Pau Monne
2012-05-18 16:51 ` Ian Jackson
2012-05-16 16:11 ` [PATCH 13/13] libxl: call hotplug scripts for nic " Roger Pau Monne
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=1337184716-49276-6-git-send-email-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=ian.jackson@eu.citrix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).