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

device: Store offset to data instead of pointer.

We want to save the relative offset before we've allocated the
buffer's memory.
This commit is contained in:
Alasdair G Kergon 2018-01-15 19:32:59 +00:00
parent 61d3296f2a
commit 1f01eaa612
2 changed files with 8 additions and 7 deletions

View File

@ -358,7 +358,7 @@ static int _aligned_io(struct device_area *where, char *buffer,
/* read */ /* read */
/* We store what we just read as it often also satisfies the next request */ /* 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; 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) 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; buf_end = devbuf->where.start + devbuf->where.size - 1;
if (offset >= devbuf->where.start && offset <= buf_end && offset + len - 1 <= buf_end) { if (offset >= devbuf->where.start && offset <= buf_end && offset + len - 1 <= buf_end) {
/* Reuse this buffer */ /* 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)", 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)); (uint64_t) len, (uint64_t) offset, dev_name(dev), _reason_text(reason));
return 1; 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 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() */ /* 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: out:
if (dev_read_callback_fn) 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; return r;
} }
@ -872,7 +872,7 @@ int dev_read_buf(struct device *dev, uint64_t offset, size_t len, dev_io_reason_
return 0; return 0;
} }
memcpy(retbuf, DEV_DEVBUF(dev, reason)->data, len); memcpy(retbuf, DEV_DEVBUF_DATA(dev, reason), len);
return 1; return 1;
} }

View File

@ -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 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(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_area {
struct device *dev; struct device *dev;
@ -85,7 +86,7 @@ struct device_area {
}; };
struct device_buffer { 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 *malloc_address; /* Start of allocated memory */
void *buf; /* Aligned buffer that contains data within it */ void *buf; /* Aligned buffer that contains data within it */
struct device_area where; /* Location of buf */ struct device_area where; /* Location of buf */