Skip to content

Commit 97365e4

Browse files
jeongda-youngDajeong-Park
authored andcommitted
usb, lun 디바이스 할당/해제
1 parent eba9b2b commit 97365e4

File tree

2 files changed

+49
-24
lines changed

2 files changed

+49
-24
lines changed

core/src/main/java/com/cloud/resource/ServerResourceBase.java

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919

2020
package com.cloud.resource;
2121

22+
import com.cloud.agent.IAgentControl;
23+
import com.cloud.agent.api.Answer;
24+
import com.cloud.agent.api.Command;
25+
import com.cloud.agent.api.ListHostDeviceAnswer;
26+
import com.cloud.agent.api.ListHostLunDeviceAnswer;
27+
import com.cloud.agent.api.ListHostUsbDeviceAnswer;
28+
import com.cloud.agent.api.StartupCommand;
29+
import com.cloud.agent.api.UpdateHostLunDeviceAnswer;
30+
import com.cloud.agent.api.UpdateHostUsbDeviceAnswer;
31+
import com.cloud.utils.net.NetUtils;
32+
import com.cloud.utils.script.OutputInterpreter;
33+
import com.cloud.utils.script.Script;
2234
import java.io.File;
2335
import java.io.FileWriter;
2436
import java.io.IOException;
@@ -36,28 +48,19 @@
3648
import java.util.List;
3749
import java.util.Locale;
3850
import java.util.Map;
39-
4051
import javax.naming.ConfigurationException;
41-
42-
import org.apache.cloudstack.storage.command.browser.ListRbdObjectsAnswer;
4352
import org.apache.cloudstack.storage.command.browser.ListDataStoreObjectsAnswer;
53+
import org.apache.cloudstack.storage.command.browser.ListRbdObjectsAnswer;
4454
import org.apache.commons.collections.CollectionUtils;
4555
import org.apache.commons.lang3.StringUtils;
4656
import org.apache.logging.log4j.LogManager;
4757
import org.apache.logging.log4j.Logger;
4858
import org.json.JSONArray;
4959
import org.json.JSONObject;
50-
import com.cloud.agent.IAgentControl;
51-
import com.cloud.agent.api.Answer;
52-
import com.cloud.agent.api.Command;
53-
import com.cloud.agent.api.ListHostDeviceAnswer;
54-
import com.cloud.agent.api.ListHostLunDeviceAnswer;
55-
import com.cloud.agent.api.ListHostUsbDeviceAnswer;
56-
import com.cloud.agent.api.StartupCommand;
57-
import com.cloud.agent.api.UpdateHostUsbDeviceAnswer;
58-
import com.cloud.utils.net.NetUtils;
59-
import com.cloud.utils.script.OutputInterpreter;
60-
import com.cloud.utils.script.Script;
60+
61+
62+
// import org.apache.cloudstack.storage.command.browser.ListRbdObjectsAnswer;
63+
6164
// import com.cloud.agent.api.ListHostLunDeviceCommand;
6265

6366
public abstract class ServerResourceBase implements ServerResource {
@@ -235,18 +238,17 @@ public Answer listHostLunDevices(Command command) {
235238
String size = device.getString("size");
236239

237240
// 파티션 존재 여부 확인
238-
JSONArray children = device.optJSONArray("children");
239-
boolean hasPartition = (children != null && children.length() > 0);
241+
boolean hasPartition = hasPartitionRecursive(device);
240242

241243
StringBuilder info = new StringBuilder();
242244
if (isMultipathActive && name.startsWith("/dev/disk/by-path/")) {
243-
info.append("Multipath LUN Device: ").append(name);
245+
// info.append("Multipath LUN Device: ").append(name);
244246
} else {
245-
info.append("LUN Device: ").append(name);
247+
// info.append("LUN Device: ").append(name);
246248
}
247-
info.append(" Size: ").append(size);
249+
info.append(size);
248250
if (hasPartition) {
249-
info.append(" (").append(children.length()).append(" partitions)");
251+
info.append(" (").append(hasPartition ? "has partitions" : "no partitions").append(")");
250252
}
251253

252254
hostDevicesNames.add(name);
@@ -274,6 +276,25 @@ private boolean checkMultipathStatus() {
274276
return "active".equals(result != null ? result.trim() : "");
275277
}
276278

279+
private boolean hasPartitionRecursive(JSONObject device) {
280+
// children이 없으면 false
281+
if (!device.has("children")) {
282+
return false;
283+
}
284+
JSONArray children = device.getJSONArray("children");
285+
for (int i = 0; i < children.length(); i++) {
286+
JSONObject child = children.getJSONObject(i);
287+
String type = child.optString("type", "");
288+
if ("part".equals(type)) {
289+
return true;
290+
}
291+
if (hasPartitionRecursive(child)) {
292+
return true;
293+
}
294+
}
295+
return false;
296+
}
297+
277298
protected Answer createImageRbd(String poolUuid, String skey, String authUserName, String host, String names, long sizes, String poolPath) {
278299
createRBDSecretKeyFileIfNoExist(poolUuid, DEFAULT_LOCAL_STORAGE_PATH, skey);
279300
String cmdout = Script.runSimpleBashScript("rbd -p " + poolPath + " --id " + authUserName + " -m " + host + " -K " + DEFAULT_LOCAL_STORAGE_PATH + poolUuid + " create -s " + (sizes * 1024) + " " + names);
@@ -626,6 +647,8 @@ protected Answer updateHostUsbDevices(Command command, String vmName, String xml
626647
logger.info("Executing detach command for VM: {} with XML: {}", vmName, xmlConfig);
627648
}
628649

650+
logger.info("isAttach value: {}", isAttach);
651+
629652
String result = virshCmd.execute();
630653

631654
if (result != null) {
@@ -664,22 +687,24 @@ protected Answer updateHostLunDevices(Command command, String vmName, String xml
664687
logger.info("Executing detach command for VM: {} with XML: {}", vmName, xmlConfig);
665688
}
666689

690+
logger.info("isAttach value: {}", isAttach);
691+
667692
String result = virshCmd.execute();
668693

669694
if (result != null) {
670695
String action = isAttach ? "attach" : "detach";
671696
logger.error("Failed to {} USB device: {}", action, result);
672-
return new UpdateHostUsbDeviceAnswer(false, vmName, xmlConfig, isAttach);
697+
return new UpdateHostLunDeviceAnswer(false, vmName, xmlConfig, isAttach);
673698
}
674699

675700
String action = isAttach ? "attached to" : "detached from";
676701
logger.info("Successfully {} USB device for VM {}", action, vmName);
677-
return new UpdateHostUsbDeviceAnswer(true, vmName, xmlConfig, isAttach);
702+
return new UpdateHostLunDeviceAnswer(true, vmName, xmlConfig, isAttach);
678703

679704
} catch (Exception e) {
680705
String action = isAttach ? "attaching" : "detaching";
681706
logger.error("Error {} USB device: {}", action, e.getMessage(), e);
682-
return new UpdateHostUsbDeviceAnswer(false, vmName, xmlConfig, isAttach);
707+
return new UpdateHostLunDeviceAnswer(false, vmName, xmlConfig, isAttach);
683708
}
684709
}
685710
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4259,7 +4259,7 @@ private void createVif(final LibvirtVMDef vm, final VirtualMachineTO vmSpec, fin
42594259
enableOVSDriver = true;
42604260
}
42614261

4262-
if (!nic.isSecurityGroupEnabled() && !enableOVSDriver && nic.getNwfilter()) {
4262+
if (!nic.isSecurityGroupEnabled() && !enableOVSDriver) {
42634263
interfaceDef.setFilterrefFilterTag();
42644264
}
42654265
if (vmSpec.getDetails() != null) {

0 commit comments

Comments
 (0)