erofs: preserve LZMA decoders on resize failure
PATCH 1/1 erofs: preserve LZMA decoders on resize failure
The pool-resize path frees each stream's old decoder before allocating its replacement. If an allocation fails after some streams have already been replaced, the failed stream is put back on the list with state == NULL. z_erofs_lzma_max_dictsize is still advanced as if the whole pool had been resized.
An existing LZMA mount can select the broken stream and pass NULL to xz_dec_microlzma_reset(). A retry at the same size also skip another resize attempt. Since the global maximum was advanced, thus, the invalid state is left unrepaired.
Allocate each replacement before freeing the old decoder, temporarily retaining one old decoder during allocation. Stop at the first failure and advance z_erofs_lzma_max_dictsize only after all streams satisfy the request.
Record each stream's dictionary capacity so retries can skip streams already enlarged before a partial failure.
--- fs/erofs/decompressor_lzma.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
fs/erofs/decompressor_lzma.c +14 -4
@@ -5,6 +5,7 @@struct z_erofs_lzma {struct z_erofs_lzma *next;struct xz_dec_microlzma *state; +unsigned int dict_size;u8 bounce[PAGE_SIZE ]; };
@@ -128,11 +129,19 @@ static int z_erofs_load_lzma_config(struct super_block *sb, err =0 ;/* 2. walk each isolated stream and grow max dict_size if needed */ for (strm = head; strm; strm = strm->next) { +struct xz_dec_microlzma *state; + +if (strm->dict_size >= dict_size) +continue ; + state =xz_dec_microlzma_alloc (XZ_PREALLOC , dict_size); +if (!state) { + err = -ENOMEM ; +break ; + }if (strm->state)xz_dec_microlzma_end (strm->state); - strm->state =xz_dec_microlzma_alloc (XZ_PREALLOC , dict_size); -if (!strm->state) - err = -ENOMEM ; + strm->state = state; + strm->dict_size = dict_size; }/* 3. push back all to the global list and update max dict_size */
@@ -142,7 +151,8 @@ static int z_erofs_load_lzma_config(struct super_block *sb,spin_unlock (&z_erofs_lzma_lock);wake_up_all (&z_erofs_lzma_wq); - z_erofs_lzma_max_dictsize = dict_size; +if (!err) + z_erofs_lzma_max_dictsize = dict_size;mutex_unlock (&lzma_resize_mutex);return err; }
base-commit: a7d28aa0e9b2c983b915d091f9596f0e3b253355
Signature · 1 line
2.43.0
Quoted 16 lines · Nikhil Gurudasani
The pool-resize path frees each stream's old decoder before allocating its replacement. If an allocation fails after some streams have already been replaced, the failed stream is put back on the list with state == NULL.
z_erofs_lzma_max_dictsizeis still advanced as if the whole pool had been resized.An existing LZMA mount can select the broken stream and pass NULL to
xz_dec_microlzma_reset(). A retry at the same size also skip another resize attempt. Since the global maximum was advanced, thus, the invalid state is left unrepaired.Allocate each replacement before freeing the old decoder, temporarily retaining one old decoder during allocation. Stop at the first failure and advance
z_erofs_lzma_max_dictsizeonly after all streams satisfy the request.
Quoted 6 lines
Record each stream's dictionary capacity so retries can skip streams already enlarged before a partial failure.
Fixes 622ceaddb764 ("erofs: lzma compression support")Signed-off-by Nikhil Gurudasani <[email protected]>
Thanks,
Gao Xiang