From patchwork Wed Apr 30 12:28:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 4093251 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6B3019F38E for ; Wed, 30 Apr 2014 12:28:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8DC0E202BE for ; Wed, 30 Apr 2014 12:28:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6AF4C2027D for ; Wed, 30 Apr 2014 12:28:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933454AbaD3M2w (ORCPT ); Wed, 30 Apr 2014 08:28:52 -0400 Received: from mail-la0-f49.google.com ([209.85.215.49]:42473 "EHLO mail-la0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932715AbaD3M2v (ORCPT ); Wed, 30 Apr 2014 08:28:51 -0400 Received: by mail-la0-f49.google.com with SMTP id hr17so1152469lab.22 for ; Wed, 30 Apr 2014 05:28:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=ZUDmS/dkW6uqSEgWrZ4cWokiNvf+v5+n5kId0cVhG5Y=; b=FYkZPkMokKOravKeK/A+Ceq3TJ+9Q6elNl2ZRWhCgNvSMObejc4jBP4WauqWGYxF21 jFC4r4cNFwoCNBOtph7tYHONPZyAy1CyCY7om3IzfP+da8ZZFDgwBfvx3puqKEjWe6kZ p5T9cuDpiR9cHo54k7qvyinWDUczXHl7GXD21mJ/IEqymRmVHZo7934/E4nxEY/X+W8O rVTuKZyocUJop4vOhA91XmmiW9dj/vHGCwkjv1vZbdQQFvCev9vG/Sbomst/MEitwv0m DLIJWayC+byEIA6yhLv/+Y8SS1Wd1plrB9iqPmxtxno2f7zgBptXtBPVj8YRamCH+3ZX RKEA== X-Gm-Message-State: ALoCoQnglN//R2JMYeb4BkKeTHDNjgeMxmFeuMQiSD32QY3rYM74mVIqC57DxedTM03i1vrE4K5r X-Received: by 10.152.28.194 with SMTP id d2mr2883035lah.25.1398860930072; Wed, 30 Apr 2014 05:28:50 -0700 (PDT) Received: from localhost ([109.110.67.18]) by mx.google.com with ESMTPSA id jm3sm26147220lbc.29.2014.04.30.05.28.48 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 30 Apr 2014 05:28:49 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH v2] rbd: make sure we have latest osdmap on 'rbd map' Date: Wed, 30 Apr 2014 16:28:47 +0400 Message-Id: <1398860927-5796-1-git-send-email-ilya.dryomov@inktank.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1398356607-10666-4-git-send-email-ilya.dryomov@inktank.com> References: <1398356607-10666-4-git-send-email-ilya.dryomov@inktank.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Given an existing idle mapping (img1), mapping an image (img2) in a newly created pool (pool2) fails: $ ceph osd pool create pool1 8 8 $ rbd create --size 1000 pool1/img1 $ sudo rbd map pool1/img1 $ ceph osd pool create pool2 8 8 $ rbd create --size 1000 pool2/img2 $ sudo rbd map pool2/img2 rbd: sysfs write failed rbd: map failed: (2) No such file or directory This is because client instances are shared by default and we don't request an osdmap update when bumping a ref on an existing client. The fix is to use the mon_get_version request to see if the osdmap we have is the latest, and block until the requested update is received if it's not. Fixes: http://tracker.ceph.com/issues/8184 Signed-off-by: Ilya Dryomov --- v2: - send mon_get_version request and wait for a reply only if we were unable to locate the pool (i.e. don't hurt the common case) drivers/block/rbd.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 552a2edcaa74..daf7b4659b4a 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -4683,6 +4683,38 @@ out_err: } /* + * Return pool id (>= 0) or a negative error code. + */ +static int rbd_add_get_pool_id(struct rbd_client *rbdc, const char *pool_name) +{ + u64 newest_epoch; + unsigned long timeout = rbdc->client->options->mount_timeout * HZ; + int tries = 0; + int ret; + +again: + ret = ceph_pg_poolid_by_name(rbdc->client->osdc.osdmap, pool_name); + if (ret == -ENOENT && tries++ < 1) { + ret = ceph_monc_do_get_version(&rbdc->client->monc, "osdmap", + &newest_epoch); + if (ret < 0) + return ret; + + if (rbdc->client->osdc.osdmap->epoch < newest_epoch) { + ceph_monc_request_next_osdmap(&rbdc->client->monc); + (void) ceph_monc_wait_osdmap(&rbdc->client->monc, + newest_epoch, timeout); + goto again; + } else { + /* the osdmap we have is new enough */ + return -ENOENT; + } + } + + return ret; +} + +/* * An rbd format 2 image has a unique identifier, distinct from the * name given to it by the user. Internally, that identifier is * what's used to specify the names of objects related to the image. @@ -5053,7 +5085,6 @@ static ssize_t do_rbd_add(struct bus_type *bus, struct rbd_options *rbd_opts = NULL; struct rbd_spec *spec = NULL; struct rbd_client *rbdc; - struct ceph_osd_client *osdc; bool read_only; int rc = -ENOMEM; @@ -5075,8 +5106,7 @@ static ssize_t do_rbd_add(struct bus_type *bus, } /* pick the pool */ - osdc = &rbdc->client->osdc; - rc = ceph_pg_poolid_by_name(osdc->osdmap, spec->pool_name); + rc = rbd_add_get_pool_id(rbdc, spec->pool_name); if (rc < 0) goto err_out_client; spec->pool_id = (u64)rc;