From patchwork Wed Mar 21 06:17:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongsheng Yang X-Patchwork-Id: 10298647 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 27D1260386 for ; Wed, 21 Mar 2018 06:17:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1546528883 for ; Wed, 21 Mar 2018 06:17:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0949528B08; Wed, 21 Mar 2018 06:17:50 +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=-6.9 required=2.0 tests=BAYES_00,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 737CA28883 for ; Wed, 21 Mar 2018 06:17:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751455AbeCUGRq (ORCPT ); Wed, 21 Mar 2018 02:17:46 -0400 Received: from m97138.mail.qiye.163.com ([220.181.97.138]:64199 "EHLO m97138.mail.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751040AbeCUGRp (ORCPT ); Wed, 21 Mar 2018 02:17:45 -0400 Received: from atest-guest.localdomain (unknown [218.94.118.90]) by smtp9 (Coremail) with SMTP id u+CowACXp1Pv+LFacQCaAg--.31S2; Wed, 21 Mar 2018 14:17:19 +0800 (CST) From: Dongsheng Yang To: idryomov@gmail.com, sage@redhat.com, elder@kernel.org, jdillama@redhat.com Cc: ceph-devel@vger.kernel.org, Dongsheng Yang Subject: [PATCH v2 2/2] rbd: refresh features and set the disk to readonly if there is unsupported bit Date: Wed, 21 Mar 2018 02:17:16 -0400 Message-Id: <1521613036-23632-1-git-send-email-dongsheng.yang@easystack.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1521541939-15932-3-git-send-email-dongsheng.yang@easystack.cn> References: <1521541939-15932-3-git-send-email-dongsheng.yang@easystack.cn> X-CM-TRANSID: u+CowACXp1Pv+LFacQCaAg--.31S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxAF4DCr45ArWUAr47Xr1DJrb_yoW5ZFyfpa 1fJa4YyFyUJr17ua1fXrn8JrWrJF48ta4Du34xAw1SgFZ5Cr13A34IkFy5tFZrJFy7Xr48 tF4rJrW5CF4UJFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0J1b_-PUUUUU= X-Originating-IP: [218.94.118.90] X-CM-SenderInfo: 5grqw2pkhqwhp1dqwq5hdv52pwdfyhdfq/1tbidQsQeln5c2Nw3QABsI 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 --- V1: - set disk to read-write when we disabled the unsupported features. 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 eb59b93..cf9c27a 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -753,6 +753,7 @@ enum { struct rbd_options { int queue_depth; bool read_only; + bool read_only_need_restore; bool lock_on_read; bool exclusive; }; @@ -4463,17 +4464,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; @@ -4938,12 +4928,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->opts->read_only_need_restore = true; + set_disk_ro(rbd_dev->disk, + rbd_dev->opts->read_only); + } + } else { + return ret; + } + } else { + if (rbd_dev->opts->read_only_need_restore) { + rbd_dev->opts->read_only = false; + rbd_dev->opts->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) @@ -5143,6 +5156,7 @@ static int rbd_add_parse_args(const char *buf, goto out_mem; rbd_opts->read_only = RBD_READ_ONLY_DEFAULT; + rbd_opts->read_only_need_restore = false; rbd_opts->queue_depth = RBD_QUEUE_DEPTH_DEFAULT; rbd_opts->lock_on_read = RBD_LOCK_ON_READ_DEFAULT; rbd_opts->exclusive = RBD_EXCLUSIVE_DEFAULT; @@ -5344,14 +5358,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) {