mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-22 17:35:59 +03:00
lvmcache: add lock_type to VG summary and info structs
vgsummary information contains provisional VG information that is obtained without holding the VG lock. This info can be used to lock the VG, and then read it with vg_read(). After the VG is read properly, the vgsummary info should be verified. Add the VG lock_type to the vgsummary. It needs to be known before the VG can be locked and read.
This commit is contained in:
parent
3cd644aeb5
commit
e593213b87
30
lib/cache/lvmcache.c
vendored
30
lib/cache/lvmcache.c
vendored
@ -56,6 +56,7 @@ struct lvmcache_vginfo {
|
|||||||
char _padding[7];
|
char _padding[7];
|
||||||
struct lvmcache_vginfo *next; /* Another VG with same name? */
|
struct lvmcache_vginfo *next; /* Another VG with same name? */
|
||||||
char *creation_host;
|
char *creation_host;
|
||||||
|
char *lock_type;
|
||||||
uint32_t mda_checksum;
|
uint32_t mda_checksum;
|
||||||
size_t mda_size;
|
size_t mda_size;
|
||||||
size_t vgmetadata_size;
|
size_t vgmetadata_size;
|
||||||
@ -1447,7 +1448,7 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int _lvmcache_update_vgstatus(struct lvmcache_info *info, uint32_t vgstatus,
|
static int _lvmcache_update_vgstatus(struct lvmcache_info *info, uint32_t vgstatus,
|
||||||
const char *creation_host)
|
const char *creation_host, const char *lock_type)
|
||||||
{
|
{
|
||||||
if (!info || !info->vginfo)
|
if (!info || !info->vginfo)
|
||||||
return 1;
|
return 1;
|
||||||
@ -1460,11 +1461,11 @@ static int _lvmcache_update_vgstatus(struct lvmcache_info *info, uint32_t vgstat
|
|||||||
info->vginfo->status = vgstatus;
|
info->vginfo->status = vgstatus;
|
||||||
|
|
||||||
if (!creation_host)
|
if (!creation_host)
|
||||||
return 1;
|
goto set_lock_type;
|
||||||
|
|
||||||
if (info->vginfo->creation_host && !strcmp(creation_host,
|
if (info->vginfo->creation_host && !strcmp(creation_host,
|
||||||
info->vginfo->creation_host))
|
info->vginfo->creation_host))
|
||||||
return 1;
|
goto set_lock_type;
|
||||||
|
|
||||||
if (info->vginfo->creation_host)
|
if (info->vginfo->creation_host)
|
||||||
dm_free(info->vginfo->creation_host);
|
dm_free(info->vginfo->creation_host);
|
||||||
@ -1478,6 +1479,24 @@ static int _lvmcache_update_vgstatus(struct lvmcache_info *info, uint32_t vgstat
|
|||||||
log_debug_cache("lvmcache: %s: VG %s: Set creation host to %s.",
|
log_debug_cache("lvmcache: %s: VG %s: Set creation host to %s.",
|
||||||
dev_name(info->dev), info->vginfo->vgname, creation_host);
|
dev_name(info->dev), info->vginfo->vgname, creation_host);
|
||||||
|
|
||||||
|
set_lock_type:
|
||||||
|
|
||||||
|
if (!lock_type)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (info->vginfo->lock_type && !strcmp(lock_type, info->vginfo->lock_type))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (info->vginfo->lock_type)
|
||||||
|
dm_free(info->vginfo->lock_type);
|
||||||
|
|
||||||
|
if (!(info->vginfo->lock_type = dm_strdup(lock_type))) {
|
||||||
|
log_error("cache creation host alloc failed for %s",
|
||||||
|
lock_type);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1546,7 +1565,7 @@ int lvmcache_update_vgname_and_id(struct lvmcache_info *info, struct lvmcache_vg
|
|||||||
if (!_lvmcache_update_vgname(info, vgname, vgid, vgsummary->vgstatus,
|
if (!_lvmcache_update_vgname(info, vgname, vgid, vgsummary->vgstatus,
|
||||||
vgsummary->creation_host, info->fmt) ||
|
vgsummary->creation_host, info->fmt) ||
|
||||||
!_lvmcache_update_vgid(info, info->vginfo, vgid) ||
|
!_lvmcache_update_vgid(info, info->vginfo, vgid) ||
|
||||||
!_lvmcache_update_vgstatus(info, vgsummary->vgstatus, vgsummary->creation_host) ||
|
!_lvmcache_update_vgstatus(info, vgsummary->vgstatus, vgsummary->creation_host, vgsummary->lock_type) ||
|
||||||
!_lvmcache_update_vg_mda_info(info, vgsummary->mda_checksum, vgsummary->mda_size))
|
!_lvmcache_update_vg_mda_info(info, vgsummary->mda_checksum, vgsummary->mda_size))
|
||||||
return_0;
|
return_0;
|
||||||
|
|
||||||
@ -1561,7 +1580,8 @@ int lvmcache_update_vg(struct volume_group *vg, unsigned precommitted)
|
|||||||
struct lvmcache_vgsummary vgsummary = {
|
struct lvmcache_vgsummary vgsummary = {
|
||||||
.vgname = vg->name,
|
.vgname = vg->name,
|
||||||
.vgstatus = vg->status,
|
.vgstatus = vg->status,
|
||||||
.vgid = vg->id
|
.vgid = vg->id,
|
||||||
|
.lock_type = vg->lock_type
|
||||||
};
|
};
|
||||||
|
|
||||||
pvid_s[sizeof(pvid_s) - 1] = '\0';
|
pvid_s[sizeof(pvid_s) - 1] = '\0';
|
||||||
|
12
lib/cache/lvmcache.h
vendored
12
lib/cache/lvmcache.h
vendored
@ -39,11 +39,23 @@ struct disk_locn;
|
|||||||
|
|
||||||
struct lvmcache_vginfo;
|
struct lvmcache_vginfo;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vgsummary represents a summary of the VG that is read
|
||||||
|
* without a lock. The info does not come through vg_read(),
|
||||||
|
* but through reading mdas. It provides information about
|
||||||
|
* the VG that is needed to lock the VG and then read it fully
|
||||||
|
* with vg_read(), after which the VG summary should be checked
|
||||||
|
* against the full VG metadata to verify it was correct (since
|
||||||
|
* it was read without a lock.)
|
||||||
|
*
|
||||||
|
* Once read, vgsummary information is saved in lvmcache_vginfo.
|
||||||
|
*/
|
||||||
struct lvmcache_vgsummary {
|
struct lvmcache_vgsummary {
|
||||||
const char *vgname;
|
const char *vgname;
|
||||||
struct id vgid;
|
struct id vgid;
|
||||||
uint64_t vgstatus;
|
uint64_t vgstatus;
|
||||||
char *creation_host;
|
char *creation_host;
|
||||||
|
const char *lock_type;
|
||||||
uint32_t mda_checksum;
|
uint32_t mda_checksum;
|
||||||
size_t mda_size;
|
size_t mda_size;
|
||||||
};
|
};
|
||||||
|
@ -1031,6 +1031,11 @@ static void _read_desc(struct dm_pool *mem,
|
|||||||
*when = u;
|
*when = u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* It would be more accurate to call this _read_vgsummary().
|
||||||
|
* It is used to read vgsummary information about a VG
|
||||||
|
* before locking and reading the VG via vg_read().
|
||||||
|
*/
|
||||||
static int _read_vgname(const struct format_type *fmt, const struct dm_config_tree *cft,
|
static int _read_vgname(const struct format_type *fmt, const struct dm_config_tree *cft,
|
||||||
struct lvmcache_vgsummary *vgsummary)
|
struct lvmcache_vgsummary *vgsummary)
|
||||||
{
|
{
|
||||||
@ -1067,6 +1072,8 @@ static int _read_vgname(const struct format_type *fmt, const struct dm_config_tr
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dm_config_get_str(vgn, "lock_type", &vgsummary->lock_type);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user