[sheepdog] [PATCH v3 11/15] sheepfs: add 'node' entry

Liu Yuan namei.unix at gmail.com
Mon May 21 17:25:55 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

Support vdi node list & info.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/ops.c         |    8 ++---
 sheepfs/Makefile.am |    2 +-
 sheepfs/core.c      |    4 +++
 sheepfs/node.c      |   84 +++++++++++++++++++++++++++++++++++++++++++++++++++
 sheepfs/sheepfs.h   |    9 ++++++
 sheepfs/volume.c    |   18 +++++------
 6 files changed, 110 insertions(+), 15 deletions(-)
 create mode 100644 sheepfs/node.c

diff --git a/sheep/ops.c b/sheep/ops.c
index 7ffa7db..7206b3e 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -605,16 +605,14 @@ static int local_flush_vdi(struct request *req)
 	return SD_RES_SUCCESS;
 }
 
-static int local_flush_and_del(const struct sd_req *req, struct sd_rsp *rsp,
-				void *data)
+static int local_flush_and_del(struct request *req)
 {
-	struct sd_obj_req *hdr = (struct sd_obj_req *)req;
-	uint64_t oid = hdr->oid;
+	uint64_t oid = req->rq.obj.oid;
 	uint32_t vid = oid_to_vid(oid);
 	struct object_cache *cache = find_object_cache(vid, 0);
 
 	if (cache)
-		if (object_cache_flush_and_delete(cache) < 0)
+		if (object_cache_flush_and_delete(req->vnodes, cache) < 0)
 			return SD_RES_EIO;
 
 	return SD_RES_SUCCESS;
diff --git a/sheepfs/Makefile.am b/sheepfs/Makefile.am
index c451b86..1204559 100644
--- a/sheepfs/Makefile.am
+++ b/sheepfs/Makefile.am
@@ -23,7 +23,7 @@ INCLUDES		= -I$(top_builddir)/include -I$(top_srcdir)/include
 
 sbin_PROGRAMS		= sheepfs
 
-sheepfs_SOURCES		= core.c cluster.c vdi.c shadow_file.c volume.c
+sheepfs_SOURCES		= core.c cluster.c vdi.c shadow_file.c volume.c node.c
 
 sheepfs_LDADD	  	= ../lib/libsheepdog.a $(fuse_LIBS) $(LIBS)
 sheepfs_DEPENDENCIES	= ../lib/libsheepdog.a
diff --git a/sheepfs/core.c b/sheepfs/core.c
index 9e24e20..a24d0c2 100644
--- a/sheepfs/core.c
+++ b/sheepfs/core.c
@@ -53,6 +53,8 @@ static struct sheepfs_file_operation {
 	[OP_VDI_LIST]     = { vdi_list_read, NULL, vdi_list_get_size },
 	[OP_VDI_MOUNT]    = { NULL, vdi_mount_write },
 	[OP_VDI_UNMOUNT]  = { NULL, vdi_unmount_write },
+	[OP_NODE_INFO]    = { node_info_read, NULL, node_info_get_size },
+	[OP_NODE_LIST]    = { node_list_read, NULL, node_list_get_size },
 	[OP_VOLUME]       = { volume_read, volume_write, volume_get_size,
 			      volume_sync, volume_open },
 };
@@ -236,6 +238,8 @@ static int create_sheepfs_layout(void)
 		return -1;
 	if (create_volume_layout() < 0)
 		return -1;
+	if (create_node_layout() < 0)
+		return -1;
 
 	return 0;
 }
diff --git a/sheepfs/node.c b/sheepfs/node.c
new file mode 100644
index 0000000..fcc490f
--- /dev/null
+++ b/sheepfs/node.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2012 Taobao Inc.
+ *
+ * Liu Yuan <namei.unix at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <syslog.h>
+
+#include "strbuf.h"
+#include "sheepfs.h"
+#include "net.h"
+
+#define PATH_NODE	"/node"
+#define PATH_NODE_INFO	"/node/info"
+#define PATH_NODE_LIST	"/node/list"
+
+
+int create_node_layout(void)
+{
+	if (shadow_dir_create(PATH_NODE) < 0)
+		return -1;
+
+	if (shadow_file_create(PATH_NODE_INFO) < 0)
+		return -1;
+	if (sheepfs_set_op(PATH_NODE_INFO, OP_NODE_INFO) < 0)
+		return -1;
+
+	if (shadow_file_create(PATH_NODE_LIST) < 0)
+		return -1;
+	if (sheepfs_set_op(PATH_NODE_LIST, OP_NODE_LIST) < 0)
+		return -1;
+
+	return 0;
+}
+
+int node_info_read(const char *path, char *buf, size_t size, off_t ignore)
+{
+	return shadow_file_read(path, buf, size, 0);
+}
+
+size_t node_info_get_size(const char *path)
+{
+	struct strbuf *buf = sheepfs_run_cmd("collie node info");
+	size_t len;
+
+	if (!buf)
+		return 0;
+
+	len = shadow_file_write(path, buf->buf, buf->len);
+	strbuf_release(buf);
+	return len;
+}
+
+int node_list_read(const char *path, char *buf, size_t size, off_t ignore)
+{
+	return shadow_file_read(path, buf, size, 0);
+}
+
+size_t node_list_get_size(const char *path)
+{
+	struct strbuf *buf = sheepfs_run_cmd("collie node list");
+	size_t len;
+
+	if (!buf)
+		return 0;
+
+	len = shadow_file_write(path, buf->buf, buf->len);
+	strbuf_release(buf);
+	return len;
+}
diff --git a/sheepfs/sheepfs.h b/sheepfs/sheepfs.h
index 9e2d4bc..a744c07 100644
--- a/sheepfs/sheepfs.h
+++ b/sheepfs/sheepfs.h
@@ -9,6 +9,8 @@ enum sheepfs_opcode {
 	OP_VDI_LIST,
 	OP_VDI_MOUNT,
 	OP_VDI_UNMOUNT,
+	OP_NODE_INFO,
+	OP_NODE_LIST,
 	OP_VOLUME,
 };
 
@@ -52,4 +54,11 @@ extern size_t vdi_list_get_size(const char *path);
 extern int vdi_mount_write(const char *, const char *buf, size_t size, off_t);
 extern int vdi_unmount_write(const char *, const char *buf, size_t, off_t);
 
+/* node.c */
+extern int node_list_read(const char *path, char *buf, size_t size, off_t);
+extern size_t node_list_get_size(const char *path);
+extern int node_info_read(const char *path, char *buf, size_t size, off_t);
+extern size_t node_info_get_size(const char *path);
+extern int create_node_layout(void);
+
 #endif
diff --git a/sheepfs/volume.c b/sheepfs/volume.c
index 8905c63..e51b1f7 100644
--- a/sheepfs/volume.c
+++ b/sheepfs/volume.c
@@ -184,7 +184,7 @@ static int volume_do_rw(const char *path, char *buf, size_t size,
 		len = size;
 
 	do {
-		syslog(LOG_ERR, "%s oid %"PRIx64", off %ju, len %zu,"
+		syslog(LOG_INFO, "%s oid %"PRIx64", off %ju, len %zu,"
 			" size %zu\n",
 			rw == VOLUME_READ ? "read" : "write",
 			oid, start, len, size);
@@ -230,15 +230,15 @@ size_t volume_get_size(const char *path)
 
 static int volume_do_sync(uint32_t vid)
 {
-	struct sd_obj_req hdr = { 0 };
-	struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr;
+	struct sd_req hdr = { 0 };
+	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	int ret;
 	unsigned wlen = 0, rlen = 0;
 
 	hdr.opcode = SD_OP_FLUSH_VDI;
-	hdr.oid = vid_to_vdi_oid(vid);
+	hdr.obj.oid = vid_to_vdi_oid(vid);
 
-	ret = exec_req(0, (struct sd_req *)&hdr, NULL, &wlen, &rlen);
+	ret = exec_req(0, &hdr, NULL, &wlen, &rlen);
 
 	if (ret || rsp->result != SD_RES_SUCCESS) {
 		syslog(LOG_ERR, "[%s] failed to flush vdi %"PRIx32"\n",
@@ -346,15 +346,15 @@ int volume_create_entry(const char *entry)
 
 static int volume_sync_and_delete(uint32_t vid)
 {
-	struct sd_obj_req hdr = { 0 };
-	struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr;
+	struct sd_req hdr = { 0 };
+	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	int ret;
 	unsigned wlen = 0, rlen = 0;
 
 	hdr.opcode = SD_OP_FLUSH_DEL_CACHE;
-	hdr.oid = vid_to_vdi_oid(vid);
+	hdr.obj.oid = vid_to_vdi_oid(vid);
 
-	ret = exec_req(0, (struct sd_req *)&hdr, NULL, &wlen, &rlen);
+	ret = exec_req(0, &hdr, NULL, &wlen, &rlen);
 
 	if (ret || rsp->result != SD_RES_SUCCESS) {
 		syslog(LOG_ERR, "[%s] failed to flush vdi %" PRIx32 "\n",
-- 
1.7.10.2




More information about the sheepdog mailing list