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

Fix support for PVs on read only devices. [Still must set LVs read only]

This commit is contained in:
Alasdair Kergon 2003-11-21 19:54:40 +00:00
parent b2bb72641f
commit e19f549a11
6 changed files with 39 additions and 12 deletions

View File

@ -10,6 +10,7 @@
#include "metadata.h"
#include "lvmcache.h"
#include "memlock.h"
#include "locking.h"
#include <limits.h>
#include <sys/stat.h>
@ -326,14 +327,20 @@ int dev_open_flags(struct device *dev, int flags, int direct, int quiet)
int dev_open_quiet(struct device *dev)
{
/* FIXME Open O_RDONLY if vg read lock? */
return dev_open_flags(dev, O_RDWR, 1, 1);
int flags;
flags = vg_write_lock_held() ? O_RDWR : O_RDONLY;
return dev_open_flags(dev, flags, 1, 1);
}
int dev_open(struct device *dev)
{
/* FIXME Open O_RDONLY if vg read lock? */
return dev_open_flags(dev, O_RDWR, 1, 0);
int flags;
flags = vg_write_lock_held() ? O_RDWR : O_RDONLY;
return dev_open_flags(dev, flags, 1, 0);
}
static void _close(struct device *dev)

View File

@ -20,7 +20,8 @@
static struct locking_type _locking;
static sigset_t _oldset;
static int _lock_count = 0; /* Number of locks held */
static int _vg_lock_count = 0; /* Number of locks held */
static int _vg_write_lock_held = 0; /* VG write lock held? */
static int _signals_blocked = 0;
static void _block_signals(int flags)
@ -48,7 +49,7 @@ static void _block_signals(int flags)
static void _unblock_signals(void)
{
/* Don't unblock signals while any locks are held */
if (!_signals_blocked || _lock_count)
if (!_signals_blocked || _vg_lock_count)
return;
if (sigprocmask(SIG_SETMASK, &_oldset, NULL)) {
@ -63,9 +64,10 @@ static void _unblock_signals(void)
void reset_locking(void)
{
int was_locked = _lock_count;
int was_locked = _vg_lock_count;
_lock_count = 0;
_vg_lock_count = 0;
_vg_write_lock_held = 0;
_locking.reset_locking();
@ -73,12 +75,21 @@ void reset_locking(void)
_unblock_signals();
}
static inline void _update_lock_count(int flags)
static inline void _update_vg_lock_count(int flags)
{
if ((flags & LCK_SCOPE_MASK) != LCK_VG)
return;
if ((flags & LCK_TYPE_MASK) == LCK_UNLOCK)
_lock_count--;
_vg_lock_count--;
else
_lock_count++;
_vg_lock_count++;
/* We don't bother to reset this until all VG locks are dropped */
if ((flags & LCK_TYPE_MASK) == LCK_WRITE)
_vg_write_lock_held = 1;
else if (!_vg_lock_count)
_vg_write_lock_held = 0;
}
/*
@ -171,7 +182,7 @@ static int _lock_vol(struct cmd_context *cmd, const char *resource, int flags)
return 0;
}
_update_lock_count(flags);
_update_vg_lock_count(flags);
_unblock_signals();
return 1;
@ -209,3 +220,8 @@ int lock_vol(struct cmd_context *cmd, const char *vol, int flags)
return 1;
}
int vg_write_lock_held(void)
{
return _vg_write_lock_held;
}

View File

@ -12,6 +12,7 @@
int init_locking(int type, struct config_tree *cf);
void fin_locking(void);
void reset_locking(void);
int vg_write_lock_held(void);
/*
* LCK_VG:

View File

@ -176,6 +176,7 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
if (!consistent) {
unlock_vg(cmd, vg_name);
dev_close_all();
log_error("Volume group \"%s\" inconsistent", vg_name);
if (!(vg = recover_vg(cmd, vg_name, LCK_VG_WRITE)))
return ECMD_FAILED;

View File

@ -44,6 +44,7 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
if (!consistent) {
unlock_vg(cmd, vg_name);
dev_close_all();
log_error("Volume group \"%s\" inconsistent", vg_name);
if (!(vg = recover_vg(cmd, vg_name, LCK_VG_WRITE)))
return ECMD_FAILED;

View File

@ -30,6 +30,7 @@ static int vgscan_single(struct cmd_context *cmd, const char *vg_name,
if (!consistent) {
unlock_vg(cmd, vg_name);
dev_close_all();
log_error("Volume group \"%s\" inconsistent", vg_name);
/* Don't allow partial switch to this program */
if (!(vg = recover_vg(cmd, vg_name, LCK_VG_WRITE)))