On 06/10/2010 04:16 AM, Daniel P. Berrange wrote:
>
> - if (virAsprintf(&dest, "exec:%s | dd of=%s bs=%llu seek=%llu",
> - argstr, safe_target,
> - QEMU_MONITOR_MIGRATE_TO_FILE_BS,
> - offset / QEMU_MONITOR_MIGRATE_TO_FILE_BS) < 0) {
> + /* Two dd processes, sharing the same stdout, are necessary to
> + * allow starting at an alignment of 512, but without wasting
> + * padding to get to the larger alignment useful for speed. */
> + if (virAsprintf(&dest, "exec:%s | { dd bs=%llu seek=%llu if=/dev/null
&& "
> + "dd bs=%llu; } >%s",
Does this work with block devices as the target ? We previously
switched from cat>> to dd, because it didn't work correctly with block
devs.
Yes - the problem with >>dev was that it appended (which doesn't make
sense for a block device); while >dev opens a seekable fd. One
difference between 'dd >file' and 'dd of=file' is which process opens
the device; but to share the fd between two dd invocations, we have to
open the file in the shell rather than with of=file. The other
difference is that >file truncates; for block devices, truncation is a
no-op, but for regular files, this wipes out any pre-existing contents
(such as the header we are skipping over) - is that an issue? If so,
then we should use <>file instead of >file, to open a read-write fd
without forcing truncation (even if we only use the fd for writing).
And from the coreutils manual, 'info dd', this example validates the use
of dual dd invocations on a block device (although it goes the opposite
direction with a seek larger than the transfer size):
Use different `dd' invocations to use different block sizes for
skipping and I/O. For example, the following shell commands copy data
in 512 KiB blocks between a disk and a tape, but do not save or restore
a 4 KiB label at the start of the disk:
disk=/dev/rdsk/c0t1d0s2
tape=/dev/rmt/0
# Copy all but the label from disk to tape.
(dd bs=4k skip=1 count=0 && dd bs=512k) <$disk >$tape
# Copy from tape back to disk, but leave the disk label alone.
(dd bs=4k seek=1 count=0 && dd bs=512k) <$tape >$disk
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org