.. | .. |
---|
10 | 10 | |
---|
11 | 11 | #include <linux/pagemap.h> |
---|
12 | 12 | #include <linux/file.h> |
---|
| 13 | +#include <linux/fs_context.h> |
---|
13 | 14 | #include <linux/sched.h> |
---|
14 | 15 | #include <linux/namei.h> |
---|
15 | 16 | #include <linux/slab.h> |
---|
16 | 17 | #include <linux/xattr.h> |
---|
| 18 | +#include <linux/iversion.h> |
---|
17 | 19 | #include <linux/posix_acl.h> |
---|
18 | | - |
---|
19 | | -static bool fuse_use_readdirplus(struct inode *dir, struct dir_context *ctx) |
---|
20 | | -{ |
---|
21 | | - struct fuse_conn *fc = get_fuse_conn(dir); |
---|
22 | | - struct fuse_inode *fi = get_fuse_inode(dir); |
---|
23 | | - |
---|
24 | | - if (!fc->do_readdirplus) |
---|
25 | | - return false; |
---|
26 | | - if (!fc->readdirplus_auto) |
---|
27 | | - return true; |
---|
28 | | - if (test_and_clear_bit(FUSE_I_ADVISE_RDPLUS, &fi->state)) |
---|
29 | | - return true; |
---|
30 | | - if (ctx->pos == 0) |
---|
31 | | - return true; |
---|
32 | | - return false; |
---|
33 | | -} |
---|
34 | 20 | |
---|
35 | 21 | static void fuse_advise_use_readdirplus(struct inode *dir) |
---|
36 | 22 | { |
---|
.. | .. |
---|
39 | 25 | set_bit(FUSE_I_ADVISE_RDPLUS, &fi->state); |
---|
40 | 26 | } |
---|
41 | 27 | |
---|
| 28 | +#if BITS_PER_LONG >= 64 |
---|
| 29 | +static inline void __fuse_dentry_settime(struct dentry *entry, u64 time) |
---|
| 30 | +{ |
---|
| 31 | + entry->d_fsdata = (void *) time; |
---|
| 32 | +} |
---|
| 33 | + |
---|
| 34 | +static inline u64 fuse_dentry_time(const struct dentry *entry) |
---|
| 35 | +{ |
---|
| 36 | + return (u64)entry->d_fsdata; |
---|
| 37 | +} |
---|
| 38 | + |
---|
| 39 | +#else |
---|
42 | 40 | union fuse_dentry { |
---|
43 | 41 | u64 time; |
---|
44 | 42 | struct rcu_head rcu; |
---|
45 | 43 | }; |
---|
46 | 44 | |
---|
47 | | -static inline void fuse_dentry_settime(struct dentry *entry, u64 time) |
---|
| 45 | +static inline void __fuse_dentry_settime(struct dentry *dentry, u64 time) |
---|
48 | 46 | { |
---|
49 | | - ((union fuse_dentry *) entry->d_fsdata)->time = time; |
---|
| 47 | + ((union fuse_dentry *) dentry->d_fsdata)->time = time; |
---|
50 | 48 | } |
---|
51 | 49 | |
---|
52 | | -static inline u64 fuse_dentry_time(struct dentry *entry) |
---|
| 50 | +static inline u64 fuse_dentry_time(const struct dentry *entry) |
---|
53 | 51 | { |
---|
54 | 52 | return ((union fuse_dentry *) entry->d_fsdata)->time; |
---|
| 53 | +} |
---|
| 54 | +#endif |
---|
| 55 | + |
---|
| 56 | +static void fuse_dentry_settime(struct dentry *dentry, u64 time) |
---|
| 57 | +{ |
---|
| 58 | + struct fuse_conn *fc = get_fuse_conn_super(dentry->d_sb); |
---|
| 59 | + bool delete = !time && fc->delete_stale; |
---|
| 60 | + /* |
---|
| 61 | + * Mess with DCACHE_OP_DELETE because dput() will be faster without it. |
---|
| 62 | + * Don't care about races, either way it's just an optimization |
---|
| 63 | + */ |
---|
| 64 | + if ((!delete && (dentry->d_flags & DCACHE_OP_DELETE)) || |
---|
| 65 | + (delete && !(dentry->d_flags & DCACHE_OP_DELETE))) { |
---|
| 66 | + spin_lock(&dentry->d_lock); |
---|
| 67 | + if (!delete) |
---|
| 68 | + dentry->d_flags &= ~DCACHE_OP_DELETE; |
---|
| 69 | + else |
---|
| 70 | + dentry->d_flags |= DCACHE_OP_DELETE; |
---|
| 71 | + spin_unlock(&dentry->d_lock); |
---|
| 72 | + } |
---|
| 73 | + |
---|
| 74 | + __fuse_dentry_settime(dentry, time); |
---|
55 | 75 | } |
---|
56 | 76 | |
---|
57 | 77 | /* |
---|
.. | .. |
---|
80 | 100 | * Set dentry and possibly attribute timeouts from the lookup/mk* |
---|
81 | 101 | * replies |
---|
82 | 102 | */ |
---|
83 | | -static void fuse_change_entry_timeout(struct dentry *entry, |
---|
84 | | - struct fuse_entry_out *o) |
---|
| 103 | +void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o) |
---|
85 | 104 | { |
---|
86 | 105 | fuse_dentry_settime(entry, |
---|
87 | 106 | time_to_jiffies(o->entry_valid, o->entry_valid_nsec)); |
---|
.. | .. |
---|
92 | 111 | return time_to_jiffies(o->attr_valid, o->attr_valid_nsec); |
---|
93 | 112 | } |
---|
94 | 113 | |
---|
95 | | -static u64 entry_attr_timeout(struct fuse_entry_out *o) |
---|
| 114 | +u64 entry_attr_timeout(struct fuse_entry_out *o) |
---|
96 | 115 | { |
---|
97 | 116 | return time_to_jiffies(o->attr_valid, o->attr_valid_nsec); |
---|
| 117 | +} |
---|
| 118 | + |
---|
| 119 | +static void fuse_invalidate_attr_mask(struct inode *inode, u32 mask) |
---|
| 120 | +{ |
---|
| 121 | + set_mask_bits(&get_fuse_inode(inode)->inval_mask, 0, mask); |
---|
98 | 122 | } |
---|
99 | 123 | |
---|
100 | 124 | /* |
---|
.. | .. |
---|
103 | 127 | */ |
---|
104 | 128 | void fuse_invalidate_attr(struct inode *inode) |
---|
105 | 129 | { |
---|
106 | | - get_fuse_inode(inode)->i_time = 0; |
---|
| 130 | + fuse_invalidate_attr_mask(inode, STATX_BASIC_STATS); |
---|
| 131 | +} |
---|
| 132 | + |
---|
| 133 | +static void fuse_dir_changed(struct inode *dir) |
---|
| 134 | +{ |
---|
| 135 | + fuse_invalidate_attr(dir); |
---|
| 136 | + inode_maybe_inc_iversion(dir, false); |
---|
107 | 137 | } |
---|
108 | 138 | |
---|
109 | 139 | /** |
---|
.. | .. |
---|
113 | 143 | void fuse_invalidate_atime(struct inode *inode) |
---|
114 | 144 | { |
---|
115 | 145 | if (!IS_RDONLY(inode)) |
---|
116 | | - fuse_invalidate_attr(inode); |
---|
| 146 | + fuse_invalidate_attr_mask(inode, STATX_ATIME); |
---|
117 | 147 | } |
---|
118 | 148 | |
---|
119 | 149 | /* |
---|
.. | .. |
---|
144 | 174 | struct fuse_entry_out *outarg) |
---|
145 | 175 | { |
---|
146 | 176 | memset(outarg, 0, sizeof(struct fuse_entry_out)); |
---|
147 | | - args->in.h.opcode = FUSE_LOOKUP; |
---|
148 | | - args->in.h.nodeid = nodeid; |
---|
149 | | - args->in.numargs = 1; |
---|
150 | | - args->in.args[0].size = name->len + 1; |
---|
151 | | - args->in.args[0].value = name->name; |
---|
152 | | - args->out.numargs = 1; |
---|
153 | | - args->out.args[0].size = sizeof(struct fuse_entry_out); |
---|
154 | | - args->out.args[0].value = outarg; |
---|
155 | | -} |
---|
156 | | - |
---|
157 | | -u64 fuse_get_attr_version(struct fuse_conn *fc) |
---|
158 | | -{ |
---|
159 | | - u64 curr_version; |
---|
160 | | - |
---|
161 | | - /* |
---|
162 | | - * The spin lock isn't actually needed on 64bit archs, but we |
---|
163 | | - * don't yet care too much about such optimizations. |
---|
164 | | - */ |
---|
165 | | - spin_lock(&fc->lock); |
---|
166 | | - curr_version = fc->attr_version; |
---|
167 | | - spin_unlock(&fc->lock); |
---|
168 | | - |
---|
169 | | - return curr_version; |
---|
| 177 | + args->opcode = FUSE_LOOKUP; |
---|
| 178 | + args->nodeid = nodeid; |
---|
| 179 | + args->in_numargs = 1; |
---|
| 180 | + args->in_args[0].size = name->len + 1; |
---|
| 181 | + args->in_args[0].value = name->name; |
---|
| 182 | + args->out_numargs = 1; |
---|
| 183 | + args->out_args[0].size = sizeof(struct fuse_entry_out); |
---|
| 184 | + args->out_args[0].value = outarg; |
---|
170 | 185 | } |
---|
171 | 186 | |
---|
172 | 187 | /* |
---|
.. | .. |
---|
182 | 197 | { |
---|
183 | 198 | struct inode *inode; |
---|
184 | 199 | struct dentry *parent; |
---|
185 | | - struct fuse_conn *fc; |
---|
| 200 | + struct fuse_mount *fm; |
---|
186 | 201 | struct fuse_inode *fi; |
---|
187 | 202 | int ret; |
---|
188 | 203 | |
---|
.. | .. |
---|
190 | 205 | if (inode && fuse_is_bad(inode)) |
---|
191 | 206 | goto invalid; |
---|
192 | 207 | else if (time_before64(fuse_dentry_time(entry), get_jiffies_64()) || |
---|
193 | | - (flags & LOOKUP_REVAL)) { |
---|
| 208 | + (flags & (LOOKUP_EXCL | LOOKUP_REVAL | LOOKUP_RENAME_TARGET))) { |
---|
194 | 209 | struct fuse_entry_out outarg; |
---|
195 | 210 | FUSE_ARGS(args); |
---|
196 | 211 | struct fuse_forget_link *forget; |
---|
.. | .. |
---|
204 | 219 | if (flags & LOOKUP_RCU) |
---|
205 | 220 | goto out; |
---|
206 | 221 | |
---|
207 | | - fc = get_fuse_conn(inode); |
---|
| 222 | + fm = get_fuse_mount(inode); |
---|
208 | 223 | |
---|
209 | 224 | forget = fuse_alloc_forget(); |
---|
210 | 225 | ret = -ENOMEM; |
---|
211 | 226 | if (!forget) |
---|
212 | 227 | goto out; |
---|
213 | 228 | |
---|
214 | | - attr_version = fuse_get_attr_version(fc); |
---|
| 229 | + attr_version = fuse_get_attr_version(fm->fc); |
---|
215 | 230 | |
---|
216 | 231 | parent = dget_parent(entry); |
---|
217 | | - fuse_lookup_init(fc, &args, get_node_id(d_inode(parent)), |
---|
| 232 | + fuse_lookup_init(fm->fc, &args, get_node_id(d_inode(parent)), |
---|
218 | 233 | &entry->d_name, &outarg); |
---|
219 | | - ret = fuse_simple_request(fc, &args); |
---|
| 234 | + ret = fuse_simple_request(fm, &args); |
---|
220 | 235 | dput(parent); |
---|
221 | 236 | /* Zero nodeid is same as -ENOENT */ |
---|
222 | 237 | if (!ret && !outarg.nodeid) |
---|
223 | 238 | ret = -ENOENT; |
---|
224 | 239 | if (!ret) { |
---|
225 | 240 | fi = get_fuse_inode(inode); |
---|
226 | | - if (outarg.nodeid != get_node_id(inode)) { |
---|
227 | | - fuse_queue_forget(fc, forget, outarg.nodeid, 1); |
---|
| 241 | + if (outarg.nodeid != get_node_id(inode) || |
---|
| 242 | + (bool) IS_AUTOMOUNT(inode) != (bool) (outarg.attr.flags & FUSE_ATTR_SUBMOUNT)) { |
---|
| 243 | + fuse_queue_forget(fm->fc, forget, |
---|
| 244 | + outarg.nodeid, 1); |
---|
228 | 245 | goto invalid; |
---|
229 | 246 | } |
---|
230 | | - spin_lock(&fc->lock); |
---|
| 247 | + spin_lock(&fi->lock); |
---|
231 | 248 | fi->nlookup++; |
---|
232 | | - spin_unlock(&fc->lock); |
---|
| 249 | + spin_unlock(&fi->lock); |
---|
233 | 250 | } |
---|
234 | 251 | kfree(forget); |
---|
235 | | - if (ret == -ENOMEM) |
---|
| 252 | + if (ret == -ENOMEM || ret == -EINTR) |
---|
236 | 253 | goto out; |
---|
237 | 254 | if (ret || fuse_invalid_attr(&outarg.attr) || |
---|
238 | | - (outarg.attr.mode ^ inode->i_mode) & S_IFMT) |
---|
| 255 | + fuse_stale_inode(inode, outarg.generation, &outarg.attr)) |
---|
239 | 256 | goto invalid; |
---|
240 | 257 | |
---|
241 | 258 | forget_all_cached_acls(inode); |
---|
.. | .. |
---|
263 | 280 | goto out; |
---|
264 | 281 | } |
---|
265 | 282 | |
---|
266 | | -static int invalid_nodeid(u64 nodeid) |
---|
267 | | -{ |
---|
268 | | - return !nodeid || nodeid == FUSE_ROOT_ID; |
---|
269 | | -} |
---|
270 | | - |
---|
| 283 | +#if BITS_PER_LONG < 64 |
---|
271 | 284 | static int fuse_dentry_init(struct dentry *dentry) |
---|
272 | 285 | { |
---|
273 | | - dentry->d_fsdata = kzalloc(sizeof(union fuse_dentry), GFP_KERNEL); |
---|
| 286 | + dentry->d_fsdata = kzalloc(sizeof(union fuse_dentry), |
---|
| 287 | + GFP_KERNEL_ACCOUNT | __GFP_RECLAIMABLE); |
---|
274 | 288 | |
---|
275 | 289 | return dentry->d_fsdata ? 0 : -ENOMEM; |
---|
276 | 290 | } |
---|
.. | .. |
---|
279 | 293 | union fuse_dentry *fd = dentry->d_fsdata; |
---|
280 | 294 | |
---|
281 | 295 | kfree_rcu(fd, rcu); |
---|
| 296 | +} |
---|
| 297 | +#endif |
---|
| 298 | + |
---|
| 299 | +static int fuse_dentry_delete(const struct dentry *dentry) |
---|
| 300 | +{ |
---|
| 301 | + return time_before64(fuse_dentry_time(dentry), get_jiffies_64()); |
---|
| 302 | +} |
---|
| 303 | + |
---|
| 304 | +/* |
---|
| 305 | + * Create a fuse_mount object with a new superblock (with path->dentry |
---|
| 306 | + * as the root), and return that mount so it can be auto-mounted on |
---|
| 307 | + * @path. |
---|
| 308 | + */ |
---|
| 309 | +static struct vfsmount *fuse_dentry_automount(struct path *path) |
---|
| 310 | +{ |
---|
| 311 | + struct fs_context *fsc; |
---|
| 312 | + struct fuse_mount *parent_fm = get_fuse_mount_super(path->mnt->mnt_sb); |
---|
| 313 | + struct fuse_conn *fc = parent_fm->fc; |
---|
| 314 | + struct fuse_mount *fm; |
---|
| 315 | + struct vfsmount *mnt; |
---|
| 316 | + struct fuse_inode *mp_fi = get_fuse_inode(d_inode(path->dentry)); |
---|
| 317 | + struct super_block *sb; |
---|
| 318 | + int err; |
---|
| 319 | + |
---|
| 320 | + fsc = fs_context_for_submount(path->mnt->mnt_sb->s_type, path->dentry); |
---|
| 321 | + if (IS_ERR(fsc)) { |
---|
| 322 | + err = PTR_ERR(fsc); |
---|
| 323 | + goto out; |
---|
| 324 | + } |
---|
| 325 | + |
---|
| 326 | + err = -ENOMEM; |
---|
| 327 | + fm = kzalloc(sizeof(struct fuse_mount), GFP_KERNEL); |
---|
| 328 | + if (!fm) |
---|
| 329 | + goto out_put_fsc; |
---|
| 330 | + |
---|
| 331 | + refcount_set(&fm->count, 1); |
---|
| 332 | + fsc->s_fs_info = fm; |
---|
| 333 | + sb = sget_fc(fsc, NULL, set_anon_super_fc); |
---|
| 334 | + if (IS_ERR(sb)) { |
---|
| 335 | + err = PTR_ERR(sb); |
---|
| 336 | + fuse_mount_put(fm); |
---|
| 337 | + goto out_put_fsc; |
---|
| 338 | + } |
---|
| 339 | + fm->fc = fuse_conn_get(fc); |
---|
| 340 | + |
---|
| 341 | + /* Initialize superblock, making @mp_fi its root */ |
---|
| 342 | + err = fuse_fill_super_submount(sb, mp_fi); |
---|
| 343 | + if (err) { |
---|
| 344 | + fuse_conn_put(fc); |
---|
| 345 | + kfree(fm); |
---|
| 346 | + sb->s_fs_info = NULL; |
---|
| 347 | + goto out_put_sb; |
---|
| 348 | + } |
---|
| 349 | + |
---|
| 350 | + down_write(&fc->killsb); |
---|
| 351 | + list_add_tail(&fm->fc_entry, &fc->mounts); |
---|
| 352 | + up_write(&fc->killsb); |
---|
| 353 | + |
---|
| 354 | + sb->s_flags |= SB_ACTIVE; |
---|
| 355 | + fsc->root = dget(sb->s_root); |
---|
| 356 | + |
---|
| 357 | + /* |
---|
| 358 | + * FIXME: setting SB_BORN requires a write barrier for |
---|
| 359 | + * super_cache_count(). We should actually come |
---|
| 360 | + * up with a proper ->get_tree() implementation |
---|
| 361 | + * for submounts and call vfs_get_tree() to take |
---|
| 362 | + * care of the write barrier. |
---|
| 363 | + */ |
---|
| 364 | + smp_wmb(); |
---|
| 365 | + sb->s_flags |= SB_BORN; |
---|
| 366 | + |
---|
| 367 | + /* We are done configuring the superblock, so unlock it */ |
---|
| 368 | + up_write(&sb->s_umount); |
---|
| 369 | + |
---|
| 370 | + /* Create the submount */ |
---|
| 371 | + mnt = vfs_create_mount(fsc); |
---|
| 372 | + if (IS_ERR(mnt)) { |
---|
| 373 | + err = PTR_ERR(mnt); |
---|
| 374 | + goto out_put_fsc; |
---|
| 375 | + } |
---|
| 376 | + mntget(mnt); |
---|
| 377 | + put_fs_context(fsc); |
---|
| 378 | + return mnt; |
---|
| 379 | + |
---|
| 380 | +out_put_sb: |
---|
| 381 | + /* |
---|
| 382 | + * Only jump here when fsc->root is NULL and sb is still locked |
---|
| 383 | + * (otherwise put_fs_context() will put the superblock) |
---|
| 384 | + */ |
---|
| 385 | + deactivate_locked_super(sb); |
---|
| 386 | +out_put_fsc: |
---|
| 387 | + put_fs_context(fsc); |
---|
| 388 | +out: |
---|
| 389 | + return ERR_PTR(err); |
---|
282 | 390 | } |
---|
283 | 391 | |
---|
284 | 392 | /* |
---|
.. | .. |
---|
291 | 399 | struct path *canonical_path) |
---|
292 | 400 | { |
---|
293 | 401 | struct inode *inode = d_inode(path->dentry); |
---|
294 | | - struct fuse_conn *fc = get_fuse_conn(inode); |
---|
| 402 | + //struct fuse_conn *fc = get_fuse_conn(inode); |
---|
| 403 | + struct fuse_mount *fm = get_fuse_mount_super(path->mnt->mnt_sb); |
---|
295 | 404 | FUSE_ARGS(args); |
---|
296 | 405 | char *path_name; |
---|
297 | 406 | int err; |
---|
298 | 407 | |
---|
299 | | - path_name = (char *)__get_free_page(GFP_KERNEL); |
---|
| 408 | + path_name = (char *)get_zeroed_page(GFP_KERNEL); |
---|
300 | 409 | if (!path_name) |
---|
301 | 410 | goto default_path; |
---|
302 | 411 | |
---|
303 | | - args.in.h.opcode = FUSE_CANONICAL_PATH; |
---|
304 | | - args.in.h.nodeid = get_node_id(inode); |
---|
305 | | - args.in.numargs = 0; |
---|
306 | | - args.out.numargs = 1; |
---|
307 | | - args.out.args[0].size = PATH_MAX; |
---|
308 | | - args.out.args[0].value = path_name; |
---|
309 | | - args.out.argvar = 1; |
---|
310 | | - args.out.canonical_path = canonical_path; |
---|
| 412 | + args.opcode = FUSE_CANONICAL_PATH; |
---|
| 413 | + args.nodeid = get_node_id(inode); |
---|
| 414 | + args.in_numargs = 0; |
---|
| 415 | + args.out_numargs = 1; |
---|
| 416 | + args.out_args[0].size = PATH_MAX; |
---|
| 417 | + args.out_args[0].value = path_name; |
---|
| 418 | + args.canonical_path = canonical_path; |
---|
| 419 | + args.out_argvar = 1; |
---|
311 | 420 | |
---|
312 | | - err = fuse_simple_request(fc, &args); |
---|
| 421 | + err = fuse_simple_request(fm, &args); |
---|
313 | 422 | free_page((unsigned long)path_name); |
---|
314 | 423 | if (err > 0) |
---|
315 | 424 | return; |
---|
.. | .. |
---|
321 | 430 | |
---|
322 | 431 | const struct dentry_operations fuse_dentry_operations = { |
---|
323 | 432 | .d_revalidate = fuse_dentry_revalidate, |
---|
| 433 | + .d_delete = fuse_dentry_delete, |
---|
| 434 | +#if BITS_PER_LONG < 64 |
---|
324 | 435 | .d_init = fuse_dentry_init, |
---|
325 | 436 | .d_release = fuse_dentry_release, |
---|
| 437 | +#endif |
---|
| 438 | + .d_automount = fuse_dentry_automount, |
---|
326 | 439 | .d_canonical_path = fuse_dentry_canonical_path, |
---|
327 | 440 | }; |
---|
328 | 441 | |
---|
329 | 442 | const struct dentry_operations fuse_root_dentry_operations = { |
---|
| 443 | +#if BITS_PER_LONG < 64 |
---|
330 | 444 | .d_init = fuse_dentry_init, |
---|
331 | 445 | .d_release = fuse_dentry_release, |
---|
| 446 | +#endif |
---|
332 | 447 | }; |
---|
333 | 448 | |
---|
334 | 449 | int fuse_valid_type(int m) |
---|
.. | .. |
---|
346 | 461 | int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, |
---|
347 | 462 | struct fuse_entry_out *outarg, struct inode **inode) |
---|
348 | 463 | { |
---|
349 | | - struct fuse_conn *fc = get_fuse_conn_super(sb); |
---|
| 464 | + struct fuse_mount *fm = get_fuse_mount_super(sb); |
---|
350 | 465 | FUSE_ARGS(args); |
---|
351 | 466 | struct fuse_forget_link *forget; |
---|
352 | 467 | u64 attr_version; |
---|
.. | .. |
---|
363 | 478 | if (!forget) |
---|
364 | 479 | goto out; |
---|
365 | 480 | |
---|
366 | | - attr_version = fuse_get_attr_version(fc); |
---|
| 481 | + attr_version = fuse_get_attr_version(fm->fc); |
---|
367 | 482 | |
---|
368 | | - fuse_lookup_init(fc, &args, nodeid, name, outarg); |
---|
369 | | - err = fuse_simple_request(fc, &args); |
---|
| 483 | + fuse_lookup_init(fm->fc, &args, nodeid, name, outarg); |
---|
| 484 | + err = fuse_simple_request(fm, &args); |
---|
370 | 485 | /* Zero nodeid is same as -ENOENT, but with valid timeout */ |
---|
371 | 486 | if (err || !outarg->nodeid) |
---|
372 | 487 | goto out_put_forget; |
---|
.. | .. |
---|
382 | 497 | attr_version); |
---|
383 | 498 | err = -ENOMEM; |
---|
384 | 499 | if (!*inode) { |
---|
385 | | - fuse_queue_forget(fc, forget, outarg->nodeid, 1); |
---|
| 500 | + fuse_queue_forget(fm->fc, forget, outarg->nodeid, 1); |
---|
386 | 501 | goto out; |
---|
387 | 502 | } |
---|
388 | 503 | err = 0; |
---|
.. | .. |
---|
432 | 547 | else |
---|
433 | 548 | fuse_invalidate_entry_cache(entry); |
---|
434 | 549 | |
---|
435 | | - fuse_advise_use_readdirplus(dir); |
---|
| 550 | + if (inode) |
---|
| 551 | + fuse_advise_use_readdirplus(dir); |
---|
436 | 552 | return newent; |
---|
437 | 553 | |
---|
438 | 554 | out_iput: |
---|
.. | .. |
---|
454 | 570 | int err; |
---|
455 | 571 | struct inode *inode; |
---|
456 | 572 | struct fuse_conn *fc = get_fuse_conn(dir); |
---|
| 573 | + struct fuse_mount *fm = get_fuse_mount(dir); |
---|
457 | 574 | FUSE_ARGS(args); |
---|
458 | 575 | struct fuse_forget_link *forget; |
---|
459 | 576 | struct fuse_create_in inarg; |
---|
460 | 577 | struct fuse_open_out outopen; |
---|
461 | 578 | struct fuse_entry_out outentry; |
---|
| 579 | + struct fuse_inode *fi; |
---|
462 | 580 | struct fuse_file *ff; |
---|
| 581 | + bool trunc = flags & O_TRUNC; |
---|
463 | 582 | |
---|
464 | 583 | /* Userspace expects S_IFREG in create mode */ |
---|
465 | 584 | BUG_ON((mode & S_IFMT) != S_IFREG); |
---|
.. | .. |
---|
470 | 589 | goto out_err; |
---|
471 | 590 | |
---|
472 | 591 | err = -ENOMEM; |
---|
473 | | - ff = fuse_file_alloc(fc); |
---|
| 592 | + ff = fuse_file_alloc(fm); |
---|
474 | 593 | if (!ff) |
---|
475 | 594 | goto out_put_forget_req; |
---|
476 | 595 | |
---|
477 | | - if (!fc->dont_mask) |
---|
| 596 | + if (!fm->fc->dont_mask) |
---|
478 | 597 | mode &= ~current_umask(); |
---|
479 | 598 | |
---|
480 | 599 | flags &= ~O_NOCTTY; |
---|
.. | .. |
---|
483 | 602 | inarg.flags = flags; |
---|
484 | 603 | inarg.mode = mode; |
---|
485 | 604 | inarg.umask = current_umask(); |
---|
486 | | - args.in.h.opcode = FUSE_CREATE; |
---|
487 | | - args.in.h.nodeid = get_node_id(dir); |
---|
488 | | - args.in.numargs = 2; |
---|
489 | | - args.in.args[0].size = sizeof(inarg); |
---|
490 | | - args.in.args[0].value = &inarg; |
---|
491 | | - args.in.args[1].size = entry->d_name.len + 1; |
---|
492 | | - args.in.args[1].value = entry->d_name.name; |
---|
493 | | - args.out.numargs = 2; |
---|
494 | | - args.out.args[0].size = sizeof(outentry); |
---|
495 | | - args.out.args[0].value = &outentry; |
---|
496 | | - args.out.args[1].size = sizeof(outopen); |
---|
497 | | - args.out.args[1].value = &outopen; |
---|
498 | | - err = fuse_simple_request(fc, &args); |
---|
| 605 | + args.opcode = FUSE_CREATE; |
---|
| 606 | + args.nodeid = get_node_id(dir); |
---|
| 607 | + args.in_numargs = 2; |
---|
| 608 | + args.in_args[0].size = sizeof(inarg); |
---|
| 609 | + args.in_args[0].value = &inarg; |
---|
| 610 | + args.in_args[1].size = entry->d_name.len + 1; |
---|
| 611 | + args.in_args[1].value = entry->d_name.name; |
---|
| 612 | + args.out_numargs = 2; |
---|
| 613 | + args.out_args[0].size = sizeof(outentry); |
---|
| 614 | + args.out_args[0].value = &outentry; |
---|
| 615 | + args.out_args[1].size = sizeof(outopen); |
---|
| 616 | + args.out_args[1].value = &outopen; |
---|
| 617 | + err = fuse_simple_request(fm, &args); |
---|
499 | 618 | if (err) |
---|
500 | 619 | goto out_free_ff; |
---|
501 | 620 | |
---|
.. | .. |
---|
507 | 626 | ff->fh = outopen.fh; |
---|
508 | 627 | ff->nodeid = outentry.nodeid; |
---|
509 | 628 | ff->open_flags = outopen.open_flags; |
---|
| 629 | + fuse_passthrough_setup(fc, ff, &outopen); |
---|
510 | 630 | inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation, |
---|
511 | 631 | &outentry.attr, entry_attr_timeout(&outentry), 0); |
---|
512 | 632 | if (!inode) { |
---|
513 | 633 | flags &= ~(O_CREAT | O_EXCL | O_TRUNC); |
---|
514 | | - fuse_sync_release(ff, flags); |
---|
515 | | - fuse_queue_forget(fc, forget, outentry.nodeid, 1); |
---|
| 634 | + fuse_sync_release(NULL, ff, flags); |
---|
| 635 | + fuse_queue_forget(fm->fc, forget, outentry.nodeid, 1); |
---|
516 | 636 | err = -ENOMEM; |
---|
517 | 637 | goto out_err; |
---|
518 | 638 | } |
---|
519 | 639 | kfree(forget); |
---|
520 | 640 | d_instantiate(entry, inode); |
---|
521 | 641 | fuse_change_entry_timeout(entry, &outentry); |
---|
522 | | - fuse_invalidate_attr(dir); |
---|
| 642 | + fuse_dir_changed(dir); |
---|
523 | 643 | err = finish_open(file, entry, generic_file_open); |
---|
524 | 644 | if (err) { |
---|
525 | | - fuse_sync_release(ff, flags); |
---|
| 645 | + fi = get_fuse_inode(inode); |
---|
| 646 | + fuse_sync_release(fi, ff, flags); |
---|
526 | 647 | } else { |
---|
527 | 648 | file->private_data = ff; |
---|
528 | 649 | fuse_finish_open(inode, file); |
---|
| 650 | + if (fm->fc->atomic_o_trunc && trunc) |
---|
| 651 | + truncate_pagecache(inode, 0); |
---|
| 652 | + else if (!(ff->open_flags & FOPEN_KEEP_CACHE)) |
---|
| 653 | + invalidate_inode_pages2(inode->i_mapping); |
---|
529 | 654 | } |
---|
530 | 655 | return err; |
---|
531 | 656 | |
---|
.. | .. |
---|
587 | 712 | /* |
---|
588 | 713 | * Code shared between mknod, mkdir, symlink and link |
---|
589 | 714 | */ |
---|
590 | | -static int create_new_entry(struct fuse_conn *fc, struct fuse_args *args, |
---|
| 715 | +static int create_new_entry(struct fuse_mount *fm, struct fuse_args *args, |
---|
591 | 716 | struct inode *dir, struct dentry *entry, |
---|
592 | 717 | umode_t mode) |
---|
593 | 718 | { |
---|
.. | .. |
---|
605 | 730 | return -ENOMEM; |
---|
606 | 731 | |
---|
607 | 732 | memset(&outarg, 0, sizeof(outarg)); |
---|
608 | | - args->in.h.nodeid = get_node_id(dir); |
---|
609 | | - args->out.numargs = 1; |
---|
610 | | - args->out.args[0].size = sizeof(outarg); |
---|
611 | | - args->out.args[0].value = &outarg; |
---|
612 | | - err = fuse_simple_request(fc, args); |
---|
| 733 | + args->nodeid = get_node_id(dir); |
---|
| 734 | + args->out_numargs = 1; |
---|
| 735 | + args->out_args[0].size = sizeof(outarg); |
---|
| 736 | + args->out_args[0].value = &outarg; |
---|
| 737 | + err = fuse_simple_request(fm, args); |
---|
613 | 738 | if (err) |
---|
614 | 739 | goto out_put_forget_req; |
---|
615 | 740 | |
---|
.. | .. |
---|
623 | 748 | inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, |
---|
624 | 749 | &outarg.attr, entry_attr_timeout(&outarg), 0); |
---|
625 | 750 | if (!inode) { |
---|
626 | | - fuse_queue_forget(fc, forget, outarg.nodeid, 1); |
---|
| 751 | + fuse_queue_forget(fm->fc, forget, outarg.nodeid, 1); |
---|
627 | 752 | return -ENOMEM; |
---|
628 | 753 | } |
---|
629 | 754 | kfree(forget); |
---|
.. | .. |
---|
639 | 764 | } else { |
---|
640 | 765 | fuse_change_entry_timeout(entry, &outarg); |
---|
641 | 766 | } |
---|
642 | | - fuse_invalidate_attr(dir); |
---|
| 767 | + fuse_dir_changed(dir); |
---|
643 | 768 | return 0; |
---|
644 | 769 | |
---|
645 | 770 | out_put_forget_req: |
---|
.. | .. |
---|
651 | 776 | dev_t rdev) |
---|
652 | 777 | { |
---|
653 | 778 | struct fuse_mknod_in inarg; |
---|
654 | | - struct fuse_conn *fc = get_fuse_conn(dir); |
---|
| 779 | + struct fuse_mount *fm = get_fuse_mount(dir); |
---|
655 | 780 | FUSE_ARGS(args); |
---|
656 | 781 | |
---|
657 | | - if (!fc->dont_mask) |
---|
| 782 | + if (!fm->fc->dont_mask) |
---|
658 | 783 | mode &= ~current_umask(); |
---|
659 | 784 | |
---|
660 | 785 | memset(&inarg, 0, sizeof(inarg)); |
---|
661 | 786 | inarg.mode = mode; |
---|
662 | 787 | inarg.rdev = new_encode_dev(rdev); |
---|
663 | 788 | inarg.umask = current_umask(); |
---|
664 | | - args.in.h.opcode = FUSE_MKNOD; |
---|
665 | | - args.in.numargs = 2; |
---|
666 | | - args.in.args[0].size = sizeof(inarg); |
---|
667 | | - args.in.args[0].value = &inarg; |
---|
668 | | - args.in.args[1].size = entry->d_name.len + 1; |
---|
669 | | - args.in.args[1].value = entry->d_name.name; |
---|
670 | | - return create_new_entry(fc, &args, dir, entry, mode); |
---|
| 789 | + args.opcode = FUSE_MKNOD; |
---|
| 790 | + args.in_numargs = 2; |
---|
| 791 | + args.in_args[0].size = sizeof(inarg); |
---|
| 792 | + args.in_args[0].value = &inarg; |
---|
| 793 | + args.in_args[1].size = entry->d_name.len + 1; |
---|
| 794 | + args.in_args[1].value = entry->d_name.name; |
---|
| 795 | + return create_new_entry(fm, &args, dir, entry, mode); |
---|
671 | 796 | } |
---|
672 | 797 | |
---|
673 | 798 | static int fuse_create(struct inode *dir, struct dentry *entry, umode_t mode, |
---|
.. | .. |
---|
679 | 804 | static int fuse_mkdir(struct inode *dir, struct dentry *entry, umode_t mode) |
---|
680 | 805 | { |
---|
681 | 806 | struct fuse_mkdir_in inarg; |
---|
682 | | - struct fuse_conn *fc = get_fuse_conn(dir); |
---|
| 807 | + struct fuse_mount *fm = get_fuse_mount(dir); |
---|
683 | 808 | FUSE_ARGS(args); |
---|
684 | 809 | |
---|
685 | | - if (!fc->dont_mask) |
---|
| 810 | + if (!fm->fc->dont_mask) |
---|
686 | 811 | mode &= ~current_umask(); |
---|
687 | 812 | |
---|
688 | 813 | memset(&inarg, 0, sizeof(inarg)); |
---|
689 | 814 | inarg.mode = mode; |
---|
690 | 815 | inarg.umask = current_umask(); |
---|
691 | | - args.in.h.opcode = FUSE_MKDIR; |
---|
692 | | - args.in.numargs = 2; |
---|
693 | | - args.in.args[0].size = sizeof(inarg); |
---|
694 | | - args.in.args[0].value = &inarg; |
---|
695 | | - args.in.args[1].size = entry->d_name.len + 1; |
---|
696 | | - args.in.args[1].value = entry->d_name.name; |
---|
697 | | - return create_new_entry(fc, &args, dir, entry, S_IFDIR); |
---|
| 816 | + args.opcode = FUSE_MKDIR; |
---|
| 817 | + args.in_numargs = 2; |
---|
| 818 | + args.in_args[0].size = sizeof(inarg); |
---|
| 819 | + args.in_args[0].value = &inarg; |
---|
| 820 | + args.in_args[1].size = entry->d_name.len + 1; |
---|
| 821 | + args.in_args[1].value = entry->d_name.name; |
---|
| 822 | + return create_new_entry(fm, &args, dir, entry, S_IFDIR); |
---|
698 | 823 | } |
---|
699 | 824 | |
---|
700 | 825 | static int fuse_symlink(struct inode *dir, struct dentry *entry, |
---|
701 | 826 | const char *link) |
---|
702 | 827 | { |
---|
703 | | - struct fuse_conn *fc = get_fuse_conn(dir); |
---|
| 828 | + struct fuse_mount *fm = get_fuse_mount(dir); |
---|
704 | 829 | unsigned len = strlen(link) + 1; |
---|
705 | 830 | FUSE_ARGS(args); |
---|
706 | 831 | |
---|
707 | | - args.in.h.opcode = FUSE_SYMLINK; |
---|
708 | | - args.in.numargs = 2; |
---|
709 | | - args.in.args[0].size = entry->d_name.len + 1; |
---|
710 | | - args.in.args[0].value = entry->d_name.name; |
---|
711 | | - args.in.args[1].size = len; |
---|
712 | | - args.in.args[1].value = link; |
---|
713 | | - return create_new_entry(fc, &args, dir, entry, S_IFLNK); |
---|
| 832 | + args.opcode = FUSE_SYMLINK; |
---|
| 833 | + args.in_numargs = 2; |
---|
| 834 | + args.in_args[0].size = entry->d_name.len + 1; |
---|
| 835 | + args.in_args[0].value = entry->d_name.name; |
---|
| 836 | + args.in_args[1].size = len; |
---|
| 837 | + args.in_args[1].value = link; |
---|
| 838 | + return create_new_entry(fm, &args, dir, entry, S_IFLNK); |
---|
| 839 | +} |
---|
| 840 | + |
---|
| 841 | +void fuse_flush_time_update(struct inode *inode) |
---|
| 842 | +{ |
---|
| 843 | + int err = sync_inode_metadata(inode, 1); |
---|
| 844 | + |
---|
| 845 | + mapping_set_error(inode->i_mapping, err); |
---|
714 | 846 | } |
---|
715 | 847 | |
---|
716 | 848 | void fuse_update_ctime(struct inode *inode) |
---|
.. | .. |
---|
718 | 850 | if (!IS_NOCMTIME(inode)) { |
---|
719 | 851 | inode->i_ctime = current_time(inode); |
---|
720 | 852 | mark_inode_dirty_sync(inode); |
---|
| 853 | + fuse_flush_time_update(inode); |
---|
721 | 854 | } |
---|
722 | 855 | } |
---|
723 | 856 | |
---|
724 | 857 | static int fuse_unlink(struct inode *dir, struct dentry *entry) |
---|
725 | 858 | { |
---|
726 | 859 | int err; |
---|
727 | | - struct fuse_conn *fc = get_fuse_conn(dir); |
---|
| 860 | + struct fuse_mount *fm = get_fuse_mount(dir); |
---|
728 | 861 | FUSE_ARGS(args); |
---|
729 | 862 | |
---|
730 | 863 | if (fuse_is_bad(dir)) |
---|
731 | 864 | return -EIO; |
---|
732 | 865 | |
---|
733 | | - args.in.h.opcode = FUSE_UNLINK; |
---|
734 | | - args.in.h.nodeid = get_node_id(dir); |
---|
735 | | - args.in.numargs = 1; |
---|
736 | | - args.in.args[0].size = entry->d_name.len + 1; |
---|
737 | | - args.in.args[0].value = entry->d_name.name; |
---|
738 | | - err = fuse_simple_request(fc, &args); |
---|
| 866 | + args.opcode = FUSE_UNLINK; |
---|
| 867 | + args.nodeid = get_node_id(dir); |
---|
| 868 | + args.in_numargs = 1; |
---|
| 869 | + args.in_args[0].size = entry->d_name.len + 1; |
---|
| 870 | + args.in_args[0].value = entry->d_name.name; |
---|
| 871 | + err = fuse_simple_request(fm, &args); |
---|
739 | 872 | if (!err) { |
---|
740 | 873 | struct inode *inode = d_inode(entry); |
---|
741 | 874 | struct fuse_inode *fi = get_fuse_inode(inode); |
---|
742 | 875 | |
---|
743 | | - spin_lock(&fc->lock); |
---|
744 | | - fi->attr_version = ++fc->attr_version; |
---|
| 876 | + spin_lock(&fi->lock); |
---|
| 877 | + fi->attr_version = atomic64_inc_return(&fm->fc->attr_version); |
---|
745 | 878 | /* |
---|
746 | 879 | * If i_nlink == 0 then unlink doesn't make sense, yet this can |
---|
747 | 880 | * happen if userspace filesystem is careless. It would be |
---|
.. | .. |
---|
750 | 883 | */ |
---|
751 | 884 | if (inode->i_nlink > 0) |
---|
752 | 885 | drop_nlink(inode); |
---|
753 | | - spin_unlock(&fc->lock); |
---|
| 886 | + spin_unlock(&fi->lock); |
---|
754 | 887 | fuse_invalidate_attr(inode); |
---|
755 | | - fuse_invalidate_attr(dir); |
---|
| 888 | + fuse_dir_changed(dir); |
---|
756 | 889 | fuse_invalidate_entry_cache(entry); |
---|
757 | 890 | fuse_update_ctime(inode); |
---|
758 | 891 | } else if (err == -EINTR) |
---|
.. | .. |
---|
763 | 896 | static int fuse_rmdir(struct inode *dir, struct dentry *entry) |
---|
764 | 897 | { |
---|
765 | 898 | int err; |
---|
766 | | - struct fuse_conn *fc = get_fuse_conn(dir); |
---|
| 899 | + struct fuse_mount *fm = get_fuse_mount(dir); |
---|
767 | 900 | FUSE_ARGS(args); |
---|
768 | 901 | |
---|
769 | 902 | if (fuse_is_bad(dir)) |
---|
770 | 903 | return -EIO; |
---|
771 | 904 | |
---|
772 | | - args.in.h.opcode = FUSE_RMDIR; |
---|
773 | | - args.in.h.nodeid = get_node_id(dir); |
---|
774 | | - args.in.numargs = 1; |
---|
775 | | - args.in.args[0].size = entry->d_name.len + 1; |
---|
776 | | - args.in.args[0].value = entry->d_name.name; |
---|
777 | | - err = fuse_simple_request(fc, &args); |
---|
| 905 | + args.opcode = FUSE_RMDIR; |
---|
| 906 | + args.nodeid = get_node_id(dir); |
---|
| 907 | + args.in_numargs = 1; |
---|
| 908 | + args.in_args[0].size = entry->d_name.len + 1; |
---|
| 909 | + args.in_args[0].value = entry->d_name.name; |
---|
| 910 | + err = fuse_simple_request(fm, &args); |
---|
778 | 911 | if (!err) { |
---|
779 | 912 | clear_nlink(d_inode(entry)); |
---|
780 | | - fuse_invalidate_attr(dir); |
---|
| 913 | + fuse_dir_changed(dir); |
---|
781 | 914 | fuse_invalidate_entry_cache(entry); |
---|
782 | 915 | } else if (err == -EINTR) |
---|
783 | 916 | fuse_invalidate_entry(entry); |
---|
.. | .. |
---|
790 | 923 | { |
---|
791 | 924 | int err; |
---|
792 | 925 | struct fuse_rename2_in inarg; |
---|
793 | | - struct fuse_conn *fc = get_fuse_conn(olddir); |
---|
| 926 | + struct fuse_mount *fm = get_fuse_mount(olddir); |
---|
794 | 927 | FUSE_ARGS(args); |
---|
795 | 928 | |
---|
796 | 929 | memset(&inarg, 0, argsize); |
---|
797 | 930 | inarg.newdir = get_node_id(newdir); |
---|
798 | 931 | inarg.flags = flags; |
---|
799 | | - args.in.h.opcode = opcode; |
---|
800 | | - args.in.h.nodeid = get_node_id(olddir); |
---|
801 | | - args.in.numargs = 3; |
---|
802 | | - args.in.args[0].size = argsize; |
---|
803 | | - args.in.args[0].value = &inarg; |
---|
804 | | - args.in.args[1].size = oldent->d_name.len + 1; |
---|
805 | | - args.in.args[1].value = oldent->d_name.name; |
---|
806 | | - args.in.args[2].size = newent->d_name.len + 1; |
---|
807 | | - args.in.args[2].value = newent->d_name.name; |
---|
808 | | - err = fuse_simple_request(fc, &args); |
---|
| 932 | + args.opcode = opcode; |
---|
| 933 | + args.nodeid = get_node_id(olddir); |
---|
| 934 | + args.in_numargs = 3; |
---|
| 935 | + args.in_args[0].size = argsize; |
---|
| 936 | + args.in_args[0].value = &inarg; |
---|
| 937 | + args.in_args[1].size = oldent->d_name.len + 1; |
---|
| 938 | + args.in_args[1].value = oldent->d_name.name; |
---|
| 939 | + args.in_args[2].size = newent->d_name.len + 1; |
---|
| 940 | + args.in_args[2].value = newent->d_name.name; |
---|
| 941 | + err = fuse_simple_request(fm, &args); |
---|
809 | 942 | if (!err) { |
---|
810 | 943 | /* ctime changes */ |
---|
811 | 944 | fuse_invalidate_attr(d_inode(oldent)); |
---|
.. | .. |
---|
816 | 949 | fuse_update_ctime(d_inode(newent)); |
---|
817 | 950 | } |
---|
818 | 951 | |
---|
819 | | - fuse_invalidate_attr(olddir); |
---|
| 952 | + fuse_dir_changed(olddir); |
---|
820 | 953 | if (olddir != newdir) |
---|
821 | | - fuse_invalidate_attr(newdir); |
---|
| 954 | + fuse_dir_changed(newdir); |
---|
822 | 955 | |
---|
823 | 956 | /* newent will end up negative */ |
---|
824 | 957 | if (!(flags & RENAME_EXCHANGE) && d_really_is_positive(newent)) { |
---|
.. | .. |
---|
850 | 983 | if (fuse_is_bad(olddir)) |
---|
851 | 984 | return -EIO; |
---|
852 | 985 | |
---|
853 | | - if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE)) |
---|
| 986 | + if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT)) |
---|
854 | 987 | return -EINVAL; |
---|
855 | 988 | |
---|
856 | 989 | if (flags) { |
---|
.. | .. |
---|
879 | 1012 | int err; |
---|
880 | 1013 | struct fuse_link_in inarg; |
---|
881 | 1014 | struct inode *inode = d_inode(entry); |
---|
882 | | - struct fuse_conn *fc = get_fuse_conn(inode); |
---|
| 1015 | + struct fuse_mount *fm = get_fuse_mount(inode); |
---|
883 | 1016 | FUSE_ARGS(args); |
---|
884 | 1017 | |
---|
885 | 1018 | memset(&inarg, 0, sizeof(inarg)); |
---|
886 | 1019 | inarg.oldnodeid = get_node_id(inode); |
---|
887 | | - args.in.h.opcode = FUSE_LINK; |
---|
888 | | - args.in.numargs = 2; |
---|
889 | | - args.in.args[0].size = sizeof(inarg); |
---|
890 | | - args.in.args[0].value = &inarg; |
---|
891 | | - args.in.args[1].size = newent->d_name.len + 1; |
---|
892 | | - args.in.args[1].value = newent->d_name.name; |
---|
893 | | - err = create_new_entry(fc, &args, newdir, newent, inode->i_mode); |
---|
| 1020 | + args.opcode = FUSE_LINK; |
---|
| 1021 | + args.in_numargs = 2; |
---|
| 1022 | + args.in_args[0].size = sizeof(inarg); |
---|
| 1023 | + args.in_args[0].value = &inarg; |
---|
| 1024 | + args.in_args[1].size = newent->d_name.len + 1; |
---|
| 1025 | + args.in_args[1].value = newent->d_name.name; |
---|
| 1026 | + err = create_new_entry(fm, &args, newdir, newent, inode->i_mode); |
---|
894 | 1027 | /* Contrary to "normal" filesystems it can happen that link |
---|
895 | 1028 | makes two "logical" inodes point to the same "physical" |
---|
896 | 1029 | inode. We invalidate the attributes of the old one, so it |
---|
.. | .. |
---|
900 | 1033 | if (!err) { |
---|
901 | 1034 | struct fuse_inode *fi = get_fuse_inode(inode); |
---|
902 | 1035 | |
---|
903 | | - spin_lock(&fc->lock); |
---|
904 | | - fi->attr_version = ++fc->attr_version; |
---|
| 1036 | + spin_lock(&fi->lock); |
---|
| 1037 | + fi->attr_version = atomic64_inc_return(&fm->fc->attr_version); |
---|
905 | 1038 | if (likely(inode->i_nlink < UINT_MAX)) |
---|
906 | 1039 | inc_nlink(inode); |
---|
907 | | - spin_unlock(&fc->lock); |
---|
| 1040 | + spin_unlock(&fi->lock); |
---|
908 | 1041 | fuse_invalidate_attr(inode); |
---|
909 | 1042 | fuse_update_ctime(inode); |
---|
910 | 1043 | } else if (err == -EINTR) { |
---|
.. | .. |
---|
958 | 1091 | int err; |
---|
959 | 1092 | struct fuse_getattr_in inarg; |
---|
960 | 1093 | struct fuse_attr_out outarg; |
---|
961 | | - struct fuse_conn *fc = get_fuse_conn(inode); |
---|
| 1094 | + struct fuse_mount *fm = get_fuse_mount(inode); |
---|
962 | 1095 | FUSE_ARGS(args); |
---|
963 | 1096 | u64 attr_version; |
---|
964 | 1097 | |
---|
965 | | - attr_version = fuse_get_attr_version(fc); |
---|
| 1098 | + attr_version = fuse_get_attr_version(fm->fc); |
---|
966 | 1099 | |
---|
967 | 1100 | memset(&inarg, 0, sizeof(inarg)); |
---|
968 | 1101 | memset(&outarg, 0, sizeof(outarg)); |
---|
.. | .. |
---|
973 | 1106 | inarg.getattr_flags |= FUSE_GETATTR_FH; |
---|
974 | 1107 | inarg.fh = ff->fh; |
---|
975 | 1108 | } |
---|
976 | | - args.in.h.opcode = FUSE_GETATTR; |
---|
977 | | - args.in.h.nodeid = get_node_id(inode); |
---|
978 | | - args.in.numargs = 1; |
---|
979 | | - args.in.args[0].size = sizeof(inarg); |
---|
980 | | - args.in.args[0].value = &inarg; |
---|
981 | | - args.out.numargs = 1; |
---|
982 | | - args.out.args[0].size = sizeof(outarg); |
---|
983 | | - args.out.args[0].value = &outarg; |
---|
984 | | - err = fuse_simple_request(fc, &args); |
---|
| 1109 | + args.opcode = FUSE_GETATTR; |
---|
| 1110 | + args.nodeid = get_node_id(inode); |
---|
| 1111 | + args.in_numargs = 1; |
---|
| 1112 | + args.in_args[0].size = sizeof(inarg); |
---|
| 1113 | + args.in_args[0].value = &inarg; |
---|
| 1114 | + args.out_numargs = 1; |
---|
| 1115 | + args.out_args[0].size = sizeof(outarg); |
---|
| 1116 | + args.out_args[0].value = &outarg; |
---|
| 1117 | + err = fuse_simple_request(fm, &args); |
---|
985 | 1118 | if (!err) { |
---|
986 | 1119 | if (fuse_invalid_attr(&outarg.attr) || |
---|
987 | | - (inode->i_mode ^ outarg.attr.mode) & S_IFMT) { |
---|
| 1120 | + inode_wrong_type(inode, outarg.attr.mode)) { |
---|
988 | 1121 | fuse_make_bad(inode); |
---|
989 | 1122 | err = -EIO; |
---|
990 | 1123 | } else { |
---|
.. | .. |
---|
999 | 1132 | } |
---|
1000 | 1133 | |
---|
1001 | 1134 | static int fuse_update_get_attr(struct inode *inode, struct file *file, |
---|
1002 | | - struct kstat *stat, unsigned int flags) |
---|
| 1135 | + struct kstat *stat, u32 request_mask, |
---|
| 1136 | + unsigned int flags) |
---|
1003 | 1137 | { |
---|
1004 | 1138 | struct fuse_inode *fi = get_fuse_inode(inode); |
---|
1005 | 1139 | int err = 0; |
---|
.. | .. |
---|
1009 | 1143 | sync = true; |
---|
1010 | 1144 | else if (flags & AT_STATX_DONT_SYNC) |
---|
1011 | 1145 | sync = false; |
---|
| 1146 | + else if (request_mask & READ_ONCE(fi->inval_mask)) |
---|
| 1147 | + sync = true; |
---|
1012 | 1148 | else |
---|
1013 | 1149 | sync = time_before64(fi->i_time, get_jiffies_64()); |
---|
1014 | 1150 | |
---|
.. | .. |
---|
1026 | 1162 | |
---|
1027 | 1163 | int fuse_update_attributes(struct inode *inode, struct file *file) |
---|
1028 | 1164 | { |
---|
1029 | | - return fuse_update_get_attr(inode, file, NULL, 0); |
---|
| 1165 | + /* Do *not* need to get atime for internal purposes */ |
---|
| 1166 | + return fuse_update_get_attr(inode, file, NULL, |
---|
| 1167 | + STATX_BASIC_STATS & ~STATX_ATIME, 0); |
---|
1030 | 1168 | } |
---|
1031 | 1169 | |
---|
1032 | | -int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, |
---|
| 1170 | +int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid, |
---|
1033 | 1171 | u64 child_nodeid, struct qstr *name) |
---|
1034 | 1172 | { |
---|
1035 | 1173 | int err = -ENOTDIR; |
---|
.. | .. |
---|
1037 | 1175 | struct dentry *dir; |
---|
1038 | 1176 | struct dentry *entry; |
---|
1039 | 1177 | |
---|
1040 | | - parent = ilookup5(sb, parent_nodeid, fuse_inode_eq, &parent_nodeid); |
---|
| 1178 | + parent = fuse_ilookup(fc, parent_nodeid, NULL); |
---|
1041 | 1179 | if (!parent) |
---|
1042 | 1180 | return -ENOENT; |
---|
1043 | 1181 | |
---|
.. | .. |
---|
1056 | 1194 | if (!entry) |
---|
1057 | 1195 | goto unlock; |
---|
1058 | 1196 | |
---|
1059 | | - fuse_invalidate_attr(parent); |
---|
| 1197 | + fuse_dir_changed(parent); |
---|
1060 | 1198 | fuse_invalidate_entry(entry); |
---|
1061 | 1199 | |
---|
1062 | 1200 | if (child_nodeid != 0 && d_really_is_positive(entry)) { |
---|
.. | .. |
---|
1129 | 1267 | |
---|
1130 | 1268 | static int fuse_access(struct inode *inode, int mask) |
---|
1131 | 1269 | { |
---|
1132 | | - struct fuse_conn *fc = get_fuse_conn(inode); |
---|
| 1270 | + struct fuse_mount *fm = get_fuse_mount(inode); |
---|
1133 | 1271 | FUSE_ARGS(args); |
---|
1134 | 1272 | struct fuse_access_in inarg; |
---|
1135 | 1273 | int err; |
---|
1136 | 1274 | |
---|
1137 | 1275 | BUG_ON(mask & MAY_NOT_BLOCK); |
---|
1138 | 1276 | |
---|
1139 | | - if (fc->no_access) |
---|
| 1277 | + if (fm->fc->no_access) |
---|
1140 | 1278 | return 0; |
---|
1141 | 1279 | |
---|
1142 | 1280 | memset(&inarg, 0, sizeof(inarg)); |
---|
1143 | 1281 | inarg.mask = mask & (MAY_READ | MAY_WRITE | MAY_EXEC); |
---|
1144 | | - args.in.h.opcode = FUSE_ACCESS; |
---|
1145 | | - args.in.h.nodeid = get_node_id(inode); |
---|
1146 | | - args.in.numargs = 1; |
---|
1147 | | - args.in.args[0].size = sizeof(inarg); |
---|
1148 | | - args.in.args[0].value = &inarg; |
---|
1149 | | - err = fuse_simple_request(fc, &args); |
---|
| 1282 | + args.opcode = FUSE_ACCESS; |
---|
| 1283 | + args.nodeid = get_node_id(inode); |
---|
| 1284 | + args.in_numargs = 1; |
---|
| 1285 | + args.in_args[0].size = sizeof(inarg); |
---|
| 1286 | + args.in_args[0].value = &inarg; |
---|
| 1287 | + err = fuse_simple_request(fm, &args); |
---|
1150 | 1288 | if (err == -ENOSYS) { |
---|
1151 | | - fc->no_access = 1; |
---|
| 1289 | + fm->fc->no_access = 1; |
---|
1152 | 1290 | err = 0; |
---|
1153 | 1291 | } |
---|
1154 | 1292 | return err; |
---|
.. | .. |
---|
1194 | 1332 | if (fc->default_permissions || |
---|
1195 | 1333 | ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) { |
---|
1196 | 1334 | struct fuse_inode *fi = get_fuse_inode(inode); |
---|
| 1335 | + u32 perm_mask = STATX_MODE | STATX_UID | STATX_GID; |
---|
1197 | 1336 | |
---|
1198 | | - if (time_before64(fi->i_time, get_jiffies_64())) { |
---|
| 1337 | + if (perm_mask & READ_ONCE(fi->inval_mask) || |
---|
| 1338 | + time_before64(fi->i_time, get_jiffies_64())) { |
---|
1199 | 1339 | refreshed = true; |
---|
1200 | 1340 | |
---|
1201 | 1341 | err = fuse_perm_getattr(inode, mask); |
---|
.. | .. |
---|
1235 | 1375 | return err; |
---|
1236 | 1376 | } |
---|
1237 | 1377 | |
---|
1238 | | -static int parse_dirfile(char *buf, size_t nbytes, struct file *file, |
---|
1239 | | - struct dir_context *ctx) |
---|
| 1378 | +static int fuse_readlink_page(struct inode *inode, struct page *page) |
---|
1240 | 1379 | { |
---|
1241 | | - while (nbytes >= FUSE_NAME_OFFSET) { |
---|
1242 | | - struct fuse_dirent *dirent = (struct fuse_dirent *) buf; |
---|
1243 | | - size_t reclen = FUSE_DIRENT_SIZE(dirent); |
---|
1244 | | - if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX) |
---|
1245 | | - return -EIO; |
---|
1246 | | - if (reclen > nbytes) |
---|
1247 | | - break; |
---|
1248 | | - if (memchr(dirent->name, '/', dirent->namelen) != NULL) |
---|
1249 | | - return -EIO; |
---|
| 1380 | + struct fuse_mount *fm = get_fuse_mount(inode); |
---|
| 1381 | + struct fuse_page_desc desc = { .length = PAGE_SIZE - 1 }; |
---|
| 1382 | + struct fuse_args_pages ap = { |
---|
| 1383 | + .num_pages = 1, |
---|
| 1384 | + .pages = &page, |
---|
| 1385 | + .descs = &desc, |
---|
| 1386 | + }; |
---|
| 1387 | + char *link; |
---|
| 1388 | + ssize_t res; |
---|
1250 | 1389 | |
---|
1251 | | - if (!dir_emit(ctx, dirent->name, dirent->namelen, |
---|
1252 | | - dirent->ino, dirent->type)) |
---|
1253 | | - break; |
---|
| 1390 | + ap.args.opcode = FUSE_READLINK; |
---|
| 1391 | + ap.args.nodeid = get_node_id(inode); |
---|
| 1392 | + ap.args.out_pages = true; |
---|
| 1393 | + ap.args.out_argvar = true; |
---|
| 1394 | + ap.args.page_zeroing = true; |
---|
| 1395 | + ap.args.out_numargs = 1; |
---|
| 1396 | + ap.args.out_args[0].size = desc.length; |
---|
| 1397 | + res = fuse_simple_request(fm, &ap.args); |
---|
1254 | 1398 | |
---|
1255 | | - buf += reclen; |
---|
1256 | | - nbytes -= reclen; |
---|
1257 | | - ctx->pos = dirent->off; |
---|
1258 | | - } |
---|
| 1399 | + fuse_invalidate_atime(inode); |
---|
1259 | 1400 | |
---|
1260 | | - return 0; |
---|
1261 | | -} |
---|
| 1401 | + if (res < 0) |
---|
| 1402 | + return res; |
---|
1262 | 1403 | |
---|
1263 | | -static int fuse_direntplus_link(struct file *file, |
---|
1264 | | - struct fuse_direntplus *direntplus, |
---|
1265 | | - u64 attr_version) |
---|
1266 | | -{ |
---|
1267 | | - struct fuse_entry_out *o = &direntplus->entry_out; |
---|
1268 | | - struct fuse_dirent *dirent = &direntplus->dirent; |
---|
1269 | | - struct dentry *parent = file->f_path.dentry; |
---|
1270 | | - struct qstr name = QSTR_INIT(dirent->name, dirent->namelen); |
---|
1271 | | - struct dentry *dentry; |
---|
1272 | | - struct dentry *alias; |
---|
1273 | | - struct inode *dir = d_inode(parent); |
---|
1274 | | - struct fuse_conn *fc; |
---|
1275 | | - struct inode *inode; |
---|
1276 | | - DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(wq); |
---|
1277 | | - |
---|
1278 | | - if (!o->nodeid) { |
---|
1279 | | - /* |
---|
1280 | | - * Unlike in the case of fuse_lookup, zero nodeid does not mean |
---|
1281 | | - * ENOENT. Instead, it only means the userspace filesystem did |
---|
1282 | | - * not want to return attributes/handle for this entry. |
---|
1283 | | - * |
---|
1284 | | - * So do nothing. |
---|
1285 | | - */ |
---|
1286 | | - return 0; |
---|
1287 | | - } |
---|
1288 | | - |
---|
1289 | | - if (name.name[0] == '.') { |
---|
1290 | | - /* |
---|
1291 | | - * We could potentially refresh the attributes of the directory |
---|
1292 | | - * and its parent? |
---|
1293 | | - */ |
---|
1294 | | - if (name.len == 1) |
---|
1295 | | - return 0; |
---|
1296 | | - if (name.name[1] == '.' && name.len == 2) |
---|
1297 | | - return 0; |
---|
1298 | | - } |
---|
1299 | | - |
---|
1300 | | - if (invalid_nodeid(o->nodeid)) |
---|
1301 | | - return -EIO; |
---|
1302 | | - if (fuse_invalid_attr(&o->attr)) |
---|
| 1404 | + if (WARN_ON(res >= PAGE_SIZE)) |
---|
1303 | 1405 | return -EIO; |
---|
1304 | 1406 | |
---|
1305 | | - fc = get_fuse_conn(dir); |
---|
1306 | | - |
---|
1307 | | - name.hash = full_name_hash(parent, name.name, name.len); |
---|
1308 | | - dentry = d_lookup(parent, &name); |
---|
1309 | | - if (!dentry) { |
---|
1310 | | -retry: |
---|
1311 | | - dentry = d_alloc_parallel(parent, &name, &wq); |
---|
1312 | | - if (IS_ERR(dentry)) |
---|
1313 | | - return PTR_ERR(dentry); |
---|
1314 | | - } |
---|
1315 | | - if (!d_in_lookup(dentry)) { |
---|
1316 | | - struct fuse_inode *fi; |
---|
1317 | | - inode = d_inode(dentry); |
---|
1318 | | - if (!inode || |
---|
1319 | | - get_node_id(inode) != o->nodeid || |
---|
1320 | | - ((o->attr.mode ^ inode->i_mode) & S_IFMT)) { |
---|
1321 | | - d_invalidate(dentry); |
---|
1322 | | - dput(dentry); |
---|
1323 | | - goto retry; |
---|
1324 | | - } |
---|
1325 | | - if (fuse_is_bad(inode)) { |
---|
1326 | | - dput(dentry); |
---|
1327 | | - return -EIO; |
---|
1328 | | - } |
---|
1329 | | - |
---|
1330 | | - fi = get_fuse_inode(inode); |
---|
1331 | | - spin_lock(&fc->lock); |
---|
1332 | | - fi->nlookup++; |
---|
1333 | | - spin_unlock(&fc->lock); |
---|
1334 | | - |
---|
1335 | | - forget_all_cached_acls(inode); |
---|
1336 | | - fuse_change_attributes(inode, &o->attr, |
---|
1337 | | - entry_attr_timeout(o), |
---|
1338 | | - attr_version); |
---|
1339 | | - /* |
---|
1340 | | - * The other branch comes via fuse_iget() |
---|
1341 | | - * which bumps nlookup inside |
---|
1342 | | - */ |
---|
1343 | | - } else { |
---|
1344 | | - inode = fuse_iget(dir->i_sb, o->nodeid, o->generation, |
---|
1345 | | - &o->attr, entry_attr_timeout(o), |
---|
1346 | | - attr_version); |
---|
1347 | | - if (!inode) |
---|
1348 | | - inode = ERR_PTR(-ENOMEM); |
---|
1349 | | - |
---|
1350 | | - alias = d_splice_alias(inode, dentry); |
---|
1351 | | - d_lookup_done(dentry); |
---|
1352 | | - if (alias) { |
---|
1353 | | - dput(dentry); |
---|
1354 | | - dentry = alias; |
---|
1355 | | - } |
---|
1356 | | - if (IS_ERR(dentry)) |
---|
1357 | | - return PTR_ERR(dentry); |
---|
1358 | | - } |
---|
1359 | | - if (fc->readdirplus_auto) |
---|
1360 | | - set_bit(FUSE_I_INIT_RDPLUS, &get_fuse_inode(inode)->state); |
---|
1361 | | - fuse_change_entry_timeout(dentry, o); |
---|
1362 | | - |
---|
1363 | | - dput(dentry); |
---|
1364 | | - return 0; |
---|
1365 | | -} |
---|
1366 | | - |
---|
1367 | | -static int parse_dirplusfile(char *buf, size_t nbytes, struct file *file, |
---|
1368 | | - struct dir_context *ctx, u64 attr_version) |
---|
1369 | | -{ |
---|
1370 | | - struct fuse_direntplus *direntplus; |
---|
1371 | | - struct fuse_dirent *dirent; |
---|
1372 | | - size_t reclen; |
---|
1373 | | - int over = 0; |
---|
1374 | | - int ret; |
---|
1375 | | - |
---|
1376 | | - while (nbytes >= FUSE_NAME_OFFSET_DIRENTPLUS) { |
---|
1377 | | - direntplus = (struct fuse_direntplus *) buf; |
---|
1378 | | - dirent = &direntplus->dirent; |
---|
1379 | | - reclen = FUSE_DIRENTPLUS_SIZE(direntplus); |
---|
1380 | | - |
---|
1381 | | - if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX) |
---|
1382 | | - return -EIO; |
---|
1383 | | - if (reclen > nbytes) |
---|
1384 | | - break; |
---|
1385 | | - if (memchr(dirent->name, '/', dirent->namelen) != NULL) |
---|
1386 | | - return -EIO; |
---|
1387 | | - |
---|
1388 | | - if (!over) { |
---|
1389 | | - /* We fill entries into dstbuf only as much as |
---|
1390 | | - it can hold. But we still continue iterating |
---|
1391 | | - over remaining entries to link them. If not, |
---|
1392 | | - we need to send a FORGET for each of those |
---|
1393 | | - which we did not link. |
---|
1394 | | - */ |
---|
1395 | | - over = !dir_emit(ctx, dirent->name, dirent->namelen, |
---|
1396 | | - dirent->ino, dirent->type); |
---|
1397 | | - if (!over) |
---|
1398 | | - ctx->pos = dirent->off; |
---|
1399 | | - } |
---|
1400 | | - |
---|
1401 | | - buf += reclen; |
---|
1402 | | - nbytes -= reclen; |
---|
1403 | | - |
---|
1404 | | - ret = fuse_direntplus_link(file, direntplus, attr_version); |
---|
1405 | | - if (ret) |
---|
1406 | | - fuse_force_forget(file, direntplus->entry_out.nodeid); |
---|
1407 | | - } |
---|
| 1407 | + link = page_address(page); |
---|
| 1408 | + link[res] = '\0'; |
---|
1408 | 1409 | |
---|
1409 | 1410 | return 0; |
---|
1410 | 1411 | } |
---|
1411 | 1412 | |
---|
1412 | | -static int fuse_readdir(struct file *file, struct dir_context *ctx) |
---|
| 1413 | +static const char *fuse_get_link(struct dentry *dentry, struct inode *inode, |
---|
| 1414 | + struct delayed_call *callback) |
---|
1413 | 1415 | { |
---|
1414 | | - int plus, err; |
---|
1415 | | - size_t nbytes; |
---|
1416 | | - struct page *page; |
---|
1417 | | - struct inode *inode = file_inode(file); |
---|
1418 | 1416 | struct fuse_conn *fc = get_fuse_conn(inode); |
---|
1419 | | - struct fuse_req *req; |
---|
1420 | | - u64 attr_version = 0; |
---|
1421 | | - bool locked; |
---|
| 1417 | + struct page *page; |
---|
| 1418 | + int err; |
---|
1422 | 1419 | |
---|
| 1420 | + err = -EIO; |
---|
1423 | 1421 | if (fuse_is_bad(inode)) |
---|
1424 | | - return -EIO; |
---|
| 1422 | + goto out_err; |
---|
1425 | 1423 | |
---|
1426 | | - req = fuse_get_req(fc, 1); |
---|
1427 | | - if (IS_ERR(req)) |
---|
1428 | | - return PTR_ERR(req); |
---|
| 1424 | + if (fc->cache_symlinks) |
---|
| 1425 | + return page_get_link(dentry, inode, callback); |
---|
| 1426 | + |
---|
| 1427 | + err = -ECHILD; |
---|
| 1428 | + if (!dentry) |
---|
| 1429 | + goto out_err; |
---|
1429 | 1430 | |
---|
1430 | 1431 | page = alloc_page(GFP_KERNEL); |
---|
1431 | | - if (!page) { |
---|
1432 | | - fuse_put_request(fc, req); |
---|
1433 | | - return -ENOMEM; |
---|
| 1432 | + err = -ENOMEM; |
---|
| 1433 | + if (!page) |
---|
| 1434 | + goto out_err; |
---|
| 1435 | + |
---|
| 1436 | + err = fuse_readlink_page(inode, page); |
---|
| 1437 | + if (err) { |
---|
| 1438 | + __free_page(page); |
---|
| 1439 | + goto out_err; |
---|
1434 | 1440 | } |
---|
1435 | 1441 | |
---|
1436 | | - plus = fuse_use_readdirplus(inode, ctx); |
---|
1437 | | - req->out.argpages = 1; |
---|
1438 | | - req->num_pages = 1; |
---|
1439 | | - req->pages[0] = page; |
---|
1440 | | - req->page_descs[0].length = PAGE_SIZE; |
---|
1441 | | - if (plus) { |
---|
1442 | | - attr_version = fuse_get_attr_version(fc); |
---|
1443 | | - fuse_read_fill(req, file, ctx->pos, PAGE_SIZE, |
---|
1444 | | - FUSE_READDIRPLUS); |
---|
1445 | | - } else { |
---|
1446 | | - fuse_read_fill(req, file, ctx->pos, PAGE_SIZE, |
---|
1447 | | - FUSE_READDIR); |
---|
1448 | | - } |
---|
1449 | | - locked = fuse_lock_inode(inode); |
---|
1450 | | - fuse_request_send(fc, req); |
---|
1451 | | - fuse_unlock_inode(inode, locked); |
---|
1452 | | - nbytes = req->out.args[0].size; |
---|
1453 | | - err = req->out.h.error; |
---|
1454 | | - fuse_put_request(fc, req); |
---|
1455 | | - if (!err) { |
---|
1456 | | - if (plus) { |
---|
1457 | | - err = parse_dirplusfile(page_address(page), nbytes, |
---|
1458 | | - file, ctx, |
---|
1459 | | - attr_version); |
---|
1460 | | - } else { |
---|
1461 | | - err = parse_dirfile(page_address(page), nbytes, file, |
---|
1462 | | - ctx); |
---|
1463 | | - } |
---|
1464 | | - } |
---|
| 1442 | + set_delayed_call(callback, page_put_link, page); |
---|
1465 | 1443 | |
---|
1466 | | - __free_page(page); |
---|
1467 | | - fuse_invalidate_atime(inode); |
---|
1468 | | - return err; |
---|
1469 | | -} |
---|
| 1444 | + return page_address(page); |
---|
1470 | 1445 | |
---|
1471 | | -static const char *fuse_get_link(struct dentry *dentry, |
---|
1472 | | - struct inode *inode, |
---|
1473 | | - struct delayed_call *done) |
---|
1474 | | -{ |
---|
1475 | | - struct fuse_conn *fc = get_fuse_conn(inode); |
---|
1476 | | - FUSE_ARGS(args); |
---|
1477 | | - char *link; |
---|
1478 | | - ssize_t ret; |
---|
1479 | | - |
---|
1480 | | - if (!dentry) |
---|
1481 | | - return ERR_PTR(-ECHILD); |
---|
1482 | | - |
---|
1483 | | - if (fuse_is_bad(inode)) |
---|
1484 | | - return ERR_PTR(-EIO); |
---|
1485 | | - |
---|
1486 | | - link = kmalloc(PAGE_SIZE, GFP_KERNEL); |
---|
1487 | | - if (!link) |
---|
1488 | | - return ERR_PTR(-ENOMEM); |
---|
1489 | | - |
---|
1490 | | - args.in.h.opcode = FUSE_READLINK; |
---|
1491 | | - args.in.h.nodeid = get_node_id(inode); |
---|
1492 | | - args.out.argvar = 1; |
---|
1493 | | - args.out.numargs = 1; |
---|
1494 | | - args.out.args[0].size = PAGE_SIZE - 1; |
---|
1495 | | - args.out.args[0].value = link; |
---|
1496 | | - ret = fuse_simple_request(fc, &args); |
---|
1497 | | - if (ret < 0) { |
---|
1498 | | - kfree(link); |
---|
1499 | | - link = ERR_PTR(ret); |
---|
1500 | | - } else { |
---|
1501 | | - link[ret] = '\0'; |
---|
1502 | | - set_delayed_call(done, kfree_link, link); |
---|
1503 | | - } |
---|
1504 | | - fuse_invalidate_atime(inode); |
---|
1505 | | - return link; |
---|
| 1446 | +out_err: |
---|
| 1447 | + return ERR_PTR(err); |
---|
1506 | 1448 | } |
---|
1507 | 1449 | |
---|
1508 | 1450 | static int fuse_dir_open(struct inode *inode, struct file *file) |
---|
.. | .. |
---|
1520 | 1462 | static int fuse_dir_fsync(struct file *file, loff_t start, loff_t end, |
---|
1521 | 1463 | int datasync) |
---|
1522 | 1464 | { |
---|
1523 | | - return fuse_fsync_common(file, start, end, datasync, 1); |
---|
| 1465 | + struct inode *inode = file->f_mapping->host; |
---|
| 1466 | + struct fuse_conn *fc = get_fuse_conn(inode); |
---|
| 1467 | + int err; |
---|
| 1468 | + |
---|
| 1469 | + if (fuse_is_bad(inode)) |
---|
| 1470 | + return -EIO; |
---|
| 1471 | + |
---|
| 1472 | + if (fc->no_fsyncdir) |
---|
| 1473 | + return 0; |
---|
| 1474 | + |
---|
| 1475 | + inode_lock(inode); |
---|
| 1476 | + err = fuse_fsync_common(file, start, end, datasync, FUSE_FSYNCDIR); |
---|
| 1477 | + if (err == -ENOSYS) { |
---|
| 1478 | + fc->no_fsyncdir = 1; |
---|
| 1479 | + err = 0; |
---|
| 1480 | + } |
---|
| 1481 | + inode_unlock(inode); |
---|
| 1482 | + |
---|
| 1483 | + return err; |
---|
1524 | 1484 | } |
---|
1525 | 1485 | |
---|
1526 | 1486 | static long fuse_dir_ioctl(struct file *file, unsigned int cmd, |
---|
.. | .. |
---|
1607 | 1567 | */ |
---|
1608 | 1568 | void fuse_set_nowrite(struct inode *inode) |
---|
1609 | 1569 | { |
---|
1610 | | - struct fuse_conn *fc = get_fuse_conn(inode); |
---|
1611 | 1570 | struct fuse_inode *fi = get_fuse_inode(inode); |
---|
1612 | 1571 | |
---|
1613 | 1572 | BUG_ON(!inode_is_locked(inode)); |
---|
1614 | 1573 | |
---|
1615 | | - spin_lock(&fc->lock); |
---|
| 1574 | + spin_lock(&fi->lock); |
---|
1616 | 1575 | BUG_ON(fi->writectr < 0); |
---|
1617 | 1576 | fi->writectr += FUSE_NOWRITE; |
---|
1618 | | - spin_unlock(&fc->lock); |
---|
| 1577 | + spin_unlock(&fi->lock); |
---|
1619 | 1578 | wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE); |
---|
1620 | 1579 | } |
---|
1621 | 1580 | |
---|
.. | .. |
---|
1636 | 1595 | |
---|
1637 | 1596 | void fuse_release_nowrite(struct inode *inode) |
---|
1638 | 1597 | { |
---|
1639 | | - struct fuse_conn *fc = get_fuse_conn(inode); |
---|
| 1598 | + struct fuse_inode *fi = get_fuse_inode(inode); |
---|
1640 | 1599 | |
---|
1641 | | - spin_lock(&fc->lock); |
---|
| 1600 | + spin_lock(&fi->lock); |
---|
1642 | 1601 | __fuse_release_nowrite(inode); |
---|
1643 | | - spin_unlock(&fc->lock); |
---|
| 1602 | + spin_unlock(&fi->lock); |
---|
1644 | 1603 | } |
---|
1645 | 1604 | |
---|
1646 | 1605 | static void fuse_setattr_fill(struct fuse_conn *fc, struct fuse_args *args, |
---|
.. | .. |
---|
1648 | 1607 | struct fuse_setattr_in *inarg_p, |
---|
1649 | 1608 | struct fuse_attr_out *outarg_p) |
---|
1650 | 1609 | { |
---|
1651 | | - args->in.h.opcode = FUSE_SETATTR; |
---|
1652 | | - args->in.h.nodeid = get_node_id(inode); |
---|
1653 | | - args->in.numargs = 1; |
---|
1654 | | - args->in.args[0].size = sizeof(*inarg_p); |
---|
1655 | | - args->in.args[0].value = inarg_p; |
---|
1656 | | - args->out.numargs = 1; |
---|
1657 | | - args->out.args[0].size = sizeof(*outarg_p); |
---|
1658 | | - args->out.args[0].value = outarg_p; |
---|
| 1610 | + args->opcode = FUSE_SETATTR; |
---|
| 1611 | + args->nodeid = get_node_id(inode); |
---|
| 1612 | + args->in_numargs = 1; |
---|
| 1613 | + args->in_args[0].size = sizeof(*inarg_p); |
---|
| 1614 | + args->in_args[0].value = inarg_p; |
---|
| 1615 | + args->out_numargs = 1; |
---|
| 1616 | + args->out_args[0].size = sizeof(*outarg_p); |
---|
| 1617 | + args->out_args[0].value = outarg_p; |
---|
1659 | 1618 | } |
---|
1660 | 1619 | |
---|
1661 | 1620 | /* |
---|
.. | .. |
---|
1663 | 1622 | */ |
---|
1664 | 1623 | int fuse_flush_times(struct inode *inode, struct fuse_file *ff) |
---|
1665 | 1624 | { |
---|
1666 | | - struct fuse_conn *fc = get_fuse_conn(inode); |
---|
| 1625 | + struct fuse_mount *fm = get_fuse_mount(inode); |
---|
1667 | 1626 | FUSE_ARGS(args); |
---|
1668 | 1627 | struct fuse_setattr_in inarg; |
---|
1669 | 1628 | struct fuse_attr_out outarg; |
---|
.. | .. |
---|
1674 | 1633 | inarg.valid = FATTR_MTIME; |
---|
1675 | 1634 | inarg.mtime = inode->i_mtime.tv_sec; |
---|
1676 | 1635 | inarg.mtimensec = inode->i_mtime.tv_nsec; |
---|
1677 | | - if (fc->minor >= 23) { |
---|
| 1636 | + if (fm->fc->minor >= 23) { |
---|
1678 | 1637 | inarg.valid |= FATTR_CTIME; |
---|
1679 | 1638 | inarg.ctime = inode->i_ctime.tv_sec; |
---|
1680 | 1639 | inarg.ctimensec = inode->i_ctime.tv_nsec; |
---|
.. | .. |
---|
1683 | 1642 | inarg.valid |= FATTR_FH; |
---|
1684 | 1643 | inarg.fh = ff->fh; |
---|
1685 | 1644 | } |
---|
1686 | | - fuse_setattr_fill(fc, &args, inode, &inarg, &outarg); |
---|
| 1645 | + fuse_setattr_fill(fm->fc, &args, inode, &inarg, &outarg); |
---|
1687 | 1646 | |
---|
1688 | | - return fuse_simple_request(fc, &args); |
---|
| 1647 | + return fuse_simple_request(fm, &args); |
---|
1689 | 1648 | } |
---|
1690 | 1649 | |
---|
1691 | 1650 | /* |
---|
.. | .. |
---|
1700 | 1659 | struct file *file) |
---|
1701 | 1660 | { |
---|
1702 | 1661 | struct inode *inode = d_inode(dentry); |
---|
1703 | | - struct fuse_conn *fc = get_fuse_conn(inode); |
---|
| 1662 | + struct fuse_mount *fm = get_fuse_mount(inode); |
---|
| 1663 | + struct fuse_conn *fc = fm->fc; |
---|
1704 | 1664 | struct fuse_inode *fi = get_fuse_inode(inode); |
---|
1705 | 1665 | FUSE_ARGS(args); |
---|
1706 | 1666 | struct fuse_setattr_in inarg; |
---|
.. | .. |
---|
1710 | 1670 | loff_t oldsize; |
---|
1711 | 1671 | int err; |
---|
1712 | 1672 | bool trust_local_cmtime = is_wb && S_ISREG(inode->i_mode); |
---|
| 1673 | + bool fault_blocked = false; |
---|
1713 | 1674 | |
---|
1714 | 1675 | if (!fc->default_permissions) |
---|
1715 | 1676 | attr->ia_valid |= ATTR_FORCE; |
---|
.. | .. |
---|
1717 | 1678 | err = setattr_prepare(dentry, attr); |
---|
1718 | 1679 | if (err) |
---|
1719 | 1680 | return err; |
---|
| 1681 | + |
---|
| 1682 | + if (attr->ia_valid & ATTR_SIZE) { |
---|
| 1683 | + if (WARN_ON(!S_ISREG(inode->i_mode))) |
---|
| 1684 | + return -EIO; |
---|
| 1685 | + is_truncate = true; |
---|
| 1686 | + } |
---|
| 1687 | + |
---|
| 1688 | + if (FUSE_IS_DAX(inode) && is_truncate) { |
---|
| 1689 | + down_write(&fi->i_mmap_sem); |
---|
| 1690 | + fault_blocked = true; |
---|
| 1691 | + err = fuse_dax_break_layouts(inode, 0, 0); |
---|
| 1692 | + if (err) { |
---|
| 1693 | + up_write(&fi->i_mmap_sem); |
---|
| 1694 | + return err; |
---|
| 1695 | + } |
---|
| 1696 | + } |
---|
1720 | 1697 | |
---|
1721 | 1698 | if (attr->ia_valid & ATTR_OPEN) { |
---|
1722 | 1699 | /* This is coming from open(..., ... | O_TRUNC); */ |
---|
.. | .. |
---|
1730 | 1707 | */ |
---|
1731 | 1708 | i_size_write(inode, 0); |
---|
1732 | 1709 | truncate_pagecache(inode, 0); |
---|
1733 | | - return 0; |
---|
| 1710 | + goto out; |
---|
1734 | 1711 | } |
---|
1735 | 1712 | file = NULL; |
---|
1736 | 1713 | } |
---|
1737 | | - |
---|
1738 | | - if (attr->ia_valid & ATTR_SIZE) |
---|
1739 | | - is_truncate = true; |
---|
1740 | 1714 | |
---|
1741 | 1715 | /* Flush dirty data/metadata before non-truncate SETATTR */ |
---|
1742 | 1716 | if (is_wb && S_ISREG(inode->i_mode) && |
---|
.. | .. |
---|
1772 | 1746 | inarg.lock_owner = fuse_lock_owner_id(fc, current->files); |
---|
1773 | 1747 | } |
---|
1774 | 1748 | fuse_setattr_fill(fc, &args, inode, &inarg, &outarg); |
---|
1775 | | - err = fuse_simple_request(fc, &args); |
---|
| 1749 | + err = fuse_simple_request(fm, &args); |
---|
1776 | 1750 | if (err) { |
---|
1777 | 1751 | if (err == -EINTR) |
---|
1778 | 1752 | fuse_invalidate_attr(inode); |
---|
.. | .. |
---|
1780 | 1754 | } |
---|
1781 | 1755 | |
---|
1782 | 1756 | if (fuse_invalid_attr(&outarg.attr) || |
---|
1783 | | - (inode->i_mode ^ outarg.attr.mode) & S_IFMT) { |
---|
| 1757 | + inode_wrong_type(inode, outarg.attr.mode)) { |
---|
1784 | 1758 | fuse_make_bad(inode); |
---|
1785 | 1759 | err = -EIO; |
---|
1786 | 1760 | goto error; |
---|
1787 | 1761 | } |
---|
1788 | 1762 | |
---|
1789 | | - spin_lock(&fc->lock); |
---|
| 1763 | + spin_lock(&fi->lock); |
---|
1790 | 1764 | /* the kernel maintains i_mtime locally */ |
---|
1791 | 1765 | if (trust_local_cmtime) { |
---|
1792 | 1766 | if (attr->ia_valid & ATTR_MTIME) |
---|
.. | .. |
---|
1804 | 1778 | i_size_write(inode, outarg.attr.size); |
---|
1805 | 1779 | |
---|
1806 | 1780 | if (is_truncate) { |
---|
1807 | | - /* NOTE: this may release/reacquire fc->lock */ |
---|
| 1781 | + /* NOTE: this may release/reacquire fi->lock */ |
---|
1808 | 1782 | __fuse_release_nowrite(inode); |
---|
1809 | 1783 | } |
---|
1810 | | - spin_unlock(&fc->lock); |
---|
| 1784 | + spin_unlock(&fi->lock); |
---|
1811 | 1785 | |
---|
1812 | 1786 | /* |
---|
1813 | 1787 | * Only call invalidate_inode_pages2() after removing |
---|
.. | .. |
---|
1820 | 1794 | } |
---|
1821 | 1795 | |
---|
1822 | 1796 | clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state); |
---|
| 1797 | +out: |
---|
| 1798 | + if (fault_blocked) |
---|
| 1799 | + up_write(&fi->i_mmap_sem); |
---|
| 1800 | + |
---|
1823 | 1801 | return 0; |
---|
1824 | 1802 | |
---|
1825 | 1803 | error: |
---|
.. | .. |
---|
1827 | 1805 | fuse_release_nowrite(inode); |
---|
1828 | 1806 | |
---|
1829 | 1807 | clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state); |
---|
| 1808 | + |
---|
| 1809 | + if (fault_blocked) |
---|
| 1810 | + up_write(&fi->i_mmap_sem); |
---|
1830 | 1811 | return err; |
---|
1831 | 1812 | } |
---|
1832 | 1813 | |
---|
.. | .. |
---|
1901 | 1882 | if (fuse_is_bad(inode)) |
---|
1902 | 1883 | return -EIO; |
---|
1903 | 1884 | |
---|
1904 | | - if (!fuse_allow_current_process(fc)) |
---|
| 1885 | + if (!fuse_allow_current_process(fc)) { |
---|
| 1886 | + if (!request_mask) { |
---|
| 1887 | + /* |
---|
| 1888 | + * If user explicitly requested *nothing* then don't |
---|
| 1889 | + * error out, but return st_dev only. |
---|
| 1890 | + */ |
---|
| 1891 | + stat->result_mask = 0; |
---|
| 1892 | + stat->dev = inode->i_sb->s_dev; |
---|
| 1893 | + return 0; |
---|
| 1894 | + } |
---|
1905 | 1895 | return -EACCES; |
---|
| 1896 | + } |
---|
1906 | 1897 | |
---|
1907 | | - return fuse_update_get_attr(inode, NULL, stat, flags); |
---|
| 1898 | + return fuse_update_get_attr(inode, NULL, stat, request_mask, flags); |
---|
1908 | 1899 | } |
---|
1909 | 1900 | |
---|
1910 | 1901 | static const struct inode_operations fuse_dir_inode_operations = { |
---|
.. | .. |
---|
1960 | 1951 | |
---|
1961 | 1952 | void fuse_init_dir(struct inode *inode) |
---|
1962 | 1953 | { |
---|
| 1954 | + struct fuse_inode *fi = get_fuse_inode(inode); |
---|
| 1955 | + |
---|
1963 | 1956 | inode->i_op = &fuse_dir_inode_operations; |
---|
1964 | 1957 | inode->i_fop = &fuse_dir_operations; |
---|
| 1958 | + |
---|
| 1959 | + spin_lock_init(&fi->rdc.lock); |
---|
| 1960 | + fi->rdc.cached = false; |
---|
| 1961 | + fi->rdc.size = 0; |
---|
| 1962 | + fi->rdc.pos = 0; |
---|
| 1963 | + fi->rdc.version = 0; |
---|
1965 | 1964 | } |
---|
| 1965 | + |
---|
| 1966 | +static int fuse_symlink_readpage(struct file *null, struct page *page) |
---|
| 1967 | +{ |
---|
| 1968 | + int err = fuse_readlink_page(page->mapping->host, page); |
---|
| 1969 | + |
---|
| 1970 | + if (!err) |
---|
| 1971 | + SetPageUptodate(page); |
---|
| 1972 | + |
---|
| 1973 | + unlock_page(page); |
---|
| 1974 | + |
---|
| 1975 | + return err; |
---|
| 1976 | +} |
---|
| 1977 | + |
---|
| 1978 | +static const struct address_space_operations fuse_symlink_aops = { |
---|
| 1979 | + .readpage = fuse_symlink_readpage, |
---|
| 1980 | +}; |
---|
1966 | 1981 | |
---|
1967 | 1982 | void fuse_init_symlink(struct inode *inode) |
---|
1968 | 1983 | { |
---|
1969 | 1984 | inode->i_op = &fuse_symlink_inode_operations; |
---|
| 1985 | + inode->i_data.a_ops = &fuse_symlink_aops; |
---|
| 1986 | + inode_nohighmem(inode); |
---|
1970 | 1987 | } |
---|