[CRIU] [RFC PATCH v2 15/23] lazy-pages: introduce split_iov

Mike Rapoport rppt at linux.vnet.ibm.com
Mon Feb 6 03:44:08 PST 2017


Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
 criu/uffd.c | 37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/criu/uffd.c b/criu/uffd.c
index 9633061..32a9ab5 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -327,6 +327,30 @@ static struct lazy_iov *find_lazy_iov(struct lazy_pages_info *lpi,
 	return NULL;
 }
 
+static int split_iov(struct lazy_iov *iov, unsigned long addr, bool new_below)
+{
+	struct lazy_iov *new;
+
+	new = xzalloc(sizeof(*new));
+	if (!new)
+		return -1;
+
+	if (new_below) {
+		new->base = iov->base;
+		new->len = addr - iov->base;
+		iov->base = addr;
+		iov->len -= new->len;
+		list_add_tail(&new->l, &iov->l);
+	} else {
+		new->base = addr;
+		new->len = iov->len - (addr - iov->base);
+		iov->len -= new->len;
+		list_add(&new->l, &iov->l);
+	}
+
+	return 0;
+}
+
 /*
  * Purge range (addr, addr + len) from lazy_iovs. The range may
  * cover several continuous IOVs.
@@ -363,18 +387,9 @@ static int drop_lazy_iovs(struct lazy_pages_info *lpi, unsigned long addr,
 				iov->base += len;
 				iov->len -= len;
 			} else {
-				struct lazy_iov *new_iov;
-
-				iov->len -= (end - addr);
-
-				new_iov = xzalloc(sizeof(*new_iov));
-				if (!new_iov)
+				if (split_iov(iov, addr + len, false))
 					return -1;
-
-				new_iov->base = addr + len;
-				new_iov->len = end - (addr + len);
-
-				list_add(&new_iov->l, &iov->l);
+				iov->len -= len;
 			}
 			break;
 		}
-- 
1.9.1



More information about the CRIU mailing list