From: Justin Cinkelj <[email protected]>
Committer: Nadav Har'El <[email protected]>
Branch: master

cloud-init: use Linux-compatible syntax for mounts

Previous syntax was for mounts was slightly different as for Linux.
In particular, the first entry was tailor made for libnfs ("nfs://IP/DIR"),
while Linux uses string like "IP:/DIR". This resulted in additional
complication when converting Linux code to OSv.

Fix that by doing doing required conversion inside OSv cloud-init.

The provided example with two options (uid=1000,gid=1000) is only
partially functional - only the first option is accepted, the second is
silently ignored. This will be fixed after #829 is fixed.

Signed-off-by: Justin Cinkelj <[email protected]>
Message-Id: <[email protected]>

---
diff --git a/modules/cloud-init/cloud-init.cc b/modules/cloud-init/cloud-init.cc
--- a/modules/cloud-init/cloud-init.cc
+++ b/modules/cloud-init/cloud-init.cc
@@ -189,21 +189,32 @@ Mount NFS mountpoint specified via cloud-init.

 Cloud-init config snippet:
 mounts:
- - [ nfs://192.168.122.1/ggg, /ggg, auto, uid=0 ]
+ - [ "192.168.122.1:/ggg", /ggg, "nfs", "uid=1000,gid=1000", "0", "0" ]

 This results in running command
 /tools/mount-nfs.so nfs://192.168.122.1/ggg/?uid=0 /ggg
 */
void mount_module::yaml_to_request(const YAML::Node& node, http::server::request& req)
 {
     std::string method = "PUT";
-    std::string nfs_server = node[0].as<string>();
+    std::string srv_hostname_dir = node[0].as<string>();
     std::string mount_point = node[1].as<string>();
-    // node[2] is "auto" flag - we ignore it
+    std::string type = node[2].as<string>();
     std::string options = "";
     if (node.size() >= 4) {
         options = node[3].as<string>();
     }
+    // node[4] and [5] are ignored.
+
+    if (type != "nfs") {
+ fprintf(stderr, "Ignoring unsupported filesystem type %s\n", type.c_str());
+        return;
+    }
+
+    auto pos = srv_hostname_dir.find_first_of(":");
+    auto srv_hostname = srv_hostname_dir.substr(0, pos);
+    auto srv_dir = srv_hostname_dir.substr(pos+1, srv_hostname_dir.size());
+    auto nfs_server = type + "://" + srv_hostname + srv_dir;

     http::server::header param;
     param.name = "command";
diff --git a/modules/cloud-init/cloud-init.yaml b/modules/cloud-init/cloud-init.yaml
--- a/modules/cloud-init/cloud-init.yaml
+++ b/modules/cloud-init/cloud-init.yaml
@@ -4,7 +4,7 @@ run:

 # mount NFS export example
 #mounts:
-# - [ nfs://192.168.122.1/ggg, /ggg, auto, uid=0 ]
+# - [ "192.168.122.1:/ggg", /ggg, "nfs", "uid=1000,gid=1000", "0", "0" ]

 # set hostname example
 #hostname: uber-vm

--
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to