exfat: aggregate dir-entry updates into __exfat_write_inode().
Subsystems (2)
PATCH 2/2 exfat: aggregate dir-entry updates into __exfat_write_inode().
The following function writes the updated inode information as dir-entry by themselves.
- __exfat_truncate()
- exfat_map_cluster()
- exfat_find_empty_entry()
Aggregate these writes into __exfat_write_inode().
Also, in __exfat_write_inode(), rename 'on_disk_size' to 'filesize' and add adjustment when filesize is 0.
--- fs/exfat/file.c | 49 +++++------------------------------------------- fs/exfat/inode.c | 42 +++++++++++------------------------------ fs/exfat/namei.c | 26 +++++-------------------- 3 files changed, 21 insertions(+), 96 deletions(-)
fs/exfat/file.c +5 -44
@@ -100,7 +100,7 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)struct super_block *sb = inode->i_sb;struct exfat_sb_info *sbi =EXFAT_SB (sb);struct exfat_inode_info *ei =EXFAT_I (inode); -int evict = (ei->dir.dir ==DIR_DELETED ) ?1 :0 ; +int ret;/* check if the given file ID is opened */ if (ei->type !=TYPE_FILE && ei->type !=TYPE_DIR )
@@ -150,49 +150,10 @@ int __exfat_truncate(struct inode *inode, loff_t new_size) ei->attr |=ATTR_ARCHIVE ;/* update the directory entry */ -if (!evict) { -struct timespec64 ts; -struct exfat_dentry *ep, *ep2; -struct exfat_entry_set_cache *es; -int err; - - es =exfat_get_dentry_set (sb, &(ei->dir), ei->entry, -ES_ALL_ENTRIES ); -if (!es) -return -EIO ; - ep =exfat_get_dentry_cached (es,0 ); - ep2 =exfat_get_dentry_cached (es,1 ); - - ts =current_time (inode); -exfat_set_entry_time (sbi, &ts, - &ep->dentry.file.modify_tz, - &ep->dentry.file.modify_time, - &ep->dentry.file.modify_date, - &ep->dentry.file.modify_time_cs); - ep->dentry.file.attr =cpu_to_le16 (ei->attr); - -/* File size should be zero if there is no cluster allocated */ -if (ei->start_clu ==EXFAT_EOF_CLUSTER ) { - ep2->dentry.stream.valid_size =0 ; - ep2->dentry.stream.size =0 ; - }else { - ep2->dentry.stream.valid_size =cpu_to_le64 (new_size); - ep2->dentry.stream.size = ep2->dentry.stream.valid_size; - } - -if (new_size ==0 ) { -/* Any directory can not be truncated to zero */ -WARN_ON (ei->type !=TYPE_FILE ); - - ep2->dentry.stream.flags =ALLOC_FAT_CHAIN ; - ep2->dentry.stream.start_clu =EXFAT_FREE_CLUSTER ; - } - -exfat_update_dir_chksum_with_entry_set (es); - err =exfat_free_dentry_set (es,inode_needs_sync (inode)); -if (err) -return err; - } + inode->i_mtime =current_time (inode); + ret =exfat_update_inode (inode); +if (ret) +return ret;/* cut off from the FAT chain */ if (ei->flags == ALLOC_FAT_CHAIN && last_clu != EXFAT_FREE_CLUSTER &&
fs/exfat/inode.c +11 -31
63 lines not on this page · raw message
fs/exfat/namei.c +5 -21
@@ -306,10 +306,8 @@ static int exfat_find_empty_entry(struct inode *inode, {int dentry;unsigned int ret, last_clu; -sector_t sector;loff_t size =0 ;struct exfat_chain clu; -struct exfat_dentry *ep =NULL ;struct super_block *sb = inode->i_sb;struct exfat_sb_info *sbi =EXFAT_SB (sb);struct exfat_inode_info *ei =EXFAT_I (inode);
@@ -375,31 +373,17 @@ static int exfat_find_empty_entry(struct inode *inode, p_dir->size++; size =EXFAT_CLU_TO_B (p_dir->size, sbi); -/* update the directory entry */ -if (p_dir->dir != sbi->root_dir) { -struct buffer_head *bh; - - ep =exfat_get_dentry (sb, - &(ei->dir), ei->entry +1 , &bh, §or); -if (!ep) -return -EIO ; - - ep->dentry.stream.valid_size =cpu_to_le64 (size); - ep->dentry.stream.size = ep->dentry.stream.valid_size; - ep->dentry.stream.flags = p_dir->flags; -exfat_update_bh (bh,IS_DIRSYNC (inode)); -brelse (bh); -if (exfat_update_dir_chksum (inode, &(ei->dir), - ei->entry)) -return -EIO ; - } -/* directory inode should be updated in here */ i_size_write (inode, size);EXFAT_I (inode)->i_size_ondisk += sbi->cluster_size;EXFAT_I (inode)->i_size_aligned += sbi->cluster_size;EXFAT_I (inode)->flags = p_dir->flags; inode->i_blocks +=1 << sbi->sect_per_clus_bits; + +/* update the directory entry */ + ret =exfat_update_inode (inode); +if (ret) +return ret; }return dentry;
Signature · 1 line
2.25.1
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Tetsuhiro,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.9-rc5 next-20200917]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Tetsuhiro-Kohada/exfat-add-exfat_update_inode/20200918-103524 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 10b82d5176488acee2820e5a2cf0f2ec5c3488b6 config: x86_64-randconfig-s022-20200917 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.2-201-g24bdaac6-dirty # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
sparse warnings: (new ones prefixed by >>)
>> fs/exfat/inode.c:78:38: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] start_clu @@ got unsigned int @@ >> fs/exfat/inode.c:78:38: sparse: expected restricted __le32 [usertype] start_clu >> fs/exfat/inode.c:78:38: sparse: got unsigned int
# https://github.com/0day-ci/linux/commit/605a79d44870ed9f396b6d5289fd1cecea3af8e3
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Tetsuhiro-Kohada/exfat-add-exfat_update_inode/20200918-103524 git checkout 605a79d44870ed9f396b6d5289fd1cecea3af8e3
vim +78 fs/exfat/inode.c
19
20 static int __exfat_write_inode(struct inode *inode, int sync)
21 {
22 unsigned long long filesize;
23 struct exfat_dentry *ep, *ep2;
24 struct exfat_entry_set_cache *es = NULL;
25 struct super_block *sb = inode->i_sb;
26 struct exfat_sb_info *sbi = EXFAT_SB(sb);
27 struct exfat_inode_info *ei = EXFAT_I(inode);
28 bool is_dir = (ei->type == TYPE_DIR) ? true : false;
29
30 if (inode->i_ino == EXFAT_ROOT_INO)
31 return 0;
32
33 /*
34 * If the indode is already unlinked, there is no need for updating it.
35 */
36 if (ei->dir.dir == DIR_DELETED)
37 return 0;
38
39 if (is_dir && ei->dir.dir == sbi->root_dir && ei->entry == -1)
40 return 0;
41
42 exfat_set_volume_dirty(sb);
43
44 /* get the directory entry of given file or directory */
45 es = exfat_get_dentry_set(sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES);
46 if (!es)
47 return -EIO;
48 ep = exfat_get_dentry_cached(es, 0);
49 ep2 = exfat_get_dentry_cached(es, 1);
50
51 ep->dentry.file.attr = cpu_to_le16(exfat_make_attr(inode));
52
53 /* set FILE_INFO structure using the acquired struct exfat_dentry */
54 exfat_set_entry_time(sbi, &ei->i_crtime,
55 &ep->dentry.file.create_tz,
56 &ep->dentry.file.create_time,
57 &ep->dentry.file.create_date,
58 &ep->dentry.file.create_time_cs);
59 exfat_set_entry_time(sbi, &inode->i_mtime,
60 &ep->dentry.file.modify_tz,
61 &ep->dentry.file.modify_time,
62 &ep->dentry.file.modify_date,
63 &ep->dentry.file.modify_time_cs);
64 exfat_set_entry_time(sbi, &inode->i_atime,
65 &ep->dentry.file.access_tz,
66 &ep->dentry.file.access_time,
67 &ep->dentry.file.access_date,
68 NULL);
69
70 /* File size should be zero if there is no cluster allocated */
71 filesize = i_size_read(inode);
72 if (ei->start_clu == EXFAT_EOF_CLUSTER)
73 filesize = 0;
74
75 ep2->dentry.stream.valid_size = cpu_to_le64(filesize);
76 ep2->dentry.stream.size = ep2->dentry.stream.valid_size;
77 ep2->dentry.stream.flags = filesize ? ei->flags : ALLOC_FAT_CHAIN;
> 78 ep2->dentry.stream.start_clu = filesize ? ei->start_clu : EXFAT_FREE_CLUSTER;
79
80 exfat_update_dir_chksum_with_entry_set(es);
81 return exfat_free_dentry_set(es, sync);
82 }
83 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org