page-xfer: page_server_get_pages: replace BUG_ONs with 'return -1'

Submitted by Mike Rapoport on Nov. 23, 2016, 12:28 p.m.

Details

Message ID 1479904115-14806-1-git-send-email-rppt@linux.vnet.ibm.com
State Superseded
Series "page-xfer: page_server_get_pages: replace BUG_ONs with 'return -1'"
Headers show

Commit Message

Mike Rapoport Nov. 23, 2016, 12:28 p.m.
Instead of crashing dump/page-server when a problem detected after the
page-pipe was split, print nice error messages and return error.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
 criu/page-xfer.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/page-xfer.c b/criu/page-xfer.c
index 041dd78..a286c96 100644
--- a/criu/page-xfer.c
+++ b/criu/page-xfer.c
@@ -627,6 +627,29 @@  static int page_server_add(int sk, struct page_server_iov *pi, u32 flags)
 	return 0;
 }
 
+static bool can_send_pages(struct page_pipe_buf *ppb, struct iovec *iov,
+			   struct page_server_iov *pi)
+{
+	if (!(ppb->flags & PPB_LAZY)) {
+		pr_err("Requested pages are not lazy\n");
+		return false;
+	}
+
+	if (iov->iov_len != pi->nr_pages * PAGE_SIZE) {
+		pr_err("IOV len %ld does not match requested %ld\n",
+		       iov->iov_len, pi->nr_pages * PAGE_SIZE);
+		return false;
+	}
+
+	if(pi->vaddr != encode_pointer(iov->iov_base)) {
+		pr_err("IOV start %p does not match requested addr %"PRIx64"\n",
+		       iov->iov_base, pi->vaddr);
+		return false;
+	}
+
+	return true;
+}
+
 static int page_server_get_pages(int sk, struct page_server_iov *pi)
 {
 	struct pstree_item *item;
@@ -651,9 +674,8 @@  static int page_server_get_pages(int sk, struct page_server_iov *pi)
 	ppb = list_first_entry(&pp->bufs, struct page_pipe_buf, l);
 	iov = &ppb->iov[0];
 
-	BUG_ON(!(ppb->flags & PPB_LAZY));
-	BUG_ON(iov->iov_len != pi->nr_pages * PAGE_SIZE);
-	BUG_ON(pi->vaddr != encode_pointer(iov->iov_base));
+	if (!can_send_pages(ppb, iov, pi))
+		return -1;
 
 	if (send_psi(sk, PS_IOV_ADD, pi->nr_pages, pi->vaddr, pi->dst_id))
 		return -1;