[sheepdog] [PATCH v3 7/8] sheep: embed struct node_id into struct {sd_node, sd_vnode}
Liu Yuan
namei.unix at gmail.com
Tue Jun 26 10:45:43 CEST 2012
From: Liu Yuan <tailai.ly at taobao.com>
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
collie/cluster.c | 2 +-
collie/node.c | 14 +++++++-------
collie/vdi.c | 26 +++++++++++++-------------
include/sheep.h | 37 ++++++++++++++++++++-----------------
sheep/cluster.h | 8 ++++----
sheep/gateway.c | 14 +++++++-------
sheep/group.c | 24 ++++++++++++------------
sheep/ops.c | 6 +++---
sheep/recovery.c | 16 ++++++++--------
sheep/sheep.c | 2 +-
sheep/sheep_priv.h | 18 ++++++++----------
sheep/sockfd_cache.c | 28 ++++++++--------------------
sheep/store.c | 10 +++++-----
13 files changed, 97 insertions(+), 108 deletions(-)
diff --git a/collie/cluster.c b/collie/cluster.c
index 23fa2b0..e3fc38a 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -197,7 +197,7 @@ again:
printf("%s%s",
(j == 0) ? "" : ", ",
addr_to_str(name, sizeof(name),
- entry->addr, entry->port));
+ entry->nid.addr, entry->nid.port));
}
printf("]\n");
}
diff --git a/collie/node.c b/collie/node.c
index 2449b16..ce1c981 100644
--- a/collie/node.c
+++ b/collie/node.c
@@ -30,8 +30,8 @@ static int node_list(int argc, char **argv)
for (i = 0; i < sd_nodes_nr; i++) {
char data[128];
- addr_to_str(data, sizeof(data), sd_nodes[i].addr,
- sd_nodes[i].port);
+ addr_to_str(data, sizeof(data), sd_nodes[i].nid.addr,
+ sd_nodes[i].nid.port);
if (i == master_idx) {
if (highlight)
@@ -67,9 +67,9 @@ static int node_info(int argc, char **argv)
struct sd_node_rsp *rsp = (struct sd_node_rsp *)&req;
char store_str[UINT64_DECIMAL_SIZE], free_str[UINT64_DECIMAL_SIZE];
- addr_to_str(name, sizeof(name), sd_nodes[i].addr, 0);
+ addr_to_str(name, sizeof(name), sd_nodes[i].nid.addr, 0);
- fd = connect_to(name, sd_nodes[i].port);
+ fd = connect_to(name, sd_nodes[i].nid.port);
if (fd < 0)
return 1;
@@ -134,9 +134,9 @@ static int node_recovery(int argc, char **argv)
struct sd_node_req req;
struct sd_node_rsp *rsp = (struct sd_node_rsp *)&req;
- addr_to_str(host, sizeof(host), sd_nodes[i].addr, 0);
+ addr_to_str(host, sizeof(host), sd_nodes[i].nid.addr, 0);
- fd = connect_to(host, sd_nodes[i].port);
+ fd = connect_to(host, sd_nodes[i].nid.port);
if (fd < 0)
return EXIT_FAILURE;
@@ -151,7 +151,7 @@ static int node_recovery(int argc, char **argv)
if (!ret && rsp->result == SD_RES_SUCCESS) {
addr_to_str(host, sizeof(host),
- sd_nodes[i].addr, sd_nodes[i].port);
+ sd_nodes[i].nid.addr, sd_nodes[i].nid.port);
printf(raw_output ? "%d %s %d %d\n" : "%4d %-20s%5d%11d\n",
i, host, sd_nodes[i].nr_vnodes,
sd_nodes[i].zone);
diff --git a/collie/vdi.c b/collie/vdi.c
index 34c8c03..d76307e 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -274,9 +274,9 @@ static void parse_objs(uint64_t oid, obj_parser_func_t func, void *data, unsigne
struct sd_req hdr;
struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
- addr_to_str(name, sizeof(name), sd_nodes[i].addr, 0);
+ addr_to_str(name, sizeof(name), sd_nodes[i].nid.addr, 0);
- fd = connect_to(name, sd_nodes[i].port);
+ fd = connect_to(name, sd_nodes[i].nid.port);
if (fd < 0)
break;
@@ -292,7 +292,7 @@ static void parse_objs(uint64_t oid, obj_parser_func_t func, void *data, unsigne
ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
close(fd);
- sprintf(name + strlen(name), ":%d", sd_nodes[i].port);
+ sprintf(name + strlen(name), ":%d", sd_nodes[i].nid.port);
if (ret)
fprintf(stderr, "Failed to connect to %s\n", name);
@@ -849,14 +849,14 @@ again:
for (i = nr_logs - 1; i >= 0; i--) {
vnodes_nr = nodes_to_vnodes(logs[i].nodes, logs[i].nr_nodes, vnodes);
printf("\nobj %"PRIx64" locations at epoch %d, copies = %d\n",
- oid, logs[i].epoch, logs[i].nr_copies);
+ oid, logs[i].epoch, logs[i].nr_copies);
printf("---------------------------------------------------\n");
obj_to_sheeps(vnodes, vnodes_nr, oid,
- logs[i].nr_copies, idx_buf);
+ logs[i].nr_copies, idx_buf);
for (j = 0; j < logs[i].nr_copies; j++) {
idx = idx_buf[j];
- addr_to_str(host, sizeof(host), vnodes[idx].addr,
- vnodes[idx].port);
+ addr_to_str(host, sizeof(host), vnodes[idx].nid.addr,
+ vnodes[idx].nid.port);
printf("%s\n", host);
}
}
@@ -1331,11 +1331,11 @@ static void *read_object_from(struct sd_vnode *vnode, uint64_t oid)
exit(EXIT_SYSFAIL);
}
- addr_to_str(name, sizeof(name), vnode->addr, 0);
- fd = connect_to(name, vnode->port);
+ addr_to_str(name, sizeof(name), vnode->nid.addr, 0);
+ fd = connect_to(name, vnode->nid.port);
if (fd < 0) {
fprintf(stderr, "failed to connect to %s:%"PRIu32"\n",
- name, vnode->port);
+ name, vnode->nid.port);
exit(EXIT_FAILURE);
}
@@ -1370,11 +1370,11 @@ static void write_object_to(struct sd_vnode *vnode, uint64_t oid, void *buf)
unsigned wlen = SD_DATA_OBJ_SIZE, rlen = 0;
char name[128];
- addr_to_str(name, sizeof(name), vnode->addr, 0);
- fd = connect_to(name, vnode->port);
+ addr_to_str(name, sizeof(name), vnode->nid.addr, 0);
+ fd = connect_to(name, vnode->nid.port);
if (fd < 0) {
fprintf(stderr, "failed to connect to %s:%"PRIu32"\n",
- name, vnode->port);
+ name, vnode->nid.port);
exit(EXIT_FAILURE);
}
diff --git a/include/sheep.h b/include/sheep.h
index 7fbc26d..d26daae 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -147,16 +147,19 @@ struct sd_node_rsp {
uint64_t store_free;
};
+struct node_id {
+ uint8_t addr[16];
+ uint16_t port;
+};
+
struct sd_node {
- uint8_t addr[16];
- uint16_t port;
+ struct node_id nid;
uint16_t nr_vnodes;
uint32_t zone;
};
struct sd_vnode {
- uint8_t addr[16];
- uint16_t port;
+ struct node_id nid;
uint16_t node_idx;
uint32_t zone;
uint64_t id;
@@ -187,8 +190,8 @@ struct trace_graph_item {
static inline int same_node(struct sd_vnode *e, int n1, int n2)
{
- if (memcmp(e[n1].addr, e[n2].addr, sizeof(e->addr)) == 0 &&
- e[n1].port == e[n2].port)
+ if (memcmp(e[n1].nid.addr, e[n2].nid.addr, sizeof(e->nid.addr)) == 0 &&
+ e[n1].nid.port == e[n2].nid.port)
return 1;
return 0;
@@ -332,13 +335,13 @@ static inline int vnode_node_cmp(const void *a, const void *b)
const struct sd_node *node2 = b;
int cmp;
- cmp = memcmp(node1->addr, node2->addr, sizeof(node1->addr));
+ cmp = memcmp(node1->nid.addr, node2->nid.addr, sizeof(node1->nid.addr));
if (cmp != 0)
return cmp;
- if (node1->port < node2->port)
+ if (node1->nid.port < node2->nid.port)
return -1;
- if (node1->port > node2->port)
+ if (node1->nid.port > node2->nid.port)
return 1;
return 0;
}
@@ -349,13 +352,13 @@ static inline int node_cmp(const void *a, const void *b)
const struct sd_node *node2 = b;
int cmp;
- cmp = memcmp(node1->addr, node2->addr, sizeof(node1->addr));
+ cmp = memcmp(node1->nid.addr, node2->nid.addr, sizeof(node1->nid.addr));
if (cmp != 0)
return cmp;
- if (node1->port < node2->port)
+ if (node1->nid.port < node2->nid.port)
return -1;
- if (node1->port > node2->port)
+ if (node1->nid.port > node2->nid.port)
return 1;
return 0;
}
@@ -389,13 +392,13 @@ static inline int nodes_to_vnodes(struct sd_node *nodes, int nr,
for (i = 0; i < n->nr_vnodes; i++) {
if (vnodes) {
- hval = fnv_64a_buf(&n->port, sizeof(n->port), hval);
- for (j = ARRAY_SIZE(n->addr) - 1; j >= 0; j--)
- hval = fnv_64a_buf(&n->addr[j], 1, hval);
+ hval = fnv_64a_buf(&n->nid.port, sizeof(n->nid.port), hval);
+ for (j = ARRAY_SIZE(n->nid.addr) - 1; j >= 0; j--)
+ hval = fnv_64a_buf(&n->nid.addr[j], 1, hval);
vnodes[nr_vnodes].id = hval;
- memcpy(vnodes[nr_vnodes].addr, n->addr, sizeof(n->addr));
- vnodes[nr_vnodes].port = n->port;
+ memcpy(vnodes[nr_vnodes].nid.addr, n->nid.addr, sizeof(n->nid.addr));
+ vnodes[nr_vnodes].nid.port = n->nid.port;
vnodes[nr_vnodes].node_idx = n - nodes;
vnodes[nr_vnodes].zone = n->zone;
}
diff --git a/sheep/cluster.h b/sheep/cluster.h
index 58b7eeb..153e33f 100644
--- a/sheep/cluster.h
+++ b/sheep/cluster.h
@@ -153,7 +153,7 @@ static inline char *node_to_str(struct sd_node *id)
static char str[256];
char name[256];
int af = AF_INET6;
- uint8_t *addr = id->addr;
+ uint8_t *addr = id->nid.addr;
/* Find address family type */
if (addr[12]) {
@@ -166,7 +166,7 @@ static inline char *node_to_str(struct sd_node *id)
snprintf(str, sizeof(str), "%s ip:%s port:%d",
(af == AF_INET) ? "IPv4" : "IPv6",
- addr_to_str(name, sizeof(name), id->addr, 0), id->port);
+ addr_to_str(name, sizeof(name), id->nid.addr, 0), id->nid.port);
return str;
}
@@ -177,12 +177,12 @@ static inline struct sd_node *str_to_node(const char *str, struct sd_node *id)
char v[8], ip[256];
sscanf(str, "%s ip:%s port:%d", v, ip, &port);
- id->port = port;
+ id->nid.port = port;
if (strcmp(v, "IPv4") == 0)
af = AF_INET;
- if (!str_to_addr(af, ip, id->addr))
+ if (!str_to_addr(af, ip, id->nid.addr))
return NULL;
return id;
diff --git a/sheep/gateway.c b/sheep/gateway.c
index ccae1b3..b0f190c 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -63,7 +63,7 @@ read_remote:
if (vnode_is_local(v))
continue;
- fd = sheep_get_fd(v, &sock_idx);
+ fd = sheep_get_fd(&v->nid, &sock_idx);
if (fd < 0) {
ret = SD_RES_NETWORK_ERROR;
continue;
@@ -76,11 +76,11 @@ read_remote:
if (ret) {
dprintf("remote node might be crashed");
- sheep_del_fd(v, fd, sock_idx);
+ sheep_del_fd(&v->nid, fd, sock_idx);
ret = SD_RES_NETWORK_ERROR;
goto reset;
}
- sheep_put_fd(v, fd, sock_idx);
+ sheep_put_fd(&v->nid, fd, sock_idx);
memcpy(&req->rp, rsp, sizeof(*rsp));
ret = rsp->result;
if (ret == SD_RES_SUCCESS)
@@ -114,14 +114,14 @@ static inline void update_write_info(struct write_info *wi, int pos)
static inline void finish_one_write(struct write_info *wi, int i)
{
- sheep_put_fd(wi->vnodes[i], wi->pfds[i].fd,
+ sheep_put_fd(&wi->vnodes[i]->nid, wi->pfds[i].fd,
wi->sock_idx[i]);
update_write_info(wi, i);
}
static inline void finish_one_write_err(struct write_info *wi, int i)
{
- sheep_del_fd(wi->vnodes[i], wi->pfds[i].fd,
+ sheep_del_fd(&wi->vnodes[i]->nid, wi->pfds[i].fd,
wi->sock_idx[i]);
update_write_info(wi, i);
}
@@ -232,7 +232,7 @@ int forward_write_obj_req(struct request *req)
if (vnode_is_local(v))
continue;
- fd = sheep_get_fd(v, &wi.sock_idx[wi.nr_sent]);
+ fd = sheep_get_fd(&v->nid, &wi.sock_idx[wi.nr_sent]);
if (fd < 0) {
err_ret = SD_RES_NETWORK_ERROR;
break;
@@ -240,7 +240,7 @@ int forward_write_obj_req(struct request *req)
ret = send_req(fd, &fwd_hdr, req->data, &wlen);
if (ret) {
- sheep_del_fd(v, fd, wi.sock_idx[wi.nr_sent]);
+ sheep_del_fd(&v->nid, fd, wi.sock_idx[wi.nr_sent]);
err_ret = SD_RES_NETWORK_ERROR;
dprintf("fail %d\n", ret);
break;
diff --git a/sheep/group.c b/sheep/group.c
index 19d5f40..39e2a50 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -686,19 +686,19 @@ static int get_vdi_bitmap_from(struct sd_node *node)
unsigned int rlen, wlen;
char host[128];
- if (is_myself(node->addr, node->port))
+ if (is_myself(node->nid.addr, node->nid.port))
goto out;
- addr_to_str(host, sizeof(host), node->addr, 0);
+ addr_to_str(host, sizeof(host), node->nid.addr, 0);
- fd = connect_to(host, node->port);
+ fd = connect_to(host, node->nid.port);
if (fd < 0) {
vprintf(SDOG_ERR, "unable to get the VDI bitmap from %s: %m\n", host);
ret = -SD_RES_EIO;
goto out;
}
- vprintf(SDOG_ERR, "%s:%d\n", host, node->port);
+ vprintf(SDOG_ERR, "%s:%d\n", host, node->nid.port);
memset(&hdr, 0, sizeof(hdr));
hdr.opcode = SD_OP_READ_VDIS;
@@ -871,7 +871,7 @@ static void update_cluster_info(struct join_message *msg,
sys_stat_set(SD_STATUS_OK);
}
- sockfd_cache_add(joined);
+ sockfd_cache_add(&joined->nid);
}
/*
@@ -889,7 +889,7 @@ void sd_notify_handler(struct sd_node *sender, void *data, size_t data_len)
dprintf("size: %zd, from: %s\n", data_len, node_to_str(sender));
- if (is_myself(sender->addr, sender->port)) {
+ if (is_myself(sender->nid.addr, sender->nid.port)) {
req = list_first_entry(&sys->pending_list, struct request,
pending_list);
list_del(&req->pending_list);
@@ -952,7 +952,7 @@ enum cluster_join_result sd_check_join_cb(struct sd_node *joining, void *opaque)
jm->ctime, jm->epoch,
&jm->cluster_status, &jm->inc_epoch);
eprintf("%s: ret = 0x%x, cluster_status = 0x%x\n",
- addr_to_str(str, sizeof(str), joining->addr, joining->port),
+ addr_to_str(str, sizeof(str), joining->nid.addr, joining->nid.port),
ret, jm->cluster_status);
jm->nr_copies = sys->nr_copies;
@@ -1116,7 +1116,7 @@ void sd_leave_handler(struct sd_node *left, struct sd_node *members,
sys_stat_set(SD_STATUS_HALT);
}
- sockfd_cache_del((struct node_id *)left);
+ sockfd_cache_del(&left->nid);
}
int create_cluster(int port, int64_t zone, int nr_vnodes,
@@ -1141,18 +1141,18 @@ int create_cluster(int port, int64_t zone, int nr_vnodes,
if (!explicit_addr) {
if (sys->cdrv->get_local_addr)
- ret = sys->cdrv->get_local_addr(sys->this_node.addr);
+ ret = sys->cdrv->get_local_addr(sys->this_node.nid.addr);
else
- ret = get_local_addr(sys->this_node.addr);
+ ret = get_local_addr(sys->this_node.nid.addr);
if (ret < 0)
return -1;
}
- sys->this_node.port = port;
+ sys->this_node.nid.port = port;
sys->this_node.nr_vnodes = nr_vnodes;
if (zone == -1) {
/* use last 4 bytes as zone id */
- uint8_t *b = sys->this_node.addr + 12;
+ uint8_t *b = sys->this_node.nid.addr + 12;
sys->this_node.zone = b[0] | b[1] << 8 | b[2] << 16 | b[3] << 24;
} else
sys->this_node.zone = zone;
diff --git a/sheep/ops.c b/sheep/ops.c
index 6bdcc83..55978f4 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -572,7 +572,7 @@ static int read_copy_from_replica(struct vnode_info *vnodes, uint32_t epoch,
struct siocb iocb;
v = obj_vnodes[i];
- addr_to_str(name, sizeof(name), v->addr, 0);
+ addr_to_str(name, sizeof(name), v->nid.addr, 0);
if (vnode_is_local(v)) {
memset(&iocb, 0, sizeof(iocb));
@@ -603,9 +603,9 @@ static int read_copy_from_replica(struct vnode_info *vnodes, uint32_t epoch,
continue;
v = obj_vnodes[j];
- addr_to_str(name, sizeof(name), v->addr, 0);
+ addr_to_str(name, sizeof(name), v->nid.addr, 0);
- fd = connect_to(name, v->port);
+ fd = connect_to(name, v->nid.port);
if (fd < 0)
continue;
diff --git a/sheep/recovery.c b/sheep/recovery.c
index a434ee9..0fafea8 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -93,11 +93,11 @@ static int recover_object_from_replica(uint64_t oid,
}
}
- addr_to_str(name, sizeof(name), entry->addr, 0);
- fd = connect_to(name, entry->port);
- dprintf("%s, %d\n", name, entry->port);
+ addr_to_str(name, sizeof(name), entry->nid.addr, 0);
+ fd = connect_to(name, entry->nid.port);
+ dprintf("%s, %d\n", name, entry->nid.port);
if (fd < 0) {
- eprintf("failed to connect to %s:%"PRIu32"\n", name, entry->port);
+ eprintf("failed to connect to %s:%"PRIu32"\n", name, entry->nid.port);
ret = -1;
goto out;
}
@@ -467,13 +467,13 @@ static int fetch_object_list(struct sd_node *e, uint32_t epoch,
struct sd_list_req hdr;
struct sd_list_rsp *rsp;
- addr_to_str(name, sizeof(name), e->addr, 0);
+ addr_to_str(name, sizeof(name), e->nid.addr, 0);
- dprintf("%s %"PRIu32"\n", name, e->port);
+ dprintf("%s %"PRIu32"\n", name, e->nid.port);
- fd = connect_to(name, e->port);
+ fd = connect_to(name, e->nid.port);
if (fd < 0) {
- eprintf("%s %"PRIu32"\n", name, e->port);
+ eprintf("%s %"PRIu32"\n", name, e->nid.port);
return -1;
}
diff --git a/sheep/sheep.c b/sheep/sheep.c
index a2cd43e..f197a38 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -148,7 +148,7 @@ int main(int argc, char **argv)
break;
case 'y':
af = strstr(optarg, ":") ? AF_INET6 : AF_INET;
- if (!str_to_addr(af, optarg, sys->this_node.addr)) {
+ if (!str_to_addr(af, optarg, sys->this_node.nid.addr)) {
fprintf(stderr,
"Invalid address: '%s'\n",
optarg);
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 747599c..a71abfb 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -322,14 +322,14 @@ int jrnl_recover(const char *jrnl_dir);
static inline int is_myself(uint8_t *addr, uint16_t port)
{
- return (memcmp(addr, sys->this_node.addr,
- sizeof(sys->this_node.addr)) == 0) &&
- port == sys->this_node.port;
+ return (memcmp(addr, sys->this_node.nid.addr,
+ sizeof(sys->this_node.nid.addr)) == 0) &&
+ port == sys->this_node.nid.port;
}
static inline int vnode_is_local(struct sd_vnode *v)
{
- return is_myself(v->addr, v->port);
+ return is_myself(v->nid.addr, v->nid.port);
}
/* Cluster status/flag helper */
@@ -402,14 +402,12 @@ void object_cache_delete(uint32_t vid);
int object_cache_init(const char *p);
/* sockfd_cache */
-struct node_id;
-
void sockfd_cache_del(struct node_id *);
-void sockfd_cache_add(struct sd_node *);
+void sockfd_cache_add(struct node_id *);
void sockfd_cache_add_group(struct sd_node *nodes, int nr);
-int sheep_get_fd(struct sd_vnode *vnode, int *);
-void sheep_put_fd(struct sd_vnode *vnode, int fd, int);
-void sheep_del_fd(struct sd_vnode *vnode, int fd, int);
+int sheep_get_fd(struct node_id *, int *);
+void sheep_put_fd(struct node_id *, int fd, int);
+void sheep_del_fd(struct node_id *, int fd, int);
#endif
diff --git a/sheep/sockfd_cache.c b/sheep/sockfd_cache.c
index 61b5595..372ec58 100644
--- a/sheep/sockfd_cache.c
+++ b/sheep/sockfd_cache.c
@@ -38,11 +38,6 @@
#include "logger.h"
#include "util.h"
-struct node_id {
- uint8_t addr[16];
- uint16_t port;
-};
-
struct sockfd_cache {
struct rb_root root;
pthread_rwlock_t lock;
@@ -261,20 +256,18 @@ static void sockfd_cache_add_nolock(struct node_id *nid)
void sockfd_cache_add_group(struct sd_node *nodes, int nr)
{
struct sd_node *p;
- struct node_id *nid;
dprintf("%d\n", nr);
pthread_rwlock_wrlock(&sockfd_cache.lock);
while (nr--) {
p = nodes + nr;
- nid = (struct node_id *)p;
- sockfd_cache_add_nolock(nid);
+ sockfd_cache_add_nolock(&p->nid);
}
pthread_rwlock_unlock(&sockfd_cache.lock);
}
/* Add one node to the cache means we can do caching tricks on this node */
-void sockfd_cache_add(struct sd_node *node)
+void sockfd_cache_add(struct node_id *nid)
{
struct sockfd_cache_entry *new = xzalloc(sizeof(*new));
char name[INET6_ADDRSTRLEN];
@@ -283,7 +276,7 @@ void sockfd_cache_add(struct sd_node *node)
for (i = 0; i < SOCKFD_CACHE_MAX_FD; i++)
new->fd[i] = -1;
- memcpy(&new->nid, node, sizeof(struct node_id));
+ memcpy(&new->nid, nid, sizeof(struct node_id));
pthread_rwlock_rdlock(&sockfd_cache.lock);
if (sockfd_cache_insert(new)) {
free(new);
@@ -292,8 +285,8 @@ void sockfd_cache_add(struct sd_node *node)
}
pthread_rwlock_unlock(&sockfd_cache.lock);
n = uatomic_add_return(&sockfd_cache.count, 1);
- addr_to_str(name, sizeof(name), node->addr, 0);
- dprintf("%s:%d, count %d\n", name, node->port, n);
+ addr_to_str(name, sizeof(name), nid->addr, 0);
+ dprintf("%s:%d, count %d\n", name, nid->port, n);
}
static int sockfd_cache_get(struct node_id *nid, char *name, int *ret_idx)
@@ -349,9 +342,8 @@ static void sockfd_cache_put(struct node_id *nid, int idx)
*
* ret_idx is opaque to the caller, -1 indicates it is a short FD.
*/
-int sheep_get_fd(struct sd_vnode *vnode, int *ret_idx)
+int sheep_get_fd(struct node_id *nid, int *ret_idx)
{
- struct node_id *nid = (struct node_id *)vnode;
char name[INET6_ADDRSTRLEN];
int fd;
@@ -380,10 +372,8 @@ int sheep_get_fd(struct sd_vnode *vnode, int *ret_idx)
* sheep_put_fd() or sheep_del_fd() should be paired with sheep_get_fd()
*/
-void sheep_put_fd(struct sd_vnode *vnode, int fd, int idx)
+void sheep_put_fd(struct node_id *nid, int fd, int idx)
{
- struct node_id *nid = (struct node_id *)vnode;
-
if (idx == -1) {
dprintf("%d\n", fd);
close(fd);
@@ -400,10 +390,8 @@ void sheep_put_fd(struct sd_vnode *vnode, int fd, int idx)
* this vnode in the cache.
* If it is a short FD, just close it.
*/
-void sheep_del_fd(struct sd_vnode *vnode, int fd, int idx)
+void sheep_del_fd(struct node_id *nid, int fd, int idx)
{
- struct node_id *nid = (struct node_id *)vnode;
-
if (idx == -1) {
dprintf("%d\n", fd);
close(fd);
diff --git a/sheep/store.c b/sheep/store.c
index d5a080b..17067c4 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -131,11 +131,11 @@ int epoch_log_read_remote(uint32_t epoch, struct sd_node *nodes, int len)
unsigned int rlen, wlen;
int fd;
- if (is_myself(local_nodes[i].addr, local_nodes[i].port))
+ if (is_myself(local_nodes[i].nid.addr, local_nodes[i].nid.port))
continue;
- addr_to_str(host, sizeof(host), local_nodes[i].addr, 0);
- fd = connect_to(host, local_nodes[i].port);
+ addr_to_str(host, sizeof(host), local_nodes[i].nid.addr, 0);
+ fd = connect_to(host, local_nodes[i].nid.port);
if (fd < 0) {
vprintf(SDOG_ERR, "failed to connect to %s: %m\n", host);
continue;
@@ -610,9 +610,9 @@ int remove_object(struct vnode_info *vnodes, uint32_t epoch,
int fd, ret;
v = obj_vnodes[i];
- addr_to_str(name, sizeof(name), v->addr, 0);
+ addr_to_str(name, sizeof(name), v->nid.addr, 0);
- fd = connect_to(name, v->port);
+ fd = connect_to(name, v->nid.port);
if (fd < 0) {
rsp->result = SD_RES_NETWORK_ERROR;
return -1;
--
1.7.10.2
More information about the sheepdog
mailing list