1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

lib2app: Added PV create. V2

V2: Correct call to lock_vol

Signed-off-by: Tony Asleson <tasleson@redhat.com>
This commit is contained in:
Tony Asleson 2013-04-03 17:53:21 -04:00
parent d079411051
commit 6d6ccded35
5 changed files with 63 additions and 9 deletions

View File

@ -345,6 +345,9 @@ int pvremove_single(struct cmd_context *cmd, const char *pv_name,
void *handle __attribute__((unused)), unsigned force_count,
unsigned prompt);
int pvcreate_locked(struct cmd_context *cmd, const char *pv_name,
struct pvcreate_params *pp);
/* Manipulate PV structures */
int pv_add(struct volume_group *vg, struct physical_volume *pv);
int pv_remove(struct volume_group *vg, struct physical_volume *pv);

View File

@ -20,6 +20,8 @@
#include "locking.h"
#include "defaults.h"
#include "lvmetad.h"
#include "display.h"
#include "label.h"
static struct pv_segment *_alloc_pv_segment(struct dm_pool *mem,
struct physical_volume *pv,
@ -672,3 +674,23 @@ out:
return ret;
}
int pvcreate_locked(struct cmd_context *cmd, const char *pv_name,
struct pvcreate_params *pp)
{
int ret = ECMD_PROCESSED;
if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) {
log_error("Can't get lock for orphan PVs");
return ECMD_FAILED;
}
if (!(pvcreate_single(cmd, pv_name, pp, 1))) {
stack;
ret = ECMD_FAILED;
}
unlock_vg(cmd, VG_ORPHANS);
return ret;
}

View File

@ -571,6 +571,16 @@ struct dm_list *lvm_list_pvs(lvm_t libh);
*/
int lvm_list_pvs_free(struct dm_list *pvlist);
/**
* Create a physical volume.
* \param libh Library handle
* \param pv_name The physical volume name
* \param size Size of physical volume, 0 = use all available.
* \return
* 0 on success, else -1 with library errno and text set.
*/
int lvm_pv_create(lvm_t libh, const char *pv_name, uint64_t size);
/**
* Remove a physical volume.
* Note: You cannot remove a PV while iterating through the list of PVs as

View File

@ -226,3 +226,29 @@ int lvm_pv_resize(const pv_t pv, uint64_t new_size)
return 0;
}
}
int lvm_pv_create(lvm_t libh, const char *pv_name, uint64_t size)
{
int rc = -1;
struct pvcreate_params pp;
struct cmd_context *cmd = (struct cmd_context *)libh;
uint64_t size_sectors = size;
pvcreate_params_set_defaults(&pp);
if (size_sectors != 0 ) {
if( size_sectors % SECTOR_SIZE ) {
log_errno(EINVAL, "Size not a multiple of 512");
return -1;
}
size_sectors = size_sectors >> SECTOR_SHIFT;
}
pp.size = size_sectors;
if (ECMD_PROCESSED == pvcreate_locked(cmd, pv_name, &pp)) {
rc = 0;
}
return rc;
}

View File

@ -15,6 +15,7 @@
#include "tools.h"
#include "metadata-exported.h"
#include "metadata.h"
/*
* Intial sanity checking of recovery-related command-line arguments.
@ -96,7 +97,6 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv)
int i;
int ret = ECMD_PROCESSED;
struct pvcreate_params pp;
struct physical_volume *pv;
pvcreate_params_set_defaults(&pp);
@ -108,19 +108,12 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv)
}
for (i = 0; i < argc; i++) {
if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) {
log_error("Can't get lock for orphan PVs");
return ECMD_FAILED;
}
dm_unescape_colons_and_at_signs(argv[i], NULL, NULL);
if (!(pv = pvcreate_single(cmd, argv[i], &pp, 1))) {
stack;
if (ECMD_PROCESSED != pvcreate_locked(cmd, argv[i], &pp)) {
ret = ECMD_FAILED;
}
unlock_vg(cmd, VG_ORPHANS);
if (sigint_caught())
return ret;
}