Skip to content

Commit

Permalink
fix bug: reference to dest->svc while dest->svc==NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
mscbg authored and beacer committed Jan 17, 2018
1 parent efe4458 commit 1dd85c8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
2 changes: 2 additions & 0 deletions include/ipvs/dest.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ struct dp_vs_dest {
uint32_t vfwmark; /* firewall mark of service */
struct dp_vs_service *svc; /* service it belongs to */
union inet_addr vaddr; /* virtual IP address */
unsigned conn_timeout; /* conn timeout copied from svc*/
unsigned limit_proportion; /* limit copied from svc*/
} __rte_cache_aligned;

struct dp_vs_dest_conf {
Expand Down
5 changes: 5 additions & 0 deletions src/ipvs/ip_vs_dest.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ struct dp_vs_dest *dp_vs_trash_get_dest(struct dp_vs_service *svc,
(svc->fwmark ||
(inet_addr_equal(svc->af, &dest->vaddr, &svc->addr) &&
dest->vport == svc->port))) {
/*since svc may be edit, variables should be coverd*/
dest->conn_timeout = svc->conn_timeout;
dest->limit_proportion = svc->limit_proportion;
return dest;
}
if (rte_atomic32_read(&dest->refcnt) == 1) {
Expand Down Expand Up @@ -223,6 +226,8 @@ int dp_vs_new_dest(struct dp_vs_service *svc, struct dp_vs_dest_conf *udest,
dest->proto = svc->proto;
dest->vaddr = svc->addr;
dest->vport = svc->port;
dest->conn_timeout = svc->conn_timeout;
dest->limit_proportion = svc->limit_proportion;
dest->vfwmark = svc->fwmark;
dest->addr = udest->addr;
dest->port = udest->port;
Expand Down
6 changes: 2 additions & 4 deletions src/ipvs/ip_vs_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,8 @@ int dp_vs_get_service_entries(const struct dp_vs_get_services *get,
unsigned dp_vs_get_conn_timeout(struct dp_vs_conn *conn)
{
unsigned conn_timeout;
if (conn->dest->svc) {
rte_atomic32_inc(&(conn->dest->svc->usecnt));
conn_timeout = conn->dest->svc->conn_timeout;
rte_atomic32_dec(&(conn->dest->svc->usecnt));
if (conn->dest) {
conn_timeout = conn->dest->conn_timeout;
return conn_timeout;
}
return 90;
Expand Down
21 changes: 7 additions & 14 deletions src/ipvs/ip_vs_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,14 @@ int dp_vs_stats_in(struct dp_vs_conn *conn, struct rte_mbuf *mbuf)

if (dest && (dest->flags & DPVS_DEST_F_AVAILABLE)) {
/*limit rate*/
assert(dest->svc);
if ((dest->svc->limit_proportion < 100) &&
(dest->svc->limit_proportion > 0)) {
return (rand()%100) > dest->svc->limit_proportion
if ((dest->limit_proportion < 100) &&
(dest->limit_proportion > 0)) {
return (rand()%100) > dest->limit_proportion
? EDPVS_OVERLOAD : EDPVS_OK;
}

dest->stats[cid].inpkts++;
dest->stats[cid].inbytes += mbuf->pkt_len;
dest->svc->stats[cid].inpkts++;
dest->svc->stats[cid].inbytes += mbuf->pkt_len;
}

this_dpvs_stats.inpkts++;
Expand All @@ -234,17 +231,14 @@ int dp_vs_stats_out(struct dp_vs_conn *conn, struct rte_mbuf *mbuf)

if (dest && (dest->flags & DPVS_DEST_F_AVAILABLE)) {
/*limit rate*/
assert(dest->svc);
if ((dest->svc->limit_proportion < 100) &&
(dest->svc->limit_proportion > 0)) {
return (rand()%100) > dest->svc->limit_proportion
if ((dest->limit_proportion < 100) &&
(dest->limit_proportion > 0)) {
return (rand()%100) > dest->limit_proportion
? EDPVS_OVERLOAD : EDPVS_OK;
}

dest->stats[cid].outpkts++;
dest->stats[cid].outbytes += mbuf->pkt_len;
dest->svc->stats[cid].outpkts++;
dest->svc->stats[cid].outbytes += mbuf->pkt_len;
}

this_dpvs_stats.outpkts++;
Expand All @@ -254,12 +248,11 @@ int dp_vs_stats_out(struct dp_vs_conn *conn, struct rte_mbuf *mbuf)

void dp_vs_stats_conn(struct dp_vs_conn *conn)
{
assert(conn && conn->dest && conn->dest->svc);
assert(conn && conn->dest);
lcoreid_t cid;

cid = rte_lcore_id();
conn->dest->stats[cid].conns++;
conn->dest->svc->stats[cid].conns++;
this_dpvs_stats.conns++;
}

Expand Down
16 changes: 16 additions & 0 deletions tools/ipvsadm/ipvsadm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,19 @@ static inline char *fwd_switch(unsigned flags)
return swt;
}

/*notice when rs is deleted svc stats count will be less than before*/
static void copy_stats_from_dest(ipvs_service_entry_t *se, struct ip_vs_get_dests *d)
{
int i = 0;
for (i = 0; i < d->num_dests; i++) {
ipvs_dest_entry_t *e = &d->entrytable[i];
se->stats.conns += e->stats.conns;
se->stats.inpkts += e->stats.inpkts;
se->stats.outpkts += e->stats.outpkts;
se->stats.inbytes += e->stats.inbytes;
se->stats.outbytes += e->stats.outbytes;
}
}

static void print_largenum(unsigned long long i, unsigned int format)
{
Expand Down Expand Up @@ -1788,6 +1801,9 @@ print_service_entry(ipvs_service_entry_t *se, unsigned int format)
}
}

/* copy svc's stats from dest */
copy_stats_from_dest(se, d);

/* print virtual service info */
if (format & FMT_RULE) {
printf("-A %s -s %s", svc_name, se->sched_name);
Expand Down

0 comments on commit 1dd85c8

Please sign in to comment.