From nobody Tue Apr 30 19:43:53 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1652695545; cv=none; d=zohomail.com; s=zohoarc; b=cX6Xzy01cLtsfQioL6HmVE2xXHMg6WBtm07Rt7l2TqeqP2coam2KAzjtzXfcn9ZlWO00slfTUL3YR+GSO6kRfFaA5t4lI7mjTE6mW9qgc9zKsTXysI1xyK5nOLU3jpTO5xkzTOmlp6Uf7jtTuNlMjxxFAhVr43pq4y8T9O1EUW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652695545; 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=LZK26sGzv/gYmCXov3Qy8P2OtrWViXL3cBIq0sBxKnE=; b=ljWZgkHI9wq2VHqoD7u3qP9j9DVqjSWtNhwdmhaciDx2XLjPK0yAua3LkAR4YHZqG29UkBcouE06tko2rwcpxNyegK5/TjhrAauH4/DcbPZalkm/C+TMK9BHWopgLWHW8iCRD+MnfTkOap28+om2kGZtfd9L/M/XHCkknX1MNOc= 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+importer=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 1652695545922588.1322108032; Mon, 16 May 2022 03:05:45 -0700 (PDT) Received: from localhost ([::1]:50664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nqXbk-0002bN-4W for importer@patchew.org; Mon, 16 May 2022 06:05:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39790) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqXZk-0001Uw-0y for qemu-devel@nongnu.org; Mon, 16 May 2022 06:03:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31878) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqXZg-00085E-Tg for qemu-devel@nongnu.org; Mon, 16 May 2022 06:03:38 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-662--xapNdQiN7aOM7Z414gwAw-1; Mon, 16 May 2022 06:03:31 -0400 Received: by mail-qk1-f199.google.com with SMTP id d186-20020a3768c3000000b0069fcfacbea0so10948488qkc.0 for ; Mon, 16 May 2022 03:03:31 -0700 (PDT) Received: from step1.redhat.com (host-87-11-6-106.retail.telecomitalia.it. [87.11.6.106]) by smtp.gmail.com with ESMTPSA id c28-20020a05620a201c00b0069fcf7678besm5482554qka.105.2022.05.16.03.03.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 03:03:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652695412; 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=LZK26sGzv/gYmCXov3Qy8P2OtrWViXL3cBIq0sBxKnE=; b=RWuRey+sk99ze24u0WkAifiMO9u+N0/4vFC+xBcjtk2aQHfRFYs0G+9Yyde1Op7MdEZzv6 +20Xje+jp8mkkeS2bxpoSuOKo1WOe2694AeXeBdr3064TxtRTuiF09s9Pd+r1Ph8uF2iv1 mCcyCySTtLPXhM48fmAIVQQVRzRIH3E= X-MC-Unique: -xapNdQiN7aOM7Z414gwAw-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=LZK26sGzv/gYmCXov3Qy8P2OtrWViXL3cBIq0sBxKnE=; b=d0wrzgPvB3bRFlSw6JE7ahMRLocWHf0P7qS/hd0XDFmPjg/P6dRby7csCZrRuu+cZN 5jyMdmki1YDjspyA2bHWSJAqKPMsQ0z86NCJZP5cI0WO7jX0YPZ+nf8K1wc1ui8X+J4y 9QLbKAezfYGjEz83btvRsii7c8h3zI7/p3h+UdIY4LAxMi1ZHpEwOHkzD8XUkqzYTsJe g7rs53Nf9bYeN3vkQosU3PRrKMqTIRdJ08wNyG+bK0GszAosaeE1SVPXefcR7xMzT6j7 TM2a/L/S1xF7EaFAzQVDz4GgbU8+G6FaFniIlLAZAAZZG3DdvErluMhO1Ha88FSspJ5j N8AA== X-Gm-Message-State: AOAM533lFJHFtRZDJcnFAGM1/X07Q+sw0xJKFZe6xmMsoXMZz2xyXII5 2raAPOKxRVzGbJXvRTtKk3RF0ymOrsP08oOhyEkRFcwbl41DekBvICn/o0YVPscNpzVLy9pGOwA sVUsYGwKleFJet8/419L58RSaYum4ZX1SFVUzqIWICEG90IWk7Qk/XMHerH6wzKl7Ges= X-Received: by 2002:ac8:5e54:0:b0:2f3:f4ee:efbd with SMTP id i20-20020ac85e54000000b002f3f4eeefbdmr14406030qtx.295.1652695410699; Mon, 16 May 2022 03:03:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAOB56SQeR+UohK+fw/ZHoAjDSwnCHW+y9zgFlv+YhBbH72znOk01C1KygbehpEvQvY84IUw== X-Received: by 2002:ac8:5e54:0:b0:2f3:f4ee:efbd with SMTP id i20-20020ac85e54000000b002f3f4eeefbdmr14406007qtx.295.1652695410435; Mon, 16 May 2022 03:03:30 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Peter Lieven , Ilya Dryomov , Tingting Mao , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH] block/rbd: report a better error when namespace does not exist Date: Mon, 16 May 2022 12:03:24 +0200 Message-Id: <20220516100324.61122-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+importer=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652695547578100001 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 Signed-off-by: Stefano Garzarella Reviewed-by: Ilya Dryomov --- 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..0ff23c5b26 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 !=3D 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