metadata: Do not try to check vg_name of a NULL PV.
PATCH 1/20 metadata: Do not try to check vg_name of a NULL PV.
--- lib/metadata/metadata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/metadata/metadata.c +1 -1
@@ -1842,7 +1842,7 @@ struct physical_volume *find_pv_by_name(struct cmd_context *cmd, } } -if (!allow_orphan &&is_orphan_vg (pv->vg_name)) { +if (pv && !allow_orphan &&is_orphan_vg (pv->vg_name)) {log_error ("Physical volume %s not in a volume group" , pv_name); goto bad; }
Signature · 1 line
1.8.2
PATCH 2/20 toollib: Drop the pv_read optimisation.
Only reading a single PV works correctly only in very limited circumstances. Moreover, we can't rely on the MDA available on the PV either, since it may be out of date in some circumstances (until now, we believed that PVs that have an empty MDA are always orphans, but this is not 100% reliable either).
--- tools/toollib.c | 93 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 46 insertions(+), 47 deletions(-)
tools/toollib.c +46 -47
@@ -644,6 +644,8 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,static int _process_all_devs (struct cmd_context *cmd,void *handle,process_single_pv_fn_t process_single_pv) { +struct pv_list *pvl; +struct dm_list *pvslist;struct physical_volume *pv;struct physical_volume pv_dummy;struct dev_iter *iter;
@@ -652,7 +654,8 @@ static int _process_all_devs(struct cmd_context *cmd, void *handle,int ret_max =ECMD_PROCESSED ;int ret; -if (!scan_vgs_for_pvs (cmd,1 )) +lvmcache_seed_infos_from_lvmetad (cmd); +if (!(pvslist =get_pvs (cmd))) return_ECMD_FAILED;if (!(iter =dev_iter_create (cmd->filter,1 ))) {
@@ -660,20 +663,28 @@ static int _process_all_devs(struct cmd_context *cmd, void *handle,return ECMD_FAILED ; } -while ((dev =dev_iter_get (iter))) { +while ((dev =dev_iter_get (iter))) + {if (sigint_caught ()) { ret_max =ECMD_FAILED ; stack;break ; } -if (!(pv =pv_read (cmd,dev_name (dev),0 ,0 ))) { -memset (&pv_dummy,0 ,sizeof (pv_dummy)); -dm_list_init (&pv_dummy.tags); -dm_list_init (&pv_dummy.segments); - pv_dummy.dev = dev; - pv = &pv_dummy; - } +memset (&pv_dummy,0 ,sizeof (pv_dummy)); +dm_list_init (&pv_dummy.tags); +dm_list_init (&pv_dummy.segments); + pv_dummy.dev = dev; + pv = &pv_dummy; + +/* TODO use a device-indexed hash here */ + dm_list_iterate_items(pvl, pvslist) +if (pvl->pv->dev == dev) + pv = pvl->pv; + + ret =process_single_pv (cmd,NULL , pv, handle); + +free_pv_fid (pv); ret =process_single_pv (cmd,NULL , pv, handle);if (ret > ret_max)
@@ -704,11 +715,11 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,struct pv_list *pvl;struct physical_volume *pv; -struct dm_list *pvslist, *vgnames; +struct dm_list *pvslist =NULL , *vgnames;struct dm_list tags;struct str_list *sll;char *at_sign, *tagname; -int scanned =0 ; +struct device *dev;dm_list_init (&tags);
@@ -754,52 +765,36 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, } pv = pvl->pv; }else { -if (!(pv =pv_read (cmd, argv[opt], -1 , scan_label_only))) { -log_error ("Failed to read physical " -"volume \"%s\"" , argv[opt]); +if (!pvslist) { +lvmcache_seed_infos_from_lvmetad (cmd); +if (!(pvslist =get_pvs (cmd))) + goto bad; + } + +if (!(dev =dev_cache_get (argv[opt], cmd->filter))) { +log_error ("Failed to find device " +"\"%s\"" , argv[opt]); ret_max =ECMD_FAILED ;continue ; } -/* -* If a PV has no MDAs it may appear to be an -* orphan until the metadata is read off -* another PV in the same VG. Detecting this -* means checking every VG by scanning every -* PV on the system. -*/ -if (!scanned &&is_orphan (pv) && -dm_list_empty (&pv->fid->metadata_areas_in_use)) { -if (!scan_label_only && - !scan_vgs_for_pvs (cmd,1 )) { - stack; - ret_max =ECMD_FAILED ; -continue ; - } - scanned =1 ; -free_pv_fid (pv); -if (!(pv =pv_read (cmd, argv[opt], -1 , - scan_label_only))) { -log_error ("Failed to read " -"physical volume " -"\"%s\"" , argv[opt]); - ret_max =ECMD_FAILED ; -continue ; - } + pv =NULL ; + dm_list_iterate_items(pvl, pvslist) +if (pvl->pv->dev == dev) + pv = pvl->pv; + +if (!pv) { +log_error ("Failed to find physical volume " +"\"%s\"" , argv[opt]); + ret_max =ECMD_FAILED ; +continue ; } } ret =process_single_pv (cmd, vg, pv, handle); +if (ret > ret_max) ret_max = ret; -/* -* Free PV only if we called pv_read before, -* otherwise the PV structure is part of the VG. -*/ -if (!vg) -free_pv_fid (pv); }if (!dm_list_empty (&tags) && (vgnames =get_vgnames (cmd,1 )) && !dm_list_empty (vgnames)) {
@@ -855,6 +850,10 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, } } out: +if (pvslist) + dm_list_iterate_items(pvl, pvslist) +free_pv_fid (pvl->pv); +if (lock_global)unlock_vg (cmd,VG_GLOBAL );return ret_max;
Signature · 1 line
1.8.2
PATCH 3/20 test: Add a test for the failing pv_read optimisation.
In reply to Petr Rockai--- test/shell/mda-rollback.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/shell/mda-rollback.sh
test/shell/mda-rollback.sh new file +26 -0
@@ -0,0 +1,26 @@ +#!/bin/sh +# Copyright (C) 2013 Red Hat, Inc. All rights reserved. +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions +# of the GNU General Public License v.2. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +. lib/test + +aux prepare_devs 3 + +vgcreate --metadatasize 128k $vg1 "$dev1" "$dev2" "$dev3" + +vgreduce $vg1 $dev1 +dd if="$dev1" of=badmda bs=256K count=1 +vgextend $vg1 $dev1 + +dd if=badmda of="$dev1" bs=256K count=1 + +# dev1 is part of vg1 (as witnessed by metadata on dev2 and dev3), but its mda +# was corrupt (written over by a backup from time dev1 was an orphan) +check pv_field $dev1 vg_name $vg1
Signature · 1 line
1.8.2
PATCH 4/20 pvresize: Do not use pv_read (get the PV from orphan VG).
In reply to Petr Rockai--- lib/metadata/pv_manip.c | 51 +++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 33 deletions(-)
lib/metadata/pv_manip.c +18 -33
@@ -549,9 +549,9 @@ static int pv_resize(struct physical_volume *pv, }int pv_resize_single (struct cmd_context *cmd, -struct volume_group *vg, -struct physical_volume *pv, -const uint64_t new_size) +struct volume_group *vg, +struct physical_volume *pv, +const uint64_t new_size) {struct pv_list *pvl;uint64_t size =0 ;
@@ -561,38 +561,25 @@ int pv_resize_single(struct cmd_context *cmd,struct volume_group *old_vg = vg;int vg_needs_pv_write =0 ; -if (is_orphan_vg (vg_name)) { -if (!lock_vol (cmd, vg_name,LCK_VG_WRITE ,NULL )) { -log_error ("Can't get lock for orphans" ); -return 0 ; - } - -if (!(pv =pv_read (cmd, pv_name,1 ,0 ))) { -unlock_vg (cmd, vg_name); -log_error ("Unable to read PV \"%s\"" , pv_name); -return 0 ; - } - }else { - vg =vg_read_for_update (cmd, vg_name,NULL ,0 ); + vg =vg_read_for_update (cmd, vg_name,NULL ,0 ); -if (vg_read_error (vg)) { -release_vg (vg); -log_error ("Unable to read volume group \"%s\"." , - vg_name); -return 0 ; - } +if (vg_read_error (vg)) { +release_vg (vg); +log_error ("Unable to read volume group \"%s\"." , + vg_name); +return 0 ; + } -if (!(pvl =find_pv_in_vg (vg, pv_name))) { -log_error ("Unable to find \"%s\" in volume group \"%s\"" , - pv_name, vg->name); - goto out; - } +if (!(pvl =find_pv_in_vg (vg, pv_name))) { +log_error ("Unable to find \"%s\" in volume group \"%s\"" , + pv_name, vg->name); + goto out; + } - pv = pvl->pv; + pv = pvl->pv; -if (!archive (vg)) - goto out; - } +if (!archive (vg)) + goto out;if (!(pv->fmt->features &FMT_RESIZE_PV )) { log_error("Physical volume %s format does not support resizing.",
@@ -650,8 +637,6 @@ out:log_error ("Use pvcreate and vgcfgrestore " "to repair from archived metadata." );unlock_vg (cmd, vg_name); -if (is_orphan_vg (vg_name)) -free_pv_fid (pv);if (!old_vg)release_vg (vg);return r;
Signature · 1 line
1.8.2
PATCH 5/20 test: Fix fallout from pv_read changes.
In reply to Petr Rockai--- test/shell/pv-duplicate.sh | 2 +- test/shell/pvcreate-operation-md.sh | 35 +++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 15 deletions(-)
test/shell/pv-duplicate.sh +1 -1
@@ -21,5 +21,5 @@ vgcreate --metadatasize 128k $vg1 "$dev1" dd if="$dev1" of="$dev2" bs=256K count=1 dd if="$dev1" of="$dev3" bs=256K count=1 -pvs "$dev1" +pvs "$dev3" vgs $vg1
test/shell/pvcreate-operation-md.sh +21 -14
@@ -58,21 +58,24 @@ test -b "$mddev" && skip mdadm --create --metadata=1.0 "$mddev" --auto=md --level 0 --raid-devices=2 --chunk 64 "$dev1" "$dev2" trap 'cleanup_md_and_teardown' EXIT # cleanup this MD device at the end of the test test -b "$mddev" || skip +cp -LR "$mddev" "$DM_DEV_DIR" # so that LVM/DM can see the device +lvmdev="$DM_DEV_DIR/md_lvm_test0" # Test alignment of PV on MD without any MD-aware or topology-aware detection # - should treat $mddev just like any other block device pv_align="1.00m" pvcreate --metadatasize 128k \ --config 'devices {md_chunk_alignment=0 data_alignment_detection=0 data_alignment_offset_detection=0}' \ - "$mddev" -check pv_field "$mddev" pe_start $pv_align + "$lvmdev" + +check pv_field "$lvmdev" pe_start $pv_align # Test md_chunk_alignment independent of topology-aware detection pv_align="1.00m" pvcreate --metadatasize 128k \ --config 'devices {data_alignment_detection=0 data_alignment_offset_detection=0}' \ - "$mddev" -check pv_field "$mddev" pe_start $pv_align + "$lvmdev" +check pv_field "$lvmdev" pe_start $pv_align # Test newer topology-aware alignment detection
@@ -81,8 +84,8 @@ if kernel_at_least 2 6 33 ; then pv_align="1.00m" # optimal_io_size=131072, minimum_io_size=65536 pvcreate --metadatasize 128k \ - --config 'devices { md_chunk_alignment=0 }' "$mddev" - check pv_field "$mddev" pe_start $pv_align + --config 'devices { md_chunk_alignment=0 }' "$lvmdev" + check pv_field "$lvmdev" pe_start $pv_align fi # partition MD array directly, depends on blkext in Linux >= 2.6.28
@@ -91,9 +94,10 @@ if kernel_at_least 2 6 28 ; then sfdisk "$mddev" <<EOF ,,83 EOF + pvscan # make sure partition on MD is _not_ removed # - tests partition -> parent lookup via sysfs paths - not pvcreate --metadatasize 128k "$mddev" + not pvcreate --metadatasize 128k "$lvmdev" # verify alignment_offset is accounted for in pe_start # - topology infrastructure is available in Linux >= 2.6.31
@@ -109,6 +113,8 @@ EOF # wait here for created device node on tmpfs aux udev_wait "$mddev_p" test -b "$mddev_p" || skip + cp -LR "$mddev_p" "$DM_DEV_DIR" + lvmdev_p="$DM_DEV_DIR/$base_mddev_p" # Checking for 'alignment_offset' in sysfs implies Linux >= 2.6.31 # but reliable alignment_offset support requires kernel.org Linux >= 2.6.33
@@ -120,9 +126,9 @@ EOF if [ $alignment_offset -gt 0 ]; then # default alignment is 1M, add alignment_offset pv_align=$((1048576+$alignment_offset))B - pvcreate --metadatasize 128k "$mddev_p" - check pv_field "$mddev_p" pe_start $pv_align --units b - pvremove "$mddev_p" + pvcreate --metadatasize 128k "$lvmdev_p" + check pv_field "$lvmdev_p" pe_start $pv_align --units b + pvremove "$lvmdev_p" fi fi
@@ -140,12 +146,13 @@ if kernel_at_least 2 6 33 ; then # optimal_io_size=2097152, minimum_io_size=1048576 pv_align="2.00m" pvcreate --metadatasize 128k \ - --config 'devices { md_chunk_alignment=0 }' "$mddev" - check pv_field "$mddev" pe_start $pv_align + --config 'devices { md_chunk_alignment=0 }' "$lvmdev" + pvscan # Something is seriously broken. + check pv_field "$lvmdev" pe_start $pv_align # now verify pe_start alignment override using --dataalignment pv_align="192.00k" pvcreate --dataalignment 64k --metadatasize 128k \ - --config 'devices { md_chunk_alignment=0 }' "$mddev" - check pv_field "$mddev" pe_start $pv_align + --config 'devices { md_chunk_alignment=0 }' "$lvmdev" + check pv_field "$lvmdev" pe_start $pv_align fi
Signature · 1 line
1.8.2
PATCH 6/20 pvremove: Avoid using pv_read in favour of scanning.
In reply to Petr Rockai--- lib/metadata/pv_manip.c | 75 +++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 36 deletions(-)
lib/metadata/pv_manip.c +39 -36
@@ -652,59 +652,62 @@ const char _really_wipe[] =static int pvremove_check (struct cmd_context *cmd,const char *name,unsigned force_count,unsigned prompt) { -struct physical_volume *pv; +struct device *dev; +struct label *label; +struct pv_list *pvl; +struct dm_list *pvslist; + +struct physical_volume *pv =NULL ; +int r =0 ;/* FIXME Check partition type is LVM unless --force is given */ +if (!(dev =dev_cache_get (name, cmd->filter))) { +log_error ("Device %s not found" , name); +return 0 ; + } +/* Is there a pv here already? */ /* If not, this is an error unless you used -f. */ -if (!(pv =pv_read (cmd, name,1 ,0 ))) { +if (!label_read (dev, &label,0 )) {if (force_count)return 1 ; -log_error ("Physical Volume %s not found" , name); +log_error ("No PV label found on %s." , name);return 0 ; } -/* -* If a PV has no MDAs it may appear to be an -* orphan until the metadata is read off -* another PV in the same VG. Detecting this -* means checking every VG by scanning every -* PV on the system. -*/ -if (is_orphan (pv) &&dm_list_empty (&pv->fid->metadata_areas_in_use) && -dm_list_empty (&pv->fid->metadata_areas_ignored)) { -if (!scan_vgs_for_pvs (cmd,0 )) { -log_error ("Rescan for PVs without metadata areas " -"failed." ); - goto bad; - } -free_pv_fid (pv); -if (!(pv =pv_read (cmd, name,1 ,0 ))) { -log_error ("Failed to read physical volume %s" , name); - goto bad; - } +lvmcache_seed_infos_from_lvmetad (cmd); +if (!(pvslist =get_pvs (cmd))) + return_0; + + dm_list_iterate_items(pvl, pvslist) +if (pvl->pv->dev == dev) + pv = pvl->pv; + +if (!pv) { +log_error ("Physical Volume %s not found through scanning." , name); + goto out;/* better safe than sorry */ } -/* orphan ? */ if (is_orphan (pv)) { -free_pv_fid (pv); -return 1 ; + r =1 ; + goto out; } -/* Allow partial & exported VGs to be destroyed. */ /* we must have -ff to overwrite a non orphan */ if (force_count <2 ) {log_error ("PV %s belongs to Volume Group %s so please use vgreduce first." , name,pv_vg_name (pv));log_error ("(If you are certain you need pvremove, then confirm by using --force twice.)" ); - goto bad; + goto out; }/* prompt */ if (!prompt && -yes_no_prompt (_really_wipe, name,pv_vg_name (pv)) =='n' ) { +yes_no_prompt ("Really WIPE LABELS from physical volume \"%s\" " +"of volume group \"%s\" [y/n]? " , + name,pv_vg_name (pv)) =='n' ) {log_error ("%s: physical volume label not removed" , name); - goto bad; + goto out; }if (force_count) {
@@ -715,17 +718,17 @@ static int pvremove_check(struct cmd_context *cmd, const char *name, !is_orphan(pv) ? "\"" : ""); } -free_pv_fid (pv); -return 1 ; - -bad: -free_pv_fid (pv); -return 0 ; + r =1 ; +out: +if (pvslist) + dm_list_iterate_items(pvl, pvslist) +free_pv_fid (pvl->pv); +return r; }int pvremove_single (struct cmd_context *cmd,const char *pv_name,void *handle __attribute__((unused)),unsigned force_count, -unsigned prompt) +unsigned prompt) {struct device *dev;int r =0 ;
Signature · 1 line
1.8.2
PATCH 7/20 metadata: Avoid pv_read in find_pv_by_name.
In reply to Petr Rockai--- lib/metadata/metadata.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-)
lib/metadata/metadata.c +20 -14
@@ -1330,7 +1330,7 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,/* FIXME Check partition type is LVM unless --force is given */ /* Is there a pv here already? */ -if (!(pv =pv_read (cmd, name,0 ,0 ))) +if (!(pv =find_pv_by_name (cmd, name,1 ))) stack;/*
@@ -1824,23 +1824,29 @@ struct physical_volume *find_pv_by_name(struct cmd_context *cmd, const char *pv_name, int allow_orphan) { -struct physical_volume *pv; +struct device *dev; +struct pv_list *pvl; +struct dm_list *pvslist; +struct physical_volume *pv =NULL ; + +lvmcache_seed_infos_from_lvmetad (cmd); -if (!(pv =_pv_read (cmd, cmd->mem, pv_name,NULL ,1 ,0 ))) { +if (!(dev =dev_cache_get (pv_name, cmd->filter))) {log_error ("Physical volume %s not found" , pv_name); - goto bad; + return_NULL; } -if (is_orphan_vg (pv->vg_name) &&dm_list_empty (&pv->fid->metadata_areas_in_use)) { -/* If a PV has no MDAs - need to search all VGs for it */ -if (!scan_vgs_for_pvs (cmd,1 )) - goto_bad; -free_pv_fid (pv); -if (!(pv =_pv_read (cmd, cmd->mem, pv_name,NULL ,1 ,0 ))) { -log_error ("Physical volume %s not found" , pv_name); - goto bad; - } - } +if (!(pvslist =get_pvs (cmd))) + return_NULL; + + dm_list_iterate_items(pvl, pvslist) +if (pvl->pv->dev == dev) + pv = pvl->pv; +else +free_pv_fid (pvl->pv); + +if (!pv) +log_error ("Physical volume %s not found" , pv_name);if (pv && !allow_orphan &&is_orphan_vg (pv->vg_name)) {log_error ("Physical volume %s not in a volume group" , pv_name);
Signature · 1 line
1.8.2
PATCH 8/20 metadata: Fix handling of orphan PV linking & re-linking.
In reply to Petr Rockai--- lib/metadata/metadata.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)
lib/metadata/metadata.c +28 -3
@@ -269,6 +269,12 @@ int add_pv_to_vg(struct volume_group *vg, const char *pv_name, vg->extent_count += pv->pe_count; vg->free_count += pv->pe_count; + dm_list_iterate_items(pvl, &fid->fmt->orphan_vg->pvs) +if (pv == pvl->pv) {/* unlink from orphan */ +dm_list_del (&pvl->list); +break ; + } +if (pv->status &UNLABELLED_PV ) {if (!(pvc =dm_pool_zalloc (mem,sizeof (*pvc)))) {log_error ("pv_to_create allocation for '%s' failed" , pv_name);
@@ -2810,8 +2816,10 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd,struct lvmcache_vginfo *vginfo;struct volume_group *vg =NULL ;struct _vg_read_orphan_baton baton; -struct pv_list *pvl; +struct pv_list *pvl, *pvl_; +struct pv_list head; +dm_list_init (&head.list);lvmcache_label_scan (cmd,0 );lvmcache_seed_infos_from_lvmetad (cmd);
@@ -2822,14 +2830,31 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd, return_NULL; vg = fmt->orphan_vg; - dm_list_iterate_items(pvl, &vg->pvs) -pv_set_fid (pvl->pv,NULL ); +restart: + dm_list_iterate_items(pvl, &vg->pvs) { +if (pvl->pv->status &UNLABELLED_PV ) { +dm_list_del (&pvl->list); +dm_list_add (&head.list, &pvl->list); + goto restart; + }else +pv_set_fid (pvl->pv,NULL ); + }dm_list_init (&vg->pvs); vg->pv_count =0 ; + vg->extent_count =0 ; + vg->free_count =0 ; baton.warnings = warnings; baton.vg = vg; +while (!dm_list_empty (&head.list)) { + pvl = (struct pv_list *)dm_list_first (&head.list); +dm_list_del (&pvl->list); +add_pvl_to_vgs (vg, pvl); + vg->extent_count += pvl->pv->pe_count; + vg->free_count += pvl->pv->pe_count; + } +if (!lvmcache_foreach_pv (vginfo, _vg_read_orphan_pv, &baton)) return_NULL;
Signature · 1 line
1.8.2
PATCH 9/20 metadata: Nuke the exported "pv_read" function.
In reply to Petr Rockai--- lib/metadata/metadata-exported.h | 3 --- lib/metadata/metadata.c | 36 ------------------------------------ 2 files changed, 39 deletions(-)
lib/metadata/metadata-exported.h +0 -3
@@ -497,9 +497,6 @@ int vg_commit(struct volume_group *vg);void vg_revert (struct volume_group *vg);struct volume_group *vg_read_internal (struct cmd_context *cmd,const char *vg_name,const char *vgid,int warnings,int *consistent); -struct physical_volume *pv_read (struct cmd_context *cmd,const char *pv_name, -int warnings, -int scan_label_only);#define get_pvs ( cmd ) get_pvs_internal((cmd), NULL, NULL)#define get_pvs_perserve_vg ( cmd, pv_list, vg_list ) get_pvs_internal((cmd), (pv_list), (vg_list))
lib/metadata/metadata.c +0 -36
@@ -1339,20 +1339,6 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,if (!(pv =find_pv_by_name (cmd, name,1 ))) stack; -/* -* If a PV has no MDAs it may appear to be an orphan until the -* metadata is read off another PV in the same VG. Detecting -* this means checking every VG by scanning every PV on the -* system. -*/ -if (pv &&is_orphan (pv) &&dm_list_empty (&pv->fid->metadata_areas_in_use)) { -free_pv_fid (pv); -if (!scan_vgs_for_pvs (cmd,0 )) - return_0; -if (!(pv =pv_read (cmd, name,0 ,0 ))) - stack; - } -/* Allow partial & exported VGs to be destroyed. */ /* We must have -ff to overwrite a non orphan */ if (pv && !is_orphan (pv) && pp->force !=DONT_PROMPT_OVERRIDE ) {
@@ -3628,28 +3614,6 @@ const char *find_vgname_from_pvname(struct cmd_context *cmd,return find_vgname_from_pvid (cmd, pvid); } -/** -* 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, -int warnings, -int scan_label_only) -{ -return _pv_read (cmd, cmd->mem, pv_name,NULL , warnings, scan_label_only); -} -/* FIXME Use label functions instead of PV functions */ static struct physical_volume *_pv_read(struct cmd_context *cmd, struct dm_pool *pvmem,
Signature · 1 line
1.8.2
PATCH 10/20 labeller: Make the use of "private" as "fmt" explicit.
In reply to Petr RockaiAll labellers always use the "private" (void *) field as the fmt pointer. Making this fact explicit in the type of the labeller simplifies the label reporting code which needs to extract the format. Moreover, it removes a number of error-prone casts from the code.
--- lib/cache/lvmcache.c | 4 ++-- lib/format1/format1.c | 2 +- lib/format1/lvm1-label.c | 2 +- lib/format_pool/format_pool.c | 2 +- lib/format_pool/pool_label.c | 2 +- lib/format_text/format-text.c | 2 +- lib/format_text/text_label.c | 4 ++-- lib/label/label.c | 4 ++-- lib/label/label.h | 4 ++-- 9 files changed, 13 insertions(+), 13 deletions(-)
lib/cache/lvmcache.c +2 -2
@@ -1450,7 +1450,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid, const char *vgname, const char *vgid, uint32_t vgstatus) { - const struct format_type *fmt = (const struct format_type *) labeller->private; + const struct format_type *fmt = labeller->fmt;struct dev_types *dt = fmt->cmd->dev_types;struct label *label;struct lvmcache_info *existing, *info;
@@ -1540,7 +1540,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid, label = info->label; } - info->fmt = (const struct format_type *) labeller->private; + info->fmt = labeller->fmt; info->status |=CACHE_INVALID ;if (!_lvmcache_update_pvid (info, pvid_s)) {
lib/format1/format1.c +1 -1
@@ -614,7 +614,7 @@ struct format_type *init_format(struct cmd_context *cmd)return NULL ; } -if (!(label_register_handler (FMT_LVM1_NAME , fmt->labeller))) { +if (!(label_register_handler (fmt->labeller))) {log_error ("Couldn't register lvm1 label handler." ); fmt->labeller->ops->destroy (fmt->labeller);dm_free (fmt);
lib/format1/lvm1-label.c +1 -1
@@ -122,7 +122,7 @@ struct labeller *lvm1_labeller_create(struct format_type *fmt) } l->ops = &_lvm1_ops; - l->private = (const void *) fmt; + l->fmt = fmt;return l; }
lib/format_pool/format_pool.c +1 -1
@@ -309,7 +309,7 @@ struct format_type *init_format(struct cmd_context *cmd)return NULL ; } -if (!(label_register_handler (FMT_POOL_NAME , fmt->labeller))) { +if (!(label_register_handler (fmt->labeller))) {log_error ("Couldn't register pool label handler." ); fmt->labeller->ops->destroy (fmt->labeller);dm_free (fmt);
lib/format_pool/pool_label.c +1 -1
@@ -99,7 +99,7 @@ struct labeller *pool_labeller_create(struct format_type *fmt) } l->ops = &_pool_ops; - l->private = (const void *) fmt; + l->fmt = fmt;return l; }
lib/format_text/format-text.c +1 -1
@@ -2433,7 +2433,7 @@ struct format_type *create_text_format(struct cmd_context *cmd) goto bad; } -if (!(label_register_handler (FMT_TEXT_NAME , fmt->labeller))) { +if (!(label_register_handler (fmt->labeller))) {log_error ("Couldn't register text label handler." ); fmt->labeller->ops->destroy (fmt->labeller); goto bad;
lib/format_text/text_label.c +2 -2
@@ -316,7 +316,7 @@ struct _update_mda_baton {static int _update_mda (struct metadata_area *mda,void *baton) {struct _update_mda_baton *p = baton; -const struct format_type *fmt = p->label->labeller->private;// Oh dear. +const struct format_type *fmt = p->label->labeller->fmt;struct mda_context *mdac = (struct mda_context *) mda->metadata_locn;struct mda_header *mdah;const char *vgname =NULL ;
@@ -471,7 +471,7 @@ struct labeller *text_labeller_create(const struct format_type *fmt) } l->ops = &_text_ops; - l->private = (const void *) fmt; + l->fmt = fmt;return l; }
lib/label/label.c +2 -2
@@ -76,11 +76,11 @@ void label_exit(void)dm_list_init (&_labellers); } -int label_register_handler (const char *name,struct labeller *handler) +int label_register_handler (struct labeller *handler) {struct labeller_i *li; -if (!(li =_alloc_li (name, handler))) +if (!(li =_alloc_li (handler->fmt->name, handler))) return_0;dm_list_add (&_labellers, &li->list);
lib/label/label.h +2 -2
@@ -87,13 +87,13 @@ struct label_ops {struct labeller {struct label_ops *ops; -const void *private; +struct format_type *fmt; };int label_init (void );void label_exit (void ); -int label_register_handler (const char *name,struct labeller *handler); +int label_register_handler (struct labeller *handler);struct labeller *label_get_handler (const char *name);
Signature · 1 line
1.8.2
PATCH 11/20 toollib: Implement process_each_label.
In reply to Petr Rockai--- tools/toollib.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/toollib.h | 6 ++++++ 2 files changed, 65 insertions(+)
tools/toollib.c +59 -0
@@ -1703,3 +1703,62 @@ int change_tag(struct cmd_context *cmd, struct volume_group *vg,return 1 ; } +int process_each_label (struct cmd_context *cmd,int argc,char **argv,void *handle, +process_single_label_fn_t process_single_label) +{ +struct label *label; +struct dev_iter *iter; +struct device *dev; + +int ret_max =ECMD_PROCESSED ; +int ret =0 ; +int opt =0 ; + +if (argc) { +for (; opt < argc; opt++) { +if (!(dev =dev_cache_get (argv[opt], cmd->filter))) { +log_error ("Failed to find device " +"\"%s\"" , argv[opt]); + ret_max =ECMD_FAILED ; +continue ; + } + +if (!label_read (dev, &label,0 )) +continue ; + + ret =process_single_label (cmd, label, handle); + +if (ret > ret_max) + ret_max = ret; + +if (sigint_caught ()) +break ; + } + +return ret_max; + } + +if (!(iter =dev_iter_create (cmd->filter,1 ))) { +log_error ("dev_iter creation failed" ); +return ECMD_FAILED ; + } + +while ((dev =dev_iter_get (iter))) + { +if (!label_read (dev, &label,0 )) +continue ; + +log_error ("processing %s" ,dev_name (dev)); + ret =process_single_label (cmd, label, handle); + +if (ret > ret_max) + ret_max = ret; + +if (sigint_caught ()) +break ; + } + +dev_iter_destroy (iter); + +return ret_max; +}
tools/toollib.h +6 -0
@@ -34,6 +34,9 @@ typedef int (*process_single_pv_fn_t) (struct cmd_context *cmd,struct volume_group *vg, struct physical_volume *pv, void *handle); +typedef int (*process_single_label_fn_t ) (struct cmd_context *cmd, +struct label *label, +void *handle);typedef int (*process_single_lv_fn_t ) (struct cmd_context *cmd,struct logical_volume *lv,void *handle);
@@ -54,6 +57,9 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, int scan_label_only, void *handle, process_single_pv_fn_t process_single_pv); +int process_each_label (struct cmd_context *cmd,int argc,char **argv, +void *handle,process_single_label_fn_t process_single_label); + int process_each_segment_in_pv(struct cmd_context *cmd, struct volume_group *vg, struct physical_volume *pv,
Signature · 1 line
1.8.2
PATCH 12/20 metadata: Add lvmcache_info_mda_free as a companion to pv_mda_free.
In reply to Petr Rockai--- lib/metadata/pv.c | 16 +++++++++++----- lib/metadata/pv.h | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-)
lib/metadata/pv.c +11 -5
@@ -241,14 +241,11 @@ static int _pv_mda_free(struct metadata_area *mda, void *baton) {return 1 ; } -uint64_t pv_mda_free (const struct physical_volume *pv) +uint64_t lvmcache_info_mda_free (struct lvmcache_info *info) { -struct lvmcache_info *info;uint64_t freespace =UINT64_MAX ; -const char *pvid = (const char *)&pv->id.uuid; -if ((info =lvmcache_info_from_pvid (pvid,0 ))) -lvmcache_foreach_mda (info, _pv_mda_free, &freespace); +lvmcache_foreach_mda (info, _pv_mda_free, &freespace);if (freespace ==UINT64_MAX ) freespace =UINT64_C (0 );
@@ -256,6 +253,15 @@ uint64_t pv_mda_free(const struct physical_volume *pv)return freespace; } +uint64_t pv_mda_free (const struct physical_volume *pv) +{ +const char *pvid = (const char *)&pv->id.uuid; +struct lvmcache_info *info; +if ((info =lvmcache_info_from_pvid (pvid,0 ))) +return lvmcache_info_mda_free (info); +return 0 ; +} +uint64_t pv_used (const struct physical_volume *pv) {uint64_t used;
lib/metadata/pv.h +2 -0
@@ -85,6 +85,8 @@ uint64_t pv_ba_size(const struct physical_volume *pv);uint32_t pv_pe_count (const struct physical_volume *pv);uint32_t pv_pe_alloc_count (const struct physical_volume *pv);uint64_t pv_mda_size (const struct physical_volume *pv); +struct lvmcache_info ; +uint64_t lvmcache_info_mda_free (struct lvmcache_info *info);uint64_t pv_mda_free (const struct physical_volume *pv);uint64_t pv_used (const struct physical_volume *pv);uint32_t pv_mda_count (const struct physical_volume *pv);
Signature · 1 line
1.8.2
PATCH 13/20 metadata: Add a pv_label accessor (go from a PV to its label).
In reply to Petr Rockai--- lib/metadata/pv.c | 10 ++++++++++ lib/metadata/pv.h | 1 + 2 files changed, 11 insertions(+)
lib/metadata/pv.c +10 -0
@@ -350,3 +350,13 @@ unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignorreturn 1 ; } +struct label *pv_label (const struct physical_volume *pv) +{ +struct lvmcache_info *info = +lvmcache_info_from_pvid ((const char *)&pv->id.uuid,0 ); +if (!info) { +log_error (INTERNAL_ERROR "PV %s unexpectedly not in cache." ,dev_name (pv->dev)); +return NULL ; + } +return lvmcache_get_label (info); +}
lib/metadata/pv.h +1 -0
@@ -95,5 +95,6 @@ unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned ignored);int is_orphan (const struct physical_volume *pv);int is_missing_pv (const struct physical_volume *pv);int is_pv (const struct physical_volume *pv); +struct label *pv_label (const struct physical_volume *pv);#endif /* _LVM_PV_H */
Signature · 1 line
1.8.2
PATCH 14/20 label: Track a device pointer in struct label.
In reply to Petr Rockai--- lib/label/label.c | 4 +++- lib/label/label.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
lib/label/label.c +3 -1
@@ -282,8 +282,10 @@ int label_read(struct device *dev, struct label **result,if (!(l =_find_labeller (dev, buf, §or, scan_sector))) goto out; -if ((r = (l->ops->read)(l, dev, buf, result)) && result && *result) +if ((r = (l->ops->read)(l, dev, buf, result)) && result && *result) { + (*result)->dev = dev; (*result)->sector = sector; + } out:if (!dev_close (dev))
lib/label/label.h +1 -0
@@ -42,6 +42,7 @@ struct label {char type[8 ];uint64_t sector;struct labeller *labeller; +struct device *dev;void *info; };
Signature · 1 line
1.8.2
PATCH 15/20 report: Make dev_size and dev_name columns' type "label".
In reply to Petr Rockai--- lib/report/columns.h | 4 ++-- lib/report/report.c | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-)
lib/report/columns.h +2 -2
@@ -68,9 +68,9 @@ FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, lv_modules, "Kernel device-mapp FIELD(LABEL, pv, STR, "Fmt", id, 3, pvfmt, pv_fmt, "Type of metadata.", 0) FIELD(LABEL, pv, STR, "PV UUID", id, 38, uuid, pv_uuid, "Unique identifier.", 0) -FIELD(LABEL, pv, NUM, "DevSize", id, 7, devsize, dev_size, "Size of underlying device in current units.", 0) -FIELD(LABEL, pv, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0) FIELD(LABEL, pv, NUM, "PMdaFree", id, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0) +FIELD(LABEL, label, NUM, "DevSize", dev, 7, devsize, dev_size, "Size of underlying device in current units.", 0) +FIELD(LABEL, label, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0) FIELD(LABEL, pv, NUM, "PMdaSize", id, 9, pvmdasize, pv_mda_size, "Size of smallest metadata area on this device in current units.", 0)FIELD (PVS , pv,NUM ,"1st PE" , pe_start,7 , size64, pe_start,"Offset to the start of data on the underlying device." ,0 )
lib/report/report.c +2 -6
@@ -672,12 +672,8 @@ static int _devsize_disp(struct dm_report *rh, struct dm_pool *mem,struct dm_report_field *field, const void *data, void *private) { - const struct physical_volume *pv = - (const struct physical_volume *) data; -uint64_t size; - - size =pv_dev_size (pv); - + uint64_t size = 0; +dev_get_size (*(const struct device **) data, &size);return _size64_disp (rh, mem, field, &size, private); }
Signature · 1 line
1.8.2
PATCH 16/20 report: Add a proper "label" field type.
In reply to Petr Rockai--- lib/report/report.c | 13 +++++++++++-- lib/report/report.h | 4 +++- tools/reporter.c | 19 +++++++++++-------- 3 files changed, 25 insertions(+), 11 deletions(-)
lib/report/report.c +11 -2
@@ -31,6 +31,7 @@ struct lvm_report_object {struct physical_volume *pv;struct lv_segment *seg;struct pv_segment *pvseg; +struct label *label; };static const uint64_t _minusone64 =UINT64_C (-1 );
@@ -1256,6 +1257,11 @@ static void *_obj_get_pv(void *obj)return ((struct lvm_report_object *)obj)->pv; } +static void *_obj_get_label (void *obj) +{ +return ((struct lvm_report_object *)obj)->label; +} +static void *_obj_get_seg (void *obj) {return ((struct lvm_report_object *)obj)->seg;
@@ -1270,7 +1276,7 @@ static const struct dm_report_object_type _report_types[] = { { VGS, "Volume Group", "vg_", _obj_get_vg }, { LVS, "Logical Volume", "lv_", _obj_get_lv }, { PVS, "Physical Volume", "pv_", _obj_get_pv }, - { LABEL, "Physical Volume Label", "pv_", _obj_get_pv }, + { LABEL, "Physical Volume Label", "pv_", _obj_get_label }, { SEGS, "Logical Volume Segment", "seg_", _obj_get_seg }, { PVSEGS, "Physical Volume Segment", "pvseg_", _obj_get_pvseg }, { 0, "", "", NULL },
@@ -1291,6 +1297,7 @@ typedef struct logical_volume type_lv;typedef struct volume_group type_vg ;typedef struct lv_segment type_seg ;typedef struct pv_segment type_pvseg ; +typedef struct label type_label ;static const struct dm_report_field_type _fields[] = { #include "columns.h"
@@ -1341,7 +1348,8 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,*/ int report_object (void *handle,struct volume_group *vg,struct logical_volume *lv,struct physical_volume *pv, -struct lv_segment *seg,struct pv_segment *pvseg) +struct lv_segment *seg,struct pv_segment *pvseg, +struct label *label) {struct lvm_report_object obj;
@@ -1354,6 +1362,7 @@ int report_object(void *handle, struct volume_group *vg, obj.pv = pv; obj.seg = seg; obj.pvseg = pvseg; + obj.label = label ? label : (pv ?pv_label (pv) :NULL );return dm_report_object (handle, &obj); }
lib/report/report.h +3 -1
@@ -17,6 +17,7 @@#define _LVM_REPORT_H#include "metadata-exported.h" +#include "label.h" typedef enum { LVS = 1,
@@ -40,7 +41,8 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,void report_free (void *handle);int report_object (void *handle,struct volume_group *vg,struct logical_volume *lv,struct physical_volume *pv, -struct lv_segment *seg,struct pv_segment *pvseg); +struct lv_segment *seg,struct pv_segment *pvseg, +struct label *label);int report_output (void *handle);#endif
tools/reporter.c +11 -8
@@ -20,7 +20,7 @@ static int _vgs_single(struct cmd_context *cmd __attribute__((unused)), const char *vg_name, struct volume_group *vg, void *handle) { - if (!report_object(handle, vg, NULL, NULL, NULL, NULL)) + if (!report_object(handle, vg, NULL, NULL, NULL, NULL, NULL)) return_ECMD_FAILED;check_current_backup (vg );
@@ -31,7 +31,7 @@ static int _vgs_single(struct cmd_context *cmd __attribute__((unused)),static int _lvs_single (struct cmd_context *cmd,struct logical_volume *lv,void *handle) { -if (!report_object (handle, lv->vg, lv,NULL ,NULL ,NULL )) +if (!report_object (handle, lv->vg, lv,NULL ,NULL ,NULL ,NULL )) return_ECMD_FAILED;return ECMD_PROCESSED ;
@@ -40,7 +40,7 @@ static int _lvs_single(struct cmd_context *cmd, struct logical_volume *lv,static int _segs_single (struct cmd_context *cmd __attribute__((unused)),struct lv_segment *seg,void *handle) { -if (!report_object (handle, seg->lv->vg, seg->lv,NULL , seg,NULL )) +if (!report_object (handle, seg->lv->vg, seg->lv,NULL , seg,NULL ,NULL )) return_ECMD_FAILED;return ECMD_PROCESSED ;
@@ -96,7 +96,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd,dm_list_init (&_free_logical_volume.snapshot_segs);if (!report_object (handle, vg, seg ? seg->lv : &_free_logical_volume, pvseg->pv, - seg ? : &_free_lv_segment, pvseg)) { + seg ? : &_free_lv_segment, pvseg,NULL )) { ret =ECMD_FAILED ; goto_out; }
@@ -129,6 +129,7 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,const char *vg_name =NULL ;struct volume_group *old_vg = vg; char uuid[64] __attribute__((aligned(8))); +struct label *label;if (is_pv (pv) && !is_orphan (pv) && !vg) { vg_name =pv_vg_name (pv);
@@ -166,7 +167,9 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg, pv = pvl->pv; } -if (!report_object (handle, vg,NULL , pv,NULL ,NULL )) { +if ((!(label =pv_label (pv))) || + (!report_object (handle, vg,NULL , pv,NULL ,NULL , label))) + { stack; ret =ECMD_FAILED ; }
@@ -181,10 +184,10 @@ out:return ret; } -static int _label_single (struct cmd_context *cmd,struct volume_group *vg, -struct physical_volume *pv,void *handle) +static int _label_single (struct cmd_context *cmd,struct label *label, +void *handle) { -if (!report_object (handle, vg,NULL , pv,NULL ,NULL )) +if (!report_object (handle,NULL ,NULL ,NULL ,NULL ,NULL , label)) return_ECMD_FAILED;return ECMD_PROCESSED ;
Signature · 1 line
1.8.2
PATCH 17/20 report: Adapt _pvfmt_disp to label-based reporting.
In reply to Petr Rockai--- lib/report/columns.h | 2 +- lib/report/report.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
lib/report/columns.h +1 -1
@@ -66,9 +66,9 @@ FIELD(LVS, lv, STR, "Time", lvid, 26, lvtime, lv_time, "Creation time of the LV, FIELD(LVS, lv, STR, "Host", lvid, 10, lvhost, lv_host, "Creation host of the LV, if known.", 0) FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, lv_modules, "Kernel device-mapper modules required for this LV.", 0) -FIELD(LABEL, pv, STR, "Fmt", id, 3, pvfmt, pv_fmt, "Type of metadata.", 0) FIELD(LABEL, pv, STR, "PV UUID", id, 38, uuid, pv_uuid, "Unique identifier.", 0) FIELD(LABEL, pv, NUM, "PMdaFree", id, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0) +FIELD(LABEL, label, STR, "Fmt", type, 3, pvfmt, pv_fmt, "Type of metadata.", 0) FIELD(LABEL, label, NUM, "DevSize", dev, 7, devsize, dev_size, "Size of underlying device in current units.", 0) FIELD(LABEL, label, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0)FIELD (LABEL , pv,NUM ,"PMdaSize" , id,9 , pvmdasize, pv_mda_size,"Size of smallest metadata area on this device in current units." ,0 )
lib/report/report.c +4 -4
@@ -143,15 +143,15 @@ static int _pvfmt_disp(struct dm_report *rh, struct dm_pool *mem,struct dm_report_field *field, const void *data, void *private) { - const struct physical_volume *pv = - (const struct physical_volume *) data; + const struct label *l = + (const struct label *) data; -if (!pv->fmt) { +if (!l->labeller->fmt) {dm_report_field_set_value (field,"" ,NULL );return 1 ; } -return _string_disp (rh, mem, field, &pv->fmt->name, private); +return _string_disp (rh, mem, field, &l->labeller->fmt->name, private); } static int _lvkmaj_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
Signature · 1 line
1.8.2
PATCH 18/20 report: Make PMdaFree into a "label" field.
In reply to Petr Rockai--- lib/report/columns.h | 2 +- lib/report/report.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-)
lib/report/columns.h +1 -1
@@ -67,10 +67,10 @@ FIELD(LVS, lv, STR, "Host", lvid, 10, lvhost, lv_host, "Creation host of the LV, FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, lv_modules, "Kernel device-mapper modules required for this LV.", 0) FIELD(LABEL, pv, STR, "PV UUID", id, 38, uuid, pv_uuid, "Unique identifier.", 0) -FIELD(LABEL, pv, NUM, "PMdaFree", id, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0) FIELD(LABEL, label, STR, "Fmt", type, 3, pvfmt, pv_fmt, "Type of metadata.", 0) FIELD(LABEL, label, NUM, "DevSize", dev, 7, devsize, dev_size, "Size of underlying device in current units.", 0) FIELD(LABEL, label, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0) +FIELD(LABEL, label, NUM, "PMdaFree", type, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0) FIELD(LABEL, pv, NUM, "PMdaSize", id, 9, pvmdasize, pv_mda_size, "Size of smallest metadata area on this device in current units.", 0)FIELD (PVS , pv,NUM ,"1st PE" , pe_start,7 , size64, pe_start,"Offset to the start of data on the underlying device." ,0 )
lib/report/report.c +2 -3
@@ -787,11 +787,10 @@ static int _pvmdafree_disp(struct dm_report *rh, struct dm_pool *mem,struct dm_report_field *field, const void *data, void *private) { - const struct physical_volume *pv = - (const struct physical_volume *) data; + const struct label *label = (const struct label *) data;uint64_t freespace; - freespace =pv_mda_free (pv); + freespace =lvmcache_info_mda_free (label->info);return _size64_disp (rh, mem, field, &freespace, private); }
Signature · 1 line
1.8.2
PATCH 19/20 report: Iterate over labels instead of PVs for label-only reports.
In reply to Petr Rockai--- tools/reporter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/reporter.c +2 -2
@@ -362,8 +362,8 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, report_handle, &_vgs_single);break ;case LABEL : - r =process_each_pv (cmd, argc, argv,NULL ,READ_WITHOUT_LOCK , -1 , report_handle, &_label_single); + r =process_each_label (cmd, argc, argv, + report_handle, &_label_single);break ;case PVS :if (args_are_pvs)
Signature · 1 line
1.8.2
PATCH 20/20 report: Make PV UUID into a "label" type field.
In reply to Petr Rockai--- lib/report/columns.h | 2 +- lib/report/report.c | 14 ++++++++++++++ test/shell/listings.sh | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-)
lib/report/columns.h +1 -1
@@ -66,8 +66,8 @@ FIELD(LVS, lv, STR, "Time", lvid, 26, lvtime, lv_time, "Creation time of the LV, FIELD(LVS, lv, STR, "Host", lvid, 10, lvhost, lv_host, "Creation host of the LV, if known.", 0) FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, lv_modules, "Kernel device-mapper modules required for this LV.", 0) -FIELD(LABEL, pv, STR, "PV UUID", id, 38, uuid, pv_uuid, "Unique identifier.", 0) FIELD(LABEL, label, STR, "Fmt", type, 3, pvfmt, pv_fmt, "Type of metadata.", 0) +FIELD(LABEL, label, STR, "PV UUID", type, 38, pvuuid, pv_uuid, "Unique identifier.", 0) FIELD(LABEL, label, NUM, "DevSize", dev, 7, devsize, dev_size, "Size of underlying device in current units.", 0) FIELD(LABEL, label, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0)FIELD (LABEL , label,NUM ,"PMdaFree" , type,9 , pvmdafree, pv_mda_free,"Free metadata area space on this device in current units." ,0 )
lib/report/report.c +14 -0
@@ -703,6 +703,20 @@ static int _uuid_disp(struct dm_report *rh __attribute__((unused)), struct dm_poreturn 1 ; } +static int _pvuuid_disp (struct dm_report *rh __attribute__((unused)),struct dm_pool *mem, +struct dm_report_field *field, +const void *data,void *private __attribute__((unused))) +{ +const struct label *label = (const struct label *) data; +char *repstr =NULL ; + +if (!(repstr =id_format_and_copy (mem, label->dev->pvid))) + return_0; + +dm_report_field_set_value (field, repstr,NULL ); +return 1 ; +} +static int _pvmdas_disp (struct dm_report *rh,struct dm_pool *mem,struct dm_report_field *field,const void *data,void *private)
test/shell/listings.sh +3 -1
@@ -17,7 +17,7 @@ aux prepare_devs 5 -pvcreate "$dev1" +pvcreate --uuid BADBEE-BAAD-BAAD-BAAD-BAAD-BAAD-BADBEE --norestorefile "$dev1" pvcreate --metadatacopies 0 "$dev2" pvcreate --metadatacopies 0 "$dev3" pvcreate "$dev4"
@@ -31,6 +31,8 @@ test $(pvs --noheadings -o seg_all,pv_all,lv_all,vg_all $(cat DEVICES) | wc -l) vgcreate $vg $(cat DEVICES) +check pv_field $dev1 pv_uuid BADBEE-BAAD-BAAD-BAAD-BAAD-BAAD-BADBEE + #COMM pvs and vgs report mda_count, mda_free (bz202886, bz247444) pvs -o +pv_mda_count,pv_mda_free $(cat DEVICES) for I in "$dev2" "$dev3" "$dev5"; do
Signature · 1 line
1.8.2