remove writeBlankRange()

(keeping it for another branch)
This commit is contained in:
Nicolas Raynaud
2020-10-29 03:16:47 +01:00
parent 3dee6f4247
commit 69267d0d04
3 changed files with 3 additions and 60 deletions

View File

@@ -97,8 +97,6 @@ export default class MountHandler extends LocalHandler {
}
}
await this._testWriteBlankRange()
// keep an open file on the mount to prevent it from being unmounted if used
// by another handler/process
const keeperPath = `${realPath}/.keeper_${Math.random()

View File

@@ -333,15 +333,6 @@ export default class RemoteHandlerAbstract {
await this._write(fdOut, buffer, offsetOut)
}
/**
* Writes a succession of zero bytes in a file, server side, and with sparse FS support if possible so that it
* doesn't take space.
*
*/
async writeBlankRange(fd, offset, blankLength) {
await this._write(fd, Buffer.alloc(blankLength), offset)
}
async readFile(
file: string,
{ flags = 'r' }: { flags?: string } = {}
@@ -389,8 +380,6 @@ export default class RemoteHandlerAbstract {
async test(): Promise<Object> {
const SIZE = 1024 * 1024 * 100
const HOLE_SIZE = 1024 * 1024 * 2
const HOLE_OFFSET = 30
const now = Date.now()
const testFileName = normalizePath(`${now}.test`)
const testFileName2 = normalizePath(`${now}__dup.test`)
@@ -401,16 +390,15 @@ export default class RemoteHandlerAbstract {
const writeStart = process.hrtime()
await this._outputFile(testFileName, data, { flags: 'wx' })
const writeDuration = process.hrtime(writeStart)
let cloneDuration
const fd1 = await this.openFile(testFileName, 'r+')
try {
step = 'punch hole'
await this.writeBlankRange(fd1, HOLE_OFFSET, HOLE_SIZE)
const fd2 = await this.openFile(testFileName2, 'wx')
try {
step = 'duplicate'
const cloneStart = process.hrtime()
await this.copyFileRange(fd1, 0, fd2, 0, data.byteLength)
const cloneDuration = process.hrtime(cloneStart)
cloneDuration = process.hrtime(cloneStart)
console.log('cloneDuration', cloneDuration)
} finally {
await this._closeFile(fd2)
@@ -423,8 +411,6 @@ export default class RemoteHandlerAbstract {
const readStart = process.hrtime()
const read = await this._readFile(testFileName, { flags: 'r' })
const readDuration = process.hrtime(readStart)
// put the hole in the expected data
data.fill(0, HOLE_OFFSET, HOLE_OFFSET + HOLE_SIZE)
if (!data.equals(read)) {
throw new Error('output and input did not match')
}
@@ -437,9 +423,9 @@ export default class RemoteHandlerAbstract {
success: true,
writeRate: computeRate(writeDuration, SIZE),
readRate: computeRate(readDuration, SIZE),
cloneDuration: computeRate(cloneDuration, SIZE),
}
} catch (error) {
console.log('ERROR', error)
return {
success: false,
step,

View File

@@ -28,19 +28,6 @@ function copyFileRangeSyscall(fdIn, offsetIn, fdOut, offsetOut, dataLen, flags =
return copied
}
const FALLOC_FL_PUNCH_HOLE = 0x02
const FALLOC_FL_KEEP_SIZE = 0x01
const FALLOC_FL_ZERO_RANGE = 0x10
function fAllocateSyscall(fd, mode, offset, length) {
// https://man7.org/linux/man-pages/man2/fallocate.2.html
const SYS_fallocate = 285
const [result, _, errno] = Syscall6(SYS_fallocate, fd, mode, offset, length)
if (result === -1) {
throw new Error('Error no ' + errno)
}
}
export default class LocalHandler extends RemoteHandlerAbstract {
constructor(remote: any, options: Object = {}) {
super(remote, options)
@@ -143,33 +130,6 @@ export default class LocalHandler extends RemoteHandlerAbstract {
} while (dataLen - copied > 0)
}
async writeBlankRange(fd, offset, blankLength) {
if (this._canFallocate) {
await fAllocateSyscall(fd.fd, FALLOC_FL_ZERO_RANGE, offset, blankLength)
} else {
await super.writeBlankRange(fd, offset, blankLength)
}
}
async _testWriteBlankRange() {
const path = this._getFilePath('test_fallocate.test')
const fd = await fs.open(path, 'w')
try {
await fAllocateSyscall(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 6000)
console.log('can fallocate')
this._canFallocate = true
} catch (e) {
console.log('cant fallocate', e)
this._canFallocate = false
} finally {
try {
await fs.close(fd)
} finally {
await this.unlink(path)
}
}
}
async _read(file, buffer, position) {
const needsClose = typeof file === 'string'
file = needsClose ? await fs.open(this._getFilePath(file), 'r') : file.fd
@@ -204,7 +164,6 @@ export default class LocalHandler extends RemoteHandlerAbstract {
const path = this._getRealPath('/')
await fs.ensureDir(path)
await fs.access(path, fs.R_OK | fs.W_OK)
await this._testWriteBlankRange()
}
_truncate(file, len) {