[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v1 08/12] tmem: Handle 'struct tmem_info' as a seperate field in the
the struct tmem_op. No functional change. But it makes the code so much easier to read. Note: We still have to do this awkward 'guest_handle_cast' otherwise it will not compile on ARM - which defines _two_ of these macros (__guest_handle_64_xen_sysctl_tmem_client_t and __guest_handle_xen_sysctl_tmem_client_t). And if cast is not used then a compile error comes up as we use the wrong one. Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> --- Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Wei Liu <wei.liu2@xxxxxxxxxx> v1: First submission. --- tools/libxc/xc_tmem.c | 4 +-- xen/common/tmem.c | 8 +++--- xen/common/tmem_control.c | 68 ++++++++++++++++++++++----------------------- xen/include/public/sysctl.h | 11 +++++--- 4 files changed, 46 insertions(+), 45 deletions(-) diff --git a/tools/libxc/xc_tmem.c b/tools/libxc/xc_tmem.c index 74d2d85..cb0dfa1 100644 --- a/tools/libxc/xc_tmem.c +++ b/tools/libxc/xc_tmem.c @@ -87,7 +87,7 @@ int xc_tmem_control(xc_interface *xch, } } - set_xen_guest_handle(sysctl.u.tmem_op.buf, buf); + set_xen_guest_handle(sysctl.u.tmem_op.u.buf, buf); rc = do_sysctl(xch, &sysctl); @@ -133,7 +133,7 @@ int xc_tmem_control_oid(xc_interface *xch, } } - set_xen_guest_handle(sysctl.u.tmem_op.buf, buf); + set_xen_guest_handle(sysctl.u.tmem_op.u.buf, buf); rc = do_sysctl(xch, &sysctl); diff --git a/xen/common/tmem.c b/xen/common/tmem.c index 27164ce..ab354b6 100644 --- a/xen/common/tmem.c +++ b/xen/common/tmem.c @@ -1843,19 +1843,19 @@ int do_tmem_control(struct xen_sysctl_tmem_op *op) case XEN_SYSCTL_TMEM_OP_RESTORE_BEGIN: case XEN_SYSCTL_TMEM_OP_SAVE_END: ret = tmemc_save_subop(op->cli_id, pool_id, cmd, - guest_handle_cast(op->buf, char), op->arg1); + guest_handle_cast(op->u.buf, char), op->arg1); break; case XEN_SYSCTL_TMEM_OP_SAVE_GET_NEXT_PAGE: ret = tmemc_save_get_next_page(op->cli_id, pool_id, - guest_handle_cast(op->buf, char), op->arg1); + guest_handle_cast(op->u.buf, char), op->arg1); break; case XEN_SYSCTL_TMEM_OP_SAVE_GET_NEXT_INV: ret = tmemc_save_get_next_inv(op->cli_id, - guest_handle_cast(op->buf, char), op->arg1); + guest_handle_cast(op->u.buf, char), op->arg1); break; case XEN_SYSCTL_TMEM_OP_RESTORE_PUT_PAGE: ret = tmemc_restore_put_page(op->cli_id, pool_id, oidp, op->arg2, - guest_handle_cast(op->buf, char), op->arg1); + guest_handle_cast(op->u.buf, char), op->arg1); break; case XEN_SYSCTL_TMEM_OP_RESTORE_FLUSH_PAGE: ret = tmemc_restore_flush_page(op->cli_id, pool_id, oidp, op->arg2); diff --git a/xen/common/tmem_control.c b/xen/common/tmem_control.c index 8bb9d48..942d4c9 100644 --- a/xen/common/tmem_control.c +++ b/xen/common/tmem_control.c @@ -258,7 +258,7 @@ static int tmemc_list(domid_t cli_id, tmem_cli_va_param_t buf, uint32_t len, return 0; } -static int __tmemc_set_var(struct client *client, uint32_t subop, +static int __tmemc_set_var(struct client *client, XEN_GUEST_HANDLE_PARAM(xen_sysctl_tmem_client_t) buf) { domid_t cli_id = client->cli_id; @@ -267,11 +267,6 @@ static int __tmemc_set_var(struct client *client, uint32_t subop, ASSERT(client); - if ( subop != XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO ) - { - tmem_client_warn("tmem: unknown subop %d for tmemc_set_var\n", subop); - return -1; - } if ( copy_from_guest(&info, buf, 1) ) return -EFAULT; @@ -296,20 +291,17 @@ static int __tmemc_set_var(struct client *client, uint32_t subop, return 0; } -static int tmemc_set_var(domid_t cli_id, uint32_t subop, - XEN_GUEST_HANDLE_PARAM(void) buf) +static int tmemc_set_client_info(domid_t cli_id, + XEN_GUEST_HANDLE_PARAM(xen_sysctl_tmem_client_t) info) { struct client *client; int ret = -ENOENT; - XEN_GUEST_HANDLE_PARAM(xen_sysctl_tmem_client_t) info; - - info = guest_handle_cast(buf, xen_sysctl_tmem_client_t); if ( cli_id == TMEM_CLI_ID_NULL ) { list_for_each_entry(client,&tmem_global.client_list,client_list) { - ret = __tmemc_set_var(client, subop, info); + ret = __tmemc_set_var(client, info); if (ret) break; } @@ -318,11 +310,32 @@ static int tmemc_set_var(domid_t cli_id, uint32_t subop, { client = tmem_client_from_cli_id(cli_id); if ( client ) - ret = __tmemc_set_var(client, subop, info); + ret = __tmemc_set_var(client, info); } return ret; } +static int tmemc_get_client_info(int cli_id, + XEN_GUEST_HANDLE_PARAM(xen_sysctl_tmem_client_t) info) +{ + struct client *client = tmem_client_from_cli_id(cli_id); + + if ( client ) + { + if ( copy_to_guest(info, &client->info, 1) ) + return -EFAULT; + } + else + { + xen_sysctl_tmem_client_t generic = { .version = TMEM_SPEC_VERSION, + .maxpools = MAX_POOLS_PER_DOMAIN }; + if ( copy_to_guest(info, &generic, 1) ) + return -EFAULT; + } + + return 0; +} + static int tmemc_save_subop(int cli_id, uint32_t pool_id, uint32_t subop, XEN_GUEST_HANDLE_PARAM(void) buf, uint32_t arg1) { @@ -330,27 +343,9 @@ static int tmemc_save_subop(int cli_id, uint32_t pool_id, uint32_t subop, struct tmem_pool *pool = (client == NULL || pool_id >= MAX_POOLS_PER_DOMAIN) ? NULL : client->pools[pool_id]; int rc = -1; - XEN_GUEST_HANDLE_PARAM(xen_sysctl_tmem_client_t) info; switch(subop) { - case XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO: - rc = 0; - info = guest_handle_cast(buf, xen_sysctl_tmem_client_t); - if ( client ) - { - if ( copy_to_guest(info, &client->info, 1) ) - rc = -EFAULT; - } - else - { - xen_sysctl_tmem_client_t generic = { .version = TMEM_SPEC_VERSION, - .maxpools = MAX_POOLS_PER_DOMAIN }; - - if ( copy_to_guest(info, &generic, 1) ) - rc = -EFAULT; - } - break; case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_FLAGS: if ( pool == NULL ) break; @@ -400,21 +395,24 @@ int tmem_control(struct xen_sysctl_tmem_op *op) break; case XEN_SYSCTL_TMEM_OP_LIST: ret = tmemc_list(op->cli_id, - guest_handle_cast(op->buf, char), op->arg1, op->arg2); + guest_handle_cast(op->u.buf, char), op->arg1, op->arg2); break; case XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO: - ret = tmemc_set_var(op->cli_id, cmd, - guest_handle_cast(op->buf, void)); + ret = tmemc_set_client_info(op->cli_id, + guest_handle_cast(op->u.client, xen_sysctl_tmem_client_t)); break; case XEN_SYSCTL_TMEM_OP_QUERY_FREEABLE_MB: ret = tmem_freeable_pages() >> (20 - PAGE_SHIFT); break; case XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO: + ret = tmemc_get_client_info(op->cli_id, + guest_handle_cast(op->u.client, xen_sysctl_tmem_client_t)); + break; case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_FLAGS: case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_NPAGES: case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_UUID: ret = tmemc_save_subop(op->cli_id, pool_id, cmd, - guest_handle_cast(op->buf, void), op->arg1); + guest_handle_cast(op->u.buf, void), op->arg1); break; default: ret = do_tmem_control(op); diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 27e051b..52898a7 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -782,8 +782,8 @@ struct tmem_handle { }; /* - * XEN_SYSCTL_TMEM_OP_[GET,SAVE]_CLIENT overrides the 'buf' in - * xen_sysctl_tmem_op with this structure - and contain data used + * XEN_SYSCTL_TMEM_OP_[GET,SAVE]_CLIENT uses the 'client' in + * xen_sysctl_tmem_op with this structure - which is mostly used * during migration. */ struct tmem_client { @@ -812,8 +812,11 @@ struct xen_sysctl_tmem_op { uint32_t arg2; /* IN: If not applicable to command use 0. */ uint32_t pad; /* Padding so structure is the same under 32 and 64. */ xen_tmem_oid_t oid; /* IN: If not applicable to command use 0s. */ - XEN_GUEST_HANDLE_64(char) buf; /* IN/OUT: Buffer to save/restore, - and set/get ops. */ + union { + XEN_GUEST_HANDLE_64(char) buf; /* IN/OUT: Buffer to save/restore */ + XEN_GUEST_HANDLE_64(xen_sysctl_tmem_client_t) client; /* IN/OUT for */ + /* XEN_SYSCTL_TMEM_OP_[GET,SAVE]_CLIENT. */ + } u; }; typedef struct xen_sysctl_tmem_op xen_sysctl_tmem_op_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_tmem_op_t); -- 2.4.11 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |