hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/ubifs/file.c
....@@ -1,20 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * This file is part of UBIFS.
34 *
45 * 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
186 *
197 * Authors: Artem Bityutskiy (Битюцкий Артём)
208 * Adrian Hunter
....@@ -79,7 +67,7 @@
7967
8068 dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
8169
82
- if (ubifs_crypt_is_encrypted(inode)) {
70
+ if (IS_ENCRYPTED(inode)) {
8371 err = ubifs_decrypt(inode, dn, &dlen, block);
8472 if (err)
8573 goto dump;
....@@ -234,7 +222,7 @@
234222 struct ubifs_info *c = inode->i_sb->s_fs_info;
235223 pgoff_t index = pos >> PAGE_SHIFT;
236224 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);
238226 struct page *page;
239227
240228 dbg_gen("ino %lu, pos %llu, len %u, i_size %lld",
....@@ -438,7 +426,7 @@
438426 struct ubifs_info *c = inode->i_sb->s_fs_info;
439427 struct ubifs_inode *ui = ubifs_inode(inode);
440428 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);
442430 int skipped_read = 0;
443431 struct page *page;
444432
....@@ -582,7 +570,7 @@
582570 }
583571
584572 if (!PagePrivate(page)) {
585
- SetPagePrivate(page);
573
+ attach_page_private(page, (void *)1);
586574 atomic_long_inc(&c->dirty_pg_cnt);
587575 __set_page_dirty_nobuffers(page);
588576 }
....@@ -659,7 +647,7 @@
659647 dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
660648 out_len = UBIFS_BLOCK_SIZE;
661649
662
- if (ubifs_crypt_is_encrypted(inode)) {
650
+ if (IS_ENCRYPTED(inode)) {
663651 err = ubifs_decrypt(inode, dn, &dlen, page_block);
664652 if (err)
665653 goto out_err;
....@@ -959,7 +947,7 @@
959947 release_existing_page_budget(c);
960948
961949 atomic_long_dec(&c->dirty_pg_cnt);
962
- ClearPagePrivate(page);
950
+ detach_page_private(page);
963951 ClearPageChecked(page);
964952
965953 kunmap(page);
....@@ -1043,7 +1031,7 @@
10431031 if (page->index >= synced_i_size >> PAGE_SHIFT) {
10441032 err = inode->i_sb->s_op->write_inode(inode, NULL);
10451033 if (err)
1046
- goto out_unlock;
1034
+ goto out_redirty;
10471035 /*
10481036 * The inode has been written, but the write-buffer has
10491037 * not been synchronized, so in case of an unclean
....@@ -1071,11 +1059,17 @@
10711059 if (i_size > synced_i_size) {
10721060 err = inode->i_sb->s_op->write_inode(inode, NULL);
10731061 if (err)
1074
- goto out_unlock;
1062
+ goto out_redirty;
10751063 }
10761064
10771065 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);
10791073 out_unlock:
10801074 unlock_page(page);
10811075 return err;
....@@ -1093,14 +1087,11 @@
10931087 if (attr->ia_valid & ATTR_GID)
10941088 inode->i_gid = attr->ia_gid;
10951089 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;
10981091 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;
11011093 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;
11041095 if (attr->ia_valid & ATTR_MODE) {
11051096 umode_t mode = attr->ia_mode;
11061097
....@@ -1318,7 +1309,7 @@
13181309 release_existing_page_budget(c);
13191310
13201311 atomic_long_dec(&c->dirty_pg_cnt);
1321
- ClearPagePrivate(page);
1312
+ detach_page_private(page);
13221313 ClearPageChecked(page);
13231314 }
13241315
....@@ -1377,7 +1368,6 @@
13771368 return 0;
13781369 }
13791370
1380
-#ifdef CONFIG_UBIFS_ATIME_SUPPORT
13811371 /**
13821372 * ubifs_update_time - update time of inode.
13831373 * @inode: inode to update
....@@ -1392,6 +1382,9 @@
13921382 struct ubifs_budget_req req = { .dirtied_ino = 1,
13931383 .dirtied_ino_d = ALIGN(ui->data_len, 8) };
13941384 int err, release;
1385
+
1386
+ if (!IS_ENABLED(CONFIG_UBIFS_ATIME_SUPPORT))
1387
+ return generic_update_time(inode, time, flags);
13951388
13961389 err = ubifs_budget_space(c, &req);
13971390 if (err)
....@@ -1412,7 +1405,6 @@
14121405 ubifs_release_budget(c, &req);
14131406 return 0;
14141407 }
1415
-#endif
14161408
14171409 /**
14181410 * update_mctime - update mtime and ctime of an inode.
....@@ -1479,13 +1471,13 @@
14791471 {
14801472 int rc;
14811473
1482
- rc = migrate_page_move_mapping(mapping, newpage, page, NULL, mode, 0);
1474
+ rc = migrate_page_move_mapping(mapping, newpage, page, 0);
14831475 if (rc != MIGRATEPAGE_SUCCESS)
14841476 return rc;
14851477
14861478 if (PagePrivate(page)) {
1487
- ClearPagePrivate(page);
1488
- SetPagePrivate(newpage);
1479
+ detach_page_private(page);
1480
+ attach_page_private(newpage, (void *)1);
14891481 }
14901482
14911483 if (mode != MIGRATE_SYNC_NO_COPY)
....@@ -1509,7 +1501,7 @@
15091501 return 0;
15101502 ubifs_assert(c, PagePrivate(page));
15111503 ubifs_assert(c, 0);
1512
- ClearPagePrivate(page);
1504
+ detach_page_private(page);
15131505 ClearPageChecked(page);
15141506 return 1;
15151507 }
....@@ -1580,7 +1572,7 @@
15801572 else {
15811573 if (!PageChecked(page))
15821574 ubifs_convert_page_budget(c);
1583
- SetPagePrivate(page);
1575
+ attach_page_private(page, (void *)1);
15841576 atomic_long_inc(&c->dirty_pg_cnt);
15851577 __set_page_dirty_nobuffers(page);
15861578 }
....@@ -1621,9 +1613,10 @@
16211613 if (err)
16221614 return err;
16231615 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
+
16271620 return 0;
16281621 }
16291622
....@@ -1671,9 +1664,7 @@
16711664 #ifdef CONFIG_UBIFS_FS_XATTR
16721665 .listxattr = ubifs_listxattr,
16731666 #endif
1674
-#ifdef CONFIG_UBIFS_ATIME_SUPPORT
16751667 .update_time = ubifs_update_time,
1676
-#endif
16771668 };
16781669
16791670 const struct inode_operations ubifs_symlink_inode_operations = {
....@@ -1683,9 +1674,7 @@
16831674 #ifdef CONFIG_UBIFS_FS_XATTR
16841675 .listxattr = ubifs_listxattr,
16851676 #endif
1686
-#ifdef CONFIG_UBIFS_ATIME_SUPPORT
16871677 .update_time = ubifs_update_time,
1688
-#endif
16891678 };
16901679
16911680 const struct file_operations ubifs_file_operations = {