diff options
Diffstat (limited to 'fs')
75 files changed, 966 insertions, 609 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 29b7fc28c607..c4115901d906 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
| @@ -1259,7 +1259,7 @@ struct btrfs_root { | |||
| 1259 | atomic_t will_be_snapshoted; | 1259 | atomic_t will_be_snapshoted; |
| 1260 | 1260 | ||
| 1261 | /* For qgroup metadata space reserve */ | 1261 | /* For qgroup metadata space reserve */ |
| 1262 | atomic_t qgroup_meta_rsv; | 1262 | atomic64_t qgroup_meta_rsv; |
| 1263 | }; | 1263 | }; |
| 1264 | static inline u32 btrfs_inode_sectorsize(const struct inode *inode) | 1264 | static inline u32 btrfs_inode_sectorsize(const struct inode *inode) |
| 1265 | { | 1265 | { |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 08b74daf35d0..eb1ee7b6f532 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
| @@ -1342,7 +1342,7 @@ static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info, | |||
| 1342 | atomic_set(&root->orphan_inodes, 0); | 1342 | atomic_set(&root->orphan_inodes, 0); |
| 1343 | atomic_set(&root->refs, 1); | 1343 | atomic_set(&root->refs, 1); |
| 1344 | atomic_set(&root->will_be_snapshoted, 0); | 1344 | atomic_set(&root->will_be_snapshoted, 0); |
| 1345 | atomic_set(&root->qgroup_meta_rsv, 0); | 1345 | atomic64_set(&root->qgroup_meta_rsv, 0); |
| 1346 | root->log_transid = 0; | 1346 | root->log_transid = 0; |
| 1347 | root->log_transid_committed = -1; | 1347 | root->log_transid_committed = -1; |
| 1348 | root->last_log_commit = 0; | 1348 | root->last_log_commit = 0; |
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 28e81922a21c..27fdb250b446 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
| @@ -1714,7 +1714,8 @@ static int __process_pages_contig(struct address_space *mapping, | |||
| 1714 | * can we find nothing at @index. | 1714 | * can we find nothing at @index. |
| 1715 | */ | 1715 | */ |
| 1716 | ASSERT(page_ops & PAGE_LOCK); | 1716 | ASSERT(page_ops & PAGE_LOCK); |
| 1717 | return ret; | 1717 | err = -EAGAIN; |
| 1718 | goto out; | ||
| 1718 | } | 1719 | } |
| 1719 | 1720 | ||
| 1720 | for (i = 0; i < ret; i++) { | 1721 | for (i = 0; i < ret; i++) { |
| @@ -2583,26 +2584,36 @@ static void end_bio_extent_readpage(struct bio *bio) | |||
| 2583 | 2584 | ||
| 2584 | if (tree->ops) { | 2585 | if (tree->ops) { |
| 2585 | ret = tree->ops->readpage_io_failed_hook(page, mirror); | 2586 | ret = tree->ops->readpage_io_failed_hook(page, mirror); |
| 2586 | if (!ret && !bio->bi_error) | 2587 | if (ret == -EAGAIN) { |
| 2587 | uptodate = 1; | 2588 | /* |
| 2588 | } else { | 2589 | * Data inode's readpage_io_failed_hook() always |
| 2590 | * returns -EAGAIN. | ||
| 2591 | * | ||
| 2592 | * The generic bio_readpage_error handles errors | ||
| 2593 | * the following way: If possible, new read | ||
| 2594 | * requests are created and submitted and will | ||
| 2595 | * end up in end_bio_extent_readpage as well (if | ||
| 2596 | * we're lucky, not in the !uptodate case). In | ||
| 2597 | * that case it returns 0 and we just go on with | ||
| 2598 | * the next page in our bio. If it can't handle | ||
| 2599 | * the error it will return -EIO and we remain | ||
| 2600 | * responsible for that page. | ||
| 2601 | */ | ||
| 2602 | ret = bio_readpage_error(bio, offset, page, | ||
| 2603 | start, end, mirror); | ||
| 2604 | if (ret == 0) { | ||
| 2605 | uptodate = !bio->bi_error; | ||
| 2606 | offset += len; | ||
| 2607 | continue; | ||
| 2608 | } | ||
| 2609 | } | ||
| 2610 | |||
| 2589 | /* | 2611 | /* |
| 2590 | * The generic bio_readpage_error handles errors the | 2612 | * metadata's readpage_io_failed_hook() always returns |
| 2591 | * following way: If possible, new read requests are | 2613 | * -EIO and fixes nothing. -EIO is also returned if |
| 2592 | * created and submitted and will end up in | 2614 | * data inode error could not be fixed. |
| 2593 | * end_bio_extent_readpage as well (if we're lucky, not | ||
| 2594 | * in the !uptodate case). In that case it returns 0 and | ||
| 2595 | * we just go on with the next page in our bio. If it | ||
| 2596 | * can't handle the error it will return -EIO and we | ||
| 2597 | * remain responsible for that page. | ||
| 2598 | */ | 2615 | */ |
| 2599 | ret = bio_readpage_error(bio, offset, page, start, end, | 2616 | ASSERT(ret == -EIO); |
| 2600 | mirror); | ||
| 2601 | if (ret == 0) { | ||
| 2602 | uptodate = !bio->bi_error; | ||
| 2603 | offset += len; | ||
| 2604 | continue; | ||
| 2605 | } | ||
| 2606 | } | 2617 | } |
| 2607 | readpage_ok: | 2618 | readpage_ok: |
| 2608 | if (likely(uptodate)) { | 2619 | if (likely(uptodate)) { |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index c40060cc481f..5e71f1ea3391 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
| @@ -6709,6 +6709,20 @@ static noinline int uncompress_inline(struct btrfs_path *path, | |||
| 6709 | max_size = min_t(unsigned long, PAGE_SIZE, max_size); | 6709 | max_size = min_t(unsigned long, PAGE_SIZE, max_size); |
| 6710 | ret = btrfs_decompress(compress_type, tmp, page, | 6710 | ret = btrfs_decompress(compress_type, tmp, page, |
| 6711 | extent_offset, inline_size, max_size); | 6711 | extent_offset, inline_size, max_size); |
| 6712 | |||
| 6713 | /* | ||
| 6714 | * decompression code contains a memset to fill in any space between the end | ||
| 6715 | * of the uncompressed data and the end of max_size in case the decompressed | ||
| 6716 | * data ends up shorter than ram_bytes. That doesn't cover the hole between | ||
| 6717 | * the end of an inline extent and the beginning of the next block, so we | ||
| 6718 | * cover that region here. | ||
| 6719 | */ | ||
| 6720 | |||
| 6721 | if (max_size + pg_offset < PAGE_SIZE) { | ||
| 6722 | char *map = kmap(page); | ||
| 6723 | memset(map + pg_offset + max_size, 0, PAGE_SIZE - max_size - pg_offset); | ||
| 6724 | kunmap(page); | ||
| 6725 | } | ||
| 6712 | kfree(tmp); | 6726 | kfree(tmp); |
| 6713 | return ret; | 6727 | return ret; |
| 6714 | } | 6728 | } |
| @@ -7896,7 +7910,6 @@ struct btrfs_retry_complete { | |||
| 7896 | static void btrfs_retry_endio_nocsum(struct bio *bio) | 7910 | static void btrfs_retry_endio_nocsum(struct bio *bio) |
| 7897 | { | 7911 | { |
| 7898 | struct btrfs_retry_complete *done = bio->bi_private; | 7912 | struct btrfs_retry_complete *done = bio->bi_private; |
| 7899 | struct inode *inode; | ||
| 7900 | struct bio_vec *bvec; | 7913 | struct bio_vec *bvec; |
| 7901 | int i; | 7914 | int i; |
| 7902 | 7915 | ||
| @@ -7904,12 +7917,12 @@ static void btrfs_retry_endio_nocsum(struct bio *bio) | |||
| 7904 | goto end; | 7917 | goto end; |
| 7905 | 7918 | ||
| 7906 | ASSERT(bio->bi_vcnt == 1); | 7919 | ASSERT(bio->bi_vcnt == 1); |
| 7907 | inode = bio->bi_io_vec->bv_page->mapping->host; | 7920 | ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(done->inode)); |
| 7908 | ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(inode)); | ||
| 7909 | 7921 | ||
| 7910 | done->uptodate = 1; | 7922 | done->uptodate = 1; |
| 7911 | bio_for_each_segment_all(bvec, bio, i) | 7923 | bio_for_each_segment_all(bvec, bio, i) |
| 7912 | clean_io_failure(BTRFS_I(done->inode), done->start, bvec->bv_page, 0); | 7924 | clean_io_failure(BTRFS_I(done->inode), done->start, |
| 7925 | bvec->bv_page, 0); | ||
| 7913 | end: | 7926 | end: |
| 7914 | complete(&done->done); | 7927 | complete(&done->done); |
| 7915 | bio_put(bio); | 7928 | bio_put(bio); |
| @@ -7959,8 +7972,10 @@ next_block_or_try_again: | |||
| 7959 | 7972 | ||
| 7960 | start += sectorsize; | 7973 | start += sectorsize; |
| 7961 | 7974 | ||
| 7962 | if (nr_sectors--) { | 7975 | nr_sectors--; |
| 7976 | if (nr_sectors) { | ||
| 7963 | pgoff += sectorsize; | 7977 | pgoff += sectorsize; |
| 7978 | ASSERT(pgoff < PAGE_SIZE); | ||
| 7964 | goto next_block_or_try_again; | 7979 | goto next_block_or_try_again; |
| 7965 | } | 7980 | } |
| 7966 | } | 7981 | } |
| @@ -7972,9 +7987,7 @@ static void btrfs_retry_endio(struct bio *bio) | |||
| 7972 | { | 7987 | { |
| 7973 | struct btrfs_retry_complete *done = bio->bi_private; | 7988 | struct btrfs_retry_complete *done = bio->bi_private; |
| 7974 | struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); | 7989 | struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); |
| 7975 | struct inode *inode; | ||
| 7976 | struct bio_vec *bvec; | 7990 | struct bio_vec *bvec; |
| 7977 | u64 start; | ||
| 7978 | int uptodate; | 7991 | int uptodate; |
| 7979 | int ret; | 7992 | int ret; |
| 7980 | int i; | 7993 | int i; |
| @@ -7984,11 +7997,8 @@ static void btrfs_retry_endio(struct bio *bio) | |||
| 7984 | 7997 | ||
| 7985 | uptodate = 1; | 7998 | uptodate = 1; |
| 7986 | 7999 | ||
| 7987 | start = done->start; | ||
| 7988 | |||
| 7989 | ASSERT(bio->bi_vcnt == 1); | 8000 | ASSERT(bio->bi_vcnt == 1); |
| 7990 | inode = bio->bi_io_vec->bv_page->mapping->host; | 8001 | ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(done->inode)); |
| 7991 | ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(inode)); | ||
| 7992 | 8002 | ||
| 7993 | bio_for_each_segment_all(bvec, bio, i) { | 8003 | bio_for_each_segment_all(bvec, bio, i) { |
| 7994 | ret = __readpage_endio_check(done->inode, io_bio, i, | 8004 | ret = __readpage_endio_check(done->inode, io_bio, i, |
| @@ -8066,8 +8076,10 @@ next: | |||
| 8066 | 8076 | ||
| 8067 | ASSERT(nr_sectors); | 8077 | ASSERT(nr_sectors); |
| 8068 | 8078 | ||
| 8069 | if (--nr_sectors) { | 8079 | nr_sectors--; |
| 8080 | if (nr_sectors) { | ||
| 8070 | pgoff += sectorsize; | 8081 | pgoff += sectorsize; |
| 8082 | ASSERT(pgoff < PAGE_SIZE); | ||
| 8071 | goto next_block; | 8083 | goto next_block; |
| 8072 | } | 8084 | } |
| 8073 | } | 8085 | } |
| @@ -10509,9 +10521,9 @@ out_inode: | |||
| 10509 | } | 10521 | } |
| 10510 | 10522 | ||
| 10511 | __attribute__((const)) | 10523 | __attribute__((const)) |
| 10512 | static int dummy_readpage_io_failed_hook(struct page *page, int failed_mirror) | 10524 | static int btrfs_readpage_io_failed_hook(struct page *page, int failed_mirror) |
| 10513 | { | 10525 | { |
| 10514 | return 0; | 10526 | return -EAGAIN; |
| 10515 | } | 10527 | } |
| 10516 | 10528 | ||
| 10517 | static const struct inode_operations btrfs_dir_inode_operations = { | 10529 | static const struct inode_operations btrfs_dir_inode_operations = { |
| @@ -10556,7 +10568,7 @@ static const struct extent_io_ops btrfs_extent_io_ops = { | |||
| 10556 | .submit_bio_hook = btrfs_submit_bio_hook, | 10568 | .submit_bio_hook = btrfs_submit_bio_hook, |
| 10557 | .readpage_end_io_hook = btrfs_readpage_end_io_hook, | 10569 | .readpage_end_io_hook = btrfs_readpage_end_io_hook, |
| 10558 | .merge_bio_hook = btrfs_merge_bio_hook, | 10570 | .merge_bio_hook = btrfs_merge_bio_hook, |
| 10559 | .readpage_io_failed_hook = dummy_readpage_io_failed_hook, | 10571 | .readpage_io_failed_hook = btrfs_readpage_io_failed_hook, |
| 10560 | 10572 | ||
| 10561 | /* optional callbacks */ | 10573 | /* optional callbacks */ |
| 10562 | .fill_delalloc = run_delalloc_range, | 10574 | .fill_delalloc = run_delalloc_range, |
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index a5da750c1087..a59801dc2a34 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c | |||
| @@ -2948,20 +2948,20 @@ int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes, | |||
| 2948 | ret = qgroup_reserve(root, num_bytes, enforce); | 2948 | ret = qgroup_reserve(root, num_bytes, enforce); |
| 2949 | if (ret < 0) | 2949 | if (ret < 0) |
| 2950 | return ret; | 2950 | return ret; |
| 2951 | atomic_add(num_bytes, &root->qgroup_meta_rsv); | 2951 | atomic64_add(num_bytes, &root->qgroup_meta_rsv); |
| 2952 | return ret; | 2952 | return ret; |
| 2953 | } | 2953 | } |
| 2954 | 2954 | ||
| 2955 | void btrfs_qgroup_free_meta_all(struct btrfs_root *root) | 2955 | void btrfs_qgroup_free_meta_all(struct btrfs_root *root) |
| 2956 | { | 2956 | { |
| 2957 | struct btrfs_fs_info *fs_info = root->fs_info; | 2957 | struct btrfs_fs_info *fs_info = root->fs_info; |
| 2958 | int reserved; | 2958 | u64 reserved; |
| 2959 | 2959 | ||
| 2960 | if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags) || | 2960 | if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags) || |
| 2961 | !is_fstree(root->objectid)) | 2961 | !is_fstree(root->objectid)) |
| 2962 | return; | 2962 | return; |
| 2963 | 2963 | ||
| 2964 | reserved = atomic_xchg(&root->qgroup_meta_rsv, 0); | 2964 | reserved = atomic64_xchg(&root->qgroup_meta_rsv, 0); |
| 2965 | if (reserved == 0) | 2965 | if (reserved == 0) |
| 2966 | return; | 2966 | return; |
| 2967 | btrfs_qgroup_free_refroot(fs_info, root->objectid, reserved); | 2967 | btrfs_qgroup_free_refroot(fs_info, root->objectid, reserved); |
| @@ -2976,8 +2976,8 @@ void btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes) | |||
| 2976 | return; | 2976 | return; |
| 2977 | 2977 | ||
| 2978 | BUG_ON(num_bytes != round_down(num_bytes, fs_info->nodesize)); | 2978 | BUG_ON(num_bytes != round_down(num_bytes, fs_info->nodesize)); |
| 2979 | WARN_ON(atomic_read(&root->qgroup_meta_rsv) < num_bytes); | 2979 | WARN_ON(atomic64_read(&root->qgroup_meta_rsv) < num_bytes); |
| 2980 | atomic_sub(num_bytes, &root->qgroup_meta_rsv); | 2980 | atomic64_sub(num_bytes, &root->qgroup_meta_rsv); |
| 2981 | btrfs_qgroup_free_refroot(fs_info, root->objectid, num_bytes); | 2981 | btrfs_qgroup_free_refroot(fs_info, root->objectid, num_bytes); |
| 2982 | } | 2982 | } |
| 2983 | 2983 | ||
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 456c8901489b..a60d5bfb8a49 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c | |||
| @@ -6305,8 +6305,13 @@ long btrfs_ioctl_send(struct file *mnt_file, void __user *arg_) | |||
| 6305 | goto out; | 6305 | goto out; |
| 6306 | } | 6306 | } |
| 6307 | 6307 | ||
| 6308 | /* | ||
| 6309 | * Check that we don't overflow at later allocations, we request | ||
| 6310 | * clone_sources_count + 1 items, and compare to unsigned long inside | ||
| 6311 | * access_ok. | ||
| 6312 | */ | ||
| 6308 | if (arg->clone_sources_count > | 6313 | if (arg->clone_sources_count > |
| 6309 | ULLONG_MAX / sizeof(*arg->clone_sources)) { | 6314 | ULONG_MAX / sizeof(struct clone_root) - 1) { |
| 6310 | ret = -EINVAL; | 6315 | ret = -EINVAL; |
| 6311 | goto out; | 6316 | goto out; |
| 6312 | } | 6317 | } |
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index da687dc79cce..9530a333d302 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
| @@ -549,16 +549,19 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, | |||
| 549 | case Opt_ssd: | 549 | case Opt_ssd: |
| 550 | btrfs_set_and_info(info, SSD, | 550 | btrfs_set_and_info(info, SSD, |
| 551 | "use ssd allocation scheme"); | 551 | "use ssd allocation scheme"); |
| 552 | btrfs_clear_opt(info->mount_opt, NOSSD); | ||
| 552 | break; | 553 | break; |
| 553 | case Opt_ssd_spread: | 554 | case Opt_ssd_spread: |
| 554 | btrfs_set_and_info(info, SSD_SPREAD, | 555 | btrfs_set_and_info(info, SSD_SPREAD, |
| 555 | "use spread ssd allocation scheme"); | 556 | "use spread ssd allocation scheme"); |
| 556 | btrfs_set_opt(info->mount_opt, SSD); | 557 | btrfs_set_opt(info->mount_opt, SSD); |
| 558 | btrfs_clear_opt(info->mount_opt, NOSSD); | ||
| 557 | break; | 559 | break; |
| 558 | case Opt_nossd: | 560 | case Opt_nossd: |
| 559 | btrfs_set_and_info(info, NOSSD, | 561 | btrfs_set_and_info(info, NOSSD, |
| 560 | "not using ssd allocation scheme"); | 562 | "not using ssd allocation scheme"); |
| 561 | btrfs_clear_opt(info->mount_opt, SSD); | 563 | btrfs_clear_opt(info->mount_opt, SSD); |
| 564 | btrfs_clear_opt(info->mount_opt, SSD_SPREAD); | ||
| 562 | break; | 565 | break; |
| 563 | case Opt_barrier: | 566 | case Opt_barrier: |
| 564 | btrfs_clear_and_info(info, NOBARRIER, | 567 | btrfs_clear_and_info(info, NOBARRIER, |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 73d56eef5e60..ab8a66d852f9 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
| @@ -6213,7 +6213,7 @@ int btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio, | |||
| 6213 | for (dev_nr = 0; dev_nr < total_devs; dev_nr++) { | 6213 | for (dev_nr = 0; dev_nr < total_devs; dev_nr++) { |
| 6214 | dev = bbio->stripes[dev_nr].dev; | 6214 | dev = bbio->stripes[dev_nr].dev; |
| 6215 | if (!dev || !dev->bdev || | 6215 | if (!dev || !dev->bdev || |
| 6216 | (bio_op(bio) == REQ_OP_WRITE && !dev->writeable)) { | 6216 | (bio_op(first_bio) == REQ_OP_WRITE && !dev->writeable)) { |
| 6217 | bbio_error(bbio, first_bio, logical); | 6217 | bbio_error(bbio, first_bio, logical); |
| 6218 | continue; | 6218 | continue; |
| 6219 | } | 6219 | } |
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 15e1db8738ae..dd3f5fabfdf6 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c | |||
| @@ -972,6 +972,86 @@ out: | |||
| 972 | return rc; | 972 | return rc; |
| 973 | } | 973 | } |
| 974 | 974 | ||
| 975 | ssize_t cifs_file_copychunk_range(unsigned int xid, | ||
| 976 | struct file *src_file, loff_t off, | ||
| 977 | struct file *dst_file, loff_t destoff, | ||
| 978 | size_t len, unsigned int flags) | ||
| 979 | { | ||
| 980 | struct inode *src_inode = file_inode(src_file); | ||
| 981 | struct inode *target_inode = file_inode(dst_file); | ||
| 982 | struct cifsFileInfo *smb_file_src; | ||
| 983 | struct cifsFileInfo *smb_file_target; | ||
| 984 | struct cifs_tcon *src_tcon; | ||
| 985 | struct cifs_tcon *target_tcon; | ||
| 986 | ssize_t rc; | ||
| 987 | |||
| 988 | cifs_dbg(FYI, "copychunk range\n"); | ||
| 989 | |||
| 990 | if (src_inode == target_inode) { | ||
| 991 | rc = -EINVAL; | ||
| 992 | goto out; | ||
| 993 | } | ||
| 994 | |||
| 995 | if (!src_file->private_data || !dst_file->private_data) { | ||
| 996 | rc = -EBADF; | ||
| 997 | cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n"); | ||
| 998 | goto out; | ||
| 999 | } | ||
| 1000 | |||
| 1001 | rc = -EXDEV; | ||
| 1002 | smb_file_target = dst_file->private_data; | ||
| 1003 | smb_file_src = src_file->private_data; | ||
| 1004 | src_tcon = tlink_tcon(smb_file_src->tlink); | ||
| 1005 | target_tcon = tlink_tcon(smb_file_target->tlink); | ||
| 1006 | |||
| 1007 | if (src_tcon->ses != target_tcon->ses) { | ||
| 1008 | cifs_dbg(VFS, "source and target of copy not on same server\n"); | ||
| 1009 | goto out; | ||
| 1010 | } | ||
| 1011 | |||
| 1012 | /* | ||
| 1013 | * Note: cifs case is easier than btrfs since server responsible for | ||
| 1014 | * checks for proper open modes and file type and if it wants | ||
| 1015 | * server could even support copy of range where source = target | ||
| 1016 | */ | ||
| 1017 | lock_two_nondirectories(target_inode, src_inode); | ||
| 1018 | |||
| 1019 | cifs_dbg(FYI, "about to flush pages\n"); | ||
| 1020 | /* should we flush first and last page first */ | ||
| 1021 | truncate_inode_pages(&target_inode->i_data, 0); | ||
| 1022 | |||
| 1023 | if (target_tcon->ses->server->ops->copychunk_range) | ||
| 1024 | rc = target_tcon->ses->server->ops->copychunk_range(xid, | ||
| 1025 | smb_file_src, smb_file_target, off, len, destoff); | ||
| 1026 | else | ||
| 1027 | rc = -EOPNOTSUPP; | ||
| 1028 | |||
| 1029 | /* force revalidate of size and timestamps of target file now | ||
| 1030 | * that target is updated on the server | ||
| 1031 | */ | ||
| 1032 | CIFS_I(target_inode)->time = 0; | ||
| 1033 | /* although unlocking in the reverse order from locking is not | ||
| 1034 | * strictly necessary here it is a little cleaner to be consistent | ||
| 1035 | */ | ||
| 1036 | unlock_two_nondirectories(src_inode, target_inode); | ||
| 1037 | |||
| 1038 | out: | ||
| 1039 | return rc; | ||
| 1040 | } | ||
| 1041 | |||
| 1042 | static ssize_t cifs_copy_file_range(struct file *src_file, loff_t off, | ||
| 1043 | struct file *dst_file, loff_t destoff, | ||
| 1044 | size_t len, unsigned int flags) | ||
| 1045 | { | ||
| 1046 | unsigned int xid = get_xid(); | ||
| 1047 | ssize_t rc; | ||
| 1048 | |||
| 1049 | rc = cifs_file_copychunk_range(xid, src_file, off, dst_file, destoff, | ||
| 1050 | len, flags); | ||
| 1051 | free_xid(xid); | ||
| 1052 | return rc; | ||
| 1053 | } | ||
| 1054 | |||
| 975 | const struct file_operations cifs_file_ops = { | 1055 | const struct file_operations cifs_file_ops = { |
| 976 | .read_iter = cifs_loose_read_iter, | 1056 | .read_iter = cifs_loose_read_iter, |
| 977 | .write_iter = cifs_file_write_iter, | 1057 | .write_iter = cifs_file_write_iter, |
| @@ -984,6 +1064,7 @@ const struct file_operations cifs_file_ops = { | |||
| 984 | .splice_read = generic_file_splice_read, | 1064 | .splice_read = generic_file_splice_read, |
| 985 | .llseek = cifs_llseek, | 1065 | .llseek = cifs_llseek, |
| 986 | .unlocked_ioctl = cifs_ioctl, | 1066 | .unlocked_ioctl = cifs_ioctl, |
| 1067 | .copy_file_range = cifs_copy_file_range, | ||
| 987 | .clone_file_range = cifs_clone_file_range, | 1068 | .clone_file_range = cifs_clone_file_range, |
| 988 | .setlease = cifs_setlease, | 1069 | .setlease = cifs_setlease, |
| 989 | .fallocate = cifs_fallocate, | 1070 | .fallocate = cifs_fallocate, |
| @@ -1001,6 +1082,7 @@ const struct file_operations cifs_file_strict_ops = { | |||
| 1001 | .splice_read = generic_file_splice_read, | 1082 | .splice_read = generic_file_splice_read, |
| 1002 | .llseek = cifs_llseek, | 1083 | .llseek = cifs_llseek, |
| 1003 | .unlocked_ioctl = cifs_ioctl, | 1084 | .unlocked_ioctl = cifs_ioctl, |
| 1085 | .copy_file_range = cifs_copy_file_range, | ||
| 1004 | .clone_file_range = cifs_clone_file_range, | 1086 | .clone_file_range = cifs_clone_file_range, |
| 1005 | .setlease = cifs_setlease, | 1087 | .setlease = cifs_setlease, |
| 1006 | .fallocate = cifs_fallocate, | 1088 | .fallocate = cifs_fallocate, |
| @@ -1018,6 +1100,7 @@ const struct file_operations cifs_file_direct_ops = { | |||
| 1018 | .mmap = cifs_file_mmap, | 1100 | .mmap = cifs_file_mmap, |
| 1019 | .splice_read = generic_file_splice_read, | 1101 | .splice_read = generic_file_splice_read, |
| 1020 | .unlocked_ioctl = cifs_ioctl, | 1102 | .unlocked_ioctl = cifs_ioctl, |
| 1103 | .copy_file_range = cifs_copy_file_range, | ||
| 1021 | .clone_file_range = cifs_clone_file_range, | 1104 | .clone_file_range = cifs_clone_file_range, |
| 1022 | .llseek = cifs_llseek, | 1105 | .llseek = cifs_llseek, |
| 1023 | .setlease = cifs_setlease, | 1106 | .setlease = cifs_setlease, |
| @@ -1035,6 +1118,7 @@ const struct file_operations cifs_file_nobrl_ops = { | |||
| 1035 | .splice_read = generic_file_splice_read, | 1118 | .splice_read = generic_file_splice_read, |
| 1036 | .llseek = cifs_llseek, | 1119 | .llseek = cifs_llseek, |
| 1037 | .unlocked_ioctl = cifs_ioctl, | 1120 | .unlocked_ioctl = cifs_ioctl, |
| 1121 | .copy_file_range = cifs_copy_file_range, | ||
| 1038 | .clone_file_range = cifs_clone_file_range, | 1122 | .clone_file_range = cifs_clone_file_range, |
| 1039 | .setlease = cifs_setlease, | 1123 | .setlease = cifs_setlease, |
| 1040 | .fallocate = cifs_fallocate, | 1124 | .fallocate = cifs_fallocate, |
| @@ -1051,6 +1135,7 @@ const struct file_operations cifs_file_strict_nobrl_ops = { | |||
| 1051 | .splice_read = generic_file_splice_read, | 1135 | .splice_read = generic_file_splice_read, |
| 1052 | .llseek = cifs_llseek, | 1136 | .llseek = cifs_llseek, |
| 1053 | .unlocked_ioctl = cifs_ioctl, | 1137 | .unlocked_ioctl = cifs_ioctl, |
| 1138 | .copy_file_range = cifs_copy_file_range, | ||
| 1054 | .clone_file_range = cifs_clone_file_range, | 1139 | .clone_file_range = cifs_clone_file_range, |
| 1055 | .setlease = cifs_setlease, | 1140 | .setlease = cifs_setlease, |
| 1056 | .fallocate = cifs_fallocate, | 1141 | .fallocate = cifs_fallocate, |
| @@ -1067,6 +1152,7 @@ const struct file_operations cifs_file_direct_nobrl_ops = { | |||
| 1067 | .mmap = cifs_file_mmap, | 1152 | .mmap = cifs_file_mmap, |
| 1068 | .splice_read = generic_file_splice_read, | 1153 | .splice_read = generic_file_splice_read, |
| 1069 | .unlocked_ioctl = cifs_ioctl, | 1154 | .unlocked_ioctl = cifs_ioctl, |
| 1155 | .copy_file_range = cifs_copy_file_range, | ||
| 1070 | .clone_file_range = cifs_clone_file_range, | 1156 | .clone_file_range = cifs_clone_file_range, |
| 1071 | .llseek = cifs_llseek, | 1157 | .llseek = cifs_llseek, |
| 1072 | .setlease = cifs_setlease, | 1158 | .setlease = cifs_setlease, |
| @@ -1078,6 +1164,7 @@ const struct file_operations cifs_dir_ops = { | |||
| 1078 | .release = cifs_closedir, | 1164 | .release = cifs_closedir, |
| 1079 | .read = generic_read_dir, | 1165 | .read = generic_read_dir, |
| 1080 | .unlocked_ioctl = cifs_ioctl, | 1166 | .unlocked_ioctl = cifs_ioctl, |
| 1167 | .copy_file_range = cifs_copy_file_range, | ||
| 1081 | .clone_file_range = cifs_clone_file_range, | 1168 | .clone_file_range = cifs_clone_file_range, |
| 1082 | .llseek = generic_file_llseek, | 1169 | .llseek = generic_file_llseek, |
| 1083 | }; | 1170 | }; |
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index da717fee3026..30bf89b1fd9a 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h | |||
| @@ -139,6 +139,11 @@ extern ssize_t cifs_listxattr(struct dentry *, char *, size_t); | |||
| 139 | # define cifs_listxattr NULL | 139 | # define cifs_listxattr NULL |
| 140 | #endif | 140 | #endif |
| 141 | 141 | ||
| 142 | extern ssize_t cifs_file_copychunk_range(unsigned int xid, | ||
| 143 | struct file *src_file, loff_t off, | ||
| 144 | struct file *dst_file, loff_t destoff, | ||
| 145 | size_t len, unsigned int flags); | ||
| 146 | |||
| 142 | extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); | 147 | extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); |
| 143 | #ifdef CONFIG_CIFS_NFSD_EXPORT | 148 | #ifdef CONFIG_CIFS_NFSD_EXPORT |
| 144 | extern const struct export_operations cifs_export_ops; | 149 | extern const struct export_operations cifs_export_ops; |
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index d42dd3288647..37f5a41cc50c 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h | |||
| @@ -243,6 +243,7 @@ struct smb_version_operations { | |||
| 243 | /* verify the message */ | 243 | /* verify the message */ |
| 244 | int (*check_message)(char *, unsigned int, struct TCP_Server_Info *); | 244 | int (*check_message)(char *, unsigned int, struct TCP_Server_Info *); |
| 245 | bool (*is_oplock_break)(char *, struct TCP_Server_Info *); | 245 | bool (*is_oplock_break)(char *, struct TCP_Server_Info *); |
| 246 | int (*handle_cancelled_mid)(char *, struct TCP_Server_Info *); | ||
| 246 | void (*downgrade_oplock)(struct TCP_Server_Info *, | 247 | void (*downgrade_oplock)(struct TCP_Server_Info *, |
| 247 | struct cifsInodeInfo *, bool); | 248 | struct cifsInodeInfo *, bool); |
| 248 | /* process transaction2 response */ | 249 | /* process transaction2 response */ |
| @@ -407,9 +408,10 @@ struct smb_version_operations { | |||
| 407 | char * (*create_lease_buf)(u8 *, u8); | 408 | char * (*create_lease_buf)(u8 *, u8); |
| 408 | /* parse lease context buffer and return oplock/epoch info */ | 409 | /* parse lease context buffer and return oplock/epoch info */ |
| 409 | __u8 (*parse_lease_buf)(void *, unsigned int *); | 410 | __u8 (*parse_lease_buf)(void *, unsigned int *); |
| 410 | int (*clone_range)(const unsigned int, struct cifsFileInfo *src_file, | 411 | ssize_t (*copychunk_range)(const unsigned int, |
| 411 | struct cifsFileInfo *target_file, u64 src_off, u64 len, | 412 | struct cifsFileInfo *src_file, |
| 412 | u64 dest_off); | 413 | struct cifsFileInfo *target_file, |
| 414 | u64 src_off, u64 len, u64 dest_off); | ||
| 413 | int (*duplicate_extents)(const unsigned int, struct cifsFileInfo *src, | 415 | int (*duplicate_extents)(const unsigned int, struct cifsFileInfo *src, |
| 414 | struct cifsFileInfo *target_file, u64 src_off, u64 len, | 416 | struct cifsFileInfo *target_file, u64 src_off, u64 len, |
| 415 | u64 dest_off); | 417 | u64 dest_off); |
| @@ -946,7 +948,6 @@ struct cifs_tcon { | |||
| 946 | bool use_persistent:1; /* use persistent instead of durable handles */ | 948 | bool use_persistent:1; /* use persistent instead of durable handles */ |
| 947 | #ifdef CONFIG_CIFS_SMB2 | 949 | #ifdef CONFIG_CIFS_SMB2 |
| 948 | bool print:1; /* set if connection to printer share */ | 950 | bool print:1; /* set if connection to printer share */ |
| 949 | bool bad_network_name:1; /* set if ret status STATUS_BAD_NETWORK_NAME */ | ||
| 950 | __le32 capabilities; | 951 | __le32 capabilities; |
| 951 | __u32 share_flags; | 952 | __u32 share_flags; |
| 952 | __u32 maximal_access; | 953 | __u32 maximal_access; |
| @@ -1343,6 +1344,7 @@ struct mid_q_entry { | |||
| 1343 | void *callback_data; /* general purpose pointer for callback */ | 1344 | void *callback_data; /* general purpose pointer for callback */ |
| 1344 | void *resp_buf; /* pointer to received SMB header */ | 1345 | void *resp_buf; /* pointer to received SMB header */ |
| 1345 | int mid_state; /* wish this were enum but can not pass to wait_event */ | 1346 | int mid_state; /* wish this were enum but can not pass to wait_event */ |
| 1347 | unsigned int mid_flags; | ||
| 1346 | __le16 command; /* smb command code */ | 1348 | __le16 command; /* smb command code */ |
| 1347 | bool large_buf:1; /* if valid response, is pointer to large buf */ | 1349 | bool large_buf:1; /* if valid response, is pointer to large buf */ |
| 1348 | bool multiRsp:1; /* multiple trans2 responses for one request */ | 1350 | bool multiRsp:1; /* multiple trans2 responses for one request */ |
| @@ -1350,6 +1352,12 @@ struct mid_q_entry { | |||
| 1350 | bool decrypted:1; /* decrypted entry */ | 1352 | bool decrypted:1; /* decrypted entry */ |
| 1351 | }; | 1353 | }; |
| 1352 | 1354 | ||
| 1355 | struct close_cancelled_open { | ||
| 1356 | struct cifs_fid fid; | ||
| 1357 | struct cifs_tcon *tcon; | ||
| 1358 | struct work_struct work; | ||
| 1359 | }; | ||
| 1360 | |||
| 1353 | /* Make code in transport.c a little cleaner by moving | 1361 | /* Make code in transport.c a little cleaner by moving |
| 1354 | update of optional stats into function below */ | 1362 | update of optional stats into function below */ |
| 1355 | #ifdef CONFIG_CIFS_STATS2 | 1363 | #ifdef CONFIG_CIFS_STATS2 |
| @@ -1481,6 +1489,9 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param, | |||
| 1481 | #define MID_RESPONSE_MALFORMED 0x10 | 1489 | #define MID_RESPONSE_MALFORMED 0x10 |
| 1482 | #define MID_SHUTDOWN 0x20 | 1490 | #define MID_SHUTDOWN 0x20 |
| 1483 | 1491 | ||
| 1492 | /* Flags */ | ||
| 1493 | #define MID_WAIT_CANCELLED 1 /* Cancelled while waiting for response */ | ||
| 1494 | |||
| 1484 | /* Types of response buffer returned from SendReceive2 */ | 1495 | /* Types of response buffer returned from SendReceive2 */ |
| 1485 | #define CIFS_NO_BUFFER 0 /* Response buffer not returned */ | 1496 | #define CIFS_NO_BUFFER 0 /* Response buffer not returned */ |
| 1486 | #define CIFS_SMALL_BUFFER 1 | 1497 | #define CIFS_SMALL_BUFFER 1 |
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 066950671929..5d21f00ae341 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c | |||
| @@ -1428,6 +1428,8 @@ cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
| 1428 | 1428 | ||
| 1429 | length = cifs_discard_remaining_data(server); | 1429 | length = cifs_discard_remaining_data(server); |
| 1430 | dequeue_mid(mid, rdata->result); | 1430 | dequeue_mid(mid, rdata->result); |
| 1431 | mid->resp_buf = server->smallbuf; | ||
| 1432 | server->smallbuf = NULL; | ||
| 1431 | return length; | 1433 | return length; |
| 1432 | } | 1434 | } |
| 1433 | 1435 | ||
| @@ -1541,6 +1543,8 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) | |||
| 1541 | return cifs_readv_discard(server, mid); | 1543 | return cifs_readv_discard(server, mid); |
| 1542 | 1544 | ||
| 1543 | dequeue_mid(mid, false); | 1545 | dequeue_mid(mid, false); |
| 1546 | mid->resp_buf = server->smallbuf; | ||
| 1547 | server->smallbuf = NULL; | ||
| 1544 | return length; | 1548 | return length; |
| 1545 | } | 1549 | } |
| 1546 | 1550 | ||
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 9ae695ae3ed7..d82467cfb0e2 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
| @@ -904,10 +904,19 @@ cifs_demultiplex_thread(void *p) | |||
| 904 | 904 | ||
| 905 | server->lstrp = jiffies; | 905 | server->lstrp = jiffies; |
| 906 | if (mid_entry != NULL) { | 906 | if (mid_entry != NULL) { |
| 907 | if ((mid_entry->mid_flags & MID_WAIT_CANCELLED) && | ||
| 908 | mid_entry->mid_state == MID_RESPONSE_RECEIVED && | ||
| 909 | server->ops->handle_cancelled_mid) | ||
| 910 | server->ops->handle_cancelled_mid( | ||
| 911 | mid_entry->resp_buf, | ||
| 912 | server); | ||
| 913 | |||
| 907 | if (!mid_entry->multiRsp || mid_entry->multiEnd) | 914 | if (!mid_entry->multiRsp || mid_entry->multiEnd) |
| 908 | mid_entry->callback(mid_entry); | 915 | mid_entry->callback(mid_entry); |
| 909 | } else if (!server->ops->is_oplock_break || | 916 | } else if (server->ops->is_oplock_break && |
| 910 | !server->ops->is_oplock_break(buf, server)) { | 917 | server->ops->is_oplock_break(buf, server)) { |
| 918 | cifs_dbg(FYI, "Received oplock break\n"); | ||
| 919 | } else { | ||
| 911 | cifs_dbg(VFS, "No task to wake, unknown frame received! NumMids %d\n", | 920 | cifs_dbg(VFS, "No task to wake, unknown frame received! NumMids %d\n", |
| 912 | atomic_read(&midCount)); | 921 | atomic_read(&midCount)); |
| 913 | cifs_dump_mem("Received Data is: ", buf, | 922 | cifs_dump_mem("Received Data is: ", buf, |
| @@ -3744,6 +3753,9 @@ try_mount_again: | |||
| 3744 | if (IS_ERR(tcon)) { | 3753 | if (IS_ERR(tcon)) { |
| 3745 | rc = PTR_ERR(tcon); | 3754 | rc = PTR_ERR(tcon); |
| 3746 | tcon = NULL; | 3755 | tcon = NULL; |
| 3756 | if (rc == -EACCES) | ||
| 3757 | goto mount_fail_check; | ||
| 3758 | |||
| 3747 | goto remote_path_check; | 3759 | goto remote_path_check; |
| 3748 | } | 3760 | } |
| 3749 | 3761 | ||
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index aa3debbba826..21d404535739 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
| @@ -2597,7 +2597,7 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, | |||
| 2597 | wdata->credits = credits; | 2597 | wdata->credits = credits; |
| 2598 | 2598 | ||
| 2599 | if (!wdata->cfile->invalidHandle || | 2599 | if (!wdata->cfile->invalidHandle || |
| 2600 | !cifs_reopen_file(wdata->cfile, false)) | 2600 | !(rc = cifs_reopen_file(wdata->cfile, false))) |
| 2601 | rc = server->ops->async_writev(wdata, | 2601 | rc = server->ops->async_writev(wdata, |
| 2602 | cifs_uncached_writedata_release); | 2602 | cifs_uncached_writedata_release); |
| 2603 | if (rc) { | 2603 | if (rc) { |
| @@ -3022,7 +3022,7 @@ cifs_send_async_read(loff_t offset, size_t len, struct cifsFileInfo *open_file, | |||
| 3022 | rdata->credits = credits; | 3022 | rdata->credits = credits; |
| 3023 | 3023 | ||
| 3024 | if (!rdata->cfile->invalidHandle || | 3024 | if (!rdata->cfile->invalidHandle || |
| 3025 | !cifs_reopen_file(rdata->cfile, true)) | 3025 | !(rc = cifs_reopen_file(rdata->cfile, true))) |
| 3026 | rc = server->ops->async_readv(rdata); | 3026 | rc = server->ops->async_readv(rdata); |
| 3027 | error: | 3027 | error: |
| 3028 | if (rc) { | 3028 | if (rc) { |
| @@ -3617,7 +3617,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, | |||
| 3617 | } | 3617 | } |
| 3618 | 3618 | ||
| 3619 | if (!rdata->cfile->invalidHandle || | 3619 | if (!rdata->cfile->invalidHandle || |
| 3620 | !cifs_reopen_file(rdata->cfile, true)) | 3620 | !(rc = cifs_reopen_file(rdata->cfile, true))) |
| 3621 | rc = server->ops->async_readv(rdata); | 3621 | rc = server->ops->async_readv(rdata); |
| 3622 | if (rc) { | 3622 | if (rc) { |
| 3623 | add_credits_and_wake_if(server, rdata->credits, 0); | 3623 | add_credits_and_wake_if(server, rdata->credits, 0); |
diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c index 001528781b6b..265c45fe4ea5 100644 --- a/fs/cifs/ioctl.c +++ b/fs/cifs/ioctl.c | |||
| @@ -34,71 +34,14 @@ | |||
| 34 | #include "cifs_ioctl.h" | 34 | #include "cifs_ioctl.h" |
| 35 | #include <linux/btrfs.h> | 35 | #include <linux/btrfs.h> |
| 36 | 36 | ||
| 37 | static int cifs_file_clone_range(unsigned int xid, struct file *src_file, | 37 | static long cifs_ioctl_copychunk(unsigned int xid, struct file *dst_file, |
| 38 | struct file *dst_file) | ||
| 39 | { | ||
| 40 | struct inode *src_inode = file_inode(src_file); | ||
| 41 | struct inode *target_inode = file_inode(dst_file); | ||
| 42 | struct cifsFileInfo *smb_file_src; | ||
| 43 | struct cifsFileInfo *smb_file_target; | ||
| 44 | struct cifs_tcon *src_tcon; | ||
| 45 | struct cifs_tcon *target_tcon; | ||
| 46 | int rc; | ||
| 47 | |||
| 48 | cifs_dbg(FYI, "ioctl clone range\n"); | ||
| 49 | |||
| 50 | if (!src_file->private_data || !dst_file->private_data) { | ||
| 51 | rc = -EBADF; | ||
| 52 | cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n"); | ||
| 53 | goto out; | ||
| 54 | } | ||
| 55 | |||
| 56 | rc = -EXDEV; | ||
| 57 | smb_file_target = dst_file->private_data; | ||
| 58 | smb_file_src = src_file->private_data; | ||
| 59 | src_tcon = tlink_tcon(smb_file_src->tlink); | ||
| 60 | target_tcon = tlink_tcon(smb_file_target->tlink); | ||
| 61 | |||
| 62 | if (src_tcon->ses != target_tcon->ses) { | ||
| 63 | cifs_dbg(VFS, "source and target of copy not on same server\n"); | ||
| 64 | goto out; | ||
| 65 | } | ||
| 66 | |||
| 67 | /* | ||
| 68 | * Note: cifs case is easier than btrfs since server responsible for | ||
| 69 | * checks for proper open modes and file type and if it wants | ||
| 70 | * server could even support copy of range where source = target | ||
| 71 | */ | ||
| 72 | lock_two_nondirectories(target_inode, src_inode); | ||
| 73 | |||
| 74 | cifs_dbg(FYI, "about to flush pages\n"); | ||
| 75 | /* should we flush first and last page first */ | ||
| 76 | truncate_inode_pages(&target_inode->i_data, 0); | ||
| 77 | |||
| 78 | if (target_tcon->ses->server->ops->clone_range) | ||
| 79 | rc = target_tcon->ses->server->ops->clone_range(xid, | ||
| 80 | smb_file_src, smb_file_target, 0, src_inode->i_size, 0); | ||
| 81 | else | ||
| 82 | rc = -EOPNOTSUPP; | ||
| 83 | |||
| 84 | /* force revalidate of size and timestamps of target file now | ||
| 85 | that target is updated on the server */ | ||
| 86 | CIFS_I(target_inode)->time = 0; | ||
| 87 | /* although unlocking in the reverse order from locking is not | ||
| 88 | strictly necessary here it is a little cleaner to be consistent */ | ||
| 89 | unlock_two_nondirectories(src_inode, target_inode); | ||
| 90 | out: | ||
| 91 | return rc; | ||
| 92 | } | ||
| 93 | |||
| 94 | static long cifs_ioctl_clone(unsigned int xid, struct file *dst_file, | ||
| 95 | unsigned long srcfd) | 38 | unsigned long srcfd) |
| 96 | { | 39 | { |
| 97 | int rc; | 40 | int rc; |
| 98 | struct fd src_file; | 41 | struct fd src_file; |
| 99 | struct inode *src_inode; | 42 | struct inode *src_inode; |
| 100 | 43 | ||
| 101 | cifs_dbg(FYI, "ioctl clone range\n"); | 44 | cifs_dbg(FYI, "ioctl copychunk range\n"); |
| 102 | /* the destination must be opened for writing */ | 45 | /* the destination must be opened for writing */ |
| 103 | if (!(dst_file->f_mode & FMODE_WRITE)) { | 46 | if (!(dst_file->f_mode & FMODE_WRITE)) { |
| 104 | cifs_dbg(FYI, "file target not open for write\n"); | 47 | cifs_dbg(FYI, "file target not open for write\n"); |
| @@ -129,7 +72,8 @@ static long cifs_ioctl_clone(unsigned int xid, struct file *dst_file, | |||
| 129 | if (S_ISDIR(src_inode->i_mode)) | 72 | if (S_ISDIR(src_inode->i_mode)) |
| 130 | goto out_fput; | 73 | goto out_fput; |
| 131 | 74 | ||
| 132 | rc = cifs_file_clone_range(xid, src_file.file, dst_file); | 75 | rc = cifs_file_copychunk_range(xid, src_file.file, 0, dst_file, 0, |
| 76 | src_inode->i_size, 0); | ||
| 133 | 77 | ||
| 134 | out_fput: | 78 | out_fput: |
| 135 | fdput(src_file); | 79 | fdput(src_file); |
| @@ -251,7 +195,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) | |||
| 251 | } | 195 | } |
| 252 | break; | 196 | break; |
| 253 | case CIFS_IOC_COPYCHUNK_FILE: | 197 | case CIFS_IOC_COPYCHUNK_FILE: |
| 254 | rc = cifs_ioctl_clone(xid, filep, arg); | 198 | rc = cifs_ioctl_copychunk(xid, filep, arg); |
| 255 | break; | 199 | break; |
| 256 | case CIFS_IOC_SET_INTEGRITY: | 200 | case CIFS_IOC_SET_INTEGRITY: |
| 257 | if (pSMBFile == NULL) | 201 | if (pSMBFile == NULL) |
diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c index cc93ba4da9b5..27bc360c7ffd 100644 --- a/fs/cifs/smb1ops.c +++ b/fs/cifs/smb1ops.c | |||
| @@ -1015,6 +1015,15 @@ cifs_dir_needs_close(struct cifsFileInfo *cfile) | |||
| 1015 | return !cfile->srch_inf.endOfSearch && !cfile->invalidHandle; | 1015 | return !cfile->srch_inf.endOfSearch && !cfile->invalidHandle; |
| 1016 | } | 1016 | } |
| 1017 | 1017 | ||
| 1018 | static bool | ||
| 1019 | cifs_can_echo(struct TCP_Server_Info *server) | ||
| 1020 | { | ||
| 1021 | if (server->tcpStatus == CifsGood) | ||
| 1022 | return true; | ||
| 1023 | |||
| 1024 | return false; | ||
| 1025 | } | ||
| 1026 | |||
| 1018 | struct smb_version_operations smb1_operations = { | 1027 | struct smb_version_operations smb1_operations = { |
| 1019 | .send_cancel = send_nt_cancel, | 1028 | .send_cancel = send_nt_cancel, |
| 1020 | .compare_fids = cifs_compare_fids, | 1029 | .compare_fids = cifs_compare_fids, |
| @@ -1049,6 +1058,7 @@ struct smb_version_operations smb1_operations = { | |||
| 1049 | .get_dfs_refer = CIFSGetDFSRefer, | 1058 | .get_dfs_refer = CIFSGetDFSRefer, |
| 1050 | .qfs_tcon = cifs_qfs_tcon, | 1059 | .qfs_tcon = cifs_qfs_tcon, |
| 1051 | .is_path_accessible = cifs_is_path_accessible, | 1060 | .is_path_accessible = cifs_is_path_accessible, |
| 1061 | .can_echo = cifs_can_echo, | ||
| 1052 | .query_path_info = cifs_query_path_info, | 1062 | .query_path_info = cifs_query_path_info, |
| 1053 | .query_file_info = cifs_query_file_info, | 1063 | .query_file_info = cifs_query_file_info, |
| 1054 | .get_srv_inum = cifs_get_srv_inum, | 1064 | .get_srv_inum = cifs_get_srv_inum, |
diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c index fd516ea8b8f8..1a04b3a5beb1 100644 --- a/fs/cifs/smb2misc.c +++ b/fs/cifs/smb2misc.c | |||
| @@ -659,3 +659,49 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server) | |||
| 659 | cifs_dbg(FYI, "Can not process oplock break for non-existent connection\n"); | 659 | cifs_dbg(FYI, "Can not process oplock break for non-existent connection\n"); |
| 660 | return false; | 660 | return false; |
| 661 | } | 661 | } |
| 662 | |||
| 663 | void | ||
| 664 | smb2_cancelled_close_fid(struct work_struct *work) | ||
| 665 | { | ||
| 666 | struct close_cancelled_open *cancelled = container_of(work, | ||
| 667 | struct close_cancelled_open, work); | ||
| 668 | |||
| 669 | cifs_dbg(VFS, "Close unmatched open\n"); | ||
| 670 | |||
| 671 | SMB2_close(0, cancelled->tcon, cancelled->fid.persistent_fid, | ||
| 672 | cancelled->fid.volatile_fid); | ||
| 673 | cifs_put_tcon(cancelled->tcon); | ||
| 674 | kfree(cancelled); | ||
| 675 | } | ||
| 676 | |||
| 677 | int | ||
| 678 | smb2_handle_cancelled_mid(char *buffer, struct TCP_Server_Info *server) | ||
| 679 | { | ||
| 680 | struct smb2_sync_hdr *sync_hdr = get_sync_hdr(buffer); | ||
| 681 | struct smb2_create_rsp *rsp = (struct smb2_create_rsp *)buffer; | ||
| 682 | struct cifs_tcon *tcon; | ||
| 683 | struct close_cancelled_open *cancelled; | ||
| 684 | |||
| 685 | if (sync_hdr->Command != SMB2_CREATE || | ||
| 686 | sync_hdr->Status != STATUS_SUCCESS) | ||
| 687 | return 0; | ||
| 688 | |||
| 689 | cancelled = kzalloc(sizeof(*cancelled), GFP_KERNEL); | ||
| 690 | if (!cancelled) | ||
| 691 | return -ENOMEM; | ||
| 692 | |||
| 693 | tcon = smb2_find_smb_tcon(server, sync_hdr->SessionId, | ||
| 694 | sync_hdr->TreeId); | ||
| 695 | if (!tcon) { | ||
| 696 | kfree(cancelled); | ||
| 697 | return -ENOENT; | ||
| 698 | } | ||
| 699 | |||
| 700 | cancelled->fid.persistent_fid = rsp->PersistentFileId; | ||
| 701 | cancelled->fid.volatile_fid = rsp->VolatileFileId; | ||
| 702 | cancelled->tcon = tcon; | ||
| 703 | INIT_WORK(&cancelled->work, smb2_cancelled_close_fid); | ||
| 704 | queue_work(cifsiod_wq, &cancelled->work); | ||
| 705 | |||
| 706 | return 0; | ||
| 707 | } | ||
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 0231108d9387..152e37f2ad92 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include <linux/vfs.h> | 21 | #include <linux/vfs.h> |
| 22 | #include <linux/falloc.h> | 22 | #include <linux/falloc.h> |
| 23 | #include <linux/scatterlist.h> | 23 | #include <linux/scatterlist.h> |
| 24 | #include <linux/uuid.h> | ||
| 24 | #include <crypto/aead.h> | 25 | #include <crypto/aead.h> |
| 25 | #include "cifsglob.h" | 26 | #include "cifsglob.h" |
| 26 | #include "smb2pdu.h" | 27 | #include "smb2pdu.h" |
| @@ -592,8 +593,8 @@ req_res_key_exit: | |||
| 592 | return rc; | 593 | return rc; |
| 593 | } | 594 | } |
| 594 | 595 | ||
| 595 | static int | 596 | static ssize_t |
| 596 | smb2_clone_range(const unsigned int xid, | 597 | smb2_copychunk_range(const unsigned int xid, |
| 597 | struct cifsFileInfo *srcfile, | 598 | struct cifsFileInfo *srcfile, |
| 598 | struct cifsFileInfo *trgtfile, u64 src_off, | 599 | struct cifsFileInfo *trgtfile, u64 src_off, |
| 599 | u64 len, u64 dest_off) | 600 | u64 len, u64 dest_off) |
| @@ -605,13 +606,14 @@ smb2_clone_range(const unsigned int xid, | |||
| 605 | struct cifs_tcon *tcon; | 606 | struct cifs_tcon *tcon; |
| 606 | int chunks_copied = 0; | 607 | int chunks_copied = 0; |
| 607 | bool chunk_sizes_updated = false; | 608 | bool chunk_sizes_updated = false; |
| 609 | ssize_t bytes_written, total_bytes_written = 0; | ||
| 608 | 610 | ||
| 609 | pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); | 611 | pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); |
| 610 | 612 | ||
| 611 | if (pcchunk == NULL) | 613 | if (pcchunk == NULL) |
| 612 | return -ENOMEM; | 614 | return -ENOMEM; |
| 613 | 615 | ||
| 614 | cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n"); | 616 | cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n"); |
| 615 | /* Request a key from the server to identify the source of the copy */ | 617 | /* Request a key from the server to identify the source of the copy */ |
| 616 | rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink), | 618 | rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink), |
| 617 | srcfile->fid.persistent_fid, | 619 | srcfile->fid.persistent_fid, |
| @@ -669,14 +671,16 @@ smb2_clone_range(const unsigned int xid, | |||
| 669 | } | 671 | } |
| 670 | chunks_copied++; | 672 | chunks_copied++; |
| 671 | 673 | ||
| 672 | src_off += le32_to_cpu(retbuf->TotalBytesWritten); | 674 | bytes_written = le32_to_cpu(retbuf->TotalBytesWritten); |
| 673 | dest_off += le32_to_cpu(retbuf->TotalBytesWritten); | 675 | src_off += bytes_written; |
| 674 | len -= le32_to_cpu(retbuf->TotalBytesWritten); | 676 | dest_off += bytes_written; |
| 677 | len -= bytes_written; | ||
| 678 | total_bytes_written += bytes_written; | ||
| 675 | 679 | ||
| 676 | cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n", | 680 | cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n", |
| 677 | le32_to_cpu(retbuf->ChunksWritten), | 681 | le32_to_cpu(retbuf->ChunksWritten), |
| 678 | le32_to_cpu(retbuf->ChunkBytesWritten), | 682 | le32_to_cpu(retbuf->ChunkBytesWritten), |
| 679 | le32_to_cpu(retbuf->TotalBytesWritten)); | 683 | bytes_written); |
| 680 | } else if (rc == -EINVAL) { | 684 | } else if (rc == -EINVAL) { |
| 681 | if (ret_data_len != sizeof(struct copychunk_ioctl_rsp)) | 685 | if (ret_data_len != sizeof(struct copychunk_ioctl_rsp)) |
| 682 | goto cchunk_out; | 686 | goto cchunk_out; |
| @@ -713,7 +717,10 @@ smb2_clone_range(const unsigned int xid, | |||
| 713 | cchunk_out: | 717 | cchunk_out: |
| 714 | kfree(pcchunk); | 718 | kfree(pcchunk); |
| 715 | kfree(retbuf); | 719 | kfree(retbuf); |
| 716 | return rc; | 720 | if (rc) |
| 721 | return rc; | ||
| 722 | else | ||
| 723 | return total_bytes_written; | ||
| 717 | } | 724 | } |
| 718 | 725 | ||
| 719 | static int | 726 | static int |
| @@ -2322,6 +2329,7 @@ struct smb_version_operations smb20_operations = { | |||
| 2322 | .clear_stats = smb2_clear_stats, | 2329 | .clear_stats = smb2_clear_stats, |
| 2323 | .print_stats = smb2_print_stats, | 2330 | .print_stats = smb2_print_stats, |
| 2324 | .is_oplock_break = smb2_is_valid_oplock_break, | 2331 | .is_oplock_break = smb2_is_valid_oplock_break, |
| 2332 | .handle_cancelled_mid = smb2_handle_cancelled_mid, | ||
| 2325 | .downgrade_oplock = smb2_downgrade_oplock, | 2333 | .downgrade_oplock = smb2_downgrade_oplock, |
| 2326 | .need_neg = smb2_need_neg, | 2334 | .need_neg = smb2_need_neg, |
| 2327 | .negotiate = smb2_negotiate, | 2335 | .negotiate = smb2_negotiate, |
| @@ -2377,7 +2385,7 @@ struct smb_version_operations smb20_operations = { | |||
| 2377 | .set_oplock_level = smb2_set_oplock_level, | 2385 | .set_oplock_level = smb2_set_oplock_level, |
| 2378 | .create_lease_buf = smb2_create_lease_buf, | 2386 | .create_lease_buf = smb2_create_lease_buf, |
| 2379 | .parse_lease_buf = smb2_parse_lease_buf, | 2387 | .parse_lease_buf = smb2_parse_lease_buf, |
| 2380 | .clone_range = smb2_clone_range, | 2388 | .copychunk_range = smb2_copychunk_range, |
| 2381 | .wp_retry_size = smb2_wp_retry_size, | 2389 | .wp_retry_size = smb2_wp_retry_size, |
| 2382 | .dir_needs_close = smb2_dir_needs_close, | 2390 | .dir_needs_close = smb2_dir_needs_close, |
| 2383 | .get_dfs_refer = smb2_get_dfs_refer, | 2391 | .get_dfs_refer = smb2_get_dfs_refer, |
| @@ -2404,6 +2412,7 @@ struct smb_version_operations smb21_operations = { | |||
| 2404 | .clear_stats = smb2_clear_stats, | 2412 | .clear_stats = smb2_clear_stats, |
| 2405 | .print_stats = smb2_print_stats, | 2413 | .print_stats = smb2_print_stats, |
| 2406 | .is_oplock_break = smb2_is_valid_oplock_break, | 2414 | .is_oplock_break = smb2_is_valid_oplock_break, |
| 2415 | .handle_cancelled_mid = smb2_handle_cancelled_mid, | ||
| 2407 | .downgrade_oplock = smb2_downgrade_oplock, | 2416 | .downgrade_oplock = smb2_downgrade_oplock, |
| 2408 | .need_neg = smb2_need_neg, | 2417 | .need_neg = smb2_need_neg, |
| 2409 | .negotiate = smb2_negotiate, | 2418 | .negotiate = smb2_negotiate, |
| @@ -2459,7 +2468,7 @@ struct smb_version_operations smb21_operations = { | |||
| 2459 | .set_oplock_level = smb21_set_oplock_level, | 2468 | .set_oplock_level = smb21_set_oplock_level, |
| 2460 | .create_lease_buf = smb2_create_lease_buf, | 2469 | .create_lease_buf = smb2_create_lease_buf, |
| 2461 | .parse_lease_buf = smb2_parse_lease_buf, | 2470 | .parse_lease_buf = smb2_parse_lease_buf, |
| 2462 | .clone_range = smb2_clone_range, | 2471 | .copychunk_range = smb2_copychunk_range, |
| 2463 | .wp_retry_size = smb2_wp_retry_size, | 2472 | .wp_retry_size = smb2_wp_retry_size, |
| 2464 | .dir_needs_close = smb2_dir_needs_close, | 2473 | .dir_needs_close = smb2_dir_needs_close, |
| 2465 | .enum_snapshots = smb3_enum_snapshots, | 2474 | .enum_snapshots = smb3_enum_snapshots, |
| @@ -2488,6 +2497,7 @@ struct smb_version_operations smb30_operations = { | |||
| 2488 | .print_stats = smb2_print_stats, | 2497 | .print_stats = smb2_print_stats, |
| 2489 | .dump_share_caps = smb2_dump_share_caps, | 2498 | .dump_share_caps = smb2_dump_share_caps, |
| 2490 | .is_oplock_break = smb2_is_valid_oplock_break, | 2499 | .is_oplock_break = smb2_is_valid_oplock_break, |
| 2500 | .handle_cancelled_mid = smb2_handle_cancelled_mid, | ||
| 2491 | .downgrade_oplock = smb2_downgrade_oplock, | 2501 | .downgrade_oplock = smb2_downgrade_oplock, |
| 2492 | .need_neg = smb2_need_neg, | 2502 | .need_neg = smb2_need_neg, |
| 2493 | .negotiate = smb2_negotiate, | 2503 | .negotiate = smb2_negotiate, |
| @@ -2545,7 +2555,7 @@ struct smb_version_operations smb30_operations = { | |||
| 2545 | .set_oplock_level = smb3_set_oplock_level, | 2555 | .set_oplock_level = smb3_set_oplock_level, |
| 2546 | .create_lease_buf = smb3_create_lease_buf, | 2556 | .create_lease_buf = smb3_create_lease_buf, |
| 2547 | .parse_lease_buf = smb3_parse_lease_buf, | 2557 | .parse_lease_buf = smb3_parse_lease_buf, |
| 2548 | .clone_range = smb2_clone_range, | 2558 | .copychunk_range = smb2_copychunk_range, |
| 2549 | .duplicate_extents = smb2_duplicate_extents, | 2559 | .duplicate_extents = smb2_duplicate_extents, |
| 2550 | .validate_negotiate = smb3_validate_negotiate, | 2560 | .validate_negotiate = smb3_validate_negotiate, |
| 2551 | .wp_retry_size = smb2_wp_retry_size, | 2561 | .wp_retry_size = smb2_wp_retry_size, |
| @@ -2582,6 +2592,7 @@ struct smb_version_operations smb311_operations = { | |||
| 2582 | .print_stats = smb2_print_stats, | 2592 | .print_stats = smb2_print_stats, |
| 2583 | .dump_share_caps = smb2_dump_share_caps, | 2593 | .dump_share_caps = smb2_dump_share_caps, |
| 2584 | .is_oplock_break = smb2_is_valid_oplock_break, | 2594 | .is_oplock_break = smb2_is_valid_oplock_break, |
| 2595 | .handle_cancelled_mid = smb2_handle_cancelled_mid, | ||
| 2585 | .downgrade_oplock = smb2_downgrade_oplock, | 2596 | .downgrade_oplock = smb2_downgrade_oplock, |
| 2586 | .need_neg = smb2_need_neg, | 2597 | .need_neg = smb2_need_neg, |
| 2587 | .negotiate = smb2_negotiate, | 2598 | .negotiate = smb2_negotiate, |
| @@ -2639,7 +2650,7 @@ struct smb_version_operations smb311_operations = { | |||
| 2639 | .set_oplock_level = smb3_set_oplock_level, | 2650 | .set_oplock_level = smb3_set_oplock_level, |
| 2640 | .create_lease_buf = smb3_create_lease_buf, | 2651 | .create_lease_buf = smb3_create_lease_buf, |
| 2641 | .parse_lease_buf = smb3_parse_lease_buf, | 2652 | .parse_lease_buf = smb3_parse_lease_buf, |
| 2642 | .clone_range = smb2_clone_range, | 2653 | .copychunk_range = smb2_copychunk_range, |
| 2643 | .duplicate_extents = smb2_duplicate_extents, | 2654 | .duplicate_extents = smb2_duplicate_extents, |
| 2644 | /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */ | 2655 | /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */ |
| 2645 | .wp_retry_size = smb2_wp_retry_size, | 2656 | .wp_retry_size = smb2_wp_retry_size, |
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 7446496850a3..02da648041fc 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c | |||
| @@ -562,8 +562,10 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) | |||
| 562 | * but for time being this is our only auth choice so doesn't matter. | 562 | * but for time being this is our only auth choice so doesn't matter. |
| 563 | * We just found a server which sets blob length to zero expecting raw. | 563 | * We just found a server which sets blob length to zero expecting raw. |
| 564 | */ | 564 | */ |
| 565 | if (blob_length == 0) | 565 | if (blob_length == 0) { |
| 566 | cifs_dbg(FYI, "missing security blob on negprot\n"); | 566 | cifs_dbg(FYI, "missing security blob on negprot\n"); |
| 567 | server->sec_ntlmssp = true; | ||
| 568 | } | ||
| 567 | 569 | ||
| 568 | rc = cifs_enable_signing(server, ses->sign); | 570 | rc = cifs_enable_signing(server, ses->sign); |
| 569 | if (rc) | 571 | if (rc) |
| @@ -1171,9 +1173,6 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree, | |||
| 1171 | else | 1173 | else |
| 1172 | return -EIO; | 1174 | return -EIO; |
| 1173 | 1175 | ||
| 1174 | if (tcon && tcon->bad_network_name) | ||
| 1175 | return -ENOENT; | ||
| 1176 | |||
| 1177 | unc_path = kmalloc(MAX_SHARENAME_LENGTH * 2, GFP_KERNEL); | 1176 | unc_path = kmalloc(MAX_SHARENAME_LENGTH * 2, GFP_KERNEL); |
| 1178 | if (unc_path == NULL) | 1177 | if (unc_path == NULL) |
| 1179 | return -ENOMEM; | 1178 | return -ENOMEM; |
| @@ -1185,6 +1184,10 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree, | |||
| 1185 | return -EINVAL; | 1184 | return -EINVAL; |
| 1186 | } | 1185 | } |
| 1187 | 1186 | ||
| 1187 | /* SMB2 TREE_CONNECT request must be called with TreeId == 0 */ | ||
| 1188 | if (tcon) | ||
| 1189 | tcon->tid = 0; | ||
| 1190 | |||
| 1188 | rc = small_smb2_init(SMB2_TREE_CONNECT, tcon, (void **) &req); | 1191 | rc = small_smb2_init(SMB2_TREE_CONNECT, tcon, (void **) &req); |
| 1189 | if (rc) { | 1192 | if (rc) { |
| 1190 | kfree(unc_path); | 1193 | kfree(unc_path); |
| @@ -1273,8 +1276,6 @@ tcon_exit: | |||
| 1273 | tcon_error_exit: | 1276 | tcon_error_exit: |
| 1274 | if (rsp->hdr.sync_hdr.Status == STATUS_BAD_NETWORK_NAME) { | 1277 | if (rsp->hdr.sync_hdr.Status == STATUS_BAD_NETWORK_NAME) { |
| 1275 | cifs_dbg(VFS, "BAD_NETWORK_NAME: %s\n", tree); | 1278 | cifs_dbg(VFS, "BAD_NETWORK_NAME: %s\n", tree); |
| 1276 | if (tcon) | ||
| 1277 | tcon->bad_network_name = true; | ||
| 1278 | } | 1279 | } |
| 1279 | goto tcon_exit; | 1280 | goto tcon_exit; |
| 1280 | } | 1281 | } |
| @@ -2177,6 +2178,9 @@ void smb2_reconnect_server(struct work_struct *work) | |||
| 2177 | struct cifs_tcon *tcon, *tcon2; | 2178 | struct cifs_tcon *tcon, *tcon2; |
| 2178 | struct list_head tmp_list; | 2179 | struct list_head tmp_list; |
| 2179 | int tcon_exist = false; | 2180 | int tcon_exist = false; |
| 2181 | int rc; | ||
| 2182 | int resched = false; | ||
| 2183 | |||
| 2180 | 2184 | ||
| 2181 | /* Prevent simultaneous reconnects that can corrupt tcon->rlist list */ | 2185 | /* Prevent simultaneous reconnects that can corrupt tcon->rlist list */ |
| 2182 | mutex_lock(&server->reconnect_mutex); | 2186 | mutex_lock(&server->reconnect_mutex); |
| @@ -2204,13 +2208,18 @@ void smb2_reconnect_server(struct work_struct *work) | |||
| 2204 | spin_unlock(&cifs_tcp_ses_lock); | 2208 | spin_unlock(&cifs_tcp_ses_lock); |
| 2205 | 2209 | ||
| 2206 | list_for_each_entry_safe(tcon, tcon2, &tmp_list, rlist) { | 2210 | list_for_each_entry_safe(tcon, tcon2, &tmp_list, rlist) { |
| 2207 | if (!smb2_reconnect(SMB2_INTERNAL_CMD, tcon)) | 2211 | rc = smb2_reconnect(SMB2_INTERNAL_CMD, tcon); |
| 2212 | if (!rc) | ||
| 2208 | cifs_reopen_persistent_handles(tcon); | 2213 | cifs_reopen_persistent_handles(tcon); |
| 2214 | else | ||
| 2215 | resched = true; | ||
| 2209 | list_del_init(&tcon->rlist); | 2216 | list_del_init(&tcon->rlist); |
| 2210 | cifs_put_tcon(tcon); | 2217 | cifs_put_tcon(tcon); |
| 2211 | } | 2218 | } |
| 2212 | 2219 | ||
| 2213 | cifs_dbg(FYI, "Reconnecting tcons finished\n"); | 2220 | cifs_dbg(FYI, "Reconnecting tcons finished\n"); |
| 2221 | if (resched) | ||
| 2222 | queue_delayed_work(cifsiod_wq, &server->reconnect, 2 * HZ); | ||
| 2214 | mutex_unlock(&server->reconnect_mutex); | 2223 | mutex_unlock(&server->reconnect_mutex); |
| 2215 | 2224 | ||
| 2216 | /* now we can safely release srv struct */ | 2225 | /* now we can safely release srv struct */ |
diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h index 69e35873b1de..6853454fc871 100644 --- a/fs/cifs/smb2proto.h +++ b/fs/cifs/smb2proto.h | |||
| @@ -48,6 +48,10 @@ extern struct mid_q_entry *smb2_setup_request(struct cifs_ses *ses, | |||
| 48 | struct smb_rqst *rqst); | 48 | struct smb_rqst *rqst); |
| 49 | extern struct mid_q_entry *smb2_setup_async_request( | 49 | extern struct mid_q_entry *smb2_setup_async_request( |
| 50 | struct TCP_Server_Info *server, struct smb_rqst *rqst); | 50 | struct TCP_Server_Info *server, struct smb_rqst *rqst); |
| 51 | extern struct cifs_ses *smb2_find_smb_ses(struct TCP_Server_Info *server, | ||
| 52 | __u64 ses_id); | ||
| 53 | extern struct cifs_tcon *smb2_find_smb_tcon(struct TCP_Server_Info *server, | ||
| 54 | __u64 ses_id, __u32 tid); | ||
| 51 | extern int smb2_calc_signature(struct smb_rqst *rqst, | 55 | extern int smb2_calc_signature(struct smb_rqst *rqst, |
| 52 | struct TCP_Server_Info *server); | 56 | struct TCP_Server_Info *server); |
| 53 | extern int smb3_calc_signature(struct smb_rqst *rqst, | 57 | extern int smb3_calc_signature(struct smb_rqst *rqst, |
| @@ -164,6 +168,9 @@ extern int SMB2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, | |||
| 164 | extern int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon, | 168 | extern int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon, |
| 165 | const u64 persistent_fid, const u64 volatile_fid, | 169 | const u64 persistent_fid, const u64 volatile_fid, |
| 166 | const __u8 oplock_level); | 170 | const __u8 oplock_level); |
| 171 | extern int smb2_handle_cancelled_mid(char *buffer, | ||
| 172 | struct TCP_Server_Info *server); | ||
| 173 | void smb2_cancelled_close_fid(struct work_struct *work); | ||
| 167 | extern int SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon, | 174 | extern int SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 168 | u64 persistent_file_id, u64 volatile_file_id, | 175 | u64 persistent_file_id, u64 volatile_file_id, |
| 169 | struct kstatfs *FSData); | 176 | struct kstatfs *FSData); |
diff --git a/fs/cifs/smb2transport.c b/fs/cifs/smb2transport.c index 7c3bb1bd7eed..506b67fc93d9 100644 --- a/fs/cifs/smb2transport.c +++ b/fs/cifs/smb2transport.c | |||
| @@ -115,23 +115,70 @@ smb3_crypto_shash_allocate(struct TCP_Server_Info *server) | |||
| 115 | return 0; | 115 | return 0; |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | struct cifs_ses * | 118 | static struct cifs_ses * |
| 119 | smb2_find_smb_ses(struct TCP_Server_Info *server, __u64 ses_id) | 119 | smb2_find_smb_ses_unlocked(struct TCP_Server_Info *server, __u64 ses_id) |
| 120 | { | 120 | { |
| 121 | struct cifs_ses *ses; | 121 | struct cifs_ses *ses; |
| 122 | 122 | ||
| 123 | spin_lock(&cifs_tcp_ses_lock); | ||
| 124 | list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { | 123 | list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { |
| 125 | if (ses->Suid != ses_id) | 124 | if (ses->Suid != ses_id) |
| 126 | continue; | 125 | continue; |
| 127 | spin_unlock(&cifs_tcp_ses_lock); | ||
| 128 | return ses; | 126 | return ses; |
| 129 | } | 127 | } |
| 128 | |||
| 129 | return NULL; | ||
| 130 | } | ||
| 131 | |||
| 132 | struct cifs_ses * | ||
| 133 | smb2_find_smb_ses(struct TCP_Server_Info *server, __u64 ses_id) | ||
| 134 | { | ||
| 135 | struct cifs_ses *ses; | ||
| 136 | |||
| 137 | spin_lock(&cifs_tcp_ses_lock); | ||
| 138 | ses = smb2_find_smb_ses_unlocked(server, ses_id); | ||
| 130 | spin_unlock(&cifs_tcp_ses_lock); | 139 | spin_unlock(&cifs_tcp_ses_lock); |
| 131 | 140 | ||
| 141 | return ses; | ||
| 142 | } | ||
| 143 | |||
| 144 | static struct cifs_tcon * | ||
| 145 | smb2_find_smb_sess_tcon_unlocked(struct cifs_ses *ses, __u32 tid) | ||
| 146 | { | ||
| 147 | struct cifs_tcon *tcon; | ||
| 148 | |||
| 149 | list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { | ||
| 150 | if (tcon->tid != tid) | ||
| 151 | continue; | ||
| 152 | ++tcon->tc_count; | ||
| 153 | return tcon; | ||
| 154 | } | ||
| 155 | |||
| 132 | return NULL; | 156 | return NULL; |
| 133 | } | 157 | } |
| 134 | 158 | ||
| 159 | /* | ||
| 160 | * Obtain tcon corresponding to the tid in the given | ||
| 161 | * cifs_ses | ||
| 162 | */ | ||
| 163 | |||
| 164 | struct cifs_tcon * | ||
| 165 | smb2_find_smb_tcon(struct TCP_Server_Info *server, __u64 ses_id, __u32 tid) | ||
| 166 | { | ||
| 167 | struct cifs_ses *ses; | ||
| 168 | struct cifs_tcon *tcon; | ||
| 169 | |||
| 170 | spin_lock(&cifs_tcp_ses_lock); | ||
| 171 | ses = smb2_find_smb_ses_unlocked(server, ses_id); | ||
| 172 | if (!ses) { | ||
| 173 | spin_unlock(&cifs_tcp_ses_lock); | ||
| 174 | return NULL; | ||
| 175 | } | ||
| 176 | tcon = smb2_find_smb_sess_tcon_unlocked(ses, tid); | ||
| 177 | spin_unlock(&cifs_tcp_ses_lock); | ||
| 178 | |||
| 179 | return tcon; | ||
| 180 | } | ||
| 181 | |||
| 135 | int | 182 | int |
| 136 | smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) | 183 | smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) |
| 137 | { | 184 | { |
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 526f0533cb4e..f6e13a977fc8 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c | |||
| @@ -752,9 +752,11 @@ cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, | |||
| 752 | 752 | ||
| 753 | rc = wait_for_response(ses->server, midQ); | 753 | rc = wait_for_response(ses->server, midQ); |
| 754 | if (rc != 0) { | 754 | if (rc != 0) { |
| 755 | cifs_dbg(FYI, "Cancelling wait for mid %llu\n", midQ->mid); | ||
| 755 | send_cancel(ses->server, rqst, midQ); | 756 | send_cancel(ses->server, rqst, midQ); |
| 756 | spin_lock(&GlobalMid_Lock); | 757 | spin_lock(&GlobalMid_Lock); |
| 757 | if (midQ->mid_state == MID_REQUEST_SUBMITTED) { | 758 | if (midQ->mid_state == MID_REQUEST_SUBMITTED) { |
| 759 | midQ->mid_flags |= MID_WAIT_CANCELLED; | ||
| 758 | midQ->callback = DeleteMidQEntry; | 760 | midQ->callback = DeleteMidQEntry; |
| 759 | spin_unlock(&GlobalMid_Lock); | 761 | spin_unlock(&GlobalMid_Lock); |
| 760 | add_credits(ses->server, 1, optype); | 762 | add_credits(ses->server, 1, optype); |
diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c index 02a7a9286449..6d6eca394d4d 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c | |||
| @@ -327,7 +327,6 @@ EXPORT_SYMBOL(fscrypt_decrypt_page); | |||
| 327 | static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags) | 327 | static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags) |
| 328 | { | 328 | { |
| 329 | struct dentry *dir; | 329 | struct dentry *dir; |
| 330 | struct fscrypt_info *ci; | ||
| 331 | int dir_has_key, cached_with_key; | 330 | int dir_has_key, cached_with_key; |
| 332 | 331 | ||
| 333 | if (flags & LOOKUP_RCU) | 332 | if (flags & LOOKUP_RCU) |
| @@ -339,18 +338,11 @@ static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags) | |||
| 339 | return 0; | 338 | return 0; |
| 340 | } | 339 | } |
| 341 | 340 | ||
| 342 | ci = d_inode(dir)->i_crypt_info; | ||
| 343 | if (ci && ci->ci_keyring_key && | ||
| 344 | (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) | | ||
| 345 | (1 << KEY_FLAG_REVOKED) | | ||
| 346 | (1 << KEY_FLAG_DEAD)))) | ||
| 347 | ci = NULL; | ||
| 348 | |||
| 349 | /* this should eventually be an flag in d_flags */ | 341 | /* this should eventually be an flag in d_flags */ |
| 350 | spin_lock(&dentry->d_lock); | 342 | spin_lock(&dentry->d_lock); |
| 351 | cached_with_key = dentry->d_flags & DCACHE_ENCRYPTED_WITH_KEY; | 343 | cached_with_key = dentry->d_flags & DCACHE_ENCRYPTED_WITH_KEY; |
| 352 | spin_unlock(&dentry->d_lock); | 344 | spin_unlock(&dentry->d_lock); |
| 353 | dir_has_key = (ci != NULL); | 345 | dir_has_key = (d_inode(dir)->i_crypt_info != NULL); |
| 354 | dput(dir); | 346 | dput(dir); |
| 355 | 347 | ||
| 356 | /* | 348 | /* |
diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c index 13052b85c393..37b49894c762 100644 --- a/fs/crypto/fname.c +++ b/fs/crypto/fname.c | |||
| @@ -350,7 +350,7 @@ int fscrypt_setup_filename(struct inode *dir, const struct qstr *iname, | |||
| 350 | fname->disk_name.len = iname->len; | 350 | fname->disk_name.len = iname->len; |
| 351 | return 0; | 351 | return 0; |
| 352 | } | 352 | } |
| 353 | ret = fscrypt_get_crypt_info(dir); | 353 | ret = fscrypt_get_encryption_info(dir); |
| 354 | if (ret && ret != -EOPNOTSUPP) | 354 | if (ret && ret != -EOPNOTSUPP) |
| 355 | return ret; | 355 | return ret; |
| 356 | 356 | ||
diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h index fdbb8af32eaf..e39696e64494 100644 --- a/fs/crypto/fscrypt_private.h +++ b/fs/crypto/fscrypt_private.h | |||
| @@ -67,7 +67,6 @@ struct fscrypt_info { | |||
| 67 | u8 ci_filename_mode; | 67 | u8 ci_filename_mode; |
| 68 | u8 ci_flags; | 68 | u8 ci_flags; |
| 69 | struct crypto_skcipher *ci_ctfm; | 69 | struct crypto_skcipher *ci_ctfm; |
| 70 | struct key *ci_keyring_key; | ||
| 71 | u8 ci_master_key[FS_KEY_DESCRIPTOR_SIZE]; | 70 | u8 ci_master_key[FS_KEY_DESCRIPTOR_SIZE]; |
| 72 | }; | 71 | }; |
| 73 | 72 | ||
| @@ -101,7 +100,4 @@ extern int fscrypt_do_page_crypto(const struct inode *inode, | |||
| 101 | extern struct page *fscrypt_alloc_bounce_page(struct fscrypt_ctx *ctx, | 100 | extern struct page *fscrypt_alloc_bounce_page(struct fscrypt_ctx *ctx, |
| 102 | gfp_t gfp_flags); | 101 | gfp_t gfp_flags); |
| 103 | 102 | ||
| 104 | /* keyinfo.c */ | ||
| 105 | extern int fscrypt_get_crypt_info(struct inode *); | ||
| 106 | |||
| 107 | #endif /* _FSCRYPT_PRIVATE_H */ | 103 | #endif /* _FSCRYPT_PRIVATE_H */ |
diff --git a/fs/crypto/keyinfo.c b/fs/crypto/keyinfo.c index d5d896fa5a71..8cdfddce2b34 100644 --- a/fs/crypto/keyinfo.c +++ b/fs/crypto/keyinfo.c | |||
| @@ -95,6 +95,7 @@ static int validate_user_key(struct fscrypt_info *crypt_info, | |||
| 95 | kfree(description); | 95 | kfree(description); |
| 96 | if (IS_ERR(keyring_key)) | 96 | if (IS_ERR(keyring_key)) |
| 97 | return PTR_ERR(keyring_key); | 97 | return PTR_ERR(keyring_key); |
| 98 | down_read(&keyring_key->sem); | ||
| 98 | 99 | ||
| 99 | if (keyring_key->type != &key_type_logon) { | 100 | if (keyring_key->type != &key_type_logon) { |
| 100 | printk_once(KERN_WARNING | 101 | printk_once(KERN_WARNING |
| @@ -102,11 +103,9 @@ static int validate_user_key(struct fscrypt_info *crypt_info, | |||
| 102 | res = -ENOKEY; | 103 | res = -ENOKEY; |
| 103 | goto out; | 104 | goto out; |
| 104 | } | 105 | } |
| 105 | down_read(&keyring_key->sem); | ||
| 106 | ukp = user_key_payload_locked(keyring_key); | 106 | ukp = user_key_payload_locked(keyring_key); |
| 107 | if (ukp->datalen != sizeof(struct fscrypt_key)) { | 107 | if (ukp->datalen != sizeof(struct fscrypt_key)) { |
| 108 | res = -EINVAL; | 108 | res = -EINVAL; |
| 109 | up_read(&keyring_key->sem); | ||
| 110 | goto out; | 109 | goto out; |
| 111 | } | 110 | } |
| 112 | master_key = (struct fscrypt_key *)ukp->data; | 111 | master_key = (struct fscrypt_key *)ukp->data; |
| @@ -117,17 +116,11 @@ static int validate_user_key(struct fscrypt_info *crypt_info, | |||
| 117 | "%s: key size incorrect: %d\n", | 116 | "%s: key size incorrect: %d\n", |
| 118 | __func__, master_key->size); | 117 | __func__, master_key->size); |
| 119 | res = -ENOKEY; | 118 | res = -ENOKEY; |
| 120 | up_read(&keyring_key->sem); | ||
| 121 | goto out; | 119 | goto out; |
| 122 | } | 120 | } |
| 123 | res = derive_key_aes(ctx->nonce, master_key->raw, raw_key); | 121 | res = derive_key_aes(ctx->nonce, master_key->raw, raw_key); |
| 124 | up_read(&keyring_key->sem); | ||
| 125 | if (res) | ||
| 126 | goto out; | ||
| 127 | |||
| 128 | crypt_info->ci_keyring_key = keyring_key; | ||
| 129 | return 0; | ||
| 130 | out: | 122 | out: |
| 123 | up_read(&keyring_key->sem); | ||
| 131 | key_put(keyring_key); | 124 | key_put(keyring_key); |
| 132 | return res; | 125 | return res; |
| 133 | } | 126 | } |
| @@ -169,12 +162,11 @@ static void put_crypt_info(struct fscrypt_info *ci) | |||
| 169 | if (!ci) | 162 | if (!ci) |
| 170 | return; | 163 | return; |
| 171 | 164 | ||
| 172 | key_put(ci->ci_keyring_key); | ||
| 173 | crypto_free_skcipher(ci->ci_ctfm); | 165 | crypto_free_skcipher(ci->ci_ctfm); |
| 174 | kmem_cache_free(fscrypt_info_cachep, ci); | 166 | kmem_cache_free(fscrypt_info_cachep, ci); |
| 175 | } | 167 | } |
| 176 | 168 | ||
| 177 | int fscrypt_get_crypt_info(struct inode *inode) | 169 | int fscrypt_get_encryption_info(struct inode *inode) |
| 178 | { | 170 | { |
| 179 | struct fscrypt_info *crypt_info; | 171 | struct fscrypt_info *crypt_info; |
| 180 | struct fscrypt_context ctx; | 172 | struct fscrypt_context ctx; |
| @@ -184,21 +176,15 @@ int fscrypt_get_crypt_info(struct inode *inode) | |||
| 184 | u8 *raw_key = NULL; | 176 | u8 *raw_key = NULL; |
| 185 | int res; | 177 | int res; |
| 186 | 178 | ||
| 179 | if (inode->i_crypt_info) | ||
| 180 | return 0; | ||
| 181 | |||
| 187 | res = fscrypt_initialize(inode->i_sb->s_cop->flags); | 182 | res = fscrypt_initialize(inode->i_sb->s_cop->flags); |
| 188 | if (res) | 183 | if (res) |
| 189 | return res; | 184 | return res; |
| 190 | 185 | ||
| 191 | if (!inode->i_sb->s_cop->get_context) | 186 | if (!inode->i_sb->s_cop->get_context) |
| 192 | return -EOPNOTSUPP; | 187 | return -EOPNOTSUPP; |
| 193 | retry: | ||
| 194 | crypt_info = ACCESS_ONCE(inode->i_crypt_info); | ||
| 195 | if (crypt_info) { | ||
| 196 | if (!crypt_info->ci_keyring_key || | ||
| 197 | key_validate(crypt_info->ci_keyring_key) == 0) | ||
| 198 | return 0; | ||
| 199 | fscrypt_put_encryption_info(inode, crypt_info); | ||
| 200 | goto retry; | ||
| 201 | } | ||
| 202 | 188 | ||
| 203 | res = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx)); | 189 | res = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx)); |
| 204 | if (res < 0) { | 190 | if (res < 0) { |
| @@ -229,7 +215,6 @@ retry: | |||
| 229 | crypt_info->ci_data_mode = ctx.contents_encryption_mode; | 215 | crypt_info->ci_data_mode = ctx.contents_encryption_mode; |
| 230 | crypt_info->ci_filename_mode = ctx.filenames_encryption_mode; | 216 | crypt_info->ci_filename_mode = ctx.filenames_encryption_mode; |
| 231 | crypt_info->ci_ctfm = NULL; | 217 | crypt_info->ci_ctfm = NULL; |
| 232 | crypt_info->ci_keyring_key = NULL; | ||
| 233 | memcpy(crypt_info->ci_master_key, ctx.master_key_descriptor, | 218 | memcpy(crypt_info->ci_master_key, ctx.master_key_descriptor, |
| 234 | sizeof(crypt_info->ci_master_key)); | 219 | sizeof(crypt_info->ci_master_key)); |
| 235 | 220 | ||
| @@ -273,14 +258,8 @@ retry: | |||
| 273 | if (res) | 258 | if (res) |
| 274 | goto out; | 259 | goto out; |
| 275 | 260 | ||
| 276 | kzfree(raw_key); | 261 | if (cmpxchg(&inode->i_crypt_info, NULL, crypt_info) == NULL) |
| 277 | raw_key = NULL; | 262 | crypt_info = NULL; |
| 278 | if (cmpxchg(&inode->i_crypt_info, NULL, crypt_info) != NULL) { | ||
| 279 | put_crypt_info(crypt_info); | ||
| 280 | goto retry; | ||
| 281 | } | ||
| 282 | return 0; | ||
| 283 | |||
| 284 | out: | 263 | out: |
| 285 | if (res == -ENOKEY) | 264 | if (res == -ENOKEY) |
| 286 | res = 0; | 265 | res = 0; |
| @@ -288,6 +267,7 @@ out: | |||
| 288 | kzfree(raw_key); | 267 | kzfree(raw_key); |
| 289 | return res; | 268 | return res; |
| 290 | } | 269 | } |
| 270 | EXPORT_SYMBOL(fscrypt_get_encryption_info); | ||
| 291 | 271 | ||
| 292 | void fscrypt_put_encryption_info(struct inode *inode, struct fscrypt_info *ci) | 272 | void fscrypt_put_encryption_info(struct inode *inode, struct fscrypt_info *ci) |
| 293 | { | 273 | { |
| @@ -305,17 +285,3 @@ void fscrypt_put_encryption_info(struct inode *inode, struct fscrypt_info *ci) | |||
| 305 | put_crypt_info(ci); | 285 | put_crypt_info(ci); |
| 306 | } | 286 | } |
| 307 | EXPORT_SYMBOL(fscrypt_put_encryption_info); | 287 | EXPORT_SYMBOL(fscrypt_put_encryption_info); |
| 308 | |||
| 309 | int fscrypt_get_encryption_info(struct inode *inode) | ||
| 310 | { | ||
| 311 | struct fscrypt_info *ci = inode->i_crypt_info; | ||
| 312 | |||
| 313 | if (!ci || | ||
| 314 | (ci->ci_keyring_key && | ||
| 315 | (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) | | ||
| 316 | (1 << KEY_FLAG_REVOKED) | | ||
| 317 | (1 << KEY_FLAG_DEAD))))) | ||
| 318 | return fscrypt_get_crypt_info(inode); | ||
| 319 | return 0; | ||
| 320 | } | ||
| 321 | EXPORT_SYMBOL(fscrypt_get_encryption_info); | ||
diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c index 14b76da71269..4908906d54d5 100644 --- a/fs/crypto/policy.c +++ b/fs/crypto/policy.c | |||
| @@ -33,17 +33,10 @@ static int create_encryption_context_from_policy(struct inode *inode, | |||
| 33 | const struct fscrypt_policy *policy) | 33 | const struct fscrypt_policy *policy) |
| 34 | { | 34 | { |
| 35 | struct fscrypt_context ctx; | 35 | struct fscrypt_context ctx; |
| 36 | int res; | ||
| 37 | 36 | ||
| 38 | if (!inode->i_sb->s_cop->set_context) | 37 | if (!inode->i_sb->s_cop->set_context) |
| 39 | return -EOPNOTSUPP; | 38 | return -EOPNOTSUPP; |
| 40 | 39 | ||
| 41 | if (inode->i_sb->s_cop->prepare_context) { | ||
| 42 | res = inode->i_sb->s_cop->prepare_context(inode); | ||
| 43 | if (res) | ||
| 44 | return res; | ||
| 45 | } | ||
| 46 | |||
| 47 | ctx.format = FS_ENCRYPTION_CONTEXT_FORMAT_V1; | 40 | ctx.format = FS_ENCRYPTION_CONTEXT_FORMAT_V1; |
| 48 | memcpy(ctx.master_key_descriptor, policy->master_key_descriptor, | 41 | memcpy(ctx.master_key_descriptor, policy->master_key_descriptor, |
| 49 | FS_KEY_DESCRIPTOR_SIZE); | 42 | FS_KEY_DESCRIPTOR_SIZE); |
| @@ -373,6 +373,22 @@ restart: | |||
| 373 | } | 373 | } |
| 374 | spin_lock_irq(&mapping->tree_lock); | 374 | spin_lock_irq(&mapping->tree_lock); |
| 375 | 375 | ||
| 376 | if (!entry) { | ||
| 377 | /* | ||
| 378 | * We needed to drop the page_tree lock while calling | ||
| 379 | * radix_tree_preload() and we didn't have an entry to | ||
| 380 | * lock. See if another thread inserted an entry at | ||
| 381 | * our index during this time. | ||
| 382 | */ | ||
| 383 | entry = __radix_tree_lookup(&mapping->page_tree, index, | ||
| 384 | NULL, &slot); | ||
| 385 | if (entry) { | ||
| 386 | radix_tree_preload_end(); | ||
| 387 | spin_unlock_irq(&mapping->tree_lock); | ||
| 388 | goto restart; | ||
| 389 | } | ||
| 390 | } | ||
| 391 | |||
| 376 | if (pmd_downgrade) { | 392 | if (pmd_downgrade) { |
| 377 | radix_tree_delete(&mapping->page_tree, index); | 393 | radix_tree_delete(&mapping->page_tree, index); |
| 378 | mapping->nrexceptional--; | 394 | mapping->nrexceptional--; |
| @@ -388,19 +404,12 @@ restart: | |||
| 388 | if (err) { | 404 | if (err) { |
| 389 | spin_unlock_irq(&mapping->tree_lock); | 405 | spin_unlock_irq(&mapping->tree_lock); |
| 390 | /* | 406 | /* |
| 391 | * Someone already created the entry? This is a | 407 | * Our insertion of a DAX entry failed, most likely |
| 392 | * normal failure when inserting PMDs in a range | 408 | * because we were inserting a PMD entry and it |
| 393 | * that already contains PTEs. In that case we want | 409 | * collided with a PTE sized entry at a different |
| 394 | * to return -EEXIST immediately. | 410 | * index in the PMD range. We haven't inserted |
| 395 | */ | 411 | * anything into the radix tree and have no waiters to |
| 396 | if (err == -EEXIST && !(size_flag & RADIX_DAX_PMD)) | 412 | * wake. |
| 397 | goto restart; | ||
| 398 | /* | ||
| 399 | * Our insertion of a DAX PMD entry failed, most | ||
| 400 | * likely because it collided with a PTE sized entry | ||
| 401 | * at a different index in the PMD range. We haven't | ||
| 402 | * inserted anything into the radix tree and have no | ||
| 403 | * waiters to wake. | ||
| 404 | */ | 413 | */ |
| 405 | return ERR_PTR(err); | 414 | return ERR_PTR(err); |
| 406 | } | 415 | } |
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index f493af666591..fb69ee2388db 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
| @@ -2466,6 +2466,7 @@ extern int ext4_setattr(struct dentry *, struct iattr *); | |||
| 2466 | extern int ext4_getattr(const struct path *, struct kstat *, u32, unsigned int); | 2466 | extern int ext4_getattr(const struct path *, struct kstat *, u32, unsigned int); |
| 2467 | extern void ext4_evict_inode(struct inode *); | 2467 | extern void ext4_evict_inode(struct inode *); |
| 2468 | extern void ext4_clear_inode(struct inode *); | 2468 | extern void ext4_clear_inode(struct inode *); |
| 2469 | extern int ext4_file_getattr(const struct path *, struct kstat *, u32, unsigned int); | ||
| 2469 | extern int ext4_sync_inode(handle_t *, struct inode *); | 2470 | extern int ext4_sync_inode(handle_t *, struct inode *); |
| 2470 | extern void ext4_dirty_inode(struct inode *, int); | 2471 | extern void ext4_dirty_inode(struct inode *, int); |
| 2471 | extern int ext4_change_inode_journal_flag(struct inode *, int); | 2472 | extern int ext4_change_inode_journal_flag(struct inode *, int); |
diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 8210c1f43556..cefa9835f275 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c | |||
| @@ -744,7 +744,7 @@ const struct file_operations ext4_file_operations = { | |||
| 744 | 744 | ||
| 745 | const struct inode_operations ext4_file_inode_operations = { | 745 | const struct inode_operations ext4_file_inode_operations = { |
| 746 | .setattr = ext4_setattr, | 746 | .setattr = ext4_setattr, |
| 747 | .getattr = ext4_getattr, | 747 | .getattr = ext4_file_getattr, |
| 748 | .listxattr = ext4_listxattr, | 748 | .listxattr = ext4_listxattr, |
| 749 | .get_acl = ext4_get_acl, | 749 | .get_acl = ext4_get_acl, |
| 750 | .set_acl = ext4_set_acl, | 750 | .set_acl = ext4_set_acl, |
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 30a9f210d1e3..375fb1c05d49 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c | |||
| @@ -1169,10 +1169,9 @@ static int ext4_finish_convert_inline_dir(handle_t *handle, | |||
| 1169 | set_buffer_uptodate(dir_block); | 1169 | set_buffer_uptodate(dir_block); |
| 1170 | err = ext4_handle_dirty_dirent_node(handle, inode, dir_block); | 1170 | err = ext4_handle_dirty_dirent_node(handle, inode, dir_block); |
| 1171 | if (err) | 1171 | if (err) |
| 1172 | goto out; | 1172 | return err; |
| 1173 | set_buffer_verified(dir_block); | 1173 | set_buffer_verified(dir_block); |
| 1174 | out: | 1174 | return ext4_mark_inode_dirty(handle, inode); |
| 1175 | return err; | ||
| 1176 | } | 1175 | } |
| 1177 | 1176 | ||
| 1178 | static int ext4_convert_inline_data_nolock(handle_t *handle, | 1177 | static int ext4_convert_inline_data_nolock(handle_t *handle, |
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 7385e6a6b6cb..b9ffa9f4191f 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
| @@ -5390,17 +5390,52 @@ err_out: | |||
| 5390 | int ext4_getattr(const struct path *path, struct kstat *stat, | 5390 | int ext4_getattr(const struct path *path, struct kstat *stat, |
| 5391 | u32 request_mask, unsigned int query_flags) | 5391 | u32 request_mask, unsigned int query_flags) |
| 5392 | { | 5392 | { |
| 5393 | struct inode *inode; | 5393 | struct inode *inode = d_inode(path->dentry); |
| 5394 | unsigned long long delalloc_blocks; | 5394 | struct ext4_inode *raw_inode; |
| 5395 | struct ext4_inode_info *ei = EXT4_I(inode); | ||
| 5396 | unsigned int flags; | ||
| 5397 | |||
| 5398 | if (EXT4_FITS_IN_INODE(raw_inode, ei, i_crtime)) { | ||
| 5399 | stat->result_mask |= STATX_BTIME; | ||
| 5400 | stat->btime.tv_sec = ei->i_crtime.tv_sec; | ||
| 5401 | stat->btime.tv_nsec = ei->i_crtime.tv_nsec; | ||
| 5402 | } | ||
| 5403 | |||
| 5404 | flags = ei->i_flags & EXT4_FL_USER_VISIBLE; | ||
| 5405 | if (flags & EXT4_APPEND_FL) | ||
| 5406 | stat->attributes |= STATX_ATTR_APPEND; | ||
| 5407 | if (flags & EXT4_COMPR_FL) | ||
| 5408 | stat->attributes |= STATX_ATTR_COMPRESSED; | ||
| 5409 | if (flags & EXT4_ENCRYPT_FL) | ||
| 5410 | stat->attributes |= STATX_ATTR_ENCRYPTED; | ||
| 5411 | if (flags & EXT4_IMMUTABLE_FL) | ||
| 5412 | stat->attributes |= STATX_ATTR_IMMUTABLE; | ||
| 5413 | if (flags & EXT4_NODUMP_FL) | ||
| 5414 | stat->attributes |= STATX_ATTR_NODUMP; | ||
| 5415 | |||
| 5416 | stat->attributes_mask |= (STATX_ATTR_APPEND | | ||
| 5417 | STATX_ATTR_COMPRESSED | | ||
| 5418 | STATX_ATTR_ENCRYPTED | | ||
| 5419 | STATX_ATTR_IMMUTABLE | | ||
| 5420 | STATX_ATTR_NODUMP); | ||
| 5395 | 5421 | ||
| 5396 | inode = d_inode(path->dentry); | ||
| 5397 | generic_fillattr(inode, stat); | 5422 | generic_fillattr(inode, stat); |
| 5423 | return 0; | ||
| 5424 | } | ||
| 5425 | |||
| 5426 | int ext4_file_getattr(const struct path *path, struct kstat *stat, | ||
| 5427 | u32 request_mask, unsigned int query_flags) | ||
| 5428 | { | ||
| 5429 | struct inode *inode = d_inode(path->dentry); | ||
| 5430 | u64 delalloc_blocks; | ||
| 5431 | |||
| 5432 | ext4_getattr(path, stat, request_mask, query_flags); | ||
| 5398 | 5433 | ||
| 5399 | /* | 5434 | /* |
| 5400 | * If there is inline data in the inode, the inode will normally not | 5435 | * If there is inline data in the inode, the inode will normally not |
| 5401 | * have data blocks allocated (it may have an external xattr block). | 5436 | * have data blocks allocated (it may have an external xattr block). |
| 5402 | * Report at least one sector for such files, so tools like tar, rsync, | 5437 | * Report at least one sector for such files, so tools like tar, rsync, |
| 5403 | * others doen't incorrectly think the file is completely sparse. | 5438 | * others don't incorrectly think the file is completely sparse. |
| 5404 | */ | 5439 | */ |
| 5405 | if (unlikely(ext4_has_inline_data(inode))) | 5440 | if (unlikely(ext4_has_inline_data(inode))) |
| 5406 | stat->blocks += (stat->size + 511) >> 9; | 5441 | stat->blocks += (stat->size + 511) >> 9; |
diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 578f8c33fb44..c992ef2c2f94 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c | |||
| @@ -511,7 +511,7 @@ mext_check_arguments(struct inode *orig_inode, | |||
| 511 | if ((orig_start & ~(PAGE_MASK >> orig_inode->i_blkbits)) != | 511 | if ((orig_start & ~(PAGE_MASK >> orig_inode->i_blkbits)) != |
| 512 | (donor_start & ~(PAGE_MASK >> orig_inode->i_blkbits))) { | 512 | (donor_start & ~(PAGE_MASK >> orig_inode->i_blkbits))) { |
| 513 | ext4_debug("ext4 move extent: orig and donor's start " | 513 | ext4_debug("ext4 move extent: orig and donor's start " |
| 514 | "offset are not alligned [ino:orig %lu, donor %lu]\n", | 514 | "offsets are not aligned [ino:orig %lu, donor %lu]\n", |
| 515 | orig_inode->i_ino, donor_inode->i_ino); | 515 | orig_inode->i_ino, donor_inode->i_ino); |
| 516 | return -EINVAL; | 516 | return -EINVAL; |
| 517 | } | 517 | } |
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 6ad612c576fc..07e5e1405771 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c | |||
| @@ -3912,6 +3912,7 @@ const struct inode_operations ext4_dir_inode_operations = { | |||
| 3912 | .tmpfile = ext4_tmpfile, | 3912 | .tmpfile = ext4_tmpfile, |
| 3913 | .rename = ext4_rename2, | 3913 | .rename = ext4_rename2, |
| 3914 | .setattr = ext4_setattr, | 3914 | .setattr = ext4_setattr, |
| 3915 | .getattr = ext4_getattr, | ||
| 3915 | .listxattr = ext4_listxattr, | 3916 | .listxattr = ext4_listxattr, |
| 3916 | .get_acl = ext4_get_acl, | 3917 | .get_acl = ext4_get_acl, |
| 3917 | .set_acl = ext4_set_acl, | 3918 | .set_acl = ext4_set_acl, |
| @@ -3920,6 +3921,7 @@ const struct inode_operations ext4_dir_inode_operations = { | |||
| 3920 | 3921 | ||
| 3921 | const struct inode_operations ext4_special_inode_operations = { | 3922 | const struct inode_operations ext4_special_inode_operations = { |
| 3922 | .setattr = ext4_setattr, | 3923 | .setattr = ext4_setattr, |
| 3924 | .getattr = ext4_getattr, | ||
| 3923 | .listxattr = ext4_listxattr, | 3925 | .listxattr = ext4_listxattr, |
| 3924 | .get_acl = ext4_get_acl, | 3926 | .get_acl = ext4_get_acl, |
| 3925 | .set_acl = ext4_set_acl, | 3927 | .set_acl = ext4_set_acl, |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 2e03a0a88d92..a9448db1cf7e 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
| @@ -1120,17 +1120,16 @@ static int ext4_get_context(struct inode *inode, void *ctx, size_t len) | |||
| 1120 | EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, ctx, len); | 1120 | EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, ctx, len); |
| 1121 | } | 1121 | } |
| 1122 | 1122 | ||
| 1123 | static int ext4_prepare_context(struct inode *inode) | ||
| 1124 | { | ||
| 1125 | return ext4_convert_inline_data(inode); | ||
| 1126 | } | ||
| 1127 | |||
| 1128 | static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, | 1123 | static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, |
| 1129 | void *fs_data) | 1124 | void *fs_data) |
| 1130 | { | 1125 | { |
| 1131 | handle_t *handle = fs_data; | 1126 | handle_t *handle = fs_data; |
| 1132 | int res, res2, retries = 0; | 1127 | int res, res2, retries = 0; |
| 1133 | 1128 | ||
| 1129 | res = ext4_convert_inline_data(inode); | ||
| 1130 | if (res) | ||
| 1131 | return res; | ||
| 1132 | |||
| 1134 | /* | 1133 | /* |
| 1135 | * If a journal handle was specified, then the encryption context is | 1134 | * If a journal handle was specified, then the encryption context is |
| 1136 | * being set on a new inode via inheritance and is part of a larger | 1135 | * being set on a new inode via inheritance and is part of a larger |
| @@ -1196,7 +1195,6 @@ static unsigned ext4_max_namelen(struct inode *inode) | |||
| 1196 | static const struct fscrypt_operations ext4_cryptops = { | 1195 | static const struct fscrypt_operations ext4_cryptops = { |
| 1197 | .key_prefix = "ext4:", | 1196 | .key_prefix = "ext4:", |
| 1198 | .get_context = ext4_get_context, | 1197 | .get_context = ext4_get_context, |
| 1199 | .prepare_context = ext4_prepare_context, | ||
| 1200 | .set_context = ext4_set_context, | 1198 | .set_context = ext4_set_context, |
| 1201 | .dummy_context = ext4_dummy_context, | 1199 | .dummy_context = ext4_dummy_context, |
| 1202 | .is_encrypted = ext4_encrypted_inode, | 1200 | .is_encrypted = ext4_encrypted_inode, |
diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c index 73b184d161fc..5c8fc53cb0e5 100644 --- a/fs/ext4/symlink.c +++ b/fs/ext4/symlink.c | |||
| @@ -85,17 +85,20 @@ errout: | |||
| 85 | const struct inode_operations ext4_encrypted_symlink_inode_operations = { | 85 | const struct inode_operations ext4_encrypted_symlink_inode_operations = { |
| 86 | .get_link = ext4_encrypted_get_link, | 86 | .get_link = ext4_encrypted_get_link, |
| 87 | .setattr = ext4_setattr, | 87 | .setattr = ext4_setattr, |
| 88 | .getattr = ext4_getattr, | ||
| 88 | .listxattr = ext4_listxattr, | 89 | .listxattr = ext4_listxattr, |
| 89 | }; | 90 | }; |
| 90 | 91 | ||
| 91 | const struct inode_operations ext4_symlink_inode_operations = { | 92 | const struct inode_operations ext4_symlink_inode_operations = { |
| 92 | .get_link = page_get_link, | 93 | .get_link = page_get_link, |
| 93 | .setattr = ext4_setattr, | 94 | .setattr = ext4_setattr, |
| 95 | .getattr = ext4_getattr, | ||
| 94 | .listxattr = ext4_listxattr, | 96 | .listxattr = ext4_listxattr, |
| 95 | }; | 97 | }; |
| 96 | 98 | ||
| 97 | const struct inode_operations ext4_fast_symlink_inode_operations = { | 99 | const struct inode_operations ext4_fast_symlink_inode_operations = { |
| 98 | .get_link = simple_get_link, | 100 | .get_link = simple_get_link, |
| 99 | .setattr = ext4_setattr, | 101 | .setattr = ext4_setattr, |
| 102 | .getattr = ext4_getattr, | ||
| 100 | .listxattr = ext4_listxattr, | 103 | .listxattr = ext4_listxattr, |
| 101 | }; | 104 | }; |
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 67636acf7624..996e7900d4c8 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c | |||
| @@ -131,31 +131,26 @@ static __le32 ext4_xattr_block_csum(struct inode *inode, | |||
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | static int ext4_xattr_block_csum_verify(struct inode *inode, | 133 | static int ext4_xattr_block_csum_verify(struct inode *inode, |
| 134 | sector_t block_nr, | 134 | struct buffer_head *bh) |
| 135 | struct ext4_xattr_header *hdr) | ||
| 136 | { | 135 | { |
| 137 | if (ext4_has_metadata_csum(inode->i_sb) && | 136 | struct ext4_xattr_header *hdr = BHDR(bh); |
| 138 | (hdr->h_checksum != ext4_xattr_block_csum(inode, block_nr, hdr))) | 137 | int ret = 1; |
| 139 | return 0; | ||
| 140 | return 1; | ||
| 141 | } | ||
| 142 | |||
| 143 | static void ext4_xattr_block_csum_set(struct inode *inode, | ||
| 144 | sector_t block_nr, | ||
| 145 | struct ext4_xattr_header *hdr) | ||
| 146 | { | ||
| 147 | if (!ext4_has_metadata_csum(inode->i_sb)) | ||
| 148 | return; | ||
| 149 | 138 | ||
| 150 | hdr->h_checksum = ext4_xattr_block_csum(inode, block_nr, hdr); | 139 | if (ext4_has_metadata_csum(inode->i_sb)) { |
| 140 | lock_buffer(bh); | ||
| 141 | ret = (hdr->h_checksum == ext4_xattr_block_csum(inode, | ||
| 142 | bh->b_blocknr, hdr)); | ||
| 143 | unlock_buffer(bh); | ||
| 144 | } | ||
| 145 | return ret; | ||
| 151 | } | 146 | } |
| 152 | 147 | ||
| 153 | static inline int ext4_handle_dirty_xattr_block(handle_t *handle, | 148 | static void ext4_xattr_block_csum_set(struct inode *inode, |
| 154 | struct inode *inode, | 149 | struct buffer_head *bh) |
| 155 | struct buffer_head *bh) | ||
| 156 | { | 150 | { |
| 157 | ext4_xattr_block_csum_set(inode, bh->b_blocknr, BHDR(bh)); | 151 | if (ext4_has_metadata_csum(inode->i_sb)) |
| 158 | return ext4_handle_dirty_metadata(handle, inode, bh); | 152 | BHDR(bh)->h_checksum = ext4_xattr_block_csum(inode, |
| 153 | bh->b_blocknr, BHDR(bh)); | ||
| 159 | } | 154 | } |
| 160 | 155 | ||
| 161 | static inline const struct xattr_handler * | 156 | static inline const struct xattr_handler * |
| @@ -233,7 +228,7 @@ ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh) | |||
| 233 | if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) || | 228 | if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) || |
| 234 | BHDR(bh)->h_blocks != cpu_to_le32(1)) | 229 | BHDR(bh)->h_blocks != cpu_to_le32(1)) |
| 235 | return -EFSCORRUPTED; | 230 | return -EFSCORRUPTED; |
| 236 | if (!ext4_xattr_block_csum_verify(inode, bh->b_blocknr, BHDR(bh))) | 231 | if (!ext4_xattr_block_csum_verify(inode, bh)) |
| 237 | return -EFSBADCRC; | 232 | return -EFSBADCRC; |
| 238 | error = ext4_xattr_check_names(BFIRST(bh), bh->b_data + bh->b_size, | 233 | error = ext4_xattr_check_names(BFIRST(bh), bh->b_data + bh->b_size, |
| 239 | bh->b_data); | 234 | bh->b_data); |
| @@ -618,23 +613,22 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode, | |||
| 618 | } | 613 | } |
| 619 | } | 614 | } |
| 620 | 615 | ||
| 616 | ext4_xattr_block_csum_set(inode, bh); | ||
| 621 | /* | 617 | /* |
| 622 | * Beware of this ugliness: Releasing of xattr block references | 618 | * Beware of this ugliness: Releasing of xattr block references |
| 623 | * from different inodes can race and so we have to protect | 619 | * from different inodes can race and so we have to protect |
| 624 | * from a race where someone else frees the block (and releases | 620 | * from a race where someone else frees the block (and releases |
| 625 | * its journal_head) before we are done dirtying the buffer. In | 621 | * its journal_head) before we are done dirtying the buffer. In |
| 626 | * nojournal mode this race is harmless and we actually cannot | 622 | * nojournal mode this race is harmless and we actually cannot |
| 627 | * call ext4_handle_dirty_xattr_block() with locked buffer as | 623 | * call ext4_handle_dirty_metadata() with locked buffer as |
| 628 | * that function can call sync_dirty_buffer() so for that case | 624 | * that function can call sync_dirty_buffer() so for that case |
| 629 | * we handle the dirtying after unlocking the buffer. | 625 | * we handle the dirtying after unlocking the buffer. |
| 630 | */ | 626 | */ |
| 631 | if (ext4_handle_valid(handle)) | 627 | if (ext4_handle_valid(handle)) |
| 632 | error = ext4_handle_dirty_xattr_block(handle, inode, | 628 | error = ext4_handle_dirty_metadata(handle, inode, bh); |
| 633 | bh); | ||
| 634 | unlock_buffer(bh); | 629 | unlock_buffer(bh); |
| 635 | if (!ext4_handle_valid(handle)) | 630 | if (!ext4_handle_valid(handle)) |
| 636 | error = ext4_handle_dirty_xattr_block(handle, inode, | 631 | error = ext4_handle_dirty_metadata(handle, inode, bh); |
| 637 | bh); | ||
| 638 | if (IS_SYNC(inode)) | 632 | if (IS_SYNC(inode)) |
| 639 | ext4_handle_sync(handle); | 633 | ext4_handle_sync(handle); |
| 640 | dquot_free_block(inode, EXT4_C2B(EXT4_SB(inode->i_sb), 1)); | 634 | dquot_free_block(inode, EXT4_C2B(EXT4_SB(inode->i_sb), 1)); |
| @@ -863,13 +857,14 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, | |||
| 863 | ext4_xattr_cache_insert(ext4_mb_cache, | 857 | ext4_xattr_cache_insert(ext4_mb_cache, |
| 864 | bs->bh); | 858 | bs->bh); |
| 865 | } | 859 | } |
| 860 | ext4_xattr_block_csum_set(inode, bs->bh); | ||
| 866 | unlock_buffer(bs->bh); | 861 | unlock_buffer(bs->bh); |
| 867 | if (error == -EFSCORRUPTED) | 862 | if (error == -EFSCORRUPTED) |
| 868 | goto bad_block; | 863 | goto bad_block; |
| 869 | if (!error) | 864 | if (!error) |
| 870 | error = ext4_handle_dirty_xattr_block(handle, | 865 | error = ext4_handle_dirty_metadata(handle, |
| 871 | inode, | 866 | inode, |
| 872 | bs->bh); | 867 | bs->bh); |
| 873 | if (error) | 868 | if (error) |
| 874 | goto cleanup; | 869 | goto cleanup; |
| 875 | goto inserted; | 870 | goto inserted; |
| @@ -967,10 +962,11 @@ inserted: | |||
| 967 | ce->e_reusable = 0; | 962 | ce->e_reusable = 0; |
| 968 | ea_bdebug(new_bh, "reusing; refcount now=%d", | 963 | ea_bdebug(new_bh, "reusing; refcount now=%d", |
| 969 | ref); | 964 | ref); |
| 965 | ext4_xattr_block_csum_set(inode, new_bh); | ||
| 970 | unlock_buffer(new_bh); | 966 | unlock_buffer(new_bh); |
| 971 | error = ext4_handle_dirty_xattr_block(handle, | 967 | error = ext4_handle_dirty_metadata(handle, |
| 972 | inode, | 968 | inode, |
| 973 | new_bh); | 969 | new_bh); |
| 974 | if (error) | 970 | if (error) |
| 975 | goto cleanup_dquot; | 971 | goto cleanup_dquot; |
| 976 | } | 972 | } |
| @@ -1020,11 +1016,12 @@ getblk_failed: | |||
| 1020 | goto getblk_failed; | 1016 | goto getblk_failed; |
| 1021 | } | 1017 | } |
| 1022 | memcpy(new_bh->b_data, s->base, new_bh->b_size); | 1018 | memcpy(new_bh->b_data, s->base, new_bh->b_size); |
| 1019 | ext4_xattr_block_csum_set(inode, new_bh); | ||
| 1023 | set_buffer_uptodate(new_bh); | 1020 | set_buffer_uptodate(new_bh); |
| 1024 | unlock_buffer(new_bh); | 1021 | unlock_buffer(new_bh); |
| 1025 | ext4_xattr_cache_insert(ext4_mb_cache, new_bh); | 1022 | ext4_xattr_cache_insert(ext4_mb_cache, new_bh); |
| 1026 | error = ext4_handle_dirty_xattr_block(handle, | 1023 | error = ext4_handle_dirty_metadata(handle, inode, |
| 1027 | inode, new_bh); | 1024 | new_bh); |
| 1028 | if (error) | 1025 | if (error) |
| 1029 | goto cleanup; | 1026 | goto cleanup; |
| 1030 | } | 1027 | } |
diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index a77df377e2e8..ee2d0a485fc3 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c | |||
| @@ -196,6 +196,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi) | |||
| 196 | si->base_mem += (NM_I(sbi)->nat_bits_blocks << F2FS_BLKSIZE_BITS); | 196 | si->base_mem += (NM_I(sbi)->nat_bits_blocks << F2FS_BLKSIZE_BITS); |
| 197 | si->base_mem += NM_I(sbi)->nat_blocks * NAT_ENTRY_BITMAP_SIZE; | 197 | si->base_mem += NM_I(sbi)->nat_blocks * NAT_ENTRY_BITMAP_SIZE; |
| 198 | si->base_mem += NM_I(sbi)->nat_blocks / 8; | 198 | si->base_mem += NM_I(sbi)->nat_blocks / 8; |
| 199 | si->base_mem += NM_I(sbi)->nat_blocks * sizeof(unsigned short); | ||
| 199 | 200 | ||
| 200 | get_cache: | 201 | get_cache: |
| 201 | si->cache_mem = 0; | 202 | si->cache_mem = 0; |
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 4650c9b85de7..8d5c62b07b28 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c | |||
| @@ -750,7 +750,7 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, | |||
| 750 | dentry_blk = page_address(page); | 750 | dentry_blk = page_address(page); |
| 751 | bit_pos = dentry - dentry_blk->dentry; | 751 | bit_pos = dentry - dentry_blk->dentry; |
| 752 | for (i = 0; i < slots; i++) | 752 | for (i = 0; i < slots; i++) |
| 753 | clear_bit_le(bit_pos + i, &dentry_blk->dentry_bitmap); | 753 | __clear_bit_le(bit_pos + i, &dentry_blk->dentry_bitmap); |
| 754 | 754 | ||
| 755 | /* Let's check and deallocate this dentry page */ | 755 | /* Let's check and deallocate this dentry page */ |
| 756 | bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap, | 756 | bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap, |
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index e849f83d6114..0a6e115562f6 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h | |||
| @@ -561,6 +561,8 @@ struct f2fs_nm_info { | |||
| 561 | struct mutex build_lock; /* lock for build free nids */ | 561 | struct mutex build_lock; /* lock for build free nids */ |
| 562 | unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; | 562 | unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; |
| 563 | unsigned char *nat_block_bitmap; | 563 | unsigned char *nat_block_bitmap; |
| 564 | unsigned short *free_nid_count; /* free nid count of NAT block */ | ||
| 565 | spinlock_t free_nid_lock; /* protect updating of nid count */ | ||
| 564 | 566 | ||
| 565 | /* for checkpoint */ | 567 | /* for checkpoint */ |
| 566 | char *nat_bitmap; /* NAT bitmap pointer */ | 568 | char *nat_bitmap; /* NAT bitmap pointer */ |
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 94967171dee8..481aa8dc79f4 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c | |||
| @@ -338,9 +338,6 @@ static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni, | |||
| 338 | set_nat_flag(e, IS_CHECKPOINTED, false); | 338 | set_nat_flag(e, IS_CHECKPOINTED, false); |
| 339 | __set_nat_cache_dirty(nm_i, e); | 339 | __set_nat_cache_dirty(nm_i, e); |
| 340 | 340 | ||
| 341 | if (enabled_nat_bits(sbi, NULL) && new_blkaddr == NEW_ADDR) | ||
| 342 | clear_bit_le(NAT_BLOCK_OFFSET(ni->nid), nm_i->empty_nat_bits); | ||
| 343 | |||
| 344 | /* update fsync_mark if its inode nat entry is still alive */ | 341 | /* update fsync_mark if its inode nat entry is still alive */ |
| 345 | if (ni->nid != ni->ino) | 342 | if (ni->nid != ni->ino) |
| 346 | e = __lookup_nat_cache(nm_i, ni->ino); | 343 | e = __lookup_nat_cache(nm_i, ni->ino); |
| @@ -1823,7 +1820,8 @@ static void remove_free_nid(struct f2fs_sb_info *sbi, nid_t nid) | |||
| 1823 | kmem_cache_free(free_nid_slab, i); | 1820 | kmem_cache_free(free_nid_slab, i); |
| 1824 | } | 1821 | } |
| 1825 | 1822 | ||
| 1826 | void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid, bool set) | 1823 | static void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid, |
| 1824 | bool set, bool build, bool locked) | ||
| 1827 | { | 1825 | { |
| 1828 | struct f2fs_nm_info *nm_i = NM_I(sbi); | 1826 | struct f2fs_nm_info *nm_i = NM_I(sbi); |
| 1829 | unsigned int nat_ofs = NAT_BLOCK_OFFSET(nid); | 1827 | unsigned int nat_ofs = NAT_BLOCK_OFFSET(nid); |
| @@ -1833,9 +1831,18 @@ void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid, bool set) | |||
| 1833 | return; | 1831 | return; |
| 1834 | 1832 | ||
| 1835 | if (set) | 1833 | if (set) |
| 1836 | set_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]); | 1834 | __set_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]); |
| 1837 | else | 1835 | else |
| 1838 | clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]); | 1836 | __clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]); |
| 1837 | |||
| 1838 | if (!locked) | ||
| 1839 | spin_lock(&nm_i->free_nid_lock); | ||
| 1840 | if (set) | ||
| 1841 | nm_i->free_nid_count[nat_ofs]++; | ||
| 1842 | else if (!build) | ||
| 1843 | nm_i->free_nid_count[nat_ofs]--; | ||
| 1844 | if (!locked) | ||
| 1845 | spin_unlock(&nm_i->free_nid_lock); | ||
| 1839 | } | 1846 | } |
| 1840 | 1847 | ||
| 1841 | static void scan_nat_page(struct f2fs_sb_info *sbi, | 1848 | static void scan_nat_page(struct f2fs_sb_info *sbi, |
| @@ -1847,7 +1854,10 @@ static void scan_nat_page(struct f2fs_sb_info *sbi, | |||
| 1847 | unsigned int nat_ofs = NAT_BLOCK_OFFSET(start_nid); | 1854 | unsigned int nat_ofs = NAT_BLOCK_OFFSET(start_nid); |
| 1848 | int i; | 1855 | int i; |
| 1849 | 1856 | ||
| 1850 | set_bit_le(nat_ofs, nm_i->nat_block_bitmap); | 1857 | if (test_bit_le(nat_ofs, nm_i->nat_block_bitmap)) |
| 1858 | return; | ||
| 1859 | |||
| 1860 | __set_bit_le(nat_ofs, nm_i->nat_block_bitmap); | ||
| 1851 | 1861 | ||
| 1852 | i = start_nid % NAT_ENTRY_PER_BLOCK; | 1862 | i = start_nid % NAT_ENTRY_PER_BLOCK; |
| 1853 | 1863 | ||
| @@ -1861,7 +1871,7 @@ static void scan_nat_page(struct f2fs_sb_info *sbi, | |||
| 1861 | f2fs_bug_on(sbi, blk_addr == NEW_ADDR); | 1871 | f2fs_bug_on(sbi, blk_addr == NEW_ADDR); |
| 1862 | if (blk_addr == NULL_ADDR) | 1872 | if (blk_addr == NULL_ADDR) |
| 1863 | freed = add_free_nid(sbi, start_nid, true); | 1873 | freed = add_free_nid(sbi, start_nid, true); |
| 1864 | update_free_nid_bitmap(sbi, start_nid, freed); | 1874 | update_free_nid_bitmap(sbi, start_nid, freed, true, false); |
| 1865 | } | 1875 | } |
| 1866 | } | 1876 | } |
| 1867 | 1877 | ||
| @@ -1877,6 +1887,8 @@ static void scan_free_nid_bits(struct f2fs_sb_info *sbi) | |||
| 1877 | for (i = 0; i < nm_i->nat_blocks; i++) { | 1887 | for (i = 0; i < nm_i->nat_blocks; i++) { |
| 1878 | if (!test_bit_le(i, nm_i->nat_block_bitmap)) | 1888 | if (!test_bit_le(i, nm_i->nat_block_bitmap)) |
| 1879 | continue; | 1889 | continue; |
| 1890 | if (!nm_i->free_nid_count[i]) | ||
| 1891 | continue; | ||
| 1880 | for (idx = 0; idx < NAT_ENTRY_PER_BLOCK; idx++) { | 1892 | for (idx = 0; idx < NAT_ENTRY_PER_BLOCK; idx++) { |
| 1881 | nid_t nid; | 1893 | nid_t nid; |
| 1882 | 1894 | ||
| @@ -1907,58 +1919,6 @@ out: | |||
| 1907 | up_read(&nm_i->nat_tree_lock); | 1919 | up_read(&nm_i->nat_tree_lock); |
| 1908 | } | 1920 | } |
| 1909 | 1921 | ||
| 1910 | static int scan_nat_bits(struct f2fs_sb_info *sbi) | ||
| 1911 | { | ||
| 1912 | struct f2fs_nm_info *nm_i = NM_I(sbi); | ||
| 1913 | struct page *page; | ||
| 1914 | unsigned int i = 0; | ||
| 1915 | nid_t nid; | ||
| 1916 | |||
| 1917 | if (!enabled_nat_bits(sbi, NULL)) | ||
| 1918 | return -EAGAIN; | ||
| 1919 | |||
| 1920 | down_read(&nm_i->nat_tree_lock); | ||
| 1921 | check_empty: | ||
| 1922 | i = find_next_bit_le(nm_i->empty_nat_bits, nm_i->nat_blocks, i); | ||
| 1923 | if (i >= nm_i->nat_blocks) { | ||
| 1924 | i = 0; | ||
| 1925 | goto check_partial; | ||
| 1926 | } | ||
| 1927 | |||
| 1928 | for (nid = i * NAT_ENTRY_PER_BLOCK; nid < (i + 1) * NAT_ENTRY_PER_BLOCK; | ||
| 1929 | nid++) { | ||
| 1930 | if (unlikely(nid >= nm_i->max_nid)) | ||
| 1931 | break; | ||
| 1932 | add_free_nid(sbi, nid, true); | ||
| 1933 | } | ||
| 1934 | |||
| 1935 | if (nm_i->nid_cnt[FREE_NID_LIST] >= MAX_FREE_NIDS) | ||
| 1936 | goto out; | ||
| 1937 | i++; | ||
| 1938 | goto check_empty; | ||
| 1939 | |||
| 1940 | check_partial: | ||
| 1941 | i = find_next_zero_bit_le(nm_i->full_nat_bits, nm_i->nat_blocks, i); | ||
| 1942 | if (i >= nm_i->nat_blocks) { | ||
| 1943 | disable_nat_bits(sbi, true); | ||
| 1944 | up_read(&nm_i->nat_tree_lock); | ||
| 1945 | return -EINVAL; | ||
| 1946 | } | ||
| 1947 | |||
| 1948 | nid = i * NAT_ENTRY_PER_BLOCK; | ||
| 1949 | page = get_current_nat_page(sbi, nid); | ||
| 1950 | scan_nat_page(sbi, page, nid); | ||
| 1951 | f2fs_put_page(page, 1); | ||
| 1952 | |||
| 1953 | if (nm_i->nid_cnt[FREE_NID_LIST] < MAX_FREE_NIDS) { | ||
| 1954 | i++; | ||
| 1955 | goto check_partial; | ||
| 1956 | } | ||
| 1957 | out: | ||
| 1958 | up_read(&nm_i->nat_tree_lock); | ||
| 1959 | return 0; | ||
| 1960 | } | ||
| 1961 | |||
| 1962 | static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) | 1922 | static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) |
| 1963 | { | 1923 | { |
| 1964 | struct f2fs_nm_info *nm_i = NM_I(sbi); | 1924 | struct f2fs_nm_info *nm_i = NM_I(sbi); |
| @@ -1980,21 +1940,6 @@ static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) | |||
| 1980 | 1940 | ||
| 1981 | if (nm_i->nid_cnt[FREE_NID_LIST]) | 1941 | if (nm_i->nid_cnt[FREE_NID_LIST]) |
| 1982 | return; | 1942 | return; |
| 1983 | |||
| 1984 | /* try to find free nids with nat_bits */ | ||
| 1985 | if (!scan_nat_bits(sbi) && nm_i->nid_cnt[FREE_NID_LIST]) | ||
| 1986 | return; | ||
| 1987 | } | ||
| 1988 | |||
| 1989 | /* find next valid candidate */ | ||
| 1990 | if (enabled_nat_bits(sbi, NULL)) { | ||
| 1991 | int idx = find_next_zero_bit_le(nm_i->full_nat_bits, | ||
| 1992 | nm_i->nat_blocks, 0); | ||
| 1993 | |||
| 1994 | if (idx >= nm_i->nat_blocks) | ||
| 1995 | set_sbi_flag(sbi, SBI_NEED_FSCK); | ||
| 1996 | else | ||
| 1997 | nid = idx * NAT_ENTRY_PER_BLOCK; | ||
| 1998 | } | 1943 | } |
| 1999 | 1944 | ||
| 2000 | /* readahead nat pages to be scanned */ | 1945 | /* readahead nat pages to be scanned */ |
| @@ -2081,7 +2026,7 @@ retry: | |||
| 2081 | __insert_nid_to_list(sbi, i, ALLOC_NID_LIST, false); | 2026 | __insert_nid_to_list(sbi, i, ALLOC_NID_LIST, false); |
| 2082 | nm_i->available_nids--; | 2027 | nm_i->available_nids--; |
| 2083 | 2028 | ||
| 2084 | update_free_nid_bitmap(sbi, *nid, false); | 2029 | update_free_nid_bitmap(sbi, *nid, false, false, false); |
| 2085 | 2030 | ||
| 2086 | spin_unlock(&nm_i->nid_list_lock); | 2031 | spin_unlock(&nm_i->nid_list_lock); |
| 2087 | return true; | 2032 | return true; |
| @@ -2137,7 +2082,7 @@ void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid) | |||
| 2137 | 2082 | ||
| 2138 | nm_i->available_nids++; | 2083 | nm_i->available_nids++; |
| 2139 | 2084 | ||
| 2140 | update_free_nid_bitmap(sbi, nid, true); | 2085 | update_free_nid_bitmap(sbi, nid, true, false, false); |
| 2141 | 2086 | ||
| 2142 | spin_unlock(&nm_i->nid_list_lock); | 2087 | spin_unlock(&nm_i->nid_list_lock); |
| 2143 | 2088 | ||
| @@ -2383,7 +2328,7 @@ add_out: | |||
| 2383 | list_add_tail(&nes->set_list, head); | 2328 | list_add_tail(&nes->set_list, head); |
| 2384 | } | 2329 | } |
| 2385 | 2330 | ||
| 2386 | void __update_nat_bits(struct f2fs_sb_info *sbi, nid_t start_nid, | 2331 | static void __update_nat_bits(struct f2fs_sb_info *sbi, nid_t start_nid, |
| 2387 | struct page *page) | 2332 | struct page *page) |
| 2388 | { | 2333 | { |
| 2389 | struct f2fs_nm_info *nm_i = NM_I(sbi); | 2334 | struct f2fs_nm_info *nm_i = NM_I(sbi); |
| @@ -2402,16 +2347,16 @@ void __update_nat_bits(struct f2fs_sb_info *sbi, nid_t start_nid, | |||
| 2402 | valid++; | 2347 | valid++; |
| 2403 | } | 2348 | } |
| 2404 | if (valid == 0) { | 2349 | if (valid == 0) { |
| 2405 | set_bit_le(nat_index, nm_i->empty_nat_bits); | 2350 | __set_bit_le(nat_index, nm_i->empty_nat_bits); |
| 2406 | clear_bit_le(nat_index, nm_i->full_nat_bits); | 2351 | __clear_bit_le(nat_index, nm_i->full_nat_bits); |
| 2407 | return; | 2352 | return; |
| 2408 | } | 2353 | } |
| 2409 | 2354 | ||
| 2410 | clear_bit_le(nat_index, nm_i->empty_nat_bits); | 2355 | __clear_bit_le(nat_index, nm_i->empty_nat_bits); |
| 2411 | if (valid == NAT_ENTRY_PER_BLOCK) | 2356 | if (valid == NAT_ENTRY_PER_BLOCK) |
| 2412 | set_bit_le(nat_index, nm_i->full_nat_bits); | 2357 | __set_bit_le(nat_index, nm_i->full_nat_bits); |
| 2413 | else | 2358 | else |
| 2414 | clear_bit_le(nat_index, nm_i->full_nat_bits); | 2359 | __clear_bit_le(nat_index, nm_i->full_nat_bits); |
| 2415 | } | 2360 | } |
| 2416 | 2361 | ||
| 2417 | static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, | 2362 | static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, |
| @@ -2467,11 +2412,11 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, | |||
| 2467 | add_free_nid(sbi, nid, false); | 2412 | add_free_nid(sbi, nid, false); |
| 2468 | spin_lock(&NM_I(sbi)->nid_list_lock); | 2413 | spin_lock(&NM_I(sbi)->nid_list_lock); |
| 2469 | NM_I(sbi)->available_nids++; | 2414 | NM_I(sbi)->available_nids++; |
| 2470 | update_free_nid_bitmap(sbi, nid, true); | 2415 | update_free_nid_bitmap(sbi, nid, true, false, false); |
| 2471 | spin_unlock(&NM_I(sbi)->nid_list_lock); | 2416 | spin_unlock(&NM_I(sbi)->nid_list_lock); |
| 2472 | } else { | 2417 | } else { |
| 2473 | spin_lock(&NM_I(sbi)->nid_list_lock); | 2418 | spin_lock(&NM_I(sbi)->nid_list_lock); |
| 2474 | update_free_nid_bitmap(sbi, nid, false); | 2419 | update_free_nid_bitmap(sbi, nid, false, false, false); |
| 2475 | spin_unlock(&NM_I(sbi)->nid_list_lock); | 2420 | spin_unlock(&NM_I(sbi)->nid_list_lock); |
| 2476 | } | 2421 | } |
| 2477 | } | 2422 | } |
| @@ -2577,6 +2522,40 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) | |||
| 2577 | return 0; | 2522 | return 0; |
| 2578 | } | 2523 | } |
| 2579 | 2524 | ||
| 2525 | inline void load_free_nid_bitmap(struct f2fs_sb_info *sbi) | ||
| 2526 | { | ||
| 2527 | struct f2fs_nm_info *nm_i = NM_I(sbi); | ||
| 2528 | unsigned int i = 0; | ||
| 2529 | nid_t nid, last_nid; | ||
| 2530 | |||
| 2531 | if (!enabled_nat_bits(sbi, NULL)) | ||
| 2532 | return; | ||
| 2533 | |||
| 2534 | for (i = 0; i < nm_i->nat_blocks; i++) { | ||
| 2535 | i = find_next_bit_le(nm_i->empty_nat_bits, nm_i->nat_blocks, i); | ||
| 2536 | if (i >= nm_i->nat_blocks) | ||
| 2537 | break; | ||
| 2538 | |||
| 2539 | __set_bit_le(i, nm_i->nat_block_bitmap); | ||
| 2540 | |||
| 2541 | nid = i * NAT_ENTRY_PER_BLOCK; | ||
| 2542 | last_nid = (i + 1) * NAT_ENTRY_PER_BLOCK; | ||
| 2543 | |||
| 2544 | spin_lock(&nm_i->free_nid_lock); | ||
| 2545 | for (; nid < last_nid; nid++) | ||
| 2546 | update_free_nid_bitmap(sbi, nid, true, true, true); | ||
| 2547 | spin_unlock(&nm_i->free_nid_lock); | ||
| 2548 | } | ||
| 2549 | |||
| 2550 | for (i = 0; i < nm_i->nat_blocks; i++) { | ||
| 2551 | i = find_next_bit_le(nm_i->full_nat_bits, nm_i->nat_blocks, i); | ||
| 2552 | if (i >= nm_i->nat_blocks) | ||
| 2553 | break; | ||
| 2554 | |||
| 2555 | __set_bit_le(i, nm_i->nat_block_bitmap); | ||
| 2556 | } | ||
| 2557 | } | ||
| 2558 | |||
| 2580 | static int init_node_manager(struct f2fs_sb_info *sbi) | 2559 | static int init_node_manager(struct f2fs_sb_info *sbi) |
| 2581 | { | 2560 | { |
| 2582 | struct f2fs_super_block *sb_raw = F2FS_RAW_SUPER(sbi); | 2561 | struct f2fs_super_block *sb_raw = F2FS_RAW_SUPER(sbi); |
| @@ -2638,7 +2617,7 @@ static int init_node_manager(struct f2fs_sb_info *sbi) | |||
| 2638 | return 0; | 2617 | return 0; |
| 2639 | } | 2618 | } |
| 2640 | 2619 | ||
| 2641 | int init_free_nid_cache(struct f2fs_sb_info *sbi) | 2620 | static int init_free_nid_cache(struct f2fs_sb_info *sbi) |
| 2642 | { | 2621 | { |
| 2643 | struct f2fs_nm_info *nm_i = NM_I(sbi); | 2622 | struct f2fs_nm_info *nm_i = NM_I(sbi); |
| 2644 | 2623 | ||
| @@ -2651,6 +2630,14 @@ int init_free_nid_cache(struct f2fs_sb_info *sbi) | |||
| 2651 | GFP_KERNEL); | 2630 | GFP_KERNEL); |
| 2652 | if (!nm_i->nat_block_bitmap) | 2631 | if (!nm_i->nat_block_bitmap) |
| 2653 | return -ENOMEM; | 2632 | return -ENOMEM; |
| 2633 | |||
| 2634 | nm_i->free_nid_count = f2fs_kvzalloc(nm_i->nat_blocks * | ||
| 2635 | sizeof(unsigned short), GFP_KERNEL); | ||
| 2636 | if (!nm_i->free_nid_count) | ||
| 2637 | return -ENOMEM; | ||
| 2638 | |||
| 2639 | spin_lock_init(&nm_i->free_nid_lock); | ||
| 2640 | |||
| 2654 | return 0; | 2641 | return 0; |
| 2655 | } | 2642 | } |
| 2656 | 2643 | ||
| @@ -2670,6 +2657,9 @@ int build_node_manager(struct f2fs_sb_info *sbi) | |||
| 2670 | if (err) | 2657 | if (err) |
| 2671 | return err; | 2658 | return err; |
| 2672 | 2659 | ||
| 2660 | /* load free nid status from nat_bits table */ | ||
| 2661 | load_free_nid_bitmap(sbi); | ||
| 2662 | |||
| 2673 | build_free_nids(sbi, true, true); | 2663 | build_free_nids(sbi, true, true); |
| 2674 | return 0; | 2664 | return 0; |
| 2675 | } | 2665 | } |
| @@ -2730,6 +2720,7 @@ void destroy_node_manager(struct f2fs_sb_info *sbi) | |||
| 2730 | 2720 | ||
| 2731 | kvfree(nm_i->nat_block_bitmap); | 2721 | kvfree(nm_i->nat_block_bitmap); |
| 2732 | kvfree(nm_i->free_nid_bitmap); | 2722 | kvfree(nm_i->free_nid_bitmap); |
| 2723 | kvfree(nm_i->free_nid_count); | ||
| 2733 | 2724 | ||
| 2734 | kfree(nm_i->nat_bitmap); | 2725 | kfree(nm_i->nat_bitmap); |
| 2735 | kfree(nm_i->nat_bits); | 2726 | kfree(nm_i->nat_bits); |
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 4bd7a8b19332..29ef7088c558 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c | |||
| @@ -1163,6 +1163,12 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) | |||
| 1163 | if (f2fs_discard_en(sbi) && | 1163 | if (f2fs_discard_en(sbi) && |
| 1164 | !f2fs_test_and_set_bit(offset, se->discard_map)) | 1164 | !f2fs_test_and_set_bit(offset, se->discard_map)) |
| 1165 | sbi->discard_blks--; | 1165 | sbi->discard_blks--; |
| 1166 | |||
| 1167 | /* don't overwrite by SSR to keep node chain */ | ||
| 1168 | if (se->type == CURSEG_WARM_NODE) { | ||
| 1169 | if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map)) | ||
| 1170 | se->ckpt_valid_blocks++; | ||
| 1171 | } | ||
| 1166 | } else { | 1172 | } else { |
| 1167 | if (!f2fs_test_and_clear_bit(offset, se->cur_valid_map)) { | 1173 | if (!f2fs_test_and_clear_bit(offset, se->cur_valid_map)) { |
| 1168 | #ifdef CONFIG_F2FS_CHECK_FS | 1174 | #ifdef CONFIG_F2FS_CHECK_FS |
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 8f96461236f6..dde861387a40 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c | |||
| @@ -136,17 +136,26 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) | |||
| 136 | vma->vm_flags |= VM_HUGETLB | VM_DONTEXPAND; | 136 | vma->vm_flags |= VM_HUGETLB | VM_DONTEXPAND; |
| 137 | vma->vm_ops = &hugetlb_vm_ops; | 137 | vma->vm_ops = &hugetlb_vm_ops; |
| 138 | 138 | ||
| 139 | /* | ||
| 140 | * Offset passed to mmap (before page shift) could have been | ||
| 141 | * negative when represented as a (l)off_t. | ||
| 142 | */ | ||
| 143 | if (((loff_t)vma->vm_pgoff << PAGE_SHIFT) < 0) | ||
| 144 | return -EINVAL; | ||
| 145 | |||
| 139 | if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT)) | 146 | if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT)) |
| 140 | return -EINVAL; | 147 | return -EINVAL; |
| 141 | 148 | ||
| 142 | vma_len = (loff_t)(vma->vm_end - vma->vm_start); | 149 | vma_len = (loff_t)(vma->vm_end - vma->vm_start); |
| 150 | len = vma_len + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); | ||
| 151 | /* check for overflow */ | ||
| 152 | if (len < vma_len) | ||
| 153 | return -EINVAL; | ||
| 143 | 154 | ||
| 144 | inode_lock(inode); | 155 | inode_lock(inode); |
| 145 | file_accessed(file); | 156 | file_accessed(file); |
| 146 | 157 | ||
| 147 | ret = -ENOMEM; | 158 | ret = -ENOMEM; |
| 148 | len = vma_len + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); | ||
| 149 | |||
| 150 | if (hugetlb_reserve_pages(inode, | 159 | if (hugetlb_reserve_pages(inode, |
| 151 | vma->vm_pgoff >> huge_page_order(h), | 160 | vma->vm_pgoff >> huge_page_order(h), |
| 152 | len >> huge_page_shift(h), vma, | 161 | len >> huge_page_shift(h), vma, |
| @@ -155,7 +164,7 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) | |||
| 155 | 164 | ||
| 156 | ret = 0; | 165 | ret = 0; |
| 157 | if (vma->vm_flags & VM_WRITE && inode->i_size < len) | 166 | if (vma->vm_flags & VM_WRITE && inode->i_size < len) |
| 158 | inode->i_size = len; | 167 | i_size_write(inode, len); |
| 159 | out: | 168 | out: |
| 160 | inode_unlock(inode); | 169 | inode_unlock(inode); |
| 161 | 170 | ||
| @@ -695,14 +704,11 @@ static struct inode *hugetlbfs_get_root(struct super_block *sb, | |||
| 695 | 704 | ||
| 696 | inode = new_inode(sb); | 705 | inode = new_inode(sb); |
| 697 | if (inode) { | 706 | if (inode) { |
| 698 | struct hugetlbfs_inode_info *info; | ||
| 699 | inode->i_ino = get_next_ino(); | 707 | inode->i_ino = get_next_ino(); |
| 700 | inode->i_mode = S_IFDIR | config->mode; | 708 | inode->i_mode = S_IFDIR | config->mode; |
| 701 | inode->i_uid = config->uid; | 709 | inode->i_uid = config->uid; |
| 702 | inode->i_gid = config->gid; | 710 | inode->i_gid = config->gid; |
| 703 | inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); | 711 | inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); |
| 704 | info = HUGETLBFS_I(inode); | ||
| 705 | mpol_shared_policy_init(&info->policy, NULL); | ||
| 706 | inode->i_op = &hugetlbfs_dir_inode_operations; | 712 | inode->i_op = &hugetlbfs_dir_inode_operations; |
| 707 | inode->i_fop = &simple_dir_operations; | 713 | inode->i_fop = &simple_dir_operations; |
| 708 | /* directory inodes start off with i_nlink == 2 (for "." entry) */ | 714 | /* directory inodes start off with i_nlink == 2 (for "." entry) */ |
| @@ -733,7 +739,6 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb, | |||
| 733 | 739 | ||
| 734 | inode = new_inode(sb); | 740 | inode = new_inode(sb); |
| 735 | if (inode) { | 741 | if (inode) { |
| 736 | struct hugetlbfs_inode_info *info; | ||
| 737 | inode->i_ino = get_next_ino(); | 742 | inode->i_ino = get_next_ino(); |
| 738 | inode_init_owner(inode, dir, mode); | 743 | inode_init_owner(inode, dir, mode); |
| 739 | lockdep_set_class(&inode->i_mapping->i_mmap_rwsem, | 744 | lockdep_set_class(&inode->i_mapping->i_mmap_rwsem, |
| @@ -741,15 +746,6 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb, | |||
| 741 | inode->i_mapping->a_ops = &hugetlbfs_aops; | 746 | inode->i_mapping->a_ops = &hugetlbfs_aops; |
| 742 | inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); | 747 | inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); |
| 743 | inode->i_mapping->private_data = resv_map; | 748 | inode->i_mapping->private_data = resv_map; |
| 744 | info = HUGETLBFS_I(inode); | ||
| 745 | /* | ||
| 746 | * The policy is initialized here even if we are creating a | ||
| 747 | * private inode because initialization simply creates an | ||
| 748 | * an empty rb tree and calls rwlock_init(), later when we | ||
| 749 | * call mpol_free_shared_policy() it will just return because | ||
| 750 | * the rb tree will still be empty. | ||
| 751 | */ | ||
| 752 | mpol_shared_policy_init(&info->policy, NULL); | ||
| 753 | switch (mode & S_IFMT) { | 749 | switch (mode & S_IFMT) { |
| 754 | default: | 750 | default: |
| 755 | init_special_inode(inode, mode, dev); | 751 | init_special_inode(inode, mode, dev); |
| @@ -937,6 +933,18 @@ static struct inode *hugetlbfs_alloc_inode(struct super_block *sb) | |||
| 937 | hugetlbfs_inc_free_inodes(sbinfo); | 933 | hugetlbfs_inc_free_inodes(sbinfo); |
| 938 | return NULL; | 934 | return NULL; |
| 939 | } | 935 | } |
| 936 | |||
| 937 | /* | ||
| 938 | * Any time after allocation, hugetlbfs_destroy_inode can be called | ||
| 939 | * for the inode. mpol_free_shared_policy is unconditionally called | ||
| 940 | * as part of hugetlbfs_destroy_inode. So, initialize policy here | ||
| 941 | * in case of a quick call to destroy. | ||
| 942 | * | ||
| 943 | * Note that the policy is initialized even if we are creating a | ||
| 944 | * private inode. This simplifies hugetlbfs_destroy_inode. | ||
| 945 | */ | ||
| 946 | mpol_shared_policy_init(&p->policy, NULL); | ||
| 947 | |||
| 940 | return &p->vfs_inode; | 948 | return &p->vfs_inode; |
| 941 | } | 949 | } |
| 942 | 950 | ||
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index a1a359bfcc9c..5adc2fb62b0f 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c | |||
| @@ -1125,10 +1125,8 @@ static journal_t *journal_init_common(struct block_device *bdev, | |||
| 1125 | 1125 | ||
| 1126 | /* Set up a default-sized revoke table for the new mount. */ | 1126 | /* Set up a default-sized revoke table for the new mount. */ |
| 1127 | err = jbd2_journal_init_revoke(journal, JOURNAL_REVOKE_DEFAULT_HASH); | 1127 | err = jbd2_journal_init_revoke(journal, JOURNAL_REVOKE_DEFAULT_HASH); |
| 1128 | if (err) { | 1128 | if (err) |
| 1129 | kfree(journal); | 1129 | goto err_cleanup; |
| 1130 | return NULL; | ||
| 1131 | } | ||
| 1132 | 1130 | ||
| 1133 | spin_lock_init(&journal->j_history_lock); | 1131 | spin_lock_init(&journal->j_history_lock); |
| 1134 | 1132 | ||
| @@ -1145,23 +1143,25 @@ static journal_t *journal_init_common(struct block_device *bdev, | |||
| 1145 | journal->j_wbufsize = n; | 1143 | journal->j_wbufsize = n; |
| 1146 | journal->j_wbuf = kmalloc_array(n, sizeof(struct buffer_head *), | 1144 | journal->j_wbuf = kmalloc_array(n, sizeof(struct buffer_head *), |
| 1147 | GFP_KERNEL); | 1145 | GFP_KERNEL); |
| 1148 | if (!journal->j_wbuf) { | 1146 | if (!journal->j_wbuf) |
| 1149 | kfree(journal); | 1147 | goto err_cleanup; |
| 1150 | return NULL; | ||
| 1151 | } | ||
| 1152 | 1148 | ||
| 1153 | bh = getblk_unmovable(journal->j_dev, start, journal->j_blocksize); | 1149 | bh = getblk_unmovable(journal->j_dev, start, journal->j_blocksize); |
| 1154 | if (!bh) { | 1150 | if (!bh) { |
| 1155 | pr_err("%s: Cannot get buffer for journal superblock\n", | 1151 | pr_err("%s: Cannot get buffer for journal superblock\n", |
| 1156 | __func__); | 1152 | __func__); |
| 1157 | kfree(journal->j_wbuf); | 1153 | goto err_cleanup; |
| 1158 | kfree(journal); | ||
| 1159 | return NULL; | ||
| 1160 | } | 1154 | } |
| 1161 | journal->j_sb_buffer = bh; | 1155 | journal->j_sb_buffer = bh; |
| 1162 | journal->j_superblock = (journal_superblock_t *)bh->b_data; | 1156 | journal->j_superblock = (journal_superblock_t *)bh->b_data; |
| 1163 | 1157 | ||
| 1164 | return journal; | 1158 | return journal; |
| 1159 | |||
| 1160 | err_cleanup: | ||
| 1161 | kfree(journal->j_wbuf); | ||
| 1162 | jbd2_journal_destroy_revoke(journal); | ||
| 1163 | kfree(journal); | ||
| 1164 | return NULL; | ||
| 1165 | } | 1165 | } |
| 1166 | 1166 | ||
| 1167 | /* jbd2_journal_init_dev and jbd2_journal_init_inode: | 1167 | /* jbd2_journal_init_dev and jbd2_journal_init_inode: |
diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c index cfc38b552118..f9aefcda5854 100644 --- a/fs/jbd2/revoke.c +++ b/fs/jbd2/revoke.c | |||
| @@ -280,6 +280,7 @@ int jbd2_journal_init_revoke(journal_t *journal, int hash_size) | |||
| 280 | 280 | ||
| 281 | fail1: | 281 | fail1: |
| 282 | jbd2_journal_destroy_revoke_table(journal->j_revoke_table[0]); | 282 | jbd2_journal_destroy_revoke_table(journal->j_revoke_table[0]); |
| 283 | journal->j_revoke_table[0] = NULL; | ||
| 283 | fail0: | 284 | fail0: |
| 284 | return -ENOMEM; | 285 | return -ENOMEM; |
| 285 | } | 286 | } |
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c index 8e4dc7ab584c..ac2dfe0c5a9c 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c | |||
| @@ -809,7 +809,8 @@ void kernfs_drain_open_files(struct kernfs_node *kn) | |||
| 809 | if (kn->flags & KERNFS_HAS_MMAP) | 809 | if (kn->flags & KERNFS_HAS_MMAP) |
| 810 | unmap_mapping_range(inode->i_mapping, 0, 0, 1); | 810 | unmap_mapping_range(inode->i_mapping, 0, 0, 1); |
| 811 | 811 | ||
| 812 | kernfs_release_file(kn, of); | 812 | if (kn->flags & KERNFS_HAS_RELEASE) |
| 813 | kernfs_release_file(kn, of); | ||
| 813 | } | 814 | } |
| 814 | 815 | ||
| 815 | mutex_unlock(&kernfs_open_file_mutex); | 816 | mutex_unlock(&kernfs_open_file_mutex); |
diff --git a/fs/namei.c b/fs/namei.c index d41fab78798b..19dcf62133cc 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
| @@ -2145,6 +2145,9 @@ static const char *path_init(struct nameidata *nd, unsigned flags) | |||
| 2145 | int retval = 0; | 2145 | int retval = 0; |
| 2146 | const char *s = nd->name->name; | 2146 | const char *s = nd->name->name; |
| 2147 | 2147 | ||
| 2148 | if (!*s) | ||
| 2149 | flags &= ~LOOKUP_RCU; | ||
| 2150 | |||
| 2148 | nd->last_type = LAST_ROOT; /* if there are only slashes... */ | 2151 | nd->last_type = LAST_ROOT; /* if there are only slashes... */ |
| 2149 | nd->flags = flags | LOOKUP_JUMPED | LOOKUP_PARENT; | 2152 | nd->flags = flags | LOOKUP_JUMPED | LOOKUP_PARENT; |
| 2150 | nd->depth = 0; | 2153 | nd->depth = 0; |
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index fb499a3f21b5..f92ba8d6c556 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c | |||
| @@ -2055,7 +2055,7 @@ int nfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
| 2055 | { | 2055 | { |
| 2056 | struct inode *old_inode = d_inode(old_dentry); | 2056 | struct inode *old_inode = d_inode(old_dentry); |
| 2057 | struct inode *new_inode = d_inode(new_dentry); | 2057 | struct inode *new_inode = d_inode(new_dentry); |
| 2058 | struct dentry *dentry = NULL, *rehash = NULL; | 2058 | struct dentry *dentry = NULL; |
| 2059 | struct rpc_task *task; | 2059 | struct rpc_task *task; |
| 2060 | int error = -EBUSY; | 2060 | int error = -EBUSY; |
| 2061 | 2061 | ||
| @@ -2078,10 +2078,8 @@ int nfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
| 2078 | * To prevent any new references to the target during the | 2078 | * To prevent any new references to the target during the |
| 2079 | * rename, we unhash the dentry in advance. | 2079 | * rename, we unhash the dentry in advance. |
| 2080 | */ | 2080 | */ |
| 2081 | if (!d_unhashed(new_dentry)) { | 2081 | if (!d_unhashed(new_dentry)) |
| 2082 | d_drop(new_dentry); | 2082 | d_drop(new_dentry); |
| 2083 | rehash = new_dentry; | ||
| 2084 | } | ||
| 2085 | 2083 | ||
| 2086 | if (d_count(new_dentry) > 2) { | 2084 | if (d_count(new_dentry) > 2) { |
| 2087 | int err; | 2085 | int err; |
| @@ -2098,7 +2096,6 @@ int nfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
| 2098 | goto out; | 2096 | goto out; |
| 2099 | 2097 | ||
| 2100 | new_dentry = dentry; | 2098 | new_dentry = dentry; |
| 2101 | rehash = NULL; | ||
| 2102 | new_inode = NULL; | 2099 | new_inode = NULL; |
| 2103 | } | 2100 | } |
| 2104 | } | 2101 | } |
| @@ -2119,8 +2116,6 @@ int nfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
| 2119 | error = task->tk_status; | 2116 | error = task->tk_status; |
| 2120 | rpc_put_task(task); | 2117 | rpc_put_task(task); |
| 2121 | out: | 2118 | out: |
| 2122 | if (rehash) | ||
| 2123 | d_rehash(rehash); | ||
| 2124 | trace_nfs_rename_exit(old_dir, old_dentry, | 2119 | trace_nfs_rename_exit(old_dir, old_dentry, |
| 2125 | new_dir, new_dentry, error); | 2120 | new_dir, new_dentry, error); |
| 2126 | /* new dentry created? */ | 2121 | /* new dentry created? */ |
diff --git a/fs/nfs/filelayout/filelayout.c b/fs/nfs/filelayout/filelayout.c index 44347f4bdc15..acd30baca461 100644 --- a/fs/nfs/filelayout/filelayout.c +++ b/fs/nfs/filelayout/filelayout.c | |||
| @@ -202,10 +202,10 @@ static int filelayout_async_handle_error(struct rpc_task *task, | |||
| 202 | task->tk_status); | 202 | task->tk_status); |
| 203 | nfs4_mark_deviceid_unavailable(devid); | 203 | nfs4_mark_deviceid_unavailable(devid); |
| 204 | pnfs_error_mark_layout_for_return(inode, lseg); | 204 | pnfs_error_mark_layout_for_return(inode, lseg); |
| 205 | pnfs_set_lo_fail(lseg); | ||
| 206 | rpc_wake_up(&tbl->slot_tbl_waitq); | 205 | rpc_wake_up(&tbl->slot_tbl_waitq); |
| 207 | /* fall through */ | 206 | /* fall through */ |
| 208 | default: | 207 | default: |
| 208 | pnfs_set_lo_fail(lseg); | ||
| 209 | reset: | 209 | reset: |
| 210 | dprintk("%s Retry through MDS. Error %d\n", __func__, | 210 | dprintk("%s Retry through MDS. Error %d\n", __func__, |
| 211 | task->tk_status); | 211 | task->tk_status); |
| @@ -560,6 +560,50 @@ filelayout_write_pagelist(struct nfs_pgio_header *hdr, int sync) | |||
| 560 | return PNFS_ATTEMPTED; | 560 | return PNFS_ATTEMPTED; |
| 561 | } | 561 | } |
| 562 | 562 | ||
| 563 | static int | ||
| 564 | filelayout_check_deviceid(struct pnfs_layout_hdr *lo, | ||
| 565 | struct nfs4_filelayout_segment *fl, | ||
| 566 | gfp_t gfp_flags) | ||
| 567 | { | ||
| 568 | struct nfs4_deviceid_node *d; | ||
| 569 | struct nfs4_file_layout_dsaddr *dsaddr; | ||
| 570 | int status = -EINVAL; | ||
| 571 | |||
| 572 | /* find and reference the deviceid */ | ||
| 573 | d = nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode), &fl->deviceid, | ||
| 574 | lo->plh_lc_cred, gfp_flags); | ||
| 575 | if (d == NULL) | ||
| 576 | goto out; | ||
| 577 | |||
| 578 | dsaddr = container_of(d, struct nfs4_file_layout_dsaddr, id_node); | ||
| 579 | /* Found deviceid is unavailable */ | ||
| 580 | if (filelayout_test_devid_unavailable(&dsaddr->id_node)) | ||
| 581 | goto out_put; | ||
| 582 | |||
| 583 | fl->dsaddr = dsaddr; | ||
| 584 | |||
| 585 | if (fl->first_stripe_index >= dsaddr->stripe_count) { | ||
| 586 | dprintk("%s Bad first_stripe_index %u\n", | ||
| 587 | __func__, fl->first_stripe_index); | ||
| 588 | goto out_put; | ||
| 589 | } | ||
| 590 | |||
| 591 | if ((fl->stripe_type == STRIPE_SPARSE && | ||
| 592 | fl->num_fh > 1 && fl->num_fh != dsaddr->ds_num) || | ||
| 593 | (fl->stripe_type == STRIPE_DENSE && | ||
| 594 | fl->num_fh != dsaddr->stripe_count)) { | ||
| 595 | dprintk("%s num_fh %u not valid for given packing\n", | ||
| 596 | __func__, fl->num_fh); | ||
| 597 | goto out_put; | ||
| 598 | } | ||
| 599 | status = 0; | ||
| 600 | out: | ||
| 601 | return status; | ||
| 602 | out_put: | ||
| 603 | nfs4_fl_put_deviceid(dsaddr); | ||
| 604 | goto out; | ||
| 605 | } | ||
| 606 | |||
| 563 | /* | 607 | /* |
| 564 | * filelayout_check_layout() | 608 | * filelayout_check_layout() |
| 565 | * | 609 | * |
| @@ -572,11 +616,8 @@ static int | |||
| 572 | filelayout_check_layout(struct pnfs_layout_hdr *lo, | 616 | filelayout_check_layout(struct pnfs_layout_hdr *lo, |
| 573 | struct nfs4_filelayout_segment *fl, | 617 | struct nfs4_filelayout_segment *fl, |
| 574 | struct nfs4_layoutget_res *lgr, | 618 | struct nfs4_layoutget_res *lgr, |
| 575 | struct nfs4_deviceid *id, | ||
| 576 | gfp_t gfp_flags) | 619 | gfp_t gfp_flags) |
| 577 | { | 620 | { |
| 578 | struct nfs4_deviceid_node *d; | ||
| 579 | struct nfs4_file_layout_dsaddr *dsaddr; | ||
| 580 | int status = -EINVAL; | 621 | int status = -EINVAL; |
| 581 | 622 | ||
| 582 | dprintk("--> %s\n", __func__); | 623 | dprintk("--> %s\n", __func__); |
| @@ -601,41 +642,10 @@ filelayout_check_layout(struct pnfs_layout_hdr *lo, | |||
| 601 | goto out; | 642 | goto out; |
| 602 | } | 643 | } |
| 603 | 644 | ||
| 604 | /* find and reference the deviceid */ | ||
| 605 | d = nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode), id, | ||
| 606 | lo->plh_lc_cred, gfp_flags); | ||
| 607 | if (d == NULL) | ||
| 608 | goto out; | ||
| 609 | |||
| 610 | dsaddr = container_of(d, struct nfs4_file_layout_dsaddr, id_node); | ||
| 611 | /* Found deviceid is unavailable */ | ||
| 612 | if (filelayout_test_devid_unavailable(&dsaddr->id_node)) | ||
| 613 | goto out_put; | ||
| 614 | |||
| 615 | fl->dsaddr = dsaddr; | ||
| 616 | |||
| 617 | if (fl->first_stripe_index >= dsaddr->stripe_count) { | ||
| 618 | dprintk("%s Bad first_stripe_index %u\n", | ||
| 619 | __func__, fl->first_stripe_index); | ||
| 620 | goto out_put; | ||
| 621 | } | ||
| 622 | |||
| 623 | if ((fl->stripe_type == STRIPE_SPARSE && | ||
| 624 | fl->num_fh > 1 && fl->num_fh != dsaddr->ds_num) || | ||
| 625 | (fl->stripe_type == STRIPE_DENSE && | ||
| 626 | fl->num_fh != dsaddr->stripe_count)) { | ||
| 627 | dprintk("%s num_fh %u not valid for given packing\n", | ||
| 628 | __func__, fl->num_fh); | ||
| 629 | goto out_put; | ||
| 630 | } | ||
| 631 | |||
| 632 | status = 0; | 645 | status = 0; |
| 633 | out: | 646 | out: |
| 634 | dprintk("--> %s returns %d\n", __func__, status); | 647 | dprintk("--> %s returns %d\n", __func__, status); |
| 635 | return status; | 648 | return status; |
| 636 | out_put: | ||
| 637 | nfs4_fl_put_deviceid(dsaddr); | ||
| 638 | goto out; | ||
| 639 | } | 649 | } |
| 640 | 650 | ||
| 641 | static void _filelayout_free_lseg(struct nfs4_filelayout_segment *fl) | 651 | static void _filelayout_free_lseg(struct nfs4_filelayout_segment *fl) |
| @@ -657,7 +667,6 @@ static int | |||
| 657 | filelayout_decode_layout(struct pnfs_layout_hdr *flo, | 667 | filelayout_decode_layout(struct pnfs_layout_hdr *flo, |
| 658 | struct nfs4_filelayout_segment *fl, | 668 | struct nfs4_filelayout_segment *fl, |
| 659 | struct nfs4_layoutget_res *lgr, | 669 | struct nfs4_layoutget_res *lgr, |
| 660 | struct nfs4_deviceid *id, | ||
| 661 | gfp_t gfp_flags) | 670 | gfp_t gfp_flags) |
| 662 | { | 671 | { |
| 663 | struct xdr_stream stream; | 672 | struct xdr_stream stream; |
| @@ -682,9 +691,9 @@ filelayout_decode_layout(struct pnfs_layout_hdr *flo, | |||
| 682 | if (unlikely(!p)) | 691 | if (unlikely(!p)) |
| 683 | goto out_err; | 692 | goto out_err; |
| 684 | 693 | ||
| 685 | memcpy(id, p, sizeof(*id)); | 694 | memcpy(&fl->deviceid, p, sizeof(fl->deviceid)); |
| 686 | p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE); | 695 | p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE); |
| 687 | nfs4_print_deviceid(id); | 696 | nfs4_print_deviceid(&fl->deviceid); |
| 688 | 697 | ||
| 689 | nfl_util = be32_to_cpup(p++); | 698 | nfl_util = be32_to_cpup(p++); |
| 690 | if (nfl_util & NFL4_UFLG_COMMIT_THRU_MDS) | 699 | if (nfl_util & NFL4_UFLG_COMMIT_THRU_MDS) |
| @@ -831,15 +840,14 @@ filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid, | |||
| 831 | { | 840 | { |
| 832 | struct nfs4_filelayout_segment *fl; | 841 | struct nfs4_filelayout_segment *fl; |
| 833 | int rc; | 842 | int rc; |
| 834 | struct nfs4_deviceid id; | ||
| 835 | 843 | ||
| 836 | dprintk("--> %s\n", __func__); | 844 | dprintk("--> %s\n", __func__); |
| 837 | fl = kzalloc(sizeof(*fl), gfp_flags); | 845 | fl = kzalloc(sizeof(*fl), gfp_flags); |
| 838 | if (!fl) | 846 | if (!fl) |
| 839 | return NULL; | 847 | return NULL; |
| 840 | 848 | ||
| 841 | rc = filelayout_decode_layout(layoutid, fl, lgr, &id, gfp_flags); | 849 | rc = filelayout_decode_layout(layoutid, fl, lgr, gfp_flags); |
| 842 | if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, &id, gfp_flags)) { | 850 | if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, gfp_flags)) { |
| 843 | _filelayout_free_lseg(fl); | 851 | _filelayout_free_lseg(fl); |
| 844 | return NULL; | 852 | return NULL; |
| 845 | } | 853 | } |
| @@ -888,18 +896,51 @@ filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, | |||
| 888 | return min(stripe_unit - (unsigned int)stripe_offset, size); | 896 | return min(stripe_unit - (unsigned int)stripe_offset, size); |
| 889 | } | 897 | } |
| 890 | 898 | ||
| 899 | static struct pnfs_layout_segment * | ||
| 900 | fl_pnfs_update_layout(struct inode *ino, | ||
| 901 | struct nfs_open_context *ctx, | ||
| 902 | loff_t pos, | ||
| 903 | u64 count, | ||
| 904 | enum pnfs_iomode iomode, | ||
| 905 | bool strict_iomode, | ||
| 906 | gfp_t gfp_flags) | ||
| 907 | { | ||
| 908 | struct pnfs_layout_segment *lseg = NULL; | ||
| 909 | struct pnfs_layout_hdr *lo; | ||
| 910 | struct nfs4_filelayout_segment *fl; | ||
| 911 | int status; | ||
| 912 | |||
| 913 | lseg = pnfs_update_layout(ino, ctx, pos, count, iomode, strict_iomode, | ||
| 914 | gfp_flags); | ||
| 915 | if (!lseg) | ||
| 916 | lseg = ERR_PTR(-ENOMEM); | ||
| 917 | if (IS_ERR(lseg)) | ||
| 918 | goto out; | ||
| 919 | |||
| 920 | lo = NFS_I(ino)->layout; | ||
| 921 | fl = FILELAYOUT_LSEG(lseg); | ||
| 922 | |||
| 923 | status = filelayout_check_deviceid(lo, fl, gfp_flags); | ||
| 924 | if (status) | ||
| 925 | lseg = ERR_PTR(status); | ||
| 926 | out: | ||
| 927 | if (IS_ERR(lseg)) | ||
| 928 | pnfs_put_lseg(lseg); | ||
| 929 | return lseg; | ||
| 930 | } | ||
| 931 | |||
| 891 | static void | 932 | static void |
| 892 | filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio, | 933 | filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio, |
| 893 | struct nfs_page *req) | 934 | struct nfs_page *req) |
| 894 | { | 935 | { |
| 895 | if (!pgio->pg_lseg) { | 936 | if (!pgio->pg_lseg) { |
| 896 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | 937 | pgio->pg_lseg = fl_pnfs_update_layout(pgio->pg_inode, |
| 897 | req->wb_context, | 938 | req->wb_context, |
| 898 | 0, | 939 | 0, |
| 899 | NFS4_MAX_UINT64, | 940 | NFS4_MAX_UINT64, |
| 900 | IOMODE_READ, | 941 | IOMODE_READ, |
| 901 | false, | 942 | false, |
| 902 | GFP_KERNEL); | 943 | GFP_KERNEL); |
| 903 | if (IS_ERR(pgio->pg_lseg)) { | 944 | if (IS_ERR(pgio->pg_lseg)) { |
| 904 | pgio->pg_error = PTR_ERR(pgio->pg_lseg); | 945 | pgio->pg_error = PTR_ERR(pgio->pg_lseg); |
| 905 | pgio->pg_lseg = NULL; | 946 | pgio->pg_lseg = NULL; |
| @@ -919,13 +960,13 @@ filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio, | |||
| 919 | int status; | 960 | int status; |
| 920 | 961 | ||
| 921 | if (!pgio->pg_lseg) { | 962 | if (!pgio->pg_lseg) { |
| 922 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | 963 | pgio->pg_lseg = fl_pnfs_update_layout(pgio->pg_inode, |
| 923 | req->wb_context, | 964 | req->wb_context, |
| 924 | 0, | 965 | 0, |
| 925 | NFS4_MAX_UINT64, | 966 | NFS4_MAX_UINT64, |
| 926 | IOMODE_RW, | 967 | IOMODE_RW, |
| 927 | false, | 968 | false, |
| 928 | GFP_NOFS); | 969 | GFP_NOFS); |
| 929 | if (IS_ERR(pgio->pg_lseg)) { | 970 | if (IS_ERR(pgio->pg_lseg)) { |
| 930 | pgio->pg_error = PTR_ERR(pgio->pg_lseg); | 971 | pgio->pg_error = PTR_ERR(pgio->pg_lseg); |
| 931 | pgio->pg_lseg = NULL; | 972 | pgio->pg_lseg = NULL; |
diff --git a/fs/nfs/filelayout/filelayout.h b/fs/nfs/filelayout/filelayout.h index 2896cb833a11..79323b5dab0c 100644 --- a/fs/nfs/filelayout/filelayout.h +++ b/fs/nfs/filelayout/filelayout.h | |||
| @@ -55,15 +55,16 @@ struct nfs4_file_layout_dsaddr { | |||
| 55 | }; | 55 | }; |
| 56 | 56 | ||
| 57 | struct nfs4_filelayout_segment { | 57 | struct nfs4_filelayout_segment { |
| 58 | struct pnfs_layout_segment generic_hdr; | 58 | struct pnfs_layout_segment generic_hdr; |
| 59 | u32 stripe_type; | 59 | u32 stripe_type; |
| 60 | u32 commit_through_mds; | 60 | u32 commit_through_mds; |
| 61 | u32 stripe_unit; | 61 | u32 stripe_unit; |
| 62 | u32 first_stripe_index; | 62 | u32 first_stripe_index; |
| 63 | u64 pattern_offset; | 63 | u64 pattern_offset; |
| 64 | struct nfs4_file_layout_dsaddr *dsaddr; /* Point to GETDEVINFO data */ | 64 | struct nfs4_deviceid deviceid; |
| 65 | unsigned int num_fh; | 65 | struct nfs4_file_layout_dsaddr *dsaddr; /* Point to GETDEVINFO data */ |
| 66 | struct nfs_fh **fh_array; | 66 | unsigned int num_fh; |
| 67 | struct nfs_fh **fh_array; | ||
| 67 | }; | 68 | }; |
| 68 | 69 | ||
| 69 | struct nfs4_filelayout { | 70 | struct nfs4_filelayout { |
diff --git a/fs/nfs/flexfilelayout/flexfilelayoutdev.c b/fs/nfs/flexfilelayout/flexfilelayoutdev.c index 85fde93dff77..457cfeb1d5c1 100644 --- a/fs/nfs/flexfilelayout/flexfilelayoutdev.c +++ b/fs/nfs/flexfilelayout/flexfilelayoutdev.c | |||
| @@ -208,6 +208,10 @@ static bool ff_layout_mirror_valid(struct pnfs_layout_segment *lseg, | |||
| 208 | } else | 208 | } else |
| 209 | goto outerr; | 209 | goto outerr; |
| 210 | } | 210 | } |
| 211 | |||
| 212 | if (IS_ERR(mirror->mirror_ds)) | ||
| 213 | goto outerr; | ||
| 214 | |||
| 211 | if (mirror->mirror_ds->ds == NULL) { | 215 | if (mirror->mirror_ds->ds == NULL) { |
| 212 | struct nfs4_deviceid_node *devid; | 216 | struct nfs4_deviceid_node *devid; |
| 213 | devid = &mirror->mirror_ds->id_node; | 217 | devid = &mirror->mirror_ds->id_node; |
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index c780d98035cc..201ca3f2c4ba 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c | |||
| @@ -2442,17 +2442,14 @@ static void nfs41_check_delegation_stateid(struct nfs4_state *state) | |||
| 2442 | } | 2442 | } |
| 2443 | 2443 | ||
| 2444 | nfs4_stateid_copy(&stateid, &delegation->stateid); | 2444 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
| 2445 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { | 2445 | if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) || |
| 2446 | !test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, | ||
| 2447 | &delegation->flags)) { | ||
| 2446 | rcu_read_unlock(); | 2448 | rcu_read_unlock(); |
| 2447 | nfs_finish_clear_delegation_stateid(state, &stateid); | 2449 | nfs_finish_clear_delegation_stateid(state, &stateid); |
| 2448 | return; | 2450 | return; |
| 2449 | } | 2451 | } |
| 2450 | 2452 | ||
| 2451 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags)) { | ||
| 2452 | rcu_read_unlock(); | ||
| 2453 | return; | ||
| 2454 | } | ||
| 2455 | |||
| 2456 | cred = get_rpccred(delegation->cred); | 2453 | cred = get_rpccred(delegation->cred); |
| 2457 | rcu_read_unlock(); | 2454 | rcu_read_unlock(); |
| 2458 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); | 2455 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index cbeeda1e94a2..d86031b6ad79 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c | |||
| @@ -2489,7 +2489,7 @@ bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) | |||
| 2489 | 2489 | ||
| 2490 | int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) | 2490 | int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) |
| 2491 | { | 2491 | { |
| 2492 | if (op->opnum == OP_ILLEGAL) | 2492 | if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp) |
| 2493 | return op_encode_hdr_size * sizeof(__be32); | 2493 | return op_encode_hdr_size * sizeof(__be32); |
| 2494 | 2494 | ||
| 2495 | BUG_ON(OPDESC(op)->op_rsize_bop == NULL); | 2495 | BUG_ON(OPDESC(op)->op_rsize_bop == NULL); |
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index 73e75ac90525..8bf8f667a8cf 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c | |||
| @@ -538,13 +538,21 @@ out_free: | |||
| 538 | 538 | ||
| 539 | static ssize_t | 539 | static ssize_t |
| 540 | nfsd_print_version_support(char *buf, int remaining, const char *sep, | 540 | nfsd_print_version_support(char *buf, int remaining, const char *sep, |
| 541 | unsigned vers, unsigned minor) | 541 | unsigned vers, int minor) |
| 542 | { | 542 | { |
| 543 | const char *format = (minor == 0) ? "%s%c%u" : "%s%c%u.%u"; | 543 | const char *format = minor < 0 ? "%s%c%u" : "%s%c%u.%u"; |
| 544 | bool supported = !!nfsd_vers(vers, NFSD_TEST); | 544 | bool supported = !!nfsd_vers(vers, NFSD_TEST); |
| 545 | 545 | ||
| 546 | if (vers == 4 && !nfsd_minorversion(minor, NFSD_TEST)) | 546 | if (vers == 4 && minor >= 0 && |
| 547 | !nfsd_minorversion(minor, NFSD_TEST)) | ||
| 547 | supported = false; | 548 | supported = false; |
| 549 | if (minor == 0 && supported) | ||
| 550 | /* | ||
| 551 | * special case for backward compatability. | ||
| 552 | * +4.0 is never reported, it is implied by | ||
| 553 | * +4, unless -4.0 is present. | ||
| 554 | */ | ||
| 555 | return 0; | ||
| 548 | return snprintf(buf, remaining, format, sep, | 556 | return snprintf(buf, remaining, format, sep, |
| 549 | supported ? '+' : '-', vers, minor); | 557 | supported ? '+' : '-', vers, minor); |
| 550 | } | 558 | } |
| @@ -554,7 +562,6 @@ static ssize_t __write_versions(struct file *file, char *buf, size_t size) | |||
| 554 | char *mesg = buf; | 562 | char *mesg = buf; |
| 555 | char *vers, *minorp, sign; | 563 | char *vers, *minorp, sign; |
| 556 | int len, num, remaining; | 564 | int len, num, remaining; |
| 557 | unsigned minor; | ||
| 558 | ssize_t tlen = 0; | 565 | ssize_t tlen = 0; |
| 559 | char *sep; | 566 | char *sep; |
| 560 | struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); | 567 | struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); |
| @@ -575,6 +582,7 @@ static ssize_t __write_versions(struct file *file, char *buf, size_t size) | |||
| 575 | if (len <= 0) return -EINVAL; | 582 | if (len <= 0) return -EINVAL; |
| 576 | do { | 583 | do { |
| 577 | enum vers_op cmd; | 584 | enum vers_op cmd; |
| 585 | unsigned minor; | ||
| 578 | sign = *vers; | 586 | sign = *vers; |
| 579 | if (sign == '+' || sign == '-') | 587 | if (sign == '+' || sign == '-') |
| 580 | num = simple_strtol((vers+1), &minorp, 0); | 588 | num = simple_strtol((vers+1), &minorp, 0); |
| @@ -585,8 +593,8 @@ static ssize_t __write_versions(struct file *file, char *buf, size_t size) | |||
| 585 | return -EINVAL; | 593 | return -EINVAL; |
| 586 | if (kstrtouint(minorp+1, 0, &minor) < 0) | 594 | if (kstrtouint(minorp+1, 0, &minor) < 0) |
| 587 | return -EINVAL; | 595 | return -EINVAL; |
| 588 | } else | 596 | } |
| 589 | minor = 0; | 597 | |
| 590 | cmd = sign == '-' ? NFSD_CLEAR : NFSD_SET; | 598 | cmd = sign == '-' ? NFSD_CLEAR : NFSD_SET; |
| 591 | switch(num) { | 599 | switch(num) { |
| 592 | case 2: | 600 | case 2: |
| @@ -594,8 +602,20 @@ static ssize_t __write_versions(struct file *file, char *buf, size_t size) | |||
| 594 | nfsd_vers(num, cmd); | 602 | nfsd_vers(num, cmd); |
| 595 | break; | 603 | break; |
| 596 | case 4: | 604 | case 4: |
| 597 | if (nfsd_minorversion(minor, cmd) >= 0) | 605 | if (*minorp == '.') { |
| 598 | break; | 606 | if (nfsd_minorversion(minor, cmd) < 0) |
| 607 | return -EINVAL; | ||
| 608 | } else if ((cmd == NFSD_SET) != nfsd_vers(num, NFSD_TEST)) { | ||
| 609 | /* | ||
| 610 | * Either we have +4 and no minors are enabled, | ||
| 611 | * or we have -4 and at least one minor is enabled. | ||
| 612 | * In either case, propagate 'cmd' to all minors. | ||
| 613 | */ | ||
| 614 | minor = 0; | ||
| 615 | while (nfsd_minorversion(minor, cmd) >= 0) | ||
| 616 | minor++; | ||
| 617 | } | ||
| 618 | break; | ||
| 599 | default: | 619 | default: |
| 600 | return -EINVAL; | 620 | return -EINVAL; |
| 601 | } | 621 | } |
| @@ -612,9 +632,11 @@ static ssize_t __write_versions(struct file *file, char *buf, size_t size) | |||
| 612 | sep = ""; | 632 | sep = ""; |
| 613 | remaining = SIMPLE_TRANSACTION_LIMIT; | 633 | remaining = SIMPLE_TRANSACTION_LIMIT; |
| 614 | for (num=2 ; num <= 4 ; num++) { | 634 | for (num=2 ; num <= 4 ; num++) { |
| 635 | int minor; | ||
| 615 | if (!nfsd_vers(num, NFSD_AVAIL)) | 636 | if (!nfsd_vers(num, NFSD_AVAIL)) |
| 616 | continue; | 637 | continue; |
| 617 | minor = 0; | 638 | |
| 639 | minor = -1; | ||
| 618 | do { | 640 | do { |
| 619 | len = nfsd_print_version_support(buf, remaining, | 641 | len = nfsd_print_version_support(buf, remaining, |
| 620 | sep, num, minor); | 642 | sep, num, minor); |
| @@ -624,7 +646,8 @@ static ssize_t __write_versions(struct file *file, char *buf, size_t size) | |||
| 624 | buf += len; | 646 | buf += len; |
| 625 | tlen += len; | 647 | tlen += len; |
| 626 | minor++; | 648 | minor++; |
| 627 | sep = " "; | 649 | if (len) |
| 650 | sep = " "; | ||
| 628 | } while (num == 4 && minor <= NFSD_SUPPORTED_MINOR_VERSION); | 651 | } while (num == 4 && minor <= NFSD_SUPPORTED_MINOR_VERSION); |
| 629 | } | 652 | } |
| 630 | out: | 653 | out: |
diff --git a/fs/nfsd/nfsproc.c b/fs/nfsd/nfsproc.c index fa82b7707e85..03a7e9da4da0 100644 --- a/fs/nfsd/nfsproc.c +++ b/fs/nfsd/nfsproc.c | |||
| @@ -786,6 +786,7 @@ nfserrno (int errno) | |||
| 786 | { nfserr_serverfault, -ESERVERFAULT }, | 786 | { nfserr_serverfault, -ESERVERFAULT }, |
| 787 | { nfserr_serverfault, -ENFILE }, | 787 | { nfserr_serverfault, -ENFILE }, |
| 788 | { nfserr_io, -EUCLEAN }, | 788 | { nfserr_io, -EUCLEAN }, |
| 789 | { nfserr_perm, -ENOKEY }, | ||
| 789 | }; | 790 | }; |
| 790 | int i; | 791 | int i; |
| 791 | 792 | ||
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index 786a4a2cb2d7..31e1f9593457 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c | |||
| @@ -167,7 +167,8 @@ nfsd_adjust_nfsd_versions4(void) | |||
| 167 | 167 | ||
| 168 | int nfsd_minorversion(u32 minorversion, enum vers_op change) | 168 | int nfsd_minorversion(u32 minorversion, enum vers_op change) |
| 169 | { | 169 | { |
| 170 | if (minorversion > NFSD_SUPPORTED_MINOR_VERSION) | 170 | if (minorversion > NFSD_SUPPORTED_MINOR_VERSION && |
| 171 | change != NFSD_AVAIL) | ||
| 171 | return -1; | 172 | return -1; |
| 172 | switch(change) { | 173 | switch(change) { |
| 173 | case NFSD_SET: | 174 | case NFSD_SET: |
| @@ -415,23 +416,20 @@ static void nfsd_last_thread(struct svc_serv *serv, struct net *net) | |||
| 415 | 416 | ||
| 416 | void nfsd_reset_versions(void) | 417 | void nfsd_reset_versions(void) |
| 417 | { | 418 | { |
| 418 | int found_one = 0; | ||
| 419 | int i; | 419 | int i; |
| 420 | 420 | ||
| 421 | for (i = NFSD_MINVERS; i < NFSD_NRVERS; i++) { | 421 | for (i = 0; i < NFSD_NRVERS; i++) |
| 422 | if (nfsd_program.pg_vers[i]) | 422 | if (nfsd_vers(i, NFSD_TEST)) |
| 423 | found_one = 1; | 423 | return; |
| 424 | } | ||
| 425 | 424 | ||
| 426 | if (!found_one) { | 425 | for (i = 0; i < NFSD_NRVERS; i++) |
| 427 | for (i = NFSD_MINVERS; i < NFSD_NRVERS; i++) | 426 | if (i != 4) |
| 428 | nfsd_program.pg_vers[i] = nfsd_version[i]; | 427 | nfsd_vers(i, NFSD_SET); |
| 429 | #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) | 428 | else { |
| 430 | for (i = NFSD_ACL_MINVERS; i < NFSD_ACL_NRVERS; i++) | 429 | int minor = 0; |
| 431 | nfsd_acl_program.pg_vers[i] = | 430 | while (nfsd_minorversion(minor, NFSD_SET) >= 0) |
| 432 | nfsd_acl_version[i]; | 431 | minor++; |
| 433 | #endif | 432 | } |
| 434 | } | ||
| 435 | } | 433 | } |
| 436 | 434 | ||
| 437 | /* | 435 | /* |
| @@ -91,6 +91,7 @@ slow: | |||
| 91 | return ERR_PTR(-ENOMEM); | 91 | return ERR_PTR(-ENOMEM); |
| 92 | } | 92 | } |
| 93 | d_instantiate(dentry, inode); | 93 | d_instantiate(dentry, inode); |
| 94 | dentry->d_flags |= DCACHE_RCUACCESS; | ||
| 94 | dentry->d_fsdata = (void *)ns->ops; | 95 | dentry->d_fsdata = (void *)ns->ops; |
| 95 | d = atomic_long_cmpxchg(&ns->stashed, 0, (unsigned long)dentry); | 96 | d = atomic_long_cmpxchg(&ns->stashed, 0, (unsigned long)dentry); |
| 96 | if (d) { | 97 | if (d) { |
diff --git a/fs/orangefs/devorangefs-req.c b/fs/orangefs/devorangefs-req.c index c4ab6fdf17a0..e1534c9bab16 100644 --- a/fs/orangefs/devorangefs-req.c +++ b/fs/orangefs/devorangefs-req.c | |||
| @@ -208,14 +208,19 @@ restart: | |||
| 208 | continue; | 208 | continue; |
| 209 | /* | 209 | /* |
| 210 | * Skip ops whose filesystem we don't know about unless | 210 | * Skip ops whose filesystem we don't know about unless |
| 211 | * it is being mounted. | 211 | * it is being mounted or unmounted. It is possible for |
| 212 | * a filesystem we don't know about to be unmounted if | ||
| 213 | * it fails to mount in the kernel after userspace has | ||
| 214 | * been sent the mount request. | ||
| 212 | */ | 215 | */ |
| 213 | /* XXX: is there a better way to detect this? */ | 216 | /* XXX: is there a better way to detect this? */ |
| 214 | } else if (ret == -1 && | 217 | } else if (ret == -1 && |
| 215 | !(op->upcall.type == | 218 | !(op->upcall.type == |
| 216 | ORANGEFS_VFS_OP_FS_MOUNT || | 219 | ORANGEFS_VFS_OP_FS_MOUNT || |
| 217 | op->upcall.type == | 220 | op->upcall.type == |
| 218 | ORANGEFS_VFS_OP_GETATTR)) { | 221 | ORANGEFS_VFS_OP_GETATTR || |
| 222 | op->upcall.type == | ||
| 223 | ORANGEFS_VFS_OP_FS_UMOUNT)) { | ||
| 219 | gossip_debug(GOSSIP_DEV_DEBUG, | 224 | gossip_debug(GOSSIP_DEV_DEBUG, |
| 220 | "orangefs: skipping op tag %llu %s\n", | 225 | "orangefs: skipping op tag %llu %s\n", |
| 221 | llu(op->tag), get_opname_string(op)); | 226 | llu(op->tag), get_opname_string(op)); |
diff --git a/fs/orangefs/orangefs-kernel.h b/fs/orangefs/orangefs-kernel.h index 5e48a0be9761..8afac46fcc87 100644 --- a/fs/orangefs/orangefs-kernel.h +++ b/fs/orangefs/orangefs-kernel.h | |||
| @@ -249,6 +249,7 @@ struct orangefs_sb_info_s { | |||
| 249 | char devname[ORANGEFS_MAX_SERVER_ADDR_LEN]; | 249 | char devname[ORANGEFS_MAX_SERVER_ADDR_LEN]; |
| 250 | struct super_block *sb; | 250 | struct super_block *sb; |
| 251 | int mount_pending; | 251 | int mount_pending; |
| 252 | int no_list; | ||
| 252 | struct list_head list; | 253 | struct list_head list; |
| 253 | }; | 254 | }; |
| 254 | 255 | ||
diff --git a/fs/orangefs/super.c b/fs/orangefs/super.c index 67c24351a67f..629d8c917fa6 100644 --- a/fs/orangefs/super.c +++ b/fs/orangefs/super.c | |||
| @@ -263,8 +263,13 @@ int orangefs_remount(struct orangefs_sb_info_s *orangefs_sb) | |||
| 263 | if (!new_op) | 263 | if (!new_op) |
| 264 | return -ENOMEM; | 264 | return -ENOMEM; |
| 265 | new_op->upcall.req.features.features = 0; | 265 | new_op->upcall.req.features.features = 0; |
| 266 | ret = service_operation(new_op, "orangefs_features", 0); | 266 | ret = service_operation(new_op, "orangefs_features", |
| 267 | orangefs_features = new_op->downcall.resp.features.features; | 267 | ORANGEFS_OP_PRIORITY | ORANGEFS_OP_NO_MUTEX); |
| 268 | if (!ret) | ||
| 269 | orangefs_features = | ||
| 270 | new_op->downcall.resp.features.features; | ||
| 271 | else | ||
| 272 | orangefs_features = 0; | ||
| 268 | op_release(new_op); | 273 | op_release(new_op); |
| 269 | } else { | 274 | } else { |
| 270 | orangefs_features = 0; | 275 | orangefs_features = 0; |
| @@ -488,7 +493,7 @@ struct dentry *orangefs_mount(struct file_system_type *fst, | |||
| 488 | 493 | ||
| 489 | if (ret) { | 494 | if (ret) { |
| 490 | d = ERR_PTR(ret); | 495 | d = ERR_PTR(ret); |
| 491 | goto free_op; | 496 | goto free_sb_and_op; |
| 492 | } | 497 | } |
| 493 | 498 | ||
| 494 | /* | 499 | /* |
| @@ -514,6 +519,9 @@ struct dentry *orangefs_mount(struct file_system_type *fst, | |||
| 514 | spin_unlock(&orangefs_superblocks_lock); | 519 | spin_unlock(&orangefs_superblocks_lock); |
| 515 | op_release(new_op); | 520 | op_release(new_op); |
| 516 | 521 | ||
| 522 | /* Must be removed from the list now. */ | ||
| 523 | ORANGEFS_SB(sb)->no_list = 0; | ||
| 524 | |||
| 517 | if (orangefs_userspace_version >= 20906) { | 525 | if (orangefs_userspace_version >= 20906) { |
| 518 | new_op = op_alloc(ORANGEFS_VFS_OP_FEATURES); | 526 | new_op = op_alloc(ORANGEFS_VFS_OP_FEATURES); |
| 519 | if (!new_op) | 527 | if (!new_op) |
| @@ -528,6 +536,10 @@ struct dentry *orangefs_mount(struct file_system_type *fst, | |||
| 528 | 536 | ||
| 529 | return dget(sb->s_root); | 537 | return dget(sb->s_root); |
| 530 | 538 | ||
| 539 | free_sb_and_op: | ||
| 540 | /* Will call orangefs_kill_sb with sb not in list. */ | ||
| 541 | ORANGEFS_SB(sb)->no_list = 1; | ||
| 542 | deactivate_locked_super(sb); | ||
| 531 | free_op: | 543 | free_op: |
| 532 | gossip_err("orangefs_mount: mount request failed with %d\n", ret); | 544 | gossip_err("orangefs_mount: mount request failed with %d\n", ret); |
| 533 | if (ret == -EINVAL) { | 545 | if (ret == -EINVAL) { |
| @@ -553,12 +565,14 @@ void orangefs_kill_sb(struct super_block *sb) | |||
| 553 | */ | 565 | */ |
| 554 | orangefs_unmount_sb(sb); | 566 | orangefs_unmount_sb(sb); |
| 555 | 567 | ||
| 556 | /* remove the sb from our list of orangefs specific sb's */ | 568 | if (!ORANGEFS_SB(sb)->no_list) { |
| 557 | 569 | /* remove the sb from our list of orangefs specific sb's */ | |
| 558 | spin_lock(&orangefs_superblocks_lock); | 570 | spin_lock(&orangefs_superblocks_lock); |
| 559 | __list_del_entry(&ORANGEFS_SB(sb)->list); /* not list_del_init */ | 571 | /* not list_del_init */ |
| 560 | ORANGEFS_SB(sb)->list.prev = NULL; | 572 | __list_del_entry(&ORANGEFS_SB(sb)->list); |
| 561 | spin_unlock(&orangefs_superblocks_lock); | 573 | ORANGEFS_SB(sb)->list.prev = NULL; |
| 574 | spin_unlock(&orangefs_superblocks_lock); | ||
| 575 | } | ||
| 562 | 576 | ||
| 563 | /* | 577 | /* |
| 564 | * make sure that ORANGEFS_DEV_REMOUNT_ALL loop that might've seen us | 578 | * make sure that ORANGEFS_DEV_REMOUNT_ALL loop that might've seen us |
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 8f91ec66baa3..d04ea4349909 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c | |||
| @@ -1074,6 +1074,7 @@ static int sysctl_check_table(const char *path, struct ctl_table *table) | |||
| 1074 | 1074 | ||
| 1075 | if ((table->proc_handler == proc_dostring) || | 1075 | if ((table->proc_handler == proc_dostring) || |
| 1076 | (table->proc_handler == proc_dointvec) || | 1076 | (table->proc_handler == proc_dointvec) || |
| 1077 | (table->proc_handler == proc_douintvec) || | ||
| 1077 | (table->proc_handler == proc_dointvec_minmax) || | 1078 | (table->proc_handler == proc_dointvec_minmax) || |
| 1078 | (table->proc_handler == proc_dointvec_jiffies) || | 1079 | (table->proc_handler == proc_dointvec_jiffies) || |
| 1079 | (table->proc_handler == proc_dointvec_userhz_jiffies) || | 1080 | (table->proc_handler == proc_dointvec_userhz_jiffies) || |
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index f08bd31c1081..312578089544 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c | |||
| @@ -900,7 +900,14 @@ static inline void clear_soft_dirty(struct vm_area_struct *vma, | |||
| 900 | static inline void clear_soft_dirty_pmd(struct vm_area_struct *vma, | 900 | static inline void clear_soft_dirty_pmd(struct vm_area_struct *vma, |
| 901 | unsigned long addr, pmd_t *pmdp) | 901 | unsigned long addr, pmd_t *pmdp) |
| 902 | { | 902 | { |
| 903 | pmd_t pmd = pmdp_huge_get_and_clear(vma->vm_mm, addr, pmdp); | 903 | pmd_t pmd = *pmdp; |
| 904 | |||
| 905 | /* See comment in change_huge_pmd() */ | ||
| 906 | pmdp_invalidate(vma, addr, pmdp); | ||
| 907 | if (pmd_dirty(*pmdp)) | ||
| 908 | pmd = pmd_mkdirty(pmd); | ||
| 909 | if (pmd_young(*pmdp)) | ||
| 910 | pmd = pmd_mkyoung(pmd); | ||
| 904 | 911 | ||
| 905 | pmd = pmd_wrprotect(pmd); | 912 | pmd = pmd_wrprotect(pmd); |
| 906 | pmd = pmd_clear_soft_dirty(pmd); | 913 | pmd = pmd_clear_soft_dirty(pmd); |
| @@ -130,9 +130,13 @@ EXPORT_SYMBOL(vfs_getattr); | |||
| 130 | int vfs_statx_fd(unsigned int fd, struct kstat *stat, | 130 | int vfs_statx_fd(unsigned int fd, struct kstat *stat, |
| 131 | u32 request_mask, unsigned int query_flags) | 131 | u32 request_mask, unsigned int query_flags) |
| 132 | { | 132 | { |
| 133 | struct fd f = fdget_raw(fd); | 133 | struct fd f; |
| 134 | int error = -EBADF; | 134 | int error = -EBADF; |
| 135 | 135 | ||
| 136 | if (query_flags & ~KSTAT_QUERY_FLAGS) | ||
| 137 | return -EINVAL; | ||
| 138 | |||
| 139 | f = fdget_raw(fd); | ||
| 136 | if (f.file) { | 140 | if (f.file) { |
| 137 | error = vfs_getattr(&f.file->f_path, stat, | 141 | error = vfs_getattr(&f.file->f_path, stat, |
| 138 | request_mask, query_flags); | 142 | request_mask, query_flags); |
| @@ -155,9 +159,6 @@ EXPORT_SYMBOL(vfs_statx_fd); | |||
| 155 | * Additionally, the use of AT_SYMLINK_NOFOLLOW in flags will prevent a symlink | 159 | * Additionally, the use of AT_SYMLINK_NOFOLLOW in flags will prevent a symlink |
| 156 | * at the given name from being referenced. | 160 | * at the given name from being referenced. |
| 157 | * | 161 | * |
| 158 | * The caller must have preset stat->request_mask as for vfs_getattr(). The | ||
| 159 | * flags are also used to load up stat->query_flags. | ||
| 160 | * | ||
| 161 | * 0 will be returned on success, and a -ve error code if unsuccessful. | 162 | * 0 will be returned on success, and a -ve error code if unsuccessful. |
| 162 | */ | 163 | */ |
| 163 | int vfs_statx(int dfd, const char __user *filename, int flags, | 164 | int vfs_statx(int dfd, const char __user *filename, int flags, |
| @@ -509,46 +510,38 @@ SYSCALL_DEFINE4(fstatat64, int, dfd, const char __user *, filename, | |||
| 509 | } | 510 | } |
| 510 | #endif /* __ARCH_WANT_STAT64 || __ARCH_WANT_COMPAT_STAT64 */ | 511 | #endif /* __ARCH_WANT_STAT64 || __ARCH_WANT_COMPAT_STAT64 */ |
| 511 | 512 | ||
| 512 | static inline int __put_timestamp(struct timespec *kts, | 513 | static noinline_for_stack int |
| 513 | struct statx_timestamp __user *uts) | 514 | cp_statx(const struct kstat *stat, struct statx __user *buffer) |
| 514 | { | ||
| 515 | return (__put_user(kts->tv_sec, &uts->tv_sec ) || | ||
| 516 | __put_user(kts->tv_nsec, &uts->tv_nsec ) || | ||
| 517 | __put_user(0, &uts->__reserved )); | ||
| 518 | } | ||
| 519 | |||
| 520 | /* | ||
| 521 | * Set the statx results. | ||
| 522 | */ | ||
| 523 | static long statx_set_result(struct kstat *stat, struct statx __user *buffer) | ||
| 524 | { | 515 | { |
| 525 | uid_t uid = from_kuid_munged(current_user_ns(), stat->uid); | 516 | struct statx tmp; |
| 526 | gid_t gid = from_kgid_munged(current_user_ns(), stat->gid); | 517 | |
| 527 | 518 | memset(&tmp, 0, sizeof(tmp)); | |
| 528 | if (__put_user(stat->result_mask, &buffer->stx_mask ) || | 519 | |
| 529 | __put_user(stat->mode, &buffer->stx_mode ) || | 520 | tmp.stx_mask = stat->result_mask; |
| 530 | __clear_user(&buffer->__spare0, sizeof(buffer->__spare0)) || | 521 | tmp.stx_blksize = stat->blksize; |
| 531 | __put_user(stat->nlink, &buffer->stx_nlink ) || | 522 | tmp.stx_attributes = stat->attributes; |
| 532 | __put_user(uid, &buffer->stx_uid ) || | 523 | tmp.stx_nlink = stat->nlink; |
| 533 | __put_user(gid, &buffer->stx_gid ) || | 524 | tmp.stx_uid = from_kuid_munged(current_user_ns(), stat->uid); |
| 534 | __put_user(stat->attributes, &buffer->stx_attributes ) || | 525 | tmp.stx_gid = from_kgid_munged(current_user_ns(), stat->gid); |
| 535 | __put_user(stat->blksize, &buffer->stx_blksize ) || | 526 | tmp.stx_mode = stat->mode; |
| 536 | __put_user(MAJOR(stat->rdev), &buffer->stx_rdev_major ) || | 527 | tmp.stx_ino = stat->ino; |
| 537 | __put_user(MINOR(stat->rdev), &buffer->stx_rdev_minor ) || | 528 | tmp.stx_size = stat->size; |
| 538 | __put_user(MAJOR(stat->dev), &buffer->stx_dev_major ) || | 529 | tmp.stx_blocks = stat->blocks; |
| 539 | __put_user(MINOR(stat->dev), &buffer->stx_dev_minor ) || | 530 | tmp.stx_attributes_mask = stat->attributes_mask; |
| 540 | __put_timestamp(&stat->atime, &buffer->stx_atime ) || | 531 | tmp.stx_atime.tv_sec = stat->atime.tv_sec; |
| 541 | __put_timestamp(&stat->btime, &buffer->stx_btime ) || | 532 | tmp.stx_atime.tv_nsec = stat->atime.tv_nsec; |
| 542 | __put_timestamp(&stat->ctime, &buffer->stx_ctime ) || | 533 | tmp.stx_btime.tv_sec = stat->btime.tv_sec; |
| 543 | __put_timestamp(&stat->mtime, &buffer->stx_mtime ) || | 534 | tmp.stx_btime.tv_nsec = stat->btime.tv_nsec; |
| 544 | __put_user(stat->ino, &buffer->stx_ino ) || | 535 | tmp.stx_ctime.tv_sec = stat->ctime.tv_sec; |
| 545 | __put_user(stat->size, &buffer->stx_size ) || | 536 | tmp.stx_ctime.tv_nsec = stat->ctime.tv_nsec; |
| 546 | __put_user(stat->blocks, &buffer->stx_blocks ) || | 537 | tmp.stx_mtime.tv_sec = stat->mtime.tv_sec; |
| 547 | __clear_user(&buffer->__spare1, sizeof(buffer->__spare1)) || | 538 | tmp.stx_mtime.tv_nsec = stat->mtime.tv_nsec; |
| 548 | __clear_user(&buffer->__spare2, sizeof(buffer->__spare2))) | 539 | tmp.stx_rdev_major = MAJOR(stat->rdev); |
| 549 | return -EFAULT; | 540 | tmp.stx_rdev_minor = MINOR(stat->rdev); |
| 550 | 541 | tmp.stx_dev_major = MAJOR(stat->dev); | |
| 551 | return 0; | 542 | tmp.stx_dev_minor = MINOR(stat->dev); |
| 543 | |||
| 544 | return copy_to_user(buffer, &tmp, sizeof(tmp)) ? -EFAULT : 0; | ||
| 552 | } | 545 | } |
| 553 | 546 | ||
| 554 | /** | 547 | /** |
| @@ -570,10 +563,10 @@ SYSCALL_DEFINE5(statx, | |||
| 570 | struct kstat stat; | 563 | struct kstat stat; |
| 571 | int error; | 564 | int error; |
| 572 | 565 | ||
| 566 | if (mask & STATX__RESERVED) | ||
| 567 | return -EINVAL; | ||
| 573 | if ((flags & AT_STATX_SYNC_TYPE) == AT_STATX_SYNC_TYPE) | 568 | if ((flags & AT_STATX_SYNC_TYPE) == AT_STATX_SYNC_TYPE) |
| 574 | return -EINVAL; | 569 | return -EINVAL; |
| 575 | if (!access_ok(VERIFY_WRITE, buffer, sizeof(*buffer))) | ||
| 576 | return -EFAULT; | ||
| 577 | 570 | ||
| 578 | if (filename) | 571 | if (filename) |
| 579 | error = vfs_statx(dfd, filename, flags, &stat, mask); | 572 | error = vfs_statx(dfd, filename, flags, &stat, mask); |
| @@ -581,7 +574,8 @@ SYSCALL_DEFINE5(statx, | |||
| 581 | error = vfs_statx_fd(dfd, &stat, mask, flags); | 574 | error = vfs_statx_fd(dfd, &stat, mask, flags); |
| 582 | if (error) | 575 | if (error) |
| 583 | return error; | 576 | return error; |
| 584 | return statx_set_result(&stat, buffer); | 577 | |
| 578 | return cp_statx(&stat, buffer); | ||
| 585 | } | 579 | } |
| 586 | 580 | ||
| 587 | /* Caller is here responsible for sufficient locking (ie. inode->i_lock) */ | 581 | /* Caller is here responsible for sufficient locking (ie. inode->i_lock) */ |
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index b803213d1307..39c75a86c67f 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
| @@ -108,7 +108,7 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf, | |||
| 108 | { | 108 | { |
| 109 | const struct sysfs_ops *ops = sysfs_file_ops(of->kn); | 109 | const struct sysfs_ops *ops = sysfs_file_ops(of->kn); |
| 110 | struct kobject *kobj = of->kn->parent->priv; | 110 | struct kobject *kobj = of->kn->parent->priv; |
| 111 | size_t len; | 111 | ssize_t len; |
| 112 | 112 | ||
| 113 | /* | 113 | /* |
| 114 | * If buf != of->prealloc_buf, we don't know how | 114 | * If buf != of->prealloc_buf, we don't know how |
| @@ -117,13 +117,15 @@ static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf, | |||
| 117 | if (WARN_ON_ONCE(buf != of->prealloc_buf)) | 117 | if (WARN_ON_ONCE(buf != of->prealloc_buf)) |
| 118 | return 0; | 118 | return 0; |
| 119 | len = ops->show(kobj, of->kn->priv, buf); | 119 | len = ops->show(kobj, of->kn->priv, buf); |
| 120 | if (len < 0) | ||
| 121 | return len; | ||
| 120 | if (pos) { | 122 | if (pos) { |
| 121 | if (len <= pos) | 123 | if (len <= pos) |
| 122 | return 0; | 124 | return 0; |
| 123 | len -= pos; | 125 | len -= pos; |
| 124 | memmove(buf, buf + pos, len); | 126 | memmove(buf, buf + pos, len); |
| 125 | } | 127 | } |
| 126 | return min(count, len); | 128 | return min_t(ssize_t, count, len); |
| 127 | } | 129 | } |
| 128 | 130 | ||
| 129 | /* kernfs write callback for regular sysfs files */ | 131 | /* kernfs write callback for regular sysfs files */ |
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c index 1e712a364680..718b749fa11a 100644 --- a/fs/ubifs/debug.c +++ b/fs/ubifs/debug.c | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | #include <linux/math64.h> | 32 | #include <linux/math64.h> |
| 33 | #include <linux/uaccess.h> | 33 | #include <linux/uaccess.h> |
| 34 | #include <linux/random.h> | 34 | #include <linux/random.h> |
| 35 | #include <linux/ctype.h> | ||
| 35 | #include "ubifs.h" | 36 | #include "ubifs.h" |
| 36 | 37 | ||
| 37 | static DEFINE_SPINLOCK(dbg_lock); | 38 | static DEFINE_SPINLOCK(dbg_lock); |
| @@ -286,8 +287,10 @@ void ubifs_dump_inode(struct ubifs_info *c, const struct inode *inode) | |||
| 286 | break; | 287 | break; |
| 287 | } | 288 | } |
| 288 | 289 | ||
| 289 | pr_err("\t%d: %s (%s)\n", | 290 | pr_err("\t%d: inode %llu, type %s, len %d\n", |
| 290 | count++, dent->name, get_dent_type(dent->type)); | 291 | count++, (unsigned long long) le64_to_cpu(dent->inum), |
| 292 | get_dent_type(dent->type), | ||
| 293 | le16_to_cpu(dent->nlen)); | ||
| 291 | 294 | ||
| 292 | fname_name(&nm) = dent->name; | 295 | fname_name(&nm) = dent->name; |
| 293 | fname_len(&nm) = le16_to_cpu(dent->nlen); | 296 | fname_len(&nm) = le16_to_cpu(dent->nlen); |
| @@ -464,7 +467,8 @@ void ubifs_dump_node(const struct ubifs_info *c, const void *node) | |||
| 464 | pr_err("(bad name length, not printing, bad or corrupted node)"); | 467 | pr_err("(bad name length, not printing, bad or corrupted node)"); |
| 465 | else { | 468 | else { |
| 466 | for (i = 0; i < nlen && dent->name[i]; i++) | 469 | for (i = 0; i < nlen && dent->name[i]; i++) |
| 467 | pr_cont("%c", dent->name[i]); | 470 | pr_cont("%c", isprint(dent->name[i]) ? |
| 471 | dent->name[i] : '?'); | ||
| 468 | } | 472 | } |
| 469 | pr_cont("\n"); | 473 | pr_cont("\n"); |
| 470 | 474 | ||
diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 30825d882aa9..b777bddaa1dd 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c | |||
| @@ -606,8 +606,8 @@ static int ubifs_readdir(struct file *file, struct dir_context *ctx) | |||
| 606 | } | 606 | } |
| 607 | 607 | ||
| 608 | while (1) { | 608 | while (1) { |
| 609 | dbg_gen("feed '%s', ino %llu, new f_pos %#x", | 609 | dbg_gen("ino %llu, new f_pos %#x", |
| 610 | dent->name, (unsigned long long)le64_to_cpu(dent->inum), | 610 | (unsigned long long)le64_to_cpu(dent->inum), |
| 611 | key_hash_flash(c, &dent->key)); | 611 | key_hash_flash(c, &dent->key)); |
| 612 | ubifs_assert(le64_to_cpu(dent->ch.sqnum) > | 612 | ubifs_assert(le64_to_cpu(dent->ch.sqnum) > |
| 613 | ubifs_inode(dir)->creat_sqnum); | 613 | ubifs_inode(dir)->creat_sqnum); |
| @@ -748,6 +748,11 @@ static int ubifs_link(struct dentry *old_dentry, struct inode *dir, | |||
| 748 | goto out_fname; | 748 | goto out_fname; |
| 749 | 749 | ||
| 750 | lock_2_inodes(dir, inode); | 750 | lock_2_inodes(dir, inode); |
| 751 | |||
| 752 | /* Handle O_TMPFILE corner case, it is allowed to link a O_TMPFILE. */ | ||
| 753 | if (inode->i_nlink == 0) | ||
| 754 | ubifs_delete_orphan(c, inode->i_ino); | ||
| 755 | |||
| 751 | inc_nlink(inode); | 756 | inc_nlink(inode); |
| 752 | ihold(inode); | 757 | ihold(inode); |
| 753 | inode->i_ctime = ubifs_current_time(inode); | 758 | inode->i_ctime = ubifs_current_time(inode); |
| @@ -768,6 +773,8 @@ out_cancel: | |||
| 768 | dir->i_size -= sz_change; | 773 | dir->i_size -= sz_change; |
| 769 | dir_ui->ui_size = dir->i_size; | 774 | dir_ui->ui_size = dir->i_size; |
| 770 | drop_nlink(inode); | 775 | drop_nlink(inode); |
| 776 | if (inode->i_nlink == 0) | ||
| 777 | ubifs_add_orphan(c, inode->i_ino); | ||
| 771 | unlock_2_inodes(dir, inode); | 778 | unlock_2_inodes(dir, inode); |
| 772 | ubifs_release_budget(c, &req); | 779 | ubifs_release_budget(c, &req); |
| 773 | iput(inode); | 780 | iput(inode); |
| @@ -1068,8 +1075,10 @@ static int ubifs_mknod(struct inode *dir, struct dentry *dentry, | |||
| 1068 | } | 1075 | } |
| 1069 | 1076 | ||
| 1070 | err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm); | 1077 | err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm); |
| 1071 | if (err) | 1078 | if (err) { |
| 1079 | kfree(dev); | ||
| 1072 | goto out_budg; | 1080 | goto out_budg; |
| 1081 | } | ||
| 1073 | 1082 | ||
| 1074 | sz_change = CALC_DENT_SIZE(fname_len(&nm)); | 1083 | sz_change = CALC_DENT_SIZE(fname_len(&nm)); |
| 1075 | 1084 | ||
| @@ -1316,9 +1325,6 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
| 1316 | unsigned int uninitialized_var(saved_nlink); | 1325 | unsigned int uninitialized_var(saved_nlink); |
| 1317 | struct fscrypt_name old_nm, new_nm; | 1326 | struct fscrypt_name old_nm, new_nm; |
| 1318 | 1327 | ||
| 1319 | if (flags & ~RENAME_NOREPLACE) | ||
| 1320 | return -EINVAL; | ||
| 1321 | |||
| 1322 | /* | 1328 | /* |
| 1323 | * Budget request settings: deletion direntry, new direntry, removing | 1329 | * Budget request settings: deletion direntry, new direntry, removing |
| 1324 | * the old inode, and changing old and new parent directory inodes. | 1330 | * the old inode, and changing old and new parent directory inodes. |
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 1d227b0fcf49..f7555fc25877 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c | |||
| @@ -1756,7 +1756,7 @@ static void userfaultfd_show_fdinfo(struct seq_file *m, struct file *f) | |||
| 1756 | * protocols: aa:... bb:... | 1756 | * protocols: aa:... bb:... |
| 1757 | */ | 1757 | */ |
| 1758 | seq_printf(m, "pending:\t%lu\ntotal:\t%lu\nAPI:\t%Lx:%x:%Lx\n", | 1758 | seq_printf(m, "pending:\t%lu\ntotal:\t%lu\nAPI:\t%Lx:%x:%Lx\n", |
| 1759 | pending, total, UFFD_API, UFFD_API_FEATURES, | 1759 | pending, total, UFFD_API, ctx->features, |
| 1760 | UFFD_API_IOCTLS|UFFD_API_RANGE_IOCTLS); | 1760 | UFFD_API_IOCTLS|UFFD_API_RANGE_IOCTLS); |
| 1761 | } | 1761 | } |
| 1762 | #endif | 1762 | #endif |
diff --git a/fs/xfs/libxfs/xfs_dir2_priv.h b/fs/xfs/libxfs/xfs_dir2_priv.h index eb00bc133bca..39f8604f764e 100644 --- a/fs/xfs/libxfs/xfs_dir2_priv.h +++ b/fs/xfs/libxfs/xfs_dir2_priv.h | |||
| @@ -125,8 +125,7 @@ extern int xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino); | |||
| 125 | extern int xfs_dir2_sf_lookup(struct xfs_da_args *args); | 125 | extern int xfs_dir2_sf_lookup(struct xfs_da_args *args); |
| 126 | extern int xfs_dir2_sf_removename(struct xfs_da_args *args); | 126 | extern int xfs_dir2_sf_removename(struct xfs_da_args *args); |
| 127 | extern int xfs_dir2_sf_replace(struct xfs_da_args *args); | 127 | extern int xfs_dir2_sf_replace(struct xfs_da_args *args); |
| 128 | extern int xfs_dir2_sf_verify(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *sfp, | 128 | extern int xfs_dir2_sf_verify(struct xfs_inode *ip); |
| 129 | int size); | ||
| 130 | 129 | ||
| 131 | /* xfs_dir2_readdir.c */ | 130 | /* xfs_dir2_readdir.c */ |
| 132 | extern int xfs_readdir(struct xfs_inode *dp, struct dir_context *ctx, | 131 | extern int xfs_readdir(struct xfs_inode *dp, struct dir_context *ctx, |
diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 96b45cd6c63f..e84af093b2ab 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c | |||
| @@ -632,36 +632,49 @@ xfs_dir2_sf_check( | |||
| 632 | /* Verify the consistency of an inline directory. */ | 632 | /* Verify the consistency of an inline directory. */ |
| 633 | int | 633 | int |
| 634 | xfs_dir2_sf_verify( | 634 | xfs_dir2_sf_verify( |
| 635 | struct xfs_mount *mp, | 635 | struct xfs_inode *ip) |
| 636 | struct xfs_dir2_sf_hdr *sfp, | ||
| 637 | int size) | ||
| 638 | { | 636 | { |
| 637 | struct xfs_mount *mp = ip->i_mount; | ||
| 638 | struct xfs_dir2_sf_hdr *sfp; | ||
| 639 | struct xfs_dir2_sf_entry *sfep; | 639 | struct xfs_dir2_sf_entry *sfep; |
| 640 | struct xfs_dir2_sf_entry *next_sfep; | 640 | struct xfs_dir2_sf_entry *next_sfep; |
| 641 | char *endp; | 641 | char *endp; |
| 642 | const struct xfs_dir_ops *dops; | 642 | const struct xfs_dir_ops *dops; |
| 643 | struct xfs_ifork *ifp; | ||
| 643 | xfs_ino_t ino; | 644 | xfs_ino_t ino; |
| 644 | int i; | 645 | int i; |
| 645 | int i8count; | 646 | int i8count; |
| 646 | int offset; | 647 | int offset; |
| 648 | int size; | ||
| 649 | int error; | ||
| 647 | __uint8_t filetype; | 650 | __uint8_t filetype; |
| 648 | 651 | ||
| 652 | ASSERT(ip->i_d.di_format == XFS_DINODE_FMT_LOCAL); | ||
| 653 | /* | ||
| 654 | * xfs_iread calls us before xfs_setup_inode sets up ip->d_ops, | ||
| 655 | * so we can only trust the mountpoint to have the right pointer. | ||
| 656 | */ | ||
| 649 | dops = xfs_dir_get_ops(mp, NULL); | 657 | dops = xfs_dir_get_ops(mp, NULL); |
| 650 | 658 | ||
| 659 | ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK); | ||
| 660 | sfp = (struct xfs_dir2_sf_hdr *)ifp->if_u1.if_data; | ||
| 661 | size = ifp->if_bytes; | ||
| 662 | |||
| 651 | /* | 663 | /* |
| 652 | * Give up if the directory is way too short. | 664 | * Give up if the directory is way too short. |
| 653 | */ | 665 | */ |
| 654 | XFS_WANT_CORRUPTED_RETURN(mp, size > | 666 | if (size <= offsetof(struct xfs_dir2_sf_hdr, parent) || |
| 655 | offsetof(struct xfs_dir2_sf_hdr, parent)); | 667 | size < xfs_dir2_sf_hdr_size(sfp->i8count)) |
| 656 | XFS_WANT_CORRUPTED_RETURN(mp, size >= | 668 | return -EFSCORRUPTED; |
| 657 | xfs_dir2_sf_hdr_size(sfp->i8count)); | ||
| 658 | 669 | ||
| 659 | endp = (char *)sfp + size; | 670 | endp = (char *)sfp + size; |
| 660 | 671 | ||
| 661 | /* Check .. entry */ | 672 | /* Check .. entry */ |
| 662 | ino = dops->sf_get_parent_ino(sfp); | 673 | ino = dops->sf_get_parent_ino(sfp); |
| 663 | i8count = ino > XFS_DIR2_MAX_SHORT_INUM; | 674 | i8count = ino > XFS_DIR2_MAX_SHORT_INUM; |
| 664 | XFS_WANT_CORRUPTED_RETURN(mp, !xfs_dir_ino_validate(mp, ino)); | 675 | error = xfs_dir_ino_validate(mp, ino); |
| 676 | if (error) | ||
| 677 | return error; | ||
| 665 | offset = dops->data_first_offset; | 678 | offset = dops->data_first_offset; |
| 666 | 679 | ||
| 667 | /* Check all reported entries */ | 680 | /* Check all reported entries */ |
| @@ -672,12 +685,12 @@ xfs_dir2_sf_verify( | |||
| 672 | * Check the fixed-offset parts of the structure are | 685 | * Check the fixed-offset parts of the structure are |
| 673 | * within the data buffer. | 686 | * within the data buffer. |
| 674 | */ | 687 | */ |
| 675 | XFS_WANT_CORRUPTED_RETURN(mp, | 688 | if (((char *)sfep + sizeof(*sfep)) >= endp) |
| 676 | ((char *)sfep + sizeof(*sfep)) < endp); | 689 | return -EFSCORRUPTED; |
| 677 | 690 | ||
| 678 | /* Don't allow names with known bad length. */ | 691 | /* Don't allow names with known bad length. */ |
| 679 | XFS_WANT_CORRUPTED_RETURN(mp, sfep->namelen > 0); | 692 | if (sfep->namelen == 0) |
| 680 | XFS_WANT_CORRUPTED_RETURN(mp, sfep->namelen < MAXNAMELEN); | 693 | return -EFSCORRUPTED; |
| 681 | 694 | ||
| 682 | /* | 695 | /* |
| 683 | * Check that the variable-length part of the structure is | 696 | * Check that the variable-length part of the structure is |
| @@ -685,33 +698,39 @@ xfs_dir2_sf_verify( | |||
| 685 | * name component, so nextentry is an acceptable test. | 698 | * name component, so nextentry is an acceptable test. |
| 686 | */ | 699 | */ |
| 687 | next_sfep = dops->sf_nextentry(sfp, sfep); | 700 | next_sfep = dops->sf_nextentry(sfp, sfep); |
| 688 | XFS_WANT_CORRUPTED_RETURN(mp, endp >= (char *)next_sfep); | 701 | if (endp < (char *)next_sfep) |
| 702 | return -EFSCORRUPTED; | ||
| 689 | 703 | ||
| 690 | /* Check that the offsets always increase. */ | 704 | /* Check that the offsets always increase. */ |
| 691 | XFS_WANT_CORRUPTED_RETURN(mp, | 705 | if (xfs_dir2_sf_get_offset(sfep) < offset) |
| 692 | xfs_dir2_sf_get_offset(sfep) >= offset); | 706 | return -EFSCORRUPTED; |
| 693 | 707 | ||
| 694 | /* Check the inode number. */ | 708 | /* Check the inode number. */ |
| 695 | ino = dops->sf_get_ino(sfp, sfep); | 709 | ino = dops->sf_get_ino(sfp, sfep); |
| 696 | i8count += ino > XFS_DIR2_MAX_SHORT_INUM; | 710 | i8count += ino > XFS_DIR2_MAX_SHORT_INUM; |
| 697 | XFS_WANT_CORRUPTED_RETURN(mp, !xfs_dir_ino_validate(mp, ino)); | 711 | error = xfs_dir_ino_validate(mp, ino); |
| 712 | if (error) | ||
| 713 | return error; | ||
| 698 | 714 | ||
| 699 | /* Check the file type. */ | 715 | /* Check the file type. */ |
| 700 | filetype = dops->sf_get_ftype(sfep); | 716 | filetype = dops->sf_get_ftype(sfep); |
| 701 | XFS_WANT_CORRUPTED_RETURN(mp, filetype < XFS_DIR3_FT_MAX); | 717 | if (filetype >= XFS_DIR3_FT_MAX) |
| 718 | return -EFSCORRUPTED; | ||
| 702 | 719 | ||
| 703 | offset = xfs_dir2_sf_get_offset(sfep) + | 720 | offset = xfs_dir2_sf_get_offset(sfep) + |
| 704 | dops->data_entsize(sfep->namelen); | 721 | dops->data_entsize(sfep->namelen); |
| 705 | 722 | ||
| 706 | sfep = next_sfep; | 723 | sfep = next_sfep; |
| 707 | } | 724 | } |
| 708 | XFS_WANT_CORRUPTED_RETURN(mp, i8count == sfp->i8count); | 725 | if (i8count != sfp->i8count) |
| 709 | XFS_WANT_CORRUPTED_RETURN(mp, (void *)sfep == (void *)endp); | 726 | return -EFSCORRUPTED; |
| 727 | if ((void *)sfep != (void *)endp) | ||
| 728 | return -EFSCORRUPTED; | ||
| 710 | 729 | ||
| 711 | /* Make sure this whole thing ought to be in local format. */ | 730 | /* Make sure this whole thing ought to be in local format. */ |
| 712 | XFS_WANT_CORRUPTED_RETURN(mp, offset + | 731 | if (offset + (sfp->count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t) + |
| 713 | (sfp->count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t) + | 732 | (uint)sizeof(xfs_dir2_block_tail_t) > mp->m_dir_geo->blksize) |
| 714 | (uint)sizeof(xfs_dir2_block_tail_t) <= mp->m_dir_geo->blksize); | 733 | return -EFSCORRUPTED; |
| 715 | 734 | ||
| 716 | return 0; | 735 | return 0; |
| 717 | } | 736 | } |
diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 9653e964eda4..8a37efe04de3 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c | |||
| @@ -212,6 +212,16 @@ xfs_iformat_fork( | |||
| 212 | if (error) | 212 | if (error) |
| 213 | return error; | 213 | return error; |
| 214 | 214 | ||
| 215 | /* Check inline dir contents. */ | ||
| 216 | if (S_ISDIR(VFS_I(ip)->i_mode) && | ||
| 217 | dip->di_format == XFS_DINODE_FMT_LOCAL) { | ||
| 218 | error = xfs_dir2_sf_verify(ip); | ||
| 219 | if (error) { | ||
| 220 | xfs_idestroy_fork(ip, XFS_DATA_FORK); | ||
| 221 | return error; | ||
| 222 | } | ||
| 223 | } | ||
| 224 | |||
| 215 | if (xfs_is_reflink_inode(ip)) { | 225 | if (xfs_is_reflink_inode(ip)) { |
| 216 | ASSERT(ip->i_cowfp == NULL); | 226 | ASSERT(ip->i_cowfp == NULL); |
| 217 | xfs_ifork_init_cow(ip); | 227 | xfs_ifork_init_cow(ip); |
| @@ -322,8 +332,6 @@ xfs_iformat_local( | |||
| 322 | int whichfork, | 332 | int whichfork, |
| 323 | int size) | 333 | int size) |
| 324 | { | 334 | { |
| 325 | int error; | ||
| 326 | |||
| 327 | /* | 335 | /* |
| 328 | * If the size is unreasonable, then something | 336 | * If the size is unreasonable, then something |
| 329 | * is wrong and we just bail out rather than crash in | 337 | * is wrong and we just bail out rather than crash in |
| @@ -339,14 +347,6 @@ xfs_iformat_local( | |||
| 339 | return -EFSCORRUPTED; | 347 | return -EFSCORRUPTED; |
| 340 | } | 348 | } |
| 341 | 349 | ||
| 342 | if (S_ISDIR(VFS_I(ip)->i_mode) && whichfork == XFS_DATA_FORK) { | ||
| 343 | error = xfs_dir2_sf_verify(ip->i_mount, | ||
| 344 | (struct xfs_dir2_sf_hdr *)XFS_DFORK_DPTR(dip), | ||
| 345 | size); | ||
| 346 | if (error) | ||
| 347 | return error; | ||
| 348 | } | ||
| 349 | |||
| 350 | xfs_init_local_fork(ip, whichfork, XFS_DFORK_PTR(dip, whichfork), size); | 350 | xfs_init_local_fork(ip, whichfork, XFS_DFORK_PTR(dip, whichfork), size); |
| 351 | return 0; | 351 | return 0; |
| 352 | } | 352 | } |
| @@ -867,7 +867,7 @@ xfs_iextents_copy( | |||
| 867 | * In these cases, the format always takes precedence, because the | 867 | * In these cases, the format always takes precedence, because the |
| 868 | * format indicates the current state of the fork. | 868 | * format indicates the current state of the fork. |
| 869 | */ | 869 | */ |
| 870 | int | 870 | void |
| 871 | xfs_iflush_fork( | 871 | xfs_iflush_fork( |
| 872 | xfs_inode_t *ip, | 872 | xfs_inode_t *ip, |
| 873 | xfs_dinode_t *dip, | 873 | xfs_dinode_t *dip, |
| @@ -877,7 +877,6 @@ xfs_iflush_fork( | |||
| 877 | char *cp; | 877 | char *cp; |
| 878 | xfs_ifork_t *ifp; | 878 | xfs_ifork_t *ifp; |
| 879 | xfs_mount_t *mp; | 879 | xfs_mount_t *mp; |
| 880 | int error; | ||
| 881 | static const short brootflag[2] = | 880 | static const short brootflag[2] = |
| 882 | { XFS_ILOG_DBROOT, XFS_ILOG_ABROOT }; | 881 | { XFS_ILOG_DBROOT, XFS_ILOG_ABROOT }; |
| 883 | static const short dataflag[2] = | 882 | static const short dataflag[2] = |
| @@ -886,7 +885,7 @@ xfs_iflush_fork( | |||
| 886 | { XFS_ILOG_DEXT, XFS_ILOG_AEXT }; | 885 | { XFS_ILOG_DEXT, XFS_ILOG_AEXT }; |
| 887 | 886 | ||
| 888 | if (!iip) | 887 | if (!iip) |
| 889 | return 0; | 888 | return; |
| 890 | ifp = XFS_IFORK_PTR(ip, whichfork); | 889 | ifp = XFS_IFORK_PTR(ip, whichfork); |
| 891 | /* | 890 | /* |
| 892 | * This can happen if we gave up in iformat in an error path, | 891 | * This can happen if we gave up in iformat in an error path, |
| @@ -894,19 +893,12 @@ xfs_iflush_fork( | |||
| 894 | */ | 893 | */ |
| 895 | if (!ifp) { | 894 | if (!ifp) { |
| 896 | ASSERT(whichfork == XFS_ATTR_FORK); | 895 | ASSERT(whichfork == XFS_ATTR_FORK); |
| 897 | return 0; | 896 | return; |
| 898 | } | 897 | } |
| 899 | cp = XFS_DFORK_PTR(dip, whichfork); | 898 | cp = XFS_DFORK_PTR(dip, whichfork); |
| 900 | mp = ip->i_mount; | 899 | mp = ip->i_mount; |
| 901 | switch (XFS_IFORK_FORMAT(ip, whichfork)) { | 900 | switch (XFS_IFORK_FORMAT(ip, whichfork)) { |
| 902 | case XFS_DINODE_FMT_LOCAL: | 901 | case XFS_DINODE_FMT_LOCAL: |
| 903 | if (S_ISDIR(VFS_I(ip)->i_mode) && whichfork == XFS_DATA_FORK) { | ||
| 904 | error = xfs_dir2_sf_verify(mp, | ||
| 905 | (struct xfs_dir2_sf_hdr *)ifp->if_u1.if_data, | ||
| 906 | ifp->if_bytes); | ||
| 907 | if (error) | ||
| 908 | return error; | ||
| 909 | } | ||
| 910 | if ((iip->ili_fields & dataflag[whichfork]) && | 902 | if ((iip->ili_fields & dataflag[whichfork]) && |
| 911 | (ifp->if_bytes > 0)) { | 903 | (ifp->if_bytes > 0)) { |
| 912 | ASSERT(ifp->if_u1.if_data != NULL); | 904 | ASSERT(ifp->if_u1.if_data != NULL); |
| @@ -959,7 +951,6 @@ xfs_iflush_fork( | |||
| 959 | ASSERT(0); | 951 | ASSERT(0); |
| 960 | break; | 952 | break; |
| 961 | } | 953 | } |
| 962 | return 0; | ||
| 963 | } | 954 | } |
| 964 | 955 | ||
| 965 | /* | 956 | /* |
diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 132dc59fdde6..7fb8365326d1 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h | |||
| @@ -140,7 +140,7 @@ typedef struct xfs_ifork { | |||
| 140 | struct xfs_ifork *xfs_iext_state_to_fork(struct xfs_inode *ip, int state); | 140 | struct xfs_ifork *xfs_iext_state_to_fork(struct xfs_inode *ip, int state); |
| 141 | 141 | ||
| 142 | int xfs_iformat_fork(struct xfs_inode *, struct xfs_dinode *); | 142 | int xfs_iformat_fork(struct xfs_inode *, struct xfs_dinode *); |
| 143 | int xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *, | 143 | void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *, |
| 144 | struct xfs_inode_log_item *, int); | 144 | struct xfs_inode_log_item *, int); |
| 145 | void xfs_idestroy_fork(struct xfs_inode *, int); | 145 | void xfs_idestroy_fork(struct xfs_inode *, int); |
| 146 | void xfs_idata_realloc(struct xfs_inode *, int, int); | 146 | void xfs_idata_realloc(struct xfs_inode *, int, int); |
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 8b75dcea5966..828532ce0adc 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c | |||
| @@ -1311,8 +1311,16 @@ xfs_free_file_space( | |||
| 1311 | /* | 1311 | /* |
| 1312 | * Now that we've unmap all full blocks we'll have to zero out any | 1312 | * Now that we've unmap all full blocks we'll have to zero out any |
| 1313 | * partial block at the beginning and/or end. xfs_zero_range is | 1313 | * partial block at the beginning and/or end. xfs_zero_range is |
| 1314 | * smart enough to skip any holes, including those we just created. | 1314 | * smart enough to skip any holes, including those we just created, |
| 1315 | * but we must take care not to zero beyond EOF and enlarge i_size. | ||
| 1315 | */ | 1316 | */ |
| 1317 | |||
| 1318 | if (offset >= XFS_ISIZE(ip)) | ||
| 1319 | return 0; | ||
| 1320 | |||
| 1321 | if (offset + len > XFS_ISIZE(ip)) | ||
| 1322 | len = XFS_ISIZE(ip) - offset; | ||
| 1323 | |||
| 1316 | return xfs_zero_range(ip, offset, len, NULL); | 1324 | return xfs_zero_range(ip, offset, len, NULL); |
| 1317 | } | 1325 | } |
| 1318 | 1326 | ||
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index c7fe2c2123ab..7605d8396596 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c | |||
| @@ -50,6 +50,7 @@ | |||
| 50 | #include "xfs_log.h" | 50 | #include "xfs_log.h" |
| 51 | #include "xfs_bmap_btree.h" | 51 | #include "xfs_bmap_btree.h" |
| 52 | #include "xfs_reflink.h" | 52 | #include "xfs_reflink.h" |
| 53 | #include "xfs_dir2_priv.h" | ||
| 53 | 54 | ||
| 54 | kmem_zone_t *xfs_inode_zone; | 55 | kmem_zone_t *xfs_inode_zone; |
| 55 | 56 | ||
| @@ -3475,7 +3476,6 @@ xfs_iflush_int( | |||
| 3475 | struct xfs_inode_log_item *iip = ip->i_itemp; | 3476 | struct xfs_inode_log_item *iip = ip->i_itemp; |
| 3476 | struct xfs_dinode *dip; | 3477 | struct xfs_dinode *dip; |
| 3477 | struct xfs_mount *mp = ip->i_mount; | 3478 | struct xfs_mount *mp = ip->i_mount; |
| 3478 | int error; | ||
| 3479 | 3479 | ||
| 3480 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)); | 3480 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)); |
| 3481 | ASSERT(xfs_isiflocked(ip)); | 3481 | ASSERT(xfs_isiflocked(ip)); |
| @@ -3547,6 +3547,12 @@ xfs_iflush_int( | |||
| 3547 | if (ip->i_d.di_version < 3) | 3547 | if (ip->i_d.di_version < 3) |
| 3548 | ip->i_d.di_flushiter++; | 3548 | ip->i_d.di_flushiter++; |
| 3549 | 3549 | ||
| 3550 | /* Check the inline directory data. */ | ||
| 3551 | if (S_ISDIR(VFS_I(ip)->i_mode) && | ||
| 3552 | ip->i_d.di_format == XFS_DINODE_FMT_LOCAL && | ||
| 3553 | xfs_dir2_sf_verify(ip)) | ||
| 3554 | goto corrupt_out; | ||
| 3555 | |||
| 3550 | /* | 3556 | /* |
| 3551 | * Copy the dirty parts of the inode into the on-disk inode. We always | 3557 | * Copy the dirty parts of the inode into the on-disk inode. We always |
| 3552 | * copy out the core of the inode, because if the inode is dirty at all | 3558 | * copy out the core of the inode, because if the inode is dirty at all |
| @@ -3558,14 +3564,9 @@ xfs_iflush_int( | |||
| 3558 | if (ip->i_d.di_flushiter == DI_MAX_FLUSH) | 3564 | if (ip->i_d.di_flushiter == DI_MAX_FLUSH) |
| 3559 | ip->i_d.di_flushiter = 0; | 3565 | ip->i_d.di_flushiter = 0; |
| 3560 | 3566 | ||
| 3561 | error = xfs_iflush_fork(ip, dip, iip, XFS_DATA_FORK); | 3567 | xfs_iflush_fork(ip, dip, iip, XFS_DATA_FORK); |
| 3562 | if (error) | 3568 | if (XFS_IFORK_Q(ip)) |
| 3563 | return error; | 3569 | xfs_iflush_fork(ip, dip, iip, XFS_ATTR_FORK); |
| 3564 | if (XFS_IFORK_Q(ip)) { | ||
| 3565 | error = xfs_iflush_fork(ip, dip, iip, XFS_ATTR_FORK); | ||
| 3566 | if (error) | ||
| 3567 | return error; | ||
| 3568 | } | ||
| 3569 | xfs_inobp_check(mp, bp); | 3570 | xfs_inobp_check(mp, bp); |
| 3570 | 3571 | ||
| 3571 | /* | 3572 | /* |
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 229cc6a6d8ef..ebfc13350f9a 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c | |||
| @@ -516,6 +516,20 @@ xfs_vn_getattr( | |||
| 516 | stat->blocks = | 516 | stat->blocks = |
| 517 | XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks); | 517 | XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks); |
| 518 | 518 | ||
| 519 | if (ip->i_d.di_version == 3) { | ||
| 520 | if (request_mask & STATX_BTIME) { | ||
| 521 | stat->result_mask |= STATX_BTIME; | ||
| 522 | stat->btime.tv_sec = ip->i_d.di_crtime.t_sec; | ||
| 523 | stat->btime.tv_nsec = ip->i_d.di_crtime.t_nsec; | ||
| 524 | } | ||
| 525 | } | ||
| 526 | |||
| 527 | if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE) | ||
| 528 | stat->attributes |= STATX_ATTR_IMMUTABLE; | ||
| 529 | if (ip->i_d.di_flags & XFS_DIFLAG_APPEND) | ||
| 530 | stat->attributes |= STATX_ATTR_APPEND; | ||
| 531 | if (ip->i_d.di_flags & XFS_DIFLAG_NODUMP) | ||
| 532 | stat->attributes |= STATX_ATTR_NODUMP; | ||
| 519 | 533 | ||
| 520 | switch (inode->i_mode & S_IFMT) { | 534 | switch (inode->i_mode & S_IFMT) { |
| 521 | case S_IFBLK: | 535 | case S_IFBLK: |
diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c index 2a6d9b1558e0..26d67ce3c18d 100644 --- a/fs/xfs/xfs_itable.c +++ b/fs/xfs/xfs_itable.c | |||
| @@ -583,7 +583,7 @@ xfs_inumbers( | |||
| 583 | return error; | 583 | return error; |
| 584 | 584 | ||
| 585 | bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer))); | 585 | bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer))); |
| 586 | buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP); | 586 | buffer = kmem_zalloc(bcount * sizeof(*buffer), KM_SLEEP); |
| 587 | do { | 587 | do { |
| 588 | struct xfs_inobt_rec_incore r; | 588 | struct xfs_inobt_rec_incore r; |
| 589 | int stat; | 589 | int stat; |
