diff options
author | Oliver Hartkopp <socketcan@hartkopp.net> | 2017-04-25 02:19:41 -0400 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2017-04-25 03:04:29 -0400 |
commit | cb5635a3677679666e4e81ecbb209d32f13dedcd (patch) | |
tree | 2d5357aa8fbb22b3e8b0baba8c838b0234c402d1 | |
parent | f2e72f43e7686720ddc5112fab2f5f71f47dc5e6 (diff) |
can: complete initial namespace support
The statistics and its proc output was not implemented as per-net in the
initial network namespace support by Mario Kicherer (8e8cda6d737d).
This patch adds the missing per-net statistics for the CAN subsystem.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r-- | include/linux/can/core.h | 4 | ||||
-rw-r--r-- | include/net/netns/can.h | 5 | ||||
-rw-r--r-- | net/can/af_can.c | 71 | ||||
-rw-r--r-- | net/can/af_can.h | 5 | ||||
-rw-r--r-- | net/can/proc.c | 141 |
5 files changed, 121 insertions, 105 deletions
diff --git a/include/linux/can/core.h b/include/linux/can/core.h index 319a0da827b8..c9a17bb1221c 100644 --- a/include/linux/can/core.h +++ b/include/linux/can/core.h | |||
@@ -5,7 +5,7 @@ | |||
5 | * | 5 | * |
6 | * Authors: Oliver Hartkopp <oliver.hartkopp@volkswagen.de> | 6 | * Authors: Oliver Hartkopp <oliver.hartkopp@volkswagen.de> |
7 | * Urs Thuermann <urs.thuermann@volkswagen.de> | 7 | * Urs Thuermann <urs.thuermann@volkswagen.de> |
8 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research | 8 | * Copyright (c) 2002-2017 Volkswagen Group Electronic Research |
9 | * All rights reserved. | 9 | * All rights reserved. |
10 | * | 10 | * |
11 | */ | 11 | */ |
@@ -17,7 +17,7 @@ | |||
17 | #include <linux/skbuff.h> | 17 | #include <linux/skbuff.h> |
18 | #include <linux/netdevice.h> | 18 | #include <linux/netdevice.h> |
19 | 19 | ||
20 | #define CAN_VERSION "20120528" | 20 | #define CAN_VERSION "20170425" |
21 | 21 | ||
22 | /* increment this number each time you change some user-space interface */ | 22 | /* increment this number each time you change some user-space interface */ |
23 | #define CAN_ABI_VERSION "9" | 23 | #define CAN_ABI_VERSION "9" |
diff --git a/include/net/netns/can.h b/include/net/netns/can.h index e8beba772f1a..574157dbc43a 100644 --- a/include/net/netns/can.h +++ b/include/net/netns/can.h | |||
@@ -8,6 +8,8 @@ | |||
8 | #include <linux/spinlock.h> | 8 | #include <linux/spinlock.h> |
9 | 9 | ||
10 | struct dev_rcv_lists; | 10 | struct dev_rcv_lists; |
11 | struct s_stats; | ||
12 | struct s_pstats; | ||
11 | 13 | ||
12 | struct netns_can { | 14 | struct netns_can { |
13 | #if IS_ENABLED(CONFIG_PROC_FS) | 15 | #if IS_ENABLED(CONFIG_PROC_FS) |
@@ -26,6 +28,9 @@ struct netns_can { | |||
26 | /* receive filters subscribed for 'all' CAN devices */ | 28 | /* receive filters subscribed for 'all' CAN devices */ |
27 | struct dev_rcv_lists *can_rx_alldev_list; | 29 | struct dev_rcv_lists *can_rx_alldev_list; |
28 | spinlock_t can_rcvlists_lock; | 30 | spinlock_t can_rcvlists_lock; |
31 | struct timer_list can_stattimer;/* timer for statistics update */ | ||
32 | struct s_stats *can_stats; /* packet statistics */ | ||
33 | struct s_pstats *can_pstats; /* receive list statistics */ | ||
29 | }; | 34 | }; |
30 | 35 | ||
31 | #endif /* __NETNS_CAN_H__ */ | 36 | #endif /* __NETNS_CAN_H__ */ |
diff --git a/net/can/af_can.c b/net/can/af_can.c index 421b60fc42c3..b6406fe33c76 100644 --- a/net/can/af_can.c +++ b/net/can/af_can.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * af_can.c - Protocol family CAN core module | 2 | * af_can.c - Protocol family CAN core module |
3 | * (used by different CAN protocol modules) | 3 | * (used by different CAN protocol modules) |
4 | * | 4 | * |
5 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research | 5 | * Copyright (c) 2002-2017 Volkswagen Group Electronic Research |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
@@ -81,10 +81,6 @@ static struct kmem_cache *rcv_cache __read_mostly; | |||
81 | static const struct can_proto *proto_tab[CAN_NPROTO] __read_mostly; | 81 | static const struct can_proto *proto_tab[CAN_NPROTO] __read_mostly; |
82 | static DEFINE_MUTEX(proto_tab_lock); | 82 | static DEFINE_MUTEX(proto_tab_lock); |
83 | 83 | ||
84 | struct timer_list can_stattimer; /* timer for statistics update */ | ||
85 | struct s_stats can_stats; /* packet statistics */ | ||
86 | struct s_pstats can_pstats; /* receive list statistics */ | ||
87 | |||
88 | static atomic_t skbcounter = ATOMIC_INIT(0); | 84 | static atomic_t skbcounter = ATOMIC_INIT(0); |
89 | 85 | ||
90 | /* | 86 | /* |
@@ -221,6 +217,7 @@ int can_send(struct sk_buff *skb, int loop) | |||
221 | { | 217 | { |
222 | struct sk_buff *newskb = NULL; | 218 | struct sk_buff *newskb = NULL; |
223 | struct canfd_frame *cfd = (struct canfd_frame *)skb->data; | 219 | struct canfd_frame *cfd = (struct canfd_frame *)skb->data; |
220 | struct s_stats *can_stats = dev_net(skb->dev)->can.can_stats; | ||
224 | int err = -EINVAL; | 221 | int err = -EINVAL; |
225 | 222 | ||
226 | if (skb->len == CAN_MTU) { | 223 | if (skb->len == CAN_MTU) { |
@@ -309,8 +306,8 @@ int can_send(struct sk_buff *skb, int loop) | |||
309 | netif_rx_ni(newskb); | 306 | netif_rx_ni(newskb); |
310 | 307 | ||
311 | /* update statistics */ | 308 | /* update statistics */ |
312 | can_stats.tx_frames++; | 309 | can_stats->tx_frames++; |
313 | can_stats.tx_frames_delta++; | 310 | can_stats->tx_frames_delta++; |
314 | 311 | ||
315 | return 0; | 312 | return 0; |
316 | 313 | ||
@@ -468,6 +465,7 @@ int can_rx_register(struct net *net, struct net_device *dev, canid_t can_id, | |||
468 | struct receiver *r; | 465 | struct receiver *r; |
469 | struct hlist_head *rl; | 466 | struct hlist_head *rl; |
470 | struct dev_rcv_lists *d; | 467 | struct dev_rcv_lists *d; |
468 | struct s_pstats *can_pstats = net->can.can_pstats; | ||
471 | int err = 0; | 469 | int err = 0; |
472 | 470 | ||
473 | /* insert new receiver (dev,canid,mask) -> (func,data) */ | 471 | /* insert new receiver (dev,canid,mask) -> (func,data) */ |
@@ -499,9 +497,9 @@ int can_rx_register(struct net *net, struct net_device *dev, canid_t can_id, | |||
499 | hlist_add_head_rcu(&r->list, rl); | 497 | hlist_add_head_rcu(&r->list, rl); |
500 | d->entries++; | 498 | d->entries++; |
501 | 499 | ||
502 | can_pstats.rcv_entries++; | 500 | can_pstats->rcv_entries++; |
503 | if (can_pstats.rcv_entries_max < can_pstats.rcv_entries) | 501 | if (can_pstats->rcv_entries_max < can_pstats->rcv_entries) |
504 | can_pstats.rcv_entries_max = can_pstats.rcv_entries; | 502 | can_pstats->rcv_entries_max = can_pstats->rcv_entries; |
505 | } else { | 503 | } else { |
506 | kmem_cache_free(rcv_cache, r); | 504 | kmem_cache_free(rcv_cache, r); |
507 | err = -ENODEV; | 505 | err = -ENODEV; |
@@ -543,6 +541,7 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id, | |||
543 | { | 541 | { |
544 | struct receiver *r = NULL; | 542 | struct receiver *r = NULL; |
545 | struct hlist_head *rl; | 543 | struct hlist_head *rl; |
544 | struct s_pstats *can_pstats = net->can.can_pstats; | ||
546 | struct dev_rcv_lists *d; | 545 | struct dev_rcv_lists *d; |
547 | 546 | ||
548 | if (dev && dev->type != ARPHRD_CAN) | 547 | if (dev && dev->type != ARPHRD_CAN) |
@@ -589,8 +588,8 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id, | |||
589 | hlist_del_rcu(&r->list); | 588 | hlist_del_rcu(&r->list); |
590 | d->entries--; | 589 | d->entries--; |
591 | 590 | ||
592 | if (can_pstats.rcv_entries > 0) | 591 | if (can_pstats->rcv_entries > 0) |
593 | can_pstats.rcv_entries--; | 592 | can_pstats->rcv_entries--; |
594 | 593 | ||
595 | /* remove device structure requested by NETDEV_UNREGISTER */ | 594 | /* remove device structure requested by NETDEV_UNREGISTER */ |
596 | if (d->remove_on_zero_entries && !d->entries) { | 595 | if (d->remove_on_zero_entries && !d->entries) { |
@@ -684,11 +683,13 @@ static int can_rcv_filter(struct dev_rcv_lists *d, struct sk_buff *skb) | |||
684 | static void can_receive(struct sk_buff *skb, struct net_device *dev) | 683 | static void can_receive(struct sk_buff *skb, struct net_device *dev) |
685 | { | 684 | { |
686 | struct dev_rcv_lists *d; | 685 | struct dev_rcv_lists *d; |
686 | struct net *net = dev_net(dev); | ||
687 | struct s_stats *can_stats = net->can.can_stats; | ||
687 | int matches; | 688 | int matches; |
688 | 689 | ||
689 | /* update statistics */ | 690 | /* update statistics */ |
690 | can_stats.rx_frames++; | 691 | can_stats->rx_frames++; |
691 | can_stats.rx_frames_delta++; | 692 | can_stats->rx_frames_delta++; |
692 | 693 | ||
693 | /* create non-zero unique skb identifier together with *skb */ | 694 | /* create non-zero unique skb identifier together with *skb */ |
694 | while (!(can_skb_prv(skb)->skbcnt)) | 695 | while (!(can_skb_prv(skb)->skbcnt)) |
@@ -697,10 +698,10 @@ static void can_receive(struct sk_buff *skb, struct net_device *dev) | |||
697 | rcu_read_lock(); | 698 | rcu_read_lock(); |
698 | 699 | ||
699 | /* deliver the packet to sockets listening on all devices */ | 700 | /* deliver the packet to sockets listening on all devices */ |
700 | matches = can_rcv_filter(dev_net(dev)->can.can_rx_alldev_list, skb); | 701 | matches = can_rcv_filter(net->can.can_rx_alldev_list, skb); |
701 | 702 | ||
702 | /* find receive list for this device */ | 703 | /* find receive list for this device */ |
703 | d = find_dev_rcv_lists(dev_net(dev), dev); | 704 | d = find_dev_rcv_lists(net, dev); |
704 | if (d) | 705 | if (d) |
705 | matches += can_rcv_filter(d, skb); | 706 | matches += can_rcv_filter(d, skb); |
706 | 707 | ||
@@ -710,8 +711,8 @@ static void can_receive(struct sk_buff *skb, struct net_device *dev) | |||
710 | consume_skb(skb); | 711 | consume_skb(skb); |
711 | 712 | ||
712 | if (matches > 0) { | 713 | if (matches > 0) { |
713 | can_stats.matches++; | 714 | can_stats->matches++; |
714 | can_stats.matches_delta++; | 715 | can_stats->matches_delta++; |
715 | } | 716 | } |
716 | } | 717 | } |
717 | 718 | ||
@@ -876,8 +877,20 @@ static int can_pernet_init(struct net *net) | |||
876 | net->can.can_rx_alldev_list = | 877 | net->can.can_rx_alldev_list = |
877 | kzalloc(sizeof(struct dev_rcv_lists), GFP_KERNEL); | 878 | kzalloc(sizeof(struct dev_rcv_lists), GFP_KERNEL); |
878 | 879 | ||
879 | if (IS_ENABLED(CONFIG_PROC_FS)) | 880 | net->can.can_stats = kzalloc(sizeof(struct s_stats), GFP_KERNEL); |
881 | net->can.can_pstats = kzalloc(sizeof(struct s_pstats), GFP_KERNEL); | ||
882 | |||
883 | if (IS_ENABLED(CONFIG_PROC_FS)) { | ||
884 | /* the statistics are updated every second (timer triggered) */ | ||
885 | if (stats_timer) { | ||
886 | setup_timer(&net->can.can_stattimer, can_stat_update, | ||
887 | (unsigned long)net); | ||
888 | mod_timer(&net->can.can_stattimer, | ||
889 | round_jiffies(jiffies + HZ)); | ||
890 | } | ||
891 | net->can.can_stats->jiffies_init = jiffies; | ||
880 | can_init_proc(net); | 892 | can_init_proc(net); |
893 | } | ||
881 | 894 | ||
882 | return 0; | 895 | return 0; |
883 | } | 896 | } |
@@ -886,8 +899,11 @@ static void can_pernet_exit(struct net *net) | |||
886 | { | 899 | { |
887 | struct net_device *dev; | 900 | struct net_device *dev; |
888 | 901 | ||
889 | if (IS_ENABLED(CONFIG_PROC_FS)) | 902 | if (IS_ENABLED(CONFIG_PROC_FS)) { |
890 | can_remove_proc(net); | 903 | can_remove_proc(net); |
904 | if (stats_timer) | ||
905 | del_timer_sync(&net->can.can_stattimer); | ||
906 | } | ||
891 | 907 | ||
892 | /* remove created dev_rcv_lists from still registered CAN devices */ | 908 | /* remove created dev_rcv_lists from still registered CAN devices */ |
893 | rcu_read_lock(); | 909 | rcu_read_lock(); |
@@ -903,6 +919,8 @@ static void can_pernet_exit(struct net *net) | |||
903 | rcu_read_unlock(); | 919 | rcu_read_unlock(); |
904 | 920 | ||
905 | kfree(net->can.can_rx_alldev_list); | 921 | kfree(net->can.can_rx_alldev_list); |
922 | kfree(net->can.can_stats); | ||
923 | kfree(net->can.can_pstats); | ||
906 | } | 924 | } |
907 | 925 | ||
908 | /* | 926 | /* |
@@ -950,14 +968,6 @@ static __init int can_init(void) | |||
950 | if (!rcv_cache) | 968 | if (!rcv_cache) |
951 | return -ENOMEM; | 969 | return -ENOMEM; |
952 | 970 | ||
953 | if (IS_ENABLED(CONFIG_PROC_FS)) { | ||
954 | if (stats_timer) { | ||
955 | /* the statistics are updated every second (timer triggered) */ | ||
956 | setup_timer(&can_stattimer, can_stat_update, 0); | ||
957 | mod_timer(&can_stattimer, round_jiffies(jiffies + HZ)); | ||
958 | } | ||
959 | } | ||
960 | |||
961 | register_pernet_subsys(&can_pernet_ops); | 971 | register_pernet_subsys(&can_pernet_ops); |
962 | 972 | ||
963 | /* protocol register */ | 973 | /* protocol register */ |
@@ -971,11 +981,6 @@ static __init int can_init(void) | |||
971 | 981 | ||
972 | static __exit void can_exit(void) | 982 | static __exit void can_exit(void) |
973 | { | 983 | { |
974 | if (IS_ENABLED(CONFIG_PROC_FS)) { | ||
975 | if (stats_timer) | ||
976 | del_timer_sync(&can_stattimer); | ||
977 | } | ||
978 | |||
979 | /* protocol unregister */ | 984 | /* protocol unregister */ |
980 | dev_remove_pack(&canfd_packet); | 985 | dev_remove_pack(&canfd_packet); |
981 | dev_remove_pack(&can_packet); | 986 | dev_remove_pack(&can_packet); |
diff --git a/net/can/af_can.h b/net/can/af_can.h index 84a35e97c5e0..d0ef45bb2a72 100644 --- a/net/can/af_can.h +++ b/net/can/af_can.h | |||
@@ -115,9 +115,4 @@ void can_init_proc(struct net *net); | |||
115 | void can_remove_proc(struct net *net); | 115 | void can_remove_proc(struct net *net); |
116 | void can_stat_update(unsigned long data); | 116 | void can_stat_update(unsigned long data); |
117 | 117 | ||
118 | /* structures and variables from af_can.c needed in proc.c for reading */ | ||
119 | extern struct timer_list can_stattimer; /* timer for statistics update */ | ||
120 | extern struct s_stats can_stats; /* packet statistics */ | ||
121 | extern struct s_pstats can_pstats; /* receive list statistics */ | ||
122 | |||
123 | #endif /* AF_CAN_H */ | 118 | #endif /* AF_CAN_H */ |
diff --git a/net/can/proc.c b/net/can/proc.c index 9a8d54d57b22..83045f00c63c 100644 --- a/net/can/proc.c +++ b/net/can/proc.c | |||
@@ -75,21 +75,23 @@ static const char rx_list_name[][8] = { | |||
75 | * af_can statistics stuff | 75 | * af_can statistics stuff |
76 | */ | 76 | */ |
77 | 77 | ||
78 | static void can_init_stats(void) | 78 | static void can_init_stats(struct net *net) |
79 | { | 79 | { |
80 | struct s_stats *can_stats = net->can.can_stats; | ||
81 | struct s_pstats *can_pstats = net->can.can_pstats; | ||
80 | /* | 82 | /* |
81 | * This memset function is called from a timer context (when | 83 | * This memset function is called from a timer context (when |
82 | * can_stattimer is active which is the default) OR in a process | 84 | * can_stattimer is active which is the default) OR in a process |
83 | * context (reading the proc_fs when can_stattimer is disabled). | 85 | * context (reading the proc_fs when can_stattimer is disabled). |
84 | */ | 86 | */ |
85 | memset(&can_stats, 0, sizeof(can_stats)); | 87 | memset(can_stats, 0, sizeof(struct s_stats)); |
86 | can_stats.jiffies_init = jiffies; | 88 | can_stats->jiffies_init = jiffies; |
87 | 89 | ||
88 | can_pstats.stats_reset++; | 90 | can_pstats->stats_reset++; |
89 | 91 | ||
90 | if (user_reset) { | 92 | if (user_reset) { |
91 | user_reset = 0; | 93 | user_reset = 0; |
92 | can_pstats.user_reset++; | 94 | can_pstats->user_reset++; |
93 | } | 95 | } |
94 | } | 96 | } |
95 | 97 | ||
@@ -115,64 +117,66 @@ static unsigned long calc_rate(unsigned long oldjif, unsigned long newjif, | |||
115 | 117 | ||
116 | void can_stat_update(unsigned long data) | 118 | void can_stat_update(unsigned long data) |
117 | { | 119 | { |
120 | struct net *net = (struct net *)data; | ||
121 | struct s_stats *can_stats = net->can.can_stats; | ||
118 | unsigned long j = jiffies; /* snapshot */ | 122 | unsigned long j = jiffies; /* snapshot */ |
119 | 123 | ||
120 | /* restart counting in timer context on user request */ | 124 | /* restart counting in timer context on user request */ |
121 | if (user_reset) | 125 | if (user_reset) |
122 | can_init_stats(); | 126 | can_init_stats(net); |
123 | 127 | ||
124 | /* restart counting on jiffies overflow */ | 128 | /* restart counting on jiffies overflow */ |
125 | if (j < can_stats.jiffies_init) | 129 | if (j < can_stats->jiffies_init) |
126 | can_init_stats(); | 130 | can_init_stats(net); |
127 | 131 | ||
128 | /* prevent overflow in calc_rate() */ | 132 | /* prevent overflow in calc_rate() */ |
129 | if (can_stats.rx_frames > (ULONG_MAX / HZ)) | 133 | if (can_stats->rx_frames > (ULONG_MAX / HZ)) |
130 | can_init_stats(); | 134 | can_init_stats(net); |
131 | 135 | ||
132 | /* prevent overflow in calc_rate() */ | 136 | /* prevent overflow in calc_rate() */ |
133 | if (can_stats.tx_frames > (ULONG_MAX / HZ)) | 137 | if (can_stats->tx_frames > (ULONG_MAX / HZ)) |
134 | can_init_stats(); | 138 | can_init_stats(net); |
135 | 139 | ||
136 | /* matches overflow - very improbable */ | 140 | /* matches overflow - very improbable */ |
137 | if (can_stats.matches > (ULONG_MAX / 100)) | 141 | if (can_stats->matches > (ULONG_MAX / 100)) |
138 | can_init_stats(); | 142 | can_init_stats(net); |
139 | 143 | ||
140 | /* calc total values */ | 144 | /* calc total values */ |
141 | if (can_stats.rx_frames) | 145 | if (can_stats->rx_frames) |
142 | can_stats.total_rx_match_ratio = (can_stats.matches * 100) / | 146 | can_stats->total_rx_match_ratio = (can_stats->matches * 100) / |
143 | can_stats.rx_frames; | 147 | can_stats->rx_frames; |
144 | 148 | ||
145 | can_stats.total_tx_rate = calc_rate(can_stats.jiffies_init, j, | 149 | can_stats->total_tx_rate = calc_rate(can_stats->jiffies_init, j, |
146 | can_stats.tx_frames); | 150 | can_stats->tx_frames); |
147 | can_stats.total_rx_rate = calc_rate(can_stats.jiffies_init, j, | 151 | can_stats->total_rx_rate = calc_rate(can_stats->jiffies_init, j, |
148 | can_stats.rx_frames); | 152 | can_stats->rx_frames); |
149 | 153 | ||
150 | /* calc current values */ | 154 | /* calc current values */ |
151 | if (can_stats.rx_frames_delta) | 155 | if (can_stats->rx_frames_delta) |
152 | can_stats.current_rx_match_ratio = | 156 | can_stats->current_rx_match_ratio = |
153 | (can_stats.matches_delta * 100) / | 157 | (can_stats->matches_delta * 100) / |
154 | can_stats.rx_frames_delta; | 158 | can_stats->rx_frames_delta; |
155 | 159 | ||
156 | can_stats.current_tx_rate = calc_rate(0, HZ, can_stats.tx_frames_delta); | 160 | can_stats->current_tx_rate = calc_rate(0, HZ, can_stats->tx_frames_delta); |
157 | can_stats.current_rx_rate = calc_rate(0, HZ, can_stats.rx_frames_delta); | 161 | can_stats->current_rx_rate = calc_rate(0, HZ, can_stats->rx_frames_delta); |
158 | 162 | ||
159 | /* check / update maximum values */ | 163 | /* check / update maximum values */ |
160 | if (can_stats.max_tx_rate < can_stats.current_tx_rate) | 164 | if (can_stats->max_tx_rate < can_stats->current_tx_rate) |
161 | can_stats.max_tx_rate = can_stats.current_tx_rate; | 165 | can_stats->max_tx_rate = can_stats->current_tx_rate; |
162 | 166 | ||
163 | if (can_stats.max_rx_rate < can_stats.current_rx_rate) | 167 | if (can_stats->max_rx_rate < can_stats->current_rx_rate) |
164 | can_stats.max_rx_rate = can_stats.current_rx_rate; | 168 | can_stats->max_rx_rate = can_stats->current_rx_rate; |
165 | 169 | ||
166 | if (can_stats.max_rx_match_ratio < can_stats.current_rx_match_ratio) | 170 | if (can_stats->max_rx_match_ratio < can_stats->current_rx_match_ratio) |
167 | can_stats.max_rx_match_ratio = can_stats.current_rx_match_ratio; | 171 | can_stats->max_rx_match_ratio = can_stats->current_rx_match_ratio; |
168 | 172 | ||
169 | /* clear values for 'current rate' calculation */ | 173 | /* clear values for 'current rate' calculation */ |
170 | can_stats.tx_frames_delta = 0; | 174 | can_stats->tx_frames_delta = 0; |
171 | can_stats.rx_frames_delta = 0; | 175 | can_stats->rx_frames_delta = 0; |
172 | can_stats.matches_delta = 0; | 176 | can_stats->matches_delta = 0; |
173 | 177 | ||
174 | /* restart timer (one second) */ | 178 | /* restart timer (one second) */ |
175 | mod_timer(&can_stattimer, round_jiffies(jiffies + HZ)); | 179 | mod_timer(&net->can.can_stattimer, round_jiffies(jiffies + HZ)); |
176 | } | 180 | } |
177 | 181 | ||
178 | /* | 182 | /* |
@@ -206,57 +210,61 @@ static void can_print_recv_banner(struct seq_file *m) | |||
206 | 210 | ||
207 | static int can_stats_proc_show(struct seq_file *m, void *v) | 211 | static int can_stats_proc_show(struct seq_file *m, void *v) |
208 | { | 212 | { |
213 | struct net *net = m->private; | ||
214 | struct s_stats *can_stats = net->can.can_stats; | ||
215 | struct s_pstats *can_pstats = net->can.can_pstats; | ||
216 | |||
209 | seq_putc(m, '\n'); | 217 | seq_putc(m, '\n'); |
210 | seq_printf(m, " %8ld transmitted frames (TXF)\n", can_stats.tx_frames); | 218 | seq_printf(m, " %8ld transmitted frames (TXF)\n", can_stats->tx_frames); |
211 | seq_printf(m, " %8ld received frames (RXF)\n", can_stats.rx_frames); | 219 | seq_printf(m, " %8ld received frames (RXF)\n", can_stats->rx_frames); |
212 | seq_printf(m, " %8ld matched frames (RXMF)\n", can_stats.matches); | 220 | seq_printf(m, " %8ld matched frames (RXMF)\n", can_stats->matches); |
213 | 221 | ||
214 | seq_putc(m, '\n'); | 222 | seq_putc(m, '\n'); |
215 | 223 | ||
216 | if (can_stattimer.function == can_stat_update) { | 224 | if (net->can.can_stattimer.function == can_stat_update) { |
217 | seq_printf(m, " %8ld %% total match ratio (RXMR)\n", | 225 | seq_printf(m, " %8ld %% total match ratio (RXMR)\n", |
218 | can_stats.total_rx_match_ratio); | 226 | can_stats->total_rx_match_ratio); |
219 | 227 | ||
220 | seq_printf(m, " %8ld frames/s total tx rate (TXR)\n", | 228 | seq_printf(m, " %8ld frames/s total tx rate (TXR)\n", |
221 | can_stats.total_tx_rate); | 229 | can_stats->total_tx_rate); |
222 | seq_printf(m, " %8ld frames/s total rx rate (RXR)\n", | 230 | seq_printf(m, " %8ld frames/s total rx rate (RXR)\n", |
223 | can_stats.total_rx_rate); | 231 | can_stats->total_rx_rate); |
224 | 232 | ||
225 | seq_putc(m, '\n'); | 233 | seq_putc(m, '\n'); |
226 | 234 | ||
227 | seq_printf(m, " %8ld %% current match ratio (CRXMR)\n", | 235 | seq_printf(m, " %8ld %% current match ratio (CRXMR)\n", |
228 | can_stats.current_rx_match_ratio); | 236 | can_stats->current_rx_match_ratio); |
229 | 237 | ||
230 | seq_printf(m, " %8ld frames/s current tx rate (CTXR)\n", | 238 | seq_printf(m, " %8ld frames/s current tx rate (CTXR)\n", |
231 | can_stats.current_tx_rate); | 239 | can_stats->current_tx_rate); |
232 | seq_printf(m, " %8ld frames/s current rx rate (CRXR)\n", | 240 | seq_printf(m, " %8ld frames/s current rx rate (CRXR)\n", |
233 | can_stats.current_rx_rate); | 241 | can_stats->current_rx_rate); |
234 | 242 | ||
235 | seq_putc(m, '\n'); | 243 | seq_putc(m, '\n'); |
236 | 244 | ||
237 | seq_printf(m, " %8ld %% max match ratio (MRXMR)\n", | 245 | seq_printf(m, " %8ld %% max match ratio (MRXMR)\n", |
238 | can_stats.max_rx_match_ratio); | 246 | can_stats->max_rx_match_ratio); |
239 | 247 | ||
240 | seq_printf(m, " %8ld frames/s max tx rate (MTXR)\n", | 248 | seq_printf(m, " %8ld frames/s max tx rate (MTXR)\n", |
241 | can_stats.max_tx_rate); | 249 | can_stats->max_tx_rate); |
242 | seq_printf(m, " %8ld frames/s max rx rate (MRXR)\n", | 250 | seq_printf(m, " %8ld frames/s max rx rate (MRXR)\n", |
243 | can_stats.max_rx_rate); | 251 | can_stats->max_rx_rate); |
244 | 252 | ||
245 | seq_putc(m, '\n'); | 253 | seq_putc(m, '\n'); |
246 | } | 254 | } |
247 | 255 | ||
248 | seq_printf(m, " %8ld current receive list entries (CRCV)\n", | 256 | seq_printf(m, " %8ld current receive list entries (CRCV)\n", |
249 | can_pstats.rcv_entries); | 257 | can_pstats->rcv_entries); |
250 | seq_printf(m, " %8ld maximum receive list entries (MRCV)\n", | 258 | seq_printf(m, " %8ld maximum receive list entries (MRCV)\n", |
251 | can_pstats.rcv_entries_max); | 259 | can_pstats->rcv_entries_max); |
252 | 260 | ||
253 | if (can_pstats.stats_reset) | 261 | if (can_pstats->stats_reset) |
254 | seq_printf(m, "\n %8ld statistic resets (STR)\n", | 262 | seq_printf(m, "\n %8ld statistic resets (STR)\n", |
255 | can_pstats.stats_reset); | 263 | can_pstats->stats_reset); |
256 | 264 | ||
257 | if (can_pstats.user_reset) | 265 | if (can_pstats->user_reset) |
258 | seq_printf(m, " %8ld user statistic resets (USTR)\n", | 266 | seq_printf(m, " %8ld user statistic resets (USTR)\n", |
259 | can_pstats.user_reset); | 267 | can_pstats->user_reset); |
260 | 268 | ||
261 | seq_putc(m, '\n'); | 269 | seq_putc(m, '\n'); |
262 | return 0; | 270 | return 0; |
@@ -264,7 +272,7 @@ static int can_stats_proc_show(struct seq_file *m, void *v) | |||
264 | 272 | ||
265 | static int can_stats_proc_open(struct inode *inode, struct file *file) | 273 | static int can_stats_proc_open(struct inode *inode, struct file *file) |
266 | { | 274 | { |
267 | return single_open(file, can_stats_proc_show, NULL); | 275 | return single_open_net(inode, file, can_stats_proc_show); |
268 | } | 276 | } |
269 | 277 | ||
270 | static const struct file_operations can_stats_proc_fops = { | 278 | static const struct file_operations can_stats_proc_fops = { |
@@ -277,25 +285,28 @@ static const struct file_operations can_stats_proc_fops = { | |||
277 | 285 | ||
278 | static int can_reset_stats_proc_show(struct seq_file *m, void *v) | 286 | static int can_reset_stats_proc_show(struct seq_file *m, void *v) |
279 | { | 287 | { |
288 | struct net *net = m->private; | ||
289 | struct s_pstats *can_pstats = net->can.can_pstats; | ||
290 | struct s_stats *can_stats = net->can.can_stats; | ||
291 | |||
280 | user_reset = 1; | 292 | user_reset = 1; |
281 | 293 | ||
282 | if (can_stattimer.function == can_stat_update) { | 294 | if (net->can.can_stattimer.function == can_stat_update) { |
283 | seq_printf(m, "Scheduled statistic reset #%ld.\n", | 295 | seq_printf(m, "Scheduled statistic reset #%ld.\n", |
284 | can_pstats.stats_reset + 1); | 296 | can_pstats->stats_reset + 1); |
285 | |||
286 | } else { | 297 | } else { |
287 | if (can_stats.jiffies_init != jiffies) | 298 | if (can_stats->jiffies_init != jiffies) |
288 | can_init_stats(); | 299 | can_init_stats(net); |
289 | 300 | ||
290 | seq_printf(m, "Performed statistic reset #%ld.\n", | 301 | seq_printf(m, "Performed statistic reset #%ld.\n", |
291 | can_pstats.stats_reset); | 302 | can_pstats->stats_reset); |
292 | } | 303 | } |
293 | return 0; | 304 | return 0; |
294 | } | 305 | } |
295 | 306 | ||
296 | static int can_reset_stats_proc_open(struct inode *inode, struct file *file) | 307 | static int can_reset_stats_proc_open(struct inode *inode, struct file *file) |
297 | { | 308 | { |
298 | return single_open(file, can_reset_stats_proc_show, NULL); | 309 | return single_open_net(inode, file, can_reset_stats_proc_show); |
299 | } | 310 | } |
300 | 311 | ||
301 | static const struct file_operations can_reset_stats_proc_fops = { | 312 | static const struct file_operations can_reset_stats_proc_fops = { |
@@ -314,7 +325,7 @@ static int can_version_proc_show(struct seq_file *m, void *v) | |||
314 | 325 | ||
315 | static int can_version_proc_open(struct inode *inode, struct file *file) | 326 | static int can_version_proc_open(struct inode *inode, struct file *file) |
316 | { | 327 | { |
317 | return single_open(file, can_version_proc_show, NULL); | 328 | return single_open_net(inode, file, can_version_proc_show); |
318 | } | 329 | } |
319 | 330 | ||
320 | static const struct file_operations can_version_proc_fops = { | 331 | static const struct file_operations can_version_proc_fops = { |