| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * This file is part of UBIFS. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2006-2008 Nokia Corporation. |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 7 | | - * under the terms of the GNU General Public License version 2 as published by |
|---|
| 8 | | - * the Free Software Foundation. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 11 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 12 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 13 | | - * more details. |
|---|
| 14 | | - * |
|---|
| 15 | | - * You should have received a copy of the GNU General Public License along with |
|---|
| 16 | | - * this program; if not, write to the Free Software Foundation, Inc., 51 |
|---|
| 17 | | - * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 18 | 6 | * |
|---|
| 19 | 7 | * Authors: Artem Bityutskiy (Битюцкий Артём) |
|---|
| 20 | 8 | * Adrian Hunter |
|---|
| .. | .. |
|---|
| 79 | 67 | |
|---|
| 80 | 68 | dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ; |
|---|
| 81 | 69 | |
|---|
| 82 | | - if (ubifs_crypt_is_encrypted(inode)) { |
|---|
| 70 | + if (IS_ENCRYPTED(inode)) { |
|---|
| 83 | 71 | err = ubifs_decrypt(inode, dn, &dlen, block); |
|---|
| 84 | 72 | if (err) |
|---|
| 85 | 73 | goto dump; |
|---|
| .. | .. |
|---|
| 234 | 222 | struct ubifs_info *c = inode->i_sb->s_fs_info; |
|---|
| 235 | 223 | pgoff_t index = pos >> PAGE_SHIFT; |
|---|
| 236 | 224 | struct ubifs_budget_req req = { .new_page = 1 }; |
|---|
| 237 | | - int uninitialized_var(err), appending = !!(pos + len > inode->i_size); |
|---|
| 225 | + int err, appending = !!(pos + len > inode->i_size); |
|---|
| 238 | 226 | struct page *page; |
|---|
| 239 | 227 | |
|---|
| 240 | 228 | dbg_gen("ino %lu, pos %llu, len %u, i_size %lld", |
|---|
| .. | .. |
|---|
| 438 | 426 | struct ubifs_info *c = inode->i_sb->s_fs_info; |
|---|
| 439 | 427 | struct ubifs_inode *ui = ubifs_inode(inode); |
|---|
| 440 | 428 | pgoff_t index = pos >> PAGE_SHIFT; |
|---|
| 441 | | - int uninitialized_var(err), appending = !!(pos + len > inode->i_size); |
|---|
| 429 | + int err, appending = !!(pos + len > inode->i_size); |
|---|
| 442 | 430 | int skipped_read = 0; |
|---|
| 443 | 431 | struct page *page; |
|---|
| 444 | 432 | |
|---|
| .. | .. |
|---|
| 582 | 570 | } |
|---|
| 583 | 571 | |
|---|
| 584 | 572 | if (!PagePrivate(page)) { |
|---|
| 585 | | - SetPagePrivate(page); |
|---|
| 573 | + attach_page_private(page, (void *)1); |
|---|
| 586 | 574 | atomic_long_inc(&c->dirty_pg_cnt); |
|---|
| 587 | 575 | __set_page_dirty_nobuffers(page); |
|---|
| 588 | 576 | } |
|---|
| .. | .. |
|---|
| 659 | 647 | dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ; |
|---|
| 660 | 648 | out_len = UBIFS_BLOCK_SIZE; |
|---|
| 661 | 649 | |
|---|
| 662 | | - if (ubifs_crypt_is_encrypted(inode)) { |
|---|
| 650 | + if (IS_ENCRYPTED(inode)) { |
|---|
| 663 | 651 | err = ubifs_decrypt(inode, dn, &dlen, page_block); |
|---|
| 664 | 652 | if (err) |
|---|
| 665 | 653 | goto out_err; |
|---|
| .. | .. |
|---|
| 959 | 947 | release_existing_page_budget(c); |
|---|
| 960 | 948 | |
|---|
| 961 | 949 | atomic_long_dec(&c->dirty_pg_cnt); |
|---|
| 962 | | - ClearPagePrivate(page); |
|---|
| 950 | + detach_page_private(page); |
|---|
| 963 | 951 | ClearPageChecked(page); |
|---|
| 964 | 952 | |
|---|
| 965 | 953 | kunmap(page); |
|---|
| .. | .. |
|---|
| 1043 | 1031 | if (page->index >= synced_i_size >> PAGE_SHIFT) { |
|---|
| 1044 | 1032 | err = inode->i_sb->s_op->write_inode(inode, NULL); |
|---|
| 1045 | 1033 | if (err) |
|---|
| 1046 | | - goto out_unlock; |
|---|
| 1034 | + goto out_redirty; |
|---|
| 1047 | 1035 | /* |
|---|
| 1048 | 1036 | * The inode has been written, but the write-buffer has |
|---|
| 1049 | 1037 | * not been synchronized, so in case of an unclean |
|---|
| .. | .. |
|---|
| 1071 | 1059 | if (i_size > synced_i_size) { |
|---|
| 1072 | 1060 | err = inode->i_sb->s_op->write_inode(inode, NULL); |
|---|
| 1073 | 1061 | if (err) |
|---|
| 1074 | | - goto out_unlock; |
|---|
| 1062 | + goto out_redirty; |
|---|
| 1075 | 1063 | } |
|---|
| 1076 | 1064 | |
|---|
| 1077 | 1065 | return do_writepage(page, len); |
|---|
| 1078 | | - |
|---|
| 1066 | +out_redirty: |
|---|
| 1067 | + /* |
|---|
| 1068 | + * redirty_page_for_writepage() won't call ubifs_dirty_inode() because |
|---|
| 1069 | + * it passes I_DIRTY_PAGES flag while calling __mark_inode_dirty(), so |
|---|
| 1070 | + * there is no need to do space budget for dirty inode. |
|---|
| 1071 | + */ |
|---|
| 1072 | + redirty_page_for_writepage(wbc, page); |
|---|
| 1079 | 1073 | out_unlock: |
|---|
| 1080 | 1074 | unlock_page(page); |
|---|
| 1081 | 1075 | return err; |
|---|
| .. | .. |
|---|
| 1093 | 1087 | if (attr->ia_valid & ATTR_GID) |
|---|
| 1094 | 1088 | inode->i_gid = attr->ia_gid; |
|---|
| 1095 | 1089 | if (attr->ia_valid & ATTR_ATIME) |
|---|
| 1096 | | - inode->i_atime = timespec64_trunc(attr->ia_atime, |
|---|
| 1097 | | - inode->i_sb->s_time_gran); |
|---|
| 1090 | + inode->i_atime = attr->ia_atime; |
|---|
| 1098 | 1091 | if (attr->ia_valid & ATTR_MTIME) |
|---|
| 1099 | | - inode->i_mtime = timespec64_trunc(attr->ia_mtime, |
|---|
| 1100 | | - inode->i_sb->s_time_gran); |
|---|
| 1092 | + inode->i_mtime = attr->ia_mtime; |
|---|
| 1101 | 1093 | if (attr->ia_valid & ATTR_CTIME) |
|---|
| 1102 | | - inode->i_ctime = timespec64_trunc(attr->ia_ctime, |
|---|
| 1103 | | - inode->i_sb->s_time_gran); |
|---|
| 1094 | + inode->i_ctime = attr->ia_ctime; |
|---|
| 1104 | 1095 | if (attr->ia_valid & ATTR_MODE) { |
|---|
| 1105 | 1096 | umode_t mode = attr->ia_mode; |
|---|
| 1106 | 1097 | |
|---|
| .. | .. |
|---|
| 1318 | 1309 | release_existing_page_budget(c); |
|---|
| 1319 | 1310 | |
|---|
| 1320 | 1311 | atomic_long_dec(&c->dirty_pg_cnt); |
|---|
| 1321 | | - ClearPagePrivate(page); |
|---|
| 1312 | + detach_page_private(page); |
|---|
| 1322 | 1313 | ClearPageChecked(page); |
|---|
| 1323 | 1314 | } |
|---|
| 1324 | 1315 | |
|---|
| .. | .. |
|---|
| 1377 | 1368 | return 0; |
|---|
| 1378 | 1369 | } |
|---|
| 1379 | 1370 | |
|---|
| 1380 | | -#ifdef CONFIG_UBIFS_ATIME_SUPPORT |
|---|
| 1381 | 1371 | /** |
|---|
| 1382 | 1372 | * ubifs_update_time - update time of inode. |
|---|
| 1383 | 1373 | * @inode: inode to update |
|---|
| .. | .. |
|---|
| 1392 | 1382 | struct ubifs_budget_req req = { .dirtied_ino = 1, |
|---|
| 1393 | 1383 | .dirtied_ino_d = ALIGN(ui->data_len, 8) }; |
|---|
| 1394 | 1384 | int err, release; |
|---|
| 1385 | + |
|---|
| 1386 | + if (!IS_ENABLED(CONFIG_UBIFS_ATIME_SUPPORT)) |
|---|
| 1387 | + return generic_update_time(inode, time, flags); |
|---|
| 1395 | 1388 | |
|---|
| 1396 | 1389 | err = ubifs_budget_space(c, &req); |
|---|
| 1397 | 1390 | if (err) |
|---|
| .. | .. |
|---|
| 1412 | 1405 | ubifs_release_budget(c, &req); |
|---|
| 1413 | 1406 | return 0; |
|---|
| 1414 | 1407 | } |
|---|
| 1415 | | -#endif |
|---|
| 1416 | 1408 | |
|---|
| 1417 | 1409 | /** |
|---|
| 1418 | 1410 | * update_mctime - update mtime and ctime of an inode. |
|---|
| .. | .. |
|---|
| 1479 | 1471 | { |
|---|
| 1480 | 1472 | int rc; |
|---|
| 1481 | 1473 | |
|---|
| 1482 | | - rc = migrate_page_move_mapping(mapping, newpage, page, NULL, mode, 0); |
|---|
| 1474 | + rc = migrate_page_move_mapping(mapping, newpage, page, 0); |
|---|
| 1483 | 1475 | if (rc != MIGRATEPAGE_SUCCESS) |
|---|
| 1484 | 1476 | return rc; |
|---|
| 1485 | 1477 | |
|---|
| 1486 | 1478 | if (PagePrivate(page)) { |
|---|
| 1487 | | - ClearPagePrivate(page); |
|---|
| 1488 | | - SetPagePrivate(newpage); |
|---|
| 1479 | + detach_page_private(page); |
|---|
| 1480 | + attach_page_private(newpage, (void *)1); |
|---|
| 1489 | 1481 | } |
|---|
| 1490 | 1482 | |
|---|
| 1491 | 1483 | if (mode != MIGRATE_SYNC_NO_COPY) |
|---|
| .. | .. |
|---|
| 1509 | 1501 | return 0; |
|---|
| 1510 | 1502 | ubifs_assert(c, PagePrivate(page)); |
|---|
| 1511 | 1503 | ubifs_assert(c, 0); |
|---|
| 1512 | | - ClearPagePrivate(page); |
|---|
| 1504 | + detach_page_private(page); |
|---|
| 1513 | 1505 | ClearPageChecked(page); |
|---|
| 1514 | 1506 | return 1; |
|---|
| 1515 | 1507 | } |
|---|
| .. | .. |
|---|
| 1580 | 1572 | else { |
|---|
| 1581 | 1573 | if (!PageChecked(page)) |
|---|
| 1582 | 1574 | ubifs_convert_page_budget(c); |
|---|
| 1583 | | - SetPagePrivate(page); |
|---|
| 1575 | + attach_page_private(page, (void *)1); |
|---|
| 1584 | 1576 | atomic_long_inc(&c->dirty_pg_cnt); |
|---|
| 1585 | 1577 | __set_page_dirty_nobuffers(page); |
|---|
| 1586 | 1578 | } |
|---|
| .. | .. |
|---|
| 1621 | 1613 | if (err) |
|---|
| 1622 | 1614 | return err; |
|---|
| 1623 | 1615 | vma->vm_ops = &ubifs_file_vm_ops; |
|---|
| 1624 | | -#ifdef CONFIG_UBIFS_ATIME_SUPPORT |
|---|
| 1625 | | - file_accessed(file); |
|---|
| 1626 | | -#endif |
|---|
| 1616 | + |
|---|
| 1617 | + if (IS_ENABLED(CONFIG_UBIFS_ATIME_SUPPORT)) |
|---|
| 1618 | + file_accessed(file); |
|---|
| 1619 | + |
|---|
| 1627 | 1620 | return 0; |
|---|
| 1628 | 1621 | } |
|---|
| 1629 | 1622 | |
|---|
| .. | .. |
|---|
| 1671 | 1664 | #ifdef CONFIG_UBIFS_FS_XATTR |
|---|
| 1672 | 1665 | .listxattr = ubifs_listxattr, |
|---|
| 1673 | 1666 | #endif |
|---|
| 1674 | | -#ifdef CONFIG_UBIFS_ATIME_SUPPORT |
|---|
| 1675 | 1667 | .update_time = ubifs_update_time, |
|---|
| 1676 | | -#endif |
|---|
| 1677 | 1668 | }; |
|---|
| 1678 | 1669 | |
|---|
| 1679 | 1670 | const struct inode_operations ubifs_symlink_inode_operations = { |
|---|
| .. | .. |
|---|
| 1683 | 1674 | #ifdef CONFIG_UBIFS_FS_XATTR |
|---|
| 1684 | 1675 | .listxattr = ubifs_listxattr, |
|---|
| 1685 | 1676 | #endif |
|---|
| 1686 | | -#ifdef CONFIG_UBIFS_ATIME_SUPPORT |
|---|
| 1687 | 1677 | .update_time = ubifs_update_time, |
|---|
| 1688 | | -#endif |
|---|
| 1689 | 1678 | }; |
|---|
| 1690 | 1679 | |
|---|
| 1691 | 1680 | const struct file_operations ubifs_file_operations = { |
|---|