More informative logs in Container Admin
authorPawel Broda <p.broda@partner.samsung.com>
Mon, 14 Apr 2014 07:59:38 +0000 (09:59 +0200)
committerJan Olszak <j.olszak@samsung.com>
Mon, 19 May 2014 11:47:15 +0000 (13:47 +0200)
[Bug/Feature]   Add more logs in Container Admin.
                Reformat Container Admin logs.
[Cause]         N/A
[Solution]      N/A
[Verification]  Build and run on the target.

Change-Id: If16acd778a3feba761a349951ca7dc97b89b9309

common/libvirt/helpers.cpp
common/libvirt/helpers.hpp
server/container-admin.cpp
server/container-admin.hpp
server/containers-manager.cpp
server/exception.hpp

index 58ee7b2..87c4705 100644 (file)
@@ -59,25 +59,16 @@ void libvirtInitialize(void)
         });
 }
 
-std::string libvirtFormatError(const std::string& domainName = std::string())
-{
-    std::string ret;
 
+std::string libvirtFormatError(void)
+{
     virErrorPtr error = virGetLastError();
 
     if (error == NULL) {
-        return ret;
-    }
-
-    if (!domainName.empty()) {
-        ret += "LIBVIRT Domain: " + domainName + "\n";
-    }
-
-    if (error->message) {
-        ret += "LIBVIRT Message: " + std::string(error->message);
+        return std::string();
     }
 
-    return ret;
+    return "Libvirt error: " + std::string(error->message);
 }
 
 
index fb9e899..35cac9e 100644 (file)
@@ -38,10 +38,9 @@ namespace libvirt {
 void libvirtInitialize(void);
 
 /**
- * Formats libvirt's last error. Might include
- * the affected domain's name if it exists.
+ * Formats libvirt's last error.
  */
-std::string libvirtFormatError(const std::string& domainName = std::string());
+std::string libvirtFormatError(void);
 
 
 } // namespace libvirt
index b530e4e..6d99189 100644 (file)
@@ -63,12 +63,14 @@ const std::uint64_t DEFAULT_VCPU_PERIOD_MS = 100000;
 ContainerAdmin::ContainerAdmin(ContainerConfig& config)
     : mConfig(config), mDom(utils::readFileContent(mConfig.config)), mId(getDomainName(mDom.get()))
 {
+    LOGD(mId << ": Instantiating ContainerAdmin object");
 }
 
 
 ContainerAdmin::~ContainerAdmin()
 {
     // Try to shutdown
+    LOGD(mId << ": Destroying ContainerAdmin object...");
     try {
         shutdown();
     } catch (ServerException& e) {}
@@ -77,8 +79,10 @@ ContainerAdmin::~ContainerAdmin()
     try {
         stop();
     } catch (ServerException& e) {
-        LOGE("Failed to destroy the container!");
+        LOGE(mId << ": Failed to destroy the container!");
     }
+
+    LOGD(mId << ": ContainerAdmin object destroyed");
 }
 
 
@@ -92,7 +96,9 @@ void ContainerAdmin::start()
 {
     assert(mDom);
 
+    LOGD(mId << ": Starting...");
     if (isRunning()) {
+        LOGD(mId << ": Already running - nothing to do...");
         return;
     }
 
@@ -102,14 +108,16 @@ void ContainerAdmin::start()
     u_int flags = VIR_DOMAIN_START_AUTODESTROY;
 
     if (virDomainCreateWithFlags(mDom.get(), flags) < 0) {
-        LOGE("Failed to start the domain:\n"
-             << libvirt::libvirtFormatError(mId));
+        LOGE(mId << ": Failed to start the domain\n"
+             << libvirt::libvirtFormatError());
         throw DomainOperationException();
     }
 
+    LOGD(mId << ": Started");
     // TODO: the container should be started in the background,
     // unfortunately libvirt doesn't allow us to set cgroups
     // before the start, hence we do it immediately afterwards
+    LOGD(mId << ": Sending to the background");
     setSchedulerLevel(SchedulerLevel::BACKGROUND);
 }
 
@@ -118,7 +126,9 @@ void ContainerAdmin::stop()
 {
     assert(mDom);
 
+    LOGD(mId << ": Stopping...");
     if (isStopped()) {
+        LOGD(mId << ": Already crashed/down/off - nothing to do...");
         return;
     }
 
@@ -126,10 +136,12 @@ void ContainerAdmin::stop()
     u_int flags = VIR_DOMAIN_DESTROY_DEFAULT;
 
     if (virDomainDestroyFlags(mDom.get(), flags) < 0) {
-        LOGE("Error while stopping the domain:\n"
-             << libvirt::libvirtFormatError(mId));
+        LOGE(mId << ": Error while stopping the domain:\n"
+             << libvirt::libvirtFormatError());
         throw DomainOperationException();
     }
+
+    LOGD(mId << ": Stopped");
 }
 
 
@@ -137,17 +149,21 @@ void ContainerAdmin::shutdown()
 {
     assert(mDom);
 
+    LOGD(mId << ": Shutting down...");
     if (isStopped()) {
+        LOGD(mId << ": Already crashed/down/off - nothing to do...");
         return;
     }
 
     resume();
 
     if (virDomainShutdown(mDom.get()) < 0) {
-        LOGE("Error while shutting down the domain:\n"
-             << libvirt::libvirtFormatError(mId));
+        LOGE(mId << ": Error while shutting down the domain:\n"
+             << libvirt::libvirtFormatError());
         throw DomainOperationException();
     }
+
+    LOGD(mId << ": Shut down");
 }
 
 
@@ -170,15 +186,19 @@ void ContainerAdmin::suspend()
 {
     assert(mDom);
 
+    LOGD(mId << ": Pausing...");
     if (isPaused()) {
+        LOGD(mId << ": Already paused - nothing to do...");
         return;
     }
 
     if (virDomainSuspend(mDom.get()) < 0) {
-        LOGE("Error while suspending the domain:\n"
-             << libvirt::libvirtFormatError(mId));
+        LOGE(mId << ": Error while suspending the domain:\n"
+             << libvirt::libvirtFormatError());
         throw DomainOperationException();
     }
+
+    LOGD(mId << ": Paused");
 }
 
 
@@ -186,15 +206,19 @@ void ContainerAdmin::resume()
 {
     assert(mDom);
 
+    LOGD(mId << ": Resuming...");
     if (!isPaused()) {
+        LOGD(mId << ": Is not paused - nothing to do...");
         return;
     }
 
     if (virDomainResume(mDom.get()) < 0) {
-        LOGE("Error while resumming the domain:\n"
-             << libvirt::libvirtFormatError(mId));
+        LOGE(mId << ": Error while resuming the domain:\n"
+             << libvirt::libvirtFormatError());
         throw DomainOperationException();
     }
+
+    LOGD(mId << ": Resumed");
 }
 
 
@@ -211,8 +235,8 @@ int ContainerAdmin::getState()
     int state;
 
     if (virDomainGetState(mDom.get(), &state, NULL, 0)) {
-        LOGE("Error whilte getting the domain's state:\n"
-             << libvirt::libvirtFormatError(mId));
+        LOGE(mId << ": Error while getting the domain's state:\n"
+             << libvirt::libvirtFormatError());
         throw DomainOperationException();
     }
 
@@ -224,11 +248,13 @@ void ContainerAdmin::setSchedulerLevel(SchedulerLevel sched)
 {
     switch (sched) {
     case SchedulerLevel::FOREGROUND:
+        LOGD(mId << ": Setting SchedulerLevel::FOREGROUND");
         setSchedulerParams(DEFAULT_CPU_SHARES,
                            DEFAULT_VCPU_PERIOD_MS,
                            mConfig.cpuQuotaForeground);
         break;
     case SchedulerLevel::BACKGROUND:
+        LOGD(mId << ": Setting SchedulerLevel::BACKGROUND");
         setSchedulerParams(DEFAULT_CPU_SHARES,
                            DEFAULT_VCPU_PERIOD_MS,
                            mConfig.cpuQuotaBackground);
@@ -255,8 +281,8 @@ void ContainerAdmin::setSchedulerParams(std::uint64_t cpuShares, std::uint64_t v
     virTypedParamsAddLLong(&paramsTmp, &numParamsBuff, &maxParams, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA, vcpuQuota);
 
     if (virDomainSetSchedulerParameters(mDom.get(), params.get(), numParamsBuff) < 0) {
-        LOGE("Error whilte setting the domain's scheduler params:\n"
-             << libvirt::libvirtFormatError(mId));
+        LOGE(mId << ": Error while setting the domain's scheduler params:\n"
+             << libvirt::libvirtFormatError());
         throw DomainOperationException();
     }
 }
@@ -270,16 +296,16 @@ std::int64_t ContainerAdmin::getSchedulerQuota()
     std::unique_ptr<char, void(*)(void*)> type(virDomainGetSchedulerType(mDom.get(), &numParamsBuff), free);
 
     if (type == NULL || numParamsBuff <= 0 || strcmp(type.get(), "posix") != 0) {
-        LOGE("Error while getting the domain's scheduler type:\n"
-             << libvirt::libvirtFormatError(mId));
+        LOGE(mId << ": Error while getting the domain's scheduler type:\n"
+             << libvirt::libvirtFormatError());
         throw DomainOperationException();
     }
 
     std::unique_ptr<virTypedParameter[]> params(new virTypedParameter[numParamsBuff]);
 
     if (virDomainGetSchedulerParameters(mDom.get(), params.get(), &numParamsBuff) < 0) {
-        LOGE("Error while getting the domain's scheduler params:\n"
-             << libvirt::libvirtFormatError(mId));
+        LOGE(mId << ": Error while getting the domain's scheduler params:\n"
+             << libvirt::libvirtFormatError());
         throw DomainOperationException();
     }
 
@@ -288,8 +314,8 @@ std::int64_t ContainerAdmin::getSchedulerQuota()
                                numParamsBuff,
                                VIR_DOMAIN_SCHEDULER_VCPU_QUOTA,
                                &quota) <= 0) {
-        LOGE("Error while getting the domain's scheduler quota param:\n"
-             << libvirt::libvirtFormatError(mId));
+        LOGE(mId << ": Error while getting the domain's scheduler quota param:\n"
+             << libvirt::libvirtFormatError());
         throw DomainOperationException();
     }
 
index 7738ba1..d1ce59a 100644 (file)
@@ -67,7 +67,7 @@ public:
 
     /**
      * Gracefully shutdown the domain.
-     * This method will NOT block untill domain is shut down,
+     * This method will NOT block until domain is shut down,
      * because some configurations may ignore this.
      */
     void shutdown();
@@ -80,7 +80,7 @@ public:
     /**
      * Check if the container is stopped. It's NOT equivalent to !isRunning,
      * because it checks different internal libvirt's states. There are other states,
-     * (e.g. paused) when the container isn't runnig nor stopped.
+     * (e.g. paused) when the container isn't running nor stopped.
      *
      * @return Is the container stopped?
      */
index 2e71ce3..3af8276 100644 (file)
@@ -38,6 +38,7 @@ namespace security_containers {
 
 ContainersManager::ContainersManager(const std::string& managerConfigPath)
 {
+    LOGD("Instantiating ContainersManager object...");
     mConfig.parseFile(managerConfigPath);
 
     for (auto& containerConfig : mConfig.containerConfigs) {
@@ -50,21 +51,25 @@ ContainersManager::ContainersManager(const std::string& managerConfigPath)
             containerConfigPath = utils::createFilePath(baseConfigPath, "/", containerConfig);
         }
 
-        LOGT("Creating Container " << containerConfigPath);
+        LOGD("Creating Container " << containerConfigPath);
         std::unique_ptr<Container> c(new Container(containerConfigPath));
         std::string id = c->getId();
         mContainers.emplace(id, std::move(c));
     }
+
+    LOGD("ContainersManager object instantiated");
 }
 
 
 ContainersManager::~ContainersManager()
 {
+    LOGD("Destroying ContainersManager object...");
     try {
         stopAll();
     } catch (ServerException& e) {
         LOGE("Failed to stop all of the containers");
     }
+    LOGD("ContainersManager object destroyed");
 }
 
 
@@ -74,9 +79,11 @@ void ContainersManager::focus(const std::string& containerId)
     ContainerMap::mapped_type& foregroundContainer = mContainers.at(containerId);
 
     for (auto& container : mContainers) {
+        LOGD(container.second->getId() << ": being sent to background");
         container.second->goBackground();
     }
     mConfig.foregroundId = foregroundContainer->getId();
+    LOGD(mConfig.foregroundId << ": being sent to foreground");
     foregroundContainer->goForeground();
 }
 
index c0e15ef..001696a 100644 (file)
@@ -40,7 +40,7 @@ struct ServerException: public SecurityContainersException {
 };
 
 /**
- * Error occured during an attempt to perform an operation on a domain,
+ * Error occurred during an attempt to perform an operation on a domain,
  * e.g. start, stop a container
  */
 struct DomainOperationException: public ServerException {