Subject: [PATCH 0022/2944] alinux: fs/writeback: wrap cgroup writeback v1 logic

From: Joseph Qi <[email-masked]>
Date: Wed, 22 May 2019 14:46:05 +0800

Wrap cgroup writeback v1 logic to prevent build errors without
CONFIG_CGROUPS or CONFIG_CGROUP_WRITEBACK.

Reported-by: kbuild test robot <[email-masked]>
Cc: Jiufei Xue <[email-masked]>
Signed-off-by: Joseph Qi <[email-masked]>
Acked-by: Caspar Zhang <[email-masked]>
---
 include/linux/backing-dev.h      | 2 ++
 include/trace/events/writeback.h | 2 ++
 mm/memcontrol.c                  | 8 +++++++-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
index 09ab067..b17ac83 100644
--- a/include/linux/backing-dev.h
+++ b/include/linux/backing-dev.h
@@ -481,6 +481,7 @@ static inline int inode_congested(struct inode *inode, int cong_bits)
 	return wb_congested(&inode_to_bdi(inode)->wb, cong_bits);
 }
 
+#ifdef CONFIG_CGROUPS
 static inline void insert_memcg_blkcg_link(struct cgroup_subsys *ss,
 					   struct list_head *tmp_links,
 					   struct css_set *cset)
@@ -500,6 +501,7 @@ static inline void delete_memcg_blkcg_link(struct cgroup_subsys *ss,
 					   struct cgroup_subsys_state *css)
 {
 }
+#endif
 
 #endif	/* CONFIG_CGROUP_WRITEBACK */
 
diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
index 6fdf7eb..100715d 100644
--- a/include/trace/events/writeback.h
+++ b/include/trace/events/writeback.h
@@ -303,6 +303,7 @@ static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *w
 	)
 );
 
+#ifdef CONFIG_CGROUP_WRITEBACK
 TRACE_EVENT(insert_memcg_blkcg_link,
 	TP_PROTO(struct cgroup_subsys_state *memcg_css,
 		 struct cgroup_subsys_state *blkcg_css,
@@ -323,6 +324,7 @@ static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *w
 		  __entry->memcg_ino, __entry->blkcg_ino, __entry->old_blkcg_ino
 	)
 );
+#endif
 
 DECLARE_EVENT_CLASS(wbc_class,
 	TP_PROTO(struct writeback_control *wbc, struct backing_dev_info *bdi),
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4626678..ea696e8 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -468,8 +468,12 @@ struct cgroup_subsys_state *mem_cgroup_css_from_page(struct page *page)
 
 	memcg = page->mem_cgroup;
 
+#ifdef CONFIG_CGROUP_WRITEBACK
 	if (!memcg ||
-	   (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgwb_v1))
+	    (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgwb_v1))
+#else
+	if (!memcg || !cgroup_subsys_on_dfl(memory_cgrp_subsys))
+#endif
 		memcg = root_mem_cgroup;
 
 	return &memcg->css;
@@ -6408,6 +6412,7 @@ static int __init cgroup_memory(char *s)
 }
 __setup("cgroup.memory=", cgroup_memory);
 
+#ifdef CONFIG_CGROUP_WRITEBACK
 bool cgwb_v1 = false;
 
 static int __init enable_cgroup_writeback_v1(char *s)
@@ -6417,6 +6422,7 @@ static int __init enable_cgroup_writeback_v1(char *s)
 	return 0;
 }
 __setup("cgwb_v1", enable_cgroup_writeback_v1);
+#endif
 
 /*
  * subsys_initcall() for memory controller.
-- 
1.8.3.1