diff options
author | Dave Wysochanski <dwysocha@redhat.com> | 2009-07-28 13:17:04 +0000 |
---|---|---|
committer | Dave Wysochanski <dwysocha@redhat.com> | 2009-07-28 13:17:04 +0000 |
commit | 9ac1af71600d0f5035b7e9d5bacb05d8a0924615 (patch) | |
tree | 461a1d174760622303f7675f39fd90b70a96e95a | |
parent | 88e3ced7dfca5f32335485d821a38415b8da592e (diff) | |
download | lvm2-9ac1af71600d0f5035b7e9d5bacb05d8a0924615.tar.gz lvm2-9ac1af71600d0f5035b7e9d5bacb05d8a0924615.tar.xz lvm2-9ac1af71600d0f5035b7e9d5bacb05d8a0924615.zip |
Add lvm_vg_get_seqno, updating lvm.h and unit test.
Adding the ability to get the seqno is important for an application to
determine if something has changed in a VG. Otherwise, the only way to
know is to open the VG with write permission and hold the handle.
-rw-r--r-- | lib/metadata/metadata-exported.h | 1 | ||||
-rw-r--r-- | lib/metadata/metadata.c | 5 | ||||
-rw-r--r-- | liblvm/.exported_symbols | 1 | ||||
-rw-r--r-- | liblvm/lvm.h | 26 | ||||
-rw-r--r-- | liblvm/lvm_vg.c | 5 | ||||
-rw-r--r-- | test/api/test.c | 5 |
6 files changed, 41 insertions, 2 deletions
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index bc946da6..0ed48e3b 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -705,6 +705,7 @@ uint32_t pv_mda_count(const pv_t *pv); uint64_t lv_size(const lv_t *lv); int vg_missing_pv_count(const vg_t *vg); +uint32_t vg_seqno(const vg_t *vg); uint32_t vg_status(const vg_t *vg); uint64_t vg_size(const vg_t *vg); uint64_t vg_free(const vg_t *vg); diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 03e77301..d25ad681 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -3424,6 +3424,11 @@ uint32_t pv_mda_count(const pv_t *pv) return info ? dm_list_size(&info->mdas) : UINT64_C(0); } +uint32_t vg_seqno(const vg_t *vg) +{ + return vg->seqno; +} + uint32_t vg_status(const vg_t *vg) { return vg->status; diff --git a/liblvm/.exported_symbols b/liblvm/.exported_symbols index 452b676a..1e6d4c41 100644 --- a/liblvm/.exported_symbols +++ b/liblvm/.exported_symbols @@ -6,6 +6,7 @@ lvm_config_override lvm_pv_get_name lvm_pv_get_uuid lvm_pv_get_mda_count +lvm_vg_get_seqno lvm_vg_get_name lvm_vg_get_uuid lvm_vg_get_size diff --git a/liblvm/lvm.h b/liblvm/lvm.h index 8049df8b..a3bfffaf 100644 --- a/liblvm/lvm.h +++ b/liblvm/lvm.h @@ -49,6 +49,17 @@ * A volume group handle may be obtained with read or write permission. * Any attempt to change a property of a pv_t, vg_t, or lv_t without * obtaining write permission on the vg_t will fail with EPERM. + * + * An application first opening a VG read-only, then later wanting to change + * a property of an object must first close the VG and re-open with write + * permission. Currently liblvm provides no mechanism to determine whether + * the VG has changed on-disk in between these operations - this is the + * application's responsiblity. One way the application can ensure the VG + * has not changed is to save the "vg_seqno" field after opening the VG with + * READ permission. If the application later needs to modify the VG, it can + * close the VG and re-open with WRITE permission. It should then check + * whether the original "vg_seqno" obtained with READ permission matches + * the new one obtained with WRITE permission. */ /** @@ -470,6 +481,21 @@ int lvm_vg_reduce(vg_t *vg, const char *device); int lvm_vg_set_extent_size(vg_t *vg, uint32_t new_size); /** + * Get the current metadata sequence number of a volume group. + * + * The metadata sequence number is incrented for each metadata change. + * Applications may use the sequence number to determine if any LVM objects + * have changed from a prior query. + * + * \param vg + * VG handle obtained from lvm_vg_create or lvm_vg_open. + * + * \return + * Metadata sequence number. + */ +uint64_t lvm_vg_get_seqno(const vg_t *vg); + +/** * Get the current name of a volume group. * * Memory is allocated using dm_malloc() and caller must free the memory diff --git a/liblvm/lvm_vg.c b/liblvm/lvm_vg.c index 0aa2e08c..bd04d812 100644 --- a/liblvm/lvm_vg.c +++ b/liblvm/lvm_vg.c @@ -223,6 +223,11 @@ struct dm_list *lvm_vg_list_lvs(vg_t *vg) return list; } +uint64_t lvm_vg_get_seqno(const vg_t *vg) +{ + return vg_seqno(vg); +} + /* FIXME: invalid handle? return INTMAX? */ uint64_t lvm_vg_get_size(const vg_t *vg) { diff --git a/test/api/test.c b/test/api/test.c index 95e1b0b1..79770354 100644 --- a/test/api/test.c +++ b/test/api/test.c @@ -345,10 +345,11 @@ static void _vg_close(char **argv, int argc) static void _show_one_vg(vg_t *vg) { - printf("%s (%s): size=%"PRIu64", free=%"PRIu64", #pv=%"PRIu64"\n", + printf("%s (%s): sz=%"PRIu64", free=%"PRIu64", #pv=%"PRIu64 + ", seq#=%"PRIu64"\n", lvm_vg_get_name(vg), lvm_vg_get_uuid(vg), lvm_vg_get_size(vg), lvm_vg_get_free_size(vg), - lvm_vg_get_pv_count(vg)); + lvm_vg_get_pv_count(vg), lvm_vg_get_seqno(vg)); } static void _list_open_vgs(void) |