uint64_t uuid_lo,
uint64_t uuid_hi)
{
- tmem_op_t op;
-
- op.cmd = TMEM_RESTORE_NEW;
- op.pool_id = pool_id;
- op.u.creat.arg1 = cli_id;
- op.u.creat.flags = flags;
- op.u.creat.uuid[0] = uuid_lo;
- op.u.creat.uuid[1] = uuid_hi;
-
- return do_tmem_op(xch, &op);
+ xen_tmem_pool_info_t pool = {
+ .flags.raw = flags,
+ .id = pool_id,
+ .n_pages = 0,
+ .uuid[0] = uuid_lo,
+ .uuid[1] = uuid_hi,
+ };
+
+ return xc_tmem_control(xch, pool_id,
+ XEN_SYSCTL_TMEM_OP_SET_POOLS,
+ cli_id, sizeof(pool),
+ 0 /* arg */, &pool);
}
int xc_tmem_restore(xc_interface *xch, int dom, int io_fd)
/************ CLIENT MANIPULATION OPERATIONS **************************/
-static struct client *client_create(domid_t cli_id)
+struct client *client_create(domid_t cli_id)
{
struct client *client = xzalloc(struct client);
int i, shift;
return 1;
}
-static int do_tmem_new_pool(domid_t this_cli_id,
- uint32_t d_poolid, uint32_t flags,
- uint64_t uuid_lo, uint64_t uuid_hi)
+int do_tmem_new_pool(domid_t this_cli_id,
+ uint32_t d_poolid, uint32_t flags,
+ uint64_t uuid_lo, uint64_t uuid_hi)
{
struct client *client;
domid_t cli_id;
/* Acquire write lock for all commands at first. */
write_lock(&tmem_rwlock);
- if ( op.cmd == TMEM_CONTROL )
+ switch ( op.cmd )
{
+ case TMEM_CONTROL:
+ case TMEM_RESTORE_NEW:
rc = -EOPNOTSUPP;
- }
- else if ( op.cmd == TMEM_AUTH )
- {
+ break;
+
+ case TMEM_AUTH:
rc = tmemc_shared_pool_auth(op.u.creat.arg1,op.u.creat.uuid[0],
op.u.creat.uuid[1],op.u.creat.flags);
- }
- else if ( op.cmd == TMEM_RESTORE_NEW )
- {
- rc = do_tmem_new_pool(op.u.creat.arg1, op.pool_id, op.u.creat.flags,
- op.u.creat.uuid[0], op.u.creat.uuid[1]);
- }
- else {
+ break;
+
+ default:
/*
* For other commands, create per-client tmem structure dynamically on
* first use by client.
tmem_stats.errored_tmem_ops++;
return rc;
}
+ break;
+
}
out:
write_unlock(&tmem_rwlock);
return rc ? : idx;
}
+static int tmemc_set_pools(int cli_id,
+ XEN_GUEST_HANDLE(xen_tmem_pool_info_t) pools,
+ uint32_t len)
+{
+ unsigned int i;
+ int rc = 0;
+ unsigned int nr = len / sizeof(xen_tmem_pool_info_t);
+ struct client *client = tmem_client_from_cli_id(cli_id);
+
+ if ( len % sizeof(xen_tmem_pool_info_t) )
+ return -EINVAL;
+
+ if ( nr > MAX_POOLS_PER_DOMAIN )
+ return -E2BIG;
+
+ if ( !guest_handle_okay(pools, nr) )
+ return -EINVAL;
+
+ if ( !client )
+ {
+ client = client_create(cli_id);
+ if ( !client )
+ return -ENOMEM;
+ }
+ for ( i = 0; i < nr; i++ )
+ {
+ xen_tmem_pool_info_t pool;
+
+ if ( __copy_from_guest_offset(&pool, pools, i, 1 ) )
+ return -EFAULT;
+
+ if ( pool.n_pages )
+ return -EINVAL;
+
+ rc = do_tmem_new_pool(cli_id, pool.id, pool.flags.raw,
+ pool.uuid[0], pool.uuid[1]);
+ if ( rc < 0 )
+ break;
+
+ pool.id = rc;
+ if ( __copy_to_guest_offset(pools, i, &pool, 1) )
+ return -EFAULT;
+ }
+
+ /* And how many we have processed. */
+ return rc ? : i;
+}
+
int tmem_control(struct xen_sysctl_tmem_op *op)
{
int ret;
case XEN_SYSCTL_TMEM_OP_GET_POOLS:
ret = tmemc_get_pool(op->cli_id, op->u.pool, op->len);
break;
+ case XEN_SYSCTL_TMEM_OP_SET_POOLS: /* TMEM_RESTORE_NEW */
+ ret = tmemc_set_pools(op->cli_id, op->u.pool, op->len);
+ break;
default:
ret = do_tmem_control(op);
break;
#define XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO 6
#define XEN_SYSCTL_TMEM_OP_GET_POOLS 7
#define XEN_SYSCTL_TMEM_OP_QUERY_FREEABLE_MB 8
+#define XEN_SYSCTL_TMEM_OP_SET_POOLS 9
#define XEN_SYSCTL_TMEM_OP_SAVE_BEGIN 10
#define XEN_SYSCTL_TMEM_OP_SAVE_GET_NEXT_PAGE 19
#define XEN_SYSCTL_TMEM_OP_SAVE_GET_NEXT_INV 20
DEFINE_XEN_GUEST_HANDLE(xen_tmem_client_t);
/*
- * XEN_SYSCTL_TMEM_OP_GET_POOLS uses the 'pool' array in
- * xen_sysctl_tmem_op with this structure. The hypercall will
+ * XEN_SYSCTL_TMEM_OP_[GET|SET]_POOLS uses the 'pool' array in
+ * xen_sysctl_tmem_op with this structure.
+ * The XEN_SYSCTL_TMEM_OP_GET_POOLS hypercall will
* return the number of entries in 'pool' or a negative value
* if an error was encountered.
+ * The XEN_SYSCTL_TMEM_OP_SET_POOLS will return the number of
+ * entries in 'pool' processed or a negative value if an error
+ * was encountered.
*/
struct xen_tmem_pool_info {
union {
} u;
} flags;
uint32_t id; /* Less than tmem_client.maxpools. */
- uint64_t n_pages;
+ uint64_t n_pages; /* Zero on XEN_SYSCTL_TMEM_OP_SET_POOLS. */
uint64_aligned_t uuid[2];
};
typedef struct xen_tmem_pool_info xen_tmem_pool_info_t;
/* Privileged commands to HYPERVISOR_tmem_op() */
#define TMEM_AUTH 101
-#define TMEM_RESTORE_NEW 102
+#define TMEM_RESTORE_NEW 102 /* Now called via XEN_SYSCTL_tmem_op as
+ XEN_SYSCTL_TMEM_OP_SET_POOL. */
/* Bits for HYPERVISOR_tmem_op(TMEM_NEW_POOL) */
#define TMEM_POOL_PERSIST 1
uint64_t uuid[2];
uint32_t flags;
uint32_t arg1;
- } creat; /* for cmd == TMEM_NEW_POOL, TMEM_AUTH, TMEM_RESTORE_NEW */
+ } creat; /* for cmd == TMEM_NEW_POOL, TMEM_AUTH */
struct {
#if __XEN_INTERFACE_VERSION__ < 0x00040600
uint64_t oid[3];
int tmem_evict(void);
int do_tmem_control(struct xen_sysctl_tmem_op *op);
+struct client *client_create(domid_t cli_id);
+int do_tmem_new_pool(domid_t this_cli_id, uint32_t d_poolid, uint32_t flags,
+ uint64_t uuid_lo, uint64_t uuid_hi);
+
#endif /* CONFIG_TMEM */
#endif /* __XEN_TMEM_CONTROL_H__ */
{
case TMEM_NEW_POOL: u = XLAT_tmem_op_u_creat; break;
case TMEM_AUTH: u = XLAT_tmem_op_u_creat; break;
- case TMEM_RESTORE_NEW:u = XLAT_tmem_op_u_creat; break;
default: u = XLAT_tmem_op_u_gen ; break;
}
XLAT_tmem_op(op, &cop);