From: Wei Liu <wei.liu2@citrix.com>
To: xen-devel@lists.xen.org
Cc: Wei Liu <wei.liu2@citrix.com>,
ian.jackson@eu.citrix.com, ian.campbell@citrix.com
Subject: [PATCH V4 22/24] xl: update domain configuration when we hotplug a device
Date: Thu, 1 May 2014 13:58:19 +0100 [thread overview]
Message-ID: <1398949101-23320-23-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1398949101-23320-1-git-send-email-wei.liu2@citrix.com>
A convenient macro is written to accomplish following tasks:
1. load domain configuration
2. allocate a new device structure NEW
3. copy the parsed device strcture PARSED to NEW
4. call libxl_device_TYPE_add(PARSED)
5. pull from PARSED any fields that might be touched by libxl to NEW
6. store domain configuration
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
tools/libxl/xl_cmdimpl.c | 85 +++++++++++++++++++++++++++++++++++++---------
1 file changed, 69 insertions(+), 16 deletions(-)
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 83f058e..91172c5 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -381,6 +381,36 @@ static void *xrealloc(void *ptr, size_t sz) {
&(array)[array_extend_old_count]; \
})
+#define ARRAY_EXTEND_INIT_NODEVID(array,count,initfn) \
+ ({ \
+ typeof((count)) array_extend_old_count = (count); \
+ (count)++; \
+ (array) = xrealloc((array), sizeof(*array) * (count)); \
+ (initfn)(&(array)[array_extend_old_count]); \
+ &(array)[array_extend_old_count]; \
+ })
+
+/* Add a device and update the stored configuration */
+#define ADD_DEVICE(devtype,domid,dev,d_config,ptr,allocate,maybe_fixup) \
+ do { \
+ libxl_domain_config_init((d_config)); \
+ load_domain_config((domid), (d_config)); \
+ \
+ allocate; \
+ \
+ libxl_device_ ## devtype ## _copy(ctx,(ptr),&(dev)); \
+ \
+ if (libxl_device_ ## devtype ## _add(ctx,(domid),&(dev), 0)) { \
+ fprintf(stderr, "libxl_device_%s_add failed.\n", #devtype); \
+ exit(1); \
+ } \
+ \
+ maybe_fixup; \
+ \
+ store_domain_config((domid), (d_config)); \
+ libxl_domain_config_dispose((d_config)); \
+ } while (0)
+
#define LOG(_f, _a...) dolog(__FILE__, __LINE__, __func__, _f "\n", ##_a)
static void dolog(const char *file, int line, const char *func, char *fmt, ...)
@@ -3047,7 +3077,8 @@ int main_pcidetach(int argc, char **argv)
}
static void pciattach(uint32_t domid, const char *bdf, const char *vs)
{
- libxl_device_pci pcidev;
+ libxl_domain_config d_config;
+ libxl_device_pci pcidev, *ppcidev;
XLU_Config *config;
libxl_device_pci_init(&pcidev);
@@ -3059,7 +3090,12 @@ static void pciattach(uint32_t domid, const char *bdf, const char *vs)
fprintf(stderr, "pci-attach: malformed BDF specification \"%s\"\n", bdf);
exit(2);
}
- libxl_device_pci_add(ctx, domid, &pcidev, 0);
+
+ ADD_DEVICE(pci, domid, pcidev, &d_config, ppcidev, {
+ ppcidev = ARRAY_EXTEND_INIT_NODEVID(d_config.pcidevs,
+ d_config.num_pcidevs,
+ libxl_device_pci_init);
+ }, {});
libxl_device_pci_dispose(&pcidev);
xlu_cfg_destroy(config);
@@ -5959,7 +5995,8 @@ int main_networkattach(int argc, char **argv)
{
uint32_t domid;
int opt;
- libxl_device_nic nic;
+ libxl_domain_config d_config;
+ libxl_device_nic nic, *pnic;
XLU_Config *config = 0;
char *endptr, *oparg;
const char *tok;
@@ -6040,10 +6077,16 @@ int main_networkattach(int argc, char **argv)
return 0;
}
- if (libxl_device_nic_add(ctx, domid, &nic, 0)) {
- fprintf(stderr, "libxl_device_nic_add failed.\n");
- return 1;
- }
+ /* libxl allocates devid and may generate mac */
+ ADD_DEVICE(nic, domid, nic, &d_config, pnic, {
+ pnic = ARRAY_EXTEND_INIT(d_config.nics,
+ d_config.num_nics,
+ libxl_device_nic_init);
+ }, {
+ pnic->devid = nic.devid;
+ libxl_mac_copy(ctx, &pnic->mac, &nic.mac);
+ });
+
libxl_device_nic_dispose(&nic);
xlu_cfg_destroy(config);
return 0;
@@ -6123,7 +6166,8 @@ int main_blockattach(int argc, char **argv)
{
int opt;
uint32_t fe_domid;
- libxl_device_disk disk;
+ libxl_domain_config d_config;
+ libxl_device_disk disk, *pdisk;
XLU_Config *config = 0;
SWITCH_FOREACH_OPT(opt, "", NULL, "block-attach", 2) {
@@ -6147,9 +6191,12 @@ int main_blockattach(int argc, char **argv)
return 0;
}
- if (libxl_device_disk_add(ctx, fe_domid, &disk, 0)) {
- fprintf(stderr, "libxl_device_disk_add failed.\n");
- }
+ ADD_DEVICE(disk, fe_domid, disk, &d_config, pdisk, {
+ pdisk = ARRAY_EXTEND_INIT_NODEVID(d_config.disks,
+ d_config.num_disks,
+ libxl_device_disk_init);
+ }, {});
+
return 0;
}
@@ -6218,7 +6265,8 @@ int main_blockdetach(int argc, char **argv)
int main_vtpmattach(int argc, char **argv)
{
int opt;
- libxl_device_vtpm vtpm;
+ libxl_domain_config d_config;
+ libxl_device_vtpm vtpm, *pvtpm;
char *oparg;
uint32_t domid;
@@ -6256,10 +6304,15 @@ int main_vtpmattach(int argc, char **argv)
return 0;
}
- if (libxl_device_vtpm_add(ctx, domid, &vtpm, 0)) {
- fprintf(stderr, "libxl_device_vtpm_add failed.\n");
- return 1;
- }
+ /* libxl may generates UUID for vtpm */
+ ADD_DEVICE(vtpm, domid, vtpm, &d_config, pvtpm, {
+ pvtpm = ARRAY_EXTEND_INIT(d_config.vtpms,
+ d_config.num_vtpms,
+ libxl_device_vtpm_init);
+ }, {
+ libxl_uuid_copy(&pvtpm->uuid, &vtpm.uuid);
+ });
+
libxl_device_vtpm_dispose(&vtpm);
return 0;
}
--
1.7.10.4
next prev parent reply other threads:[~2014-05-01 12:58 UTC|newest]
Thread overview: 120+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-01 12:57 [PATCH V4 00/24] JSON infrastructure, new "xl-json" format and domain configuration synchronization Wei Liu
2014-05-01 12:57 ` [PATCH V4 01/24] xl / libxl: push parsing of SSID and CPU pool ID down to libxl Wei Liu
2014-05-06 12:45 ` Ian Campbell
2014-05-06 13:03 ` Wei Liu
2014-05-07 9:50 ` Ian Campbell
2014-05-07 10:30 ` Wei Liu
2014-05-01 12:57 ` [PATCH V4 02/24] libxl: fix memory leak in libxl_cpuid_dispose Wei Liu
2014-05-06 12:47 ` Ian Campbell
2014-05-01 12:58 ` [PATCH V4 03/24] libxl.h: document the paradigm of using libxl types Wei Liu
2014-05-06 12:49 ` Ian Campbell
2014-05-06 13:12 ` Ian Jackson
2014-05-06 13:49 ` Wei Liu
2014-05-07 9:53 ` Ian Campbell
2014-05-01 12:58 ` [PATCH V4 04/24] libxl.h: move / add some libxl defbool #define here Wei Liu
2014-05-06 12:50 ` Ian Campbell
2014-05-01 12:58 ` [PATCH V4 05/24] libxl IDL: rename json_fn to json_gen_fn Wei Liu
2014-05-01 12:58 ` [PATCH V4 06/24] libxl_json: introduce libx__object_from_json Wei Liu
2014-05-06 12:53 ` Ian Campbell
2014-05-01 12:58 ` [PATCH V4 07/24] libxl_internal: make JSON_* types a bit-field Wei Liu
2014-05-01 12:58 ` [PATCH V4 08/24] libxl_internal: introduce libxl__json_object_is_{null, number, double} Wei Liu
2014-05-01 12:58 ` [PATCH V4 09/24] libxl_json: introduce parser functions for builtin types Wei Liu
2014-05-06 12:57 ` Ian Campbell
2014-05-06 13:06 ` Wei Liu
2014-05-07 9:57 ` Ian Campbell
2014-05-06 13:57 ` Anthony PERARD
2014-05-06 14:04 ` Wei Liu
2014-05-06 14:35 ` Anthony PERARD
2014-05-06 14:45 ` Wei Liu
2014-05-06 14:49 ` Wei Liu
2014-05-06 15:14 ` Anthony PERARD
2014-05-06 15:42 ` Wei Liu
2014-05-06 15:59 ` Anthony PERARD
2014-05-06 16:13 ` Wei Liu
2014-05-12 16:43 ` Wei Liu
2014-05-13 8:26 ` Ian Campbell
2014-05-13 9:19 ` Wei Liu
2014-05-13 9:32 ` Ian Campbell
2014-05-13 10:40 ` Wei Liu
2014-05-13 10:45 ` Ian Campbell
2014-05-13 10:51 ` Wei Liu
2014-05-13 10:55 ` Ian Campbell
2014-05-13 11:03 ` Wei Liu
2014-05-13 11:13 ` Ian Campbell
2014-05-13 11:38 ` Wei Liu
2014-05-13 11:28 ` Anthony PERARD
2014-05-13 11:40 ` Wei Liu
2014-05-13 11:54 ` Ian Campbell
2014-05-13 11:58 ` Wei Liu
2014-05-01 12:58 ` [PATCH V4 10/24] libxl_json: allow basic JSON type objects generation Wei Liu
2014-05-06 13:02 ` Ian Campbell
2014-05-01 12:58 ` [PATCH V4 11/24] libxl/gentypes.py: include discriminator in JSON output Wei Liu
2014-05-06 13:03 ` Ian Campbell
2014-05-06 13:09 ` Wei Liu
2014-05-07 10:00 ` Ian Campbell
2014-05-07 10:35 ` Wei Liu
2014-05-07 10:45 ` Ian Campbell
2014-05-01 12:58 ` [PATCH V4 12/24] libxl IDL: generate code to parse libxl__json_object to libxl_FOO struct Wei Liu
2014-05-06 13:45 ` Ian Campbell
2014-05-01 12:58 ` [PATCH V4 13/24] libxl/gentest.py: test JSON parser Wei Liu
2014-05-06 13:46 ` Ian Campbell
2014-05-06 14:11 ` Wei Liu
2014-05-01 12:58 ` [PATCH V4 14/24] libxl: introduce libxl_key_value_list_length Wei Liu
2014-05-06 13:50 ` Ian Campbell
2014-05-06 14:13 ` Wei Liu
2014-05-01 12:58 ` [PATCH V4 15/24] libxl: introduce libxl_cpuid_policy_list_length Wei Liu
2014-05-06 13:51 ` Ian Campbell
2014-05-06 14:17 ` Wei Liu
2014-05-01 12:58 ` [PATCH V4 16/24] libxl: copy function for builtin types Wei Liu
2014-05-06 14:03 ` Ian Campbell
2014-05-06 14:36 ` Wei Liu
2014-05-07 10:05 ` Ian Campbell
2014-05-07 10:19 ` Wei Liu
2014-05-07 10:40 ` Ian Campbell
2014-05-07 10:47 ` Ian Jackson
2014-05-07 10:57 ` Ian Campbell
2014-05-07 12:55 ` Wei Liu
2014-05-07 13:10 ` Ian Campbell
2014-05-01 12:58 ` [PATCH V4 17/24] libxl IDL: generate deep copy functions Wei Liu
2014-05-06 14:06 ` Ian Campbell
2014-05-01 12:58 ` [PATCH V4 18/24] libxl/gentest.py: test " Wei Liu
2014-05-06 14:06 ` Ian Campbell
2014-05-01 12:58 ` [PATCH V4 19/24] xl: introduce and use "xl-json" format Wei Liu
2014-05-06 14:26 ` Ian Campbell
2014-05-06 15:17 ` Wei Liu
2014-05-06 16:35 ` Wei Liu
2014-05-07 10:11 ` Ian Campbell
2014-05-07 11:18 ` Ian Jackson
2014-05-07 11:20 ` Wei Liu
2014-05-07 11:30 ` Ian Campbell
2014-05-07 13:00 ` Wei Liu
2014-05-07 13:08 ` Ian Campbell
2014-05-07 11:16 ` Ian Jackson
2014-05-07 11:20 ` Ian Campbell
2014-05-07 12:56 ` Wei Liu
2014-05-01 12:58 ` [PATCH V4 20/24] xl: introduce load/save_domain_config Wei Liu
2014-05-06 14:28 ` Ian Campbell
2014-05-06 15:03 ` Wei Liu
2014-05-07 10:12 ` Ian Campbell
2014-05-01 12:58 ` [PATCH V4 21/24] xl: update domain configuration when running mem-set and mem-max Wei Liu
2014-05-06 14:30 ` Ian Campbell
2014-05-06 14:56 ` Wei Liu
2014-05-01 12:58 ` Wei Liu [this message]
2014-05-06 15:44 ` [PATCH V4 22/24] xl: update domain configuration when we hotplug a device Ian Campbell
2014-05-06 15:58 ` Wei Liu
2014-05-07 10:16 ` Ian Campbell
2014-05-06 16:57 ` David Vrabel
2014-05-06 17:13 ` Wei Liu
2014-05-07 10:21 ` David Vrabel
2014-05-07 10:42 ` Ian Campbell
2014-05-07 10:59 ` Andrew Cooper
2014-05-01 12:58 ` [PATCH V4 23/24] libxl: consider force removal of device successful Wei Liu
2014-05-06 15:48 ` Ian Campbell
2014-05-06 16:04 ` Wei Liu
2014-05-07 10:18 ` Ian Campbell
2014-05-07 13:09 ` Wei Liu
2014-05-01 12:58 ` [PATCH V4 24/24] xl: update configuration when we unplug a device Wei Liu
2014-05-06 15:55 ` Ian Campbell
2014-05-06 16:12 ` Wei Liu
2014-05-07 10:20 ` Ian Campbell
2014-05-01 13:02 ` [PATCH V4 00/24] JSON infrastructure, new "xl-json" format and domain configuration synchronization Wei Liu
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=1398949101-23320-23-git-send-email-wei.liu2@citrix.com \
--to=wei.liu2@citrix.com \
--cc=ian.campbell@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).