From nobody Sat May 4 11:09:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1562953038; cv=none; d=zoho.com; s=zohoarc; b=WV6rvB8wfyXoyeYNdKqX7YuZm9eMputFK1dQn1PrSP2WLofkifPXAKNBjUtSxRQmpWALEtb8yzt6tc51hWXlF9zPcDEIQnw/KuuhsZo+WlSmkK7/H5/m/R/udheldzxupnEfapGxFpR0+ArxGLoW3zenkQMFJt6gcKwKg0CYt3Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562953038; h=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:ARC-Authentication-Results; bh=ICPu1/PcBQYi4QDdZy5evLMHksQLRTrsN+gH8yrsx7Y=; b=JqJa5XVgGJ02ttcJLsQeaWRJ3huFAIv2SZISGAyGRckUlQIdvmlTjmMq7wBAhDnR6hIyuUaiPdbDv3I1mo8FTd81I86RIT3b8pGJ3F5ZjYQFde2VWhhsN3fzTqpxMvOVBklgKNj0lomXeTpsT42jWfQ0ls1EC+qvyJgSWtPValU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1562953038361889.2198998894087; Fri, 12 Jul 2019 10:37:18 -0700 (PDT) Received: from localhost ([::1]:51536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzTw-00023X-Ms for importer@patchew.org; Fri, 12 Jul 2019 13:37:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39673) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzSq-0006Ap-Ss for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlzSp-0004B9-Su for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41506) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlzSn-000469-Qd; Fri, 12 Jul 2019 13:36:05 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 23B31300194A; Fri, 12 Jul 2019 17:36:05 +0000 (UTC) Received: from localhost (unknown [10.40.205.208]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B307919C58; Fri, 12 Jul 2019 17:36:04 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 12 Jul 2019 19:35:54 +0200 Message-Id: <20190712173600.14554-2-mreitz@redhat.com> In-Reply-To: <20190712173600.14554-1-mreitz@redhat.com> References: <20190712173600.14554-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 12 Jul 2019 17:36:05 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/7] block/nbd: Fix hang in .bdrv_close() 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When nbd_close() is called from a coroutine, the connection_co never gets to run, and thus nbd_teardown_connection() hangs. This is because aio_co_enter() only puts the connection_co into the main coroutine's wake-up queue, so this main coroutine needs to yield and wait for connection_co to terminate. Suggested-by: Kevin Wolf Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky --- block/nbd.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/block/nbd.c b/block/nbd.c index 81edabbf35..8f5ee86842 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -61,6 +61,7 @@ typedef struct BDRVNBDState { CoMutex send_mutex; CoQueue free_sema; Coroutine *connection_co; + Coroutine *teardown_co; int in_flight; =20 NBDClientRequest requests[MAX_NBD_REQUESTS]; @@ -135,7 +136,15 @@ static void nbd_teardown_connection(BlockDriverState *= bs) qio_channel_shutdown(s->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); - BDRV_POLL_WHILE(bs, s->connection_co); + if (qemu_in_coroutine()) { + s->teardown_co =3D qemu_coroutine_self(); + /* connection_co resumes us when it terminates */ + qemu_coroutine_yield(); + s->teardown_co =3D NULL; + } else { + BDRV_POLL_WHILE(bs, s->connection_co); + } + assert(!s->connection_co); =20 nbd_client_detach_aio_context(bs); object_unref(OBJECT(s->sioc)); @@ -207,6 +216,9 @@ static coroutine_fn void nbd_connection_entry(void *opa= que) bdrv_dec_in_flight(s->bs); =20 s->connection_co =3D NULL; + if (s->teardown_co) { + aio_co_wake(s->teardown_co); + } aio_wait_kick(); } =20 --=20 2.21.0 From nobody Sat May 4 11:09:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1562953002; cv=none; d=zoho.com; s=zohoarc; b=I95kHI/ts6tAwQQ5TYT0WRZALaiBRR097O8Rlb7QP1V8TW868eIn3GSRnAdMvdY152y9lCFyz/rW9ZQ+bl50jRnp9xmOdox61vLaYyd8dn9rZgxwzDJ4c+xGLUT3IV4/UmCzcuiPb+zh3ns2WVWuNyIH0saCaRGS0NN6BdomWqs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562953002; h=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:ARC-Authentication-Results; bh=n/JohrD0LMzvaKNjLllBoliILZZRv1U1qEgaV5BxrOo=; b=RC6iDor5ufDfyH5brtjbuR8ICH7SGNdAYsR5/oBx9S22WlcX3ZcrkQXStcgNIetcZRrUqNi5hEEcR0s/JcWUdYPeqD5oO4OQZXypFW0p641gME6yQQIYtDTZdnm1xNW7ezYS06dagQHoJeKnMQqLKRpob/4Zrr94U3If3ync3Hs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1562953002093816.2882451451543; Fri, 12 Jul 2019 10:36:42 -0700 (PDT) Received: from localhost ([::1]:51514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzTM-0007mA-Jg for importer@patchew.org; Fri, 12 Jul 2019 13:36:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39718) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzSu-0006OL-11 for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlzSs-0004I2-Qy for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36118) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlzSq-0004Ao-4x; Fri, 12 Jul 2019 13:36:08 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 792F13079B63; Fri, 12 Jul 2019 17:36:07 +0000 (UTC) Received: from localhost (unknown [10.40.205.208]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 10E8819C58; Fri, 12 Jul 2019 17:36:06 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 12 Jul 2019 19:35:55 +0200 Message-Id: <20190712173600.14554-3-mreitz@redhat.com> In-Reply-To: <20190712173600.14554-1-mreitz@redhat.com> References: <20190712173600.14554-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 12 Jul 2019 17:36:07 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/7] block: Add blk_truncate_for_formatting() 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz --- include/sysemu/block-backend.h | 12 ++++++++ block/block-backend.c | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 733c4957eb..cd9ec8bf52 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -236,6 +236,18 @@ int blk_pwrite_compressed(BlockBackend *blk, int64_t o= ffset, const void *buf, int bytes); int blk_truncate(BlockBackend *blk, int64_t offset, PreallocMode prealloc, Error **errp); + +/** + * Wrapper of blk_truncate() for format drivers that need to truncate + * their protocol node before formatting it. + * Invoke blk_truncate() to truncate the file to @offset; if that + * fails with -ENOTSUP (and the file is already big enough), try to + * overwrite the first sector with zeroes. If that succeeds, return + * success. + */ +int blk_truncate_for_formatting(BlockBackend *blk, int64_t offset, + Error **errp); + int blk_pdiscard(BlockBackend *blk, int64_t offset, int bytes); int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf, int64_t pos, int size); diff --git a/block/block-backend.c b/block/block-backend.c index a8d160fd5d..c0e64b1ee1 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2041,6 +2041,60 @@ int blk_truncate(BlockBackend *blk, int64_t offset, = PreallocMode prealloc, return bdrv_truncate(blk->root, offset, prealloc, errp); } =20 +int blk_truncate_for_formatting(BlockBackend *blk, int64_t offset, Error *= *errp) +{ + Error *local_err =3D NULL; + int64_t current_size; + int bytes_to_clear; + int ret; + + ret =3D blk_truncate(blk, offset, PREALLOC_MODE_OFF, &local_err); + if (ret < 0 && ret !=3D -ENOTSUP) { + error_propagate(errp, local_err); + return ret; + } else if (ret >=3D 0) { + return ret; + } + + current_size =3D blk_getlength(blk); + if (current_size < 0) { + error_free(local_err); + error_setg_errno(errp, -current_size, + "Failed to inquire new image file's current lengt= h"); + return current_size; + } + + if (current_size < offset) { + /* Need to grow the image, but we failed to do that */ + error_propagate(errp, local_err); + return -ENOTSUP; + } + + error_free(local_err); + /* + * We can deal with images that are too big. We just need to + * clear the first sector. + */ + + bytes_to_clear =3D MIN(current_size, BDRV_SECTOR_SIZE) - offset; + if (bytes_to_clear) { + if (!(blk->root->perm & BLK_PERM_WRITE)) { + error_setg(errp, "Cannot clear first sector of new image: " + "Write permission missing"); + return -EPERM; + } + + ret =3D blk_pwrite_zeroes(blk, offset, bytes_to_clear, 0); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to clear the first sector= of " + "the new image"); + return ret; + } + } + + return 0; +} + static void blk_pdiscard_entry(void *opaque) { BlkRwCo *rwco =3D opaque; --=20 2.21.0 From nobody Sat May 4 11:09:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1562953047; cv=none; d=zoho.com; s=zohoarc; b=bP0hNiM/NUQKKPg22enFJxagLVhZrYP5iITUaUAdPUHG7chrjBexH+ZTQcNuR5kV/A74vJz579ac23uljKxFTUc/r9n04Pdp4A9TwIgVh//G7w/Y6bhFrSGClyPr8k4gusfRfQl7p2ave8s2t5HqJndIVgmsZA0Qc0JONTyg07U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562953047; h=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:ARC-Authentication-Results; bh=YMtEJ8xD4H0q46KQMWuKZ8+LrToa8ngC+R9YhPrzU/E=; b=fF0u7I32/pGTGMgh/WTptjf8+5cMNegj2Uwg+wADQpKrPTYGZuVDtu5mRVJNPg7eeQt2X05eRaptOtnedRTSskdpeYqMPYfi5go5NDDKgP38A0vMW13u3zqvZWcdgT7Xp1ve6ZvSTx3IkCRdAx2kaJt591umuNA+55p6qcpkD8M= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 15629530478497.525143101870185; Fri, 12 Jul 2019 10:37:27 -0700 (PDT) Received: from localhost ([::1]:51540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzU5-0002e2-8f for importer@patchew.org; Fri, 12 Jul 2019 13:37:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39737) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzSv-0006WW-VT for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlzSu-0004NC-Ot for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34668) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlzSs-0004G2-EY; Fri, 12 Jul 2019 13:36:10 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C18073082211; Fri, 12 Jul 2019 17:36:09 +0000 (UTC) Received: from localhost (unknown [10.40.205.208]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5FE9E5C207; Fri, 12 Jul 2019 17:36:09 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 12 Jul 2019 19:35:56 +0200 Message-Id: <20190712173600.14554-4-mreitz@redhat.com> In-Reply-To: <20190712173600.14554-1-mreitz@redhat.com> References: <20190712173600.14554-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 12 Jul 2019 17:36:09 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/7] block: Use blk_truncate_for_formatting() 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky --- block/parallels.c | 2 +- block/qcow.c | 2 +- block/qcow2.c | 2 +- block/qed.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 00fae125d1..a17b2d92f2 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -563,7 +563,7 @@ static int coroutine_fn parallels_co_create(BlockdevCre= ateOptions* opts, blk_set_allow_write_beyond_eof(blk, true); =20 /* Create image format */ - ret =3D blk_truncate(blk, 0, PREALLOC_MODE_OFF, errp); + ret =3D blk_truncate_for_formatting(blk, 0, errp); if (ret < 0) { goto out; } diff --git a/block/qcow.c b/block/qcow.c index 5bdf72ba33..86034135f9 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -858,7 +858,7 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOp= tions *opts, blk_set_allow_write_beyond_eof(qcow_blk, true); =20 /* Create image format */ - ret =3D blk_truncate(qcow_blk, 0, PREALLOC_MODE_OFF, errp); + ret =3D blk_truncate_for_formatting(qcow_blk, 0, errp); if (ret < 0) { goto exit; } diff --git a/block/qcow2.c b/block/qcow2.c index 039bdc2f7e..f3e53c781d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3184,7 +3184,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) blk_set_allow_write_beyond_eof(blk, true); =20 /* Clear the protocol layer and preallocate it if necessary */ - ret =3D blk_truncate(blk, 0, PREALLOC_MODE_OFF, errp); + ret =3D blk_truncate_for_formatting(blk, 0, errp); if (ret < 0) { goto out; } diff --git a/block/qed.c b/block/qed.c index 77c7cef175..ec244158b5 100644 --- a/block/qed.c +++ b/block/qed.c @@ -673,7 +673,7 @@ static int coroutine_fn bdrv_qed_co_create(BlockdevCrea= teOptions *opts, l1_size =3D header.cluster_size * header.table_size; =20 /* File must start empty and grow, check truncate is supported */ - ret =3D blk_truncate(blk, 0, PREALLOC_MODE_OFF, errp); + ret =3D blk_truncate_for_formatting(blk, 0, errp); if (ret < 0) { goto out; } --=20 2.21.0 From nobody Sat May 4 11:09:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1562953011; cv=none; d=zoho.com; s=zohoarc; b=Wn6Ap1IJDp0Pnn0Lz9+DvFYuXcgr8gyCSNhHMtpETnIkP1z/R3lWQOciKIsnzpufEWutWl81Z/BTwHug2g0S9uW/DtEVjC0yxxO7OIpxliNpiwdwhOyErNFv++HhFbz21+RGPkXIZntF7KFtRzJzIaK82IvuTn0f2bDSePqp4Vg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562953011; h=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:ARC-Authentication-Results; bh=nXUIW+1TO6SsmTeFh53QPKRjlQin2k+VY9KrF4LQ1qY=; b=NFl9tWnYfAxdeyy+ak/+tMVcshgNq4RrjyMyxijKaObDoQ9Xuu3DG0omSW1YgMmUA7q3ZxddhCeYstQQUCCLW+ohOo826BJC/DYjTVl6Adh9Z/jEv3Jrn5uPUBbqFeOgrYlqnBahrNJfuxGTVb2aA2ZzjiOUZB50H51GMZM74yk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 156295301164184.11247940373221; Fri, 12 Jul 2019 10:36:51 -0700 (PDT) Received: from localhost ([::1]:51516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzTV-000082-VV for importer@patchew.org; Fri, 12 Jul 2019 13:36:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39761) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzSy-0006ih-H7 for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlzSx-0004SW-Ai for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41562) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlzSu-0004Lx-Pe; Fri, 12 Jul 2019 13:36:12 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2234830C3192; Fri, 12 Jul 2019 17:36:12 +0000 (UTC) Received: from localhost (unknown [10.40.205.208]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AF68F5D772; Fri, 12 Jul 2019 17:36:11 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 12 Jul 2019 19:35:57 +0200 Message-Id: <20190712173600.14554-5-mreitz@redhat.com> In-Reply-To: <20190712173600.14554-1-mreitz@redhat.com> References: <20190712173600.14554-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 12 Jul 2019 17:36:12 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/7] block: Generic file creation fallback 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If a protocol driver does not support image creation, we can see whether maybe the file exists already. If so, just truncating it will be sufficient. Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky --- block.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 12 deletions(-) diff --git a/block.c b/block.c index c139540f2b..5466585501 100644 --- a/block.c +++ b/block.c @@ -531,20 +531,63 @@ out: return ret; } =20 -int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp) +static int bdrv_create_file_fallback(const char *filename, BlockDriver *dr= v, + QemuOpts *opts, Error **errp) { - BlockDriver *drv; + BlockBackend *blk; + QDict *options =3D qdict_new(); + int64_t size =3D 0; + char *buf =3D NULL; + PreallocMode prealloc; Error *local_err =3D NULL; int ret; =20 + size =3D qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); + buf =3D qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); + prealloc =3D qapi_enum_parse(&PreallocMode_lookup, buf, + PREALLOC_MODE_OFF, &local_err); + g_free(buf); + if (local_err) { + error_propagate(errp, local_err); + return -EINVAL; + } + + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_str(prealloc)); + return -ENOTSUP; + } + + qdict_put_str(options, "driver", drv->format_name); + + blk =3D blk_new_open(filename, NULL, options, + BDRV_O_RDWR | BDRV_O_RESIZE, errp); + if (!blk) { + error_prepend(errp, "Protocol driver '%s' does not support image " + "creation, and opening the image failed: ", + drv->format_name); + return -EINVAL; + } + + ret =3D blk_truncate_for_formatting(blk, size, errp); + blk_unref(blk); + return ret; +} + +int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp) +{ + BlockDriver *drv; + drv =3D bdrv_find_protocol(filename, true, errp); if (drv =3D=3D NULL) { return -ENOENT; } =20 - ret =3D bdrv_create(drv, filename, opts, &local_err); - error_propagate(errp, local_err); - return ret; + if (drv->bdrv_co_create_opts) { + return bdrv_create(drv, filename, opts, errp); + } else { + return bdrv_create_file_fallback(filename, drv, opts, errp); + } } =20 /** @@ -1420,6 +1463,24 @@ QemuOptsList bdrv_runtime_opts =3D { }, }; =20 +static QemuOptsList fallback_create_opts =3D { + .name =3D "fallback-create-opts", + .head =3D QTAILQ_HEAD_INITIALIZER(fallback_create_opts.head), + .desc =3D { + { + .name =3D BLOCK_OPT_SIZE, + .type =3D QEMU_OPT_SIZE, + .help =3D "Virtual disk size" + }, + { + .name =3D BLOCK_OPT_PREALLOC, + .type =3D QEMU_OPT_STRING, + .help =3D "Preallocation mode (allowed values: off)" + }, + { /* end of list */ } + } +}; + /* * Common part for opening disk images and files * @@ -5681,14 +5742,12 @@ void bdrv_img_create(const char *filename, const ch= ar *fmt, return; } =20 - if (!proto_drv->create_opts) { - error_setg(errp, "Protocol driver '%s' does not support image crea= tion", - proto_drv->format_name); - return; - } - create_opts =3D qemu_opts_append(create_opts, drv->create_opts); - create_opts =3D qemu_opts_append(create_opts, proto_drv->create_opts); + if (proto_drv->create_opts) { + create_opts =3D qemu_opts_append(create_opts, proto_drv->create_op= ts); + } else { + create_opts =3D qemu_opts_append(create_opts, &fallback_create_opt= s); + } =20 /* Create parameter list with default values */ opts =3D qemu_opts_create(create_opts, NULL, 0, &error_abort); --=20 2.21.0 From nobody Sat May 4 11:09:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1562953014; cv=none; d=zoho.com; s=zohoarc; b=iOonIUx2u39yYBXJ2Uc+Zu3Nmj+JBnXcBRM0/X2mTx7Oj2yNxX00rcs+dVho6+xTWvurmJFL8XKH1h+AXsrW669dDocvoNKJQmkJwE+WyKLVwcZgZxszffRhY5jjGMp5Rt8EsL62PCIpAbyVhTZphIoeZuu19RBzywoO5yV3NPw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562953014; h=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:ARC-Authentication-Results; bh=retGUkLPREhuf+7o90gLm9wHJfsFnPzL1Kms8Cniafw=; b=FLYZDBobEOp7NkFvXibrgPOakOSAV1gjRQlU/LjJq60A491UNOLrlsbdkct2jiL0tj/bzqLp6gxOi0J2w4CJthMARmtxoWFbNhN6ZdoW0xB72uaYpQOo/9EJdZ45dHg6cbwx0GsMNdTUYoFxygEbrd5bUa/+PG/GFR41wbwiqXM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1562953014733316.8525341955459; Fri, 12 Jul 2019 10:36:54 -0700 (PDT) Received: from localhost ([::1]:51520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzTZ-0000IS-AB for importer@patchew.org; Fri, 12 Jul 2019 13:36:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39788) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzT0-0006tU-Uf for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlzSz-0004VE-Kv for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49758) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlzSx-0004RU-4C; Fri, 12 Jul 2019 13:36:15 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F95419CBD6; Fri, 12 Jul 2019 17:36:14 +0000 (UTC) Received: from localhost (unknown [10.40.205.208]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07E336013B; Fri, 12 Jul 2019 17:36:13 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 12 Jul 2019 19:35:58 +0200 Message-Id: <20190712173600.14554-6-mreitz@redhat.com> In-Reply-To: <20190712173600.14554-1-mreitz@redhat.com> References: <20190712173600.14554-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 12 Jul 2019 17:36:14 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/7] file-posix: Drop hdev_co_create_opts() 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The generic fallback implementation effectively does the same. Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky --- block/file-posix.c | 67 ---------------------------------------------- 1 file changed, 67 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 4479cc7ab4..65bd6d3333 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3325,67 +3325,6 @@ static coroutine_fn int hdev_co_pwrite_zeroes(BlockD= riverState *bs, return raw_do_pwrite_zeroes(bs, offset, bytes, flags, true); } =20 -static int coroutine_fn hdev_co_create_opts(const char *filename, QemuOpts= *opts, - Error **errp) -{ - int fd; - int ret =3D 0; - struct stat stat_buf; - int64_t total_size =3D 0; - bool has_prefix; - - /* This function is used by both protocol block drivers and therefore = either - * of these prefixes may be given. - * The return value has to be stored somewhere, otherwise this is an e= rror - * due to -Werror=3Dunused-value. */ - has_prefix =3D - strstart(filename, "host_device:", &filename) || - strstart(filename, "host_cdrom:" , &filename); - - (void)has_prefix; - - ret =3D raw_normalize_devicepath(&filename, errp); - if (ret < 0) { - return ret; - } - - /* Read out options */ - total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), - BDRV_SECTOR_SIZE); - - fd =3D qemu_open(filename, O_WRONLY | O_BINARY); - if (fd < 0) { - ret =3D -errno; - error_setg_errno(errp, -ret, "Could not open device"); - return ret; - } - - if (fstat(fd, &stat_buf) < 0) { - ret =3D -errno; - error_setg_errno(errp, -ret, "Could not stat device"); - } else if (!S_ISBLK(stat_buf.st_mode) && !S_ISCHR(stat_buf.st_mode)) { - error_setg(errp, - "The given file is neither a block nor a character devi= ce"); - ret =3D -ENODEV; - } else if (lseek(fd, 0, SEEK_END) < total_size) { - error_setg(errp, "Device is too small"); - ret =3D -ENOSPC; - } - - if (!ret && total_size) { - uint8_t buf[BDRV_SECTOR_SIZE] =3D { 0 }; - int64_t zero_size =3D MIN(BDRV_SECTOR_SIZE, total_size); - if (lseek(fd, 0, SEEK_SET) =3D=3D -1) { - ret =3D -errno; - } else { - ret =3D qemu_write_full(fd, buf, zero_size); - ret =3D ret =3D=3D zero_size ? 0 : -errno; - } - } - qemu_close(fd); - return ret; -} - static BlockDriver bdrv_host_device =3D { .format_name =3D "host_device", .protocol_name =3D "host_device", @@ -3398,8 +3337,6 @@ static BlockDriver bdrv_host_device =3D { .bdrv_reopen_prepare =3D raw_reopen_prepare, .bdrv_reopen_commit =3D raw_reopen_commit, .bdrv_reopen_abort =3D raw_reopen_abort, - .bdrv_co_create_opts =3D hdev_co_create_opts, - .create_opts =3D &raw_create_opts, .mutable_opts =3D mutable_opts, .bdrv_co_invalidate_cache =3D raw_co_invalidate_cache, .bdrv_co_pwrite_zeroes =3D hdev_co_pwrite_zeroes, @@ -3525,8 +3462,6 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_reopen_prepare =3D raw_reopen_prepare, .bdrv_reopen_commit =3D raw_reopen_commit, .bdrv_reopen_abort =3D raw_reopen_abort, - .bdrv_co_create_opts =3D hdev_co_create_opts, - .create_opts =3D &raw_create_opts, .mutable_opts =3D mutable_opts, .bdrv_co_invalidate_cache =3D raw_co_invalidate_cache, =20 @@ -3659,8 +3594,6 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_reopen_prepare =3D raw_reopen_prepare, .bdrv_reopen_commit =3D raw_reopen_commit, .bdrv_reopen_abort =3D raw_reopen_abort, - .bdrv_co_create_opts =3D hdev_co_create_opts, - .create_opts =3D &raw_create_opts, .mutable_opts =3D mutable_opts, =20 .bdrv_co_preadv =3D raw_co_preadv, --=20 2.21.0 From nobody Sat May 4 11:09:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1562953062; cv=none; d=zoho.com; s=zohoarc; b=iU97kSZzLa93LowTgU4PvwZT3fc9iRW7Xdx4u4miqrosxKTjjJWqBS2h4pHHoI4l2457qvoT7b2TCbrnk+rUkV7hHhhkL8GGDgNZDUlufXCEWIrQx1G5nnq+ICc/zLBj9Y8myoCf3U7oX8KDApb+06ND8wksxC8MGjpxO3KguUY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562953062; h=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:ARC-Authentication-Results; bh=a94ipsy4GlT3u4igvdj5tma3C1EQMM7lEPwCjT2J0jo=; b=DbMQZ5Yw2oBytIad/qvAi03KaOprTChCxjuhIyIyNEZZx+hiRkG9N/P/Q42gq50uW4RKRl4Gw+jxoc9sOPu6ttSrphNFAhMhMZ+az1/3DQqxwOuu/sPHnUgFy+nKLBahdCOHBLVLEoGebfv5YwovMI9leyGjszPlWFprMiEtKG8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1562953062889339.79535851876506; Fri, 12 Jul 2019 10:37:42 -0700 (PDT) Received: from localhost ([::1]:51548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzUL-0003qh-BX for importer@patchew.org; Fri, 12 Jul 2019 13:37:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39854) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzT4-00077K-1b for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlzT1-0004ZY-Sy for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36190) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlzSz-0004UJ-DR; Fri, 12 Jul 2019 13:36:17 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B7D26307845E; Fri, 12 Jul 2019 17:36:16 +0000 (UTC) Received: from localhost (unknown [10.40.205.208]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 514035D71C; Fri, 12 Jul 2019 17:36:16 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 12 Jul 2019 19:35:59 +0200 Message-Id: <20190712173600.14554-7-mreitz@redhat.com> In-Reply-To: <20190712173600.14554-1-mreitz@redhat.com> References: <20190712173600.14554-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 12 Jul 2019 17:36:16 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 6/7] iscsi: Drop iscsi_co_create_opts() 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The generic fallback implementation effectively does the same. Signed-off-by: Max Reitz Reviewed-by: Maxim Levitsky --- block/iscsi.c | 56 --------------------------------------------------- 1 file changed, 56 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 267f160bf6..0e5729d335 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2157,58 +2157,6 @@ static int coroutine_fn iscsi_co_truncate(BlockDrive= rState *bs, int64_t offset, return 0; } =20 -static int coroutine_fn iscsi_co_create_opts(const char *filename, QemuOpt= s *opts, - Error **errp) -{ - int ret =3D 0; - int64_t total_size =3D 0; - BlockDriverState *bs; - IscsiLun *iscsilun =3D NULL; - QDict *bs_options; - Error *local_err =3D NULL; - - bs =3D bdrv_new(); - - /* Read out options */ - total_size =3D DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE= , 0), - BDRV_SECTOR_SIZE); - bs->opaque =3D g_new0(struct IscsiLun, 1); - iscsilun =3D bs->opaque; - - bs_options =3D qdict_new(); - iscsi_parse_filename(filename, bs_options, &local_err); - if (local_err) { - error_propagate(errp, local_err); - ret =3D -EINVAL; - } else { - ret =3D iscsi_open(bs, bs_options, 0, NULL); - } - qobject_unref(bs_options); - - if (ret !=3D 0) { - goto out; - } - iscsi_detach_aio_context(bs); - if (iscsilun->type !=3D TYPE_DISK) { - ret =3D -ENODEV; - goto out; - } - if (bs->total_sectors < total_size) { - ret =3D -ENOSPC; - goto out; - } - - ret =3D 0; -out: - if (iscsilun->iscsi !=3D NULL) { - iscsi_destroy_context(iscsilun->iscsi); - } - g_free(bs->opaque); - bs->opaque =3D NULL; - bdrv_unref(bs); - return ret; -} - static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { IscsiLun *iscsilun =3D bs->opaque; @@ -2479,8 +2427,6 @@ static BlockDriver bdrv_iscsi =3D { .bdrv_parse_filename =3D iscsi_parse_filename, .bdrv_file_open =3D iscsi_open, .bdrv_close =3D iscsi_close, - .bdrv_co_create_opts =3D iscsi_co_create_opts, - .create_opts =3D &iscsi_create_opts, .bdrv_reopen_prepare =3D iscsi_reopen_prepare, .bdrv_reopen_commit =3D iscsi_reopen_commit, .bdrv_co_invalidate_cache =3D iscsi_co_invalidate_cache, @@ -2518,8 +2464,6 @@ static BlockDriver bdrv_iser =3D { .bdrv_parse_filename =3D iscsi_parse_filename, .bdrv_file_open =3D iscsi_open, .bdrv_close =3D iscsi_close, - .bdrv_co_create_opts =3D iscsi_co_create_opts, - .create_opts =3D &iscsi_create_opts, .bdrv_reopen_prepare =3D iscsi_reopen_prepare, .bdrv_reopen_commit =3D iscsi_reopen_commit, .bdrv_co_invalidate_cache =3D iscsi_co_invalidate_cache, --=20 2.21.0 From nobody Sat May 4 11:09:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1562953055; cv=none; d=zoho.com; s=zohoarc; b=YIwJ/L8IGdL+Wc3SHgGwcZFnXLeNao/776y5zEIB8P1+TxXpNk5bWq1XTMiyMrqlKOeYOh38rQ+TWqvijdQRfq5Hn8/vQ6fX47Tdae8JZrccU4qjhyJz9qAbX+tQd0lBh1t1i1mlfYYkXUYMvuaHstZDiBSqxfv59KpVIDlCpLg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562953055; h=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:ARC-Authentication-Results; bh=XzwfTyw51mT5HtfvxJeVyR3gpHLM785Fdm4TX2JTlRE=; b=gb9r59HE/dRlwPeg7XO39SXZWcuo7x5V3UPKBvPmqNQMUJtOgknRXBoNSxQO9/36TempxeBWJPDnLuhOiTN7PXq2RpD3l6uoiuZeLztc2T9+u0/HbHnBI+cmChplDXmNovNr1FNcotsAPr+DDA4uK8vXURvbnVDPzcqm/IUzUIw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1562953055550185.007660172913; Fri, 12 Jul 2019 10:37:35 -0700 (PDT) Received: from localhost ([::1]:51542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzUE-0003OM-AU for importer@patchew.org; Fri, 12 Jul 2019 13:37:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39921) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlzT7-0007N9-6j for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlzT4-0004f9-Kq for qemu-devel@nongnu.org; Fri, 12 Jul 2019 13:36:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45600) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlzT1-0004YO-Ru; Fri, 12 Jul 2019 13:36:20 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 304BC3098458; Fri, 12 Jul 2019 17:36:19 +0000 (UTC) Received: from localhost (unknown [10.40.205.208]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE86860142; Fri, 12 Jul 2019 17:36:18 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 12 Jul 2019 19:36:00 +0200 Message-Id: <20190712173600.14554-8-mreitz@redhat.com> In-Reply-To: <20190712173600.14554-1-mreitz@redhat.com> References: <20190712173600.14554-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 12 Jul 2019 17:36:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 7/7] iotests: Add test for image creation fallback 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz --- tests/qemu-iotests/259 | 61 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/259.out | 14 +++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 76 insertions(+) create mode 100755 tests/qemu-iotests/259 create mode 100644 tests/qemu-iotests/259.out diff --git a/tests/qemu-iotests/259 b/tests/qemu-iotests/259 new file mode 100755 index 0000000000..22b4c10241 --- /dev/null +++ b/tests/qemu-iotests/259 @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# +# Test generic image creation fallback (by using NBD) +# +# Copyright (C) 2019 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dmreitz@redhat.com + +seq=3D$(basename $0) +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt raw +_supported_proto nbd +_supported_os Linux + + +_make_test_img 64M + +echo +echo '--- Testing creation ---' + +$QEMU_IMG create -f qcow2 "$TEST_IMG" 64M | _filter_img_create +$QEMU_IMG info "$TEST_IMG" | _filter_img_info + +echo +echo '--- Testing creation for which the node would need to grow ---' + +$QEMU_IMG create -f qcow2 -o preallocation=3Dmetadata "$TEST_IMG" 64M 2>&1= \ + | _filter_img_create + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/259.out b/tests/qemu-iotests/259.out new file mode 100644 index 0000000000..ffed19c2a0 --- /dev/null +++ b/tests/qemu-iotests/259.out @@ -0,0 +1,14 @@ +QA output created by 259 +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 + +--- Testing creation --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3Dqcow2 size=3D67108864 +image: TEST_DIR/t.IMGFMT +file format: qcow2 +virtual size: 64 MiB (67108864 bytes) +disk size: unavailable + +--- Testing creation for which the node would need to grow --- +qemu-img: TEST_DIR/t.IMGFMT: Could not resize image: Image format driver d= oes not support resize +Formatting 'TEST_DIR/t.IMGFMT', fmt=3Dqcow2 size=3D67108864 preallocation= =3Dmetadata +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index b34c8e3c0c..80e7603174 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -269,3 +269,4 @@ 254 rw auto backing quick 255 rw auto quick 256 rw auto quick +259 rw auto quick --=20 2.21.0