[sheepdog] [PATCH v3 09/15] sheepfs: implement 'open' operation

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


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

This is useful to control whether we use page cache or not.

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

diff --git a/sheepfs/core.c b/sheepfs/core.c
index 6e2570c..7da6674 100644
--- a/sheepfs/core.c
+++ b/sheepfs/core.c
@@ -46,13 +46,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)
@@ -183,6 +184,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,
@@ -190,6 +202,7 @@ struct fuse_operations sheepfs_ops =  {
 	.read     = sheepfs_read,
 	.write    = sheepfs_write,
 	.fsync    = sheepfs_fsync,
+	.open     = sheepfs_open,
 };
 
 static int sheepfs_main_loop(char *mountpoint)
diff --git a/sheepfs/sheepfs.h b/sheepfs/sheepfs.h
index 563d3c3..e0be541 100644
--- a/sheepfs/sheepfs.h
+++ b/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,
@@ -33,6 +35,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/sheepfs/volume.c b/sheepfs/volume.c
index 060a0f3..94f35b4 100644
--- a/sheepfs/volume.c
+++ b/sheepfs/volume.c
@@ -261,6 +261,11 @@ int volume_sync(const char *path)
 	return 0;
 }
 
+int volume_open(const char *path, struct fuse_file_info *fi)
+{
+	return 0;
+}
+
 static int init_vdi_info(const char *entry, uint32_t *vid, size_t *size)
 {
 	struct strbuf *buf;
-- 
1.7.10.2




More information about the sheepdog mailing list