[sheepdog] [PATCH v4 2/2] collie: let collie use sockfd cache
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Thu Jul 25 08:43:55 CEST 2013
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
v4:
- remove the redundant function, collie_exec_req_nid()
collie/collie.c | 9 +++++++++
collie/collie.h | 2 ++
collie/common.c | 24 ++++++++++++++----------
3 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/collie/collie.c b/collie/collie.c
index 2f8e9d0..60e6fe7 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -17,6 +17,7 @@
#include "sheep.h"
#include "collie.h"
#include "util.h"
+#include "sockfd_cache.h"
#define EPOLL_SIZE 4096
@@ -345,6 +346,7 @@ int main(int argc, char **argv)
const char *short_options;
char *p;
const struct sd_option *sd_opts;
+ struct work_queue *sockfd_wq;
install_crash_handler(crash_handler);
@@ -418,6 +420,13 @@ int main(int argc, char **argv)
exit(EXIT_SYSFAIL);
}
+ sockfd_wq = create_ordered_work_queue("sockfd");
+ if (!sockfd_wq) {
+ fprintf(stderr, "Failed to create workqueue for sockfd\n");
+ exit(EXIT_SYSFAIL);
+ }
+ init_sockfd(sockfd_wq);
+
ret = command_fn(argc, argv);
if (ret == EXIT_USAGE)
subcommand_usage(argv[1], argv[2], EXIT_USAGE);
diff --git a/collie/collie.h b/collie/collie.h
index 7f5c128..8426f99 100644
--- a/collie/collie.h
+++ b/collie/collie.h
@@ -74,6 +74,8 @@ int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data,
unsigned int datalen, uint64_t offset, uint32_t flags,
int copies, bool create, bool direct);
int collie_exec_req(const char *host, int port, struct sd_req *hdr, void *data);
+int collie_exec_req_nid(const struct node_id *nid,
+ struct sd_req *hdr, void *buf);
int send_light_req(struct sd_req *hdr, const char *host, int port);
int do_generic_subcommand(struct subcommand *sub, int argc, char **argv);
int update_node_list(int max_nodes);
diff --git a/collie/common.c b/collie/common.c
index b2b9fb1..2aca7bd 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -11,6 +11,7 @@
#include "collie.h"
#include "sha1.h"
+#include "sockfd_cache.h"
char *size_to_str(uint64_t _size, char *str, int str_size)
{
@@ -169,13 +170,18 @@ out:
return ret;
}
-int collie_exec_req(const char *host, int port, struct sd_req *hdr, void *data)
+int collie_exec_req(const char *host, int port, struct sd_req *hdr, void *buf)
{
- int fd, ret;
- struct sd_rsp *rsp = (struct sd_rsp *)hdr;
+ struct node_id nid;
+ struct sockfd *sfd;
+ int ret;
+
+ memset(&nid, 0, sizeof(nid));
+ str_to_addr(host, nid.addr);
+ nid.port = port;
- fd = connect_to(host, port);
- if (fd < 0)
+ sfd = sockfd_cache_get(&nid);
+ if (!sfd)
return -1;
/*
@@ -183,13 +189,11 @@ int collie_exec_req(const char *host, int port, struct sd_req *hdr, void *data)
* 1. We can't get the newest epoch
* 2. Some operations might take unexpected long time
*/
- ret = exec_req(fd, hdr, data, NULL, 0, UINT32_MAX);
- close(fd);
+ ret = exec_req(sfd->fd, hdr, buf, NULL, 0, UINT32_MAX);
- if (ret)
- return -1;
+ sockfd_cache_put(&nid, sfd);
- return rsp->result;
+ return ret;
}
/* Light request only contains header, without body content. */
--
1.7.10.4
More information about the sheepdog
mailing list