DaanHoogland commented on a change in pull request #3819: Clean up inactive iscsi sessions when VMs get moved due to crashes URL: https://github.com/apache/cloudstack/pull/3819#discussion_r371929778
########## File path: plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiStorageCleanupMonitor.java ########## @@ -0,0 +1,143 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.hypervisor.kvm.storage; + +import com.cloud.hypervisor.kvm.resource.LibvirtConnection; +import com.cloud.hypervisor.kvm.resource.LibvirtDomainXMLParser; +import com.cloud.hypervisor.kvm.resource.LibvirtVMDef; +import org.apache.cloudstack.managed.context.ManagedContextRunnable; +import org.apache.log4j.Logger; +import org.libvirt.Connect; +import org.libvirt.Domain; +import org.libvirt.LibvirtException; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class IscsiStorageCleanupMonitor implements Runnable{ + private static final Logger s_logger = Logger.getLogger(IscsiStorageCleanupMonitor.class); + private static final int CLEANUP_INTERVAL_SEC = 60; // check every X seconds + private static final String ISCSI_PATH_PREFIX = "/dev/disk/by-path"; + private static final String KEYWORD_ISCSI = "iscsi"; + private static final String KEYWORD_IQN = "iqn"; + + private IscsiAdmStorageAdaptor iscsiStorageAdaptor; + + private Map<String, Boolean> diskStatusMap; + + public IscsiStorageCleanupMonitor() { + diskStatusMap = new HashMap<>(); + s_logger.debug("Initialize cleanup thread"); + iscsiStorageAdaptor = new IscsiAdmStorageAdaptor(); + } + + + private class Monitor extends ManagedContextRunnable { + + @Override + protected void runInContext() { Review comment: long method with a lot of comment. can you please factor out the pieces that need commenting in their own method with clear names? that would make this thread code more maintainable for future generations. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
