From: Dave Wysochanski Date: Sun, 26 Jul 2009 01:54:40 +0000 (+0000) Subject: Update lvm_vg_extend to do an implicit pvcreate on the device. X-Git-Tag: old-v2_02_50~69 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=aaeec6541569b6a5718d442b35ad8068ce7c3c2b;p=lvm2.git Update lvm_vg_extend to do an implicit pvcreate on the device. Although the tools do not currently do this, we update lvm_vg_extend to do an implicit pvcreate on an uninitialized device. The tools will soon be refactored to do this as well, but more work is needed in the tools. For now we update lvm_vg_extend since this is the behavior required by liblvm. With this change, the simple liblvm unit test, test/api/vgtest.c should pass whether or not the device is initialized. Author: Dave Wysochanski --- diff --git a/liblvm/lvm.h b/liblvm/lvm.h index c2157a87b..48ec63766 100644 --- a/liblvm/lvm.h +++ b/liblvm/lvm.h @@ -146,6 +146,10 @@ vg_t *lvm_vg_create(lvm_t libh, const char *vg_name); * After successfully adding a device, use lvm_vg_write to commit the new VG * to disk. Upon failure, retry the operation or release the VG handle with * lvm_vg_close. + * If the device is not initialized for LVM use, it will be initialized + * before adding to the VG. Although some internal checks are done, + * the caller should be sure the device is not in use by other subsystems + * before calling lvm_vg_extend. * * \param vg * VG handle obtained from lvm_vg_create. diff --git a/liblvm/lvm_vg.c b/liblvm/lvm_vg.c index 8f0cd5c89..0668aee55 100644 --- a/liblvm/lvm_vg.c +++ b/liblvm/lvm_vg.c @@ -12,9 +12,6 @@ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include - #include "lib.h" #include "lvm.h" #include "toolcontext.h" @@ -23,6 +20,10 @@ #include "locking.h" #include "lvm-string.h" #include "lvmcache.h" +#include "metadata.h" + +#include +#include vg_t *lvm_vg_create(lvm_t libh, const char *vg_name) { @@ -47,6 +48,14 @@ int lvm_vg_extend(vg_t *vg, const char *device) return 0; } + /* If device not initialized, pvcreate it */ + if (!pv_by_path(vg->cmd, device) && + (!pvcreate_single(vg->cmd, device, NULL))) { + log_error("Unable to initialize device for LVM use\n"); + unlock_vg(vg->cmd, VG_ORPHANS); + return 0; + } + if (!vg_extend(vg, 1, (char **) &device)) { unlock_vg(vg->cmd, VG_ORPHANS); return 0;