All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] btrfs-progs: fix page align issue for lzo compress in restore
@ 2014-09-22  8:58 Gui Hecheng
  2014-09-22 13:41 ` David Sterba
  0 siblings, 1 reply; 10+ messages in thread
From: Gui Hecheng @ 2014-09-22  8:58 UTC (permalink / raw)
  To: linux-btrfs; +Cc: marvin24, zooko, Gui Hecheng

When runing restore under lzo compression, "bad compress length"
problems are encountered.
It is because there is a page align problem with the @decompress_lzo,
as follows:
		|------| |----|-| |------|...|------|
		  page         ^    page       page
			       |
			  3 bytes left

	When lzo compress pages im RAM, lzo will ensure that
	the 4 bytes len will be in one page as a whole.
	There is a situation that 3 (or less) bytes are left
	at the end of a page, and then the 4 bytes len is
	stored at the start of the next page.
	But the @decompress_lzo doesn't goto the start of
	the next page and continue to read the next 4 bytes
	which is across two pages, so a random value is fetched
	as a "bad compress length".

So we check page alignment every time before we are going to
fetch the next @len and after the former piece of data is decompressed.
If the current page that we reach has less than 4 bytes left,
then we should fetch the next @len at the start of next page.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Reviewed-by: Marc Dietrich <marvin24@gmx.de>
---
changelog
	v1->v2: adopt alignment check method suggested by Marc
	v2->v3: make code more readable
---
 cmds-restore.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/cmds-restore.c b/cmds-restore.c
index 38a131e..5094b05 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -57,6 +57,9 @@ static int dry_run = 0;
 
 #define LZO_LEN 4
 #define PAGE_CACHE_SIZE 4096
+#define PAGE_CACHE_MASK (~(PAGE_CACHE_SIZE - 1))
+#define PAGE_CACHE_ALIGN(addr) (((addr) + PAGE_CACHE_SIZE - 1)	\
+							& PAGE_CACHE_MASK)
 #define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
 
 static int decompress_zlib(char *inbuf, char *outbuf, u64 compress_len,
@@ -93,6 +96,28 @@ static inline size_t read_compress_length(unsigned char *buf)
 	return le32_to_cpu(dlen);
 }
 
+static void align_if_need(size_t *tot_in, size_t *in_len)
+{
+	int tot_in_aligned;
+	int bytes_left;
+
+	tot_in_aligned = PAGE_CACHE_ALIGN(*tot_in);
+	bytes_left = tot_in_aligned - *tot_in;
+
+	if (bytes_left >= LZO_LEN)
+		return;
+
+	/*
+	 * The LZO_LEN bytes is guaranteed to be
+	 * in one page as a whole, so if a page
+	 * has fewer than LZO_LEN bytes left,
+	 * the LZO_LEN bytes should be fetched
+	 * at the start of the next page
+	 */
+	*in_len += bytes_left;
+	*tot_in = tot_in_aligned;
+}
+
 static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len,
 			  u64 *decompress_len)
 {
@@ -135,8 +160,8 @@ static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len,
 		}
 		out_len += new_len;
 		outbuf += new_len;
+		align_if_need(&tot_in, &in_len);
 		inbuf += in_len;
-		tot_in += in_len;
 	}
 
 	*decompress_len = out_len;
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] btrfs-progs: fix page align issue for lzo compress in restore
  2014-09-22  8:58 [PATCH v3] btrfs-progs: fix page align issue for lzo compress in restore Gui Hecheng
@ 2014-09-22 13:41 ` David Sterba
  2014-09-23  1:26   ` Gui Hecheng
                     ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: David Sterba @ 2014-09-22 13:41 UTC (permalink / raw)
  To: Gui Hecheng; +Cc: linux-btrfs, marvin24, zooko

On Mon, Sep 22, 2014 at 04:58:26PM +0800, Gui Hecheng wrote:
> So we check page alignment every time before we are going to
> fetch the next @len and after the former piece of data is decompressed.
> If the current page that we reach has less than 4 bytes left,
> then we should fetch the next @len at the start of next page.

Thanks for the fix.

> --- a/cmds-restore.c
> +++ b/cmds-restore.c
> @@ -57,6 +57,9 @@ static int dry_run = 0;
>  
>  #define LZO_LEN 4
>  #define PAGE_CACHE_SIZE 4096
> +#define PAGE_CACHE_MASK (~(PAGE_CACHE_SIZE - 1))
> +#define PAGE_CACHE_ALIGN(addr) (((addr) + PAGE_CACHE_SIZE - 1)	\
> +							& PAGE_CACHE_MASK)

This is not type-safe, the PAGE_CACHE_SIZE should be unsigned long.

>  #define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
>  
>  static int decompress_zlib(char *inbuf, char *outbuf, u64 compress_len,
> @@ -93,6 +96,28 @@ static inline size_t read_compress_length(unsigned char *buf)
>  	return le32_to_cpu(dlen);
>  }
>  
> +static void align_if_need(size_t *tot_in, size_t *in_len)
> +{
> +	int tot_in_aligned;
> +	int bytes_left;
> +
> +	tot_in_aligned = PAGE_CACHE_ALIGN(*tot_in);

size_t -> int, plus other tricks that happen inside the macro

> +	bytes_left = tot_in_aligned - *tot_in;

int = int - size_t

> +
> +	if (bytes_left >= LZO_LEN)
> +		return;
> +
> +	/*
> +	 * The LZO_LEN bytes is guaranteed to be
> +	 * in one page as a whole, so if a page
> +	 * has fewer than LZO_LEN bytes left,
> +	 * the LZO_LEN bytes should be fetched
> +	 * at the start of the next page
> +	 */

Nitpick, the comment can use the whole width of the line

	/*
	 * The LZO_LEN bytes is guaranteed to be in one page as a whole,
	 * so if a page has fewer than LZO_LEN bytes left, the LZO_LEN
	 * bytes should be fetched at the start of the next page
	 */

> +	*in_len += bytes_left;
> +	*tot_in = tot_in_aligned;
> +}

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] btrfs-progs: fix page align issue for lzo compress in restore
  2014-09-22 13:41 ` David Sterba
@ 2014-09-23  1:26   ` Gui Hecheng
  2014-09-23  2:25   ` [PATCH v4] " Gui Hecheng
  2014-09-23  8:34   ` Gui Hecheng
  2 siblings, 0 replies; 10+ messages in thread
From: Gui Hecheng @ 2014-09-23  1:26 UTC (permalink / raw)
  To: dsterba; +Cc: linux-btrfs, marvin24, zooko

On Mon, 2014-09-22 at 15:41 +0200, David Sterba wrote:
> On Mon, Sep 22, 2014 at 04:58:26PM +0800, Gui Hecheng wrote:
> > So we check page alignment every time before we are going to
> > fetch the next @len and after the former piece of data is decompressed.
> > If the current page that we reach has less than 4 bytes left,
> > then we should fetch the next @len at the start of next page.
> 
> Thanks for the fix.
> 
> > --- a/cmds-restore.c
> > +++ b/cmds-restore.c
> > @@ -57,6 +57,9 @@ static int dry_run = 0;
> >  
> >  #define LZO_LEN 4
> >  #define PAGE_CACHE_SIZE 4096
> > +#define PAGE_CACHE_MASK (~(PAGE_CACHE_SIZE - 1))
> > +#define PAGE_CACHE_ALIGN(addr) (((addr) + PAGE_CACHE_SIZE - 1)	\
> > +							& PAGE_CACHE_MASK)
> 
> This is not type-safe, the PAGE_CACHE_SIZE should be unsigned long.
> 
> >  #define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
> >  
> >  static int decompress_zlib(char *inbuf, char *outbuf, u64 compress_len,
> > @@ -93,6 +96,28 @@ static inline size_t read_compress_length(unsigned char *buf)
> >  	return le32_to_cpu(dlen);
> >  }
> >  
> > +static void align_if_need(size_t *tot_in, size_t *in_len)
> > +{
> > +	int tot_in_aligned;
> > +	int bytes_left;
> > +
> > +	tot_in_aligned = PAGE_CACHE_ALIGN(*tot_in);
> 
> size_t -> int, plus other tricks that happen inside the macro
> 
> > +	bytes_left = tot_in_aligned - *tot_in;
> 
> int = int - size_t
> 
> > +
> > +	if (bytes_left >= LZO_LEN)
> > +		return;
> > +
> > +	/*
> > +	 * The LZO_LEN bytes is guaranteed to be
> > +	 * in one page as a whole, so if a page
> > +	 * has fewer than LZO_LEN bytes left,
> > +	 * the LZO_LEN bytes should be fetched
> > +	 * at the start of the next page
> > +	 */
> 
> Nitpick, the comment can use the whole width of the line
> 
> 	/*
> 	 * The LZO_LEN bytes is guaranteed to be in one page as a whole,
> 	 * so if a page has fewer than LZO_LEN bytes left, the LZO_LEN
> 	 * bytes should be fetched at the start of the next page
> 	 */
> 
> > +	*in_len += bytes_left;
> > +	*tot_in = tot_in_aligned;
> > +}

Thanks David, I will pay more attention to the type-safe issue and
resend.

-Gui


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v4] btrfs-progs: fix page align issue for lzo compress in restore
  2014-09-22 13:41 ` David Sterba
  2014-09-23  1:26   ` Gui Hecheng
@ 2014-09-23  2:25   ` Gui Hecheng
  2014-09-23  8:25     ` Gui Hecheng
  2014-09-23  8:34   ` Gui Hecheng
  2 siblings, 1 reply; 10+ messages in thread
From: Gui Hecheng @ 2014-09-23  2:25 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba, Gui Hecheng

When runing restore under lzo compression, "bad compress length"
problems are encountered.
It is because there is a page align problem with the @decompress_lzo,
as follows:
		|------| |----|-| |------|...|------|
		  page         ^    page       page
			       |
			  3 bytes left

	When lzo compress pages im RAM, lzo will ensure that
	the 4 bytes len will be in one page as a whole.
	There is a situation that 3 (or less) bytes are left
	at the end of a page, and then the 4 bytes len is
	stored at the start of the next page.
	But the @decompress_lzo doesn't goto the start of
	the next page and continue to read the next 4 bytes
	which is across two pages, so a random value is fetched
	as a "bad compress length".

So we check page alignment every time before we are going to
fetch the next @len and after the former piece of data is decompressed.
If the current page that we reach has less than 4 bytes left,
then we should fetch the next @len at the start of next page.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Reviewed-by: Marc Dietrich <marvin24@gmx.de>
---
changelog
	v1->v2: adopt alignment check method suggested by Marc
	v2->v3: make code more readable
	v3->v4: keep type safety
---
 cmds-restore.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/cmds-restore.c b/cmds-restore.c
index 38a131e..fa5d5d1 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -56,7 +56,10 @@ static int get_xattrs = 0;
 static int dry_run = 0;
 
 #define LZO_LEN 4
-#define PAGE_CACHE_SIZE 4096
+#define PAGE_CACHE_SIZE 4096UL
+#define PAGE_CACHE_MASK (~(PAGE_CACHE_SIZE - 1))
+#define PAGE_CACHE_ALIGN(addr) (((addr) + PAGE_CACHE_SIZE - 1)	\
+							& PAGE_CACHE_MASK)
 #define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
 
 static int decompress_zlib(char *inbuf, char *outbuf, u64 compress_len,
@@ -93,6 +96,28 @@ static inline size_t read_compress_length(unsigned char *buf)
 	return le32_to_cpu(dlen);
 }
 
+static void align_if_need(size_t *tot_in, size_t *in_len)
+{
+	size_t tot_in_aligned;
+	size_t bytes_left;
+
+	tot_in_aligned = PAGE_CACHE_ALIGN(*tot_in);
+	bytes_left = tot_in_aligned - *tot_in;
+
+	if (bytes_left >= LZO_LEN)
+		return;
+
+	/*
+	 * The LZO_LEN bytes is guaranteed to be
+	 * in one page as a whole, so if a page
+	 * has fewer than LZO_LEN bytes left,
+	 * the LZO_LEN bytes should be fetched
+	 * at the start of the next page
+	 */
+	*in_len += bytes_left;
+	*tot_in = tot_in_aligned;
+}
+
 static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len,
 			  u64 *decompress_len)
 {
@@ -135,8 +160,8 @@ static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len,
 		}
 		out_len += new_len;
 		outbuf += new_len;
+		align_if_need(&tot_in, &in_len);
 		inbuf += in_len;
-		tot_in += in_len;
 	}
 
 	*decompress_len = out_len;
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v4] btrfs-progs: fix page align issue for lzo compress in restore
  2014-09-23  2:25   ` [PATCH v4] " Gui Hecheng
@ 2014-09-23  8:25     ` Gui Hecheng
  0 siblings, 0 replies; 10+ messages in thread
From: Gui Hecheng @ 2014-09-23  8:25 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

On Tue, 2014-09-23 at 10:25 +0800, Gui Hecheng wrote:
> When runing restore under lzo compression, "bad compress length"
> problems are encountered.
> It is because there is a page align problem with the @decompress_lzo,
> as follows:
> 		|------| |----|-| |------|...|------|
> 		  page         ^    page       page
> 			       |
> 			  3 bytes left
> 
> 	When lzo compress pages im RAM, lzo will ensure that
> 	the 4 bytes len will be in one page as a whole.
> 	There is a situation that 3 (or less) bytes are left
> 	at the end of a page, and then the 4 bytes len is
> 	stored at the start of the next page.
> 	But the @decompress_lzo doesn't goto the start of
> 	the next page and continue to read the next 4 bytes
> 	which is across two pages, so a random value is fetched
> 	as a "bad compress length".
> 
> So we check page alignment every time before we are going to
> fetch the next @len and after the former piece of data is decompressed.
> If the current page that we reach has less than 4 bytes left,
> then we should fetch the next @len at the start of next page.
> 
> Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
> Reviewed-by: Marc Dietrich <marvin24@gmx.de>
> ---
> changelog
> 	v1->v2: adopt alignment check method suggested by Marc
> 	v2->v3: make code more readable
> 	v3->v4: keep type safety
> ---
>  cmds-restore.c | 29 +++++++++++++++++++++++++++--
>  1 file changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git a/cmds-restore.c b/cmds-restore.c
> index 38a131e..fa5d5d1 100644
> --- a/cmds-restore.c
> +++ b/cmds-restore.c
> @@ -56,7 +56,10 @@ static int get_xattrs = 0;
>  static int dry_run = 0;
>  
>  #define LZO_LEN 4
> -#define PAGE_CACHE_SIZE 4096
> +#define PAGE_CACHE_SIZE 4096UL
> +#define PAGE_CACHE_MASK (~(PAGE_CACHE_SIZE - 1))
> +#define PAGE_CACHE_ALIGN(addr) (((addr) + PAGE_CACHE_SIZE - 1)	\
> +							& PAGE_CACHE_MASK)
>  #define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
>  
>  static int decompress_zlib(char *inbuf, char *outbuf, u64 compress_len,
> @@ -93,6 +96,28 @@ static inline size_t read_compress_length(unsigned char *buf)
>  	return le32_to_cpu(dlen);
>  }
>  
> +static void align_if_need(size_t *tot_in, size_t *in_len)
> +{
> +	size_t tot_in_aligned;
> +	size_t bytes_left;
> +
> +	tot_in_aligned = PAGE_CACHE_ALIGN(*tot_in);
> +	bytes_left = tot_in_aligned - *tot_in;
> +
> +	if (bytes_left >= LZO_LEN)
> +		return;
> +
> +	/*
> +	 * The LZO_LEN bytes is guaranteed to be
> +	 * in one page as a whole, so if a page
> +	 * has fewer than LZO_LEN bytes left,
> +	 * the LZO_LEN bytes should be fetched
> +	 * at the start of the next page
> +	 */
> +	*in_len += bytes_left;
> +	*tot_in = tot_in_aligned;
> +}
> +
>  static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len,
>  			  u64 *decompress_len)
>  {
> @@ -135,8 +160,8 @@ static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len,
>  		}
>  		out_len += new_len;
>  		outbuf += new_len;
> +		align_if_need(&tot_in, &in_len);
>  		inbuf += in_len;
> -		tot_in += in_len;
>  	}
>  
>  	*decompress_len = out_len;

Sorry, please scratch this one, the comments should be reformated. 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v4] btrfs-progs: fix page align issue for lzo compress in restore
  2014-09-22 13:41 ` David Sterba
  2014-09-23  1:26   ` Gui Hecheng
  2014-09-23  2:25   ` [PATCH v4] " Gui Hecheng
@ 2014-09-23  8:34   ` Gui Hecheng
  2014-10-14  8:06     ` Marc Dietrich
  2 siblings, 1 reply; 10+ messages in thread
From: Gui Hecheng @ 2014-09-23  8:34 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba, Gui Hecheng

When runing restore under lzo compression, "bad compress length"
problems are encountered.
It is because there is a page align problem with the @decompress_lzo,
as follows:
		|------| |----|-| |------|...|------|
		  page         ^    page       page
			       |
			  3 bytes left

	When lzo compress pages im RAM, lzo will ensure that
	the 4 bytes len will be in one page as a whole.
	There is a situation that 3 (or less) bytes are left
	at the end of a page, and then the 4 bytes len is
	stored at the start of the next page.
	But the @decompress_lzo doesn't goto the start of
	the next page and continue to read the next 4 bytes
	which is across two pages, so a random value is fetched
	as a "bad compress length".

So we check page alignment every time before we are going to
fetch the next @len and after the former piece of data is decompressed.
If the current page that we reach has less than 4 bytes left,
then we should fetch the next @len at the start of next page.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Reviewed-by: Marc Dietrich <marvin24@gmx.de>
---
changelog
	v1->v2: adopt alignment check method suggested by Marc
	v2->v3: make code more readable
	v3->v4: keep type safety & reformat comments
---
 cmds-restore.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/cmds-restore.c b/cmds-restore.c
index e09acc4..1fe2df0 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -56,7 +56,10 @@ static int get_xattrs = 0;
 static int dry_run = 0;
 
 #define LZO_LEN 4
-#define PAGE_CACHE_SIZE 4096
+#define PAGE_CACHE_SIZE 4096UL
+#define PAGE_CACHE_MASK (~(PAGE_CACHE_SIZE - 1))
+#define PAGE_CACHE_ALIGN(addr) (((addr) + PAGE_CACHE_SIZE - 1)	\
+							& PAGE_CACHE_MASK)
 #define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
 
 static int decompress_zlib(char *inbuf, char *outbuf, u64 compress_len,
@@ -93,6 +96,26 @@ static inline size_t read_compress_length(unsigned char *buf)
 	return le32_to_cpu(dlen);
 }
 
+static void align_if_need(size_t *tot_in, size_t *in_len)
+{
+	size_t tot_in_aligned;
+	size_t bytes_left;
+
+	tot_in_aligned = PAGE_CACHE_ALIGN(*tot_in);
+	bytes_left = tot_in_aligned - *tot_in;
+
+	if (bytes_left >= LZO_LEN)
+		return;
+
+	/*
+	 * The LZO_LEN bytes is guaranteed to be in one page as a whole,
+	 * so if a page has fewer than LZO_LEN bytes left, the LZO_LEN bytes
+	 * should be fetched at the start of the next page
+	 */
+	*in_len += bytes_left;
+	*tot_in = tot_in_aligned;
+}
+
 static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len,
 			  u64 *decompress_len)
 {
@@ -135,8 +158,8 @@ static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64 compress_len,
 		}
 		out_len += new_len;
 		outbuf += new_len;
+		align_if_need(&tot_in, &in_len);
 		inbuf += in_len;
-		tot_in += in_len;
 	}
 
 	*decompress_len = out_len;
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v4] btrfs-progs: fix page align issue for lzo compress in restore
  2014-09-23  8:34   ` Gui Hecheng
@ 2014-10-14  8:06     ` Marc Dietrich
  2014-10-14  9:32       ` David Sterba
  0 siblings, 1 reply; 10+ messages in thread
From: Marc Dietrich @ 2014-10-14  8:06 UTC (permalink / raw)
  To: Gui Hecheng; +Cc: linux-btrfs, dsterba

[-- Attachment #1: Type: text/plain, Size: 3160 bytes --]

This hasn't landed in an btrfs-progs branch I found. Any update?

Marc

Am Dienstag, 23. September 2014, 16:34:54 schrieb Gui Hecheng:
> When runing restore under lzo compression, "bad compress length"
> problems are encountered.
> It is because there is a page align problem with the @decompress_lzo,
> 
> as follows:
> 		|------| |----|-| |------|...|------|
> 
> 		  page         ^    page       page
> 
> 			  3 bytes left
> 
> 	When lzo compress pages im RAM, lzo will ensure that
> 	the 4 bytes len will be in one page as a whole.
> 	There is a situation that 3 (or less) bytes are left
> 	at the end of a page, and then the 4 bytes len is
> 	stored at the start of the next page.
> 	But the @decompress_lzo doesn't goto the start of
> 	the next page and continue to read the next 4 bytes
> 	which is across two pages, so a random value is fetched
> 	as a "bad compress length".
> 
> So we check page alignment every time before we are going to
> fetch the next @len and after the former piece of data is decompressed.
> If the current page that we reach has less than 4 bytes left,
> then we should fetch the next @len at the start of next page.
> 
> Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
> Reviewed-by: Marc Dietrich <marvin24@gmx.de>
> ---
> changelog
> 	v1->v2: adopt alignment check method suggested by Marc
> 	v2->v3: make code more readable
> 	v3->v4: keep type safety & reformat comments
> ---
>  cmds-restore.c | 27 +++++++++++++++++++++++++--
>  1 file changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/cmds-restore.c b/cmds-restore.c
> index e09acc4..1fe2df0 100644
> --- a/cmds-restore.c
> +++ b/cmds-restore.c
> @@ -56,7 +56,10 @@ static int get_xattrs = 0;
>  static int dry_run = 0;
> 
>  #define LZO_LEN 4
> -#define PAGE_CACHE_SIZE 4096
> +#define PAGE_CACHE_SIZE 4096UL
> +#define PAGE_CACHE_MASK (~(PAGE_CACHE_SIZE - 1))
> +#define PAGE_CACHE_ALIGN(addr) (((addr) + PAGE_CACHE_SIZE - 1)	\
> +							& PAGE_CACHE_MASK)
>  #define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
> 
>  static int decompress_zlib(char *inbuf, char *outbuf, u64 compress_len,
> @@ -93,6 +96,26 @@ static inline size_t read_compress_length(unsigned char
> *buf) return le32_to_cpu(dlen);
>  }
> 
> +static void align_if_need(size_t *tot_in, size_t *in_len)
> +{
> +	size_t tot_in_aligned;
> +	size_t bytes_left;
> +
> +	tot_in_aligned = PAGE_CACHE_ALIGN(*tot_in);
> +	bytes_left = tot_in_aligned - *tot_in;
> +
> +	if (bytes_left >= LZO_LEN)
> +		return;
> +
> +	/*
> +	 * The LZO_LEN bytes is guaranteed to be in one page as a whole,
> +	 * so if a page has fewer than LZO_LEN bytes left, the LZO_LEN bytes
> +	 * should be fetched at the start of the next page
> +	 */
> +	*in_len += bytes_left;
> +	*tot_in = tot_in_aligned;
> +}
> +
>  static int decompress_lzo(unsigned char *inbuf, char *outbuf, u64
> compress_len, u64 *decompress_len)
>  {
> @@ -135,8 +158,8 @@ static int decompress_lzo(unsigned char *inbuf, char
> *outbuf, u64 compress_len, }
>  		out_len += new_len;
>  		outbuf += new_len;
> +		align_if_need(&tot_in, &in_len);
>  		inbuf += in_len;
> -		tot_in += in_len;
>  	}
> 
>  	*decompress_len = out_len;

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4] btrfs-progs: fix page align issue for lzo compress in restore
  2014-10-14  8:06     ` Marc Dietrich
@ 2014-10-14  9:32       ` David Sterba
  2014-11-27  3:02         ` Gui Hecheng
  0 siblings, 1 reply; 10+ messages in thread
From: David Sterba @ 2014-10-14  9:32 UTC (permalink / raw)
  To: Marc Dietrich; +Cc: Gui Hecheng, linux-btrfs, dsterba

On Tue, Oct 14, 2014 at 10:06:16AM +0200, Marc Dietrich wrote:
> This hasn't landed in an btrfs-progs branch I found. Any update?

I had it tagged for review and found something that needs fixing. The
PAGE_CACHE_SIZE is hardcoded to 4k, this will break on filesystems with
larger sectors (eg. the powerpc machines). I'll scheudule the patch post
3.17, with a fix.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4] btrfs-progs: fix page align issue for lzo compress in restore
  2014-10-14  9:32       ` David Sterba
@ 2014-11-27  3:02         ` Gui Hecheng
  2015-01-02 15:09           ` David Sterba
  0 siblings, 1 reply; 10+ messages in thread
From: Gui Hecheng @ 2014-11-27  3:02 UTC (permalink / raw)
  To: dsterba; +Cc: linux-btrfs

On Tue, 2014-10-14 at 11:32 +0200, David Sterba wrote:
> On Tue, Oct 14, 2014 at 10:06:16AM +0200, Marc Dietrich wrote:
> > This hasn't landed in an btrfs-progs branch I found. Any update?
> 
> I had it tagged for review and found something that needs fixing. The
> PAGE_CACHE_SIZE is hardcoded to 4k, this will break on filesystems with
> larger sectors (eg. the powerpc machines). I'll scheudule the patch post
> 3.17, with a fix.

Hi David,

I note that this patch is not yet in the latest integration, how's the
fix going?

-Gui


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4] btrfs-progs: fix page align issue for lzo compress in restore
  2014-11-27  3:02         ` Gui Hecheng
@ 2015-01-02 15:09           ` David Sterba
  0 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2015-01-02 15:09 UTC (permalink / raw)
  To: Gui Hecheng; +Cc: dsterba, linux-btrfs

On Thu, Nov 27, 2014 at 11:02:38AM +0800, Gui Hecheng wrote:
> I note that this patch is not yet in the latest integration, how's the
> fix going?

The patch was still buggy, a fix will land in 3.18.1

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-01-02 15:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-22  8:58 [PATCH v3] btrfs-progs: fix page align issue for lzo compress in restore Gui Hecheng
2014-09-22 13:41 ` David Sterba
2014-09-23  1:26   ` Gui Hecheng
2014-09-23  2:25   ` [PATCH v4] " Gui Hecheng
2014-09-23  8:25     ` Gui Hecheng
2014-09-23  8:34   ` Gui Hecheng
2014-10-14  8:06     ` Marc Dietrich
2014-10-14  9:32       ` David Sterba
2014-11-27  3:02         ` Gui Hecheng
2015-01-02 15:09           ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.