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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'ubifs-for-linus-6.11-rc1-take2' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs

Pull UBI and UBIFS updates from Richard Weinberger:

- Many fixes for power-cut issues by Zhihao Cheng

- Another ubiblock error path fix

- ubiblock section mismatch fix

- Misc fixes all over the place

* tag 'ubifs-for-linus-6.11-rc1-take2' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs:
ubi: Fix ubi_init() ubiblock_exit() section mismatch
ubifs: add check for crypto_shash_tfm_digest
ubifs: Fix inconsistent inode size when powercut happens during appendant writing
ubi: block: fix null-pointer-dereference in ubiblock_create()
ubifs: fix kernel-doc warnings
ubifs: correct UBIFS_DFS_DIR_LEN macro definition and improve code clarity
mtd: ubi: Restore missing cleanup on ubi_init() failure path
ubifs: dbg_orphan_check: Fix missed key type checking
ubifs: Fix unattached inode when powercut happens in creating
ubifs: Fix space leak when powercut happens in linking tmpfile
ubifs: Move ui->data initialization after initializing security
ubifs: Fix adding orphan entry twice for the same inode
ubifs: Remove insert_dead_orphan from replaying orphan process
Revert "ubifs: ubifs_symlink: Fix memleak of inode->i_link in error path"
ubifs: Don't add xattr inode into orphan area
ubifs: Fix unattached xattr inode if powercut happens after deleting
mtd: ubi: avoid expensive do_div() on 32-bit machines
mtd: ubi: make ubi_class constant
ubi: eba: properly rollback inside self_check_eba

+135 -214
+5 -4
drivers/mtd/ubi/block.c
··· 390 390 391 391 ret = blk_mq_alloc_tag_set(&dev->tag_set); 392 392 if (ret) { 393 - dev_err(disk_to_dev(dev->gd), "blk_mq_alloc_tag_set failed"); 393 + pr_err("ubiblock%d_%d: blk_mq_alloc_tag_set failed\n", 394 + dev->ubi_num, dev->vol_id); 394 395 goto out_free_dev; 395 396 } 396 397 ··· 408 407 gd->minors = 1; 409 408 gd->first_minor = idr_alloc(&ubiblock_minor_idr, dev, 0, 0, GFP_KERNEL); 410 409 if (gd->first_minor < 0) { 411 - dev_err(disk_to_dev(gd), 412 - "block: dynamic minor allocation failed"); 410 + pr_err("ubiblock%d_%d: block: dynamic minor allocation failed\n", 411 + dev->ubi_num, dev->vol_id); 413 412 ret = -ENODEV; 414 413 goto out_cleanup_disk; 415 414 } ··· 670 669 return ret; 671 670 } 672 671 673 - void __exit ubiblock_exit(void) 672 + void ubiblock_exit(void) 674 673 { 675 674 ubi_unregister_volume_notifier(&ubiblock_notifier); 676 675 ubiblock_remove_all();
+5 -2
drivers/mtd/ubi/build.c
··· 112 112 ATTRIBUTE_GROUPS(ubi_class); 113 113 114 114 /* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */ 115 - struct class ubi_class = { 115 + const struct class ubi_class = { 116 116 .name = UBI_NAME_STR, 117 117 .class_groups = ubi_class_groups, 118 118 }; ··· 1372 1372 1373 1373 /* See comment above re-ubi_is_module(). */ 1374 1374 if (ubi_is_module()) 1375 - goto out_slab; 1375 + goto out_debugfs; 1376 1376 } 1377 1377 1378 1378 register_mtd_user(&ubi_mtd_notifier); ··· 1387 1387 1388 1388 out_mtd_notifier: 1389 1389 unregister_mtd_user(&ubi_mtd_notifier); 1390 + ubiblock_exit(); 1391 + out_debugfs: 1392 + ubi_debugfs_exit(); 1390 1393 out_slab: 1391 1394 kmem_cache_destroy(ubi_wl_entry_slab); 1392 1395 out_dev_unreg:
+2 -2
drivers/mtd/ubi/debug.c
··· 598 598 if (!IS_ENABLED(CONFIG_DEBUG_FS)) 599 599 return 0; 600 600 601 - n = snprintf(d->dfs_dir_name, UBI_DFS_DIR_LEN + 1, UBI_DFS_DIR_NAME, 601 + n = snprintf(d->dfs_dir_name, UBI_DFS_DIR_LEN, UBI_DFS_DIR_NAME, 602 602 ubi->ubi_num); 603 - if (n > UBI_DFS_DIR_LEN) { 603 + if (n >= UBI_DFS_DIR_LEN) { 604 604 /* The array size is too small */ 605 605 return -EINVAL; 606 606 }
+2 -1
drivers/mtd/ubi/eba.c
··· 1564 1564 GFP_KERNEL); 1565 1565 if (!fm_eba[i]) { 1566 1566 ret = -ENOMEM; 1567 + kfree(scan_eba[i]); 1567 1568 goto out_free; 1568 1569 } 1569 1570 ··· 1600 1599 } 1601 1600 1602 1601 out_free: 1603 - for (i = 0; i < num_volumes; i++) { 1602 + while (--i >= 0) { 1604 1603 if (!ubi->volumes[i]) 1605 1604 continue; 1606 1605
+3 -3
drivers/mtd/ubi/nvmem.c
··· 6 6 /* UBI NVMEM provider */ 7 7 #include "ubi.h" 8 8 #include <linux/nvmem-provider.h> 9 - #include <asm/div64.h> 10 9 11 10 /* List of all NVMEM devices */ 12 11 static LIST_HEAD(nvmem_devices); ··· 26 27 struct ubi_nvmem *unv = priv; 27 28 struct ubi_volume_desc *desc; 28 29 uint32_t offs; 29 - uint64_t lnum = from; 30 + uint32_t lnum; 30 31 int err = 0; 31 32 32 33 desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY); 33 34 if (IS_ERR(desc)) 34 35 return PTR_ERR(desc); 35 36 36 - offs = do_div(lnum, unv->usable_leb_size); 37 + offs = from % unv->usable_leb_size; 38 + lnum = from / unv->usable_leb_size; 37 39 while (bytes_left) { 38 40 to_read = unv->usable_leb_size - offs; 39 41
+2 -2
drivers/mtd/ubi/ubi.h
··· 420 420 unsigned int power_cut_min; 421 421 unsigned int power_cut_max; 422 422 unsigned int emulate_failures; 423 - char dfs_dir_name[UBI_DFS_DIR_LEN + 1]; 423 + char dfs_dir_name[UBI_DFS_DIR_LEN]; 424 424 struct dentry *dfs_dir; 425 425 struct dentry *dfs_chk_gen; 426 426 struct dentry *dfs_chk_io; ··· 814 814 extern const struct file_operations ubi_ctrl_cdev_operations; 815 815 extern const struct file_operations ubi_cdev_operations; 816 816 extern const struct file_operations ubi_vol_cdev_operations; 817 - extern struct class ubi_class; 817 + extern const struct class ubi_class; 818 818 extern struct mutex ubi_devices_mutex; 819 819 extern struct blocking_notifier_head ubi_notifiers; 820 820
+2
fs/ubifs/compress.c
··· 82 82 83 83 /** 84 84 * ubifs_compress - compress data. 85 + * @c: UBIFS file-system description object 85 86 * @in_buf: data to compress 86 87 * @in_len: length of the data to compress 87 88 * @out_buf: output buffer where compressed data should be stored ··· 141 140 142 141 /** 143 142 * ubifs_decompress - decompress data. 143 + * @c: UBIFS file-system description object 144 144 * @in_buf: data to decompress 145 145 * @in_len: length of the data to decompress 146 146 * @out_buf: output buffer where decompressed data should
+2 -2
fs/ubifs/debug.c
··· 2827 2827 const char *fname; 2828 2828 struct ubifs_debug_info *d = c->dbg; 2829 2829 2830 - n = snprintf(d->dfs_dir_name, UBIFS_DFS_DIR_LEN + 1, UBIFS_DFS_DIR_NAME, 2830 + n = snprintf(d->dfs_dir_name, UBIFS_DFS_DIR_LEN, UBIFS_DFS_DIR_NAME, 2831 2831 c->vi.ubi_num, c->vi.vol_id); 2832 - if (n > UBIFS_DFS_DIR_LEN) { 2832 + if (n >= UBIFS_DFS_DIR_LEN) { 2833 2833 /* The array size is too small */ 2834 2834 return; 2835 2835 }
+4 -3
fs/ubifs/debug.h
··· 19 19 20 20 /* 21 21 * The UBIFS debugfs directory name pattern and maximum name length (3 for "ubi" 22 - * + 1 for "_" and plus 2x2 for 2 UBI numbers and 1 for the trailing zero byte. 22 + * + 1 for "_" and 2 for UBI device numbers and 3 for volume number and 1 for 23 + * the trailing zero byte. 23 24 */ 24 25 #define UBIFS_DFS_DIR_NAME "ubi%d_%d" 25 - #define UBIFS_DFS_DIR_LEN (3 + 1 + 2*2 + 1) 26 + #define UBIFS_DFS_DIR_LEN (3 + 1 + 2 + 3 + 1) 26 27 27 28 /** 28 29 * ubifs_debug_info - per-FS debugging information. ··· 104 103 unsigned int chk_fs:1; 105 104 unsigned int tst_rcvry:1; 106 105 107 - char dfs_dir_name[UBIFS_DFS_DIR_LEN + 1]; 106 + char dfs_dir_name[UBIFS_DFS_DIR_LEN]; 108 107 struct dentry *dfs_dir; 109 108 struct dentry *dfs_dump_lprops; 110 109 struct dentry *dfs_dump_budg;
+53 -38
fs/ubifs/dir.c
··· 71 71 * @is_xattr: whether the inode is xattr inode 72 72 * 73 73 * This function finds an unused inode number, allocates new inode and 74 - * initializes it. Returns new inode in case of success and an error code in 75 - * case of failure. 74 + * initializes it. Non-xattr new inode may be written with xattrs(selinux/ 75 + * encryption) before writing dentry, which could cause inconsistent problem 76 + * when powercut happens between two operations. To deal with it, non-xattr 77 + * new inode is initialized with zero-nlink and added into orphan list, caller 78 + * should make sure that inode is relinked later, and make sure that orphan 79 + * removing and journal writing into an committing atomic operation. Returns 80 + * new inode in case of success and an error code in case of failure. 76 81 */ 77 82 struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir, 78 83 umode_t mode, bool is_xattr) ··· 168 163 ui->creat_sqnum = ++c->max_sqnum; 169 164 spin_unlock(&c->cnt_lock); 170 165 166 + if (!is_xattr) { 167 + set_nlink(inode, 0); 168 + err = ubifs_add_orphan(c, inode->i_ino); 169 + if (err) { 170 + ubifs_err(c, "ubifs_add_orphan failed: %i", err); 171 + goto out_iput; 172 + } 173 + down_read(&c->commit_sem); 174 + ui->del_cmtno = c->cmt_no; 175 + up_read(&c->commit_sem); 176 + } 177 + 171 178 if (encrypted) { 172 179 err = fscrypt_set_context(inode, NULL); 173 180 if (err) { 181 + if (!is_xattr) { 182 + set_nlink(inode, 1); 183 + ubifs_delete_orphan(c, inode->i_ino); 184 + } 174 185 ubifs_err(c, "fscrypt_set_context failed: %i", err); 175 186 goto out_iput; 176 187 } ··· 341 320 if (err) 342 321 goto out_inode; 343 322 323 + set_nlink(inode, 1); 344 324 mutex_lock(&dir_ui->ui_mutex); 345 325 dir->i_size += sz_change; 346 326 dir_ui->ui_size = dir->i_size; 347 327 inode_set_mtime_to_ts(dir, 348 328 inode_set_ctime_to_ts(dir, inode_get_ctime(inode))); 349 - err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0); 329 + err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0, 1); 350 330 if (err) 351 331 goto out_cancel; 352 332 mutex_unlock(&dir_ui->ui_mutex); ··· 362 340 dir->i_size -= sz_change; 363 341 dir_ui->ui_size = dir->i_size; 364 342 mutex_unlock(&dir_ui->ui_mutex); 343 + set_nlink(inode, 0); 365 344 out_inode: 366 - make_bad_inode(inode); 367 345 iput(inode); 368 346 out_fname: 369 347 fscrypt_free_filename(&nm); ··· 408 386 return inode; 409 387 410 388 out_inode: 411 - make_bad_inode(inode); 412 389 iput(inode); 413 390 out_free: 414 391 ubifs_err(c, "cannot create whiteout file, error %d", err); ··· 491 470 if (err) 492 471 goto out_inode; 493 472 473 + set_nlink(inode, 1); 494 474 mutex_lock(&ui->ui_mutex); 495 475 insert_inode_hash(inode); 496 476 d_tmpfile(file, inode); ··· 501 479 mutex_unlock(&ui->ui_mutex); 502 480 503 481 lock_2_inodes(dir, inode); 504 - err = ubifs_jnl_update(c, dir, &nm, inode, 1, 0); 482 + err = ubifs_jnl_update(c, dir, &nm, inode, 1, 0, 1); 505 483 if (err) 506 484 goto out_cancel; 507 485 unlock_2_inodes(dir, inode); ··· 514 492 out_cancel: 515 493 unlock_2_inodes(dir, inode); 516 494 out_inode: 517 - make_bad_inode(inode); 518 495 if (!instantiated) 519 496 iput(inode); 520 497 out_budg: ··· 781 760 782 761 lock_2_inodes(dir, inode); 783 762 784 - /* Handle O_TMPFILE corner case, it is allowed to link a O_TMPFILE. */ 785 - if (inode->i_nlink == 0) 786 - ubifs_delete_orphan(c, inode->i_ino); 787 - 788 763 inc_nlink(inode); 789 764 ihold(inode); 790 765 inode_set_ctime_current(inode); ··· 788 771 dir_ui->ui_size = dir->i_size; 789 772 inode_set_mtime_to_ts(dir, 790 773 inode_set_ctime_to_ts(dir, inode_get_ctime(inode))); 791 - err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0); 774 + err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0, inode->i_nlink == 1); 792 775 if (err) 793 776 goto out_cancel; 794 777 unlock_2_inodes(dir, inode); ··· 802 785 dir->i_size -= sz_change; 803 786 dir_ui->ui_size = dir->i_size; 804 787 drop_nlink(inode); 805 - if (inode->i_nlink == 0) 806 - ubifs_add_orphan(c, inode->i_ino); 807 788 unlock_2_inodes(dir, inode); 808 789 ubifs_release_budget(c, &req); 809 790 iput(inode); ··· 861 846 dir_ui->ui_size = dir->i_size; 862 847 inode_set_mtime_to_ts(dir, 863 848 inode_set_ctime_to_ts(dir, inode_get_ctime(inode))); 864 - err = ubifs_jnl_update(c, dir, &nm, inode, 1, 0); 849 + err = ubifs_jnl_update(c, dir, &nm, inode, 1, 0, 0); 865 850 if (err) 866 851 goto out_cancel; 867 852 unlock_2_inodes(dir, inode); ··· 965 950 dir_ui->ui_size = dir->i_size; 966 951 inode_set_mtime_to_ts(dir, 967 952 inode_set_ctime_to_ts(dir, inode_get_ctime(inode))); 968 - err = ubifs_jnl_update(c, dir, &nm, inode, 1, 0); 953 + err = ubifs_jnl_update(c, dir, &nm, inode, 1, 0, 0); 969 954 if (err) 970 955 goto out_cancel; 971 956 unlock_2_inodes(dir, inode); ··· 1032 1017 if (err) 1033 1018 goto out_inode; 1034 1019 1020 + set_nlink(inode, 1); 1035 1021 mutex_lock(&dir_ui->ui_mutex); 1036 1022 insert_inode_hash(inode); 1037 1023 inc_nlink(inode); ··· 1041 1025 dir_ui->ui_size = dir->i_size; 1042 1026 inode_set_mtime_to_ts(dir, 1043 1027 inode_set_ctime_to_ts(dir, inode_get_ctime(inode))); 1044 - err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0); 1028 + err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0, 1); 1045 1029 if (err) { 1046 1030 ubifs_err(c, "cannot create directory, error %d", err); 1047 1031 goto out_cancel; ··· 1058 1042 dir_ui->ui_size = dir->i_size; 1059 1043 drop_nlink(dir); 1060 1044 mutex_unlock(&dir_ui->ui_mutex); 1045 + set_nlink(inode, 0); 1061 1046 out_inode: 1062 - make_bad_inode(inode); 1063 1047 iput(inode); 1064 1048 out_fname: 1065 1049 fscrypt_free_filename(&nm); ··· 1118 1102 goto out_fname; 1119 1103 } 1120 1104 1105 + err = ubifs_init_security(dir, inode, &dentry->d_name); 1106 + if (err) { 1107 + kfree(dev); 1108 + goto out_inode; 1109 + } 1110 + 1121 1111 init_special_inode(inode, inode->i_mode, rdev); 1122 1112 inode->i_size = ubifs_inode(inode)->ui_size = devlen; 1123 1113 ui = ubifs_inode(inode); 1124 1114 ui->data = dev; 1125 1115 ui->data_len = devlen; 1126 - 1127 - err = ubifs_init_security(dir, inode, &dentry->d_name); 1128 - if (err) 1129 - goto out_inode; 1116 + set_nlink(inode, 1); 1130 1117 1131 1118 mutex_lock(&dir_ui->ui_mutex); 1132 1119 dir->i_size += sz_change; 1133 1120 dir_ui->ui_size = dir->i_size; 1134 1121 inode_set_mtime_to_ts(dir, 1135 1122 inode_set_ctime_to_ts(dir, inode_get_ctime(inode))); 1136 - err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0); 1123 + err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0, 1); 1137 1124 if (err) 1138 1125 goto out_cancel; 1139 1126 mutex_unlock(&dir_ui->ui_mutex); ··· 1151 1132 dir->i_size -= sz_change; 1152 1133 dir_ui->ui_size = dir->i_size; 1153 1134 mutex_unlock(&dir_ui->ui_mutex); 1135 + set_nlink(inode, 0); 1154 1136 out_inode: 1155 - /* Free inode->i_link before inode is marked as bad. */ 1156 - fscrypt_free_inode(inode); 1157 - make_bad_inode(inode); 1158 1137 iput(inode); 1159 1138 out_fname: 1160 1139 fscrypt_free_filename(&nm); ··· 1203 1186 goto out_fname; 1204 1187 } 1205 1188 1189 + err = ubifs_init_security(dir, inode, &dentry->d_name); 1190 + if (err) 1191 + goto out_inode; 1192 + 1206 1193 ui = ubifs_inode(inode); 1207 1194 ui->data = kmalloc(disk_link.len, GFP_NOFS); 1208 1195 if (!ui->data) { ··· 1231 1210 */ 1232 1211 ui->data_len = disk_link.len - 1; 1233 1212 inode->i_size = ubifs_inode(inode)->ui_size = disk_link.len - 1; 1234 - 1235 - err = ubifs_init_security(dir, inode, &dentry->d_name); 1236 - if (err) 1237 - goto out_inode; 1213 + set_nlink(inode, 1); 1238 1214 1239 1215 mutex_lock(&dir_ui->ui_mutex); 1240 1216 dir->i_size += sz_change; 1241 1217 dir_ui->ui_size = dir->i_size; 1242 1218 inode_set_mtime_to_ts(dir, 1243 1219 inode_set_ctime_to_ts(dir, inode_get_ctime(inode))); 1244 - err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0); 1220 + err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0, 1); 1245 1221 if (err) 1246 1222 goto out_cancel; 1247 1223 mutex_unlock(&dir_ui->ui_mutex); ··· 1252 1234 dir->i_size -= sz_change; 1253 1235 dir_ui->ui_size = dir->i_size; 1254 1236 mutex_unlock(&dir_ui->ui_mutex); 1237 + set_nlink(inode, 0); 1255 1238 out_inode: 1256 1239 /* Free inode->i_link before inode is marked as bad. */ 1257 1240 fscrypt_free_inode(inode); 1258 - make_bad_inode(inode); 1259 1241 iput(inode); 1260 1242 out_fname: 1261 1243 fscrypt_free_filename(&nm); ··· 1423 1405 */ 1424 1406 err = ubifs_budget_space(c, &wht_req); 1425 1407 if (err) { 1426 - /* 1427 - * Whiteout inode can not be written on flash by 1428 - * ubifs_jnl_write_inode(), because it's neither 1429 - * dirty nor zero-nlink. 1430 - */ 1431 1408 iput(whiteout); 1432 1409 goto out_release; 1433 1410 } 1411 + set_nlink(whiteout, 1); 1434 1412 1435 1413 /* Add the old_dentry size to the old_dir size. */ 1436 1414 old_sz -= CALC_DENT_SIZE(fname_len(&old_nm)); ··· 1505 1491 } 1506 1492 1507 1493 err = ubifs_jnl_rename(c, old_dir, old_inode, &old_nm, new_dir, 1508 - new_inode, &new_nm, whiteout, sync); 1494 + new_inode, &new_nm, whiteout, sync, !!whiteout); 1509 1495 if (err) 1510 1496 goto out_cancel; 1511 1497 ··· 1558 1544 unlock_4_inodes(old_dir, new_dir, new_inode, whiteout); 1559 1545 if (whiteout) { 1560 1546 ubifs_release_budget(c, &wht_req); 1547 + set_nlink(whiteout, 0); 1561 1548 iput(whiteout); 1562 1549 } 1563 1550 out_release:
+1 -1
fs/ubifs/file.c
··· 1027 1027 1028 1028 /* Is the folio fully inside i_size? */ 1029 1029 if (folio_pos(folio) + len <= i_size) { 1030 - if (folio_pos(folio) >= synced_i_size) { 1030 + if (folio_pos(folio) + len > synced_i_size) { 1031 1031 err = inode->i_sb->s_op->write_inode(inode, NULL); 1032 1032 if (err) 1033 1033 goto out_redirty;
+4 -4
fs/ubifs/find.c
··· 73 73 * @c: the UBIFS file-system description object 74 74 * @lprops: LEB properties to scan 75 75 * @in_tree: whether the LEB properties are in main memory 76 - * @data: information passed to and from the caller of the scan 76 + * @arg: information passed to and from the caller of the scan 77 77 * 78 78 * This function returns a code that indicates whether the scan should continue 79 79 * (%LPT_SCAN_CONTINUE), whether the LEB properties should be added to the tree ··· 340 340 * @c: the UBIFS file-system description object 341 341 * @lprops: LEB properties to scan 342 342 * @in_tree: whether the LEB properties are in main memory 343 - * @data: information passed to and from the caller of the scan 343 + * @arg: information passed to and from the caller of the scan 344 344 * 345 345 * This function returns a code that indicates whether the scan should continue 346 346 * (%LPT_SCAN_CONTINUE), whether the LEB properties should be added to the tree ··· 581 581 * @c: the UBIFS file-system description object 582 582 * @lprops: LEB properties to scan 583 583 * @in_tree: whether the LEB properties are in main memory 584 - * @data: information passed to and from the caller of the scan 584 + * @arg: information passed to and from the caller of the scan 585 585 * 586 586 * This function returns a code that indicates whether the scan should continue 587 587 * (%LPT_SCAN_CONTINUE), whether the LEB properties should be added to the tree ··· 773 773 * @c: the UBIFS file-system description object 774 774 * @lprops: LEB properties to scan 775 775 * @in_tree: whether the LEB properties are in main memory 776 - * @data: information passed to and from the caller of the scan 776 + * @arg: information passed to and from the caller of the scan 777 777 * 778 778 * This function returns a code that indicates whether the scan should continue 779 779 * (%LPT_SCAN_CONTINUE), whether the LEB properties should be added to the tree
+12 -4
fs/ubifs/journal.c
··· 359 359 } 360 360 361 361 /** 362 - * wake_up_reservation - add current task in queue or start queuing. 362 + * add_or_start_queue - add current task in queue or start queuing. 363 363 * @c: UBIFS file-system description object 364 364 * 365 365 * This function starts queuing if queuing is not started, otherwise adds ··· 643 643 * @inode: inode to update 644 644 * @deletion: indicates a directory entry deletion i.e unlink or rmdir 645 645 * @xent: non-zero if the directory entry is an extended attribute entry 646 + * @in_orphan: indicates whether the @inode is in orphan list 646 647 * 647 648 * This function updates an inode by writing a directory entry (or extended 648 649 * attribute entry), the inode itself, and the parent directory inode (or the ··· 665 664 */ 666 665 int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir, 667 666 const struct fscrypt_name *nm, const struct inode *inode, 668 - int deletion, int xent) 667 + int deletion, int xent, int in_orphan) 669 668 { 670 669 int err, dlen, ilen, len, lnum, ino_offs, dent_offs, orphan_added = 0; 671 670 int aligned_dlen, aligned_ilen, sync = IS_DIRSYNC(dir); ··· 751 750 if (err) 752 751 goto out_release; 753 752 754 - if (last_reference) { 753 + if (last_reference && !in_orphan) { 755 754 err = ubifs_add_orphan(c, inode->i_ino); 756 755 if (err) { 757 756 release_head(c, BASEHD); ··· 806 805 UBIFS_INO_NODE_SZ + host_ui->data_len, hash_ino_host); 807 806 if (err) 808 807 goto out_ro; 808 + 809 + if (in_orphan && inode->i_nlink) 810 + ubifs_delete_orphan(c, inode->i_ino); 809 811 810 812 finish_reservation(c); 811 813 spin_lock(&ui->ui_lock); ··· 1340 1336 * @new_nm: new name of the new directory entry 1341 1337 * @whiteout: whiteout inode 1342 1338 * @sync: non-zero if the write-buffer has to be synchronized 1339 + * @delete_orphan: indicates an orphan entry deletion for @whiteout 1343 1340 * 1344 1341 * This function implements the re-name operation which may involve writing up 1345 1342 * to 4 inodes(new inode, whiteout inode, old and new parent directory inodes) ··· 1353 1348 const struct inode *new_dir, 1354 1349 const struct inode *new_inode, 1355 1350 const struct fscrypt_name *new_nm, 1356 - const struct inode *whiteout, int sync) 1351 + const struct inode *whiteout, int sync, int delete_orphan) 1357 1352 { 1358 1353 void *p; 1359 1354 union ubifs_key key; ··· 1569 1564 if (err) 1570 1565 goto out_ro; 1571 1566 } 1567 + 1568 + if (delete_orphan) 1569 + ubifs_delete_orphan(c, whiteout->i_ino); 1572 1570 1573 1571 finish_reservation(c); 1574 1572 if (new_inode) {
+1 -1
fs/ubifs/lprops.c
··· 1005 1005 * @c: the UBIFS file-system description object 1006 1006 * @lp: LEB properties to scan 1007 1007 * @in_tree: whether the LEB properties are in main memory 1008 - * @lst: lprops statistics to update 1008 + * @arg: lprops statistics to update 1009 1009 * 1010 1010 * This function returns a code that indicates whether the scan should continue 1011 1011 * (%LPT_SCAN_CONTINUE), whether the LEB properties should be added to the tree
+1
fs/ubifs/lpt.c
··· 1918 1918 * @pnode: where to keep a pnode 1919 1919 * @cnode: where to keep a cnode 1920 1920 * @in_tree: is the node in the tree in memory 1921 + * @ptr: union of node pointers 1921 1922 * @ptr.nnode: pointer to the nnode (if it is an nnode) which may be here or in 1922 1923 * the tree 1923 1924 * @ptr.pnode: ditto for pnode
+4 -1
fs/ubifs/master.c
··· 67 67 { 68 68 u8 calc[UBIFS_MAX_HASH_LEN]; 69 69 const void *node = mst; 70 + int ret; 70 71 71 - crypto_shash_tfm_digest(c->hash_tfm, node + sizeof(struct ubifs_ch), 72 + ret = crypto_shash_tfm_digest(c->hash_tfm, node + sizeof(struct ubifs_ch), 72 73 UBIFS_MST_NODE_SZ - sizeof(struct ubifs_ch), 73 74 calc); 75 + if (ret) 76 + return ret; 74 77 75 78 if (ubifs_check_hash(c, expected, calc)) 76 79 return -EPERM;
+25 -130
fs/ubifs/orphan.c
··· 42 42 43 43 static int dbg_check_orphans(struct ubifs_info *c); 44 44 45 - static struct ubifs_orphan *orphan_add(struct ubifs_info *c, ino_t inum, 46 - struct ubifs_orphan *parent_orphan) 45 + /** 46 + * ubifs_add_orphan - add an orphan. 47 + * @c: UBIFS file-system description object 48 + * @inum: orphan inode number 49 + * 50 + * Add an orphan. This function is called when an inodes link count drops to 51 + * zero. 52 + */ 53 + int ubifs_add_orphan(struct ubifs_info *c, ino_t inum) 47 54 { 48 55 struct ubifs_orphan *orphan, *o; 49 56 struct rb_node **p, *parent = NULL; 50 57 51 58 orphan = kzalloc(sizeof(struct ubifs_orphan), GFP_NOFS); 52 59 if (!orphan) 53 - return ERR_PTR(-ENOMEM); 60 + return -ENOMEM; 54 61 orphan->inum = inum; 55 62 orphan->new = 1; 56 - INIT_LIST_HEAD(&orphan->child_list); 57 63 58 64 spin_lock(&c->orphan_lock); 59 65 if (c->tot_orphans >= c->max_orphans) { 60 66 spin_unlock(&c->orphan_lock); 61 67 kfree(orphan); 62 - return ERR_PTR(-ENFILE); 68 + return -ENFILE; 63 69 } 64 70 p = &c->orph_tree.rb_node; 65 71 while (*p) { ··· 79 73 ubifs_err(c, "orphaned twice"); 80 74 spin_unlock(&c->orphan_lock); 81 75 kfree(orphan); 82 - return ERR_PTR(-EINVAL); 76 + return -EINVAL; 83 77 } 84 78 } 85 79 c->tot_orphans += 1; ··· 89 83 list_add_tail(&orphan->list, &c->orph_list); 90 84 list_add_tail(&orphan->new_list, &c->orph_new); 91 85 92 - if (parent_orphan) { 93 - list_add_tail(&orphan->child_list, 94 - &parent_orphan->child_list); 95 - } 96 - 97 86 spin_unlock(&c->orphan_lock); 98 87 dbg_gen("ino %lu", (unsigned long)inum); 99 - return orphan; 88 + return 0; 100 89 } 101 90 102 91 static struct ubifs_orphan *lookup_orphan(struct ubifs_info *c, ino_t inum) ··· 136 135 137 136 if (orph->cmt) { 138 137 orph->del = 1; 138 + rb_erase(&orph->rb, &c->orph_tree); 139 139 orph->dnext = c->orph_dnext; 140 140 c->orph_dnext = orph; 141 141 dbg_gen("delete later ino %lu", (unsigned long)orph->inum); ··· 144 142 } 145 143 146 144 __orphan_drop(c, orph); 147 - } 148 - 149 - /** 150 - * ubifs_add_orphan - add an orphan. 151 - * @c: UBIFS file-system description object 152 - * @inum: orphan inode number 153 - * 154 - * Add an orphan. This function is called when an inodes link count drops to 155 - * zero. 156 - */ 157 - int ubifs_add_orphan(struct ubifs_info *c, ino_t inum) 158 - { 159 - int err = 0; 160 - ino_t xattr_inum; 161 - union ubifs_key key; 162 - struct ubifs_dent_node *xent, *pxent = NULL; 163 - struct fscrypt_name nm = {0}; 164 - struct ubifs_orphan *xattr_orphan; 165 - struct ubifs_orphan *orphan; 166 - 167 - orphan = orphan_add(c, inum, NULL); 168 - if (IS_ERR(orphan)) 169 - return PTR_ERR(orphan); 170 - 171 - lowest_xent_key(c, &key, inum); 172 - while (1) { 173 - xent = ubifs_tnc_next_ent(c, &key, &nm); 174 - if (IS_ERR(xent)) { 175 - err = PTR_ERR(xent); 176 - if (err == -ENOENT) 177 - break; 178 - kfree(pxent); 179 - return err; 180 - } 181 - 182 - fname_name(&nm) = xent->name; 183 - fname_len(&nm) = le16_to_cpu(xent->nlen); 184 - xattr_inum = le64_to_cpu(xent->inum); 185 - 186 - xattr_orphan = orphan_add(c, xattr_inum, orphan); 187 - if (IS_ERR(xattr_orphan)) { 188 - kfree(pxent); 189 - kfree(xent); 190 - return PTR_ERR(xattr_orphan); 191 - } 192 - 193 - kfree(pxent); 194 - pxent = xent; 195 - key_read(c, &xent->key, &key); 196 - } 197 - kfree(pxent); 198 - 199 - return 0; 200 145 } 201 146 202 147 /** ··· 155 206 */ 156 207 void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum) 157 208 { 158 - struct ubifs_orphan *orph, *child_orph, *tmp_o; 209 + struct ubifs_orphan *orph; 159 210 160 211 spin_lock(&c->orphan_lock); 161 212 ··· 168 219 return; 169 220 } 170 221 171 - list_for_each_entry_safe(child_orph, tmp_o, &orph->child_list, child_list) { 172 - list_del(&child_orph->child_list); 173 - orphan_delete(c, child_orph); 174 - } 175 - 176 222 orphan_delete(c, orph); 177 223 178 224 spin_unlock(&c->orphan_lock); ··· 462 518 dnext = orphan->dnext; 463 519 ubifs_assert(c, !orphan->new); 464 520 ubifs_assert(c, orphan->del); 465 - rb_erase(&orphan->rb, &c->orph_tree); 466 521 list_del(&orphan->list); 467 522 c->tot_orphans -= 1; 468 523 dbg_gen("deleting orphan ino %lu", (unsigned long)orphan->inum); ··· 510 567 } 511 568 c->ohead_lnum = c->orph_first; 512 569 c->ohead_offs = 0; 513 - return 0; 514 - } 515 - 516 - /** 517 - * insert_dead_orphan - insert an orphan. 518 - * @c: UBIFS file-system description object 519 - * @inum: orphan inode number 520 - * 521 - * This function is a helper to the 'do_kill_orphans()' function. The orphan 522 - * must be kept until the next commit, so it is added to the rb-tree and the 523 - * deletion list. 524 - */ 525 - static int insert_dead_orphan(struct ubifs_info *c, ino_t inum) 526 - { 527 - struct ubifs_orphan *orphan, *o; 528 - struct rb_node **p, *parent = NULL; 529 - 530 - orphan = kzalloc(sizeof(struct ubifs_orphan), GFP_KERNEL); 531 - if (!orphan) 532 - return -ENOMEM; 533 - orphan->inum = inum; 534 - 535 - p = &c->orph_tree.rb_node; 536 - while (*p) { 537 - parent = *p; 538 - o = rb_entry(parent, struct ubifs_orphan, rb); 539 - if (inum < o->inum) 540 - p = &(*p)->rb_left; 541 - else if (inum > o->inum) 542 - p = &(*p)->rb_right; 543 - else { 544 - /* Already added - no problem */ 545 - kfree(orphan); 546 - return 0; 547 - } 548 - } 549 - c->tot_orphans += 1; 550 - rb_link_node(&orphan->rb, parent, p); 551 - rb_insert_color(&orphan->rb, &c->orph_tree); 552 - list_add_tail(&orphan->list, &c->orph_list); 553 - orphan->del = 1; 554 - orphan->dnext = c->orph_dnext; 555 - c->orph_dnext = orphan; 556 - dbg_mnt("ino %lu, new %d, tot %d", (unsigned long)inum, 557 - c->new_orphans, c->tot_orphans); 558 570 return 0; 559 571 } 560 572 ··· 589 691 590 692 n = (le32_to_cpu(orph->ch.len) - UBIFS_ORPH_NODE_SZ) >> 3; 591 693 for (i = 0; i < n; i++) { 592 - union ubifs_key key1, key2; 694 + union ubifs_key key; 593 695 594 696 inum = le64_to_cpu(orph->inos[i]); 595 697 596 - ino_key_init(c, &key1, inum); 597 - err = ubifs_tnc_lookup(c, &key1, ino); 698 + ino_key_init(c, &key, inum); 699 + err = ubifs_tnc_lookup(c, &key, ino); 598 700 if (err && err != -ENOENT) 599 701 goto out_free; 600 702 ··· 606 708 dbg_rcvry("deleting orphaned inode %lu", 607 709 (unsigned long)inum); 608 710 609 - lowest_ino_key(c, &key1, inum); 610 - highest_ino_key(c, &key2, inum); 611 - 612 - err = ubifs_tnc_remove_range(c, &key1, &key2); 711 + err = ubifs_tnc_remove_ino(c, inum); 613 712 if (err) 614 713 goto out_ro; 615 714 } 616 - 617 - err = insert_dead_orphan(c, inum); 618 - if (err) 619 - goto out_free; 620 715 } 621 716 622 717 *last_cmt_no = cmt_no; ··· 816 925 817 926 inum = key_inum(c, &zbr->key); 818 927 if (inum != ci->last_ino) { 819 - /* Lowest node type is the inode node, so it comes first */ 820 - if (key_type(c, &zbr->key) != UBIFS_INO_KEY) 928 + /* 929 + * Lowest node type is the inode node or xattr entry(when 930 + * selinux/encryption is enabled), so it comes first 931 + */ 932 + if (key_type(c, &zbr->key) != UBIFS_INO_KEY && 933 + key_type(c, &zbr->key) != UBIFS_XENT_KEY) 821 934 ubifs_err(c, "found orphan node ino %lu, type %d", 822 935 (unsigned long)inum, key_type(c, &zbr->key)); 823 936 ci->last_ino = inum;
+1
fs/ubifs/replay.c
··· 29 29 * @lnum: logical eraseblock number of the node 30 30 * @offs: node offset 31 31 * @len: node length 32 + * @hash: node hash 32 33 * @deletion: non-zero if this entry corresponds to a node deletion 33 34 * @sqnum: node sequence number 34 35 * @list: links the replay list
+3 -3
fs/ubifs/sysfs.c
··· 91 91 int ubifs_sysfs_register(struct ubifs_info *c) 92 92 { 93 93 int ret, n; 94 - char dfs_dir_name[UBIFS_DFS_DIR_LEN+1]; 94 + char dfs_dir_name[UBIFS_DFS_DIR_LEN]; 95 95 96 96 c->stats = kzalloc(sizeof(struct ubifs_stats_info), GFP_KERNEL); 97 97 if (!c->stats) { 98 98 ret = -ENOMEM; 99 99 goto out_last; 100 100 } 101 - n = snprintf(dfs_dir_name, UBIFS_DFS_DIR_LEN + 1, UBIFS_DFS_DIR_NAME, 101 + n = snprintf(dfs_dir_name, UBIFS_DFS_DIR_LEN, UBIFS_DFS_DIR_NAME, 102 102 c->vi.ubi_num, c->vi.vol_id); 103 103 104 - if (n > UBIFS_DFS_DIR_LEN) { 104 + if (n >= UBIFS_DFS_DIR_LEN) { 105 105 /* The array size is too small */ 106 106 ret = -EINVAL; 107 107 goto out_free;
+2 -12
fs/ubifs/ubifs.h
··· 158 158 #endif 159 159 160 160 /* 161 - * The UBIFS sysfs directory name pattern and maximum name length (3 for "ubi" 162 - * + 1 for "_" and plus 2x2 for 2 UBI numbers and 1 for the trailing zero byte. 163 - */ 164 - #define UBIFS_DFS_DIR_NAME "ubi%d_%d" 165 - #define UBIFS_DFS_DIR_LEN (3 + 1 + 2*2 + 1) 166 - 167 - /* 168 161 * Lockdep classes for UBIFS inode @ui_mutex. 169 162 */ 170 163 enum { ··· 916 923 * @rb: rb-tree node of rb-tree of orphans sorted by inode number 917 924 * @list: list head of list of orphans in order added 918 925 * @new_list: list head of list of orphans added since the last commit 919 - * @child_list: list of xattr children if this orphan hosts xattrs, list head 920 - * if this orphan is a xattr, not used otherwise. 921 926 * @cnext: next orphan to commit 922 927 * @dnext: next orphan to delete 923 928 * @inum: inode number ··· 927 936 struct rb_node rb; 928 937 struct list_head list; 929 938 struct list_head new_list; 930 - struct list_head child_list; 931 939 struct ubifs_orphan *cnext; 932 940 struct ubifs_orphan *dnext; 933 941 ino_t inum; ··· 1793 1803 /* journal.c */ 1794 1804 int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir, 1795 1805 const struct fscrypt_name *nm, const struct inode *inode, 1796 - int deletion, int xent); 1806 + int deletion, int xent, int in_orphan); 1797 1807 int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode, 1798 1808 const union ubifs_key *key, const void *buf, int len); 1799 1809 int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode); ··· 1810 1820 const struct inode *new_dir, 1811 1821 const struct inode *new_inode, 1812 1822 const struct fscrypt_name *new_nm, 1813 - const struct inode *whiteout, int sync); 1823 + const struct inode *whiteout, int sync, int delete_orphan); 1814 1824 int ubifs_jnl_truncate(struct ubifs_info *c, const struct inode *inode, 1815 1825 loff_t old_size, loff_t new_size); 1816 1826 int ubifs_jnl_delete_xattr(struct ubifs_info *c, const struct inode *host,
+1 -1
fs/ubifs/xattr.c
··· 149 149 if (strcmp(fname_name(nm), UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT) == 0) 150 150 host_ui->flags |= UBIFS_CRYPT_FL; 151 151 152 - err = ubifs_jnl_update(c, host, nm, inode, 0, 1); 152 + err = ubifs_jnl_update(c, host, nm, inode, 0, 1, 0); 153 153 if (err) 154 154 goto out_cancel; 155 155 ubifs_set_inode_flags(host);