From: Christoph Hellwig <hch@lst.de>
To: Namjae Jeon <namjae.jeon@samsung.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
gregkh@linuxfoundation.org, valdis.kletnieks@vt.edu, hch@lst.de,
sj1557.seo@samsung.com, linkinjeon@gmail.com,
pali.rohar@gmail.com
Subject: Re: [PATCH v9 03/13] exfat: add inode operations
Date: Wed, 8 Jan 2020 18:50:44 +0100 [thread overview]
Message-ID: <20200108175044.GA14009@lst.de> (raw)
In-Reply-To: <20200102082036.29643-4-namjae.jeon@samsung.com>
On Thu, Jan 02, 2020 at 04:20:26PM +0800, Namjae Jeon wrote:
> +#include "exfat_fs.h"
> +
> +/* 2-level option flag */
> +enum {
> + BMAP_NOT_CREATE,
> + BMAP_ADD_CLUSTER,
> +};
I looked at how this flag is used and found the get_block code a little
confusing. Let me know what you think of the following untested patch to
streamline that area:
diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c
index c2b04537cb24..ccf9700c6a55 100644
--- a/fs/exfat/inode.c
+++ b/fs/exfat/inode.c
@@ -17,12 +17,6 @@
#include "exfat_raw.h"
#include "exfat_fs.h"
-/* 2-level option flag */
-enum {
- BMAP_NOT_CREATE,
- BMAP_ADD_CLUSTER,
-};
-
static int __exfat_write_inode(struct inode *inode, int sync)
{
int ret = -EIO;
@@ -298,109 +292,91 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
return 0;
}
-static int exfat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
- unsigned long *mapped_blocks, int *create)
+static int exfat_map_new_buffer(struct exfat_inode_info *ei,
+ struct buffer_head *bh, loff_t pos)
{
- struct super_block *sb = inode->i_sb;
- struct exfat_sb_info *sbi = EXFAT_SB(sb);
- sector_t last_block;
- unsigned int cluster, clu_offset, sec_offset;
- int err = 0;
-
- *phys = 0;
- *mapped_blocks = 0;
-
- last_block = EXFAT_B_TO_BLK_ROUND_UP(i_size_read(inode), sb);
- if (sector >= last_block && *create == BMAP_NOT_CREATE)
- return 0;
-
- /* Is this block already allocated? */
- clu_offset = sector >> sbi->sect_per_clus_bits; /* cluster offset */
-
- err = exfat_map_cluster(inode, clu_offset, &cluster,
- *create & BMAP_ADD_CLUSTER);
- if (err) {
- if (err != -ENOSPC)
- return -EIO;
- return err;
- }
-
- if (cluster != EXFAT_EOF_CLUSTER) {
- /* sector offset in cluster */
- sec_offset = sector & (sbi->sect_per_clus - 1);
-
- *phys = exfat_cluster_to_sector(sbi, cluster) + sec_offset;
- *mapped_blocks = sbi->sect_per_clus - sec_offset;
- }
+ if (buffer_delay(bh) && pos > ei->i_size_aligned)
+ return -EIO;
+ set_buffer_new(bh);
- if (sector < last_block)
- *create = BMAP_NOT_CREATE;
+ /*
+ * Adjust i_size_aligned if i_size_ondisk is bigger than it.
+ * (i.e. non-DA)
+ */
+ if (ei->i_size_ondisk > ei->i_size_aligned)
+ ei->i_size_aligned = ei->i_size_ondisk;
return 0;
}
static int exfat_get_block(struct inode *inode, sector_t iblock,
struct buffer_head *bh_result, int create)
{
+ struct exfat_inode_info *ei = EXFAT_I(inode);
struct super_block *sb = inode->i_sb;
+ struct exfat_sb_info *sbi = EXFAT_SB(sb);
unsigned long max_blocks = bh_result->b_size >> inode->i_blkbits;
int err = 0;
- unsigned long mapped_blocks;
- sector_t phys;
+ unsigned long mapped_blocks = 0;
+ unsigned int cluster, sec_offset;
+ sector_t last_block;
+ sector_t phys = 0;
loff_t pos;
- int bmap_create = create ? BMAP_ADD_CLUSTER : BMAP_NOT_CREATE;
+
+ mutex_lock(&sbi->s_lock);
+ last_block = EXFAT_B_TO_BLK_ROUND_UP(i_size_read(inode), sb);
+ if (iblock >= last_block && !create)
+ goto done;
- mutex_lock(&EXFAT_SB(sb)->s_lock);
- err = exfat_bmap(inode, iblock, &phys, &mapped_blocks, &bmap_create);
+ /* Is this block already allocated? */
+ err = exfat_map_cluster(inode, iblock >> sbi->sect_per_clus_bits,
+ &cluster, create);
if (err) {
- if (err != -ENOSPC)
- exfat_fs_error_ratelimit(sb,
- "failed to bmap (inode : %p iblock : %llu, err : %d)",
- inode, (unsigned long long)iblock, err);
+ if (err == -ENOSPC)
+ goto unlock_ret;
+
+ exfat_fs_error_ratelimit(sb,
+ "failed to bmap (inode : %p iblock : %llu, err : %d)",
+ inode, (unsigned long long)iblock, err);
goto unlock_ret;
}
- if (phys) {
- max_blocks = min(mapped_blocks, max_blocks);
-
- /* Treat newly added block / cluster */
- if (bmap_create || buffer_delay(bh_result)) {
- /* Update i_size_ondisk */
- pos = EXFAT_BLK_TO_B((iblock + 1), sb);
- if (EXFAT_I(inode)->i_size_ondisk < pos)
- EXFAT_I(inode)->i_size_ondisk = pos;
-
- if (bmap_create) {
- if (buffer_delay(bh_result) &&
- pos > EXFAT_I(inode)->i_size_aligned) {
- exfat_fs_error(sb,
- "requested for bmap out of range(pos : (%llu) > i_size_aligned(%llu)\n",
- pos,
- EXFAT_I(inode)->i_size_aligned);
- err = -EIO;
- goto unlock_ret;
- }
- set_buffer_new(bh_result);
-
- /*
- * adjust i_size_aligned if i_size_ondisk is
- * bigger than it. (i.e. non-DA)
- */
- if (EXFAT_I(inode)->i_size_ondisk >
- EXFAT_I(inode)->i_size_aligned) {
- EXFAT_I(inode)->i_size_aligned =
- EXFAT_I(inode)->i_size_ondisk;
- }
- }
+ if (cluster == EXFAT_EOF_CLUSTER)
+ goto done;
+
+ /* sector offset in cluster */
+ sec_offset = iblock & (sbi->sect_per_clus - 1);
+
+ phys = exfat_cluster_to_sector(sbi, cluster) + sec_offset;
+ mapped_blocks = sbi->sect_per_clus - sec_offset;
+ max_blocks = min(mapped_blocks, max_blocks);
- if (buffer_delay(bh_result))
- clear_buffer_delay(bh_result);
+ /* Treat newly added block / cluster */
+ if (iblock < last_block)
+ create = 0;
+
+ if (create || buffer_delay(bh_result)) {
+ pos = EXFAT_BLK_TO_B((iblock + 1), sb);
+ if (ei->i_size_ondisk < pos)
+ ei->i_size_ondisk = pos;
+ }
+
+ if (create) {
+ err = exfat_map_new_buffer(ei, bh_result, pos);
+ if (err) {
+ exfat_fs_error(sb,
+ "requested for bmap out of range(pos : (%llu) > i_size_aligned(%llu)\n",
+ pos, ei->i_size_aligned);
+ goto unlock_ret;
}
- map_bh(bh_result, sb, phys);
}
+ if (buffer_delay(bh_result))
+ clear_buffer_delay(bh_result);
+ map_bh(bh_result, sb, phys);
+done:
bh_result->b_size = EXFAT_BLK_TO_B(max_blocks, sb);
unlock_ret:
- mutex_unlock(&EXFAT_SB(sb)->s_lock);
+ mutex_unlock(&sbi->s_lock);
return err;
}
next prev parent reply other threads:[~2020-01-08 17:50 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20200102082359epcas1p2aa1eca9729a6ec54ec3b8140615dca6e@epcas1p2.samsung.com>
2020-01-02 8:20 ` [PATCH v9 00/13] add the latest exfat driver Namjae Jeon
2020-01-02 8:20 ` [PATCH v9 01/13] exfat: add in-memory and on-disk structures and headers Namjae Jeon
2020-01-08 17:08 ` Christoph Hellwig
2020-01-09 22:43 ` Namjae Jeon
2020-01-02 8:20 ` [PATCH v9 02/13] exfat: add super block operations Namjae Jeon
2020-01-08 17:21 ` Christoph Hellwig
2020-01-09 23:21 ` Namjae Jeon
2020-01-02 8:20 ` [PATCH v9 03/13] exfat: add inode operations Namjae Jeon
2020-01-08 17:50 ` Christoph Hellwig [this message]
2020-01-09 23:23 ` Namjae Jeon
2020-01-02 8:20 ` [PATCH v9 04/13] exfat: add directory operations Namjae Jeon
2020-01-08 17:52 ` Christoph Hellwig
2020-01-02 8:20 ` [PATCH v9 05/13] exfat: add file operations Namjae Jeon
2020-01-08 17:56 ` Christoph Hellwig
2020-01-02 8:20 ` [PATCH v9 06/13] exfat: add exfat entry operations Namjae Jeon
2020-01-08 18:00 ` Christoph Hellwig
2020-01-09 23:24 ` Namjae Jeon
2020-01-02 8:20 ` [PATCH v9 07/13] exfat: add bitmap operations Namjae Jeon
2020-01-08 18:01 ` Christoph Hellwig
2020-01-02 8:20 ` [PATCH v9 08/13] exfat: add exfat cache Namjae Jeon
2020-01-08 18:02 ` Christoph Hellwig
2020-01-02 8:20 ` [PATCH v9 09/13] exfat: add misc operations Namjae Jeon
2020-01-02 9:19 ` Pali Rohár
2020-01-02 11:30 ` Namjae Jeon
2020-01-02 11:40 ` Pali Rohár
2020-01-03 18:36 ` Pali Rohár
2020-01-03 23:28 ` Namjae Jeon
2020-01-08 18:03 ` Christoph Hellwig
2020-01-08 19:40 ` Arnd Bergmann
2020-01-09 23:32 ` Namjae Jeon
2020-01-02 8:20 ` [PATCH v9 10/13] exfat: add nls operations Namjae Jeon
2020-01-02 13:55 ` Pali Rohár
2020-01-03 7:06 ` Namjae Jeon
2020-01-03 8:44 ` Pali Rohár
2020-01-02 14:20 ` Pali Rohár
2020-01-03 4:44 ` Namjae Jeon
2020-01-03 9:40 ` Pali Rohár
2020-01-03 12:31 ` Pali Rohár
2020-01-09 22:35 ` Namjae Jeon
2020-01-05 15:24 ` Pali Rohár
2020-01-05 16:51 ` Pali Rohár
2020-01-06 19:46 ` Gabriel Krisman Bertazi
2020-01-07 11:52 ` Pali Rohár
2020-01-09 22:04 ` [PATCH v9 09/13] exfat: add misc operations Valdis Klētnieks
2020-01-09 23:41 ` Namjae Jeon
2020-01-09 22:37 ` [PATCH v9 10/13] exfat: add nls operations Namjae Jeon
2020-01-02 8:20 ` [PATCH v9 11/13] exfat: add Kconfig and Makefile Namjae Jeon
2020-01-02 12:53 ` Pali Rohár
2020-01-02 8:20 ` [PATCH v9 12/13] exfat: add exfat in fs/Kconfig and fs/Makefile Namjae Jeon
2020-01-02 12:58 ` Pali Rohár
2020-01-02 13:07 ` Namjae Jeon
2020-01-02 13:10 ` Pali Rohár
2020-01-02 14:19 ` Greg KH
2020-01-02 23:48 ` Namjae Jeon
2020-01-04 5:22 ` kbuild test robot
2020-01-02 8:20 ` [PATCH v9 13/13] MAINTAINERS: add exfat filesystem Namjae Jeon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200108175044.GA14009@lst.de \
--to=hch@lst.de \
--cc=gregkh@linuxfoundation.org \
--cc=linkinjeon@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=namjae.jeon@samsung.com \
--cc=pali.rohar@gmail.com \
--cc=sj1557.seo@samsung.com \
--cc=valdis.kletnieks@vt.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox