Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | d713311 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 3 | Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu> |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 4 | |
| 5 | This program can be distributed under the terms of the GNU GPL. |
| 6 | See the file COPYING. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/fuse.h> |
| 10 | #include <linux/fs.h> |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 11 | #include <linux/mount.h> |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 12 | #include <linux/wait.h> |
| 13 | #include <linux/list.h> |
| 14 | #include <linux/spinlock.h> |
| 15 | #include <linux/mm.h> |
| 16 | #include <linux/backing-dev.h> |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 17 | #include <linux/mutex.h> |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 18 | #include <linux/rwsem.h> |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 19 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 20 | /** Max number of pages that can be used in a single read request */ |
| 21 | #define FUSE_MAX_PAGES_PER_REQ 32 |
| 22 | |
Miklos Szeredi | 08a53cd | 2006-04-10 22:54:59 -0700 | [diff] [blame] | 23 | /** Maximum number of outstanding background requests */ |
Miklos Szeredi | f92b99b | 2007-10-16 23:30:59 -0700 | [diff] [blame] | 24 | #define FUSE_MAX_BACKGROUND 12 |
| 25 | |
| 26 | /** Congestion starts at 75% of maximum */ |
| 27 | #define FUSE_CONGESTION_THRESHOLD (FUSE_MAX_BACKGROUND * 75 / 100) |
Miklos Szeredi | 08a53cd | 2006-04-10 22:54:59 -0700 | [diff] [blame] | 28 | |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 29 | /** Bias for fi->writectr, meaning new writepages must not be sent */ |
| 30 | #define FUSE_NOWRITE INT_MIN |
| 31 | |
Miklos Szeredi | 1d3d752 | 2006-01-06 00:19:40 -0800 | [diff] [blame] | 32 | /** It could be as large as PATH_MAX, but would that have any uses? */ |
| 33 | #define FUSE_NAME_MAX 1024 |
| 34 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 35 | /** Number of dentries for each connection in the control filesystem */ |
| 36 | #define FUSE_CTL_NUM_DENTRIES 3 |
| 37 | |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 38 | /** If the FUSE_DEFAULT_PERMISSIONS flag is given, the filesystem |
| 39 | module will check permissions based on the file mode. Otherwise no |
| 40 | permission checking is done in the kernel */ |
| 41 | #define FUSE_DEFAULT_PERMISSIONS (1 << 0) |
| 42 | |
| 43 | /** If the FUSE_ALLOW_OTHER flag is given, then not only the user |
| 44 | doing the mount will be allowed to access the filesystem */ |
| 45 | #define FUSE_ALLOW_OTHER (1 << 1) |
| 46 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 47 | /** List of active connections */ |
| 48 | extern struct list_head fuse_conn_list; |
| 49 | |
| 50 | /** Global mutex protecting fuse_conn_list and the control filesystem */ |
| 51 | extern struct mutex fuse_mutex; |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 52 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 53 | /** FUSE inode */ |
| 54 | struct fuse_inode { |
| 55 | /** Inode data */ |
| 56 | struct inode inode; |
| 57 | |
| 58 | /** Unique ID, which identifies the inode between userspace |
| 59 | * and kernel */ |
| 60 | u64 nodeid; |
| 61 | |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 62 | /** Number of lookups on this inode */ |
| 63 | u64 nlookup; |
| 64 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 65 | /** The request used for sending the FORGET message */ |
| 66 | struct fuse_req *forget_req; |
| 67 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 68 | /** Time in jiffies until the file attributes are valid */ |
Miklos Szeredi | 0a0898c | 2006-07-30 03:04:10 -0700 | [diff] [blame] | 69 | u64 i_time; |
Miklos Szeredi | ebc14c4 | 2007-10-16 23:31:03 -0700 | [diff] [blame] | 70 | |
| 71 | /** The sticky bit in inode->i_mode may have been removed, so |
| 72 | preserve the original mode */ |
| 73 | mode_t orig_i_mode; |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 74 | |
| 75 | /** Version of last attribute change */ |
| 76 | u64 attr_version; |
Miklos Szeredi | 93a8c3c | 2007-10-18 03:07:03 -0700 | [diff] [blame] | 77 | |
| 78 | /** Files usable in writepage. Protected by fc->lock */ |
| 79 | struct list_head write_files; |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 80 | |
| 81 | /** Writepages pending on truncate or fsync */ |
| 82 | struct list_head queued_writes; |
| 83 | |
| 84 | /** Number of sent writes, a negative bias (FUSE_NOWRITE) |
| 85 | * means more writes are blocked */ |
| 86 | int writectr; |
| 87 | |
| 88 | /** Waitq for writepage completion */ |
| 89 | wait_queue_head_t page_waitq; |
| 90 | |
| 91 | /** List of writepage requestst (pending or sent) */ |
| 92 | struct list_head writepages; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 95 | /** FUSE specific file data */ |
| 96 | struct fuse_file { |
| 97 | /** Request reserved for flush and release */ |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 98 | struct fuse_req *reserved_req; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 99 | |
| 100 | /** File handle used by userspace */ |
| 101 | u64 fh; |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 102 | |
| 103 | /** Refcount */ |
| 104 | atomic_t count; |
Miklos Szeredi | 93a8c3c | 2007-10-18 03:07:03 -0700 | [diff] [blame] | 105 | |
| 106 | /** Entry on inode's write_files list */ |
| 107 | struct list_head write_entry; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 110 | /** One input argument of a request */ |
| 111 | struct fuse_in_arg { |
| 112 | unsigned size; |
| 113 | const void *value; |
| 114 | }; |
| 115 | |
| 116 | /** The request input */ |
| 117 | struct fuse_in { |
| 118 | /** The request header */ |
| 119 | struct fuse_in_header h; |
| 120 | |
| 121 | /** True if the data for the last argument is in req->pages */ |
| 122 | unsigned argpages:1; |
| 123 | |
| 124 | /** Number of arguments */ |
| 125 | unsigned numargs; |
| 126 | |
| 127 | /** Array of arguments */ |
| 128 | struct fuse_in_arg args[3]; |
| 129 | }; |
| 130 | |
| 131 | /** One output argument of a request */ |
| 132 | struct fuse_arg { |
| 133 | unsigned size; |
| 134 | void *value; |
| 135 | }; |
| 136 | |
| 137 | /** The request output */ |
| 138 | struct fuse_out { |
| 139 | /** Header returned from userspace */ |
| 140 | struct fuse_out_header h; |
| 141 | |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 142 | /* |
| 143 | * The following bitfields are not changed during the request |
| 144 | * processing |
| 145 | */ |
| 146 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 147 | /** Last argument is variable length (can be shorter than |
| 148 | arg->size) */ |
| 149 | unsigned argvar:1; |
| 150 | |
| 151 | /** Last argument is a list of pages to copy data to */ |
| 152 | unsigned argpages:1; |
| 153 | |
| 154 | /** Zero partially or not copied pages */ |
| 155 | unsigned page_zeroing:1; |
| 156 | |
| 157 | /** Number or arguments */ |
| 158 | unsigned numargs; |
| 159 | |
| 160 | /** Array of arguments */ |
| 161 | struct fuse_arg args[3]; |
| 162 | }; |
| 163 | |
Miklos Szeredi | 83cfd49 | 2006-01-16 22:14:31 -0800 | [diff] [blame] | 164 | /** The request state */ |
| 165 | enum fuse_req_state { |
| 166 | FUSE_REQ_INIT = 0, |
| 167 | FUSE_REQ_PENDING, |
| 168 | FUSE_REQ_READING, |
| 169 | FUSE_REQ_SENT, |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame] | 170 | FUSE_REQ_WRITING, |
Miklos Szeredi | 83cfd49 | 2006-01-16 22:14:31 -0800 | [diff] [blame] | 171 | FUSE_REQ_FINISHED |
| 172 | }; |
| 173 | |
Miklos Szeredi | 64c6d8e | 2006-01-16 22:14:42 -0800 | [diff] [blame] | 174 | struct fuse_conn; |
| 175 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 176 | /** |
| 177 | * A request to the client |
| 178 | */ |
| 179 | struct fuse_req { |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 180 | /** This can be on either pending processing or io lists in |
| 181 | fuse_conn */ |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 182 | struct list_head list; |
| 183 | |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame] | 184 | /** Entry on the interrupts list */ |
| 185 | struct list_head intr_entry; |
| 186 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 187 | /** refcount */ |
| 188 | atomic_t count; |
| 189 | |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame] | 190 | /** Unique ID for the interrupt request */ |
| 191 | u64 intr_unique; |
| 192 | |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 193 | /* |
| 194 | * The following bitfields are either set once before the |
| 195 | * request is queued or setting/clearing them is protected by |
Miklos Szeredi | d713311 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 196 | * fuse_conn->lock |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 197 | */ |
| 198 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 199 | /** True if the request has reply */ |
| 200 | unsigned isreply:1; |
| 201 | |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 202 | /** Force sending of the request even if interrupted */ |
| 203 | unsigned force:1; |
| 204 | |
Miklos Szeredi | f9a2842 | 2006-06-25 05:48:53 -0700 | [diff] [blame] | 205 | /** The request was aborted */ |
| 206 | unsigned aborted:1; |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 207 | |
| 208 | /** Request is sent in the background */ |
| 209 | unsigned background:1; |
| 210 | |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame] | 211 | /** The request has been interrupted */ |
| 212 | unsigned interrupted:1; |
| 213 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 214 | /** Data is being copied to/from the request */ |
| 215 | unsigned locked:1; |
| 216 | |
Miklos Szeredi | 9bc5ddd | 2006-04-11 21:16:09 +0200 | [diff] [blame] | 217 | /** Request is counted as "waiting" */ |
| 218 | unsigned waiting:1; |
| 219 | |
Miklos Szeredi | 83cfd49 | 2006-01-16 22:14:31 -0800 | [diff] [blame] | 220 | /** State of the request */ |
| 221 | enum fuse_req_state state; |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 222 | |
| 223 | /** The request input */ |
| 224 | struct fuse_in in; |
| 225 | |
| 226 | /** The request output */ |
| 227 | struct fuse_out out; |
| 228 | |
| 229 | /** Used to wake up the task waiting for completion of request*/ |
| 230 | wait_queue_head_t waitq; |
| 231 | |
| 232 | /** Data for asynchronous requests */ |
| 233 | union { |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 234 | struct fuse_forget_in forget_in; |
Miklos Szeredi | b57d426 | 2008-02-06 01:38:39 -0800 | [diff] [blame] | 235 | struct { |
| 236 | struct fuse_release_in in; |
| 237 | struct vfsmount *vfsmount; |
| 238 | struct dentry *dentry; |
| 239 | } release; |
Miklos Szeredi | 3ec870d | 2006-01-06 00:19:41 -0800 | [diff] [blame] | 240 | struct fuse_init_in init_in; |
| 241 | struct fuse_init_out init_out; |
Miklos Szeredi | 5c5c5e5 | 2008-04-30 00:54:43 -0700 | [diff] [blame] | 242 | struct { |
| 243 | struct fuse_read_in in; |
| 244 | u64 attr_ver; |
| 245 | } read; |
Miklos Szeredi | b25e82e | 2007-10-18 03:07:03 -0700 | [diff] [blame] | 246 | struct { |
| 247 | struct fuse_write_in in; |
| 248 | struct fuse_write_out out; |
| 249 | } write; |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 250 | struct fuse_lk_in lk_in; |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 251 | } misc; |
| 252 | |
| 253 | /** page vector */ |
| 254 | struct page *pages[FUSE_MAX_PAGES_PER_REQ]; |
| 255 | |
| 256 | /** number of pages in vector */ |
| 257 | unsigned num_pages; |
| 258 | |
| 259 | /** offset of data on first page */ |
| 260 | unsigned page_offset; |
| 261 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 262 | /** File used in the request (or NULL) */ |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 263 | struct fuse_file *ff; |
Miklos Szeredi | 64c6d8e | 2006-01-16 22:14:42 -0800 | [diff] [blame] | 264 | |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 265 | /** Inode used in the request or NULL */ |
| 266 | struct inode *inode; |
| 267 | |
| 268 | /** Link on fi->writepages */ |
| 269 | struct list_head writepages_entry; |
| 270 | |
Miklos Szeredi | 64c6d8e | 2006-01-16 22:14:42 -0800 | [diff] [blame] | 271 | /** Request completion callback */ |
| 272 | void (*end)(struct fuse_conn *, struct fuse_req *); |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 273 | |
| 274 | /** Request is stolen from fuse_file->reserved_req */ |
| 275 | struct file *stolen_file; |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 276 | }; |
| 277 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 278 | /** |
| 279 | * A Fuse connection. |
| 280 | * |
| 281 | * This structure is created, when the filesystem is mounted, and is |
| 282 | * destroyed, when the client device is closed and the filesystem is |
| 283 | * unmounted. |
| 284 | */ |
| 285 | struct fuse_conn { |
Miklos Szeredi | d713311 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 286 | /** Lock protecting accessess to members of this structure */ |
| 287 | spinlock_t lock; |
| 288 | |
Miklos Szeredi | d2a8516 | 2006-10-17 00:10:11 -0700 | [diff] [blame] | 289 | /** Mutex protecting against directory alias creation */ |
| 290 | struct mutex inst_mutex; |
| 291 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 292 | /** Refcount */ |
| 293 | atomic_t count; |
| 294 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 295 | /** The user id for this mount */ |
| 296 | uid_t user_id; |
| 297 | |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 298 | /** The group id for this mount */ |
| 299 | gid_t group_id; |
| 300 | |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 301 | /** The fuse mount flags for this mount */ |
| 302 | unsigned flags; |
| 303 | |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 304 | /** Maximum read size */ |
| 305 | unsigned max_read; |
| 306 | |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 307 | /** Maximum write size */ |
| 308 | unsigned max_write; |
| 309 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 310 | /** Readers of the connection are waiting on this */ |
| 311 | wait_queue_head_t waitq; |
| 312 | |
| 313 | /** The list of pending requests */ |
| 314 | struct list_head pending; |
| 315 | |
| 316 | /** The list of requests being processed */ |
| 317 | struct list_head processing; |
| 318 | |
Miklos Szeredi | d77a1d5 | 2006-01-16 22:14:31 -0800 | [diff] [blame] | 319 | /** The list of requests under I/O */ |
| 320 | struct list_head io; |
| 321 | |
Miklos Szeredi | 08a53cd | 2006-04-10 22:54:59 -0700 | [diff] [blame] | 322 | /** Number of requests currently in the background */ |
| 323 | unsigned num_background; |
| 324 | |
Miklos Szeredi | d12def1 | 2008-02-06 01:38:39 -0800 | [diff] [blame] | 325 | /** Number of background requests currently queued for userspace */ |
| 326 | unsigned active_background; |
| 327 | |
| 328 | /** The list of background requests set aside for later queuing */ |
| 329 | struct list_head bg_queue; |
| 330 | |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame] | 331 | /** Pending interrupts */ |
| 332 | struct list_head interrupts; |
| 333 | |
Miklos Szeredi | 08a53cd | 2006-04-10 22:54:59 -0700 | [diff] [blame] | 334 | /** Flag indicating if connection is blocked. This will be |
| 335 | the case before the INIT reply is received, and if there |
| 336 | are too many outstading backgrounds requests */ |
| 337 | int blocked; |
| 338 | |
| 339 | /** waitq for blocked connection */ |
| 340 | wait_queue_head_t blocked_waitq; |
| 341 | |
Miklos Szeredi | de5e3de | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 342 | /** waitq for reserved requests */ |
| 343 | wait_queue_head_t reserved_req_waitq; |
| 344 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 345 | /** The next unique request id */ |
| 346 | u64 reqctr; |
| 347 | |
Miklos Szeredi | 69a53bf | 2006-01-16 22:14:41 -0800 | [diff] [blame] | 348 | /** Connection established, cleared on umount, connection |
| 349 | abort and device release */ |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 350 | unsigned connected; |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 351 | |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 352 | /** Connection failed (version mismatch). Cannot race with |
| 353 | setting other bitfields since it is only set once in INIT |
| 354 | reply, before any other request, and never cleared */ |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 355 | unsigned conn_error : 1; |
| 356 | |
Miklos Szeredi | 0ec7ca4 | 2006-12-06 20:35:52 -0800 | [diff] [blame] | 357 | /** Connection successful. Only set in INIT */ |
| 358 | unsigned conn_init : 1; |
| 359 | |
Miklos Szeredi | 9cd6845 | 2006-02-01 03:04:40 -0800 | [diff] [blame] | 360 | /** Do readpages asynchronously? Only set in INIT */ |
| 361 | unsigned async_read : 1; |
| 362 | |
Miklos Szeredi | 6ff958e | 2007-10-18 03:07:02 -0700 | [diff] [blame] | 363 | /** Do not send separate SETATTR request before open(O_TRUNC) */ |
| 364 | unsigned atomic_o_trunc : 1; |
| 365 | |
Miklos Szeredi | 33670fa | 2008-07-25 01:49:02 -0700 | [diff] [blame] | 366 | /** Filesystem supports NFS exporting. Only set in INIT */ |
| 367 | unsigned export_support : 1; |
| 368 | |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 369 | /* |
| 370 | * The following bitfields are only for optimization purposes |
| 371 | * and hence races in setting them will not cause malfunction |
| 372 | */ |
| 373 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 374 | /** Is fsync not implemented by fs? */ |
| 375 | unsigned no_fsync : 1; |
| 376 | |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 377 | /** Is fsyncdir not implemented by fs? */ |
| 378 | unsigned no_fsyncdir : 1; |
| 379 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 380 | /** Is flush not implemented by fs? */ |
| 381 | unsigned no_flush : 1; |
| 382 | |
Miklos Szeredi | 92a8780 | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 383 | /** Is setxattr not implemented by fs? */ |
| 384 | unsigned no_setxattr : 1; |
| 385 | |
| 386 | /** Is getxattr not implemented by fs? */ |
| 387 | unsigned no_getxattr : 1; |
| 388 | |
| 389 | /** Is listxattr not implemented by fs? */ |
| 390 | unsigned no_listxattr : 1; |
| 391 | |
| 392 | /** Is removexattr not implemented by fs? */ |
| 393 | unsigned no_removexattr : 1; |
| 394 | |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 395 | /** Are file locking primitives not implemented by fs? */ |
| 396 | unsigned no_lock : 1; |
| 397 | |
Miklos Szeredi | 31d40d7 | 2005-11-07 00:59:50 -0800 | [diff] [blame] | 398 | /** Is access not implemented by fs? */ |
| 399 | unsigned no_access : 1; |
| 400 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 401 | /** Is create not implemented by fs? */ |
| 402 | unsigned no_create : 1; |
| 403 | |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame] | 404 | /** Is interrupt not implemented by fs? */ |
| 405 | unsigned no_interrupt : 1; |
| 406 | |
Miklos Szeredi | b2d2272 | 2006-12-06 20:35:51 -0800 | [diff] [blame] | 407 | /** Is bmap not implemented by fs? */ |
| 408 | unsigned no_bmap : 1; |
| 409 | |
Miklos Szeredi | 78bb6cb | 2008-05-12 14:02:32 -0700 | [diff] [blame] | 410 | /** Do multi-page cached writes */ |
| 411 | unsigned big_writes : 1; |
| 412 | |
Miklos Szeredi | 0cd5b88 | 2006-01-16 22:14:38 -0800 | [diff] [blame] | 413 | /** The number of requests waiting for completion */ |
| 414 | atomic_t num_waiting; |
| 415 | |
Miklos Szeredi | 45714d6 | 2006-01-06 00:19:36 -0800 | [diff] [blame] | 416 | /** Negotiated minor version */ |
| 417 | unsigned minor; |
| 418 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 419 | /** Backing dev info */ |
| 420 | struct backing_dev_info bdi; |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 421 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 422 | /** Entry on the fuse_conn_list */ |
| 423 | struct list_head entry; |
| 424 | |
Miklos Szeredi | b6f2fcb | 2008-04-30 00:54:34 -0700 | [diff] [blame] | 425 | /** Device ID from super block */ |
| 426 | dev_t dev; |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 427 | |
| 428 | /** Dentries in the control filesystem */ |
| 429 | struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; |
| 430 | |
| 431 | /** number of dentries used in the above array */ |
| 432 | int ctl_ndents; |
Jeff Dike | 385a17b | 2006-04-10 22:54:52 -0700 | [diff] [blame] | 433 | |
| 434 | /** O_ASYNC requests */ |
| 435 | struct fasync_struct *fasync; |
Miklos Szeredi | 9c8ef56 | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 436 | |
| 437 | /** Key for lock owner ID scrambling */ |
| 438 | u32 scramble_key[4]; |
Miklos Szeredi | 0ec7ca4 | 2006-12-06 20:35:52 -0800 | [diff] [blame] | 439 | |
| 440 | /** Reserved request for the DESTROY message */ |
| 441 | struct fuse_req *destroy_req; |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 442 | |
| 443 | /** Version counter for attribute changes */ |
| 444 | u64 attr_version; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 445 | }; |
| 446 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 447 | static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) |
| 448 | { |
Miklos Szeredi | 6383bda | 2006-01-16 22:14:29 -0800 | [diff] [blame] | 449 | return sb->s_fs_info; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static inline struct fuse_conn *get_fuse_conn(struct inode *inode) |
| 453 | { |
| 454 | return get_fuse_conn_super(inode->i_sb); |
| 455 | } |
| 456 | |
| 457 | static inline struct fuse_inode *get_fuse_inode(struct inode *inode) |
| 458 | { |
| 459 | return container_of(inode, struct fuse_inode, inode); |
| 460 | } |
| 461 | |
| 462 | static inline u64 get_node_id(struct inode *inode) |
| 463 | { |
| 464 | return get_fuse_inode(inode)->nodeid; |
| 465 | } |
| 466 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 467 | /** Device operations */ |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 468 | extern const struct file_operations fuse_dev_operations; |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 469 | |
Miklos Szeredi | dbd561d | 2008-07-25 01:49:00 -0700 | [diff] [blame] | 470 | extern struct dentry_operations fuse_dentry_operations; |
| 471 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 472 | /** |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 473 | * Get a filled in inode |
| 474 | */ |
Miklos Szeredi | b48badf | 2008-04-30 00:54:44 -0700 | [diff] [blame] | 475 | struct inode *fuse_iget(struct super_block *sb, u64 nodeid, |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 476 | int generation, struct fuse_attr *attr, |
| 477 | u64 attr_valid, u64 attr_version); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 478 | |
Miklos Szeredi | 33670fa | 2008-07-25 01:49:02 -0700 | [diff] [blame] | 479 | int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name, |
| 480 | struct fuse_entry_out *outarg, struct inode **inode); |
| 481 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 482 | /** |
| 483 | * Send FORGET command |
| 484 | */ |
| 485 | void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req, |
Miklos Szeredi | b48badf | 2008-04-30 00:54:44 -0700 | [diff] [blame] | 486 | u64 nodeid, u64 nlookup); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 487 | |
| 488 | /** |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 489 | * Initialize READ or READDIR request |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 490 | */ |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 491 | void fuse_read_fill(struct fuse_req *req, struct file *file, |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 492 | struct inode *inode, loff_t pos, size_t count, int opcode); |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 493 | |
| 494 | /** |
| 495 | * Send OPEN or OPENDIR request |
| 496 | */ |
| 497 | int fuse_open_common(struct inode *inode, struct file *file, int isdir); |
| 498 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 499 | struct fuse_file *fuse_file_alloc(void); |
| 500 | void fuse_file_free(struct fuse_file *ff); |
| 501 | void fuse_finish_open(struct inode *inode, struct file *file, |
| 502 | struct fuse_file *ff, struct fuse_open_out *outarg); |
| 503 | |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 504 | /** Fill in ff->reserved_req with a RELEASE request */ |
| 505 | void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode); |
| 506 | |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 507 | /** |
| 508 | * Send RELEASE or RELEASEDIR request |
| 509 | */ |
| 510 | int fuse_release_common(struct inode *inode, struct file *file, int isdir); |
| 511 | |
| 512 | /** |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 513 | * Send FSYNC or FSYNCDIR request |
| 514 | */ |
| 515 | int fuse_fsync_common(struct file *file, struct dentry *de, int datasync, |
| 516 | int isdir); |
| 517 | |
| 518 | /** |
Miklos Szeredi | 1779381 | 2005-10-30 15:02:51 -0800 | [diff] [blame] | 519 | * Initialize file operations on a regular file |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 520 | */ |
| 521 | void fuse_init_file_inode(struct inode *inode); |
| 522 | |
| 523 | /** |
Miklos Szeredi | 1779381 | 2005-10-30 15:02:51 -0800 | [diff] [blame] | 524 | * Initialize inode operations on regular files and special files |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 525 | */ |
| 526 | void fuse_init_common(struct inode *inode); |
| 527 | |
| 528 | /** |
Miklos Szeredi | 1779381 | 2005-10-30 15:02:51 -0800 | [diff] [blame] | 529 | * Initialize inode and file operations on a directory |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 530 | */ |
| 531 | void fuse_init_dir(struct inode *inode); |
| 532 | |
| 533 | /** |
Miklos Szeredi | 1779381 | 2005-10-30 15:02:51 -0800 | [diff] [blame] | 534 | * Initialize inode operations on a symlink |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 535 | */ |
| 536 | void fuse_init_symlink(struct inode *inode); |
| 537 | |
| 538 | /** |
| 539 | * Change attributes of an inode |
| 540 | */ |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 541 | void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, |
| 542 | u64 attr_valid, u64 attr_version); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 543 | |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 544 | void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, |
| 545 | u64 attr_valid); |
| 546 | |
| 547 | void fuse_truncate(struct address_space *mapping, loff_t offset); |
| 548 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 549 | /** |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 550 | * Initialize the client device |
| 551 | */ |
| 552 | int fuse_dev_init(void); |
| 553 | |
| 554 | /** |
| 555 | * Cleanup the client device |
| 556 | */ |
| 557 | void fuse_dev_cleanup(void); |
| 558 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 559 | int fuse_ctl_init(void); |
| 560 | void fuse_ctl_cleanup(void); |
| 561 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 562 | /** |
| 563 | * Allocate a request |
| 564 | */ |
| 565 | struct fuse_req *fuse_request_alloc(void); |
| 566 | |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 567 | struct fuse_req *fuse_request_alloc_nofs(void); |
| 568 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 569 | /** |
| 570 | * Free a request |
| 571 | */ |
| 572 | void fuse_request_free(struct fuse_req *req); |
| 573 | |
| 574 | /** |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 575 | * Get a request, may fail with -ENOMEM |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 576 | */ |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 577 | struct fuse_req *fuse_get_req(struct fuse_conn *fc); |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 578 | |
| 579 | /** |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 580 | * Gets a requests for a file operation, always succeeds |
| 581 | */ |
| 582 | struct fuse_req *fuse_get_req_nofail(struct fuse_conn *fc, struct file *file); |
| 583 | |
| 584 | /** |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 585 | * Decrement reference count of a request. If count goes to zero free |
| 586 | * the request. |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 587 | */ |
| 588 | void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req); |
| 589 | |
| 590 | /** |
Miklos Szeredi | 7c352bd | 2005-09-09 13:10:39 -0700 | [diff] [blame] | 591 | * Send a request (synchronous) |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 592 | */ |
| 593 | void request_send(struct fuse_conn *fc, struct fuse_req *req); |
| 594 | |
| 595 | /** |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 596 | * Send a request with no reply |
| 597 | */ |
| 598 | void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req); |
| 599 | |
| 600 | /** |
| 601 | * Send a request in the background |
| 602 | */ |
| 603 | void request_send_background(struct fuse_conn *fc, struct fuse_req *req); |
| 604 | |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 605 | void request_send_background_locked(struct fuse_conn *fc, struct fuse_req *req); |
| 606 | |
Miklos Szeredi | 5a5fb1e | 2006-04-26 10:48:55 +0200 | [diff] [blame] | 607 | /* Abort all requests */ |
Miklos Szeredi | 69a53bf | 2006-01-16 22:14:41 -0800 | [diff] [blame] | 608 | void fuse_abort_conn(struct fuse_conn *fc); |
| 609 | |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 610 | /** |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 611 | * Invalidate inode attributes |
| 612 | */ |
| 613 | void fuse_invalidate_attr(struct inode *inode); |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 614 | |
Miklos Szeredi | dbd561d | 2008-07-25 01:49:00 -0700 | [diff] [blame] | 615 | void fuse_invalidate_entry_cache(struct dentry *entry); |
| 616 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame] | 617 | /** |
| 618 | * Acquire reference to fuse_conn |
| 619 | */ |
| 620 | struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); |
| 621 | |
| 622 | /** |
| 623 | * Release reference to fuse_conn |
| 624 | */ |
| 625 | void fuse_conn_put(struct fuse_conn *fc); |
| 626 | |
| 627 | /** |
| 628 | * Add connection to control filesystem |
| 629 | */ |
| 630 | int fuse_ctl_add_conn(struct fuse_conn *fc); |
| 631 | |
| 632 | /** |
| 633 | * Remove connection from control filesystem |
| 634 | */ |
| 635 | void fuse_ctl_remove_conn(struct fuse_conn *fc); |
Timo Savola | a5bfffac | 2007-04-08 16:04:00 -0700 | [diff] [blame] | 636 | |
| 637 | /** |
| 638 | * Is file type valid? |
| 639 | */ |
| 640 | int fuse_valid_type(int m); |
Miklos Szeredi | e57ac68 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 641 | |
| 642 | /** |
| 643 | * Is task allowed to perform filesystem operation? |
| 644 | */ |
| 645 | int fuse_allow_task(struct fuse_conn *fc, struct task_struct *task); |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 646 | |
| 647 | u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); |
Miklos Szeredi | bcb4be8 | 2007-11-28 16:21:59 -0800 | [diff] [blame] | 648 | |
| 649 | int fuse_update_attributes(struct inode *inode, struct kstat *stat, |
| 650 | struct file *file, bool *refreshed); |
Miklos Szeredi | 3be5a52 | 2008-04-30 00:54:41 -0700 | [diff] [blame] | 651 | |
| 652 | void fuse_flush_writepages(struct inode *inode); |
| 653 | |
| 654 | void fuse_set_nowrite(struct inode *inode); |
| 655 | void fuse_release_nowrite(struct inode *inode); |
Miklos Szeredi | 5c5c5e5 | 2008-04-30 00:54:43 -0700 | [diff] [blame] | 656 | |
| 657 | u64 fuse_get_attr_version(struct fuse_conn *fc); |