From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Richard W . M . Jones" <rjones@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>,
"reviewer:Incompatible changes" <libvir-list@redhat.com>,
"open list:Network Block Dev..." <qemu-block@nongnu.org>
Subject: [Qemu-devel] [PULL 1/8] qemu-nbd: Deprecate qemu-nbd --partition
Date: Mon, 4 Feb 2019 21:56:57 -0600 [thread overview]
Message-ID: <20190205035704.26014-2-eblake@redhat.com> (raw)
In-Reply-To: <20190205035704.26014-1-eblake@redhat.com>
The existing qemu-nbd --partition code claims to handle logical
partitions up to 8, since its introduction in 2008 (commit 7a5ca86).
However, the implementation is bogus (actual MBR logical partitions
form a sort of linked list, with one partition per extended table
entry, rather than four logical partitions in a single extended
table), making the code unlikely to work for anything beyond -P5 on
actual guest images. What's more, the code does not support GPT
partitions, which are becoming more popular, and maintaining device
subsetting in both NBD and the raw device is unnecessary duplication
of effort (even if it is not too difficult).
Note that obtaining the offsets of a partition (MBR or GPT) can be
learned by using 'qemu-nbd -c /dev/nbd0 file.qcow2 && sfdisk --dump
/dev/nbd0', but by the time you've done that, you might as well
just mount /dev/nbd0p1 that the kernel creates for you instead of
bothering with qemu exporting a subset. Or, keeping to just
user-space code, use nbdkit's partition filter, which has already
known both GPT and primary MBR partitions for a while, and was
just recently enhanced to support arbitrary logical MBR parititions.
Start the clock on the deprecation cycle, with examples of how
to accomplish device subsetting without using -P.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20190125234837.2272-1-eblake@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
---
qemu-deprecated.texi | 33 +++++++++++++++++++++++++++++++++
qemu-nbd.texi | 6 ++++--
qemu-nbd.c | 2 ++
3 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi
index 9cc20b365c5..8a6174df0c1 100644
--- a/qemu-deprecated.texi
+++ b/qemu-deprecated.texi
@@ -160,3 +160,36 @@ Example of legacy encoding:
The above, converted to the current supported format:
@code{json:@{"file.driver":"rbd", "file.pool":"rbd", "file.image":"name"@}}
+
+@section Related binaries
+
+@subsection qemu-nbd --partition (since 4.0.0)
+
+The ``qemu-nbd --partition $digit'' code (also spelled @option{-P})
+can only handle MBR partitions, and has never correctly handled
+logical partitions beyond partition 5. If you know the offset and
+length of the partition (perhaps by using @code{sfdisk} within the
+guest), you can achieve the effect of exporting just that subset of
+the disk by use of the @option{--image-opts} option with a raw
+blockdev using the @code{offset} and @code{size} parameters layered on
+top of any other existing blockdev. For example, if partition 1 is
+100MiB long starting at 1MiB, the old command:
+
+@code{qemu-nbd -t -P 1 -f qcow2 file.qcow2}
+
+can be rewritten as:
+
+@code{qemu-nbd -t --image-opts driver=raw,offset=1M,size=100M,file.driver=qcow2,file.backing.driver=file,file.backing.filename=file.qcow2}
+
+Alternatively, the @code{nbdkit} project provides a more powerful
+partition filter on top of its nbd plugin, which can be used to select
+an arbitrary MBR or GPT partition on top of any other full-image NBD
+export. Using this to rewrite the above example results in:
+
+@code{qemu-nbd -t -k /tmp/sock -f qcow2 file.qcow2 &}
+@code{nbdkit -f --filter=partition nbd socket=/tmp/sock partition=1}
+
+Note that if you are exposing the export via /dev/nbd0, it is easier
+to just export the entire image and then mount only /dev/nbd0p1 than
+it is to reinvoke @command{qemu-nbd -c /dev/nbd0} limited to just a
+subset of the image.
diff --git a/qemu-nbd.texi b/qemu-nbd.texi
index 386bece4680..d0c51828149 100644
--- a/qemu-nbd.texi
+++ b/qemu-nbd.texi
@@ -56,8 +56,10 @@ auto-detecting.
@item -r, --read-only
Export the disk as read-only.
@item -P, --partition=@var{num}
-Only expose MBR partition @var{num}. Understands physical partitions
-1-4 and logical partitions 5-8.
+Deprecated: Only expose MBR partition @var{num}. Understands physical
+partitions 1-4 and logical partition 5. New code should instead use
+@option{--image-opts} with the raw driver wrapping a subset of the
+original image.
@item -B, --bitmap=@var{name}
If @var{filename} has a qcow2 persistent bitmap @var{name}, expose
that bitmap via the ``qemu:dirty-bitmap:@var{name}'' context
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 1f7b2a03f5d..00c07fd27ea 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -787,6 +787,8 @@ int main(int argc, char **argv)
flags &= ~BDRV_O_RDWR;
break;
case 'P':
+ warn_report("The '-P' option is deprecated; use --image-opts with "
+ "a raw device wrapper for subset exports instead");
if (qemu_strtoi(optarg, NULL, 0, &partition) < 0 ||
partition < 1 || partition > 8) {
error_report("Invalid partition '%s'", optarg);
--
2.20.1
next prev parent reply other threads:[~2019-02-05 3:57 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-05 3:56 [Qemu-devel] [PULL 0/8] NBD patches for 2019-02-04 Eric Blake
2019-02-05 3:56 ` Eric Blake [this message]
2019-02-05 3:56 ` [Qemu-devel] [PULL 2/8] nbd: generalize usage of nbd_read Eric Blake
2019-02-05 3:56 ` [Qemu-devel] [PULL 3/8] block/nbd-client: split channel errors from export errors Eric Blake
2019-02-05 3:57 ` [Qemu-devel] [PULL 4/8] block/nbd: move connection code from block/nbd to block/nbd-client Eric Blake
2019-02-05 3:57 ` [Qemu-devel] [PULL 5/8] block/nbd-client: split connection from initialization Eric Blake
2019-02-05 3:57 ` [Qemu-devel] [PULL 6/8] block/nbd-client: fix nbd_reply_chunk_iter_receive Eric Blake
2019-02-05 3:57 ` [Qemu-devel] [PULL 7/8] block/nbd-client: don't check ioc Eric Blake
2019-02-05 3:57 ` [Qemu-devel] [PULL 8/8] block/nbd-client: rename read_reply_co to connection_co Eric Blake
2019-02-05 4:08 ` [Qemu-devel] [PULL 0/8] NBD patches for 2019-02-04 no-reply
2019-02-05 4:12 ` Eric Blake
2019-02-05 4:08 ` no-reply
2019-02-05 4:11 ` no-reply
2019-02-05 14:01 ` Peter Maydell
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=20190205035704.26014-2-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=libvir-list@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rjones@redhat.com \
--cc=sgarzare@redhat.com \
/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).