[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



Alasdair G Kergon wrote:
> On Wed, Jul 25, 2007 at 04:01:13PM -0400, Jun'ichi Nomura wrote:
>> This is the patch for LVM2.
>> LVM2's create_dir() is left there for the case LVM2 specific
>> something could be put in future.
> 
> Don't bother: if the functions are identical today, remove the lvm2
> wrapper and have everything call the dm version directly.

OK, then this is a revised version of the patch.

Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America
Use dm_create_dir() instead of its own.

Index: LVM2.work/lib/misc/lvm-file.c
===================================================================
--- LVM2.work.orig/lib/misc/lvm-file.c
+++ LVM2.work/lib/misc/lvm-file.c
@@ -140,56 +140,6 @@ int dir_exists(const char *path)
 	return 1;
 }
 
-static int _create_dir_recursive(const char *dir)
-{
-	char *orig, *s;
-	int rc;
-
-	log_verbose("Creating directory \"%s\"", dir);
-	/* Create parent directories */
-	orig = s = dm_strdup(dir);
-	while ((s = strchr(s, '/')) != NULL) {
-		*s = '\0';
-		if (*orig) {
-			rc = mkdir(orig, 0777);
-			if (rc < 0 && errno != EEXIST) {
-				if (errno != EROFS)
-					log_sys_error("mkdir", orig);
-				dm_free(orig);
-				return 0;
-			}
-		}
-		*s++ = '/';
-	}
-	dm_free(orig);
-
-	/* Create final directory */
-	rc = mkdir(dir, 0777);
-	if (rc < 0 && errno != EEXIST) {
-		if (errno != EROFS)
-			log_sys_error("mkdir", dir);
-		return 0;
-	}
-	return 1;
-}
-
-int create_dir(const char *dir)
-{
-	struct stat info;
-
-	if (!*dir)
-		return 1;
-
-	if (stat(dir, &info) < 0)
-		return _create_dir_recursive(dir);
-
-	if (S_ISDIR(info.st_mode))
-		return 1;
-
-	log_error("Directory \"%s\" not found", dir);
-	return 0;
-}
-
 int is_empty_dir(const char *dir)
 {
 	struct dirent *dirent;
@@ -273,7 +223,7 @@ int fcntl_lock_file(const char *file, sh
 	if ((c = strrchr(dir, '/')))
 		*c = '\0';
 
-	if (!create_dir(dir)) {
+	if (!dm_create_dir(dir)) {
 		dm_free(dir);
 		return -1;
 	}
Index: LVM2.work/lib/commands/toolcontext.c
===================================================================
--- LVM2.work.orig/lib/commands/toolcontext.c
+++ LVM2.work/lib/commands/toolcontext.c
@@ -939,7 +939,7 @@ struct cmd_context *create_toolcontext(s
 		goto error;
 
 	/* Create system directory if it doesn't already exist */
-	if (*cmd->sys_dir && !create_dir(cmd->sys_dir)) {
+	if (*cmd->sys_dir && !dm_create_dir(cmd->sys_dir)) {
 		log_error("Failed to create LVM2 system dir for metadata backups, config "
 			  "files and internal cache.");
 		log_error("Set environment variable LVM_SYSTEM_DIR to alternative location "
Index: LVM2.work/lib/format_text/archiver.c
===================================================================
--- LVM2.work.orig/lib/format_text/archiver.c
+++ LVM2.work/lib/format_text/archiver.c
@@ -117,7 +117,7 @@ int archive(struct volume_group *vg)
 		return 1;
 	}
 
-	if (!create_dir(vg->cmd->archive_params->dir))
+	if (!dm_create_dir(vg->cmd->archive_params->dir))
 		return 0;
 
 	/* Trap a read-only file system */
@@ -223,7 +223,7 @@ int backup(struct volume_group *vg)
 		return 1;
 	}
 
-	if (!create_dir(vg->cmd->backup_params->dir))
+	if (!dm_create_dir(vg->cmd->backup_params->dir))
 		return 0;
 
 	/* Trap a read-only file system */
Index: LVM2.work/lib/format_text/format-text.c
===================================================================
--- LVM2.work.orig/lib/format_text/format-text.c
+++ LVM2.work/lib/format_text/format-text.c
@@ -1856,7 +1856,7 @@ static int _add_dir(const char *dir, str
 {
 	struct dir_list *dl;
 
-	if (create_dir(dir)) {
+	if (dm_create_dir(dir)) {
 		if (!(dl = dm_malloc(sizeof(struct list) + strlen(dir) + 1))) {
 			log_error("_add_dir allocation failed");
 			return 0;
Index: LVM2.work/lib/locking/file_locking.c
===================================================================
--- LVM2.work.orig/lib/locking/file_locking.c
+++ LVM2.work/lib/locking/file_locking.c
@@ -284,7 +284,7 @@ int init_file_locking(struct locking_typ
 						DEFAULT_LOCK_DIR),
 		sizeof(_lock_dir));
 
-	if (!create_dir(_lock_dir))
+	if (!dm_create_dir(_lock_dir))
 		return 0;
 
 	/* Trap a read-only file system */
Index: LVM2.work/lib/misc/lvm-file.h
===================================================================
--- LVM2.work.orig/lib/misc/lvm-file.h
+++ LVM2.work/lib/misc/lvm-file.h
@@ -39,12 +39,6 @@ int dir_exists(const char *path);
  */
 int is_empty_dir(const char *dir);
 
-/*
- * Create directory (recursively) if necessary.  Return 1
- * if directory was successfully created (or already exists), else 0.
- */
-int create_dir(const char *dir);
-
 /* Sync directory changes */
 void sync_dir(const char *file);
 

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