From patchwork Tue Dec 18 09:32:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongsheng Yang X-Patchwork-Id: 10735271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 340306C2 for ; Tue, 18 Dec 2018 09:32:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24A7C29EF0 for ; Tue, 18 Dec 2018 09:32:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18F2729F17; Tue, 18 Dec 2018 09:32:36 +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 292E529EF0 for ; Tue, 18 Dec 2018 09:32:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726441AbeLRJcc (ORCPT ); Tue, 18 Dec 2018 04:32:32 -0500 Received: from m97138.mail.qiye.163.com ([220.181.97.138]:20043 "EHLO m97138.mail.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726414AbeLRJcc (ORCPT ); Tue, 18 Dec 2018 04:32:32 -0500 Received: from atest-guest.localdomain (unknown [218.94.118.90]) by smtp9 (Coremail) with SMTP id u+CowACHxyOnvhhcRQNfAA--.1812S2; Tue, 18 Dec 2018 17:32:23 +0800 (CST) From: Dongsheng Yang To: idryomov@gmail.com, jdurgin@redhat.com Cc: ceph-devel@vger.kernel.org, Dongsheng Yang Subject: [PATCH] rbd: mark rbd disk to ro if we found feature unsupported enabled after mapping Date: Tue, 18 Dec 2018 04:32:20 -0500 Message-Id: <1545125540-14815-1-git-send-email-dongsheng.yang@easystack.cn> X-Mailer: git-send-email 1.8.3.1 X-CM-TRANSID: u+CowACHxyOnvhhcRQNfAA--.1812S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxCF48KF43tFWDJFykXFW3GFg_yoW5Kw1Upa 1fJas0yFWUXr13Ca1rXrs8Xr45J3W8tayDury7Cw1avFn5CrnIyryIkFWFqrWDJFyUXrWr JF45JrW3Cr40yFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0Jb-OzsUUUUU= X-Originating-IP: [218.94.118.90] X-CM-SenderInfo: 5grqw2pkhqwhp1dqwq5hdv52pwdfyhdfq/1tbiGwchelpcgSlP7QAAsL 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. In addition, we need to set disk to rw if these unsupportted features disabled later. Signed-off-by: Dongsheng Yang --- drivers/block/rbd.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 8e5140b..e911830 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -3695,6 +3695,9 @@ static void rbd_queue_workfn(struct work_struct *work) snapc = rbd_dev->header.snapc; ceph_get_snap_context(snapc); } + must_be_locked = + (rbd_dev->header.features & RBD_FEATURE_EXCLUSIVE_LOCK) && + (op_type != OBJ_OP_READ || rbd_dev->opts->lock_on_read); up_read(&rbd_dev->header_rwsem); if (offset + length > mapping_size) { @@ -3704,9 +3707,6 @@ static void rbd_queue_workfn(struct work_struct *work) goto err_rq; } - must_be_locked = - (rbd_dev->header.features & RBD_FEATURE_EXCLUSIVE_LOCK) && - (op_type != OBJ_OP_READ || rbd_dev->opts->lock_on_read); if (must_be_locked) { down_read(&rbd_dev->lock_rwsem); result = rbd_wait_state_locked(rbd_dev, @@ -4567,13 +4567,6 @@ static int _rbd_dev_v2_snap_features(struct rbd_device *rbd_dev, u64 snap_id, if (ret < sizeof (features_buf)) return -ERANGE; - unsup = le64_to_cpu(features_buf.incompat) & ~RBD_FEATURES_SUPPORTED; - if (unsup) { - rbd_warn(rbd_dev, "image uses unsupported features: 0x%llx", - unsup); - return -ENXIO; - } - *snap_features = le64_to_cpu(features_buf.features); dout(" snap_id 0x%016llx features = 0x%016llx incompat = 0x%016llx\n", @@ -4581,13 +4574,14 @@ static int _rbd_dev_v2_snap_features(struct rbd_device *rbd_dev, u64 snap_id, (unsigned long long)*snap_features, (unsigned long long)le64_to_cpu(features_buf.incompat)); - return 0; -} + unsup = le64_to_cpu(features_buf.incompat) & ~RBD_FEATURES_SUPPORTED; + if (unsup) { + rbd_warn(rbd_dev, "image uses unsupported features: 0x%llx", + unsup); + return -ENXIO; + } -static int rbd_dev_v2_features(struct rbd_device *rbd_dev) -{ - return _rbd_dev_v2_snap_features(rbd_dev, CEPH_NOSNAP, - &rbd_dev->header.features); + return 0; } struct parent_image_info { @@ -5184,12 +5178,26 @@ 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) + set_disk_ro(rbd_dev->disk, true); + else + return ret; + } else { + if (!first_time && !rbd_dev->opts->read_only) + set_disk_ro(rbd_dev->disk, false); + } + rbd_dev->mapping.features = rbd_dev->header.features = features; + if (first_time) { ret = rbd_dev_v2_header_onetime(rbd_dev); if (ret) @@ -5560,14 +5568,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) {