[Ocfs2-tools-commits] taoma commits r1328 - branches/sparse-files/libocfs2

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Sun Mar 25 23:30:02 PDT 2007


Author: taoma
Date: 2007-03-25 23:30:00 -0700 (Sun, 25 Mar 2007)
New Revision: 1328

Modified:
   branches/sparse-files/libocfs2/extend_file.c
Log:
 Change the return values of callback in __ocfs2_find_path.

Since we pass an allocated buffer to the callback, we need to know how the callback handle it
and what we have to do with the buffer according to the return values.

Modified: branches/sparse-files/libocfs2/extend_file.c
===================================================================
--- branches/sparse-files/libocfs2/extend_file.c	2007-03-26 06:03:02 UTC (rev 1327)
+++ branches/sparse-files/libocfs2/extend_file.c	2007-03-26 06:30:00 UTC (rev 1328)
@@ -755,7 +755,7 @@
 	return i - 1;
 }
 
-typedef void (path_insert_t)(void *, char *);
+typedef errcode_t (path_insert_t)(void *, char *);
 
 /*
  * Traverse a btree path in search of cpos, starting at root_el.
@@ -833,8 +833,31 @@
 			goto out;
 		}
 
-		if (func)
-			func(data, buf);
+		/* The user's callback must give us the tip for how to
+		 * handle the buf we allocated by return values.
+		 *
+ 		 * 1) return '0':
+		 *    the function succeeds,and it will use the buf and
+		 *    take care of the buffer release.
+		 *
+ 		 * 2) return > 0:
+		 *    the function succeeds, and there is no need for buf,
+		 *    so we will release it.
+		 *
+		 * 3) return < 0:
+		 *    the function fails.
+		 */
+		if (func) {
+			ret = func(data, buf);
+
+			if (ret == 0) {
+				buf = NULL;
+				continue;
+			}
+			else if (ret < 0)
+				goto out;
+		}
+		ocfs2_free(&buf);
 		buf = NULL;
 	}
 
@@ -862,12 +885,14 @@
 	struct ocfs2_path *path;
 };
 
-static void find_path_ins(void *data, char *eb)
+static errcode_t find_path_ins(void *data, char *eb)
 {
 	struct find_path_data *fp = data;
 
 	ocfs2_path_insert_eb(fp->path, fp->index, eb);
 	fp->index++;
+
+	return 0;
 }
 
 static int ocfs2_find_path(ocfs2_filesys *fs, struct ocfs2_path *path,




More information about the Ocfs2-tools-commits mailing list