Пример #1
0
static int res_no_args_parse_cb(const struct nlmsghdr *nlh, void *data)
{
	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
	struct rd *rd = data;
	const char *name;
	uint32_t idx;

	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] ||
	    !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
	    !tb[RDMA_NLDEV_ATTR_RES_SUMMARY])
		return MNL_CB_ERROR;

	idx =  mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
	if (rd->json_output) {
		jsonw_uint_field(rd->jw, "ifindex", idx);
		jsonw_string_field(rd->jw, "ifname", name);
	} else {
		pr_out("%u: %s: ", idx, name);
	}

	res_print_summary(rd, tb);

	if (!rd->json_output)
		pr_out("\n");
	return MNL_CB_OK;
}
Пример #2
0
int get_epollevent(int fd_listener, struct epoll_event *ep_events, int ret_poll)
{
	int i, ret, ret_recv, fd;
	char buf[1024], buf_time[32];

	for (i = 0; i < ret_poll; i++) {
		if (ep_events[i].events & EPOLLIN) {
			if (ep_events[i].data.fd == fd_listener) {
				while (1) {
					if ((fd = accept(fd_listener, NULL, NULL)) == -1) {
						if (errno == EAGAIN)
							break;
						pr_err("accept()");
						break;
					}
					fcntl_setnb(fd);
					ADD_EV(epollfd, fd, FDSESSION_DEFAULT_TIMEOUT);
					pr_out("accept : add socket = %d", fd);
				} /* while */
			} else {
				FDSESSION *ret_fds;
				if (fds_findbytimerfd(&ret_fds, ep_events[i].data.fd) == 0) {
					pr_out("timeout[%s] expired/closed (sfd/tfd=%d/%d)", GET_TIME0(buf_time),
							ret_fds->socketfd, ret_fds->timerfd);
					setsockopt_linger(ret_fds->socketfd);
					DEL_EV(epollfd, ret_fds->socketfd);
				} else {
					if ((ret_recv = recv(ep_events[i].data.fd, buf, sizeof(buf), 0)) == -1) {
						pr_err("recv()");
					} else {
						if (ret_recv == 0) {
							pr_out("closed by foreign host (sfd=%d)", ep_events[i].data.fd);
							DEL_EV(epollfd, ep_events[i].data.fd);
						} else {
							pr_out("recv[%s] (fd=%d,n=%d)=%.*s", GET_TIME0(buf_time),
									ep_events[i].data.fd, ret_recv, ret_recv, buf);
							if ((ret = fds_findbysocketfd(&ret_fds, ep_events[i].data.fd)) != 0) {
								return ret;
							}
							if ((ret = fds_set_timerfd(ret_fds)) != 0) {
								return ret;
							}
						}
					} /* end : recv() */
				} /* end : if-else timerfd */
			} /* end : if-else fd_listener */
		} else if (ep_events[i].events & EPOLLERR) {
			/* error */
		} else {
			pr_out("fd(%d) epoll event(%d) err(%s)",
					ep_events[i].data.fd, ep_events[i].events, strerror(errno));
		}
	}

	return 0;
}
Пример #3
0
static int stateview_json_port_runner_process(char *runner_name,
					      json_t *port_json)
{
	int err;

	if (!strcmp(runner_name, "lacp")) {
		int selected;
		int aggregator_id;
		char *state;
		int key;
		int prio;
		json_t *actor_json;
		json_t *partner_json;

		pr_out("runner:\n");
		err = json_unpack(port_json,
				  "{s:{s:b, s:i, s:s, s:i, s:i, s:o, s:o}}",
				  "runner",
				  "selected", &selected,
				  "aggregator_id", &aggregator_id,
				  "state", &state,
				  "key", &key,
				  "prio", &prio,
				  "actor_lacpdu_info", &actor_json,
				  "partner_lacpdu_info", &partner_json);
		if (err) {
			pr_err("Failed to parse JSON port runner dump.\n");
			return -EINVAL;
		}
		pr_out_indent_inc();
		pr_out("aggregator ID: %d\n", aggregator_id);
		pr_out("selected: %s\n", boolyesno(selected));
		pr_out("state: %s\n", state);
		pr_out2("key: %d\n", key);
		pr_out2("priority: %d\n", prio);
		pr_out2("actor LACPDU info:\n");
		pr_out_indent_inc();
		err = stateview_json_lacpdu_process(actor_json);
		if (err)
			return err;
		pr_out_indent_dec();
		pr_out2("partner LACPDU info:\n");
		pr_out_indent_inc();
		err = stateview_json_lacpdu_process(partner_json);
		if (err)
			return err;
		pr_out_indent_dec();
		pr_out_indent_dec();
	}
	return 0;
}
Пример #4
0
static void print_pid(struct rd *rd, uint32_t val)
{
	if (rd->json_output)
		jsonw_uint_field(rd->jw, "pid", val);
	else
		pr_out("pid %u ", val);
}
Пример #5
0
static void print_sqpsn(struct rd *rd, uint32_t val)
{
	if (rd->json_output)
		jsonw_uint_field(rd->jw, "sq-psn", val);
	else
		pr_out("sq-psn %u ", val);
}
Пример #6
0
static void print_cqe(struct rd *rd, uint32_t val)
{
	if (rd->json_output)
		jsonw_uint_field(rd->jw, "cqe", val);
	else
		pr_out("cqe %u ", val);
}
Пример #7
0
/* Name : start_thread
 * Desc : thread function with message
 * Argv : int idx (child index)
 * Ret  : None
 */
void *start_thread(void *arg)
{
	struct thread_arg *t_arg = (struct thread_arg *)arg;
	char	ts_now[20];
	int 	ret;

	pr_out("[Thread:%d] [%s] sleep(%d)", 
			t_arg->idx, GET_TIME0(ts_now), t_arg->idx + 2);
	sleep(t_arg->idx + 2);
	ret = pthread_barrier_wait(&pt_barrier);
	if (ret == PTHREAD_BARRIER_SERIAL_THREAD) {
		pr_out("[Thread:%d] PTHREAD_BARRIER_SERIAL_THREAD", t_arg->idx);
	}
	pr_out("\t[Thread:%d] [%s] wake up", t_arg->idx, GET_TIME0(ts_now));
	pthread_exit(t_arg);
}
Пример #8
0
static void print_users(struct rd *rd, uint64_t val)
{
	if (rd->json_output)
		jsonw_uint_field(rd->jw, "users", val);
	else
		pr_out("users %" PRIu64 " ", val);
}
Пример #9
0
static void print_iova(struct rd *rd, uint64_t val)
{
	if (rd->json_output)
		jsonw_xint_field(rd->jw, "iova", val);
	else
		pr_out("iova 0x%" PRIx64 " ", val);
}
Пример #10
0
static void print_mrlen(struct rd *rd, uint64_t val)
{
	if (rd->json_output)
		jsonw_uint_field(rd->jw, "mrlen", val);
	else
		pr_out("mrlen %" PRIu64 " ", val);
}
Пример #11
0
static int res_print_summary(struct rd *rd, struct nlattr **tb)
{
	struct nlattr *nla_table = tb[RDMA_NLDEV_ATTR_RES_SUMMARY];
	struct nlattr *nla_entry;
	const char *name;
	uint64_t curr;
	int err;

	mnl_attr_for_each_nested(nla_entry, nla_table) {
		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
		char json_name[32];

		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
		if (err != MNL_CB_OK)
			return -EINVAL;

		if (!nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_NAME] ||
		    !nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_CURR]) {
			return -EINVAL;
		}

		name = mnl_attr_get_str(nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_NAME]);
		curr = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_CURR]);
		if (rd->json_output) {
			snprintf(json_name, 32, "%s", name);
			jsonw_lluint_field(rd->jw, json_name, curr);
		} else {
			pr_out("%s %"PRId64 " ", name, curr);
		}
	}
	return 0;
}
Пример #12
0
static void print_lqpn(struct rd *rd, uint32_t val)
{
	if (rd->json_output)
		jsonw_uint_field(rd->jw, "lqpn", val);
	else
		pr_out("lqpn %u ", val);
}
Пример #13
0
static void print_key(struct rd *rd, const char *name, uint32_t val)
{
	if (rd->json_output)
		jsonw_xint_field(rd->jw, name, val);
	else
		pr_out("%s 0x%x ", name, val);
}
Пример #14
0
static inline void postprocess_malloc (ptr_t ffp, size_t size, ptr_t mem_addr)
{
	ptr_t code_addr, stack_offs, stack_addr;
	i32 i, j, wbytes, num_taddr = 0;
	void *trace[MAX_GNUBT] = { NULL };

	if (!active)
		return;

	for (i = 0; config[i] != NULL; i++) {
		struct grow *grow = config[i]->grow;
		if (size == config[i]->mem_size) {
			code_addr = config[i]->code_addr;
			stack_offs = config[i]->stack_offs;
		} else if (grow && size <= grow->size_max &&
		    size >= grow->size_min) {
			if (size % grow->add != 0)
				continue;
			code_addr = grow->code_addr;
			stack_offs = grow->stack_offs;
		} else {
			continue;
		}
		/* rarely used GNU backtrace method (unstable, slow) */
		if (use_gbt) {
			num_taddr = backtrace(trace, MAX_GNUBT);
			if (num_taddr < 2)
				continue;
			/* skip the first code addr (our own one) */
			for (j = 1; j < num_taddr; j++) {
				if ((ptr_t) trace[j] == code_addr)
					goto found;
			}
			continue;
		}

		/* reverse stack offset method */
		stack_addr = ffp + stack_offs;
		if (stack_addr > stack_end - sizeof(ptr_t))
			continue;
		if (*(ptr_t *) stack_addr == code_addr)
			goto found;
		continue;
found:
#if DEBUG_MEM
		pr_out("malloc: mem_addr: " PRI_PTR ", size: %zu, code_addr: "
			PRI_PTR "\n", mem_addr, size, code_addr);
#endif
		wbytes = sprintf(obuf, "m" PRI_PTR ";s%zu;c" PRI_PTR "\n",
			mem_addr, size, code_addr);

		wbytes = write(ofd, obuf, wbytes);
		if (wbytes < 0)
			perror("write");
		else
			store_mem_addr(config[i], mem_addr);
		break;
	}
}
Пример #15
0
static void print_cm_id_state(struct rd *rd, uint8_t state)
{
	if (rd->json_output) {
		jsonw_string_field(rd->jw, "state", cm_id_state_to_str(state));
		return;
	}
	pr_out("state %s ", cm_id_state_to_str(state));
}
Пример #16
0
static int stateview_json_port_link_watches_process(json_t *port_link_watches_json)
{
	int err;
	int up;
	json_t *lw_list_json;
	json_t *lw_json;
	json_t *lw_info_json;
	char *lw_name;
	int i;

	err = json_unpack(port_link_watches_json, "{s:b, s:o}",
			  "up", &up, "list", &lw_list_json);
	if (err) {
		pr_err("Failed to parse JSON port link watches dump.\n");
		return -EINVAL;
	}
	pr_out("link watches:\n");
	pr_out_indent_inc();
	pr_out("link summary: %s\n", boolupdown(up));
	for (i = 0; i < json_array_size(lw_list_json); i++) {
		lw_json = json_array_get(lw_list_json, i);

		err = json_unpack(lw_json, "{s:b, s:s, s:o}",
				  "up", &up,
				  "name", &lw_name,
				  "info", &lw_info_json);
		if (err) {
			pr_err("Failed to parse JSON port link watch dump.\n");
			return -EINVAL;
		}
		pr_out("intance[%d]:\n", i);
		pr_out_indent_inc();
		pr_out("name: %s\n", lw_name);
		pr_out("link: %s\n", boolupdown(up));
		pr_out2("info:\n");
		pr_out_indent_inc();
		err = stateview_json_link_watch_info_process(lw_name,
							     lw_info_json);
		if (err)
			return err;
		pr_out_indent_dec();
		pr_out_indent_dec();
	}
	pr_out_indent_dec();
	return 0;
}
Пример #17
0
static void print_qp_type(struct rd *rd, uint32_t val)
{
	if (rd->json_output)
		jsonw_string_field(rd->jw, "qp-type",
				   qp_types_to_str(val));
	else
		pr_out("qp-type %s ", qp_types_to_str(val));
}
Пример #18
0
static void print_link(struct rd *rd, uint32_t idx, const char *name,
		       uint32_t port, struct nlattr **nla_line)
{
	if (rd->json_output) {
		jsonw_uint_field(rd->jw, "ifindex", idx);

		if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
			jsonw_uint_field(rd->jw, "port", port);

		jsonw_string_field(rd->jw, "ifname", name);
	} else {
		if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
			pr_out("link %s/%u ", name, port);
		else
			pr_out("link %s/- ", name);
	}
}
Пример #19
0
static void print_ps(struct rd *rd, uint32_t ps)
{
	if (rd->json_output) {
		jsonw_string_field(rd->jw, "ps", cm_id_ps_to_str(ps));
		return;
	}
	pr_out("ps %s ", cm_id_ps_to_str(ps));
}
Пример #20
0
static void print_dev(struct rd *rd, uint32_t idx, const char *name)
{
	if (rd->json_output) {
		jsonw_uint_field(rd->jw, "ifindex", idx);
		jsonw_string_field(rd->jw, "ifname", name);
	} else {
		pr_out("dev %s ", name);
	}
}
Пример #21
0
static void print_poll_ctx(struct rd *rd, uint8_t poll_ctx)
{
	if (rd->json_output) {
		jsonw_string_field(rd->jw, "poll-ctx",
				   poll_ctx_to_str(poll_ctx));
		return;
	}
	pr_out("poll-ctx %s ", poll_ctx_to_str(poll_ctx));
}
Пример #22
0
/* Name : clean_thread
 * Desc : clean(join) thread
 * Argv : None
 * Ret  : None
 */
void clean_thread(struct thread_arg *t_arg)
{
	int     i;
	struct thread_arg *t_arg_ret;

	for (i=0; i<NUM_THREADS; i++, t_arg++) {
		pthread_join(t_arg->tid, (void **)&t_arg_ret);
		pr_out("pthread_join : %d - %lu", t_arg->idx, t_arg->tid);
	}
}
Пример #23
0
static void print_rqpsn(struct rd *rd, uint32_t val, struct nlattr **nla_line)
{
	if (!nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN])
		return;

	if (rd->json_output)
		jsonw_uint_field(rd->jw, "rq-psn", val);
	else
		pr_out("rq-psn %u ", val);
}
Пример #24
0
static inline void output_cfg (void)
{
	i32 i;

	for (i = 0; config[i] != NULL; i++) {
		struct grow *grow = config[i]->grow;
		pr_out("config[%u]: mem_size: %zd; "
			"code_addr: " PRI_PTR "; stack_offs: " PRI_PTR "; %s\n", i,
			config[i]->mem_size, config[i]->code_addr,
			config[i]->stack_offs, (config[i]->lib) ?
			config[i]->lib : "exe");
		if (grow) {
			pr_out("config[%u] growing: size_min: %zd; size_max: "
				"%zd; add: %u; code_addr: " PRI_PTR
				"; stack_offs: " PRI_PTR "; %s\n", i,
				grow->size_min, grow->size_max, grow->add,
				grow->code_addr, grow->stack_offs, (grow->lib) ?
				grow->lib : "exe");
		}

	}
}
Пример #25
0
static int stateview_json_runner_process(char *runner_name, json_t *json)
{
	int err;

	if (!strcmp(runner_name, "activebackup")) {
		char *active_port;

		pr_out("runner:\n");
		err = json_unpack(json, "{s:{s:s}}", "runner",
				  "active_port", &active_port);
		if (err) {
			pr_err("Failed to parse JSON runner dump.\n");
			return -EINVAL;
		}
		pr_out_indent_inc();
		pr_out("active port: %s\n", active_port);
		pr_out_indent_dec();
	} else if (!strcmp(runner_name, "lacp")) {
		json_t *agg_list_json;
		int active;
		int sys_prio;
		int fast_rate;
		int i;

		pr_out("runner:\n");
		err = json_unpack(json, "{s:{s:o, s:b, s:i, s:b}}", "runner",
				  "aggregators", &agg_list_json,
				  "active", &active,
				  "sys_prio", &sys_prio,
				  "fast_rate", &fast_rate);
		if (err) {
			pr_err("Failed to parse JSON runner dump.\n");
			return -EINVAL;
		}
		pr_out_indent_inc();
		for (i = 0; i < json_array_size(agg_list_json); i++) {
			json_t *agg_json;
			int agg_id;
			int agg_selected;

			agg_json = json_array_get(agg_list_json, i);
			err = json_unpack(agg_json, "{s:i, s:b}",
				  "id", &agg_id,
				  "selected", &agg_selected);
			if (err) {
				pr_err("Failed to parse JSON aggregator dump.\n");
				return -EINVAL;
			}
			if (agg_selected)
				pr_out("selected aggregator ID: %d\n", agg_id);
		}

		pr_out("active: %s\n", boolyesno(active));
		pr_out("fast rate: %s\n", boolyesno(fast_rate));
		pr_out2("system priority: %d\n", sys_prio);
		pr_out_indent_dec();
	}
	return 0;
}
Пример #26
0
static void print_pathmig(struct rd *rd, uint32_t val,
			  struct nlattr **nla_line)
{
	if (!nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE])
		return;

	if (rd->json_output)
		jsonw_string_field(rd->jw,
				   "path-mig-state",
				   path_mig_to_str(val));
	else
		pr_out("path-mig-state %s ", path_mig_to_str(val));
}
Пример #27
0
static void print_ipaddr(struct rd *rd, const char *key, char *addrstr,
			 uint16_t port)
{
	if (rd->json_output) {
		int name_size = INET6_ADDRSTRLEN+strlen(":65535");
		char json_name[name_size];

		snprintf(json_name, name_size, "%s:%u", addrstr, port);
		jsonw_string_field(rd->jw, key, json_name);
		return;
	}
	pr_out("%s %s:%u ", key, addrstr, port);
}
Пример #28
0
static int stateview_json_setup_process(char **prunner_name, json_t *setup_json)
{
	int err;
	char *runner_name;
	char *kernel_team_mode_name;
	int dbus_enabled;
	int debug_level;
	int daemonized;
	int pid;
	char *pid_file;

	pr_out("setup:\n");
	err = json_unpack(setup_json, "{s:s, s:s, s:b, s:i, s:b, s:i, s:s}",
			  "runner_name", &runner_name,
			  "kernel_team_mode_name", &kernel_team_mode_name,
			  "dbus_enabled", &dbus_enabled,
			  "debug_level", &debug_level,
			  "daemonized", &daemonized,
			  "pid", &pid,
			  "pid_file", &pid_file);
	if (err) {
		pr_err("Failed to parse JSON setup dump.\n");
		return -EINVAL;
	}
	pr_out_indent_inc();
	pr_out("runner: %s\n", runner_name);
	pr_out2("kernel team mode: %s\n", kernel_team_mode_name);
	pr_out2("D-BUS enabled: %s\n", boolyesno(dbus_enabled));
	pr_out2("debug level: %d\n", debug_level);
	pr_out2("daemonized: %s\n", boolyesno(daemonized));
	pr_out2("PID: %d\n", pid);
	pr_out2("PID file: %s\n", pid_file);
	pr_out_indent_dec();

	*prunner_name = runner_name;
	return 0;
}
Пример #29
0
static int __jsondump(json_t *json)
{
	char *dump;
	int indent = g_oneline ? 0 : 4;

	dump = json_dumps(json, JSON_INDENT(indent) | JSON_ENSURE_ASCII |
				JSON_SORT_KEYS);
	if (!dump) {
		pr_err("Failed to get JSON dump.\n");
		return -ENOMEM;
	}
	pr_out("%s\n", dump);
	free(dump);
	return 0;
}
Пример #30
0
static void print_comm(struct rd *rd, const char *str,
		       struct nlattr **nla_line)
{
	char tmp[18];

	if (rd->json_output) {
		/* Don't beatify output in JSON format */
		jsonw_string_field(rd->jw, "comm", str);
		return;
	}

	if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
		snprintf(tmp, sizeof(tmp), "%s", str);
	else
		snprintf(tmp, sizeof(tmp), "[%s]", str);

	pr_out("comm %s ", tmp);
}