From patchwork Mon May 7 08:43:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongsheng Yang X-Patchwork-Id: 10383553 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E84136037F for ; Mon, 7 May 2018 08:45:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCD51286DF for ; Mon, 7 May 2018 08:45:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE9FC28B2C; Mon, 7 May 2018 08:45:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6849C286DF for ; Mon, 7 May 2018 08:45:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752534AbeEGIpT (ORCPT ); Mon, 7 May 2018 04:45:19 -0400 Received: from m97136.mail.qiye.163.com ([220.181.97.136]:5475 "EHLO m97136.mail.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752533AbeEGIoV (ORCPT ); Mon, 7 May 2018 04:44:21 -0400 Received: from atest-guest.localdomain (unknown [218.94.118.90]) by smtp2 (Coremail) with SMTP id iOCowAD3D8riEfBa7U7qAA--.740S5; Mon, 07 May 2018 16:44:19 +0800 (CST) From: Dongsheng Yang To: ceph-devel@vger.kernel.org, idryomov@gmail.com Cc: Dongsheng Yang Subject: [PATCH 3/9] rbd: refresh features and set the disk to readonly if there is unsupported bit Date: Mon, 7 May 2018 04:43:59 -0400 Message-Id: <1525682645-30510-4-git-send-email-dongsheng.yang@easystack.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1525682645-30510-1-git-send-email-dongsheng.yang@easystack.cn> References: <1525682645-30510-1-git-send-email-dongsheng.yang@easystack.cn> X-CM-TRANSID: iOCowAD3D8riEfBa7U7qAA--.740S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxAF4DCr13GFyDZw1DJw47urg_yoW5ZrW7pa 1fGa45tFWUJr17uan3Xrn8Jr45Ja18ta4Du347Aw1Skan5CrnxA34IkFy8trWDJFy3Xr4x JF4rtrW5CF4UGFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0J1ja9-UUUUU= X-Originating-IP: [218.94.118.90] X-CM-SenderInfo: 5grqw2pkhqwhp1dqwq5hdv52pwdfyhdfq/1tbidQQ-eln5d2yE4wAAso Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If there is unsupported feature enabled after rbd map, we will noticed it in refreshing, then we need to set the disk readonly. For example, if we enabled the object-map feature after rbd map, as we don't support object-map in kernel rbd currently, we should avoid user to write rbd device. And set dist to read-write when we disable the unsupported features. Signed-off-by: Dongsheng Yang --- drivers/block/rbd.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index a1a4bbe..70ca81d 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -345,6 +345,7 @@ struct rbd_device { unsigned long flags; /* possibly lock protected */ struct rbd_spec *spec; struct rbd_options *opts; + bool read_only_need_restore; char *config_info; /* add{,_single_major} string */ struct ceph_object_id header_oid; @@ -4561,17 +4562,6 @@ static int _rbd_dev_v2_snap_features(struct rbd_device *rbd_dev, u64 snap_id, return 0; } -static int rbd_dev_v2_features(struct rbd_device *rbd_dev) -{ - u64 features = 0; - int ret = _rbd_dev_v2_snap_features(rbd_dev, CEPH_NOSNAP, features); - if (ret) - return ret - - rbd_dev->header.features = features - return 0; -} - static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev) { struct rbd_spec *parent_spec; @@ -5036,12 +5026,35 @@ static const char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev, static int rbd_dev_v2_header_info(struct rbd_device *rbd_dev) { bool first_time = rbd_dev->header.object_prefix == NULL; + u64 features = 0; int ret; ret = rbd_dev_v2_image_size(rbd_dev); if (ret) return ret; + ret = _rbd_dev_v2_snap_features(rbd_dev, CEPH_NOSNAP, + &features); + if (ret) { + if (-ENXIO == ret && !first_time) { + if (!rbd_dev->opts->read_only) { + rbd_dev->opts->read_only = true; + rbd_dev->read_only_need_restore = true; + set_disk_ro(rbd_dev->disk, + rbd_dev->opts->read_only); + } + } else { + return ret; + } + } else { + if (rbd_dev->read_only_need_restore) { + rbd_dev->opts->read_only = false; + rbd_dev->read_only_need_restore = false; + set_disk_ro(rbd_dev->disk, rbd_dev->opts->read_only); + } + } + rbd_dev->mapping.features = rbd_dev->header.features = features; + if (first_time) { ret = rbd_dev_v2_header_onetime(rbd_dev); if (ret) @@ -5413,14 +5426,6 @@ static int rbd_dev_v2_header_onetime(struct rbd_device *rbd_dev) if (ret) goto out_err; - /* - * Get the and check features for the image. Currently the - * features are assumed to never change. - */ - ret = rbd_dev_v2_features(rbd_dev); - if (ret) - goto out_err; - /* If the image supports fancy striping, get its parameters */ if (rbd_dev->header.features & RBD_FEATURE_STRIPINGV2) { @@ -5731,6 +5736,7 @@ static ssize_t do_rbd_add(struct bus_type *bus, goto err_out_rbd_dev; } + rbd_dev->read_only_need_restore = false; /* If we are mapping a snapshot it must be marked read-only */ if (rbd_dev->spec->snap_id != CEPH_NOSNAP) rbd_dev->opts->read_only = true;