mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-11 09:18:25 +03:00
bcache/sync io engine: handle short ios
This commit is contained in:
parent
39ce38eb88
commit
5f780813f2
@ -283,7 +283,6 @@ struct io_engine *create_async_io_engine(void)
|
|||||||
struct sync_io {
|
struct sync_io {
|
||||||
struct dm_list list;
|
struct dm_list list;
|
||||||
void *context;
|
void *context;
|
||||||
int err;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sync_engine {
|
struct sync_engine {
|
||||||
@ -306,30 +305,46 @@ static bool _sync_issue(struct io_engine *ioe, enum dir d, int fd,
|
|||||||
sector_t sb, sector_t se, void *data, void *context)
|
sector_t sb, sector_t se, void *data, void *context)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
uint64_t len = (se - sb) * 512;
|
uint64_t len = (se - sb) * 512, where;
|
||||||
struct sync_engine *e = _to_sync(ioe);
|
struct sync_engine *e = _to_sync(ioe);
|
||||||
struct sync_io *io = malloc(sizeof(*io));
|
struct sync_io *io = malloc(sizeof(*io));
|
||||||
if (!io)
|
if (!io) {
|
||||||
|
log_warn("unable to allocate sync_io");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
r = lseek(fd, sb * 512, SEEK_SET);
|
where = sb * 512;
|
||||||
if (r < 0)
|
r = lseek(fd, where, SEEK_SET);
|
||||||
|
if (r < 0) {
|
||||||
|
log_warn("unable to seek to position %llu", (unsigned long long) where);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
while (len) {
|
||||||
if (d == DIR_READ)
|
do {
|
||||||
r = read(fd, data, len);
|
if (d == DIR_READ)
|
||||||
else
|
r = read(fd, data, len);
|
||||||
r = write(fd, data, len);
|
else
|
||||||
|
r = write(fd, data, len);
|
||||||
|
|
||||||
} while (r == EINTR || r == EAGAIN);
|
} while ((r < 0) && ((r == EINTR) || (r == EAGAIN)));
|
||||||
|
|
||||||
|
if (r < 0) {
|
||||||
|
log_warn("io failed %d", r);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
len -= r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len) {
|
||||||
|
log_warn("short io %u bytes remaining", (unsigned) len);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (r != len)
|
|
||||||
r = -EIO;
|
|
||||||
|
|
||||||
dm_list_add(&e->complete, &io->list);
|
dm_list_add(&e->complete, &io->list);
|
||||||
io->context = context;
|
io->context = context;
|
||||||
io->err = r < 0 ? r : 0;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -340,7 +355,7 @@ static bool _sync_wait(struct io_engine *ioe, io_complete_fn fn)
|
|||||||
struct sync_engine *e = _to_sync(ioe);
|
struct sync_engine *e = _to_sync(ioe);
|
||||||
|
|
||||||
dm_list_iterate_items_safe(io, tmp, &e->complete) {
|
dm_list_iterate_items_safe(io, tmp, &e->complete) {
|
||||||
fn(io->context, io->err);
|
fn(io->context, 0);
|
||||||
dm_list_del(&io->list);
|
dm_list_del(&io->list);
|
||||||
dm_free(io);
|
dm_free(io);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user