Skip to contentSkip to conversation

master - Place the first PE at 1 MiB for all defaults

PATCH David Teigland 1 participant 1 message Nov 26, 2018

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=904e1e3d26ccb43c19266e96e67f8c10f93eaaa4
Commit:        904e1e3d26ccb43c19266e96e67f8c10f93eaaa4
Parent:        2d1152103f8fce4892380f75f59dd5013bcd84d3
Author:        David Teigland <[email protected]>
AuthorDate:    Tue Nov 13 15:00:11 2018 -0600
Committer:     David Teigland <[email protected]>
CommitterDate: Mon Nov 26 16:36:50 2018 -0600

Place the first PE at 1 MiB for all defaults

. When using default settings, this commit should change
nothing. The first PE continues to be placed at 1 MiB resulting in a metadata area size of 1020 KiB (for 4K page sizes; slightly smaller for larger page sizes.)

. When default_data_alignment is disabled in lvm.conf,
align pe_start at 1 MiB, based on a default metadata area size that adapts to the page size. Previously, disabling this option would result in mda_size that was too small for common use, and produced a 64 KiB aligned pe_start.

. Customized pe_start and mda_size values continue to be
set as before in lvm.conf and command line.

. Remove the configure option for setting default_data_alignment
at build time.

. Improve alignment related option descriptions.

. Add section about alignment to pvcreate man page.

Previously, DEFAULT_PVMETADATASIZE was 255 sectors. However, the fact that the config setting named "default_data_alignment" has a default value of 1 (MiB) meant that DEFAULT_PVMETADATASIZE was having no effect.

The metadata area size is the space between the start of the metadata area (page size offset from the start of the device) and the first PE (1 MiB by default due to default_data_alignment 1.) The result is a 1020 KiB metadata area on machines with 4KiB page size (1024 KiB - 4 KiB), and smaller on machines with larger page size.

If default_data_alignment was set to 0 (disabled), then DEFAULT_PVMETADATASIZE 255 would take effect, and produce a metadata area that was 188 KiB and pe_start of 192 KiB. This was too small for common use.

This is fixed by making the default metadata area size a computed value that matches the value produced by default_data_alignment.

---
 configure.ac                          |   10 --
 include/configure.h.in                |    3 -
 lib/config/config.c                   |    6 +
 lib/config/config.h                   |    2 +
 lib/config/config_settings.h          |   62 +++++++-----
 lib/config/defaults.h                 |   15 +++-
 lib/format_text/format-text.c         |   81 +++++++++-------
 lib/metadata/metadata-exported.h      |   14 ++--
 lib/metadata/metadata.c               |  175 +++++++++++++++++++++++++--------
 lib/metadata/metadata.h               |    7 +-
 lib/metadata/pv.h                     |    4 +-
 man/pvcreate.8_des                    |   87 ++++++++++++++---
 man/vgcreate.8_des                    |    6 +
 test/shell/pe-align.sh                |  144 +++++++++++++++++++++++++++
 test/shell/pvcreate-bootloaderarea.sh |    8 +-
 test/shell/pvcreate-usage.sh          |   42 +++++---
 test/shell/topology-support.sh        |    3 +-
 tools/args.h                          |   31 +++---
 tools/toollib.c                       |    5 +-
 19 files changed, 526 insertions(+), 179 deletions(-)
configure.ac +0 -10
index ffec809..3578f7b 100644
@@ -1599,15 +1599,6 @@ AC_DEFINE_UNQUOTED(DEFAULT_LOCK_DIR, ["$DEFAULT_LOCK_DIR"],
 		   [Name of default locking directory.])
 
 ################################################################################
-dnl -- Setup default data alignment
-AC_ARG_WITH(default-data-alignment,
-	    AC_HELP_STRING([--with-default-data-alignment=NUM],
-			   [set the default data alignment in MiB [1]]),
-	    DEFAULT_DATA_ALIGNMENT=$withval, DEFAULT_DATA_ALIGNMENT=1)
-AC_DEFINE_UNQUOTED(DEFAULT_DATA_ALIGNMENT, [$DEFAULT_DATA_ALIGNMENT],
-		   [Default data alignment.])
-
-################################################################################
 dnl -- which kernel interface to use (ioctl only)
 AC_MSG_CHECKING(for kernel interface choice)
 AC_ARG_WITH(interface,
@@ -1667,7 +1658,6 @@ AC_SUBST(DEBUG)
 AC_SUBST(DEFAULT_ARCHIVE_SUBDIR)
 AC_SUBST(DEFAULT_BACKUP_SUBDIR)
 AC_SUBST(DEFAULT_CACHE_SUBDIR)
-AC_SUBST(DEFAULT_DATA_ALIGNMENT)
 AC_SUBST(DEFAULT_DM_RUN_DIR)
 AC_SUBST(DEFAULT_LOCK_DIR)
 AC_SUBST(DEFAULT_MIRROR_SEGTYPE)
include/configure.h.in +0 -3
index 19c1922..c66b37b 100644
@@ -45,9 +45,6 @@
 /* Name of default metadata cache subdirectory. */
 #undef DEFAULT_CACHE_SUBDIR
 
-/* Default data alignment. */
-#undef DEFAULT_DATA_ALIGNMENT
-
 /* Define default node creation behavior with dmsetup create */
 #undef DEFAULT_DM_ADD_NODE
 
lib/config/config.c +6 -0
index 2e7e9b6..b3e230d 100644
@@ -24,6 +24,7 @@
 #include "lib/misc/lvm-file.h"
 #include "lib/mm/memlock.h"
 #include "lib/label/label.h"
+#include "lib/metadata/metadata.h"
 
 #include <sys/stat.h>
 #include <sys/mman.h>
@@ -2333,6 +2334,11 @@ int load_pending_profiles(struct cmd_context *cmd)
 	return r;
 }
 
+int get_default_metadata_pvmetadatasize_CFG(struct cmd_context *cmd, struct profile *profile)
+{
+	return get_default_pvmetadatasize_sectors();
+}
+
 const char *get_default_devices_cache_dir_CFG(struct cmd_context *cmd, struct profile *profile)
 {
 	static char buf[PATH_MAX];
lib/config/config.h +2 -0
index 4c8ddac..c62ea20 100644
@@ -311,5 +311,7 @@ int get_default_allocation_cache_pool_chunk_size_CFG(struct cmd_context *cmd, st
 const char *get_default_allocation_cache_policy_CFG(struct cmd_context *cmd, struct profile *profile);
 #define get_default_unconfigured_allocation_cache_policy_CFG NULL
 uint64_t get_default_allocation_cache_pool_max_chunks_CFG(struct cmd_context *cmd, struct profile *profile);
+int get_default_metadata_pvmetadatasize_CFG(struct cmd_context *cmd, struct profile *profile);
+#define get_default_unconfigured_metadata_pvmetadatasize_CFG NULL
 
 #endif
lib/config/config_settings.h +38 -24

91 lines not on this page · raw message

lib/config/defaults.h +12 -3
index f3fcb09..fc12626 100644
@@ -18,8 +18,18 @@
 
 #include "device_mapper/vdo/vdo_limits.h"
 
-#define DEFAULT_PE_ALIGN 2048
-#define DEFAULT_PE_ALIGN_OLD 128
+
+/*
+ * By default the first PE is placed at 1 MiB.
+ *
+ * If default_data_alignment is 2, then the first PE
+ * is placed at 2 * 1 MiB.
+ *
+ * If default_data_alignment is 3, then the first PE
+ * is placed at 3 * 1 MiB.
+ */
+#define FIRST_PE_AT_ONE_MB_IN_SECTORS 2048  /* 1 MiB in 512 byte sectors */
+#define FIRST_PE_AT_ONE_MB_IN_MB         1
 
 #define DEFAULT_ARCHIVE_ENABLED 1
 #define DEFAULT_BACKUP_ENABLED 1
@@ -180,7 +190,6 @@
 #define DEFAULT_RECORD_LVS_HISTORY 0
 #define DEFAULT_LVS_HISTORY_RETENTION_TIME 0
 #define DEFAULT_PVMETADATAIGNORE 0
-#define DEFAULT_PVMETADATASIZE 255
 #define DEFAULT_PVMETADATACOPIES 1
 #define DEFAULT_VGMETADATACOPIES 0
 #define DEFAULT_LABELSECTOR UINT64_C(1)
lib/format_text/format-text.c +47 -34

123 lines not on this page · raw message

lib/metadata/metadata-exported.h +7 -7
index 7f673cd..763b91b 100644
@@ -566,20 +566,20 @@ struct vgnameid_list {
  * Values used by pv_create().
  */
 struct pv_create_args {
-	uint64_t size;
-	uint64_t data_alignment;
-	uint64_t data_alignment_offset;
+	uint64_t size; /* in sectors */
+	uint64_t data_alignment; /* in sectors */
+	uint64_t data_alignment_offset; /* in sectors */
 	uint64_t label_sector;
 	int pvmetadatacopies;
-	uint64_t pvmetadatasize;
+	uint64_t pvmetadatasize; /* in sectors */
 	unsigned metadataignore;
 
 	/* used when restoring */
 	struct id id;
 	struct id *idp;
-	uint64_t ba_start;
-	uint64_t ba_size;
-	uint64_t pe_start;
+	uint64_t ba_start; /* in sectors */
+	uint64_t ba_size; /* in sectors */
+	uint64_t pe_start; /* in sectors */
 	uint32_t extent_count;
 	uint32_t extent_size;
 };
lib/metadata/metadata.c +132 -43

246 lines not on this page · raw message

lib/metadata/metadata.h +4 -3
index 164fba2..f578325 100644
@@ -358,9 +358,10 @@ struct format_handler {
 /*
  * Utility functions
  */
-unsigned long set_pe_align(struct physical_volume *pv, unsigned long data_alignment);
-unsigned long set_pe_align_offset(struct physical_volume *pv,
-				  unsigned long data_alignment_offset);
+
+int get_default_pvmetadatasize_sectors(void);
+void set_pe_align(struct physical_volume *pv, uint64_t data_alignment);
+void set_pe_align_offset(struct physical_volume *pv, uint64_t data_alignment_offset);
 
 int pv_write_orphan(struct cmd_context *cmd, struct physical_volume *pv);
 
lib/metadata/pv.h +2 -2
index 61aa54e..c162acd 100644
@@ -54,8 +54,8 @@ struct physical_volume {
 	uint64_t pe_start;
 	uint32_t pe_count;
 	uint32_t pe_alloc_count;
-	unsigned long pe_align;
-	unsigned long pe_align_offset;
+	uint64_t pe_align;
+	uint64_t pe_align_offset;
 
         /* This is true whenever the represented PV has a label associated. */
         uint64_t is_labelled:1;
man/pvcreate.8_des +72 -15

93 lines not on this page · raw message

man/vgcreate.8_des +6 -0
index a2d7161..bc63660 100644
@@ -2,3 +2,9 @@ vgcreate creates a new VG on block devices. If the devices were not
 previously intialized as PVs with \fBpvcreate\fP(8), vgcreate will
 inititialize them, making them PVs. The pvcreate options for initializing
 devices are also available with vgcreate.
+
+When vgcreate uses an existing PV, that PV's existing values for metadata
+size, PE start, etc, are used, even if different values are specified in
+the vgcreate command.  To change these values, first use pvremove on the
+device.
+
test/shell/pe-align.sh new file +144 -0

144 lines not on this page · raw message

test/shell/pvcreate-bootloaderarea.sh +4 -4
index 2e16a5f..cc31812 100644
@@ -20,7 +20,7 @@ aux prepare_devs 1
 aux lvmconf 'global/suffix=0' 'global/units="b"'
 
 #COMM 'pvcreate sets/aligns bootloader area correctly'
-pvcreate --dataalignment 262144b --bootloaderareasize 614400b "$dev1"
+pvcreate --metadatasize 255s --dataalignment 262144b --bootloaderareasize 614400b "$dev1"
 # ba_start must be aligned based on dataalignment
 # pe_start starts at next dataalignment multiple
 # ba_size is the whole space in between ba_start and pe_start
@@ -33,7 +33,7 @@ dev_size=$(pvs -o pv_size --noheadings "$dev1")
 pv_size=$(( dev_size - 1048576 )) # device size - 1m pe_start = area for data
 
 # try to use the whole data area for bootloader area, remaining data area is zero then (pe_start = pv_size)
-pvcreate --bootloaderareasize ${pv_size}b --dataalignment 1048576b "$dev1"
+pvcreate --metadatasize 255s --bootloaderareasize ${pv_size}b --dataalignment 1048576b "$dev1"
 check pv_field "$dev1" pe_start $dev_size
 check pv_field "$dev1" ba_start 1048576
 check pv_field "$dev1" ba_size $pv_size
@@ -44,13 +44,13 @@ grep "Bootloader area with data-aligned start must not exceed device size" err
 
 # restoring the PV should also restore the bootloader area correctly
 pvremove -ff "$dev1"
-pvcreate --dataalignment 256k --bootloaderareasize 600k "$dev1"
+pvcreate --metadatasize 255s --dataalignment 256k --bootloaderareasize 600k "$dev1"
 vgcreate $SHARED $vg "$dev1"
 vgcfgbackup -f "$TESTDIR/vg_with_ba_backup" "$vg"
 pv_uuid=$(get pv_field "$dev1" pv_uuid)
 vgremove -ff $vg
 pvremove -ff "$dev1"
-pvcreate --dataalignment 256k --restorefile "$TESTDIR/vg_with_ba_backup" --uuid "$pv_uuid" "$dev1"
+pvcreate --metadatasize 255s --dataalignment 256k --restorefile "$TESTDIR/vg_with_ba_backup" --uuid "$pv_uuid" "$dev1"
 check pv_field "$dev1" ba_start "262144"
 check pv_field "$dev1" ba_size "786432"
 check pv_field "$dev1" pe_start "1048576"
test/shell/pvcreate-usage.sh +28 -14

68 lines not on this page · raw message

test/shell/topology-support.sh +2 -1
index f8526ad..ffd637f 100644
@@ -112,7 +112,8 @@ aux prepare_scsi_debug_dev $DEV_SIZE \
 check sysfs "$(< SCSI_DEBUG_DEV)" queue/logical_block_size $LOGICAL_BLOCK_SIZE
 check sysfs "$(< SCSI_DEBUG_DEV)" queue/optimal_io_size 786432
 
-aux prepare_pvs 1 $PER_DEV_SIZE
+aux prepare_devs 1 $PER_DEV_SIZE
+pvcreate --metadatasize 255s "${DEVICES[@]}"
 
 # Kernel (3.19) could provide wrong results - in this case skip
 # test with incorrect result - lvm2 can't figure out good values.
tools/args.h +16 -15
index 414d7a8..522cccf 100644
@@ -84,14 +84,16 @@ arg(binary_ARG, '\0', "binary", 0, 0, 0,
     "the \"unknown\" value which denotes that the value could not be determined).\n")
 
 arg(bootloaderareasize_ARG, '\0', "bootloaderareasize", sizemb_VAL, 0, 0,
-    "Create a separate bootloader area of specified size besides PV's data\n"
-    "area. The bootloader area is an area of reserved space on the PV from\n"
-    "which LVM will not allocate any extents and it's kept untouched. This is\n"
-    "primarily aimed for use with bootloaders to embed their own data or metadata.\n"
+    "Reserve space for the bootloader between the LVM metadata area and the first PE.\n"
+    "The bootloader area is reserved for bootloaders to embed their own data or\n"
+    "metadata; LVM will not use it.\n"
+    "The bootloader area begins where the first PE would otherwise be located.\n"
+    "The first PE is moved out by the size of the bootloader area, and then moved\n"
+    "out further if necessary to match the data alignment.\n"
     "The start of the bootloader area is always aligned, see also --dataalignment\n"
-    "and --dataalignmentoffset. The bootloader area size may eventually\n"
-    "end up increased due to the alignment, but it's never less than the\n"
-    "size that is requested. To see the bootloader area start and size of\n"
+    "and --dataalignmentoffset. The bootloader area may be larger than requested\n"
+    "due to the alignment, but it's never less than the requested size.\n"
+    "To see the bootloader area start and size of\n"
     "an existing PV use pvs -o +pv_ba_start,pv_ba_size.\n")
 
 arg(cache_long_ARG, '\0', "cache", 0, 0, 0,
@@ -173,14 +175,14 @@ arg(configtype_ARG, '\0', "typeconfig", configtype_VAL, 0, 0,
     "Also see \\fBlvm.conf\\fP(5).\n")
 
 arg(dataalignment_ARG, '\0', "dataalignment", sizekb_VAL, 0, 0,
-    "Align the start of the data to a multiple of this number.\n"
-    "Also specify an appropriate Physical Extent size when creating a VG.\n"
-    "To see the location of the first Physical Extent of an existing PV,\n"
-    "use pvs -o +pe_start. In addition, it may be shifted by an alignment offset.\n"
-    "See lvm.conf/data_alignment_offset_detection and --dataalignmentoffset.\n")
+    "Align the start of a PV data area with a multiple of this number.\n"
+    "To see the location of the first Physical Extent (PE) of an existing PV,\n"
+    "use pvs -o +pe_start. In addition, it may be shifted by an alignment offset,\n"
+    "see --dataalignmentoffset.\n"
+    "Also specify an appropriate PE size when creating a VG.\n")
 
 arg(dataalignmentoffset_ARG, '\0', "dataalignmentoffset", sizekb_VAL, 0, 0,
-    "Shift the start of the data area by this additional offset.\n")
+    "Shift the start of the PV data area by this additional offset.\n")
 
 arg(deduplication_ARG, '\0', "deduplication", bool_VAL, 0, 0,
     "Controls whether deduplication is enabled or disable for VDO volume.\n"
@@ -488,8 +490,7 @@ arg(pvmetadatacopies_ARG, '\0', "pvmetadatacopies", pvmetadatacopies_VAL, 0, 0,
     "The number of metadata areas to set aside on a PV for storing VG metadata.\n"
     "When 2, one copy of the VG metadata is stored at the front of the PV\n"
     "and a second copy is stored at the end.\n"
-    "When 1, one copy of the VG metadata is stored at the front of the PV\n"
-    "(starting in the 5th sector).\n"
+    "When 1, one copy of the VG metadata is stored@the front of the PV.\n"
     "When 0, no copies of the VG metadata are stored on the given PV.\n"
     "This may be useful in VGs containing many PVs (this places limitations\n"
     "on the ability to use vgsplit later.)\n")
tools/toollib.c +4 -1
index 2ab4b62..6c38eb2 100644
@@ -4757,8 +4757,11 @@ int pvcreate_params_from_args(struct cmd_context *cmd, struct pvcreate_params *p
 	}
 
 	pp->pva.pvmetadatasize = arg_uint64_value(cmd, metadatasize_ARG, UINT64_C(0));
-	if (!pp->pva.pvmetadatasize)
+	if (!pp->pva.pvmetadatasize) {
 		pp->pva.pvmetadatasize = find_config_tree_int(cmd, metadata_pvmetadatasize_CFG, NULL);
+		if (!pp->pva.pvmetadatasize)
+			pp->pva.pvmetadatasize = get_default_pvmetadatasize_sectors();
+	}
 
 	pp->pva.pvmetadatacopies = arg_int_value(cmd, pvmetadatacopies_ARG, -1);
 	if (pp->pva.pvmetadatacopies < 0)