History

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull more vfs updates from Al Viro: "In this pile: - autofs-namespace series - dedupe stuff - more struct path constification" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (40 commits) ocfs2: implement the VFS clone_range, copy_range, and dedupe_range features ocfs2: charge quota for reflinked blocks ocfs2: fix bad pointer cast ocfs2: always unlock when completing dio writes ocfs2: don't eat io errors during _dio_end_io_write ocfs2: budget for extent tree splits when adding refcount flag ocfs2: prohibit refcounted swapfiles ocfs2: add newlines to some error messages ocfs2: convert inode refcount test to a helper simple_write_end(): don't zero in short copy into uptodate exofs: don't mess with simple_write_{begin,end} 9p: saner ->write_end() on failing copy into non-uptodate page fix gfs2_stuffed_write_end() on short copies fix ceph_write_end() nfs_write_end(): fix handling of short copies vfs: refactor clone/dedupe_file_range common functions fs: try to clone files first in vfs_copy_file_range vfs: misc struct path constification namespace.c: constify struct path passed to a bunch of primitives quota: constify struct path in quota_on ...

Linus Torvalds committed 9 years ago

Commit 0110c352 parents d9cb5bf 9763f7a64 files · +1027 −509Browse files

Unified · Split

64 files
  1. Documentation/filesystems/Locking +1 −1
  2. Documentation/filesystems/vfs.txt +1 −1
  3. arch/powerpc/oprofile/cell/spu_task_sync.c +1 −1
  4. drivers/oprofile/buffer_sync.c +1 −1
  5. fs/9p/vfs_addr.c +4 −11
  6. fs/autofs4/autofs_i.h +3 −2
  7. fs/autofs4/dev-ioctl.c +5 −5
  8. fs/autofs4/expire.c +15 −10
  9. fs/autofs4/root.c +32 −29
  10. fs/autofs4/waitq.c +9 −4
  11. fs/btrfs/ctree.h +0 −3
  12. fs/btrfs/file.c +0 −1
  13. fs/btrfs/ioctl.c +1 −13
  14. fs/ceph/addr.c +8 −6
  15. fs/dcache.c +23 −17
  16. fs/dcookies.c +2 −2
  17. fs/exofs/inode.c +30 −38
  18. fs/ext4/super.c +2 −2
  19. fs/file_table.c +1 −1
  20. fs/gfs2/aops.c +1 −3
  21. fs/internal.h +1 −1
  22. fs/libfs.c +8 −6
  23. fs/mount.h +6 −0
  24. fs/namei.c +8 −9
  25. fs/namespace.c +34 −5
  26. fs/nfs/file.c +1 −1
  27. fs/notify/dnotify/dnotify.c +1 −1
  28. fs/notify/fanotify/fanotify.c +4 −4
  29. fs/notify/fanotify/fanotify.h +1 −1
  30. fs/notify/fsnotify.c +4 −4
  31. fs/notify/inotify/inotify.h +1 −1
  32. fs/notify/inotify/inotify_fsnotify.c +2 −2
  33. fs/ocfs2/alloc.c +3 −4
  34. fs/ocfs2/aops.c +20 −11
  35. fs/ocfs2/file.c +35 −7
  36. fs/ocfs2/file.h +3 −0
  37. fs/ocfs2/inode.h +6 −0
  38. fs/ocfs2/move_extents.c +2 −8
  39. fs/ocfs2/refcounttree.c +451 −13
  40. fs/ocfs2/refcounttree.h +7 −0
  41. fs/ocfs2/xattr.c +2 −2
  42. fs/quota/dquot.c +1 −1
  43. fs/quota/quota.c +2 −2
  44. fs/read_write.c +226 −5
  45. fs/reiserfs/super.c +2 −2
  46. fs/statfs.c +1 −1
  47. fs/utimes.c +1 −1
  48. fs/xfs/xfs_file.c +0 −19
  49. fs/xfs/xfs_reflink.c +9 −210
  50. include/linux/audit.h +1 −1
  51. include/linux/dcache.h +2 −2
  52. include/linux/dcookies.h +2 −2
  53. include/linux/file.h +1 −1
  54. include/linux/fs.h +9 −3
  55. include/linux/fsnotify.h +6 −6
  56. include/linux/fsnotify_backend.h +5 −5
  57. include/linux/mount.h +4 −2
  58. include/linux/quota.h +1 −1
  59. include/linux/quotaops.h +1 −1
  60. kernel/audit.c +2 −2
  61. kernel/audit.h +1 −1
  62. kernel/audit_fsnotify.c +5 −5
  63. kernel/audit_tree.c +1 −1
  64. kernel/audit_watch.c +4 −4
Documentation/filesystems/Locking+1−1
@@ -20,7 +20,7 @@ prototypes: · 19 unmodified lines
2020 void (*d_iput)(struct dentry *, struct inode *);
2121 char *(*d_dname)((struct dentry *dentry, char *buffer, int buflen);
2222 struct vfsmount *(*d_automount)(struct path *path);
23− int (*d_manage)(struct dentry *, bool);
23+ int (*d_manage)(const struct path *, bool);
2424 struct dentry *(*d_real)(struct dentry *, const struct inode *,
2525 unsigned int);
2626
Documentation/filesystems/vfs.txt+1−1
@@ -948,7 +948,7 @@ struct dentry_operations { · 947 unmodified lines
948948 void (*d_iput)(struct dentry *, struct inode *);
949949 char *(*d_dname)(struct dentry *, char *, int);
950950 struct vfsmount *(*d_automount)(struct path *);
951− int (*d_manage)(struct dentry *, bool);
951+ int (*d_manage)(const struct path *, bool);
952952 struct dentry *(*d_real)(struct dentry *, const struct inode *,
953953 unsigned int);
954954 };
arch/powerpc/oprofile/cell/spu_task_sync.c+1−1
@@ -295,7 +295,7 @@ out: · 294 unmodified lines
295295 * dcookie user still being registered (namely, the reader
296296 * of the event buffer).
297297 */
298−static inline unsigned long fast_get_dcookie(struct path *path)
298+static inline unsigned long fast_get_dcookie(const struct path *path)
299299 {
300300 unsigned long cookie;
301301
drivers/oprofile/buffer_sync.c+1−1
@@ -206,7 +206,7 @@ void sync_stop(void) · 205 unmodified lines
206206 * because we cannot reach this code without at least one
207207 * dcookie user still being registered (namely, the reader
208208 * of the event buffer). */
209−static inline unsigned long fast_get_dcookie(struct path *path)
209+static inline unsigned long fast_get_dcookie(const struct path *path)
210210 {
211211 unsigned long cookie;
212212
fs/9p/vfs_addr.c+4−11
@@ -310,18 +310,10 @@ static int v9fs_write_end(struct file *filp, struct address_space *mapping, · 309 unmodified lines
310310
311311 p9_debug(P9_DEBUG_VFS, "filp %p, mapping %p\n", filp, mapping);
312312
313− if (unlikely(copied < len)) {
314− /*
315− * zero out the rest of the area
316− */
317− unsigned from = pos & (PAGE_SIZE - 1);
318−
319− zero_user(page, from + copied, len - copied);
320− flush_dcache_page(page);
313+ if (unlikely(copied < len && !PageUptodate(page))) {
314+ copied = 0;
315+ goto out;
321316 }
322−
323− if (!PageUptodate(page))
324− SetPageUptodate(page);
325317 /*
326318 * No need to use i_size_read() here, the i_size
327319 * cannot change under us because we hold the i_mutex.
@@ -331,6 +323,7 @@ static int v9fs_write_end(struct file *filp, struct address_space *mapping, · 3 unmodified lines
331323 i_size_write(inode, last_pos);
332324 }
333325 set_page_dirty(page);
326+out:
334327 unlock_page(page);
335328 put_page(page);
336329
fs/autofs4/autofs_i.h+3−2
@@ -145,7 +145,7 @@ void autofs4_free_ino(struct autofs_info *); · 144 unmodified lines
145145
146146 /* Expiration */
147147 int is_autofs4_dentry(struct dentry *);
148−int autofs4_expire_wait(struct dentry *dentry, int rcu_walk);
148+int autofs4_expire_wait(const struct path *path, int rcu_walk);
149149 int autofs4_expire_run(struct super_block *, struct vfsmount *,
150150 struct autofs_sb_info *,
151151 struct autofs_packet_expire __user *);
@@ -217,7 +217,8 @@ static inline int autofs_prepare_pipe(struct file *pipe) · 65 unmodified lines
217217
218218 /* Queue management functions */
219219
220−int autofs4_wait(struct autofs_sb_info *, struct dentry *, enum autofs_notify);
220+int autofs4_wait(struct autofs_sb_info *,
221+ const struct path *, enum autofs_notify);
221222 int autofs4_wait_release(struct autofs_sb_info *, autofs_wqt_t, int);
222223 void autofs4_catatonic_mode(struct autofs_sb_info *);
223224
fs/autofs4/dev-ioctl.c+5−5
@@ -204,7 +204,7 @@ static int autofs_dev_ioctl_protosubver(struct file *fp, · 203 unmodified lines
204204 /* Find the topmost mount satisfying test() */
205205 static int find_autofs_mount(const char *pathname,
206206 struct path *res,
207− int test(struct path *path, void *data),
207+ int test(const struct path *path, void *data),
208208 void *data)
209209 {
210210 struct path path;
@@ -230,12 +230,12 @@ static int find_autofs_mount(const char *pathname, · 19 unmodified lines
230230 return err;
231231 }
232232
233−static int test_by_dev(struct path *path, void *p)
233+static int test_by_dev(const struct path *path, void *p)
234234 {
235235 return path->dentry->d_sb->s_dev == *(dev_t *)p;
236236 }
237237
238−static int test_by_type(struct path *path, void *p)
238+static int test_by_type(const struct path *path, void *p)
239239 {
240240 struct autofs_info *ino = autofs4_dentry_ino(path->dentry);
241241
@@ -468,7 +468,7 @@ static int autofs_dev_ioctl_requester(struct file *fp, · 226 unmodified lines
468468 ino = autofs4_dentry_ino(path.dentry);
469469 if (ino) {
470470 err = 0;
471− autofs4_expire_wait(path.dentry, 0);
471+ autofs4_expire_wait(&path, 0);
472472 spin_lock(&sbi->fs_lock);
473473 param->requester.uid =
474474 from_kuid_munged(current_user_ns(), ino->uid);
@@ -575,7 +575,7 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp, · 100 unmodified lines
575575
576576 devid = new_encode_dev(dev);
577577
578− err = have_submounts(path.dentry);
578+ err = path_has_submounts(&path);
579579
580580 if (follow_down_one(&path))
581581 magic = path.dentry->d_sb->s_magic;
fs/autofs4/expire.c+15−10
@@ -310,26 +310,29 @@ struct dentry *autofs4_expire_direct(struct super_block *sb, · 309 unmodified lines
310310 now = jiffies;
311311 timeout = sbi->exp_timeout;
312312
313− spin_lock(&sbi->fs_lock);
314− ino = autofs4_dentry_ino(root);
315− /* No point expiring a pending mount */
316− if (ino->flags & AUTOFS_INF_PENDING)
317− goto out;
318313 if (!autofs4_direct_busy(mnt, root, timeout, do_now)) {
314+ spin_lock(&sbi->fs_lock);
315+ ino = autofs4_dentry_ino(root);
316+ /* No point expiring a pending mount */
317+ if (ino->flags & AUTOFS_INF_PENDING) {
318+ spin_unlock(&sbi->fs_lock);
319+ goto out;
320+ }
319321 ino->flags |= AUTOFS_INF_WANT_EXPIRE;
320322 spin_unlock(&sbi->fs_lock);
321323 synchronize_rcu();
322− spin_lock(&sbi->fs_lock);
323324 if (!autofs4_direct_busy(mnt, root, timeout, do_now)) {
325+ spin_lock(&sbi->fs_lock);
324326 ino->flags |= AUTOFS_INF_EXPIRING;
325327 init_completion(&ino->expire_complete);
326328 spin_unlock(&sbi->fs_lock);
327329 return root;
328330 }
331+ spin_lock(&sbi->fs_lock);
329332 ino->flags &= ~AUTOFS_INF_WANT_EXPIRE;
333+ spin_unlock(&sbi->fs_lock);
330334 }
331335 out:
332− spin_unlock(&sbi->fs_lock);
333336 dput(root);
334337
335338 return NULL;
@@ -495,8 +498,9 @@ found: · 159 unmodified lines
495498 return expired;
496499 }
497500
498−int autofs4_expire_wait(struct dentry *dentry, int rcu_walk)
501+int autofs4_expire_wait(const struct path *path, int rcu_walk)
499502 {
503+ struct dentry *dentry = path->dentry;
500504 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
501505 struct autofs_info *ino = autofs4_dentry_ino(dentry);
502506 int status;
@@ -525,7 +529,7 @@ retry: · 22 unmodified lines
525529
526530 pr_debug("waiting for expire %p name=%pd\n", dentry, dentry);
527531
528− status = autofs4_wait(sbi, dentry, NFY_NONE);
532+ status = autofs4_wait(sbi, path, NFY_NONE);
529533 wait_for_completion(&ino->expire_complete);
530534
531535 pr_debug("expire done status=%d\n", status);
@@ -592,11 +596,12 @@ int autofs4_do_expire_multi(struct super_block *sb, struct vfsmount *mnt, · 60 unmodified lines
592596
593597 if (dentry) {
594598 struct autofs_info *ino = autofs4_dentry_ino(dentry);
599+ const struct path path = { .mnt = mnt, .dentry = dentry };
595600
596601 /* This is synchronous because it makes the daemon a
597602 * little easier
598603 */
599− ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
604+ ret = autofs4_wait(sbi, &path, NFY_EXPIRE);
600605
601606 spin_lock(&sbi->fs_lock);
602607 /* avoid rapid-fire expire attempts if expiry fails */
fs/autofs4/root.c+32−29
@@ -32,7 +32,7 @@ static int autofs4_dir_open(struct inode *inode, struct file *file); · 31 unmodified lines
3232 static struct dentry *autofs4_lookup(struct inode *,
3333 struct dentry *, unsigned int);
3434 static struct vfsmount *autofs4_d_automount(struct path *);
35−static int autofs4_d_manage(struct dentry *, bool);
35+static int autofs4_d_manage(const struct path *, bool);
3636 static void autofs4_dentry_release(struct dentry *);
3737
3838 const struct file_operations autofs4_root_operations = {
@@ -123,7 +123,7 @@ static int autofs4_dir_open(struct inode *inode, struct file *file) · 84 unmodified lines
123123 * it.
124124 */
125125 spin_lock(&sbi->lookup_lock);
126− if (!d_mountpoint(dentry) && simple_empty(dentry)) {
126+ if (!path_is_mountpoint(&file->f_path) && simple_empty(dentry)) {
127127 spin_unlock(&sbi->lookup_lock);
128128 return -ENOENT;
129129 }
@@ -269,39 +269,41 @@ next: · 139 unmodified lines
269269 return NULL;
270270 }
271271
272−static int autofs4_mount_wait(struct dentry *dentry, bool rcu_walk)
272+static int autofs4_mount_wait(const struct path *path, bool rcu_walk)
273273 {
274− struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
275− struct autofs_info *ino = autofs4_dentry_ino(dentry);
274+ struct autofs_sb_info *sbi = autofs4_sbi(path->dentry->d_sb);
275+ struct autofs_info *ino = autofs4_dentry_ino(path->dentry);
276276 int status = 0;
277277
278278 if (ino->flags & AUTOFS_INF_PENDING) {
279279 if (rcu_walk)
280280 return -ECHILD;
281− pr_debug("waiting for mount name=%pd\n", dentry);
282− status = autofs4_wait(sbi, dentry, NFY_MOUNT);
281+ pr_debug("waiting for mount name=%pd\n", path->dentry);
282+ status = autofs4_wait(sbi, path, NFY_MOUNT);
283283 pr_debug("mount wait done status=%d\n", status);
284284 }
285285 ino->last_used = jiffies;
286286 return status;
287287 }
288288
289−static int do_expire_wait(struct dentry *dentry, bool rcu_walk)
289+static int do_expire_wait(const struct path *path, bool rcu_walk)
290290 {
291+ struct dentry *dentry = path->dentry;
291292 struct dentry *expiring;
292293
293294 expiring = autofs4_lookup_expiring(dentry, rcu_walk);
294295 if (IS_ERR(expiring))
295296 return PTR_ERR(expiring);
296297 if (!expiring)
297− return autofs4_expire_wait(dentry, rcu_walk);
298+ return autofs4_expire_wait(path, rcu_walk);
298299 else {
300+ const struct path this = { .mnt = path->mnt, .dentry = expiring };
299301 /*
300302 * If we are racing with expire the request might not
301303 * be quite complete, but the directory has been removed
302304 * so it must have been successful, just wait for it.
303305 */
304− autofs4_expire_wait(expiring, 0);
306+ autofs4_expire_wait(&this, 0);
305307 autofs4_del_expiring(expiring);
306308 dput(expiring);
307309 }
@@ -354,7 +356,7 @@ static struct vfsmount *autofs4_d_automount(struct path *path) · 46 unmodified lines
354356 * and the directory was removed, so just go ahead and try
355357 * the mount.
356358 */
357− status = do_expire_wait(dentry, 0);
359+ status = do_expire_wait(path, 0);
358360 if (status && status != -EAGAIN)
359361 return NULL;
360362
@@ -362,7 +364,7 @@ static struct vfsmount *autofs4_d_automount(struct path *path) · 1 unmodified line
362364 spin_lock(&sbi->fs_lock);
363365 if (ino->flags & AUTOFS_INF_PENDING) {
364366 spin_unlock(&sbi->fs_lock);
365− status = autofs4_mount_wait(dentry, 0);
367+ status = autofs4_mount_wait(path, 0);
366368 if (status)
367369 return ERR_PTR(status);
368370 goto done;
@@ -370,28 +372,28 @@ static struct vfsmount *autofs4_d_automount(struct path *path) · 1 unmodified line
370372
371373 /*
372374 * If the dentry is a symlink it's equivalent to a directory
373− * having d_mountpoint() true, so there's no need to call back
374− * to the daemon.
375+ * having path_is_mountpoint() true, so there's no need to call
376+ * back to the daemon.
375377 */
376378 if (d_really_is_positive(dentry) && d_is_symlink(dentry)) {
377379 spin_unlock(&sbi->fs_lock);
378380 goto done;
379381 }
380382
381− if (!d_mountpoint(dentry)) {
383+ if (!path_is_mountpoint(path)) {
382384 /*
383385 * It's possible that user space hasn't removed directories
384386 * after umounting a rootless multi-mount, although it
385− * should. For v5 have_submounts() is sufficient to handle
386− * this because the leaves of the directory tree under the
387− * mount never trigger mounts themselves (they have an autofs
388− * trigger mount mounted on them). But v4 pseudo direct mounts
389− * do need the leaves to trigger mounts. In this case we
390− * have no choice but to use the list_empty() check and
387+ * should. For v5 path_has_submounts() is sufficient to
388+ * handle this because the leaves of the directory tree under
389+ * the mount never trigger mounts themselves (they have an
390+ * autofs trigger mount mounted on them). But v4 pseudo direct
391+ * mounts do need the leaves to trigger mounts. In this case
392+ * we have no choice but to use the list_empty() check and
391393 * require user space behave.
392394 */
393395 if (sbi->version > 4) {
394− if (have_submounts(dentry)) {
396+ if (path_has_submounts(path)) {
395397 spin_unlock(&sbi->fs_lock);
396398 goto done;
397399 }
@@ -403,7 +405,7 @@ static struct vfsmount *autofs4_d_automount(struct path *path) · 5 unmodified lines
403405 }
404406 ino->flags |= AUTOFS_INF_PENDING;
405407 spin_unlock(&sbi->fs_lock);
406− status = autofs4_mount_wait(dentry, 0);
408+ status = autofs4_mount_wait(path, 0);
407409 spin_lock(&sbi->fs_lock);
408410 ino->flags &= ~AUTOFS_INF_PENDING;
409411 if (status) {
@@ -421,8 +423,9 @@ done: · 11 unmodified lines
421423 return NULL;
422424 }
423425
424−static int autofs4_d_manage(struct dentry *dentry, bool rcu_walk)
426+static int autofs4_d_manage(const struct path *path, bool rcu_walk)
425427 {
428+ struct dentry *dentry = path->dentry;
426429 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
427430 struct autofs_info *ino = autofs4_dentry_ino(dentry);
428431 int status;
@@ -431,20 +434,20 @@ static int autofs4_d_manage(struct dentry *dentry, bool rcu_walk) · 2 unmodified lines
431434
432435 /* The daemon never waits. */
433436 if (autofs4_oz_mode(sbi)) {
434− if (!d_mountpoint(dentry))
437+ if (!path_is_mountpoint(path))
435438 return -EISDIR;
436439 return 0;
437440 }
438441
439442 /* Wait for pending expires */
440− if (do_expire_wait(dentry, rcu_walk) == -ECHILD)
443+ if (do_expire_wait(path, rcu_walk) == -ECHILD)
441444 return -ECHILD;
442445
443446 /*
444447 * This dentry may be under construction so wait on mount
445448 * completion.
446449 */
447− status = autofs4_mount_wait(dentry, rcu_walk);
450+ status = autofs4_mount_wait(path, rcu_walk);
448451 if (status)
449452 return status;
450453
@@ -460,7 +463,7 @@ static int autofs4_d_manage(struct dentry *dentry, bool rcu_walk) · 9 unmodified lines
460463
461464 if (ino->flags & AUTOFS_INF_WANT_EXPIRE)
462465 return 0;
463− if (d_mountpoint(dentry))
466+ if (path_is_mountpoint(path))
464467 return 0;
465468 inode = d_inode_rcu(dentry);
466469 if (inode && S_ISLNK(inode->i_mode))
@@ -487,7 +490,7 @@ static int autofs4_d_manage(struct dentry *dentry, bool rcu_walk) · 20 unmodified lines
487490 * we can avoid needless calls ->d_automount() and avoid
488491 * an incorrect ELOOP error return.
489492 */
490− if ((!d_mountpoint(dentry) && !simple_empty(dentry)) ||
493+ if ((!path_is_mountpoint(path) && !simple_empty(dentry)) ||
491494 (d_really_is_positive(dentry) && d_is_symlink(dentry)))
492495 status = -EISDIR;
493496 }
fs/autofs4/waitq.c+9−4
@@ -250,8 +250,9 @@ autofs4_find_wait(struct autofs_sb_info *sbi, const struct qstr *qstr) · 249 unmodified lines
250250 static int validate_request(struct autofs_wait_queue **wait,
251251 struct autofs_sb_info *sbi,
252252 const struct qstr *qstr,
253− struct dentry *dentry, enum autofs_notify notify)
253+ const struct path *path, enum autofs_notify notify)
254254 {
255+ struct dentry *dentry = path->dentry;
255256 struct autofs_wait_queue *wq;
256257 struct autofs_info *ino;
257258
@@ -314,6 +315,7 @@ static int validate_request(struct autofs_wait_queue **wait, · 56 unmodified lines
314315 */
315316 if (notify == NFY_MOUNT) {
316317 struct dentry *new = NULL;
318+ struct path this;
317319 int valid = 1;
318320
319321 /*
@@ -333,7 +335,9 @@ static int validate_request(struct autofs_wait_queue **wait, · 13 unmodified lines
333335 dentry = new;
334336 }
335337 }
336− if (have_submounts(dentry))
338+ this.mnt = path->mnt;
339+ this.dentry = dentry;
340+ if (path_has_submounts(&this))
337341 valid = 0;
338342
339343 if (new)
@@ -345,8 +349,9 @@ static int validate_request(struct autofs_wait_queue **wait, · 5 unmodified lines
345349 }
346350
347351 int autofs4_wait(struct autofs_sb_info *sbi,
348− struct dentry *dentry, enum autofs_notify notify)
352+ const struct path *path, enum autofs_notify notify)
349353 {
354+ struct dentry *dentry = path->dentry;
350355 struct autofs_wait_queue *wq;
351356 struct qstr qstr;
352357 char *name;
@@ -405,7 +410,7 @@ int autofs4_wait(struct autofs_sb_info *sbi, · 52 unmodified lines
405410 return -EINTR;
406411 }
407412
408− ret = validate_request(&wq, sbi, &qstr, dentry, notify);
413+ ret = validate_request(&wq, sbi, &qstr, path, notify);
409414 if (ret <= 0) {
410415 if (ret != -EINTR)
411416 mutex_unlock(&sbi->wq_mutex);
fs/btrfs/ctree.h+0−3
@@ -3232,9 +3232,6 @@ int btrfs_dirty_pages(struct inode *inode, struct page **pages, · 3231 unmodified lines
32323232 size_t num_pages, loff_t pos, size_t write_bytes,
32333233 struct extent_state **cached);
32343234 int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);
3235−ssize_t btrfs_copy_file_range(struct file *file_in, loff_t pos_in,
3236− struct file *file_out, loff_t pos_out,
3237− size_t len, unsigned int flags);
32383235 int btrfs_clone_file_range(struct file *file_in, loff_t pos_in,
32393236 struct file *file_out, loff_t pos_out, u64 len);
32403237
fs/btrfs/file.c+0−1
@@ -3033,7 +3033,6 @@ const struct file_operations btrfs_file_operations = { · 3032 unmodified lines
30333033 #ifdef CONFIG_COMPAT
30343034 .compat_ioctl = btrfs_compat_ioctl,
30353035 #endif
3036− .copy_file_range = btrfs_copy_file_range,
30373036 .clone_file_range = btrfs_clone_file_range,
30383037 .dedupe_file_range = btrfs_dedupe_file_range,
30393038 };
fs/btrfs/ioctl.c+1−13
@@ -834,7 +834,7 @@ static inline int btrfs_may_create(struct inode *dir, struct dentry *child) · 833 unmodified lines
834834 * sys_mkdirat and vfs_mkdir, but we only do a single component lookup
835835 * inside this filesystem so it's quite a bit simpler.
836836 */
837−static noinline int btrfs_mksubvol(struct path *parent,
837+static noinline int btrfs_mksubvol(const struct path *parent,
838838 char *name, int namelen,
839839 struct btrfs_root *snap_src,
840840 u64 *async_transid, bool readonly,
@@ -3987,18 +3987,6 @@ out_unlock: · 3146 unmodified lines
39873987 return ret;
39883988 }
39893989
3990−ssize_t btrfs_copy_file_range(struct file *file_in, loff_t pos_in,
3991− struct file *file_out, loff_t pos_out,
3992− size_t len, unsigned int flags)
3993−{
3994− ssize_t ret;
3995−
3996− ret = btrfs_clone_files(file_out, file_in, pos_in, len, pos_out);
3997− if (ret == 0)
3998− ret = len;
3999− return ret;
4000−}
4001−
40023990 int btrfs_clone_file_range(struct file *src_file, loff_t off,
40033991 struct file *dst_file, loff_t destoff, u64 len)
40043992 {
fs/ceph/addr.c+8−6
@@ -1317,25 +1317,27 @@ static int ceph_write_end(struct file *file, struct address_space *mapping, · 1316 unmodified lines
13171317 struct page *page, void *fsdata)
13181318 {
13191319 struct inode *inode = file_inode(file);
1320− unsigned from = pos & (PAGE_SIZE - 1);
13211320 int check_cap = 0;
13221321
13231322 dout("write_end file %p inode %p page %p %d~%d (%d)\n", file,
13241323 inode, page, (int)pos, (int)copied, (int)len);
13251324
13261325 /* zero the stale part of the page if we did a short copy */
1327− if (copied < len)
1328− zero_user_segment(page, from+copied, len);
1326+ if (!PageUptodate(page)) {
1327+ if (copied < len) {
1328+ copied = 0;
1329+ goto out;
1330+ }
1331+ SetPageUptodate(page);
1332+ }
13291333
13301334 /* did file size increase? */
13311335 if (pos+copied > i_size_read(inode))
13321336 check_cap = ceph_inode_set_size(inode, pos+copied);
13331337
1334− if (!PageUptodate(page))
1335− SetPageUptodate(page);
1336−
13371338 set_page_dirty(page);
13381339
1340+out:
13391341 unlock_page(page);
13401342 put_page(page);
13411343
fs/dcache.c+23−17
@@ -1273,38 +1273,44 @@ rename_retry: · 1272 unmodified lines
12731273 goto again;
12741274 }
12751275
1276−/*
1277− * Search for at least 1 mount point in the dentry's subdirs.
1278− * We descend to the next level whenever the d_subdirs
1279− * list is non-empty and continue searching.
1280− */
1276+struct check_mount {
1277+ struct vfsmount *mnt;
1278+ unsigned int mounted;
1279+};
12811280
1282−static enum d_walk_ret check_mount(void *data, struct dentry *dentry)
1281+static enum d_walk_ret path_check_mount(void *data, struct dentry *dentry)
12831282 {
1284− int *ret = data;
1285− if (d_mountpoint(dentry)) {
1286− *ret = 1;
1283+ struct check_mount *info = data;
1284+ struct path path = { .mnt = info->mnt, .dentry = dentry };
1285+
1286+ if (likely(!d_mountpoint(dentry)))
1287+ return D_WALK_CONTINUE;
1288+ if (__path_is_mountpoint(&path)) {
1289+ info->mounted = 1;
12871290 return D_WALK_QUIT;
12881291 }
12891292 return D_WALK_CONTINUE;
12901293 }
12911294
12921295 /**
1293− * have_submounts - check for mounts over a dentry
1294− * @parent: dentry to check.
1296+ * path_has_submounts - check for mounts over a dentry in the
1297+ * current namespace.
1298+ * @parent: path to check.
12951299 *
12961300 * Return true if the parent or its subdirectories contain
1297− * a mount point
1301+ * a mount point in the current namespace.
12981302 */
1299−int have_submounts(struct dentry *parent)
1303+int path_has_submounts(const struct path *parent)
13001304 {
1301− int ret = 0;
1305+ struct check_mount data = { .mnt = parent->mnt, .mounted = 0 };
13021306
1303− d_walk(parent, &ret, check_mount, NULL);
1307+ read_seqlock_excl(&mount_lock);
1308+ d_walk(parent->dentry, &data, path_check_mount, NULL);
1309+ read_sequnlock_excl(&mount_lock);
13041310
1305− return ret;
1311+ return data.mounted;
13061312 }
1307−EXPORT_SYMBOL(have_submounts);
1313+EXPORT_SYMBOL(path_has_submounts);
13081314
13091315 /*
13101316 * Called by mount code to set a mountpoint and check if the mountpoint is
fs/dcookies.c+2−2
@@ -90,7 +90,7 @@ static void hash_dcookie(struct dcookie_struct * dcs) · 89 unmodified lines
9090 }
9191
9292
93−static struct dcookie_struct *alloc_dcookie(struct path *path)
93+static struct dcookie_struct *alloc_dcookie(const struct path *path)
9494 {
9595 struct dcookie_struct *dcs = kmem_cache_alloc(dcookie_cache,
9696 GFP_KERNEL);
@@ -113,7 +113,7 @@ static struct dcookie_struct *alloc_dcookie(struct path *path) · 16 unmodified lines
113113 /* This is the main kernel-side routine that retrieves the cookie
114114 * value for a dentry/vfsmnt pair.
115115 */
116−int get_dcookie(struct path *path, unsigned long *cookie)
116+int get_dcookie(const struct path *path, unsigned long *cookie)
117117 {
118118 int err = 0;
119119 struct dcookie_struct * dcs;
fs/exofs/inode.c+30−38
@@ -870,46 +870,31 @@ int exofs_write_begin(struct file *file, struct address_space *mapping, · 869 unmodified lines
870870
871871 page = *pagep;
872872 if (page == NULL) {
873− ret = simple_write_begin(file, mapping, pos, len, flags, pagep,
874− fsdata);
875− if (ret) {
876− EXOFS_DBGMSG("simple_write_begin failed\n");
877− goto out;
873+ page = grab_cache_page_write_begin(mapping, pos >> PAGE_SHIFT,
874+ flags);
875+ if (!page) {
876+ EXOFS_DBGMSG("grab_cache_page_write_begin failed\n");
877+ return -ENOMEM;
878878 }
879−
880− page = *pagep;
879+ *pagep = page;
881880 }
882881
883882 /* read modify write */
884883 if (!PageUptodate(page) && (len != PAGE_SIZE)) {
885884 loff_t i_size = i_size_read(mapping->host);
886885 pgoff_t end_index = i_size >> PAGE_SHIFT;
887− size_t rlen;
888886
889− if (page->index < end_index)
890− rlen = PAGE_SIZE;
891− else if (page->index == end_index)
892− rlen = i_size & ~PAGE_MASK;
893− else
894− rlen = 0;
895−
896− if (!rlen) {
887+ if (page->index > end_index) {
897888 clear_highpage(page);
898889 SetPageUptodate(page);
899− goto out;
900− }
901−
902− ret = _readpage(page, true);
903− if (ret) {
904− /*SetPageError was done by _readpage. Is it ok?*/
905− unlock_page(page);
906− EXOFS_DBGMSG("__readpage failed\n");
890+ } else {
891+ ret = _readpage(page, true);
892+ if (ret) {
893+ unlock_page(page);
894+ EXOFS_DBGMSG("__readpage failed\n");
895+ }
907896 }
908897 }
909−out:
910− if (unlikely(ret))
911− _write_failed(mapping->host, pos + len);
912−
913898 return ret;
914899 }
915900
@@ -929,18 +914,25 @@ static int exofs_write_end(struct file *file, struct address_space *mapping, · 13 unmodified lines
929914 struct page *page, void *fsdata)
930915 {
931916 struct inode *inode = mapping->host;
932− /* According to comment in simple_write_end i_mutex is held */
933− loff_t i_size = inode->i_size;
934− int ret;
935−
936− ret = simple_write_end(file, mapping,pos, len, copied, page, fsdata);
937− if (unlikely(ret))
938− _write_failed(inode, pos + len);
917+ loff_t last_pos = pos + copied;
939918
940− /* TODO: once simple_write_end marks inode dirty remove */
941− if (i_size != inode->i_size)
919+ if (!PageUptodate(page)) {
920+ if (copied < len) {
921+ _write_failed(inode, pos + len);
922+ copied = 0;
923+ goto out;
924+ }
925+ SetPageUptodate(page);
926+ }
927+ if (last_pos > inode->i_size) {
928+ i_size_write(inode, last_pos);
942929 mark_inode_dirty(inode);
943− return ret;
930+ }
931+ set_page_dirty(page);
932+out:
933+ unlock_page(page);
934+ put_page(page);
935+ return copied;
944936 }
945937
946938 static int exofs_releasepage(struct page *page, gfp_t gfp)
fs/ext4/super.c+2−2
@@ -1205,7 +1205,7 @@ static int ext4_release_dquot(struct dquot *dquot); · 1204 unmodified lines
12051205 static int ext4_mark_dquot_dirty(struct dquot *dquot);
12061206 static int ext4_write_info(struct super_block *sb, int type);
12071207 static int ext4_quota_on(struct super_block *sb, int type, int format_id,
1208− struct path *path);
1208+ const struct path *path);
12091209 static int ext4_quota_off(struct super_block *sb, int type);
12101210 static int ext4_quota_on_mount(struct super_block *sb, int type);
12111211 static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
@@ -5293,7 +5293,7 @@ static void lockdep_set_quota_inode(struct inode *inode, int subclass) · 4081 unmodified lines
52935293 * Standard function to be called on quota_on
52945294 */
52955295 static int ext4_quota_on(struct super_block *sb, int type, int format_id,
5296− struct path *path)
5296+ const struct path *path)
52975297 {
52985298 int err;
52995299
fs/file_table.c+1−1
@@ -155,7 +155,7 @@ over: · 154 unmodified lines
155155 * @mode: the mode with which the new file will be opened
156156 * @fop: the 'struct file_operations' for the new file
157157 */
158−struct file *alloc_file(struct path *path, fmode_t mode,
158+struct file *alloc_file(const struct path *path, fmode_t mode,
159159 const struct file_operations *fop)
160160 {
161161 struct file *file;
fs/gfs2/aops.c+1−3
@@ -839,12 +839,10 @@ static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh, · 838 unmodified lines
839839 BUG_ON((pos + len) > (dibh->b_size - sizeof(struct gfs2_dinode)));
840840 kaddr = kmap_atomic(page);
841841 memcpy(buf + pos, kaddr + pos, copied);
842− memset(kaddr + pos + copied, 0, len - copied);
843842 flush_dcache_page(page);
844843 kunmap_atomic(kaddr);
845844
846− if (!PageUptodate(page))
847− SetPageUptodate(page);
845+ WARN_ON(!PageUptodate(page));
848846 unlock_page(page);
849847 put_page(page);
850848
fs/internal.h+1−1
@@ -62,7 +62,7 @@ extern int vfs_path_lookup(struct dentry *, struct vfsmount *, · 61 unmodified lines
6262 extern void *copy_mount_options(const void __user *);
6363 extern char *copy_mount_string(const void __user *);
6464
65−extern struct vfsmount *lookup_mnt(struct path *);
65+extern struct vfsmount *lookup_mnt(const struct path *);
6666 extern int finish_automount(struct vfsmount *, struct path *);
6767
6868 extern int sb_prepare_remount_readonly(struct super_block *);
fs/libfs.c+8−6
@@ -465,6 +465,8 @@ EXPORT_SYMBOL(simple_write_begin); · 464 unmodified lines
465465 * is not called, so a filesystem that actually does store data in .write_inode
466466 * should extend on what's done here with a call to mark_inode_dirty() in the
467467 * case that i_size has changed.
468+ *
469+ * Use *ONLY* with simple_readpage()
468470 */
469471 int simple_write_end(struct file *file, struct address_space *mapping,
470472 loff_t pos, unsigned len, unsigned copied,
@@ -474,14 +476,14 @@ int simple_write_end(struct file *file, struct address_space *mapping, · 3 unmodified lines
474476 loff_t last_pos = pos + copied;
475477
476478 /* zero the stale part of the page if we did a short copy */
477− if (copied < len) {
478− unsigned from = pos & (PAGE_SIZE - 1);
479−
480− zero_user(page, from + copied, len - copied);
481− }
479+ if (!PageUptodate(page)) {
480+ if (copied < len) {
481+ unsigned from = pos & (PAGE_SIZE - 1);
482482
483− if (!PageUptodate(page))
483+ zero_user(page, from + copied, len - copied);
484+ }
484485 SetPageUptodate(page);
486+ }
485487 /*
486488 * No need to use i_size_read() here, the i_size
487489 * cannot change under us because we hold the i_mutex.
fs/mount.h+6−0
@@ -94,6 +94,12 @@ extern struct mount *__lookup_mnt_last(struct vfsmount *, struct dentry *); · 93 unmodified lines
9494 extern int __legitimize_mnt(struct vfsmount *, unsigned);
9595 extern bool legitimize_mnt(struct vfsmount *, unsigned);
9696
97+static inline bool __path_is_mountpoint(const struct path *path)
98+{
99+ struct mount *m = __lookup_mnt(path->mnt, path->dentry);
100+ return m && likely(!(m->mnt.mnt_flags & MNT_SYNC_UMOUNT));
101+}
102+
97103 extern void __detach_mounts(struct dentry *dentry);
98104
99105 static inline void detach_mounts(struct dentry *dentry)
fs/namei.c+8−9
@@ -1200,7 +1200,7 @@ static int follow_managed(struct path *path, struct nameidata *nd) · 1199 unmodified lines
12001200 if (managed & DCACHE_MANAGE_TRANSIT) {
12011201 BUG_ON(!path->dentry->d_op);
12021202 BUG_ON(!path->dentry->d_op->d_manage);
1203− ret = path->dentry->d_op->d_manage(path->dentry, false);
1203+ ret = path->dentry->d_op->d_manage(path, false);
12041204 if (ret < 0)
12051205 break;
12061206 }
@@ -1263,10 +1263,10 @@ int follow_down_one(struct path *path) · 56 unmodified lines
12631263 }
12641264 EXPORT_SYMBOL(follow_down_one);
12651265
1266−static inline int managed_dentry_rcu(struct dentry *dentry)
1266+static inline int managed_dentry_rcu(const struct path *path)
12671267 {
1268− return (dentry->d_flags & DCACHE_MANAGE_TRANSIT) ?
1269− dentry->d_op->d_manage(dentry, true) : 0;
1268+ return (path->dentry->d_flags & DCACHE_MANAGE_TRANSIT) ?
1269+ path->dentry->d_op->d_manage(path, true) : 0;
12701270 }
12711271
12721272 /*
@@ -1282,7 +1282,7 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path, · 9 unmodified lines
12821282 * Don't forget we might have a non-mountpoint managed dentry
12831283 * that wants to block transit.
12841284 */
1285− switch (managed_dentry_rcu(path->dentry)) {
1285+ switch (managed_dentry_rcu(path)) {
12861286 case -ECHILD:
12871287 default:
12881288 return false;
@@ -1392,8 +1392,7 @@ int follow_down(struct path *path) · 103 unmodified lines
13921392 if (managed & DCACHE_MANAGE_TRANSIT) {
13931393 BUG_ON(!path->dentry->d_op);
13941394 BUG_ON(!path->dentry->d_op->d_manage);
1395− ret = path->dentry->d_op->d_manage(
1396− path->dentry, false);
1395+ ret = path->dentry->d_op->d_manage(path, false);
13971396 if (ret < 0)
13981397 return ret == -EISDIR ? 0 : ret;
13991398 }
@@ -2863,7 +2862,7 @@ bool may_open_dev(const struct path *path) · 1463 unmodified lines
28632862 !(path->mnt->mnt_sb->s_iflags & SB_I_NODEV);
28642863 }
28652864
2866−static int may_open(struct path *path, int acc_mode, int flag)
2865+static int may_open(const struct path *path, int acc_mode, int flag)
28672866 {
28682867 struct dentry *dentry = path->dentry;
28692868 struct inode *inode = dentry->d_inode;
@@ -2913,7 +2912,7 @@ static int may_open(struct path *path, int acc_mode, int flag) · 43 unmodified lines
29132912
29142913 static int handle_truncate(struct file *filp)
29152914 {
2916− struct path *path = &filp->f_path;
2915+ const struct path *path = &filp->f_path;
29172916 struct inode *inode = path->dentry->d_inode;
29182917 int error = get_write_access(inode);
29192918 if (error)
fs/namespace.c+34−5
@@ -678,7 +678,7 @@ out: · 677 unmodified lines
678678 *
679679 * lookup_mnt takes a reference to the found vfsmount.
680680 */
681−struct vfsmount *lookup_mnt(struct path *path)
681+struct vfsmount *lookup_mnt(const struct path *path)
682682 {
683683 struct mount *child_mnt;
684684 struct vfsmount *m;
@@ -1159,7 +1159,36 @@ struct vfsmount *mntget(struct vfsmount *mnt) · 474 unmodified lines
11591159 }
11601160 EXPORT_SYMBOL(mntget);
11611161
1162−struct vfsmount *mnt_clone_internal(struct path *path)
1162+/* path_is_mountpoint() - Check if path is a mount in the current
1163+ * namespace.
1164+ *
1165+ * d_mountpoint() can only be used reliably to establish if a dentry is
1166+ * not mounted in any namespace and that common case is handled inline.
1167+ * d_mountpoint() isn't aware of the possibility there may be multiple
1168+ * mounts using a given dentry in a different namespace. This function
1169+ * checks if the passed in path is a mountpoint rather than the dentry
1170+ * alone.
1171+ */
1172+bool path_is_mountpoint(const struct path *path)
1173+{
1174+ unsigned seq;
1175+ bool res;
1176+
1177+ if (!d_mountpoint(path->dentry))
1178+ return false;
1179+
1180+ rcu_read_lock();
1181+ do {
1182+ seq = read_seqbegin(&mount_lock);
1183+ res = __path_is_mountpoint(path);
1184+ } while (read_seqretry(&mount_lock, seq));
1185+ rcu_read_unlock();
1186+
1187+ return res;
1188+}
1189+EXPORT_SYMBOL(path_is_mountpoint);
1190+
1191+struct vfsmount *mnt_clone_internal(const struct path *path)
11631192 {
11641193 struct mount *p;
11651194 p = clone_mnt(real_mount(path->mnt), path->dentry, CL_PRIVATE);
@@ -1758,7 +1787,7 @@ out: · 592 unmodified lines
17581787
17591788 /* Caller should check returned pointer for errors */
17601789
1761−struct vfsmount *collect_mounts(struct path *path)
1790+struct vfsmount *collect_mounts(const struct path *path)
17621791 {
17631792 struct mount *tree;
17641793 namespace_lock();
@@ -1791,7 +1820,7 @@ void drop_collected_mounts(struct vfsmount *mnt) · 26 unmodified lines
17911820 *
17921821 * Release with mntput().
17931822 */
1794−struct vfsmount *clone_private_mount(struct path *path)
1823+struct vfsmount *clone_private_mount(const struct path *path)
17951824 {
17961825 struct mount *old_mnt = real_mount(path->mnt);
17971826 struct mount *new_mnt;
@@ -2997,7 +3026,7 @@ bool is_path_reachable(struct mount *mnt, struct dentry *dentry, · 1199 unmodified lines
29973026 return &mnt->mnt == root->mnt && is_subdir(dentry, root->dentry);
29983027 }
29993028
3000−bool path_is_under(struct path *path1, struct path *path2)
3029+bool path_is_under(const struct path *path1, const struct path *path2)
30013030 {
30023031 bool res;
30033032 read_seqlock_excl(&mount_lock);
fs/nfs/file.c+1−1
@@ -377,7 +377,7 @@ static int nfs_write_end(struct file *file, struct address_space *mapping, · 376 unmodified lines
377377 */
378378 if (!PageUptodate(page)) {
379379 unsigned pglen = nfs_page_length(page);
380− unsigned end = offset + len;
380+ unsigned end = offset + copied;
381381
382382 if (pglen == 0) {
383383 zero_user_segments(page, 0, offset,
fs/notify/dnotify/dnotify.c+1−1
@@ -85,7 +85,7 @@ static int dnotify_handle_event(struct fsnotify_group *group, · 84 unmodified lines
8585 struct inode *inode,
8686 struct fsnotify_mark *inode_mark,
8787 struct fsnotify_mark *vfsmount_mark,
88− u32 mask, void *data, int data_type,
88+ u32 mask, const void *data, int data_type,
8989 const unsigned char *file_name, u32 cookie)
9090 {
9191 struct dnotify_mark *dn_mark;
fs/notify/fanotify/fanotify.c+4−4
@@ -90,10 +90,10 @@ static int fanotify_get_response(struct fsnotify_group *group, · 89 unmodified lines
9090 static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark,
9191 struct fsnotify_mark *vfsmnt_mark,
9292 u32 event_mask,
93− void *data, int data_type)
93+ const void *data, int data_type)
9494 {
9595 __u32 marks_mask, marks_ignored_mask;
96− struct path *path = data;
96+ const struct path *path = data;
9797
9898 pr_debug("%s: inode_mark=%p vfsmnt_mark=%p mask=%x data=%p"
9999 " data_type=%d\n", __func__, inode_mark, vfsmnt_mark,
@@ -140,7 +140,7 @@ static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark, · 40 unmodified lines
140140 }
141141
142142 struct fanotify_event_info *fanotify_alloc_event(struct inode *inode, u32 mask,
143− struct path *path)
143+ const struct path *path)
144144 {
145145 struct fanotify_event_info *event;
146146
@@ -177,7 +177,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, · 30 unmodified lines
177177 struct inode *inode,
178178 struct fsnotify_mark *inode_mark,
179179 struct fsnotify_mark *fanotify_mark,
180− u32 mask, void *data, int data_type,
180+ u32 mask, const void *data, int data_type,
181181 const unsigned char *file_name, u32 cookie)
182182 {
183183 int ret = 0;
fs/notify/fanotify/fanotify.h+1−1
@@ -47,4 +47,4 @@ static inline struct fanotify_event_info *FANOTIFY_E(struct fsnotify_event *fse) · 46 unmodified lines
4747 }
4848
4949 struct fanotify_event_info *fanotify_alloc_event(struct inode *inode, u32 mask,
50− struct path *path);
50+ const struct path *path);
fs/notify/fsnotify.c+4−4
@@ -86,7 +86,7 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode) · 85 unmodified lines
8686 }
8787
8888 /* Notify this dentry's parent about a child's events. */
89−int __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
89+int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask)
9090 {
9191 struct dentry *parent;
9292 struct inode *p_inode;
@@ -125,7 +125,7 @@ EXPORT_SYMBOL_GPL(__fsnotify_parent); · 32 unmodified lines
125125 static int send_to_group(struct inode *to_tell,
126126 struct fsnotify_mark *inode_mark,
127127 struct fsnotify_mark *vfsmount_mark,
128− __u32 mask, void *data,
128+ __u32 mask, const void *data,
129129 int data_is, u32 cookie,
130130 const unsigned char *file_name)
131131 {
@@ -187,7 +187,7 @@ static int send_to_group(struct inode *to_tell, · 55 unmodified lines
187187 * out to all of the registered fsnotify_group. Those groups can then use the
188188 * notification event in whatever means they feel necessary.
189189 */
190−int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
190+int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
191191 const unsigned char *file_name, u32 cookie)
192192 {
193193 struct hlist_node *inode_node = NULL, *vfsmount_node = NULL;
@@ -199,7 +199,7 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, · 5 unmodified lines
199199 __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD);
200200
201201 if (data_is == FSNOTIFY_EVENT_PATH)
202− mnt = real_mount(((struct path *)data)->mnt);
202+ mnt = real_mount(((const struct path *)data)->mnt);
203203 else
204204 mnt = NULL;
205205
fs/notify/inotify/inotify.h+1−1
@@ -26,7 +26,7 @@ extern int inotify_handle_event(struct fsnotify_group *group, · 25 unmodified lines
2626 struct inode *inode,
2727 struct fsnotify_mark *inode_mark,
2828 struct fsnotify_mark *vfsmount_mark,
29− u32 mask, void *data, int data_type,
29+ u32 mask, const void *data, int data_type,
3030 const unsigned char *file_name, u32 cookie);
3131
3232 extern const struct fsnotify_ops inotify_fsnotify_ops;
fs/notify/inotify/inotify_fsnotify.c+2−2
@@ -66,7 +66,7 @@ int inotify_handle_event(struct fsnotify_group *group, · 65 unmodified lines
6666 struct inode *inode,
6767 struct fsnotify_mark *inode_mark,
6868 struct fsnotify_mark *vfsmount_mark,
69− u32 mask, void *data, int data_type,
69+ u32 mask, const void *data, int data_type,
7070 const unsigned char *file_name, u32 cookie)
7171 {
7272 struct inotify_inode_mark *i_mark;
@@ -80,7 +80,7 @@ int inotify_handle_event(struct fsnotify_group *group, · 7 unmodified lines
8080
8181 if ((inode_mark->mask & FS_EXCL_UNLINK) &&
8282 (data_type == FSNOTIFY_EVENT_PATH)) {
83− struct path *path = data;
83+ const struct path *path = data;
8484
8585 if (d_unlinked(path->dentry))
8686 return 0;
fs/ocfs2/alloc.c+3−4
@@ -5194,7 +5194,7 @@ int ocfs2_change_extent_flag(handle_t *handle, · 5193 unmodified lines
51945194 rec = &el->l_recs[index];
51955195 if (new_flags && (rec->e_flags & new_flags)) {
51965196 mlog(ML_ERROR, "Owner %llu tried to set %d flags on an "
5197− "extent that already had them",
5197+ "extent that already had them\n",
51985198 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
51995199 new_flags);
52005200 goto out;
@@ -5202,7 +5202,7 @@ int ocfs2_change_extent_flag(handle_t *handle, · 1 unmodified line
52025202
52035203 if (clear_flags && !(rec->e_flags & clear_flags)) {
52045204 mlog(ML_ERROR, "Owner %llu tried to clear %d flags on an "
5205− "extent that didn't have them",
5205+ "extent that didn't have them\n",
52065206 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
52075207 clear_flags);
52085208 goto out;
@@ -5713,8 +5713,7 @@ int ocfs2_remove_btree_range(struct inode *inode, · 504 unmodified lines
57135713 struct ocfs2_refcount_tree *ref_tree = NULL;
57145714
57155715 if ((flags & OCFS2_EXT_REFCOUNTED) && len) {
5716− BUG_ON(!(OCFS2_I(inode)->ip_dyn_features &
5717− OCFS2_HAS_REFCOUNT_FL));
5716+ BUG_ON(!ocfs2_is_refcount_inode(inode));
57185717
57195718 if (!refcount_tree_locked) {
57205719 ret = ocfs2_lock_refcount_tree(osb, refcount_loc, 1,
fs/ocfs2/aops.c+20−11
@@ -464,6 +464,15 @@ static sector_t ocfs2_bmap(struct address_space *mapping, sector_t block) · 463 unmodified lines
464464 trace_ocfs2_bmap((unsigned long long)OCFS2_I(inode)->ip_blkno,
465465 (unsigned long long)block);
466466
467+ /*
468+ * The swap code (ab-)uses ->bmap to get a block mapping and then
469+ * bypasseѕ the file system for actual I/O. We really can't allow
470+ * that on refcounted inodes, so we have to skip out here. And yes,
471+ * 0 is the magic code for a bmap error..
472+ */
473+ if (ocfs2_is_refcount_inode(inode))
474+ return 0;
475+
467476 /* We don't need to lock journal system files, since they aren't
468477 * accessed concurrently from multiple nodes.
469478 */
@@ -2253,10 +2262,10 @@ out: · 1783 unmodified lines
22532262 return ret;
22542263 }
22552264
2256−static void ocfs2_dio_end_io_write(struct inode *inode,
2257− struct ocfs2_dio_write_ctxt *dwc,
2258− loff_t offset,
2259− ssize_t bytes)
2265+static int ocfs2_dio_end_io_write(struct inode *inode,
2266+ struct ocfs2_dio_write_ctxt *dwc,
2267+ loff_t offset,
2268+ ssize_t bytes)
22602269 {
22612270 struct ocfs2_cached_dealloc_ctxt dealloc;
22622271 struct ocfs2_extent_tree et;
@@ -2307,7 +2316,7 @@ static void ocfs2_dio_end_io_write(struct inode *inode, · 44 unmodified lines
23072316 mlog_errno(ret);
23082317 }
23092318
2310− di = (struct ocfs2_dinode *)di_bh;
2319+ di = (struct ocfs2_dinode *)di_bh->b_data;
23112320
23122321 ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode), di_bh);
23132322
@@ -2364,6 +2373,8 @@ out: · 50 unmodified lines
23642373 if (locked)
23652374 inode_unlock(inode);
23662375 ocfs2_dio_free_write_ctx(inode, dwc);
2376+
2377+ return ret;
23672378 }
23682379
23692380 /*
@@ -2378,21 +2389,19 @@ static int ocfs2_dio_end_io(struct kiocb *iocb, · 8 unmodified lines
23782389 {
23792390 struct inode *inode = file_inode(iocb->ki_filp);
23802391 int level;
2381−
2382− if (bytes <= 0)
2383− return 0;
2392+ int ret = 0;
23842393
23852394 /* this io's submitter should not have unlocked this before we could */
23862395 BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));
23872396
2388− if (private)
2389− ocfs2_dio_end_io_write(inode, private, offset, bytes);
2397+ if (bytes > 0 && private)
2398+ ret = ocfs2_dio_end_io_write(inode, private, offset, bytes);
23902399
23912400 ocfs2_iocb_clear_rw_locked(iocb);
23922401
23932402 level = ocfs2_iocb_rw_locked_level(iocb);
23942403 ocfs2_rw_unlock(inode, level);
2395− return 0;
2404+ return ret;
23962405 }
23972406
23982407 static ssize_t ocfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
fs/ocfs2/file.c+35−7
@@ -1030,7 +1030,7 @@ int ocfs2_extend_no_holes(struct inode *inode, struct buffer_head *di_bh, · 1029 unmodified lines
10301030 * Only quota files call this without a bh, and they can't be
10311031 * refcounted.
10321032 */
1033− BUG_ON(!di_bh && (oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL));
1033+ BUG_ON(!di_bh && ocfs2_is_refcount_inode(inode));
10341034 BUG_ON(!di_bh && !(oi->ip_flags & OCFS2_INODE_SYSTEM_FILE));
10351035
10361036 clusters_to_add = ocfs2_clusters_for_bytes(inode->i_sb, new_i_size);
@@ -1667,9 +1667,9 @@ static void ocfs2_calc_trunc_pos(struct inode *inode, · 630 unmodified lines
16671667 *done = ret;
16681668 }
16691669
1670−static int ocfs2_remove_inode_range(struct inode *inode,
1671− struct buffer_head *di_bh, u64 byte_start,
1672− u64 byte_len)
1670+int ocfs2_remove_inode_range(struct inode *inode,
1671+ struct buffer_head *di_bh, u64 byte_start,
1672+ u64 byte_len)
16731673 {
16741674 int ret = 0, flags = 0, done = 0, i;
16751675 u32 trunc_start, trunc_len, trunc_end, trunc_cpos, phys_cpos;
@@ -1719,8 +1719,7 @@ static int ocfs2_remove_inode_range(struct inode *inode, · 43 unmodified lines
17191719 * within one cluster(means is not exactly aligned to clustersize).
17201720 */
17211721
1722− if (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL) {
1723−
1722+ if (ocfs2_is_refcount_inode(inode)) {
17241723 ret = ocfs2_cow_file_pos(inode, di_bh, byte_start);
17251724 if (ret) {
17261725 mlog_errno(ret);
@@ -2036,7 +2035,7 @@ int ocfs2_check_range_for_refcount(struct inode *inode, loff_t pos, · 309 unmodified lines
20362035 struct super_block *sb = inode->i_sb;
20372036
20382037 if (!ocfs2_refcount_tree(OCFS2_SB(inode->i_sb)) ||
2039− !(OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL) ||
2038+ !ocfs2_is_refcount_inode(inode) ||
20402039 OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL)
20412040 return 0;
20422041
@@ -2440,6 +2439,31 @@ out: · 397 unmodified lines
24402439 return offset;
24412440 }
24422441
2442+static int ocfs2_file_clone_range(struct file *file_in,
2443+ loff_t pos_in,
2444+ struct file *file_out,
2445+ loff_t pos_out,
2446+ u64 len)
2447+{
2448+ return ocfs2_reflink_remap_range(file_in, pos_in, file_out, pos_out,
2449+ len, false);
2450+}
2451+
2452+static ssize_t ocfs2_file_dedupe_range(struct file *src_file,
2453+ u64 loff,
2454+ u64 len,
2455+ struct file *dst_file,
2456+ u64 dst_loff)
2457+{
2458+ int error;
2459+
2460+ error = ocfs2_reflink_remap_range(src_file, loff, dst_file, dst_loff,
2461+ len, true);
2462+ if (error)
2463+ return error;
2464+ return len;
2465+}
2466+
24432467 const struct inode_operations ocfs2_file_iops = {
24442468 .setattr = ocfs2_setattr,
24452469 .getattr = ocfs2_getattr,
@@ -2479,6 +2503,8 @@ const struct file_operations ocfs2_fops = { · 33 unmodified lines
24792503 .splice_read = generic_file_splice_read,
24802504 .splice_write = iter_file_splice_write,
24812505 .fallocate = ocfs2_fallocate,
2506+ .clone_file_range = ocfs2_file_clone_range,
2507+ .dedupe_file_range = ocfs2_file_dedupe_range,
24822508 };
24832509
24842510 const struct file_operations ocfs2_dops = {
@@ -2524,6 +2550,8 @@ const struct file_operations ocfs2_fops_no_plocks = { · 39 unmodified lines
25242550 .splice_read = generic_file_splice_read,
25252551 .splice_write = iter_file_splice_write,
25262552 .fallocate = ocfs2_fallocate,
2553+ .clone_file_range = ocfs2_file_clone_range,
2554+ .dedupe_file_range = ocfs2_file_dedupe_range,
25272555 };
25282556
25292557 const struct file_operations ocfs2_dops_no_plocks = {
fs/ocfs2/file.h+3−0
@@ -82,4 +82,7 @@ int ocfs2_change_file_space(struct file *file, unsigned int cmd, · 81 unmodified lines
8282
8383 int ocfs2_check_range_for_refcount(struct inode *inode, loff_t pos,
8484 size_t count);
85+int ocfs2_remove_inode_range(struct inode *inode,
86+ struct buffer_head *di_bh, u64 byte_start,
87+ u64 byte_len);
8588 #endif /* OCFS2_FILE_H */
fs/ocfs2/inode.h+6−0
@@ -181,4 +181,10 @@ static inline struct ocfs2_inode_info *cache_info_to_inode(struct ocfs2_caching_ · 180 unmodified lines
181181 return container_of(ci, struct ocfs2_inode_info, ip_metadata_cache);
182182 }
183183
184+/* Does this inode have the reflink flag set? */
185+static inline bool ocfs2_is_refcount_inode(struct inode *inode)
186+{
187+ return (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL);
188+}
189+
184190 #endif /* OCFS2_INODE_H */
fs/ocfs2/move_extents.c+2−8
@@ -235,10 +235,7 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context, · 234 unmodified lines
235235 u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos);
236236
237237 if ((ext_flags & OCFS2_EXT_REFCOUNTED) && *len) {
238−
239− BUG_ON(!(OCFS2_I(inode)->ip_dyn_features &
240− OCFS2_HAS_REFCOUNT_FL));
241−
238+ BUG_ON(!ocfs2_is_refcount_inode(inode));
242239 BUG_ON(!context->refcount_loc);
243240
244241 ret = ocfs2_lock_refcount_tree(osb, context->refcount_loc, 1,
@@ -581,10 +578,7 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context, · 336 unmodified lines
581578 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos);
582579
583580 if ((ext_flags & OCFS2_EXT_REFCOUNTED) && len) {
584−
585− BUG_ON(!(OCFS2_I(inode)->ip_dyn_features &
586− OCFS2_HAS_REFCOUNT_FL));
587−
581+ BUG_ON(!ocfs2_is_refcount_inode(inode));
588582 BUG_ON(!context->refcount_loc);
589583
590584 ret = ocfs2_lock_refcount_tree(osb, context->refcount_loc, 1,
fs/ocfs2/refcounttree.c+451−13
@@ -34,6 +34,7 @@ · 33 unmodified lines
3434 #include "xattr.h"
3535 #include "namei.h"
3636 #include "ocfs2_trace.h"
37+#include "file.h"
3738
3839 #include <linux/bio.h>
3940 #include <linux/blkdev.h>
@@ -410,7 +411,7 @@ static int ocfs2_get_refcount_block(struct inode *inode, u64 *ref_blkno) · 370 unmodified lines
410411 goto out;
411412 }
412413
413− BUG_ON(!(OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL));
414+ BUG_ON(!ocfs2_is_refcount_inode(inode));
414415
415416 di = (struct ocfs2_dinode *)di_bh->b_data;
416417 *ref_blkno = le64_to_cpu(di->i_refcount_loc);
@@ -569,7 +570,7 @@ static int ocfs2_create_refcount_tree(struct inode *inode, · 152 unmodified lines
569570 u32 num_got;
570571 u64 suballoc_loc, first_blkno;
571572
572− BUG_ON(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL);
573+ BUG_ON(ocfs2_is_refcount_inode(inode));
573574
574575 trace_ocfs2_create_refcount_tree(
575576 (unsigned long long)OCFS2_I(inode)->ip_blkno);
@@ -707,7 +708,7 @@ static int ocfs2_set_refcount_tree(struct inode *inode, · 131 unmodified lines
707708 struct ocfs2_refcount_block *rb;
708709 struct ocfs2_refcount_tree *ref_tree;
709710
710− BUG_ON(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL);
711+ BUG_ON(ocfs2_is_refcount_inode(inode));
711712
712713 ret = ocfs2_lock_refcount_tree(osb, refcount_loc, 1,
713714 &ref_tree, &ref_root_bh);
@@ -774,7 +775,7 @@ int ocfs2_remove_refcount_tree(struct inode *inode, struct buffer_head *di_bh) · 60 unmodified lines
774775 u64 blk = 0, bg_blkno = 0, ref_blkno = le64_to_cpu(di->i_refcount_loc);
775776 u16 bit = 0;
776777
777− if (!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL))
778+ if (!ocfs2_is_refcount_inode(inode))
778779 return 0;
779780
780781 BUG_ON(!ref_blkno);
@@ -2298,11 +2299,10 @@ int ocfs2_decrease_refcount(struct inode *inode, · 1517 unmodified lines
22982299 {
22992300 int ret;
23002301 u64 ref_blkno;
2301− struct ocfs2_inode_info *oi = OCFS2_I(inode);
23022302 struct buffer_head *ref_root_bh = NULL;
23032303 struct ocfs2_refcount_tree *tree;
23042304
2305− BUG_ON(!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL));
2305+ BUG_ON(!ocfs2_is_refcount_inode(inode));
23062306
23072307 ret = ocfs2_get_refcount_block(inode, &ref_blkno);
23082308 if (ret) {
@@ -2532,7 +2532,6 @@ int ocfs2_prepare_refcount_change_for_del(struct inode *inode, · 223 unmodified lines
25322532 int *ref_blocks)
25332533 {
25342534 int ret;
2535− struct ocfs2_inode_info *oi = OCFS2_I(inode);
25362535 struct buffer_head *ref_root_bh = NULL;
25372536 struct ocfs2_refcount_tree *tree;
25382537 u64 start_cpos = ocfs2_blocks_to_clusters(inode->i_sb, phys_blkno);
@@ -2543,7 +2542,7 @@ int ocfs2_prepare_refcount_change_for_del(struct inode *inode, · 4 unmodified lines
25432542 goto out;
25442543 }
25452544
2546− BUG_ON(!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL));
2545+ BUG_ON(!ocfs2_is_refcount_inode(inode));
25472546
25482547 ret = ocfs2_get_refcount_tree(OCFS2_SB(inode->i_sb),
25492548 refcount_loc, &tree);
@@ -3411,14 +3410,13 @@ static int ocfs2_refcount_cow_hunk(struct inode *inode, · 861 unmodified lines
34113410 {
34123411 int ret;
34133412 u32 cow_start = 0, cow_len = 0;
3414− struct ocfs2_inode_info *oi = OCFS2_I(inode);
34153413 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
34163414 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
34173415 struct buffer_head *ref_root_bh = NULL;
34183416 struct ocfs2_refcount_tree *ref_tree;
34193417 struct ocfs2_cow_context *context = NULL;
34203418
3421− BUG_ON(!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL));
3419+ BUG_ON(!ocfs2_is_refcount_inode(inode));
34223420
34233421 ret = ocfs2_refcount_cal_cow_clusters(inode, &di->id2.i_list,
34243422 cpos, write_len, max_cpos,
@@ -3628,11 +3626,10 @@ int ocfs2_refcount_cow_xattr(struct inode *inode, · 203 unmodified lines
36283626 {
36293627 int ret;
36303628 struct ocfs2_xattr_value_root *xv = vb->vb_xv;
3631− struct ocfs2_inode_info *oi = OCFS2_I(inode);
36323629 struct ocfs2_cow_context *context = NULL;
36333630 u32 cow_start, cow_len;
36343631
3635− BUG_ON(!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL));
3632+ BUG_ON(!ocfs2_is_refcount_inode(inode));
36363633
36373634 ret = ocfs2_refcount_cal_cow_clusters(inode, &xv->xr_list,
36383635 cpos, write_len, UINT_MAX,
@@ -3695,6 +3692,9 @@ int ocfs2_add_refcount_flag(struct inode *inode, · 56 unmodified lines
36953692 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
36963693 struct ocfs2_alloc_context *meta_ac = NULL;
36973694
3695+ /* We need to be able to handle at least an extent tree split. */
3696+ ref_blocks = ocfs2_extend_meta_needed(data_et->et_root_el);
3697+
36983698 ret = ocfs2_calc_refcount_meta_credits(inode->i_sb,
36993699 ref_ci, ref_root_bh,
37003700 p_cluster, num_clusters,
@@ -3806,7 +3806,7 @@ static int ocfs2_attach_refcount_tree(struct inode *inode, · 105 unmodified lines
38063806
38073807 ocfs2_init_dealloc_ctxt(&dealloc);
38083808
3809− if (!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL)) {
3809+ if (!ocfs2_is_refcount_inode(inode)) {
38103810 ret = ocfs2_create_refcount_tree(inode, di_bh);
38113811 if (ret) {
38123812 mlog_errno(ret);
@@ -3933,6 +3933,13 @@ static int ocfs2_add_refcounted_extent(struct inode *inode, · 120 unmodified lines
39333933 ret = ocfs2_increase_refcount(handle, ref_ci, ref_root_bh,
39343934 p_cluster, num_clusters,
39353935 meta_ac, dealloc);
3936+ if (ret) {
3937+ mlog_errno(ret);
3938+ goto out_commit;
3939+ }
3940+
3941+ ret = dquot_alloc_space_nodirty(inode,
3942+ ocfs2_clusters_to_bytes(osb->sb, num_clusters));
39363943 if (ret)
39373944 mlog_errno(ret);
39383945
@@ -4441,3 +4448,434 @@ out: · 502 unmodified lines
44414448
44424449 return error;
44434450 }
4451+
4452+/* Update destination inode size, if necessary. */
4453+static int ocfs2_reflink_update_dest(struct inode *dest,
4454+ struct buffer_head *d_bh,
4455+ loff_t newlen)
4456+{
4457+ handle_t *handle;
4458+ int ret;
4459+
4460+ dest->i_blocks = ocfs2_inode_sector_count(dest);
4461+
4462+ if (newlen <= i_size_read(dest))
4463+ return 0;
4464+
4465+ handle = ocfs2_start_trans(OCFS2_SB(dest->i_sb),
4466+ OCFS2_INODE_UPDATE_CREDITS);
4467+ if (IS_ERR(handle)) {
4468+ ret = PTR_ERR(handle);
4469+ mlog_errno(ret);
4470+ return ret;
4471+ }
4472+
4473+ /* Extend i_size if needed. */
4474+ spin_lock(&OCFS2_I(dest)->ip_lock);
4475+ if (newlen > i_size_read(dest))
4476+ i_size_write(dest, newlen);
4477+ spin_unlock(&OCFS2_I(dest)->ip_lock);
4478+ dest->i_ctime = dest->i_mtime = current_time(dest);
4479+
4480+ ret = ocfs2_mark_inode_dirty(handle, dest, d_bh);
4481+ if (ret) {
4482+ mlog_errno(ret);
4483+ goto out_commit;
4484+ }
4485+
4486+out_commit:
4487+ ocfs2_commit_trans(OCFS2_SB(dest->i_sb), handle);
4488+ return ret;
4489+}
4490+
4491+/* Remap the range pos_in:len in s_inode to pos_out:len in t_inode. */
4492+static int ocfs2_reflink_remap_extent(struct inode *s_inode,
4493+ struct buffer_head *s_bh,
4494+ loff_t pos_in,
4495+ struct inode *t_inode,
4496+ struct buffer_head *t_bh,
4497+ loff_t pos_out,
4498+ loff_t len,
4499+ struct ocfs2_cached_dealloc_ctxt *dealloc)
4500+{
4501+ struct ocfs2_extent_tree s_et;
4502+ struct ocfs2_extent_tree t_et;
4503+ struct ocfs2_dinode *dis;
4504+ struct buffer_head *ref_root_bh = NULL;
4505+ struct ocfs2_refcount_tree *ref_tree;
4506+ struct ocfs2_super *osb;
4507+ loff_t pstart, plen;
4508+ u32 p_cluster, num_clusters, slast, spos, tpos;
4509+ unsigned int ext_flags;
4510+ int ret = 0;
4511+
4512+ osb = OCFS2_SB(s_inode->i_sb);
4513+ dis = (struct ocfs2_dinode *)s_bh->b_data;
4514+ ocfs2_init_dinode_extent_tree(&s_et, INODE_CACHE(s_inode), s_bh);
4515+ ocfs2_init_dinode_extent_tree(&t_et, INODE_CACHE(t_inode), t_bh);
4516+
4517+ spos = ocfs2_bytes_to_clusters(s_inode->i_sb, pos_in);
4518+ tpos = ocfs2_bytes_to_clusters(t_inode->i_sb, pos_out);
4519+ slast = ocfs2_clusters_for_bytes(s_inode->i_sb, pos_in + len);
4520+
4521+ while (spos < slast) {
4522+ if (fatal_signal_pending(current)) {
4523+ ret = -EINTR;
4524+ goto out;
4525+ }
4526+
4527+ /* Look up the extent. */
4528+ ret = ocfs2_get_clusters(s_inode, spos, &p_cluster,
4529+ &num_clusters, &ext_flags);
4530+ if (ret) {
4531+ mlog_errno(ret);
4532+ goto out;
4533+ }
4534+
4535+ num_clusters = min_t(u32, num_clusters, slast - spos);
4536+
4537+ /* Punch out the dest range. */
4538+ pstart = ocfs2_clusters_to_bytes(t_inode->i_sb, tpos);
4539+ plen = ocfs2_clusters_to_bytes(t_inode->i_sb, num_clusters);
4540+ ret = ocfs2_remove_inode_range(t_inode, t_bh, pstart, plen);
4541+ if (ret) {
4542+ mlog_errno(ret);
4543+ goto out;
4544+ }
4545+
4546+ if (p_cluster == 0)
4547+ goto next_loop;
4548+
4549+ /* Lock the refcount btree... */
4550+ ret = ocfs2_lock_refcount_tree(osb,
4551+ le64_to_cpu(dis->i_refcount_loc),
4552+ 1, &ref_tree, &ref_root_bh);
4553+ if (ret) {
4554+ mlog_errno(ret);
4555+ goto out;
4556+ }
4557+
4558+ /* Mark s_inode's extent as refcounted. */
4559+ if (!(ext_flags & OCFS2_EXT_REFCOUNTED)) {
4560+ ret = ocfs2_add_refcount_flag(s_inode, &s_et,
4561+ &ref_tree->rf_ci,
4562+ ref_root_bh, spos,
4563+ p_cluster, num_clusters,
4564+ dealloc, NULL);
4565+ if (ret) {
4566+ mlog_errno(ret);
4567+ goto out_unlock_refcount;
4568+ }
4569+ }
4570+
4571+ /* Map in the new extent. */
4572+ ext_flags |= OCFS2_EXT_REFCOUNTED;
4573+ ret = ocfs2_add_refcounted_extent(t_inode, &t_et,
4574+ &ref_tree->rf_ci,
4575+ ref_root_bh,
4576+ tpos, p_cluster,
4577+ num_clusters,
4578+ ext_flags,
4579+ dealloc);
4580+ if (ret) {
4581+ mlog_errno(ret);
4582+ goto out_unlock_refcount;
4583+ }
4584+
4585+ ocfs2_unlock_refcount_tree(osb, ref_tree, 1);
4586+ brelse(ref_root_bh);
4587+next_loop:
4588+ spos += num_clusters;
4589+ tpos += num_clusters;
4590+ }
4591+
4592+out:
4593+ return ret;
4594+out_unlock_refcount:
4595+ ocfs2_unlock_refcount_tree(osb, ref_tree, 1);
4596+ brelse(ref_root_bh);
4597+ return ret;
4598+}
4599+
4600+/* Set up refcount tree and remap s_inode to t_inode. */
4601+static int ocfs2_reflink_remap_blocks(struct inode *s_inode,
4602+ struct buffer_head *s_bh,
4603+ loff_t pos_in,
4604+ struct inode *t_inode,
4605+ struct buffer_head *t_bh,
4606+ loff_t pos_out,
4607+ loff_t len)
4608+{
4609+ struct ocfs2_cached_dealloc_ctxt dealloc;
4610+ struct ocfs2_super *osb;
4611+ struct ocfs2_dinode *dis;
4612+ struct ocfs2_dinode *dit;
4613+ int ret;
4614+
4615+ osb = OCFS2_SB(s_inode->i_sb);
4616+ dis = (struct ocfs2_dinode *)s_bh->b_data;
4617+ dit = (struct ocfs2_dinode *)t_bh->b_data;
4618+ ocfs2_init_dealloc_ctxt(&dealloc);
4619+
4620+ /*
4621+ * If we're reflinking the entire file and the source is inline
4622+ * data, just copy the contents.
4623+ */
4624+ if (pos_in == pos_out && pos_in == 0 && len == i_size_read(s_inode) &&
4625+ i_size_read(t_inode) <= len &&
4626+ (OCFS2_I(s_inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL)) {
4627+ ret = ocfs2_duplicate_inline_data(s_inode, s_bh, t_inode, t_bh);
4628+ if (ret)
4629+ mlog_errno(ret);
4630+ goto out;
4631+ }
4632+
4633+ /*
4634+ * If both inodes belong to two different refcount groups then
4635+ * forget it because we don't know how (or want) to go merging
4636+ * refcount trees.
4637+ */
4638+ ret = -EOPNOTSUPP;
4639+ if (ocfs2_is_refcount_inode(s_inode) &&
4640+ ocfs2_is_refcount_inode(t_inode) &&
4641+ le64_to_cpu(dis->i_refcount_loc) !=
4642+ le64_to_cpu(dit->i_refcount_loc))
4643+ goto out;
4644+
4645+ /* Neither inode has a refcount tree. Add one to s_inode. */
4646+ if (!ocfs2_is_refcount_inode(s_inode) &&
4647+ !ocfs2_is_refcount_inode(t_inode)) {
4648+ ret = ocfs2_create_refcount_tree(s_inode, s_bh);
4649+ if (ret) {
4650+ mlog_errno(ret);
4651+ goto out;
4652+ }
4653+ }
4654+
4655+ /* Ensure that both inodes end up with the same refcount tree. */
4656+ if (!ocfs2_is_refcount_inode(s_inode)) {
4657+ ret = ocfs2_set_refcount_tree(s_inode, s_bh,
4658+ le64_to_cpu(dit->i_refcount_loc));
4659+ if (ret) {
4660+ mlog_errno(ret);
4661+ goto out;
4662+ }
4663+ }
4664+ if (!ocfs2_is_refcount_inode(t_inode)) {
4665+ ret = ocfs2_set_refcount_tree(t_inode, t_bh,
4666+ le64_to_cpu(dis->i_refcount_loc));
4667+ if (ret) {
4668+ mlog_errno(ret);
4669+ goto out;
4670+ }
4671+ }
4672+
4673+ /* Turn off inline data in the dest file. */
4674+ if (OCFS2_I(t_inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) {
4675+ ret = ocfs2_convert_inline_data_to_extents(t_inode, t_bh);
4676+ if (ret) {
4677+ mlog_errno(ret);
4678+ goto out;
4679+ }
4680+ }
4681+
4682+ /* Actually remap extents now. */
4683+ ret = ocfs2_reflink_remap_extent(s_inode, s_bh, pos_in, t_inode, t_bh,
4684+ pos_out, len, &dealloc);
4685+ if (ret) {
4686+ mlog_errno(ret);
4687+ goto out;
4688+ }
4689+
4690+out:
4691+ if (ocfs2_dealloc_has_cluster(&dealloc)) {
4692+ ocfs2_schedule_truncate_log_flush(osb, 1);
4693+ ocfs2_run_deallocs(osb, &dealloc);
4694+ }
4695+
4696+ return ret;
4697+}
4698+
4699+/* Lock an inode and grab a bh pointing to the inode. */
4700+static int ocfs2_reflink_inodes_lock(struct inode *s_inode,
4701+ struct buffer_head **bh1,
4702+ struct inode *t_inode,
4703+ struct buffer_head **bh2)
4704+{
4705+ struct inode *inode1;
4706+ struct inode *inode2;
4707+ struct ocfs2_inode_info *oi1;
4708+ struct ocfs2_inode_info *oi2;
4709+ bool same_inode = (s_inode == t_inode);
4710+ int status;
4711+
4712+ /* First grab the VFS and rw locks. */
4713+ lock_two_nondirectories(s_inode, t_inode);
4714+ inode1 = s_inode;
4715+ inode2 = t_inode;
4716+ if (inode1->i_ino > inode2->i_ino)
4717+ swap(inode1, inode2);
4718+
4719+ status = ocfs2_rw_lock(inode1, 1);
4720+ if (status) {
4721+ mlog_errno(status);
4722+ goto out_i1;
4723+ }
4724+ if (!same_inode) {
4725+ status = ocfs2_rw_lock(inode2, 1);
4726+ if (status) {
4727+ mlog_errno(status);
4728+ goto out_i2;
4729+ }
4730+ }
4731+
4732+ /* Now go for the cluster locks */
4733+ oi1 = OCFS2_I(inode1);
4734+ oi2 = OCFS2_I(inode2);
4735+
4736+ trace_ocfs2_double_lock((unsigned long long)oi1->ip_blkno,
4737+ (unsigned long long)oi2->ip_blkno);
4738+
4739+ if (*bh1)
4740+ *bh1 = NULL;
4741+ if (*bh2)
4742+ *bh2 = NULL;
4743+
4744+ /* We always want to lock the one with the lower lockid first. */
4745+ if (oi1->ip_blkno > oi2->ip_blkno)
4746+ mlog_errno(-ENOLCK);
4747+
4748+ /* lock id1 */
4749+ status = ocfs2_inode_lock_nested(inode1, bh1, 1, OI_LS_REFLINK_TARGET);
4750+ if (status < 0) {
4751+ if (status != -ENOENT)
4752+ mlog_errno(status);
4753+ goto out_rw2;
4754+ }
4755+
4756+ /* lock id2 */
4757+ if (!same_inode) {
4758+ status = ocfs2_inode_lock_nested(inode2, bh2, 1,
4759+ OI_LS_REFLINK_TARGET);
4760+ if (status < 0) {
4761+ if (status != -ENOENT)
4762+ mlog_errno(status);
4763+ goto out_cl1;
4764+ }
4765+ } else
4766+ *bh2 = *bh1;
4767+
4768+ trace_ocfs2_double_lock_end(
4769+ (unsigned long long)OCFS2_I(inode1)->ip_blkno,
4770+ (unsigned long long)OCFS2_I(inode2)->ip_blkno);
4771+
4772+ return 0;
4773+
4774+out_cl1:
4775+ ocfs2_inode_unlock(inode1, 1);
4776+ brelse(*bh1);
4777+ *bh1 = NULL;
4778+out_rw2:
4779+ ocfs2_rw_unlock(inode2, 1);
4780+out_i2:
4781+ ocfs2_rw_unlock(inode1, 1);
4782+out_i1:
4783+ unlock_two_nondirectories(s_inode, t_inode);
4784+ return status;
4785+}
4786+
4787+/* Unlock both inodes and release buffers. */
4788+static void ocfs2_reflink_inodes_unlock(struct inode *s_inode,
4789+ struct buffer_head *s_bh,
4790+ struct inode *t_inode,
4791+ struct buffer_head *t_bh)
4792+{
4793+ ocfs2_inode_unlock(s_inode, 1);
4794+ ocfs2_rw_unlock(s_inode, 1);
4795+ brelse(s_bh);
4796+ if (s_inode != t_inode) {
4797+ ocfs2_inode_unlock(t_inode, 1);
4798+ ocfs2_rw_unlock(t_inode, 1);
4799+ brelse(t_bh);
4800+ }
4801+ unlock_two_nondirectories(s_inode, t_inode);
4802+}
4803+
4804+/* Link a range of blocks from one file to another. */
4805+int ocfs2_reflink_remap_range(struct file *file_in,
4806+ loff_t pos_in,
4807+ struct file *file_out,
4808+ loff_t pos_out,
4809+ u64 len,
4810+ bool is_dedupe)
4811+{
4812+ struct inode *inode_in = file_inode(file_in);
4813+ struct inode *inode_out = file_inode(file_out);
4814+ struct ocfs2_super *osb = OCFS2_SB(inode_in->i_sb);
4815+ struct buffer_head *in_bh = NULL, *out_bh = NULL;
4816+ bool same_inode = (inode_in == inode_out);
4817+ ssize_t ret;
4818+
4819+ if (!ocfs2_refcount_tree(osb))
4820+ return -EOPNOTSUPP;
4821+ if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
4822+ return -EROFS;
4823+
4824+ /* Lock both files against IO */
4825+ ret = ocfs2_reflink_inodes_lock(inode_in, &in_bh, inode_out, &out_bh);
4826+ if (ret)
4827+ return ret;
4828+
4829+ /* Check file eligibility and prepare for block sharing. */
4830+ ret = -EINVAL;
4831+ if ((OCFS2_I(inode_in)->ip_flags & OCFS2_INODE_SYSTEM_FILE) ||
4832+ (OCFS2_I(inode_out)->ip_flags & OCFS2_INODE_SYSTEM_FILE))
4833+ goto out_unlock;
4834+
4835+ ret = vfs_clone_file_prep_inodes(inode_in, pos_in, inode_out, pos_out,
4836+ &len, is_dedupe);
4837+ if (ret || len == 0)
4838+ goto out_unlock;
4839+
4840+ /* Lock out changes to the allocation maps and remap. */
4841+ down_write(&OCFS2_I(inode_in)->ip_alloc_sem);
4842+ if (!same_inode)
4843+ down_write_nested(&OCFS2_I(inode_out)->ip_alloc_sem,
4844+ SINGLE_DEPTH_NESTING);
4845+
4846+ ret = ocfs2_reflink_remap_blocks(inode_in, in_bh, pos_in, inode_out,
4847+ out_bh, pos_out, len);
4848+
4849+ /* Zap any page cache for the destination file's range. */
4850+ if (!ret)
4851+ truncate_inode_pages_range(&inode_out->i_data, pos_out,
4852+ PAGE_ALIGN(pos_out + len) - 1);
4853+
4854+ up_write(&OCFS2_I(inode_in)->ip_alloc_sem);
4855+ if (!same_inode)
4856+ up_write(&OCFS2_I(inode_out)->ip_alloc_sem);
4857+ if (ret) {
4858+ mlog_errno(ret);
4859+ goto out_unlock;
4860+ }
4861+
4862+ /*
4863+ * Empty the extent map so that we may get the right extent
4864+ * record from the disk.
4865+ */
4866+ ocfs2_extent_map_trunc(inode_in, 0);
4867+ ocfs2_extent_map_trunc(inode_out, 0);
4868+
4869+ ret = ocfs2_reflink_update_dest(inode_out, out_bh, pos_out + len);
4870+ if (ret) {
4871+ mlog_errno(ret);
4872+ goto out_unlock;
4873+ }
4874+
4875+ ocfs2_reflink_inodes_unlock(inode_in, in_bh, inode_out, out_bh);
4876+ return 0;
4877+
4878+out_unlock:
4879+ ocfs2_reflink_inodes_unlock(inode_in, in_bh, inode_out, out_bh);
4880+ return ret;
4881+}
fs/ocfs2/refcounttree.h+7−0
@@ -115,4 +115,11 @@ int ocfs2_reflink_ioctl(struct inode *inode, · 114 unmodified lines
115115 const char __user *oldname,
116116 const char __user *newname,
117117 bool preserve);
118+int ocfs2_reflink_remap_range(struct file *file_in,
119+ loff_t pos_in,
120+ struct file *file_out,
121+ loff_t pos_out,
122+ u64 len,
123+ bool is_dedupe);
124+
118125 #endif /* OCFS2_REFCOUNTTREE_H */
fs/ocfs2/xattr.c+2−2
@@ -2577,7 +2577,7 @@ int ocfs2_xattr_remove(struct inode *inode, struct buffer_head *di_bh) · 2576 unmodified lines
25772577 if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL))
25782578 return 0;
25792579
2580− if (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL) {
2580+ if (ocfs2_is_refcount_inode(inode)) {
25812581 ret = ocfs2_lock_refcount_tree(OCFS2_SB(inode->i_sb),
25822582 le64_to_cpu(di->i_refcount_loc),
25832583 1, &ref_tree, &ref_root_bh);
@@ -3608,7 +3608,7 @@ int ocfs2_xattr_set(struct inode *inode, · 1024 unmodified lines
36083608 }
36093609
36103610 /* Check whether the value is refcounted and do some preparation. */
3611− if (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL &&
3611+ if (ocfs2_is_refcount_inode(inode) &&
36123612 (!xis.not_found || !xbs.not_found)) {
36133613 ret = ocfs2_prepare_refcount_xattr(inode, di, &xi,
36143614 &xis, &xbs, &ref_tree,
fs/quota/dquot.c+1−1
@@ -2401,7 +2401,7 @@ int dquot_resume(struct super_block *sb, int type) · 2400 unmodified lines
24012401 EXPORT_SYMBOL(dquot_resume);
24022402
24032403 int dquot_quota_on(struct super_block *sb, int type, int format_id,
2404− struct path *path)
2404+ const struct path *path)
24052405 {
24062406 int error = security_quota_on(path->dentry);
24072407 if (error)
fs/quota/quota.c+2−2
@@ -80,7 +80,7 @@ unsigned int qtype_enforce_flag(int type) · 79 unmodified lines
8080 }
8181
8282 static int quota_quotaon(struct super_block *sb, int type, qid_t id,
83− struct path *path)
83+ const struct path *path)
8484 {
8585 if (!sb->s_qcop->quota_on && !sb->s_qcop->quota_enable)
8686 return -ENOSYS;
@@ -700,7 +700,7 @@ static int quota_rmxquota(struct super_block *sb, void __user *addr) · 613 unmodified lines
700700
701701 /* Copy parameters and call proper function */
702702 static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
703− void __user *addr, struct path *path)
703+ void __user *addr, const struct path *path)
704704 {
705705 int ret;
706706
fs/read_write.c+226−5
@@ -1540,20 +1540,37 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, · 1539 unmodified lines
15401540
15411541 sb_start_write(inode_out->i_sb);
15421542
1543− ret = -EOPNOTSUPP;
1544− if (file_out->f_op->copy_file_range)
1543+ /*
1544+ * Try cloning first, this is supported by more file systems, and
1545+ * more efficient if both clone and copy are supported (e.g. NFS).
1546+ */
1547+ if (file_in->f_op->clone_file_range) {
1548+ ret = file_in->f_op->clone_file_range(file_in, pos_in,
1549+ file_out, pos_out, len);
1550+ if (ret == 0) {
1551+ ret = len;
1552+ goto done;
1553+ }
1554+ }
1555+
1556+ if (file_out->f_op->copy_file_range) {
15451557 ret = file_out->f_op->copy_file_range(file_in, pos_in, file_out,
15461558 pos_out, len, flags);
1547− if (ret == -EOPNOTSUPP)
1548− ret = do_splice_direct(file_in, &pos_in, file_out, &pos_out,
1549− len > MAX_RW_COUNT ? MAX_RW_COUNT : len, 0);
1559+ if (ret != -EOPNOTSUPP)
1560+ goto done;
1561+ }
1562+
1563+ ret = do_splice_direct(file_in, &pos_in, file_out, &pos_out,
1564+ len > MAX_RW_COUNT ? MAX_RW_COUNT : len, 0);
15501565
1566+done:
15511567 if (ret > 0) {
15521568 fsnotify_access(file_in);
15531569 add_rchar(current, ret);
15541570 fsnotify_modify(file_out);
15551571 add_wchar(current, ret);
15561572 }
1573+
15571574 inc_syscr(current);
15581575 inc_syscw(current);
15591576
@@ -1648,6 +1665,114 @@ static int clone_verify_area(struct file *file, loff_t pos, u64 len, bool write) · 88 unmodified lines
16481665 return security_file_permission(file, write ? MAY_WRITE : MAY_READ);
16491666 }
16501667
1668+/*
1669+ * Check that the two inodes are eligible for cloning, the ranges make
1670+ * sense, and then flush all dirty data. Caller must ensure that the
1671+ * inodes have been locked against any other modifications.
1672+ */
1673+int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in,
1674+ struct inode *inode_out, loff_t pos_out,
1675+ u64 *len, bool is_dedupe)
1676+{
1677+ loff_t bs = inode_out->i_sb->s_blocksize;
1678+ loff_t blen;
1679+ loff_t isize;
1680+ bool same_inode = (inode_in == inode_out);
1681+ int ret;
1682+
1683+ /* Don't touch certain kinds of inodes */
1684+ if (IS_IMMUTABLE(inode_out))
1685+ return -EPERM;
1686+
1687+ if (IS_SWAPFILE(inode_in) || IS_SWAPFILE(inode_out))
1688+ return -ETXTBSY;
1689+
1690+ /* Don't reflink dirs, pipes, sockets... */
1691+ if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode))
1692+ return -EISDIR;
1693+ if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode))
1694+ return -EINVAL;
1695+
1696+ /* Are we going all the way to the end? */
1697+ isize = i_size_read(inode_in);
1698+ if (isize == 0) {
1699+ *len = 0;
1700+ return 0;
1701+ }
1702+
1703+ /* Zero length dedupe exits immediately; reflink goes to EOF. */
1704+ if (*len == 0) {
1705+ if (is_dedupe) {
1706+ *len = 0;
1707+ return 0;
1708+ }
1709+ *len = isize - pos_in;
1710+ }
1711+
1712+ /* Ensure offsets don't wrap and the input is inside i_size */
1713+ if (pos_in + *len < pos_in || pos_out + *len < pos_out ||
1714+ pos_in + *len > isize)
1715+ return -EINVAL;
1716+
1717+ /* Don't allow dedupe past EOF in the dest file */
1718+ if (is_dedupe) {
1719+ loff_t disize;
1720+
1721+ disize = i_size_read(inode_out);
1722+ if (pos_out >= disize || pos_out + *len > disize)
1723+ return -EINVAL;
1724+ }
1725+
1726+ /* If we're linking to EOF, continue to the block boundary. */
1727+ if (pos_in + *len == isize)
1728+ blen = ALIGN(isize, bs) - pos_in;
1729+ else
1730+ blen = *len;
1731+
1732+ /* Only reflink if we're aligned to block boundaries */
1733+ if (!IS_ALIGNED(pos_in, bs) || !IS_ALIGNED(pos_in + blen, bs) ||
1734+ !IS_ALIGNED(pos_out, bs) || !IS_ALIGNED(pos_out + blen, bs))
1735+ return -EINVAL;
1736+
1737+ /* Don't allow overlapped reflink within the same file */
1738+ if (same_inode) {
1739+ if (pos_out + blen > pos_in && pos_out < pos_in + blen)
1740+ return -EINVAL;
1741+ }
1742+
1743+ /* Wait for the completion of any pending IOs on both files */
1744+ inode_dio_wait(inode_in);
1745+ if (!same_inode)
1746+ inode_dio_wait(inode_out);
1747+
1748+ ret = filemap_write_and_wait_range(inode_in->i_mapping,
1749+ pos_in, pos_in + *len - 1);
1750+ if (ret)
1751+ return ret;
1752+
1753+ ret = filemap_write_and_wait_range(inode_out->i_mapping,
1754+ pos_out, pos_out + *len - 1);
1755+ if (ret)
1756+ return ret;
1757+
1758+ /*
1759+ * Check that the extents are the same.
1760+ */
1761+ if (is_dedupe) {
1762+ bool is_same = false;
1763+
1764+ ret = vfs_dedupe_file_range_compare(inode_in, pos_in,
1765+ inode_out, pos_out, *len, &is_same);
1766+ if (ret)
1767+ return ret;
1768+ if (!is_same)
1769+ return -EBADE;
1770+ }
1771+
1772+ return 0;
1773+}
1774+EXPORT_SYMBOL(vfs_clone_file_prep_inodes);
1775+
16511776 int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
16521777 struct file *file_out, loff_t pos_out, u64 len)
16531778 {
@@ -1698,6 +1823,102 @@ int vfs_clone_file_range(struct file *file_in, loff_t pos_in, · 44 unmodified lines
16981823 }
16991824 EXPORT_SYMBOL(vfs_clone_file_range);
17001825
1826+/*
1827+ * Read a page's worth of file data into the page cache. Return the page
1828+ * locked.
1829+ */
1830+static struct page *vfs_dedupe_get_page(struct inode *inode, loff_t offset)
1831+{
1832+ struct address_space *mapping;
1833+ struct page *page;
1834+ pgoff_t n;
1835+
1836+ n = offset >> PAGE_SHIFT;
1837+ mapping = inode->i_mapping;
1838+ page = read_mapping_page(mapping, n, NULL);
1839+ if (IS_ERR(page))
1840+ return page;
1841+ if (!PageUptodate(page)) {
1842+ put_page(page);
1843+ return ERR_PTR(-EIO);
1844+ }
1845+ lock_page(page);
1846+ return page;
1847+}
1848+
1849+/*
1850+ * Compare extents of two files to see if they are the same.
1851+ * Caller must have locked both inodes to prevent write races.
1852+ */
1853+int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
1854+ struct inode *dest, loff_t destoff,
1855+ loff_t len, bool *is_same)
1856+{
1857+ loff_t src_poff;
1858+ loff_t dest_poff;
1859+ void *src_addr;
1860+ void *dest_addr;
1861+ struct page *src_page;
1862+ struct page *dest_page;
1863+ loff_t cmp_len;
1864+ bool same;
1865+ int error;
1866+
1867+ error = -EINVAL;
1868+ same = true;
1869+ while (len) {
1870+ src_poff = srcoff & (PAGE_SIZE - 1);
1871+ dest_poff = destoff & (PAGE_SIZE - 1);
1872+ cmp_len = min(PAGE_SIZE - src_poff,
1873+ PAGE_SIZE - dest_poff);
1874+ cmp_len = min(cmp_len, len);
1875+ if (cmp_len <= 0)
1876+ goto out_error;
1877+
1878+ src_page = vfs_dedupe_get_page(src, srcoff);
1879+ if (IS_ERR(src_page)) {
1880+ error = PTR_ERR(src_page);
1881+ goto out_error;
1882+ }
1883+ dest_page = vfs_dedupe_get_page(dest, destoff);
1884+ if (IS_ERR(dest_page)) {
1885+ error = PTR_ERR(dest_page);
1886+ unlock_page(src_page);
1887+ put_page(src_page);
1888+ goto out_error;
1889+ }
1890+ src_addr = kmap_atomic(src_page);
1891+ dest_addr = kmap_atomic(dest_page);
1892+
1893+ flush_dcache_page(src_page);
1894+ flush_dcache_page(dest_page);
1895+
1896+ if (memcmp(src_addr + src_poff, dest_addr + dest_poff, cmp_len))
1897+ same = false;
1898+
1899+ kunmap_atomic(dest_addr);
1900+ kunmap_atomic(src_addr);
1901+ unlock_page(dest_page);
1902+ unlock_page(src_page);
1903+ put_page(dest_page);
1904+ put_page(src_page);
1905+
1906+ if (!same)
1907+ break;
1908+
1909+ srcoff += cmp_len;
1910+ destoff += cmp_len;
1911+ len -= cmp_len;
1912+ }
1913+
1914+ *is_same = same;
1915+ return 0;
1916+
1917+out_error:
1918+ return error;
1919+}
1920+EXPORT_SYMBOL(vfs_dedupe_file_range_compare);
1921+
17011922 int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same)
17021923 {
17031924 struct file_dedupe_range_info *info;
fs/reiserfs/super.c+2−2
@@ -802,7 +802,7 @@ static int reiserfs_acquire_dquot(struct dquot *); · 801 unmodified lines
802802 static int reiserfs_release_dquot(struct dquot *);
803803 static int reiserfs_mark_dquot_dirty(struct dquot *);
804804 static int reiserfs_write_info(struct super_block *, int);
805−static int reiserfs_quota_on(struct super_block *, int, int, struct path *);
805+static int reiserfs_quota_on(struct super_block *, int, int, const struct path *);
806806
807807 static const struct dquot_operations reiserfs_quota_operations = {
808808 .write_dquot = reiserfs_write_dquot,
@@ -2348,7 +2348,7 @@ static int reiserfs_quota_on_mount(struct super_block *sb, int type) · 1539 unmodified lines
23482348 * Standard function to be called on quota_on
23492349 */
23502350 static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
2351− struct path *path)
2351+ const struct path *path)
23522352 {
23532353 int err;
23542354 struct inode *inode;
fs/statfs.c+1−1
@@ -63,7 +63,7 @@ static int statfs_by_dentry(struct dentry *dentry, struct kstatfs *buf) · 62 unmodified lines
6363 return retval;
6464 }
6565
66−int vfs_statfs(struct path *path, struct kstatfs *buf)
66+int vfs_statfs(const struct path *path, struct kstatfs *buf)
6767 {
6868 int error;
6969
fs/utimes.c+1−1
@@ -48,7 +48,7 @@ static bool nsec_valid(long nsec) · 47 unmodified lines
4848 return nsec >= 0 && nsec <= 999999999;
4949 }
5050
51−static int utimes_common(struct path *path, struct timespec *times)
51+static int utimes_common(const struct path *path, struct timespec *times)
5252 {
5353 int error;
5454 struct iattr newattrs;
fs/xfs/xfs_file.c+0−19
@@ -848,24 +848,6 @@ out_unlock: · 847 unmodified lines
848848 return error;
849849 }
850850
851−STATIC ssize_t
852−xfs_file_copy_range(
853− struct file *file_in,
854− loff_t pos_in,
855− struct file *file_out,
856− loff_t pos_out,
857− size_t len,
858− unsigned int flags)
859−{
860− int error;
861−
862− error = xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out,
863− len, false);
864− if (error)
865− return error;
866− return len;
867−}
868−
869851 STATIC int
870852 xfs_file_clone_range(
871853 struct file *file_in,
@@ -1549,7 +1531,6 @@ const struct file_operations xfs_file_operations = { · 677 unmodified lines
15491531 .fsync = xfs_file_fsync,
15501532 .get_unmapped_area = thp_get_unmapped_area,
15511533 .fallocate = xfs_file_fallocate,
1552− .copy_file_range = xfs_file_copy_range,
15531534 .clone_file_range = xfs_file_clone_range,
15541535 .dedupe_file_range = xfs_file_dedupe_range,
15551536 };
fs/xfs/xfs_reflink.c+9−210
@@ -1113,111 +1113,6 @@ err: · 1112 unmodified lines
11131113 return error;
11141114 }
11151115
1116−/*
1117− * Read a page's worth of file data into the page cache. Return the page
1118− * locked.
1119− */
1120−static struct page *
1121−xfs_get_page(
1122− struct inode *inode,
1123− xfs_off_t offset)
1124−{
1125− struct address_space *mapping;
1126− struct page *page;
1127− pgoff_t n;
1128−
1129− n = offset >> PAGE_SHIFT;
1130− mapping = inode->i_mapping;
1131− page = read_mapping_page(mapping, n, NULL);
1132− if (IS_ERR(page))
1133− return page;
1134− if (!PageUptodate(page)) {
1135− put_page(page);
1136− return ERR_PTR(-EIO);
1137− }
1138− lock_page(page);
1139− return page;
1140−}
1141−
1142−/*
1143− * Compare extents of two files to see if they are the same.
1144− */
1145−static int
1146−xfs_compare_extents(
1147− struct inode *src,
1148− xfs_off_t srcoff,
1149− struct inode *dest,
1150− xfs_off_t destoff,
1151− xfs_off_t len,
1152− bool *is_same)
1153−{
1154− xfs_off_t src_poff;
1155− xfs_off_t dest_poff;
1156− void *src_addr;
1157− void *dest_addr;
1158− struct page *src_page;
1159− struct page *dest_page;
1160− xfs_off_t cmp_len;
1161− bool same;
1162− int error;
1163−
1164− error = -EINVAL;
1165− same = true;
1166− while (len) {
1167− src_poff = srcoff & (PAGE_SIZE - 1);
1168− dest_poff = destoff & (PAGE_SIZE - 1);
1169− cmp_len = min(PAGE_SIZE - src_poff,
1170− PAGE_SIZE - dest_poff);
1171− cmp_len = min(cmp_len, len);
1172− ASSERT(cmp_len > 0);
1173−
1174− trace_xfs_reflink_compare_extents(XFS_I(src), srcoff, cmp_len,
1175− XFS_I(dest), destoff);
1176−
1177− src_page = xfs_get_page(src, srcoff);
1178− if (IS_ERR(src_page)) {
1179− error = PTR_ERR(src_page);
1180− goto out_error;
1181− }
1182− dest_page = xfs_get_page(dest, destoff);
1183− if (IS_ERR(dest_page)) {
1184− error = PTR_ERR(dest_page);
1185− unlock_page(src_page);
1186− put_page(src_page);
1187− goto out_error;
1188− }
1189− src_addr = kmap_atomic(src_page);
1190− dest_addr = kmap_atomic(dest_page);
1191−
1192− flush_dcache_page(src_page);
1193− flush_dcache_page(dest_page);
1194−
1195− if (memcmp(src_addr + src_poff, dest_addr + dest_poff, cmp_len))
1196− same = false;
1197−
1198− kunmap_atomic(dest_addr);
1199− kunmap_atomic(src_addr);
1200− unlock_page(dest_page);
1201− unlock_page(src_page);
1202− put_page(dest_page);
1203− put_page(src_page);
1204−
1205− if (!same)
1206− break;
1207−
1208− srcoff += cmp_len;
1209− destoff += cmp_len;
1210− len -= cmp_len;
1211− }
1212−
1213− *is_same = same;
1214− return 0;
1215−
1216−out_error:
1217− trace_xfs_reflink_compare_extents_error(XFS_I(dest), error, _RET_IP_);
1218− return error;
1219−}
1220−
12211116 /*
12221117 * Link a range of blocks from one file to another.
12231118 */
@@ -1235,14 +1130,11 @@ xfs_reflink_remap_range( · 11 unmodified lines
12351130 struct inode *inode_out = file_inode(file_out);
12361131 struct xfs_inode *dest = XFS_I(inode_out);
12371132 struct xfs_mount *mp = src->i_mount;
1238− loff_t bs = inode_out->i_sb->s_blocksize;
12391133 bool same_inode = (inode_in == inode_out);
12401134 xfs_fileoff_t sfsbno, dfsbno;
12411135 xfs_filblks_t fsblen;
12421136 xfs_extlen_t cowextsize;
1243− loff_t isize;
12441137 ssize_t ret;
1245− loff_t blen;
12461138
12471139 if (!xfs_sb_version_hasreflink(&mp->m_sb))
12481140 return -EOPNOTSUPP;
@@ -1257,26 +1149,8 @@ xfs_reflink_remap_range( · 8 unmodified lines
12571149 else
12581150 xfs_lock_two_inodes(src, dest, XFS_MMAPLOCK_EXCL);
12591151
1260− /* Don't touch certain kinds of inodes */
1261− ret = -EPERM;
1262− if (IS_IMMUTABLE(inode_out))
1263− goto out_unlock;
1264−
1265− ret = -ETXTBSY;
1266− if (IS_SWAPFILE(inode_in) || IS_SWAPFILE(inode_out))
1267− goto out_unlock;
1268−
1269−
1270− /* Don't reflink dirs, pipes, sockets... */
1271− ret = -EISDIR;
1272− if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode))
1273− goto out_unlock;
1152+ /* Check file eligibility and prepare for block sharing. */
12741153 ret = -EINVAL;
1275− if (S_ISFIFO(inode_in->i_mode) || S_ISFIFO(inode_out->i_mode))
1276− goto out_unlock;
1277− if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode))
1278− goto out_unlock;
1279−
12801154 /* Don't reflink realtime inodes */
12811155 if (XFS_IS_REALTIME_INODE(src) || XFS_IS_REALTIME_INODE(dest))
12821156 goto out_unlock;
@@ -1285,97 +1159,18 @@ xfs_reflink_remap_range( · 2 unmodified lines
12851159 if (IS_DAX(inode_in) || IS_DAX(inode_out))
12861160 goto out_unlock;
12871161
1288− /* Are we going all the way to the end? */
1289− isize = i_size_read(inode_in);
1290− if (isize == 0) {
1291− ret = 0;
1292− goto out_unlock;
1293− }
1294−
1295− /* Zero length dedupe exits immediately; reflink goes to EOF. */
1296− if (len == 0) {
1297− if (is_dedupe) {
1298− ret = 0;
1299− goto out_unlock;
1300− }
1301− len = isize - pos_in;
1302− }
1303−
1304− /* Ensure offsets don't wrap and the input is inside i_size */
1305− if (pos_in + len < pos_in || pos_out + len < pos_out ||
1306− pos_in + len > isize)
1307− goto out_unlock;
1308−
1309− /* Don't allow dedupe past EOF in the dest file */
1310− if (is_dedupe) {
1311− loff_t disize;
1312−
1313− disize = i_size_read(inode_out);
1314− if (pos_out >= disize || pos_out + len > disize)
1315− goto out_unlock;
1316− }
1317−
1318− /* If we're linking to EOF, continue to the block boundary. */
1319− if (pos_in + len == isize)
1320− blen = ALIGN(isize, bs) - pos_in;
1321− else
1322− blen = len;
1323−
1324− /* Only reflink if we're aligned to block boundaries */
1325− if (!IS_ALIGNED(pos_in, bs) || !IS_ALIGNED(pos_in + blen, bs) ||
1326− !IS_ALIGNED(pos_out, bs) || !IS_ALIGNED(pos_out + blen, bs))
1327− goto out_unlock;
1328−
1329− /* Don't allow overlapped reflink within the same file */
1330− if (same_inode) {
1331− if (pos_out + blen > pos_in && pos_out < pos_in + blen)
1332− goto out_unlock;
1333− }
1334−
1335− /* Wait for the completion of any pending IOs on both files */
1336− inode_dio_wait(inode_in);
1337− if (!same_inode)
1338− inode_dio_wait(inode_out);
1339−
1340− ret = filemap_write_and_wait_range(inode_in->i_mapping,
1341− pos_in, pos_in + len - 1);
1342− if (ret)
1343− goto out_unlock;
1344−
1345− ret = filemap_write_and_wait_range(inode_out->i_mapping,
1346− pos_out, pos_out + len - 1);
1347− if (ret)
1162+ ret = vfs_clone_file_prep_inodes(inode_in, pos_in, inode_out, pos_out,
1163+ &len, is_dedupe);
1164+ if (ret || len == 0)
13481165 goto out_unlock;
13491166
13501167 trace_xfs_reflink_remap_range(src, pos_in, len, dest, pos_out);
13511168
1352− /*
1353− * Check that the extents are the same.
1354− */
1355− if (is_dedupe) {
1356− bool is_same = false;
1357−
1358− ret = xfs_compare_extents(inode_in, pos_in, inode_out, pos_out,
1359− len, &is_same);
1360− if (ret)
1361− goto out_unlock;
1362− if (!is_same) {
1363− ret = -EBADE;
1364− goto out_unlock;
1365− }
1366− }
1367−
1169+ /* Set flags and remap blocks. */
13681170 ret = xfs_reflink_set_inode_flag(src, dest);
13691171 if (ret)
13701172 goto out_unlock;
13711173
1372− /*
1373− * Invalidate the page cache so that we can clear any CoW mappings
1374− * in the destination file.
1375− */
1376− truncate_inode_pages_range(&inode_out->i_data, pos_out,
1377− PAGE_ALIGN(pos_out + len) - 1);
1378−
13791174 dfsbno = XFS_B_TO_FSBT(mp, pos_out);
13801175 sfsbno = XFS_B_TO_FSBT(mp, pos_in);
13811176 fsblen = XFS_B_TO_FSB(mp, len);
@@ -1384,6 +1179,10 @@ xfs_reflink_remap_range( · 2 unmodified lines
13841179 if (ret)
13851180 goto out_unlock;
13861181
1182+ /* Zap any page cache for the destination file's range. */
1183+ truncate_inode_pages_range(&inode_out->i_data, pos_out,
1184+ PAGE_ALIGN(pos_out + len) - 1);
1185+
13871186 /*
13881187 * Carry the cowextsize hint from src to dest if we're sharing the
13891188 * entire source file to the entire destination file, the source file
include/linux/audit.h+1−1
@@ -147,7 +147,7 @@ extern void audit_log_d_path(struct audit_buffer *ab, · 146 unmodified lines
147147 extern void audit_log_key(struct audit_buffer *ab,
148148 char *key);
149149 extern void audit_log_link_denied(const char *operation,
150− struct path *link);
150+ const struct path *link);
151151 extern void audit_log_lost(const char *message);
152152 #ifdef CONFIG_SECURITY
153153 extern void audit_log_secctx(struct audit_buffer *ab, u32 secid);
include/linux/dcache.h+2−2
@@ -139,7 +139,7 @@ struct dentry_operations { · 138 unmodified lines
139139 void (*d_iput)(struct dentry *, struct inode *);
140140 char *(*d_dname)(struct dentry *, char *, int);
141141 struct vfsmount *(*d_automount)(struct path *);
142− int (*d_manage)(struct dentry *, bool);
142+ int (*d_manage)(const struct path *, bool);
143143 struct dentry *(*d_real)(struct dentry *, const struct inode *,
144144 unsigned int);
145145 } ____cacheline_aligned;
@@ -254,7 +254,7 @@ extern struct dentry *d_find_alias(struct inode *); · 108 unmodified lines
254254 extern void d_prune_aliases(struct inode *);
255255
256256 /* test whether we have any submounts in a subdir tree */
257−extern int have_submounts(struct dentry *);
257+extern int path_has_submounts(const struct path *);
258258
259259 /*
260260 * This adds the entry to the hash queues.
include/linux/dcookies.h+2−2
@@ -44,7 +44,7 @@ void dcookie_unregister(struct dcookie_user * user); · 43 unmodified lines
4444 *
4545 * Returns 0 on success, with *cookie filled in
4646 */
47−int get_dcookie(struct path *path, unsigned long *cookie);
47+int get_dcookie(const struct path *path, unsigned long *cookie);
4848
4949 #else
5050
@@ -58,7 +58,7 @@ static inline void dcookie_unregister(struct dcookie_user * user) · 7 unmodified lines
5858 return;
5959 }
6060
61−static inline int get_dcookie(struct path *path, unsigned long *cookie)
61+static inline int get_dcookie(const struct path *path, unsigned long *cookie)
6262 {
6363 return -ENOSYS;
6464 }
include/linux/file.h+1−1
@@ -17,7 +17,7 @@ struct file_operations; · 16 unmodified lines
1717 struct vfsmount;
1818 struct dentry;
1919 struct path;
20−extern struct file *alloc_file(struct path *, fmode_t mode,
20+extern struct file *alloc_file(const struct path *, fmode_t mode,
2121 const struct file_operations *fop);
2222
2323 static inline void fput_light(struct file *file, int fput_needed)
include/linux/fs.h+9−3
@@ -1726,8 +1726,14 @@ extern ssize_t vfs_writev(struct file *, const struct iovec __user *, · 1725 unmodified lines
17261726 unsigned long, loff_t *, int);
17271727 extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *,
17281728 loff_t, size_t, unsigned int);
1729+extern int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in,
1730+ struct inode *inode_out, loff_t pos_out,
1731+ u64 *len, bool is_dedupe);
17291732 extern int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
17301733 struct file *file_out, loff_t pos_out, u64 len);
1734+extern int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
1735+ struct inode *dest, loff_t destoff,
1736+ loff_t len, bool *is_same);
17311737 extern int vfs_dedupe_file_range(struct file *file,
17321738 struct file_dedupe_range *same);
17331739
@@ -2084,11 +2090,11 @@ extern int may_umount_tree(struct vfsmount *); · 350 unmodified lines
20842090 extern int may_umount(struct vfsmount *);
20852091 extern long do_mount(const char *, const char __user *,
20862092 const char *, unsigned long, void *);
2087−extern struct vfsmount *collect_mounts(struct path *);
2093+extern struct vfsmount *collect_mounts(const struct path *);
20882094 extern void drop_collected_mounts(struct vfsmount *);
20892095 extern int iterate_mounts(int (*)(struct vfsmount *, void *), void *,
20902096 struct vfsmount *);
2091−extern int vfs_statfs(struct path *, struct kstatfs *);
2097+extern int vfs_statfs(const struct path *, struct kstatfs *);
20922098 extern int user_statfs(const char __user *, struct kstatfs *);
20932099 extern int fd_statfs(int, struct kstatfs *);
20942100 extern int vfs_ustat(dev_t, struct kstatfs *);
@@ -2657,7 +2663,7 @@ extern struct file * open_exec(const char *); · 562 unmodified lines
26572663
26582664 /* fs/dcache.c -- generic fs support functions */
26592665 extern bool is_subdir(struct dentry *, struct dentry *);
2660−extern bool path_is_under(struct path *, struct path *);
2666+extern bool path_is_under(const struct path *, const struct path *);
26612667
26622668 extern char *file_path(struct file *, char *, int);
26632669
include/linux/fsnotify.h+6−6
@@ -17,7 +17,7 @@ · 16 unmodified lines
1717 #include <linux/bug.h>
1818
1919 /* Notify this dentry's parent about a child's events. */
20−static inline int fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
20+static inline int fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask)
2121 {
2222 if (!dentry)
2323 dentry = path->dentry;
@@ -28,7 +28,7 @@ static inline int fsnotify_parent(struct path *path, struct dentry *dentry, __u3 · 4 unmodified lines
2828 /* simple call site for access decisions */
2929 static inline int fsnotify_perm(struct file *file, int mask)
3030 {
31− struct path *path = &file->f_path;
31+ const struct path *path = &file->f_path;
3232 /*
3333 * Do not use file_inode() here or anywhere in this file to get the
3434 * inode. That would break *notity on overlayfs.
@@ -176,7 +176,7 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) · 141 unmodified lines
176176 */
177177 static inline void fsnotify_access(struct file *file)
178178 {
179− struct path *path = &file->f_path;
179+ const struct path *path = &file->f_path;
180180 struct inode *inode = path->dentry->d_inode;
181181 __u32 mask = FS_ACCESS;
182182
@@ -194,7 +194,7 @@ static inline void fsnotify_access(struct file *file) · 11 unmodified lines
194194 */
195195 static inline void fsnotify_modify(struct file *file)
196196 {
197− struct path *path = &file->f_path;
197+ const struct path *path = &file->f_path;
198198 struct inode *inode = path->dentry->d_inode;
199199 __u32 mask = FS_MODIFY;
200200
@@ -212,7 +212,7 @@ static inline void fsnotify_modify(struct file *file) · 11 unmodified lines
212212 */
213213 static inline void fsnotify_open(struct file *file)
214214 {
215− struct path *path = &file->f_path;
215+ const struct path *path = &file->f_path;
216216 struct inode *inode = path->dentry->d_inode;
217217 __u32 mask = FS_OPEN;
218218
@@ -228,7 +228,7 @@ static inline void fsnotify_open(struct file *file) · 9 unmodified lines
228228 */
229229 static inline void fsnotify_close(struct file *file)
230230 {
231− struct path *path = &file->f_path;
231+ const struct path *path = &file->f_path;
232232 struct inode *inode = path->dentry->d_inode;
233233 fmode_t mode = file->f_mode;
234234 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
include/linux/fsnotify_backend.h+5−5
@@ -96,7 +96,7 @@ struct fsnotify_ops { · 95 unmodified lines
9696 struct inode *inode,
9797 struct fsnotify_mark *inode_mark,
9898 struct fsnotify_mark *vfsmount_mark,
99− u32 mask, void *data, int data_type,
99+ u32 mask, const void *data, int data_type,
100100 const unsigned char *file_name, u32 cookie);
101101 void (*free_group_priv)(struct fsnotify_group *group);
102102 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
@@ -245,9 +245,9 @@ struct fsnotify_mark { · 142 unmodified lines
245245 /* called from the vfs helpers */
246246
247247 /* main fsnotify call to send events */
248−extern int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
248+extern int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
249249 const unsigned char *name, u32 cookie);
250−extern int __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask);
250+extern int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask);
251251 extern void __fsnotify_inode_delete(struct inode *inode);
252252 extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt);
253253 extern u32 fsnotify_get_cookie(void);
@@ -357,13 +357,13 @@ extern void fsnotify_init_event(struct fsnotify_event *event, · 103 unmodified lines
357357
358358 #else
359359
360−static inline int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
360+static inline int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
361361 const unsigned char *name, u32 cookie)
362362 {
363363 return 0;
364364 }
365365
366−static inline int __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
366+static inline int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask)
367367 {
368368 return 0;
369369 }
include/linux/mount.h+4−2
@@ -79,12 +79,12 @@ extern void mnt_drop_write(struct vfsmount *mnt); · 78 unmodified lines
7979 extern void mnt_drop_write_file(struct file *file);
8080 extern void mntput(struct vfsmount *mnt);
8181 extern struct vfsmount *mntget(struct vfsmount *mnt);
82−extern struct vfsmount *mnt_clone_internal(struct path *path);
82+extern struct vfsmount *mnt_clone_internal(const struct path *path);
8383 extern int __mnt_is_readonly(struct vfsmount *mnt);
8484 extern bool mnt_may_suid(struct vfsmount *mnt);
8585
8686 struct path;
87−extern struct vfsmount *clone_private_mount(struct path *path);
87+extern struct vfsmount *clone_private_mount(const struct path *path);
8888
8989 struct file_system_type;
9090 extern struct vfsmount *vfs_kern_mount(struct file_system_type *type,
@@ -98,4 +98,6 @@ extern dev_t name_to_dev_t(const char *name); · 7 unmodified lines
9898
9999 extern unsigned int sysctl_mount_max;
100100
101+extern bool path_is_mountpoint(const struct path *path);
102+
101103 #endif /* _LINUX_MOUNT_H */
include/linux/quota.h+1−1
@@ -431,7 +431,7 @@ struct qc_info { · 430 unmodified lines
431431
432432 /* Operations handling requests from userspace */
433433 struct quotactl_ops {
434− int (*quota_on)(struct super_block *, int, int, struct path *);
434+ int (*quota_on)(struct super_block *, int, int, const struct path *);
435435 int (*quota_off)(struct super_block *, int);
436436 int (*quota_enable)(struct super_block *, unsigned int);
437437 int (*quota_disable)(struct super_block *, unsigned int);
include/linux/quotaops.h+1−1
@@ -90,7 +90,7 @@ int dquot_file_open(struct inode *inode, struct file *file); · 89 unmodified lines
9090 int dquot_enable(struct inode *inode, int type, int format_id,
9191 unsigned int flags);
9292 int dquot_quota_on(struct super_block *sb, int type, int format_id,
93− struct path *path);
93+ const struct path *path);
9494 int dquot_quota_on_mount(struct super_block *sb, char *qf_name,
9595 int format_id, int type);
9696 int dquot_quota_off(struct super_block *sb, int type);
kernel/audit.c+2−2
@@ -1893,7 +1893,7 @@ void audit_copy_inode(struct audit_names *name, const struct dentry *dentry, · 1892 unmodified lines
18931893 * @call_panic: optional pointer to int that will be updated if secid fails
18941894 */
18951895 void audit_log_name(struct audit_context *context, struct audit_names *n,
1896− struct path *path, int record_num, int *call_panic)
1896+ const struct path *path, int record_num, int *call_panic)
18971897 {
18981898 struct audit_buffer *ab;
18991899 ab = audit_log_start(context, GFP_KERNEL, AUDIT_PATH);
@@ -2081,7 +2081,7 @@ EXPORT_SYMBOL(audit_log_task_info); · 181 unmodified lines
20812081 * @operation: specific link operation
20822082 * @link: the path that triggered the restriction
20832083 */
2084−void audit_log_link_denied(const char *operation, struct path *link)
2084+void audit_log_link_denied(const char *operation, const struct path *link)
20852085 {
20862086 struct audit_buffer *ab;
20872087 struct audit_names *name;
kernel/audit.h+1−1
@@ -212,7 +212,7 @@ extern void audit_copy_inode(struct audit_names *name, · 211 unmodified lines
212212 extern void audit_log_cap(struct audit_buffer *ab, char *prefix,
213213 kernel_cap_t *cap);
214214 extern void audit_log_name(struct audit_context *context,
215− struct audit_names *n, struct path *path,
215+ struct audit_names *n, const struct path *path,
216216 int record_num, int *call_panic);
217217
218218 extern int audit_pid;
kernel/audit_fsnotify.c+5−5
@@ -74,7 +74,7 @@ int audit_mark_compare(struct audit_fsnotify_mark *mark, unsigned long ino, dev_ · 73 unmodified lines
7474 }
7575
7676 static void audit_update_mark(struct audit_fsnotify_mark *audit_mark,
77− struct inode *inode)
77+ const struct inode *inode)
7878 {
7979 audit_mark->dev = inode ? inode->i_sb->s_dev : AUDIT_DEV_UNSET;
8080 audit_mark->ino = inode ? inode->i_ino : AUDIT_INO_UNSET;
@@ -167,11 +167,11 @@ static int audit_mark_handle_event(struct fsnotify_group *group, · 86 unmodified lines
167167 struct inode *to_tell,
168168 struct fsnotify_mark *inode_mark,
169169 struct fsnotify_mark *vfsmount_mark,
170− u32 mask, void *data, int data_type,
170+ u32 mask, const void *data, int data_type,
171171 const unsigned char *dname, u32 cookie)
172172 {
173173 struct audit_fsnotify_mark *audit_mark;
174− struct inode *inode = NULL;
174+ const struct inode *inode = NULL;
175175
176176 audit_mark = container_of(inode_mark, struct audit_fsnotify_mark, mark);
177177
@@ -179,10 +179,10 @@ static int audit_mark_handle_event(struct fsnotify_group *group, · 1 unmodified line
179179
180180 switch (data_type) {
181181 case (FSNOTIFY_EVENT_PATH):
182− inode = ((struct path *)data)->dentry->d_inode;
182+ inode = ((const struct path *)data)->dentry->d_inode;
183183 break;
184184 case (FSNOTIFY_EVENT_INODE):
185− inode = (struct inode *)data;
185+ inode = (const struct inode *)data;
186186 break;
187187 default:
188188 BUG();
kernel/audit_tree.c+1−1
@@ -947,7 +947,7 @@ static int audit_tree_handle_event(struct fsnotify_group *group, · 946 unmodified lines
947947 struct inode *to_tell,
948948 struct fsnotify_mark *inode_mark,
949949 struct fsnotify_mark *vfsmount_mark,
950− u32 mask, void *data, int data_type,
950+ u32 mask, const void *data, int data_type,
951951 const unsigned char *file_name, u32 cookie)
952952 {
953953 return 0;
kernel/audit_watch.c+4−4
@@ -471,10 +471,10 @@ static int audit_watch_handle_event(struct fsnotify_group *group, · 470 unmodified lines
471471 struct inode *to_tell,
472472 struct fsnotify_mark *inode_mark,
473473 struct fsnotify_mark *vfsmount_mark,
474− u32 mask, void *data, int data_type,
474+ u32 mask, const void *data, int data_type,
475475 const unsigned char *dname, u32 cookie)
476476 {
477− struct inode *inode;
477+ const struct inode *inode;
478478 struct audit_parent *parent;
479479
480480 parent = container_of(inode_mark, struct audit_parent, mark);
@@ -483,10 +483,10 @@ static int audit_watch_handle_event(struct fsnotify_group *group, · 2 unmodified lines
483483
484484 switch (data_type) {
485485 case (FSNOTIFY_EVENT_PATH):
486− inode = d_backing_inode(((struct path *)data)->dentry);
486+ inode = d_backing_inode(((const struct path *)data)->dentry);
487487 break;
488488 case (FSNOTIFY_EVENT_INODE):
489− inode = (struct inode *)data;
489+ inode = (const struct inode *)data;
490490 break;
491491 default:
492492 BUG();

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t