Compare commits
2 Commits
contributi
...
fix_fuse_d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd0b71bca0 | ||
|
|
dc571a5811 |
@@ -1,12 +1,8 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const LRU = require('lru-cache')
|
const LRU = require('lru-cache')
|
||||||
const Fuse = require('fuse-native')
|
|
||||||
const { VhdSynthetic } = require('vhd-lib')
|
const { VhdSynthetic } = require('vhd-lib')
|
||||||
const { Disposable, fromCallback } = require('promise-toolbox')
|
const { Disposable, fromCallback } = require('promise-toolbox')
|
||||||
const { createLogger } = require('@xen-orchestra/log')
|
|
||||||
|
|
||||||
const { warn } = createLogger('vates:fuse-vhd')
|
|
||||||
|
|
||||||
// build a s stat object from https://github.com/fuse-friends/fuse-native/blob/master/test/fixtures/stat.js
|
// build a s stat object from https://github.com/fuse-friends/fuse-native/blob/master/test/fixtures/stat.js
|
||||||
const stat = st => ({
|
const stat = st => ({
|
||||||
@@ -20,6 +16,7 @@ const stat = st => ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
exports.mount = Disposable.factory(async function* mount(handler, diskPath, mountDir) {
|
exports.mount = Disposable.factory(async function* mount(handler, diskPath, mountDir) {
|
||||||
|
const Fuse = require('fuse-native')
|
||||||
const vhd = yield VhdSynthetic.fromVhdChain(handler, diskPath)
|
const vhd = yield VhdSynthetic.fromVhdChain(handler, diskPath)
|
||||||
|
|
||||||
const cache = new LRU({
|
const cache = new LRU({
|
||||||
@@ -57,9 +54,7 @@ exports.mount = Disposable.factory(async function* mount(handler, diskPath, moun
|
|||||||
},
|
},
|
||||||
read(path, fd, buf, len, pos, cb) {
|
read(path, fd, buf, len, pos, cb) {
|
||||||
if (path === '/vhd0') {
|
if (path === '/vhd0') {
|
||||||
return vhd
|
return vhd.readRawData(pos, len, cache, buf).then(cb)
|
||||||
.readRawData(pos, len, cache, buf)
|
|
||||||
.then(cb)
|
|
||||||
}
|
}
|
||||||
throw new Error(`read file ${path} not exists`)
|
throw new Error(`read file ${path} not exists`)
|
||||||
},
|
},
|
||||||
@@ -67,5 +62,5 @@ exports.mount = Disposable.factory(async function* mount(handler, diskPath, moun
|
|||||||
return new Disposable(
|
return new Disposable(
|
||||||
() => fromCallback(() => fuse.unmount()),
|
() => fromCallback(() => fuse.unmount()),
|
||||||
fromCallback(() => fuse.mount())
|
fromCallback(() => fuse.mount())
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -19,11 +19,13 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@xen-orchestra/log": "^0.3.0",
|
"@xen-orchestra/log": "^0.3.0",
|
||||||
"fuse-native": "^2.2.6",
|
|
||||||
"lru-cache": "^7.14.0",
|
"lru-cache": "^7.14.0",
|
||||||
"promise-toolbox": "^0.21.0",
|
"promise-toolbox": "^0.21.0",
|
||||||
"vhd-lib": "^4.0.1"
|
"vhd-lib": "^4.0.1"
|
||||||
},
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"fuse-native": "^2.2.6"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postversion": "npm publish --access public"
|
"postversion": "npm publish --access public"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,10 +28,8 @@ const { isMetadataFile } = require('./_backupType.js')
|
|||||||
const { isValidXva } = require('./_isValidXva.js')
|
const { isValidXva } = require('./_isValidXva.js')
|
||||||
const { listPartitions, LVM_PARTITION_TYPE } = require('./_listPartitions.js')
|
const { listPartitions, LVM_PARTITION_TYPE } = require('./_listPartitions.js')
|
||||||
const { lvs, pvs } = require('./_lvm.js')
|
const { lvs, pvs } = require('./_lvm.js')
|
||||||
// @todo : this import is marked extraneous , sould be fixed when lib is published
|
|
||||||
const { mount } = require('@vates/fuse-vhd')
|
|
||||||
const { asyncEach } = require('@vates/async-each')
|
const { asyncEach } = require('@vates/async-each')
|
||||||
|
const { mount } = require('@vates/fuse-vhd')
|
||||||
const DIR_XO_CONFIG_BACKUPS = 'xo-config-backups'
|
const DIR_XO_CONFIG_BACKUPS = 'xo-config-backups'
|
||||||
exports.DIR_XO_CONFIG_BACKUPS = DIR_XO_CONFIG_BACKUPS
|
exports.DIR_XO_CONFIG_BACKUPS = DIR_XO_CONFIG_BACKUPS
|
||||||
|
|
||||||
@@ -76,14 +74,16 @@ const debounceResourceFactory = factory =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
class RemoteAdapter {
|
class RemoteAdapter {
|
||||||
constructor(handler, { debounceResource = res => res, dirMode, vhdDirectoryCompression, useGetDiskLegacy=false } = {}) {
|
constructor(
|
||||||
|
handler,
|
||||||
|
{ debounceResource = res => res, dirMode, vhdDirectoryCompression, useGetDiskLegacy = false } = {}
|
||||||
|
) {
|
||||||
this._debounceResource = debounceResource
|
this._debounceResource = debounceResource
|
||||||
this._dirMode = dirMode
|
this._dirMode = dirMode
|
||||||
this._handler = handler
|
this._handler = handler
|
||||||
this._vhdDirectoryCompression = vhdDirectoryCompression
|
this._vhdDirectoryCompression = vhdDirectoryCompression
|
||||||
this._readCacheListVmBackups = synchronized.withKey()(this._readCacheListVmBackups)
|
this._readCacheListVmBackups = synchronized.withKey()(this._readCacheListVmBackups)
|
||||||
this._useGetDiskLegacy = useGetDiskLegacy
|
this._useGetDiskLegacy = useGetDiskLegacy
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get handler() {
|
get handler() {
|
||||||
@@ -324,9 +324,7 @@ class RemoteAdapter {
|
|||||||
return this.#useVhdDirectory()
|
return this.#useVhdDirectory()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async *#getDiskLegacy(diskId) {
|
async *#getDiskLegacy(diskId) {
|
||||||
|
|
||||||
const RE_VHDI = /^vhdi(\d+)$/
|
const RE_VHDI = /^vhdi(\d+)$/
|
||||||
const handler = this._handler
|
const handler = this._handler
|
||||||
|
|
||||||
@@ -358,15 +356,25 @@ class RemoteAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async *getDisk(diskId) {
|
async *getDisk(diskId) {
|
||||||
if(this._useGetDiskLegacy){
|
if (this._useGetDiskLegacy) {
|
||||||
yield * this.#getDiskLegacy(diskId)
|
yield* this.#getDiskLegacy(diskId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const handler = this._handler
|
const handler = this._handler
|
||||||
// this is a disposable
|
// this is a disposable
|
||||||
const mountDir = yield getTmpDir()
|
const mountDir = yield getTmpDir()
|
||||||
// this is also a disposable
|
|
||||||
yield mount(handler, diskId, mountDir)
|
try {
|
||||||
|
// this is also a disposable
|
||||||
|
yield mount(handler, diskId, mountDir)
|
||||||
|
} catch (error) {
|
||||||
|
// fallback in case of missing dependency
|
||||||
|
if (error.code === 'MODULE_NOT_FOUND') {
|
||||||
|
yield* this.#getDiskLegacy(diskId)
|
||||||
|
} else {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
// this will yield disk path to caller
|
// this will yield disk path to caller
|
||||||
yield `${mountDir}/vhd0`
|
yield `${mountDir}/vhd0`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user