RE: [f2fs-dev] [PATCH] f2fs: avoid overflow when large directory feathure is enabled

2014-05-27 Thread Chao Yu
Hi changman,

> -Original Message-
> From: Changman Lee [mailto:cm224@samsung.com]
> Sent: Tuesday, May 27, 2014 2:23 PM
> To: Chao Yu
> Cc: Jaegeuk Kim; linux-fsde...@vger.kernel.org; linux-kernel@vger.kernel.org;
> linux-f2fs-de...@lists.sourceforge.net
> Subject: Re: [f2fs-dev] [PATCH] f2fs: avoid overflow when large directory 
> feathure is enabled
> 
> Hi, Chao
> Good catch. Please, modify Documentation/filesytems/f2fs.txt

Thank you for reminding me, I will add modification of f2fs.txt in the patch 
later.

> 
> On Tue, May 27, 2014 at 09:06:52AM +0800, Chao Yu wrote:
> > When large directory feathure is enable, We have one case which could cause
> > overflow in dir_buckets() as following:
> > special case: level + dir_level >= 32 and level < MAX_DIR_HASH_DEPTH / 2.
> >
> > Here we define MAX_DIR_BUCKETS to limit the return value when the condition
> > could trigger potential overflow.
> >
> > Signed-off-by: Chao Yu 
> > ---
> >  fs/f2fs/dir.c   |4 ++--
> >  include/linux/f2fs_fs.h |3 +++
> >  2 files changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
> > index c3f1485..966acb0 100644
> > --- a/fs/f2fs/dir.c
> > +++ b/fs/f2fs/dir.c
> > @@ -23,10 +23,10 @@ static unsigned long dir_blocks(struct inode *inode)
> >
> >  static unsigned int dir_buckets(unsigned int level, int dir_level)
> >  {
> > -   if (level < MAX_DIR_HASH_DEPTH / 2)
> > +   if (level + dir_level < MAX_DIR_HASH_DEPTH / 2)
> > return 1 << (level + dir_level);
> > else
> > -   return 1 << ((MAX_DIR_HASH_DEPTH / 2 + dir_level) - 1);
> > +   return MAX_DIR_BUCKETS;
> >  }
> >
> >  static unsigned int bucket_blocks(unsigned int level)
> > diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
> > index 8c03f71..ba6f312 100644
> > --- a/include/linux/f2fs_fs.h
> > +++ b/include/linux/f2fs_fs.h
> > @@ -394,6 +394,9 @@ typedef __le32  f2fs_hash_t;
> >  /* MAX level for dir lookup */
> >  #define MAX_DIR_HASH_DEPTH 63
> >
> > +/* MAX buckets in one level of dir */
> > +#define MAX_DIR_BUCKETS(1 << ((MAX_DIR_HASH_DEPTH / 2) - 1))
> > +
> >  #define SIZE_OF_DIR_ENTRY  11  /* by byte */
> >  #define SIZE_OF_DENTRY_BITMAP  ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 
> > 1) / \
> > BITS_PER_BYTE)
> > --
> > 1.7.10.4
> >
> >
> >
> > --
> > The best possible search technologies are now affordable for all companies.
> > Download your FREE open source Enterprise Search Engine today!
> > Our experts will assist you in its installation for $59/mo, no commitment.
> > Test it for FREE on our Cloud platform anytime!
> > http://pubads.g.doubleclick.net/gampad/clk?id=145328191=/4140/ostg.clktrk
> > ___
> > Linux-f2fs-devel mailing list
> > linux-f2fs-de...@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [f2fs-dev] [PATCH] f2fs: avoid overflow when large directory feathure is enabled

2014-05-27 Thread Changman Lee
Hi, Chao
Good catch. Please, modify Documentation/filesytems/f2fs.txt

On Tue, May 27, 2014 at 09:06:52AM +0800, Chao Yu wrote:
> When large directory feathure is enable, We have one case which could cause
> overflow in dir_buckets() as following:
> special case: level + dir_level >= 32 and level < MAX_DIR_HASH_DEPTH / 2.
> 
> Here we define MAX_DIR_BUCKETS to limit the return value when the condition
> could trigger potential overflow.
> 
> Signed-off-by: Chao Yu 
> ---
>  fs/f2fs/dir.c   |4 ++--
>  include/linux/f2fs_fs.h |3 +++
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
> index c3f1485..966acb0 100644
> --- a/fs/f2fs/dir.c
> +++ b/fs/f2fs/dir.c
> @@ -23,10 +23,10 @@ static unsigned long dir_blocks(struct inode *inode)
>  
>  static unsigned int dir_buckets(unsigned int level, int dir_level)
>  {
> - if (level < MAX_DIR_HASH_DEPTH / 2)
> + if (level + dir_level < MAX_DIR_HASH_DEPTH / 2)
>   return 1 << (level + dir_level);
>   else
> - return 1 << ((MAX_DIR_HASH_DEPTH / 2 + dir_level) - 1);
> + return MAX_DIR_BUCKETS;
>  }
>  
>  static unsigned int bucket_blocks(unsigned int level)
> diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
> index 8c03f71..ba6f312 100644
> --- a/include/linux/f2fs_fs.h
> +++ b/include/linux/f2fs_fs.h
> @@ -394,6 +394,9 @@ typedef __le32f2fs_hash_t;
>  /* MAX level for dir lookup */
>  #define MAX_DIR_HASH_DEPTH   63
>  
> +/* MAX buckets in one level of dir */
> +#define MAX_DIR_BUCKETS  (1 << ((MAX_DIR_HASH_DEPTH / 2) - 1))
> +
>  #define SIZE_OF_DIR_ENTRY11  /* by byte */
>  #define SIZE_OF_DENTRY_BITMAP((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 
> 1) / \
>   BITS_PER_BYTE)
> -- 
> 1.7.10.4
> 
> 
> 
> --
> The best possible search technologies are now affordable for all companies.
> Download your FREE open source Enterprise Search Engine today!
> Our experts will assist you in its installation for $59/mo, no commitment.
> Test it for FREE on our Cloud platform anytime!
> http://pubads.g.doubleclick.net/gampad/clk?id=145328191=/4140/ostg.clktrk
> ___
> Linux-f2fs-devel mailing list
> linux-f2fs-de...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [f2fs-dev] [PATCH] f2fs: avoid overflow when large directory feathure is enabled

2014-05-27 Thread Changman Lee
Hi, Chao
Good catch. Please, modify Documentation/filesytems/f2fs.txt

On Tue, May 27, 2014 at 09:06:52AM +0800, Chao Yu wrote:
 When large directory feathure is enable, We have one case which could cause
 overflow in dir_buckets() as following:
 special case: level + dir_level = 32 and level  MAX_DIR_HASH_DEPTH / 2.
 
 Here we define MAX_DIR_BUCKETS to limit the return value when the condition
 could trigger potential overflow.
 
 Signed-off-by: Chao Yu chao2...@samsung.com
 ---
  fs/f2fs/dir.c   |4 ++--
  include/linux/f2fs_fs.h |3 +++
  2 files changed, 5 insertions(+), 2 deletions(-)
 
 diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
 index c3f1485..966acb0 100644
 --- a/fs/f2fs/dir.c
 +++ b/fs/f2fs/dir.c
 @@ -23,10 +23,10 @@ static unsigned long dir_blocks(struct inode *inode)
  
  static unsigned int dir_buckets(unsigned int level, int dir_level)
  {
 - if (level  MAX_DIR_HASH_DEPTH / 2)
 + if (level + dir_level  MAX_DIR_HASH_DEPTH / 2)
   return 1  (level + dir_level);
   else
 - return 1  ((MAX_DIR_HASH_DEPTH / 2 + dir_level) - 1);
 + return MAX_DIR_BUCKETS;
  }
  
  static unsigned int bucket_blocks(unsigned int level)
 diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
 index 8c03f71..ba6f312 100644
 --- a/include/linux/f2fs_fs.h
 +++ b/include/linux/f2fs_fs.h
 @@ -394,6 +394,9 @@ typedef __le32f2fs_hash_t;
  /* MAX level for dir lookup */
  #define MAX_DIR_HASH_DEPTH   63
  
 +/* MAX buckets in one level of dir */
 +#define MAX_DIR_BUCKETS  (1  ((MAX_DIR_HASH_DEPTH / 2) - 1))
 +
  #define SIZE_OF_DIR_ENTRY11  /* by byte */
  #define SIZE_OF_DENTRY_BITMAP((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 
 1) / \
   BITS_PER_BYTE)
 -- 
 1.7.10.4
 
 
 
 --
 The best possible search technologies are now affordable for all companies.
 Download your FREE open source Enterprise Search Engine today!
 Our experts will assist you in its installation for $59/mo, no commitment.
 Test it for FREE on our Cloud platform anytime!
 http://pubads.g.doubleclick.net/gampad/clk?id=145328191iu=/4140/ostg.clktrk
 ___
 Linux-f2fs-devel mailing list
 linux-f2fs-de...@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [f2fs-dev] [PATCH] f2fs: avoid overflow when large directory feathure is enabled

2014-05-27 Thread Chao Yu
Hi changman,

 -Original Message-
 From: Changman Lee [mailto:cm224@samsung.com]
 Sent: Tuesday, May 27, 2014 2:23 PM
 To: Chao Yu
 Cc: Jaegeuk Kim; linux-fsde...@vger.kernel.org; linux-kernel@vger.kernel.org;
 linux-f2fs-de...@lists.sourceforge.net
 Subject: Re: [f2fs-dev] [PATCH] f2fs: avoid overflow when large directory 
 feathure is enabled
 
 Hi, Chao
 Good catch. Please, modify Documentation/filesytems/f2fs.txt

Thank you for reminding me, I will add modification of f2fs.txt in the patch 
later.

 
 On Tue, May 27, 2014 at 09:06:52AM +0800, Chao Yu wrote:
  When large directory feathure is enable, We have one case which could cause
  overflow in dir_buckets() as following:
  special case: level + dir_level = 32 and level  MAX_DIR_HASH_DEPTH / 2.
 
  Here we define MAX_DIR_BUCKETS to limit the return value when the condition
  could trigger potential overflow.
 
  Signed-off-by: Chao Yu chao2...@samsung.com
  ---
   fs/f2fs/dir.c   |4 ++--
   include/linux/f2fs_fs.h |3 +++
   2 files changed, 5 insertions(+), 2 deletions(-)
 
  diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
  index c3f1485..966acb0 100644
  --- a/fs/f2fs/dir.c
  +++ b/fs/f2fs/dir.c
  @@ -23,10 +23,10 @@ static unsigned long dir_blocks(struct inode *inode)
 
   static unsigned int dir_buckets(unsigned int level, int dir_level)
   {
  -   if (level  MAX_DIR_HASH_DEPTH / 2)
  +   if (level + dir_level  MAX_DIR_HASH_DEPTH / 2)
  return 1  (level + dir_level);
  else
  -   return 1  ((MAX_DIR_HASH_DEPTH / 2 + dir_level) - 1);
  +   return MAX_DIR_BUCKETS;
   }
 
   static unsigned int bucket_blocks(unsigned int level)
  diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
  index 8c03f71..ba6f312 100644
  --- a/include/linux/f2fs_fs.h
  +++ b/include/linux/f2fs_fs.h
  @@ -394,6 +394,9 @@ typedef __le32  f2fs_hash_t;
   /* MAX level for dir lookup */
   #define MAX_DIR_HASH_DEPTH 63
 
  +/* MAX buckets in one level of dir */
  +#define MAX_DIR_BUCKETS(1  ((MAX_DIR_HASH_DEPTH / 2) - 1))
  +
   #define SIZE_OF_DIR_ENTRY  11  /* by byte */
   #define SIZE_OF_DENTRY_BITMAP  ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 
  1) / \
  BITS_PER_BYTE)
  --
  1.7.10.4
 
 
 
  --
  The best possible search technologies are now affordable for all companies.
  Download your FREE open source Enterprise Search Engine today!
  Our experts will assist you in its installation for $59/mo, no commitment.
  Test it for FREE on our Cloud platform anytime!
  http://pubads.g.doubleclick.net/gampad/clk?id=145328191iu=/4140/ostg.clktrk
  ___
  Linux-f2fs-devel mailing list
  linux-f2fs-de...@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[f2fs-dev][PATCH] f2fs: avoid overflow when large directory feathure is enabled

2014-05-26 Thread Chao Yu
When large directory feathure is enable, We have one case which could cause
overflow in dir_buckets() as following:
special case: level + dir_level >= 32 and level < MAX_DIR_HASH_DEPTH / 2.

Here we define MAX_DIR_BUCKETS to limit the return value when the condition
could trigger potential overflow.

Signed-off-by: Chao Yu 
---
 fs/f2fs/dir.c   |4 ++--
 include/linux/f2fs_fs.h |3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index c3f1485..966acb0 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -23,10 +23,10 @@ static unsigned long dir_blocks(struct inode *inode)
 
 static unsigned int dir_buckets(unsigned int level, int dir_level)
 {
-   if (level < MAX_DIR_HASH_DEPTH / 2)
+   if (level + dir_level < MAX_DIR_HASH_DEPTH / 2)
return 1 << (level + dir_level);
else
-   return 1 << ((MAX_DIR_HASH_DEPTH / 2 + dir_level) - 1);
+   return MAX_DIR_BUCKETS;
 }
 
 static unsigned int bucket_blocks(unsigned int level)
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
index 8c03f71..ba6f312 100644
--- a/include/linux/f2fs_fs.h
+++ b/include/linux/f2fs_fs.h
@@ -394,6 +394,9 @@ typedef __le32  f2fs_hash_t;
 /* MAX level for dir lookup */
 #define MAX_DIR_HASH_DEPTH 63
 
+/* MAX buckets in one level of dir */
+#define MAX_DIR_BUCKETS(1 << ((MAX_DIR_HASH_DEPTH / 2) - 1))
+
 #define SIZE_OF_DIR_ENTRY  11  /* by byte */
 #define SIZE_OF_DENTRY_BITMAP  ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \
BITS_PER_BYTE)
-- 
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[f2fs-dev][PATCH] f2fs: avoid overflow when large directory feathure is enabled

2014-05-26 Thread Chao Yu
When large directory feathure is enable, We have one case which could cause
overflow in dir_buckets() as following:
special case: level + dir_level = 32 and level  MAX_DIR_HASH_DEPTH / 2.

Here we define MAX_DIR_BUCKETS to limit the return value when the condition
could trigger potential overflow.

Signed-off-by: Chao Yu chao2...@samsung.com
---
 fs/f2fs/dir.c   |4 ++--
 include/linux/f2fs_fs.h |3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index c3f1485..966acb0 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -23,10 +23,10 @@ static unsigned long dir_blocks(struct inode *inode)
 
 static unsigned int dir_buckets(unsigned int level, int dir_level)
 {
-   if (level  MAX_DIR_HASH_DEPTH / 2)
+   if (level + dir_level  MAX_DIR_HASH_DEPTH / 2)
return 1  (level + dir_level);
else
-   return 1  ((MAX_DIR_HASH_DEPTH / 2 + dir_level) - 1);
+   return MAX_DIR_BUCKETS;
 }
 
 static unsigned int bucket_blocks(unsigned int level)
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
index 8c03f71..ba6f312 100644
--- a/include/linux/f2fs_fs.h
+++ b/include/linux/f2fs_fs.h
@@ -394,6 +394,9 @@ typedef __le32  f2fs_hash_t;
 /* MAX level for dir lookup */
 #define MAX_DIR_HASH_DEPTH 63
 
+/* MAX buckets in one level of dir */
+#define MAX_DIR_BUCKETS(1  ((MAX_DIR_HASH_DEPTH / 2) - 1))
+
 #define SIZE_OF_DIR_ENTRY  11  /* by byte */
 #define SIZE_OF_DENTRY_BITMAP  ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \
BITS_PER_BYTE)
-- 
1.7.10.4


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/