From patchwork Thu May 21 09:19:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 6453611 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2209EC0432 for ; Thu, 21 May 2015 09:28:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 49AFE20382 for ; Thu, 21 May 2015 09:28:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 52DE120376 for ; Thu, 21 May 2015 09:28:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753805AbbEUJ2y (ORCPT ); Thu, 21 May 2015 05:28:54 -0400 Received: from m59-178.qiye.163.com ([123.58.178.59]:37362 "EHLO m59-178.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751962AbbEUJ2t (ORCPT ); Thu, 21 May 2015 05:28:49 -0400 Received: from localhost.localdomain (unknown [113.240.220.93]) by m59-178.qiye.163.com (HMail) with ESMTPA id B1CEA14816B6; Thu, 21 May 2015 17:21:25 +0800 (CST) From: Li Wang To: Sage Weil , Ilya Dryomov , Alex Elder , Josh Durgin Cc: ceph-devel@vger.kernel.org, Min Chen , Yunchuan Wen , Li Wang Subject: [PATCH 1/4] Rbd: add an option for copy-on-read Date: Thu, 21 May 2015 17:19:52 +0800 Message-Id: <55d6964afbe3bc8f130e8fe07c4dd46b8fbd8e21.1432177493.git.liwang@ubuntukylin.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: X-HM-Spam-Status: e1koWUFPN1dZCBgUCR5ZQUpOVUNJQkJCQkJJSExLTUtOTldZCQ4XHghZQV koKz0kKDQ9Lz06MjckMjUkMz46Pz4pQUtVS0A2IyQiPigkMjUkMz46Pz4pQUtVS0ArLykkNTQkMj UkMz46Pz4pQUlVS0A*IjU6NjI4JDIrJDU0JDI1JDM#Oj8#KUFLVUtANi43LzIkKTgrLyQ*Mj09Pi k#NS8kMjUkMz46Pz4pQUlVS0AyKyQvND86IiQ4NS8kSyRKS0tBS1VLQDIrJEokMzQuKSQ4NS8kSy RKS0tBS1VLQDIrJEokNjI1Li8#JDg1LyRLJEpLQUtVS0AyKyRISyQ2MjUuLz4kODUvJEskTktBS1 VLQDIrJE4kNjI1Li8#JDg1LyRLJEpLQUtVS0AoLjkxPjgvJC80PzoiJDg1LyRLJEpLS0FLVUtAKC 45MT44LyROJDYyNS4vPiQ4NS8kSyRKS0FLVUtAKC45MT44LyRKJDM0LikkODUvJEskSktLQUtVS0 A1NC8kPTo2NC4oJD80NjoyNSQoKz0kPToyN0FKS1VLQCguOSQ#QUpVTk5APTUkKC45JD41LDQpPy gkMzcxJEpLS0lLSkFLVUlDWQY+ X-HM-Sender-Digest: e1kSHx4VD1lBWUc6MRA6UTo4QjoyEgE8LxQ2FzktMUowCQ5VSlVKT0hJ SUtLS0NMSkxMVTMWGhIXVRcSDBoVHDsOGQ4VDw4QAhcSFVUYFBZFWVdZDB4ZWUEdGhcIHldZCAFZ QU9NT043V1kSC1lBWUpKSFVJT0tVSUlLVUJIWQY+ X-HM-Tid: 0a4d75c701dd649fb1cea14816b6 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 From: Min Chen Signed-off-by: Min Chen Signed-off-by: Li Wang Signed-off-by: Yunchuan Wen --- drivers/block/rbd.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index ec6c5c6..446204b 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -324,6 +324,7 @@ struct rbd_mapping { u64 size; u64 features; bool read_only; + bool copy_on_read; /* rbd map option: copy on read */ }; /* @@ -733,6 +734,7 @@ enum { /* string args above */ Opt_read_only, Opt_read_write, + Opt_copy_on_read, /* Boolean args above */ Opt_last_bool, }; @@ -744,15 +746,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_copy_on_read, "copy_on_read"}, + {Opt_copy_on_read, "cor"}, /* Alternate spelling */ /* Boolean args above */ {-1, NULL} }; struct rbd_options { bool read_only; + bool copy_on_read; }; #define RBD_READ_ONLY_DEFAULT false +#define RBD_COPY_ON_READ_DEFAULT false static int parse_rbd_opts_token(char *c, void *private) { @@ -788,6 +794,9 @@ static int parse_rbd_opts_token(char *c, void *private) case Opt_read_write: rbd_opts->read_only = false; break; + case Opt_copy_on_read: + rbd_opts->copy_on_read = true; + break; default: rbd_assert(false); break; @@ -1736,6 +1745,13 @@ static void rbd_osd_trivial_callback(struct rbd_obj_request *obj_request) obj_request_done_set(obj_request); } +static inline bool is_copy_on_read(struct rbd_device *rbd_dev) +{ + rbd_assert(rbd_dev); + rbd_assert(&rbd_dev->mapping); + return !rbd_dev->mapping.read_only && rbd_dev->mapping.copy_on_read; +} + static void rbd_osd_read_callback(struct rbd_obj_request *obj_request) { struct rbd_img_request *img_request = NULL; @@ -4933,6 +4949,7 @@ static int rbd_add_parse_args(const char *buf, goto out_mem; rbd_opts->read_only = RBD_READ_ONLY_DEFAULT; + rbd_opts->copy_on_read = RBD_COPY_ON_READ_DEFAULT; copts = ceph_parse_options(options, mon_addrs, mon_addrs + mon_addrs_size - 1, @@ -5385,6 +5402,7 @@ static ssize_t do_rbd_add(struct bus_type *bus, struct rbd_spec *spec = NULL; struct rbd_client *rbdc; bool read_only; + bool copy_on_read; int rc = -ENOMEM; if (!try_module_get(THIS_MODULE)) @@ -5395,6 +5413,7 @@ static ssize_t do_rbd_add(struct bus_type *bus, if (rc < 0) goto err_out_module; read_only = rbd_opts->read_only; + copy_on_read = rbd_opts->copy_on_read; kfree(rbd_opts); rbd_opts = NULL; /* done with this */ @@ -5436,7 +5455,9 @@ static ssize_t do_rbd_add(struct bus_type *bus, if (rbd_dev->spec->snap_id != CEPH_NOSNAP) read_only = true; + rbd_dev->mapping.read_only = read_only; + rbd_dev->mapping.copy_on_read = copy_on_read; rc = rbd_dev_device_setup(rbd_dev); if (rc) {