Skip to content

Commit 26902be

Browse files
adam900710kdave
authored andcommitted
btrfs: remove the old btrfs_compress_folios() infrastructure
Since it's been replaced by btrfs_compress_bio(), remove all involved functions. Reviewed-by: Boris Burkov <boris@bur.io> Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 6f706f3 commit 26902be

6 files changed

Lines changed: 1 addition & 649 deletions

File tree

fs/btrfs/compression.c

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -86,37 +86,6 @@ bool btrfs_compress_is_valid_type(const char *str, size_t len)
8686
return false;
8787
}
8888

89-
static int compression_compress_pages(int type, struct list_head *ws,
90-
struct btrfs_inode *inode, u64 start,
91-
struct folio **folios, unsigned long *out_folios,
92-
unsigned long *total_in, unsigned long *total_out)
93-
{
94-
switch (type) {
95-
case BTRFS_COMPRESS_ZLIB:
96-
return zlib_compress_folios(ws, inode, start, folios,
97-
out_folios, total_in, total_out);
98-
case BTRFS_COMPRESS_LZO:
99-
return lzo_compress_folios(ws, inode, start, folios,
100-
out_folios, total_in, total_out);
101-
case BTRFS_COMPRESS_ZSTD:
102-
return zstd_compress_folios(ws, inode, start, folios,
103-
out_folios, total_in, total_out);
104-
case BTRFS_COMPRESS_NONE:
105-
default:
106-
/*
107-
* This can happen when compression races with remount setting
108-
* it to 'no compress', while caller doesn't call
109-
* inode_need_compress() to check if we really need to
110-
* compress.
111-
*
112-
* Not a big deal, just need to inform caller that we
113-
* haven't allocated any pages yet.
114-
*/
115-
*out_folios = 0;
116-
return -E2BIG;
117-
}
118-
}
119-
12089
static int compression_decompress_bio(struct list_head *ws,
12190
struct compressed_bio *cb)
12291
{
@@ -1023,45 +992,6 @@ int btrfs_compress_filemap_get_folio(struct address_space *mapping, u64 start,
1023992
return 0;
1024993
}
1025994

1026-
/*
1027-
* Given an address space and start and length, compress the bytes into @pages
1028-
* that are allocated on demand.
1029-
*
1030-
* @type_level is encoded algorithm and level, where level 0 means whatever
1031-
* default the algorithm chooses and is opaque here;
1032-
* - compression algo are 0-3
1033-
* - the level are bits 4-7
1034-
*
1035-
* @out_folios is an in/out parameter, holds maximum number of folios to allocate
1036-
* and returns number of actually allocated folios
1037-
*
1038-
* @total_in is used to return the number of bytes actually read. It
1039-
* may be smaller than the input length if we had to exit early because we
1040-
* ran out of room in the folios array or because we cross the
1041-
* max_out threshold.
1042-
*
1043-
* @total_out is an in/out parameter, must be set to the input length and will
1044-
* be also used to return the total number of compressed bytes
1045-
*/
1046-
int btrfs_compress_folios(unsigned int type, int level, struct btrfs_inode *inode,
1047-
u64 start, struct folio **folios, unsigned long *out_folios,
1048-
unsigned long *total_in, unsigned long *total_out)
1049-
{
1050-
struct btrfs_fs_info *fs_info = inode->root->fs_info;
1051-
const unsigned long orig_len = *total_out;
1052-
struct list_head *workspace;
1053-
int ret;
1054-
1055-
level = btrfs_compress_set_level(type, level);
1056-
workspace = get_workspace(fs_info, type, level);
1057-
ret = compression_compress_pages(type, workspace, inode, start, folios,
1058-
out_folios, total_in, total_out);
1059-
/* The total read-in bytes should be no larger than the input. */
1060-
ASSERT(*total_in <= orig_len);
1061-
put_workspace(fs_info, type, workspace);
1062-
return ret;
1063-
}
1064-
1065995
/*
1066996
* Given an address space and start and length, compress the page cache
1067997
* contents into @cb.

fs/btrfs/compression.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ int __init btrfs_init_compress(void);
9191
void __cold btrfs_exit_compress(void);
9292

9393
bool btrfs_compress_level_valid(unsigned int type, int level);
94-
int btrfs_compress_folios(unsigned int type, int level, struct btrfs_inode *inode,
95-
u64 start, struct folio **folios, unsigned long *out_folios,
96-
unsigned long *total_in, unsigned long *total_out);
9794
int btrfs_decompress(int type, const u8 *data_in, struct folio *dest_folio,
9895
unsigned long dest_pgoff, size_t srclen, size_t destlen);
9996
int btrfs_decompress_buf2page(const char *buf, u32 buf_len,
@@ -160,9 +157,6 @@ static inline void cleanup_compressed_bio(struct compressed_bio *cb)
160157
bio_put(bio);
161158
}
162159

163-
int zlib_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
164-
u64 start, struct folio **folios, unsigned long *out_folios,
165-
unsigned long *total_in, unsigned long *total_out);
166160
int zlib_compress_bio(struct list_head *ws, struct compressed_bio *cb);
167161
int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb);
168162
int zlib_decompress(struct list_head *ws, const u8 *data_in,
@@ -172,9 +166,6 @@ struct list_head *zlib_alloc_workspace(struct btrfs_fs_info *fs_info, unsigned i
172166
void zlib_free_workspace(struct list_head *ws);
173167
struct list_head *zlib_get_workspace(struct btrfs_fs_info *fs_info, unsigned int level);
174168

175-
int lzo_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
176-
u64 start, struct folio **folios, unsigned long *out_folios,
177-
unsigned long *total_in, unsigned long *total_out);
178169
int lzo_compress_bio(struct list_head *ws, struct compressed_bio *cb);
179170
int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb);
180171
int lzo_decompress(struct list_head *ws, const u8 *data_in,
@@ -183,9 +174,6 @@ int lzo_decompress(struct list_head *ws, const u8 *data_in,
183174
struct list_head *lzo_alloc_workspace(struct btrfs_fs_info *fs_info);
184175
void lzo_free_workspace(struct list_head *ws);
185176

186-
int zstd_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
187-
u64 start, struct folio **folios, unsigned long *out_folios,
188-
unsigned long *total_in, unsigned long *total_out);
189177
int zstd_compress_bio(struct list_head *ws, struct compressed_bio *cb);
190178
int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb);
191179
int zstd_decompress(struct list_head *ws, const u8 *data_in,

fs/btrfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ static void compress_file_range(struct btrfs_work *work)
966966
/*
967967
* All the folios should have been locked thus no failure.
968968
*
969-
* And even if some folios are missing, btrfs_compress_folios()
969+
* And even if some folios are missing, btrfs_compress_bio()
970970
* would handle them correctly, so here just do an ASSERT() check for
971971
* early logic errors.
972972
*/

fs/btrfs/lzo.c

Lines changed: 0 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -122,98 +122,6 @@ static inline size_t read_compress_length(const char *buf)
122122
return le32_to_cpu(dlen);
123123
}
124124

125-
/*
126-
* Will do:
127-
*
128-
* - Write a segment header into the destination
129-
* - Copy the compressed buffer into the destination
130-
* - Make sure we have enough space in the last sector to fit a segment header
131-
* If not, we will pad at most (LZO_LEN (4)) - 1 bytes of zeros.
132-
*
133-
* Will allocate new pages when needed.
134-
*/
135-
static int copy_compressed_data_to_page(struct btrfs_fs_info *fs_info,
136-
char *compressed_data,
137-
size_t compressed_size,
138-
struct folio **out_folios,
139-
unsigned long max_nr_folio,
140-
u32 *cur_out)
141-
{
142-
const u32 sectorsize = fs_info->sectorsize;
143-
const u32 min_folio_shift = PAGE_SHIFT + fs_info->block_min_order;
144-
u32 sector_bytes_left;
145-
u32 orig_out;
146-
struct folio *cur_folio;
147-
char *kaddr;
148-
149-
if ((*cur_out >> min_folio_shift) >= max_nr_folio)
150-
return -E2BIG;
151-
152-
/*
153-
* We never allow a segment header crossing sector boundary, previous
154-
* run should ensure we have enough space left inside the sector.
155-
*/
156-
ASSERT((*cur_out / sectorsize) == (*cur_out + LZO_LEN - 1) / sectorsize);
157-
158-
cur_folio = out_folios[*cur_out >> min_folio_shift];
159-
/* Allocate a new page */
160-
if (!cur_folio) {
161-
cur_folio = btrfs_alloc_compr_folio(fs_info);
162-
if (!cur_folio)
163-
return -ENOMEM;
164-
out_folios[*cur_out >> min_folio_shift] = cur_folio;
165-
}
166-
167-
kaddr = kmap_local_folio(cur_folio, offset_in_folio(cur_folio, *cur_out));
168-
write_compress_length(kaddr, compressed_size);
169-
*cur_out += LZO_LEN;
170-
171-
orig_out = *cur_out;
172-
173-
/* Copy compressed data */
174-
while (*cur_out - orig_out < compressed_size) {
175-
u32 copy_len = min_t(u32, sectorsize - *cur_out % sectorsize,
176-
orig_out + compressed_size - *cur_out);
177-
178-
kunmap_local(kaddr);
179-
180-
if ((*cur_out >> min_folio_shift) >= max_nr_folio)
181-
return -E2BIG;
182-
183-
cur_folio = out_folios[*cur_out >> min_folio_shift];
184-
/* Allocate a new page */
185-
if (!cur_folio) {
186-
cur_folio = btrfs_alloc_compr_folio(fs_info);
187-
if (!cur_folio)
188-
return -ENOMEM;
189-
out_folios[*cur_out >> min_folio_shift] = cur_folio;
190-
}
191-
kaddr = kmap_local_folio(cur_folio, 0);
192-
193-
memcpy(kaddr + offset_in_folio(cur_folio, *cur_out),
194-
compressed_data + *cur_out - orig_out, copy_len);
195-
196-
*cur_out += copy_len;
197-
}
198-
199-
/*
200-
* Check if we can fit the next segment header into the remaining space
201-
* of the sector.
202-
*/
203-
sector_bytes_left = round_up(*cur_out, sectorsize) - *cur_out;
204-
if (sector_bytes_left >= LZO_LEN || sector_bytes_left == 0)
205-
goto out;
206-
207-
/* The remaining size is not enough, pad it with zeros */
208-
memset(kaddr + offset_in_page(*cur_out), 0,
209-
sector_bytes_left);
210-
*cur_out += sector_bytes_left;
211-
212-
out:
213-
kunmap_local(kaddr);
214-
return 0;
215-
}
216-
217125
/*
218126
* Write data into @out_folio and queue it into @out_bio.
219127
*
@@ -365,102 +273,6 @@ static int copy_compressed_data_to_bio(struct btrfs_fs_info *fs_info,
365273
return write_and_queue_folio(out_bio, out_folio, total_out, sector_bytes_left);
366274
}
367275

368-
int lzo_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
369-
u64 start, struct folio **folios, unsigned long *out_folios,
370-
unsigned long *total_in, unsigned long *total_out)
371-
{
372-
struct btrfs_fs_info *fs_info = inode->root->fs_info;
373-
struct workspace *workspace = list_entry(ws, struct workspace, list);
374-
const u32 sectorsize = fs_info->sectorsize;
375-
const u32 min_folio_size = btrfs_min_folio_size(fs_info);
376-
struct address_space *mapping = inode->vfs_inode.i_mapping;
377-
struct folio *folio_in = NULL;
378-
char *sizes_ptr;
379-
const unsigned long max_nr_folio = *out_folios;
380-
int ret = 0;
381-
/* Points to the file offset of input data */
382-
u64 cur_in = start;
383-
/* Points to the current output byte */
384-
u32 cur_out = 0;
385-
u32 len = *total_out;
386-
387-
ASSERT(max_nr_folio > 0);
388-
*out_folios = 0;
389-
*total_out = 0;
390-
*total_in = 0;
391-
392-
/*
393-
* Skip the header for now, we will later come back and write the total
394-
* compressed size
395-
*/
396-
cur_out += LZO_LEN;
397-
while (cur_in < start + len) {
398-
char *data_in;
399-
const u32 sectorsize_mask = sectorsize - 1;
400-
u32 sector_off = (cur_in - start) & sectorsize_mask;
401-
u32 in_len;
402-
size_t out_len;
403-
404-
/* Get the input page first */
405-
if (!folio_in) {
406-
ret = btrfs_compress_filemap_get_folio(mapping, cur_in, &folio_in);
407-
if (ret < 0)
408-
goto out;
409-
}
410-
411-
/* Compress at most one sector of data each time */
412-
in_len = min_t(u32, start + len - cur_in, sectorsize - sector_off);
413-
ASSERT(in_len);
414-
data_in = kmap_local_folio(folio_in, offset_in_folio(folio_in, cur_in));
415-
ret = lzo1x_1_compress(data_in, in_len,
416-
workspace->cbuf, &out_len,
417-
workspace->mem);
418-
kunmap_local(data_in);
419-
if (unlikely(ret < 0)) {
420-
/* lzo1x_1_compress never fails. */
421-
ret = -EIO;
422-
goto out;
423-
}
424-
425-
ret = copy_compressed_data_to_page(fs_info, workspace->cbuf, out_len,
426-
folios, max_nr_folio,
427-
&cur_out);
428-
if (ret < 0)
429-
goto out;
430-
431-
cur_in += in_len;
432-
433-
/*
434-
* Check if we're making it bigger after two sectors. And if
435-
* it is so, give up.
436-
*/
437-
if (cur_in - start > sectorsize * 2 && cur_in - start < cur_out) {
438-
ret = -E2BIG;
439-
goto out;
440-
}
441-
442-
/* Check if we have reached folio boundary. */
443-
if (IS_ALIGNED(cur_in, min_folio_size)) {
444-
folio_put(folio_in);
445-
folio_in = NULL;
446-
}
447-
}
448-
449-
/* Store the size of all chunks of compressed data */
450-
sizes_ptr = kmap_local_folio(folios[0], 0);
451-
write_compress_length(sizes_ptr, cur_out);
452-
kunmap_local(sizes_ptr);
453-
454-
ret = 0;
455-
*total_out = cur_out;
456-
*total_in = cur_in - start;
457-
out:
458-
if (folio_in)
459-
folio_put(folio_in);
460-
*out_folios = DIV_ROUND_UP(cur_out, min_folio_size);
461-
return ret;
462-
}
463-
464276
int lzo_compress_bio(struct list_head *ws, struct compressed_bio *cb)
465277
{
466278
struct btrfs_inode *inode = cb->bbio.inode;

0 commit comments

Comments
 (0)