[sheepdog] [PATCH 2/3] sheep: remove vnode info leak in cluster_make_fs()

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Wed Jan 14 06:23:22 CET 2015


The commit 5fed9d696c70 introduced change of cluster_make_fs() and the
change had vnode info leak.

Cc: Saeki Masaki <saeki.masaki at po.ntts.co.jp>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 sheep/ops.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/sheep/ops.c b/sheep/ops.c
index dad03a6..b6ce84f 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -291,7 +291,7 @@ static int get_vnodes(struct vnode_info *vinfo, int *nr_vnodes)
 static int cluster_make_fs(const struct sd_req *req, struct sd_rsp *rsp,
 			   void *data, const struct sd_node *sender)
 {
-	int i, ret;
+	int i, ret = SD_RES_SUCCESS;
 	uint32_t latest_epoch;
 	struct store_driver *driver;
 	char *store_name = data;
@@ -299,8 +299,10 @@ static int cluster_make_fs(const struct sd_req *req, struct sd_rsp *rsp,
 	struct vnode_info *vinfo = get_vnode_info();
 
 	driver = find_store_driver(data);
-	if (!driver)
-		return SD_RES_NO_STORE;
+	if (!driver) {
+		ret = SD_RES_NO_STORE;
+		goto out;
+	}
 
 	pstrcpy((char *)sys->cinfo.store, sizeof(sys->cinfo.store),
 		store_name);
@@ -309,16 +311,16 @@ static int cluster_make_fs(const struct sd_req *req, struct sd_rsp *rsp,
 
 	ret = sd_store->format();
 	if (ret != SD_RES_SUCCESS)
-		return ret;
+		goto out;
 
 	ret = sd_store->init();
 	if (ret != SD_RES_SUCCESS)
-		return ret;
+		goto out;
 
 	if (sys->gateway_only) {
 		ret = get_vnodes(vinfo, &nr_vnodes);
 		if (ret != SD_RES_SUCCESS)
-			return ret;
+			goto out;
 	}
 
 	sys->cinfo.nr_copies = req->cluster.copies;
@@ -342,12 +344,16 @@ static int cluster_make_fs(const struct sd_req *req, struct sd_rsp *rsp,
 	sys->cinfo.epoch = 0;
 
 	ret = inc_and_log_epoch();
-	if (ret)
-		return SD_RES_EIO;
+	if (ret) {
+		ret = SD_RES_EIO;
+		goto out;
+	}
 
 	sys->cinfo.status = SD_STATUS_OK;
 
-	return SD_RES_SUCCESS;
+out:
+	put_vnode_info(vinfo);
+	return ret;
 }
 
 static int cluster_shutdown(const struct sd_req *req, struct sd_rsp *rsp,
-- 
1.9.1




More information about the sheepdog mailing list