[Sheepdog] [PATCH RFC 08/10] sheepfs: implement 'open' operation

Liu Yuan namei.unix at gmail.com
Sat May 5 13:29:20 CEST 2012


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


Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/sheepfs/core.c    |   15 ++++++++++++++-
 sheep/sheepfs/sheepfs.h |    3 +++
 sheep/sheepfs/volume.c  |    7 +++++++
 3 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/sheep/sheepfs/core.c b/sheep/sheepfs/core.c
index 612a36b..04fb934 100644
--- a/sheep/sheepfs/core.c
+++ b/sheep/sheepfs/core.c
@@ -21,13 +21,14 @@ static struct sheepfs_file_operation {
 	int (*write)(const char *path, const char *buf, size_t size, off_t);
 	size_t (*get_size)(const char *path);
 	int (*sync)(const char *path);
+	int (*open)(const char *paht, struct fuse_file_info *);
 } sheepfs_file_ops[] = {
 	[OP_NULL]         = { NULL, NULL, NULL },
 	[OP_CLUSTER_INFO] = { cluster_info_read, NULL, cluster_info_get_size },
 	[OP_VDI_LIST]     = { vdi_list_read, NULL, vdi_list_get_size },
 	[OP_VDI_MOUNT]    = { NULL, vdi_mount_write, NULL },
 	[OP_VOLUME]       = { volume_read, volume_write, volume_get_size,
-			      volume_sync },
+			      volume_sync, volume_open },
 };
 
 int sheepfs_set_op(const char *path, unsigned opcode)
@@ -158,6 +159,17 @@ static int sheepfs_fsync(const char *path, int datasync,
 	return ret;
 }
 
+static int sheepfs_open(const char *path, struct fuse_file_info *fi)
+{
+	int ret = 0;
+	unsigned op = sheepfs_get_op(path);
+
+	if (sheepfs_file_ops[op].open)
+		ret = sheepfs_file_ops[op].open(path, fi);
+
+	return ret;
+}
+
 struct fuse_operations sheepfs_ops =  {
 	.getattr  = sheepfs_getattr,
 	.readdir  = sheepfs_readdir,
@@ -165,6 +177,7 @@ struct fuse_operations sheepfs_ops =  {
 	.read     = sheepfs_read,
 	.write    = sheepfs_write,
 	.fsync    = sheepfs_fsync,
+	.open     = sheepfs_open,
 };
 
 static void sheepfs_main_loop(char *root)
diff --git a/sheep/sheepfs/sheepfs.h b/sheep/sheepfs/sheepfs.h
index faef834..a307bc5 100644
--- a/sheep/sheepfs/sheepfs.h
+++ b/sheep/sheepfs/sheepfs.h
@@ -1,6 +1,8 @@
 #ifndef SHEEPFS_H
 #define SHEEPFS_H
 
+#include <fuse.h>
+
 enum sheepfs_opcode {
 	OP_NULL = 0,
 	OP_CLUSTER_INFO,
@@ -35,6 +37,7 @@ extern int volume_write(const char *, const char *buf, size_t size, off_t);
 extern size_t volume_get_size(const char *);
 extern int volume_create_entry(const char *entry);
 extern int volume_sync(const char *path);
+extern int volume_open(const char *path, struct fuse_file_info *);
 
 /* cluster.c */
 extern int cluster_info_read(const char *path, char *buf, size_t size, off_t);
diff --git a/sheep/sheepfs/volume.c b/sheep/sheepfs/volume.c
index 17edf4c..f9d33e5 100644
--- a/sheep/sheepfs/volume.c
+++ b/sheep/sheepfs/volume.c
@@ -244,6 +244,13 @@ int volume_sync(const char *path)
 	return 0;
 }
 
+int volume_open(const char *path, struct fuse_file_info *fi)
+{
+	/* our pseudo block file need this flag to function correctly */
+	fi->direct_io = 1;
+	return 0;
+}
+
 static int init_vdi_info(const char *entry, uint32_t *vid, size_t *size)
 {
 	struct strbuf *buf;
-- 
1.7.8.2




More information about the sheepdog mailing list