Skip to content

Commit f89bb1b

Browse files
Srivastava, PiyushSrivastava, Piyush
authored andcommitted
storage pool mounting on host 1
1 parent aa14ab5 commit f89bb1b

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet
116116
createCmdResult = new CreateCmdResult(null, new Answer(null, false, errMsg));
117117
createCmdResult.setResult(e.toString());
118118
} finally {
119+
s_logger.info("Volume creation successfully completed");
119120
callback.complete(createCmdResult);
120121
}
121122
}

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/listener/OntapHostListener.java

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import javax.inject.Inject;
2121

2222
import com.cloud.agent.api.ModifyStoragePoolCommand;
23+
import com.cloud.agent.api.ModifyStoragePoolAnswer;
24+
import com.cloud.agent.api.StoragePoolInfo;
2325
import com.cloud.alert.AlertManager;
2426
import com.cloud.storage.StoragePoolHostVO;
2527
import com.cloud.storage.dao.StoragePoolHostDao;
@@ -32,6 +34,7 @@
3234
import com.cloud.storage.StoragePool;
3335
import com.cloud.utils.exception.CloudRuntimeException;
3436
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
37+
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
3538
import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
3639
import com.cloud.host.dao.HostDao;
3740

@@ -67,25 +70,8 @@ public boolean hostConnect(long hostId, long poolId) {
6770
logger.info("Connecting host {} to ONTAP storage pool {}", host.getName(), pool.getName());
6871

6972

70-
// incase host was not added by cloudstack , we will add it
71-
StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(poolId, hostId);
72-
73-
if (storagePoolHost == null) {
74-
storagePoolHost = new StoragePoolHostVO(poolId, hostId, "");
75-
76-
storagePoolHostDao.persist(storagePoolHost);
77-
}
78-
79-
// Validate pool type - ONTAP supports NFS and iSCSI
80-
// StoragePoolType poolType = pool.getPoolType();
81-
// // TODO add iscsi also here
82-
// if (poolType != StoragePoolType.NetworkFilesystem) {
83-
// logger.error("Unsupported pool type {} for ONTAP storage", poolType);
84-
// return false;
85-
// }
86-
8773
try {
88-
// Create the CreateStoragePoolCommand to send to the agent
74+
// Create the ModifyStoragePoolCommand to send to the agent
8975
ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
9076

9177
Answer answer = _agentMgr.easySend(hostId, cmd);
@@ -102,6 +88,39 @@ public boolean hostConnect(long hostId, long poolId) {
10288
throw new CloudRuntimeException(String.format(
10389
"Unable to establish a connection from agent to storage pool %s due to %s", pool, answer.getDetails()));
10490
}
91+
92+
// Get the mount path from the answer
93+
ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer;
94+
StoragePoolInfo poolInfo = mspAnswer.getPoolInfo();
95+
if (poolInfo == null) {
96+
throw new CloudRuntimeException("ModifyStoragePoolAnswer returned null poolInfo");
97+
}
98+
99+
String localPath = poolInfo.getLocalPath();
100+
logger.info("Storage pool {} successfully mounted at: {}", pool.getName(), localPath);
101+
102+
// Update or create the storage_pool_host_ref entry with the correct local_path
103+
StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(poolId, hostId);
104+
105+
if (storagePoolHost == null) {
106+
storagePoolHost = new StoragePoolHostVO(poolId, hostId, localPath);
107+
storagePoolHostDao.persist(storagePoolHost);
108+
logger.info("Created storage_pool_host_ref entry for pool {} and host {}", pool.getName(), host.getName());
109+
} else {
110+
storagePoolHost.setLocalPath(localPath);
111+
storagePoolHostDao.update(storagePoolHost.getId(), storagePoolHost);
112+
logger.info("Updated storage_pool_host_ref entry with local_path: {}", localPath);
113+
}
114+
115+
// Update pool capacity/usage information
116+
StoragePoolVO poolVO = _storagePoolDao.findById(poolId);
117+
if (poolVO != null && poolInfo.getCapacityBytes() > 0) {
118+
poolVO.setCapacityBytes(poolInfo.getCapacityBytes());
119+
poolVO.setUsedBytes(poolInfo.getCapacityBytes() - poolInfo.getAvailableBytes());
120+
_storagePoolDao.update(poolVO.getId(), poolVO);
121+
logger.info("Updated storage pool capacity: {} GB, used: {} GB", poolInfo.getCapacityBytes() / (1024 * 1024 * 1024), (poolInfo.getCapacityBytes() - poolInfo.getAvailableBytes()) / (1024 * 1024 * 1024));
122+
}
123+
105124
} catch (Exception e) {
106125
logger.error("Exception while connecting host {} to storage pool {}", host.getName(), pool.getName(), e);
107126
throw new CloudRuntimeException("Failed to connect host to storage pool: " + e.getMessage(), e);

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedNASStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ private ExportPolicy createExportPolicyRequest(AccessGroup accessGroup,String sv
372372
String ip = (hostStorageIp != null && !hostStorageIp.isEmpty())
373373
? hostStorageIp
374374
: host.getPrivateIpAddress();
375-
String ipToUse = ip + "/32";
375+
String ipToUse = ip + "/31"; // TODO since we have 2 IPs internal and external
376376
ExportRule.ExportClient exportClient = new ExportRule.ExportClient();
377377
exportClient.setMatch(ipToUse);
378378
exportClients.add(exportClient);

0 commit comments

Comments
 (0)