[Sheepdog] [PATCH v2 11/15] sheepfs: add 'node' entry
Liu Yuan
namei.unix at gmail.com
Mon May 14 11:47:36 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>
---
sheepfs/Makefile.am | 2 +-
sheepfs/core.c | 4 ++
sheepfs/node.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++
sheepfs/sheepfs.h | 9 +++++
sheepfs/volume.c | 2 +-
5 files changed, 99 insertions(+), 2 deletions(-)
create mode 100644 sheepfs/node.c
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 4ff60cf..869baac 100644
--- a/sheepfs/core.c
+++ b/sheepfs/core.c
@@ -54,6 +54,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 },
};
@@ -237,6 +239,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 2a6ba4c..f9b4dfc 100644
--- a/sheepfs/volume.c
+++ b/sheepfs/volume.c
@@ -179,7 +179,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);
--
1.7.8.2
More information about the sheepdog
mailing list