[Ocfs2-tools-devel] [PATCH 8/9] ocfs2-tools: add xattr support in tunefs.ocfs2

Joel Becker Joel.Becker at oracle.com
Fri Feb 13 15:20:55 PST 2009


On Sun, Feb 01, 2009 at 10:14:20AM +0800, Tiger Yang wrote:
> Joel Becker wrote:
>> 	This looks good, though it needs progress support.  If you fix
>> up fsck, I'll do the progress support here if you want.  We're almost
>> there!
>
> Thanks, Please help me fix this patch for tunefs, I am going to fix fsck.

	Here is the patch for progress display in tunefs.  Compiled, but
not tested.

Joel

diff --git a/tunefs.ocfs2/feature_xattr.c b/tunefs.ocfs2/feature_xattr.c
index fa70c64..fda3b17 100644
--- a/tunefs.ocfs2/feature_xattr.c
+++ b/tunefs.ocfs2/feature_xattr.c
@@ -35,6 +35,8 @@ struct xattr_inode {
 struct xattr_context {
 	errcode_t ret;
 	struct list_head inodes;
+	struct tools_progress *prog;
+	uint64_t inode_count;
 };
 
 static void empty_xattr_context(struct xattr_context *ctxt)
@@ -258,6 +260,12 @@ static errcode_t remove_xattr(ocfs2_filesys *fs,
 	struct xattr_inode *xdi;
 	struct ocfs2_dinode *di = NULL;
 	ocfs2_cached_inode *ci = NULL;
+	struct tools_progress *prog = NULL;
+
+	prog = tools_progress_start("Removing xattrs", "removing",
+				    ctxt->inode_count);
+	if (!prog)
+		return TUNEFS_ET_NO_MEMORY;
 
 	list_for_each(pos, &ctxt->inodes) {
 		xdi = list_entry(pos, struct xattr_inode, list);
@@ -280,7 +288,11 @@ static errcode_t remove_xattr(ocfs2_filesys *fs,
 		ocfs2_free_cached_inode(fs, ci);
 		if (ret)
 			break;
+
+		tools_progress_step(prog, 1);
 	}
+
+	tools_progress_stop(prog);
 	return ret;
 }
 
@@ -306,6 +318,9 @@ static errcode_t xattr_iterate(ocfs2_filesys *fs,
 	xdi->blkno = di->i_blkno;
 	list_add_tail(&xdi->list, &ctxt->inodes);
 
+	ctxt->inode_count++;
+	tools_progress_step(ctxt->prog, 1);
+
 	return 0;
 bail:
 	return ret;
@@ -315,6 +330,7 @@ static int enable_xattr(ocfs2_filesys *fs, int flag)
 {
 	errcode_t ret = 0;
 	struct ocfs2_super_block *super = OCFS2_RAW_SB(fs->fs_super);
+	struct tools_progress *prog = NULL;
 
 	if (ocfs2_support_xattr(super)) {
 		verbosef(VL_APP,
@@ -328,6 +344,13 @@ static int enable_xattr(ocfs2_filesys *fs, int flag)
 			     fs->fs_devname))
 		goto out;
 
+	prog = tools_progress_start("Enabling xattr", "xattr", 1);
+	if (!prog) {
+		ret = TUNEFS_ET_NO_MEMORY;
+		tcom_err(ret, "while initializing the progress display");
+		goto out;
+	}
+
 	super->s_uuid_hash = xattr_uuid_hash((unsigned char *)super->s_uuid);
 	super->s_xattr_inline_size = OCFS2_MIN_XATTR_INLINE_SIZE;
 	OCFS2_SET_INCOMPAT_FEATURE(super, OCFS2_FEATURE_INCOMPAT_XATTR);
@@ -338,7 +361,11 @@ static int enable_xattr(ocfs2_filesys *fs, int flag)
 	if (ret)
 		tcom_err(ret, "while writing out the superblock");
 
+	tools_progress_step(prog, 1);
 out:
+	if (prog)
+		tools_progress_stop(prog);
+
 	return ret;
 }
 
@@ -346,7 +373,11 @@ static int disable_xattr(ocfs2_filesys *fs, int flag)
 {
 	errcode_t ret = 0;
 	struct ocfs2_super_block *super = OCFS2_RAW_SB(fs->fs_super);
-	struct xattr_context ctxt;
+	struct xattr_context ctxt = {
+		.prog = NULL,
+		.inode_count = 0,
+	};
+	struct tools_progress *prog = NULL;
 
 	if (!ocfs2_support_xattr(super)) {
 		verbosef(VL_APP,
@@ -360,19 +391,34 @@ static int disable_xattr(ocfs2_filesys *fs, int flag)
 			     fs->fs_devname))
 		goto out;
 
-	memset(&ctxt, 0, sizeof(struct xattr_context));
+	prog = tools_progress_start("Disabling xattr", "noxattr", 3);
+	if (!prog) {
+		ret = TUNEFS_ET_NO_MEMORY;
+		tcom_err(ret, "while initializing the progress display");
+		goto out;
+	}
+
+	ctxt.prog = tools_progress_start("Scanning filesystem", "scanning",
+					 0);
+	if (!ctxt.prog) {
+		ret = TUNEFS_ET_NO_MEMORY;
+		goto out;
+	}
 	INIT_LIST_HEAD(&ctxt.inodes);
 	ret = tunefs_foreach_inode(fs, xattr_iterate, &ctxt);
+	tools_progress_stop(ctxt.prog);
 	if (ret) {
 		tcom_err(ret, "while trying to find files with xattr");
 		goto out_cleanup;
 	}
+	tools_progress_step(prog, 1);
 
 	ret = remove_xattr(fs, &ctxt);
 	if (ret) {
 		tcom_err(ret, "while trying to remove xattr");
 		goto out_cleanup;
 	}
+	tools_progress_step(prog, 1);
 
 	super->s_uuid_hash = 0;
 	super->s_xattr_inline_size = 0;
@@ -384,9 +430,14 @@ static int disable_xattr(ocfs2_filesys *fs, int flag)
 	if (ret)
 		tcom_err(ret, "while writing out the superblock");
 
+	tools_progress_step(prog, 1);
+
 out_cleanup:
 	empty_xattr_context(&ctxt);
 out:
+	if (prog)
+		tools_progress_stop(prog);
+
 	return ret;
 }
 
-- 

"The whole principle is wrong; it's like demanding that grown men 
 live on skim milk because the baby can't eat steak."
        - author Robert A. Heinlein on censorship

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127



More information about the Ocfs2-tools-devel mailing list