Skip to contentSkip to conversation

Btrfs-progs new btrfs_error() macro to deprecate fprintf(stderr, ...)

PATCH In review Eduardo Silva 2 participants 3 messages Feb 10, 2011 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs-progs new btrfs_error() macro to deprecate fprintf(stderr, ...)

Hi,

This patch add a new macro called btrfs_error(...) which deprecate the use of fprintf(stderr, ...)

regards,

Eduardo

Quoted 1 line

From e661fd2bdfc4145a7170ecf5de5fd012af7baf4e Mon Sep 17 00:00:00 2001

From: Eduardo Silva <[email protected]>
Date: Thu, 10 Feb 2011 11:50:14 -0300
Subject: [PATCH] New btrfs_error() macro to deprecate fprintf(stderr, ...)

---
 btrfs-image.c       |   10 ++--
 btrfs-list.c        |   14 +++---
 btrfs-map-logical.c |   15 ++++---
 btrfs-show.c        |    6 +-
 btrfs-vol.c         |   22 +++++-----
 btrfs-zero-log.c    |    8 ++--
 btrfs.c             |   13 +++---
 btrfs_cmds.c        |  102 +++++++++++++++++++++++++-------------------------
 btrfsck.c           |   72 +++++++++++++++++-----------------
 btrfsctl.c          |   22 +++++-----
 btrfstune.c         |   10 ++--
 convert.c           |  104 +++++++++++++++++++++++++-------------------------
 debug-tree.c        |    9 ++--
 dir-test.c          |   12 +++---
 disk-io.c           |    6 +-
 extent_io.c         |    3 +-
 mkfs.c              |   58 ++++++++++++++--------------
 print-tree.c        |    3 +-
 quick-test.c        |   10 ++--
 random-test.c       |   12 +++---
 utils.c             |   20 +++++-----
 utils.h             |    3 +
 22 files changed, 271 insertions(+), 263 deletions(-)
btrfs-image.c +5 -5
index f2bbcc8..6b88b24 100644
@@ -791,7 +791,7 @@ static int restore_metadump(const char *input, FILE *out, int num_threads)
 		header = &cluster->header;
 		if (le64_to_cpu(header->magic) != HEADER_MAGIC ||
 		    le64_to_cpu(header->bytenr) != bytenr) {
-			fprintf(stderr, "bad header in metadump image\n");
+			btrfs_error("bad header in metadump image\n");
 			return 1;
 		}
 		ret = add_cluster(cluster, &mdrestore, &bytenr);
@@ -809,10 +809,10 @@ static int restore_metadump(const char *input, FILE *out, int num_threads)
 
 static void print_usage(void)
 {
-	fprintf(stderr, "usage: btrfs-image [options] source target\n");
-	fprintf(stderr, "\t-r      \trestore metadump image\n");
-	fprintf(stderr, "\t-c value\tcompression level (0 ~ 9)\n");
-	fprintf(stderr, "\t-t value\tnumber of threads (1 ~ 32)\n");
+	btrfs_error("usage: btrfs-image [options] source target\n");
+	btrfs_error("\t-r      \trestore metadump image\n");
+	btrfs_error("\t-c value\tcompression level (0 ~ 9)\n");
+	btrfs_error("\t-t value\tnumber of threads (1 ~ 32)\n");
 	exit(1);
 }
 
btrfs-list.c +7 -7
index 93766a8..470cf1c 100644
@@ -276,7 +276,7 @@ static int lookup_ino_path(int fd, struct root_info *ri)
 
 	ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
 	if (ret) {
-		fprintf(stderr, "ERROR: Failed to lookup path for root %llu\n",
+		btrfs_error("ERROR: Failed to lookup path for root %llu\n",
 			(unsigned long long)ri->ref_tree);
 		return ret;
 	}
@@ -327,7 +327,7 @@ static u64 find_root_gen(int fd)
 	/* this ioctl fills in ino_args->treeid */
 	ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &ino_args);
 	if (ret) {
-		fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu\n",
+		btrfs_error("ERROR: Failed to lookup path for dirid %llu\n",
 			(unsigned long long)BTRFS_FIRST_FREE_OBJECTID);
 		return 0;
 	}
@@ -352,7 +352,7 @@ static u64 find_root_gen(int fd)
 	while (1) {
 		ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
 		if (ret < 0) {
-			fprintf(stderr, "ERROR: can't perform the search\n");
+			btrfs_error("ERROR: can't perform the search\n");
 			return 0;
 		}
 		/* the ioctl returns the number of item it found in nr_items */
@@ -413,7 +413,7 @@ static char *__ino_resolve(int fd, u64 dirid)
 
 	ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
 	if (ret) {
-		fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu\n",
+		btrfs_error("ERROR: Failed to lookup path for dirid %llu\n",
 			(unsigned long long)dirid);
 		return ERR_PTR(ret);
 	}
@@ -491,7 +491,7 @@ static char *ino_resolve(int fd, u64 ino, u64 *cache_dirid, char **cache_name)
 
 	ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
 	if (ret < 0) {
-		fprintf(stderr, "ERROR: can't perform the search\n");
+		btrfs_error("ERROR: can't perform the search\n");
 		return NULL;
 	}
 	/* the ioctl returns the number of item it found in nr_items */
@@ -579,7 +579,7 @@ int list_subvols(int fd)
 	while(1) {
 		ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
 		if (ret < 0) {
-			fprintf(stderr, "ERROR: can't perform the search\n");
+			btrfs_error("ERROR: can't perform the search\n");
 			return ret;
 		}
 		/* the ioctl returns the number of item it found in nr_items */
@@ -774,7 +774,7 @@ int find_updated_files(int fd, u64 root_id, u64 oldest_gen)
 	while(1) {
 		ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
 		if (ret < 0) {
-			fprintf(stderr, "ERROR: can't perform the search\n");
+			btrfs_error("ERROR: can't perform the search\n");
 			return ret;
 		}
 		/* the ioctl returns the number of item it found in nr_items */
btrfs-map-logical.c +8 -7
index a109c6a..235bb1e 100644
@@ -31,6 +31,7 @@
 #include "transaction.h"
 #include "list.h"
 #include "version.h"
+#include "utils.h"
 
 /* we write the mirror info to stdout unless they are dumping the data
  * to stdout
@@ -86,11 +87,11 @@ struct extent_buffer *debug_read_block(struct btrfs_root *root, u64 bytenr,
 
 static void print_usage(void)
 {
-	fprintf(stderr, "usage: btrfs-map-logical [options] mount_point\n");
-	fprintf(stderr, "\t-l Logical extent to map\n");
-	fprintf(stderr, "\t-c Copy of the extent to read (usually 1 or 2)\n");
-	fprintf(stderr, "\t-o Output file to hold the extent\n");
-	fprintf(stderr, "\t-s Number of bytes to read\n");
+	btrfs_error("usage: btrfs-map-logical [options] mount_point\n");
+	btrfs_error("\t-l Logical extent to map\n");
+	btrfs_error("\t-c Copy of the extent to read (usually 1 or 2)\n");
+	btrfs_error("\t-o Output file to hold the extent\n");
+	btrfs_error("\t-s Number of bytes to read\n");
 	exit(1);
 }
 
@@ -171,7 +172,7 @@ int main(int ac, char **av)
 
 	root = open_ctree(dev, 0, 0);
 	if (!root) {
-		fprintf(stderr, "Open ctree failed\n");
+		btrfs_error("Open ctree failed\n");
 		exit(1);
 	}
 
@@ -203,7 +204,7 @@ int main(int ac, char **av)
 		if (eb && output_file) {
 			err = write(out_fd, eb->data, eb->len);
 			if (err < 0 || err != eb->len) {
-				fprintf(stderr, "output file write failed\n");
+				btrfs_error("output file write failed\n");
 				goto out_close_fd;
 			}
 		}
btrfs-show.c +3 -3
index c49626c..17fa543 100644
@@ -98,8 +98,8 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
 
 static void print_usage(void)
 {
-	fprintf(stderr, "usage: btrfs-show [search label or device]\n");
-	fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION);
+	btrfs_error("usage: btrfs-show [search label or device]\n");
+	btrfs_error("%s\n", BTRFS_BUILD_VERSION);
 	exit(1);
 }
 
@@ -135,7 +135,7 @@ int main(int ac, char **av)
 
 	ret = btrfs_scan_one_dir("/dev", 0);
 	if (ret)
-		fprintf(stderr, "error %d while scanning\n", ret);
+		btrfs_error("error %d while scanning\n", ret);
 
 	all_uuids = btrfs_scanned_uuids();
 	list_for_each(cur_uuid, all_uuids) {
btrfs-vol.c +11 -11
index 4ed799d..bbb2d98 100644
@@ -49,10 +49,10 @@ static inline int ioctl(int fd, int define, void *arg) { return 0; }
 
 static void print_usage(void)
 {
-	fprintf(stderr, "usage: btrfs-vol [options] mount_point\n");
-	fprintf(stderr, "\t-a device add one device\n");
-	fprintf(stderr, "\t-b balance chunks across all devices\n");
-	fprintf(stderr, "\t-r device remove one device\n");
+	btrfs_error("usage: btrfs-vol [options] mount_point\n");
+	btrfs_error("\t-a device add one device\n");
+	btrfs_error("\t-b balance chunks across all devices\n");
+	btrfs_error("\t-r device remove one device\n");
 	exit(1);
 }
 
@@ -107,7 +107,7 @@ int main(int ac, char **av)
 
 	if (device && strcmp(device, "missing") == 0 &&
 	    cmd == BTRFS_IOC_RM_DEV) {
-		fprintf(stderr, "removing missing devices from %s\n", mnt);
+		btrfs_error("removing missing devices from %s\n", mnt);
 	} else if (cmd != BTRFS_IOC_BALANCE) {
 		if (cmd == BTRFS_IOC_ADD_DEV) {
 			ret = check_mounted(device);
@@ -118,34 +118,34 @@ int main(int ac, char **av)
 				exit(1);
 			}
 			if (ret == 1) {
-				fprintf(stderr, "%s is mounted\n", device);
+				btrfs_error("%s is mounted\n", device);
 				exit(1);
 			}
 		}
 		devfd = open(device, O_RDWR);
 		if (devfd < 0) {
-			fprintf(stderr, "Unable to open device %s\n", device);
+			btrfs_error("Unable to open device %s\n", device);
 			exit(1);
 		}
 		ret = fstat(devfd, &st);
 		if (ret) {
-			fprintf(stderr, "Unable to stat %s\n", device);
+			btrfs_error("Unable to stat %s\n", device);
 			exit(1);
 		}
 		if (!S_ISBLK(st.st_mode)) {
-			fprintf(stderr, "%s is not a block device\n", device);
+			btrfs_error("%s is not a block device\n", device);
 			exit(1);
 		}
 	}
 	dirstream = opendir(mnt);
 	if (!dirstream) {
-		fprintf(stderr, "Unable to open directory %s\n", mnt);
+		btrfs_error("Unable to open directory %s\n", mnt);
 		exit(1);
 	}
 	if (cmd == BTRFS_IOC_ADD_DEV) {
 		ret = btrfs_prepare_device(devfd, device, 1, &dev_block_count);
 		if (ret) {
-			fprintf(stderr, "Unable to init %s\n", device);
+			btrfs_error("Unable to init %s\n", device);
 			exit(1);
 		}
 	}
btrfs-zero-log.c +4 -4
index f10438b..066dd6e 100644
@@ -34,8 +34,8 @@
 
 static void print_usage(void)
 {
-	fprintf(stderr, "usage: btrfs-zero-log dev\n");
-	fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION);
+	btrfs_error("usage: btrfs-zero-log dev\n");
+	btrfs_error("%s\n", BTRFS_BUILD_VERSION);
 	exit(1);
 }
 
@@ -50,10 +50,10 @@ int main(int ac, char **av)
 	radix_tree_init();
 
 	if((ret = check_mounted(av[1])) < 0) {
-		fprintf(stderr, "Could not check mount status: %s\n", strerror(ret));
+		btrfs_error("Could not check mount status: %s\n", strerror(ret));
 		return ret;
 	} else if(ret) {
-		fprintf(stderr, "%s is currently mounted. Aborting.\n", av[1]);
+		btrfs_error("%s is currently mounted. Aborting.\n", av[1]);
 		return -EBUSY;
 	}
 
btrfs.c +7 -6
index 46314cf..4dc2c3c 100644
@@ -22,6 +22,7 @@
 #include "kerncompat.h"
 #include "btrfs_cmds.h"
 #include "version.h"
+#include "utils.h"
 
 typedef int (*CommandFunction)(int argc, char **argv);
 
@@ -209,10 +210,10 @@ static int check_ambiguity(struct Command *cmd, char **argv){
 		}
 		if(match){
 			int j;
-			fprintf(stderr, "ERROR: in command '");
+			btrfs_error("ERROR: in command '");
 			for( j = 0 ; j <= i ; j++ )
-				fprintf(stderr, "%s%s",j?" ":"", argv[j+1]);
-			fprintf(stderr, "', '%s' is ambiguous\n",argv[j]);
+				btrfs_error("%s%s",j?" ":"", argv[j+1]);
+			btrfs_error("', '%s' is ambiguous\n",argv[j]);
 			return -2;
 		}
 	}
@@ -350,18 +351,18 @@ static int parse_args(int argc, char **argv,
 
 	/* check the number of argument */
 	if (matchcmd->nargs < 0 && matchcmd->nargs < -*nargs_ ){
-		fprintf(stderr, "ERROR: '%s' requires minimum %d arg(s)\n",
+		btrfs_error("ERROR: '%s' requires minimum %d arg(s)\n",
 			matchcmd->verb, -matchcmd->nargs);
 			return -2;
 	}
 	if(matchcmd->nargs >= 0 && matchcmd->nargs != *nargs_ && matchcmd->nargs != 999){
-		fprintf(stderr, "ERROR: '%s' requires %d arg(s)\n",
+		btrfs_error("ERROR: '%s' requires %d arg(s)\n",
 			matchcmd->verb, matchcmd->nargs);
 			return -2;
 	}
 	
         if (prepare_args( nargs_, args_, prgname, matchcmd )){
-                fprintf(stderr, "ERROR: not enough memory\\n");
+                btrfs_error("ERROR: not enough memory\\n");
 		return -20;
         }
 
btrfs_cmds.c +51 -51

387 lines not on this page · raw message

btrfsck.c +36 -36

268 lines not on this page · raw message

btrfsctl.c +11 -11
index 92bdf39..d6620da 100644
@@ -108,14 +108,14 @@ int main(int ac, char **av)
 	u64 objectid = 0;
 
 	if (ac == 2 && strcmp(av[1], "-a") == 0) {
-		fprintf(stderr, "Scanning for Btrfs filesystems\n");
+		btrfs_error("Scanning for Btrfs filesystems\n");
 		btrfs_scan_one_dir("/dev", 1);
 		exit(0);
 	}
 	for (i = 1; i < ac; i++) {
 		if (strcmp(av[i], "-s") == 0) {
 			if (i + 1 >= ac - 1) {
-				fprintf(stderr, "-s requires an arg");
+				btrfs_error("-s requires an arg");
 				print_usage();
 			}
 			fullpath = av[i + 1];
@@ -142,7 +142,7 @@ int main(int ac, char **av)
 			command = BTRFS_IOC_SNAP_CREATE;
 		} else if (strcmp(av[i], "-S") == 0) {
 			if (i + 1 >= ac - 1) {
-				fprintf(stderr, "-S requires an arg");
+				btrfs_error("-S requires an arg");
 				print_usage();
 			}
 			name = av[i + 1];
@@ -160,13 +160,13 @@ int main(int ac, char **av)
 			command = BTRFS_IOC_SUBVOL_CREATE;
 		} else if (strcmp(av[i], "-d") == 0) {
 			if (i >= ac - 1) {
-				fprintf(stderr, "-d requires an arg\n");
+				btrfs_error("-d requires an arg\n");
 				print_usage();
 			}
 			command = BTRFS_IOC_DEFRAG;
 		} else if (strcmp(av[i], "-D") == 0) {
 			if (i >= ac - 1) {
-				fprintf(stderr, "-D requires an arg\n");
+				btrfs_error("-D requires an arg\n");
 				print_usage();
 			}
 			command = BTRFS_IOC_SNAP_DESTROY;
@@ -183,24 +183,24 @@ int main(int ac, char **av)
 				}
 			}
 			if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
-				fprintf(stderr, "-D size too long\n");
+				btrfs_error("-D size too long\n");
 				exit(1);
 			}
 		} else if (strcmp(av[i], "-A") == 0) {
 			if (i >= ac - 1) {
-				fprintf(stderr, "-A requires an arg\n");
+				btrfs_error("-A requires an arg\n");
 				print_usage();
 			}
 			command = BTRFS_IOC_SCAN_DEV;
 		} else if (strcmp(av[i], "-r") == 0) {
 			if (i >= ac - 1) {
-				fprintf(stderr, "-r requires an arg\n");
+				btrfs_error("-r requires an arg\n");
 				print_usage();
 			}
 			name = av[i + 1];
 			len = strlen(name);
 			if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
-				fprintf(stderr, "-r size too long\n");
+				btrfs_error("-r size too long\n");
 				exit(1);
 			}
 			command = BTRFS_IOC_RESIZE;
@@ -212,14 +212,14 @@ int main(int ac, char **av)
 				objectid = (unsigned long long)
 					    strtoll(av[i + 1], NULL, 0);
 				if (errno == ERANGE) {
-					fprintf(stderr, "invalid tree id\n");
+					btrfs_error("invalid tree id\n");
 					exit(1);
 				}
 			}
 		}
 	}
 	if (command == 0) {
-		fprintf(stderr, "no valid commands given\n");
+		btrfs_error("no valid commands given\n");
 		print_usage();
 		exit(1);
 	}
btrfstune.c +5 -5
index 47830c5..957ad8f 100644
@@ -44,14 +44,14 @@ int update_seeding_flag(struct btrfs_root *root, int set_flag)
 	super_flags = btrfs_super_flags(disk_super);
 	if (set_flag) {
 		if (super_flags & BTRFS_SUPER_FLAG_SEEDING) {
-			fprintf(stderr, "seeding flag is already set on %s\n",
+			btrfs_error("seeding flag is already set on %s\n",
 				device);
 			return 1;
 		}
 		super_flags |= BTRFS_SUPER_FLAG_SEEDING;
 	} else {
 		if (!(super_flags & BTRFS_SUPER_FLAG_SEEDING)) {
-			fprintf(stderr, "seeding flag is not set on %s\n",
+			btrfs_error("seeding flag is not set on %s\n",
 				device);
 			return 1;
 		}
@@ -67,8 +67,8 @@ int update_seeding_flag(struct btrfs_root *root, int set_flag)
 
 static void print_usage(void)
 {
-	fprintf(stderr, "usage: btrfstune [options] device\n");
-	fprintf(stderr, "\t-S value\tenable/disable seeding\n");
+	btrfs_error("usage: btrfstune [options] device\n");
+	btrfs_error("\t-S value\tenable/disable seeding\n");
 }
 
 int main(int argc, char *argv[])
@@ -102,7 +102,7 @@ int main(int argc, char *argv[])
 	}
 
 	if (check_mounted(device)) {
-		fprintf(stderr, "%s is mounted\n", device);
+		btrfs_error("%s is mounted\n", device);
 		return 1;
 	}
 
convert.c +52 -52

387 lines not on this page · raw message

debug-tree.c +5 -4
index 0525354..5e1f005 100644
@@ -27,11 +27,12 @@
 #include "print-tree.h"
 #include "transaction.h"
 #include "version.h"
+#include "utils.h"
 
 static int print_usage(void)
 {
-	fprintf(stderr, "usage: debug-tree [ -e ] device\n");
-	fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION);
+	btrfs_error("usage: debug-tree [ -e ] device\n");
+	btrfs_error("%s\n", BTRFS_BUILD_VERSION);
 	exit(1);
 }
 
@@ -147,7 +148,7 @@ int main(int ac, char **av)
 
 	root = open_ctree(av[optind], 0, 0);
 	if (!root) {
-		fprintf(stderr, "unable to open %s\n", av[optind]);
+		btrfs_error("unable to open %s\n", av[optind]);
 		exit(1);
 	}
 	if (block_only) {
@@ -166,7 +167,7 @@ int main(int ac, char **av)
 					      root->nodesize, 0);
 		}
 		if (!leaf) {
-			fprintf(stderr, "failed to read %llu\n", block_only);
+			btrfs_error("failed to read %llu\n", block_only);
 			return 0;
 		}
 		btrfs_print_tree(root, leaf, 0);
dir-test.c +6 -6
index 3ae9c68..c808b0a 100644
@@ -348,7 +348,7 @@ static int empty_tree(struct btrfs_trans_handle *trans, struct btrfs_root
 			break;
 	}
 	return 0;
-	fprintf(stderr, "failed to delete from the radix %lu\n", found);
+	btrfs_error("failed to delete from the radix %lu\n", found);
 	return -1;
 }
 
@@ -360,13 +360,13 @@ static int fill_tree(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 	for (i = 0; i < count; i++) {
 		ret = ins_one(trans, root, radix);
 		if (ret) {
-			fprintf(stderr, "fill failed\n");
+			btrfs_error("fill failed\n");
 			goto out;
 		}
 		if (i % 1000 == 0) {
 			ret = btrfs_commit_transaction(trans, root, &super);
 			if (ret) {
-				fprintf(stderr, "fill commit failed\n");
+				btrfs_error("fill commit failed\n");
 				return ret;
 			}
 		}
@@ -408,7 +408,7 @@ int (*ops[])(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct
 void sigstopper(int ignored)
 {
 	keep_running = 0;
-	fprintf(stderr, "caught exit signal, stopping\n");
+	btrfs_error("caught exit signal, stopping\n");
 }
 
 int print_usage(void)
@@ -483,10 +483,10 @@ int main(int ac, char **av)
 		while(count--) {
 			ret = ops[op](trans, root, &radix);
 			if (ret) {
-				fprintf(stderr, "op %d failed %d:%d\n",
+				btrfs_error("op %d failed %d:%d\n",
 					op, i, iterations);
 				btrfs_print_tree(root, root->node, 1);
-				fprintf(stderr, "op %d failed %d:%d\n",
+				btrfs_error("op %d failed %d:%d\n",
 					op, i, iterations);
 				err = ret;
 				goto out;
disk-io.c +3 -3
index a6e1000..e8793c0 100644
@@ -581,7 +581,7 @@ struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, int writes)
 
 	fp = open(filename, flags, 0600);
 	if (fp < 0) {
-		fprintf (stderr, "Could not open %s\n", filename);
+		btrfs_error("Could not open %s\n", filename);
 		return NULL;
 	}
 	root = open_ctree_fd(fp, filename, sb_bytenr, writes);
@@ -619,7 +619,7 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
 				    &total_devs, sb_bytenr);
 
 	if (ret) {
-		fprintf(stderr, "No valid Btrfs found on %s\n", path);
+		btrfs_error("No valid Btrfs found on %s\n", path);
 		return NULL;
 	}
 
@@ -920,7 +920,7 @@ int write_ctree_super(struct btrfs_trans_handle *trans,
 
 	ret = write_all_supers(root);
 	if (ret)
-		fprintf(stderr, "failed to write new super block err %d\n", ret);
+		btrfs_error("failed to write new super block err %d\n", ret);
 	return ret;
 }
 
extent_io.c +2 -1
index 069c199..77a1abf 100644
@@ -27,6 +27,7 @@
 #include "kerncompat.h"
 #include "extent_io.h"
 #include "list.h"
+#include "utils.h"
 
 u64 cache_max = 1024 * 1024 * 32;
 
@@ -68,7 +69,7 @@ void extent_io_tree_cleanup(struct extent_io_tree *tree)
 	while(!list_empty(&tree->lru)) {
 		eb = list_entry(tree->lru.next, struct extent_buffer, lru);
 		if (eb->refs != 1) {
-			fprintf(stderr, "extent buffer leak: "
+			btrfs_error("extent buffer leak: "
 				"start %llu len %u\n",
 				(unsigned long long)eb->start, eb->len);
 			eb->refs = 1;
mkfs.c +29 -29

158 lines not on this page · raw message

print-tree.c +2 -1
index ac575d5..ebda4b6 100644
@@ -24,6 +24,7 @@
 #include "ctree.h"
 #include "disk-io.h"
 #include "print-tree.h"
+#include "utils.h"
 
 static int print_dir_item(struct extent_buffer *eb, struct btrfs_item *item,
 			  struct btrfs_dir_item *di)
@@ -655,7 +656,7 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int fol
 					     size,
 					     btrfs_node_ptr_generation(eb, i));
 		if (!next) {
-			fprintf(stderr, "failed to read %llu in tree %llu\n",
+			btrfs_error("failed to read %llu in tree %llu\n",
 				(unsigned long long)btrfs_node_blockptr(eb, i),
 				(unsigned long long)btrfs_header_owner(eb));
 			continue;
quick-test.c +5 -5
index fa6fd83..15a147e 100644
@@ -60,7 +60,7 @@ int main(int ac, char **av) {
 		// num = i;
 		sprintf(buf, "string-%d", num);
 		if (i % 10000 == 0)
-			fprintf(stderr, "insert %d:%d\n", num, i);
+			btrfs_error("insert %d:%d\n", num, i);
 		ins.objectid = num;
 		ins.offset = 0;
 		ret = btrfs_insert_item(trans, root, &ins, buf, 512);
@@ -82,7 +82,7 @@ int main(int ac, char **av) {
 		ins.objectid = num;
 		btrfs_init_path(&path);
 		if (i % 10000 == 0)
-			fprintf(stderr, "search %d:%d\n", num, i);
+			btrfs_error("search %d:%d\n", num, i);
 		ret = btrfs_search_slot(NULL, root, &ins, &path, 0, 0);
 		if (ret) {
 			btrfs_print_tree(root, root->node, 1);
@@ -110,7 +110,7 @@ int main(int ac, char **av) {
 		ret = btrfs_search_slot(trans, root, &ins, &path, -1, 1);
 		if (!ret) {
 			if (i % 10000 == 0)
-				fprintf(stderr, "del %d:%d\n", num, i);
+				btrfs_error("del %d:%d\n", num, i);
 			ret = btrfs_del_item(trans, root, &path);
 			if (ret != 0)
 				BUG();
@@ -129,7 +129,7 @@ int main(int ac, char **av) {
 		sprintf(buf, "string-%d", num);
 		ins.objectid = num;
 		if (i % 10000 == 0)
-			fprintf(stderr, "insert %d:%d\n", num, i);
+			btrfs_error("insert %d:%d\n", num, i);
 		ret = btrfs_insert_item(trans, root, &ins, buf, 512);
 		if (!ret)
 			tree_size++;
@@ -145,7 +145,7 @@ int main(int ac, char **av) {
 		ins.objectid = num;
 		btrfs_init_path(&path);
 		if (i % 10000 == 0)
-			fprintf(stderr, "search %d:%d\n", num, i);
+			btrfs_error("search %d:%d\n", num, i);
 		ret = btrfs_search_slot(NULL, root, &ins, &path, 0, 0);
 		if (ret) {
 			btrfs_print_tree(root, root->node, 1);
random-test.c +6 -6
index 0003236..9e1ac93 100644
@@ -220,7 +220,7 @@ static int empty_tree(struct btrfs_trans_handle *trans, struct btrfs_root
 	}
 	return 0;
 error:
-	fprintf(stderr, "failed to delete from the radix %lu\n", found);
+	btrfs_error("failed to delete from the radix %lu\n", found);
 	return -1;
 }
 
@@ -232,13 +232,13 @@ static int fill_tree(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 	for (i = 0; i < count; i++) {
 		ret = ins_one(trans, root, radix);
 		if (ret) {
-			fprintf(stderr, "fill failed\n");
+			btrfs_error("fill failed\n");
 			goto out;
 		}
 		if (i % 1000 == 0) {
 			ret = btrfs_commit_transaction(trans, root, &super);
 			if (ret) {
-				fprintf(stderr, "fill commit failed\n");
+				btrfs_error("fill commit failed\n");
 				return ret;
 			}
 		}
@@ -329,7 +329,7 @@ static int fill_radix(struct btrfs_root *root, struct radix_tree_root *radix)
 void sigstopper(int ignored)
 {
 	keep_running = 0;
-	fprintf(stderr, "caught exit signal, stopping\n");
+	btrfs_error("caught exit signal, stopping\n");
 }
 
 int print_usage(void)
@@ -402,10 +402,10 @@ int main(int ac, char **av)
 		while(count--) {
 			ret = ops[op](trans, root, &radix);
 			if (ret) {
-				fprintf(stderr, "op %d failed %d:%d\n",
+				btrfs_error("op %d failed %d:%d\n",
 					op, i, iterations);
 				btrfs_print_tree(root, root->node, 1);
-				fprintf(stderr, "op %d failed %d:%d\n",
+				btrfs_error("op %d failed %d:%d\n",
 					op, i, iterations);
 				err = ret;
 				goto out;
utils.c +10 -10
index fd894f3..4f8e97e 100644
@@ -520,25 +520,25 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret)
 
 	ret = fstat(fd, &st);
 	if (ret < 0) {
-		fprintf(stderr, "unable to stat %s\n", file);
+		btrfs_error("unable to stat %s\n", file);
 		exit(1);
 	}
 
 	block_count = device_size(fd, &st);
 	if (block_count == 0) {
-		fprintf(stderr, "unable to find %s size\n", file);
+		btrfs_error("unable to find %s size\n", file);
 		exit(1);
 	}
 	zero_end = 1;
 
 	if (block_count < 256 * 1024 * 1024) {
-		fprintf(stderr, "device %s is too small "
+		btrfs_error("device %s is too small "
 		        "(must be at least 256 MB)\n", file);
 		exit(1);
 	}
 	ret = zero_dev_start(fd);
 	if (ret) {
-		fprintf(stderr, "failed to zero device start %d\n", ret);
+		btrfs_error("failed to zero device start %d\n", ret);
 		exit(1);
 	}
 
@@ -552,7 +552,7 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret)
 	if (zero_end) {
 		ret = zero_dev_end(fd, block_count);
 		if (ret) {
-			fprintf(stderr, "failed to zero device end %d\n", ret);
+			btrfs_error("failed to zero device end %d\n", ret);
 			exit(1);
 		}
 	}
@@ -759,7 +759,7 @@ int check_mounted(const char* file)
 
 	fd = open(file, O_RDONLY);
 	if (fd < 0) {
-		fprintf (stderr, "check_mounted(): Could not open %s\n", file);
+		btrfs_error("check_mounted(): Could not open %s\n", file);
 		return -errno;
 	}
 
@@ -824,7 +824,7 @@ void btrfs_register_one_device(char *fname)
 
 	fd = open("/dev/btrfs-control", O_RDONLY);
 	if (fd < 0) {
-		fprintf(stderr, "failed to open /dev/btrfs-control "
+		btrfs_error("failed to open /dev/btrfs-control "
 			"skipping device registration\n");
 		return;
 	}
@@ -867,7 +867,7 @@ again:
 	}
 	dirp = opendir(dirname);
 	if (!dirp) {
-		fprintf(stderr, "Unable to open /sys/block for scanning\n");
+		btrfs_error("Unable to open /sys/block for scanning\n");
 		return -ENOENT;
 	}
 	while(1) {
@@ -883,7 +883,7 @@ again:
 		snprintf(fullpath, pathlen, "%s/%s", dirname, dirent->d_name);
 		ret = lstat(fullpath, &st);
 		if (ret < 0) {
-			fprintf(stderr, "failed to stat %s\n", fullpath);
+			btrfs_error("failed to stat %s\n", fullpath);
 			continue;
 		}
 		if (S_ISLNK(st.st_mode))
@@ -902,7 +902,7 @@ again:
 		}
 		fd = open(fullpath, O_RDONLY);
 		if (fd < 0) {
-			fprintf(stderr, "failed to read %s\n", fullpath);
+			btrfs_error("failed to read %s\n", fullpath);
 			continue;
 		}
 		ret = btrfs_scan_one_device(fd, fullpath, &tmp_devices,
utils.h +3 -0
index 9dce5b0..06df856 100644
@@ -19,7 +19,10 @@
 #ifndef __UTILS__
 #define __UTILS__
 
+#include "ctree.h"
+
 #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024)
+#define btrfs_error(...) fprintf(stderr, __VA_ARGS__)
 
 int make_btrfs(int fd, const char *device, const char *label,
 	       u64 blocks[6], u64 num_bytes, u32 nodesize,
Signature · 1 line
1.7.1
#1 lore raw
Quoted 3 lines · On Thursday, February 10, 2011 15:54:55 Eduardo Silva wrote:

Hi,
=20
This patch add a new macro called btrfs_error(...) which deprecate th=

e

Quoted 5 lines

use of fprintf(stderr, ...)
=20
regards,
=20
Eduardo

Sorry, but I don't see a reason for such change. IMHO it only makes the=
code=20
_less_ readable.

Regards,
--=20
Hubert Kario
QBS - Quality Business Software
02-656 Warszawa, ul. Ksawer=F3w 30/85
tel. +48 (22) 646-61-51, 646-74-24
www.qbs.com.pl
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 6 lines · Hubert Kario
Quoted 5 lines · On Thursday, February 10, 2011 15:54:55 Eduardo Silva wrote:

Hi,

This patch add a new macro called btrfs_error(...) which deprecate the use of fprintf(stderr, ...)

Quoted 8 lines
Quoted 3 lines

regards,

Eduardo

Sorry, but I don't see a reason for such change. IMHO it only makes the code _less_ readable.

Regards,

no troubles :)

regards,

Ed.-