This commit adds check in datapath/Makefile to make sure that all public
functions in linux/compat/ are all rpl_ prefixed and exported, except
those in compat/build-aux/export-check-whitelist.

Signed-off-by: Alex Wang <al...@nicira.com>
---
 datapath/Makefile.am                               |   23 +++++++++++++++++++-
 datapath/README.md                                 |   14 ++++++++++++
 datapath/linux/Modules.mk                          |    1 +
 .../linux/compat/build-aux/export-check-whitelist  |    1 +
 4 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 datapath/linux/compat/build-aux/export-check-whitelist

diff --git a/datapath/Makefile.am b/datapath/Makefile.am
index eac9582..47afd10 100644
--- a/datapath/Makefile.am
+++ b/datapath/Makefile.am
@@ -28,4 +28,25 @@ print-build-modules:
           echo "Could not find any kernel module."; \
           exit 1; \
        fi
-       @echo "$(build_modules)" | tr '_' '-';
\ No newline at end of file
+       @echo "$(build_modules)" | tr '_' '-';
+
+COMPAT_CHECK_CMD := find $(top_srcdir)/datapath/linux/compat -name "*.h" \
+       -exec sed -n '/^[a-z][a-z]* \*\?[A-Za-z0-9_][A-Za-z0-9_]*([a-z]/p; 
/^struct [a-z0-9_][a-z0-9_]* \*\?[A-Za-z0-9_][A-Za-z0-9_]*([a-z]/p' {} \; | tr 
-d '*' | cut -d '(' -f1 | rev | cut -d ' ' -f1 | rev
+COMPAT_FUNCTIONS := $(shell $(COMPAT_CHECK_CMD))
+
+# Checks for exporting function symbols.
+check-export-public-functions:
+       @for fun_ in $(COMPAT_FUNCTIONS); do \
+          if ! grep -- $${fun_} 
$(top_srcdir)/datapath/linux/compat/build-aux/export-check-whitelist > 
/dev/null; then \
+             if [[ ! $${fun_} =~ ^rpl_* ]]; then \
+                echo "Should prefix $${fun_} with rpl_."; \
+                exit 1; \
+             fi; \
+             if ! grep -- $${fun_} $(top_srcdir)/datapath/linux/compat/*.c | 
grep -- EXPORT_SYMBOL > /dev/null; then \
+                echo "Should export $${fun_}."; \
+                exit 1; \
+             fi; \
+          fi; \
+       done
+
+all-local: check-export-public-functions
\ No newline at end of file
diff --git a/datapath/README.md b/datapath/README.md
index 9c03a2b..5adb531 100644
--- a/datapath/README.md
+++ b/datapath/README.md
@@ -246,3 +246,17 @@ The other rules for flow keys are much less subtle:
     composes it the same way.  This allows userspace to hash and
     compare entire flow keys that it may not be able to fully
     interpret.
+
+
+Coding rules
+============
+
+Compatibility
+-------------
+
+Please implement the headers and codes for compatibility with older kernel
+in linux/compat/ directory.  All public functions should be prefixed with
+rpl_ and be exported using EXPORT_SYMBOL macro.  For special case when it
+is not possible to follow this rule (e.g., the pskb_expand_head() function),
+the function name must be added to 
linux/compat/build-aux/export-check-whitelist,
+otherwise, the compilation will fail.
diff --git a/datapath/linux/Modules.mk b/datapath/linux/Modules.mk
index 875ac03..74ebc06 100644
--- a/datapath/linux/Modules.mk
+++ b/datapath/linux/Modules.mk
@@ -77,3 +77,4 @@ openvswitch_headers += \
        linux/compat/include/net/sock.h \
        linux/compat/include/net/vxlan.h \
        linux/compat/include/net/sctp/checksum.h
+EXTRA_DIST += linux/compat/build-aux/export-check-whitelist
diff --git a/datapath/linux/compat/build-aux/export-check-whitelist 
b/datapath/linux/compat/build-aux/export-check-whitelist
new file mode 100644
index 0000000..1178f46
--- /dev/null
+++ b/datapath/linux/compat/build-aux/export-check-whitelist
@@ -0,0 +1 @@
+pskb_expand_head
\ No newline at end of file
-- 
1.7.9.5

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to