[Ocfs2-tools-devel] [PATCH 06/12] ocfs2-tools: swap inline xattr when swap inode
Tiger Yang
tiger.yang at oracle.com
Tue Mar 24 19:49:15 PDT 2009
This patch add swap inline xattr when we do
swap inode from/to cpu.
Signed-off-by: Tiger Yang <tiger.yang at oracle.com>
---
debugfs.ocfs2/dump.c | 3 ++-
debugfs.ocfs2/find_block_inode.c | 2 +-
extras/find_dup_extents.c | 2 +-
fsck.ocfs2/pass1.c | 2 +-
include/ocfs2/ocfs2.h | 4 ++--
libocfs2/inode.c | 18 ++++++++++++++----
libocfs2/openfs.c | 4 ++--
mkfs.ocfs2/mkfs.c | 4 ++--
tunefs.ocfs2/libocfs2ne.c | 2 +-
9 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/debugfs.ocfs2/dump.c b/debugfs.ocfs2/dump.c
index 371b87e..ee67bac 100644
--- a/debugfs.ocfs2/dump.c
+++ b/debugfs.ocfs2/dump.c
@@ -672,7 +672,8 @@ void dump_jbd_metadata (FILE *out, enum dump_block_type type, char *buf,
switch (type) {
case DUMP_BLOCK_INODE:
fprintf(out, "Inode\n");
- ocfs2_swap_inode_to_cpu((struct ocfs2_dinode *)buf);
+ ocfs2_swap_inode_to_cpu((struct ocfs2_dinode *)buf,
+ gbls.fs->fs_blocksize);
dump_inode (out, (struct ocfs2_dinode *)buf);
fprintf (out, "\n");
break;
diff --git a/debugfs.ocfs2/find_block_inode.c b/debugfs.ocfs2/find_block_inode.c
index a6c9754..1291afb 100644
--- a/debugfs.ocfs2/find_block_inode.c
+++ b/debugfs.ocfs2/find_block_inode.c
@@ -378,7 +378,7 @@ errcode_t find_block_inode(ocfs2_filesys *fs, uint64_t *blkno, int count,
strlen(OCFS2_INODE_SIGNATURE)))
continue;
- ocfs2_swap_inode_to_cpu(di);
+ ocfs2_swap_inode_to_cpu(di, fs->fs_blocksize);
if (di->i_fs_generation != fs->fs_super->i_fs_generation)
continue;
diff --git a/extras/find_dup_extents.c b/extras/find_dup_extents.c
index 1ce0f11..9263891 100644
--- a/extras/find_dup_extents.c
+++ b/extras/find_dup_extents.c
@@ -184,7 +184,7 @@ static errcode_t run_scan(struct walk_extents *we, int test)
strlen(OCFS2_INODE_SIGNATURE)))
continue;
- ocfs2_swap_inode_to_cpu(di);
+ ocfs2_swap_inode_to_cpu(di, we->fs->fs_blocksize);
if (!(di->i_flags & OCFS2_VALID_FL))
continue;
diff --git a/fsck.ocfs2/pass1.c b/fsck.ocfs2/pass1.c
index 209f8ff..fb5fd49 100644
--- a/fsck.ocfs2/pass1.c
+++ b/fsck.ocfs2/pass1.c
@@ -1370,7 +1370,7 @@ errcode_t o2fsck_pass1(o2fsck_state *ost)
if (!memcmp(di->i_signature, OCFS2_INODE_SIGNATURE,
strlen(OCFS2_INODE_SIGNATURE))) {
- ocfs2_swap_inode_to_cpu(di);
+ ocfs2_swap_inode_to_cpu(di, fs->fs_blocksize);
/* We only consider inodes whose generations don't
* match if the user has asked us to */
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 1e30f49..8144a90 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -251,8 +251,8 @@ errcode_t ocfs2_flush(ocfs2_filesys *fs);
errcode_t ocfs2_close(ocfs2_filesys *fs);
void ocfs2_freefs(ocfs2_filesys *fs);
-void ocfs2_swap_inode_from_cpu(struct ocfs2_dinode *di);
-void ocfs2_swap_inode_to_cpu(struct ocfs2_dinode *di);
+void ocfs2_swap_inode_from_cpu(struct ocfs2_dinode *di, size_t blocksize);
+void ocfs2_swap_inode_to_cpu(struct ocfs2_dinode *di, size_t blocksize);
errcode_t ocfs2_read_inode(ocfs2_filesys *fs, uint64_t blkno,
char *inode_buf);
errcode_t ocfs2_write_inode(ocfs2_filesys *fs, uint64_t blkno,
diff --git a/libocfs2/inode.c b/libocfs2/inode.c
index 2686aaa..e786f5e 100644
--- a/libocfs2/inode.c
+++ b/libocfs2/inode.c
@@ -214,11 +214,16 @@ static inline void ocfs2_swap_inline_dir(struct ocfs2_dinode *di,
ocfs2_swap_dir_entries_from_cpu(de_buf, bytes);
}
-void ocfs2_swap_inode_from_cpu(struct ocfs2_dinode *di)
+void ocfs2_swap_inode_from_cpu(struct ocfs2_dinode *di, size_t blocksize)
{
if (cpu_is_little_endian)
return;
+ if (di->i_dyn_features & OCFS2_INLINE_XATTR_FL) {
+ struct ocfs2_xattr_header *xh = (struct ocfs2_xattr_header *)
+ ((void *)di + blocksize - di->i_xattr_inline_size);
+ ocfs2_swap_xattrs_from_cpu(xh);
+ }
if (has_extents(di))
ocfs2_swap_extent_list_from_cpu(&di->id2.i_list);
if (di->i_dyn_features & OCFS2_INLINE_DATA_FL && S_ISDIR(di->i_mode))
@@ -228,7 +233,7 @@ void ocfs2_swap_inode_from_cpu(struct ocfs2_dinode *di)
ocfs2_swap_inode_first(di);
}
-void ocfs2_swap_inode_to_cpu(struct ocfs2_dinode *di)
+void ocfs2_swap_inode_to_cpu(struct ocfs2_dinode *di, size_t blocksize)
{
if (cpu_is_little_endian)
return;
@@ -240,6 +245,11 @@ void ocfs2_swap_inode_to_cpu(struct ocfs2_dinode *di)
ocfs2_swap_inline_dir(di, 1);
if (has_extents(di))
ocfs2_swap_extent_list_to_cpu(&di->id2.i_list);
+ if (di->i_dyn_features & OCFS2_INLINE_XATTR_FL) {
+ struct ocfs2_xattr_header *xh = (struct ocfs2_xattr_header *)
+ ((void *)di + blocksize - di->i_xattr_inline_size);
+ ocfs2_swap_xattrs_to_cpu(xh);
+ }
}
errcode_t ocfs2_read_inode(ocfs2_filesys *fs, uint64_t blkno,
@@ -274,7 +284,7 @@ errcode_t ocfs2_read_inode(ocfs2_filesys *fs, uint64_t blkno,
memcpy(inode_buf, blk, fs->fs_blocksize);
di = (struct ocfs2_dinode *) inode_buf;
- ocfs2_swap_inode_to_cpu(di);
+ ocfs2_swap_inode_to_cpu(di, fs->fs_blocksize);
ret = 0;
out:
@@ -304,7 +314,7 @@ errcode_t ocfs2_write_inode(ocfs2_filesys *fs, uint64_t blkno,
memcpy(blk, inode_buf, fs->fs_blocksize);
di = (struct ocfs2_dinode *)blk;
- ocfs2_swap_inode_from_cpu(di);
+ ocfs2_swap_inode_from_cpu(di, fs->fs_blocksize);
ocfs2_compute_meta_ecc(fs, blk, &di->i_check);
ret = io_write_block(fs->fs_io, blkno, 1, blk);
diff --git a/libocfs2/openfs.c b/libocfs2/openfs.c
index 0f6d048..538d859 100644
--- a/libocfs2/openfs.c
+++ b/libocfs2/openfs.c
@@ -137,7 +137,7 @@ errcode_t ocfs2_read_super(ocfs2_filesys *fs, uint64_t superblock, char *sb)
orig_blocksize = fs->fs_blocksize;
fs->fs_super = (struct ocfs2_dinode *)swapblk;
fs->fs_blocksize = blocksize;
- ocfs2_swap_inode_to_cpu(fs->fs_super);
+ ocfs2_swap_inode_to_cpu(fs->fs_super, fs->fs_blocksize);
ret = ocfs2_validate_meta_ecc(fs, blk, &di->i_check);
@@ -148,7 +148,7 @@ errcode_t ocfs2_read_super(ocfs2_filesys *fs, uint64_t superblock, char *sb)
if (ret)
goto out_blk;
- ocfs2_swap_inode_to_cpu(di);
+ ocfs2_swap_inode_to_cpu(di, fs->fs_blocksize);
if (!sb)
fs->fs_super = di;
else {
diff --git a/mkfs.ocfs2/mkfs.c b/mkfs.ocfs2/mkfs.c
index c9f6999..f5706e8 100644
--- a/mkfs.ocfs2/mkfs.c
+++ b/mkfs.ocfs2/mkfs.c
@@ -2018,7 +2018,7 @@ format_superblock(State *s, SystemFileDiskRecord *rec,
strcpy((char *)di->id2.i_super.s_label, s->vol_label);
memcpy(di->id2.i_super.s_uuid, s->uuid, 16);
- ocfs2_swap_inode_from_cpu(di);
+ ocfs2_swap_inode_from_cpu(di, s->blocksize);
mkfs_compute_meta_ecc(s, di, &di->i_check);
do_pwrite(s, di, s->blocksize, super_off);
free(di);
@@ -2184,7 +2184,7 @@ format_file(State *s, SystemFileDiskRecord *rec)
}
write_out:
- ocfs2_swap_inode_from_cpu(di);
+ ocfs2_swap_inode_from_cpu(di, s->blocksize);
mkfs_compute_meta_ecc(s, di, &di->i_check);
do_pwrite(s, di, s->blocksize, rec->fe_off);
free(di);
diff --git a/tunefs.ocfs2/libocfs2ne.c b/tunefs.ocfs2/libocfs2ne.c
index 3245089..c5362db 100644
--- a/tunefs.ocfs2/libocfs2ne.c
+++ b/tunefs.ocfs2/libocfs2ne.c
@@ -498,7 +498,7 @@ static errcode_t tunefs_validate_inode(ocfs2_filesys *fs,
strlen(OCFS2_INODE_SIGNATURE)))
return OCFS2_ET_BAD_INODE_MAGIC;
- ocfs2_swap_inode_to_cpu(di);
+ ocfs2_swap_inode_to_cpu(di, fs->fs_blocksize);
if (di->i_fs_generation != fs->fs_super->i_fs_generation)
return OCFS2_ET_INODE_NOT_VALID;
--
1.5.4.1
More information about the Ocfs2-tools-devel
mailing list