From nobody Tue Feb 10 05:27:00 2026 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=1597337031; cv=none; d=zohomail.com; s=zohoarc; b=nF0IPNCj1dq2XoiBorn99OpW63bgNXfAD8BeMHS2WuUiD0UeKRI80TQo3aRIL9XvgVc4JRZ8NqRFHvOL+1FQ4BXaCHSpEeWHNAwJ7fVVTRfNS6b10lzVdWzy4cAgta1fkGf5KjEErZa+jJaAgM+4PxmoAWl9N3Sol6T9iNRmisE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597337031; 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=BIk7i9h0goB63ZMrR/6zqne/mhsultHKTPd2Tl8s3cw=; b=XSThMcuW3fydbnF9hry4YXbUak8PNObtyj+TLPWoOho9xvqBKZoH3KvBdDBxZcWY+V8GflH+GYl0jza3lmVFKlw3KsV9kQaCDlEP8xi2GCW5JseaXcZJRk8azvBH9rvF5UHO2oAZwzZJ2UfxlTJ0Uepz2AuJnds0Y9qQr/UQwRg= 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 1597337031585550.8352507906997; Thu, 13 Aug 2020 09:43:51 -0700 (PDT) Received: from localhost ([::1]:48136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GKU-0002As-Dc for importer@patchew.org; Thu, 13 Aug 2020 12:43:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G96-00059C-JA for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:32:04 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:47844 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 1k6G94-0001dy-Jk for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:32:04 -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-477-Y3rqyoP-OiaThj0dLxRW3A-1; Thu, 13 Aug 2020 12:30:27 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C892A800050; Thu, 13 Aug 2020 16:30:26 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id A65475C1A3; Thu, 13 Aug 2020 16:30:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336321; 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=BIk7i9h0goB63ZMrR/6zqne/mhsultHKTPd2Tl8s3cw=; b=X+1Guwwqn8jc095LIFv8ITAXU/f3pRwsu9Kc5XzK2gUECGbbGXrU1vLIgMUrBJVXOk069y GutYQZ9PKaPFDuE9oRTUoqFssjg+dGPP/Z2/WZsSujAwWb9p0aMulOZ+eW/Uni4kn3HPpo pTzjOkTVMgg0A37rr41gyX+GSLsgU58= X-MC-Unique: Y3rqyoP-OiaThj0dLxRW3A-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 21/22] block/export: Move blk to BlockExport Date: Thu, 13 Aug 2020 18:29:34 +0200 Message-Id: <20200813162935.210070-22-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 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.61; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 12:29:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com 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" Every block export has a BlockBackend representing the disk that is exported. It should live in BlockExport therefore. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/block/export.h | 3 +++ block/export/export.c | 3 +++ nbd/server.c | 44 ++++++++++++++++++++++-------------------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/include/block/export.h b/include/block/export.h index 83f554b745..53b4163a3b 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -54,6 +54,9 @@ struct BlockExport { */ AioContext *ctx; =20 + /* The block device to export */ + BlockBackend *blk; + /* List entry for block_exports */ QLIST_ENTRY(BlockExport) next; }; diff --git a/block/export/export.c b/block/export/export.c index 1255f3fc80..3cd448ba72 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -89,6 +89,8 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Erro= r **errp) return NULL; } =20 + assert(exp->blk !=3D NULL); + QLIST_INSERT_HEAD(&block_exports, exp, next); return exp; } @@ -105,6 +107,7 @@ void blk_exp_unref(BlockExport *exp) if (--exp->refcount =3D=3D 0) { QLIST_REMOVE(exp, next); exp->drv->delete(exp); + blk_unref(exp->blk); g_free(exp->id); g_free(exp); aio_wait_kick(); diff --git a/nbd/server.c b/nbd/server.c index 899d00782f..6ad78203c9 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -84,7 +84,6 @@ struct NBDRequestData { struct NBDExport { BlockExport common; =20 - BlockBackend *blk; char *name; char *description; uint64_t size; @@ -643,7 +642,7 @@ static int nbd_negotiate_handle_info(NBDClient *client,= Error **errp) * whether this is OPT_INFO or OPT_GO. */ /* minimum - 1 for back-compat, or actual if client will obey it. */ if (client->opt =3D=3D NBD_OPT_INFO || blocksize) { - check_align =3D sizes[0] =3D blk_get_request_alignment(exp->blk); + check_align =3D sizes[0] =3D blk_get_request_alignment(exp->common= .blk); } else { sizes[0] =3D 1; } @@ -652,7 +651,7 @@ static int nbd_negotiate_handle_info(NBDClient *client,= Error **errp) * TODO: is blk_bs(blk)->bl.opt_transfer appropriate? */ sizes[1] =3D MAX(4096, sizes[0]); /* maximum - At most 32M, but smaller as appropriate. */ - sizes[2] =3D MIN(blk_get_max_transfer(exp->blk), NBD_MAX_BUFFER_SIZE); + sizes[2] =3D MIN(blk_get_max_transfer(exp->common.blk), NBD_MAX_BUFFER= _SIZE); trace_nbd_negotiate_handle_info_block_size(sizes[0], sizes[1], sizes[2= ]); sizes[0] =3D cpu_to_be32(sizes[0]); sizes[1] =3D cpu_to_be32(sizes[1]); @@ -684,7 +683,7 @@ static int nbd_negotiate_handle_info(NBDClient *client,= Error **errp) * tolerate all clients, regardless of alignments. */ if (client->opt =3D=3D NBD_OPT_INFO && !blocksize && - blk_get_request_alignment(exp->blk) > 1) { + blk_get_request_alignment(exp->common.blk) > 1) { return nbd_negotiate_send_rep_err(client, NBD_REP_ERR_BLOCK_SIZE_REQD, errp, @@ -1556,7 +1555,7 @@ int nbd_export_new(BlockExport *blk_exp, BlockDriverS= tate *bs, blk_set_allow_aio_context_change(blk, true); =20 QTAILQ_INIT(&exp->clients); - exp->blk =3D blk; + exp->common.blk =3D blk; exp->name =3D g_strdup(name); assert(!desc || strlen(desc) <=3D NBD_MAX_STRING_SIZE); exp->description =3D g_strdup(desc); @@ -1679,15 +1678,13 @@ static void nbd_export_delete(BlockExport *blk_exp) g_free(exp->description); exp->description =3D NULL; =20 - if (exp->blk) { + if (exp->common.blk) { if (exp->eject_notifier_blk) { notifier_remove(&exp->eject_notifier); blk_unref(exp->eject_notifier_blk); } - blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, + blk_remove_aio_context_notifier(exp->common.blk, blk_aio_attached, blk_aio_detach, exp); - blk_unref(exp->blk); - exp->blk =3D NULL; } =20 if (exp->export_bitmap) { @@ -1840,7 +1837,7 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDCl= ient *client, =20 while (progress < size) { int64_t pnum; - int status =3D bdrv_block_status_above(blk_bs(exp->blk), NULL, + int status =3D bdrv_block_status_above(blk_bs(exp->common.blk), NU= LL, offset + progress, size - progress, &pnum, NULL, NULL); @@ -1872,7 +1869,8 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDCl= ient *client, stl_be_p(&chunk.length, pnum); ret =3D nbd_co_send_iov(client, iov, 1, errp); } else { - ret =3D blk_pread(exp->blk, offset + progress, data + progress= , pnum); + ret =3D blk_pread(exp->common.blk, offset + progress, + data + progress, pnum); if (ret < 0) { error_setg_errno(errp, -ret, "reading from file failed"); break; @@ -2136,7 +2134,8 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, } =20 if (request->type !=3D NBD_CMD_CACHE) { - req->data =3D blk_try_blockalign(client->exp->blk, request->le= n); + req->data =3D blk_try_blockalign(client->exp->common.blk, + request->len); if (req->data =3D=3D NULL) { error_setg(errp, "No memory"); return -ENOMEM; @@ -2232,7 +2231,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, =20 /* XXX: NBD Protocol only documents use of FUA with WRITE */ if (request->flags & NBD_CMD_FLAG_FUA) { - ret =3D blk_co_flush(exp->blk); + ret =3D blk_co_flush(exp->common.blk); if (ret < 0) { return nbd_send_generic_reply(client, request->handle, ret, "flush failed", errp); @@ -2246,7 +2245,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, data, request->len, errp); } =20 - ret =3D blk_pread(exp->blk, request->from, data, request->len); + ret =3D blk_pread(exp->common.blk, request->from, data, request->len); if (ret < 0) { return nbd_send_generic_reply(client, request->handle, ret, "reading from file failed", errp); @@ -2281,7 +2280,7 @@ static coroutine_fn int nbd_do_cmd_cache(NBDClient *c= lient, NBDRequest *request, =20 assert(request->type =3D=3D NBD_CMD_CACHE); =20 - ret =3D blk_co_preadv(exp->blk, request->from, request->len, + ret =3D blk_co_preadv(exp->common.blk, request->from, request->len, NULL, BDRV_REQ_COPY_ON_READ | BDRV_REQ_PREFETCH); =20 return nbd_send_generic_reply(client, request->handle, ret, @@ -2312,7 +2311,8 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, if (request->flags & NBD_CMD_FLAG_FUA) { flags |=3D BDRV_REQ_FUA; } - ret =3D blk_pwrite(exp->blk, request->from, data, request->len, fl= ags); + ret =3D blk_pwrite(exp->common.blk, request->from, data, request->= len, + flags); return nbd_send_generic_reply(client, request->handle, ret, "writing to file failed", errp); =20 @@ -2327,7 +2327,8 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, if (request->flags & NBD_CMD_FLAG_FAST_ZERO) { flags |=3D BDRV_REQ_NO_FALLBACK; } - ret =3D blk_pwrite_zeroes(exp->blk, request->from, request->len, f= lags); + ret =3D blk_pwrite_zeroes(exp->common.blk, request->from, request-= >len, + flags); return nbd_send_generic_reply(client, request->handle, ret, "writing to file failed", errp); =20 @@ -2336,14 +2337,14 @@ static coroutine_fn int nbd_handle_request(NBDClien= t *client, abort(); =20 case NBD_CMD_FLUSH: - ret =3D blk_co_flush(exp->blk); + ret =3D blk_co_flush(exp->common.blk); return nbd_send_generic_reply(client, request->handle, ret, "flush failed", errp); =20 case NBD_CMD_TRIM: - ret =3D blk_co_pdiscard(exp->blk, request->from, request->len); + ret =3D blk_co_pdiscard(exp->common.blk, request->from, request->l= en); if (ret =3D=3D 0 && request->flags & NBD_CMD_FLAG_FUA) { - ret =3D blk_co_flush(exp->blk); + ret =3D blk_co_flush(exp->common.blk); } return nbd_send_generic_reply(client, request->handle, ret, "discard failed", errp); @@ -2361,7 +2362,8 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, =20 if (client->export_meta.base_allocation) { ret =3D nbd_co_send_block_status(client, request->handle, - blk_bs(exp->blk), request->= from, + blk_bs(exp->common.blk), + request->from, request->len, dont_fragment, !client->export_meta.bitmap, NBD_META_ID_BASE_ALLOCATION, --=20 2.25.4