diff options
author | Jens Axboe <axboe@fb.com> | 2017-04-07 14:45:20 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2017-04-07 14:45:20 -0400 |
commit | 65f619d2535197d97067eeeef75a40f25b552e69 (patch) | |
tree | 13f96c51a2b591ed22f1771541998bb77178f685 /fs | |
parent | fbbaf700e7b163a0f1704b2d542ee28be11fce21 (diff) | |
parent | 6d8c6c0f97ad8a3517c42b179c1dc8e77397d0e2 (diff) |
Merge branch 'for-linus' into for-4.12/block
We've added a considerable amount of fixes for stalls and issues
with the blk-mq scheduling in the 4.11 series since forking
off the for-4.12/block branch. We need to do improvements on
top of that for 4.12, so pull in the previous fixes to make
our lives easier going forward.
Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/extent_io.c | 3 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 14 | ||||
-rw-r--r-- | fs/crypto/crypto.c | 10 | ||||
-rw-r--r-- | fs/crypto/fname.c | 2 | ||||
-rw-r--r-- | fs/crypto/fscrypt_private.h | 4 | ||||
-rw-r--r-- | fs/crypto/keyinfo.c | 52 | ||||
-rw-r--r-- | fs/crypto/policy.c | 7 | ||||
-rw-r--r-- | fs/ext4/inline.c | 5 | ||||
-rw-r--r-- | fs/ext4/inode.c | 2 | ||||
-rw-r--r-- | fs/ext4/move_extent.c | 2 | ||||
-rw-r--r-- | fs/ext4/super.c | 10 | ||||
-rw-r--r-- | fs/ext4/xattr.c | 65 | ||||
-rw-r--r-- | fs/f2fs/debug.c | 1 | ||||
-rw-r--r-- | fs/f2fs/dir.c | 2 | ||||
-rw-r--r-- | fs/f2fs/f2fs.h | 2 | ||||
-rw-r--r-- | fs/f2fs/node.c | 163 | ||||
-rw-r--r-- | fs/f2fs/segment.c | 6 | ||||
-rw-r--r-- | fs/jbd2/journal.c | 22 | ||||
-rw-r--r-- | fs/jbd2/revoke.c | 1 | ||||
-rw-r--r-- | fs/kernfs/file.c | 3 |
20 files changed, 167 insertions, 209 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 28e81922a21c..8df797432740 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++) { |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index c40060cc481f..231503935652 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 | } |
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); |
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..4247d8d25687 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -5400,7 +5400,7 @@ int ext4_getattr(const struct path *path, struct kstat *stat, | |||
5400 | * If there is inline data in the inode, the inode will normally not | 5400 | * 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). | 5401 | * 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, | 5402 | * Report at least one sector for such files, so tools like tar, rsync, |
5403 | * others doen't incorrectly think the file is completely sparse. | 5403 | * others don't incorrectly think the file is completely sparse. |
5404 | */ | 5404 | */ |
5405 | if (unlikely(ext4_has_inline_data(inode))) | 5405 | if (unlikely(ext4_has_inline_data(inode))) |
5406 | stat->blocks += (stat->size + 511) >> 9; | 5406 | 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/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/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/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); |