[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v2 07/11] tmem: cleanup: drop typedef tmem_client_t



Informations in typedef 'tmem_client_t' can be integreated into
'struct client' directly, no need to use a separate struct.

Signed-off-by: Bob Liu <bob.liu@xxxxxxxxxx>
---
 xen/common/tmem.c          |   31 ++++++++++++++++++++++++-------
 xen/common/tmem_xen.c      |   34 ++--------------------------------
 xen/include/xen/tmem_xen.h |   40 +++++++---------------------------------
 3 files changed, 33 insertions(+), 72 deletions(-)

diff --git a/xen/common/tmem.c b/xen/common/tmem.c
index 589a515..db18b65 100644
--- a/xen/common/tmem.c
+++ b/xen/common/tmem.c
@@ -104,7 +104,8 @@ struct tmem_page_content_descriptor;
 struct client {
     struct list_head client_list;
     struct tmem_pool *pools[MAX_POOLS_PER_DOMAIN];
-    tmem_client_t *tmem;
+    struct domain *domain;
+    struct xmem_pool *persistent_pool;
     struct list_head ephemeral_page_list;
     long eph_count, eph_count_max;
     domid_t cli_id;
@@ -1190,7 +1191,9 @@ static void pool_flush(struct tmem_pool *pool, domid_t 
cli_id, bool_t destroy)
 static struct client *client_create(domid_t cli_id)
 {
     struct client *client = xzalloc(struct client);
-    int i;
+    int i, shift;
+    char name[5];
+    struct domain *d;
 
     tmem_client_info("tmem: initializing tmem capability for %s=%d...",
                     tmem_cli_id_str, cli_id);
@@ -1199,16 +1202,30 @@ static struct client *client_create(domid_t cli_id)
         tmem_client_err("failed... out of memory\n");
         goto fail;
     }
-    if ( (client->tmem = tmem_client_init(cli_id)) == NULL )
+
+    for (i = 0, shift = 12; i < 4; shift -=4, i++)
+        name[i] = (((unsigned short)cli_id >> shift) & 0xf) + '0';
+    name[4] = '\0';
+    client->persistent_pool = xmem_pool_create(name, 
tmem_persistent_pool_page_get,
+        tmem_persistent_pool_page_put, PAGE_SIZE, 0, PAGE_SIZE);
+    if ( client->persistent_pool == NULL )
     {
-        tmem_client_err("failed... can't allocate host-dependent part of 
client\n");
+        tmem_client_err("failed... can't alloc persistent pool\n");
         goto fail;
     }
-    if ( !tmem_set_client_from_id(client, client->tmem, cli_id) )
-    {
+
+    d = rcu_lock_domain_by_id(cli_id);
+    if ( d == NULL ) {
         tmem_client_err("failed... can't set client\n");
+        xmem_pool_destroy(client->persistent_pool);
         goto fail;
     }
+    if ( !d->is_dying ) {
+        d->tmem = client;
+       client->domain = d;
+    }
+    rcu_unlock_domain(d);
+
     client->cli_id = cli_id;
     client->compress = tmem_compression_enabled();
     client->shared_auth_required = tmem_shared_auth();
@@ -1235,7 +1252,7 @@ static struct client *client_create(domid_t cli_id)
 static void client_free(struct client *client)
 {
     list_del(&client->client_list);
-    tmem_client_destroy(client->tmem);
+    xmem_pool_destroy(client->persistent_pool);
     xfree(client);
 }
 
diff --git a/xen/common/tmem_xen.c b/xen/common/tmem_xen.c
index e92eab6..1309932 100644
--- a/xen/common/tmem_xen.c
+++ b/xen/common/tmem_xen.c
@@ -341,7 +341,7 @@ static int __init tmem_mempool_init(void)
 
 /* persistent pools are per-domain */
 
-static void *tmem_persistent_pool_page_get(unsigned long size)
+void *tmem_persistent_pool_page_get(unsigned long size)
 {
     struct page_info *pi;
     struct domain *d = current->domain;
@@ -353,7 +353,7 @@ static void *tmem_persistent_pool_page_get(unsigned long 
size)
     return page_to_virt(pi);
 }
 
-static void tmem_persistent_pool_page_put(void *page_va)
+void tmem_persistent_pool_page_put(void *page_va)
 {
     struct page_info *pi;
 
@@ -363,36 +363,6 @@ static void tmem_persistent_pool_page_put(void *page_va)
     _tmem_free_page_thispool(pi);
 }
 
-/******************  XEN-SPECIFIC CLIENT HANDLING ********************/
-
-EXPORT tmem_client_t *tmem_client_init(domid_t cli_id)
-{
-    tmem_client_t *tmem;
-    char name[5];
-    int i, shift;
-
-    if ( (tmem = xmalloc(tmem_client_t)) == NULL )
-        return NULL;
-    for (i = 0, shift = 12; i < 4; shift -=4, i++)
-        name[i] = (((unsigned short)cli_id >> shift) & 0xf) + '0';
-    name[4] = '\0';
-    tmem->persistent_pool = xmem_pool_create(name, 
tmem_persistent_pool_page_get,
-        tmem_persistent_pool_page_put, PAGE_SIZE, 0, PAGE_SIZE);
-    if ( tmem->persistent_pool == NULL )
-    {
-        xfree(tmem);
-        return NULL;
-    }
-    return tmem;
-}
-
-EXPORT void tmem_client_destroy(tmem_client_t *tmem)
-{
-    ASSERT(tmem->domain->is_dying);
-    xmem_pool_destroy(tmem->persistent_pool);
-    tmem->domain = NULL;
-}
-
 /******************  XEN-SPECIFIC HOST INITIALIZATION ********************/
 
 static int dstmem_order, workmem_order;
diff --git a/xen/include/xen/tmem_xen.h b/xen/include/xen/tmem_xen.h
index d4eafaf..3c99bee 100644
--- a/xen/include/xen/tmem_xen.h
+++ b/xen/include/xen/tmem_xen.h
@@ -21,13 +21,6 @@
 #ifdef CONFIG_COMPAT
 #include <compat/tmem.h>
 #endif
-
-struct tmem_host_dependent_client {
-    struct domain *domain;
-    struct xmem_pool *persistent_pool;
-};
-typedef struct tmem_host_dependent_client tmem_client_t;
-
 typedef uint32_t pagesize_t;  /* like size_t, must handle largest PAGE_SIZE */
 
 #define IS_PAGE_ALIGNED(addr) \
@@ -123,7 +116,7 @@ static inline bool_t domain_fully_allocated(struct domain 
*d)
     return ( d->tot_pages >= d->max_pages );
 }
 #define tmem_client_memory_fully_allocated(_pool) \
- domain_fully_allocated(_pool->client->tmem->domain)
+ domain_fully_allocated(_pool->client->domain)
 
 static inline void *_tmem_alloc_subpage_thispool(struct xmem_pool 
*cmem_mempool,
                                                  size_t size, size_t align)
@@ -138,7 +131,7 @@ static inline void *_tmem_alloc_subpage_thispool(struct 
xmem_pool *cmem_mempool,
     return xmem_pool_alloc(size, cmem_mempool);
 }
 #define tmem_alloc_subpage_thispool(_pool, _s, _a) \
-            _tmem_alloc_subpage_thispool(pool->client->tmem->persistent_pool, \
+            _tmem_alloc_subpage_thispool(pool->client->persistent_pool, \
                                          _s, _a)
 
 static inline void _tmem_free_subpage_thispool(struct xmem_pool *cmem_mempool,
@@ -149,7 +142,7 @@ static inline void _tmem_free_subpage_thispool(struct 
xmem_pool *cmem_mempool,
     xmem_pool_free(ptr,cmem_mempool);
 }
 #define tmem_free_subpage_thispool(_pool, _p, _s) \
- _tmem_free_subpage_thispool(_pool->client->tmem->persistent_pool, _p, _s)
+ _tmem_free_subpage_thispool(_pool->client->persistent_pool, _p, _s)
 
 static inline struct page_info *_tmem_alloc_page_thispool(struct domain *d)
 {
@@ -179,7 +172,7 @@ out:
     return pi;
 }
 #define tmem_alloc_page_thispool(_pool) \
-    _tmem_alloc_page_thispool(_pool->client->tmem->domain)
+    _tmem_alloc_page_thispool(_pool->client->domain)
 
 static inline void _tmem_free_page_thispool(struct page_info *pi)
 {
@@ -251,10 +244,6 @@ static inline unsigned long tmem_free_mb(void)
 /*  "Client" (==domain) abstraction */
 
 struct client;
-
-extern tmem_client_t *tmem_client_init(domid_t);
-extern void tmem_client_destroy(tmem_client_t *);
-
 static inline struct client *tmem_client_from_cli_id(domid_t cli_id)
 {
     struct client *c;
@@ -271,7 +260,7 @@ static inline struct client *tmem_client_from_current(void)
     return (struct client *)(current->domain->tmem);
 }
 
-#define tmem_client_is_dying(_client) (!!_client->tmem->domain->is_dying)
+#define tmem_client_is_dying(_client) (!!_client->domain->is_dying)
 
 static inline domid_t tmem_get_cli_id_from_current(void)
 {
@@ -283,23 +272,6 @@ static inline struct domain 
*tmem_get_cli_ptr_from_current(void)
     return current->domain;
 }
 
-static inline bool_t tmem_set_client_from_id(
-    struct client *client, tmem_client_t *tmem, domid_t cli_id)
-{
-    struct domain *d = rcu_lock_domain_by_id(cli_id);
-    bool_t rc = 0;
-    if ( d == NULL )
-        return 0;
-    if ( !d->is_dying )
-    {
-        d->tmem = client;
-        tmem->domain = d;
-        rc = 1;
-    }
-    rcu_unlock_domain(d);
-    return rc;
-}
-
 static inline bool_t tmem_current_permitted(void)
 {
     return !xsm_tmem_op(XSM_HOOK);
@@ -476,6 +448,8 @@ int tmem_copy_to_client(xen_pfn_t, struct page_info *, 
pagesize_t tmem_offset,
     pagesize_t pfn_offset, pagesize_t len, tmem_cli_va_param_t);
 
 extern int tmem_copy_tze_to_client(xen_pfn_t cmfn, void *tmem_va, pagesize_t 
len);
+extern void *tmem_persistent_pool_page_get(unsigned long size);
+extern void tmem_persistent_pool_page_put(void *page_va);
 
 #define tmem_client_err(fmt, args...)  printk(XENLOG_G_ERR fmt, ##args)
 #define tmem_client_warn(fmt, args...) printk(XENLOG_G_WARNING fmt, ##args)
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.