1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-10 05:18:36 +03:00

Introduce as-yet-unused replacement vg_read() and vg_read_for_update()

functions.  (mornfall)
This commit is contained in:
Alasdair Kergon 2009-01-27 00:40:44 +00:00
parent 6e8bd97709
commit 22c4076818
2 changed files with 70 additions and 0 deletions

View File

@ -387,6 +387,12 @@ vg_t *vg_lock_and_read(struct cmd_context *cmd, const char *vg_name,
uint32_t lock_flags, uint32_t status_flags,
uint32_t misc_flags);
/* Loading volume group metadata. */
vg_t *vg_read(struct cmd_context *cmd, const char *vg_name,
const char *vgid, uint32_t flags);
vg_t *vg_read_for_update(struct cmd_context *cmd, const char *vg_name,
const char *vgid, uint32_t flags);
/* pe_start and pe_end relate to any existing data so that new metadata
* areas can avoid overlap */
pv_t *pv_create(const struct cmd_context *cmd,

View File

@ -2609,6 +2609,70 @@ bad:
return _vg_make_handle(cmd, vg, failure);
}
/*
* vg_read: High-level volume group metadata read function.
*
* vg_read_error() must be used on any handle returned to check for errors.
*
* - metadata inconsistent and automatic correction failed: FAILED_INCONSISTENT
* - VG is read-only: FAILED_READ_ONLY
* - VG is EXPORTED, unless flags has READ_ALLOW_EXPORTED: FAILED_EXPORTED
* - VG is not RESIZEABLE, unless flags has ALLOW_NONRESIZEABLE:
* FAILED_RESIZEABLE
* - locking failed: FAILED_LOCKING
*
* On failures, all locks are released, unless LOCK_KEEP has been supplied.
*
* Volume groups are opened read-only unless flags contains READ_FOR_UPDATE.
*
* Checking for VG existence:
*
* If READ_CHECK_EXISTENCE is set in flags, if the VG exists, a non-NULL struct
* volume_group will be returned every time, but if it has INCONSISTENT_VG set,
* the other fields will be uninitialized. You must check for INCONSISTENT_VG
* if passing READ_CHECK_EXISTENCE. You also must not use it if it has
* INCONSISTENT_VG set.
*
* FIXME: We want vg_read to attempt automatic recovery after acquiring a
* temporary write lock: if that fails, we bail out as usual, with failed &
* FAILED_INCONSISTENT. If it works, we are good to go. Code that's been in
* toollib just set lock_flags to LCK_VG_WRITE and called vg_read_internal with
* *consistent = 1.
*/
vg_t *vg_read(struct cmd_context *cmd, const char *vg_name,
const char *vgid, uint32_t flags)
{
uint32_t status = CLUSTERED;
uint32_t lock_flags = LCK_VG_READ;
if (flags & READ_FOR_UPDATE) {
status |= EXPORTED_VG | LVM_WRITE;
lock_flags = LCK_VG_WRITE;
}
if (flags & READ_ALLOW_EXPORTED)
status &= ~EXPORTED_VG;
if (flags & READ_REQUIRE_RESIZEABLE)
status |= RESIZEABLE_VG;
if (flags & LOCK_NONBLOCKING)
lock_flags |= LCK_NONBLOCK;
return _vg_lock_and_read(cmd, vg_name, vgid, lock_flags, status, flags);
}
/*
* A high-level volume group metadata reading function. Open a volume group for
* later update (this means the user code can change the metadata and later
* request the new metadata to be written and committed).
*/
vg_t *vg_read_for_update(struct cmd_context *cmd, const char *vg_name,
const char *vgid, uint32_t flags)
{
return vg_read(cmd, vg_name, vgid, flags | READ_FOR_UPDATE);
}
/*
* Gets/Sets for external LVM library
*/