xref: /qemu/fsdev/file-op-9p.h (revision 727385c4)
1 /*
2  * 9p
3  *
4  * Copyright IBM, Corp. 2010
5  *
6  * Authors:
7  *  Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  *
12  */
13 
14 #ifndef FILE_OP_9P_H
15 #define FILE_OP_9P_H
16 
17 #include <dirent.h>
18 #include <utime.h>
19 #include <sys/vfs.h>
20 #include "qemu-fsdev-throttle.h"
21 #include "p9array.h"
22 
23 #define SM_LOCAL_MODE_BITS    0600
24 #define SM_LOCAL_DIR_MODE_BITS    0700
25 
26 typedef struct FsCred {
27     uid_t   fc_uid;
28     gid_t   fc_gid;
29     mode_t  fc_mode;
30     dev_t   fc_rdev;
31 } FsCred;
32 
33 typedef struct FsContext FsContext;
34 typedef struct V9fsPath V9fsPath;
35 
36 typedef struct ExtendedOps {
37     int (*get_st_gen)(FsContext *, V9fsPath *, mode_t, uint64_t *);
38 } ExtendedOps;
39 
40 /* export flags */
41 #define V9FS_IMMEDIATE_WRITEOUT     0x00000001
42 #define V9FS_PATHNAME_FSCONTEXT     0x00000002
43 /*
44  * uid/gid set on fileserver files
45  */
46 #define V9FS_SM_PASSTHROUGH         0x00000004
47 /*
48  * uid/gid part of xattr
49  */
50 #define V9FS_SM_MAPPED              0x00000008
51 /*
52  * Server will try to set uid/gid.
53  * On failure ignore the error.
54  */
55 #define V9FS_SM_NONE                0x00000010
56 /*
57  * uid/gid part of .virtfs_meatadata namespace
58  */
59 #define V9FS_SM_MAPPED_FILE         0x00000020
60 #define V9FS_RDONLY                 0x00000040
61 #define V9FS_PROXY_SOCK_FD          0x00000080
62 #define V9FS_PROXY_SOCK_NAME        0x00000100
63 /*
64  * multidevs option (either one of the two applies exclusively)
65  */
66 #define V9FS_REMAP_INODES           0x00000200
67 #define V9FS_FORBID_MULTIDEVS       0x00000400
68 /*
69  * Disables certain performance warnings from being logged on host side.
70  */
71 #define V9FS_NO_PERF_WARN           0x00000800
72 
73 #define V9FS_SEC_MASK               0x0000003C
74 
75 
76 typedef struct FileOperations FileOperations;
77 typedef struct XattrOperations XattrOperations;
78 
79 /*
80  * Structure to store the various fsdev's passed through command line.
81  */
82 typedef struct FsDriverEntry {
83     char *fsdev_id;
84     char *path;
85     int export_flags;
86     FileOperations *ops;
87     FsThrottle fst;
88     mode_t fmode;
89     mode_t dmode;
90 } FsDriverEntry;
91 
92 struct FsContext {
93     uid_t uid;
94     char *fs_root;
95     int export_flags;
96     XattrOperations **xops;
97     ExtendedOps exops;
98     FsThrottle *fst;
99     /* fs driver specific data */
100     void *private;
101     mode_t fmode;
102     mode_t dmode;
103 };
104 
105 struct V9fsPath {
106     uint16_t size;
107     char *data;
108 };
109 P9ARRAY_DECLARE_TYPE(V9fsPath);
110 
111 typedef union V9fsFidOpenState V9fsFidOpenState;
112 
113 void cred_init(FsCred *);
114 
115 struct FileOperations {
116     int (*parse_opts)(QemuOpts *, FsDriverEntry *, Error **errp);
117     int (*init)(FsContext *, Error **errp);
118     void (*cleanup)(FsContext *);
119     int (*lstat)(FsContext *, V9fsPath *, struct stat *);
120     ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t);
121     int (*chmod)(FsContext *, V9fsPath *, FsCred *);
122     int (*chown)(FsContext *, V9fsPath *, FsCred *);
123     int (*mknod)(FsContext *, V9fsPath *, const char *, FsCred *);
124     int (*utimensat)(FsContext *, V9fsPath *, const struct timespec *);
125     int (*remove)(FsContext *, const char *);
126     int (*symlink)(FsContext *, const char *, V9fsPath *,
127                    const char *, FsCred *);
128     int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *);
129     int (*setuid)(FsContext *, uid_t);
130     int (*close)(FsContext *, V9fsFidOpenState *);
131     int (*closedir)(FsContext *, V9fsFidOpenState *);
132     int (*opendir)(FsContext *, V9fsPath *, V9fsFidOpenState *);
133     int (*open)(FsContext *, V9fsPath *, int, V9fsFidOpenState *);
134     int (*open2)(FsContext *, V9fsPath *, const char *,
135                  int, FsCred *, V9fsFidOpenState *);
136     void (*rewinddir)(FsContext *, V9fsFidOpenState *);
137     off_t (*telldir)(FsContext *, V9fsFidOpenState *);
138     struct dirent * (*readdir)(FsContext *, V9fsFidOpenState *);
139     void (*seekdir)(FsContext *, V9fsFidOpenState *, off_t);
140     ssize_t (*preadv)(FsContext *, V9fsFidOpenState *,
141                       const struct iovec *, int, off_t);
142     ssize_t (*pwritev)(FsContext *, V9fsFidOpenState *,
143                        const struct iovec *, int, off_t);
144     int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *);
145     int (*fstat)(FsContext *, int, V9fsFidOpenState *, struct stat *);
146     int (*rename)(FsContext *, const char *, const char *);
147     int (*truncate)(FsContext *, V9fsPath *, off_t);
148     int (*fsync)(FsContext *, int, V9fsFidOpenState *, int);
149     int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf);
150     ssize_t (*lgetxattr)(FsContext *, V9fsPath *,
151                          const char *, void *, size_t);
152     ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t);
153     int (*lsetxattr)(FsContext *, V9fsPath *,
154                      const char *, void *, size_t, int);
155     int (*lremovexattr)(FsContext *, V9fsPath *, const char *);
156     int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *);
157     int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name,
158                     V9fsPath *newdir, const char *new_name);
159     int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags);
160 };
161 
162 #endif
163