[libvirt] [PATCH] Adding filesystem mount support for openVZ

Evgeniy Sokolov evg at openvz.org
Thu Mar 12 13:39:04 UTC 2009


Hi Florian,

> Hi everyone,
> 
> This patch is to allow using the "mount" type in the "filesystem" tag 
> for OpenVZ domains.
> 
> Example:
> ...
>     <filesystem type='mount'>
>       <source dir='/path/to/filesystem/directory/' />
>       <target dir='/path/to/pivot/root/' />
>     </filesystem>
> ...
> 
> This is my first patch to an external project, so don't spare me if I 
> got things wrong :)
> 
> Also, I'm curious for suggestions as to how I could allow for the target 
> not to be specified in the XML. Because in this case OpenVZ just makes a 
> temporary pivot root in "/var/lib/vz/root/" and that is probably 
> sufficient for most people, who might not want to have to explicitly 
> create a pivot root somewhere, just for mounting the filesystem while 
> it's running.
> 
> I was thinking either allow for the target tag not to be specified, or 
> add an "auto" attribute to target. Which one sounds better ?
> 
> Thanks,
> Florian
> 
diff --git a/src/openvz_conf.c b/src/openvz_conf.c
index ff3d607..33fb259 100644
--- a/src/openvz_conf.c
+++ b/src/openvz_conf.c
@@ -314,6 +314,41 @@ error:
  }


+/* utility function to replace 'from' by 'to' in 'str' */
+static char*
+openvz_replace(const char* str,
+               const char* from,
+               int to) {
+    char tmp[4096];
+    char* offset = tmp;
+    int len = strlen(str);
+    int fromLen = strlen(from);
+    int r,i,maxcmp,left = sizeof(tmp);
+
+    if(!from)
+        return NULL;
+
+    for(i = 0; i < len && left; ++i) {
+      /* compare first caracters to limit useless full comparisons */
+        if(*from == str[i]) {
+            maxcmp = (fromLen > len-i) ? len-i : fromLen;
+            if(strncmp(from, str+i, maxcmp) == 0) {
+                r = snprintf(offset, left, "%d", to);
+                offset += r;
+                i += fromLen - 1;
+                continue;
+            }
+        }
+        *offset++ = str[i];
+        left = sizeof(tmp) - (offset-tmp);
+    }
search can be simplified by strstr(str, from)

+
+    tmp[sizeof(tmp)-left] = '\0';
+
+    return strdup(tmp);
+}
+
+


diff --git a/src/openvz_conf.h b/src/openvz_conf.h
index 8e02056..da9bfb4 100644
--- a/src/openvz_conf.h
+++ b/src/openvz_conf.h
@@ -42,6 +42,7 @@ enum { OPENVZ_WARN, OPENVZ_ERR };
  /* OpenVZ commands - Replace with wrapper scripts later? */
  #define VZLIST  "/usr/sbin/vzlist"
  #define VZCTL   "/usr/sbin/vzctl"
+#define VZ_DEFAULT_CONF_FILE "ve-vps.basic.conf-sample"


really, default config is specified in /etc/sysconfig/vz

# grep -R CONFIGFILE /etc/sysconfig/vz
CONFIGFILE="vps.basic"

config file is calculating by
snprintf(path, sizeof(path),  VPS_CONF_DIR "ve-%s.conf-sample", 
      config);


  #define VZCTL_BRIDGE_MIN_VERSION ((3 * 1000 * 1000) + (0 * 1000) + 22 + 1)





More information about the libvir-list mailing list