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

Signed-off-by: Alex Wang <al...@nicira.com>
---
PATCH->V2:
- Add check for EXPORT_SYMBOL_GPL().  The exported function must have
  rpl_ or ovs_ as prefix.
---
 datapath/Makefile.am                               |   31 +++++++++++++++++++-
 datapath/README.md                                 |   16 ++++++++++
 datapath/linux/Modules.mk                          |    1 +
 .../linux/compat/build-aux/export-check-whitelist  |    1 +
 4 files changed, 48 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..68a1188 100644
--- a/datapath/Makefile.am
+++ b/datapath/Makefile.am
@@ -28,4 +28,33 @@ 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_GET_FUNCTIONS := 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_GET_EXPORTS := find $(top_srcdir)/datapath/linux/compat -name "*.c" \
+       -exec sed -n 's/^EXPORT_SYMBOL_GPL(\([a-z_][a-z_]*\));$$/\1/p' {} \;
+COMPAT_FUNCTIONS := $(shell $(COMPAT_GET_FUNCTIONS))
+COMPAT_EXPORTS := $(shell $(COMPAT_GET_EXPORTS))
+
+# Checks that all public functions are 'rpl_' or 'ovs_' prefixed.
+# Checks that all EXPORT_SYMBOL_GPL() export 'rpl_' or 'ovs_' prefixed 
functions.
+check-export-symbol:
+       @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_* ]] \
+                && [[ ! $${fun_} =~ ^ovs_* ]]; then \
+                echo "Should prefix $${fun_} with rpl_ or ovs_."; \
+                exit 1; \
+             fi; \
+          fi; \
+       done
+       @for fun_ in $(COMPAT_EXPORTS); do \
+          if [[ ! $${fun_} =~ ^rpl_* ]] \
+             && [[ ! $${fun_} =~ ^ovs_* ]]; then \
+             echo "Should prefix $${fun_} with rpl_ or ovs_."; \
+             exit 1; \
+          fi; \
+       done
+
+all-local: check-export-symbol
\ No newline at end of file
diff --git a/datapath/README.md b/datapath/README.md
index 9c03a2b..1a4d8e1 100644
--- a/datapath/README.md
+++ b/datapath/README.md
@@ -246,3 +246,19 @@ 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 exported using
+EXPORT_SYMBOL macro.  Public function replacing the same-named kernel
+function should be prefixed with 'rpl_'.  Otherwise, the function should be
+prefixed with 'ovs_'.  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 check 'check-export-symbol' 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