[Ocfs2-tools-devel] [PATCH 4/5] Add "Set sparse flag" to
ocfs2-tools, take 2
Mark Fasheh
mark.fasheh at oracle.com
Tue Oct 30 23:07:01 PDT 2007
On Thu, Oct 25, 2007 at 03:37:57PM +0800, tao.ma wrote:
> +static errcode_t iterate_all_regular(ocfs2_filesys *fs, char *progname,
> + errcode_t (*func)(ocfs2_filesys *fs,
> + struct ocfs2_dinode *di))
> +{
> + errcode_t ret;
> + uint64_t blkno;
> + char *buf;
> + struct ocfs2_dinode *di;
> + ocfs2_inode_scan *scan;
> +
> + ret = ocfs2_malloc_block(fs->fs_io, &buf);
> + if (ret)
> + goto out;
> +
> + di = (struct ocfs2_dinode *)buf;
> +
> + ret = ocfs2_open_inode_scan(fs, &scan);
> + if (ret) {
> + com_err(progname, ret, "while opening inode scan");
> + goto out_free;
> + }
> +
> + for(;;) {
> + ret = ocfs2_get_next_inode(scan, &blkno, buf);
> + if (ret) {
> + com_err(progname, ret,
> + "while getting next inode");
> + break;
> + }
> + if (blkno == 0)
> + break;
> +
> + if (memcmp(di->i_signature, OCFS2_INODE_SIGNATURE,
> + strlen(OCFS2_INODE_SIGNATURE)))
> + continue;
> +
> + ocfs2_swap_inode_to_cpu(di);
> +
> + if (di->i_fs_generation != fs->fs_super->i_fs_generation)
> + continue;
> +
I think we also want to check OCFS2_VALID_FL here too - otherwise you'll
wind up doing work on deleted inodes.
> + if (di->i_flags & OCFS2_SYSTEM_FL)
> + continue;
> +
> + if (S_ISREG(di->i_mode) && func) {
> + ret = func(fs, di);
> + if (ret)
> + break;
> + }
> + }
> +
> + ocfs2_close_inode_scan(scan);
> +out_free:
> + ocfs2_free(&buf);
> +
> +out:
> + return ret;
> +}
> +
> +static errcode_t set_func(ocfs2_filesys *fs, struct ocfs2_dinode *di)
> +{
> + errcode_t ret;
> + ocfs2_cached_inode *ci = NULL;
> +
> + ret = ocfs2_read_cached_inode(fs, di->i_blkno, &ci);
> + if (ret)
> + goto out;
> +
> + ret = ocfs2_zero_tail_and_truncate(fs, ci, di->i_size, NULL);
Are we missing writeout of the inode block here, for the case where
i_clusters changed?
--Mark
--
Mark Fasheh
Senior Software Developer, Oracle
mark.fasheh at oracle.com
More information about the Ocfs2-tools-devel
mailing list