From nobody Mon May 6 06:33:18 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1652771612; cv=none; d=zohomail.com; s=zohoarc; b=Olv4DKUDggeZxiUHFklzUVSW921bzvf9UcOiopiQKzFhrhM3TBy0MNfGzU7JhAGggpV7a/0twwa7nXUD7aw64s07OUTSNqT0e+pLWwEPBDcm5u6oC9ddeSPsiTNImtIhW97xDhNizpYXCTK/oV1IM3pyP2XzWQUxbM2SVSU+rNg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652771612; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=m7sBWzc3ink6IbHaTeIrbGxG+koBMXneQrV7hajKjwM=; b=Q14NB+lNbmWlKCfFa55T2RDqOr2K2p/f85baaEb24Agms8lmTP4K+LrLeI99RjIl96zMq2pXC+6pQZad+3SqHn9ipvFq5mJJdzUsdeu7PBFuW5W8faUHxw8bL7tcPeuv2JxQ3eRRbL1Yc35Gt1Lkbmru5I3Qll5o369h2pnK+jo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652771612060637.6333082276833; Tue, 17 May 2022 00:13:32 -0700 (PDT) Received: from localhost ([::1]:47204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nqrOc-0007UJ-VV for importer2@patchew.org; Tue, 17 May 2022 03:13:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqrLf-000688-TX for qemu-devel@nongnu.org; Tue, 17 May 2022 03:10:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36576) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqrLc-0005AO-MM for qemu-devel@nongnu.org; Tue, 17 May 2022 03:10:26 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-48-WW4ANxVMOwWRqFL1_lLHbg-1; Tue, 17 May 2022 03:10:17 -0400 Received: by mail-wm1-f70.google.com with SMTP id e9-20020a05600c4e4900b00394779649b1so873737wmq.3 for ; Tue, 17 May 2022 00:10:16 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-16.business.telecomitalia.it. [87.12.25.16]) by smtp.gmail.com with ESMTPSA id bd10-20020a05600c1f0a00b00394538d039esm1123512wmb.6.2022.05.17.00.10.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 00:10:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652771418; 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; bh=m7sBWzc3ink6IbHaTeIrbGxG+koBMXneQrV7hajKjwM=; b=McI13z5TLO5U5ypzUt4gQeArWzx8qu6zVL0Z3lDH/WEKBROFjXLJpL9XAwunYVR7ezGafa 7eNRCIKfEanT2yPSR4rrYIMHxZcwIgr9LqkZaoFRWTHo3u1VGFbcC2msV+18B6DYg72ftq hY9lPXUmOxldUbBWJ1SYahM0zgs6fgY= X-MC-Unique: WW4ANxVMOwWRqFL1_lLHbg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=m7sBWzc3ink6IbHaTeIrbGxG+koBMXneQrV7hajKjwM=; b=PcRHg1O6JDWsLM92umOyDIcoE1Bl0CJFxOGZjOpW2AVSqVSccxAC6Gfd5QWjns+h2P 2G829srZTg9J0G1Et4Nj1KZ+EbMpOaGlV72fQRKuUkD5ZBRL/FJCnlGdL11Pe23K1Yzw XhRMJc9dnntS/OrT1QyiIdF1pwPXfKWYXBmBD32nYtXpvI7JaI8JfH1uxjArLX87kwMe xZdXI/J7COI+ddS0lcB0uVv67oCsgHOhDbh2LDusJ91w9wDm5q+4XDah/4SUSrAdscKn xj4CZgBQ/uw7vSTfhGtddcIcI0q6mRF+oFQ9A63uXRUM9ieeGeBLkDGL9p4YwMsaRtp3 4KRA== X-Gm-Message-State: AOAM531/40Fsyz5z6t/ucAP3ChYG7T/V+vGYUO8JNDeosFlIaRAO+3tP BQdGXB0cv78lX/2xN3Sv2vrAQ4uV0D9lTIKlaeAWjfF8SfzEHpfjkks4McE5cFu76ox7lFZ6w0P YFmgdTXK50QjdIX/d7qO8YllSrjjOpqWb7KIUng0B9KsidNXNEWSMJJX3gcg/tddG6ss= X-Received: by 2002:adf:d1cd:0:b0:20c:51c6:5d9f with SMTP id b13-20020adfd1cd000000b0020c51c65d9fmr17750069wrd.244.1652771415511; Tue, 17 May 2022 00:10:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1V6J3xGRZlqK0EijCwLg2qUnzb+3GmafkaeIl4xIA3GobVQBSnGN3TO0wDa9B1YERR1du9w== X-Received: by 2002:adf:d1cd:0:b0:20c:51c6:5d9f with SMTP id b13-20020adfd1cd000000b0020c51c65d9fmr17750036wrd.244.1652771415117; Tue, 17 May 2022 00:10:15 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Peter Lieven , Ilya Dryomov , Kevin Wolf , Hanna Reitz , Tingting Mao , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v2] block/rbd: report a better error when namespace does not exist Date: Tue, 17 May 2022 09:10:12 +0200 Message-Id: <20220517071012.6120-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652771614000100001 Content-Type: text/plain; charset="utf-8" If the namespace does not exist, rbd_create() fails with -ENOENT and QEMU reports a generic "error rbd create: No such file or directory": $ qemu-img create rbd:rbd/namespace/image 1M Formatting 'rbd:rbd/namespace/image', fmt=3Draw size=3D1048576 qemu-img: rbd:rbd/namespace/image: error rbd create: No such file or di= rectory Unfortunately rados_ioctx_set_namespace() does not fail if the namespace does not exist, so let's use rbd_namespace_exists() in qemu_rbd_connect() to check if the namespace exists, reporting a more understandable error: $ qemu-img create rbd:rbd/namespace/image 1M Formatting 'rbd:rbd/namespace/image', fmt=3Draw size=3D1048576 qemu-img: rbd:rbd/namespace/image: namespace 'namespace' does not exist Reported-by: Tingting Mao Reviewed-by: Ilya Dryomov Signed-off-by: Stefano Garzarella --- v2: - check r < 0 for consistency (librbd errors are always negative) [Ilya] --- meson.build | 6 ++++++ block/rbd.c | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/meson.build b/meson.build index 9b20dcd143..e6c0afd62b 100644 --- a/meson.build +++ b/meson.build @@ -1828,6 +1828,12 @@ config_host_data.set('HAVE_GETIFADDRS', cc.has_funct= ion('getifaddrs')) config_host_data.set('HAVE_OPENPTY', cc.has_function('openpty', dependenci= es: util)) config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul')) config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', pre= fix: '#include ')) +if rbd.found() + config_host_data.set('HAVE_RBD_NAMESPACE_EXISTS', + cc.has_function('rbd_namespace_exists', + dependencies: rbd, + prefix: '#include ')) +endif if rdma.found() config_host_data.set('HAVE_IBV_ADVISE_MR', cc.has_function('ibv_advise_mr', diff --git a/block/rbd.c b/block/rbd.c index 6caf35cbba..f826410f40 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -831,6 +831,26 @@ static int qemu_rbd_connect(rados_t *cluster, rados_io= ctx_t *io_ctx, error_setg_errno(errp, -r, "error opening pool %s", opts->pool); goto failed_shutdown; } + +#ifdef HAVE_RBD_NAMESPACE_EXISTS + if (opts->has_q_namespace && strlen(opts->q_namespace) > 0) { + bool exists; + + r =3D rbd_namespace_exists(*io_ctx, opts->q_namespace, &exists); + if (r < 0) { + error_setg_errno(errp, -r, "error checking namespace"); + goto failed_ioctx_destroy; + } + + if (!exists) { + error_setg(errp, "namespace '%s' does not exist", + opts->q_namespace); + r =3D -ENOENT; + goto failed_ioctx_destroy; + } + } +#endif + /* * Set the namespace after opening the io context on the pool, * if nspace =3D=3D NULL or if nspace =3D=3D "", it is just as we did = nothing @@ -840,6 +860,10 @@ static int qemu_rbd_connect(rados_t *cluster, rados_io= ctx_t *io_ctx, r =3D 0; goto out; =20 +#ifdef HAVE_RBD_NAMESPACE_EXISTS +failed_ioctx_destroy: + rados_ioctx_destroy(*io_ctx); +#endif failed_shutdown: rados_shutdown(*cluster); out: --=20 2.35.3