@@ -101,81 +101,6 @@ public StorageVol createVolume(Connect conn, StoragePool pool, String uuid,
101101 return pool .storageVolCreateXML (volDef .toString (), 0 );
102102 }
103103
104- public StoragePool getStoragePoolbyURI (Connect conn , URI uri )
105- throws LibvirtException {
106- String sourcePath ;
107- String uuid ;
108- String sourceHost = "" ;
109- String protocal ;
110- if (uri .getScheme ().equalsIgnoreCase ("local" )) {
111- sourcePath = _mountPoint + File .separator
112- + uri .toString ().replace ("local:///" , "" );
113- sourcePath = sourcePath .replace ("//" , "/" );
114- uuid = UUID .nameUUIDFromBytes (new String (sourcePath ).getBytes ())
115- .toString ();
116- protocal = "DIR" ;
117- } else {
118- sourcePath = uri .getPath ();
119- sourcePath = sourcePath .replace ("//" , "/" );
120- sourceHost = uri .getHost ();
121- uuid = UUID .nameUUIDFromBytes (
122- new String (sourceHost + sourcePath ).getBytes ()).toString ();
123- protocal = "NFS" ;
124- }
125-
126- String targetPath = _mountPoint + File .separator + uuid ;
127- StoragePool sp = null ;
128- try {
129- sp = conn .storagePoolLookupByUUIDString (uuid );
130- } catch (LibvirtException e ) {
131- }
132-
133- if (sp == null ) {
134- try {
135- LibvirtStoragePoolDef spd = null ;
136- if (protocal .equalsIgnoreCase ("NFS" )) {
137- _storageLayer .mkdir (targetPath );
138- spd = new LibvirtStoragePoolDef (poolType .NETFS , uuid , uuid ,
139- sourceHost , sourcePath , targetPath );
140- s_logger .debug (spd .toString ());
141- // addStoragePool(uuid);
142-
143- } else if (protocal .equalsIgnoreCase ("DIR" )) {
144- _storageLayer .mkdir (targetPath );
145- spd = new LibvirtStoragePoolDef (poolType .DIR , uuid , uuid ,
146- null , null , sourcePath );
147- }
148-
149- synchronized (getStoragePool (uuid )) {
150- sp = conn .storagePoolDefineXML (spd .toString (), 0 );
151- if (sp == null ) {
152- s_logger .debug ("Failed to define storage pool" );
153- return null ;
154- }
155- sp .create (0 );
156- }
157-
158- return sp ;
159- } catch (LibvirtException e ) {
160- try {
161- if (sp != null ) {
162- sp .undefine ();
163- sp .free ();
164- }
165- } catch (LibvirtException l ) {
166-
167- }
168- throw e ;
169- }
170- } else {
171- StoragePoolInfo spi = sp .getInfo ();
172- if (spi .state != StoragePoolState .VIR_STORAGE_POOL_RUNNING ) {
173- sp .create (0 );
174- }
175- return sp ;
176- }
177- }
178-
179104 public void storagePoolRefresh (StoragePool pool ) {
180105 try {
181106 synchronized (getStoragePool (pool .getUUIDString ())) {
@@ -368,32 +293,6 @@ public LibvirtStorageVolumeDef getStorageVolumeDef(Connect conn,
368293 return parser .parseStorageVolumeXML (volDefXML );
369294 }
370295
371- public StorageVol getVolumeFromURI (Connect conn , String volPath )
372- throws LibvirtException , URISyntaxException {
373- int index = volPath .lastIndexOf ("/" );
374- URI volDir = null ;
375- StoragePool sp = null ;
376- StorageVol vol = null ;
377- try {
378- volDir = new URI (volPath .substring (0 , index ));
379- String volName = volPath .substring (index + 1 );
380- sp = getStoragePoolbyURI (conn , volDir );
381- vol = sp .storageVolLookupByName (volName );
382- return vol ;
383- } catch (LibvirtException e ) {
384- s_logger .debug ("Faild to get vol path: " + e .toString ());
385- throw e ;
386- } finally {
387- try {
388- if (sp != null ) {
389- sp .free ();
390- }
391- } catch (LibvirtException e ) {
392-
393- }
394- }
395- }
396-
397296 public StoragePool createFileBasedStoragePool (Connect conn ,
398297 String localStoragePath , String uuid ) {
399298 if (!(_storageLayer .exists (localStoragePath ) && _storageLayer
@@ -821,7 +720,7 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name,
821720 }
822721
823722 @ Override
824- public KVMStoragePool getStoragePoolByUri (String uri ) {
723+ public KVMStoragePool getStoragePoolByURI (String uri ) {
825724 URI storageUri = null ;
826725
827726 try {
@@ -838,11 +737,12 @@ public KVMStoragePool getStoragePoolByUri(String uri) {
838737 sourcePath = storageUri .getPath ();
839738 sourcePath = sourcePath .replace ("//" , "/" );
840739 sourceHost = storageUri .getHost ();
841- uuid = UUID .randomUUID ().toString ();
740+ uuid = UUID .nameUUIDFromBytes (
741+ new String (sourceHost + sourcePath ).getBytes ()).toString ();
842742 protocal = StoragePoolType .NetworkFilesystem ;
843743 }
844744
845- return createStoragePool (uuid , sourceHost , 0 , sourcePath , "" , protocal );
745+ return createStoragePool (uuid , sourceHost , 0 , sourcePath , "" , protocal );
846746 }
847747
848748 @ Override
0 commit comments