From nobody Sun Oct 5 19:23:35 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589819642; cv=none; d=zohomail.com; s=zohoarc; b=f2Q8OO137LGHI80svv8O98i5dbl/rsxbD4+Cpf4N3ro0kQXmdOVJ9cDT7oQaHjYwPc7P54zVb4rkdwt0GA2PJIKrkrMZ1IoIwYzrgKyl8kLqHzhdD7DwOxd5CBPIikrK3lQyavMDc21LI/dsFttYAK7taY1aUhokOLsOeyUWbao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589819642; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=o+juXcJOAG82/3PgIt7OdR8p9Z6Nh/+OtN61JebXt68=; b=V8fYoDppaaJeC8Q4w23LWnIBt9r5Ojgja/esfuJyI+5AwkjpCnujXQaYA0AoxCOxNlm0/Mjxxb8Z0UtyNql1qcAvbZIZ1qzrFO0N7zBnfMAEhT5uG5Hi7dEw1+y21A9tz6C0OfBzXO5horcZe63eIGydscCFn78Aj2oZdcVhhw0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589819642882327.0573255836972; Mon, 18 May 2020 09:34:02 -0700 (PDT) Received: from localhost ([::1]:45236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jaiiH-0007B1-HQ for importer@patchew.org; Mon, 18 May 2020 12:34:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58692) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jaigl-0005Do-JZ for qemu-devel@nongnu.org; Mon, 18 May 2020 12:32:27 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:38196 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jaigk-0003DM-KF for qemu-devel@nongnu.org; Mon, 18 May 2020 12:32:27 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-310-NmOhcSM8OBW-NsMvcyfL0g-1; Mon, 18 May 2020 12:32:22 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2260E107ACCA; Mon, 18 May 2020 16:32:21 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-88.phx2.redhat.com [10.3.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id A324C5D9DC; Mon, 18 May 2020 16:32:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589819545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o+juXcJOAG82/3PgIt7OdR8p9Z6Nh/+OtN61JebXt68=; b=H7ql2V4YjuK57KvSuABVQNCeGbwMrzpNdBi4BSNv/crEXiXE907q937bUZ94iqUVAa+hFS dvnRJxsx1Kuf5+zKldb7PZNdKLKZDvHCcZlhmFwfv7SmzUtNLR9385OQ1gyS8yPKZtcp2U MKQEtd2UxNoHUH9CTta5K39TR6YlNC4= X-MC-Unique: NmOhcSM8OBW-NsMvcyfL0g-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 1/6] qemu-nbd: Close inherited stderr Date: Mon, 18 May 2020 11:32:13 -0500 Message-Id: <20200518163218.649412-2-eblake@redhat.com> In-Reply-To: <20200518163218.649412-1-eblake@redhat.com> References: <20200518163218.649412-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=eblake@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/17 22:51:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: "open list:Network Block Dev..." , Raphael Pour Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Raphael Pour Close inherited stderr of the parent if fork_process is false. Otherwise no one will close it. (introduced by e6df58a5) This only affected 'qemu-nbd -c /dev/nbd0'. Signed-off-by: Raphael Pour Message-Id: Reviewed-by: Eric Blake [eblake: Enhance commit message] Signed-off-by: Eric Blake --- qemu-nbd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 4aa005004ebd..306e44fb0a4b 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -916,7 +916,11 @@ int main(int argc, char **argv) } else if (pid =3D=3D 0) { close(stderr_fd[0]); - old_stderr =3D dup(STDERR_FILENO); + /* Remember parent's stderr if we will be restoring it. */ + if (fork_process) { + old_stderr =3D dup(STDERR_FILENO); + } + ret =3D qemu_daemon(1, 0); /* Temporarily redirect stderr to the parent's pipe... */ --=20 2.26.2 From nobody Sun Oct 5 19:23:35 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589819762; cv=none; d=zohomail.com; s=zohoarc; b=Gl4iFRzlEZuWbzpHljAzys0mxSCkKMqvIf2aGWEEk/0KNI02kEIyZHUGsXaLKZ03++otTsNE55HUVRosKMVyS1019QTRTi6Du7r8A7fbCYq9a8/40+aoJAQiH95//Ww10rE9Sh4WJSh0Ck6Ioc32h/M5AA/TdpX0KZmungliHUI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589819762; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oii076EEtIpLbw2zbK/UeFHcdIxo/eOwUrg1PeUKOQo=; b=LM3bMT/dSaod8XntMIyaagaZargPrYFXJs3ojCwyOK81SFrwtsHG5YSaDrWN1/wgAzsIqf2RCgn6gNv1H4VFpKWumqI+H8Eu398wDA91F4KEu6+1kG7Op8va03Z5kLQO9yVcf6YqY3X2pa0P/FvTusBGfqQ/glUSYPeO5ejR0Eg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158981976227528.16254060163294; Mon, 18 May 2020 09:36:02 -0700 (PDT) Received: from localhost ([::1]:51762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jaikD-0001Zj-0Y for importer@patchew.org; Mon, 18 May 2020 12:36:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jaign-0005IH-1s for qemu-devel@nongnu.org; Mon, 18 May 2020 12:32:29 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:37220 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jaigk-0003DS-N0 for qemu-devel@nongnu.org; Mon, 18 May 2020 12:32:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-335-uUGmwDcHMvmY0_j0MYoOTA-1; Mon, 18 May 2020 12:32:22 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D311B107ACF7; Mon, 18 May 2020 16:32:21 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-88.phx2.redhat.com [10.3.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52F9A5D9DC; Mon, 18 May 2020 16:32:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589819545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oii076EEtIpLbw2zbK/UeFHcdIxo/eOwUrg1PeUKOQo=; b=Chq74P1oUXwQk+Az6fyM0Myzmw2/i6DJWt29Sj4VCx/K0xvSvYPyR9po66bzklGeSLhajK uFYLwVaC+URSP3EKzWVLkEKvFc5c/4QRIO/BQxa1CukoilGMIbd3NQ7zrp2q0AJORsTsSk Ks64ouFkDHCWPJ6JaelRXcHQtJLzMuQ= X-MC-Unique: uUGmwDcHMvmY0_j0MYoOTA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 2/6] qemu_img: add cvtnum_full to print error reports Date: Mon, 18 May 2020 11:32:14 -0500 Message-Id: <20200518163218.649412-3-eblake@redhat.com> In-Reply-To: <20200518163218.649412-1-eblake@redhat.com> References: <20200518163218.649412-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.81; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/17 22:52:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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 , Eyal Moscovici , "open list:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Eyal Moscovici All calls to cvtnum check the return value and print the same error message more or less. And so error reporting moved to cvtnum_full to reduce code duplication and provide a single error message. Additionally, cvtnum now wraps cvtnum_full with the existing default range of 0 to MAX_INT64. Acked-by: Mark Kanda Signed-off-by: Eyal Moscovici Message-Id: <20200513133629.18508-2-eyal.moscovici@oracle.com> Reviewed-by: Eric Blake [eblake: fix printf formatting, avoid trailing space, change error wording, reformat commit message] Signed-off-by: Eric Blake --- qemu-img.c | 74 +++++++++++++++++--------------------- tests/qemu-iotests/049.out | 8 ++--- 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 6a4327aaba56..5d824fc15f39 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -470,19 +470,31 @@ static int add_old_style_options(const char *fmt, Qem= uOpts *opts, return 0; } -static int64_t cvtnum(const char *s) +static int64_t cvtnum_full(const char *name, const char *value, int64_t mi= n, + int64_t max) { int err; - uint64_t value; + uint64_t res; - err =3D qemu_strtosz(s, NULL, &value); - if (err < 0) { + err =3D qemu_strtosz(value, NULL, &res); + if (err < 0 && err !=3D -ERANGE) { + error_report("Invalid %s specified. You may use " + "k, M, G, T, P or E suffixes for", name); + error_report("kilobytes, megabytes, gigabytes, terabytes, " + "petabytes and exabytes."); return err; } - if (value > INT64_MAX) { + if (err =3D=3D -ERANGE || res > max || res < min) { + error_report("Invalid %s specified. Must be between %" PRId64 + " and %" PRId64 ".", name, min, max); return -ERANGE; } - return value; + return res; +} + +static int64_t cvtnum(const char *name, const char *value) +{ + return cvtnum_full(name, value, 0, INT64_MAX); } static int img_create(int argc, char **argv) @@ -572,16 +584,8 @@ static int img_create(int argc, char **argv) if (optind < argc) { int64_t sval; - sval =3D cvtnum(argv[optind++]); + sval =3D cvtnum("image size", argv[optind++]); if (sval < 0) { - if (sval =3D=3D -ERANGE) { - error_report("Image size must be less than 8 EiB!"); - } else { - error_report("Invalid image size specified! You may use k,= M, " - "G, T, P or E suffixes for "); - error_report("kilobytes, megabytes, gigabytes, terabytes, " - "petabytes and exabytes."); - } goto fail; } img_size =3D (uint64_t)sval; @@ -2187,8 +2191,10 @@ static int img_convert(int argc, char **argv) { int64_t sval; - sval =3D cvtnum(optarg); - if (sval < 0 || !QEMU_IS_ALIGNED(sval, BDRV_SECTOR_SIZE) || + sval =3D cvtnum("buffer size for sparse output", optarg); + if (sval < 0) { + goto fail_getopt; + } else if (!QEMU_IS_ALIGNED(sval, BDRV_SECTOR_SIZE) || sval / BDRV_SECTOR_SIZE > MAX_BUF_SECTORS) { error_report("Invalid buffer size for sparse output specif= ied. " "Valid sizes are multiples of %llu up to %llu. Select " @@ -4291,9 +4297,8 @@ static int img_bench(int argc, char **argv) break; case 'o': { - offset =3D cvtnum(optarg); + offset =3D cvtnum("offset", optarg); if (offset < 0) { - error_report("Invalid offset specified"); return 1; } break; @@ -4306,9 +4311,8 @@ static int img_bench(int argc, char **argv) { int64_t sval; - sval =3D cvtnum(optarg); - if (sval < 0 || sval > INT_MAX) { - error_report("Invalid buffer size specified"); + sval =3D cvtnum_full("buffer size", optarg, 0, INT_MAX); + if (sval < 0) { return 1; } @@ -4319,9 +4323,8 @@ static int img_bench(int argc, char **argv) { int64_t sval; - sval =3D cvtnum(optarg); - if (sval < 0 || sval > INT_MAX) { - error_report("Invalid step size specified"); + sval =3D cvtnum_full("step_size", optarg, 0, INT_MAX); + if (sval < 0) { return 1; } @@ -4491,10 +4494,9 @@ static int img_dd_bs(const char *arg, { int64_t res; - res =3D cvtnum(arg); + res =3D cvtnum_full("bs", arg, 1, INT_MAX); - if (res <=3D 0 || res > INT_MAX) { - error_report("invalid number: '%s'", arg); + if (res < 0) { return 1; } in->bsz =3D out->bsz =3D res; @@ -4506,10 +4508,9 @@ static int img_dd_count(const char *arg, struct DdIo *in, struct DdIo *out, struct DdInfo *dd) { - dd->count =3D cvtnum(arg); + dd->count =3D cvtnum("count", arg); if (dd->count < 0) { - error_report("invalid number: '%s'", arg); return 1; } @@ -4538,10 +4539,9 @@ static int img_dd_skip(const char *arg, struct DdIo *in, struct DdIo *out, struct DdInfo *dd) { - in->offset =3D cvtnum(arg); + in->offset =3D cvtnum("skip", arg); if (in->offset < 0) { - error_report("invalid number: '%s'", arg); return 1; } @@ -4923,16 +4923,8 @@ static int img_measure(int argc, char **argv) { int64_t sval; - sval =3D cvtnum(optarg); + sval =3D cvtnum("image size", optarg); if (sval < 0) { - if (sval =3D=3D -ERANGE) { - error_report("Image size must be less than 8 EiB!"); - } else { - error_report("Invalid image size specified! You may us= e " - "k, M, G, T, P or E suffixes for "); - error_report("kilobytes, megabytes, gigabytes, terabyt= es, " - "petabytes and exabytes."); - } goto out; } img_size =3D (uint64_t)sval; diff --git a/tests/qemu-iotests/049.out b/tests/qemu-iotests/049.out index a5cfba175626..c54ae21b868a 100644 --- a/tests/qemu-iotests/049.out +++ b/tests/qemu-iotests/049.out @@ -92,19 +92,19 @@ Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D16492= 67441664 cluster_size=3D65536 l =3D=3D 3. Invalid sizes =3D=3D qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- -1024 -qemu-img: Image size must be less than 8 EiB! +qemu-img: Invalid image size specified. Must be between 0 and 922337203685= 4775807. qemu-img create -f qcow2 -o size=3D-1024 TEST_DIR/t.qcow2 qemu-img: TEST_DIR/t.qcow2: Value '-1024' is out of range for parameter 's= ize' qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- -1k -qemu-img: Image size must be less than 8 EiB! +qemu-img: Invalid image size specified. Must be between 0 and 922337203685= 4775807. qemu-img create -f qcow2 -o size=3D-1k TEST_DIR/t.qcow2 qemu-img: TEST_DIR/t.qcow2: Value '-1k' is out of range for parameter 'siz= e' qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- 1kilobyte -qemu-img: Invalid image size specified! You may use k, M, G, T, P or E suf= fixes for +qemu-img: Invalid image size specified. You may use k, M, G, T, P or E suf= fixes for qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabyt= es. qemu-img create -f qcow2 -o size=3D1kilobyte TEST_DIR/t.qcow2 @@ -113,7 +113,7 @@ Optional suffix k, M, G, T, P or E means kilo-, mega-, = giga-, tera-, peta- and exabytes, respectively. qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- foobar -qemu-img: Invalid image size specified! You may use k, M, G, T, P or E suf= fixes for +qemu-img: Invalid image size specified. You may use k, M, G, T, P or E suf= fixes for qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabyt= es. qemu-img create -f qcow2 -o size=3Dfoobar TEST_DIR/t.qcow2 --=20 2.26.2 From nobody Sun Oct 5 19:23:35 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589819848; cv=none; d=zohomail.com; s=zohoarc; b=nst4zvEJV9+UIxIgs3CTny9KKxPsqFW40qAEia2s0U/lj5L7QyifKGE2gmpyOtyf6xTPWmJ31WDDeD7wu6U+Os0/FeAp++lYT4+MHOp3F+nvjcQE3cANCWmhfAPHhoFz+/nsb7tUSKKLpOdCDBzzDfDJhigemzvnlRkJWXAP3U0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589819848; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wdxmpdzEUZLLZ6Q0W0qyeGo0cYkBFewYpDPT/hVS0mk=; b=cV96rM6HSP+xT5UQuhXsKCt1KsiyHLvM5TOfGbDqssvMKIazyjuCqbHyqHs32DN7SljEVuO2k3zbaUyw/wSKs2L4yDGlgTZOqJs7hstLFyd0hWtoohqd1kPaxdRvFQQML16h/MCIRmB1w1SJiidXhP3EzmCcSCJsSLDe8UuOd94= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589819848977383.8981295445684; Mon, 18 May 2020 09:37:28 -0700 (PDT) Received: from localhost ([::1]:59338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jailb-0004dT-KM for importer@patchew.org; Mon, 18 May 2020 12:37:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jaigm-0005HQ-KU for qemu-devel@nongnu.org; Mon, 18 May 2020 12:32:28 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:23553 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jaigl-0003Go-P4 for qemu-devel@nongnu.org; Mon, 18 May 2020 12:32:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-127-bryVW3gRM8O-J_HMQKjMdA-1; Mon, 18 May 2020 12:32:23 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 862C5EC1AB; Mon, 18 May 2020 16:32:22 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-88.phx2.redhat.com [10.3.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BD505D9DC; Mon, 18 May 2020 16:32:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589819547; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wdxmpdzEUZLLZ6Q0W0qyeGo0cYkBFewYpDPT/hVS0mk=; b=hnvI69ESUXJm7DlbMAzQARrKEMY7ETGRGhUjwAiJv4ATZRHjDos5546JdkfRySgXmYpduw xtD6AEyTciZNphRFMPd/w0m6VevSZOTse2VtYSUSfERnwIlJGWnefaPXkA1nvuuUUVPPDx RwEeIKRvlT0uj1SKmtboir7N3ZF6Rm8= X-MC-Unique: bryVW3gRM8O-J_HMQKjMdA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 3/6] qemu-img: validate image length in img_map Date: Mon, 18 May 2020 11:32:15 -0500 Message-Id: <20200518163218.649412-4-eblake@redhat.com> In-Reply-To: <20200518163218.649412-1-eblake@redhat.com> References: <20200518163218.649412-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=eblake@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/18 00:53:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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 , Eyal Moscovici , "open list:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Eyal Moscovici The code handles this case correctly: we merely skip the loop. However it is probably best to return an explicit error. Reviewed-by: Eric Blake Acked-by: Mark Kanda Signed-off-by: Eyal Moscovici Message-Id: <20200513133629.18508-3-eyal.moscovici@oracle.com> [eblake: commit message tweak] Signed-off-by: Eric Blake --- qemu-img.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qemu-img.c b/qemu-img.c index 5d824fc15f39..c88f412333ec 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3092,6 +3092,11 @@ static int img_map(int argc, char **argv) } length =3D blk_getlength(blk); + if (length < 0) { + error_report("Failed to get size for '%s'", filename); + return 1; + } + while (curr.start + curr.length < length) { int64_t offset =3D curr.start + curr.length; int64_t n; --=20 2.26.2 From nobody Sun Oct 5 19:23:35 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589819756; cv=none; d=zohomail.com; s=zohoarc; b=bU2hO21+9CtZblSzhYi7z6f+njqwLoYDK/hSD7h6e0SACbTPN9oCneihhAVORXKntGB/eVrrTi5+mkPXwTiVl94AH5+z0OHWYtXj3jOxk5L7LX2AfmmBH5w5+uOvC/JUbN77IN9HHrC0Ryy353mx3Wj45oww+oEffA2pm5Q3NHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589819756; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=49/f+keEDjKs+v+LzGBui/j6kv7VOomAe8IriXvd7qU=; b=eTg+/fg+QlnrmG7XgtNQtaey3xX5Gt+7zwS44JUPT4kcr+ytaQPde3qMdj6Z4ByTsoTTgCqbLbH1V462bkczBw76iRuJ/MLSQV+e/30+obXfM+EeuEe9Jd9JltO2EmLxNK/Q4aI9LAPgdcyZh/75PUOSe6EygvGziDDqlOhSInE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589819756688771.1383120178695; Mon, 18 May 2020 09:35:56 -0700 (PDT) Received: from localhost ([::1]:51164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jaik7-0001Kv-CX for importer@patchew.org; Mon, 18 May 2020 12:35:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jaigm-0005Gn-EX for qemu-devel@nongnu.org; Mon, 18 May 2020 12:32:28 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:35510 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jaigl-0003GL-CD for qemu-devel@nongnu.org; Mon, 18 May 2020 12:32:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-275-4ipxGvMUPkWpzSDahPDmeA-1; Mon, 18 May 2020 12:32:24 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3703E835B74; Mon, 18 May 2020 16:32:23 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-88.phx2.redhat.com [10.3.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD4525D9DC; Mon, 18 May 2020 16:32:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589819546; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=49/f+keEDjKs+v+LzGBui/j6kv7VOomAe8IriXvd7qU=; b=R1CbKK88ZiGMgGvOTuHyvNnDMYCXRsHL9VNZLJngYIEgMDZTmWEfwhW75IrPdL3IlWdCC3 HPKlGytMoXKq1hL6uzcLZ6jmKW2FK3fr8eDKnI5pu6Gpts4UjjMcTRArkpm5iKVMn/9x/s YhyM8UL3DhzuJzvix4J4qK41xAeaAKM= X-MC-Unique: 4ipxGvMUPkWpzSDahPDmeA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 4/6] qemu-img: refactor dump_map_entry JSON format output Date: Mon, 18 May 2020 11:32:16 -0500 Message-Id: <20200518163218.649412-5-eblake@redhat.com> In-Reply-To: <20200518163218.649412-1-eblake@redhat.com> References: <20200518163218.649412-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.81; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/17 22:52:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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 , Eyal Moscovici , "open list:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Eyal Moscovici Previously dump_map_entry identified whether we need to start a new JSON array based on whether start address =3D=3D 0. In this refactor we remove this assumption as in following patches we will allow map to start from an arbitrary position. Reviewed-by: Eric Blake Acked-by: Mark Kanda Signed-off-by: Eyal Moscovici Message-Id: <20200513133629.18508-4-eyal.moscovici@oracle.com> Signed-off-by: Eric Blake --- qemu-img.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index c88f412333ec..4aa9414aba6f 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2902,9 +2902,8 @@ static int dump_map_entry(OutputFormat output_format,= MapEntry *e, } break; case OFORMAT_JSON: - printf("%s{ \"start\": %"PRId64", \"length\": %"PRId64"," + printf("{ \"start\": %"PRId64", \"length\": %"PRId64"," " \"depth\": %"PRId64", \"zero\": %s, \"data\": %s", - (e->start =3D=3D 0 ? "[" : ",\n"), e->start, e->length, e->depth, e->zero ? "true" : "false", e->data ? "true" : "false"); @@ -2913,8 +2912,8 @@ static int dump_map_entry(OutputFormat output_format,= MapEntry *e, } putchar('}'); - if (!next) { - printf("]\n"); + if (next) { + puts(","); } break; } @@ -3089,6 +3088,8 @@ static int img_map(int argc, char **argv) if (output_format =3D=3D OFORMAT_HUMAN) { printf("%-16s%-16s%-16s%s\n", "Offset", "Length", "Mapped to", "Fi= le"); + } else if (output_format =3D=3D OFORMAT_JSON) { + putchar('['); } length =3D blk_getlength(blk); @@ -3125,6 +3126,9 @@ static int img_map(int argc, char **argv) } ret =3D dump_map_entry(output_format, &curr, NULL); + if (output_format =3D=3D OFORMAT_JSON) { + puts("]"); + } out: blk_unref(blk); --=20 2.26.2 From nobody Sun Oct 5 19:23:35 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589819756; cv=none; d=zohomail.com; s=zohoarc; b=XZ1LJEynAbT6roAHD0uZs/O8Pt4OnUW3IX/qHd5fYgqi14/qzfFeshCgboMTu7rF11L9f2ldtyk96TtzrNSYlbxugoaVNLPg6xj8jRt7sZ0asAa26ZrNi3ZEdFETU+hDEsvHhsaQ1SrkKikJbfC8Nu+mysLn+l++VcSi55QbA/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589819756; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=s0aF8eppS+yvsU4EEHPHYd94QaqK4y//bjVQKPx5j1g=; b=LMZX169NrXvD5p2VM4Ryx3r3WhrDhFDmkjvb6VvgX5Qvxc5PJUMdP/ohfbSA4fgh2423gDGArywhLyCsOlTr5KN5QP05oZv+isIurq6ozUX7dwtNHOOkau0WMggG3+Kl7sisbaV5CpU/dS3j4Y+OuJk26CAqOoSZjhl6lZ8VyeU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589819756953570.2838334655685; Mon, 18 May 2020 09:35:56 -0700 (PDT) Received: from localhost ([::1]:50842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jaik5-0001Cu-FZ for importer@patchew.org; Mon, 18 May 2020 12:35:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jaign-0005Ja-Kj for qemu-devel@nongnu.org; Mon, 18 May 2020 12:32:29 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:24065 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jaigm-0003HE-97 for qemu-devel@nongnu.org; Mon, 18 May 2020 12:32:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-363-owRo0MjtP2yk7Dtjy80DOA-1; Mon, 18 May 2020 12:32:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2443EC1A0; Mon, 18 May 2020 16:32:23 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-88.phx2.redhat.com [10.3.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6858E5D9DC; Mon, 18 May 2020 16:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589819547; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s0aF8eppS+yvsU4EEHPHYd94QaqK4y//bjVQKPx5j1g=; b=J2qTwHaJ6k5PZECvg3XMdfVSqteR5w8WdJ7zgsEkgi0EaZ6VWI4Ion3nJju8NY7Nw1veib mTya/bcAk/XXaG2dN4FtO6bYr6TE6ikDC4URoBNOgbr+ALPaWaVlBAoufI0ICWKzcz2Ao8 Xwt4kjI5pGyMl2UcImQeJLOJ5HIpilo= X-MC-Unique: owRo0MjtP2yk7Dtjy80DOA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 5/6] qemu-img: Add --start-offset and --max-length to map Date: Mon, 18 May 2020 11:32:17 -0500 Message-Id: <20200518163218.649412-6-eblake@redhat.com> In-Reply-To: <20200518163218.649412-1-eblake@redhat.com> References: <20200518163218.649412-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=eblake@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/18 00:53:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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 , Eyal Moscovici , "open list:Block layer core" , Max Reitz , Yoav Elnekave Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Eyal Moscovici The mapping operation of large disks especially ones stored over a long chain of QCOW2 files can take a long time to finish. Additionally when mapping fails there was no way recover by restarting the mapping from the failed location. The new options, --start-offset and --max-length allows the user to divide these type of map operations into shorter independent tasks. Reviewed-by: Eric Blake Acked-by: Mark Kanda Co-developed-by: Yoav Elnekave Signed-off-by: Yoav Elnekave Signed-off-by: Eyal Moscovici Message-Id: <20200513133629.18508-5-eyal.moscovici@oracle.com> Signed-off-by: Eric Blake --- docs/tools/qemu-img.rst | 2 +- qemu-img.c | 22 +++++++++++++++++++++- qemu-img-cmds.hx | 4 ++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 0080f83a76c9..f4ffe528ea83 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -519,7 +519,7 @@ Command description: ``ImageInfoSpecific*`` QAPI object (e.g. ``ImageInfoSpecificQCow2`` for qcow2 images). -.. option:: map [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=3DO= FMT] [-U] FILENAME +.. option:: map [--object OBJECTDEF] [--image-opts] [-f FMT] [--start-offs= et=3DOFFSET] [--max-length=3DLEN] [--output=3DOFMT] [-U] FILENAME Dump the metadata of image *FILENAME* and its backing file chain. In particular, this commands dumps the allocation state of every sector diff --git a/qemu-img.c b/qemu-img.c index 4aa9414aba6f..947bf8b34b3d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3009,6 +3009,8 @@ static int img_map(int argc, char **argv) int ret =3D 0; bool image_opts =3D false; bool force_share =3D false; + int64_t start_offset =3D 0; + int64_t max_length =3D -1; fmt =3D NULL; output =3D NULL; @@ -3021,9 +3023,11 @@ static int img_map(int argc, char **argv) {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {"force-share", no_argument, 0, 'U'}, + {"start-offset", required_argument, 0, 's'}, + {"max-length", required_argument, 0, 'l'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":f:hU", + c =3D getopt_long(argc, argv, ":f:s:l:hU", long_options, &option_index); if (c =3D=3D -1) { break; @@ -3047,6 +3051,18 @@ static int img_map(int argc, char **argv) case OPTION_OUTPUT: output =3D optarg; break; + case 's': + start_offset =3D cvtnum("start offset", optarg); + if (start_offset < 0) { + return 1; + } + break; + case 'l': + max_length =3D cvtnum("max length", optarg); + if (max_length < 0) { + return 1; + } + break; case OPTION_OBJECT: { QemuOpts *opts; opts =3D qemu_opts_parse_noisily(&qemu_object_opts, @@ -3097,7 +3113,11 @@ static int img_map(int argc, char **argv) error_report("Failed to get size for '%s'", filename); return 1; } + if (max_length !=3D -1) { + length =3D MIN(start_offset + max_length, length); + } + curr.start =3D start_offset; while (curr.start + curr.length < length) { int64_t offset =3D curr.start + curr.length; int64_t n; diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index c9c54de1df40..35f832816f96 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -63,9 +63,9 @@ SRST ERST DEF("map", img_map, - "map [--object objectdef] [--image-opts] [-f fmt] [--output=3Dofmt] [-= U] filename") + "map [--object objectdef] [--image-opts] [-f fmt] [--start-offset=3Dof= fset] [--max-length=3Dlen] [--output=3Dofmt] [-U] filename") SRST -.. option:: map [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=3DO= FMT] [-U] FILENAME +.. option:: map [--object OBJECTDEF] [--image-opts] [-f FMT] [--start-offs= et=3DOFFSET] [--max-length=3DLEN] [--output=3DOFMT] [-U] FILENAME ERST DEF("measure", img_measure, --=20 2.26.2 From nobody Sun Oct 5 19:23:35 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589819847; cv=none; d=zohomail.com; s=zohoarc; b=evT9YQNqljkLk74qj3rjugJLZDNlGtuLCcU5hmxuIkt0EJ9CMS1WACpDk7KY6pfadaKJr7BXAcVM8aGOwJciVUwsTQMW6evqpNzPc2ydpGorLmrTrVy+nmzdJjjVwME4koPP1uw86GlwNeIJB53niL6ShCBEKerRvhERCDTiH5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589819847; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2DaVhlUUMzLKCmXvrlPg1FK7qEoUxfS7ou598eeRodQ=; b=cCXU+z5nefma8JOIPQ4Fht3sVqB95BbxLtj2pLZ9LoI1RwontHUIUi7/W3I6ByvialLwu14MPsBgRqhu8EKRyhRpftYqzn2jyJjS94XAKtbPN/sv/hE4EsrB3n2Q2MJUSUmJzC7xLCX+a1Gxwrrk+xhynRlljUJW1Jp2KSfBzno= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589819847837857.7901340990356; Mon, 18 May 2020 09:37:27 -0700 (PDT) Received: from localhost ([::1]:59240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jaila-0004aw-IB for importer@patchew.org; Mon, 18 May 2020 12:37:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jaigo-0005LU-55 for qemu-devel@nongnu.org; Mon, 18 May 2020 12:32:30 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:57583 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jaign-0003I0-83 for qemu-devel@nongnu.org; Mon, 18 May 2020 12:32:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-454-nZMhFrT7MP6RjvcBdaSVxQ-1; Mon, 18 May 2020 12:32:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 89A8A1B18BC1; Mon, 18 May 2020 16:32:24 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-88.phx2.redhat.com [10.3.112.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CCB65D9DC; Mon, 18 May 2020 16:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589819548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2DaVhlUUMzLKCmXvrlPg1FK7qEoUxfS7ou598eeRodQ=; b=WpBIZIMQ8/QMicW0OA8rQPdYFldl9KJMuHI4QdT8YwqTtUiPhB2jA0pQfdWRmvslEPEiXg vjfgj6MJPMiHoIxiOwRfck/IhbjIY0eYqWdtoSGE18iu+2uZeFStsqQtBt5kqKJktg38ji dvfiQ5doV06jFYiLRAOlDk9kWaQpvIM= X-MC-Unique: nZMhFrT7MP6RjvcBdaSVxQ-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 6/6] iotests: Enhance 223 to cover qemu-img map improvements Date: Mon, 18 May 2020 11:32:18 -0500 Message-Id: <20200518163218.649412-7-eblake@redhat.com> In-Reply-To: <20200518163218.649412-1-eblake@redhat.com> References: <20200518163218.649412-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=eblake@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/17 22:51:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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 , "open list:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Since qemu-img map + x-dirty-bitmap remains the easiest way to read persistent bitmaps at the moment, it makes a reasonable place to add coverage to ensure we do not regress on the just-added parameters to qemu-img map. Signed-off-by: Eric Blake Message-Id: <20200513181455.295267-1-eblake@redhat.com> --- tests/qemu-iotests/223 | 6 ++++-- tests/qemu-iotests/223.out | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/223 b/tests/qemu-iotests/223 index 56fbc5fb09a0..d68bc3cb6f1a 100755 --- a/tests/qemu-iotests/223 +++ b/tests/qemu-iotests/223 @@ -2,7 +2,7 @@ # # Test reading dirty bitmap over NBD # -# Copyright (C) 2018-2019 Red Hat, Inc. +# Copyright (C) 2018-2020 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -206,7 +206,9 @@ $QEMU_IMG map --output=3Djson --image-opts \ nbd_server_start_unix_socket -f $IMGFMT -B b2 "$TEST_IMG" IMG=3D"driver=3Dnbd,server.type=3Dunix,server.path=3D$nbd_unix_socket" -$QEMU_IMG map --output=3Djson --image-opts \ +$QEMU_IMG map --output=3Djson --image-opts --max-length=3D12345 \ + "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b2" | _filter_qemu_img_map +$QEMU_IMG map --output=3Djson --image-opts --start-offset=3D12345 \ "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b2" | _filter_qemu_img_map # success, all done diff --git a/tests/qemu-iotests/223.out b/tests/qemu-iotests/223.out index 80c0cf65095b..e1eaaedb55b3 100644 --- a/tests/qemu-iotests/223.out +++ b/tests/qemu-iotests/223.out @@ -201,6 +201,7 @@ read 2097152/2097152 bytes at offset 2097152 { "start": 2097152, "length": 2097152, "depth": 0, "zero": false, "data": = false}] [{ "start": 0, "length": 512, "depth": 0, "zero": false, "data": true, "of= fset": OFFSET}, { "start": 512, "length": 512, "depth": 0, "zero": false, "data": false}, -{ "start": 1024, "length": 2096128, "depth": 0, "zero": false, "data": tru= e, "offset": OFFSET}, +{ "start": 1024, "length": 11321, "depth": 0, "zero": false, "data": true,= "offset": OFFSET}] +[{ "start": 12345, "length": 2084807, "depth": 0, "zero": false, "data": t= rue, "offset": OFFSET}, { "start": 2097152, "length": 2097152, "depth": 0, "zero": false, "data": = false}] *** done --=20 2.26.2