On Fri, Jul 29, 2011 at 12:34:15PM +0800, Lei Li wrote: > To make sure the unique storage pool defined and created from different directory to avoid inconsistent version of volume pool created, I add two API be called by storage driver to check for the probable duplicate pools and refused the duplicate pool. > > virStoragePoolObjFindByPath() provide a method to find pool object by target path in pool list. > virStoragePoolTargetDuplicate() implement the function to check if there is duplicate pool. > Add judgement for storagePoolCreate&storagePoolDefine by calling virStoragePoolTargetDuplicate() to avoid both transient storage pool and persistent storage pool be created repeatedly in storage driver. > > > Signed-off-by: Lei Li<lilei@xxxxxxxxxxxxxxxxxx> > --- > src/conf/storage_conf.c | 39 +++++++++++++++++++++++++++++++++++++++ > src/conf/storage_conf.h | 4 ++++ > src/libvirt_private.syms | 2 ++ > src/storage/storage_driver.c | 6 ++++++ > 4 files changed, 51 insertions(+), 0 deletions(-) > > diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c > index 995f9a6..a499e82 100644 > --- a/src/conf/storage_conf.c > +++ b/src/conf/storage_conf.c > @@ -1317,6 +1317,22 @@ virStoragePoolObjFindByName(virStoragePoolObjListPtr pools, > return NULL; > } > > +virStoragePoolObjPtr > +virStoragePoolObjFindByPath(virStoragePoolObjListPtr pools, > + const char *path) > +{ > + unsigned int i; > + > + for (i = 0 ; i< pools->count ; i++) { > + virStoragePoolObjLock(pools->objs[i]); > + if (STREQ(pools->objs[i]->def->target.path, path)) > + return pools->objs[i]; > + virStoragePoolObjUnlock(pools->objs[i]); > + } > + > + return NULL; > +} > + > void > virStoragePoolObjClearVols(virStoragePoolObjPtr pool) > { > @@ -1707,6 +1723,29 @@ cleanup: > return ret; > } > > +int virStoragePoolTargetDuplicate(virStoragePoolObjListPtr pools, > + virStoragePoolDefPtr def) > +{ > + int ret = 1; > + virStoragePoolObjPtr pool = NULL; > + > + /*check pool list if defined target path already exist*/ > + pool = virStoragePoolObjFindByPath(pools, def->target.path); > + > + if (pool) { > + virStorageReportError(VIR_ERR_OPERATION_FAILED, > + _("target path '%s' is already in use"), > + pool->def->target.path); > + ret = -1; > + goto cleanup; > + } This only works for pools which are type=dir|fs|netfs|logical It will fail for type=iscsi|scsi|disk, because in those cases the target path has no uniqueness requirement, and will almost always just be either /dev or /dev/disk/by-path for all pool. 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 :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list