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

Re: [libvirt] [PATCH v2 4/5] In storageVolumeCreateXML, spawn a new thread for volbuilding, in storageVolumeDelete, generate the signal



On Sun, Jul 17, 2011 at 06:45:00PM +0800, Guannan Ren wrote:
> ---
>  src/storage/storage_backend.c |    9 ++++
>  src/storage/storage_driver.c  |   83 ++++++++++++++++++++++++++++++++++++-----
>  2 files changed, 82 insertions(+), 10 deletions(-)
> 
> diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
> index f632edd..bc10933 100644
> --- a/src/storage/storage_backend.c
> +++ b/src/storage/storage_backend.c
> @@ -1632,3 +1632,12 @@ virStorageBackendRunProgNul(virConnectPtr conn,
>      return -1;
>  }
>  #endif /* WIN32 */
> +
> +void virStorageBackendVoluCleanup(void *arg)
> +{
> +
> +    volBuildThreadPtr data = arg;
> +
> +    data->buildret = 0;
> +    data->threadEnd = 1;
> +}
> diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
> index 997b876..d8ac648 100644
> --- a/src/storage/storage_driver.c
> +++ b/src/storage/storage_driver.c
> @@ -48,6 +48,7 @@
>  #include "files.h"
>  #include "fdstream.h"
>  #include "configmake.h"
> +#include "threads.h"
>  
>  #define VIR_FROM_THIS VIR_FROM_STORAGE
>  
> @@ -1276,6 +1277,29 @@ cleanup:
>  
>  static int storageVolumeDelete(virStorageVolPtr obj, unsigned int flags);
>  
> +static void virStorageBuildVol(void *arg)
> +{
> +    int ret = -1;
> +    volBuildThreadPtr data = arg;
> +    virStoragePoolObjPtr pool = data->pool;
> +    virStorageVolDefPtr vol = data->vol;
> +
> +    pthread_cleanup_push(virStorageBackendVoluCleanup, data);
> +
> +    ret = data->buildvol(data->obj->conn, pool, vol);
> +
> +    pthread_cleanup_pop(0);

NACK, all use of pthread specific APIs must be in src/util/threads-pthread.c

Independantly of this, IMHO pthread cancellation handlers are a recipe
for trouble because it is incredibly hard to make sure you correctly
cleanup all resources in the thread, even with use of cleanup handlers.

IMHO, threads should be made to monitor some external "quit" boolean
variable (eg see  threadpool.c thread termination).

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


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