[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC Patch v2 15/45] don't touch remus in checkpoint_device
Checkpoint device is an abstract layer to do checkpoint. COLO can also use it to do checkpoint. But there is still some codes in checkpoint device which touch remus: 1. remus_ops: we use remus ops directly in checkpoint device. Store it in checkpoint device state. 2. concrete layer's private member: add a new structure remus state, and move them to remus state. Signed-off-by: Wen Congyang <wency@xxxxxxxxxxxxxx> --- tools/libxl/libxl.c | 2 +- tools/libxl/libxl_checkpoint_device.c | 14 +++------- tools/libxl/libxl_dom.c | 3 +-- tools/libxl/libxl_internal.h | 37 ++++++++++++++++--------- tools/libxl/libxl_netbuffer.c | 51 ++++++++++++++++++++--------------- tools/libxl/libxl_remus.c | 50 +++++++++++++++++++++------------- tools/libxl/libxl_remus.h | 5 ++-- tools/libxl/libxl_remus_disk_drbd.c | 9 ++++--- 8 files changed, 97 insertions(+), 74 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index ff93af3..9a8fd16 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -820,7 +820,7 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info, assert(info); /* Point of no return */ - libxl__remus_setup(egc, dss); + libxl__remus_setup(egc, &dss->rs); return AO_INPROGRESS; out: diff --git a/tools/libxl/libxl_checkpoint_device.c b/tools/libxl/libxl_checkpoint_device.c index a57b9e4..f73db0e 100644 --- a/tools/libxl/libxl_checkpoint_device.c +++ b/tools/libxl/libxl_checkpoint_device.c @@ -17,14 +17,6 @@ #include "libxl_internal.h" -extern const libxl__checkpoint_device_subkind_ops remus_device_nic; -extern const libxl__checkpoint_device_subkind_ops remus_device_drbd_disk; -static const libxl__checkpoint_device_subkind_ops *remus_ops[] = { - &remus_device_nic, - &remus_device_drbd_disk, - NULL, -}; - /*----- helper functions -----*/ static int init_device_subkind(libxl__checkpoint_devices_state *cds) @@ -32,7 +24,7 @@ static int init_device_subkind(libxl__checkpoint_devices_state *cds) int rc; const libxl__checkpoint_device_subkind_ops **ops; - for (ops = remus_ops; *ops; ops++) { + for (ops = cds->ops; *ops; ops++) { rc = (*ops)->init(cds); if (rc) goto out; @@ -48,7 +40,7 @@ static void cleanup_device_subkind(libxl__checkpoint_devices_state *cds) { const libxl__checkpoint_device_subkind_ops **ops; - for (ops = remus_ops; *ops; ops++) + for (ops = cds->ops; *ops; ops++) (*ops)->cleanup(cds); } @@ -148,7 +140,7 @@ static void checkpoint_devices_setup(libxl__egc *egc, /* find avaliable ops */ do { - dev->ops = remus_ops[++dev->ops_index]; + dev->ops = cds->ops[++dev->ops_index]; if (!dev->ops) { rc = ERROR_CHECKPOINT_DEVICE_NOT_SUPPORTED; goto out; diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index f819846..4e71ec5 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -1605,7 +1605,6 @@ void libxl__domain_suspend(libxl__egc *egc, libxl__domain_suspend_state *dss) dss2->save_dm = 1; if (r_info != NULL) { - dss->interval = r_info->interval; if (r_info->compression) dss->xcflags |= XCFLAGS_CHECKPOINT_COMPRESS; } @@ -1787,7 +1786,7 @@ static void domain_suspend_done(libxl__egc *egc, dss2->guest_evtchn.port, &dss2->guest_evtchn_lockfd); if (dss->remus) { - libxl__remus_teardown(egc, dss, rc); + libxl__remus_teardown(egc, &dss->rs, rc); return; } diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 766868c..4d37cb4 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2627,6 +2627,8 @@ struct libxl__checkpoint_devices_state { uint32_t domid; libxl__checkpoint_callback *callback; int device_kind_flags; + /* The ops must be pointer array, and the last ops must be NULL */ + const libxl__checkpoint_device_subkind_ops **ops; /*----- private for abstract layer only -----*/ @@ -2645,16 +2647,6 @@ struct libxl__checkpoint_devices_state { int num_disks; libxl__multidev multidev; - - /*----- private for concrete (device-specific) layer only -----*/ - - /* private for nic device subkind ops */ - char *netbufscript; - struct nl_sock *nlsock; - struct nl_cache *qdisc_cache; - - /* private for drbd disk subkind ops */ - char *drbd_probe_script; }; /* @@ -2704,6 +2696,27 @@ _hidden void libxl__checkpoint_devices_preresume(libxl__egc *egc, libxl__checkpoint_devices_state *cds); _hidden void libxl__checkpoint_devices_commit(libxl__egc *egc, libxl__checkpoint_devices_state *cds); + +/*----- Remus related state structure -----*/ +typedef struct libxl__remus_state libxl__remus_state; +struct libxl__remus_state { + /* private */ + libxl__ev_time checkpoint_timeout; /* used for Remus checkpoint */ + int interval; /* checkpoint interval */ + + /* abstract layer */ + libxl__checkpoint_devices_state cds; + + /*----- private for concrete (device-specific) layer only -----*/ + /* private for nic device subkind ops */ + char *netbufscript; + struct nl_sock *nlsock; + struct nl_cache *qdisc_cache; + + /* private for drbd disk subkind ops */ + char *drbd_probe_script; +}; + _hidden int libxl__netbuffer_enabled(libxl__gc *gc); /*----- Domain suspend (save) state structure -----*/ @@ -2767,9 +2780,7 @@ struct libxl__domain_suspend_state { libxl__domain_suspend_state2 dss2; int hvm; int xcflags; - libxl__checkpoint_devices_state cds; - libxl__ev_time checkpoint_timeout; /* used for Remus checkpoint */ - int interval; /* checkpoint interval (for Remus) */ + libxl__remus_state rs; libxl__save_helper_state shs; libxl__logdirty_switch logdirty; /* private for libxl__domain_save_device_model */ diff --git a/tools/libxl/libxl_netbuffer.c b/tools/libxl/libxl_netbuffer.c index 385922f..7944d43 100644 --- a/tools/libxl/libxl_netbuffer.c +++ b/tools/libxl/libxl_netbuffer.c @@ -43,18 +43,19 @@ int libxl__netbuffer_enabled(libxl__gc *gc) static int nic_init(libxl__checkpoint_devices_state *cds) { int rc, ret; - libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, cds); + libxl__remus_state *rs = CONTAINER_OF(cds, *rs, cds); + libxl__domain_suspend_state *dss = CONTAINER_OF(rs, *dss, rs); STATE_AO_GC(cds->ao); - cds->nlsock = nl_socket_alloc(); - if (!cds->nlsock) { + rs->nlsock = nl_socket_alloc(); + if (!rs->nlsock) { LOG(ERROR, "cannot allocate nl socket"); rc = ERROR_FAIL; goto out; } - ret = nl_connect(cds->nlsock, NETLINK_ROUTE); + ret = nl_connect(rs->nlsock, NETLINK_ROUTE); if (ret) { LOG(ERROR, "failed to open netlink socket: %s", nl_geterror(ret)); @@ -63,7 +64,7 @@ static int nic_init(libxl__checkpoint_devices_state *cds) } /* get list of all qdiscs installed on network devs. */ - ret = rtnl_qdisc_alloc_cache(cds->nlsock, &cds->qdisc_cache); + ret = rtnl_qdisc_alloc_cache(rs->nlsock, &rs->qdisc_cache); if (ret) { LOG(ERROR, "failed to allocate qdisc cache: %s", nl_geterror(ret)); @@ -72,10 +73,10 @@ static int nic_init(libxl__checkpoint_devices_state *cds) } if (dss->remus->netbufscript) { - cds->netbufscript = libxl__strdup(gc, dss->remus->netbufscript); + rs->netbufscript = libxl__strdup(gc, dss->remus->netbufscript); } else { - cds->netbufscript = GCSPRINTF("%s/remus-netbuf-setup", - libxl__xen_script_dir_path()); + rs->netbufscript = GCSPRINTF("%s/remus-netbuf-setup", + libxl__xen_script_dir_path()); } rc = 0; @@ -86,20 +87,22 @@ out: static void nic_cleanup(libxl__checkpoint_devices_state *cds) { + libxl__remus_state *rs = CONTAINER_OF(cds, *rs, cds); + STATE_AO_GC(cds->ao); /* free qdisc cache */ - if (cds->qdisc_cache) { - nl_cache_clear(cds->qdisc_cache); - nl_cache_free(cds->qdisc_cache); - cds->qdisc_cache = NULL; + if (rs->qdisc_cache) { + nl_cache_clear(rs->qdisc_cache); + nl_cache_free(rs->qdisc_cache); + rs->qdisc_cache = NULL; } /* close & free nlsock */ - if (cds->nlsock) { - nl_close(cds->nlsock); - nl_socket_free(cds->nlsock); - cds->nlsock = NULL; + if (rs->nlsock) { + nl_close(rs->nlsock); + nl_socket_free(rs->nlsock); + rs->nlsock = NULL; } } @@ -152,13 +155,14 @@ static int init_qdisc(libxl__checkpoint_devices_state *cds, int rc, ret, ifindex; struct rtnl_link *ifb = NULL; struct rtnl_qdisc *qdisc = NULL; + libxl__remus_state *rs = CONTAINER_OF(cds, *rs, cds); STATE_AO_GC(cds->ao); /* Now that we have brought up REMUS_IFB device with plug qdisc for * this vif, so we need to refill the qdisc cache. */ - ret = nl_cache_refill(cds->nlsock, cds->qdisc_cache); + ret = nl_cache_refill(rs->nlsock, rs->qdisc_cache); if (ret) { LOG(ERROR, "cannot refill qdisc cache: %s", nl_geterror(ret)); rc = ERROR_FAIL; @@ -166,7 +170,7 @@ static int init_qdisc(libxl__checkpoint_devices_state *cds, } /* get a handle to the REMUS_IFB interface */ - ret = rtnl_link_get_kernel(cds->nlsock, 0, remus_nic->ifb, &ifb); + ret = rtnl_link_get_kernel(rs->nlsock, 0, remus_nic->ifb, &ifb); if (ret) { LOG(ERROR, "cannot obtain handle for %s: %s", remus_nic->ifb, nl_geterror(ret)); @@ -189,7 +193,7 @@ static int init_qdisc(libxl__checkpoint_devices_state *cds, * There is no need to explicitly free this qdisc as its just a * reference from the qdisc cache we allocated earlier. */ - qdisc = rtnl_qdisc_get_by_parent(cds->qdisc_cache, ifindex, TC_H_ROOT); + qdisc = rtnl_qdisc_get_by_parent(rs->qdisc_cache, ifindex, TC_H_ROOT); if (qdisc) { const char *tc_kind = rtnl_tc_get_kind(TC_CAST(qdisc)); /* Sanity check: Ensure that the root qdisc is a plug qdisc. */ @@ -240,11 +244,12 @@ static void setup_async_exec(libxl__checkpoint_device *dev, char *op) libxl__remus_device_nic *remus_nic = dev->concrete_data; libxl__checkpoint_devices_state *cds = dev->cds; libxl__async_exec_state *aes = &dev->aodev.aes; + libxl__remus_state *rs = CONTAINER_OF(cds, *rs, cds); STATE_AO_GC(cds->ao); /* Convenience aliases */ - char *const script = libxl__strdup(gc, cds->netbufscript); + char *const script = libxl__strdup(gc, rs->netbufscript); const uint32_t domid = cds->domid; const int dev_id = remus_nic->devid; const char *const vif = remus_nic->vif; @@ -335,6 +340,7 @@ static void netbuf_setup_script_cb(libxl__egc *egc, libxl__checkpoint_device *dev = CONTAINER_OF(aodev, *dev, aodev); libxl__remus_device_nic *remus_nic = dev->concrete_data; libxl__checkpoint_devices_state *cds = dev->cds; + libxl__remus_state *rs = CONTAINER_OF(cds, *rs, cds); const char *out_path_base, *hotplug_error = NULL; int rc; @@ -375,7 +381,7 @@ static void netbuf_setup_script_cb(libxl__egc *egc, if (hotplug_error) { LOG(ERROR, "netbuf script %s setup failed for vif %s: %s", - cds->netbufscript, vif, hotplug_error); + rs->netbufscript, vif, hotplug_error); rc = ERROR_FAIL; goto out; } @@ -446,6 +452,7 @@ static int remus_netbuf_op(libxl__remus_device_nic *remus_nic, int buffer_op) { int rc, ret; + libxl__remus_state *rs = CONTAINER_OF(cds, *rs, cds); STATE_AO_GC(cds->ao); @@ -459,7 +466,7 @@ static int remus_netbuf_op(libxl__remus_device_nic *remus_nic, goto out; } - ret = rtnl_qdisc_add(cds->nlsock, remus_nic->qdisc, NLM_F_REQUEST); + ret = rtnl_qdisc_add(rs->nlsock, remus_nic->qdisc, NLM_F_REQUEST); if (ret) { rc = ERROR_FAIL; goto out; diff --git a/tools/libxl/libxl_remus.c b/tools/libxl/libxl_remus.c index ca205a7..383b1d2 100644 --- a/tools/libxl/libxl_remus.c +++ b/tools/libxl/libxl_remus.c @@ -18,6 +18,13 @@ #include "libxl_internal.h" #include "libxl_remus.h" +extern const libxl__checkpoint_device_subkind_ops remus_device_nic; +extern const libxl__checkpoint_device_subkind_ops remus_device_drbd_disk; +static const libxl__checkpoint_device_subkind_ops *remus_ops[] = { + &remus_device_nic, + &remus_device_drbd_disk, + NULL, +}; /*----- remus: setup the environment -----*/ static void libxl__remus_setup_done(libxl__egc *egc, @@ -27,11 +34,12 @@ static void libxl__remus_setup_failed(libxl__egc *egc, libxl__checkpoint_devices_state *cds, int rc); -void libxl__remus_setup(libxl__egc *egc, - libxl__domain_suspend_state *dss) +void libxl__remus_setup(libxl__egc *egc, libxl__remus_state *rs) { + libxl__domain_suspend_state *dss = CONTAINER_OF(rs, *dss, rs); + /* Convenience aliases */ - libxl__checkpoint_devices_state *const cds = &dss->cds; + libxl__checkpoint_devices_state *const cds = &rs->cds; const libxl_domain_remus_info *const info = dss->remus; STATE_AO_GC(dss->ao); @@ -51,19 +59,21 @@ void libxl__remus_setup(libxl__egc *egc, cds->egc = egc; cds->domid = dss->domid; cds->callback = libxl__remus_setup_done; + cds->ops = remus_ops; + rs->interval = info->interval; libxl__checkpoint_devices_setup(egc, cds); return; out: - libxl__remus_setup_failed(egc, cds, ERROR_FAIL); + dss->callback(egc, dss, ERROR_FAIL); } static void libxl__remus_setup_done(libxl__egc *egc, libxl__checkpoint_devices_state *cds, int rc) { - libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, cds); + libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, rs.cds); STATE_AO_GC(dss->ao); if (!rc) { @@ -81,7 +91,7 @@ static void libxl__remus_setup_failed(libxl__egc *egc, libxl__checkpoint_devices_state *cds, int rc) { - libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, cds); + libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, rs.cds); STATE_AO_GC(dss->ao); if (rc) @@ -98,9 +108,11 @@ static void remus_teardown_done(libxl__egc *egc, int rc); void libxl__remus_teardown(libxl__egc *egc, - libxl__domain_suspend_state *dss, + libxl__remus_state *rs, int rc) { + libxl__domain_suspend_state *dss = CONTAINER_OF(rs, *dss, rs); + EGC_GC; /* @@ -111,15 +123,15 @@ void libxl__remus_teardown(libxl__egc *egc, */ LOG(WARN, "Remus: Domain suspend terminated with rc %d," " teardown Remus devices...", rc); - dss->cds.callback = remus_teardown_done; - libxl__checkpoint_devices_teardown(egc, &dss->cds); + dss->rs.cds.callback = remus_teardown_done; + libxl__checkpoint_devices_teardown(egc, &dss->rs.cds); } static void remus_teardown_done(libxl__egc *egc, libxl__checkpoint_devices_state *cds, int rc) { - libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, cds); + libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, rs.cds); STATE_AO_GC(dss->ao); if (rc) @@ -158,7 +170,7 @@ static void remus_domain_suspend_callback_common_done(libxl__egc *egc, if (!ok) goto out; - libxl__checkpoint_devices_state *const cds = &dss->cds; + libxl__checkpoint_devices_state *const cds = &dss->rs.cds; cds->callback = remus_devices_postsuspend_cb; libxl__checkpoint_devices_postsuspend(egc, cds); return; @@ -172,7 +184,7 @@ static void remus_devices_postsuspend_cb(libxl__egc *egc, int rc) { int ok = 0; - libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, cds); + libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, rs.cds); if (rc) goto out; @@ -196,7 +208,7 @@ void libxl__remus_domain_resume_callback(void *data) libxl__domain_suspend_state *dss = CONTAINER_OF(shs, *dss, shs); STATE_AO_GC(dss->ao); - libxl__checkpoint_devices_state *const cds = &dss->cds; + libxl__checkpoint_devices_state *const cds = &dss->rs.cds; cds->callback = remus_devices_preresume_cb; libxl__checkpoint_devices_preresume(egc, cds); } @@ -206,7 +218,7 @@ static void remus_devices_preresume_cb(libxl__egc *egc, int rc) { int ok = 0; - libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, cds); + libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, rs.cds); STATE_AO_GC(dss->ao); if (rc) @@ -250,7 +262,7 @@ static void remus_checkpoint_dm_saved(libxl__egc *egc, libxl__domain_suspend_state *dss, int rc) { /* Convenience aliases */ - libxl__checkpoint_devices_state *const cds = &dss->cds; + libxl__checkpoint_devices_state *const cds = &dss->rs.cds; STATE_AO_GC(dss->ao); @@ -272,7 +284,7 @@ static void remus_devices_commit_cb(libxl__egc *egc, libxl__checkpoint_devices_state *cds, int rc) { - libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, cds); + libxl__domain_suspend_state *dss = CONTAINER_OF(cds, *dss, rs.cds); STATE_AO_GC(dss->ao); @@ -290,9 +302,9 @@ static void remus_devices_commit_cb(libxl__egc *egc, */ /* Set checkpoint interval timeout */ - rc = libxl__ev_time_register_rel(gc, &dss->checkpoint_timeout, + rc = libxl__ev_time_register_rel(gc, &dss->rs.checkpoint_timeout, remus_next_checkpoint, - dss->interval); + dss->rs.interval); if (rc) { LOG(ERROR, "unable to register timeout for next epoch." @@ -310,7 +322,7 @@ static void remus_next_checkpoint(libxl__egc *egc, libxl__ev_time *ev, const struct timeval *requested_abs) { libxl__domain_suspend_state *dss = - CONTAINER_OF(ev, *dss, checkpoint_timeout); + CONTAINER_OF(ev, *dss, rs.checkpoint_timeout); STATE_AO_GC(dss->ao); diff --git a/tools/libxl/libxl_remus.h b/tools/libxl/libxl_remus.h index 53e5e81..15bbbe8 100644 --- a/tools/libxl/libxl_remus.h +++ b/tools/libxl/libxl_remus.h @@ -16,10 +16,9 @@ #ifndef LIBXL_REMUS_H #define LIBXL_REMUS_H -void libxl__remus_setup(libxl__egc *egc, - libxl__domain_suspend_state *dss); +void libxl__remus_setup(libxl__egc *egc, libxl__remus_state *rs); void libxl__remus_teardown(libxl__egc *egc, - libxl__domain_suspend_state *dss, + libxl__remus_state *rs, int rc); void libxl__remus_domain_suspend_callback(void *data); void libxl__remus_domain_resume_callback(void *data); diff --git a/tools/libxl/libxl_remus_disk_drbd.c b/tools/libxl/libxl_remus_disk_drbd.c index 5928187..89465b6 100644 --- a/tools/libxl/libxl_remus_disk_drbd.c +++ b/tools/libxl/libxl_remus_disk_drbd.c @@ -60,10 +60,12 @@ out: /*----- init() and cleanup() -----*/ static int drbd_init(libxl__checkpoint_devices_state *cds) { + libxl__remus_state *rs = CONTAINER_OF(cds, *rs, cds); + STATE_AO_GC(cds->ao); - cds->drbd_probe_script = GCSPRINTF("%s/block-drbd-probe", - libxl__xen_script_dir_path()); + rs->drbd_probe_script = GCSPRINTF("%s/block-drbd-probe", + libxl__xen_script_dir_path()); return 0; } @@ -96,6 +98,7 @@ static void match_async_exec(libxl__egc *egc, libxl__checkpoint_device *dev) int arraysize, nr = 0, rc; const libxl_device_disk *disk = dev->backend_dev; libxl__async_exec_state *aes = &dev->aodev.aes; + libxl__remus_state *rs = CONTAINER_OF(dev->cds, *rs, cds); STATE_AO_GC(dev->cds->ao); /* setup env & args */ @@ -107,7 +110,7 @@ static void match_async_exec(libxl__egc *egc, libxl__checkpoint_device *dev) arraysize = 3; nr = 0; GCNEW_ARRAY(aes->args, arraysize); - aes->args[nr++] = dev->cds->drbd_probe_script; + aes->args[nr++] = rs->drbd_probe_script; aes->args[nr++] = disk->pdev_path; aes->args[nr++] = NULL; assert(nr <= arraysize); -- 1.9.3 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |