mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-02 01:18:26 +03:00
device: Eliminate unnecessary buffer from dev_read.
This commit is contained in:
parent
366493a1d1
commit
c350f96c09
@ -817,7 +817,7 @@ static int _dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_rea
|
|||||||
/* Reuse this buffer */
|
/* Reuse this buffer */
|
||||||
devbuf->data = (char *) devbuf->buf + (offset - devbuf->where.start);
|
devbuf->data = (char *) devbuf->buf + (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)",
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -833,27 +833,18 @@ static int _dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_rea
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Caller is responsible for dm_free */
|
/* Returns pointer to read-only buffer. Caller does not free it. */
|
||||||
char *dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason)
|
char *dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason)
|
||||||
{
|
{
|
||||||
char *buf;
|
|
||||||
|
|
||||||
if (!(buf = dm_malloc(len))) {
|
|
||||||
log_error("Buffer allocation failed for device read.");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_dev_read(dev, offset, len, reason)) {
|
if (!_dev_read(dev, offset, len, reason)) {
|
||||||
log_error("Read from %s failed", dev_name(dev));
|
log_error("Read from %s failed", dev_name(dev));
|
||||||
dm_free(buf);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buf, DEV_DEVBUF(dev, reason)->data, len);
|
return DEV_DEVBUF(dev, reason)->data;
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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,
|
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)
|
lvm_callback_fn_t dev_read_callback_fn, void *callback_context)
|
||||||
{
|
{
|
||||||
@ -873,17 +864,15 @@ out:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read into supplied retbuf */
|
/* 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)
|
int dev_read_buf(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *retbuf)
|
||||||
{
|
{
|
||||||
char *buf = NULL;
|
if (!_dev_read(dev, offset, len, reason)) {
|
||||||
|
log_error("Read from %s failed", dev_name(dev));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(buf = dev_read(dev, offset, len, reason)))
|
memcpy(retbuf, DEV_DEVBUF(dev, reason)->data, len);
|
||||||
return_0;
|
|
||||||
|
|
||||||
memcpy(retbuf, buf, len);
|
|
||||||
|
|
||||||
dm_free(buf);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -902,22 +891,18 @@ char *dev_read_circular(struct device *dev, uint64_t offset, size_t len,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_dev_read(dev, offset, len, reason)) {
|
if (!dev_read_buf(dev, offset, len, reason, buf)) {
|
||||||
log_error("Read from %s failed", dev_name(dev));
|
log_error("Read from %s failed", dev_name(dev));
|
||||||
dm_free(buf);
|
dm_free(buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buf, DEV_DEVBUF(dev, reason)->data, len);
|
if (!dev_read_buf(dev, offset2, len2, reason, buf + len)) {
|
||||||
|
|
||||||
if (!_dev_read(dev, offset2, len2, reason)) {
|
|
||||||
log_error("Circular read from %s failed", dev_name(dev));
|
log_error("Circular read from %s failed", dev_name(dev));
|
||||||
dm_free(buf);
|
dm_free(buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buf + len, DEV_DEVBUF(dev, reason)->data, len2);
|
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,20 +272,20 @@ static int _pv_analyze_mda_raw (const struct format_type * fmt,
|
|||||||
size += SECTOR_SIZE;
|
size += SECTOR_SIZE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (circular)
|
||||||
dm_free(buf);
|
dm_free(buf);
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = 1;
|
r = 1;
|
||||||
out:
|
out:
|
||||||
|
if (circular)
|
||||||
dm_free(buf);
|
dm_free(buf);
|
||||||
if (!dev_close(area->dev))
|
if (!dev_close(area->dev))
|
||||||
stack;
|
stack;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int _text_lv_setup(struct format_instance *fid __attribute__((unused)),
|
static int _text_lv_setup(struct format_instance *fid __attribute__((unused)),
|
||||||
struct logical_volume *lv)
|
struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
@ -512,12 +512,8 @@ static struct raw_locn *_find_vg_rlocn(struct device_area *dev_area,
|
|||||||
goto_bad;
|
goto_bad;
|
||||||
|
|
||||||
if (!strncmp(buf, vgname, len = strlen(vgname)) &&
|
if (!strncmp(buf, vgname, len = strlen(vgname)) &&
|
||||||
(isspace(*(buf + len)) || *(buf + len) == '{')) {
|
(isspace(*(buf + len)) || *(buf + len) == '{'))
|
||||||
dm_free(buf);
|
|
||||||
return rlocn;
|
return rlocn;
|
||||||
}
|
|
||||||
|
|
||||||
dm_free(buf);
|
|
||||||
|
|
||||||
log_debug_metadata("Volume group name found in %smetadata on %s at " FMTu64 " does "
|
log_debug_metadata("Volume group name found in %smetadata on %s at " FMTu64 " does "
|
||||||
"not match expected name %s.",
|
"not match expected name %s.",
|
||||||
|
@ -307,7 +307,6 @@ int label_remove(struct device *dev)
|
|||||||
if (!dev_close(dev))
|
if (!dev_close(dev))
|
||||||
stack;
|
stack;
|
||||||
|
|
||||||
dm_free(readbuf);
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user