From patchwork Mon Aug 10 12:35:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 1342821 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=openvz.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BQFnt74WGz9sRN for ; Mon, 10 Aug 2020 22:36:33 +1000 (AEST) Received: from localhost ([::1]:36708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k572T-0002sA-BH for incoming@patchwork.ozlabs.org; Mon, 10 Aug 2020 08:36:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35284) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k5723-0002qq-Oy; Mon, 10 Aug 2020 08:36:03 -0400 Received: from relay.sw.ru ([185.231.240.75]:58140 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k5720-0002NM-SU; Mon, 10 Aug 2020 08:36:03 -0400 Received: from [192.168.15.81] (helo=iris.lishka.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k571m-0002Gz-Qk; Mon, 10 Aug 2020 15:35:46 +0300 From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH for 5.2 1/1] qemu-io: add -V flag for read sub-command Date: Mon, 10 Aug 2020 15:35:55 +0300 Message-Id: <20200810123555.30481-1-den@openvz.org> X-Mailer: git-send-email 2.17.1 Received-SPF: pass client-ip=185.231.240.75; envelope-from=den@openvz.org; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/10 08:35:57 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , "Richard W . M . Jones" , Max Reitz , Andrey Shinkevich , "Denis V. Lunev" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The problem this patch is trying to address is libguestfs behavior on the appliance startup. It starts supporting to use root=UUID definition in the kernel command line of its root filesystem using file -- /usr/lib64/guestfs/appliance/root This works fine with RAW image, but we are using QCOW2 as a storage to save a bit of file space and in this case we get QEMU QCOW Image (v3), 1610612736 bytes instead of UUID of the root filesystem. The solution is very simple - we should dump first 256k of the image file like the follows qemu-io -c "read -V 0 256k" appliance | file - which will provide correct result for all possible types of the appliance storage. Unfortunately, additional option for qemu-io is the only and the simplest solution as '-v' creates very specific output, which requires to be parsed. 'qemu-img dd of=/dev/stdout' does not work and the fix would be much more intrusive. Signed-off-by: Denis V. Lunev CC: Andrey Shinkevich CC: Vladimir Sementsov-Ogievskiy CC: Kevin Wolf CC: Max Reitz CC: Richard W.M. Jones Reviewed-by: Vladimir Sementsov-Ogievskiy --- P.S. Patch to libguestfs will follow. qemu-io-cmds.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index baeae86d8c..7aae9726cd 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -718,7 +718,7 @@ static const cmdinfo_t read_cmd = { .cfunc = read_f, .argmin = 2, .argmax = -1, - .args = "[-abCqv] [-P pattern [-s off] [-l len]] off len", + .args = "[-abCqvV] [-P pattern [-s off] [-l len]] off len", .oneline = "reads a number of bytes at a specified offset", .help = read_help, }; @@ -728,6 +728,7 @@ static int read_f(BlockBackend *blk, int argc, char **argv) struct timespec t1, t2; bool Cflag = false, qflag = false, vflag = false; bool Pflag = false, sflag = false, lflag = false, bflag = false; + bool vrawflag = true; int c, cnt, ret; char *buf; int64_t offset; @@ -737,7 +738,7 @@ static int read_f(BlockBackend *blk, int argc, char **argv) int pattern = 0; int64_t pattern_offset = 0, pattern_count = 0; - while ((c = getopt(argc, argv, "bCl:pP:qs:v")) != -1) { + while ((c = getopt(argc, argv, "bCl:pP:qs:vV")) != -1) { switch (c) { case 'b': bflag = true; @@ -777,6 +778,9 @@ static int read_f(BlockBackend *blk, int argc, char **argv) case 'v': vflag = true; break; + case 'V': + vrawflag = true; + break; default: qemuio_command_usage(&read_cmd); return -EINVAL; @@ -869,10 +873,15 @@ static int read_f(BlockBackend *blk, int argc, char **argv) if (vflag) { dump_buffer(buf, offset, count); } + if (vrawflag) { + write(STDOUT_FILENO, buf, count); + } /* Finally, report back -- -C gives a parsable format */ - t2 = tsub(t2, t1); - print_report("read", &t2, offset, count, total, cnt, Cflag); + if (!vrawflag) { + t2 = tsub(t2, t1); + print_report("read", &t2, offset, count, total, cnt, Cflag); + } out: qemu_io_free(buf);