[sheepdog] [PATCH 5/6] sheep: use wrappers for handling EMFILE

Hitoshi Mitake mitake.hitoshi at gmail.com
Tue Aug 13 18:27:40 CEST 2013


Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 sheep/md.c           |  2 +-
 sheep/object_cache.c | 10 +++++-----
 sheep/plain_store.c  |  4 ++--
 sheep/request.c      |  4 ++--
 sheep/store.c        |  2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/sheep/md.c b/sheep/md.c
index dd2bba5..fcdbea4 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -492,7 +492,7 @@ static int md_move_object(uint64_t oid, char *old, char *new)
 	int fd, ret = -1;
 	size_t sz = get_objsize(oid);
 
-	fd = open(old, O_RDONLY);
+	fd = xopen(old, O_RDONLY);
 	if (fd < 0) {
 		sd_err("failed to open %s", old);
 		goto out;
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 1f8822e..761ba95 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -348,7 +348,7 @@ static int read_cache_object_noupdate(uint32_t vid, uint32_t idx, void *buf,
 		flags |= O_DIRECT;
 	}
 
-	fd = open(p, flags, sd_def_fmode);
+	fd = xopen(p, flags, sd_def_fmode);
 	if (unlikely(fd < 0)) {
 		sd_err("%m");
 		ret = SD_RES_EIO;
@@ -384,7 +384,7 @@ static int write_cache_object_noupdate(uint32_t vid, uint32_t idx, void *buf,
 		flags |= O_DIRECT;
 	}
 
-	fd = open(p, flags, sd_def_fmode);
+	fd = xopen(p, flags, sd_def_fmode);
 	if (unlikely(fd < 0)) {
 		sd_err("%m");
 		ret = SD_RES_EIO;
@@ -653,7 +653,7 @@ not_found:
 		cache->vid = vid;
 		INIT_RB_ROOT(&cache->lru_tree);
 		create_dir_for(vid);
-		cache->push_efd = eventfd(0, 0);
+		cache->push_efd = xeventfd(0, 0);
 
 		INIT_LIST_HEAD(&cache->dirty_head);
 		INIT_LIST_HEAD(&cache->lru_head);
@@ -752,7 +752,7 @@ static int object_cache_lookup(struct object_cache *oc, uint32_t idx,
 		return lookup_path(path);
 
 	flags |= O_CREAT | O_TRUNC;
-	fd = open(path, flags, sd_def_fmode);
+	fd = xopen(path, flags, sd_def_fmode);
 	if (unlikely(fd < 0)) {
 		sd_debug("%s, %m", path);
 		ret = SD_RES_EIO;
@@ -781,7 +781,7 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx,
 
 	snprintf(tmp_path, sizeof(tmp_path), "%s/%06"PRIx32"/%08"PRIx32".tmp",
 		object_cache_dir, oc->vid, idx);
-	fd = open(tmp_path, flags, sd_def_fmode);
+	fd = xopen(tmp_path, flags, sd_def_fmode);
 	if (fd < 0) {
 		if (likely(errno == EEXIST)) {
 			sd_debug("%08"PRIx32" already created", idx);
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index c9a077e..acb017f 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -116,7 +116,7 @@ int default_write(uint64_t oid, const struct siocb *iocb)
 
 	get_obj_path(oid, path);
 
-	fd = open(path, flags, sd_def_fmode);
+	fd = xopen(path, flags, sd_def_fmode);
 	if (unlikely(fd < 0))
 		return err_to_sderr(path, oid, errno);
 
@@ -235,7 +235,7 @@ static int default_read_from_path(uint64_t oid, char *path,
 	    ret = SD_RES_SUCCESS;
 	ssize_t size;
 
-	fd = open(path, flags);
+	fd = xopen(path, flags);
 
 	if (fd < 0)
 		return err_to_sderr(path, oid, errno);
diff --git a/sheep/request.c b/sheep/request.c
index bd69ea9..6eaa36d 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -439,7 +439,7 @@ worker_fn int exec_local_req(struct sd_req *rq, void *data)
 
 	req = alloc_local_request(data, rq->data_length);
 	req->rq = *rq;
-	req->local_req_efd = eventfd(0, 0);
+	req->local_req_efd = xeventfd(0, 0);
 	if (req->local_req_efd < 0) {
 		/* Fake the result to ask for retry */
 		req->rp.result = SD_RES_NETWORK_ERROR;
@@ -810,7 +810,7 @@ static void listen_handler(int listen_fd, int events, void *data)
 	}
 
 	namesize = sizeof(from);
-	fd = accept(listen_fd, (struct sockaddr *)&from, &namesize);
+	fd = xaccept(listen_fd, (struct sockaddr *)&from, &namesize);
 	if (fd < 0) {
 		sd_err("failed to accept a new connection: %m");
 		return;
diff --git a/sheep/store.c b/sheep/store.c
index f4343b3..f6923bf 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -49,7 +49,7 @@ static int do_epoch_log_read(uint32_t epoch, struct sd_node *nodes, int len,
 	struct stat epoch_stat;
 
 	snprintf(path, sizeof(path), "%s%08u", epoch_path, epoch);
-	fd = open(path, O_RDONLY);
+	fd = xopen(path, O_RDONLY);
 	if (fd < 0) {
 		sd_err("failed to open epoch %"PRIu32" log, %m", epoch);
 		goto err;
-- 
1.8.1.2




More information about the sheepdog mailing list