blob: 2ea8871e837684a6ee3b80913df43a924426f20d [file] [log] [blame]
--- a/bridge.c
+++ b/bridge.c
@@ -91,6 +91,7 @@ static void bridge_stp_init(struct devic
static void bridge_dump_info(struct device *dev, struct blob_buf *b);
static enum dev_change_type
bridge_reload(struct device *dev, struct blob_attr *attr);
+extern void write_str_to_kmsg(char str[]);
static struct device_type bridge_device_type = {
.name = "bridge",
@@ -653,6 +654,7 @@ static void
bridge_remove_member(struct bridge_member *bm)
{
struct bridge_state *bst = bm->bst;
+ char str[256];
if (!bm->present)
return;
@@ -663,6 +665,18 @@ bridge_remove_member(struct bridge_membe
bm->present = false;
bm->bst->n_present--;
+ if (bm->bst->n_present < 0) {
+ sprintf(str, "bm->bst->n_present abnormal\n");
+ write_str_to_kmsg(str);
+ sprintf(str, "!!!!bridge_remove_member:claimed:%d,present:%d, n_present:%d, active: %d, bm:%s, act:%d\n",
+ bm->dev.claimed, bm->present, bm->bst->n_present,
+ bst->dev.active, bm->name, bm->dev.dev->active);
+ write_str_to_kmsg(str);
+ bm->bst->n_present = 0;
+ sprintf(str, "force n_present=0\n");
+ write_str_to_kmsg(str);
+ }
+
if (bm == bst->primary_port)
bridge_reset_primary(bst);
@@ -755,11 +769,17 @@ bridge_member_cb(struct device_user *dep
struct bridge_member *bm = container_of(dep, struct bridge_member, dev);
struct bridge_state *bst = bm->bst;
struct device *dev = dep->dev;
+ char str[128];
switch (ev) {
case DEV_EVENT_ADD:
assert(!bm->present);
+ sprintf(str, "NETIFD:ADD bm_claimed:%d,bm_prsent:%d,n_prsent:%d,dev.act:%d,bm:%s,act:%d\n",
+ bm->dev.claimed, bm->present, bst->n_present,
+ bst->dev.active, bm->name, bm->dev.dev->active);
+ write_str_to_kmsg(str);
+ bm->dev.claimed = 0;
bm->present = true;
bst->n_present++;
@@ -797,6 +817,11 @@ bridge_member_cb(struct device_user *dep
bridge_disable_member(bm, true);
break;
case DEV_EVENT_REMOVE:
+ sprintf(str, "NETIFD:RM dev.claimed:%d,prsent:%d,n_prsent:%d,dev.active: %d,hotplug:%d,act: %d\n",
+ bm->dev.claimed, bm->present, bst->n_present,
+ bst->dev.active, dep->hotplug, bm->dev.dev->active);
+ write_str_to_kmsg(str);
+ bm->present = true;
if (dep->hotplug && !dev->sys_present) {
vlist_delete(&bst->members, &bm->node);
return;
@@ -1455,3 +1480,4 @@ static void __init bridge_device_type_in
{
device_type_add(&bridge_device_type);
}
+
--- a/device.c
+++ b/device.c
@@ -84,7 +84,7 @@ const struct uci_blob_param_list device_
};
static int __devlock = 0;
-
+extern void write_str_to_kmsg(char str[]);
int device_type_add(struct device_type *devtype)
{
if (device_type_get(devtype->name)) {
@@ -717,6 +717,7 @@ device_fill_default_settings(struct devi
int device_claim(struct device_user *dep)
{
+ char str[64];
struct device *dev = dep->dev;
int ret = 0;
@@ -728,9 +729,11 @@ int device_claim(struct device_user *dep
dep->claimed = true;
D(DEVICE, "Claim %s %s, new active count: %d", dev->type->name, dev->ifname, dev->active + 1);
- if (++dev->active != 1)
+ if (++dev->active != 1) {
+ sprintf(str, "device_claim: active: %d\n", dev->active);
+ write_str_to_kmsg(str);
return 0;
-
+ }
device_broadcast_event(dev, DEV_EVENT_SETUP);
device_fill_default_settings(dev);
ret = dev->set_state(dev, true);
@@ -738,6 +741,8 @@ int device_claim(struct device_user *dep
device_broadcast_event(dev, DEV_EVENT_UP);
else {
D(DEVICE, "claim %s %s failed: %d", dev->type->name, dev->ifname, ret);
+ sprintf(str, "----claim %s %s failed: %d\n", dev->type->name, dev->ifname, ret);
+ write_str_to_kmsg(str);
dev->active = 0;
dep->claimed = false;
}
@@ -747,6 +752,7 @@ int device_claim(struct device_user *dep
void device_release(struct device_user *dep)
{
+ char str[64];
struct device *dev = dep->dev;
if (!dep->claimed)
@@ -755,6 +761,9 @@ void device_release(struct device_user *
dep->claimed = false;
dev->active--;
D(DEVICE, "Release %s %s, new active count: %d", dev->type->name, dev->ifname, dev->active);
+ sprintf(str, "--Release %s %s, new active count: %d\n", dev->type->name, dev->ifname, dev->active);
+ write_str_to_kmsg(str);
+
assert(dev->active >= 0);
if (dev->active)
@@ -1465,3 +1474,4 @@ void device_hotplug_event(const char *na
device_set_present(dev, add);
}
+
--- a/main.c
+++ b/main.c
@@ -18,6 +18,9 @@
#include <signal.h>
#include <stdarg.h>
#include <syslog.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
#include "netifd.h"
#include "ubus.h"
@@ -332,6 +335,26 @@ netifd_kill_processes(void)
netifd_kill_process(proc);
}
+static int kmsg_fd = -1;
+void write_str_to_kmsg(char str[]);
+void write_str_to_kmsg(char str[])
+{
+ if (kmsg_fd != -1)
+ write(kmsg_fd, str, strlen(str));
+}
+static void init_open_kmsg(void)
+{
+ char open_done[] = "netifd open kmsg done\n";
+
+ kmsg_fd = open("/dev/kmsg", O_RDWR);
+ write(kmsg_fd, open_done, strlen(open_done));
+}
+
+static void close_kmsg()
+{
+ close(kmsg_fd);
+}
+
int main(int argc, char **argv)
{
const char *socket = NULL;
@@ -374,6 +397,7 @@ int main(int argc, char **argv)
}
}
+ init_open_kmsg();
if (use_syslog)
openlog("netifd", 0, LOG_DAEMON);
@@ -408,5 +432,7 @@ int main(int argc, char **argv)
if (use_syslog)
closelog();
+ close_kmsg();
return 0;
}
+