Skip to content

Commit

Permalink
Fill / persist all iovecs in FileDisk.request.
Browse files Browse the repository at this point in the history
Change-Type: patch
  • Loading branch information
zvin committed Mar 23, 2017
1 parent bd54afa commit 88890da
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions lib/disk.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ class FileDisk extends EventEmitter {

switch (type) {
case constants.LKL_DEV_BLK_TYPE_READ:
// FIXME: we have to fill all the iovecs, not just the first
fs.read(this.fd, iovecs[0], 0, iovecs[0].length, offset, callback);
this._readWriteAllIovecs(fs.read, iovecs, offset, callback);
break;
case constants.LKL_DEV_BLK_TYPE_WRITE:
// FIXME: we have to persist all the iovecs, not just the first
fs.write(this.fd, iovecs[0], 0, iovecs[0].length, offset, callback);
this._readWriteAllIovecs(fs.write, iovecs, offset, callback);
break;
case constants.LKL_DEV_BLK_TYPE_FLUSH:
case constants.LKL_DEV_BLK_TYPE_FLUSH_OUT:
Expand All @@ -65,6 +63,35 @@ class FileDisk extends EventEmitter {
callback(null, stat.size);
});
};

_readWriteAllIovecs(fn, iovecs, offset, callback, iovecIndex) {
iovecIndex = (iovecIndex === undefined) ? 0 : iovecIndex;
fn(
this.fd,
iovecs[iovecIndex],
0,
iovecs[iovecIndex].length,
offset,
function(err, bytesCount, buf) {
if (err) {
// An error happened: errback.
callback(err.errno);
} else if (iovecIndex === iovecs.length - 1) {
// All iovecs are filled / persisted: callback.
callback(null);
} else {
// There are iovecs left: continue reading / writing.
this._readWriteAllIovecs(
fn,
iovecs,
offset + bytesCount,
callback,
iovecIndex + 1
);
}
}.bind(this)
);
};
}

exports.FileDisk = FileDisk;

0 comments on commit 88890da

Please sign in to comment.