68 lines
2.3 KiB
Diff
68 lines
2.3 KiB
Diff
From 94a78764d80b6dc41ff2ae8a0e5f1b35c2fd8e78 Mon Sep 17 00:00:00 2001
|
|
From: Nir Soffer <nsoffer@redhat.com>
|
|
Date: Sat, 27 Feb 2021 05:36:38 +0200
|
|
Subject: [PATCH 4/6] copy: file-ops.c: Remove unneeded check
|
|
|
|
This function is called only from page_cache_evict(), which already
|
|
check that we could map the cached pages. Add an assert to document this
|
|
assumption.
|
|
|
|
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
|
|
---
|
|
copy/file-ops.c | 21 +++++++++++----------
|
|
1 file changed, 11 insertions(+), 10 deletions(-)
|
|
|
|
diff --git a/copy/file-ops.c b/copy/file-ops.c
|
|
index ea725a4..47ec768 100644
|
|
--- a/copy/file-ops.c
|
|
+++ b/copy/file-ops.c
|
|
@@ -102,7 +102,7 @@ page_size_init (void)
|
|
/* Load the page cache map for a particular file into
|
|
* rwf->cached_pages. Only used when reading files. This doesn't
|
|
* fail: if a system call fails then rwf->cached_pages.size will be
|
|
- * zero which is handled in page_was_cached.
|
|
+ * zero which is handled in page_cache_evict.
|
|
*/
|
|
static inline void
|
|
page_cache_map (struct rw_file *rwf)
|
|
@@ -126,19 +126,16 @@ page_cache_map (struct rw_file *rwf)
|
|
munmap (ptr, rwf->rw.size);
|
|
}
|
|
|
|
-/* Test if a single page of the file was cached before nbdcopy ran. */
|
|
+/* Test if a single page of the file was cached before nbdcopy ran.
|
|
+ * Valid only if we mapped the cached pages.
|
|
+ */
|
|
static inline bool
|
|
page_was_cached (struct rw_file *rwf, uint64_t offset)
|
|
{
|
|
uint64_t page = offset / page_size;
|
|
- if (page < rwf->cached_pages.size)
|
|
- return (rwf->cached_pages.ptr[page] & 1) != 0;
|
|
- else
|
|
- /* This path is taken if we didn't manage to map the input file
|
|
- * for any reason. In this case assume that pages were mapped so
|
|
- * we will not evict them: essentially fall back to doing nothing.
|
|
- */
|
|
- return true;
|
|
+ assert (page < rwf->cached_pages.size);
|
|
+
|
|
+ return (rwf->cached_pages.ptr[page] & 1) != 0;
|
|
}
|
|
|
|
/* Evict file contents from the page cache if they were not present in
|
|
@@ -150,6 +147,10 @@ page_cache_evict (struct rw_file *rwf, uint64_t orig_offset, size_t orig_len)
|
|
uint64_t offset, n;
|
|
size_t len;
|
|
|
|
+ /* If we didn't manage to map the input file for any reason, assume
|
|
+ * that pages were mapped so we will not evict them: essentially fall
|
|
+ * back to doing nothing.
|
|
+ */
|
|
if (rwf->cached_pages.size == 0) return;
|
|
|
|
/* Only bother with whole pages. */
|
|
--
|
|
2.29.0.rc2
|
|
|