Skip to content

Commit f90a884

Browse files
committed
Add a new option, --data-source [Fixes GH#10, GH#17]
Specify a different block device to read from. Not something I'd be inclined to use myself, but when two people take the time to submit PRs for the same issue, clearly there's demand for it.
1 parent 6cbdd6e commit f90a884

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

bin/lvmsync

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def main()
6161
options[:stdout] = true
6262
end
6363

64+
opts.on("-r", "--data-source", "Read data blocks from a block device other than the snapshot origin") do |v|
65+
options[:source] = v
66+
end
67+
6468
opts.on("-V", "--version", "Print version of lvmsync") do |v|
6569
begin
6670
puts "lvmsync #{GVB.version}"
@@ -189,8 +193,6 @@ def run_client(opts)
189193
exit 1
190194
end
191195

192-
$stderr.puts "Origin device: #{lv.origin.path}" if opts[:verbose]
193-
194196
# Since, in principle, we're not supposed to be reading from snapshot
195197
# devices directly, the kernel makes no attempt to make the device's read
196198
# cache stay in sync with the actual state of the device. As a result,
@@ -200,8 +202,11 @@ def run_client(opts)
200202

201203
snapback = opts[:snapback] ? "--snapback #{opts[:snapback]}" : ''
202204

205+
source = opts[:source] || lv.origin.path
206+
$stderr.puts "Data source: #{source}" if opts[:verbose]
207+
203208
if opts[:stdout]
204-
dump_changes(lv, $stdout, opts)
209+
dump_changes(lv, source, $stdout, opts)
205210
else
206211
verbose = opts[:verbose] ? '-v' : ''
207212
server_cmd = if desthost
@@ -216,7 +221,7 @@ def run_client(opts)
216221
Open3.popen3(server_cmd) do |stdin_fd, stdout_fd, stderr_fd, wait_thr|
217222
fds = [stdout_fd, stderr_fd]
218223

219-
dump_changes(lv, stdin_fd, opts) do
224+
dump_changes(lv, source, stdin_fd, opts) do
220225
# Remember that this fires between *every* block sent to the
221226
# receiver, so don't do anything particularly slow in here!
222227
until (active_fds = IO.select(fds, [], [], 0)).nil?
@@ -257,23 +262,23 @@ def run_client(opts)
257262
end
258263
end
259264

260-
def dump_changes(lv, outfd, opts)
265+
def dump_changes(snapshot, source, outfd, opts)
261266
outfd.puts PROTOCOL_VERSION
262267

263268
start_time = Time.now
264269
xfer_count = 0
265270
xfer_size = 0
266271
total_size = 0
267-
change_count = lv.changes.length
272+
change_count = snapshot.changes.length
268273

269-
File.open(lv.origin.path, 'r') do |origindev|
270-
lv.changes.each do |r|
274+
File.open(source, 'r') do |origindev|
275+
snapshot.changes.each do |r|
271276
xfer_count += 1
272277
chunk_size = r.last - r.first + 1
273278
xfer_size += chunk_size
274279

275280
$stderr.puts "Sending chunk #{r.to_s}..." if opts[:verbose]
276-
$stderr.puts "Seeking to #{r.first} in #{lv.origin.path}" if opts[:verbose]
281+
$stderr.puts "Seeking to #{r.first} in #{source}" if opts[:verbose]
277282

278283
origindev.seek(r.first, IO::SEEK_SET)
279284

0 commit comments

Comments
 (0)