1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Add random suffix to archive file names to prevent races when being created.

In certain configurations, we're not under a VG rw lock while trying to write
a new archive file with VG metadata. A common example is using "vgs" while
having the content of backup and archive directories empty. The code scans the
content of these directories and tries to determine the final index that should
be used in archive name. Since we're not under a lock, we can get into a race
while choosing the index which could end up showing errors about not being able
to rename to final archive name. Let's add random number suffix to these archive
file names so we can avoid the race.
This commit is contained in:
Peter Rajnoha 2010-09-09 13:13:12 +00:00
parent dc8478458e
commit d20ce59b80
2 changed files with 6 additions and 2 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.74 -
==================================
Add random suffix to archive file names to prevent races when being created.
Reinitialize archive and backup handling on toolcontext refresh.
Fix opprobriously slow I/O to cluster mirrors created with --nosync.
Make poll_mirror_progress report PROGRESS_CHECK_FAILED if LV is not a mirror.

View File

@ -226,7 +226,7 @@ int archive_vg(struct volume_group *vg,
const char *dir, const char *desc,
uint32_t retain_days, uint32_t min_archive)
{
int i, fd, renamed = 0;
int i, fd, rnum, renamed = 0;
uint32_t ix = 0;
struct archive_file *last;
FILE *fp = NULL;
@ -271,9 +271,12 @@ int archive_vg(struct volume_group *vg,
ix = last->index + 1;
}
rnum = rand_r(&vg->cmd->rand_seed);
for (i = 0; i < 10; i++) {
if (dm_snprintf(archive_name, sizeof(archive_name),
"%s/%s_%05u.vg", dir, vg->name, ix) < 0) {
"%s/%s_%05u-%d.vg",
dir, vg->name, ix, rnum) < 0) {
log_error("Archive file name too long.");
return 0;
}