vgremove -f option add
Yesterday I send this mail, but nobody has answer me:
hello, i write a little patch to 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:
(list lv's)
root at 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
(delete vg prueba: here is the point )
root at 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 at cobalto:/usr/local/src/LVM2/tools# ./lvm lvs root at cobalto:/usr/local/src/LVM2/tools#
root at 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
commands.h 9 Aug 2007 02:28:01 -0000 renamed from commands.h 1 Aug 2007 21:01:06 -0000 1.98 +3 -2
@@ -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
vgremove.c 9 Aug 2007 02:28:04 -0000 renamed from vgremove.c 19 Jun 2007 04:36:12 -0000 1.41 +20 -3
@@ -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; Signature · 19 lines
No vivas solo por que respiras, vive para cumplir tus sue~os Este mensaje es exclusivamente para el uso de la persona o entidad a quien esta dirigido; contiene informacion estrictamente confidencial y legalmente protegida, cuya divulgacion es sancionada por la ley. Si el lector de este mensaje no es a quien esta dirigido, ni se trata del empleado o agente responsable de esta informacion, se le notifica por medio del presente, que su reproduccion y distribucion, esta estrictamente prohibida. Si Usted recibio este comunicado por error, favor de notificarlo inmediatamente al remitente y destruir el mensaje. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Radiomovil Dipsa, S.A. de C.V. o alguna de sus empresas controladas, controladoras, afiliadas y subsidiarias. Este mensaje intencionalmente no contiene acentos. This message is for the sole use of the person or entity to whom it is being sent. Therefore, it contains strictly confidential and legally protected material whose disclosure is subject to penalty by law. If the person reading this message is not the one to whom it is being sent and/or is not an employee or the responsible agent for this information, this person is herein notified that any unauthorized dissemination, distribution or copying of the materials included in this facsimile is strictly prohibited. If you received this document by mistake please notify immediately to the subscriber and destroy the message. Any opinions contained in this e-mail are those of the author of the message and do not necessarily coincide with those of Radiomovil Dipsa, S.A. de C.V. or any of its control, controlled, affiliates and subsidiaries companies. No part of this message or attachments may be used or reproduced in any manner whatsoever. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://listman.redhat.com/archives/lvm-devel/attachments/20070809/78069254/attachment.htm> -------------- next part -------------- A non-text attachment was scrubbed... Name: vgremove-force_option.diff Type: application/octet-stream Size: 11367 bytes Desc: not available URL: <http://listman.redhat.com/archives/lvm-devel/attachments/20070809/78069254/attachment.obj>
Quoted 34 lines · jorge alberto garcia gonzalez
Yesterday I send this mail, but nobody has answer me:
hello, i write a little patch to 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:
(list lv?s)
root at 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(delete vg prueba: here is the point )
root at 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
Quoted 9 lines
root at cobalto:/usr/local/src/LVM2/tools# ./lvm lvs root at cobalto:/usr/local/src/LVM2/tools#
root at cobalto:/usr/local/src/LVM2/tools# ./lvm vgdisplay prueba
Volume group "prueba" not foundSorry i dont know the procedure to submit a patch, this is my firt time ever a send a patch to any gnu project.
Thanks for the submission - you did fine. In the future, just try to be a little more mindful of the existing coding style. Also try to avoid additions of whitespaces, debug code, etc.
I did some cleanup work first and I've attached an updated patch against the latest code. Patch was tested against a simple cluster as well as single node and seems to work fine. Some sample output in a clustered environment:
# lvs LV VG Attr LSize Origin Snap% Move Log Copy% LogVol00 VolGroup00 -wi-ao 5.84G LogVol01 VolGroup00 -wi-ao 1.03G lv0 vg0 -wi-a- 96.00M # vgs VG #PV #LV #SN Attr VSize VFree VolGroup00 1 2 0 wz--n- 6.91G 32.00M vg0 5 1 0 wz--nc 240.00M 144.00M # vgremove vg0 Do you really want to remove volume group "vg0" with active logical volumes? [y/n]: n Volume group "vg0" not removed # vgremove -f vg0 Error locking on node rhel4u5-node1: Volume is busy on another node Can't get exclusive access to volume "lv0" # vgremove vg0 Do you really want to remove volume group "vg0" with active logical volumes? [y/n]: y Do you really want to remove active logical volume "lv0"? [y/n]: y Error locking on node rhel4u5-node1: Volume is busy on another node Can't get exclusive access to volume "lv0" # lvchange -an vg0/lv0 # vgremove vg0 Do you really want to remove volume group "vg0" with active logical volumes? [y/n]: y Logical volume "lv0" successfully removed Volume group "vg0" successfully removed
Quoted 104 lines
Thanks!
Saludos
--------------------------------------
Index:commands.h
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/commands.h,v
retrieving revision 1.98
diff -u -r1.98commands.hcommands.h 9 Aug 2007 02:28:01 -0000 renamed from commands.h 1 Aug 2007 21:01:06 -0000 1.98 +3
-2@@ -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.cIndex:
vgremove.c
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/vgremove.c,v
retrieving revision 1.41
diff -u -r1.41vgremove.cvgremove.c 9 Aug 2007 02:28:04 -0000 renamed from vgremove.c 19 Jun 2007 04:36:12 -0000 1.41 +26
-4@@ -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); - + }
Quoted 9 lines
unlock_vg(cmd, ORPHAN);
return ret; -------------- next part --------------
A non-text attachment was scrubbed...
Name: vgremove-f-current.patch
Type: text/x-patch
Size: 3359 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/lvm-devel/attachments/20070823/f9769665/attachment.bin>
Quoted 17 lines · Dave Wysochanski
I did some cleanup work first and I've attached an updated patch against the latest code. Patch was tested against a simple cluster as well as single node and seems to work fine. Some sample output in a clustered environment:
# lvs LV VG Attr LSize Origin Snap% Move Log Copy% LogVol00 VolGroup00 -wi-ao 5.84G LogVol01 VolGroup00 -wi-ao 1.03G lv0 vg0 -wi-a- 96.00M # vgs VG #PV #LV #SN Attr VSize VFree VolGroup00 1 2 0 wz--n- 6.91G 32.00M vg0 5 1 0 wz--nc 240.00M 144.00M # vgremove vg0 Do you really want to remove volume group "vg0" with active logical volumes? [y/n]: n Volume group "vg0" not removed
Quoted 8 lines
# vgremove -f vg0 Error locking on node rhel4u5-node1: Volume is busy on another node Can't get exclusive access to volume "lv0" # vgremove vg0 Do you really want to remove volume group "vg0" with active logical volumes? [y/n]: y Do you really want to remove active logical volume "lv0"? [y/n]: y Error locking on node rhel4u5-node1: Volume is busy on another node Can't get exclusive access to volume "lv0"
Updated patch attached that fixes the above case. Now we can remove LVs that may be active on other nodes in the cluster:
[root at rhel4u5-node1 LVM2]# ./tools/lvm vgremove vg0
Do you really want to remove volume group "vg0" containing 1 logical volumes? [y/n]: y
Error locking on node rhel4u5-node1: Volume is busy on another node
Logical volume "lv0" is active on other cluster nodes. Really remove? [y/n]: y
Logical volume "lv0" successfully removed
Volume group "vg0" successfully removed
The new check seems ok even when another node has the LV open (e.g. mounted) - the remove just fails at the deactivate_lv() call for the node(s) that have it open:
[root at rhel4u5-node1 LVM2]# ./tools/lvm vgremove vg0
Do you really want to remove volume group "vg0" containing 1 logical volumes? [y/n]: y
Error locking on node rhel4u5-node1: Volume is busy on another node
Logical volume "lv0" is active on other cluster nodes. Really remove? [y/n]: y
Error locking on node rhel4u5-node3: LV vg0/lv0 in use: not
deactivating
Unable to deactivate logical volume "lv0"
Also cleaned up the first message "Do you really want to remove..." - got rid of "active" word (at that point, we don't know any LVs are active) and printed the number of LVs in the VG.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vgremove-f-current.patch
Type: text/x-patch
Size: 5824 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/lvm-devel/attachments/20070824/eb3a4079/attachment.bin>