diff options
author | Phillip Lougher <phillip@squashfs.org.uk> | 2013-11-12 21:56:26 -0500 |
---|---|---|
committer | Phillip Lougher <phillip@squashfs.org.uk> | 2013-11-19 22:35:18 -0500 |
commit | 9508c6b90b3f57ecea4e7a896cf8325400fc0c6e (patch) | |
tree | a31589009d7d85d722b52c0ef21838ca6d2888da /fs/squashfs/zlib_wrapper.c | |
parent | 959f58544b7f20c92d5eb43d1232c96c15c01bfb (diff) |
Squashfs: Refactor decompressor interface and code
The decompressor interface and code was written from
the point of view of single-threaded operation. In doing
so it mixed a lot of single-threaded implementation specific
aspects into the decompressor code and elsewhere which makes it
difficult to seamlessly support multiple different decompressor
implementations.
This patch does the following:
1. It removes compressor_options parsing from the decompressor
init() function. This allows the decompressor init() function
to be dynamically called to instantiate multiple decompressors,
without the compressor options needing to be read and parsed each
time.
2. It moves threading and all sleeping operations out of the
decompressors. In doing so, it makes the decompressors
non-blocking wrappers which only deal with interfacing with
the decompressor implementation.
3. It splits decompressor.[ch] into decompressor generic functions
in decompressor.[ch], and moves the single threaded
decompressor implementation into decompressor_single.c.
The result of this patch is Squashfs should now be able to
support multiple decompressors by adding new decompressor_xxx.c
files with specialised implementations of the functions in
decompressor_single.c
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
Reviewed-by: Minchan Kim <minchan@kernel.org>
Diffstat (limited to 'fs/squashfs/zlib_wrapper.c')
-rw-r--r-- | fs/squashfs/zlib_wrapper.c | 50 |
1 files changed, 15 insertions, 35 deletions
diff --git a/fs/squashfs/zlib_wrapper.c b/fs/squashfs/zlib_wrapper.c index 55d918fd2d86..bb049027d15c 100644 --- a/fs/squashfs/zlib_wrapper.c +++ b/fs/squashfs/zlib_wrapper.c | |||
@@ -33,7 +33,7 @@ | |||
33 | #include "squashfs.h" | 33 | #include "squashfs.h" |
34 | #include "decompressor.h" | 34 | #include "decompressor.h" |
35 | 35 | ||
36 | static void *zlib_init(struct squashfs_sb_info *dummy, void *buff, int len) | 36 | static void *zlib_init(struct squashfs_sb_info *dummy, void *buff) |
37 | { | 37 | { |
38 | z_stream *stream = kmalloc(sizeof(z_stream), GFP_KERNEL); | 38 | z_stream *stream = kmalloc(sizeof(z_stream), GFP_KERNEL); |
39 | if (stream == NULL) | 39 | if (stream == NULL) |
@@ -61,15 +61,13 @@ static void zlib_free(void *strm) | |||
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
64 | static int zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer, | 64 | static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm, |
65 | struct buffer_head **bh, int b, int offset, int length, int srclength, | 65 | void **buffer, struct buffer_head **bh, int b, int offset, int length, |
66 | int pages) | 66 | int srclength, int pages) |
67 | { | 67 | { |
68 | int zlib_err, zlib_init = 0; | 68 | int zlib_err, zlib_init = 0; |
69 | int k = 0, page = 0; | 69 | int k = 0, page = 0; |
70 | z_stream *stream = msblk->stream; | 70 | z_stream *stream = strm; |
71 | |||
72 | mutex_lock(&msblk->read_data_mutex); | ||
73 | 71 | ||
74 | stream->avail_out = 0; | 72 | stream->avail_out = 0; |
75 | stream->avail_in = 0; | 73 | stream->avail_in = 0; |
@@ -78,10 +76,6 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer, | |||
78 | if (stream->avail_in == 0 && k < b) { | 76 | if (stream->avail_in == 0 && k < b) { |
79 | int avail = min(length, msblk->devblksize - offset); | 77 | int avail = min(length, msblk->devblksize - offset); |
80 | length -= avail; | 78 | length -= avail; |
81 | wait_on_buffer(bh[k]); | ||
82 | if (!buffer_uptodate(bh[k])) | ||
83 | goto release_mutex; | ||
84 | |||
85 | stream->next_in = bh[k]->b_data + offset; | 79 | stream->next_in = bh[k]->b_data + offset; |
86 | stream->avail_in = avail; | 80 | stream->avail_in = avail; |
87 | offset = 0; | 81 | offset = 0; |
@@ -94,12 +88,8 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer, | |||
94 | 88 | ||
95 | if (!zlib_init) { | 89 | if (!zlib_init) { |
96 | zlib_err = zlib_inflateInit(stream); | 90 | zlib_err = zlib_inflateInit(stream); |
97 | if (zlib_err != Z_OK) { | 91 | if (zlib_err != Z_OK) |
98 | ERROR("zlib_inflateInit returned unexpected " | 92 | goto out; |
99 | "result 0x%x, srclength %d\n", | ||
100 | zlib_err, srclength); | ||
101 | goto release_mutex; | ||
102 | } | ||
103 | zlib_init = 1; | 93 | zlib_init = 1; |
104 | } | 94 | } |
105 | 95 | ||
@@ -109,29 +99,19 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer, | |||
109 | put_bh(bh[k++]); | 99 | put_bh(bh[k++]); |
110 | } while (zlib_err == Z_OK); | 100 | } while (zlib_err == Z_OK); |
111 | 101 | ||
112 | if (zlib_err != Z_STREAM_END) { | 102 | if (zlib_err != Z_STREAM_END) |
113 | ERROR("zlib_inflate error, data probably corrupt\n"); | 103 | goto out; |
114 | goto release_mutex; | ||
115 | } | ||
116 | 104 | ||
117 | zlib_err = zlib_inflateEnd(stream); | 105 | zlib_err = zlib_inflateEnd(stream); |
118 | if (zlib_err != Z_OK) { | 106 | if (zlib_err != Z_OK) |
119 | ERROR("zlib_inflate error, data probably corrupt\n"); | 107 | goto out; |
120 | goto release_mutex; | ||
121 | } | ||
122 | |||
123 | if (k < b) { | ||
124 | ERROR("zlib_uncompress error, data remaining\n"); | ||
125 | goto release_mutex; | ||
126 | } | ||
127 | 108 | ||
128 | length = stream->total_out; | 109 | if (k < b) |
129 | mutex_unlock(&msblk->read_data_mutex); | 110 | goto out; |
130 | return length; | ||
131 | 111 | ||
132 | release_mutex: | 112 | return stream->total_out; |
133 | mutex_unlock(&msblk->read_data_mutex); | ||
134 | 113 | ||
114 | out: | ||
135 | for (; k < b; k++) | 115 | for (; k < b; k++) |
136 | put_bh(bh[k]); | 116 | put_bh(bh[k]); |
137 | 117 | ||