[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [lvm-devel] new device-mapper required to build latest lvm from cvs



Jun'ichi Nomura wrote:
> Jun'ichi Nomura wrote:
>> Alasdair G Kergon wrote:
>>> On Wed, Jul 25, 2007 at 09:10:05PM +0100, Alasdair G Kergon wrote:
>>>> Don't bother: if the functions are identical today, remove the lvm2
>>>> wrapper and have everything call the dm version directly.
>>> The functions are not quite identical:-)
>>>   1 - a log_sys_error() cleanup missing
>> I thought they are identical after the macro is expanded.
>> Should I use log_sys_error() in libdevmapper, too?
> 
> OK, this patch copies log_sys_error() macro from LVM2
> and let libdevmapper use it.

Sorry there was a typo in the patch. ("fscanf" -> "scanf")
Attached is a revised patch.

Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America
Introduce log_sys_* macros from LVM2.
Convert existing "<string>: <function> failed: <strerror>" type messages
to this macro.

Index: device-mapper.work/include/log.h
===================================================================
--- device-mapper.work.orig/include/log.h
+++ device-mapper.work/include/log.h
@@ -38,6 +38,14 @@ extern dm_log_fn dm_log;
 #define log_very_verbose(x...) plog(_LOG_INFO, x)
 #define log_debug(x...) plog(_LOG_DEBUG, x)
 
+/* System call equivalents */
+#define log_sys_error(x, y) \
+		log_error("%s: %s failed: %s", y, x, strerror(errno))
+#define log_sys_very_verbose(x, y) \
+		log_info("%s: %s failed: %s", y, x, strerror(errno))
+#define log_sys_debug(x, y) \
+		log_debug("%s: %s failed: %s", y, x, strerror(errno))
+
 #define stack log_debug("<backtrace>")  /* Backtrace on error */
 
 #define return_0	do { stack; return 0; } while (0)
Index: device-mapper.work/lib/fs/libdevmapper.c
===================================================================
--- device-mapper.work.orig/lib/fs/libdevmapper.c
+++ device-mapper.work/lib/fs/libdevmapper.c
@@ -149,11 +149,11 @@ static int do_suspend(char *mnt, char *n
 		if (fputc(c, fp) == (int)c)
 			ret = 1;
 		else
-			log_error("%s: fputc failed: %s", path, strerror(errno));
+			log_sys_error("fputc", path);
 		if (fclose(fp))
-			log_error("%s: write failed: %s", path, strerror(errno));
+			log_sys_error("write", path);
 	} else
-		log_error("%s: fopen failed: %s", path, strerror(errno));
+		log_sys_error("fopen", path);
 
 	free(path);
 
@@ -174,10 +174,10 @@ static int do_newold(char *mnt, char *na
 			if (errno == EEXIST && !stat(path, &st) &&
 			    S_ISDIR(st.st_mode)) 
 				ret = 1;
-			log_error("%s: mkdir failed: %s", path, strerror(errno));
+			log_sys_error("mkdir", path);
 		}
 	} else if ((ret = rmdir(path)) < 0)
-		log_error("%s: rmdir failed: %s", path, strerror(errno));
+		log_sys_error("rmdir", path);
 
 	free(path);
 
@@ -216,10 +216,10 @@ static int do_suspend_state(char *mnt, c
 		if (fscanf(fp, "%d", &info->suspended) == 1)
 			ret = 1;
 		else
-			log_error("%s fscanf failed: %s", path, strerror(errno));
+			log_sys_error("fscanf", path);
 		fclose(fp);
 	} else
-		log_error("%s: fopen failed: %s", path, strerror(errno));
+		log_sys_error("fopen", path);
 
 	free(path);
 
@@ -288,7 +288,7 @@ static int do_load(char *mnt, char *name
 
 	if ((fd = open(path, O_RDWR)) != -1) {
 		if (!(ret = write_data(fd, dmt)))
-			log_error("%s: write failed: %s", path, strerror(errno));
+			log_sys_error("write", path);
 		close(fd);
 	}
 
@@ -315,7 +315,7 @@ static int do_error_check(char *mnt, cha
 		return 0;
 
 	if (!(fp = fopen(path, "r"))) {
-		log_error("%s: fopen failed: %s", path, strerror(errno));
+		log_sys_error("fopen", path);
 		free(path);
 		return 0;
 	}
@@ -338,7 +338,7 @@ static char *find_mount_point(void)
 	char fstype[30];
 
 	if (!(fp = fopen("/proc/mounts", "r"))) {
-		log_error("/proc/mounts: fopen failed: %s", strerror(errno));
+		log_sys_error("fopen", "/proc/mounts");
 		return NULL;
 	}
 
Index: device-mapper.work/lib/ioctl/libdm-iface.c
===================================================================
--- device-mapper.work.orig/lib/ioctl/libdm-iface.c
+++ device-mapper.work/lib/ioctl/libdm-iface.c
@@ -140,7 +140,7 @@ static int _get_proc_number(const char *
 	uint32_t num;
 
 	if (!(fl = fopen(file, "r"))) {
-		log_error("%s: fopen failed: %s", file, strerror(errno));
+		log_sys_error("fopen", file);
 		return 0;
 	}
 
@@ -150,7 +150,7 @@ static int _get_proc_number(const char *
 				if (number) {
 					*number = num;
 					if (fclose(fl))
-						log_error("%s: fclose failed: %s", file, strerror(errno));
+						log_sys_error("fclose", file);
 					return 1;
 				}
 				dm_bit_set(_dm_bitset, num);
@@ -160,7 +160,7 @@ static int _get_proc_number(const char *
 		} while (c != EOF && c != '\n');
 	}
 	if (fclose(fl))
-		log_error("%s: fclose failed: %s", file, strerror(errno));
+		log_sys_error("fclose", file);
 
 	if (number) {
 		log_error("%s: No entry for %s found", file, name);
@@ -190,8 +190,7 @@ static int _control_exists(const char *c
 
 	if (stat(control, &buf) < 0) {
 		if (errno != ENOENT)
-			log_error("%s: stat failed: %s", control,
-				  strerror(errno));
+			log_sys_error("stat", control);
 		return 0;
 	}
 
@@ -199,8 +198,7 @@ static int _control_exists(const char *c
 		log_verbose("%s: Wrong inode type", control);
 		if (!unlink(control))
 			return 0;
-		log_error("%s: unlink failed: %s", control,
-			  strerror(errno));
+		log_sys_error("unlink", control);
 		return -1;
 	}
 
@@ -211,8 +209,7 @@ static int _control_exists(const char *c
 			    major, minor);
 		if (!unlink(control))
 			return 0;
-		log_error("%s: unlink failed: %s", control,
-			  strerror(errno));
+		log_sys_error("unlink", control);
 		return -1;
 	}
 
@@ -238,7 +235,7 @@ static int _create_control(const char *c
 
 	if (mknod(control, S_IFCHR | S_IRUSR | S_IWUSR,
 		  MKDEV(major, minor)) < 0)  {
-		log_error("%s: mknod failed: %s", control, strerror(errno));
+		log_sys_error("mknod", control);
 		return 0;
 	}
 
@@ -301,7 +298,7 @@ static int _open_control(void)
 		goto error;
 
 	if ((_control_fd = open(control, O_RDWR)) < 0) {
-		log_error("%s: open failed: %s", control, strerror(errno));
+		log_sys_error("open", control);
 		goto error;
 	}
 
@@ -597,7 +594,7 @@ static int _dm_names_v1(struct dm_ioctl_
 	log_warn("Please upgrade your kernel device-mapper driver.");
 
 	if (!(d = opendir(dev_dir))) {
-		log_error("%s: opendir failed: %s", dev_dir, strerror(errno));
+		log_sys_error("opendir", dev_dir);
 		return 0;
 	}
 
@@ -616,7 +613,7 @@ static int _dm_names_v1(struct dm_ioctl_
 						      (void *) old_names);
 		snprintf(path, sizeof(path), "%s/%s", dev_dir, name);
 		if (stat(path, &buf)) {
-			log_error("%s: stat failed: %s", path, strerror(errno));
+			log_sys_error("stat", path);
 			continue;
 		}
 		if (!S_ISBLK(buf.st_mode))
@@ -637,7 +634,7 @@ static int _dm_names_v1(struct dm_ioctl_
 	}
 
 	if (closedir(d))
-		log_error("%s: closedir failed: %s", dev_dir, strerror(errno));
+		log_sys_error("closedir", dev_dir);
 
 	return r;
 }
@@ -1324,7 +1321,7 @@ static int _process_mapper_dir(struct dm
 
 	dir = dm_dir();
 	if (!(d = opendir(dir))) {
-		log_error("opendir %s: %s", dir, strerror(errno));
+		log_sys_error("opendir", dir);
 		return 0;
 	}
 
@@ -1338,7 +1335,7 @@ static int _process_mapper_dir(struct dm
 	}
 
 	if (closedir(d))
-		log_error("closedir %s: %s", dir, strerror(errno));
+		log_sys_error("closedir", dir);
 
 	return r;
 }
Index: device-mapper.work/lib/libdm-common.c
===================================================================
--- device-mapper.work.orig/lib/libdm-common.c
+++ device-mapper.work/lib/libdm-common.c
@@ -242,7 +242,7 @@ int dm_set_selinux_context(const char *p
 	log_debug("Setting SELinux context for %s to %s.", path, scontext);
 
 	if ((lsetfilecon(path, scontext) < 0) && (errno != ENOTSUP)) {
-		log_error("%s: lsetfilecon failed: %s", path, strerror(errno));
+		log_sys_error("lsetfilecon", path);
 		freecon(scontext);
 		return 0;
 	}
@@ -288,7 +288,7 @@ static int _add_dev_node(const char *dev
 	umask(old_mask);
 
 	if (chown(path, uid, gid) < 0) {
-		log_error("%s: chown failed: %s", path, strerror(errno));
+		log_sys_error("chown", path);
 		return 0;
 	}
 
Index: device-mapper.work/lib/libdm-file.c
===================================================================
--- device-mapper.work.orig/lib/libdm-file.c
+++ device-mapper.work/lib/libdm-file.c
@@ -33,8 +33,7 @@ static int _create_dir_recursive(const c
 		if (*orig) {
 			rc = mkdir(orig, 0777);
 			if (rc < 0 && errno != EEXIST) {
-				log_error("%s: mkdir failed: %s", orig,
-					  strerror(errno));
+				log_sys_error("mkdir", orig);
 				goto out;
 			}
 		}
@@ -44,8 +43,7 @@ static int _create_dir_recursive(const c
 	/* Create final directory */
 	rc = mkdir(dir, 0777);
 	if (rc < 0 && errno != EEXIST) {
-		log_error("%s: mkdir failed: %s", orig,
-			  strerror(errno));
+		log_sys_error("mkdir", orig);
 		goto out;
 	}
 

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]