Blob Blame History Raw
commit 2f57a96ce27d8b121c2822de2a66c71b83bdad21
Author: Dave Anderson <anderson@redhat.com>
Date:   Tue Sep 4 14:29:45 2018 -0400

    Fix for the "files" command in Linux 4.17 and later kernels that
    contain commit b93b016313b3ba8003c3b8bb71f569af91f19fc7, titled
    "page cache: use xa_lock".  Without the patch, the "files -c" option
    fails with the message "files: -c option not supported or applicable
    on this architecture or kernel", and the "files -p &lt;inode>" option
    fails in a similar manner.
    (k-hagio@ab.jp.nec.com)

diff --git a/filesys.c b/filesys.c
index 47f5a24..32daa5a 100644
--- a/filesys.c
+++ b/filesys.c
@@ -2207,6 +2207,11 @@ dump_inode_page_cache_info(ulong inode)
 		RJUST|LONG_DEC,
 		MKSTR(nrpages)));
 
+	FREEBUF(inode_buf);
+
+	if (!nrpages)
+		return;
+
 	root_rnode = i_mapping + OFFSET(address_space_page_tree);
 	rtp.index = 0;
 	rtp.value = (void *)&dump_inode_page;
@@ -2217,7 +2222,6 @@ dump_inode_page_cache_info(ulong inode)
 		error(INFO, "page_tree count: %ld  nrpages: %ld\n",
 			count, nrpages);
 
-	FREEBUF(inode_buf);
 	return;
 }
 
@@ -2275,7 +2279,7 @@ cmd_files(void)
 			return;
 
 		case 'c':
-			if (VALID_MEMBER(address_space_page_tree) &&
+			if (VALID_MEMBER(address_space_nrpages) &&
 			    VALID_MEMBER(inode_i_mapping))
 				open_flags |= PRINT_NRPAGES;
 			else
diff --git a/memory.c b/memory.c
index 24fce5e..ea25047 100644
--- a/memory.c
+++ b/memory.c
@@ -485,6 +485,8 @@ vm_init(void)
 	MEMBER_OFFSET_INIT(block_device_bd_disk, "block_device", "bd_disk");
 	MEMBER_OFFSET_INIT(inode_i_mapping, "inode", "i_mapping");
 	MEMBER_OFFSET_INIT(address_space_page_tree, "address_space", "page_tree");
+	if (INVALID_MEMBER(address_space_page_tree))
+		MEMBER_OFFSET_INIT(address_space_page_tree, "address_space", "i_pages");
 	MEMBER_OFFSET_INIT(address_space_nrpages, "address_space", "nrpages");
 	if (INVALID_MEMBER(address_space_nrpages))
 		MEMBER_OFFSET_INIT(address_space_nrpages, "address_space", "__nrpages");