qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Richard W.M. Jones" <rjones@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: kwolf@redhat.com, Peter Lieven <pl@kamp.de>,
	qemu-devel@nongnu.org, qemu-block@nongnu.org, mreitz@redhat.com
Subject: Re: [PATCH] qemu-img: add seek and -n option to dd command
Date: Fri, 5 Feb 2021 10:43:39 +0000	[thread overview]
Message-ID: <20210205104339.GD30079@redhat.com> (raw)
In-Reply-To: <3dff97ae-5172-d9ca-509f-2a520c2841b5@redhat.com>

On Thu, Feb 04, 2021 at 02:44:03PM -0600, Eric Blake wrote:
> On 2/4/21 2:09 PM, Peter Lieven wrote:
> > Am 02.02.21 um 16:51 schrieb Eric Blake:
> >> On 1/28/21 8:07 AM, Peter Lieven wrote:
> >>> Signed-off-by: Peter Lieven <pl@kamp.de>
> >> Your commit message says 'what', but not 'why'.  Generally, the one-line
> >> 'what' works well as the subject line, but you want the commit body to
> >> give an argument why your patch should be applied, rather than blank.
> >>
> >> Here's the last time we tried to improve qemu-img dd:
> >> https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg02618.html
> > 
> > 
> > I was not aware of that story. My use case is that I want to be
> > 
> > able to "patch" an image that Qemu is able to handle by overwriting
> > 
> > certain sectors. And I especially do not want to "mount" that image
> > 
> > via qemu-nbd because I might not trust it. I totally want to avoid that the host
> > 
> > system tries to analyse that image in terms of scanning the bootsector, partprobe,
> > 
> > lvm etc. pp.
> 
> qemu-nbd does not have to mount an image (yes, one use of qemu-nbd is to
> use -c /dev/nbdX to get the kernel to mount it; but other uses are to
> expose the NBD image in user-space only with no kernel involvement, and
> therefore no system mount efforts).

I agree, there's nothing unsafe about qemu-nbd (provided you don't use
the -c option).

> Another thing you might try is libnbd, which now includes a utility
> nbdcopy.  It should make it easier to overwrite a portion of an NBD
> image using only user-space actions.  I'm not sure if Rich has got it
> doing partial file overwrites yet (.../me goes and compiles the latest
> git checkout... nope, still a TODO item to implement subsetting), but it
> may be possible to combine nbdkit's --filter=offset with the full NBD
> image in order to then easily point nbdcopy to only the subset you care
> about.  Definitely some ideas worthy of implementation.

TBH I would use nbdsh.  For example to overwrite the sector at 1M in a
qcow2 image with "1"s:

  $ qemu-img create -f qcow2 test.qcow2 10M
  $ nbdsh -c 'h.connect_systemd_socket_activation(["qemu-nbd","-t","-f","qcow2","test.qcow2"])' \
          -c 'h.pwrite(b"1"*512, 1024*1024)'

and to show it was really overwritten:

  $ nbdcopy -- [ qemu-nbd -f qcow2 test.qcow2 ] - | hexdump -C
  00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
  *
  00100000  31 31 31 31 31 31 31 31  31 31 31 31 31 31 31 31  |1111111111111111|
*
  00100200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
  00a00000

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/



  reply	other threads:[~2021-02-05 10:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-28 14:07 [PATCH] qemu-img: add seek and -n option to dd command Peter Lieven
2021-02-02 10:20 ` David Edmondson
2021-02-02 15:51 ` Eric Blake
2021-02-04 20:09   ` Peter Lieven
2021-02-04 20:44     ` Eric Blake
2021-02-05 10:43       ` Richard W.M. Jones [this message]
2021-02-05  8:18     ` Max Reitz
2021-02-05  8:47       ` Peter Lieven
2021-02-05  9:16         ` Max Reitz
2021-02-05 10:06           ` Max Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210205104339.GD30079@redhat.com \
    --to=rjones@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).