From 0e2f6120ee3814755709e18e61e7ef83485aeaa3 Mon Sep 17 00:00:00 2001 From: Dave Wysochanski Date: Tue, 12 Jun 2007 21:20:20 +0000 Subject: [PATCH] Add get_pv_* functions to return PV fields in prep for external LVM library --- WHATS_NEW | 1 + lib/metadata/metadata.c | 82 ++++++++++++++++++++++++++++++++++++++++- lib/metadata/metadata.h | 15 ++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 87f6efee7..9a8ce2be4 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.26 - ================================= + Add get_pv_* functions to return PV members (external LVM library). Add wrappers to some functions in preparation for external LVM library. Allow vgcfgrestore to list metadata backup files using -f Add vg_check_status to consolidate vg status checks and error messages. diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 43d6c217c..b7f654b57 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -28,6 +28,12 @@ #include +/* + * FIXME: Check for valid handle before dereferencing member or log error? + */ +#define PV_HANDLE_DEREF(H, M) \ + (((struct physical_volume *)H)->M) + static struct physical_volume *_pv_read(struct cmd_context *cmd, const char *pv_name, struct list *mdas, @@ -1452,7 +1458,21 @@ struct logical_volume *lv_from_lvid(struct cmd_context *cmd, const char *lvid_s, return lvl->lv; } -/* FIXME: liblvm todo - make into function that returns handle */ +/** + * pv_read - read and return a handle to a physical volume + * @cmd: LVM command initiating the pv_read + * @pv_name: full device name of the PV, including the path + * @mdas: list of metadata areas of the PV + * @label_sector: sector number where the PV label is stored on @pv_name + * @warnings: + * + * Returns: + * PV handle - valid pv_name and successful read of the PV, or + * NULL - invalid parameter or error in reading the PV + * + * Note: + * FIXME - liblvm todo - make into function that returns handle + */ struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name, struct list *mdas, uint64_t *label_sector, int warnings) @@ -1684,7 +1704,6 @@ int pv_analyze(struct cmd_context *cmd, const char *pv_name, /** * vg_check_status - check volume group status flags and log error - * * @vg - volume group to check status flags * @status_flags - specific status flags to check (e.g. EXPORTED_VG) * @@ -1720,3 +1739,62 @@ int vg_check_status(struct volume_group *vg, uint32_t status_flags) return 1; } + + +/* + * Gets/Sets for external LVM library + */ +struct id get_pv_id (void *pv_handle) +{ + return PV_HANDLE_DEREF(pv_handle, id); +} + +const struct format_type *get_pv_format_type (void *pv_handle) +{ + return PV_HANDLE_DEREF(pv_handle, fmt); +} + +struct id get_pv_vgid (void *pv_handle) +{ + return PV_HANDLE_DEREF(pv_handle, vgid); +} + +struct device *get_pv_dev (void *pv_handle) +{ + return PV_HANDLE_DEREF(pv_handle, dev); +} + +const char *get_pv_vg_name (void *pv_handle) +{ + return PV_HANDLE_DEREF(pv_handle, vg_name); +} + +uint64_t get_pv_size(void *pv_handle) +{ + return PV_HANDLE_DEREF(pv_handle, size); +} + +uint32_t get_pv_status (void *pv_handle) +{ + return PV_HANDLE_DEREF(pv_handle, status); +} + +uint32_t get_pv_pe_size (void *pv_handle) +{ + return PV_HANDLE_DEREF(pv_handle, pe_size); +} + +uint64_t get_pv_pe_start (void *pv_handle) +{ + return PV_HANDLE_DEREF(pv_handle, pe_start); +} + +uint32_t get_pv_pe_count (void *pv_handle) +{ + return PV_HANDLE_DEREF(pv_handle, pe_count); +} + +uint32_t get_pv_pe_alloc_count (void *pv_handle) +{ + return PV_HANDLE_DEREF(pv_handle, pe_alloc_count); +} diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index f03afc32a..1ebe571a9 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -635,4 +635,19 @@ uint32_t find_free_lvnum(struct logical_volume *lv); char *generate_lv_name(struct volume_group *vg, const char *format, char *buffer, size_t len); +/* + * Gets/Sets for external LVM library + */ +struct id get_pv_id (void *pv_handle); +const struct format_type *get_pv_format_type (void *pv_handle); +struct id get_pv_vgid (void *pv_handle); +struct device *get_pv_dev (void *pv_handle); +const char *get_pv_vg_name (void *pv_handle); +uint64_t get_pv_size(void *pv_handle); +uint32_t get_pv_status (void *pv_handle); +uint32_t get_pv_pe_size (void *pv_handle); +uint64_t get_pv_pe_start (void *pv_handle); +uint32_t get_pv_pe_count (void *pv_handle); +uint32_t get_pv_pe_alloc_count (void *pv_handle); + #endif -- 2.43.5