]> git.proxmox.com Git - pve-cluster.git/blob - data/src/cfs-plug.h
ac12ad6c1d8853ac6101ab42e6c0933a0965ae75
[pve-cluster.git] / data / src / cfs-plug.h
1 /*
2 Copyright (C) 2010 Proxmox Server Solutions GmbH
3
4 This software is written by Proxmox Server Solutions GmbH <support@proxmox.com>
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Affero General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 Author: Dietmar Maurer <dietmar@proxmox.com>
20
21 */
22
23 #ifndef _PVE_CFS_PLUG_H_
24 #define _PVE_CFS_PLUG_H_
25
26 #define FUSE_USE_VERSION 26
27
28 #include <errno.h>
29 #include <fuse.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <unistd.h>
33
34 #define PARAM_CHECK_ERRNO -EREMOTEIO
35
36 typedef struct cfs_plug cfs_plug_t;
37
38 struct cfs_operations {
39 int (*getattr) (cfs_plug_t *, const char *, struct stat *);
40 int (*readlink) (cfs_plug_t *, const char *, char *, size_t);
41 int (*mkdir) (cfs_plug_t *, const char *, mode_t);
42 int (*unlink) (cfs_plug_t *, const char *);
43 int (*rmdir) (cfs_plug_t *, const char *);
44 int (*rename) (cfs_plug_t *, const char *, const char *);
45 int (*truncate) (cfs_plug_t *, const char *, off_t);
46 int (*open) (cfs_plug_t *, const char *, struct fuse_file_info *);
47 int (*read) (cfs_plug_t *, const char *, char *, size_t, off_t,
48 struct fuse_file_info *);
49 int (*write) (cfs_plug_t *, const char *, const char *, size_t, off_t,
50 struct fuse_file_info *);
51 int (*readdir) (cfs_plug_t *, const char *, void *, fuse_fill_dir_t, off_t,
52 struct fuse_file_info *);
53 int (*create) (cfs_plug_t *, const char *, mode_t, struct fuse_file_info *);
54 int (*utimens) (cfs_plug_t *, const char *, const struct timespec tv[2]);
55 int (*statfs) (cfs_plug_t *, const char *, struct statvfs *);
56 };
57
58 struct cfs_plug {
59 struct cfs_operations *ops;
60 cfs_plug_t *(*lookup_plug)(cfs_plug_t *plug, char **path);
61 void (*destroy_plug) (cfs_plug_t *plug);
62 void (*start_workers) (cfs_plug_t *plug);
63 void (*stop_workers) (cfs_plug_t *plug);
64
65 char *name;
66 };
67
68 typedef struct {
69 cfs_plug_t plug;
70 cfs_plug_t *base;
71 GHashTable *entries;
72 } cfs_plug_base_t;
73
74 typedef struct {
75 cfs_plug_t plug;
76 char *symlink;
77 } cfs_plug_link_t;
78
79 typedef char *(*cfs_plug_func_udpate_data_fn_t)(cfs_plug_t *plug);
80 typedef int (*cfs_plug_func_write_data_fn_t)(
81 cfs_plug_t *plug,
82 const char *buf,
83 size_t size);
84
85 typedef struct {
86 cfs_plug_t plug;
87 char *data;
88 GRWLock data_rw_lock;
89 mode_t mode;
90 cfs_plug_func_udpate_data_fn_t update_callback;
91 cfs_plug_func_write_data_fn_t write_callback;
92 } cfs_plug_func_t;
93
94 cfs_plug_base_t *cfs_plug_base_new(const char *name, cfs_plug_t *base);
95 void cfs_plug_base_insert(cfs_plug_base_t *base, cfs_plug_t *sub);
96
97 cfs_plug_link_t *cfs_plug_link_new(const char *name, const char *symlink);
98 cfs_plug_func_t *cfs_plug_func_new(
99 const char *name,
100 mode_t mode,
101 cfs_plug_func_udpate_data_fn_t update_callback,
102 cfs_plug_func_write_data_fn_t write_callback);
103
104
105 #endif /* _PVE_CFS_PLUG_H_ */