mirror of
https://github.com/OpenNebula/one.git
synced 2026-12-01 20:56:42 +09:00
F OpenNebula/one#8230: optimize /extent endpoint for RBD and NBD OneBEX exporters (#4667)
This commit is contained in:
1 parent
c8ceea5627
commit
bc4ec22d69
2 files changed
+32
-13
No files matched your search
@@ -233,14 +233,14 @@ module OneBEX
|
||||
|
||||
# Converts an nbdinfo extent hash to the API block format.
|
||||
def block(extent)
|
||||
description = extent['description'].to_s.downcase
|
||||
flags = extent['description'].to_s.downcase.split(',')
|
||||
|
||||
{
|
||||
:start => extent['offset'].to_i,
|
||||
:length => extent['length'].to_i,
|
||||
:dirty => description == 'dirty',
|
||||
:zero => description == 'zero',
|
||||
:hole => description == 'hole'
|
||||
:dirty => flags.include?('dirty'),
|
||||
:zero => flags.include?('zero'),
|
||||
:hole => flags.include?('hole')
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'fileutils'
|
||||
require 'json'
|
||||
require 'open3'
|
||||
require 'timeout'
|
||||
|
||||
@@ -128,15 +129,7 @@ module OneBEX
|
||||
def blocks(xfr)
|
||||
case xfr[:mode]
|
||||
when 'full'
|
||||
[
|
||||
{
|
||||
:start => 0,
|
||||
:length => size_bytes(xfr),
|
||||
:dirty => true,
|
||||
:zero => false,
|
||||
:hole => false
|
||||
}
|
||||
]
|
||||
extents(xfr[:uri]).map {|extent| block(extent) }
|
||||
when 'incremental'
|
||||
diff_parser(xfr).records
|
||||
else
|
||||
@@ -222,6 +215,32 @@ module OneBEX
|
||||
|
||||
private
|
||||
|
||||
# Queries nbdinfo for allocation extents.
|
||||
def extents(uri)
|
||||
stdout, stderr, status = Open3.capture3(
|
||||
'nbdinfo', uri, '--json', '--map'
|
||||
)
|
||||
|
||||
unless status.success?
|
||||
raise "nbdinfo failed for #{uri}: #{stderr}"
|
||||
end
|
||||
|
||||
JSON.parse(stdout).compact
|
||||
end
|
||||
|
||||
# Converts an nbdinfo extent hash to the API block format.
|
||||
def block(extent)
|
||||
flags = extent['description'].to_s.downcase.split(',')
|
||||
|
||||
{
|
||||
:start => extent['offset'].to_i,
|
||||
:length => extent['length'].to_i,
|
||||
:dirty => true,
|
||||
:zero => flags.include?('zero'),
|
||||
:hole => flags.include?('hole')
|
||||
}
|
||||
end
|
||||
|
||||
# Parses and caches the RBD diff file.
|
||||
def diff_parser(xfr)
|
||||
xfr[:diff_parser] ||= RbdDiffParser.new(
|
||||
|
||||
Reference in new issue
Block a user