| 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 "qemu-fsdev-throttle.h" |
| 20 | #include "p9array.h" |
| 21 | |
| 22 | #ifdef CONFIG_LINUX |
| 23 | # include <sys/vfs.h> |
| 24 | #elif defined(CONFIG_DARWIN) || defined(CONFIG_FREEBSD) |
| 25 | # include <sys/param.h> |
| 26 | # ifdef CONFIG_FREEBSD |
| 27 | # undef MACHINE /* work around some unfortunate namespace pollution */ |
| 28 | # endif |
| 29 | # include <sys/mount.h> |
| 30 | #endif |
| 31 | |
| 32 | #define SM_LOCAL_MODE_BITS 0600 |
| 33 | #define SM_LOCAL_DIR_MODE_BITS 0700 |
| 34 | |
| 35 | typedef struct FsCred { |
| 36 | uid_t fc_uid; |
| 37 | gid_t fc_gid; |
| 38 | mode_t fc_mode; |
| 39 | dev_t fc_rdev; |
| 40 | } FsCred; |
| 41 | |
| 42 | typedef struct FsContext FsContext; |
| 43 | typedef struct V9fsPath V9fsPath; |
| 44 | |
| 45 | typedef struct ExtendedOps { |
| 46 | int (*get_st_gen)(FsContext *, V9fsPath *, mode_t, uint64_t *); |
| 47 | } ExtendedOps; |
| 48 | |
| 49 | /* export flags */ |
| 50 | #define V9FS_IMMEDIATE_WRITEOUT 0x00000001 |
| 51 | #define V9FS_PATHNAME_FSCONTEXT 0x00000002 |
| 52 | /* |
| 53 | * uid/gid set on fileserver files |
| 54 | */ |
| 55 | #define V9FS_SM_PASSTHROUGH 0x00000004 |
| 56 | /* |
| 57 | * uid/gid part of xattr |
| 58 | */ |
| 59 | #define V9FS_SM_MAPPED 0x00000008 |
| 60 | /* |
| 61 | * Server will try to set uid/gid. |
| 62 | * On failure ignore the error. |
| 63 | */ |
| 64 | #define V9FS_SM_NONE 0x00000010 |
| 65 | /* |
| 66 | * uid/gid part of .virtfs_meatadata namespace |
| 67 | */ |
| 68 | #define V9FS_SM_MAPPED_FILE 0x00000020 |
| 69 | #define V9FS_RDONLY 0x00000040 |
| 70 | #define V9FS_PROXY_SOCK_FD 0x00000080 |
| 71 | #define V9FS_PROXY_SOCK_NAME 0x00000100 |
| 72 | /* |
| 73 | * multidevs option (either one of the two applies exclusively) |
| 74 | */ |
| 75 | #define V9FS_REMAP_INODES 0x00000200 |
| 76 | #define V9FS_FORBID_MULTIDEVS 0x00000400 |
| 77 | /* |
| 78 | * Disables certain performance warnings from being logged on host side. |
| 79 | */ |
| 80 | #define V9FS_NO_PERF_WARN 0x00000800 |
| 81 | |
| 82 | #define V9FS_SEC_MASK 0x0000003C |
| 83 | |
| 84 | /* |
| 85 | * Limits the maximum amount of simultaneously open xattr FIDs to prevent |
| 86 | * host memory exhaustion (as each xattr FID contains a xattr value buffer). |
| 87 | */ |
| 88 | #define V9FS_MAX_XATTR_DEFAULT 1024 |
| 89 | |
| 90 | typedef struct FileOperations FileOperations; |
| 91 | typedef struct XattrOperations XattrOperations; |
| 92 | |
| 93 | /* |
| 94 | * Structure to store the various fsdev's passed through command line. |
| 95 | */ |
| 96 | typedef struct FsDriverEntry { |
| 97 | char *fsdev_id; |
| 98 | char *path; |
| 99 | int export_flags; |
| 100 | FileOperations *ops; |
| 101 | FsThrottle fst; |
| 102 | mode_t fmode; |
| 103 | mode_t dmode; |
| 104 | /* temporary storage for parse_opts only */ |
| 105 | uint32_t max_xattr; |
| 106 | } FsDriverEntry; |
| 107 | |
| 108 | struct FsContext { |
| 109 | uid_t uid; |
| 110 | char *fs_root; |
| 111 | int export_flags; |
| 112 | XattrOperations **xops; |
| 113 | ExtendedOps exops; |
| 114 | FsThrottle *fst; |
| 115 | /* fs driver specific data */ |
| 116 | void *private; |
| 117 | mode_t fmode; |
| 118 | mode_t dmode; |
| 119 | /* max. amount of simultaneously open xattr FIDs */ |
| 120 | uint32_t xattr_fid_limit; |
| 121 | /* current amount of open xattr FIDs */ |
| 122 | uint32_t xattr_fid_count; |
| 123 | }; |
| 124 | |
| 125 | struct V9fsPath { |
| 126 | size_t size; |
| 127 | char *data; |
| 128 | }; |
| 129 | P9ARRAY_DECLARE_TYPE(V9fsPath); |
| 130 | |
| 131 | typedef union V9fsFidOpenState V9fsFidOpenState; |
| 132 | |
| 133 | void cred_init(FsCred *); |
| 134 | |
| 135 | struct FileOperations { |
| 136 | int (*parse_opts)(QemuOpts *, FsDriverEntry *, Error **errp); |
| 137 | int (*init)(FsContext *, Error **errp); |
| 138 | void (*cleanup)(FsContext *); |
| 139 | int (*lstat)(FsContext *, V9fsPath *, struct stat *); |
| 140 | ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t); |
| 141 | int (*chmod)(FsContext *, V9fsPath *, FsCred *); |
| 142 | int (*chown)(FsContext *, V9fsPath *, FsCred *); |
| 143 | int (*mknod)(FsContext *, V9fsPath *, const char *, FsCred *); |
| 144 | int (*utimensat)(FsContext *, V9fsPath *, const struct timespec *); |
| 145 | int (*futimens)(FsContext *ctx, int fid_type, V9fsFidOpenState *fs, |
| 146 | const struct timespec *times); |
| 147 | int (*remove)(FsContext *, const char *); |
| 148 | int (*symlink)(FsContext *, const char *, V9fsPath *, |
| 149 | const char *, FsCred *); |
| 150 | int (*link)(FsContext *, V9fsPath *, V9fsPath *, const char *); |
| 151 | int (*setuid)(FsContext *, uid_t); |
| 152 | int (*close)(FsContext *, V9fsFidOpenState *); |
| 153 | int (*closedir)(FsContext *, V9fsFidOpenState *); |
| 154 | int (*opendir)(FsContext *, V9fsPath *, V9fsFidOpenState *); |
| 155 | int (*open)(FsContext *, V9fsPath *, int, V9fsFidOpenState *); |
| 156 | int (*open2)(FsContext *, V9fsPath *, const char *, |
| 157 | int, FsCred *, V9fsFidOpenState *); |
| 158 | void (*rewinddir)(FsContext *, V9fsFidOpenState *); |
| 159 | off_t (*telldir)(FsContext *, V9fsFidOpenState *); |
| 160 | struct dirent * (*readdir)(FsContext *, V9fsFidOpenState *); |
| 161 | void (*seekdir)(FsContext *, V9fsFidOpenState *, off_t); |
| 162 | ssize_t (*preadv)(FsContext *, V9fsFidOpenState *, |
| 163 | const struct iovec *, int, off_t); |
| 164 | ssize_t (*pwritev)(FsContext *, V9fsFidOpenState *, |
| 165 | const struct iovec *, int, off_t); |
| 166 | int (*mkdir)(FsContext *, V9fsPath *, const char *, FsCred *); |
| 167 | int (*fstat)(FsContext *, int, V9fsFidOpenState *, struct stat *); |
| 168 | int (*rename)(FsContext *, const char *, const char *); |
| 169 | int (*truncate)(FsContext *, V9fsPath *, off_t); |
| 170 | int (*ftruncate)(FsContext *ctx, int fid_type, V9fsFidOpenState *fs, |
| 171 | off_t size); |
| 172 | int (*fsync)(FsContext *, int, V9fsFidOpenState *, int); |
| 173 | int (*statfs)(FsContext *s, V9fsPath *path, struct statfs *stbuf); |
| 174 | ssize_t (*lgetxattr)(FsContext *, V9fsPath *, |
| 175 | const char *, void *, size_t); |
| 176 | ssize_t (*llistxattr)(FsContext *, V9fsPath *, void *, size_t); |
| 177 | int (*lsetxattr)(FsContext *, V9fsPath *, |
| 178 | const char *, void *, size_t, int); |
| 179 | int (*lremovexattr)(FsContext *, V9fsPath *, const char *); |
| 180 | int (*name_to_path)(FsContext *, V9fsPath *, const char *, V9fsPath *); |
| 181 | int (*renameat)(FsContext *ctx, V9fsPath *olddir, const char *old_name, |
| 182 | V9fsPath *newdir, const char *new_name); |
| 183 | int (*unlinkat)(FsContext *ctx, V9fsPath *dir, const char *name, int flags); |
| 184 | bool (*has_valid_file_handle)(int fid_type, V9fsFidOpenState *fs); |
| 185 | }; |
| 186 | |
| 187 | #endif |