[f2fs-dev] [PATCH v3] f2fs-tools: fix to check loop device for non-root users

2024-02-29 Thread Huang Jianan via Linux-f2fs-devel
Currently mkfs/fsck gets the following error when executed by
non-root users:

Info: open /dev/loop0 failed errno:13
Error: Not available on mounted device!

Let's fix it by reading the backing file from sysfs.

Fixes: 14197d546b93 ("f2fs-tools: fix to check loop device")
Signed-off-by: Huang Jianan 
---
v3:
- Skip deleted backing file.
 lib/libf2fs.c | 40 +++-
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index d51e485..fad3fd4 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -832,7 +832,7 @@ int f2fs_dev_is_umounted(char *path)
}
} else if (S_ISREG(st_buf.st_mode)) {
/* check whether regular is backfile of loop device */
-#if defined(HAVE_LINUX_LOOP_H) && defined(HAVE_LINUX_MAJOR_H)
+#if defined(HAVE_LINUX_MAJOR_H)
struct mntent *mnt;
struct stat st_loop;
FILE *f;
@@ -840,8 +840,9 @@ int f2fs_dev_is_umounted(char *path)
f = setmntent("/proc/mounts", "r");
 
while ((mnt = getmntent(f)) != NULL) {
-   struct loop_info64 loopinfo = {0, };
-   int loop_fd, err;
+   struct stat st_back;
+   int sysfs_fd, rc;
+   char buf[PATH_MAX + 1];
 
if (mnt->mnt_fsname[0] != '/')
continue;
@@ -852,23 +853,36 @@ int f2fs_dev_is_umounted(char *path)
if (major(st_loop.st_rdev) != LOOP_MAJOR)
continue;
 
-   loop_fd = open(mnt->mnt_fsname, O_RDONLY);
-   if (loop_fd < 0) {
+   snprintf(buf, PATH_MAX,
+"/sys/dev/block/%d:%d/loop/backing_file",
+major(st_loop.st_rdev), 
minor(st_loop.st_rdev));
+
+   sysfs_fd = open(buf, O_RDONLY);
+   if (sysfs_fd < 0) {
MSG(0, "Info: open %s failed errno:%d\n",
-   mnt->mnt_fsname, errno);
+   buf, errno);
return -1;
}
 
-   err = ioctl(loop_fd, LOOP_GET_STATUS64, &loopinfo);
-   close(loop_fd);
-   if (err < 0) {
-   MSG(0, "\tError: ioctl LOOP_GET_STATUS64 failed 
errno:%d!\n",
-   errno);
+   memset(buf, 0, PATH_MAX + 1);
+   rc = read(sysfs_fd, buf, PATH_MAX);
+   if (rc < 0) {
+   MSG(0, "Info: read %s failed errno:%d\n",
+   buf, errno);
return -1;
}
 
-   if (st_buf.st_dev == loopinfo.lo_device &&
-   st_buf.st_ino == loopinfo.lo_inode) {
+   /* Remove trailing newline */
+   if (rc > 0 && *(buf + rc - 1) == '\n')
+   --rc;
+   buf[rc] = '\0';
+
+   /* Skip deleted files like "xxx (deleted)" */
+   if (stat(buf, &st_back) != 0)
+   continue;
+
+   if (st_buf.st_dev == st_back.st_dev &&
+   st_buf.st_ino == st_back.st_ino) {
MSG(0, "\tError: In use by loop device!\n");
return -EBUSY;
}
-- 
2.34.1



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH] f2fs: introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup

2024-02-29 Thread Chao Yu

On 2024/3/1 9:57, Jaegeuk Kim wrote:

On 03/01, Chao Yu wrote:

On 2024/3/1 0:35, Jaegeuk Kim wrote:

On 02/29, Chao Yu wrote:

On 2024/2/28 1:47, Jaegeuk Kim wrote:

On 02/21, Chao Yu wrote:

Just cleanup, no functional change.

Signed-off-by: Chao Yu 
---
fs/f2fs/debug.c   |  7 +++
fs/f2fs/f2fs.h| 14 --
fs/f2fs/gc.c  | 10 +-
fs/f2fs/gc.h  |  4 ++--
fs/f2fs/segment.c | 12 ++--
fs/f2fs/segment.h |  8 
fs/f2fs/super.c   | 16 
fs/f2fs/sysfs.c   |  4 ++--
8 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
index 6617195bd27e..12893477f2e4 100644
--- a/fs/f2fs/debug.c
+++ b/fs/f2fs/debug.c
@@ -134,7 +134,7 @@ static void update_general_status(struct f2fs_sb_info *sbi)
si->cur_ckpt_time = sbi->cprc_info.cur_time;
si->peak_ckpt_time = sbi->cprc_info.peak_time;
spin_unlock(&sbi->cprc_info.stat_lock);
-   si->total_count = (int)sbi->user_block_count / BLKS_PER_SEG(sbi);
+   si->total_count = BLKS_TO_SEGS(sbi, (int)sbi->user_block_count);
si->rsvd_segs = reserved_segments(sbi);
si->overp_segs = overprovision_segments(sbi);
si->valid_count = valid_user_blocks(sbi);
@@ -175,11 +175,10 @@ static void update_general_status(struct f2fs_sb_info 
*sbi)
si->alloc_nids = NM_I(sbi)->nid_cnt[PREALLOC_NID];
si->io_skip_bggc = sbi->io_skip_bggc;
si->other_skip_bggc = sbi->other_skip_bggc;
-   si->util_free = (int)(free_user_blocks(sbi) >> sbi->log_blocks_per_seg)
+   si->util_free = (int)(BLKS_TO_SEGS(sbi, free_user_blocks(sbi)))
* 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
/ 2;
-   si->util_valid = (int)(written_block_count(sbi) >>
-   sbi->log_blocks_per_seg)
+   si->util_valid = (int)(BLKS_TO_SEGS(sbi, written_block_count(sbi)))
* 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
/ 2;
si->util_invalid = 50 - si->util_free - si->util_valid;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index dad2774ca72f..8a6fd4352a0e 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1813,12 +1813,14 @@ struct f2fs_sb_info {
};
/* Definitions to access f2fs_sb_info */
-#define BLKS_PER_SEG(sbi)  \
-   ((sbi)->blocks_per_seg)
-#define BLKS_PER_SEC(sbi)  \
-   ((sbi)->segs_per_sec << (sbi)->log_blocks_per_seg)
-#define SEGS_PER_SEC(sbi)  \
-   ((sbi)->segs_per_sec)
+#define SEGS_TO_BLKS(sbi, segs)\
+   ((segs) << (sbi)->log_blocks_per_seg)



I also applied this.

/* Definitions to access f2fs_sb_info */
#define SEGS_TO_BLKS(sbi, segs)\
-   ((segs) << (sbi)->log_blocks_per_seg)
+   (((long long)segs) << (sbi)->log_blocks_per_seg)


Jaegeuk,

This may cause compile failure reported as below, can we revert this?

https://lore.kernel.org/linux-f2fs-devel/camuhmdxruiv8pee6azkylp+z_sa8cbl8849bzu59j1_xxty...@mail.gmail.com/T/#t


Yeah, it seems so. I removed it in -dev.


Oh, I meant reverting (((long long)segs) << (sbi)->log_blocks_per_seg),
this line can bring 64bits data into division statement, result in
compile failure.


Time to resend the patch to address previous casting issue as well? :)


Sure, I can resend the patch.

However, there will be no overflow issues in this calculation
((segs) << (sbi)->log_blocks_per_seg), right? because we do not
support 64-bits addressing, so the calculation result should be a
32-bits value.

Thanks,





Thanks,





Thanks,


#define BLKS_TO_SEGS(sbi, blks)\
   ((blks) >> (sbi)->log_blocks_per_seg)


+#define BLKS_TO_SEGS(sbi, blks)\
+   ((blks) >> (sbi)->log_blocks_per_seg)
+
+#define BLKS_PER_SEG(sbi)  ((sbi)->blocks_per_seg)
+#define BLKS_PER_SEC(sbi)  (SEGS_TO_BLKS(sbi, (sbi)->segs_per_sec))
+#define SEGS_PER_SEC(sbi)  ((sbi)->segs_per_sec)
__printf(3, 4)
void f2fs_printk(struct f2fs_sb_info *sbi, bool limit_rate, const char 
*fmt, ...);
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 3ff126316d42..6d160d50e14e 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -301,7 +301,7 @@ static unsigned int get_max_cost(struct f2fs_sb_info *sbi,
/* LFS */
if (p->gc_mode == GC_GREEDY)
-   return 2 * BLKS_PER_SEG(sbi) * p->ofs_unit;
+   return SEGS_TO_BLKS(sbi, 2 * p->ofs_unit);
else if (p->gc_mode == GC_CB)
return UINT_MAX;
else if (p->gc_mode == GC_AT)
@@ -347,7 +347,7 @@ static unsigned int get_cb_cost(struct f2fs_sb_info *sbi, 
unsigned int segno)
mtime = div_u64(mtime, S

Re: [f2fs-dev] [PATCH 1/4] f2fs: fix blkofs_end correctly in f2fs_migrate_blocks()

2024-02-29 Thread Jaegeuk Kim
On 03/01, Chao Yu wrote:
> On 2024/3/1 1:41, Daeho Jeong wrote:
> > On Thu, Feb 29, 2024 at 2:11 AM Chao Yu  wrote:
> > > 
> > > Jaegeuk, Daeho,
> > > 
> > > Any comments on this serials?
> > > 
> > > Thanks,
> > 
> > No functional difference here, since start_blk is always aligned with
> > the section address.
> 
> You're right.
> 
> > However, this is more clear in itself.
> 
> Thanks for the review!
> 
> One more thing is, I found that fallocate() on pinned file will preallocate
> aligned w/ section-size which is about several hundred megabyte for ZUFS case,
> since commit e1175f022911 ("f2fs: fix to align to section for fallocate() on
> pinned file").
> 
> It looks not make sense, especially for logcat case which actually want to
> preallocate 2MB space, so, what about reverting commit e1175f022911 and
> looking for other solution to avoid GCing on fragmented pinned file.

I remember we removed the logcat case.

> 
> What do you think?
> 
> Thanks,
> 
> > 
> > Reviewed-by: Daeho Jeong 
> > 
> > Thanks,
> > 
> > > 
> > > On 2024/2/26 9:32, Chao Yu wrote:
> > > > In f2fs_migrate_blocks(), when traversing blocks in last section,
> > > > blkofs_end should be (start_blk + blkcnt - 1) % blk_per_sec, fix it.
> > > > 
> > > > Signed-off-by: Chao Yu 
> > > > ---
> > > >fs/f2fs/data.c | 5 +++--
> > > >1 file changed, 3 insertions(+), 2 deletions(-)
> > > > 
> > > > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> > > > index c21b92f18463..0c728e82d936 100644
> > > > --- a/fs/f2fs/data.c
> > > > +++ b/fs/f2fs/data.c
> > > > @@ -3841,13 +3841,14 @@ static int f2fs_migrate_blocks(struct inode 
> > > > *inode, block_t start_blk,
> > > >struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
> > > >unsigned int blkofs;
> > > >unsigned int blk_per_sec = BLKS_PER_SEC(sbi);
> > > > + unsigned int end_blk = start_blk + blkcnt - 1;
> > > >unsigned int secidx = start_blk / blk_per_sec;
> > > >unsigned int end_sec;
> > > >int ret = 0;
> > > > 
> > > >if (!blkcnt)
> > > >return 0;
> > > > - end_sec = secidx + (blkcnt - 1) / blk_per_sec;
> > > > + end_sec = end_blk / blk_per_sec;
> > > > 
> > > >f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
> > > >filemap_invalidate_lock(inode->i_mapping);
> > > > @@ -3857,7 +3858,7 @@ static int f2fs_migrate_blocks(struct inode 
> > > > *inode, block_t start_blk,
> > > > 
> > > >for (; secidx <= end_sec; secidx++) {
> > > >unsigned int blkofs_end = secidx == end_sec ?
> > > > - (blkcnt - 1) % blk_per_sec : blk_per_sec - 1;
> > > > + end_blk % blk_per_sec : blk_per_sec - 1;
> > > > 
> > > >f2fs_down_write(&sbi->pin_sem);
> > > > 
> > > 
> > > 
> > > ___
> > > Linux-f2fs-devel mailing list
> > > Linux-f2fs-devel@lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH] f2fs: introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup

2024-02-29 Thread Jaegeuk Kim
On 03/01, Chao Yu wrote:
> On 2024/3/1 0:35, Jaegeuk Kim wrote:
> > On 02/29, Chao Yu wrote:
> > > On 2024/2/28 1:47, Jaegeuk Kim wrote:
> > > > On 02/21, Chao Yu wrote:
> > > > > Just cleanup, no functional change.
> > > > > 
> > > > > Signed-off-by: Chao Yu 
> > > > > ---
> > > > >fs/f2fs/debug.c   |  7 +++
> > > > >fs/f2fs/f2fs.h| 14 --
> > > > >fs/f2fs/gc.c  | 10 +-
> > > > >fs/f2fs/gc.h  |  4 ++--
> > > > >fs/f2fs/segment.c | 12 ++--
> > > > >fs/f2fs/segment.h |  8 
> > > > >fs/f2fs/super.c   | 16 
> > > > >fs/f2fs/sysfs.c   |  4 ++--
> > > > >8 files changed, 38 insertions(+), 37 deletions(-)
> > > > > 
> > > > > diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
> > > > > index 6617195bd27e..12893477f2e4 100644
> > > > > --- a/fs/f2fs/debug.c
> > > > > +++ b/fs/f2fs/debug.c
> > > > > @@ -134,7 +134,7 @@ static void update_general_status(struct 
> > > > > f2fs_sb_info *sbi)
> > > > >   si->cur_ckpt_time = sbi->cprc_info.cur_time;
> > > > >   si->peak_ckpt_time = sbi->cprc_info.peak_time;
> > > > >   spin_unlock(&sbi->cprc_info.stat_lock);
> > > > > - si->total_count = (int)sbi->user_block_count / 
> > > > > BLKS_PER_SEG(sbi);
> > > > > + si->total_count = BLKS_TO_SEGS(sbi, (int)sbi->user_block_count);
> > > > >   si->rsvd_segs = reserved_segments(sbi);
> > > > >   si->overp_segs = overprovision_segments(sbi);
> > > > >   si->valid_count = valid_user_blocks(sbi);
> > > > > @@ -175,11 +175,10 @@ static void update_general_status(struct 
> > > > > f2fs_sb_info *sbi)
> > > > >   si->alloc_nids = NM_I(sbi)->nid_cnt[PREALLOC_NID];
> > > > >   si->io_skip_bggc = sbi->io_skip_bggc;
> > > > >   si->other_skip_bggc = sbi->other_skip_bggc;
> > > > > - si->util_free = (int)(free_user_blocks(sbi) >> 
> > > > > sbi->log_blocks_per_seg)
> > > > > + si->util_free = (int)(BLKS_TO_SEGS(sbi, free_user_blocks(sbi)))
> > > > >   * 100 / (int)(sbi->user_block_count >> 
> > > > > sbi->log_blocks_per_seg)
> > > > >   / 2;
> > > > > - si->util_valid = (int)(written_block_count(sbi) >>
> > > > > - sbi->log_blocks_per_seg)
> > > > > + si->util_valid = (int)(BLKS_TO_SEGS(sbi, 
> > > > > written_block_count(sbi)))
> > > > >   * 100 / (int)(sbi->user_block_count >> 
> > > > > sbi->log_blocks_per_seg)
> > > > >   / 2;
> > > > >   si->util_invalid = 50 - si->util_free - si->util_valid;
> > > > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> > > > > index dad2774ca72f..8a6fd4352a0e 100644
> > > > > --- a/fs/f2fs/f2fs.h
> > > > > +++ b/fs/f2fs/f2fs.h
> > > > > @@ -1813,12 +1813,14 @@ struct f2fs_sb_info {
> > > > >};
> > > > >/* Definitions to access f2fs_sb_info */
> > > > > -#define BLKS_PER_SEG(sbi)\
> > > > > - ((sbi)->blocks_per_seg)
> > > > > -#define BLKS_PER_SEC(sbi)\
> > > > > - ((sbi)->segs_per_sec << (sbi)->log_blocks_per_seg)
> > > > > -#define SEGS_PER_SEC(sbi)\
> > > > > - ((sbi)->segs_per_sec)
> > > > > +#define SEGS_TO_BLKS(sbi, segs)  
> > > > > \
> > > > > + ((segs) << (sbi)->log_blocks_per_seg)
> > > > 
> > > > 
> > > > I also applied this.
> > > > 
> > > >/* Definitions to access f2fs_sb_info */
> > > >#define SEGS_TO_BLKS(sbi, segs)  
> > > >   \
> > > > -   ((segs) << (sbi)->log_blocks_per_seg)
> > > > +   (((long long)segs) << (sbi)->log_blocks_per_seg)
> > > 
> > > Jaegeuk,
> > > 
> > > This may cause compile failure reported as below, can we revert this?
> > > 
> > > https://lore.kernel.org/linux-f2fs-devel/camuhmdxruiv8pee6azkylp+z_sa8cbl8849bzu59j1_xxty...@mail.gmail.com/T/#t
> > 
> > Yeah, it seems so. I removed it in -dev.
> 
> Oh, I meant reverting (((long long)segs) << (sbi)->log_blocks_per_seg),
> this line can bring 64bits data into division statement, result in
> compile failure.

Time to resend the patch to address previous casting issue as well? :)

> 
> Thanks,
> 
> > 
> > > 
> > > Thanks,
> > > 
> > > >#define BLKS_TO_SEGS(sbi, blks)  
> > > >   \
> > > >   ((blks) >> (sbi)->log_blocks_per_seg)
> > > > 
> > > > > +#define BLKS_TO_SEGS(sbi, blks)  
> > > > > \
> > > > > + ((blks) >> (sbi)->log_blocks_per_seg)
> > > > > +
> > > > > +#define BLKS_PER_SEG(sbi)((sbi)->blocks_per_seg)
> > > > > +#define BLKS_PER_SEC(sbi)(SEGS_TO_BLKS(sbi, (sbi)->segs_per_sec))
> > > > > +#define SEGS_PER_SEC(sbi)((sbi)->segs_per_sec)
> > > > >__printf(3, 4)
> > > > >void f2fs_printk(struct f2fs_sb_info *sbi, bool limit_rate, const 
> > > > > char *fmt, ...);
> > > > > diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc

Re: [f2fs-dev] [PATCH 1/4] f2fs: fix blkofs_end correctly in f2fs_migrate_blocks()

2024-02-29 Thread Chao Yu

On 2024/3/1 1:41, Daeho Jeong wrote:

On Thu, Feb 29, 2024 at 2:11 AM Chao Yu  wrote:


Jaegeuk, Daeho,

Any comments on this serials?

Thanks,


No functional difference here, since start_blk is always aligned with
the section address.


You're right.


However, this is more clear in itself.


Thanks for the review!

One more thing is, I found that fallocate() on pinned file will preallocate
aligned w/ section-size which is about several hundred megabyte for ZUFS case,
since commit e1175f022911 ("f2fs: fix to align to section for fallocate() on
pinned file").

It looks not make sense, especially for logcat case which actually want to
preallocate 2MB space, so, what about reverting commit e1175f022911 and
looking for other solution to avoid GCing on fragmented pinned file.

What do you think?

Thanks,



Reviewed-by: Daeho Jeong 

Thanks,



On 2024/2/26 9:32, Chao Yu wrote:

In f2fs_migrate_blocks(), when traversing blocks in last section,
blkofs_end should be (start_blk + blkcnt - 1) % blk_per_sec, fix it.

Signed-off-by: Chao Yu 
---
   fs/f2fs/data.c | 5 +++--
   1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index c21b92f18463..0c728e82d936 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3841,13 +3841,14 @@ static int f2fs_migrate_blocks(struct inode *inode, 
block_t start_blk,
   struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
   unsigned int blkofs;
   unsigned int blk_per_sec = BLKS_PER_SEC(sbi);
+ unsigned int end_blk = start_blk + blkcnt - 1;
   unsigned int secidx = start_blk / blk_per_sec;
   unsigned int end_sec;
   int ret = 0;

   if (!blkcnt)
   return 0;
- end_sec = secidx + (blkcnt - 1) / blk_per_sec;
+ end_sec = end_blk / blk_per_sec;

   f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
   filemap_invalidate_lock(inode->i_mapping);
@@ -3857,7 +3858,7 @@ static int f2fs_migrate_blocks(struct inode *inode, 
block_t start_blk,

   for (; secidx <= end_sec; secidx++) {
   unsigned int blkofs_end = secidx == end_sec ?
- (blkcnt - 1) % blk_per_sec : blk_per_sec - 1;
+ end_blk % blk_per_sec : blk_per_sec - 1;

   f2fs_down_write(&sbi->pin_sem);




___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH] f2fs: introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup

2024-02-29 Thread Chao Yu

On 2024/3/1 0:35, Jaegeuk Kim wrote:

On 02/29, Chao Yu wrote:

On 2024/2/28 1:47, Jaegeuk Kim wrote:

On 02/21, Chao Yu wrote:

Just cleanup, no functional change.

Signed-off-by: Chao Yu 
---
   fs/f2fs/debug.c   |  7 +++
   fs/f2fs/f2fs.h| 14 --
   fs/f2fs/gc.c  | 10 +-
   fs/f2fs/gc.h  |  4 ++--
   fs/f2fs/segment.c | 12 ++--
   fs/f2fs/segment.h |  8 
   fs/f2fs/super.c   | 16 
   fs/f2fs/sysfs.c   |  4 ++--
   8 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
index 6617195bd27e..12893477f2e4 100644
--- a/fs/f2fs/debug.c
+++ b/fs/f2fs/debug.c
@@ -134,7 +134,7 @@ static void update_general_status(struct f2fs_sb_info *sbi)
si->cur_ckpt_time = sbi->cprc_info.cur_time;
si->peak_ckpt_time = sbi->cprc_info.peak_time;
spin_unlock(&sbi->cprc_info.stat_lock);
-   si->total_count = (int)sbi->user_block_count / BLKS_PER_SEG(sbi);
+   si->total_count = BLKS_TO_SEGS(sbi, (int)sbi->user_block_count);
si->rsvd_segs = reserved_segments(sbi);
si->overp_segs = overprovision_segments(sbi);
si->valid_count = valid_user_blocks(sbi);
@@ -175,11 +175,10 @@ static void update_general_status(struct f2fs_sb_info 
*sbi)
si->alloc_nids = NM_I(sbi)->nid_cnt[PREALLOC_NID];
si->io_skip_bggc = sbi->io_skip_bggc;
si->other_skip_bggc = sbi->other_skip_bggc;
-   si->util_free = (int)(free_user_blocks(sbi) >> sbi->log_blocks_per_seg)
+   si->util_free = (int)(BLKS_TO_SEGS(sbi, free_user_blocks(sbi)))
* 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
/ 2;
-   si->util_valid = (int)(written_block_count(sbi) >>
-   sbi->log_blocks_per_seg)
+   si->util_valid = (int)(BLKS_TO_SEGS(sbi, written_block_count(sbi)))
* 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
/ 2;
si->util_invalid = 50 - si->util_free - si->util_valid;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index dad2774ca72f..8a6fd4352a0e 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1813,12 +1813,14 @@ struct f2fs_sb_info {
   };
   /* Definitions to access f2fs_sb_info */
-#define BLKS_PER_SEG(sbi)  \
-   ((sbi)->blocks_per_seg)
-#define BLKS_PER_SEC(sbi)  \
-   ((sbi)->segs_per_sec << (sbi)->log_blocks_per_seg)
-#define SEGS_PER_SEC(sbi)  \
-   ((sbi)->segs_per_sec)
+#define SEGS_TO_BLKS(sbi, segs)\
+   ((segs) << (sbi)->log_blocks_per_seg)



I also applied this.

   /* Definitions to access f2fs_sb_info */
   #define SEGS_TO_BLKS(sbi, segs)\
-   ((segs) << (sbi)->log_blocks_per_seg)
+   (((long long)segs) << (sbi)->log_blocks_per_seg)


Jaegeuk,

This may cause compile failure reported as below, can we revert this?

https://lore.kernel.org/linux-f2fs-devel/camuhmdxruiv8pee6azkylp+z_sa8cbl8849bzu59j1_xxty...@mail.gmail.com/T/#t


Yeah, it seems so. I removed it in -dev.


Oh, I meant reverting (((long long)segs) << (sbi)->log_blocks_per_seg),
this line can bring 64bits data into division statement, result in
compile failure.

Thanks,





Thanks,


   #define BLKS_TO_SEGS(sbi, blks)\
  ((blks) >> (sbi)->log_blocks_per_seg)


+#define BLKS_TO_SEGS(sbi, blks)\
+   ((blks) >> (sbi)->log_blocks_per_seg)
+
+#define BLKS_PER_SEG(sbi)  ((sbi)->blocks_per_seg)
+#define BLKS_PER_SEC(sbi)  (SEGS_TO_BLKS(sbi, (sbi)->segs_per_sec))
+#define SEGS_PER_SEC(sbi)  ((sbi)->segs_per_sec)
   __printf(3, 4)
   void f2fs_printk(struct f2fs_sb_info *sbi, bool limit_rate, const char *fmt, 
...);
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 3ff126316d42..6d160d50e14e 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -301,7 +301,7 @@ static unsigned int get_max_cost(struct f2fs_sb_info *sbi,
/* LFS */
if (p->gc_mode == GC_GREEDY)
-   return 2 * BLKS_PER_SEG(sbi) * p->ofs_unit;
+   return SEGS_TO_BLKS(sbi, 2 * p->ofs_unit);
else if (p->gc_mode == GC_CB)
return UINT_MAX;
else if (p->gc_mode == GC_AT)
@@ -347,7 +347,7 @@ static unsigned int get_cb_cost(struct f2fs_sb_info *sbi, 
unsigned int segno)
mtime = div_u64(mtime, SEGS_PER_SEC(sbi));
vblocks = div_u64(vblocks, SEGS_PER_SEC(sbi));
-   u = (vblocks * 100) >> sbi->log_blocks_per_seg;
+   u = BLKS_TO_SEGS(sbi, vblocks * 100);
/* Handle if the system time has changed by the user */
if (mtime < sit_i->min_mtime)
@@ -2060,7 +2060,7 @@ static void update_sb_metadata(struct f2fs_sb_info *sbi, 
int secs)
raw_sb->segment_count = cpu_to_

Re: [f2fs-dev] [PATCH] f2fs: fix to do sanity check in update_sit_entry

2024-02-29 Thread Chao Yu

On 2024/2/28 19:59, Zhiguo Niu wrote:

If GET_SEGNO return NULL_SEGNO for some unecpected case,
update_sit_entry will access invalid memory address,
cause system crash. It is better to do sanity check about
GET_SEGNO just like update_segment_mtime & locate_dirty_segment.

Also remove some redundant judgment code.

Signed-off-by: Zhiguo Niu 


Reviewed-by: Chao Yu 

Thanks,


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 4/4] f2fs: fix to reset fields for unloaded curseg

2024-02-29 Thread Daeho Jeong
Reviewed-by: Daeho Jeong 

Thanks,

On Sun, Feb 25, 2024 at 5:33 PM Chao Yu  wrote:
>
> In f2fs_allocate_data_block(), before skip allocating new segment
> for DATA_PINNED log header, it needs to tag log header as unloaded
> one to avoid skipping logic in locate_dirty_segment() and
> __f2fs_save_inmem_curseg().
>
> Signed-off-by: Chao Yu 
> ---
>  fs/f2fs/segment.c | 19 +++
>  1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index c159b0985596..5e45afd69f3f 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -3101,12 +3101,16 @@ static int __allocate_new_segment(struct f2fs_sb_info 
> *sbi, int type,
> struct curseg_info *curseg = CURSEG_I(sbi, type);
> unsigned int old_segno;
>
> +   if (type == CURSEG_COLD_DATA_PINNED && !curseg->inited)
> +   goto allocate;
> +
> if (!force && curseg->inited &&
> !curseg->next_blkoff &&
> !get_valid_blocks(sbi, curseg->segno, new_sec) &&
> !get_ckpt_valid_blocks(sbi, curseg->segno, new_sec))
> return 0;
>
> +allocate:
> old_segno = curseg->segno;
> if (new_curseg(sbi, type, true))
> return -EAGAIN;
> @@ -3451,6 +3455,13 @@ static void f2fs_randomize_chunk(struct f2fs_sb_info 
> *sbi,
> get_random_u32_inclusive(1, sbi->max_fragment_hole);
>  }
>
> +static void reset_curseg_fields(struct curseg_info *curseg)
> +{
> +   curseg->inited = false;
> +   curseg->segno = NULL_SEGNO;
> +   curseg->next_segno = 0;
> +}
> +
>  int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
> block_t old_blkaddr, block_t *new_blkaddr,
> struct f2fs_summary *sum, int type,
> @@ -3516,8 +3527,10 @@ int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, 
> struct page *page,
>  */
> if (segment_full) {
> if (type == CURSEG_COLD_DATA_PINNED &&
> -   !((curseg->segno + 1) % sbi->segs_per_sec))
> +   !((curseg->segno + 1) % sbi->segs_per_sec)) {
> +   reset_curseg_fields(curseg);
> goto skip_new_segment;
> +   }
>
> if (from_gc) {
> get_atssr_segment(sbi, type, se->type,
> @@ -4595,9 +4608,7 @@ static int build_curseg(struct f2fs_sb_info *sbi)
> array[i].seg_type = CURSEG_COLD_DATA;
> else if (i == CURSEG_ALL_DATA_ATGC)
> array[i].seg_type = CURSEG_COLD_DATA;
> -   array[i].segno = NULL_SEGNO;
> -   array[i].next_blkoff = 0;
> -   array[i].inited = false;
> +   reset_curseg_fields(&array[i]);
> }
> return restore_curseg_summaries(sbi);
>  }
> --
> 2.40.1
>
>
>
> ___
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 3/4] f2fs: clean up new_curseg()

2024-02-29 Thread Daeho Jeong
Reviewed-by: Daeho Jeong 

Thanks,

On Sun, Feb 25, 2024 at 5:33 PM Chao Yu  wrote:
>
> Move f2fs_valid_pinned_area() check logic from new_curseg() to
> get_new_segment(), it can avoid calling __set_free() if it fails
> to find free segment in conventional zone for pinned file.
>
> Signed-off-by: Chao Yu 
> ---
>  fs/f2fs/segment.c | 23 ++-
>  1 file changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 847fe0b7f29f..c159b0985596 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -2715,12 +2715,19 @@ static int get_new_segment(struct f2fs_sb_info *sbi,
>  got_it:
> /* set it as dirty segment in free segmap */
> f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap));
> +
> +   /* no free section in conventional zone */
> +   if (new_sec && pinning &&
> +   !f2fs_valid_pinned_area(sbi, START_BLOCK(sbi, segno))) {
> +   ret = -EAGAIN;
> +   goto out_unlock;
> +   }
> __set_inuse(sbi, segno);
> *newseg = segno;
>  out_unlock:
> spin_unlock(&free_i->segmap_lock);
>
> -   if (ret) {
> +   if (ret == -ENOSPC) {
> f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_NO_SEGMENT);
> f2fs_bug_on(sbi, 1);
> }
> @@ -2796,19 +2803,17 @@ static int new_curseg(struct f2fs_sb_info *sbi, int 
> type, bool new_sec)
> struct curseg_info *curseg = CURSEG_I(sbi, type);
> unsigned int segno = curseg->segno;
> bool pinning = type == CURSEG_COLD_DATA_PINNED;
> +   int ret;
>
> if (curseg->inited)
> write_sum_page(sbi, curseg->sum_blk, GET_SUM_BLOCK(sbi, 
> segno));
>
> segno = __get_next_segno(sbi, type);
> -   if (get_new_segment(sbi, &segno, new_sec, pinning)) {
> -   curseg->segno = NULL_SEGNO;
> -   return -ENOSPC;
> -   }
> -   if (new_sec && pinning &&
> -   !f2fs_valid_pinned_area(sbi, START_BLOCK(sbi, segno))) {
> -   __set_free(sbi, segno);
> -   return -EAGAIN;
> +   ret = get_new_segment(sbi, &segno, new_sec, pinning);
> +   if (ret) {
> +   if (ret == -ENOSPC)
> +   curseg->segno = NULL_SEGNO;
> +   return ret;
> }
>
> curseg->next_segno = segno;
> --
> 2.40.1
>
>
>
> ___
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 1/4] f2fs: fix blkofs_end correctly in f2fs_migrate_blocks()

2024-02-29 Thread Daeho Jeong
On Thu, Feb 29, 2024 at 2:11 AM Chao Yu  wrote:
>
> Jaegeuk, Daeho,
>
> Any comments on this serials?
>
> Thanks,

No functional difference here, since start_blk is always aligned with
the section address.
However, this is more clear in itself.

Reviewed-by: Daeho Jeong 

Thanks,

>
> On 2024/2/26 9:32, Chao Yu wrote:
> > In f2fs_migrate_blocks(), when traversing blocks in last section,
> > blkofs_end should be (start_blk + blkcnt - 1) % blk_per_sec, fix it.
> >
> > Signed-off-by: Chao Yu 
> > ---
> >   fs/f2fs/data.c | 5 +++--
> >   1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> > index c21b92f18463..0c728e82d936 100644
> > --- a/fs/f2fs/data.c
> > +++ b/fs/f2fs/data.c
> > @@ -3841,13 +3841,14 @@ static int f2fs_migrate_blocks(struct inode *inode, 
> > block_t start_blk,
> >   struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
> >   unsigned int blkofs;
> >   unsigned int blk_per_sec = BLKS_PER_SEC(sbi);
> > + unsigned int end_blk = start_blk + blkcnt - 1;
> >   unsigned int secidx = start_blk / blk_per_sec;
> >   unsigned int end_sec;
> >   int ret = 0;
> >
> >   if (!blkcnt)
> >   return 0;
> > - end_sec = secidx + (blkcnt - 1) / blk_per_sec;
> > + end_sec = end_blk / blk_per_sec;
> >
> >   f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
> >   filemap_invalidate_lock(inode->i_mapping);
> > @@ -3857,7 +3858,7 @@ static int f2fs_migrate_blocks(struct inode *inode, 
> > block_t start_blk,
> >
> >   for (; secidx <= end_sec; secidx++) {
> >   unsigned int blkofs_end = secidx == end_sec ?
> > - (blkcnt - 1) % blk_per_sec : blk_per_sec - 1;
> > + end_blk % blk_per_sec : blk_per_sec - 1;
> >
> >   f2fs_down_write(&sbi->pin_sem);
> >
>
>
> ___
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 2/4] f2fs: relocate f2fs_precache_extents() in f2fs_swap_activate()

2024-02-29 Thread Daeho Jeong
Reviewed-by: Daeho Jeong 

Thanks,

On Sun, Feb 25, 2024 at 5:33 PM Chao Yu  wrote:
>
> This patch exchangs position of f2fs_precache_extents() and
> filemap_fdatawrite(), so that f2fs_precache_extents() can load
> extent info after physical addresses of all data are fixed.
>
> Signed-off-by: Chao Yu 
> ---
>  fs/f2fs/data.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 0c728e82d936..bd8674bf1d84 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -4045,12 +4045,12 @@ static int f2fs_swap_activate(struct swap_info_struct 
> *sis, struct file *file,
> if (!f2fs_disable_compressed_file(inode))
> return -EINVAL;
>
> -   f2fs_precache_extents(inode);
> -
> ret = filemap_fdatawrite(inode->i_mapping);
> if (ret < 0)
> return ret;
>
> +   f2fs_precache_extents(inode);
> +
> ret = check_swap_activate(sis, file, span);
> if (ret < 0)
> return ret;
> --
> 2.40.1
>
>
>
> ___
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH][next] f2fs: Fix two spelling mistakes in f2fs_zone_status array

2024-02-29 Thread Jaegeuk Kim
On 02/29, Colin King (gmail) wrote:
> On 29/02/2024 17:12, Jaegeuk Kim wrote:
> > Hi Colin,
> > 
> > Thank you for the fix. If you don't mind, can I integrate this fix
> > into the original patch?
> 
> Sure. No problem.

Thank you so much!

> 
> Colin
> > 
> > Thanks,
> > 
> > On 02/29, Colin Ian King wrote:
> > > The array f2fs_zone_status contains two spelling mistakes in
> > > literal strings. Fix them.
> > > 
> > > Signed-off-by: Colin Ian King 
> > > ---
> > >   fs/f2fs/segment.c | 4 ++--
> > >   1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> > > index bdb27e4a604b..072c4355d3d3 100644
> > > --- a/fs/f2fs/segment.c
> > > +++ b/fs/f2fs/segment.c
> > > @@ -4921,8 +4921,8 @@ static int sanity_check_curseg(struct f2fs_sb_info 
> > > *sbi)
> > >   const char *f2fs_zone_status[BLK_ZONE_COND_OFFLINE + 1] = {
> > >   [BLK_ZONE_COND_NOT_WP]  = "NOT_WP",
> > >   [BLK_ZONE_COND_EMPTY]   = "EMPTY",
> > > - [BLK_ZONE_COND_IMP_OPEN]= "IMPLICITE_OPEN",
> > > - [BLK_ZONE_COND_EXP_OPEN]= "EXPLICITE_OPEN",
> > > + [BLK_ZONE_COND_IMP_OPEN]= "IMPLICIT_OPEN",
> > > + [BLK_ZONE_COND_EXP_OPEN]= "EXPLICIT_OPEN",
> > >   [BLK_ZONE_COND_CLOSED]  = "CLOSED",
> > >   [BLK_ZONE_COND_READONLY]= "READONLY",
> > >   [BLK_ZONE_COND_FULL]= "FULL",
> > > -- 
> > > 2.39.2


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH][next] f2fs: Fix two spelling mistakes in f2fs_zone_status array

2024-02-29 Thread Colin King (gmail)

On 29/02/2024 17:12, Jaegeuk Kim wrote:

Hi Colin,

Thank you for the fix. If you don't mind, can I integrate this fix
into the original patch?


Sure. No problem.

Colin


Thanks,

On 02/29, Colin Ian King wrote:

The array f2fs_zone_status contains two spelling mistakes in
literal strings. Fix them.

Signed-off-by: Colin Ian King 
---
  fs/f2fs/segment.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index bdb27e4a604b..072c4355d3d3 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -4921,8 +4921,8 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
  const char *f2fs_zone_status[BLK_ZONE_COND_OFFLINE + 1] = {
[BLK_ZONE_COND_NOT_WP]  = "NOT_WP",
[BLK_ZONE_COND_EMPTY]   = "EMPTY",
-   [BLK_ZONE_COND_IMP_OPEN]= "IMPLICITE_OPEN",
-   [BLK_ZONE_COND_EXP_OPEN]= "EXPLICITE_OPEN",
+   [BLK_ZONE_COND_IMP_OPEN]= "IMPLICIT_OPEN",
+   [BLK_ZONE_COND_EXP_OPEN]= "EXPLICIT_OPEN",
[BLK_ZONE_COND_CLOSED]  = "CLOSED",
[BLK_ZONE_COND_READONLY]= "READONLY",
[BLK_ZONE_COND_FULL]= "FULL",
--
2.39.2




___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH][next] f2fs: Fix two spelling mistakes in f2fs_zone_status array

2024-02-29 Thread Jaegeuk Kim
Hi Colin,

Thank you for the fix. If you don't mind, can I integrate this fix
into the original patch?

Thanks,

On 02/29, Colin Ian King wrote:
> The array f2fs_zone_status contains two spelling mistakes in
> literal strings. Fix them.
> 
> Signed-off-by: Colin Ian King 
> ---
>  fs/f2fs/segment.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index bdb27e4a604b..072c4355d3d3 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -4921,8 +4921,8 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
>  const char *f2fs_zone_status[BLK_ZONE_COND_OFFLINE + 1] = {
>   [BLK_ZONE_COND_NOT_WP]  = "NOT_WP",
>   [BLK_ZONE_COND_EMPTY]   = "EMPTY",
> - [BLK_ZONE_COND_IMP_OPEN]= "IMPLICITE_OPEN",
> - [BLK_ZONE_COND_EXP_OPEN]= "EXPLICITE_OPEN",
> + [BLK_ZONE_COND_IMP_OPEN]= "IMPLICIT_OPEN",
> + [BLK_ZONE_COND_EXP_OPEN]= "EXPLICIT_OPEN",
>   [BLK_ZONE_COND_CLOSED]  = "CLOSED",
>   [BLK_ZONE_COND_READONLY]= "READONLY",
>   [BLK_ZONE_COND_FULL]= "FULL",
> -- 
> 2.39.2


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH] f2fs: introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup

2024-02-29 Thread Jaegeuk Kim
On 02/29, Chao Yu wrote:
> On 2024/2/28 1:47, Jaegeuk Kim wrote:
> > On 02/21, Chao Yu wrote:
> > > Just cleanup, no functional change.
> > > 
> > > Signed-off-by: Chao Yu 
> > > ---
> > >   fs/f2fs/debug.c   |  7 +++
> > >   fs/f2fs/f2fs.h| 14 --
> > >   fs/f2fs/gc.c  | 10 +-
> > >   fs/f2fs/gc.h  |  4 ++--
> > >   fs/f2fs/segment.c | 12 ++--
> > >   fs/f2fs/segment.h |  8 
> > >   fs/f2fs/super.c   | 16 
> > >   fs/f2fs/sysfs.c   |  4 ++--
> > >   8 files changed, 38 insertions(+), 37 deletions(-)
> > > 
> > > diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
> > > index 6617195bd27e..12893477f2e4 100644
> > > --- a/fs/f2fs/debug.c
> > > +++ b/fs/f2fs/debug.c
> > > @@ -134,7 +134,7 @@ static void update_general_status(struct f2fs_sb_info 
> > > *sbi)
> > >   si->cur_ckpt_time = sbi->cprc_info.cur_time;
> > >   si->peak_ckpt_time = sbi->cprc_info.peak_time;
> > >   spin_unlock(&sbi->cprc_info.stat_lock);
> > > - si->total_count = (int)sbi->user_block_count / BLKS_PER_SEG(sbi);
> > > + si->total_count = BLKS_TO_SEGS(sbi, (int)sbi->user_block_count);
> > >   si->rsvd_segs = reserved_segments(sbi);
> > >   si->overp_segs = overprovision_segments(sbi);
> > >   si->valid_count = valid_user_blocks(sbi);
> > > @@ -175,11 +175,10 @@ static void update_general_status(struct 
> > > f2fs_sb_info *sbi)
> > >   si->alloc_nids = NM_I(sbi)->nid_cnt[PREALLOC_NID];
> > >   si->io_skip_bggc = sbi->io_skip_bggc;
> > >   si->other_skip_bggc = sbi->other_skip_bggc;
> > > - si->util_free = (int)(free_user_blocks(sbi) >> sbi->log_blocks_per_seg)
> > > + si->util_free = (int)(BLKS_TO_SEGS(sbi, free_user_blocks(sbi)))
> > >   * 100 / (int)(sbi->user_block_count >> 
> > > sbi->log_blocks_per_seg)
> > >   / 2;
> > > - si->util_valid = (int)(written_block_count(sbi) >>
> > > - sbi->log_blocks_per_seg)
> > > + si->util_valid = (int)(BLKS_TO_SEGS(sbi, written_block_count(sbi)))
> > >   * 100 / (int)(sbi->user_block_count >> 
> > > sbi->log_blocks_per_seg)
> > >   / 2;
> > >   si->util_invalid = 50 - si->util_free - si->util_valid;
> > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> > > index dad2774ca72f..8a6fd4352a0e 100644
> > > --- a/fs/f2fs/f2fs.h
> > > +++ b/fs/f2fs/f2fs.h
> > > @@ -1813,12 +1813,14 @@ struct f2fs_sb_info {
> > >   };
> > >   /* Definitions to access f2fs_sb_info */
> > > -#define BLKS_PER_SEG(sbi)\
> > > - ((sbi)->blocks_per_seg)
> > > -#define BLKS_PER_SEC(sbi)\
> > > - ((sbi)->segs_per_sec << (sbi)->log_blocks_per_seg)
> > > -#define SEGS_PER_SEC(sbi)\
> > > - ((sbi)->segs_per_sec)
> > > +#define SEGS_TO_BLKS(sbi, segs)  \
> > > + ((segs) << (sbi)->log_blocks_per_seg)
> > 
> > 
> > I also applied this.
> > 
> >   /* Definitions to access f2fs_sb_info */
> >   #define SEGS_TO_BLKS(sbi, segs)\
> > -   ((segs) << (sbi)->log_blocks_per_seg)
> > +   (((long long)segs) << (sbi)->log_blocks_per_seg)
> 
> Jaegeuk,
> 
> This may cause compile failure reported as below, can we revert this?
> 
> https://lore.kernel.org/linux-f2fs-devel/camuhmdxruiv8pee6azkylp+z_sa8cbl8849bzu59j1_xxty...@mail.gmail.com/T/#t

Yeah, it seems so. I removed it in -dev.

> 
> Thanks,
> 
> >   #define BLKS_TO_SEGS(sbi, blks)\
> >  ((blks) >> (sbi)->log_blocks_per_seg)
> > 
> > > +#define BLKS_TO_SEGS(sbi, blks)  \
> > > + ((blks) >> (sbi)->log_blocks_per_seg)
> > > +
> > > +#define BLKS_PER_SEG(sbi)((sbi)->blocks_per_seg)
> > > +#define BLKS_PER_SEC(sbi)(SEGS_TO_BLKS(sbi, (sbi)->segs_per_sec))
> > > +#define SEGS_PER_SEC(sbi)((sbi)->segs_per_sec)
> > >   __printf(3, 4)
> > >   void f2fs_printk(struct f2fs_sb_info *sbi, bool limit_rate, const char 
> > > *fmt, ...);
> > > diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> > > index 3ff126316d42..6d160d50e14e 100644
> > > --- a/fs/f2fs/gc.c
> > > +++ b/fs/f2fs/gc.c
> > > @@ -301,7 +301,7 @@ static unsigned int get_max_cost(struct f2fs_sb_info 
> > > *sbi,
> > >   /* LFS */
> > >   if (p->gc_mode == GC_GREEDY)
> > > - return 2 * BLKS_PER_SEG(sbi) * p->ofs_unit;
> > > + return SEGS_TO_BLKS(sbi, 2 * p->ofs_unit);
> > >   else if (p->gc_mode == GC_CB)
> > >   return UINT_MAX;
> > >   else if (p->gc_mode == GC_AT)
> > > @@ -347,7 +347,7 @@ static unsigned int get_cb_cost(struct f2fs_sb_info 
> > > *sbi, unsigned int segno)
> > >   mtime = div_u64(mtime, SEGS_PER_SEC(sbi));
> > >   vblocks = div_u64(vblocks, SEGS_PER_SEC(sbi));
> > > - u = (vblocks 

[f2fs-dev] [PATCH] f2fs: support .shutdown in f2fs_sops

2024-02-29 Thread Chao Yu
Support .shutdown callback in f2fs_sops, then, it can be called to
shut down the file system when underlying block device is marked dead.

Signed-off-by: Chao Yu 
---
 fs/f2fs/f2fs.h  |  2 ++
 fs/f2fs/file.c  | 70 ++---
 fs/f2fs/super.c |  6 +
 3 files changed, 51 insertions(+), 27 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 85eb9a8a5ed3..80789255bf68 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -3506,6 +3506,8 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry 
*dentry,
 struct iattr *attr);
 int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end);
 void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count);
+int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,
+   bool readonly);
 int f2fs_precache_extents(struct inode *inode);
 int f2fs_fileattr_get(struct dentry *dentry, struct fileattr *fa);
 int f2fs_fileattr_set(struct mnt_idmap *idmap,
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 4ca6c693b33a..d223175b3d5c 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2226,34 +2226,13 @@ static int f2fs_ioc_abort_atomic_write(struct file 
*filp)
return ret;
 }
 
-static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg)
+int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,
+   bool readonly)
 {
-   struct inode *inode = file_inode(filp);
-   struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
struct super_block *sb = sbi->sb;
-   __u32 in;
int ret = 0;
 
-   if (!capable(CAP_SYS_ADMIN))
-   return -EPERM;
-
-   if (get_user(in, (__u32 __user *)arg))
-   return -EFAULT;
-
-   if (in != F2FS_GOING_DOWN_FULLSYNC) {
-   ret = mnt_want_write_file(filp);
-   if (ret) {
-   if (ret == -EROFS) {
-   ret = 0;
-   f2fs_stop_checkpoint(sbi, false,
-   STOP_CP_REASON_SHUTDOWN);
-   trace_f2fs_shutdown(sbi, in, ret);
-   }
-   return ret;
-   }
-   }
-
-   switch (in) {
+   switch (flag) {
case F2FS_GOING_DOWN_FULLSYNC:
ret = bdev_freeze(sb->s_bdev);
if (ret)
@@ -2292,6 +2271,9 @@ static int f2fs_ioc_shutdown(struct file *filp, unsigned 
long arg)
goto out;
}
 
+   if (readonly)
+   goto out;
+
f2fs_stop_gc_thread(sbi);
f2fs_stop_discard_thread(sbi);
 
@@ -2300,10 +2282,44 @@ static int f2fs_ioc_shutdown(struct file *filp, 
unsigned long arg)
 
f2fs_update_time(sbi, REQ_TIME);
 out:
-   if (in != F2FS_GOING_DOWN_FULLSYNC)
-   mnt_drop_write_file(filp);
 
-   trace_f2fs_shutdown(sbi, in, ret);
+   trace_f2fs_shutdown(sbi, flag, ret);
+
+   return ret;
+}
+
+static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg)
+{
+   struct inode *inode = file_inode(filp);
+   struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+   __u32 in;
+   int ret;
+   bool need_drop = false, readonly = false;
+
+   if (!capable(CAP_SYS_ADMIN))
+   return -EPERM;
+
+   if (get_user(in, (__u32 __user *)arg))
+   return -EFAULT;
+
+   if (in != F2FS_GOING_DOWN_FULLSYNC) {
+   ret = mnt_want_write_file(filp);
+   if (ret) {
+   if (ret != -EROFS)
+   return ret;
+
+   /* fallback to nosync shutdown for readonly fs */
+   in = F2FS_GOING_DOWN_NOSYNC;
+   readonly = true;
+   } else {
+   need_drop = true;
+   }
+   }
+
+   ret = f2fs_do_shutdown(sbi, in, readonly);
+
+   if (need_drop)
+   mnt_drop_write_file(filp);
 
return ret;
 }
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 78a76583a4aa..0676c2dcbbf7 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -2547,6 +2547,11 @@ static int f2fs_remount(struct super_block *sb, int 
*flags, char *data)
return err;
 }
 
+static void f2fs_shutdown(struct super_block *sb)
+{
+   f2fs_do_shutdown(F2FS_SB(sb), F2FS_GOING_DOWN_NOSYNC, false);
+}
+
 #ifdef CONFIG_QUOTA
 static bool f2fs_need_recovery(struct f2fs_sb_info *sbi)
 {
@@ -3146,6 +3151,7 @@ static const struct super_operations f2fs_sops = {
.unfreeze_fs= f2fs_unfreeze,
.statfs = f2fs_statfs,
.remount_fs = f2fs_remount,
+   .shutdown   = f2fs_shutdown,
 };
 
 #ifdef CONFIG_FS_ENCRYPTION
-- 
2.40.1



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://

Re: [f2fs-dev] [PATCH 1/4] f2fs: fix blkofs_end correctly in f2fs_migrate_blocks()

2024-02-29 Thread Chao Yu

Jaegeuk, Daeho,

Any comments on this serials?

Thanks,

On 2024/2/26 9:32, Chao Yu wrote:

In f2fs_migrate_blocks(), when traversing blocks in last section,
blkofs_end should be (start_blk + blkcnt - 1) % blk_per_sec, fix it.

Signed-off-by: Chao Yu 
---
  fs/f2fs/data.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index c21b92f18463..0c728e82d936 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3841,13 +3841,14 @@ static int f2fs_migrate_blocks(struct inode *inode, 
block_t start_blk,
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
unsigned int blkofs;
unsigned int blk_per_sec = BLKS_PER_SEC(sbi);
+   unsigned int end_blk = start_blk + blkcnt - 1;
unsigned int secidx = start_blk / blk_per_sec;
unsigned int end_sec;
int ret = 0;
  
  	if (!blkcnt)

return 0;
-   end_sec = secidx + (blkcnt - 1) / blk_per_sec;
+   end_sec = end_blk / blk_per_sec;
  
  	f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);

filemap_invalidate_lock(inode->i_mapping);
@@ -3857,7 +3858,7 @@ static int f2fs_migrate_blocks(struct inode *inode, 
block_t start_blk,
  
  	for (; secidx <= end_sec; secidx++) {

unsigned int blkofs_end = secidx == end_sec ?
-   (blkcnt - 1) % blk_per_sec : blk_per_sec - 1;
+   end_blk % blk_per_sec : blk_per_sec - 1;
  
  		f2fs_down_write(&sbi->pin_sem);
  



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH] f2fs: introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup

2024-02-29 Thread Chao Yu

On 2024/2/28 1:47, Jaegeuk Kim wrote:

On 02/21, Chao Yu wrote:

Just cleanup, no functional change.

Signed-off-by: Chao Yu 
---
  fs/f2fs/debug.c   |  7 +++
  fs/f2fs/f2fs.h| 14 --
  fs/f2fs/gc.c  | 10 +-
  fs/f2fs/gc.h  |  4 ++--
  fs/f2fs/segment.c | 12 ++--
  fs/f2fs/segment.h |  8 
  fs/f2fs/super.c   | 16 
  fs/f2fs/sysfs.c   |  4 ++--
  8 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
index 6617195bd27e..12893477f2e4 100644
--- a/fs/f2fs/debug.c
+++ b/fs/f2fs/debug.c
@@ -134,7 +134,7 @@ static void update_general_status(struct f2fs_sb_info *sbi)
si->cur_ckpt_time = sbi->cprc_info.cur_time;
si->peak_ckpt_time = sbi->cprc_info.peak_time;
spin_unlock(&sbi->cprc_info.stat_lock);
-   si->total_count = (int)sbi->user_block_count / BLKS_PER_SEG(sbi);
+   si->total_count = BLKS_TO_SEGS(sbi, (int)sbi->user_block_count);
si->rsvd_segs = reserved_segments(sbi);
si->overp_segs = overprovision_segments(sbi);
si->valid_count = valid_user_blocks(sbi);
@@ -175,11 +175,10 @@ static void update_general_status(struct f2fs_sb_info 
*sbi)
si->alloc_nids = NM_I(sbi)->nid_cnt[PREALLOC_NID];
si->io_skip_bggc = sbi->io_skip_bggc;
si->other_skip_bggc = sbi->other_skip_bggc;
-   si->util_free = (int)(free_user_blocks(sbi) >> sbi->log_blocks_per_seg)
+   si->util_free = (int)(BLKS_TO_SEGS(sbi, free_user_blocks(sbi)))
* 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
/ 2;
-   si->util_valid = (int)(written_block_count(sbi) >>
-   sbi->log_blocks_per_seg)
+   si->util_valid = (int)(BLKS_TO_SEGS(sbi, written_block_count(sbi)))
* 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
/ 2;
si->util_invalid = 50 - si->util_free - si->util_valid;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index dad2774ca72f..8a6fd4352a0e 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1813,12 +1813,14 @@ struct f2fs_sb_info {
  };
  
  /* Definitions to access f2fs_sb_info */

-#define BLKS_PER_SEG(sbi)  \
-   ((sbi)->blocks_per_seg)
-#define BLKS_PER_SEC(sbi)  \
-   ((sbi)->segs_per_sec << (sbi)->log_blocks_per_seg)
-#define SEGS_PER_SEC(sbi)  \
-   ((sbi)->segs_per_sec)
+#define SEGS_TO_BLKS(sbi, segs)\
+   ((segs) << (sbi)->log_blocks_per_seg)



I also applied this.

  /* Definitions to access f2fs_sb_info */
  #define SEGS_TO_BLKS(sbi, segs)\
-   ((segs) << (sbi)->log_blocks_per_seg)
+   (((long long)segs) << (sbi)->log_blocks_per_seg)


Jaegeuk,

This may cause compile failure reported as below, can we revert this?

https://lore.kernel.org/linux-f2fs-devel/camuhmdxruiv8pee6azkylp+z_sa8cbl8849bzu59j1_xxty...@mail.gmail.com/T/#t

Thanks,


  #define BLKS_TO_SEGS(sbi, blks)\
 ((blks) >> (sbi)->log_blocks_per_seg)


+#define BLKS_TO_SEGS(sbi, blks)\
+   ((blks) >> (sbi)->log_blocks_per_seg)
+
+#define BLKS_PER_SEG(sbi)  ((sbi)->blocks_per_seg)
+#define BLKS_PER_SEC(sbi)  (SEGS_TO_BLKS(sbi, (sbi)->segs_per_sec))
+#define SEGS_PER_SEC(sbi)  ((sbi)->segs_per_sec)
  
  __printf(3, 4)

  void f2fs_printk(struct f2fs_sb_info *sbi, bool limit_rate, const char *fmt, 
...);
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 3ff126316d42..6d160d50e14e 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -301,7 +301,7 @@ static unsigned int get_max_cost(struct f2fs_sb_info *sbi,
  
  	/* LFS */

if (p->gc_mode == GC_GREEDY)
-   return 2 * BLKS_PER_SEG(sbi) * p->ofs_unit;
+   return SEGS_TO_BLKS(sbi, 2 * p->ofs_unit);
else if (p->gc_mode == GC_CB)
return UINT_MAX;
else if (p->gc_mode == GC_AT)
@@ -347,7 +347,7 @@ static unsigned int get_cb_cost(struct f2fs_sb_info *sbi, 
unsigned int segno)
mtime = div_u64(mtime, SEGS_PER_SEC(sbi));
vblocks = div_u64(vblocks, SEGS_PER_SEC(sbi));
  
-	u = (vblocks * 100) >> sbi->log_blocks_per_seg;

+   u = BLKS_TO_SEGS(sbi, vblocks * 100);
  
  	/* Handle if the system time has changed by the user */

if (mtime < sit_i->min_mtime)
@@ -2060,7 +2060,7 @@ static void update_sb_metadata(struct f2fs_sb_info *sbi, 
int secs)
raw_sb->segment_count = cpu_to_le32(segment_count + segs);
raw_sb->segment_count_main = cpu_to_le32(segment_count_main + segs);
raw_sb->block_count = cpu_to_le64(block_count +
-   (long long)(segs << sbi->log_blocks_per_seg));
+   (long long)SEGS_TO_BLKS(sbi, segs))

[f2fs-dev] [PATCH][next] f2fs: Fix two spelling mistakes in f2fs_zone_status array

2024-02-29 Thread Colin Ian King
The array f2fs_zone_status contains two spelling mistakes in
literal strings. Fix them.

Signed-off-by: Colin Ian King 
---
 fs/f2fs/segment.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index bdb27e4a604b..072c4355d3d3 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -4921,8 +4921,8 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
 const char *f2fs_zone_status[BLK_ZONE_COND_OFFLINE + 1] = {
[BLK_ZONE_COND_NOT_WP]  = "NOT_WP",
[BLK_ZONE_COND_EMPTY]   = "EMPTY",
-   [BLK_ZONE_COND_IMP_OPEN]= "IMPLICITE_OPEN",
-   [BLK_ZONE_COND_EXP_OPEN]= "EXPLICITE_OPEN",
+   [BLK_ZONE_COND_IMP_OPEN]= "IMPLICIT_OPEN",
+   [BLK_ZONE_COND_EXP_OPEN]= "EXPLICIT_OPEN",
[BLK_ZONE_COND_CLOSED]  = "CLOSED",
[BLK_ZONE_COND_READONLY]= "READONLY",
[BLK_ZONE_COND_FULL]= "FULL",
-- 
2.39.2



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH] f2fs: introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup

2024-02-29 Thread Geert Uytterhoeven
Hi Chao,

On Wed, Feb 21, 2024 at 10:20 AM Chao Yu  wrote:
> Just cleanup, no functional change.
>
> Signed-off-by: Chao Yu 

Thanks for your patch, which is now commit 5fa6a97d27842dab ("f2fs:
introduce SEGS_TO_BLKS/BLKS_TO_SEGS for cleanup") in next-20240229.

nore...@ellerman.id.au reports several build failures on m68k.
http://kisskb.ellerman.id.au/kisskb/head/f303a3e2bcfba900efb5aee55236d17030e9f882/

E.g. m68k defconfig + CONFIG_F2FS_FS=y:

m68k-linux-gnu-ld: fs/f2fs/file.o: in function
`has_not_enough_free_secs.constprop.0':
file.c:(.text+0x19ee): undefined reference to `__moddi3'
m68k-linux-gnu-ld: file.c:(.text+0x1a22): undefined reference to `__divdi3'
m68k-linux-gnu-ld: fs/f2fs/file.o: in function `f2fs_ioc_defragment':
file.c:(.text+0x205a): undefined reference to `__divdi3'
m68k-linux-gnu-ld: fs/f2fs/inode.o: in function `f2fs_write_inode':
inode.c:(.text+0x1692): undefined reference to `__moddi3'
m68k-linux-gnu-ld: inode.c:(.text+0x16c0): undefined reference to `__divdi3'
m68k-linux-gnu-ld: fs/f2fs/namei.o: in function `f2fs_is_checkpoint_ready':
namei.c:(.text+0xa64): undefined reference to `__moddi3'
m68k-linux-gnu-ld: namei.c:(.text+0xa98): undefined reference to `__divdi3'
m68k-linux-gnu-ld: fs/f2fs/gc.o: in function
`has_not_enough_free_secs.constprop.0':
gc.c:(.text+0xe28): undefined reference to `__moddi3'
m68k-linux-gnu-ld: gc.c:(.text+0xe5c): undefined reference to `__divdi3'
m68k-linux-gnu-ld: fs/f2fs/gc.o: in function `f2fs_gc':
gc.c:(.text+0x2f2c): undefined reference to `__divdi3'
m68k-linux-gnu-ld: gc.c:(.text+0x2f58): undefined reference to `__divdi3'
m68k-linux-gnu-ld: gc.c:(.text+0x2f66): undefined reference to `__moddi3'
m68k-linux-gnu-ld: gc.c:(.text+0x2f96): undefined reference to `__moddi3'
m68k-linux-gnu-ld: fs/f2fs/data.o: in function
`has_not_enough_free_secs.constprop.0':
data.c:(.text+0xde8): undefined reference to `__moddi3'
m68k-linux-gnu-ld: data.c:(.text+0xe1c): undefined reference to `__divdi3'
m68k-linux-gnu-ld: fs/f2fs/segment.o: in function
`has_not_enough_free_secs.constprop.0':
segment.c:(.text+0x16ee): undefined reference to `__moddi3'
m68k-linux-gnu-ld: segment.c:(.text+0x1722): undefined reference to `__divdi3'
m68k-linux-gnu-ld: fs/f2fs/xattr.o: in function `f2fs_setxattr':
xattr.c:(.text+0xf5e): undefined reference to `__moddi3'
m68k-linux-gnu-ld: xattr.c:(.text+0xf8c): undefined reference to `__divdi3'

Other 32-bit architectures are affected, too, e.g. arm/shmobile_defconfig
+ CONFIG_F2FS_FS=y:

arm-linux-gnueabihf-ld: fs/f2fs/file.o: in function
`has_not_enough_free_secs.constprop.0':
file.c:(.text+0x1d40): undefined reference to `__aeabi_ldivmod'
arm-linux-gnueabihf-ld: file.c:(.text+0x1d5c): undefined reference to
`__aeabi_ldivmod'
arm-linux-gnueabihf-ld: fs/f2fs/file.o: in function `f2fs_defragment_range':
file.c:(.text+0x2018): undefined reference to `__aeabi_ldivmod'
arm-linux-gnueabihf-ld: fs/f2fs/inode.o: in function `f2fs_write_inode':
inode.c:(.text+0x19d4): undefined reference to `__aeabi_ldivmod'
arm-linux-gnueabihf-ld: inode.c:(.text+0x19f0): undefined reference to
`__aeabi_ldivmod'
arm-linux-gnueabihf-ld: fs/f2fs/namei.o:namei.c:(.text+0x12bc): more
undefined references to `__aeabi_ldivmod' follow

Manually reverting 5fa6a97d27842dab fixes the issue.

64-bit divisions (iff needed at all) must not be open-coded, but use
the helpers from  instead.

Gr{oetje,eeting}s,

Geert


--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel