[Spice-devel] [phodav PATCH 4/4] spice-webdavd: Automount shared folder on Windows

Marc-André Lureau mlureau at redhat.com
Thu Sep 17 05:47:49 PDT 2015


Hi

----- Original Message -----
> How do you prevent from having multiple drive pointing to the spice folder?
> 
> 
> Currently, I don't.
> 
> Only way to connect multiple drives, is if you restart the service,
> because the drives will disconnect, after restarting guest.
> 
> I will add a disconnect function to the quit function in the service,
> so that if uou disable, or restart teh service, the drive will be unmapped
> 

Can't you enumerate existing mappings and only add one if it's necessary?

> > ---
> > Changes since RFC:
> > - Calling WNetAddConnection2() blindly was slow and caause many threads to
> > spawn.
> > - Now only call it once, when it is sure, that it will connect.
> > - Now connects to a * drive, instead of always Z:
> > - Thread is now spawned and joined every time run_service() is called.
> > ---
> > Makefile.am | 4 +++
> > spice/spice-webdavd.c | 76
> > +++++++++++++++++++++++++++++++++++++++++++++++++++
> > 2 files changed, 80 insertions(+)
> > 
> > diff --git a/Makefile.am b/Makefile.am
> > index 485417b..df9a73e 100644
> > --- a/Makefile.am
> > +++ b/Makefile.am
> > @@ -87,6 +87,10 @@ spice_webdavd_LDADD = \
> > $(PIE_LDFLAGS) \
> > $(NULL)
> > 
> > +if OS_WIN32
> > +spice_webdavd_LDADD += -lnetapi32 -lmpr
> > +endif
> > +
> > deps.txt:
> > $(AM_V_GEN)rpm -qa | grep $(host_os) | sort | unix2dos > $@
> > 
> > diff --git a/spice/spice-webdavd.c b/spice/spice-webdavd.c
> > index f9c5cf1..3940f1c 100644
> > --- a/spice/spice-webdavd.c
> > +++ b/spice/spice-webdavd.c
> > @@ -737,11 +737,81 @@ open_mux_path (const char *path)
> > mux_queue = output_queue_new (G_OUTPUT_STREAM (mux_ostream));
> > }
> > 
> > +#ifdef G_OS_WIN32
> > +static gchar
> > +get_free_drive_letter(void)
> > +{
> > + const guint32 max_mask = 1 << 25;
> > + guint32 drives;
> > + guint32 mask;
> > + gint i;
> > +
> > + drives = GetLogicalDrives ();
> > +
> > + for (i = 0; i < 26; i++)
> > + {
> > + mask = max_mask >> i;
> > + if ((drives & mask) == 0)
> > + return 'Z' - i;
> > + }
> > +
> > + return 0;
> > +}
> > +
> > +static gpointer
> > +map_drive(gpointer user_data)
> > +{
> > + GCancellable * cancel_map = user_data;
> > + gchar drive_letter;
> > + gchar local_name[3];
> > + gchar remote_name[] = " http://localhost:9843/ ";
> > + NETRESOURCE net_resource;
> > + guint32 retval;
> > + gint i;
> > +
> > + for (i = 0; i < 5; ++i)
> > + {
> > + if (g_cancellable_is_cancelled (cancel_map))
> > + return NULL;
> > + else
> > + g_usleep (G_USEC_PER_SEC);
> > + }
> 
> It looks like this would fail if the guest is started without client
> connected (or not sharing folder).
> 
> I'm not sure I follow.
> This is supposed to return NULL precisely, if the client is not connected,
> or not sharing folder. Windows webdavd will loop and call run_service(),
> until sharing is enabled, which will then NOT cancel this function,
> and we map the drive.

ah so the service keeps running and next time the client connects, then the thread will be started again?



More information about the Spice-devel mailing list