You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.3 KiB

  1. diff --git a/datapath/datapath.h b/datapath/datapath.h
  2. index fdf35f0..02be8be 100644
  3. --- a/datapath/datapath.h
  4. +++ b/datapath/datapath.h
  5. @@ -86,10 +86,8 @@ struct datapath {
  6. /* Stats. */
  7. struct dp_stats_percpu __percpu *stats_percpu;
  8. -#ifdef CONFIG_NET_NS
  9. /* Network namespace ref. */
  10. - struct net *net;
  11. -#endif
  12. + possible_net_t net;
  13. u32 user_features;
  14. };
  15. @@ -154,12 +152,12 @@ int lockdep_ovsl_is_held(void);
  16. static inline struct net *ovs_dp_get_net(const struct datapath *dp)
  17. {
  18. - return read_pnet(&dp->net);
  19. + return ovs_compat_read_pnet(&dp->net);
  20. }
  21. static inline void ovs_dp_set_net(struct datapath *dp, struct net *net)
  22. {
  23. - write_pnet(&dp->net, net);
  24. + ovs_compat_write_pnet(&dp->net, net);
  25. }
  26. struct vport *ovs_lookup_vport(const struct datapath *dp, u16 port_no);
  27. diff --git a/datapath/linux/compat/include/net/net_namespace.h b/datapath/linux/compat/include/net/net_namespace.h
  28. index b7dbfe3..7763584 100644
  29. --- a/datapath/linux/compat/include/net/net_namespace.h
  30. +++ b/datapath/linux/compat/include/net/net_namespace.h
  31. @@ -51,4 +51,57 @@ static void rpl_unregister_pernet_gen_##TYPE(struct rpl_pernet_operations *rpl_p
  32. #define DEFINE_COMPAT_PNET_REG_FUNC(TYPE)
  33. #endif /* 2.6.33 */
  34. +/* In recent kernel versions (4.1) this type is defined ; for older versions we have to define it */
  35. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
  36. +#define ovs_compat_read_pnet read_pnet
  37. +#define ovs_compat_write_pnet write_pnet
  38. +
  39. +#if defined(CONFIG_NET_NS) && defined(NETNS_REFCNT_DEBUG)
  40. +static inline struct net *hold_net(struct net *net)
  41. +{
  42. + if (net)
  43. + atomic_inc(&net->use_count);
  44. + return net;
  45. +}
  46. +
  47. +static inline void release_net(struct net *net)
  48. +{
  49. + if (net)
  50. + atomic_dec(&net->use_count);
  51. +}
  52. +#else
  53. +static inline struct net *hold_net(struct net *net)
  54. +{
  55. + return net;
  56. +}
  57. +
  58. +static inline void release_net(struct net *net)
  59. +{
  60. +}
  61. +#endif
  62. +
  63. +#else /* lower than 4.1 */
  64. +typedef struct {
  65. +#ifdef CONFIG_NET_NS
  66. + struct net *net;
  67. +#endif
  68. +} possible_net_t;
  69. +
  70. +static inline void ovs_compat_write_pnet(possible_net_t *pnet, struct net *net)
  71. +{
  72. +#ifdef CONFIG_NET_NS
  73. + pnet->net = net;
  74. +#endif
  75. +}
  76. +
  77. +static inline struct net *ovs_compat_read_pnet(const possible_net_t *pnet)
  78. +{
  79. +#ifdef CONFIG_NET_NS
  80. + return pnet->net;
  81. +#else
  82. + return &init_net;
  83. +#endif
  84. +}
  85. +#endif /* 4.1.0 */
  86. +
  87. #endif /* net/net_namespace.h wrapper */