remove device scan from _text_create_text_instance
RFC PATCH 1/7 remove device scan from _text_create_text_instance
In reply to a message not in the archiveUsually the _text_create_text_instance function is called after device scan is done, and as far as I understand, lvmcache_label_scan in the _text_create_text_instance is not necessarily needed.
--- lib/format_text/format-text.c | 2 -- 1 file changed, 2 deletions(-)
lib/format_text/format-text.c +0 -2
@@ -1792,8 +1792,6 @@ static struct format_instance *_text_credm_list_add (&fid->metadata_areas, &mda->list); } -/* Scan PVs in VG for any further MDAs */ -lvmcache_label_scan (fmt->cmd,0 );if (!(vginfo =vginfo_from_vgname (vgname, vgid))) goto_out; dm_list_iterate_items(info, &vginfo->infos) {
RFC PATCH 2/7 rename _has_scanned to _need_scan
In reply to a message not in the archiveWhen metadata cache is loaded into lvmcache, no device scan is necessary, but it does not mean "has scanned". To tell lvmcache not to scan devices, the variable name, _has_scanned, is renamed to _need_scan and its logic is reversed.
--- lib/cache/lvmcache.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
lib/cache/lvmcache.c +4 -4
@@ -32,7 +32,7 @@ static struct dm_hash_table *_vgname_hasstatic struct dm_hash_table *_lock_hash =NULL ;static struct dm_list _vginfos;static int _scanning_in_progress =0 ; -static int _has_scanned =0 ; +static int _need_scan =1 ;static int _vgs_locked =0 ;static int _vg_global_lock_held =0 ;/* Global lock held when cache wiped? */
@@ -455,7 +455,7 @@ int lvmcache_label_scan(struct cmd_conte goto out; } -if (_has_scanned && !full_scan) { +if (!_need_scan && !full_scan) { r =_scan_invalid (); goto out; }
@@ -470,7 +470,7 @@ int lvmcache_label_scan(struct cmd_contedev_iter_destroy (iter); - _has_scanned =1 ; + _need_scan =0 ;/* Perform any format-specific scanning e.g. text files */ dm_list_iterate_items(fmt, &cmd->formats) {
@@ -1239,7 +1239,7 @@ void lvmcache_destroy(struct cmd_contextstruct dm_hash_node *n;log_verbose ("Wiping internal VG cache" ); - _has_scanned =0 ; + _need_scan =1 ;if (_vgid_hash) {dm_hash_destroy (_vgid_hash);
RFC PATCH 3/7 separate metadata parse and verification
In reply to a message not in the archiveThis patch separates parse and verification process in _reav_pv function. Instead of getting device data by accessing and checking devices, the DEV_NEED_VERIFY flag is set to the device structures so that they will be verified later.
--- lib/cache/lvmcache.c | 5 +++-- lib/device/dev-cache.c | 12 ++++++++++++ lib/device/dev-cache.h | 1 + lib/device/device.h | 2 ++ lib/format_text/format-text.c | 37 ++++++++++++++++++++++++++++++++----- lib/format_text/format-text.h | 2 ++ lib/format_text/import_vsn1.c | 40 ++++++++++++++++++++++++++++------------ lib/label/label.c | 9 +++++++++ 8 files changed, 89 insertions(+), 19 deletions(-)
lib/cache/lvmcache.c +3 -2
@@ -525,6 +525,8 @@ struct volume_group *lvmcache_get_vg(con return_NULL; } +verify_pv_status (fid, vg); +log_debug ("Using cached %smetadata for VG %s." , vginfo->precommitted ?"pre-committed" :"" , vginfo->vgname);
@@ -705,7 +707,6 @@ static int _drop_vginfo(struct lvmcache_return 1 ; } -/* Unused void lvmcache_del (struct lvmcache_info *info) {if (info->dev->pvid[0 ] && _pvid_hash)
@@ -718,7 +719,7 @@ void lvmcache_del(struct lvmcache_info *dm_free (info);return ; -} */ +}static int _lvmcache_update_pvid (struct lvmcache_info *info,const char *pvid) {
lib/device/dev-cache.c +12 -0
@@ -779,3 +779,15 @@ const char *dev_name(const struct device return (dev) ? dm_list_item(dev->aliases.n, struct str_list)->str :"unknown device" ; } + +int dev_is_valid (struct device *dev,struct dev_filter *f) +{ +if (dev->flags &DEV_NEED_VERIFY ) { + dev->flags &= ~DEV_NEED_VERIFY ; + +if (!f->passes_filter (f, dev)) +return 0 ; + } + +return 1 ; +}
lib/device/dev-cache.h +1 -0
@@ -51,5 +51,6 @@ struct dev_iter;struct dev_iter *dev_iter_create (struct dev_filter *f,int dev_scan);void dev_iter_destroy (struct dev_iter *iter);struct device *dev_iter_get (struct dev_iter *iter); +int dev_is_valid (struct device *dev,struct dev_filter *f);#endif
lib/device/device.h +2 -0
@@ -28,6 +28,8 @@#define DEV_O_DIRECT 0x00000020/* Use O_DIRECT */ #define DEV_O_DIRECT_TESTED 0x00000040/* DEV_O_DIRECT is reliable */ +#define DEV_NEED_VERIFY 0x10000000/* Should be verified */ +/* * All devices in LVM will be represented by one of these. * pointer comparisons are valid.
lib/format_text/format-text.c +32 -5
@@ -439,6 +439,27 @@ static int _raw_holds_vgname(struct formreturn r; } +void verify_pv_status (struct format_instance *fid,struct volume_group *vg) +{ +struct pv_list *pvl; + char buffer[64] __attribute((aligned(8))); + + dm_list_iterate_items(pvl, &vg->pvs) { +if (!dev_is_valid (pvl->pv->dev, vg->cmd->filter) || + !(pvl->pv->dev =device_from_pvid (fid->fmt->cmd, + &pvl->pv->id))) { +if (!id_write_format (&pvl->pv->id, buffer, +sizeof (buffer))) +log_error ("Couldn't find device." ); +else +log_error ("Couldn't find device with uuid" +" '%s'." , buffer); + + pvl->pv->status |=MISSING_PV ; + } + } +} + static struct volume_group *_vg_read_raw_area(struct format_instance *fid, const char *vgname, struct device_area *area,
@@ -487,6 +508,8 @@ static struct volume_group *_vg_read_rawif (precommitted) vg->status |=PRECOMMITTED ; +verify_pv_status (fid, vg); + out:if (!dev_close (area->dev)) stack;
@@ -783,7 +806,8 @@ static int _vg_remove_raw(struct format_static struct volume_group *_vg_read_file_name (struct format_instance *fid,const char *vgname, -const char *read_path) +const char *read_path, +int verify_pv) {struct volume_group *vg;time_t when;
@@ -805,6 +829,9 @@ static struct volume_group *_vg_read_fil }else log_debug ("Read volume group %s from %s" , vg->name, read_path); +if (verify_pv) +verify_pv_status (fid, vg); +return vg; }
@@ -814,7 +841,7 @@ static struct volume_group *_vg_read_fil {struct text_context *tc = (struct text_context *) mda->metadata_locn; -return _vg_read_file_name (fid, vgname, tc->path_live); +return _vg_read_file_name (fid, vgname, tc->path_live,1 ); } static struct volume_group *_vg_read_precommit_file(struct format_instance *fid,
@@ -824,10 +851,10 @@ static struct volume_group *_vg_read_prestruct text_context *tc = (struct text_context *) mda->metadata_locn;struct volume_group *vg; -if ((vg =_vg_read_file_name (fid, vgname, tc->path_edit))) +if ((vg =_vg_read_file_name (fid, vgname, tc->path_edit,1 ))) vg->status |=PRECOMMITTED ;else - vg =_vg_read_file_name (fid, vgname, tc->path_live); + vg =_vg_read_file_name (fid, vgname, tc->path_live,1 );return vg; }
@@ -1023,7 +1050,7 @@ static int _scan_file(const struct forma fid =_text_create_text_instance (fmt,NULL ,NULL ,NULL );if ((vg =_vg_read_file_name (fid, vgname, - path))) + path,1 )))/* FIXME Store creation host in vg */ lvmcache_update_vg (vg,0 ); }
lib/format_text/format-text.h +2 -0
@@ -47,6 +47,8 @@ struct format_type *create_text_format(svoid *create_text_context (struct cmd_context *cmd,const char *path,const char *desc); +void verify_pv_status (struct format_instance *fid,struct volume_group *vg); +struct labeller *text_labeller_create (const struct format_type *fmt);int pvhdr_read (struct device *dev,char *buf);
lib/format_text/import_vsn1.c +28 -12
@@ -150,6 +150,32 @@ static int _read_flag_config(struct confreturn 1 ; } +static int _read_device (struct cmd_context *cmd,struct device **dev, +struct config_node *cn,const char *path) +{ +struct config_value *cv; + +if (!(cn =find_config_node (cn, path))) { +log_error ("Couldn't find device." ); +return 0 ; + } + + cv = cn->v; +if (!cv || cv->type !=CFG_STRING || !cv->v.str) { +log_error ("device must be a string." ); +return 0 ; + } + +/* dev_cache_get function causes disk access if partition +information is not cached on memory */ +if (!(*dev =dev_cache_get (cv->v.str,NULL ))) +return 0 ; + + (*dev)->flags |=DEV_NEED_VERIFY ; + +return 1 ; +} + static int _read_pv(struct format_instance *fid, struct dm_pool *mem, struct volume_group *vg, struct config_node *pvn, struct config_node *vgn __attribute((unused)),
@@ -183,18 +209,8 @@ static int _read_pv(struct format_instanreturn 0 ; } -/* -* Convert the uuid into a device. -*/ -if (!(pv->dev =device_from_pvid (fid->fmt->cmd, &pv->id))) { - char buffer[64] __attribute((aligned(8))); - -if (!id_write_format (&pv->id, buffer,sizeof (buffer))) -log_error ("Couldn't find device." ); -else -log_error ("Couldn't find device with uuid '%s'." , - buffer); - } +if (!_read_device (fid->fmt->cmd, &pv->dev, pvn,"device" )) +log_error ("Couldn't get device for physical volume." );if (!(pv->vg_name =dm_pool_strdup (mem, vg->name))) return_0;
lib/label/label.c +9 -0
@@ -19,6 +19,8 @@#include "xlate.h" #include "lvmcache.h" #include "metadata.h" +#include "toolcontext.h" +#include "dev-cache.h" #include <sys/stat.h> #include <fcntl.h>
@@ -283,6 +285,13 @@ int label_read(struct device *dev, strucreturn r; } +if ((info =info_from_pvid (dev->pvid,0 ))) { +if (!dev_is_valid (info->dev, info->fmt->cmd->filter)) { +lvmcache_del (info); + goto out; + } + } +if (!(l =_find_labeller (dev, buf, §or, scan_sector))) goto out;
RFC PATCH 4/7 support metadata cache feature
In reply to a message not in the archiveMetadata cache files are read from the specified directory, and their information are registered into lvmcache. The CACHE_INVALID flag is set to the caches so that they will be reloaded from actual devices when they are really processed.
This prototype uses metadata backup files in the backup directory as cache files. But the own cache directory will be used in the future version.
--- lib/cache/lvmcache.c | 5 +++ lib/cache/lvmcache.h | 2 + lib/commands/toolcontext.c | 1 lib/commands/toolcontext.h | 3 ++ lib/format_text/archiver.c | 50 +++++++++++++++++++++++++++++++++ lib/format_text/archiver.h | 5 +++ lib/format_text/format-text.c | 63 ++++++++++++++++++++++++++++++++++++++++++ lib/metadata/metadata.h | 5 +++ 8 files changed, 134 insertions(+)
lib/cache/lvmcache.c +5 -0
@@ -1274,3 +1274,8 @@ void lvmcache_destroy(struct cmd_contextif (retain_orphans)init_lvmcache_orphans (cmd); } + +void lvmcache_reset_need_scan (void ) +{ + _need_scan =0 ; +}
lib/cache/lvmcache.h +2 -0
@@ -112,4 +112,6 @@ struct dm_list *lvmcache_get_pvids(strucstruct volume_group *lvmcache_get_vg (const char *vgid,unsigned precommitted);void lvmcache_drop_metadata (const char *vgname); +void lvmcache_reset_need_scan (void ); +#endif
lib/commands/toolcontext.c +1 -0
@@ -776,6 +776,7 @@ static int _init_formats(struct cmd_contdm_list_add (&cmd->formats, &fmt->list); cmd->fmt_backup = fmt; + cmd->fmt_mcache = fmt; format =find_config_tree_str (cmd,"global/format" ,DEFAULT_FORMAT );
lib/commands/toolcontext.h +3 -0
@@ -33,6 +33,7 @@ struct config_info {int suffix;int archive;/* should we archive ? */ int backup;/* should we backup ? */ +int mcache;/* should we enable metadata cache ? */ int read_ahead;/* DM_READ_AHEAD_NONE or _AUTO */ int cache_vgmetadata;const char *msg_prefix;
@@ -56,6 +57,7 @@ struct cmd_context {const struct format_type *fmt;/* Current format to use by default */ struct format_type *fmt_backup;/* Format to use for backups */ +struct format_type *fmt_mcache;/* Format to use for metadata cache */ struct dm_list formats;/* Available formats */ struct dm_list segtypes;/* Available segment types */
@@ -82,6 +84,7 @@ struct cmd_context {struct archive_params *archive_params;struct backup_params *backup_params; +struct mcache_params *mcache_params;const char *stripe_filler;/* List of defined tags */
lib/format_text/archiver.c +50 -0
59 lines not on this page · raw message
lib/format_text/archiver.h +5 -0
@@ -59,4 +59,9 @@ int backup_to_file(const char *file, convoid check_current_backup (struct volume_group *vg); +int mcache_init (struct cmd_context *cmd,const char *dir,int enabled); +void mcache_exit (struct cmd_context *cmd); +void mcache_enable (struct cmd_context *cmd,int flag); +void mcache_load (struct cmd_context *cmd); +#endif
lib/format_text/format-text.c +63 -0
75 lines not on this page · raw message
lib/metadata/metadata.h +5 -0
@@ -198,6 +198,11 @@ struct format_handler {int (*scan) (const struct format_type * fmt);/* +* Load and setup metadata cache files +*/ +int (*scan_mcache) (const struct format_type *fmt,const char *dir); + +/* * Return PV with given path. */ int (*pv_read) (const struct format_type * fmt, const char *pv_name,
RFC PATCH 5/7 add metadata cache interface
In reply to a message not in the archiveMetadata cache is loaded into lvmcache if the lvm configuration parameter, "backup/metadata_cache" has a value of "1" and MCACHE_DISABLE flag is not set in its lvm command context.
--- lib/commands/toolcontext.c | 14 ++++++++++++++ lib/config/defaults.h | 1 + tools/lvmcmdline.c | 4 ++++ tools/tools.h | 3 ++- 4 files changed, 21 insertions(+), 1 deletion(-)
lib/commands/toolcontext.c +14 -0
@@ -929,6 +929,7 @@ static int _init_backup(struct cmd_contelog_warn ("WARNING: Metadata changes will NOT be backed up" );backup_init (cmd,"" ,0 );archive_init (cmd,"" ,0 ,0 ,0 ); +mcache_init (cmd,"" ,0 );return 1 ; }
@@ -980,6 +981,19 @@ static int _init_backup(struct cmd_contereturn 0 ; } +/* set up the metadata cache */ + cmd->default_settings.mcache = +find_config_tree_bool (cmd,"backup/metadata_cache" , +DEFAULT_MCACHE_ENABLED ); + +/* TODO: Currently mcache uses the same directory as backup, but +* mcache should be put in its own directory, ex) /etc/lvm/mcache. +*/ +if (!mcache_init (cmd, dir, cmd->default_settings.mcache)) { +log_debug ("mcache_init failed." ); +return 0 ; + } +return 1 ; }
lib/config/defaults.h +1 -0
@@ -18,6 +18,7 @@#define DEFAULT_ARCHIVE_ENABLED 1#define DEFAULT_BACKUP_ENABLED 1 +#define DEFAULT_MCACHE_ENABLED 0#define DEFAULT_ARCHIVE_SUBDIR "archive"#define DEFAULT_BACKUP_SUBDIR "backup"
tools/lvmcmdline.c +4 -0
@@ -777,6 +777,7 @@ static int _get_settings(struct cmd_cont cmd->current_settings.archive =arg_int_value (cmd, autobackup_ARG, cmd->current_settings.archive); cmd->current_settings.backup =arg_int_value (cmd, autobackup_ARG, cmd->current_settings.backup); + cmd->current_settings.mcache &= cmd->command->flags &MCACHE_DISABLE ?0 :1 ; cmd->current_settings.cache_vgmetadata = cmd->command->flags &CACHE_VGMETADATA ?1 :0 ; cmd->partial_activation =0 ;
@@ -892,6 +893,7 @@ static void _apply_settings(struct cmd_carchive_enable (cmd, cmd->current_settings.archive);backup_enable (cmd, cmd->current_settings.backup); +mcache_enable (cmd, cmd->current_settings.mcache);set_activation (cmd->current_settings.activation);
@@ -1004,6 +1006,8 @@ int lvm_run_command(struct cmd_context * goto out; } +mcache_load (cmd); + ret = cmd->command->fn (cmd, argc, argv);fin_locking ();
tools/tools.h +2 -1
@@ -116,7 +116,8 @@ struct arg {void *ptr; }; -#define CACHE_VGMETADATA 0x00000001 +#define CACHE_VGMETADATA 0x00000001 +#define MCACHE_DISABLE 0x00000002/* a register of the lvm commands */ struct command {
RFC PATCH 6/7 individual lvm command settings
In reply to a message not in the archiveSeveral lvm commands should not work based on metadata cache data. They need to scan real metadata on devices. lvm commands with MCACHE_DISABLE flag do not use metadata cache.
Currently the metadata cache feature is disabled in the following commands.
* scan commands: vgscan and lvscan
pvscan destroys lvmcache before its procedure, and MCACHE_DISABLE flag is not needed.
* physical volume commands: pvdisplay, pvs
Metadata cache files contain physical volume data which belong to a volume group, and orphan physical volumes can not be handled. To support these volumes, a kind of orphan physical volume cache need to be introduced.
As a next step, I'm planning to set MCACHE_CLEANUP flag to vgscan command to refresh all metadata cache files in the cache directory.
--- tools/commands.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/commands.h +4 -4
@@ -390,7 +390,7 @@ xx(lvs,xx (lvscan,"List all logical volumes in all volume groups" , -0 , +MCACHE_DISABLE ,"lvscan " "\n" "\t[-a|--all]\n" "\t[-b|--blockdevice] " "\n"
@@ -497,7 +497,7 @@ xx(pvdata,xx (pvdisplay,"Display various attributes of physical volume(s)" , -0 , +MCACHE_DISABLE ,"pvdisplay\n" "\t[-c|--colon]\n" "\t[-d|--debug]\n"
@@ -571,7 +571,7 @@ xx(pvremove,xx (pvs,"Display information about physical volumes" , -0 , +MCACHE_DISABLE ,"pvs" "\n" "\t[--aligned]\n" "\t[-a|--all]\n"
@@ -925,7 +925,7 @@ xx(vgs,xx (vgscan,"Search for all volume groups" , -0 , +MCACHE_DISABLE ,"vgscan " "\t[-d|--debug]\n" "\t[-h|--help]\n"
RFC PATCH 7/7 introduce metadata cache feature
In reply to a message not in the archiveAdd backup/metadata_cache parameter to enable the metadata cache feature. Another new parameter, metadata_cache_dir will be added in the future version to indicate metadata cache directory.
--- doc/example.conf | 6 ++++++ 1 file changed, 6 insertions(+)
doc/example.conf +6 -0
@@ -187,6 +187,12 @@ backup { # What is the minimum time you wish to keep an archive file for ? retain_days = 30 + + # Use metadata cache to get lvm structures in the system instead of + # scanning all devices every time. If any errors are detected, lvm + # commands fall back to not use metadata cache. + # 1 enables; 0 disables. + # metadata_cache = 0 } # Settings for the running LVM2 in shell (readline) mode.