-
Notifications
You must be signed in to change notification settings - Fork 4
/
failover-for-linux-5.0-rc1.patch
593 lines (550 loc) · 21 KB
/
failover-for-linux-5.0-rc1.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
From 2247488626283177dd90b01482f3bd6b02ee1372 Mon Sep 17 00:00:00 2001
From: Dongli Zhang <[email protected]>
Date: Thu, 10 Jan 2019 06:00:51 +0800
Subject: [PATCH 1/1] failover for linux-5.0-rc1
Signed-off-by: Dongli Zhang <[email protected]>
---
drivers/net/net_failover.c | 140 +++++++++++++++++++++++++++++++++++++++++++++
include/linux/netdevice.h | 24 ++++++++
include/net/failover.h | 28 +++++++++
net/core/dev.c | 3 +
net/core/ethtool.c | 3 +
net/core/failover.c | 44 ++++++++++++++
net/ethernet/eth.c | 3 +
7 files changed, 245 insertions(+)
diff --git a/drivers/net/net_failover.c b/drivers/net/net_failover.c
index ed1166a..6f07a24 100644
--- a/drivers/net/net_failover.c
+++ b/drivers/net/net_failover.c
@@ -27,11 +27,40 @@
#include <uapi/linux/if_arp.h>
#include <net/net_failover.h>
+/*
+ *
+ * MAC address of Virtual Function changes unexpectedly
+ * ----------------------------------------------------
+ * If a Virtual Function's MAC address is not assigned in the host, then the VF
+ * (virtual function) driver will use a random MAC address. This random MAC
+ * address may change each time the VF driver is reloaded. You can assign a static
+ * MAC address in the host machine. This static MAC address will survive
+ * a VF driver reload.
+ */
+
+/*
+ * called by:
+ * - drivers/net/net_failover.c|58| <<net_failover_open>> if ((primary_dev && net_failover_xmit_ready(primary_dev)) ||
+ * - drivers/net/net_failover.c|59| <<net_failover_open>> (standby_dev && net_failover_xmit_ready(standby_dev))) {
+ * - drivers/net/net_failover.c|113| <<net_failover_start_xmit>> if (!xmit_dev || !net_failover_xmit_ready(xmit_dev)) {
+ * - drivers/net/net_failover.c|115| <<net_failover_start_xmit>> if (!xmit_dev || !net_failover_xmit_ready(xmit_dev))
+ * - drivers/net/net_failover.c|370| <<nfo_ethtool_get_link_ksettings>> if (!slave_dev || !net_failover_xmit_ready(slave_dev)) {
+ * - drivers/net/net_failover.c|372| <<nfo_ethtool_get_link_ksettings>> if (!slave_dev || !net_failover_xmit_ready(slave_dev)) {
+ * - drivers/net/net_failover.c|718| <<net_failover_slave_link_change>> if ((primary_dev && net_failover_xmit_ready(primary_dev)) ||
+ * - drivers/net/net_failover.c|719| <<net_failover_slave_link_change>> (standby_dev && net_failover_xmit_ready(standby_dev))) {
+ *
+ * 返回netif_running(dev) && netif_carrier_ok(dev)
+ */
static bool net_failover_xmit_ready(struct net_device *dev)
{
return netif_running(dev) && netif_carrier_ok(dev);
}
+/*
+ * struct net_device_ops failover_dev_ops.ndo_open = net_failover_open()
+ *
+ * 对net_failover_info->primary_dev和net_failover_info->standby_dev分别调用open
+ */
static int net_failover_open(struct net_device *dev)
{
struct net_failover_info *nfo_info = netdev_priv(dev);
@@ -67,6 +96,9 @@ static int net_failover_open(struct net_device *dev)
return err;
}
+/*
+ * struct net_device_ops failover_dev_ops.ndo_stop = net_failover_close()
+ */
static int net_failover_close(struct net_device *dev)
{
struct net_failover_info *nfo_info = netdev_priv(dev);
@@ -85,6 +117,10 @@ static int net_failover_close(struct net_device *dev)
return 0;
}
+/*
+ * called by:
+ * - drivers/net/net_failover.c|129| <<net_failover_start_xmit>> return net_failover_drop_xmit(skb, dev);
+ */
static netdev_tx_t net_failover_drop_xmit(struct sk_buff *skb,
struct net_device *dev)
{
@@ -93,26 +129,46 @@ static netdev_tx_t net_failover_drop_xmit(struct sk_buff *skb,
return NETDEV_TX_OK;
}
+/*
+ * struct net_device_ops failover_dev_ops.ndo_start_xmit = net_failover_start_xmit()
+ */
static netdev_tx_t net_failover_start_xmit(struct sk_buff *skb,
struct net_device *dev)
{
+ /* 在net_failover_create()分配的 */
struct net_failover_info *nfo_info = netdev_priv(dev);
struct net_device *xmit_dev;
/* Try xmit via primary netdev followed by standby netdev */
xmit_dev = rcu_dereference_bh(nfo_info->primary_dev);
+ /*
+ * net_failover_xmit_ready():
+ * 返回netif_running(dev) && netif_carrier_ok(dev)
+ */
if (!xmit_dev || !net_failover_xmit_ready(xmit_dev)) {
xmit_dev = rcu_dereference_bh(nfo_info->standby_dev);
+ /*
+ * net_failover_xmit_ready():
+ * 返回netif_running(dev) && netif_carrier_ok(dev)
+ */
if (!xmit_dev || !net_failover_xmit_ready(xmit_dev))
return net_failover_drop_xmit(skb, dev);
}
+ /*
+ * 上面先尝试net_failover_info->primary_dev
+ * 再尝试net_failover_info->standby_dev
+ */
+
skb->dev = xmit_dev;
skb->queue_mapping = qdisc_skb_cb(skb)->slave_dev_queue_mapping;
return dev_queue_xmit(skb);
}
+/*
+ * struct net_device_ops failover_dev_ops.ndo_select_queue = net_failover_select_queue()
+ */
static u16 net_failover_select_queue(struct net_device *dev,
struct sk_buff *skb,
struct net_device *sb_dev,
@@ -180,6 +236,9 @@ static void net_failover_fold_stats(struct rtnl_link_stats64 *_res,
}
}
+/*
+ * struct net_device_ops failover_dev_ops.ndo_get_stats64 = net_failover_get_stats()
+ */
static void net_failover_get_stats(struct net_device *dev,
struct rtnl_link_stats64 *stats)
{
@@ -213,6 +272,9 @@ static void net_failover_get_stats(struct net_device *dev,
spin_unlock(&nfo_info->stats_lock);
}
+/*
+ * struct net_device_ops failover_dev_ops.ndo_change_mtu = net_failover_change_mtu()
+ */
static int net_failover_change_mtu(struct net_device *dev, int new_mtu)
{
struct net_failover_info *nfo_info = netdev_priv(dev);
@@ -241,6 +303,9 @@ static int net_failover_change_mtu(struct net_device *dev, int new_mtu)
return 0;
}
+/*
+ * struct net_device_ops failover_dev_ops.ndo_set_rx_mode = net_failover_set_rx_mode()
+ */
static void net_failover_set_rx_mode(struct net_device *dev)
{
struct net_failover_info *nfo_info = netdev_priv(dev);
@@ -263,6 +328,9 @@ static void net_failover_set_rx_mode(struct net_device *dev)
rcu_read_unlock();
}
+/*
+ * struct net_device_ops failover_dev_ops.ndo_vlan_rx_add_vid = net_failover_vlan_rx_add_vid()
+ */
static int net_failover_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
u16 vid)
{
@@ -288,6 +356,9 @@ static int net_failover_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
return ret;
}
+/*
+ * struct net_device_ops failover_dev_ops.ndo_vlan_rx_kill_vid = net_failover_vlan_rx_kill_vid()
+ */
static int net_failover_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
u16 vid)
{
@@ -305,6 +376,10 @@ static int net_failover_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
return 0;
}
+/*
+ * used by:
+ * - drivers/net/net_failover.c|800| <<net_failover_create>> failover_dev->netdev_ops = &failover_dev_ops;
+ */
static const struct net_device_ops failover_dev_ops = {
.ndo_open = net_failover_open,
.ndo_stop = net_failover_close,
@@ -322,6 +397,9 @@ static const struct net_device_ops failover_dev_ops = {
#define FAILOVER_NAME "net_failover"
#define FAILOVER_VERSION "0.1"
+/*
+ * struct ethtool_ops failover_ethtool_ops.get_drvinfo = nfo_ethtool_get_drvinfo()
+ */
static void nfo_ethtool_get_drvinfo(struct net_device *dev,
struct ethtool_drvinfo *drvinfo)
{
@@ -329,6 +407,9 @@ static void nfo_ethtool_get_drvinfo(struct net_device *dev,
strlcpy(drvinfo->version, FAILOVER_VERSION, sizeof(drvinfo->version));
}
+/*
+ * struct ethtool_ops failover_ethtool_ops.get_link_ksettings = nfo_ethtool_get_link_ksettings()
+ */
static int nfo_ethtool_get_link_ksettings(struct net_device *dev,
struct ethtool_link_ksettings *cmd)
{
@@ -360,6 +441,12 @@ static const struct ethtool_ops failover_ethtool_ops = {
* Change the associated network device from lower dev to failover dev.
* note: already called with rcu_read_lock
*/
+/*
+ * used by:
+ * - net/core/failover.c|66| <<failover_slave_register>> err = netdev_rx_handler_register(slave_dev, fops->slave_handle_frame,
+ *
+ * struct failover_ops net_failover_ops.slave_handle_frame = net_failover_handle_frame()
+ */
static rx_handler_result_t net_failover_handle_frame(struct sk_buff **pskb)
{
struct sk_buff *skb = *pskb;
@@ -460,6 +547,12 @@ static void net_failover_lower_state_changed(struct net_device *slave_dev,
netdev_lower_state_changed(slave_dev, &info);
}
+/*
+ * called by:
+ * - net/core/failover.c|63| <<failover_slave_register>> fops->slave_pre_register(slave_dev, failover_dev))
+ *
+ * struct failover_ops net_failover_ops.slave_pre_register = net_failover_slave_pre_register()
+ */
static int net_failover_slave_pre_register(struct net_device *slave_dev,
struct net_device *failover_dev)
{
@@ -496,6 +589,12 @@ static int net_failover_slave_pre_register(struct net_device *slave_dev,
return 0;
}
+/*
+ * called by:
+ * - net/core/failover.c|86| <<failover_slave_register>> !fops->slave_register(slave_dev, failover_dev))
+ *
+ * struct failover_ops net_failover_ops.slave_register = net_failover_slave_register()
+ */
static int net_failover_slave_register(struct net_device *slave_dev,
struct net_device *failover_dev)
{
@@ -575,6 +674,12 @@ static int net_failover_slave_register(struct net_device *slave_dev,
return err;
}
+/*
+ * called by:
+ * - net/core/failover.c|119| <<failover_slave_unregister>> fops->slave_pre_unregister(slave_dev, failover_dev))
+ *
+ * struct failover_ops net_failover_ops.slave_pre_unregister = net_failover_slave_pre_unregister()
+ */
static int net_failover_slave_pre_unregister(struct net_device *slave_dev,
struct net_device *failover_dev)
{
@@ -591,6 +696,12 @@ static int net_failover_slave_pre_unregister(struct net_device *slave_dev,
return 0;
}
+/*
+ * called by:
+ * - net/core/failover.c|127| <<failover_slave_unregister>> !fops->slave_unregister(slave_dev, failover_dev))
+ *
+ * struct failover_ops net_failover_ops.slave_unregister = net_failover_slave_unregister()
+ */
static int net_failover_slave_unregister(struct net_device *slave_dev,
struct net_device *failover_dev)
{
@@ -634,6 +745,12 @@ static int net_failover_slave_unregister(struct net_device *slave_dev,
return 0;
}
+/*
+ * called by:
+ * - net/core/failover.c|153| <<failover_slave_link_change>> !fops->slave_link_change(slave_dev, failover_dev))
+ *
+ * struct failover_ops net_failover_ops.slave_link_change = net_failover_slave_link_change()
+ */
static int net_failover_slave_link_change(struct net_device *slave_dev,
struct net_device *failover_dev)
{
@@ -663,6 +780,12 @@ static int net_failover_slave_link_change(struct net_device *slave_dev,
return 0;
}
+/*
+ * called by:
+ * - net/core/failover.c|178| <<failover_slave_name_change>> !fops->slave_name_change(slave_dev, failover_dev))
+ *
+ * struct failover_ops net_failover_ops.slave_name_change = net_failover_slave_name_change()
+ */
static int net_failover_slave_name_change(struct net_device *slave_dev,
struct net_device *failover_dev)
{
@@ -685,6 +808,10 @@ static int net_failover_slave_name_change(struct net_device *slave_dev,
return 0;
}
+/*
+ * used by:
+ * - drivers/net/net_failover.c|808| <<net_failover_create>> failover = failover_register(failover_dev, &net_failover_ops);
+ */
static struct failover_ops net_failover_ops = {
.slave_pre_register = net_failover_slave_pre_register,
.slave_register = net_failover_slave_register,
@@ -708,8 +835,13 @@ static struct failover_ops net_failover_ops = {
*
* Return: pointer to failover instance
*/
+/*
+ * called by:
+ * - drivers/net/virtio_net.c|3078| <<virtnet_probe>> vi->failover = net_failover_create(vi->dev);
+ */
struct failover *net_failover_create(struct net_device *standby_dev)
{
+ /* 根据目前的情况, standby_dev就是virtio_net的net_device */
struct device *dev = standby_dev->dev.parent;
struct net_device *failover_dev;
struct failover *failover;
@@ -724,7 +856,15 @@ struct failover *net_failover_create(struct net_device *standby_dev)
return ERR_PTR(-ENOMEM);
}
+ /*
+ * failover_dev: vf的
+ * standby_dev : virtio的
+ */
dev_net_set(failover_dev, dev_net(standby_dev));
+ /*
+ * #define SET_NETDEV_DEV(net, pdev) ((net)->dev.parent = (pdev))
+ * 设置failover_dev->>dev.parent = dev
+ */
SET_NETDEV_DEV(failover_dev, dev);
failover_dev->netdev_ops = &failover_dev_ops;
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 1377d08..fd30457 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1542,7 +1542,20 @@ enum netdev_priv_flags {
#define IFF_RXFH_CONFIGURED IFF_RXFH_CONFIGURED
#define IFF_MACSEC IFF_MACSEC
#define IFF_NO_RX_HANDLER IFF_NO_RX_HANDLER
+/*
+ * used by:
+ * - include/linux/netdevice.h|4609| <<netif_is_failover>> return dev->priv_flags & IFF_FAILOVER;
+ * - net/core/failover.c|274| <<failover_register>> dev->priv_flags |= IFF_FAILOVER;
+ * - net/core/failover.c|305| <<failover_unregister>> failover_dev->priv_flags &= ~IFF_FAILOVER;
+ */
#define IFF_FAILOVER IFF_FAILOVER
+/*
+ * used by:
+ * - include/linux/netdevice.h|4614| <<netif_is_failover_slave>> return dev->priv_flags & IFF_FAILOVER_SLAVE;
+ * - net/core/failover.c|93| <<failover_slave_register>> slave_dev->priv_flags |= IFF_FAILOVER_SLAVE;
+ * - net/core/failover.c|100| <<failover_slave_register>> slave_dev->priv_flags &= ~IFF_FAILOVER_SLAVE;
+ * - net/core/failover.c|134| <<failover_slave_unregister>> slave_dev->priv_flags &= ~IFF_FAILOVER_SLAVE;
+ */
#define IFF_FAILOVER_SLAVE IFF_FAILOVER_SLAVE
/**
@@ -4604,11 +4617,22 @@ static inline bool netif_is_rxfh_configured(const struct net_device *dev)
return dev->priv_flags & IFF_RXFH_CONFIGURED;
}
+/*
+ * called by:
+ * - net/core/failover.c|201| <<failover_event>> if (netif_is_failover(event_dev))
+ * - net/core/failover.c|236| <<failover_existing_slave_register>> if (netif_is_failover(dev))
+ */
static inline bool netif_is_failover(const struct net_device *dev)
{
return dev->priv_flags & IFF_FAILOVER;
}
+/*
+ * called by:
+ * - net/core/failover.c|119| <<failover_slave_unregister>> if (!netif_is_failover_slave(slave_dev))
+ * - net/core/failover.c|150| <<failover_slave_link_change>> if (!netif_is_failover_slave(slave_dev))
+ * - net/core/failover.c|175| <<failover_slave_name_change>> if (!netif_is_failover_slave(slave_dev))
+ */
static inline bool netif_is_failover_slave(const struct net_device *dev)
{
return dev->priv_flags & IFF_FAILOVER_SLAVE;
diff --git a/include/net/failover.h b/include/net/failover.h
index bb15438..07a7cca 100644
--- a/include/net/failover.h
+++ b/include/net/failover.h
@@ -7,18 +7,46 @@
#include <linux/netdevice.h>
struct failover_ops {
+ /*
+ * called by:
+ * - net/core/failover.c|63| <<failover_slave_register>> fops->slave_pre_register(slave_dev, failover_dev))
+ */
int (*slave_pre_register)(struct net_device *slave_dev,
struct net_device *failover_dev);
+ /*
+ * called by:
+ * - net/core/failover.c|86| <<failover_slave_register>> !fops->slave_register(slave_dev, failover_dev))
+ */
int (*slave_register)(struct net_device *slave_dev,
struct net_device *failover_dev);
+ /*
+ * called by:
+ * - net/core/failover.c|119| <<failover_slave_unregister>> fops->slave_pre_unregister(slave_dev, failover_dev))
+ */
int (*slave_pre_unregister)(struct net_device *slave_dev,
struct net_device *failover_dev);
+ /*
+ * called by:
+ * - net/core/failover.c|127| <<failover_slave_unregister>> !fops->slave_unregister(slave_dev, failover_dev))
+ */
int (*slave_unregister)(struct net_device *slave_dev,
struct net_device *failover_dev);
+ /*
+ * called by:
+ * - net/core/failover.c|153| <<failover_slave_link_change>> !fops->slave_link_change(slave_dev, failover_dev))
+ */
int (*slave_link_change)(struct net_device *slave_dev,
struct net_device *failover_dev);
+ /*
+ * called by:
+ * - net/core/failover.c|178| <<failover_slave_name_change>> !fops->slave_name_change(slave_dev, failover_dev))
+ */
int (*slave_name_change)(struct net_device *slave_dev,
struct net_device *failover_dev);
+ /*
+ * used by:
+ * - net/core/failover.c|66| <<failover_slave_register>> err = netdev_rx_handler_register(slave_dev, fops->slave_handle_frame,
+ */
rx_handler_result_t (*slave_handle_frame)(struct sk_buff **pskb);
};
diff --git a/net/core/dev.c b/net/core/dev.c
index 82f2002..b789c86 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3186,6 +3186,9 @@ static netdev_features_t harmonize_features(struct sk_buff *skb,
return features;
}
+/*
+ * struct net_device_ops failover_dev_ops.ndo_features_check = passthru_features_check()
+ */
netdev_features_t passthru_features_check(struct sk_buff *skb,
struct net_device *dev,
netdev_features_t features)
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 158264f..5fc51fe 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -35,6 +35,9 @@
* we can turn these into dev_() function calls.
*/
+/*
+ * struct ethtool_ops failover_ethtool_ops.get_link = ethtool_op_get_link()
+ */
u32 ethtool_op_get_link(struct net_device *dev)
{
return netif_carrier_ok(dev) ? 1 : 0;
diff --git a/net/core/failover.c b/net/core/failover.c
index 4a92a98..9a71ba7 100644
--- a/net/core/failover.c
+++ b/net/core/failover.c
@@ -14,9 +14,23 @@
#include <linux/if_vlan.h>
#include <net/failover.h>
+/*
+ * used by:
+ * - net/core/failover.c|26| <<failover_get_bymac>> list_for_each_entry(failover, &failover_list, list) {
+ * - net/core/failover.c|264| <<failover_register>> list_add_tail(&failover->list, &failover_list);
+ */
static LIST_HEAD(failover_list);
static DEFINE_SPINLOCK(failover_lock);
+/*
+ * called by:
+ * - net/core/failover.c|68| <<failover_slave_register>> failover_dev = failover_get_bymac(slave_dev->perm_addr, &fops);
+ * - net/core/failover.c|124| <<failover_slave_unregister>> failover_dev = failover_get_bymac(slave_dev->perm_addr, &fops);
+ * - net/core/failover.c|155| <<failover_slave_link_change>> failover_dev = failover_get_bymac(slave_dev->perm_addr, &fops);
+ * - net/core/failover.c|180| <<failover_slave_name_change>> failover_dev = failover_get_bymac(slave_dev->perm_addr, &fops);
+ *
+ * 根据地址返回failover_list中的failover的net_device
+ */
static struct net_device *failover_get_bymac(u8 *mac, struct failover_ops **ops)
{
struct net_device *failover_dev;
@@ -43,6 +57,11 @@ static struct net_device *failover_get_bymac(u8 *mac, struct failover_ops **ops)
* Registers a slave device to a failover instance. Only ethernet devices
* are supported.
*/
+/*
+ * called by:
+ * - net/core/failover.c|201| <<failover_event>> return failover_slave_register(event_dev);
+ * - net/core/failover.c|230| <<failover_existing_slave_register>> failover_slave_register(dev);
+ */
static int failover_slave_register(struct net_device *slave_dev)
{
struct netdev_lag_upper_info lag_upper_info;
@@ -55,6 +74,13 @@ static int failover_slave_register(struct net_device *slave_dev)
ASSERT_RTNL();
+ /*
+ * 根据地址返回failover_list中的failover的net_device
+ *
+ * fops是net_failover_ops
+ * .slave_pre_register = net_failover_slave_pre_register,
+ * .slave_register = net_failover_slave_register,
+ */
failover_dev = failover_get_bymac(slave_dev->perm_addr, &fops);
if (!failover_dev)
goto done;
@@ -182,6 +208,9 @@ static int failover_slave_name_change(struct net_device *slave_dev)
return NOTIFY_DONE;
}
+/*
+ * struct notifier_block failover_notifier.notifier_call = failover_event()
+ */
static int
failover_event(struct notifier_block *this, unsigned long event, void *ptr)
{
@@ -211,6 +240,10 @@ static struct notifier_block failover_notifier = {
.notifier_call = failover_event,
};
+/*
+ * called by:
+ * - net/core/failover.c|274| <<failover_register>> failover_existing_slave_register(dev);
+ */
static void
failover_existing_slave_register(struct net_device *failover_dev)
{
@@ -221,6 +254,9 @@ failover_existing_slave_register(struct net_device *failover_dev)
for_each_netdev(net, dev) {
if (netif_is_failover(dev))
continue;
+ /*
+ * 调用两次还是多次????
+ */
if (ether_addr_equal(failover_dev->perm_addr, dev->perm_addr))
failover_slave_register(dev);
}
@@ -239,6 +275,10 @@ failover_existing_slave_register(struct net_device *failover_dev)
*
* Return: pointer to failover instance
*/
+/*
+ * called only by:
+ * - drivers/net/net_failover.c|886| <<net_failover_create>> failover = failover_register(failover_dev, &net_failover_ops);
+ */
struct failover *failover_register(struct net_device *dev,
struct failover_ops *ops)
{
@@ -275,6 +315,10 @@ EXPORT_SYMBOL_GPL(failover_register);
*
* Unregisters and frees a failover instance.
*/
+/*
+ * called by only:
+ * - drivers/net/net_failover.c|954| <<net_failover_destroy>> failover_unregister(failover);
+ */
void failover_unregister(struct failover *failover)
{
struct net_device *failover_dev;
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index 4c52011..2e9ed93 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -332,6 +332,9 @@ int eth_change_mtu(struct net_device *dev, int new_mtu)
}
EXPORT_SYMBOL(eth_change_mtu);
+/*
+ * struct net_device_ops failover_dev_ops.ndo_validate_addr = eth_validate_addr()
+ */
int eth_validate_addr(struct net_device *dev)
{
if (!is_valid_ether_addr(dev->dev_addr))
--
2.7.4