[PATCH 2/2] openvz; support file system quota reporting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/openvz/openvz_conf.c |  114 +++++++++++++++++++++++++++++-----------------
 1 file changed, 73 insertions(+), 41 deletions(-)

diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 579fcfc..7ea5e25 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -129,6 +129,51 @@ int openvzExtractVersion(struct openvz_driver *driver)
 }
 
 
+/* Parse config values of the form barrier:limit into barrier and limit */
+static int
+openvzParseBarrierAndLimit(const char *value,
+                           unsigned long long *barrier,
+                           unsigned long long *limit)
+{
+    char *token;
+    char *saveptr = NULL;
+    char *str = strdup(value);
+
+    if (strcmp(value, "unlimited") == 0) {
+        barrier = limit = 0;
+        return 0;
+    }
+
+    if (str == NULL) {
+        virReportOOMError();
+        goto error;
+    }
+
+    token = strtok_r(str, ":", &saveptr);
+    if (token == NULL) {
+        goto error;
+    } else {
+        if (barrier != NULL) {
+            if (virStrToLong_ull(token, NULL, 10, barrier))
+                goto error;
+        }
+    }
+    token = strtok_r(NULL, ":", &saveptr);
+    if (token == NULL) {
+        goto error;
+    } else {
+        if (limit != NULL) {
+            if (virStrToLong_ull(token, NULL, 10, limit))
+                goto error;
+        }
+    }
+    return 0;
+error:
+    VIR_FREE(str);
+    return -1;
+}
+
+
 static int openvzDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
 {
     return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_OPENVZ;
@@ -366,6 +411,7 @@ openvzReadFSConf(virDomainDefPtr def,
     virDomainFSDefPtr fs = NULL;
     char *veid_str = NULL;
     char *temp = NULL;
+    const char *param;
 
     ret = openvzReadVPSConfigParam(veid, "OSTEMPLATE", &temp);
     if (ret < 0) {
@@ -403,6 +449,32 @@ openvzReadFSConf(virDomainDefPtr def,
 
     fs->dst = strdup("/");
 
+    param = "DISKSPACE";
+    ret = openvzReadVPSConfigParam(veid, param, &temp);
+    if (ret > 0) {
+        if (openvzParseBarrierAndLimit(temp,
+                                       &fs->soft_limit,
+                                       &fs->hard_limit)) {
+            openvzError(VIR_ERR_INTERNAL_ERROR,
+                        _("Could not read '%s' from config for container %d"),
+                        param, veid);
+            goto error;
+        }
+    }
+
+    param = "DISKINODES";
+    ret = openvzReadVPSConfigParam(veid, param, &temp);
+    if (ret > 0) {
+        if (openvzParseBarrierAndLimit(temp,
+                                       &fs->inodes_soft_limit,
+                                       &fs->inodes_hard_limit)) {
+            openvzError(VIR_ERR_INTERNAL_ERROR,
+                        _("Could not read '%s' from config for container %d"),
+                        param, veid);
+            goto error;
+        }
+    }
+
     if (fs->src == NULL || fs->dst == NULL)
         goto no_memory;
 
@@ -423,52 +495,12 @@ error:
 }
 
 
-/* Parse config values of the form barrier:limit into barrier and limit */
-static int
-openvzParseBarrierAndLimit(const char* value,
-                           unsigned long *barrier,
-                           unsigned long *limit)
-{
-    char *token;
-    char *saveptr = NULL;
-    char *str = strdup(value);
-
-    if (str == NULL) {
-        virReportOOMError();
-        goto error;
-    }
-
-    token = strtok_r(str, ":", &saveptr);
-    if (token == NULL) {
-        goto error;
-    } else {
-        if (barrier != NULL) {
-            if (virStrToLong_ul(token, NULL, 10, barrier))
-                goto error;
-        }
-    }
-    token = strtok_r(NULL, ":", &saveptr);
-    if (token == NULL) {
-        goto error;
-    } else {
-        if (limit != NULL) {
-            if (virStrToLong_ul(token, NULL, 10, limit))
-                goto error;
-        }
-    }
-    return 0;
-error:
-    VIR_FREE(str);
-    return -1;
-}
-
-
 static int
 openvzReadMemConf(virDomainDefPtr def, int veid)
 {
     int ret;
     char *temp = NULL;
-    unsigned long barrier, limit;
+    unsigned long long barrier, limit;
     const char *param;
     unsigned long kb_per_pages;
 
-- 
1.7.10

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]