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 ...
Unified · Split
| @@ -20,7 +20,7 @@ prototypes: · 19 unmodified lines | ||
| 20 | 20 | void (*d_iput)(struct dentry *, struct inode *); |
| 21 | 21 | char *(*d_dname)((struct dentry *dentry, char *buffer, int buflen); |
| 22 | 22 | struct vfsmount *(*d_automount)(struct path *path); |
| 23 | − int (*d_manage)(struct dentry *, bool); | |
| 23 | + int (*d_manage)(const struct path *, bool); | |
| 24 | 24 | struct dentry *(*d_real)(struct dentry *, const struct inode *, |
| 25 | 25 | unsigned int); |
| 26 | 26 | |
| @@ -948,7 +948,7 @@ struct dentry_operations { · 947 unmodified lines | ||
| 948 | 948 | void (*d_iput)(struct dentry *, struct inode *); |
| 949 | 949 | char *(*d_dname)(struct dentry *, char *, int); |
| 950 | 950 | struct vfsmount *(*d_automount)(struct path *); |
| 951 | − int (*d_manage)(struct dentry *, bool); | |
| 951 | + int (*d_manage)(const struct path *, bool); | |
| 952 | 952 | struct dentry *(*d_real)(struct dentry *, const struct inode *, |
| 953 | 953 | unsigned int); |
| 954 | 954 | }; |
| @@ -295,7 +295,7 @@ out: · 294 unmodified lines | ||
| 295 | 295 | * dcookie user still being registered (namely, the reader |
| 296 | 296 | * of the event buffer). |
| 297 | 297 | */ |
| 298 | −static inline unsigned long fast_get_dcookie(struct path *path) | |
| 298 | +static inline unsigned long fast_get_dcookie(const struct path *path) | |
| 299 | 299 | { |
| 300 | 300 | unsigned long cookie; |
| 301 | 301 | |
| @@ -206,7 +206,7 @@ void sync_stop(void) · 205 unmodified lines | ||
| 206 | 206 | * because we cannot reach this code without at least one |
| 207 | 207 | * dcookie user still being registered (namely, the reader |
| 208 | 208 | * 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) | |
| 210 | 210 | { |
| 211 | 211 | unsigned long cookie; |
| 212 | 212 | |
| @@ -310,18 +310,10 @@ static int v9fs_write_end(struct file *filp, struct address_space *mapping, · 309 unmodified lines | ||
| 310 | 310 | |
| 311 | 311 | p9_debug(P9_DEBUG_VFS, "filp %p, mapping %p\n", filp, mapping); |
| 312 | 312 | |
| 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; | |
| 321 | 316 | } |
| 322 | − | |
| 323 | − if (!PageUptodate(page)) | |
| 324 | − SetPageUptodate(page); | |
| 325 | 317 | /* |
| 326 | 318 | * No need to use i_size_read() here, the i_size |
| 327 | 319 | * 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 | ||
| 331 | 323 | i_size_write(inode, last_pos); |
| 332 | 324 | } |
| 333 | 325 | set_page_dirty(page); |
| 326 | +out: | |
| 334 | 327 | unlock_page(page); |
| 335 | 328 | put_page(page); |
| 336 | 329 | |
| @@ -145,7 +145,7 @@ void autofs4_free_ino(struct autofs_info *); · 144 unmodified lines | ||
| 145 | 145 | |
| 146 | 146 | /* Expiration */ |
| 147 | 147 | 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); | |
| 149 | 149 | int autofs4_expire_run(struct super_block *, struct vfsmount *, |
| 150 | 150 | struct autofs_sb_info *, |
| 151 | 151 | struct autofs_packet_expire __user *); |
| @@ -217,7 +217,8 @@ static inline int autofs_prepare_pipe(struct file *pipe) · 65 unmodified lines | ||
| 217 | 217 | |
| 218 | 218 | /* Queue management functions */ |
| 219 | 219 | |
| 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); | |
| 221 | 222 | int autofs4_wait_release(struct autofs_sb_info *, autofs_wqt_t, int); |
| 222 | 223 | void autofs4_catatonic_mode(struct autofs_sb_info *); |
| 223 | 224 | |
| @@ -204,7 +204,7 @@ static int autofs_dev_ioctl_protosubver(struct file *fp, · 203 unmodified lines | ||
| 204 | 204 | /* Find the topmost mount satisfying test() */ |
| 205 | 205 | static int find_autofs_mount(const char *pathname, |
| 206 | 206 | struct path *res, |
| 207 | − int test(struct path *path, void *data), | |
| 207 | + int test(const struct path *path, void *data), | |
| 208 | 208 | void *data) |
| 209 | 209 | { |
| 210 | 210 | struct path path; |
| @@ -230,12 +230,12 @@ static int find_autofs_mount(const char *pathname, · 19 unmodified lines | ||
| 230 | 230 | return err; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | −static int test_by_dev(struct path *path, void *p) | |
| 233 | +static int test_by_dev(const struct path *path, void *p) | |
| 234 | 234 | { |
| 235 | 235 | return path->dentry->d_sb->s_dev == *(dev_t *)p; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | −static int test_by_type(struct path *path, void *p) | |
| 238 | +static int test_by_type(const struct path *path, void *p) | |
| 239 | 239 | { |
| 240 | 240 | struct autofs_info *ino = autofs4_dentry_ino(path->dentry); |
| 241 | 241 | |
| @@ -468,7 +468,7 @@ static int autofs_dev_ioctl_requester(struct file *fp, · 226 unmodified lines | ||
| 468 | 468 | ino = autofs4_dentry_ino(path.dentry); |
| 469 | 469 | if (ino) { |
| 470 | 470 | err = 0; |
| 471 | − autofs4_expire_wait(path.dentry, 0); | |
| 471 | + autofs4_expire_wait(&path, 0); | |
| 472 | 472 | spin_lock(&sbi->fs_lock); |
| 473 | 473 | param->requester.uid = |
| 474 | 474 | from_kuid_munged(current_user_ns(), ino->uid); |
| @@ -575,7 +575,7 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp, · 100 unmodified lines | ||
| 575 | 575 | |
| 576 | 576 | devid = new_encode_dev(dev); |
| 577 | 577 | |
| 578 | − err = have_submounts(path.dentry); | |
| 578 | + err = path_has_submounts(&path); | |
| 579 | 579 | |
| 580 | 580 | if (follow_down_one(&path)) |
| 581 | 581 | magic = path.dentry->d_sb->s_magic; |
| @@ -310,26 +310,29 @@ struct dentry *autofs4_expire_direct(struct super_block *sb, · 309 unmodified lines | ||
| 310 | 310 | now = jiffies; |
| 311 | 311 | timeout = sbi->exp_timeout; |
| 312 | 312 | |
| 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; | |
| 318 | 313 | 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 | + } | |
| 319 | 321 | ino->flags |= AUTOFS_INF_WANT_EXPIRE; |
| 320 | 322 | spin_unlock(&sbi->fs_lock); |
| 321 | 323 | synchronize_rcu(); |
| 322 | − spin_lock(&sbi->fs_lock); | |
| 323 | 324 | if (!autofs4_direct_busy(mnt, root, timeout, do_now)) { |
| 325 | + spin_lock(&sbi->fs_lock); | |
| 324 | 326 | ino->flags |= AUTOFS_INF_EXPIRING; |
| 325 | 327 | init_completion(&ino->expire_complete); |
| 326 | 328 | spin_unlock(&sbi->fs_lock); |
| 327 | 329 | return root; |
| 328 | 330 | } |
| 331 | + spin_lock(&sbi->fs_lock); | |
| 329 | 332 | ino->flags &= ~AUTOFS_INF_WANT_EXPIRE; |
| 333 | + spin_unlock(&sbi->fs_lock); | |
| 330 | 334 | } |
| 331 | 335 | out: |
| 332 | − spin_unlock(&sbi->fs_lock); | |
| 333 | 336 | dput(root); |
| 334 | 337 | |
| 335 | 338 | return NULL; |
| @@ -495,8 +498,9 @@ found: · 159 unmodified lines | ||
| 495 | 498 | return expired; |
| 496 | 499 | } |
| 497 | 500 | |
| 498 | −int autofs4_expire_wait(struct dentry *dentry, int rcu_walk) | |
| 501 | +int autofs4_expire_wait(const struct path *path, int rcu_walk) | |
| 499 | 502 | { |
| 503 | + struct dentry *dentry = path->dentry; | |
| 500 | 504 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
| 501 | 505 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
| 502 | 506 | int status; |
| @@ -525,7 +529,7 @@ retry: · 22 unmodified lines | ||
| 525 | 529 | |
| 526 | 530 | pr_debug("waiting for expire %p name=%pd\n", dentry, dentry); |
| 527 | 531 | |
| 528 | − status = autofs4_wait(sbi, dentry, NFY_NONE); | |
| 532 | + status = autofs4_wait(sbi, path, NFY_NONE); | |
| 529 | 533 | wait_for_completion(&ino->expire_complete); |
| 530 | 534 | |
| 531 | 535 | 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 | ||
| 592 | 596 | |
| 593 | 597 | if (dentry) { |
| 594 | 598 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
| 599 | + const struct path path = { .mnt = mnt, .dentry = dentry }; | |
| 595 | 600 | |
| 596 | 601 | /* This is synchronous because it makes the daemon a |
| 597 | 602 | * little easier |
| 598 | 603 | */ |
| 599 | − ret = autofs4_wait(sbi, dentry, NFY_EXPIRE); | |
| 604 | + ret = autofs4_wait(sbi, &path, NFY_EXPIRE); | |
| 600 | 605 | |
| 601 | 606 | spin_lock(&sbi->fs_lock); |
| 602 | 607 | /* avoid rapid-fire expire attempts if expiry fails */ |
| @@ -32,7 +32,7 @@ static int autofs4_dir_open(struct inode *inode, struct file *file); · 31 unmodified lines | ||
| 32 | 32 | static struct dentry *autofs4_lookup(struct inode *, |
| 33 | 33 | struct dentry *, unsigned int); |
| 34 | 34 | 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); | |
| 36 | 36 | static void autofs4_dentry_release(struct dentry *); |
| 37 | 37 | |
| 38 | 38 | 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 | ||
| 123 | 123 | * it. |
| 124 | 124 | */ |
| 125 | 125 | spin_lock(&sbi->lookup_lock); |
| 126 | − if (!d_mountpoint(dentry) && simple_empty(dentry)) { | |
| 126 | + if (!path_is_mountpoint(&file->f_path) && simple_empty(dentry)) { | |
| 127 | 127 | spin_unlock(&sbi->lookup_lock); |
| 128 | 128 | return -ENOENT; |
| 129 | 129 | } |
| @@ -269,39 +269,41 @@ next: · 139 unmodified lines | ||
| 269 | 269 | return NULL; |
| 270 | 270 | } |
| 271 | 271 | |
| 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) | |
| 273 | 273 | { |
| 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); | |
| 276 | 276 | int status = 0; |
| 277 | 277 | |
| 278 | 278 | if (ino->flags & AUTOFS_INF_PENDING) { |
| 279 | 279 | if (rcu_walk) |
| 280 | 280 | 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); | |
| 283 | 283 | pr_debug("mount wait done status=%d\n", status); |
| 284 | 284 | } |
| 285 | 285 | ino->last_used = jiffies; |
| 286 | 286 | return status; |
| 287 | 287 | } |
| 288 | 288 | |
| 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) | |
| 290 | 290 | { |
| 291 | + struct dentry *dentry = path->dentry; | |
| 291 | 292 | struct dentry *expiring; |
| 292 | 293 | |
| 293 | 294 | expiring = autofs4_lookup_expiring(dentry, rcu_walk); |
| 294 | 295 | if (IS_ERR(expiring)) |
| 295 | 296 | return PTR_ERR(expiring); |
| 296 | 297 | if (!expiring) |
| 297 | − return autofs4_expire_wait(dentry, rcu_walk); | |
| 298 | + return autofs4_expire_wait(path, rcu_walk); | |
| 298 | 299 | else { |
| 300 | + const struct path this = { .mnt = path->mnt, .dentry = expiring }; | |
| 299 | 301 | /* |
| 300 | 302 | * If we are racing with expire the request might not |
| 301 | 303 | * be quite complete, but the directory has been removed |
| 302 | 304 | * so it must have been successful, just wait for it. |
| 303 | 305 | */ |
| 304 | − autofs4_expire_wait(expiring, 0); | |
| 306 | + autofs4_expire_wait(&this, 0); | |
| 305 | 307 | autofs4_del_expiring(expiring); |
| 306 | 308 | dput(expiring); |
| 307 | 309 | } |
| @@ -354,7 +356,7 @@ static struct vfsmount *autofs4_d_automount(struct path *path) · 46 unmodified lines | ||
| 354 | 356 | * and the directory was removed, so just go ahead and try |
| 355 | 357 | * the mount. |
| 356 | 358 | */ |
| 357 | − status = do_expire_wait(dentry, 0); | |
| 359 | + status = do_expire_wait(path, 0); | |
| 358 | 360 | if (status && status != -EAGAIN) |
| 359 | 361 | return NULL; |
| 360 | 362 | |
| @@ -362,7 +364,7 @@ static struct vfsmount *autofs4_d_automount(struct path *path) · 1 unmodified line | ||
| 362 | 364 | spin_lock(&sbi->fs_lock); |
| 363 | 365 | if (ino->flags & AUTOFS_INF_PENDING) { |
| 364 | 366 | spin_unlock(&sbi->fs_lock); |
| 365 | − status = autofs4_mount_wait(dentry, 0); | |
| 367 | + status = autofs4_mount_wait(path, 0); | |
| 366 | 368 | if (status) |
| 367 | 369 | return ERR_PTR(status); |
| 368 | 370 | goto done; |
| @@ -370,28 +372,28 @@ static struct vfsmount *autofs4_d_automount(struct path *path) · 1 unmodified line | ||
| 370 | 372 | |
| 371 | 373 | /* |
| 372 | 374 | * 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. | |
| 375 | 377 | */ |
| 376 | 378 | if (d_really_is_positive(dentry) && d_is_symlink(dentry)) { |
| 377 | 379 | spin_unlock(&sbi->fs_lock); |
| 378 | 380 | goto done; |
| 379 | 381 | } |
| 380 | 382 | |
| 381 | − if (!d_mountpoint(dentry)) { | |
| 383 | + if (!path_is_mountpoint(path)) { | |
| 382 | 384 | /* |
| 383 | 385 | * It's possible that user space hasn't removed directories |
| 384 | 386 | * 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 | |
| 391 | 393 | * require user space behave. |
| 392 | 394 | */ |
| 393 | 395 | if (sbi->version > 4) { |
| 394 | − if (have_submounts(dentry)) { | |
| 396 | + if (path_has_submounts(path)) { | |
| 395 | 397 | spin_unlock(&sbi->fs_lock); |
| 396 | 398 | goto done; |
| 397 | 399 | } |
| @@ -403,7 +405,7 @@ static struct vfsmount *autofs4_d_automount(struct path *path) · 5 unmodified lines | ||
| 403 | 405 | } |
| 404 | 406 | ino->flags |= AUTOFS_INF_PENDING; |
| 405 | 407 | spin_unlock(&sbi->fs_lock); |
| 406 | − status = autofs4_mount_wait(dentry, 0); | |
| 408 | + status = autofs4_mount_wait(path, 0); | |
| 407 | 409 | spin_lock(&sbi->fs_lock); |
| 408 | 410 | ino->flags &= ~AUTOFS_INF_PENDING; |
| 409 | 411 | if (status) { |
| @@ -421,8 +423,9 @@ done: · 11 unmodified lines | ||
| 421 | 423 | return NULL; |
| 422 | 424 | } |
| 423 | 425 | |
| 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) | |
| 425 | 427 | { |
| 428 | + struct dentry *dentry = path->dentry; | |
| 426 | 429 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
| 427 | 430 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
| 428 | 431 | int status; |
| @@ -431,20 +434,20 @@ static int autofs4_d_manage(struct dentry *dentry, bool rcu_walk) · 2 unmodified lines | ||
| 431 | 434 | |
| 432 | 435 | /* The daemon never waits. */ |
| 433 | 436 | if (autofs4_oz_mode(sbi)) { |
| 434 | − if (!d_mountpoint(dentry)) | |
| 437 | + if (!path_is_mountpoint(path)) | |
| 435 | 438 | return -EISDIR; |
| 436 | 439 | return 0; |
| 437 | 440 | } |
| 438 | 441 | |
| 439 | 442 | /* Wait for pending expires */ |
| 440 | − if (do_expire_wait(dentry, rcu_walk) == -ECHILD) | |
| 443 | + if (do_expire_wait(path, rcu_walk) == -ECHILD) | |
| 441 | 444 | return -ECHILD; |
| 442 | 445 | |
| 443 | 446 | /* |
| 444 | 447 | * This dentry may be under construction so wait on mount |
| 445 | 448 | * completion. |
| 446 | 449 | */ |
| 447 | − status = autofs4_mount_wait(dentry, rcu_walk); | |
| 450 | + status = autofs4_mount_wait(path, rcu_walk); | |
| 448 | 451 | if (status) |
| 449 | 452 | return status; |
| 450 | 453 | |
| @@ -460,7 +463,7 @@ static int autofs4_d_manage(struct dentry *dentry, bool rcu_walk) · 9 unmodified lines | ||
| 460 | 463 | |
| 461 | 464 | if (ino->flags & AUTOFS_INF_WANT_EXPIRE) |
| 462 | 465 | return 0; |
| 463 | − if (d_mountpoint(dentry)) | |
| 466 | + if (path_is_mountpoint(path)) | |
| 464 | 467 | return 0; |
| 465 | 468 | inode = d_inode_rcu(dentry); |
| 466 | 469 | 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 | ||
| 487 | 490 | * we can avoid needless calls ->d_automount() and avoid |
| 488 | 491 | * an incorrect ELOOP error return. |
| 489 | 492 | */ |
| 490 | − if ((!d_mountpoint(dentry) && !simple_empty(dentry)) || | |
| 493 | + if ((!path_is_mountpoint(path) && !simple_empty(dentry)) || | |
| 491 | 494 | (d_really_is_positive(dentry) && d_is_symlink(dentry))) |
| 492 | 495 | status = -EISDIR; |
| 493 | 496 | } |
| @@ -250,8 +250,9 @@ autofs4_find_wait(struct autofs_sb_info *sbi, const struct qstr *qstr) · 249 unmodified lines | ||
| 250 | 250 | static int validate_request(struct autofs_wait_queue **wait, |
| 251 | 251 | struct autofs_sb_info *sbi, |
| 252 | 252 | const struct qstr *qstr, |
| 253 | − struct dentry *dentry, enum autofs_notify notify) | |
| 253 | + const struct path *path, enum autofs_notify notify) | |
| 254 | 254 | { |
| 255 | + struct dentry *dentry = path->dentry; | |
| 255 | 256 | struct autofs_wait_queue *wq; |
| 256 | 257 | struct autofs_info *ino; |
| 257 | 258 | |
| @@ -314,6 +315,7 @@ static int validate_request(struct autofs_wait_queue **wait, · 56 unmodified lines | ||
| 314 | 315 | */ |
| 315 | 316 | if (notify == NFY_MOUNT) { |
| 316 | 317 | struct dentry *new = NULL; |
| 318 | + struct path this; | |
| 317 | 319 | int valid = 1; |
| 318 | 320 | |
| 319 | 321 | /* |
| @@ -333,7 +335,9 @@ static int validate_request(struct autofs_wait_queue **wait, · 13 unmodified lines | ||
| 333 | 335 | dentry = new; |
| 334 | 336 | } |
| 335 | 337 | } |
| 336 | − if (have_submounts(dentry)) | |
| 338 | + this.mnt = path->mnt; | |
| 339 | + this.dentry = dentry; | |
| 340 | + if (path_has_submounts(&this)) | |
| 337 | 341 | valid = 0; |
| 338 | 342 | |
| 339 | 343 | if (new) |
| @@ -345,8 +349,9 @@ static int validate_request(struct autofs_wait_queue **wait, · 5 unmodified lines | ||
| 345 | 349 | } |
| 346 | 350 | |
| 347 | 351 | 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) | |
| 349 | 353 | { |
| 354 | + struct dentry *dentry = path->dentry; | |
| 350 | 355 | struct autofs_wait_queue *wq; |
| 351 | 356 | struct qstr qstr; |
| 352 | 357 | char *name; |
| @@ -405,7 +410,7 @@ int autofs4_wait(struct autofs_sb_info *sbi, · 52 unmodified lines | ||
| 405 | 410 | return -EINTR; |
| 406 | 411 | } |
| 407 | 412 | |
| 408 | − ret = validate_request(&wq, sbi, &qstr, dentry, notify); | |
| 413 | + ret = validate_request(&wq, sbi, &qstr, path, notify); | |
| 409 | 414 | if (ret <= 0) { |
| 410 | 415 | if (ret != -EINTR) |
| 411 | 416 | mutex_unlock(&sbi->wq_mutex); |
| @@ -3232,9 +3232,6 @@ int btrfs_dirty_pages(struct inode *inode, struct page **pages, · 3231 unmodified lines | ||
| 3232 | 3232 | size_t num_pages, loff_t pos, size_t write_bytes, |
| 3233 | 3233 | struct extent_state **cached); |
| 3234 | 3234 | 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); | |
| 3238 | 3235 | int btrfs_clone_file_range(struct file *file_in, loff_t pos_in, |
| 3239 | 3236 | struct file *file_out, loff_t pos_out, u64 len); |
| 3240 | 3237 | |
| @@ -3033,7 +3033,6 @@ const struct file_operations btrfs_file_operations = { · 3032 unmodified lines | ||
| 3033 | 3033 | #ifdef CONFIG_COMPAT |
| 3034 | 3034 | .compat_ioctl = btrfs_compat_ioctl, |
| 3035 | 3035 | #endif |
| 3036 | − .copy_file_range = btrfs_copy_file_range, | |
| 3037 | 3036 | .clone_file_range = btrfs_clone_file_range, |
| 3038 | 3037 | .dedupe_file_range = btrfs_dedupe_file_range, |
| 3039 | 3038 | }; |
| @@ -834,7 +834,7 @@ static inline int btrfs_may_create(struct inode *dir, struct dentry *child) · 833 unmodified lines | ||
| 834 | 834 | * sys_mkdirat and vfs_mkdir, but we only do a single component lookup |
| 835 | 835 | * inside this filesystem so it's quite a bit simpler. |
| 836 | 836 | */ |
| 837 | −static noinline int btrfs_mksubvol(struct path *parent, | |
| 837 | +static noinline int btrfs_mksubvol(const struct path *parent, | |
| 838 | 838 | char *name, int namelen, |
| 839 | 839 | struct btrfs_root *snap_src, |
| 840 | 840 | u64 *async_transid, bool readonly, |
| @@ -3987,18 +3987,6 @@ out_unlock: · 3146 unmodified lines | ||
| 3987 | 3987 | return ret; |
| 3988 | 3988 | } |
| 3989 | 3989 | |
| 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 | − | |
| 4002 | 3990 | int btrfs_clone_file_range(struct file *src_file, loff_t off, |
| 4003 | 3991 | struct file *dst_file, loff_t destoff, u64 len) |
| 4004 | 3992 | { |
| @@ -1317,25 +1317,27 @@ static int ceph_write_end(struct file *file, struct address_space *mapping, · 1316 unmodified lines | ||
| 1317 | 1317 | struct page *page, void *fsdata) |
| 1318 | 1318 | { |
| 1319 | 1319 | struct inode *inode = file_inode(file); |
| 1320 | − unsigned from = pos & (PAGE_SIZE - 1); | |
| 1321 | 1320 | int check_cap = 0; |
| 1322 | 1321 | |
| 1323 | 1322 | dout("write_end file %p inode %p page %p %d~%d (%d)\n", file, |
| 1324 | 1323 | inode, page, (int)pos, (int)copied, (int)len); |
| 1325 | 1324 | |
| 1326 | 1325 | /* 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 | + } | |
| 1329 | 1333 | |
| 1330 | 1334 | /* did file size increase? */ |
| 1331 | 1335 | if (pos+copied > i_size_read(inode)) |
| 1332 | 1336 | check_cap = ceph_inode_set_size(inode, pos+copied); |
| 1333 | 1337 | |
| 1334 | − if (!PageUptodate(page)) | |
| 1335 | − SetPageUptodate(page); | |
| 1336 | − | |
| 1337 | 1338 | set_page_dirty(page); |
| 1338 | 1339 | |
| 1340 | +out: | |
| 1339 | 1341 | unlock_page(page); |
| 1340 | 1342 | put_page(page); |
| 1341 | 1343 | |
| @@ -1273,38 +1273,44 @@ rename_retry: · 1272 unmodified lines | ||
| 1273 | 1273 | goto again; |
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 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 | +}; | |
| 1281 | 1280 | |
| 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) | |
| 1283 | 1282 | { |
| 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; | |
| 1287 | 1290 | return D_WALK_QUIT; |
| 1288 | 1291 | } |
| 1289 | 1292 | return D_WALK_CONTINUE; |
| 1290 | 1293 | } |
| 1291 | 1294 | |
| 1292 | 1295 | /** |
| 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. | |
| 1295 | 1299 | * |
| 1296 | 1300 | * Return true if the parent or its subdirectories contain |
| 1297 | − * a mount point | |
| 1301 | + * a mount point in the current namespace. | |
| 1298 | 1302 | */ |
| 1299 | −int have_submounts(struct dentry *parent) | |
| 1303 | +int path_has_submounts(const struct path *parent) | |
| 1300 | 1304 | { |
| 1301 | − int ret = 0; | |
| 1305 | + struct check_mount data = { .mnt = parent->mnt, .mounted = 0 }; | |
| 1302 | 1306 | |
| 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); | |
| 1304 | 1310 | |
| 1305 | − return ret; | |
| 1311 | + return data.mounted; | |
| 1306 | 1312 | } |
| 1307 | −EXPORT_SYMBOL(have_submounts); | |
| 1313 | +EXPORT_SYMBOL(path_has_submounts); | |
| 1308 | 1314 | |
| 1309 | 1315 | /* |
| 1310 | 1316 | * Called by mount code to set a mountpoint and check if the mountpoint is |
| @@ -90,7 +90,7 @@ static void hash_dcookie(struct dcookie_struct * dcs) · 89 unmodified lines | ||
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
| 93 | −static struct dcookie_struct *alloc_dcookie(struct path *path) | |
| 93 | +static struct dcookie_struct *alloc_dcookie(const struct path *path) | |
| 94 | 94 | { |
| 95 | 95 | struct dcookie_struct *dcs = kmem_cache_alloc(dcookie_cache, |
| 96 | 96 | GFP_KERNEL); |
| @@ -113,7 +113,7 @@ static struct dcookie_struct *alloc_dcookie(struct path *path) · 16 unmodified lines | ||
| 113 | 113 | /* This is the main kernel-side routine that retrieves the cookie |
| 114 | 114 | * value for a dentry/vfsmnt pair. |
| 115 | 115 | */ |
| 116 | −int get_dcookie(struct path *path, unsigned long *cookie) | |
| 116 | +int get_dcookie(const struct path *path, unsigned long *cookie) | |
| 117 | 117 | { |
| 118 | 118 | int err = 0; |
| 119 | 119 | struct dcookie_struct * dcs; |
| @@ -870,46 +870,31 @@ int exofs_write_begin(struct file *file, struct address_space *mapping, · 869 unmodified lines | ||
| 870 | 870 | |
| 871 | 871 | page = *pagep; |
| 872 | 872 | 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; | |
| 878 | 878 | } |
| 879 | − | |
| 880 | − page = *pagep; | |
| 879 | + *pagep = page; | |
| 881 | 880 | } |
| 882 | 881 | |
| 883 | 882 | /* read modify write */ |
| 884 | 883 | if (!PageUptodate(page) && (len != PAGE_SIZE)) { |
| 885 | 884 | loff_t i_size = i_size_read(mapping->host); |
| 886 | 885 | pgoff_t end_index = i_size >> PAGE_SHIFT; |
| 887 | − size_t rlen; | |
| 888 | 886 | |
| 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) { | |
| 897 | 888 | clear_highpage(page); |
| 898 | 889 | 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 | + } | |
| 907 | 896 | } |
| 908 | 897 | } |
| 909 | −out: | |
| 910 | − if (unlikely(ret)) | |
| 911 | − _write_failed(mapping->host, pos + len); | |
| 912 | − | |
| 913 | 898 | return ret; |
| 914 | 899 | } |
| 915 | 900 | |
| @@ -929,18 +914,25 @@ static int exofs_write_end(struct file *file, struct address_space *mapping, · 13 unmodified lines | ||
| 929 | 914 | struct page *page, void *fsdata) |
| 930 | 915 | { |
| 931 | 916 | 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; | |
| 939 | 918 | |
| 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); | |
| 942 | 929 | 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; | |
| 944 | 936 | } |
| 945 | 937 | |
| 946 | 938 | static int exofs_releasepage(struct page *page, gfp_t gfp) |
| @@ -1205,7 +1205,7 @@ static int ext4_release_dquot(struct dquot *dquot); · 1204 unmodified lines | ||
| 1205 | 1205 | static int ext4_mark_dquot_dirty(struct dquot *dquot); |
| 1206 | 1206 | static int ext4_write_info(struct super_block *sb, int type); |
| 1207 | 1207 | static int ext4_quota_on(struct super_block *sb, int type, int format_id, |
| 1208 | − struct path *path); | |
| 1208 | + const struct path *path); | |
| 1209 | 1209 | static int ext4_quota_off(struct super_block *sb, int type); |
| 1210 | 1210 | static int ext4_quota_on_mount(struct super_block *sb, int type); |
| 1211 | 1211 | 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 | ||
| 5293 | 5293 | * Standard function to be called on quota_on |
| 5294 | 5294 | */ |
| 5295 | 5295 | static int ext4_quota_on(struct super_block *sb, int type, int format_id, |
| 5296 | − struct path *path) | |
| 5296 | + const struct path *path) | |
| 5297 | 5297 | { |
| 5298 | 5298 | int err; |
| 5299 | 5299 | |
| @@ -155,7 +155,7 @@ over: · 154 unmodified lines | ||
| 155 | 155 | * @mode: the mode with which the new file will be opened |
| 156 | 156 | * @fop: the 'struct file_operations' for the new file |
| 157 | 157 | */ |
| 158 | −struct file *alloc_file(struct path *path, fmode_t mode, | |
| 158 | +struct file *alloc_file(const struct path *path, fmode_t mode, | |
| 159 | 159 | const struct file_operations *fop) |
| 160 | 160 | { |
| 161 | 161 | struct file *file; |
| @@ -839,12 +839,10 @@ static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh, · 838 unmodified lines | ||
| 839 | 839 | BUG_ON((pos + len) > (dibh->b_size - sizeof(struct gfs2_dinode))); |
| 840 | 840 | kaddr = kmap_atomic(page); |
| 841 | 841 | memcpy(buf + pos, kaddr + pos, copied); |
| 842 | − memset(kaddr + pos + copied, 0, len - copied); | |
| 843 | 842 | flush_dcache_page(page); |
| 844 | 843 | kunmap_atomic(kaddr); |
| 845 | 844 | |
| 846 | − if (!PageUptodate(page)) | |
| 847 | − SetPageUptodate(page); | |
| 845 | + WARN_ON(!PageUptodate(page)); | |
| 848 | 846 | unlock_page(page); |
| 849 | 847 | put_page(page); |
| 850 | 848 | |
| @@ -62,7 +62,7 @@ extern int vfs_path_lookup(struct dentry *, struct vfsmount *, · 61 unmodified lines | ||
| 62 | 62 | extern void *copy_mount_options(const void __user *); |
| 63 | 63 | extern char *copy_mount_string(const void __user *); |
| 64 | 64 | |
| 65 | −extern struct vfsmount *lookup_mnt(struct path *); | |
| 65 | +extern struct vfsmount *lookup_mnt(const struct path *); | |
| 66 | 66 | extern int finish_automount(struct vfsmount *, struct path *); |
| 67 | 67 | |
| 68 | 68 | extern int sb_prepare_remount_readonly(struct super_block *); |
| @@ -465,6 +465,8 @@ EXPORT_SYMBOL(simple_write_begin); · 464 unmodified lines | ||
| 465 | 465 | * is not called, so a filesystem that actually does store data in .write_inode |
| 466 | 466 | * should extend on what's done here with a call to mark_inode_dirty() in the |
| 467 | 467 | * case that i_size has changed. |
| 468 | + * | |
| 469 | + * Use *ONLY* with simple_readpage() | |
| 468 | 470 | */ |
| 469 | 471 | int simple_write_end(struct file *file, struct address_space *mapping, |
| 470 | 472 | 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 | ||
| 474 | 476 | loff_t last_pos = pos + copied; |
| 475 | 477 | |
| 476 | 478 | /* 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); | |
| 482 | 482 | |
| 483 | − if (!PageUptodate(page)) | |
| 483 | + zero_user(page, from + copied, len - copied); | |
| 484 | + } | |
| 484 | 485 | SetPageUptodate(page); |
| 486 | + } | |
| 485 | 487 | /* |
| 486 | 488 | * No need to use i_size_read() here, the i_size |
| 487 | 489 | * cannot change under us because we hold the i_mutex. |
| @@ -94,6 +94,12 @@ extern struct mount *__lookup_mnt_last(struct vfsmount *, struct dentry *); · 93 unmodified lines | ||
| 94 | 94 | extern int __legitimize_mnt(struct vfsmount *, unsigned); |
| 95 | 95 | extern bool legitimize_mnt(struct vfsmount *, unsigned); |
| 96 | 96 | |
| 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 | + | |
| 97 | 103 | extern void __detach_mounts(struct dentry *dentry); |
| 98 | 104 | |
| 99 | 105 | static inline void detach_mounts(struct dentry *dentry) |
| @@ -1200,7 +1200,7 @@ static int follow_managed(struct path *path, struct nameidata *nd) · 1199 unmodified lines | ||
| 1200 | 1200 | if (managed & DCACHE_MANAGE_TRANSIT) { |
| 1201 | 1201 | BUG_ON(!path->dentry->d_op); |
| 1202 | 1202 | 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); | |
| 1204 | 1204 | if (ret < 0) |
| 1205 | 1205 | break; |
| 1206 | 1206 | } |
| @@ -1263,10 +1263,10 @@ int follow_down_one(struct path *path) · 56 unmodified lines | ||
| 1263 | 1263 | } |
| 1264 | 1264 | EXPORT_SYMBOL(follow_down_one); |
| 1265 | 1265 | |
| 1266 | −static inline int managed_dentry_rcu(struct dentry *dentry) | |
| 1266 | +static inline int managed_dentry_rcu(const struct path *path) | |
| 1267 | 1267 | { |
| 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; | |
| 1270 | 1270 | } |
| 1271 | 1271 | |
| 1272 | 1272 | /* |
| @@ -1282,7 +1282,7 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path, · 9 unmodified lines | ||
| 1282 | 1282 | * Don't forget we might have a non-mountpoint managed dentry |
| 1283 | 1283 | * that wants to block transit. |
| 1284 | 1284 | */ |
| 1285 | − switch (managed_dentry_rcu(path->dentry)) { | |
| 1285 | + switch (managed_dentry_rcu(path)) { | |
| 1286 | 1286 | case -ECHILD: |
| 1287 | 1287 | default: |
| 1288 | 1288 | return false; |
| @@ -1392,8 +1392,7 @@ int follow_down(struct path *path) · 103 unmodified lines | ||
| 1392 | 1392 | if (managed & DCACHE_MANAGE_TRANSIT) { |
| 1393 | 1393 | BUG_ON(!path->dentry->d_op); |
| 1394 | 1394 | 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); | |
| 1397 | 1396 | if (ret < 0) |
| 1398 | 1397 | return ret == -EISDIR ? 0 : ret; |
| 1399 | 1398 | } |
| @@ -2863,7 +2862,7 @@ bool may_open_dev(const struct path *path) · 1463 unmodified lines | ||
| 2863 | 2862 | !(path->mnt->mnt_sb->s_iflags & SB_I_NODEV); |
| 2864 | 2863 | } |
| 2865 | 2864 | |
| 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) | |
| 2867 | 2866 | { |
| 2868 | 2867 | struct dentry *dentry = path->dentry; |
| 2869 | 2868 | 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 | ||
| 2913 | 2912 | |
| 2914 | 2913 | static int handle_truncate(struct file *filp) |
| 2915 | 2914 | { |
| 2916 | − struct path *path = &filp->f_path; | |
| 2915 | + const struct path *path = &filp->f_path; | |
| 2917 | 2916 | struct inode *inode = path->dentry->d_inode; |
| 2918 | 2917 | int error = get_write_access(inode); |
| 2919 | 2918 | if (error) |
| @@ -678,7 +678,7 @@ out: · 677 unmodified lines | ||
| 678 | 678 | * |
| 679 | 679 | * lookup_mnt takes a reference to the found vfsmount. |
| 680 | 680 | */ |
| 681 | −struct vfsmount *lookup_mnt(struct path *path) | |
| 681 | +struct vfsmount *lookup_mnt(const struct path *path) | |
| 682 | 682 | { |
| 683 | 683 | struct mount *child_mnt; |
| 684 | 684 | struct vfsmount *m; |
| @@ -1159,7 +1159,36 @@ struct vfsmount *mntget(struct vfsmount *mnt) · 474 unmodified lines | ||
| 1159 | 1159 | } |
| 1160 | 1160 | EXPORT_SYMBOL(mntget); |
| 1161 | 1161 | |
| 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) | |
| 1163 | 1192 | { |
| 1164 | 1193 | struct mount *p; |
| 1165 | 1194 | p = clone_mnt(real_mount(path->mnt), path->dentry, CL_PRIVATE); |
| @@ -1758,7 +1787,7 @@ out: · 592 unmodified lines | ||
| 1758 | 1787 | |
| 1759 | 1788 | /* Caller should check returned pointer for errors */ |
| 1760 | 1789 | |
| 1761 | −struct vfsmount *collect_mounts(struct path *path) | |
| 1790 | +struct vfsmount *collect_mounts(const struct path *path) | |
| 1762 | 1791 | { |
| 1763 | 1792 | struct mount *tree; |
| 1764 | 1793 | namespace_lock(); |
| @@ -1791,7 +1820,7 @@ void drop_collected_mounts(struct vfsmount *mnt) · 26 unmodified lines | ||
| 1791 | 1820 | * |
| 1792 | 1821 | * Release with mntput(). |
| 1793 | 1822 | */ |
| 1794 | −struct vfsmount *clone_private_mount(struct path *path) | |
| 1823 | +struct vfsmount *clone_private_mount(const struct path *path) | |
| 1795 | 1824 | { |
| 1796 | 1825 | struct mount *old_mnt = real_mount(path->mnt); |
| 1797 | 1826 | struct mount *new_mnt; |
| @@ -2997,7 +3026,7 @@ bool is_path_reachable(struct mount *mnt, struct dentry *dentry, · 1199 unmodified lines | ||
| 2997 | 3026 | return &mnt->mnt == root->mnt && is_subdir(dentry, root->dentry); |
| 2998 | 3027 | } |
| 2999 | 3028 | |
| 3000 | −bool path_is_under(struct path *path1, struct path *path2) | |
| 3029 | +bool path_is_under(const struct path *path1, const struct path *path2) | |
| 3001 | 3030 | { |
| 3002 | 3031 | bool res; |
| 3003 | 3032 | read_seqlock_excl(&mount_lock); |
| @@ -377,7 +377,7 @@ static int nfs_write_end(struct file *file, struct address_space *mapping, · 376 unmodified lines | ||
| 377 | 377 | */ |
| 378 | 378 | if (!PageUptodate(page)) { |
| 379 | 379 | unsigned pglen = nfs_page_length(page); |
| 380 | − unsigned end = offset + len; | |
| 380 | + unsigned end = offset + copied; | |
| 381 | 381 | |
| 382 | 382 | if (pglen == 0) { |
| 383 | 383 | zero_user_segments(page, 0, offset, |
| @@ -85,7 +85,7 @@ static int dnotify_handle_event(struct fsnotify_group *group, · 84 unmodified lines | ||
| 85 | 85 | struct inode *inode, |
| 86 | 86 | struct fsnotify_mark *inode_mark, |
| 87 | 87 | struct fsnotify_mark *vfsmount_mark, |
| 88 | − u32 mask, void *data, int data_type, | |
| 88 | + u32 mask, const void *data, int data_type, | |
| 89 | 89 | const unsigned char *file_name, u32 cookie) |
| 90 | 90 | { |
| 91 | 91 | struct dnotify_mark *dn_mark; |
| @@ -90,10 +90,10 @@ static int fanotify_get_response(struct fsnotify_group *group, · 89 unmodified lines | ||
| 90 | 90 | static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark, |
| 91 | 91 | struct fsnotify_mark *vfsmnt_mark, |
| 92 | 92 | u32 event_mask, |
| 93 | − void *data, int data_type) | |
| 93 | + const void *data, int data_type) | |
| 94 | 94 | { |
| 95 | 95 | __u32 marks_mask, marks_ignored_mask; |
| 96 | − struct path *path = data; | |
| 96 | + const struct path *path = data; | |
| 97 | 97 | |
| 98 | 98 | pr_debug("%s: inode_mark=%p vfsmnt_mark=%p mask=%x data=%p" |
| 99 | 99 | " 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 | ||
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | struct fanotify_event_info *fanotify_alloc_event(struct inode *inode, u32 mask, |
| 143 | − struct path *path) | |
| 143 | + const struct path *path) | |
| 144 | 144 | { |
| 145 | 145 | struct fanotify_event_info *event; |
| 146 | 146 | |
| @@ -177,7 +177,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, · 30 unmodified lines | ||
| 177 | 177 | struct inode *inode, |
| 178 | 178 | struct fsnotify_mark *inode_mark, |
| 179 | 179 | struct fsnotify_mark *fanotify_mark, |
| 180 | − u32 mask, void *data, int data_type, | |
| 180 | + u32 mask, const void *data, int data_type, | |
| 181 | 181 | const unsigned char *file_name, u32 cookie) |
| 182 | 182 | { |
| 183 | 183 | int ret = 0; |
| @@ -47,4 +47,4 @@ static inline struct fanotify_event_info *FANOTIFY_E(struct fsnotify_event *fse) · 46 unmodified lines | ||
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | struct fanotify_event_info *fanotify_alloc_event(struct inode *inode, u32 mask, |
| 50 | − struct path *path); | |
| 50 | + const struct path *path); | |
| @@ -86,7 +86,7 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode) · 85 unmodified lines | ||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /* 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) | |
| 90 | 90 | { |
| 91 | 91 | struct dentry *parent; |
| 92 | 92 | struct inode *p_inode; |
| @@ -125,7 +125,7 @@ EXPORT_SYMBOL_GPL(__fsnotify_parent); · 32 unmodified lines | ||
| 125 | 125 | static int send_to_group(struct inode *to_tell, |
| 126 | 126 | struct fsnotify_mark *inode_mark, |
| 127 | 127 | struct fsnotify_mark *vfsmount_mark, |
| 128 | − __u32 mask, void *data, | |
| 128 | + __u32 mask, const void *data, | |
| 129 | 129 | int data_is, u32 cookie, |
| 130 | 130 | const unsigned char *file_name) |
| 131 | 131 | { |
| @@ -187,7 +187,7 @@ static int send_to_group(struct inode *to_tell, · 55 unmodified lines | ||
| 187 | 187 | * out to all of the registered fsnotify_group. Those groups can then use the |
| 188 | 188 | * notification event in whatever means they feel necessary. |
| 189 | 189 | */ |
| 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, | |
| 191 | 191 | const unsigned char *file_name, u32 cookie) |
| 192 | 192 | { |
| 193 | 193 | 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 | ||
| 199 | 199 | __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD); |
| 200 | 200 | |
| 201 | 201 | if (data_is == FSNOTIFY_EVENT_PATH) |
| 202 | − mnt = real_mount(((struct path *)data)->mnt); | |
| 202 | + mnt = real_mount(((const struct path *)data)->mnt); | |
| 203 | 203 | else |
| 204 | 204 | mnt = NULL; |
| 205 | 205 | |
| @@ -26,7 +26,7 @@ extern int inotify_handle_event(struct fsnotify_group *group, · 25 unmodified lines | ||
| 26 | 26 | struct inode *inode, |
| 27 | 27 | struct fsnotify_mark *inode_mark, |
| 28 | 28 | struct fsnotify_mark *vfsmount_mark, |
| 29 | − u32 mask, void *data, int data_type, | |
| 29 | + u32 mask, const void *data, int data_type, | |
| 30 | 30 | const unsigned char *file_name, u32 cookie); |
| 31 | 31 | |
| 32 | 32 | extern const struct fsnotify_ops inotify_fsnotify_ops; |
| @@ -66,7 +66,7 @@ int inotify_handle_event(struct fsnotify_group *group, · 65 unmodified lines | ||
| 66 | 66 | struct inode *inode, |
| 67 | 67 | struct fsnotify_mark *inode_mark, |
| 68 | 68 | struct fsnotify_mark *vfsmount_mark, |
| 69 | − u32 mask, void *data, int data_type, | |
| 69 | + u32 mask, const void *data, int data_type, | |
| 70 | 70 | const unsigned char *file_name, u32 cookie) |
| 71 | 71 | { |
| 72 | 72 | struct inotify_inode_mark *i_mark; |
| @@ -80,7 +80,7 @@ int inotify_handle_event(struct fsnotify_group *group, · 7 unmodified lines | ||
| 80 | 80 | |
| 81 | 81 | if ((inode_mark->mask & FS_EXCL_UNLINK) && |
| 82 | 82 | (data_type == FSNOTIFY_EVENT_PATH)) { |
| 83 | − struct path *path = data; | |
| 83 | + const struct path *path = data; | |
| 84 | 84 | |
| 85 | 85 | if (d_unlinked(path->dentry)) |
| 86 | 86 | return 0; |
| @@ -5194,7 +5194,7 @@ int ocfs2_change_extent_flag(handle_t *handle, · 5193 unmodified lines | ||
| 5194 | 5194 | rec = &el->l_recs[index]; |
| 5195 | 5195 | if (new_flags && (rec->e_flags & new_flags)) { |
| 5196 | 5196 | 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", | |
| 5198 | 5198 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), |
| 5199 | 5199 | new_flags); |
| 5200 | 5200 | goto out; |
| @@ -5202,7 +5202,7 @@ int ocfs2_change_extent_flag(handle_t *handle, · 1 unmodified line | ||
| 5202 | 5202 | |
| 5203 | 5203 | if (clear_flags && !(rec->e_flags & clear_flags)) { |
| 5204 | 5204 | 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", | |
| 5206 | 5206 | (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), |
| 5207 | 5207 | clear_flags); |
| 5208 | 5208 | goto out; |
| @@ -5713,8 +5713,7 @@ int ocfs2_remove_btree_range(struct inode *inode, · 504 unmodified lines | ||
| 5713 | 5713 | struct ocfs2_refcount_tree *ref_tree = NULL; |
| 5714 | 5714 | |
| 5715 | 5715 | 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)); | |
| 5718 | 5717 | |
| 5719 | 5718 | if (!refcount_tree_locked) { |
| 5720 | 5719 | ret = ocfs2_lock_refcount_tree(osb, refcount_loc, 1, |
| @@ -464,6 +464,15 @@ static sector_t ocfs2_bmap(struct address_space *mapping, sector_t block) · 463 unmodified lines | ||
| 464 | 464 | trace_ocfs2_bmap((unsigned long long)OCFS2_I(inode)->ip_blkno, |
| 465 | 465 | (unsigned long long)block); |
| 466 | 466 | |
| 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 | + | |
| 467 | 476 | /* We don't need to lock journal system files, since they aren't |
| 468 | 477 | * accessed concurrently from multiple nodes. |
| 469 | 478 | */ |
| @@ -2253,10 +2262,10 @@ out: · 1783 unmodified lines | ||
| 2253 | 2262 | return ret; |
| 2254 | 2263 | } |
| 2255 | 2264 | |
| 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) | |
| 2260 | 2269 | { |
| 2261 | 2270 | struct ocfs2_cached_dealloc_ctxt dealloc; |
| 2262 | 2271 | struct ocfs2_extent_tree et; |
| @@ -2307,7 +2316,7 @@ static void ocfs2_dio_end_io_write(struct inode *inode, · 44 unmodified lines | ||
| 2307 | 2316 | mlog_errno(ret); |
| 2308 | 2317 | } |
| 2309 | 2318 | |
| 2310 | − di = (struct ocfs2_dinode *)di_bh; | |
| 2319 | + di = (struct ocfs2_dinode *)di_bh->b_data; | |
| 2311 | 2320 | |
| 2312 | 2321 | ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode), di_bh); |
| 2313 | 2322 | |
| @@ -2364,6 +2373,8 @@ out: · 50 unmodified lines | ||
| 2364 | 2373 | if (locked) |
| 2365 | 2374 | inode_unlock(inode); |
| 2366 | 2375 | ocfs2_dio_free_write_ctx(inode, dwc); |
| 2376 | + | |
| 2377 | + return ret; | |
| 2367 | 2378 | } |
| 2368 | 2379 | |
| 2369 | 2380 | /* |
| @@ -2378,21 +2389,19 @@ static int ocfs2_dio_end_io(struct kiocb *iocb, · 8 unmodified lines | ||
| 2378 | 2389 | { |
| 2379 | 2390 | struct inode *inode = file_inode(iocb->ki_filp); |
| 2380 | 2391 | int level; |
| 2381 | − | |
| 2382 | − if (bytes <= 0) | |
| 2383 | − return 0; | |
| 2392 | + int ret = 0; | |
| 2384 | 2393 | |
| 2385 | 2394 | /* this io's submitter should not have unlocked this before we could */ |
| 2386 | 2395 | BUG_ON(!ocfs2_iocb_is_rw_locked(iocb)); |
| 2387 | 2396 | |
| 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); | |
| 2390 | 2399 | |
| 2391 | 2400 | ocfs2_iocb_clear_rw_locked(iocb); |
| 2392 | 2401 | |
| 2393 | 2402 | level = ocfs2_iocb_rw_locked_level(iocb); |
| 2394 | 2403 | ocfs2_rw_unlock(inode, level); |
| 2395 | − return 0; | |
| 2404 | + return ret; | |
| 2396 | 2405 | } |
| 2397 | 2406 | |
| 2398 | 2407 | static ssize_t ocfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter) |
| @@ -1030,7 +1030,7 @@ int ocfs2_extend_no_holes(struct inode *inode, struct buffer_head *di_bh, · 1029 unmodified lines | ||
| 1030 | 1030 | * Only quota files call this without a bh, and they can't be |
| 1031 | 1031 | * refcounted. |
| 1032 | 1032 | */ |
| 1033 | − BUG_ON(!di_bh && (oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL)); | |
| 1033 | + BUG_ON(!di_bh && ocfs2_is_refcount_inode(inode)); | |
| 1034 | 1034 | BUG_ON(!di_bh && !(oi->ip_flags & OCFS2_INODE_SYSTEM_FILE)); |
| 1035 | 1035 | |
| 1036 | 1036 | 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 | ||
| 1667 | 1667 | *done = ret; |
| 1668 | 1668 | } |
| 1669 | 1669 | |
| 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) | |
| 1673 | 1673 | { |
| 1674 | 1674 | int ret = 0, flags = 0, done = 0, i; |
| 1675 | 1675 | 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 | ||
| 1719 | 1719 | * within one cluster(means is not exactly aligned to clustersize). |
| 1720 | 1720 | */ |
| 1721 | 1721 | |
| 1722 | − if (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL) { | |
| 1723 | − | |
| 1722 | + if (ocfs2_is_refcount_inode(inode)) { | |
| 1724 | 1723 | ret = ocfs2_cow_file_pos(inode, di_bh, byte_start); |
| 1725 | 1724 | if (ret) { |
| 1726 | 1725 | mlog_errno(ret); |
| @@ -2036,7 +2035,7 @@ int ocfs2_check_range_for_refcount(struct inode *inode, loff_t pos, · 309 unmodified lines | ||
| 2036 | 2035 | struct super_block *sb = inode->i_sb; |
| 2037 | 2036 | |
| 2038 | 2037 | 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) || | |
| 2040 | 2039 | OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) |
| 2041 | 2040 | return 0; |
| 2042 | 2041 | |
| @@ -2440,6 +2439,31 @@ out: · 397 unmodified lines | ||
| 2440 | 2439 | return offset; |
| 2441 | 2440 | } |
| 2442 | 2441 | |
| 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 | + | |
| 2443 | 2467 | const struct inode_operations ocfs2_file_iops = { |
| 2444 | 2468 | .setattr = ocfs2_setattr, |
| 2445 | 2469 | .getattr = ocfs2_getattr, |
| @@ -2479,6 +2503,8 @@ const struct file_operations ocfs2_fops = { · 33 unmodified lines | ||
| 2479 | 2503 | .splice_read = generic_file_splice_read, |
| 2480 | 2504 | .splice_write = iter_file_splice_write, |
| 2481 | 2505 | .fallocate = ocfs2_fallocate, |
| 2506 | + .clone_file_range = ocfs2_file_clone_range, | |
| 2507 | + .dedupe_file_range = ocfs2_file_dedupe_range, | |
| 2482 | 2508 | }; |
| 2483 | 2509 | |
| 2484 | 2510 | const struct file_operations ocfs2_dops = { |
| @@ -2524,6 +2550,8 @@ const struct file_operations ocfs2_fops_no_plocks = { · 39 unmodified lines | ||
| 2524 | 2550 | .splice_read = generic_file_splice_read, |
| 2525 | 2551 | .splice_write = iter_file_splice_write, |
| 2526 | 2552 | .fallocate = ocfs2_fallocate, |
| 2553 | + .clone_file_range = ocfs2_file_clone_range, | |
| 2554 | + .dedupe_file_range = ocfs2_file_dedupe_range, | |
| 2527 | 2555 | }; |
| 2528 | 2556 | |
| 2529 | 2557 | const struct file_operations ocfs2_dops_no_plocks = { |
| @@ -82,4 +82,7 @@ int ocfs2_change_file_space(struct file *file, unsigned int cmd, · 81 unmodified lines | ||
| 82 | 82 | |
| 83 | 83 | int ocfs2_check_range_for_refcount(struct inode *inode, loff_t pos, |
| 84 | 84 | 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); | |
| 85 | 88 | #endif /* OCFS2_FILE_H */ |
| @@ -181,4 +181,10 @@ static inline struct ocfs2_inode_info *cache_info_to_inode(struct ocfs2_caching_ · 180 unmodified lines | ||
| 181 | 181 | return container_of(ci, struct ocfs2_inode_info, ip_metadata_cache); |
| 182 | 182 | } |
| 183 | 183 | |
| 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 | + | |
| 184 | 190 | #endif /* OCFS2_INODE_H */ |
| @@ -235,10 +235,7 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context, · 234 unmodified lines | ||
| 235 | 235 | u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos); |
| 236 | 236 | |
| 237 | 237 | 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)); | |
| 242 | 239 | BUG_ON(!context->refcount_loc); |
| 243 | 240 | |
| 244 | 241 | 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 | ||
| 581 | 578 | phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos); |
| 582 | 579 | |
| 583 | 580 | 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)); | |
| 588 | 582 | BUG_ON(!context->refcount_loc); |
| 589 | 583 | |
| 590 | 584 | ret = ocfs2_lock_refcount_tree(osb, context->refcount_loc, 1, |
| @@ -34,6 +34,7 @@ · 33 unmodified lines | ||
| 34 | 34 | #include "xattr.h" |
| 35 | 35 | #include "namei.h" |
| 36 | 36 | #include "ocfs2_trace.h" |
| 37 | +#include "file.h" | |
| 37 | 38 | |
| 38 | 39 | #include <linux/bio.h> |
| 39 | 40 | #include <linux/blkdev.h> |
| @@ -410,7 +411,7 @@ static int ocfs2_get_refcount_block(struct inode *inode, u64 *ref_blkno) · 370 unmodified lines | ||
| 410 | 411 | goto out; |
| 411 | 412 | } |
| 412 | 413 | |
| 413 | − BUG_ON(!(OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL)); | |
| 414 | + BUG_ON(!ocfs2_is_refcount_inode(inode)); | |
| 414 | 415 | |
| 415 | 416 | di = (struct ocfs2_dinode *)di_bh->b_data; |
| 416 | 417 | *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 | ||
| 569 | 570 | u32 num_got; |
| 570 | 571 | u64 suballoc_loc, first_blkno; |
| 571 | 572 | |
| 572 | − BUG_ON(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL); | |
| 573 | + BUG_ON(ocfs2_is_refcount_inode(inode)); | |
| 573 | 574 | |
| 574 | 575 | trace_ocfs2_create_refcount_tree( |
| 575 | 576 | (unsigned long long)OCFS2_I(inode)->ip_blkno); |
| @@ -707,7 +708,7 @@ static int ocfs2_set_refcount_tree(struct inode *inode, · 131 unmodified lines | ||
| 707 | 708 | struct ocfs2_refcount_block *rb; |
| 708 | 709 | struct ocfs2_refcount_tree *ref_tree; |
| 709 | 710 | |
| 710 | − BUG_ON(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL); | |
| 711 | + BUG_ON(ocfs2_is_refcount_inode(inode)); | |
| 711 | 712 | |
| 712 | 713 | ret = ocfs2_lock_refcount_tree(osb, refcount_loc, 1, |
| 713 | 714 | &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 | ||
| 774 | 775 | u64 blk = 0, bg_blkno = 0, ref_blkno = le64_to_cpu(di->i_refcount_loc); |
| 775 | 776 | u16 bit = 0; |
| 776 | 777 | |
| 777 | − if (!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL)) | |
| 778 | + if (!ocfs2_is_refcount_inode(inode)) | |
| 778 | 779 | return 0; |
| 779 | 780 | |
| 780 | 781 | BUG_ON(!ref_blkno); |
| @@ -2298,11 +2299,10 @@ int ocfs2_decrease_refcount(struct inode *inode, · 1517 unmodified lines | ||
| 2298 | 2299 | { |
| 2299 | 2300 | int ret; |
| 2300 | 2301 | u64 ref_blkno; |
| 2301 | − struct ocfs2_inode_info *oi = OCFS2_I(inode); | |
| 2302 | 2302 | struct buffer_head *ref_root_bh = NULL; |
| 2303 | 2303 | struct ocfs2_refcount_tree *tree; |
| 2304 | 2304 | |
| 2305 | − BUG_ON(!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL)); | |
| 2305 | + BUG_ON(!ocfs2_is_refcount_inode(inode)); | |
| 2306 | 2306 | |
| 2307 | 2307 | ret = ocfs2_get_refcount_block(inode, &ref_blkno); |
| 2308 | 2308 | if (ret) { |
| @@ -2532,7 +2532,6 @@ int ocfs2_prepare_refcount_change_for_del(struct inode *inode, · 223 unmodified lines | ||
| 2532 | 2532 | int *ref_blocks) |
| 2533 | 2533 | { |
| 2534 | 2534 | int ret; |
| 2535 | − struct ocfs2_inode_info *oi = OCFS2_I(inode); | |
| 2536 | 2535 | struct buffer_head *ref_root_bh = NULL; |
| 2537 | 2536 | struct ocfs2_refcount_tree *tree; |
| 2538 | 2537 | 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 | ||
| 2543 | 2542 | goto out; |
| 2544 | 2543 | } |
| 2545 | 2544 | |
| 2546 | − BUG_ON(!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL)); | |
| 2545 | + BUG_ON(!ocfs2_is_refcount_inode(inode)); | |
| 2547 | 2546 | |
| 2548 | 2547 | ret = ocfs2_get_refcount_tree(OCFS2_SB(inode->i_sb), |
| 2549 | 2548 | refcount_loc, &tree); |
| @@ -3411,14 +3410,13 @@ static int ocfs2_refcount_cow_hunk(struct inode *inode, · 861 unmodified lines | ||
| 3411 | 3410 | { |
| 3412 | 3411 | int ret; |
| 3413 | 3412 | u32 cow_start = 0, cow_len = 0; |
| 3414 | − struct ocfs2_inode_info *oi = OCFS2_I(inode); | |
| 3415 | 3413 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); |
| 3416 | 3414 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; |
| 3417 | 3415 | struct buffer_head *ref_root_bh = NULL; |
| 3418 | 3416 | struct ocfs2_refcount_tree *ref_tree; |
| 3419 | 3417 | struct ocfs2_cow_context *context = NULL; |
| 3420 | 3418 | |
| 3421 | − BUG_ON(!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL)); | |
| 3419 | + BUG_ON(!ocfs2_is_refcount_inode(inode)); | |
| 3422 | 3420 | |
| 3423 | 3421 | ret = ocfs2_refcount_cal_cow_clusters(inode, &di->id2.i_list, |
| 3424 | 3422 | cpos, write_len, max_cpos, |
| @@ -3628,11 +3626,10 @@ int ocfs2_refcount_cow_xattr(struct inode *inode, · 203 unmodified lines | ||
| 3628 | 3626 | { |
| 3629 | 3627 | int ret; |
| 3630 | 3628 | struct ocfs2_xattr_value_root *xv = vb->vb_xv; |
| 3631 | − struct ocfs2_inode_info *oi = OCFS2_I(inode); | |
| 3632 | 3629 | struct ocfs2_cow_context *context = NULL; |
| 3633 | 3630 | u32 cow_start, cow_len; |
| 3634 | 3631 | |
| 3635 | − BUG_ON(!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL)); | |
| 3632 | + BUG_ON(!ocfs2_is_refcount_inode(inode)); | |
| 3636 | 3633 | |
| 3637 | 3634 | ret = ocfs2_refcount_cal_cow_clusters(inode, &xv->xr_list, |
| 3638 | 3635 | cpos, write_len, UINT_MAX, |
| @@ -3695,6 +3692,9 @@ int ocfs2_add_refcount_flag(struct inode *inode, · 56 unmodified lines | ||
| 3695 | 3692 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); |
| 3696 | 3693 | struct ocfs2_alloc_context *meta_ac = NULL; |
| 3697 | 3694 | |
| 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 | + | |
| 3698 | 3698 | ret = ocfs2_calc_refcount_meta_credits(inode->i_sb, |
| 3699 | 3699 | ref_ci, ref_root_bh, |
| 3700 | 3700 | p_cluster, num_clusters, |
| @@ -3806,7 +3806,7 @@ static int ocfs2_attach_refcount_tree(struct inode *inode, · 105 unmodified lines | ||
| 3806 | 3806 | |
| 3807 | 3807 | ocfs2_init_dealloc_ctxt(&dealloc); |
| 3808 | 3808 | |
| 3809 | − if (!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL)) { | |
| 3809 | + if (!ocfs2_is_refcount_inode(inode)) { | |
| 3810 | 3810 | ret = ocfs2_create_refcount_tree(inode, di_bh); |
| 3811 | 3811 | if (ret) { |
| 3812 | 3812 | mlog_errno(ret); |
| @@ -3933,6 +3933,13 @@ static int ocfs2_add_refcounted_extent(struct inode *inode, · 120 unmodified lines | ||
| 3933 | 3933 | ret = ocfs2_increase_refcount(handle, ref_ci, ref_root_bh, |
| 3934 | 3934 | p_cluster, num_clusters, |
| 3935 | 3935 | 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)); | |
| 3936 | 3943 | if (ret) |
| 3937 | 3944 | mlog_errno(ret); |
| 3938 | 3945 | |
| @@ -4441,3 +4448,434 @@ out: · 502 unmodified lines | ||
| 4441 | 4448 | |
| 4442 | 4449 | return error; |
| 4443 | 4450 | } |
| 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 | +} | |
| @@ -115,4 +115,11 @@ int ocfs2_reflink_ioctl(struct inode *inode, · 114 unmodified lines | ||
| 115 | 115 | const char __user *oldname, |
| 116 | 116 | const char __user *newname, |
| 117 | 117 | 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 | + | |
| 118 | 125 | #endif /* OCFS2_REFCOUNTTREE_H */ |
| @@ -2577,7 +2577,7 @@ int ocfs2_xattr_remove(struct inode *inode, struct buffer_head *di_bh) · 2576 unmodified lines | ||
| 2577 | 2577 | if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL)) |
| 2578 | 2578 | return 0; |
| 2579 | 2579 | |
| 2580 | − if (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL) { | |
| 2580 | + if (ocfs2_is_refcount_inode(inode)) { | |
| 2581 | 2581 | ret = ocfs2_lock_refcount_tree(OCFS2_SB(inode->i_sb), |
| 2582 | 2582 | le64_to_cpu(di->i_refcount_loc), |
| 2583 | 2583 | 1, &ref_tree, &ref_root_bh); |
| @@ -3608,7 +3608,7 @@ int ocfs2_xattr_set(struct inode *inode, · 1024 unmodified lines | ||
| 3608 | 3608 | } |
| 3609 | 3609 | |
| 3610 | 3610 | /* 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) && | |
| 3612 | 3612 | (!xis.not_found || !xbs.not_found)) { |
| 3613 | 3613 | ret = ocfs2_prepare_refcount_xattr(inode, di, &xi, |
| 3614 | 3614 | &xis, &xbs, &ref_tree, |
| @@ -2401,7 +2401,7 @@ int dquot_resume(struct super_block *sb, int type) · 2400 unmodified lines | ||
| 2401 | 2401 | EXPORT_SYMBOL(dquot_resume); |
| 2402 | 2402 | |
| 2403 | 2403 | int dquot_quota_on(struct super_block *sb, int type, int format_id, |
| 2404 | − struct path *path) | |
| 2404 | + const struct path *path) | |
| 2405 | 2405 | { |
| 2406 | 2406 | int error = security_quota_on(path->dentry); |
| 2407 | 2407 | if (error) |
| @@ -80,7 +80,7 @@ unsigned int qtype_enforce_flag(int type) · 79 unmodified lines | ||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | static int quota_quotaon(struct super_block *sb, int type, qid_t id, |
| 83 | − struct path *path) | |
| 83 | + const struct path *path) | |
| 84 | 84 | { |
| 85 | 85 | if (!sb->s_qcop->quota_on && !sb->s_qcop->quota_enable) |
| 86 | 86 | return -ENOSYS; |
| @@ -700,7 +700,7 @@ static int quota_rmxquota(struct super_block *sb, void __user *addr) · 613 unmodified lines | ||
| 700 | 700 | |
| 701 | 701 | /* Copy parameters and call proper function */ |
| 702 | 702 | 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) | |
| 704 | 704 | { |
| 705 | 705 | int ret; |
| 706 | 706 | |
| @@ -1540,20 +1540,37 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, · 1539 unmodified lines | ||
| 1540 | 1540 | |
| 1541 | 1541 | sb_start_write(inode_out->i_sb); |
| 1542 | 1542 | |
| 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) { | |
| 1545 | 1557 | ret = file_out->f_op->copy_file_range(file_in, pos_in, file_out, |
| 1546 | 1558 | 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); | |
| 1550 | 1565 | |
| 1566 | +done: | |
| 1551 | 1567 | if (ret > 0) { |
| 1552 | 1568 | fsnotify_access(file_in); |
| 1553 | 1569 | add_rchar(current, ret); |
| 1554 | 1570 | fsnotify_modify(file_out); |
| 1555 | 1571 | add_wchar(current, ret); |
| 1556 | 1572 | } |
| 1573 | + | |
| 1557 | 1574 | inc_syscr(current); |
| 1558 | 1575 | inc_syscw(current); |
| 1559 | 1576 | |
| @@ -1648,6 +1665,114 @@ static int clone_verify_area(struct file *file, loff_t pos, u64 len, bool write) · 88 unmodified lines | ||
| 1648 | 1665 | return security_file_permission(file, write ? MAY_WRITE : MAY_READ); |
| 1649 | 1666 | } |
| 1650 | 1667 | |
| 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 | + | |
| 1651 | 1776 | int vfs_clone_file_range(struct file *file_in, loff_t pos_in, |
| 1652 | 1777 | struct file *file_out, loff_t pos_out, u64 len) |
| 1653 | 1778 | { |
| @@ -1698,6 +1823,102 @@ int vfs_clone_file_range(struct file *file_in, loff_t pos_in, · 44 unmodified lines | ||
| 1698 | 1823 | } |
| 1699 | 1824 | EXPORT_SYMBOL(vfs_clone_file_range); |
| 1700 | 1825 | |
| 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 | + | |
| 1701 | 1922 | int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) |
| 1702 | 1923 | { |
| 1703 | 1924 | struct file_dedupe_range_info *info; |
| @@ -802,7 +802,7 @@ static int reiserfs_acquire_dquot(struct dquot *); · 801 unmodified lines | ||
| 802 | 802 | static int reiserfs_release_dquot(struct dquot *); |
| 803 | 803 | static int reiserfs_mark_dquot_dirty(struct dquot *); |
| 804 | 804 | 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 *); | |
| 806 | 806 | |
| 807 | 807 | static const struct dquot_operations reiserfs_quota_operations = { |
| 808 | 808 | .write_dquot = reiserfs_write_dquot, |
| @@ -2348,7 +2348,7 @@ static int reiserfs_quota_on_mount(struct super_block *sb, int type) · 1539 unmodified lines | ||
| 2348 | 2348 | * Standard function to be called on quota_on |
| 2349 | 2349 | */ |
| 2350 | 2350 | static int reiserfs_quota_on(struct super_block *sb, int type, int format_id, |
| 2351 | − struct path *path) | |
| 2351 | + const struct path *path) | |
| 2352 | 2352 | { |
| 2353 | 2353 | int err; |
| 2354 | 2354 | struct inode *inode; |
| @@ -63,7 +63,7 @@ static int statfs_by_dentry(struct dentry *dentry, struct kstatfs *buf) · 62 unmodified lines | ||
| 63 | 63 | return retval; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | −int vfs_statfs(struct path *path, struct kstatfs *buf) | |
| 66 | +int vfs_statfs(const struct path *path, struct kstatfs *buf) | |
| 67 | 67 | { |
| 68 | 68 | int error; |
| 69 | 69 | |
| @@ -48,7 +48,7 @@ static bool nsec_valid(long nsec) · 47 unmodified lines | ||
| 48 | 48 | return nsec >= 0 && nsec <= 999999999; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | −static int utimes_common(struct path *path, struct timespec *times) | |
| 51 | +static int utimes_common(const struct path *path, struct timespec *times) | |
| 52 | 52 | { |
| 53 | 53 | int error; |
| 54 | 54 | struct iattr newattrs; |
| @@ -848,24 +848,6 @@ out_unlock: · 847 unmodified lines | ||
| 848 | 848 | return error; |
| 849 | 849 | } |
| 850 | 850 | |
| 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 | − | |
| 869 | 851 | STATIC int |
| 870 | 852 | xfs_file_clone_range( |
| 871 | 853 | struct file *file_in, |
| @@ -1549,7 +1531,6 @@ const struct file_operations xfs_file_operations = { · 677 unmodified lines | ||
| 1549 | 1531 | .fsync = xfs_file_fsync, |
| 1550 | 1532 | .get_unmapped_area = thp_get_unmapped_area, |
| 1551 | 1533 | .fallocate = xfs_file_fallocate, |
| 1552 | − .copy_file_range = xfs_file_copy_range, | |
| 1553 | 1534 | .clone_file_range = xfs_file_clone_range, |
| 1554 | 1535 | .dedupe_file_range = xfs_file_dedupe_range, |
| 1555 | 1536 | }; |
| @@ -1113,111 +1113,6 @@ err: · 1112 unmodified lines | ||
| 1113 | 1113 | return error; |
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 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 | − | |
| 1221 | 1116 | /* |
| 1222 | 1117 | * Link a range of blocks from one file to another. |
| 1223 | 1118 | */ |
| @@ -1235,14 +1130,11 @@ xfs_reflink_remap_range( · 11 unmodified lines | ||
| 1235 | 1130 | struct inode *inode_out = file_inode(file_out); |
| 1236 | 1131 | struct xfs_inode *dest = XFS_I(inode_out); |
| 1237 | 1132 | struct xfs_mount *mp = src->i_mount; |
| 1238 | − loff_t bs = inode_out->i_sb->s_blocksize; | |
| 1239 | 1133 | bool same_inode = (inode_in == inode_out); |
| 1240 | 1134 | xfs_fileoff_t sfsbno, dfsbno; |
| 1241 | 1135 | xfs_filblks_t fsblen; |
| 1242 | 1136 | xfs_extlen_t cowextsize; |
| 1243 | − loff_t isize; | |
| 1244 | 1137 | ssize_t ret; |
| 1245 | − loff_t blen; | |
| 1246 | 1138 | |
| 1247 | 1139 | if (!xfs_sb_version_hasreflink(&mp->m_sb)) |
| 1248 | 1140 | return -EOPNOTSUPP; |
| @@ -1257,26 +1149,8 @@ xfs_reflink_remap_range( · 8 unmodified lines | ||
| 1257 | 1149 | else |
| 1258 | 1150 | xfs_lock_two_inodes(src, dest, XFS_MMAPLOCK_EXCL); |
| 1259 | 1151 | |
| 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. */ | |
| 1274 | 1153 | 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 | − | |
| 1280 | 1154 | /* Don't reflink realtime inodes */ |
| 1281 | 1155 | if (XFS_IS_REALTIME_INODE(src) || XFS_IS_REALTIME_INODE(dest)) |
| 1282 | 1156 | goto out_unlock; |
| @@ -1285,97 +1159,18 @@ xfs_reflink_remap_range( · 2 unmodified lines | ||
| 1285 | 1159 | if (IS_DAX(inode_in) || IS_DAX(inode_out)) |
| 1286 | 1160 | goto out_unlock; |
| 1287 | 1161 | |
| 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) | |
| 1348 | 1165 | goto out_unlock; |
| 1349 | 1166 | |
| 1350 | 1167 | trace_xfs_reflink_remap_range(src, pos_in, len, dest, pos_out); |
| 1351 | 1168 | |
| 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. */ | |
| 1368 | 1170 | ret = xfs_reflink_set_inode_flag(src, dest); |
| 1369 | 1171 | if (ret) |
| 1370 | 1172 | goto out_unlock; |
| 1371 | 1173 | |
| 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 | − | |
| 1379 | 1174 | dfsbno = XFS_B_TO_FSBT(mp, pos_out); |
| 1380 | 1175 | sfsbno = XFS_B_TO_FSBT(mp, pos_in); |
| 1381 | 1176 | fsblen = XFS_B_TO_FSB(mp, len); |
| @@ -1384,6 +1179,10 @@ xfs_reflink_remap_range( · 2 unmodified lines | ||
| 1384 | 1179 | if (ret) |
| 1385 | 1180 | goto out_unlock; |
| 1386 | 1181 | |
| 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 | + | |
| 1387 | 1186 | /* |
| 1388 | 1187 | * Carry the cowextsize hint from src to dest if we're sharing the |
| 1389 | 1188 | * entire source file to the entire destination file, the source file |
| @@ -147,7 +147,7 @@ extern void audit_log_d_path(struct audit_buffer *ab, · 146 unmodified lines | ||
| 147 | 147 | extern void audit_log_key(struct audit_buffer *ab, |
| 148 | 148 | char *key); |
| 149 | 149 | extern void audit_log_link_denied(const char *operation, |
| 150 | − struct path *link); | |
| 150 | + const struct path *link); | |
| 151 | 151 | extern void audit_log_lost(const char *message); |
| 152 | 152 | #ifdef CONFIG_SECURITY |
| 153 | 153 | extern void audit_log_secctx(struct audit_buffer *ab, u32 secid); |
| @@ -139,7 +139,7 @@ struct dentry_operations { · 138 unmodified lines | ||
| 139 | 139 | void (*d_iput)(struct dentry *, struct inode *); |
| 140 | 140 | char *(*d_dname)(struct dentry *, char *, int); |
| 141 | 141 | struct vfsmount *(*d_automount)(struct path *); |
| 142 | − int (*d_manage)(struct dentry *, bool); | |
| 142 | + int (*d_manage)(const struct path *, bool); | |
| 143 | 143 | struct dentry *(*d_real)(struct dentry *, const struct inode *, |
| 144 | 144 | unsigned int); |
| 145 | 145 | } ____cacheline_aligned; |
| @@ -254,7 +254,7 @@ extern struct dentry *d_find_alias(struct inode *); · 108 unmodified lines | ||
| 254 | 254 | extern void d_prune_aliases(struct inode *); |
| 255 | 255 | |
| 256 | 256 | /* 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 *); | |
| 258 | 258 | |
| 259 | 259 | /* |
| 260 | 260 | * This adds the entry to the hash queues. |
| @@ -44,7 +44,7 @@ void dcookie_unregister(struct dcookie_user * user); · 43 unmodified lines | ||
| 44 | 44 | * |
| 45 | 45 | * Returns 0 on success, with *cookie filled in |
| 46 | 46 | */ |
| 47 | −int get_dcookie(struct path *path, unsigned long *cookie); | |
| 47 | +int get_dcookie(const struct path *path, unsigned long *cookie); | |
| 48 | 48 | |
| 49 | 49 | #else |
| 50 | 50 | |
| @@ -58,7 +58,7 @@ static inline void dcookie_unregister(struct dcookie_user * user) · 7 unmodified lines | ||
| 58 | 58 | return; |
| 59 | 59 | } |
| 60 | 60 | |
| 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) | |
| 62 | 62 | { |
| 63 | 63 | return -ENOSYS; |
| 64 | 64 | } |
| @@ -17,7 +17,7 @@ struct file_operations; · 16 unmodified lines | ||
| 17 | 17 | struct vfsmount; |
| 18 | 18 | struct dentry; |
| 19 | 19 | 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, | |
| 21 | 21 | const struct file_operations *fop); |
| 22 | 22 | |
| 23 | 23 | static inline void fput_light(struct file *file, int fput_needed) |
| @@ -1726,8 +1726,14 @@ extern ssize_t vfs_writev(struct file *, const struct iovec __user *, · 1725 unmodified lines | ||
| 1726 | 1726 | unsigned long, loff_t *, int); |
| 1727 | 1727 | extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *, |
| 1728 | 1728 | 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); | |
| 1729 | 1732 | extern int vfs_clone_file_range(struct file *file_in, loff_t pos_in, |
| 1730 | 1733 | 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); | |
| 1731 | 1737 | extern int vfs_dedupe_file_range(struct file *file, |
| 1732 | 1738 | struct file_dedupe_range *same); |
| 1733 | 1739 | |
| @@ -2084,11 +2090,11 @@ extern int may_umount_tree(struct vfsmount *); · 350 unmodified lines | ||
| 2084 | 2090 | extern int may_umount(struct vfsmount *); |
| 2085 | 2091 | extern long do_mount(const char *, const char __user *, |
| 2086 | 2092 | const char *, unsigned long, void *); |
| 2087 | −extern struct vfsmount *collect_mounts(struct path *); | |
| 2093 | +extern struct vfsmount *collect_mounts(const struct path *); | |
| 2088 | 2094 | extern void drop_collected_mounts(struct vfsmount *); |
| 2089 | 2095 | extern int iterate_mounts(int (*)(struct vfsmount *, void *), void *, |
| 2090 | 2096 | struct vfsmount *); |
| 2091 | −extern int vfs_statfs(struct path *, struct kstatfs *); | |
| 2097 | +extern int vfs_statfs(const struct path *, struct kstatfs *); | |
| 2092 | 2098 | extern int user_statfs(const char __user *, struct kstatfs *); |
| 2093 | 2099 | extern int fd_statfs(int, struct kstatfs *); |
| 2094 | 2100 | extern int vfs_ustat(dev_t, struct kstatfs *); |
| @@ -2657,7 +2663,7 @@ extern struct file * open_exec(const char *); · 562 unmodified lines | ||
| 2657 | 2663 | |
| 2658 | 2664 | /* fs/dcache.c -- generic fs support functions */ |
| 2659 | 2665 | 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 *); | |
| 2661 | 2667 | |
| 2662 | 2668 | extern char *file_path(struct file *, char *, int); |
| 2663 | 2669 | |
| @@ -17,7 +17,7 @@ · 16 unmodified lines | ||
| 17 | 17 | #include <linux/bug.h> |
| 18 | 18 | |
| 19 | 19 | /* 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) | |
| 21 | 21 | { |
| 22 | 22 | if (!dentry) |
| 23 | 23 | dentry = path->dentry; |
| @@ -28,7 +28,7 @@ static inline int fsnotify_parent(struct path *path, struct dentry *dentry, __u3 · 4 unmodified lines | ||
| 28 | 28 | /* simple call site for access decisions */ |
| 29 | 29 | static inline int fsnotify_perm(struct file *file, int mask) |
| 30 | 30 | { |
| 31 | − struct path *path = &file->f_path; | |
| 31 | + const struct path *path = &file->f_path; | |
| 32 | 32 | /* |
| 33 | 33 | * Do not use file_inode() here or anywhere in this file to get the |
| 34 | 34 | * 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 | ||
| 176 | 176 | */ |
| 177 | 177 | static inline void fsnotify_access(struct file *file) |
| 178 | 178 | { |
| 179 | − struct path *path = &file->f_path; | |
| 179 | + const struct path *path = &file->f_path; | |
| 180 | 180 | struct inode *inode = path->dentry->d_inode; |
| 181 | 181 | __u32 mask = FS_ACCESS; |
| 182 | 182 | |
| @@ -194,7 +194,7 @@ static inline void fsnotify_access(struct file *file) · 11 unmodified lines | ||
| 194 | 194 | */ |
| 195 | 195 | static inline void fsnotify_modify(struct file *file) |
| 196 | 196 | { |
| 197 | − struct path *path = &file->f_path; | |
| 197 | + const struct path *path = &file->f_path; | |
| 198 | 198 | struct inode *inode = path->dentry->d_inode; |
| 199 | 199 | __u32 mask = FS_MODIFY; |
| 200 | 200 | |
| @@ -212,7 +212,7 @@ static inline void fsnotify_modify(struct file *file) · 11 unmodified lines | ||
| 212 | 212 | */ |
| 213 | 213 | static inline void fsnotify_open(struct file *file) |
| 214 | 214 | { |
| 215 | − struct path *path = &file->f_path; | |
| 215 | + const struct path *path = &file->f_path; | |
| 216 | 216 | struct inode *inode = path->dentry->d_inode; |
| 217 | 217 | __u32 mask = FS_OPEN; |
| 218 | 218 | |
| @@ -228,7 +228,7 @@ static inline void fsnotify_open(struct file *file) · 9 unmodified lines | ||
| 228 | 228 | */ |
| 229 | 229 | static inline void fsnotify_close(struct file *file) |
| 230 | 230 | { |
| 231 | − struct path *path = &file->f_path; | |
| 231 | + const struct path *path = &file->f_path; | |
| 232 | 232 | struct inode *inode = path->dentry->d_inode; |
| 233 | 233 | fmode_t mode = file->f_mode; |
| 234 | 234 | __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE; |
| @@ -96,7 +96,7 @@ struct fsnotify_ops { · 95 unmodified lines | ||
| 96 | 96 | struct inode *inode, |
| 97 | 97 | struct fsnotify_mark *inode_mark, |
| 98 | 98 | struct fsnotify_mark *vfsmount_mark, |
| 99 | − u32 mask, void *data, int data_type, | |
| 99 | + u32 mask, const void *data, int data_type, | |
| 100 | 100 | const unsigned char *file_name, u32 cookie); |
| 101 | 101 | void (*free_group_priv)(struct fsnotify_group *group); |
| 102 | 102 | void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group); |
| @@ -245,9 +245,9 @@ struct fsnotify_mark { · 142 unmodified lines | ||
| 245 | 245 | /* called from the vfs helpers */ |
| 246 | 246 | |
| 247 | 247 | /* 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, | |
| 249 | 249 | 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); | |
| 251 | 251 | extern void __fsnotify_inode_delete(struct inode *inode); |
| 252 | 252 | extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt); |
| 253 | 253 | extern u32 fsnotify_get_cookie(void); |
| @@ -357,13 +357,13 @@ extern void fsnotify_init_event(struct fsnotify_event *event, · 103 unmodified lines | ||
| 357 | 357 | |
| 358 | 358 | #else |
| 359 | 359 | |
| 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, | |
| 361 | 361 | const unsigned char *name, u32 cookie) |
| 362 | 362 | { |
| 363 | 363 | return 0; |
| 364 | 364 | } |
| 365 | 365 | |
| 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) | |
| 367 | 367 | { |
| 368 | 368 | return 0; |
| 369 | 369 | } |
| @@ -79,12 +79,12 @@ extern void mnt_drop_write(struct vfsmount *mnt); · 78 unmodified lines | ||
| 79 | 79 | extern void mnt_drop_write_file(struct file *file); |
| 80 | 80 | extern void mntput(struct vfsmount *mnt); |
| 81 | 81 | 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); | |
| 83 | 83 | extern int __mnt_is_readonly(struct vfsmount *mnt); |
| 84 | 84 | extern bool mnt_may_suid(struct vfsmount *mnt); |
| 85 | 85 | |
| 86 | 86 | struct path; |
| 87 | −extern struct vfsmount *clone_private_mount(struct path *path); | |
| 87 | +extern struct vfsmount *clone_private_mount(const struct path *path); | |
| 88 | 88 | |
| 89 | 89 | struct file_system_type; |
| 90 | 90 | 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 | ||
| 98 | 98 | |
| 99 | 99 | extern unsigned int sysctl_mount_max; |
| 100 | 100 | |
| 101 | +extern bool path_is_mountpoint(const struct path *path); | |
| 102 | + | |
| 101 | 103 | #endif /* _LINUX_MOUNT_H */ |
| @@ -431,7 +431,7 @@ struct qc_info { · 430 unmodified lines | ||
| 431 | 431 | |
| 432 | 432 | /* Operations handling requests from userspace */ |
| 433 | 433 | 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 *); | |
| 435 | 435 | int (*quota_off)(struct super_block *, int); |
| 436 | 436 | int (*quota_enable)(struct super_block *, unsigned int); |
| 437 | 437 | int (*quota_disable)(struct super_block *, unsigned int); |
| @@ -90,7 +90,7 @@ int dquot_file_open(struct inode *inode, struct file *file); · 89 unmodified lines | ||
| 90 | 90 | int dquot_enable(struct inode *inode, int type, int format_id, |
| 91 | 91 | unsigned int flags); |
| 92 | 92 | int dquot_quota_on(struct super_block *sb, int type, int format_id, |
| 93 | − struct path *path); | |
| 93 | + const struct path *path); | |
| 94 | 94 | int dquot_quota_on_mount(struct super_block *sb, char *qf_name, |
| 95 | 95 | int format_id, int type); |
| 96 | 96 | int dquot_quota_off(struct super_block *sb, int type); |
| @@ -1893,7 +1893,7 @@ void audit_copy_inode(struct audit_names *name, const struct dentry *dentry, · 1892 unmodified lines | ||
| 1893 | 1893 | * @call_panic: optional pointer to int that will be updated if secid fails |
| 1894 | 1894 | */ |
| 1895 | 1895 | 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) | |
| 1897 | 1897 | { |
| 1898 | 1898 | struct audit_buffer *ab; |
| 1899 | 1899 | ab = audit_log_start(context, GFP_KERNEL, AUDIT_PATH); |
| @@ -2081,7 +2081,7 @@ EXPORT_SYMBOL(audit_log_task_info); · 181 unmodified lines | ||
| 2081 | 2081 | * @operation: specific link operation |
| 2082 | 2082 | * @link: the path that triggered the restriction |
| 2083 | 2083 | */ |
| 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) | |
| 2085 | 2085 | { |
| 2086 | 2086 | struct audit_buffer *ab; |
| 2087 | 2087 | struct audit_names *name; |
| @@ -212,7 +212,7 @@ extern void audit_copy_inode(struct audit_names *name, · 211 unmodified lines | ||
| 212 | 212 | extern void audit_log_cap(struct audit_buffer *ab, char *prefix, |
| 213 | 213 | kernel_cap_t *cap); |
| 214 | 214 | 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, | |
| 216 | 216 | int record_num, int *call_panic); |
| 217 | 217 | |
| 218 | 218 | extern int audit_pid; |
| @@ -74,7 +74,7 @@ int audit_mark_compare(struct audit_fsnotify_mark *mark, unsigned long ino, dev_ · 73 unmodified lines | ||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | static void audit_update_mark(struct audit_fsnotify_mark *audit_mark, |
| 77 | − struct inode *inode) | |
| 77 | + const struct inode *inode) | |
| 78 | 78 | { |
| 79 | 79 | audit_mark->dev = inode ? inode->i_sb->s_dev : AUDIT_DEV_UNSET; |
| 80 | 80 | 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 | ||
| 167 | 167 | struct inode *to_tell, |
| 168 | 168 | struct fsnotify_mark *inode_mark, |
| 169 | 169 | struct fsnotify_mark *vfsmount_mark, |
| 170 | − u32 mask, void *data, int data_type, | |
| 170 | + u32 mask, const void *data, int data_type, | |
| 171 | 171 | const unsigned char *dname, u32 cookie) |
| 172 | 172 | { |
| 173 | 173 | struct audit_fsnotify_mark *audit_mark; |
| 174 | − struct inode *inode = NULL; | |
| 174 | + const struct inode *inode = NULL; | |
| 175 | 175 | |
| 176 | 176 | audit_mark = container_of(inode_mark, struct audit_fsnotify_mark, mark); |
| 177 | 177 | |
| @@ -179,10 +179,10 @@ static int audit_mark_handle_event(struct fsnotify_group *group, · 1 unmodified line | ||
| 179 | 179 | |
| 180 | 180 | switch (data_type) { |
| 181 | 181 | case (FSNOTIFY_EVENT_PATH): |
| 182 | − inode = ((struct path *)data)->dentry->d_inode; | |
| 182 | + inode = ((const struct path *)data)->dentry->d_inode; | |
| 183 | 183 | break; |
| 184 | 184 | case (FSNOTIFY_EVENT_INODE): |
| 185 | − inode = (struct inode *)data; | |
| 185 | + inode = (const struct inode *)data; | |
| 186 | 186 | break; |
| 187 | 187 | default: |
| 188 | 188 | BUG(); |
| @@ -947,7 +947,7 @@ static int audit_tree_handle_event(struct fsnotify_group *group, · 946 unmodified lines | ||
| 947 | 947 | struct inode *to_tell, |
| 948 | 948 | struct fsnotify_mark *inode_mark, |
| 949 | 949 | struct fsnotify_mark *vfsmount_mark, |
| 950 | − u32 mask, void *data, int data_type, | |
| 950 | + u32 mask, const void *data, int data_type, | |
| 951 | 951 | const unsigned char *file_name, u32 cookie) |
| 952 | 952 | { |
| 953 | 953 | return 0; |
| @@ -471,10 +471,10 @@ static int audit_watch_handle_event(struct fsnotify_group *group, · 470 unmodified lines | ||
| 471 | 471 | struct inode *to_tell, |
| 472 | 472 | struct fsnotify_mark *inode_mark, |
| 473 | 473 | struct fsnotify_mark *vfsmount_mark, |
| 474 | − u32 mask, void *data, int data_type, | |
| 474 | + u32 mask, const void *data, int data_type, | |
| 475 | 475 | const unsigned char *dname, u32 cookie) |
| 476 | 476 | { |
| 477 | − struct inode *inode; | |
| 477 | + const struct inode *inode; | |
| 478 | 478 | struct audit_parent *parent; |
| 479 | 479 | |
| 480 | 480 | 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 | ||
| 483 | 483 | |
| 484 | 484 | switch (data_type) { |
| 485 | 485 | case (FSNOTIFY_EVENT_PATH): |
| 486 | − inode = d_backing_inode(((struct path *)data)->dentry); | |
| 486 | + inode = d_backing_inode(((const struct path *)data)->dentry); | |
| 487 | 487 | break; |
| 488 | 488 | case (FSNOTIFY_EVENT_INODE): |
| 489 | − inode = (struct inode *)data; | |
| 489 | + inode = (const struct inode *)data; | |
| 490 | 490 | break; |
| 491 | 491 | default: |
| 492 | 492 | BUG(); |