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

Re: [lvm-devel] LVM2/lib/metadata lv_manip.c




hello,  i write a little patch that add a force (or recursive ?) option to vgremove
i think  the semantic is better if you call vgremove -f <vg>  than
call lvremove <vg> and then vgremove <vg>

Example:

root cobalto:/usr/local/src/LVM2/tools# lvm lvs
  LV        VG     Attr   LSize   Origin Snap%  Move Log Copy%
  lvprueba1 prueba -wi-a- 128.00M                             
  lvprueba2 prueba -wi-a- 128.00M                             
  lvprueba3 prueba -wi-a- 128.00M                             
  lvprueba4 prueba -wi-a- 128.00M                             

root cobalto:/usr/local/src/LVM2/tools# ./lvm vgremove -f prueba
  Logical volume "lvprueba1" successfully removed
  Logical volume "lvprueba2" successfully removed
  Logical volume "lvprueba3" successfully removed
  Logical volume "lvprueba4" successfully removed
  Volume group "prueba" successfully removed


root cobalto:/usr/local/src/LVM2/tools# ./lvm lvs
root cobalto:/usr/local/src/LVM2/tools#
root cobalto:/usr/local/src/LVM2/tools# ./lvm vgdisplay prueba
  Volume group "prueba" not found


Sorry i dont know the procedure to submit a patch, this is my firt time ever a send a patch to any gnu project.

Thanks!

Saludos
--------------------------------------
Index: commands.h
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/commands.h,v
retrieving revision 1.98
diff -u -r1.98 commands.h
--- commands.h  1 Aug 2007 21:01:06 -0000       1.98
+++ commands.h  9 Aug 2007 02:28:01 -0000
@@ -806,6 +806,7 @@
 xx(vgremove,
    "Remove volume group(s)",
    "vgremove\n"
+   "\t[-f|--force]\n"
    "\t[-d|--debug]\n"
    "\t[-h|--help]\n"
    "\t[-t|--test]\n"
@@ -813,7 +814,7 @@
    "\t[--version]" "\n"
    "\tVolumeGroupName [VolumeGroupName...]\n",
 
-   test_ARG)
+   force_ARG,test_ARG)
 
 xx(vgrename,
    "Rename a volume group",
@@ -827,7 +828,7 @@
    "\tOldVolumeGroupPath NewVolumeGroupPath |\n"
    "\tOldVolumeGroupName NewVolumeGroupName\n",
 
-   autobackup_ARG, force_ARG, test_ARG)
+   autobackup_ARG, test_ARG)
 
 xx(vgs,
    "Display information about volume groups",
Index: lvm.c

Index: vgremove.c
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/vgremove.c,v
retrieving revision 1.41
diff -u -r1.41 vgremove.c
--- vgremove.c  19 Jun 2007 04:36:12 -0000      1.41
+++ vgremove.c  9 Aug 2007 02:28:04 -0000
@@ -34,9 +34,13 @@
        if (!vg_check_status(vg, EXPORTED_VG))
                return ECMD_FAILED;
 
+       /*
+        * If there is 1 or more lv print a error
+        * */
        if (vg->lv_count) {
                log_error("Volume group \"%s\" still contains %d "
                          "logical volume(s)", vg_name, vg->lv_count);
+
                return ECMD_FAILED;
        }
 
@@ -84,21 +88,39 @@
 int vgremove(struct cmd_context *cmd, int argc, char **argv)
 {
        int ret;
-
+   
+
        if (!argc) {
                log_error("Please enter one or more volume group paths");
                return EINVALID_CMD_LINE;
        }
-
+    //printf("argv= %s \n", argv[0]);
+   
+       //printf("hostname = %s \n" , cmd->cmd_line);
+
+
+
+
        if (!lock_vol(cmd, ORPHAN, LCK_VG_WRITE)) {
                log_error("Can't get lock for orphan PVs");
                return ECMD_FAILED;
        }
-
+/* check  -f argument  */
+       if( arg_count(cmd,force_ARG ) ) {
+               ret=lvremove(cmd,  argc, argv);
+               if( ret==1 ){
+               ret = process_each_vg(cmd, argc, argv,
+                                                
+                                                 LCK_VG_WRITE | LCK_NONBLOCK,1,
+                                                 NULL, & vgremove_single);
+               }
+
+       }
+       else{
        ret = process_each_vg(cmd, argc, argv,
                              LCK_VG_WRITE | LCK_NONBLOCK, 1,
                              NULL, &vgremove_single);
-
+       }
        unlock_vg(cmd, ORPHAN);
 
        return ret;

--
No vivas solo por que respiras, vive para cumplir tus sue~os
Index: commands.h
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/commands.h,v
retrieving revision 1.98
diff -u -r1.98 commands.h
--- commands.h	1 Aug 2007 21:01:06 -0000	1.98
+++ commands.h	9 Aug 2007 02:28:01 -0000
@@ -806,6 +806,7 @@
 xx(vgremove,
    "Remove volume group(s)",
    "vgremove\n"
+   "\t[-f|--force]\n"
    "\t[-d|--debug]\n"
    "\t[-h|--help]\n"
    "\t[-t|--test]\n"
@@ -813,7 +814,7 @@
    "\t[--version]" "\n"
    "\tVolumeGroupName [VolumeGroupName...]\n",
 
-   test_ARG)
+   force_ARG,test_ARG)
 
 xx(vgrename,
    "Rename a volume group",
@@ -827,7 +828,7 @@
    "\tOldVolumeGroupPath NewVolumeGroupPath |\n"
    "\tOldVolumeGroupName NewVolumeGroupName\n",
 
-   autobackup_ARG, force_ARG, test_ARG)
+   autobackup_ARG, test_ARG)
 
 xx(vgs,
    "Display information about volume groups",
Index: lvm.c
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/lvm.c,v
retrieving revision 1.102
diff -u -r1.102 lvm.c
--- lvm.c	14 Feb 2007 16:51:48 -0000	1.102
+++ lvm.c	9 Aug 2007 02:28:01 -0000
@@ -229,7 +229,9 @@
 			log_error("Exiting.");
 			break;
 		}
-
+		/*
+		 * Run command with cmd  and argv parameters
+		 */
 		ret = lvm_run_command(cmd, argc, argv);
 		if (ret == ENO_SUCH_CMD)
 			log_error("No such command '%s'.  Try 'help'.",
Index: lvmcmdline.c
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/lvmcmdline.c,v
retrieving revision 1.45
diff -u -r1.45 lvmcmdline.c
--- lvmcmdline.c	20 Jul 2007 15:48:39 -0000	1.45
+++ lvmcmdline.c	9 Aug 2007 02:28:02 -0000
@@ -591,7 +591,11 @@
 
 		if (opt == '?')
 			return 0;
-
+        /*
+		if (opt == 'f' ){	
+			printf("force option \n");
+		}
+		*/
 		a = _find_arg(cmd->command, opt);
 
 		if (!a) {
@@ -599,6 +603,9 @@
 			return 0;
 		}
 
+		/*
+		*Execute the function
+		*/
 		if (a->fn) {
 			if (a->count) {
 				log_error("Option%s%c%s%s may not be repeated",
@@ -615,7 +622,7 @@
 			}
 
 			a->value = optarg;
-
+            
 			if (!a->fn(cmd, a)) {
 				log_error("Invalid argument %s", optarg);
 				return 0;
@@ -921,6 +928,8 @@
 		goto out;
 	}
 
+	/*Call the function read from shell
+	 */
 	ret = cmd->command->fn(cmd, argc, argv);
 
 	fin_locking();
@@ -1195,7 +1204,9 @@
 		argc--;
 		argv++;
 	}
-
+    /*
+	*Execute the command
+	*/
 	ret = lvm_run_command(cmd, argc, argv);
 	if ((ret == ENO_SUCH_CMD) && (!alias))
 		ret = _run_script(cmd, argc, argv);
Index: lvrename.c
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/lvrename.c,v
retrieving revision 1.45
retrieving revision 1.44
diff -u -r1.45 -r1.44
--- lvrename.c	3 Aug 2007 21:22:10 -0000	1.45
+++ lvrename.c	23 Jul 2007 22:20:42 -0000	1.44
@@ -16,11 +16,6 @@
 #include "tools.h"
 #include "lvm-types.h"
 
-
-/*
- * lvrename command implementation.
- * Check arguments and call lv_rename() to execute the request.
- */
 int lvrename(struct cmd_context *cmd, int argc, char **argv)
 {
 	size_t maxlen;
@@ -29,6 +24,7 @@
 	char *st;
 
 	struct volume_group *vg;
+	struct logical_volume *lv;
 	struct lv_list *lvl;
 
 	if (argc == 3) {
@@ -107,14 +103,72 @@
 				    CORRECT_INCONSISTENT)))
 		return ECMD_FAILED;
 
+	if (find_lv_in_vg(vg, lv_name_new)) {
+		log_error("Logical volume \"%s\" already exists in "
+			  "volume group \"%s\"", lv_name_new, vg_name);
+		goto error;
+	}
+
 	if (!(lvl = find_lv_in_vg(vg, lv_name_old))) {
 		log_error("Existing logical volume \"%s\" not found in "
 			  "volume group \"%s\"", lv_name_old, vg_name);
 		goto error;
 	}
 
-	if (!lv_rename(cmd, lvl->lv, lv_name_new))
+	lv = lvl->lv;
+
+	if (lv->status & LOCKED) {
+		log_error("Cannot rename locked LV %s", lv->name);
 		goto error;
+	}
+
+	if ((lv->status & MIRRORED) ||
+	    (lv->status & MIRROR_LOG) ||
+	    (lv->status & MIRROR_IMAGE)) {
+		log_error("Mirrored LV, \"%s\" cannot be renamed: %s",
+			  lv->name, strerror(ENOSYS));
+		goto error;
+	}
+
+	if ((lv->status & MIRRORED) ||
+	    (lv->status & MIRROR_LOG) ||
+	    (lv->status & MIRROR_IMAGE)) {
+		log_error("Mirrored LV, \"%s\" cannot be renamed: %s",
+			  lv->name, strerror(ENOSYS));
+		goto error;
+	}
+
+	if (!archive(lv->vg)) {
+		stack;
+		goto error;
+	}
+
+	if (!(lv->name = dm_pool_strdup(cmd->mem, lv_name_new))) {
+		log_error("Failed to allocate space for new name");
+		goto error;
+	}
+
+	log_verbose("Writing out updated volume group");
+	if (!vg_write(vg)) {
+		stack;
+		goto error;
+	}
+
+	backup(lv->vg);
+
+	if (!suspend_lv(cmd, lv)) {
+		stack;
+		vg_revert(vg);
+		goto error;
+	}
+
+	if (!vg_commit(vg)) {
+		stack;
+		resume_lv(cmd, lv);
+		goto error;
+	}
+
+	resume_lv(cmd, lv);
 
 	unlock_vg(cmd, vg_name);
 
Index: toollib.c
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/toollib.c,v
retrieving revision 1.103
diff -u -r1.103 toollib.c
--- toollib.c	7 Aug 2007 09:06:05 -0000	1.103
+++ toollib.c	9 Aug 2007 02:28:03 -0000
@@ -25,7 +25,7 @@
 #define MIRROR_DISK_VERSION 2
 
 /* Command line args */
-unsigned arg_count(const struct cmd_context *cmd, int a)
+unsigned arg_count(struct cmd_context *cmd, int a)
 {
 	return cmd->args[a].count;
 }
@@ -142,12 +142,12 @@
 /*
  * Metadata iteration functions
  */
-int process_each_lv_in_vg(struct cmd_context *cmd,
-			  const struct volume_group *vg,
-			  const struct list *arg_lvnames,
-			  const struct list *tags,
+int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
+			  struct list *arg_lvnames, struct list *tags,
 			  void *handle,
-			  process_single_lv_fn_t process_single)
+			  int (*process_single) (struct cmd_context * cmd,
+						 struct logical_volume * lv,
+						 void *handle))
 {
 	int ret_max = 0;
 	int ret = 0;
@@ -531,7 +531,7 @@
 	list_init(&tags);
 	list_init(&arg_vgnames);
 
-	if (argc) {
+		if (argc) {
 		log_verbose("Using volume group(s) on command line");
 
 		for (; opt < argc; opt++) {
@@ -603,8 +603,11 @@
 }
 
 int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
-			  const struct list *tags, void *handle,
-			  process_single_pv_fn_t process_single)
+			  struct list *tags, void *handle,
+			  int (*process_single) (struct cmd_context * cmd,
+						 struct volume_group * vg,
+						 struct physical_volume * pv,
+						 void *handle))
 {
 	int ret_max = 0;
 	int ret = 0;
Index: toollib.h
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/toollib.h,v
retrieving revision 1.48
retrieving revision 1.47
diff -u -r1.48 -r1.47
--- toollib.h	7 Aug 2007 09:06:05 -0000	1.48
+++ toollib.h	18 Jul 2007 15:38:58 -0000	1.47
@@ -60,25 +60,19 @@
 						      struct lv_segment * seg,
 						      void *handle));
 
-typedef int (*process_single_pv_fn_t) (struct cmd_context *cmd,
-				  struct volume_group *vg,
-				  struct physical_volume *pv,
-				  void *handle);
-
 int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
-			  const struct list *tags, void *handle,
-			  process_single_pv_fn_t process_single);
+			  struct list *tags, void *handle,
+			  int (*process_single) (struct cmd_context * cmd,
+						 struct volume_group * vg,
+						 struct physical_volume * pv,
+						 void *handle));
 
-typedef int (*process_single_lv_fn_t) (struct cmd_context *cmd,
-				  struct logical_volume *lv,
-				  void *handle);
-
-int process_each_lv_in_vg(struct cmd_context *cmd,
-			  const struct volume_group *vg,
-			  const struct list *arg_lvnames,
-			  const struct list *tags,
+int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
+			  struct list *arg_lvnames, struct list *tags,
 			  void *handle,
-			  process_single_lv_fn_t process_single);
+			  int (*process_single) (struct cmd_context * cmd,
+						 struct logical_volume * lv,
+						 void *handle));
 
 char *default_vgname(struct cmd_context *cmd);
 const char *extract_vgname(struct cmd_context *cmd, const char *lv_name);
Index: tools.h
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/tools.h,v
retrieving revision 1.54
diff -u -r1.54 tools.h
--- tools.h	7 Aug 2007 09:06:05 -0000	1.54
+++ tools.h	9 Aug 2007 02:28:04 -0000
@@ -100,7 +100,7 @@
 	char _padding[7];
 	const char *long_arg;
 
-	int (*fn) (struct cmd_context * cmd, struct arg * a);
+	int (*fn) (struct cmd_context * 	cmd, struct arg * a);
 
 	unsigned count;
 	char *value;
@@ -147,7 +147,7 @@
 char yes_no_prompt(const char *prompt, ...);
 
 /* we use the enums to access the switches */
-unsigned int arg_count(const struct cmd_context *cmd, int a);
+unsigned int arg_count(struct cmd_context *cmd, int a);
 const char *arg_value(struct cmd_context *cmd, int a);
 const char *arg_str_value(struct cmd_context *cmd, int a, const char *def);
 int32_t arg_int_value(struct cmd_context *cmd, int a, const int32_t def); 
Index: vgdisplay.c
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/vgdisplay.c,v
retrieving revision 1.18
retrieving revision 1.17
diff -u -r1.18 -r1.17
--- vgdisplay.c	7 Aug 2007 09:06:05 -0000	1.18
+++ vgdisplay.c	19 Jun 2007 04:36:12 -0000	1.17
@@ -46,11 +46,10 @@
 		vgdisplay_extents(vg);
 
 		process_each_lv_in_vg(cmd, vg, NULL, NULL, NULL,
-				      (process_single_lv_fn_t)lvdisplay_full);
+				      &lvdisplay_full);
 
 		log_print("--- Physical volumes ---");
-		process_each_pv_in_vg(cmd, vg, NULL, NULL,
-				      (process_single_pv_fn_t)pvdisplay_short);
+		process_each_pv_in_vg(cmd, vg, NULL, NULL, &pvdisplay_short);
 	}
 
 	check_current_backup(vg);
@@ -99,7 +98,7 @@
 **********/
 
 	process_each_vg(cmd, argc, argv, LCK_VG_READ, 0, NULL,
-			vgdisplay_single);
+			&vgdisplay_single);
 
 /******** FIXME Need to count number processed 
 	  Add this to process_each_vg if arg_count(cmd,activevolumegroups_ARG) ? 
Index: vgremove.c
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/vgremove.c,v
retrieving revision 1.41
diff -u -r1.41 vgremove.c
--- vgremove.c	19 Jun 2007 04:36:12 -0000	1.41
+++ vgremove.c	9 Aug 2007 02:28:04 -0000
@@ -34,9 +34,13 @@
 	if (!vg_check_status(vg, EXPORTED_VG))
 		return ECMD_FAILED;
 
+	/* 
+	 * If there is 1 or more lv print a error
+	 * */
 	if (vg->lv_count) {
 		log_error("Volume group \"%s\" still contains %d "
 			  "logical volume(s)", vg_name, vg->lv_count);
+
 		return ECMD_FAILED;
 	}
 
@@ -84,21 +88,39 @@
 int vgremove(struct cmd_context *cmd, int argc, char **argv)
 {
 	int ret;
-
+    
+	
 	if (!argc) {
 		log_error("Please enter one or more volume group paths");
 		return EINVALID_CMD_LINE;
 	}
-
+    //printf("argv= %s \n", argv[0]);
+    
+	//printf("hostname = %s \n" , cmd->cmd_line);
+	
+	
+	
+	
 	if (!lock_vol(cmd, ORPHAN, LCK_VG_WRITE)) {
 		log_error("Can't get lock for orphan PVs");
 		return ECMD_FAILED;
 	}
-
+/* check  -f argument  */
+	if( arg_count(cmd,force_ARG ) ) {
+		ret=lvremove(cmd,  argc, argv);
+		if( ret==1 ){
+		ret = process_each_vg(cmd, argc, argv, 
+						  
+						  LCK_VG_WRITE | LCK_NONBLOCK,1,
+						  NULL, & vgremove_single);
+		}
+		
+	}
+	else{
 	ret = process_each_vg(cmd, argc, argv,
 			      LCK_VG_WRITE | LCK_NONBLOCK, 1, 
 			      NULL, &vgremove_single);
-
+	}
 	unlock_vg(cmd, ORPHAN);
 
 	return ret;

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