From patchwork Thu Sep 22 14:22:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 9345405 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 EC7A56077A for ; Thu, 22 Sep 2016 14:23:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD5D22AB28 for ; Thu, 22 Sep 2016 14:23:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D111C2AB2A; Thu, 22 Sep 2016 14:23:27 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 5467E2AB28 for ; Thu, 22 Sep 2016 14:23:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757353AbcIVOXZ (ORCPT ); Thu, 22 Sep 2016 10:23:25 -0400 Received: from mail-yw0-f194.google.com ([209.85.161.194]:33758 "EHLO mail-yw0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756833AbcIVOXY (ORCPT ); Thu, 22 Sep 2016 10:23:24 -0400 Received: by mail-yw0-f194.google.com with SMTP id g192so4797663ywh.0 for ; Thu, 22 Sep 2016 07:23:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=FuaEXV32JDjxOIcp6RbSONQTkLjcQBq4ARCn5WsTM/w=; b=Oh2JS++xfEzCAKYIP6NvnBXIi6hMk/H/SkCEIyJ3Wv/sPIJJi+DJUlkuD4F36EPS8H sULuyrJy4TzZW2dhSqeREK00YzHUS3AnwTdlIce999g+WcdI2cbkJGGNi0oQ+URuGZDe OnUftMSaSfivclq8Ur3Y9Pf7355GpbIRzmbufLwMk2ywENNngxjTF8667+bXZwTHzlSj wimuqdkcKhh0f2aO0ik04YPS5zCMKP/7J9XXQHJf+HkTrw8RbQ48Lt5GbZ+NDPPvvjVo d5p0vd9WS+z5CFQ8/l0AhV8wIUoWoUCTR7pGXBqqON1r91+QAeAvxZvG9KesAY4nxTVM xvpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=FuaEXV32JDjxOIcp6RbSONQTkLjcQBq4ARCn5WsTM/w=; b=EPhVQsBtd3qAcD2ttqJ3buJoY43bXbQMPGlsq9BeN+dnb81EaXo5HX5fr8AWOqz9tm APnHTElzc0HvxcLkOziM1bhRt+moy/H/qhPEb/CQGLGIdOsh+BEIaqIHfbN357f56xYy LfUnMhn4lZi820Rr04I6VbwAFsKfebV7Eu3ykOKKD+qyseYwMAwdFdxEjyJzwadJ4l+I 7Laz2r05TlrYxB1/Yp8QVr4XYQtpPAXyJvMYa5XiQo8iJ+AukEYKmQ7iTMpoYhB/tSH3 Zs58UWLNDacYI7Do/g8swsGXYdd7pZXh0mSCwT+vnSCMxMp/L8k40Qw5ewr2xpLb5vMM //Pg== X-Gm-Message-State: AE9vXwMrnNEiRcU2fIQWXz6Y/DrABDd1zdsmXtlUFP3Ge0wyxNnTQN0tqiSy0bI7j2AdDQ== X-Received: by 10.13.230.149 with SMTP id p143mr1622618ywe.187.1474554203521; Thu, 22 Sep 2016 07:23:23 -0700 (PDT) Received: from dhcp-1-215.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id o125sm685257ywe.31.2016.09.22.07.23.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Sep 2016 07:23:23 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Cc: Mike Christie Subject: [PATCH] rbd: lock_on_read map option Date: Thu, 22 Sep 2016 16:22:57 +0200 Message-Id: <1474554177-4029-1-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.3 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 Add a per-device option to acquire exclusive lock on reads (in addition to writes and discards). The use case is iSCSI, where it will be used to prevent execution of stale writes after the implicit failover. Signed-off-by: Ilya Dryomov Tested-by: Mike Christie --- drivers/block/rbd.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index d305b9ebe2cf..eca04b6dc747 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -795,6 +795,7 @@ enum { /* string args above */ Opt_read_only, Opt_read_write, + Opt_lock_on_read, Opt_err }; @@ -806,16 +807,19 @@ static match_table_t rbd_opts_tokens = { {Opt_read_only, "ro"}, /* Alternate spelling */ {Opt_read_write, "read_write"}, {Opt_read_write, "rw"}, /* Alternate spelling */ + {Opt_lock_on_read, "lock_on_read"}, {Opt_err, NULL} }; struct rbd_options { int queue_depth; bool read_only; + bool lock_on_read; }; #define RBD_QUEUE_DEPTH_DEFAULT BLKDEV_MAX_RQ #define RBD_READ_ONLY_DEFAULT false +#define RBD_LOCK_ON_READ_DEFAULT false static int parse_rbd_opts_token(char *c, void *private) { @@ -851,6 +855,9 @@ static int parse_rbd_opts_token(char *c, void *private) case Opt_read_write: rbd_opts->read_only = false; break; + case Opt_lock_on_read: + rbd_opts->lock_on_read = true; + break; default: /* libceph prints "bad option" msg */ return -EINVAL; @@ -4073,7 +4080,7 @@ static void rbd_queue_workfn(struct work_struct *work) u64 length = blk_rq_bytes(rq); enum obj_operation_type op_type; u64 mapping_size; - bool must_be_locked = false; + bool must_be_locked; int result; if (rq->cmd_type != REQ_TYPE_FS) { @@ -4136,6 +4143,9 @@ static void rbd_queue_workfn(struct work_struct *work) snapc = rbd_dev->header.snapc; ceph_get_snap_context(snapc); must_be_locked = rbd_is_lock_supported(rbd_dev); + } else { + must_be_locked = rbd_dev->opts->lock_on_read && + rbd_is_lock_supported(rbd_dev); } up_read(&rbd_dev->header_rwsem); @@ -5721,6 +5731,7 @@ static int rbd_add_parse_args(const char *buf, rbd_opts->read_only = RBD_READ_ONLY_DEFAULT; rbd_opts->queue_depth = RBD_QUEUE_DEPTH_DEFAULT; + rbd_opts->lock_on_read = RBD_LOCK_ON_READ_DEFAULT; copts = ceph_parse_options(options, mon_addrs, mon_addrs + mon_addrs_size - 1,