master - device: Move buffer allocation nearer to the I/O.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=c26458339ee3b3bdd0e...
Commit: c26458339ee3b3bdd0e49127e887c0417cbc1438
Parent: 081902b4c115c465b123c13e9d8287a75f9d7b2a
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Tue Jan 16 01:12:08 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Tue Jan 16 01:12:08 2018 +0000
device: Move buffer allocation nearer to the I/O.
Don't allocate memory until it's needed - later we'll add
some of the I/O to an internal queue instead of issuing it
immediately.
---
lib/device/dev-io.c | 19 ++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index d995452..2150b0d 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -153,6 +153,13 @@ static int _io(struct device_buffer *devbuf)
return 0;
}
+#ifndef DEBUG_MEM
+ if (!devbuf->buf && !(devbuf->malloc_address = devbuf->buf = dm_malloc_aligned((size_t) devbuf->where.size, 0))) {
+ log_error("Bounce buffer malloc failed");
+ return 0;
+ }
+#endif
+
log_debug_io("%s %s(fd %d):%8" PRIu64 " bytes (sync) at %" PRIu64 "%s (for %s)",
devbuf->write ? "Write" : "Read ", dev_name(where->dev), fd,
where->size, (uint64_t) where->start,
@@ -305,17 +312,15 @@ static int _aligned_io(struct device_area *where, char *write_buffer,
/* Store location of requested data relative to start of buf */
devbuf->data_offset = where->start - devbuf->where.start;
- if (should_write && !buffer_was_widened && !((uintptr_t) write_buffer & mask)) {
+ if (should_write && !buffer_was_widened && !((uintptr_t) write_buffer & mask))
/* Perform the I/O directly. */
devbuf->buf = write_buffer;
- devbuf->malloc_address = NULL;
+ else
#ifndef DEBUG_MEM
- } else if (!(devbuf->malloc_address = devbuf->buf = dm_malloc_aligned((size_t) devbuf->where.size, 0))) {
- log_error("Bounce buffer malloc failed");
- return 0;
- }
+ /* Postpone buffer allocation until we're about to issue the I/O */
+ devbuf->buf = NULL;
#else
- } else {
+ else {
/* Allocate a bounce buffer with an extra block */
if (!(devbuf->malloc_address = devbuf->buf = dm_malloc((size_t) devbuf->where.size + block_size))) {
log_error("Bounce buffer malloc failed");
6 years, 3 months
master - device: Merge _dev_read and dev_read_callback.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=081902b4c115c465b12...
Commit: 081902b4c115c465b123c13e9d8287a75f9d7b2a
Parent: 0a3c6bf8c61224024c030152693fe2ce103cc6f0
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Tue Jan 16 00:41:42 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Tue Jan 16 00:41:42 2018 +0000
device: Merge _dev_read and dev_read_callback.
---
lib/device/dev-io.c | 59 ++++++++++++++++++---------------------------
lib/format1/lvm1-label.c | 2 +-
2 files changed, 25 insertions(+), 36 deletions(-)
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index 6d5433f..d995452 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -791,20 +791,26 @@ static void _dev_inc_error_count(struct device *dev)
/*
* Data is returned (read-only) at DEV_DEVBUF_DATA(dev, reason)
*/
-static int _dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason)
+int dev_read_callback(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason,
+ lvm_callback_fn_t dev_read_callback_fn, void *callback_context)
{
struct device_area where;
struct device_buffer *devbuf;
uint64_t buf_end;
- int ret;
+ int cached = 0;
+ int ret = 1;
if (!dev->open_count) {
log_error(INTERNAL_ERROR "Attempt to access device %s while closed.", dev_name(dev));
- return 0;
+ ret = 0;
+ goto out;
}
- if (!_dev_is_valid(dev))
- return 0;
+ if (!_dev_is_valid(dev)) {
+ log_error("Not reading from %s - too many errors.", dev_name(dev));
+ ret = 0;
+ goto out;
+ }
/*
* Can we satisfy this from data we stored last time we read?
@@ -813,10 +819,11 @@ static int _dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_rea
buf_end = devbuf->where.start + devbuf->where.size - 1;
if (offset >= devbuf->where.start && offset <= buf_end && offset + len - 1 <= buf_end) {
/* Reuse this buffer */
+ cached = 1;
devbuf->data_offset = offset - devbuf->where.start;
log_debug_io("Cached read for %" PRIu64 " bytes at %" PRIu64 " on %s (for %s)",
(uint64_t) len, (uint64_t) offset, dev_name(dev), _reason_text(reason));
- return 1;
+ goto out;
}
}
@@ -825,8 +832,14 @@ static int _dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_rea
where.size = len;
ret = _aligned_io(&where, NULL, 0, reason);
- if (!ret)
+ if (!ret) {
+ log_error("Read from %s failed.", dev_name(dev));
_dev_inc_error_count(dev);
+ }
+
+out:
+ if (dev_read_callback_fn)
+ dev_read_callback_fn(!ret, callback_context, DEV_DEVBUF_DATA(dev, reason));
return ret;
}
@@ -834,41 +847,17 @@ static int _dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_rea
/* Returns pointer to read-only buffer. Caller does not free it. */
const char *dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason)
{
- if (!_dev_read(dev, offset, len, reason)) {
- log_error("Read from %s failed", dev_name(dev));
- return NULL;
- }
+ if (!dev_read_callback(dev, offset, len, reason, NULL, NULL))
+ return_NULL;
return DEV_DEVBUF_DATA(dev, reason);
}
-/* Obtains data requested then passes it (read-only) to dev_read_callback_fn() */
-int dev_read_callback(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason,
- lvm_callback_fn_t dev_read_callback_fn, void *callback_context)
-{
- int r = 0;
-
- if (!_dev_read(dev, offset, len, reason)) {
- log_error("Read from %s failed", dev_name(dev));
- goto out;
- }
-
- r = 1;
-
-out:
- if (dev_read_callback_fn)
- dev_read_callback_fn(!r, callback_context, DEV_DEVBUF_DATA(dev, reason));
-
- return r;
-}
-
/* Read into supplied retbuf owned by the caller. */
int dev_read_buf(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *retbuf)
{
- if (!_dev_read(dev, offset, len, reason)) {
- log_error("Read from %s failed", dev_name(dev));
- return 0;
- }
+ if (!dev_read_callback(dev, offset, len, reason, NULL, NULL))
+ return_0;
memcpy(retbuf, DEV_DEVBUF_DATA(dev, reason), len);
diff --git a/lib/format1/lvm1-label.c b/lib/format1/lvm1-label.c
index 1452dea..77dab1e 100644
--- a/lib/format1/lvm1-label.c
+++ b/lib/format1/lvm1-label.c
@@ -64,7 +64,7 @@ static int _lvm1_read(struct labeller *l, struct device *dev, void *buf,
const char *vgid = FMT_LVM1_ORPHAN_VG_NAME;
const char *vgname = FMT_LVM1_ORPHAN_VG_NAME;
unsigned exported = 0;
- int r;
+ int r = 0;
munge_pvd(dev, pvd);
6 years, 3 months
master - format_text: Refactor mda counting in label processing.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0a3c6bf8c61224024c0...
Commit: 0a3c6bf8c61224024c030152693fe2ce103cc6f0
Parent: 73b5ee64e7bf1525f1958a1fb212b67a0832e6c7
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Jan 15 20:43:51 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Jan 15 23:47:44 2018 +0000
format_text: Refactor mda counting in label processing.
---
lib/format_text/text_label.c | 53 +++++++++++++++++++++++++++---------------
1 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/lib/format_text/text_label.c b/lib/format_text/text_label.c
index a676f19..be797b2 100644
--- a/lib/format_text/text_label.c
+++ b/lib/format_text/text_label.c
@@ -349,12 +349,17 @@ static void _process_vgsummary(int failed, void *context, const void *data)
if (!lvmcache_update_vgname_and_id(pmp->umb->info, vgsummary)) {
pmp->umb->ret = 0;
pmp->ret = 0;
- goto_out;
}
out:
+ if (!pmp->umb->nr_outstanding_mdas && pmp->umb->ret)
+ lvmcache_make_valid(pmp->umb->info);
+
if (!dev_close(pmp->dev))
stack;
+
+ if (!pmp->umb->nr_outstanding_mdas && pmp->umb->read_label_callback_fn)
+ pmp->umb->read_label_callback_fn(!pmp->umb->ret, pmp->umb->read_label_callback_context, pmp->umb->label);
}
static void _process_mda_header(int failed, void *context, const void *data)
@@ -367,7 +372,7 @@ static void _process_mda_header(int failed, void *context, const void *data)
struct mda_context *mdac = (struct mda_context *) mda->metadata_locn;
if (failed)
- return;
+ goto_bad;
mda_set_ignored(mda, rlocn_is_ignored(mdah->raw_locns));
@@ -390,6 +395,15 @@ bad:
return;
}
+static int _count_mda(struct metadata_area *mda, void *baton)
+{
+ struct update_mda_baton *umb = baton;
+
+ umb->nr_outstanding_mdas++;
+
+ return 1;
+}
+
static int _update_mda(struct metadata_area *mda, void *baton)
{
struct process_mda_header_params *pmp;
@@ -410,24 +424,23 @@ static int _update_mda(struct metadata_area *mda, void *baton)
* TODO: make lvmcache smarter and move this cache logic there
*/
+ pmp->dev = mdac->area.dev;
+ pmp->umb = umb;
+ pmp->mda = mda;
+
if (!dev_open_readonly(mdac->area.dev)) {
mda_set_ignored(mda, 1);
stack;
+ if (!--umb->nr_outstanding_mdas && umb->read_label_callback_fn)
+ umb->read_label_callback_fn(!umb->ret, umb->read_label_callback_context, umb->label);
return 1;
}
- umb->nr_outstanding_mdas++;
- pmp->dev = mdac->area.dev;
-
- pmp->umb = umb;
- pmp->mda = mda;
pmp->ret = 1;
if (!raw_read_mda_header_callback(fmt->cmd->mem, &mdac->area, mda_is_primary(mda), _process_mda_header, pmp)) {
+ _process_vgsummary(1, pmp, NULL);
stack;
- --pmp->umb->nr_outstanding_mdas;
- if (!dev_close(pmp->dev))
- stack;
return 1;
}
@@ -446,7 +459,7 @@ static int _text_read(struct labeller *l, struct device *dev, void *buf,
uint32_t ext_version;
struct dm_pool *mem = l->fmt->cmd->mem;
struct update_mda_baton *umb;
- struct label *label = NULL;
+ struct label *label;
/*
* PV header base
@@ -515,19 +528,21 @@ out:
umb->label = label;
umb->read_label_callback_fn = read_label_callback_fn;
umb->read_label_callback_context = read_label_callback_context;
- umb->nr_outstanding_mdas = 1;
umb->ret = 1;
- if (!lvmcache_foreach_mda(info, _update_mda, umb))
- return_0;
+ if (!lvmcache_foreach_mda(info, _count_mda, umb))
+ goto_bad;
- if (!--umb->nr_outstanding_mdas)
- if (umb->ret)
- lvmcache_make_valid(info);
+ if (!umb->nr_outstanding_mdas) {
+ lvmcache_make_valid(info);
+ if (read_label_callback_fn)
+ read_label_callback_fn(0, read_label_callback_context, label);
+ return 1;
+ }
- if (umb->read_label_callback_fn)
- umb->read_label_callback_fn(!umb->ret, umb->read_label_callback_context, label);
+ if (!lvmcache_foreach_mda(info, _update_mda, umb))
+ goto_bad;
return 1;
6 years, 3 months
master - format_text: Change update_mda_baton to use label not labeller
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=73b5ee64e7bf1525f19...
Commit: 73b5ee64e7bf1525f1958a1fb212b67a0832e6c7
Parent: b825987b2fc6a8294d164bf4c5e1be7edc199bea
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Jan 15 20:13:53 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Jan 15 20:13:53 2018 +0000
format_text: Change update_mda_baton to use label not labeller
---
lib/format_text/text_label.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/format_text/text_label.c b/lib/format_text/text_label.c
index 44d43f1..a676f19 100644
--- a/lib/format_text/text_label.c
+++ b/lib/format_text/text_label.c
@@ -321,7 +321,7 @@ static int _text_initialise_label(struct labeller *l __attribute__((unused)),
struct update_mda_baton {
struct lvmcache_info *info;
- struct labeller *labeller;
+ struct label *label;
int nr_outstanding_mdas;
lvm_callback_fn_t read_label_callback_fn;
void *read_label_callback_context;
@@ -362,7 +362,7 @@ static void _process_mda_header(int failed, void *context, const void *data)
struct process_mda_header_params *pmp = context;
const struct mda_header *mdah = data;
struct update_mda_baton *umb = pmp->umb;
- const struct format_type *fmt = umb->labeller->fmt;
+ const struct format_type *fmt = umb->label->labeller->fmt;
struct metadata_area *mda = pmp->mda;
struct mda_context *mdac = (struct mda_context *) mda->metadata_locn;
@@ -394,8 +394,8 @@ static int _update_mda(struct metadata_area *mda, void *baton)
{
struct process_mda_header_params *pmp;
struct update_mda_baton *umb = baton;
- const struct format_type *fmt = umb->labeller->fmt;
- struct dm_pool *mem = umb->labeller->fmt->cmd->mem;
+ const struct format_type *fmt = umb->label->labeller->fmt;
+ struct dm_pool *mem = umb->label->labeller->fmt->cmd->mem;
struct mda_context *mdac = (struct mda_context *) mda->metadata_locn;
if (!(pmp = dm_pool_zalloc(mem, sizeof(*pmp)))) {
@@ -512,7 +512,7 @@ out:
}
umb->info = info;
- umb->labeller = label->labeller;
+ umb->label = label;
umb->read_label_callback_fn = read_label_callback_fn;
umb->read_label_callback_context = read_label_callback_context;
umb->nr_outstanding_mdas = 1;
6 years, 3 months
master - device: Rearrange _aligned_io().
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b825987b2fc6a8294d1...
Commit: b825987b2fc6a8294d164bf4c5e1be7edc199bea
Parent: c90582344d4c04d020899a8ff8857f09368e0a98
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Jan 15 19:59:28 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Jan 15 20:10:54 2018 +0000
device: Rearrange _aligned_io().
---
lib/device/dev-io.c | 73 ++++++++++++++++++++++++--------------------------
1 files changed, 35 insertions(+), 38 deletions(-)
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index 514aaca..6d5433f 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -261,10 +261,9 @@ static void _widen_region(unsigned int block_size, struct device_area *region,
result->size += block_size - delta;
}
-static int _aligned_io(struct device_area *where, char *buffer,
+static int _aligned_io(struct device_area *where, char *write_buffer,
int should_write, dev_io_reason_t reason)
{
- char *bounce, *bounce_buf = NULL;
unsigned int physical_block_size = 0;
unsigned int block_size = 0;
unsigned buffer_was_widened = 0;
@@ -295,18 +294,30 @@ static int _aligned_io(struct device_area *where, char *buffer,
where->size, (uint64_t) where->start, widened.size, (uint64_t) widened.start, dev_name(where->dev), _reason_text(reason));
}
- if (should_write && !buffer_was_widened && !((uintptr_t) buffer & mask))
+ devbuf = DEV_DEVBUF(where->dev, reason);
+ _release_devbuf(devbuf);
+ devbuf->where.dev = where->dev;
+ devbuf->where.start = widened.start;
+ devbuf->where.size = widened.size;
+ devbuf->write = should_write;
+ devbuf->reason = reason;
+
+ /* Store location of requested data relative to start of buf */
+ devbuf->data_offset = where->start - devbuf->where.start;
+
+ if (should_write && !buffer_was_widened && !((uintptr_t) write_buffer & mask)) {
/* Perform the I/O directly. */
- bounce = buffer;
+ devbuf->buf = write_buffer;
+ devbuf->malloc_address = NULL;
#ifndef DEBUG_MEM
- else if (!(bounce_buf = bounce = dm_malloc_aligned((size_t) widened.size, 0))) {
+ } else if (!(devbuf->malloc_address = devbuf->buf = dm_malloc_aligned((size_t) devbuf->where.size, 0))) {
log_error("Bounce buffer malloc failed");
return 0;
}
#else
- else {
+ } else {
/* Allocate a bounce buffer with an extra block */
- if (!(bounce_buf = bounce = dm_malloc((size_t) widened.size + block_size))) {
+ if (!(devbuf->malloc_address = devbuf->buf = dm_malloc((size_t) devbuf->where.size + block_size))) {
log_error("Bounce buffer malloc failed");
return 0;
}
@@ -314,53 +325,39 @@ static int _aligned_io(struct device_area *where, char *buffer,
/*
* Realign start of bounce buffer (using the extra sector)
*/
- if (((uintptr_t) bounce) & mask)
- bounce = (char *) ((((uintptr_t) bounce) + mask) & ~mask);
+ if (((uintptr_t) devbuf->buf) & mask)
+ devbuf->buf = (char *) ((((uintptr_t) devbuf->buf) + mask) & ~mask);
}
#endif
- devbuf = DEV_DEVBUF(where->dev, reason);
- _release_devbuf(devbuf);
- devbuf->malloc_address = bounce_buf;
- devbuf->buf = bounce;
- devbuf->where.dev = where->dev;
- devbuf->where.start = widened.start;
- devbuf->where.size = widened.size;
devbuf->write = 0;
- devbuf->reason = reason;
/* Do we need to read into the bounce buffer? */
- if ((!should_write || buffer_was_widened) &&
- !_io(devbuf)) {
+ if ((!should_write || buffer_was_widened) && !_io(devbuf)) {
if (!should_write)
goto_bad;
/* FIXME Handle errors properly! */
/* FIXME pre-extend the file */
- memset(bounce, '\n', widened.size);
+ memset(devbuf->buf, '\n', devbuf->where.size);
}
- if (should_write) {
- if (bounce_buf) {
- memcpy(bounce + (where->start - widened.start), buffer,
- (size_t) where->size);
- log_debug_io("Overwriting %" PRIu64 " bytes at %" PRIu64 " (for %s)", where->size,
- (uint64_t) where->start, _reason_text(reason));
- }
-
- /* ... then we write */
- devbuf->write = 1;
- if (!(r = _io(devbuf)))
- goto_bad;
-
- _release_devbuf(devbuf);
+ if (!should_write)
return 1;
- }
- /* read */
+ /* writes */
- /* We store what we just read as it often also satisfies the next request */
- devbuf->data_offset = where->start - widened.start;
+ if (devbuf->malloc_address) {
+ memcpy((char *) devbuf->buf + devbuf->data_offset, write_buffer, (size_t) where->size);
+ log_debug_io("Overwriting %" PRIu64 " bytes at %" PRIu64 " (for %s)", where->size,
+ (uint64_t) where->start, _reason_text(devbuf->reason));
+ }
+ /* ... then we write */
+ devbuf->write = 1;
+ if (!(r = _io(devbuf)))
+ goto_bad;
+
+ _release_devbuf(devbuf);
return 1;
bad:
6 years, 3 months
master - device: Add reason to devbuf.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=c90582344d4c04d0208...
Commit: c90582344d4c04d020899a8ff8857f09368e0a98
Parent: 1f01eaa61200bb1144bb6f424d8df2c77a8b8307
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Jan 15 19:38:18 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Jan 15 19:38:18 2018 +0000
device: Add reason to devbuf.
---
lib/device/dev-io.c | 9 +++++----
lib/device/device.h | 1 +
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index 38127c7..514aaca 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -142,7 +142,7 @@ static int _io_sync(struct device_buffer *devbuf)
return (total == (size_t) where->size);
}
-static int _io(struct device_buffer *devbuf, dev_io_reason_t reason)
+static int _io(struct device_buffer *devbuf)
{
struct device_area *where = &devbuf->where;
int fd = dev_fd(where->dev);
@@ -156,7 +156,7 @@ static int _io(struct device_buffer *devbuf, dev_io_reason_t reason)
log_debug_io("%s %s(fd %d):%8" PRIu64 " bytes (sync) at %" PRIu64 "%s (for %s)",
devbuf->write ? "Write" : "Read ", dev_name(where->dev), fd,
where->size, (uint64_t) where->start,
- (devbuf->write && test_mode()) ? " (test mode - suppressed)" : "", _reason_text(reason));
+ (devbuf->write && test_mode()) ? " (test mode - suppressed)" : "", _reason_text(devbuf->reason));
/*
* Skip all writes in test mode.
@@ -327,10 +327,11 @@ static int _aligned_io(struct device_area *where, char *buffer,
devbuf->where.start = widened.start;
devbuf->where.size = widened.size;
devbuf->write = 0;
+ devbuf->reason = reason;
/* Do we need to read into the bounce buffer? */
if ((!should_write || buffer_was_widened) &&
- !_io(devbuf, reason)) {
+ !_io(devbuf)) {
if (!should_write)
goto_bad;
/* FIXME Handle errors properly! */
@@ -348,7 +349,7 @@ static int _aligned_io(struct device_area *where, char *buffer,
/* ... then we write */
devbuf->write = 1;
- if (!(r = _io(devbuf, reason)))
+ if (!(r = _io(devbuf)))
goto_bad;
_release_devbuf(devbuf);
diff --git a/lib/device/device.h b/lib/device/device.h
index 2a05fd4..d70d3aa 100644
--- a/lib/device/device.h
+++ b/lib/device/device.h
@@ -90,6 +90,7 @@ struct device_buffer {
void *malloc_address; /* Start of allocated memory */
void *buf; /* Aligned buffer that contains data within it */
struct device_area where; /* Location of buf */
+ dev_io_reason_t reason;
unsigned write:1; /* 1 if write; 0 if read */
};
6 years, 3 months
master - device: Store offset to data instead of pointer.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=1f01eaa61200bb1144b...
Commit: 1f01eaa61200bb1144bb6f424d8df2c77a8b8307
Parent: 61d3296f2aae134a9215a9c9c2f3146a75fddc19
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Jan 15 19:32:59 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Jan 15 19:32:59 2018 +0000
device: Store offset to data instead of pointer.
We want to save the relative offset before we've allocated the
buffer's memory.
---
lib/device/dev-io.c | 12 ++++++------
lib/device/device.h | 3 ++-
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index f916761..38127c7 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -358,7 +358,7 @@ static int _aligned_io(struct device_area *where, char *buffer,
/* read */
/* We store what we just read as it often also satisfies the next request */
- devbuf->data = bounce + (where->start - widened.start);
+ devbuf->data_offset = where->start - widened.start;
return 1;
@@ -791,7 +791,7 @@ static void _dev_inc_error_count(struct device *dev)
}
/*
- * Data is returned (read-only) at dev->last_[extra_]devbuf->data
+ * Data is returned (read-only) at DEV_DEVBUF_DATA(dev, reason)
*/
static int _dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason)
{
@@ -815,7 +815,7 @@ static int _dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_rea
buf_end = devbuf->where.start + devbuf->where.size - 1;
if (offset >= devbuf->where.start && offset <= buf_end && offset + len - 1 <= buf_end) {
/* Reuse this buffer */
- devbuf->data = (char *) devbuf->buf + (offset - devbuf->where.start);
+ devbuf->data_offset = offset - devbuf->where.start;
log_debug_io("Cached read for %" PRIu64 " bytes at %" PRIu64 " on %s (for %s)",
(uint64_t) len, (uint64_t) offset, dev_name(dev), _reason_text(reason));
return 1;
@@ -841,7 +841,7 @@ const char *dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_rea
return NULL;
}
- return DEV_DEVBUF(dev, reason)->data;
+ return DEV_DEVBUF_DATA(dev, reason);
}
/* Obtains data requested then passes it (read-only) to dev_read_callback_fn() */
@@ -859,7 +859,7 @@ int dev_read_callback(struct device *dev, uint64_t offset, size_t len, dev_io_re
out:
if (dev_read_callback_fn)
- dev_read_callback_fn(!r, callback_context, DEV_DEVBUF(dev, reason)->data);
+ dev_read_callback_fn(!r, callback_context, DEV_DEVBUF_DATA(dev, reason));
return r;
}
@@ -872,7 +872,7 @@ int dev_read_buf(struct device *dev, uint64_t offset, size_t len, dev_io_reason_
return 0;
}
- memcpy(retbuf, DEV_DEVBUF(dev, reason)->data, len);
+ memcpy(retbuf, DEV_DEVBUF_DATA(dev, reason), len);
return 1;
}
diff --git a/lib/device/device.h b/lib/device/device.h
index 6280138..2a05fd4 100644
--- a/lib/device/device.h
+++ b/lib/device/device.h
@@ -77,6 +77,7 @@ typedef enum dev_io_reason {
*/
#define EXTRA_IO(reason) ((reason) == DEV_IO_MDA_EXTRA_HEADER || (reason) == DEV_IO_MDA_EXTRA_CONTENT)
#define DEV_DEVBUF(dev, reason) (EXTRA_IO((reason)) ? &(dev)->last_extra_devbuf : &(dev)->last_devbuf)
+#define DEV_DEVBUF_DATA(dev, reason) ((char *) DEV_DEVBUF((dev), (reason))->buf + DEV_DEVBUF((dev), (reason))->data_offset)
struct device_area {
struct device *dev;
@@ -85,7 +86,7 @@ struct device_area {
};
struct device_buffer {
- const void *data; /* Location of start of requested data (inside buf) */
+ uint64_t data_offset; /* Offset to start of requested data within buf */
void *malloc_address; /* Start of allocated memory */
void *buf; /* Aligned buffer that contains data within it */
struct device_area where; /* Location of buf */
6 years, 3 months
master - device: Reorder device.h before change.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=61d3296f2aae134a921...
Commit: 61d3296f2aae134a9215a9c9c2f3146a75fddc19
Parent: da37cbd24fc0073f3f00a3b7aac7807d2185b829
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Jan 15 19:24:01 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Jan 15 19:24:01 2018 +0000
device: Reorder device.h before change.
---
lib/device/device.h | 56 ++++++++++++++++++++++++--------------------------
1 files changed, 27 insertions(+), 29 deletions(-)
diff --git a/lib/device/device.h b/lib/device/device.h
index 926d24a..6280138 100644
--- a/lib/device/device.h
+++ b/lib/device/device.h
@@ -56,6 +56,28 @@ struct dev_ext {
void *handle;
};
+/*
+ * 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_MDA_EXTRA_HEADER, /* Header of any extra metadata areas on device */
+ DEV_IO_MDA_EXTRA_CONTENT, /* Content of any extra metadata areas on device */
+ 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;
+
+/*
+ * Is this I/O for a device's extra metadata area?
+ */
+#define EXTRA_IO(reason) ((reason) == DEV_IO_MDA_EXTRA_HEADER || (reason) == DEV_IO_MDA_EXTRA_CONTENT)
+#define DEV_DEVBUF(dev, reason) (EXTRA_IO((reason)) ? &(dev)->last_extra_devbuf : &(dev)->last_devbuf)
+
struct device_area {
struct device *dev;
uint64_t start; /* Bytes */
@@ -63,13 +85,11 @@ struct device_area {
};
struct device_buffer {
- const void *data; /* Location of start of requested data (inside buf) */
-
- /* Private */
- void *malloc_address; /* Start of allocated memory */
- void *buf; /* Aligned buffer that contains data within it */
- struct device_area where; /* Location of buf */
- unsigned write:1; /* 1 if write; 0 if read */
+ const void *data; /* Location of start of requested data (inside buf) */
+ void *malloc_address; /* Start of allocated memory */
+ void *buf; /* Aligned buffer that contains data within it */
+ struct device_area where; /* Location of buf */
+ unsigned write:1; /* 1 if write; 0 if read */
};
/*
@@ -104,28 +124,6 @@ struct device {
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_MDA_EXTRA_HEADER, /* Header of any extra metadata areas on device */
- DEV_IO_MDA_EXTRA_CONTENT, /* Content of any extra metadata areas on device */
- 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;
-
-/*
- * Is this I/O for a device's extra metadata area?
- */
-#define EXTRA_IO(reason) ((reason) == DEV_IO_MDA_EXTRA_HEADER || (reason) == DEV_IO_MDA_EXTRA_CONTENT)
-#define DEV_DEVBUF(dev, reason) (EXTRA_IO((reason)) ? &(dev)->last_extra_devbuf : &(dev)->last_devbuf)
-
struct device_list {
struct dm_list list;
struct device *dev;
6 years, 3 months
master - command: Skip some memory zeroing.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=da37cbd24fc0073f3f0...
Commit: da37cbd24fc0073f3f00a3b7aac7807d2185b829
Parent: e4e2abc8bc2f257c2d0f9458bab7c87d34626be3
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Sat Jan 13 03:36:53 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Sat Jan 13 03:44:15 2018 +0000
command: Skip some memory zeroing.
commands[] is in bss, its content wouldn't change if reinitialised
and unregister has no memory to free so don't bother.
---
tools/command.c | 11 ++++++-----
tools/lvmcmdline.c | 12 ------------
2 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/tools/command.c b/tools/command.c
index 1a712cc..5a5f351 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -1356,13 +1356,11 @@ static void _create_opt_names_alpha(void)
qsort(opt_names_alpha, ARG_COUNT, sizeof(long), _long_name_compare);
}
-static int _copy_line(char *line, int max_line, int *position)
+static int _copy_line(char *line, int max_line, int *position, int *len)
{
int p = *position;
int i = 0;
- memset(line, 0, max_line);
-
while (1) {
line[i] = _command_input[p];
i++;
@@ -1376,7 +1374,9 @@ static int _copy_line(char *line, int max_line, int *position)
if (i == (max_line - 1))
break;
}
+ line[i] = '\0';
*position = p;
+ *len = i + 1;
return 1;
}
@@ -1394,6 +1394,7 @@ int define_commands(struct cmd_context *cmdtool, const char *run_name)
int prev_was_oo = 0;
int prev_was_op = 0;
int copy_pos = 0;
+ int copy_len = 0;
int skip = 0;
int i;
@@ -1404,14 +1405,14 @@ int define_commands(struct cmd_context *cmdtool, const char *run_name)
/* Process each line of command-lines-input.h (from command-lines.in) */
- while (_copy_line(line, MAX_LINE, ©_pos)) {
+ while (_copy_line(line, MAX_LINE, ©_pos, ©_len)) {
if (line[0] == '\n')
break;
if ((n = strchr(line, '\n')))
*n = '\0';
- memcpy(line_orig, line, sizeof(line));
+ memcpy(line_orig, line, copy_len);
_split_line(line, &line_argc, line_argv, ' ');
if (!line_argc)
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 6be4bcd..246d332 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1262,15 +1262,6 @@ static const struct command_function *_find_command_id_function(int command_enum
return NULL;
}
-static void _unregister_commands(void)
-{
- _cmdline.commands = NULL;
- _cmdline.num_commands = 0;
- _cmdline.command_names = NULL;
- _cmdline.num_command_names = 0;
- memset(&commands, 0, sizeof(commands));
-}
-
int lvm_register_commands(struct cmd_context *cmd, const char *run_name)
{
int i;
@@ -1279,8 +1270,6 @@ int lvm_register_commands(struct cmd_context *cmd, const char *run_name)
if (_cmdline.commands)
return 1;
- memset(&commands, 0, sizeof(commands));
-
/*
* populate commands[] array with command definitions
* by parsing command-lines.in/command-lines-input.h
@@ -3335,7 +3324,6 @@ struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters)
void lvm_fin(struct cmd_context *cmd)
{
- _unregister_commands();
destroy_toolcontext(cmd);
udev_fin_library_context();
}
6 years, 3 months
master - libdm: Fix a size_t in _dm_malloc_aligned_aux message.
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e4e2abc8bc2f257c2d0...
Commit: e4e2abc8bc2f257c2d0f9458bab7c87d34626be3
Parent: 5bbe68cf15b00987e6644c956cf602251ac91581
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Thu Jan 11 22:19:41 2018 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Fri Jan 12 00:42:53 2018 +0000
libdm: Fix a size_t in _dm_malloc_aligned_aux message.
---
libdm/mm/dbg_malloc.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/libdm/mm/dbg_malloc.c b/libdm/mm/dbg_malloc.c
index f108e7b..280213b 100644
--- a/libdm/mm/dbg_malloc.c
+++ b/libdm/mm/dbg_malloc.c
@@ -304,7 +304,7 @@ static void *_dm_malloc_aligned_aux(size_t s, size_t a, const char *file __attri
}
if ((r = posix_memalign(&memptr, a, s))) {
- log_error("Failed to allocate %" PRIsize_t " bytes aligned to %d: %s", s, a, strerror(r));
+ log_error("Failed to allocate %" PRIsize_t " bytes aligned to %" PRIsize_t ": %s", s, a, strerror(r));
return 0;
}
6 years, 3 months