Re: [spice-gtk 3/9] usb-redir: Prepare for creation of emulated CD drive

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

 



On Thu, Jul 25, 2019 at 06:59:39PM +0300, Yuri Benditovich wrote:
> On Thu, Jul 25, 2019 at 1:33 PM Victor Toso <victortoso@xxxxxxxxxx> wrote:
> >
> > On Wed, Jul 24, 2019 at 01:53:45PM +0300, Yuri Benditovich wrote:
> > > Added command-line option for shared CD devices and respective
> > > property in usb-device-manager.
> > >
> > > Signed-off-by: Yuri Benditovich <yuri.benditovich@xxxxxxxxxx>
> > > ---
> > >  src/spice-option.c       | 15 +++++++++++++++
> > >  src/usb-device-manager.c | 33 +++++++++++++++++++++++++++++++++
> > >  2 files changed, 48 insertions(+)
> > >
> > > diff --git a/src/spice-option.c b/src/spice-option.c
> > > index c2b059e..4fbca9f 100644
> > > --- a/src/spice-option.c
> > > +++ b/src/spice-option.c
> > > @@ -32,6 +32,7 @@ static char *smartcard_db = NULL;
> > >  static char *smartcard_certificates = NULL;
> > >  static char *usbredir_auto_redirect_filter = NULL;
> > >  static char *usbredir_redirect_on_connect = NULL;
> > > +static gchar **cd_share_files = NULL;
> > >  static gboolean smartcard = FALSE;
> > >  static gboolean disable_audio = FALSE;
> > >  static gboolean disable_usbredir = FALSE;
> > > @@ -183,6 +184,8 @@ GOptionGroup* spice_get_option_group(void)
> > >            N_("Filter selecting USB devices to be auto-redirected when plugged in"), N_("<filter-string>") },
> > >          { "spice-usbredir-redirect-on-connect", '\0', 0, G_OPTION_ARG_STRING, &usbredir_redirect_on_connect,
> > >            N_("Filter selecting USB devices to redirect on connect"), N_("<filter-string>") },
> > > +        { "spice-share-cd", '\0', 0, G_OPTION_ARG_STRING_ARRAY, &cd_share_files,
> > > +          N_("Name of ISO file or CD/DVD device to share"), N_("<filename> (repeat allowed)") },
> > >          { "spice-cache-size", '\0', 0, G_OPTION_ARG_INT, &cache_size,
> > >            N_("Image cache size (deprecated)"), N_("<bytes>") },
> > >          { "spice-glz-window-size", '\0', 0, G_OPTION_ARG_INT, &glz_window_size,
> > > @@ -272,6 +275,18 @@ void spice_set_session_option(SpiceSession *session)
> > >              g_object_set(m, "redirect-on-connect",
> > >                           usbredir_redirect_on_connect, NULL);
> > >      }
> > > +    if (cd_share_files) {
> > > +        SpiceUsbDeviceManager *m = spice_usb_device_manager_get(session, NULL);
> >
> > Please check for errors as well, I patched the other two calls
> > for this
> 
> I do not exactly understand the comment. Can you explain?

spice_usb_device_manager_get() can fail, for instance if usbredir
is not enabled at compile time. You can pass a GError** instead
of NULL to warn user about the fact that its cd-rom will not
show up in the guest for whatever reason it might be.


Just switch to the local get_usb_device_manager_for_option()
added in the last commit

https://gitlab.freedesktop.org/spice/spice-gtk/commit/1ab015b369f34169747e0cbfb1e0b6a8c99e9141

Cheers,

> 
> >
> > > +        if (m) {
> > > +            gchar **name = cd_share_files;
> > > +            while (name && *name) {
> > > +                g_object_set(m, "share-cd", *name, NULL);
> > > +                name++;
> > > +            }
> > > +        }
> > > +        g_strfreev(cd_share_files);
> > > +        cd_share_files = NULL;
> > > +    }
> > >      if (disable_usbredir)
> > >          g_object_set(session, "enable-usbredir", FALSE, NULL);
> > >      if (disable_audio)
> > > diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
> > > index 0961d16..b11bb15 100644
> > > --- a/src/usb-device-manager.c
> > > +++ b/src/usb-device-manager.c
> > > @@ -75,6 +75,7 @@ enum {
> > >      PROP_AUTO_CONNECT_FILTER,
> > >      PROP_REDIRECT_ON_CONNECT,
> > >      PROP_FREE_CHANNELS,
> > > +    PROP_SHARE_CD
> > >  };
> > >
> > >  enum
> > > @@ -433,6 +434,26 @@ static void spice_usb_device_manager_set_property(GObject       *gobject,
> > >          priv->redirect_on_connect = g_strdup(filter);
> > >          break;
> > >      }
> > > +    case PROP_SHARE_CD:
> > > +    {
> > > +#ifdef USE_USBREDIR
> > > +        UsbCreateDeviceParameters param = { 0 };
> > > +        const gchar *name = g_value_get_string(value);
> > > +        /* the string is temporary, no need to keep it */
> > > +        SPICE_DEBUG("share_cd set to %s", name);
> > > +        if (name[0] == '!') {
> > > +            name++;
> > > +            param.device_param.create_cd.delete_on_eject = 1;
> > > +        }
> > > +        param.device_param.create_cd.filename = name;
> > > +        if (!spice_usb_backend_create_device(priv->context, USB_DEV_TYPE_CD, &param)) {
> > > +            g_warning(param.error->message);
> > > +            spice_usb_device_manager_device_error(self, NULL, param.error);
> > > +            g_error_free(param.error);
> > > +        }
> > > +#endif
> > > +        break;
> > > +    }
> > >      default:
> > >          G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
> > >          break;
> > > @@ -523,6 +544,18 @@ static void spice_usb_device_manager_class_init(SpiceUsbDeviceManagerClass *klas
> > >      g_object_class_install_property(gobject_class, PROP_REDIRECT_ON_CONNECT,
> > >                                      pspec);
> > >
> > > +    /**
> > > +    * SpiceUsbDeviceManager:share-cd:
> > > +    *
> > > +    * Set a string specifying a filename (ISO) or physical CD/DVD device
> > > +    * to share via USB after a Spice connection has been established.
> > > +    *
> > > +    */
> > > +    pspec = g_param_spec_string("share-cd", "Share ISO file or device as CD",
> > > +        "File or device name to share", NULL,
> > > +        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
> > > +    g_object_class_install_property(gobject_class, PROP_SHARE_CD, pspec);
> > > +
> > >      /**
> > >       * SpiceUsbDeviceManager:free-channels:
> > >       *
> > > --
> > > 2.17.1
> > >
> > > _______________________________________________
> > > Spice-devel mailing list
> > > Spice-devel@xxxxxxxxxxxxxxxxxxxxx
> > > https://lists.freedesktop.org/mailman/listinfo/spice-devel

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]