Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4

Pull ext4 updates from Ted Ts'o:
"Lots of bug fixes and cleanups"

* tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (40 commits)
ext4: remove unused variable
ext4: use journal inode to determine journal overhead
ext4: create function to read journal inode
ext4: unmap metadata when zeroing blocks
ext4: remove plugging from ext4_file_write_iter()
ext4: allow unlocked direct IO when pages are cached
ext4: require encryption feature for EXT4_IOC_SET_ENCRYPTION_POLICY
fscrypto: use standard macros to compute length of fname ciphertext
ext4: do not unnecessarily null-terminate encrypted symlink data
ext4: release bh in make_indexed_dir
ext4: Allow parallel DIO reads
ext4: allow DAX writeback for hole punch
jbd2: fix lockdep annotation in add_transaction_credits()
blockgroup_lock.h: simplify definition of NR_BG_LOCKS
blockgroup_lock.h: remove debris from bgl_lock_ptr() conversion
fscrypto: make filename crypto functions return 0 on success
fscrypto: rename completion callbacks to reflect usage
fscrypto: remove unnecessary includes
fscrypto: improved validation when loading inode encryption metadata
ext4: fix memory leak when symlink decryption fails
...

+535 -525
+5 -6
fs/crypto/crypto.c
··· 28 28 #include <linux/dcache.h> 29 29 #include <linux/namei.h> 30 30 #include <linux/fscrypto.h> 31 - #include <linux/ecryptfs.h> 32 31 33 32 static unsigned int num_prealloc_crypto_pages = 32; 34 33 static unsigned int num_prealloc_crypto_ctxs = 128; ··· 127 128 EXPORT_SYMBOL(fscrypt_get_ctx); 128 129 129 130 /** 130 - * fscrypt_complete() - The completion callback for page encryption 131 - * @req: The asynchronous encryption request context 132 - * @res: The result of the encryption operation 131 + * page_crypt_complete() - completion callback for page crypto 132 + * @req: The asynchronous cipher request context 133 + * @res: The result of the cipher operation 133 134 */ 134 - static void fscrypt_complete(struct crypto_async_request *req, int res) 135 + static void page_crypt_complete(struct crypto_async_request *req, int res) 135 136 { 136 137 struct fscrypt_completion_result *ecr = req->data; 137 138 ··· 169 170 170 171 skcipher_request_set_callback( 171 172 req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, 172 - fscrypt_complete, &ecr); 173 + page_crypt_complete, &ecr); 173 174 174 175 BUILD_BUG_ON(FS_XTS_TWEAK_SIZE < sizeof(index)); 175 176 memcpy(xts_tweak, &index, sizeof(index));
+43 -42
fs/crypto/fname.c
··· 10 10 * This has not yet undergone a rigorous security audit. 11 11 */ 12 12 13 - #include <keys/encrypted-type.h> 14 - #include <keys/user-type.h> 15 13 #include <linux/scatterlist.h> 16 14 #include <linux/ratelimit.h> 17 15 #include <linux/fscrypto.h> 18 16 19 - static u32 size_round_up(size_t size, size_t blksize) 20 - { 21 - return ((size + blksize - 1) / blksize) * blksize; 22 - } 23 - 24 17 /** 25 - * dir_crypt_complete() - 18 + * fname_crypt_complete() - completion callback for filename crypto 19 + * @req: The asynchronous cipher request context 20 + * @res: The result of the cipher operation 26 21 */ 27 - static void dir_crypt_complete(struct crypto_async_request *req, int res) 22 + static void fname_crypt_complete(struct crypto_async_request *req, int res) 28 23 { 29 24 struct fscrypt_completion_result *ecr = req->data; 30 25 ··· 30 35 } 31 36 32 37 /** 33 - * fname_encrypt() - 38 + * fname_encrypt() - encrypt a filename 34 39 * 35 - * This function encrypts the input filename, and returns the length of the 36 - * ciphertext. Errors are returned as negative numbers. We trust the caller to 37 - * allocate sufficient memory to oname string. 40 + * The caller must have allocated sufficient memory for the @oname string. 41 + * 42 + * Return: 0 on success, -errno on failure 38 43 */ 39 44 static int fname_encrypt(struct inode *inode, 40 45 const struct qstr *iname, struct fscrypt_str *oname) ··· 55 60 if (iname->len <= 0 || iname->len > lim) 56 61 return -EIO; 57 62 58 - ciphertext_len = (iname->len < FS_CRYPTO_BLOCK_SIZE) ? 59 - FS_CRYPTO_BLOCK_SIZE : iname->len; 60 - ciphertext_len = size_round_up(ciphertext_len, padding); 61 - ciphertext_len = (ciphertext_len > lim) ? lim : ciphertext_len; 63 + ciphertext_len = max(iname->len, (u32)FS_CRYPTO_BLOCK_SIZE); 64 + ciphertext_len = round_up(ciphertext_len, padding); 65 + ciphertext_len = min(ciphertext_len, lim); 62 66 63 67 if (ciphertext_len <= sizeof(buf)) { 64 68 workbuf = buf; ··· 78 84 } 79 85 skcipher_request_set_callback(req, 80 86 CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, 81 - dir_crypt_complete, &ecr); 87 + fname_crypt_complete, &ecr); 82 88 83 89 /* Copy the input */ 84 90 memcpy(workbuf, iname->name, iname->len); ··· 99 105 } 100 106 kfree(alloc_buf); 101 107 skcipher_request_free(req); 102 - if (res < 0) 108 + if (res < 0) { 103 109 printk_ratelimited(KERN_ERR 104 110 "%s: Error (error code %d)\n", __func__, res); 111 + return res; 112 + } 105 113 106 114 oname->len = ciphertext_len; 107 - return res; 115 + return 0; 108 116 } 109 117 110 - /* 111 - * fname_decrypt() 112 - * This function decrypts the input filename, and returns 113 - * the length of the plaintext. 114 - * Errors are returned as negative numbers. 115 - * We trust the caller to allocate sufficient memory to oname string. 118 + /** 119 + * fname_decrypt() - decrypt a filename 120 + * 121 + * The caller must have allocated sufficient memory for the @oname string. 122 + * 123 + * Return: 0 on success, -errno on failure 116 124 */ 117 125 static int fname_decrypt(struct inode *inode, 118 126 const struct fscrypt_str *iname, ··· 142 146 } 143 147 skcipher_request_set_callback(req, 144 148 CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, 145 - dir_crypt_complete, &ecr); 149 + fname_crypt_complete, &ecr); 146 150 147 151 /* Initialize IV */ 148 152 memset(iv, 0, FS_CRYPTO_BLOCK_SIZE); ··· 164 168 } 165 169 166 170 oname->len = strnlen(oname->name, iname->len); 167 - return oname->len; 171 + return 0; 168 172 } 169 173 170 174 static const char *lookup_table = ··· 227 231 228 232 if (ci) 229 233 padding = 4 << (ci->ci_flags & FS_POLICY_FLAGS_PAD_MASK); 230 - if (ilen < FS_CRYPTO_BLOCK_SIZE) 231 - ilen = FS_CRYPTO_BLOCK_SIZE; 232 - return size_round_up(ilen, padding); 234 + ilen = max(ilen, (u32)FS_CRYPTO_BLOCK_SIZE); 235 + return round_up(ilen, padding); 233 236 } 234 237 EXPORT_SYMBOL(fscrypt_fname_encrypted_size); 235 238 ··· 274 279 /** 275 280 * fscrypt_fname_disk_to_usr() - converts a filename from disk space to user 276 281 * space 282 + * 283 + * The caller must have allocated sufficient memory for the @oname string. 284 + * 285 + * Return: 0 on success, -errno on failure 277 286 */ 278 287 int fscrypt_fname_disk_to_usr(struct inode *inode, 279 288 u32 hash, u32 minor_hash, ··· 286 287 { 287 288 const struct qstr qname = FSTR_TO_QSTR(iname); 288 289 char buf[24]; 289 - int ret; 290 290 291 291 if (fscrypt_is_dot_dotdot(&qname)) { 292 292 oname->name[0] = '.'; 293 293 oname->name[iname->len - 1] = '.'; 294 294 oname->len = iname->len; 295 - return oname->len; 295 + return 0; 296 296 } 297 297 298 298 if (iname->len < FS_CRYPTO_BLOCK_SIZE) ··· 301 303 return fname_decrypt(inode, iname, oname); 302 304 303 305 if (iname->len <= FS_FNAME_CRYPTO_DIGEST_SIZE) { 304 - ret = digest_encode(iname->name, iname->len, oname->name); 305 - oname->len = ret; 306 - return ret; 306 + oname->len = digest_encode(iname->name, iname->len, 307 + oname->name); 308 + return 0; 307 309 } 308 310 if (hash) { 309 311 memcpy(buf, &hash, 4); ··· 313 315 } 314 316 memcpy(buf + 8, iname->name + iname->len - 16, 16); 315 317 oname->name[0] = '_'; 316 - ret = digest_encode(buf, 24, oname->name + 1); 317 - oname->len = ret + 1; 318 - return ret + 1; 318 + oname->len = 1 + digest_encode(buf, 24, oname->name + 1); 319 + return 0; 319 320 } 320 321 EXPORT_SYMBOL(fscrypt_fname_disk_to_usr); 321 322 322 323 /** 323 324 * fscrypt_fname_usr_to_disk() - converts a filename from user space to disk 324 325 * space 326 + * 327 + * The caller must have allocated sufficient memory for the @oname string. 328 + * 329 + * Return: 0 on success, -errno on failure 325 330 */ 326 331 int fscrypt_fname_usr_to_disk(struct inode *inode, 327 332 const struct qstr *iname, ··· 334 333 oname->name[0] = '.'; 335 334 oname->name[iname->len - 1] = '.'; 336 335 oname->len = iname->len; 337 - return oname->len; 336 + return 0; 338 337 } 339 338 if (inode->i_crypt_info) 340 339 return fname_encrypt(inode, iname, oname); ··· 368 367 if (dir->i_crypt_info) { 369 368 ret = fscrypt_fname_alloc_buffer(dir, iname->len, 370 369 &fname->crypto_buf); 371 - if (ret < 0) 370 + if (ret) 372 371 return ret; 373 372 ret = fname_encrypt(dir, iname, &fname->crypto_buf); 374 - if (ret < 0) 373 + if (ret) 375 374 goto errout; 376 375 fname->disk_name.name = fname->crypto_buf.name; 377 376 fname->disk_name.len = fname->crypto_buf.len;
+44 -25
fs/crypto/keyinfo.c
··· 8 8 * Written by Michael Halcrow, Ildar Muslukhov, and Uday Savagaonkar, 2015. 9 9 */ 10 10 11 - #include <keys/encrypted-type.h> 12 11 #include <keys/user-type.h> 13 - #include <linux/random.h> 14 12 #include <linux/scatterlist.h> 15 - #include <uapi/linux/keyctl.h> 16 13 #include <linux/fscrypto.h> 17 14 18 15 static void derive_crypt_complete(struct crypto_async_request *req, int rc) ··· 136 139 return res; 137 140 } 138 141 142 + static int determine_cipher_type(struct fscrypt_info *ci, struct inode *inode, 143 + const char **cipher_str_ret, int *keysize_ret) 144 + { 145 + if (S_ISREG(inode->i_mode)) { 146 + if (ci->ci_data_mode == FS_ENCRYPTION_MODE_AES_256_XTS) { 147 + *cipher_str_ret = "xts(aes)"; 148 + *keysize_ret = FS_AES_256_XTS_KEY_SIZE; 149 + return 0; 150 + } 151 + pr_warn_once("fscrypto: unsupported contents encryption mode " 152 + "%d for inode %lu\n", 153 + ci->ci_data_mode, inode->i_ino); 154 + return -ENOKEY; 155 + } 156 + 157 + if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) { 158 + if (ci->ci_filename_mode == FS_ENCRYPTION_MODE_AES_256_CTS) { 159 + *cipher_str_ret = "cts(cbc(aes))"; 160 + *keysize_ret = FS_AES_256_CTS_KEY_SIZE; 161 + return 0; 162 + } 163 + pr_warn_once("fscrypto: unsupported filenames encryption mode " 164 + "%d for inode %lu\n", 165 + ci->ci_filename_mode, inode->i_ino); 166 + return -ENOKEY; 167 + } 168 + 169 + pr_warn_once("fscrypto: unsupported file type %d for inode %lu\n", 170 + (inode->i_mode & S_IFMT), inode->i_ino); 171 + return -ENOKEY; 172 + } 173 + 139 174 static void put_crypt_info(struct fscrypt_info *ci) 140 175 { 141 176 if (!ci) ··· 184 155 struct fscrypt_context ctx; 185 156 struct crypto_skcipher *ctfm; 186 157 const char *cipher_str; 158 + int keysize; 187 159 u8 raw_key[FS_MAX_KEY_SIZE]; 188 - u8 mode; 189 160 int res; 190 161 191 162 res = fscrypt_initialize(); ··· 208 179 if (res < 0) { 209 180 if (!fscrypt_dummy_context_enabled(inode)) 210 181 return res; 182 + ctx.format = FS_ENCRYPTION_CONTEXT_FORMAT_V1; 211 183 ctx.contents_encryption_mode = FS_ENCRYPTION_MODE_AES_256_XTS; 212 184 ctx.filenames_encryption_mode = FS_ENCRYPTION_MODE_AES_256_CTS; 213 185 ctx.flags = 0; 214 186 } else if (res != sizeof(ctx)) { 215 187 return -EINVAL; 216 188 } 217 - res = 0; 189 + 190 + if (ctx.format != FS_ENCRYPTION_CONTEXT_FORMAT_V1) 191 + return -EINVAL; 192 + 193 + if (ctx.flags & ~FS_POLICY_FLAGS_VALID) 194 + return -EINVAL; 218 195 219 196 crypt_info = kmem_cache_alloc(fscrypt_info_cachep, GFP_NOFS); 220 197 if (!crypt_info) ··· 233 198 crypt_info->ci_keyring_key = NULL; 234 199 memcpy(crypt_info->ci_master_key, ctx.master_key_descriptor, 235 200 sizeof(crypt_info->ci_master_key)); 236 - if (S_ISREG(inode->i_mode)) 237 - mode = crypt_info->ci_data_mode; 238 - else if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) 239 - mode = crypt_info->ci_filename_mode; 240 - else 241 - BUG(); 242 201 243 - switch (mode) { 244 - case FS_ENCRYPTION_MODE_AES_256_XTS: 245 - cipher_str = "xts(aes)"; 246 - break; 247 - case FS_ENCRYPTION_MODE_AES_256_CTS: 248 - cipher_str = "cts(cbc(aes))"; 249 - break; 250 - default: 251 - printk_once(KERN_WARNING 252 - "%s: unsupported key mode %d (ino %u)\n", 253 - __func__, mode, (unsigned) inode->i_ino); 254 - res = -ENOKEY; 202 + res = determine_cipher_type(crypt_info, inode, &cipher_str, &keysize); 203 + if (res) 255 204 goto out; 256 - } 205 + 257 206 if (fscrypt_dummy_context_enabled(inode)) { 258 207 memset(raw_key, 0x42, FS_AES_256_XTS_KEY_SIZE); 259 208 goto got_key; ··· 272 253 crypt_info->ci_ctfm = ctfm; 273 254 crypto_skcipher_clear_flags(ctfm, ~0); 274 255 crypto_skcipher_set_flags(ctfm, CRYPTO_TFM_REQ_WEAK_KEY); 275 - res = crypto_skcipher_setkey(ctfm, raw_key, fscrypt_key_size(mode)); 256 + res = crypto_skcipher_setkey(ctfm, raw_key, keysize); 276 257 if (res) 277 258 goto out; 278 259
+4 -4
fs/ext4/dir.c
··· 260 260 /* Directory is encrypted */ 261 261 err = fscrypt_fname_disk_to_usr(inode, 262 262 0, 0, &de_name, &fstr); 263 + de_name = fstr; 263 264 fstr.len = save_len; 264 - if (err < 0) 265 + if (err) 265 266 goto errout; 266 267 if (!dir_emit(ctx, 267 - fstr.name, err, 268 + de_name.name, de_name.len, 268 269 le32_to_cpu(de->inode), 269 270 get_dtype(sb, de->file_type))) 270 271 goto done; ··· 628 627 int buf_size) 629 628 { 630 629 struct ext4_dir_entry_2 *de; 631 - int nlen, rlen; 630 + int rlen; 632 631 unsigned int offset = 0; 633 632 char *top; 634 633 ··· 638 637 if (ext4_check_dir_entry(dir, NULL, de, bh, 639 638 buf, buf_size, offset)) 640 639 return -EFSCORRUPTED; 641 - nlen = EXT4_DIR_REC_LEN(de->name_len); 642 640 rlen = ext4_rec_len_from_disk(de->rec_len, buf_size); 643 641 de = (struct ext4_dir_entry_2 *)((char *)de + rlen); 644 642 offset += rlen;
+12 -23
fs/ext4/ext4.h
··· 262 262 (s)->s_first_ino) 263 263 #endif 264 264 #define EXT4_BLOCK_ALIGN(size, blkbits) ALIGN((size), (1 << (blkbits))) 265 + #define EXT4_MAX_BLOCKS(size, offset, blkbits) \ 266 + ((EXT4_BLOCK_ALIGN(size + offset, blkbits) >> blkbits) - (offset >> \ 267 + blkbits)) 265 268 266 269 /* Translate a block number to a cluster number */ 267 270 #define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits) ··· 1120 1117 #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */ 1121 1118 #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */ 1122 1119 #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */ 1123 - #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */ 1124 - #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */ 1125 - #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */ 1120 + #define EXT4_MOUNT_QUOTA 0x40000 /* Some quota option set */ 1121 + #define EXT4_MOUNT_USRQUOTA 0x80000 /* "old" user quota, 1122 + * enable enforcement for hidden 1123 + * quota files */ 1124 + #define EXT4_MOUNT_GRPQUOTA 0x100000 /* "old" group quota, enable 1125 + * enforcement for hidden quota 1126 + * files */ 1127 + #define EXT4_MOUNT_PRJQUOTA 0x200000 /* Enable project quota 1128 + * enforcement */ 1126 1129 #define EXT4_MOUNT_DIOREAD_NOLOCK 0x400000 /* Enable support for dio read nolocking */ 1127 1130 #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */ 1128 1131 #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */ ··· 1644 1635 /* 1645 1636 * Feature set definitions 1646 1637 */ 1647 - 1648 - /* Use the ext4_{has,set,clear}_feature_* helpers; these will be removed */ 1649 - #define EXT4_HAS_COMPAT_FEATURE(sb,mask) \ 1650 - ((EXT4_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask)) != 0) 1651 - #define EXT4_HAS_RO_COMPAT_FEATURE(sb,mask) \ 1652 - ((EXT4_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask)) != 0) 1653 - #define EXT4_HAS_INCOMPAT_FEATURE(sb,mask) \ 1654 - ((EXT4_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask)) != 0) 1655 - #define EXT4_SET_COMPAT_FEATURE(sb,mask) \ 1656 - EXT4_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask) 1657 - #define EXT4_SET_RO_COMPAT_FEATURE(sb,mask) \ 1658 - EXT4_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask) 1659 - #define EXT4_SET_INCOMPAT_FEATURE(sb,mask) \ 1660 - EXT4_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask) 1661 - #define EXT4_CLEAR_COMPAT_FEATURE(sb,mask) \ 1662 - EXT4_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask) 1663 - #define EXT4_CLEAR_RO_COMPAT_FEATURE(sb,mask) \ 1664 - EXT4_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask) 1665 - #define EXT4_CLEAR_INCOMPAT_FEATURE(sb,mask) \ 1666 - EXT4_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask) 1667 1638 1668 1639 #define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001 1669 1640 #define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002
+8 -19
fs/ext4/extents.c
··· 4679 4679 unsigned int credits; 4680 4680 loff_t epos; 4681 4681 4682 + BUG_ON(!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)); 4682 4683 map.m_lblk = offset; 4683 4684 map.m_len = len; 4684 4685 /* ··· 4694 4693 * credits to insert 1 extent into extent tree 4695 4694 */ 4696 4695 credits = ext4_chunk_trans_blocks(inode, len); 4697 - /* 4698 - * We can only call ext_depth() on extent based inodes 4699 - */ 4700 - if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) 4701 - depth = ext_depth(inode); 4702 - else 4703 - depth = -1; 4696 + depth = ext_depth(inode); 4704 4697 4705 4698 retry: 4706 4699 while (ret >= 0 && len) { ··· 4961 4966 4962 4967 trace_ext4_fallocate_enter(inode, offset, len, mode); 4963 4968 lblk = offset >> blkbits; 4964 - /* 4965 - * We can't just convert len to max_blocks because 4966 - * If blocksize = 4096 offset = 3072 and len = 2048 4967 - */ 4968 - max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits) 4969 - - lblk; 4970 4969 4970 + max_blocks = EXT4_MAX_BLOCKS(len, offset, blkbits); 4971 4971 flags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT; 4972 4972 if (mode & FALLOC_FL_KEEP_SIZE) 4973 4973 flags |= EXT4_GET_BLOCKS_KEEP_SIZE; ··· 5025 5035 unsigned int credits, blkbits = inode->i_blkbits; 5026 5036 5027 5037 map.m_lblk = offset >> blkbits; 5028 - /* 5029 - * We can't just convert len to max_blocks because 5030 - * If blocksize = 4096 offset = 3072 and len = 2048 5031 - */ 5032 - max_blocks = ((EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits) - 5033 - map.m_lblk); 5038 + max_blocks = EXT4_MAX_BLOCKS(len, offset, blkbits); 5039 + 5034 5040 /* 5035 5041 * This is somewhat ugly but the idea is clear: When transaction is 5036 5042 * reserved, everything goes into it. Otherwise we rather start several ··· 5720 5734 up_write(&EXT4_I(inode)->i_data_sem); 5721 5735 goto out_stop; 5722 5736 } 5737 + } else { 5738 + ext4_ext_drop_refs(path); 5739 + kfree(path); 5723 5740 } 5724 5741 5725 5742 ret = ext4_es_remove_extent(inode, offset_lblk,
+2 -8
fs/ext4/file.c
··· 91 91 static ssize_t 92 92 ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from) 93 93 { 94 - struct file *file = iocb->ki_filp; 95 94 struct inode *inode = file_inode(iocb->ki_filp); 96 - struct blk_plug plug; 97 95 int o_direct = iocb->ki_flags & IOCB_DIRECT; 98 96 int unaligned_aio = 0; 99 97 int overwrite = 0; ··· 132 134 if (o_direct) { 133 135 size_t length = iov_iter_count(from); 134 136 loff_t pos = iocb->ki_pos; 135 - blk_start_plug(&plug); 136 137 137 138 /* check whether we do a DIO overwrite or not */ 138 139 if (ext4_should_dioread_nolock(inode) && !unaligned_aio && 139 - !file->f_mapping->nrpages && pos + length <= i_size_read(inode)) { 140 + pos + length <= i_size_read(inode)) { 140 141 struct ext4_map_blocks map; 141 142 unsigned int blkbits = inode->i_blkbits; 142 143 int err, len; 143 144 144 145 map.m_lblk = pos >> blkbits; 145 - map.m_len = (EXT4_BLOCK_ALIGN(pos + length, blkbits) >> blkbits) 146 - - map.m_lblk; 146 + map.m_len = EXT4_MAX_BLOCKS(length, pos, blkbits); 147 147 len = map.m_len; 148 148 149 149 err = ext4_map_blocks(NULL, inode, &map, 0); ··· 167 171 168 172 if (ret > 0) 169 173 ret = generic_write_sync(iocb, ret); 170 - if (o_direct) 171 - blk_finish_plug(&plug); 172 174 173 175 return ret; 174 176
+8 -1
fs/ext4/fsync.c
··· 61 61 break; 62 62 iput(inode); 63 63 inode = next; 64 + /* 65 + * The directory inode may have gone through rmdir by now. But 66 + * the inode itself and its blocks are still allocated (we hold 67 + * a reference to the inode so it didn't go through 68 + * ext4_evict_inode()) and so we are safe to flush metadata 69 + * blocks and the inode. 70 + */ 64 71 ret = sync_mapping_buffers(inode->i_mapping); 65 72 if (ret) 66 73 break; ··· 114 107 115 108 if (!journal) { 116 109 ret = __generic_file_fsync(file, start, end, datasync); 117 - if (!ret && !hlist_empty(&inode->i_dentry)) 110 + if (!ret) 118 111 ret = ext4_sync_parent(inode); 119 112 if (test_opt(inode->i_sb, BARRIER)) 120 113 goto issue_flush;
+1 -1
fs/ext4/ialloc.c
··· 802 802 } else 803 803 inode_init_owner(inode, dir, mode); 804 804 805 - if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_PROJECT) && 805 + if (ext4_has_feature_project(sb) && 806 806 ext4_test_inode_flag(dir, EXT4_INODE_PROJINHERIT)) 807 807 ei->i_projid = EXT4_I(dir)->i_projid; 808 808 else
+38 -33
fs/ext4/inode.c
··· 647 647 /* 648 648 * We have to zeroout blocks before inserting them into extent 649 649 * status tree. Otherwise someone could look them up there and 650 - * use them before they are really zeroed. 650 + * use them before they are really zeroed. We also have to 651 + * unmap metadata before zeroing as otherwise writeback can 652 + * overwrite zeros with stale data from block device. 651 653 */ 652 654 if (flags & EXT4_GET_BLOCKS_ZERO && 653 655 map->m_flags & EXT4_MAP_MAPPED && 654 656 map->m_flags & EXT4_MAP_NEW) { 657 + ext4_lblk_t i; 658 + 659 + for (i = 0; i < map->m_len; i++) { 660 + unmap_underlying_metadata(inode->i_sb->s_bdev, 661 + map->m_pblk + i); 662 + } 655 663 ret = ext4_issue_zeroout(inode, map->m_lblk, 656 664 map->m_pblk, map->m_len); 657 665 if (ret) { ··· 1657 1649 BUG_ON(!PageLocked(page)); 1658 1650 BUG_ON(PageWriteback(page)); 1659 1651 if (invalidate) { 1652 + if (page_mapped(page)) 1653 + clear_page_dirty_for_io(page); 1660 1654 block_invalidatepage(page, 0, PAGE_SIZE); 1661 1655 ClearPageUptodate(page); 1662 1656 } ··· 3536 3526 3537 3527 static ssize_t ext4_direct_IO_read(struct kiocb *iocb, struct iov_iter *iter) 3538 3528 { 3539 - int unlocked = 0; 3540 - struct inode *inode = iocb->ki_filp->f_mapping->host; 3529 + struct address_space *mapping = iocb->ki_filp->f_mapping; 3530 + struct inode *inode = mapping->host; 3541 3531 ssize_t ret; 3542 3532 3543 - if (ext4_should_dioread_nolock(inode)) { 3544 - /* 3545 - * Nolock dioread optimization may be dynamically disabled 3546 - * via ext4_inode_block_unlocked_dio(). Check inode's state 3547 - * while holding extra i_dio_count ref. 3548 - */ 3549 - inode_dio_begin(inode); 3550 - smp_mb(); 3551 - if (unlikely(ext4_test_inode_state(inode, 3552 - EXT4_STATE_DIOREAD_LOCK))) 3553 - inode_dio_end(inode); 3554 - else 3555 - unlocked = 1; 3556 - } 3533 + /* 3534 + * Shared inode_lock is enough for us - it protects against concurrent 3535 + * writes & truncates and since we take care of writing back page cache, 3536 + * we are protected against page writeback as well. 3537 + */ 3538 + inode_lock_shared(inode); 3557 3539 if (IS_DAX(inode)) { 3558 - ret = dax_do_io(iocb, inode, iter, ext4_dio_get_block, 3559 - NULL, unlocked ? 0 : DIO_LOCKING); 3540 + ret = dax_do_io(iocb, inode, iter, ext4_dio_get_block, NULL, 0); 3560 3541 } else { 3542 + size_t count = iov_iter_count(iter); 3543 + 3544 + ret = filemap_write_and_wait_range(mapping, iocb->ki_pos, 3545 + iocb->ki_pos + count); 3546 + if (ret) 3547 + goto out_unlock; 3561 3548 ret = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, 3562 3549 iter, ext4_dio_get_block, 3563 - NULL, NULL, 3564 - unlocked ? 0 : DIO_LOCKING); 3550 + NULL, NULL, 0); 3565 3551 } 3566 - if (unlocked) 3567 - inode_dio_end(inode); 3552 + out_unlock: 3553 + inode_unlock_shared(inode); 3568 3554 return ret; 3569 3555 } 3570 3556 ··· 3896 3890 } 3897 3891 3898 3892 /* 3899 - * ext4_punch_hole: punches a hole in a file by releaseing the blocks 3893 + * ext4_punch_hole: punches a hole in a file by releasing the blocks 3900 3894 * associated with the given offset and length 3901 3895 * 3902 3896 * @inode: File inode ··· 3925 3919 * Write out all dirty pages to avoid race conditions 3926 3920 * Then release them. 3927 3921 */ 3928 - if (mapping->nrpages && mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) { 3922 + if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) { 3929 3923 ret = filemap_write_and_wait_range(mapping, offset, 3930 3924 offset + length - 1); 3931 3925 if (ret) ··· 4420 4414 4421 4415 int ext4_get_projid(struct inode *inode, kprojid_t *projid) 4422 4416 { 4423 - if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, EXT4_FEATURE_RO_COMPAT_PROJECT)) 4417 + if (!ext4_has_feature_project(inode->i_sb)) 4424 4418 return -EOPNOTSUPP; 4425 4419 *projid = EXT4_I(inode)->i_projid; 4426 4420 return 0; ··· 4487 4481 inode->i_mode = le16_to_cpu(raw_inode->i_mode); 4488 4482 i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low); 4489 4483 i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low); 4490 - if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_PROJECT) && 4484 + if (ext4_has_feature_project(sb) && 4491 4485 EXT4_INODE_SIZE(sb) > EXT4_GOOD_OLD_INODE_SIZE && 4492 4486 EXT4_FITS_IN_INODE(raw_inode, ei, i_projid)) 4493 4487 i_projid = (projid_t)le32_to_cpu(raw_inode->i_projid); ··· 4820 4814 * Fix up interoperability with old kernels. Otherwise, old inodes get 4821 4815 * re-used with the upper 16 bits of the uid/gid intact 4822 4816 */ 4823 - if (!ei->i_dtime) { 4817 + if (ei->i_dtime && list_empty(&ei->i_orphan)) { 4818 + raw_inode->i_uid_high = 0; 4819 + raw_inode->i_gid_high = 0; 4820 + } else { 4824 4821 raw_inode->i_uid_high = 4825 4822 cpu_to_le16(high_16_bits(i_uid)); 4826 4823 raw_inode->i_gid_high = 4827 4824 cpu_to_le16(high_16_bits(i_gid)); 4828 - } else { 4829 - raw_inode->i_uid_high = 0; 4830 - raw_inode->i_gid_high = 0; 4831 4825 } 4832 4826 } else { 4833 4827 raw_inode->i_uid_low = cpu_to_le16(fs_high2lowuid(i_uid)); ··· 4891 4885 } 4892 4886 } 4893 4887 4894 - BUG_ON(!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 4895 - EXT4_FEATURE_RO_COMPAT_PROJECT) && 4888 + BUG_ON(!ext4_has_feature_project(inode->i_sb) && 4896 4889 i_projid != EXT4_DEF_PROJID); 4897 4890 4898 4891 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE &&
+5 -6
fs/ext4/ioctl.c
··· 19 19 #include "ext4_jbd2.h" 20 20 #include "ext4.h" 21 21 22 - #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1) 23 - 24 22 /** 25 23 * Swap memory between @a and @b for @len bytes. 26 24 * ··· 308 310 struct ext4_inode *raw_inode; 309 311 struct dquot *transfer_to[MAXQUOTAS] = { }; 310 312 311 - if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, 312 - EXT4_FEATURE_RO_COMPAT_PROJECT)) { 313 + if (!ext4_has_feature_project(sb)) { 313 314 if (projid != EXT4_DEF_PROJID) 314 315 return -EOPNOTSUPP; 315 316 else ··· 769 772 #ifdef CONFIG_EXT4_FS_ENCRYPTION 770 773 struct fscrypt_policy policy; 771 774 775 + if (!ext4_has_feature_encrypt(sb)) 776 + return -EOPNOTSUPP; 777 + 772 778 if (copy_from_user(&policy, 773 779 (struct fscrypt_policy __user *)arg, 774 780 sizeof(policy))) ··· 842 842 ext4_get_inode_flags(ei); 843 843 fa.fsx_xflags = ext4_iflags_to_xflags(ei->i_flags & EXT4_FL_USER_VISIBLE); 844 844 845 - if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 846 - EXT4_FEATURE_RO_COMPAT_PROJECT)) { 845 + if (ext4_has_feature_project(inode->i_sb)) { 847 846 fa.fsx_projid = (__u32)from_kprojid(&init_user_ns, 848 847 EXT4_I(inode)->i_projid); 849 848 }
+7
fs/ext4/move_extent.c
··· 598 598 return -EOPNOTSUPP; 599 599 } 600 600 601 + if (ext4_encrypted_inode(orig_inode) || 602 + ext4_encrypted_inode(donor_inode)) { 603 + ext4_msg(orig_inode->i_sb, KERN_ERR, 604 + "Online defrag not supported for encrypted files"); 605 + return -EOPNOTSUPP; 606 + } 607 + 601 608 /* Protect orig and donor inodes against a truncate */ 602 609 lock_two_nondirectories(orig_inode, donor_inode); 603 610
+10 -12
fs/ext4/namei.c
··· 639 639 res = fscrypt_fname_alloc_buffer( 640 640 dir, len, 641 641 &fname_crypto_str); 642 - if (res < 0) 642 + if (res) 643 643 printk(KERN_WARNING "Error " 644 644 "allocating crypto " 645 645 "buffer--skipping " ··· 647 647 res = fscrypt_fname_disk_to_usr(dir, 648 648 0, 0, &de_name, 649 649 &fname_crypto_str); 650 - if (res < 0) { 650 + if (res) { 651 651 printk(KERN_WARNING "Error " 652 652 "converting filename " 653 653 "from disk to usr" ··· 1011 1011 err = fscrypt_fname_disk_to_usr(dir, hinfo->hash, 1012 1012 hinfo->minor_hash, &de_name, 1013 1013 &fname_crypto_str); 1014 - if (err < 0) { 1014 + if (err) { 1015 1015 count = err; 1016 1016 goto errout; 1017 1017 } ··· 2044 2044 frame->entries = entries; 2045 2045 frame->at = entries; 2046 2046 frame->bh = bh; 2047 - bh = bh2; 2048 2047 2049 2048 retval = ext4_handle_dirty_dx_node(handle, dir, frame->bh); 2050 2049 if (retval) 2051 2050 goto out_frames; 2052 - retval = ext4_handle_dirty_dirent_node(handle, dir, bh); 2051 + retval = ext4_handle_dirty_dirent_node(handle, dir, bh2); 2053 2052 if (retval) 2054 2053 goto out_frames; 2055 2054 2056 - de = do_split(handle,dir, &bh, frame, &fname->hinfo); 2055 + de = do_split(handle,dir, &bh2, frame, &fname->hinfo); 2057 2056 if (IS_ERR(de)) { 2058 2057 retval = PTR_ERR(de); 2059 2058 goto out_frames; 2060 2059 } 2061 - dx_release(frames); 2062 2060 2063 - retval = add_dirent_to_buf(handle, fname, dir, inode, de, bh); 2064 - brelse(bh); 2065 - return retval; 2061 + retval = add_dirent_to_buf(handle, fname, dir, inode, de, bh2); 2066 2062 out_frames: 2067 2063 /* 2068 2064 * Even if the block split failed, we have to properly write 2069 2065 * out all the changes we did so far. Otherwise we can end up 2070 2066 * with corrupted filesystem. 2071 2067 */ 2072 - ext4_mark_inode_dirty(handle, dir); 2068 + if (retval) 2069 + ext4_mark_inode_dirty(handle, dir); 2073 2070 dx_release(frames); 2071 + brelse(bh2); 2074 2072 return retval; 2075 2073 } 2076 2074 ··· 3142 3144 istr.name = (const unsigned char *) symname; 3143 3145 istr.len = len; 3144 3146 err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr); 3145 - if (err < 0) 3147 + if (err) 3146 3148 goto err_drop_inode; 3147 3149 sd->len = cpu_to_le16(ostr.len); 3148 3150 disk_link.name = (char *) sd;
+1 -3
fs/ext4/page-io.c
··· 405 405 { 406 406 struct page *data_page = NULL; 407 407 struct inode *inode = page->mapping->host; 408 - unsigned block_start, blocksize; 408 + unsigned block_start; 409 409 struct buffer_head *bh, *head; 410 410 int ret = 0; 411 411 int nr_submitted = 0; 412 412 int nr_to_submit = 0; 413 - 414 - blocksize = 1 << inode->i_blkbits; 415 413 416 414 BUG_ON(!PageLocked(page)); 417 415 BUG_ON(PageWriteback(page));
+96 -32
fs/ext4/super.c
··· 78 78 static void ext4_destroy_lazyinit_thread(void); 79 79 static void ext4_unregister_li_request(struct super_block *sb); 80 80 static void ext4_clear_request_list(void); 81 + static struct inode *ext4_get_journal_inode(struct super_block *sb, 82 + unsigned int journal_inum); 81 83 82 84 /* 83 85 * Lock ordering ··· 1269 1267 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, 1270 1268 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota, 1271 1269 Opt_noquota, Opt_barrier, Opt_nobarrier, Opt_err, 1272 - Opt_usrquota, Opt_grpquota, Opt_i_version, Opt_dax, 1270 + Opt_usrquota, Opt_grpquota, Opt_prjquota, Opt_i_version, Opt_dax, 1273 1271 Opt_stripe, Opt_delalloc, Opt_nodelalloc, Opt_mblk_io_submit, 1274 1272 Opt_lazytime, Opt_nolazytime, 1275 1273 Opt_nomblk_io_submit, Opt_block_validity, Opt_noblock_validity, ··· 1329 1327 {Opt_noquota, "noquota"}, 1330 1328 {Opt_quota, "quota"}, 1331 1329 {Opt_usrquota, "usrquota"}, 1330 + {Opt_prjquota, "prjquota"}, 1332 1331 {Opt_barrier, "barrier=%u"}, 1333 1332 {Opt_barrier, "barrier"}, 1334 1333 {Opt_nobarrier, "nobarrier"}, ··· 1549 1546 MOPT_SET | MOPT_Q}, 1550 1547 {Opt_grpquota, EXT4_MOUNT_QUOTA | EXT4_MOUNT_GRPQUOTA, 1551 1548 MOPT_SET | MOPT_Q}, 1549 + {Opt_prjquota, EXT4_MOUNT_QUOTA | EXT4_MOUNT_PRJQUOTA, 1550 + MOPT_SET | MOPT_Q}, 1552 1551 {Opt_noquota, (EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA | 1553 - EXT4_MOUNT_GRPQUOTA), MOPT_CLEAR | MOPT_Q}, 1552 + EXT4_MOUNT_GRPQUOTA | EXT4_MOUNT_PRJQUOTA), 1553 + MOPT_CLEAR | MOPT_Q}, 1554 1554 {Opt_usrjquota, 0, MOPT_Q}, 1555 1555 {Opt_grpjquota, 0, MOPT_Q}, 1556 1556 {Opt_offusrjquota, 0, MOPT_Q}, ··· 1842 1836 return 0; 1843 1837 } 1844 1838 #ifdef CONFIG_QUOTA 1845 - if (ext4_has_feature_quota(sb) && 1846 - (test_opt(sb, USRQUOTA) || test_opt(sb, GRPQUOTA))) { 1847 - ext4_msg(sb, KERN_INFO, "Quota feature enabled, usrquota and grpquota " 1848 - "mount options ignored."); 1849 - clear_opt(sb, USRQUOTA); 1850 - clear_opt(sb, GRPQUOTA); 1851 - } else if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { 1839 + /* 1840 + * We do the test below only for project quotas. 'usrquota' and 1841 + * 'grpquota' mount options are allowed even without quota feature 1842 + * to support legacy quotas in quota files. 1843 + */ 1844 + if (test_opt(sb, PRJQUOTA) && !ext4_has_feature_project(sb)) { 1845 + ext4_msg(sb, KERN_ERR, "Project quota feature not enabled. " 1846 + "Cannot enable project quota enforcement."); 1847 + return 0; 1848 + } 1849 + if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { 1852 1850 if (test_opt(sb, USRQUOTA) && sbi->s_qf_names[USRQUOTA]) 1853 1851 clear_opt(sb, USRQUOTA); 1854 1852 ··· 2751 2741 sb = elr->lr_super; 2752 2742 ngroups = EXT4_SB(sb)->s_groups_count; 2753 2743 2754 - sb_start_write(sb); 2755 2744 for (group = elr->lr_next_group; group < ngroups; group++) { 2756 2745 gdp = ext4_get_group_desc(sb, group, NULL); 2757 2746 if (!gdp) { ··· 2777 2768 elr->lr_next_sched = jiffies + elr->lr_timeout; 2778 2769 elr->lr_next_group = group + 1; 2779 2770 } 2780 - sb_end_write(sb); 2781 - 2782 2771 return ret; 2783 2772 } 2784 2773 ··· 2841 2834 mutex_unlock(&eli->li_list_mtx); 2842 2835 goto exit_thread; 2843 2836 } 2844 - 2845 2837 list_for_each_safe(pos, n, &eli->li_request_list) { 2838 + int err = 0; 2839 + int progress = 0; 2846 2840 elr = list_entry(pos, struct ext4_li_request, 2847 2841 lr_request); 2848 2842 2849 - if (time_after_eq(jiffies, elr->lr_next_sched)) { 2850 - if (ext4_run_li_request(elr) != 0) { 2851 - /* error, remove the lazy_init job */ 2852 - ext4_remove_li_request(elr); 2853 - continue; 2854 - } 2843 + if (time_before(jiffies, elr->lr_next_sched)) { 2844 + if (time_before(elr->lr_next_sched, next_wakeup)) 2845 + next_wakeup = elr->lr_next_sched; 2846 + continue; 2855 2847 } 2856 - 2848 + if (down_read_trylock(&elr->lr_super->s_umount)) { 2849 + if (sb_start_write_trylock(elr->lr_super)) { 2850 + progress = 1; 2851 + /* 2852 + * We hold sb->s_umount, sb can not 2853 + * be removed from the list, it is 2854 + * now safe to drop li_list_mtx 2855 + */ 2856 + mutex_unlock(&eli->li_list_mtx); 2857 + err = ext4_run_li_request(elr); 2858 + sb_end_write(elr->lr_super); 2859 + mutex_lock(&eli->li_list_mtx); 2860 + n = pos->next; 2861 + } 2862 + up_read((&elr->lr_super->s_umount)); 2863 + } 2864 + /* error, remove the lazy_init job */ 2865 + if (err) { 2866 + ext4_remove_li_request(elr); 2867 + continue; 2868 + } 2869 + if (!progress) { 2870 + elr->lr_next_sched = jiffies + 2871 + (prandom_u32() 2872 + % (EXT4_DEF_LI_MAX_START_DELAY * HZ)); 2873 + } 2857 2874 if (time_before(elr->lr_next_sched, next_wakeup)) 2858 2875 next_wakeup = elr->lr_next_sched; 2859 2876 } ··· 3210 3179 { 3211 3180 struct ext4_sb_info *sbi = EXT4_SB(sb); 3212 3181 struct ext4_super_block *es = sbi->s_es; 3182 + struct inode *j_inode; 3183 + unsigned int j_blocks, j_inum = le32_to_cpu(es->s_journal_inum); 3213 3184 ext4_group_t i, ngroups = ext4_get_groups_count(sb); 3214 3185 ext4_fsblk_t overhead = 0; 3215 3186 char *buf = (char *) get_zeroed_page(GFP_NOFS); ··· 3242 3209 memset(buf, 0, PAGE_SIZE); 3243 3210 cond_resched(); 3244 3211 } 3245 - /* Add the internal journal blocks as well */ 3212 + 3213 + /* 3214 + * Add the internal journal blocks whether the journal has been 3215 + * loaded or not 3216 + */ 3246 3217 if (sbi->s_journal && !sbi->journal_bdev) 3247 3218 overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen); 3248 - 3219 + else if (ext4_has_feature_journal(sb) && !sbi->s_journal) { 3220 + j_inode = ext4_get_journal_inode(sb, j_inum); 3221 + if (j_inode) { 3222 + j_blocks = j_inode->i_size >> sb->s_blocksize_bits; 3223 + overhead += EXT4_NUM_B2C(sbi, j_blocks); 3224 + iput(j_inode); 3225 + } else { 3226 + ext4_msg(sb, KERN_ERR, "can't get journal size"); 3227 + } 3228 + } 3249 3229 sbi->s_overhead = overhead; 3250 3230 smp_wmb(); 3251 3231 free_page((unsigned long) buf); ··· 4254 4208 write_unlock(&journal->j_state_lock); 4255 4209 } 4256 4210 4257 - static journal_t *ext4_get_journal(struct super_block *sb, 4258 - unsigned int journal_inum) 4211 + static struct inode *ext4_get_journal_inode(struct super_block *sb, 4212 + unsigned int journal_inum) 4259 4213 { 4260 4214 struct inode *journal_inode; 4261 - journal_t *journal; 4262 4215 4263 - BUG_ON(!ext4_has_feature_journal(sb)); 4264 - 4265 - /* First, test for the existence of a valid inode on disk. Bad 4266 - * things happen if we iget() an unused inode, as the subsequent 4267 - * iput() will try to delete it. */ 4268 - 4216 + /* 4217 + * Test for the existence of a valid inode on disk. Bad things 4218 + * happen if we iget() an unused inode, as the subsequent iput() 4219 + * will try to delete it. 4220 + */ 4269 4221 journal_inode = ext4_iget(sb, journal_inum); 4270 4222 if (IS_ERR(journal_inode)) { 4271 4223 ext4_msg(sb, KERN_ERR, "no journal found"); ··· 4283 4239 iput(journal_inode); 4284 4240 return NULL; 4285 4241 } 4242 + return journal_inode; 4243 + } 4244 + 4245 + static journal_t *ext4_get_journal(struct super_block *sb, 4246 + unsigned int journal_inum) 4247 + { 4248 + struct inode *journal_inode; 4249 + journal_t *journal; 4250 + 4251 + BUG_ON(!ext4_has_feature_journal(sb)); 4252 + 4253 + journal_inode = ext4_get_journal_inode(sb, journal_inum); 4254 + if (!journal_inode) 4255 + return NULL; 4286 4256 4287 4257 journal = jbd2_journal_init_inode(journal_inode); 4288 4258 if (!journal) { ··· 5308 5250 le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum), 5309 5251 le32_to_cpu(EXT4_SB(sb)->s_es->s_prj_quota_inum) 5310 5252 }; 5253 + bool quota_mopt[EXT4_MAXQUOTAS] = { 5254 + test_opt(sb, USRQUOTA), 5255 + test_opt(sb, GRPQUOTA), 5256 + test_opt(sb, PRJQUOTA), 5257 + }; 5311 5258 5312 5259 sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE; 5313 5260 for (type = 0; type < EXT4_MAXQUOTAS; type++) { 5314 5261 if (qf_inums[type]) { 5315 5262 err = ext4_quota_enable(sb, type, QFMT_VFS_V1, 5316 - DQUOT_USAGE_ENABLED); 5263 + DQUOT_USAGE_ENABLED | 5264 + (quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0)); 5317 5265 if (err) { 5318 5266 ext4_warning(sb, 5319 5267 "Failed to enable quota tracking "
+5 -9
fs/ext4/symlink.c
··· 30 30 char *caddr, *paddr = NULL; 31 31 struct fscrypt_str cstr, pstr; 32 32 struct fscrypt_symlink_data *sd; 33 - loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1); 34 33 int res; 35 34 u32 max_size = inode->i_sb->s_blocksize; 36 35 ··· 48 49 if (IS_ERR(cpage)) 49 50 return ERR_CAST(cpage); 50 51 caddr = page_address(cpage); 51 - caddr[size] = 0; 52 52 } 53 53 54 54 /* Symlink is encrypted */ ··· 63 65 res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr); 64 66 if (res) 65 67 goto errout; 66 - 67 - res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr); 68 - if (res < 0) 69 - goto errout; 70 - 71 68 paddr = pstr.name; 72 69 70 + res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr); 71 + if (res) 72 + goto errout; 73 + 73 74 /* Null-terminate the name */ 74 - if (res <= pstr.len) 75 - paddr[res] = '\0'; 75 + paddr[pstr.len] = '\0'; 76 76 if (cpage) 77 77 put_page(cpage); 78 78 set_delayed_call(done, kfree_link, paddr);
+178 -162
fs/ext4/xattr.c
··· 199 199 } 200 200 201 201 while (!IS_LAST_ENTRY(entry)) { 202 + if (entry->e_value_block != 0) 203 + return -EFSCORRUPTED; 202 204 if (entry->e_value_size != 0 && 203 205 (value_start + le16_to_cpu(entry->e_value_offs) < 204 206 (void *)e + sizeof(__u32) || ··· 643 641 size_t *min_offs, void *base, int *total) 644 642 { 645 643 for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) { 646 - if (!last->e_value_block && last->e_value_size) { 644 + if (last->e_value_size) { 647 645 size_t offs = le16_to_cpu(last->e_value_offs); 648 646 if (offs < *min_offs) 649 647 *min_offs = offs; ··· 663 661 /* Compute min_offs and last. */ 664 662 last = s->first; 665 663 for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) { 666 - if (!last->e_value_block && last->e_value_size) { 664 + if (last->e_value_size) { 667 665 size_t offs = le16_to_cpu(last->e_value_offs); 668 666 if (offs < min_offs) 669 667 min_offs = offs; ··· 671 669 } 672 670 free = min_offs - ((void *)last - s->base) - sizeof(__u32); 673 671 if (!s->not_found) { 674 - if (!s->here->e_value_block && s->here->e_value_size) { 672 + if (s->here->e_value_size) { 675 673 size_t size = le32_to_cpu(s->here->e_value_size); 676 674 free += EXT4_XATTR_SIZE(size); 677 675 } ··· 693 691 s->here->e_name_len = name_len; 694 692 memcpy(s->here->e_name, i->name, name_len); 695 693 } else { 696 - if (!s->here->e_value_block && s->here->e_value_size) { 694 + if (s->here->e_value_size) { 697 695 void *first_val = s->base + min_offs; 698 696 size_t offs = le16_to_cpu(s->here->e_value_offs); 699 697 void *val = s->base + offs; ··· 727 725 last = s->first; 728 726 while (!IS_LAST_ENTRY(last)) { 729 727 size_t o = le16_to_cpu(last->e_value_offs); 730 - if (!last->e_value_block && 731 - last->e_value_size && o < offs) 728 + if (last->e_value_size && o < offs) 732 729 last->e_value_offs = 733 730 cpu_to_le16(o + size); 734 731 last = EXT4_XATTR_NEXT(last); ··· 1319 1318 */ 1320 1319 static void ext4_xattr_shift_entries(struct ext4_xattr_entry *entry, 1321 1320 int value_offs_shift, void *to, 1322 - void *from, size_t n, int blocksize) 1321 + void *from, size_t n) 1323 1322 { 1324 1323 struct ext4_xattr_entry *last = entry; 1325 1324 int new_offs; 1326 1325 1326 + /* We always shift xattr headers further thus offsets get lower */ 1327 + BUG_ON(value_offs_shift > 0); 1328 + 1327 1329 /* Adjust the value offsets of the entries */ 1328 1330 for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) { 1329 - if (!last->e_value_block && last->e_value_size) { 1331 + if (last->e_value_size) { 1330 1332 new_offs = le16_to_cpu(last->e_value_offs) + 1331 1333 value_offs_shift; 1332 - BUG_ON(new_offs + le32_to_cpu(last->e_value_size) 1333 - > blocksize); 1334 1334 last->e_value_offs = cpu_to_le16(new_offs); 1335 1335 } 1336 1336 } 1337 1337 /* Shift the entries by n bytes */ 1338 1338 memmove(to, from, n); 1339 + } 1340 + 1341 + /* 1342 + * Move xattr pointed to by 'entry' from inode into external xattr block 1343 + */ 1344 + static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode, 1345 + struct ext4_inode *raw_inode, 1346 + struct ext4_xattr_entry *entry) 1347 + { 1348 + struct ext4_xattr_ibody_find *is = NULL; 1349 + struct ext4_xattr_block_find *bs = NULL; 1350 + char *buffer = NULL, *b_entry_name = NULL; 1351 + size_t value_offs, value_size; 1352 + struct ext4_xattr_info i = { 1353 + .value = NULL, 1354 + .value_len = 0, 1355 + .name_index = entry->e_name_index, 1356 + }; 1357 + struct ext4_xattr_ibody_header *header = IHDR(inode, raw_inode); 1358 + int error; 1359 + 1360 + value_offs = le16_to_cpu(entry->e_value_offs); 1361 + value_size = le32_to_cpu(entry->e_value_size); 1362 + 1363 + is = kzalloc(sizeof(struct ext4_xattr_ibody_find), GFP_NOFS); 1364 + bs = kzalloc(sizeof(struct ext4_xattr_block_find), GFP_NOFS); 1365 + buffer = kmalloc(value_size, GFP_NOFS); 1366 + b_entry_name = kmalloc(entry->e_name_len + 1, GFP_NOFS); 1367 + if (!is || !bs || !buffer || !b_entry_name) { 1368 + error = -ENOMEM; 1369 + goto out; 1370 + } 1371 + 1372 + is->s.not_found = -ENODATA; 1373 + bs->s.not_found = -ENODATA; 1374 + is->iloc.bh = NULL; 1375 + bs->bh = NULL; 1376 + 1377 + /* Save the entry name and the entry value */ 1378 + memcpy(buffer, (void *)IFIRST(header) + value_offs, value_size); 1379 + memcpy(b_entry_name, entry->e_name, entry->e_name_len); 1380 + b_entry_name[entry->e_name_len] = '\0'; 1381 + i.name = b_entry_name; 1382 + 1383 + error = ext4_get_inode_loc(inode, &is->iloc); 1384 + if (error) 1385 + goto out; 1386 + 1387 + error = ext4_xattr_ibody_find(inode, &i, is); 1388 + if (error) 1389 + goto out; 1390 + 1391 + /* Remove the chosen entry from the inode */ 1392 + error = ext4_xattr_ibody_set(handle, inode, &i, is); 1393 + if (error) 1394 + goto out; 1395 + 1396 + i.name = b_entry_name; 1397 + i.value = buffer; 1398 + i.value_len = value_size; 1399 + error = ext4_xattr_block_find(inode, &i, bs); 1400 + if (error) 1401 + goto out; 1402 + 1403 + /* Add entry which was removed from the inode into the block */ 1404 + error = ext4_xattr_block_set(handle, inode, &i, bs); 1405 + if (error) 1406 + goto out; 1407 + error = 0; 1408 + out: 1409 + kfree(b_entry_name); 1410 + kfree(buffer); 1411 + if (is) 1412 + brelse(is->iloc.bh); 1413 + kfree(is); 1414 + kfree(bs); 1415 + 1416 + return error; 1417 + } 1418 + 1419 + static int ext4_xattr_make_inode_space(handle_t *handle, struct inode *inode, 1420 + struct ext4_inode *raw_inode, 1421 + int isize_diff, size_t ifree, 1422 + size_t bfree, int *total_ino) 1423 + { 1424 + struct ext4_xattr_ibody_header *header = IHDR(inode, raw_inode); 1425 + struct ext4_xattr_entry *small_entry; 1426 + struct ext4_xattr_entry *entry; 1427 + struct ext4_xattr_entry *last; 1428 + unsigned int entry_size; /* EA entry size */ 1429 + unsigned int total_size; /* EA entry size + value size */ 1430 + unsigned int min_total_size; 1431 + int error; 1432 + 1433 + while (isize_diff > ifree) { 1434 + entry = NULL; 1435 + small_entry = NULL; 1436 + min_total_size = ~0U; 1437 + last = IFIRST(header); 1438 + /* Find the entry best suited to be pushed into EA block */ 1439 + for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) { 1440 + total_size = 1441 + EXT4_XATTR_SIZE(le32_to_cpu(last->e_value_size)) + 1442 + EXT4_XATTR_LEN(last->e_name_len); 1443 + if (total_size <= bfree && 1444 + total_size < min_total_size) { 1445 + if (total_size + ifree < isize_diff) { 1446 + small_entry = last; 1447 + } else { 1448 + entry = last; 1449 + min_total_size = total_size; 1450 + } 1451 + } 1452 + } 1453 + 1454 + if (entry == NULL) { 1455 + if (small_entry == NULL) 1456 + return -ENOSPC; 1457 + entry = small_entry; 1458 + } 1459 + 1460 + entry_size = EXT4_XATTR_LEN(entry->e_name_len); 1461 + total_size = entry_size + 1462 + EXT4_XATTR_SIZE(le32_to_cpu(entry->e_value_size)); 1463 + error = ext4_xattr_move_to_block(handle, inode, raw_inode, 1464 + entry); 1465 + if (error) 1466 + return error; 1467 + 1468 + *total_ino -= entry_size; 1469 + ifree += total_size; 1470 + bfree -= total_size; 1471 + } 1472 + 1473 + return 0; 1339 1474 } 1340 1475 1341 1476 /* ··· 1482 1345 struct ext4_inode *raw_inode, handle_t *handle) 1483 1346 { 1484 1347 struct ext4_xattr_ibody_header *header; 1485 - struct ext4_xattr_entry *entry, *last, *first; 1486 1348 struct buffer_head *bh = NULL; 1487 - struct ext4_xattr_ibody_find *is = NULL; 1488 - struct ext4_xattr_block_find *bs = NULL; 1489 - char *buffer = NULL, *b_entry_name = NULL; 1490 - size_t min_offs, free; 1349 + size_t min_offs; 1350 + size_t ifree, bfree; 1491 1351 int total_ino; 1492 - void *base, *start, *end; 1352 + void *base, *end; 1493 1353 int error = 0, tried_min_extra_isize = 0; 1494 1354 int s_min_extra_isize = le16_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_min_extra_isize); 1495 1355 int isize_diff; /* How much do we need to grow i_extra_isize */ ··· 1502 1368 goto out; 1503 1369 1504 1370 header = IHDR(inode, raw_inode); 1505 - entry = IFIRST(header); 1506 1371 1507 1372 /* 1508 1373 * Check if enough free space is available in the inode to shift the 1509 1374 * entries ahead by new_extra_isize. 1510 1375 */ 1511 1376 1512 - base = start = entry; 1377 + base = IFIRST(header); 1513 1378 end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; 1514 1379 min_offs = end - base; 1515 - last = entry; 1516 1380 total_ino = sizeof(struct ext4_xattr_ibody_header); 1517 1381 1518 1382 error = xattr_check_inode(inode, header, end); 1519 1383 if (error) 1520 1384 goto cleanup; 1521 1385 1522 - free = ext4_xattr_free_space(last, &min_offs, base, &total_ino); 1523 - if (free >= isize_diff) { 1524 - entry = IFIRST(header); 1525 - ext4_xattr_shift_entries(entry, EXT4_I(inode)->i_extra_isize 1526 - - new_extra_isize, (void *)raw_inode + 1527 - EXT4_GOOD_OLD_INODE_SIZE + new_extra_isize, 1528 - (void *)header, total_ino, 1529 - inode->i_sb->s_blocksize); 1530 - EXT4_I(inode)->i_extra_isize = new_extra_isize; 1531 - goto out; 1532 - } 1386 + ifree = ext4_xattr_free_space(base, &min_offs, base, &total_ino); 1387 + if (ifree >= isize_diff) 1388 + goto shift; 1533 1389 1534 1390 /* 1535 1391 * Enough free space isn't available in the inode, check if ··· 1537 1413 goto cleanup; 1538 1414 } 1539 1415 base = BHDR(bh); 1540 - first = BFIRST(bh); 1541 1416 end = bh->b_data + bh->b_size; 1542 1417 min_offs = end - base; 1543 - free = ext4_xattr_free_space(first, &min_offs, base, NULL); 1544 - if (free < isize_diff) { 1418 + bfree = ext4_xattr_free_space(BFIRST(bh), &min_offs, base, 1419 + NULL); 1420 + if (bfree + ifree < isize_diff) { 1545 1421 if (!tried_min_extra_isize && s_min_extra_isize) { 1546 1422 tried_min_extra_isize++; 1547 1423 new_extra_isize = s_min_extra_isize; 1548 1424 brelse(bh); 1549 1425 goto retry; 1550 1426 } 1551 - error = -1; 1427 + error = -ENOSPC; 1552 1428 goto cleanup; 1553 1429 } 1554 1430 } else { 1555 - free = inode->i_sb->s_blocksize; 1431 + bfree = inode->i_sb->s_blocksize; 1556 1432 } 1557 1433 1558 - while (isize_diff > 0) { 1559 - size_t offs, size, entry_size; 1560 - struct ext4_xattr_entry *small_entry = NULL; 1561 - struct ext4_xattr_info i = { 1562 - .value = NULL, 1563 - .value_len = 0, 1564 - }; 1565 - unsigned int total_size; /* EA entry size + value size */ 1566 - unsigned int shift_bytes; /* No. of bytes to shift EAs by? */ 1567 - unsigned int min_total_size = ~0U; 1568 - 1569 - is = kzalloc(sizeof(struct ext4_xattr_ibody_find), GFP_NOFS); 1570 - bs = kzalloc(sizeof(struct ext4_xattr_block_find), GFP_NOFS); 1571 - if (!is || !bs) { 1572 - error = -ENOMEM; 1573 - goto cleanup; 1434 + error = ext4_xattr_make_inode_space(handle, inode, raw_inode, 1435 + isize_diff, ifree, bfree, 1436 + &total_ino); 1437 + if (error) { 1438 + if (error == -ENOSPC && !tried_min_extra_isize && 1439 + s_min_extra_isize) { 1440 + tried_min_extra_isize++; 1441 + new_extra_isize = s_min_extra_isize; 1442 + brelse(bh); 1443 + goto retry; 1574 1444 } 1575 - 1576 - is->s.not_found = -ENODATA; 1577 - bs->s.not_found = -ENODATA; 1578 - is->iloc.bh = NULL; 1579 - bs->bh = NULL; 1580 - 1581 - last = IFIRST(header); 1582 - /* Find the entry best suited to be pushed into EA block */ 1583 - entry = NULL; 1584 - for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) { 1585 - total_size = 1586 - EXT4_XATTR_SIZE(le32_to_cpu(last->e_value_size)) + 1587 - EXT4_XATTR_LEN(last->e_name_len); 1588 - if (total_size <= free && total_size < min_total_size) { 1589 - if (total_size < isize_diff) { 1590 - small_entry = last; 1591 - } else { 1592 - entry = last; 1593 - min_total_size = total_size; 1594 - } 1595 - } 1596 - } 1597 - 1598 - if (entry == NULL) { 1599 - if (small_entry) { 1600 - entry = small_entry; 1601 - } else { 1602 - if (!tried_min_extra_isize && 1603 - s_min_extra_isize) { 1604 - tried_min_extra_isize++; 1605 - new_extra_isize = s_min_extra_isize; 1606 - kfree(is); is = NULL; 1607 - kfree(bs); bs = NULL; 1608 - brelse(bh); 1609 - goto retry; 1610 - } 1611 - error = -1; 1612 - goto cleanup; 1613 - } 1614 - } 1615 - offs = le16_to_cpu(entry->e_value_offs); 1616 - size = le32_to_cpu(entry->e_value_size); 1617 - entry_size = EXT4_XATTR_LEN(entry->e_name_len); 1618 - i.name_index = entry->e_name_index, 1619 - buffer = kmalloc(EXT4_XATTR_SIZE(size), GFP_NOFS); 1620 - b_entry_name = kmalloc(entry->e_name_len + 1, GFP_NOFS); 1621 - if (!buffer || !b_entry_name) { 1622 - error = -ENOMEM; 1623 - goto cleanup; 1624 - } 1625 - /* Save the entry name and the entry value */ 1626 - memcpy(buffer, (void *)IFIRST(header) + offs, 1627 - EXT4_XATTR_SIZE(size)); 1628 - memcpy(b_entry_name, entry->e_name, entry->e_name_len); 1629 - b_entry_name[entry->e_name_len] = '\0'; 1630 - i.name = b_entry_name; 1631 - 1632 - error = ext4_get_inode_loc(inode, &is->iloc); 1633 - if (error) 1634 - goto cleanup; 1635 - 1636 - error = ext4_xattr_ibody_find(inode, &i, is); 1637 - if (error) 1638 - goto cleanup; 1639 - 1640 - /* Remove the chosen entry from the inode */ 1641 - error = ext4_xattr_ibody_set(handle, inode, &i, is); 1642 - if (error) 1643 - goto cleanup; 1644 - total_ino -= entry_size; 1645 - 1646 - entry = IFIRST(header); 1647 - if (entry_size + EXT4_XATTR_SIZE(size) >= isize_diff) 1648 - shift_bytes = isize_diff; 1649 - else 1650 - shift_bytes = entry_size + EXT4_XATTR_SIZE(size); 1651 - /* Adjust the offsets and shift the remaining entries ahead */ 1652 - ext4_xattr_shift_entries(entry, -shift_bytes, 1653 - (void *)raw_inode + EXT4_GOOD_OLD_INODE_SIZE + 1654 - EXT4_I(inode)->i_extra_isize + shift_bytes, 1655 - (void *)header, total_ino, inode->i_sb->s_blocksize); 1656 - 1657 - isize_diff -= shift_bytes; 1658 - EXT4_I(inode)->i_extra_isize += shift_bytes; 1659 - header = IHDR(inode, raw_inode); 1660 - 1661 - i.name = b_entry_name; 1662 - i.value = buffer; 1663 - i.value_len = size; 1664 - error = ext4_xattr_block_find(inode, &i, bs); 1665 - if (error) 1666 - goto cleanup; 1667 - 1668 - /* Add entry which was removed from the inode into the block */ 1669 - error = ext4_xattr_block_set(handle, inode, &i, bs); 1670 - if (error) 1671 - goto cleanup; 1672 - kfree(b_entry_name); 1673 - kfree(buffer); 1674 - b_entry_name = NULL; 1675 - buffer = NULL; 1676 - brelse(is->iloc.bh); 1677 - kfree(is); 1678 - kfree(bs); 1445 + goto cleanup; 1679 1446 } 1447 + shift: 1448 + /* Adjust the offsets and shift the remaining entries ahead */ 1449 + ext4_xattr_shift_entries(IFIRST(header), EXT4_I(inode)->i_extra_isize 1450 + - new_extra_isize, (void *)raw_inode + 1451 + EXT4_GOOD_OLD_INODE_SIZE + new_extra_isize, 1452 + (void *)header, total_ino); 1453 + EXT4_I(inode)->i_extra_isize = new_extra_isize; 1680 1454 brelse(bh); 1681 1455 out: 1682 1456 ext4_clear_inode_state(inode, EXT4_STATE_NO_EXPAND); ··· 1582 1560 return 0; 1583 1561 1584 1562 cleanup: 1585 - kfree(b_entry_name); 1586 - kfree(buffer); 1587 - if (is) 1588 - brelse(is->iloc.bh); 1589 - kfree(is); 1590 - kfree(bs); 1591 1563 brelse(bh); 1592 1564 /* 1593 1565 * We deliberately leave EXT4_STATE_NO_EXPAND set here since inode ··· 1750 1734 *name++; 1751 1735 } 1752 1736 1753 - if (entry->e_value_block == 0 && entry->e_value_size != 0) { 1737 + if (entry->e_value_size != 0) { 1754 1738 __le32 *value = (__le32 *)((char *)header + 1755 1739 le16_to_cpu(entry->e_value_offs)); 1756 1740 for (n = (le32_to_cpu(entry->e_value_size) +
+3 -3
fs/f2fs/dir.c
··· 813 813 814 814 if (f2fs_encrypted_inode(d->inode)) { 815 815 int save_len = fstr->len; 816 - int ret; 816 + int err; 817 817 818 - ret = fscrypt_fname_disk_to_usr(d->inode, 818 + err = fscrypt_fname_disk_to_usr(d->inode, 819 819 (u32)de->hash_code, 0, 820 820 &de_name, fstr); 821 - if (ret < 0) 821 + if (err) 822 822 return true; 823 823 824 824 de_name = *fstr;
+3 -3
fs/f2fs/namei.c
··· 454 454 ostr.name = sd->encrypted_path; 455 455 ostr.len = disk_link.len; 456 456 err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr); 457 - if (err < 0) 457 + if (err) 458 458 goto err_out; 459 459 460 460 sd->len = cpu_to_le16(ostr.len); ··· 1051 1051 goto errout; 1052 1052 1053 1053 res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr); 1054 - if (res < 0) 1054 + if (res) 1055 1055 goto errout; 1056 1056 1057 1057 /* this is broken symlink case */ ··· 1063 1063 paddr = pstr.name; 1064 1064 1065 1065 /* Null-terminate the name */ 1066 - paddr[res] = '\0'; 1066 + paddr[pstr.len] = '\0'; 1067 1067 1068 1068 put_page(cpage); 1069 1069 set_delayed_call(done, kfree_link, paddr);
+50 -81
fs/jbd2/journal.c
··· 1090 1090 * very few fields yet: that has to wait until we have created the 1091 1091 * journal structures from from scratch, or loaded them from disk. */ 1092 1092 1093 - static journal_t * journal_init_common (void) 1093 + static journal_t *journal_init_common(struct block_device *bdev, 1094 + struct block_device *fs_dev, 1095 + unsigned long long start, int len, int blocksize) 1094 1096 { 1095 1097 static struct lock_class_key jbd2_trans_commit_key; 1096 1098 journal_t *journal; 1097 1099 int err; 1100 + struct buffer_head *bh; 1101 + int n; 1098 1102 1099 1103 journal = kzalloc(sizeof(*journal), GFP_KERNEL); 1100 1104 if (!journal) ··· 1135 1131 lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle", 1136 1132 &jbd2_trans_commit_key, 0); 1137 1133 1134 + /* journal descriptor can store up to n blocks -bzzz */ 1135 + journal->j_blocksize = blocksize; 1136 + journal->j_dev = bdev; 1137 + journal->j_fs_dev = fs_dev; 1138 + journal->j_blk_offset = start; 1139 + journal->j_maxlen = len; 1140 + n = journal->j_blocksize / sizeof(journal_block_tag_t); 1141 + journal->j_wbufsize = n; 1142 + journal->j_wbuf = kmalloc_array(n, sizeof(struct buffer_head *), 1143 + GFP_KERNEL); 1144 + if (!journal->j_wbuf) { 1145 + kfree(journal); 1146 + return NULL; 1147 + } 1148 + 1149 + bh = getblk_unmovable(journal->j_dev, start, journal->j_blocksize); 1150 + if (!bh) { 1151 + pr_err("%s: Cannot get buffer for journal superblock\n", 1152 + __func__); 1153 + kfree(journal->j_wbuf); 1154 + kfree(journal); 1155 + return NULL; 1156 + } 1157 + journal->j_sb_buffer = bh; 1158 + journal->j_superblock = (journal_superblock_t *)bh->b_data; 1159 + 1138 1160 return journal; 1139 1161 } 1140 1162 ··· 1187 1157 * range of blocks on an arbitrary block device. 1188 1158 * 1189 1159 */ 1190 - journal_t * jbd2_journal_init_dev(struct block_device *bdev, 1160 + journal_t *jbd2_journal_init_dev(struct block_device *bdev, 1191 1161 struct block_device *fs_dev, 1192 1162 unsigned long long start, int len, int blocksize) 1193 1163 { 1194 - journal_t *journal = journal_init_common(); 1195 - struct buffer_head *bh; 1196 - int n; 1164 + journal_t *journal; 1197 1165 1166 + journal = journal_init_common(bdev, fs_dev, start, len, blocksize); 1198 1167 if (!journal) 1199 1168 return NULL; 1200 1169 1201 - /* journal descriptor can store up to n blocks -bzzz */ 1202 - journal->j_blocksize = blocksize; 1203 - journal->j_dev = bdev; 1204 - journal->j_fs_dev = fs_dev; 1205 - journal->j_blk_offset = start; 1206 - journal->j_maxlen = len; 1207 1170 bdevname(journal->j_dev, journal->j_devname); 1208 1171 strreplace(journal->j_devname, '/', '!'); 1209 1172 jbd2_stats_proc_init(journal); 1210 - n = journal->j_blocksize / sizeof(journal_block_tag_t); 1211 - journal->j_wbufsize = n; 1212 - journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL); 1213 - if (!journal->j_wbuf) { 1214 - printk(KERN_ERR "%s: Can't allocate bhs for commit thread\n", 1215 - __func__); 1216 - goto out_err; 1217 - } 1218 - 1219 - bh = __getblk(journal->j_dev, start, journal->j_blocksize); 1220 - if (!bh) { 1221 - printk(KERN_ERR 1222 - "%s: Cannot get buffer for journal superblock\n", 1223 - __func__); 1224 - goto out_err; 1225 - } 1226 - journal->j_sb_buffer = bh; 1227 - journal->j_superblock = (journal_superblock_t *)bh->b_data; 1228 1173 1229 1174 return journal; 1230 - out_err: 1231 - kfree(journal->j_wbuf); 1232 - jbd2_stats_proc_exit(journal); 1233 - kfree(journal); 1234 - return NULL; 1235 1175 } 1236 1176 1237 1177 /** ··· 1212 1212 * the journal. The inode must exist already, must support bmap() and 1213 1213 * must have all data blocks preallocated. 1214 1214 */ 1215 - journal_t * jbd2_journal_init_inode (struct inode *inode) 1215 + journal_t *jbd2_journal_init_inode(struct inode *inode) 1216 1216 { 1217 - struct buffer_head *bh; 1218 - journal_t *journal = journal_init_common(); 1217 + journal_t *journal; 1219 1218 char *p; 1220 - int err; 1221 - int n; 1222 1219 unsigned long long blocknr; 1223 1220 1221 + blocknr = bmap(inode, 0); 1222 + if (!blocknr) { 1223 + pr_err("%s: Cannot locate journal superblock\n", 1224 + __func__); 1225 + return NULL; 1226 + } 1227 + 1228 + jbd_debug(1, "JBD2: inode %s/%ld, size %lld, bits %d, blksize %ld\n", 1229 + inode->i_sb->s_id, inode->i_ino, (long long) inode->i_size, 1230 + inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize); 1231 + 1232 + journal = journal_init_common(inode->i_sb->s_bdev, inode->i_sb->s_bdev, 1233 + blocknr, inode->i_size >> inode->i_sb->s_blocksize_bits, 1234 + inode->i_sb->s_blocksize); 1224 1235 if (!journal) 1225 1236 return NULL; 1226 1237 1227 - journal->j_dev = journal->j_fs_dev = inode->i_sb->s_bdev; 1228 1238 journal->j_inode = inode; 1229 1239 bdevname(journal->j_dev, journal->j_devname); 1230 1240 p = strreplace(journal->j_devname, '/', '!'); 1231 1241 sprintf(p, "-%lu", journal->j_inode->i_ino); 1232 - jbd_debug(1, 1233 - "journal %p: inode %s/%ld, size %Ld, bits %d, blksize %ld\n", 1234 - journal, inode->i_sb->s_id, inode->i_ino, 1235 - (long long) inode->i_size, 1236 - inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize); 1237 - 1238 - journal->j_maxlen = inode->i_size >> inode->i_sb->s_blocksize_bits; 1239 - journal->j_blocksize = inode->i_sb->s_blocksize; 1240 1242 jbd2_stats_proc_init(journal); 1241 1243 1242 - /* journal descriptor can store up to n blocks -bzzz */ 1243 - n = journal->j_blocksize / sizeof(journal_block_tag_t); 1244 - journal->j_wbufsize = n; 1245 - journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL); 1246 - if (!journal->j_wbuf) { 1247 - printk(KERN_ERR "%s: Can't allocate bhs for commit thread\n", 1248 - __func__); 1249 - goto out_err; 1250 - } 1251 - 1252 - err = jbd2_journal_bmap(journal, 0, &blocknr); 1253 - /* If that failed, give up */ 1254 - if (err) { 1255 - printk(KERN_ERR "%s: Cannot locate journal superblock\n", 1256 - __func__); 1257 - goto out_err; 1258 - } 1259 - 1260 - bh = getblk_unmovable(journal->j_dev, blocknr, journal->j_blocksize); 1261 - if (!bh) { 1262 - printk(KERN_ERR 1263 - "%s: Cannot get buffer for journal superblock\n", 1264 - __func__); 1265 - goto out_err; 1266 - } 1267 - journal->j_sb_buffer = bh; 1268 - journal->j_superblock = (journal_superblock_t *)bh->b_data; 1269 - 1270 1244 return journal; 1271 - out_err: 1272 - kfree(journal->j_wbuf); 1273 - jbd2_stats_proc_exit(journal); 1274 - kfree(journal); 1275 - return NULL; 1276 1245 } 1277 1246 1278 1247 /*
+4 -2
fs/jbd2/transaction.c
··· 159 159 read_unlock(&journal->j_state_lock); 160 160 if (need_to_start) 161 161 jbd2_log_start_commit(journal, tid); 162 + jbd2_might_wait_for_commit(journal); 162 163 schedule(); 163 164 finish_wait(&journal->j_wait_transaction_locked, &wait); 164 165 } ··· 182 181 transaction_t *t = journal->j_running_transaction; 183 182 int needed; 184 183 int total = blocks + rsv_blocks; 185 - 186 - jbd2_might_wait_for_commit(journal); 187 184 188 185 /* 189 186 * If the current transaction is locked down for commit, wait ··· 213 214 if (atomic_read(&journal->j_reserved_credits) + total > 214 215 journal->j_max_transaction_buffers) { 215 216 read_unlock(&journal->j_state_lock); 217 + jbd2_might_wait_for_commit(journal); 216 218 wait_event(journal->j_wait_reserved, 217 219 atomic_read(&journal->j_reserved_credits) + total <= 218 220 journal->j_max_transaction_buffers); ··· 238 238 if (jbd2_log_space_left(journal) < jbd2_space_needed(journal)) { 239 239 atomic_sub(total, &t->t_outstanding_credits); 240 240 read_unlock(&journal->j_state_lock); 241 + jbd2_might_wait_for_commit(journal); 241 242 write_lock(&journal->j_state_lock); 242 243 if (jbd2_log_space_left(journal) < jbd2_space_needed(journal)) 243 244 __jbd2_log_wait_for_space(journal); ··· 256 255 sub_reserved_credits(journal, rsv_blocks); 257 256 atomic_sub(total, &t->t_outstanding_credits); 258 257 read_unlock(&journal->j_state_lock); 258 + jbd2_might_wait_for_commit(journal); 259 259 wait_event(journal->j_wait_reserved, 260 260 atomic_read(&journal->j_reserved_credits) + rsv_blocks 261 261 <= journal->j_max_transaction_buffers / 2);
+5 -1
fs/mbcache.c
··· 366 366 cache->c_shrink.count_objects = mb_cache_count; 367 367 cache->c_shrink.scan_objects = mb_cache_scan; 368 368 cache->c_shrink.seeks = DEFAULT_SEEKS; 369 - register_shrinker(&cache->c_shrink); 369 + if (register_shrinker(&cache->c_shrink)) { 370 + kfree(cache->c_hash); 371 + kfree(cache); 372 + goto err_out; 373 + } 370 374 371 375 INIT_WORK(&cache->c_shrink_work, mb_cache_shrink_worker); 372 376
+3 -25
include/linux/blockgroup_lock.h
··· 10 10 #include <linux/cache.h> 11 11 12 12 #ifdef CONFIG_SMP 13 - 14 - /* 15 - * We want a power-of-two. Is there a better way than this? 16 - */ 17 - 18 - #if NR_CPUS >= 32 19 - #define NR_BG_LOCKS 128 20 - #elif NR_CPUS >= 16 21 - #define NR_BG_LOCKS 64 22 - #elif NR_CPUS >= 8 23 - #define NR_BG_LOCKS 32 24 - #elif NR_CPUS >= 4 25 - #define NR_BG_LOCKS 16 26 - #elif NR_CPUS >= 2 27 - #define NR_BG_LOCKS 8 13 + #define NR_BG_LOCKS (4 << ilog2(NR_CPUS < 32 ? NR_CPUS : 32)) 28 14 #else 29 - #define NR_BG_LOCKS 4 30 - #endif 31 - 32 - #else /* CONFIG_SMP */ 33 15 #define NR_BG_LOCKS 1 34 - #endif /* CONFIG_SMP */ 16 + #endif 35 17 36 18 struct bgl_lock { 37 19 spinlock_t lock; ··· 31 49 spin_lock_init(&bgl->locks[i].lock); 32 50 } 33 51 34 - /* 35 - * The accessor is a macro so we can embed a blockgroup_lock into different 36 - * superblock types 37 - */ 38 52 static inline spinlock_t * 39 53 bgl_lock_ptr(struct blockgroup_lock *bgl, unsigned int block_group) 40 54 { 41 - return &bgl->locks[(block_group) & (NR_BG_LOCKS-1)].lock; 55 + return &bgl->locks[block_group & (NR_BG_LOCKS-1)].lock; 42 56 } 43 57 44 58 #endif
-24
include/linux/fscrypto.h
··· 111 111 struct fscrypt_completion_result ecr = { \ 112 112 COMPLETION_INITIALIZER((ecr).completion), 0 } 113 113 114 - static inline int fscrypt_key_size(int mode) 115 - { 116 - switch (mode) { 117 - case FS_ENCRYPTION_MODE_AES_256_XTS: 118 - return FS_AES_256_XTS_KEY_SIZE; 119 - case FS_ENCRYPTION_MODE_AES_256_GCM: 120 - return FS_AES_256_GCM_KEY_SIZE; 121 - case FS_ENCRYPTION_MODE_AES_256_CBC: 122 - return FS_AES_256_CBC_KEY_SIZE; 123 - case FS_ENCRYPTION_MODE_AES_256_CTS: 124 - return FS_AES_256_CTS_KEY_SIZE; 125 - default: 126 - BUG(); 127 - } 128 - return 0; 129 - } 130 - 131 114 #define FS_FNAME_NUM_SCATTER_ENTRIES 4 132 115 #define FS_CRYPTO_BLOCK_SIZE 16 133 116 #define FS_FNAME_CRYPTO_DIGEST_SIZE 32 ··· 183 200 static inline bool fscrypt_valid_filenames_enc_mode(u32 mode) 184 201 { 185 202 return (mode == FS_ENCRYPTION_MODE_AES_256_CTS); 186 - } 187 - 188 - static inline u32 fscrypt_validate_encryption_key_size(u32 mode, u32 size) 189 - { 190 - if (size == fscrypt_key_size(mode)) 191 - return size; 192 - return 0; 193 203 } 194 204 195 205 static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)