fs/gfs2/aops.c

Source file repositories/reference/linux-study-clean/fs/gfs2/aops.c

File Facts

System
Linux kernel
Corpus path
fs/gfs2/aops.c
Extension
.c
Size
19268 bytes
Lines
744
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

if (!folio_buffers(folio)) {
			create_empty_buffers(folio,
					inode->i_sb->s_blocksize,
					BIT(BH_Dirty)|BIT(BH_Uptodate));
		}
		gfs2_trans_add_databufs(ip->i_gl, folio, 0, folio_size(folio));
	}
	return gfs2_write_jdata_folio(folio, wbc);
}

/**
 * gfs2_jdata_writeback - Write jdata folios to the log
 * @mapping: The mapping to write
 * @wbc: The writeback control
 *
 * Returns: errno
 */
int gfs2_jdata_writeback(struct address_space *mapping, struct writeback_control *wbc)
{
	struct inode *inode = mapping->host;
	struct gfs2_inode *ip = GFS2_I(inode);
	struct gfs2_sbd *sdp = GFS2_SB(mapping->host);
	struct folio *folio = NULL;
	int error;

	BUG_ON(current->journal_info);
	if (gfs2_assert_withdraw(sdp, ip->i_gl->gl_state == LM_ST_EXCLUSIVE))
		return 0;

	while ((folio = writeback_iter(mapping, wbc, folio, &error))) {
		if (folio_test_checked(folio)) {
			folio_redirty_for_writepage(wbc, folio);
			folio_unlock(folio);
			continue;
		}
		error = __gfs2_jdata_write_folio(folio, wbc);
	}

	return error;
}

/**
 * gfs2_writepages - Write a bunch of dirty pages back to disk
 * @mapping: The mapping to write
 * @wbc: Write-back control
 *
 * Used for both ordered and writeback modes.
 */
static int gfs2_writepages(struct address_space *mapping,
			   struct writeback_control *wbc)
{
	struct gfs2_sbd *sdp = gfs2_mapping2sbd(mapping);
	long initial_nr_to_write = wbc->nr_to_write;
	struct iomap_writepage_ctx wpc = {
		.inode		= mapping->host,
		.wbc		= wbc,
		.ops		= &gfs2_writeback_ops,
	};
	int ret;

	/*
	 * Even if we didn't write any pages here, we might still be holding
	 * dirty pages in the ail. We forcibly flush the ail because we don't
	 * want balance_dirty_pages() to loop indefinitely trying to write out
	 * pages held in the ail that it can't find.
	 */
	ret = iomap_writepages(&wpc);
	if (ret == 0 && wbc->nr_to_write == initial_nr_to_write)
		set_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags);
	return ret;
}

/**
 * gfs2_write_jdata_batch - Write back a folio batch's worth of folios
 * @mapping: The mapping
 * @wbc: The writeback control
 * @fbatch: The batch of folios
 * @done_index: Page index
 *
 * Returns: non-zero if loop should terminate, zero otherwise
 */

static int gfs2_write_jdata_batch(struct address_space *mapping,
				    struct writeback_control *wbc,
				    struct folio_batch *fbatch,
				    pgoff_t *done_index)
{
	struct inode *inode = mapping->host;
	struct gfs2_sbd *sdp = GFS2_SB(inode);
	unsigned nrblocks;

Annotation

Implementation Notes