* 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.
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <errno.h>
-#include <string.h>
-
#include "lib.h"
#include "lvm.h"
#include "toolcontext.h"
#include "locking.h"
#include "lvm-string.h"
#include "lvmcache.h"
+#include "metadata.h"
+
+#include <errno.h>
+#include <string.h>
vg_t *lvm_vg_create(lvm_t libh, const char *vg_name)
{
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;