@@ -127,6 +127,14 @@ public class KVMStorageProcessor implements StorageProcessor {
127127 private String _createTmplPath ;
128128 private String _manageSnapshotPath ;
129129 private int _cmdsTimeout ;
130+
131+ private static final String MANAGEME_SNAPSTHOT_CREATE = "-c" ;
132+ private static final String MANAGEME_SNAPSTHOT_DESTROY = "-d" ;
133+ private static final String NAME = "-n" ;
134+ private static final String CEPH_MON_HOST = "mon_host" ;
135+ private static final String CEPH_AUTH_KEY = "key" ;
136+ private static final String CEPH_CLIENT_MOUNT_TIMEOUT = "client_mount_timeout" ;
137+ private static final String CEPH_DEFAULT_MOUNT_TIMEOUT = "30" ;
130138
131139 public KVMStorageProcessor (final KVMStoragePoolManager storagePoolMgr , final LibvirtComputingResource resource ) {
132140 this .storagePoolMgr = storagePoolMgr ;
@@ -563,7 +571,7 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) {
563571 final Script command = new Script (_createTmplPath , wait , s_logger );
564572 command .add ("-f" , disk .getPath ());
565573 command .add ("-t" , tmpltPath );
566- command .add ("-n" , templateName + ".qcow2" );
574+ command .add (NAME , templateName + ".qcow2" );
567575
568576 final String result = command .execute ();
569577
@@ -949,7 +957,7 @@ public Answer backupSnapshot(final CopyCommand cmd) {
949957 } else {
950958 final Script command = new Script (_manageSnapshotPath , cmd .getWaitInMillSeconds (), s_logger );
951959 command .add ("-b" , snapshotDisk .getPath ());
952- command .add ("-n" , snapshotName );
960+ command .add (NAME , snapshotName );
953961 command .add ("-p" , snapshotDestPath );
954962 if (isCreatedFromVmSnapshot ) {
955963 descName = UUID .randomUUID ().toString ();
@@ -1010,14 +1018,7 @@ public Answer backupSnapshot(final CopyCommand cmd) {
10101018 }
10111019 } else {
10121020 if (primaryPool .getType () != StoragePoolType .RBD ) {
1013- final Script command = new Script (_manageSnapshotPath , _cmdsTimeout , s_logger );
1014- command .add ("-d" , snapshotDisk .getPath ());
1015- command .add ("-n" , snapshotName );
1016- final String result = command .execute ();
1017- if (result != null ) {
1018- s_logger .debug ("Failed to delete snapshot on primary: " + result );
1019- // return new CopyCmdAnswer("Failed to backup snapshot: " + result);
1020- }
1021+ deleteSnapshotViaManageSnapshotScript (snapshotName , snapshotDisk );
10211022 }
10221023 }
10231024 } catch (final Exception ex ) {
@@ -1035,6 +1036,16 @@ public Answer backupSnapshot(final CopyCommand cmd) {
10351036 }
10361037 }
10371038
1039+ private void deleteSnapshotViaManageSnapshotScript (final String snapshotName , KVMPhysicalDisk snapshotDisk ) {
1040+ final Script command = new Script (_manageSnapshotPath , _cmdsTimeout , s_logger );
1041+ command .add (MANAGEME_SNAPSTHOT_DESTROY , snapshotDisk .getPath ());
1042+ command .add (NAME , snapshotName );
1043+ final String result = command .execute ();
1044+ if (result != null ) {
1045+ s_logger .debug ("Failed to delete snapshot on primary: " + result );
1046+ }
1047+ }
1048+
10381049 protected synchronized String attachOrDetachISO (final Connect conn , final String vmName , String isoPath , final boolean isAttach ) throws LibvirtException , URISyntaxException ,
10391050 InternalErrorException {
10401051 String isoXml = null ;
@@ -1489,12 +1500,7 @@ public Answer createSnapshot(final CreateObjectCommand cmd) {
14891500 */
14901501 if (primaryPool .getType () == StoragePoolType .RBD ) {
14911502 try {
1492- final Rados r = new Rados (primaryPool .getAuthUserName ());
1493- r .confSet ("mon_host" , primaryPool .getSourceHost () + ":" + primaryPool .getSourcePort ());
1494- r .confSet ("key" , primaryPool .getAuthSecret ());
1495- r .confSet ("client_mount_timeout" , "30" );
1496- r .connect ();
1497- s_logger .debug ("Succesfully connected to Ceph cluster at " + r .confGet ("mon_host" ));
1503+ Rados r = radosConnect (primaryPool );
14981504
14991505 final IoCTX io = r .ioCtxCreate (primaryPool .getSourceDir ());
15001506 final Rbd rbd = new Rbd (io );
@@ -1511,8 +1517,8 @@ public Answer createSnapshot(final CreateObjectCommand cmd) {
15111517 } else {
15121518 /* VM is not running, create a snapshot by ourself */
15131519 final Script command = new Script (_manageSnapshotPath , _cmdsTimeout , s_logger );
1514- command .add ("-c" , disk .getPath ());
1515- command .add ("-n" , snapshotName );
1520+ command .add (MANAGEME_SNAPSTHOT_CREATE , disk .getPath ());
1521+ command .add (NAME , snapshotName );
15161522 final String result = command .execute ();
15171523 if (result != null ) {
15181524 s_logger .debug ("Failed to manage snapshot: " + result );
@@ -1531,6 +1537,16 @@ public Answer createSnapshot(final CreateObjectCommand cmd) {
15311537 }
15321538 }
15331539
1540+ private Rados radosConnect (final KVMStoragePool primaryPool ) throws RadosException {
1541+ Rados r = new Rados (primaryPool .getAuthUserName ());
1542+ r .confSet (CEPH_MON_HOST , primaryPool .getSourceHost () + ":" + primaryPool .getSourcePort ());
1543+ r .confSet (CEPH_AUTH_KEY , primaryPool .getAuthSecret ());
1544+ r .confSet (CEPH_CLIENT_MOUNT_TIMEOUT , CEPH_DEFAULT_MOUNT_TIMEOUT );
1545+ r .connect ();
1546+ s_logger .debug ("Succesfully connected to Ceph cluster at " + r .confGet (CEPH_MON_HOST ));
1547+ return r ;
1548+ }
1549+
15341550 @ Override
15351551 public Answer deleteVolume (final DeleteCommand cmd ) {
15361552 final VolumeObjectTO vol = (VolumeObjectTO )cmd .getData ();
@@ -1619,12 +1635,7 @@ public Answer deleteSnapshot(final DeleteCommand cmd) {
16191635 String snapshotName = snapshotFullPath .substring (snapshotFullPath .lastIndexOf ("/" ) + 1 );
16201636 snap_full_name = disk .getName () + "@" + snapshotName ;
16211637 if (primaryPool .getType () == StoragePoolType .RBD ) {
1622- Rados r = new Rados (primaryPool .getAuthUserName ());
1623- r .confSet ("mon_host" , primaryPool .getSourceHost () + ":" + primaryPool .getSourcePort ());
1624- r .confSet ("key" , primaryPool .getAuthSecret ());
1625- r .confSet ("client_mount_timeout" , "30" );
1626- r .connect ();
1627- s_logger .debug ("Succesfully connected to Ceph cluster at " + r .confGet ("mon_host" ));
1638+ Rados r = radosConnect (primaryPool );
16281639 IoCTX io = r .ioCtxCreate (primaryPool .getSourceDir ());
16291640 Rbd rbd = new Rbd (io );
16301641 RbdImage image = rbd .open (disk .getName ());
@@ -1644,6 +1655,9 @@ public Answer deleteSnapshot(final DeleteCommand cmd) {
16441655 rbd .close (image );
16451656 r .ioCtxDestroy (io );
16461657 }
1658+ } else if (primaryPool .getType () == StoragePoolType .NetworkFilesystem ) {
1659+ s_logger .info (String .format ("Attempting to remove snapshot on primary storage (id=%s, snapshot=%s, storage type=%s)" , snapshotTO .getId (), snap_full_name , primaryPool .getType ()));
1660+ deleteSnapshotViaManageSnapshotScript (snapshotName , disk );
16471661 } else {
16481662 s_logger .warn ("Operation not implemented for storage pool type of " + primaryPool .getType ().toString ());
16491663 throw new InternalErrorException ("Operation not implemented for storage pool type of " + primaryPool .getType ().toString ());
0 commit comments