From patchwork Fri Aug 24 16:34:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1372161 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 92374DF28C for ; Fri, 24 Aug 2012 16:34:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964802Ab2HXQec (ORCPT ); Fri, 24 Aug 2012 12:34:32 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:45658 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964805Ab2HXQea (ORCPT ); Fri, 24 Aug 2012 12:34:30 -0400 Received: by mail-iy0-f174.google.com with SMTP id o24so3735552ial.19 for ; Fri, 24 Aug 2012 09:34:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=B7PPxG+lOd5S9nTcv7MliBtP/8O3qqegxH3KEn9RpuU=; b=cDsDmvR7nTZAnmkn04DcGs4NsnjGxNYInXj2BwmlscBnod+NaOYUXL2cEi3SUetdgp gyawhuNq+qd2dn+dPVRkvyv7ok1my8xkkH2tvu8m8MiLUCK6tFMuHDLgj5Kflj0QxJue AgW5HUD+42K/d02Idgf/UBbEZA8qlMEb4ci6eyYBKqI1I+fg8aYZ+AvrNG0EYJU18or2 L73XrIbVbzLmh4UidRwEVQvdbfydkmBqPY7In5N0IZInDj8zW8V+Pgk5mvuM+6RUNCUd kCserafPGQXVb+rtHTJaF8pbxRArNx6YXM/3ybk/4FrmB/szCIjQpBmjtPGbo1Oufztd Mf/A== Received: by 10.50.76.137 with SMTP id k9mr2751985igw.58.1345826070586; Fri, 24 Aug 2012 09:34:30 -0700 (PDT) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPS id i17sm242058igd.5.2012.08.24.09.34.24 (version=SSLv3 cipher=OTHER); Fri, 24 Aug 2012 09:34:29 -0700 (PDT) Message-ID: <5037AD10.9010203@inktank.com> Date: Fri, 24 Aug 2012 11:34:24 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 06/11] rbd: add read_only rbd map option References: <5037AB20.4000103@inktank.com> In-Reply-To: <5037AB20.4000103@inktank.com> X-Gm-Message-State: ALoCoQnr+4XeGJZ3w5anunXhGhCcHcz4u1v2E3bHemUZnVmoP9DEvo5knzYb6756w8DyMYT9PKcO Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Add the ability to map an rbd image read-only, by specifying either "read_only" or "ro" as an option on the rbd "command line." Signed-off-by: Alex Elder --- drivers/block/rbd.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) mon_addr + mon_addr_len, @@ -613,7 +627,7 @@ static int rbd_header_set_snap(struct rbd_device *rbd_dev, u64 *size) sizeof (RBD_SNAP_HEAD_NAME))) { rbd_dev->snap_id = CEPH_NOSNAP; rbd_dev->snap_exists = false; - rbd_dev->read_only = 0; + rbd_dev->read_only = rbd_dev->rbd_opts.read_only; if (size) *size = rbd_dev->header.image_size; } else { @@ -625,7 +639,7 @@ static int rbd_header_set_snap(struct rbd_device *rbd_dev, u64 *size) goto done; rbd_dev->snap_id = snap_id; rbd_dev->snap_exists = true; - rbd_dev->read_only = 1; + rbd_dev->read_only = true; /* No choice for snapshots */ } ret = 0; diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index b40f553..5e22bb5 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -69,7 +69,8 @@ #define DEV_NAME_LEN 32 #define MAX_INT_FORMAT_WIDTH ((5 * sizeof (int)) / 2 + 1) -#define RBD_NOTIFY_TIMEOUT_DEFAULT 10 +#define RBD_NOTIFY_TIMEOUT_DEFAULT 10 +#define RBD_READ_ONLY_DEFAULT false /* * block device image metadata (in-memory version) @@ -91,6 +92,7 @@ struct rbd_image_header { struct rbd_options { int notify_timeout; + bool read_only; }; /* @@ -176,7 +178,7 @@ struct rbd_device { u64 snap_id; /* current snapshot id */ /* whether the snap_id this device reads from still exists */ bool snap_exists; - int read_only; + bool read_only; struct list_head node; @@ -351,12 +353,18 @@ enum { /* int args above */ Opt_last_string, /* string args above */ + Opt_read_only, + /* Boolean args above */ + Opt_last_bool, }; static match_table_t rbd_opts_tokens = { {Opt_notify_timeout, "notify_timeout=%d"}, /* int args above */ /* string args above */ + {Opt_read_only, "read_only"}, + {Opt_read_only, "ro"}, /* Alternate spelling */ + /* Boolean args above */ {-1, NULL} }; @@ -381,6 +389,8 @@ static int parse_rbd_opts_token(char *c, void *private) } else if (token > Opt_last_int && token < Opt_last_string) { dout("got string token %d val %s\n", token, argstr[0].from); + } else if (token > Opt_last_string && token < Opt_last_bool) { + dout("got Boolean token %d\n", token); } else { dout("got token %d\n", token); } @@ -389,6 +399,9 @@ static int parse_rbd_opts_token(char *c, void *private) case Opt_notify_timeout: rbd_opts->notify_timeout = intval; break; + case Opt_read_only: + rbd_opts->read_only = !rbd_opts->read_only; + break; default: BUG_ON(token); } @@ -407,6 +420,7 @@ static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr, struct rbd_client *rbdc; rbd_opts->notify_timeout = RBD_NOTIFY_TIMEOUT_DEFAULT; + rbd_opts->read_only = RBD_READ_ONLY_DEFAULT; ceph_opts = ceph_parse_options(options, mon_addr,