From: Bob Liu <lliubbo@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: james.harper@bendigoit.com.au, ian.campbell@citrix.com,
andrew.cooper3@citrix.com, JBeulich@suse.com
Subject: [PATCH v3 04/15] tmem: cleanup: drop useless parameters from put/get page
Date: Wed, 11 Dec 2013 16:50:33 +0800 [thread overview]
Message-ID: <1386751844-32387-5-git-send-email-bob.liu@oracle.com> (raw)
In-Reply-To: <1386751844-32387-1-git-send-email-bob.liu@oracle.com>
Tmem only takes page as a unit, so parameters tmem_offset, pfn_offset and len in
do_tmem_put/get() are meaningless. All of the callers are using the same
value(tmem_offset=0, pfn_offset=0, len=PAGE_SIZE).
This patch simplifies tmem ignoring those useless parameters and use the default
value directly.
Signed-off-by: Bob Liu <bob.liu@oracle.com>
---
xen/common/tmem.c | 47 +++++++++++++++++++-------------------------
xen/common/tmem_xen.c | 45 +++++++++---------------------------------
xen/include/xen/tmem_xen.h | 6 ++----
3 files changed, 31 insertions(+), 67 deletions(-)
diff --git a/xen/common/tmem.c b/xen/common/tmem.c
index cdc8826..da2326b 100644
--- a/xen/common/tmem.c
+++ b/xen/common/tmem.c
@@ -330,8 +330,7 @@ static int pcd_copy_to_client(xen_pfn_t cmfn, struct tmem_page_descriptor *pgp)
else if ( tmem_tze_enabled() && pcd->size < PAGE_SIZE )
ret = tmem_copy_tze_to_client(cmfn, pcd->tze, pcd->size);
else
- ret = tmem_copy_to_client(cmfn, pcd->pfp, 0, 0, PAGE_SIZE,
- tmem_cli_buf_null);
+ ret = tmem_copy_to_client(cmfn, pcd->pfp, tmem_cli_buf_null);
tmem_read_unlock(&pcd_tree_rwlocks[firstbyte]);
return ret;
}
@@ -1421,7 +1420,6 @@ out:
}
static int do_tmem_dup_put(struct tmem_page_descriptor *pgp, xen_pfn_t cmfn,
- pagesize_t tmem_offset, pagesize_t pfn_offset, pagesize_t len,
tmem_cli_va_param_t clibuf)
{
struct tmem_pool *pool;
@@ -1442,7 +1440,7 @@ static int do_tmem_dup_put(struct tmem_page_descriptor *pgp, xen_pfn_t cmfn,
if ( client->live_migrating )
goto failed_dup; /* no dups allowed when migrating */
/* can we successfully manipulate pgp to change out the data? */
- if ( len != 0 && client->compress && pgp->size != 0 )
+ if ( client->compress && pgp->size != 0 )
{
ret = do_tmem_put_compress(pgp, cmfn, clibuf);
if ( ret == 1 )
@@ -1461,9 +1459,7 @@ copy_uncompressed:
if ( ( pgp->pfp = tmem_page_alloc(pool) ) == NULL )
goto failed_dup;
pgp->size = 0;
- /* tmem_copy_from_client properly handles len==0 and offsets != 0 */
- ret = tmem_copy_from_client(pgp->pfp, cmfn, tmem_offset, pfn_offset, len,
- tmem_cli_buf_null);
+ ret = tmem_copy_from_client(pgp->pfp, cmfn, tmem_cli_buf_null);
if ( ret < 0 )
goto bad_copy;
if ( tmem_dedup_enabled() && !is_persistent(pool) )
@@ -1509,11 +1505,9 @@ cleanup:
return ret;
}
-
static int do_tmem_put(struct tmem_pool *pool,
struct oid *oidp, uint32_t index,
- xen_pfn_t cmfn, pagesize_t tmem_offset,
- pagesize_t pfn_offset, pagesize_t len, tmem_cli_va_param_t clibuf)
+ xen_pfn_t cmfn, tmem_cli_va_param_t clibuf)
{
struct tmem_object_root *obj = NULL, *objfound = NULL, *objnew = NULL;
struct tmem_page_descriptor *pgp = NULL, *pgpdel = NULL;
@@ -1527,8 +1521,7 @@ static int do_tmem_put(struct tmem_pool *pool,
{
ASSERT_SPINLOCK(&objfound->obj_spinlock);
if ((pgp = pgp_lookup_in_obj(objfound, index)) != NULL)
- return do_tmem_dup_put(pgp, cmfn, tmem_offset, pfn_offset, len,
- clibuf);
+ return do_tmem_dup_put(pgp, cmfn, clibuf);
}
/* no puts allowed into a frozen pool (except dup puts) */
@@ -1560,7 +1553,7 @@ static int do_tmem_put(struct tmem_pool *pool,
pgp->index = index;
pgp->size = 0;
- if ( len != 0 && client->compress )
+ if ( client->compress )
{
ASSERT(pgp->pfp == NULL);
ret = do_tmem_put_compress(pgp, cmfn, clibuf);
@@ -1586,9 +1579,7 @@ copy_uncompressed:
ret = -ENOMEM;
goto delete_and_free;
}
- /* tmem_copy_from_client properly handles len==0 (TMEM_NEW_PAGE) */
- ret = tmem_copy_from_client(pgp->pfp, cmfn, tmem_offset, pfn_offset, len,
- clibuf);
+ ret = tmem_copy_from_client(pgp->pfp, cmfn, clibuf);
if ( ret < 0 )
goto bad_copy;
if ( tmem_dedup_enabled() && !is_persistent(pool) )
@@ -1655,8 +1646,7 @@ free:
}
static int do_tmem_get(struct tmem_pool *pool, struct oid *oidp, uint32_t index,
- xen_pfn_t cmfn, pagesize_t tmem_offset,
- pagesize_t pfn_offset, pagesize_t len, tmem_cli_va_param_t clibuf)
+ xen_pfn_t cmfn, tmem_cli_va_param_t clibuf)
{
struct tmem_object_root *obj;
struct tmem_page_descriptor *pgp;
@@ -1688,12 +1678,10 @@ static int do_tmem_get(struct tmem_pool *pool, struct oid *oidp, uint32_t index,
rc = pcd_copy_to_client(cmfn, pgp);
else if ( pgp->size != 0 )
{
- rc = tmem_decompress_to_client(cmfn, pgp->cdata,
- pgp->size, clibuf);
+ rc = tmem_decompress_to_client(cmfn, pgp->cdata, pgp->size, clibuf);
}
else
- rc = tmem_copy_to_client(cmfn, pgp->pfp, tmem_offset,
- pfn_offset, len, clibuf);
+ rc = tmem_copy_to_client(cmfn, pgp->pfp, clibuf);
if ( rc <= 0 )
goto bad_copy;
@@ -2385,7 +2373,7 @@ static int tmemc_save_get_next_page(int cli_id, uint32_t pool_id,
h.index = pgp->index;
tmem_copy_to_client_buf(buf, &h, 1);
tmem_client_buf_add(buf, sizeof(h));
- ret = do_tmem_get(pool, &oid, pgp->index, 0, 0, 0, pagesize, buf);
+ ret = do_tmem_get(pool, &oid, pgp->index, 0, buf);
out:
tmem_spin_unlock(&pers_lists_spinlock);
@@ -2443,7 +2431,12 @@ static int tmemc_restore_put_page(int cli_id, uint32_t pool_id, struct oid *oidp
if ( pool == NULL )
return -1;
- return do_tmem_put(pool, oidp, index, 0, 0, 0, bufsize, buf);
+ if (bufsize != PAGE_SIZE) {
+ tmem_client_err("tmem: %s: invalid parameter bufsize(%d) != (%ld)\n",
+ __func__, bufsize, PAGE_SIZE);
+ return -EINVAL;
+ }
+ return do_tmem_put(pool, oidp, index, 0, buf);
}
static int tmemc_restore_flush_page(int cli_id, uint32_t pool_id, struct oid *oidp,
@@ -2648,14 +2641,14 @@ EXPORT long do_tmem_op(tmem_cli_op_t uops)
break;
case TMEM_PUT_PAGE:
tmem_ensure_avail_pages();
- rc = do_tmem_put(pool, oidp, op.u.gen.index, op.u.gen.cmfn, 0, 0,
- PAGE_SIZE, tmem_cli_buf_null);
+ rc = do_tmem_put(pool, oidp, op.u.gen.index, op.u.gen.cmfn,
+ tmem_cli_buf_null);
if (rc == 1) succ_put = 1;
else non_succ_put = 1;
break;
case TMEM_GET_PAGE:
rc = do_tmem_get(pool, oidp, op.u.gen.index, op.u.gen.cmfn,
- 0, 0, PAGE_SIZE, tmem_cli_buf_null);
+ tmem_cli_buf_null);
if (rc == 1) succ_get = 1;
else non_succ_get = 1;
break;
diff --git a/xen/common/tmem_xen.c b/xen/common/tmem_xen.c
index af67703..efc2259 100644
--- a/xen/common/tmem_xen.c
+++ b/xen/common/tmem_xen.c
@@ -100,25 +100,16 @@ static inline void cli_put_page(void *cli_va, struct page_info *cli_pfp,
#endif
EXPORT int tmem_copy_from_client(struct page_info *pfp,
- xen_pfn_t cmfn, pagesize_t tmem_offset,
- pagesize_t pfn_offset, pagesize_t len, tmem_cli_va_param_t clibuf)
+ xen_pfn_t cmfn, tmem_cli_va_param_t clibuf)
{
unsigned long tmem_mfn, cli_mfn = 0;
char *tmem_va, *cli_va = NULL;
struct page_info *cli_pfp = NULL;
int rc = 1;
- if ( tmem_offset > PAGE_SIZE || pfn_offset > PAGE_SIZE || len > PAGE_SIZE )
- return -EINVAL;
ASSERT(pfp != NULL);
tmem_mfn = page_to_mfn(pfp);
tmem_va = map_domain_page(tmem_mfn);
- if ( tmem_offset == 0 && pfn_offset == 0 && len == 0 )
- {
- memset(tmem_va, 0, PAGE_SIZE);
- unmap_domain_page(tmem_va);
- return 1;
- }
if ( guest_handle_is_null(clibuf) )
{
cli_va = cli_get_page(cmfn, &cli_mfn, &cli_pfp, 0);
@@ -129,21 +120,13 @@ EXPORT int tmem_copy_from_client(struct page_info *pfp,
}
}
smp_mb();
- if ( len == PAGE_SIZE && !tmem_offset && !pfn_offset && cli_va )
- memcpy(tmem_va, cli_va, PAGE_SIZE);
- else if ( (tmem_offset+len <= PAGE_SIZE) &&
- (pfn_offset+len <= PAGE_SIZE) )
+ if ( cli_va )
{
- if ( cli_va )
- memcpy(tmem_va + tmem_offset, cli_va + pfn_offset, len);
- else if ( copy_from_guest_offset(tmem_va + tmem_offset, clibuf,
- pfn_offset, len) )
- rc = -EFAULT;
+ memcpy(tmem_va, cli_va, PAGE_SIZE);
+ cli_put_page(cli_va, cli_pfp, cli_mfn, 0);
}
- else if ( len )
+ else
rc = -EINVAL;
- if ( cli_va )
- cli_put_page(cli_va, cli_pfp, cli_mfn, 0);
unmap_domain_page(tmem_va);
return rc;
}
@@ -181,7 +164,6 @@ EXPORT int tmem_compress_from_client(xen_pfn_t cmfn,
}
EXPORT int tmem_copy_to_client(xen_pfn_t cmfn, struct page_info *pfp,
- pagesize_t tmem_offset, pagesize_t pfn_offset, pagesize_t len,
tmem_cli_va_param_t clibuf)
{
unsigned long tmem_mfn, cli_mfn = 0;
@@ -189,8 +171,6 @@ EXPORT int tmem_copy_to_client(xen_pfn_t cmfn, struct page_info *pfp,
struct page_info *cli_pfp = NULL;
int rc = 1;
- if ( tmem_offset > PAGE_SIZE || pfn_offset > PAGE_SIZE || len > PAGE_SIZE )
- return -EINVAL;
ASSERT(pfp != NULL);
if ( guest_handle_is_null(clibuf) )
{
@@ -200,21 +180,14 @@ EXPORT int tmem_copy_to_client(xen_pfn_t cmfn, struct page_info *pfp,
}
tmem_mfn = page_to_mfn(pfp);
tmem_va = map_domain_page(tmem_mfn);
- if ( len == PAGE_SIZE && !tmem_offset && !pfn_offset && cli_va )
- memcpy(cli_va, tmem_va, PAGE_SIZE);
- else if ( (tmem_offset+len <= PAGE_SIZE) && (pfn_offset+len <= PAGE_SIZE) )
+ if ( cli_va )
{
- if ( cli_va )
- memcpy(cli_va + pfn_offset, tmem_va + tmem_offset, len);
- else if ( copy_to_guest_offset(clibuf, pfn_offset,
- tmem_va + tmem_offset, len) )
- rc = -EFAULT;
+ memcpy(cli_va, tmem_va, PAGE_SIZE);
+ cli_put_page(cli_va, cli_pfp, cli_mfn, 1);
}
- else if ( len )
+ else
rc = -EINVAL;
unmap_domain_page(tmem_va);
- if ( cli_va )
- cli_put_page(cli_va, cli_pfp, cli_mfn, 1);
smp_mb();
return rc;
}
diff --git a/xen/include/xen/tmem_xen.h b/xen/include/xen/tmem_xen.h
index a477960..d842374 100644
--- a/xen/include/xen/tmem_xen.h
+++ b/xen/include/xen/tmem_xen.h
@@ -387,11 +387,9 @@ int tmem_decompress_to_client(xen_pfn_t, void *, size_t,
int tmem_compress_from_client(xen_pfn_t, void **, size_t *,
tmem_cli_va_param_t);
-int tmem_copy_from_client(struct page_info *, xen_pfn_t, pagesize_t tmem_offset,
- pagesize_t pfn_offset, pagesize_t len, tmem_cli_va_param_t);
+int tmem_copy_from_client(struct page_info *, xen_pfn_t, tmem_cli_va_param_t);
-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);
+int tmem_copy_to_client(xen_pfn_t, struct page_info *, 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);
--
1.7.10.4
next prev parent reply other threads:[~2013-12-11 8:52 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-11 8:50 [PATCH v3 00/15] tmem: continue to cleanup tmem Bob Liu
2013-12-11 8:50 ` [PATCH v3 01/15] tmem: cleanup: drop unused sub command Bob Liu
2013-12-11 8:50 ` [PATCH v3 02/15] tmem: cleanup: drop some debug code Bob Liu
2013-12-11 8:50 ` [PATCH v3 03/15] tmem: cleanup: drop useless function 'tmem_copy_page' Bob Liu
2013-12-11 8:50 ` Bob Liu [this message]
2013-12-11 8:50 ` [PATCH v3 05/15] tmem: cleanup: reorg function do_tmem_put() Bob Liu
2013-12-11 8:50 ` [PATCH v3 06/15] tmem: drop unneeded is_ephemeral() and is_private() Bob Liu
2013-12-11 8:50 ` [PATCH v3 07/15] tmem: cleanup: rm useless EXPORT/FORWARD define Bob Liu
2013-12-11 8:50 ` [PATCH v3 08/15] tmem: cleanup: drop runtime statistics Bob Liu
2013-12-11 8:50 ` [PATCH v3 09/15] tmem: cleanup: drop tmem_lock_all Bob Liu
2013-12-11 10:45 ` Andrew Cooper
2013-12-11 13:11 ` Bob Liu
2013-12-11 22:01 ` Konrad Rzeszutek Wilk
2013-12-11 8:50 ` [PATCH v3 10/15] tmem: cleanup: refactor the alloc/free path Bob Liu
2013-12-11 8:50 ` [PATCH v3 11/15] tmem: cleanup: __tmem_alloc_page: drop unneed parameters Bob Liu
2013-12-11 8:50 ` [PATCH v3 12/15] tmem: cleanup: drop useless functions from head file Bob Liu
2013-12-11 8:50 ` [PATCH v3 13/15] tmem: refator function tmem_ensure_avail_pages() Bob Liu
2013-12-11 8:50 ` [PATCH v3 14/15] tmem: cleanup: rename tmem_relinquish_npages() Bob Liu
2013-12-11 8:50 ` [PATCH v3 15/15] tmem: cleanup: rm unused tmem_freeze_all() Bob 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=1386751844-32387-5-git-send-email-bob.liu@oracle.com \
--to=lliubbo@gmail.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.campbell@citrix.com \
--cc=james.harper@bendigoit.com.au \
--cc=xen-devel@lists.xenproject.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).