[PATCH 2/4] qemu: Support for parsing usb-mtp devices

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

 



The source tag sets the rootdir property of the device, which is the directory
exposed to the guest via the MTP device. The target tag sets the desc property.
This device supports read-only mode as well. Like virtiofs, it does not
support additional access modes.

Signed-off-by: Rayhan Faizel <rayhan.faizel@xxxxxxxxx>
---
 src/bhyve/bhyve_command.c         |  1 +
 src/conf/domain_conf.c            | 10 +++++++++
 src/conf/domain_conf.h            |  1 +
 src/conf/schemas/domaincommon.rng |  5 +++++
 src/qemu/qemu_command.c           | 34 +++++++++++++++++++++++++++++++
 src/qemu/qemu_domain_address.c    |  7 +++++--
 src/qemu/qemu_validate.c          | 13 ++++++++++++
 7 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index d05b01ae5d..bc287307c8 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -611,6 +611,7 @@ bhyveBuildFSArgStr(const virDomainDef *def G_GNUC_UNUSED,
     case VIR_DOMAIN_FS_DRIVER_TYPE_LOOP:
     case VIR_DOMAIN_FS_DRIVER_TYPE_NBD:
     case VIR_DOMAIN_FS_DRIVER_TYPE_PLOOP:
+    case VIR_DOMAIN_FS_DRIVER_TYPE_MTP:
     case VIR_DOMAIN_FS_DRIVER_TYPE_LAST:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("unsupported filesystem driver '%1$s'"),
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3597959e33..396e388ca8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -517,6 +517,7 @@ VIR_ENUM_IMPL(virDomainFSDriver,
               "nbd",
               "ploop",
               "virtiofs",
+              "mtp",
 );
 
 VIR_ENUM_IMPL(virDomainFSAccessMode,
@@ -28721,6 +28722,15 @@ virDomainUSBDeviceDefForeach(virDomainDef *def,
         }
     }
 
+    /* usb-mtp */
+    for (i = 0; i < def->nfss; i++) {
+        virDomainFSDef *fsdev = def->fss[i];
+        if (fsdev->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_MTP) {
+            if (iter(&fsdev->info, opaque) < 0)
+                return -1;
+        }
+    }
+
     return 0;
 }
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c7e5005b3b..76251938b8 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -804,6 +804,7 @@ typedef enum {
     VIR_DOMAIN_FS_DRIVER_TYPE_NBD,
     VIR_DOMAIN_FS_DRIVER_TYPE_PLOOP,
     VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS,
+    VIR_DOMAIN_FS_DRIVER_TYPE_MTP,
 
     VIR_DOMAIN_FS_DRIVER_TYPE_LAST
 } virDomainFSDriverType;
diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng
index df44cd9857..c992956280 100644
--- a/src/conf/schemas/domaincommon.rng
+++ b/src/conf/schemas/domaincommon.rng
@@ -3253,6 +3253,11 @@
           </optional>
           <ref name="virtioOptions"/>
         </group>
+        <group>
+          <attribute name="type">
+            <value>mtp</value>
+          </attribute>
+        </group>
         <empty/>
       </choice>
     </element>
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2719574fb5..9c20670843 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -861,6 +861,7 @@ qemuBuildVirtioDevGetConfigDev(const virDomainDeviceDef *device,
                 *baseName = "vhost-user-fs";
                 break;
 
+            case VIR_DOMAIN_FS_DRIVER_TYPE_MTP:
             case VIR_DOMAIN_FS_DRIVER_TYPE_LOOP:
             case VIR_DOMAIN_FS_DRIVER_TYPE_NBD:
             case VIR_DOMAIN_FS_DRIVER_TYPE_PLOOP:
@@ -2310,6 +2311,33 @@ qemuBuildDisksCommandLine(virCommand *cmd,
 }
 
 
+static int
+qemuBuildMTPCommandLine(virCommand *cmd,
+                          virDomainFSDef *fs,
+                          const virDomainDef *def,
+                          virQEMUCaps *qemuCaps)
+{
+    g_autoptr(virJSONValue) props = NULL;
+
+    if (virJSONValueObjectAdd(&props,
+                              "s:driver", "usb-mtp",
+                              "s:id", fs->info.alias,
+                              "s:rootdir", fs->src->path,
+                              "s:desc", fs->dst,
+                              "b:readonly", fs->readonly,
+                              NULL) < 0)
+        return -1;
+
+    if (qemuBuildDeviceAddressProps(props, def, &fs->info) < 0)
+        return -1;
+
+    if (qemuBuildDeviceCommandlineFromJSON(cmd, props, def, qemuCaps) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 virJSONValue *
 qemuBuildVHostUserFsDevProps(virDomainFSDef *fs,
                              const virDomainDef *def,
@@ -2493,6 +2521,12 @@ qemuBuildFilesystemCommandLine(virCommand *cmd,
                 return -1;
             break;
 
+        case VIR_DOMAIN_FS_DRIVER_TYPE_MTP:
+            /* Media Transfer Protocol over USB */
+            if (qemuBuildMTPCommandLine(cmd, def->fss[i], def, qemuCaps) < 0)
+                return -1;
+            break;
+
         case VIR_DOMAIN_FS_DRIVER_TYPE_LOOP:
         case VIR_DOMAIN_FS_DRIVER_TYPE_NBD:
         case VIR_DOMAIN_FS_DRIVER_TYPE_PLOOP:
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index af486aea97..cc3bc76971 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -642,6 +642,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev,
             /* vhost-user-fs-pci */
             return virtioFlags;
 
+        case VIR_DOMAIN_FS_DRIVER_TYPE_MTP:
         case VIR_DOMAIN_FS_DRIVER_TYPE_LOOP:
         case VIR_DOMAIN_FS_DRIVER_TYPE_NBD:
         case VIR_DOMAIN_FS_DRIVER_TYPE_PLOOP:
@@ -2074,8 +2075,10 @@ qemuDomainAssignDevicePCISlots(virDomainDef *def,
         if (!virDeviceInfoPCIAddressIsWanted(&def->fss[i]->info))
             continue;
 
-        /* Only support VirtIO-9p-pci so far. If that changes,
-         * we might need to skip devices here */
+        /* Skip MTP device */
+        if (def->fss[i]->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_MTP)
+            continue;
+
         if (qemuDomainPCIAddressReserveNextAddr(addrs, &def->fss[i]->info) < 0)
             return -1;
     }
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 73afd094a9..2d391a3916 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -4469,6 +4469,19 @@ qemuValidateDomainDeviceDefFS(virDomainFSDef *fs,
         }
         break;
 
+    case VIR_DOMAIN_FS_DRIVER_TYPE_MTP:
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_MTP)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("mtp is not supported with this QEMU binary"));
+            return -1;
+        }
+        if (fs->accessmode != VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                            _("mtp only supports passthrough accessmode"));
+            return -1;
+        }
+        break;
+
     case VIR_DOMAIN_FS_DRIVER_TYPE_LAST:
     default:
         virReportEnumRangeError(virDomainFSDriverType, fs->fsdriver);
-- 
2.34.1
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[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]

  Powered by Linux