162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * ocfs2_buffer_head.h
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Buffer cache handling functions defined
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (C) 2002, 2004 Oracle.  All rights reserved.
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef OCFS2_BUFFER_HEAD_IO_H
1162306a36Sopenharmony_ci#define OCFS2_BUFFER_HEAD_IO_H
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include <linux/buffer_head.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ciint ocfs2_write_block(struct ocfs2_super          *osb,
1662306a36Sopenharmony_ci		      struct buffer_head  *bh,
1762306a36Sopenharmony_ci		      struct ocfs2_caching_info   *ci);
1862306a36Sopenharmony_ciint ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
1962306a36Sopenharmony_ci			   unsigned int nr, struct buffer_head *bhs[]);
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci/*
2262306a36Sopenharmony_ci * If not NULL, validate() will be called on a buffer that is freshly
2362306a36Sopenharmony_ci * read from disk.  It will not be called if the buffer was in cache.
2462306a36Sopenharmony_ci * Note that if validate() is being used for this buffer, it needs to
2562306a36Sopenharmony_ci * be set even for a READAHEAD call, as it marks the buffer for later
2662306a36Sopenharmony_ci * validation.
2762306a36Sopenharmony_ci */
2862306a36Sopenharmony_ciint ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
2962306a36Sopenharmony_ci		      struct buffer_head *bhs[], int flags,
3062306a36Sopenharmony_ci		      int (*validate)(struct super_block *sb,
3162306a36Sopenharmony_ci				      struct buffer_head *bh));
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ciint ocfs2_write_super_or_backup(struct ocfs2_super *osb,
3462306a36Sopenharmony_ci				struct buffer_head *bh);
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#define OCFS2_BH_IGNORE_CACHE      1
3762306a36Sopenharmony_ci#define OCFS2_BH_READAHEAD         8
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_cistatic inline int ocfs2_read_block(struct ocfs2_caching_info *ci, u64 off,
4062306a36Sopenharmony_ci				   struct buffer_head **bh,
4162306a36Sopenharmony_ci				   int (*validate)(struct super_block *sb,
4262306a36Sopenharmony_ci						   struct buffer_head *bh))
4362306a36Sopenharmony_ci{
4462306a36Sopenharmony_ci	int status = 0;
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci	if (bh == NULL) {
4762306a36Sopenharmony_ci		printk("ocfs2: bh == NULL\n");
4862306a36Sopenharmony_ci		status = -EINVAL;
4962306a36Sopenharmony_ci		goto bail;
5062306a36Sopenharmony_ci	}
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci	status = ocfs2_read_blocks(ci, off, 1, bh, 0, validate);
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cibail:
5562306a36Sopenharmony_ci	return status;
5662306a36Sopenharmony_ci}
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#endif /* OCFS2_BUFFER_HEAD_IO_H */
59