Skip to content

Commit 5699b7e

Browse files
Christoph Hellwigbrauner
authored andcommitted
iomap: build the writeback code without CONFIG_BLOCK
Allow fuse to use the iomap writeback code even when CONFIG_BLOCK is not enabled. Do this with an ifdef instead of a separate file to keep the iomap_folio_state local to buffered-io.c. Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Darrick J. Wong <[email protected]> Reviewed-by: Joanne Koong <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent c5690dd commit 5699b7e

File tree

2 files changed

+64
-55
lines changed

2 files changed

+64
-55
lines changed

fs/iomap/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ ccflags-y += -I $(src) # needed for trace events
99
obj-$(CONFIG_FS_IOMAP) += iomap.o
1010

1111
iomap-y += trace.o \
12-
iter.o
13-
iomap-$(CONFIG_BLOCK) += buffered-io.o \
14-
direct-io.o \
12+
iter.o \
13+
buffered-io.o
14+
iomap-$(CONFIG_BLOCK) += direct-io.o \
1515
ioend.o \
1616
fiemap.o \
1717
seek.o

fs/iomap/buffered-io.c

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,46 @@ static void iomap_adjust_read_range(struct inode *inode, struct folio *folio,
275275
*lenp = plen;
276276
}
277277

278+
static inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter,
279+
loff_t pos)
280+
{
281+
const struct iomap *srcmap = iomap_iter_srcmap(iter);
282+
283+
return srcmap->type != IOMAP_MAPPED ||
284+
(srcmap->flags & IOMAP_F_NEW) ||
285+
pos >= i_size_read(iter->inode);
286+
}
287+
288+
/**
289+
* iomap_read_inline_data - copy inline data into the page cache
290+
* @iter: iteration structure
291+
* @folio: folio to copy to
292+
*
293+
* Copy the inline data in @iter into @folio and zero out the rest of the folio.
294+
* Only a single IOMAP_INLINE extent is allowed at the end of each file.
295+
* Returns zero for success to complete the read, or the usual negative errno.
296+
*/
297+
static int iomap_read_inline_data(const struct iomap_iter *iter,
298+
struct folio *folio)
299+
{
300+
const struct iomap *iomap = iomap_iter_srcmap(iter);
301+
size_t size = i_size_read(iter->inode) - iomap->offset;
302+
size_t offset = offset_in_folio(folio, iomap->offset);
303+
304+
if (folio_test_uptodate(folio))
305+
return 0;
306+
307+
if (WARN_ON_ONCE(size > iomap->length))
308+
return -EIO;
309+
if (offset > 0)
310+
ifs_alloc(iter->inode, folio, iter->flags);
311+
312+
folio_fill_tail(folio, offset, iomap->inline_data, size);
313+
iomap_set_range_uptodate(folio, offset, folio_size(folio) - offset);
314+
return 0;
315+
}
316+
317+
#ifdef CONFIG_BLOCK
278318
static void iomap_finish_folio_read(struct folio *folio, size_t off,
279319
size_t len, int error)
280320
{
@@ -314,45 +354,6 @@ struct iomap_readpage_ctx {
314354
struct readahead_control *rac;
315355
};
316356

317-
/**
318-
* iomap_read_inline_data - copy inline data into the page cache
319-
* @iter: iteration structure
320-
* @folio: folio to copy to
321-
*
322-
* Copy the inline data in @iter into @folio and zero out the rest of the folio.
323-
* Only a single IOMAP_INLINE extent is allowed at the end of each file.
324-
* Returns zero for success to complete the read, or the usual negative errno.
325-
*/
326-
static int iomap_read_inline_data(const struct iomap_iter *iter,
327-
struct folio *folio)
328-
{
329-
const struct iomap *iomap = iomap_iter_srcmap(iter);
330-
size_t size = i_size_read(iter->inode) - iomap->offset;
331-
size_t offset = offset_in_folio(folio, iomap->offset);
332-
333-
if (folio_test_uptodate(folio))
334-
return 0;
335-
336-
if (WARN_ON_ONCE(size > iomap->length))
337-
return -EIO;
338-
if (offset > 0)
339-
ifs_alloc(iter->inode, folio, iter->flags);
340-
341-
folio_fill_tail(folio, offset, iomap->inline_data, size);
342-
iomap_set_range_uptodate(folio, offset, folio_size(folio) - offset);
343-
return 0;
344-
}
345-
346-
static inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter,
347-
loff_t pos)
348-
{
349-
const struct iomap *srcmap = iomap_iter_srcmap(iter);
350-
351-
return srcmap->type != IOMAP_MAPPED ||
352-
(srcmap->flags & IOMAP_F_NEW) ||
353-
pos >= i_size_read(iter->inode);
354-
}
355-
356357
static int iomap_readpage_iter(struct iomap_iter *iter,
357358
struct iomap_readpage_ctx *ctx)
358359
{
@@ -545,6 +546,27 @@ void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops)
545546
}
546547
EXPORT_SYMBOL_GPL(iomap_readahead);
547548

549+
static int iomap_read_folio_range(const struct iomap_iter *iter,
550+
struct folio *folio, loff_t pos, size_t len)
551+
{
552+
const struct iomap *srcmap = iomap_iter_srcmap(iter);
553+
struct bio_vec bvec;
554+
struct bio bio;
555+
556+
bio_init(&bio, srcmap->bdev, &bvec, 1, REQ_OP_READ);
557+
bio.bi_iter.bi_sector = iomap_sector(srcmap, pos);
558+
bio_add_folio_nofail(&bio, folio, len, offset_in_folio(folio, pos));
559+
return submit_bio_wait(&bio);
560+
}
561+
#else
562+
static int iomap_read_folio_range(const struct iomap_iter *iter,
563+
struct folio *folio, loff_t pos, size_t len)
564+
{
565+
WARN_ON_ONCE(1);
566+
return -EIO;
567+
}
568+
#endif /* CONFIG_BLOCK */
569+
548570
/*
549571
* iomap_is_partially_uptodate checks whether blocks within a folio are
550572
* uptodate or not.
@@ -658,19 +680,6 @@ iomap_write_failed(struct inode *inode, loff_t pos, unsigned len)
658680
pos + len - 1);
659681
}
660682

661-
static int iomap_read_folio_range(const struct iomap_iter *iter,
662-
struct folio *folio, loff_t pos, size_t len)
663-
{
664-
const struct iomap *srcmap = iomap_iter_srcmap(iter);
665-
struct bio_vec bvec;
666-
struct bio bio;
667-
668-
bio_init(&bio, srcmap->bdev, &bvec, 1, REQ_OP_READ);
669-
bio.bi_iter.bi_sector = iomap_sector(srcmap, pos);
670-
bio_add_folio_nofail(&bio, folio, len, offset_in_folio(folio, pos));
671-
return submit_bio_wait(&bio);
672-
}
673-
674683
static int __iomap_write_begin(const struct iomap_iter *iter,
675684
const struct iomap_write_ops *write_ops, size_t len,
676685
struct folio *folio)

0 commit comments

Comments
 (0)