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

[libvirt] [PATCH] qemu: Add Secure Shell (ssh) network block device.



From: "Richard W.M. Jones" <rjones redhat com>

---
 docs/formatdomain.html.in     | 10 ++++++++--
 docs/schemas/domaincommon.rng |  1 +
 src/conf/domain_conf.c        |  3 ++-
 src/conf/domain_conf.h        |  1 +
 src/qemu/qemu_command.c       | 44 +++++++++++++++++++++++++++++++++++++++++--
 src/util/virstoragefile.c     |  5 +++--
 6 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index d400e35..c86f023 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1450,8 +1450,8 @@
         to the directory to use as the disk. If the disk <code>type</code>
         is "network", then the <code>protocol</code> attribute specifies
         the protocol to access to the requested image; possible values
-        are "nbd", "iscsi", "rbd", "sheepdog" or "gluster".  If the
-        <code>protocol</code> attribute is "rbd", "sheepdog" or "gluster", an
+        are "nbd", "iscsi", "rbd", "sheepdog", "gluster" or "ssh".  If the
+        <code>protocol</code> attribute is "rbd", "sheepdog", "gluster" or "ssh", an
         additional attribute <code>name</code> is mandatory to specify which
         volume/image will be used; for "nbd" it is optional.  For "iscsi",
         the <code>name</code> attribute may include a logical unit number,
@@ -1746,6 +1746,12 @@
             <td> only one </td>
             <td> 24007 </td>
           </tr>
+          <tr>
+            <td> ssh </td>
+            <td> the ssh server </td>
+            <td> only one </td>
+            <td> 22 </td>
+          </tr>
         </table>
         gluster supports "tcp", "rdma", "unix" as valid values for the
         transport attribute.  nbd supports "tcp" and "unix".  Others only
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 2c31f76..c9e4e5b 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1143,6 +1143,7 @@
         <value>sheepdog</value>
         <value>gluster</value>
         <value>iscsi</value>
+        <value>ssh</value>
       </choice>
     </attribute>
     <optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e00a532..5ccaac2 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -255,7 +255,8 @@ VIR_ENUM_IMPL(virDomainDiskProtocol, VIR_DOMAIN_DISK_PROTOCOL_LAST,
               "rbd",
               "sheepdog",
               "gluster",
-              "iscsi")
+              "iscsi",
+              "ssh")
 
 VIR_ENUM_IMPL(virDomainDiskProtocolTransport, VIR_DOMAIN_DISK_PROTO_TRANS_LAST,
               "tcp",
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 08b8e48..7e3e162 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -506,6 +506,7 @@ enum virDomainDiskProtocol {
     VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG,
     VIR_DOMAIN_DISK_PROTOCOL_GLUSTER,
     VIR_DOMAIN_DISK_PROTOCOL_ISCSI,
+    VIR_DOMAIN_DISK_PROTOCOL_SSH,
 
     VIR_DOMAIN_DISK_PROTOCOL_LAST
 };
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 41a2dfd..4a5d0bf 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2500,6 +2500,18 @@ error:
 }
 
 static int
+qemuParseSSHString(virDomainDiskDefPtr disk)
+{
+    virURIPtr uri;
+
+    uri = virURIParse(disk->src);
+    if (!uri)
+        return -1;
+
+    return qemuParseDriveURIString(disk, uri, "ssh");
+}
+
+static int
 qemuBuildDriveURIString(virConnectPtr conn,
                         virDomainDiskDefPtr disk, virBufferPtr opt,
                         const char *scheme, virSecretUsageType secretType)
@@ -2617,8 +2629,6 @@ qemuBuildGlusterString(virConnectPtr conn, virDomainDiskDefPtr disk, virBufferPt
                                    VIR_SECRET_USAGE_TYPE_NONE);
 }
 
-#define QEMU_DEFAULT_NBD_PORT "10809"
-
 static int
 qemuBuildISCSIString(virConnectPtr conn, virDomainDiskDefPtr disk, virBufferPtr opt)
 {
@@ -2627,6 +2637,16 @@ qemuBuildISCSIString(virConnectPtr conn, virDomainDiskDefPtr disk, virBufferPtr
 }
 
 static int
+qemuBuildSSHString(virConnectPtr conn, virDomainDiskDefPtr disk,
+                   virBufferPtr opt)
+{
+    return qemuBuildDriveURIString(conn, disk, opt, "ssh",
+                                   VIR_SECRET_USAGE_TYPE_NONE);
+}
+
+#define QEMU_DEFAULT_NBD_PORT "10809"
+
+static int
 qemuBuildNBDString(virConnectPtr conn, virDomainDiskDefPtr disk, virBufferPtr opt)
 {
     const char *transp;
@@ -2828,6 +2848,12 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
                     virBufferEscape(&opt, ',', ",", "%s,", disk->src);
                 }
                 break;
+
+            case VIR_DOMAIN_DISK_PROTOCOL_SSH:
+                if (qemuBuildSSHString(conn, disk, &opt) < 0)
+                    goto error;
+                virBufferAddChar(&opt, ',');
+                break;
             }
         } else if (disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME) {
             switch (disk->srcpool->voltype) {
@@ -8120,6 +8146,13 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
                     }
 
                     VIR_FREE(p);
+                } else if (STRPREFIX(def->src, "ssh:")) {
+                    def->type = VIR_DOMAIN_DISK_TYPE_NETWORK;
+                    def->protocol = VIR_DOMAIN_DISK_PROTOCOL_SSH;
+
+                    if (qemuParseSSHString(def) < 0)
+                        goto error;
+
                 } else
                     def->type = VIR_DOMAIN_DISK_TYPE_FILE;
             } else {
@@ -9296,6 +9329,9 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
                 disk->type = VIR_DOMAIN_DISK_TYPE_NETWORK;
                 disk->protocol = VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG;
                 val += strlen("sheepdog:");
+            } else if (STRPREFIX(val, "ssh:")) {
+                disk->type = VIR_DOMAIN_DISK_TYPE_NETWORK;
+                disk->protocol = VIR_DOMAIN_DISK_PROTOCOL_SSH;
             } else
                 disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
             if (STREQ(arg, "-cdrom")) {
@@ -9372,6 +9408,10 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
                         goto error;
 
                     break;
+                case VIR_DOMAIN_DISK_PROTOCOL_SSH:
+                    if (qemuParseSSHString(disk) < 0)
+                        goto error;
+                    break;
                 }
             }
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index aabb5c8..2c701c3 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -622,8 +622,9 @@ virStorageFileMatchesVersion(int format,
 static bool
 virBackingStoreIsFile(const char *backing)
 {
-    /* Backing store is a network block device or Rados block device */
-    if (STRPREFIX(backing, "nbd:") || STRPREFIX(backing, "rbd:"))
+    /* Backing store is a network block device, Rados block device, or ssh */
+    if (STRPREFIX(backing, "nbd:") || STRPREFIX(backing, "rbd:") ||
+        STRPREFIX(backing, "ssh:"))
         return false;
     return true;
 }
-- 
1.8.1.4


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