[Ocfs2-tools-devel] [PATCH] Add extent flag as the paramter to
block iteration function,take 2
Tao Ma
tao.ma at oracle.com
Tue Oct 9 23:10:13 PDT 2007
Modification from V1 to V2:
Move the OCFS2_EXTENT_*, OCFS2_BLOCK_* flag / return code definitions
and ocfs2_extent_iterate{_inode}/ocfs2_block_iterate{_inode} prototypes to
the bottom of libocfs2/include/ocfs2.h?
Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
extras/set_random_bits.c | 1 +
fsck.ocfs2/pass1.c | 2 +
fswreck/symlink.c | 1 +
libocfs2/dir_iterate.c | 1 +
libocfs2/extents.c | 5 +-
libocfs2/fileio.c | 9 ++-
libocfs2/include/dir_iterate.h | 1 +
libocfs2/include/ocfs2.h | 185 +++++++++++++++++++++-------------------
8 files changed, 114 insertions(+), 91 deletions(-)
diff --git a/extras/set_random_bits.c b/extras/set_random_bits.c
index 6aeec98..23c1813 100644
--- a/extras/set_random_bits.c
+++ b/extras/set_random_bits.c
@@ -68,6 +68,7 @@ struct walk_block {
static int walk_blocks_func(ocfs2_filesys *fs,
uint64_t blkno,
uint64_t bcount,
+ uint16_t ext_flags,
void *priv_data)
{
struct walk_block *wb = priv_data;
diff --git a/fsck.ocfs2/pass1.c b/fsck.ocfs2/pass1.c
index 85ed239..c5bbf5b 100644
--- a/fsck.ocfs2/pass1.c
+++ b/fsck.ocfs2/pass1.c
@@ -683,6 +683,7 @@ static void check_link_data(struct verifying_blocks *vb)
static int verify_block(ocfs2_filesys *fs,
uint64_t blkno,
uint64_t bcount,
+ uint16_t ext_flags,
void *priv_data)
{
struct verifying_blocks *vb = priv_data;
@@ -721,6 +722,7 @@ static int verify_block(ocfs2_filesys *fs,
static int clear_block(ocfs2_filesys *fs,
uint64_t blkno,
uint64_t bcount,
+ uint16_t ext_flags,
void *priv_data)
{
struct verifying_blocks *vb = priv_data;
diff --git a/fswreck/symlink.c b/fswreck/symlink.c
index 390b8ec..e746374 100644
--- a/fswreck/symlink.c
+++ b/fswreck/symlink.c
@@ -37,6 +37,7 @@ extern char *progname;
static int fillup_block(ocfs2_filesys *fs,
uint64_t blkno,
uint64_t bcount,
+ uint16_t ext_flags,
void *priv_data)
{
errcode_t ret = 0;
diff --git a/libocfs2/dir_iterate.c b/libocfs2/dir_iterate.c
index 609cd97..a156ed0 100644
--- a/libocfs2/dir_iterate.c
+++ b/libocfs2/dir_iterate.c
@@ -145,6 +145,7 @@ extern errcode_t ocfs2_dir_iterate(ocfs2_filesys *fs,
int ocfs2_process_dir_block(ocfs2_filesys *fs,
uint64_t blocknr,
uint64_t blockcnt,
+ uint16_t ext_flags,
void *priv_data)
{
struct dir_context *ctx = (struct dir_context *) priv_data;
diff --git a/libocfs2/extents.c b/libocfs2/extents.c
index 8d176d1..50f3b6e 100644
--- a/libocfs2/extents.c
+++ b/libocfs2/extents.c
@@ -503,6 +503,7 @@ struct block_context {
int (*func)(ocfs2_filesys *fs,
uint64_t blkno,
uint64_t bcount,
+ uint16_t ext_flags,
void *priv_data);
int flags;
struct ocfs2_dinode *inode;
@@ -531,7 +532,7 @@ static int block_iterate_func(ocfs2_filesys *fs,
!(ctxt->flags & OCFS2_BLOCK_FLAG_APPEND))
break;
- iret = (*ctxt->func)(fs, blkno, bcount,
+ iret = (*ctxt->func)(fs, blkno, bcount, rec->e_flags,
ctxt->priv_data);
if (iret & OCFS2_BLOCK_ABORT)
break;
@@ -546,6 +547,7 @@ errcode_t ocfs2_block_iterate_inode(ocfs2_filesys *fs,
int (*func)(ocfs2_filesys *fs,
uint64_t blkno,
uint64_t bcount,
+ uint16_t ext_flags,
void *priv_data),
void *priv_data)
{
@@ -571,6 +573,7 @@ errcode_t ocfs2_block_iterate(ocfs2_filesys *fs,
int (*func)(ocfs2_filesys *fs,
uint64_t blkno,
uint64_t bcount,
+ uint16_t ext_flags,
void *priv_data),
void *priv_data)
{
diff --git a/libocfs2/fileio.c b/libocfs2/fileio.c
index 85730b2..d10d141 100644
--- a/libocfs2/fileio.c
+++ b/libocfs2/fileio.c
@@ -45,12 +45,17 @@ struct read_whole_context {
static int read_whole_func(ocfs2_filesys *fs,
uint64_t blkno,
uint64_t bcount,
+ uint16_t ext_flags,
void *priv_data)
{
struct read_whole_context *ctx = priv_data;
- ctx->errcode = io_read_block(fs->fs_io, blkno,
- 1, ctx->ptr);
+ if (ext_flags & OCFS2_EXT_UNWRITTEN) {
+ memset(ctx->ptr, 0, fs->fs_blocksize);
+ ctx->errcode = 0;
+ } else
+ ctx->errcode = io_read_block(fs->fs_io, blkno,
+ 1, ctx->ptr);
if (ctx->errcode)
return OCFS2_BLOCK_ABORT;
diff --git a/libocfs2/include/dir_iterate.h b/libocfs2/include/dir_iterate.h
index 5694386..9ec11a3 100644
--- a/libocfs2/include/dir_iterate.h
+++ b/libocfs2/include/dir_iterate.h
@@ -45,6 +45,7 @@ struct dir_context {
extern int ocfs2_process_dir_block(ocfs2_filesys *fs,
uint64_t blocknr,
uint64_t blockcnt,
+ uint16_t ext_flags,
void *priv_data);
#endif /* _DIR_ITERATE_H */
diff --git a/libocfs2/include/ocfs2.h b/libocfs2/include/ocfs2.h
index 120c8d9..56933d8 100644
--- a/libocfs2/include/ocfs2.h
+++ b/libocfs2/include/ocfs2.h
@@ -101,53 +101,6 @@
#define OCFS2_FLAG_HEARTBEAT_DEV_OK 0x40
#define OCFS2_FLAG_STRICT_COMPAT_CHECK 0x80
-/* Return flags for the extent iterator functions */
-#define OCFS2_EXTENT_CHANGED 0x01
-#define OCFS2_EXTENT_ABORT 0x02
-#define OCFS2_EXTENT_ERROR 0x04
-
-/*
- * Extent iterate flags
- *
- * OCFS2_EXTENT_FLAG_APPEND indicates that the iterator function should
- * be called on extents past the leaf next_free_rec. This is used by
- * ocfs2_expand_dir() to add a new extent to a directory (via
- * OCFS2_BLOCK_FLAG_APPEND and the block iteration functions).
- *
- * OCFS2_EXTENT_FLAG_DEPTH_TRAVERSE indicates that the iterator
- * function for tree_depth > 0 records (ocfs2_extent_blocks, iow)
- * should be called after all of the extents contained in the
- * extent_block are processed. This is useful if you are going to be
- * deallocating extents.
- *
- * OCFS2_EXTENT_FLAG_DATA_ONLY indicates that the iterator function
- * should be called for data extents (depth == 0) only.
- */
-#define OCFS2_EXTENT_FLAG_APPEND 0x01
-#define OCFS2_EXTENT_FLAG_DEPTH_TRAVERSE 0x02
-#define OCFS2_EXTENT_FLAG_DATA_ONLY 0x04
-
-
-/* Return flags for the block iterator functions */
-#define OCFS2_BLOCK_CHANGED 0x01
-#define OCFS2_BLOCK_ABORT 0x02
-#define OCFS2_BLOCK_ERROR 0x04
-
-/*
- * Block iterate flags
- *
- * In OCFS2, block iteration runs through the blocks contained in an
- * inode's data extents. As such, "DATA_ONLY" and "DEPTH_TRAVERSE"
- * can't really apply.
- *
- * OCFS2_BLOCK_FLAG_APPEND is as OCFS2_EXTENT_FLAG_APPEND, except on a
- * blocksize basis. This may mean that the underlying extent already
- * contains the space for a new block, and i_size is updated
- * accordingly.
- */
-#define OCFS2_BLOCK_FLAG_APPEND 0x01
-
-
/* Return flags for the directory iterator functions */
#define OCFS2_DIRENT_CHANGED 0x01
#define OCFS2_DIRENT_ABORT 0x02
@@ -320,47 +273,6 @@ errcode_t ocfs2_read_extent_block_nocheck(ocfs2_filesys *fs, uint64_t blkno,
char *eb_buf);
errcode_t ocfs2_write_extent_block(ocfs2_filesys *fs, uint64_t blkno,
char *eb_buf);
-errcode_t ocfs2_extent_iterate(ocfs2_filesys *fs,
- uint64_t blkno,
- int flags,
- char *block_buf,
- int (*func)(ocfs2_filesys *fs,
- struct ocfs2_extent_rec *rec,
- int tree_depth,
- uint32_t ccount,
- uint64_t ref_blkno,
- int ref_recno,
- void *priv_data),
- void *priv_data);
-errcode_t ocfs2_extent_iterate_inode(ocfs2_filesys *fs,
- struct ocfs2_dinode *inode,
- int flags,
- char *block_buf,
- int (*func)(ocfs2_filesys *fs,
- struct ocfs2_extent_rec *rec,
- int tree_depth,
- uint32_t ccount,
- uint64_t ref_blkno,
- int ref_recno,
- void *priv_data),
- void *priv_data);
-errcode_t ocfs2_block_iterate(ocfs2_filesys *fs,
- uint64_t blkno,
- int flags,
- int (*func)(ocfs2_filesys *fs,
- uint64_t blkno,
- uint64_t bcount,
- void *priv_data),
- void *priv_data);
-errcode_t ocfs2_block_iterate_inode(ocfs2_filesys *fs,
- struct ocfs2_dinode *inode,
- int flags,
- int (*func)(ocfs2_filesys *fs,
- uint64_t blkno,
- uint64_t bcount,
- void *priv_data),
- void *priv_data);
-
errcode_t ocfs2_swap_dir_entries_from_cpu(void *buf, uint64_t bytes);
errcode_t ocfs2_swap_dir_entries_to_cpu(void *buf, uint64_t bytes);
errcode_t ocfs2_read_dir_block(ocfs2_filesys *fs, uint64_t block,
@@ -805,4 +717,101 @@ static inline int ocfs2_writes_unwritten_extents(struct ocfs2_super_block *osb)
/* lifted from the kernel. include/linux/kernel.h */
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+/*
+ * DEPRECATED: Extent/block iterate functions.
+ *
+ * Do not use these for reading/writing regular files - they don't properly
+ * handle holes or inline data.
+ */
+
+/* Return flags for the extent iterator functions */
+#define OCFS2_EXTENT_CHANGED 0x01
+#define OCFS2_EXTENT_ABORT 0x02
+#define OCFS2_EXTENT_ERROR 0x04
+
+/*
+ * Extent iterate flags
+ *
+ * OCFS2_EXTENT_FLAG_APPEND indicates that the iterator function should
+ * be called on extents past the leaf next_free_rec. This is used by
+ * ocfs2_expand_dir() to add a new extent to a directory (via
+ * OCFS2_BLOCK_FLAG_APPEND and the block iteration functions).
+ *
+ * OCFS2_EXTENT_FLAG_DEPTH_TRAVERSE indicates that the iterator
+ * function for tree_depth > 0 records (ocfs2_extent_blocks, iow)
+ * should be called after all of the extents contained in the
+ * extent_block are processed. This is useful if you are going to be
+ * deallocating extents.
+ *
+ * OCFS2_EXTENT_FLAG_DATA_ONLY indicates that the iterator function
+ * should be called for data extents (depth == 0) only.
+ */
+#define OCFS2_EXTENT_FLAG_APPEND 0x01
+#define OCFS2_EXTENT_FLAG_DEPTH_TRAVERSE 0x02
+#define OCFS2_EXTENT_FLAG_DATA_ONLY 0x04
+
+
+/* Return flags for the block iterator functions */
+#define OCFS2_BLOCK_CHANGED 0x01
+#define OCFS2_BLOCK_ABORT 0x02
+#define OCFS2_BLOCK_ERROR 0x04
+
+/*
+ * Block iterate flags
+ *
+ * In OCFS2, block iteration runs through the blocks contained in an
+ * inode's data extents. As such, "DATA_ONLY" and "DEPTH_TRAVERSE"
+ * can't really apply.
+ *
+ * OCFS2_BLOCK_FLAG_APPEND is as OCFS2_EXTENT_FLAG_APPEND, except on a
+ * blocksize basis. This may mean that the underlying extent already
+ * contains the space for a new block, and i_size is updated
+ * accordingly.
+ */
+#define OCFS2_BLOCK_FLAG_APPEND 0x01
+
+errcode_t ocfs2_extent_iterate(ocfs2_filesys *fs,
+ uint64_t blkno,
+ int flags,
+ char *block_buf,
+ int (*func)(ocfs2_filesys *fs,
+ struct ocfs2_extent_rec *rec,
+ int tree_depth,
+ uint32_t ccount,
+ uint64_t ref_blkno,
+ int ref_recno,
+ void *priv_data),
+ void *priv_data);
+errcode_t ocfs2_extent_iterate_inode(ocfs2_filesys *fs,
+ struct ocfs2_dinode *inode,
+ int flags,
+ char *block_buf,
+ int (*func)(ocfs2_filesys *fs,
+ struct ocfs2_extent_rec *rec,
+ int tree_depth,
+ uint32_t ccount,
+ uint64_t ref_blkno,
+ int ref_recno,
+ void *priv_data),
+ void *priv_data);
+errcode_t ocfs2_block_iterate(ocfs2_filesys *fs,
+ uint64_t blkno,
+ int flags,
+ int (*func)(ocfs2_filesys *fs,
+ uint64_t blkno,
+ uint64_t bcount,
+ uint16_t ext_flags,
+ void *priv_data),
+ void *priv_data);
+errcode_t ocfs2_block_iterate_inode(ocfs2_filesys *fs,
+ struct ocfs2_dinode *inode,
+ int flags,
+ int (*func)(ocfs2_filesys *fs,
+ uint64_t blkno,
+ uint64_t bcount,
+ uint16_t ext_flags,
+ void *priv_data),
+ void *priv_data);
+
#endif /* _FILESYS_H */
More information about the Ocfs2-tools-devel
mailing list