Version 2.02.177 -
====================================
+ Categorise I/O with reason annotations in debug messages.
Command will lock memory only when suspending volumes.
Merge segments when pvmove is finished.
Remove label_verify that has never been used.
return 0;
}
if (!dev_read_circular(dev, (uint64_t) offset, size,
- (uint64_t) offset2, size2, buf)) {
+ (uint64_t) offset2, size2, DEV_IO_MDA_CONTENT, buf)) {
goto out;
}
fb = buf;
static DM_LIST_INIT(_open_devices);
static unsigned _dev_size_seqno = 1;
+static const char *_reasons[] = {
+ "dev signatures",
+ "PV labels",
+ "VG metadata header",
+ "VG metadata content",
+ "LVM1 metadata",
+ "pool metadata",
+ "LV content",
+ "logging",
+};
+
+static const char *_reason_text(dev_io_reason_t reason)
+{
+ return _reasons[(unsigned) reason];
+}
+
/*-----------------------------------------------------------------
* The standard io loop that keeps submitting an io until it's
* all gone.
*---------------------------------------------------------------*/
-static int _io(struct device_area *where, char *buffer, int should_write)
+static int _io(struct device_area *where, char *buffer, int should_write, dev_io_reason_t reason)
{
int fd = dev_fd(where->dev);
ssize_t n = 0;
return 0;
}
- log_debug_io("%s %s:%8" PRIu64 " bytes (sync) at %" PRIu64 "%s",
+ log_debug_io("%s %s:%8" PRIu64 " bytes (sync) at %" PRIu64 "%s (for %s)",
should_write ? "Write" : "Read ", dev_name(where->dev),
where->size, (uint64_t) where->start,
- (should_write && test_mode()) ? " (test mode - suppressed)" : "");
+ (should_write && test_mode()) ? " (test mode - suppressed)" : "", _reason_text(reason));
/*
* Skip all writes in test mode.
}
static int _aligned_io(struct device_area *where, char *buffer,
- int should_write)
+ int should_write, dev_io_reason_t reason)
{
char *bounce, *bounce_buf;
unsigned int physical_block_size = 0;
mask = block_size - 1;
if (!memcmp(where, &widened, sizeof(widened)) &&
!((uintptr_t) buffer & mask))
- return _io(where, buffer, should_write);
+ return _io(where, buffer, should_write, reason);
- log_debug_io("Widening request for %" PRIu64 " bytes at %" PRIu64 " to %" PRIu64 " bytes at %" PRIu64 " on %s",
- where->size, (uint64_t) where->start, widened.size, (uint64_t) widened.start, dev_name(where->dev));
+ log_debug_io("Widening request for %" PRIu64 " bytes at %" PRIu64 " to %" PRIu64 " bytes at %" PRIu64 " on %s (for %s)",
+ where->size, (uint64_t) where->start, widened.size, (uint64_t) widened.start, dev_name(where->dev), _reason_text(reason));
/* Allocate a bounce buffer with an extra block */
if (!(bounce_buf = bounce = dm_malloc((size_t) widened.size + block_size))) {
bounce = (char *) ((((uintptr_t) bounce) + mask) & ~mask);
/* channel the io through the bounce buffer */
- if (!_io(&widened, bounce, 0)) {
+ if (!_io(&widened, bounce, 0, reason)) {
if (!should_write)
goto_out;
/* FIXME pre-extend the file */
(size_t) where->size);
/* ... then we write */
- if (!(r = _io(&widened, bounce, 1)))
+ if (!(r = _io(&widened, bounce, 1, reason)))
stack;
goto out;
dev->max_error_count, dev_name(dev));
}
-int dev_read(struct device *dev, uint64_t offset, size_t len, void *buffer)
+int dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *buffer)
{
struct device_area where;
int ret;
where.start = offset;
where.size = len;
- // fprintf(stderr, "READ: %s, %lld, %d\n", dev_name(dev), offset, len);
-
- ret = _aligned_io(&where, buffer, 0);
+ ret = _aligned_io(&where, buffer, 0, reason);
if (!ret)
_dev_inc_error_count(dev);
* 'buf' should be len+len2.
*/
int dev_read_circular(struct device *dev, uint64_t offset, size_t len,
- uint64_t offset2, size_t len2, char *buf)
+ uint64_t offset2, size_t len2, dev_io_reason_t reason, char *buf)
{
- if (!dev_read(dev, offset, len, buf)) {
+ if (!dev_read(dev, offset, len, reason, buf)) {
log_error("Read from %s failed", dev_name(dev));
return 0;
}
if (!len2)
return 1;
- if (!dev_read(dev, offset2, len2, buf + len)) {
+ if (!dev_read(dev, offset2, len2, reason, buf + len)) {
log_error("Circular read from %s failed",
dev_name(dev));
return 0;
*/
/* FIXME pre-extend the file */
-int dev_append(struct device *dev, size_t len, char *buffer)
+int dev_append(struct device *dev, size_t len, dev_io_reason_t reason, char *buffer)
{
int r;
if (!dev->open_count)
return_0;
- r = dev_write(dev, dev->end, len, buffer);
+ r = dev_write(dev, dev->end, len, reason, buffer);
dev->end += (uint64_t) len;
#ifndef O_DIRECT_SUPPORT
return r;
}
-int dev_write(struct device *dev, uint64_t offset, size_t len, void *buffer)
+int dev_write(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *buffer)
{
struct device_area where;
int ret;
dev->flags |= DEV_ACCESSED_W;
- ret = _aligned_io(&where, buffer, 1);
+ ret = _aligned_io(&where, buffer, 1, reason);
if (!ret)
_dev_inc_error_count(dev);
return ret;
}
-int dev_set(struct device *dev, uint64_t offset, size_t len, int value)
+int dev_set(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, int value)
{
size_t s;
char buffer[4096] __attribute__((aligned(8)));
memset(buffer, value, sizeof(buffer));
while (1) {
s = len > sizeof(buffer) ? sizeof(buffer) : len;
- if (!dev_write(dev, offset, s, buffer))
+ if (!dev_write(dev, offset, s, reason, buffer))
break;
len -= s;
if (offset_found)
*offset_found = 0;
- if (!dev_read(dev, 0, LUKS_SIGNATURE_SIZE, buf))
+ if (!dev_read(dev, 0, LUKS_SIGNATURE_SIZE, DEV_IO_SIGNATURES, buf))
goto_out;
ret = memcmp(buf, LUKS_SIGNATURE, LUKS_SIGNATURE_SIZE) ? 0 : 1;
uint32_t md_magic;
/* Version 1 is little endian; version 0.90.0 is machine endian */
- if (dev_read(dev, sb_offset, sizeof(uint32_t), &md_magic) &&
+ if (dev_read(dev, sb_offset, sizeof(uint32_t), DEV_IO_SIGNATURES, &md_magic) &&
((md_magic == MD_SB_MAGIC) ||
((MD_SB_MAGIC != xlate32(MD_SB_MAGIC)) && (md_magic == xlate32(MD_SB_MAGIC)))))
return 1;
if (size < (page >> SECTOR_SHIFT))
break;
if (!dev_read(dev, page - SIGNATURE_SIZE,
- SIGNATURE_SIZE, buf)) {
+ SIGNATURE_SIZE, DEV_IO_SIGNATURES, buf)) {
ret = -1;
break;
}
uint16_t magic;
} __attribute__((packed)) buf; /* sizeof() == SECTOR_SIZE */
- if (!dev_read(dev, UINT64_C(0), sizeof(buf), &buf))
+ if (!dev_read(dev, UINT64_C(0), sizeof(buf), DEV_IO_SIGNATURES, &buf))
return_0;
/* FIXME Check for other types of partition table too */
} else
log_verbose(_msg_wiping, type, name);
- if (!dev_set(dev, offset_value, len, 0)) {
+ if (!dev_set(dev, offset_value, len, DEV_IO_SIGNATURES, 0)) {
log_error("Failed to wipe %s signature on %s.", type, name);
return 0;
}
}
log_print_unless_silent("Wiping %s on %s.", type, name);
- if (!dev_set(dev, offset_found, wipe_len, 0)) {
+ if (!dev_set(dev, offset_found, wipe_len, DEV_IO_SIGNATURES, 0)) {
log_error("Failed to wipe %s on %s.", type, name);
return 0;
}
char _padding[7];
};
+/*
+ * All I/O is annotated with the reason it is performed.
+ */
+typedef enum dev_io_reason {
+ DEV_IO_SIGNATURES = 0, /* Scanning device signatures */
+ DEV_IO_LABEL, /* LVM PV disk label */
+ DEV_IO_MDA_HEADER, /* Text format metadata area header */
+ DEV_IO_MDA_CONTENT, /* Text format metadata area content */
+ DEV_IO_FMT1, /* Original LVM1 metadata format */
+ DEV_IO_POOL, /* Pool metadata format */
+ DEV_IO_LV, /* Content written to an LV */
+ DEV_IO_LOG /* Logging messages */
+} dev_io_reason_t;
+
struct device_list {
struct dm_list list;
struct device *dev;
int dev_fd(struct device *dev);
const char *dev_name(const struct device *dev);
-int dev_read(struct device *dev, uint64_t offset, size_t len, void *buffer);
+int dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *buffer);
int dev_read_circular(struct device *dev, uint64_t offset, size_t len,
- uint64_t offset2, size_t len2, char *buf);
-int dev_write(struct device *dev, uint64_t offset, size_t len, void *buffer);
-int dev_append(struct device *dev, size_t len, char *buffer);
-int dev_set(struct device *dev, uint64_t offset, size_t len, int value);
+ uint64_t offset2, size_t len2, dev_io_reason_t reason, char *buf);
+int dev_write(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *buffer);
+int dev_append(struct device *dev, size_t len, dev_io_reason_t reason, char *buffer);
+int dev_set(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, int value);
void dev_flush(struct device *dev);
struct device *dev_create_file(const char *filename, struct device *dev,
static int _read_pvd(struct device *dev, struct pv_disk *pvd)
{
- if (!dev_read(dev, UINT64_C(0), sizeof(*pvd), pvd)) {
+ if (!dev_read(dev, UINT64_C(0), sizeof(*pvd), DEV_IO_FMT1, pvd)) {
log_very_verbose("Failed to read PV data from %s",
dev_name(dev));
return 0;
static int _read_lvd(struct device *dev, uint64_t pos, struct lv_disk *disk)
{
- if (!dev_read(dev, pos, sizeof(*disk), disk))
+ if (!dev_read(dev, pos, sizeof(*disk), DEV_IO_FMT1, disk))
return_0;
_xlate_lvd(disk);
{
uint64_t pos = pvd->vg_on_disk.base;
- if (!dev_read(dev, pos, sizeof(*vgd), vgd))
+ if (!dev_read(dev, pos, sizeof(*vgd), DEV_IO_FMT1, vgd))
return_0;
_xlate_vgd(vgd);
uint64_t end = pos + data->pvd.pv_uuidlist_on_disk.size;
while (pos < end && num_read < data->vgd.pv_cur) {
- if (!dev_read(data->dev, pos, sizeof(buffer), buffer))
+ if (!dev_read(data->dev, pos, sizeof(buffer), DEV_IO_FMT1, buffer))
return_0;
if (!(ul = dm_pool_alloc(data->mem, sizeof(*ul))))
if (!extents)
return_0;
- if (!dev_read(data->dev, pos, len, extents))
+ if (!dev_read(data->dev, pos, len, DEV_IO_FMT1, extents))
return_0;
_xlate_extents(extents, data->pvd.pe_total);
data->pvd.vg_name, dev_name(data->dev), pos, sizeof(*vgd));
_xlate_vgd(vgd);
- if (!dev_write(data->dev, pos, sizeof(*vgd), vgd))
+ if (!dev_write(data->dev, pos, sizeof(*vgd), DEV_IO_FMT1, vgd))
return_0;
_xlate_vgd(vgd);
data->pvd.vg_name, dev_name(data->dev),
pos, NAME_LEN);
- if (!dev_write(data->dev, pos, NAME_LEN, ul->uuid))
+ if (!dev_write(data->dev, pos, NAME_LEN, DEV_IO_FMT1, ul->uuid))
return_0;
pos += NAME_LEN;
pos, sizeof(*disk));
_xlate_lvd(disk);
- if (!dev_write(dev, pos, sizeof(*disk), disk))
+ if (!dev_write(dev, pos, sizeof(*disk), DEV_IO_FMT1, disk))
return_0;
_xlate_lvd(disk);
pos = data->pvd.lv_on_disk.base;
- if (!dev_set(data->dev, pos, data->pvd.lv_on_disk.size, 0)) {
+ if (!dev_set(data->dev, pos, data->pvd.lv_on_disk.size, DEV_IO_FMT1, 0)) {
log_error("Couldn't zero lv area on device '%s'",
dev_name(data->dev));
return 0;
pos, len);
_xlate_extents(extents, data->pvd.pe_total);
- if (!dev_write(data->dev, pos, len, extents))
+ if (!dev_write(data->dev, pos, len, DEV_IO_FMT1, extents))
return_0;
_xlate_extents(extents, data->pvd.pe_total);
pos, size);
_xlate_pvd((struct pv_disk *) buf);
- if (!dev_write(data->dev, pos, size, buf)) {
+ if (!dev_write(data->dev, pos, size, DEV_IO_FMT1, buf)) {
dm_free(buf);
return_0;
}
char buf[512] __attribute__((aligned(8)));
/* FIXME: Need to check the cache here first */
- if (!dev_read(dev, UINT64_C(0), 512, buf)) {
+ if (!dev_read(dev, UINT64_C(0), 512, DEV_IO_POOL, buf)) {
log_very_verbose("Failed to read PV data from %s",
dev_name(dev));
return 0;
return 0;
}
- if (!dev_set(dev, UINT64_C(0), (size_t) 2048, 0)) {
+ if (!dev_set(dev, UINT64_C(0), (size_t) 2048, DEV_IO_LABEL, 0)) {
log_error("%s not wiped: aborting", pv_name);
if (!dev_close(dev))
stack;
if (!(buf = dm_malloc(size + size2)))
goto_out;
- if (!dev_read_circular(area->dev, offset, size,
- offset2, size2, buf))
+ if (!dev_read_circular(area->dev, offset, size, offset2, size2, DEV_IO_MDA_CONTENT, buf))
goto_out;
/*
if (!dev_open_readonly(dev_area->dev))
return_0;
- if (!dev_read(dev_area->dev, dev_area->start, MDA_HEADER_SIZE, mdah)) {
+ if (!dev_read(dev_area->dev, dev_area->start, MDA_HEADER_SIZE, DEV_IO_MDA_HEADER, mdah)) {
if (!dev_close(dev_area->dev))
stack;
return_0;
MDA_HEADER_SIZE -
sizeof(mdah->checksum_xl)));
- if (!dev_write(dev, start_byte, MDA_HEADER_SIZE, mdah))
+ if (!dev_write(dev, start_byte, MDA_HEADER_SIZE, DEV_IO_MDA_HEADER, mdah))
return_0;
return 1;
/* FIXME Loop through rlocns two-at-a-time. List null-terminated. */
/* FIXME Ignore if checksum incorrect!!! */
if (!dev_read(dev_area->dev, dev_area->start + rlocn->offset,
- sizeof(vgnamebuf), vgnamebuf))
+ sizeof(vgnamebuf), DEV_IO_MDA_CONTENT, vgnamebuf))
goto_bad;
if (!strncmp(vgnamebuf, vgname, len = strlen(vgname)) &&
/* Write text out, circularly */
if (!dev_write(mdac->area.dev, mdac->area.start + mdac->rlocn.offset,
- (size_t) (mdac->rlocn.size - new_wrap),
+ (size_t) (mdac->rlocn.size - new_wrap), DEV_IO_MDA_CONTENT,
fidtc->raw_metadata_buf))
goto_out;
dev_name(mdac->area.dev), mdac->area.start +
MDA_HEADER_SIZE, new_wrap);
- if (!dev_write(mdac->area.dev,
- mdac->area.start + MDA_HEADER_SIZE,
- (size_t) new_wrap,
- fidtc->raw_metadata_buf +
- mdac->rlocn.size - new_wrap))
+ if (!dev_write(mdac->area.dev, mdac->area.start + MDA_HEADER_SIZE,
+ (size_t) new_wrap, DEV_IO_MDA_CONTENT,
+ fidtc->raw_metadata_buf + mdac->rlocn.size - new_wrap))
goto_out;
}
/* Do quick check for a vgname */
if (!dev_read(dev_area->dev, dev_area->start + rlocn->offset,
- NAME_LEN, buf))
+ NAME_LEN, DEV_IO_MDA_CONTENT, buf))
return_0;
while (buf[len] && !isspace(buf[len]) && buf[len] != '{' &&
/* Wipe metadata area with zeroes. */
if (!dev_set(pv->dev, mda_start,
- (size_t) ((mda_size > wipe_size) ?
- wipe_size : mda_size), 0)) {
- log_error("Failed to wipe new metadata area "
- "at the %s of the %s",
- mda_index ? "end" : "start",
- pv_dev_name(pv));
- return 0;
+ (size_t) ((mda_size > wipe_size) ? wipe_size : mda_size),
+ DEV_IO_MDA_HEADER, 0)) {
+ log_error("Failed to wipe new metadata area "
+ "at the %s of the %s",
+ mda_index ? "end" : "start",
+ pv_dev_name(pv));
+ return 0;
}
/* Finally, add new metadata area to PV's format instance. */
char readbuf[LABEL_SCAN_SIZE] __attribute__((aligned(8)));
if (!dev_read(dev, scan_sector << SECTOR_SHIFT,
- LABEL_SCAN_SIZE, readbuf)) {
+ LABEL_SCAN_SIZE, DEV_IO_LABEL, readbuf)) {
log_debug_devs("%s: Failed to read label area", dev_name(dev));
goto out;
}
*/
dev_flush(dev);
- if (!dev_read(dev, UINT64_C(0), LABEL_SCAN_SIZE, readbuf)) {
+ if (!dev_read(dev, UINT64_C(0), LABEL_SCAN_SIZE, DEV_IO_LABEL, readbuf)) {
log_debug_devs("%s: Failed to read label area", dev_name(dev));
goto out;
}
if (wipe) {
log_very_verbose("%s: Wiping label at sector %" PRIu64,
dev_name(dev), sector);
- if (dev_write(dev, sector << SECTOR_SHIFT, LABEL_SIZE,
+ if (dev_write(dev, sector << SECTOR_SHIFT, LABEL_SIZE, DEV_IO_LABEL,
buf)) {
/* Also remove the PV record from cache. */
info = lvmcache_info_from_pvid(dev->pvid, dev, 0);
log_very_verbose("%s: Writing label to sector %" PRIu64 " with stored offset %"
PRIu32 ".", dev_name(dev), label->sector,
xlate32(lh->offset_xl));
- if (!dev_write(dev, label->sector << SECTOR_SHIFT, LABEL_SIZE, buf)) {
+ if (!dev_write(dev, label->sector << SECTOR_SHIFT, LABEL_SIZE, DEV_IO_LABEL, buf)) {
log_debug_devs("Failed to write label to %s", dev_name(dev));
r = 0;
}
return 0;
}
- if (!dev_set(dev, old_size_bytes, new_size_bytes - old_size_bytes, 0)) {
+ if (!dev_set(dev, old_size_bytes, new_size_bytes - old_size_bytes, DEV_IO_LV, 0)) {
log_error("Extend sanlock LV %s cannot zero device.", display_lvname(lv));
dev_close_immediate(dev);
return 0;
buf[bufused] = '\n';
buf[sizeof(buf) - 1] = '\n';
/* FIXME real size bufused */
- dev_append(&_log_dev, sizeof(buf), buf);
+ dev_append(&_log_dev, sizeof(buf), DEV_IO_LOG, buf);
_already_logging = 0;
}
}
display_size(lv->vg->cmd, zero_sectors),
lv->vg->name, lv->name, wp.zero_value);
- if (!dev_set(dev, UINT64_C(0), (size_t) zero_sectors << SECTOR_SHIFT, wp.zero_value))
+ if (!dev_set(dev, UINT64_C(0), (size_t) zero_sectors << SECTOR_SHIFT, DEV_IO_LV, wp.zero_value))
stack;
}
return 0;
}
- if (!dev_set(dev, UINT64_C(0), (size_t) 2048, 0)) {
+ if (!dev_set(dev, UINT64_C(0), (size_t) 2048, DEV_IO_LABEL, 0)) {
log_error("%s not wiped: aborting", pv_name);
if (!dev_close(dev))
stack;
return 0;
}
- if (!dev_set(dev, UINT64_C(0), (size_t) 2048, 0)) {
+ if (!dev_set(dev, UINT64_C(0), (size_t) 2048, DEV_IO_LABEL, 0)) {
log_error("%s not wiped: aborting", pv_name);
if (!dev_close(dev))
stack;
if (!dev_open_quiet(dev))
return 0;
- if (!dev_write(dev, UINT64_C(0), sizeof(log_header), &log_header)) {
+ if (!dev_write(dev, UINT64_C(0), sizeof(log_header), DEV_IO_LV, &log_header)) {
log_error("Failed to write log header to %s.", name);
dev_close_immediate(dev);
return 0;
continue;
}
- if (!dev_set(pv->dev, UINT64_C(0), (size_t) 2048, 0)) {
+ if (!dev_set(pv->dev, UINT64_C(0), (size_t) 2048, DEV_IO_LABEL, 0)) {
log_error("%s not wiped: aborting.", pv_name);
if (!dev_close(pv->dev))
stack;