[sheepdog] [PATCH v2 09/15] sheepfs: implement 'open' operation
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Sun May 20 12:07:24 CEST 2012
At Mon, 14 May 2012 17:47:34 +0800,
Liu Yuan wrote:
>
> 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 | 6 ++++++
> 3 files changed, 23 insertions(+), 1 deletions(-)
>
> diff --git a/sheepfs/core.c b/sheepfs/core.c
> index bda043f..0298ee8 100644
> --- a/sheepfs/core.c
> +++ b/sheepfs/core.c
> @@ -47,13 +47,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)
> @@ -184,6 +185,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,
> @@ -191,6 +203,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 c84b0a6..17c2e9b 100644
> --- a/sheepfs/volume.c
> +++ b/sheepfs/volume.c
> @@ -256,6 +256,12 @@ int volume_sync(const char *path)
> return 0;
> }
>
> +int volume_open(const char *path, struct fuse_file_info *fi)
> +{
> + //fi->direct_io = 1;
Don't use a "//" comment. This line is removed in the later patch,
though.
Thanks,
Kazutaka
> + 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