From patchwork Thu Sep 6 15:36: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: 1416191 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 5D172DFFCF for ; Thu, 6 Sep 2012 15:36:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757864Ab2IFPgc (ORCPT ); Thu, 6 Sep 2012 11:36:32 -0400 Received: from mail-ie0-f174.google.com ([209.85.223.174]:50522 "EHLO mail-ie0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754434Ab2IFPgb (ORCPT ); Thu, 6 Sep 2012 11:36:31 -0400 Received: by ieje11 with SMTP id e11so3247159iej.19 for ; Thu, 06 Sep 2012 08:36:31 -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=xkqtdJ2RAVfBwKgbpUIurWccAd9LR8q0s/4V0CxQWbI=; b=iaZLMT+rgtYUo34ndBAH8SDQsd3ZOLg5cntyaNvluhKxX3/FzIA8ZlBqrewZvxkWqO N6t3HEKN1SIDuoV70mA2zubaY6oSdErvFZwY8OJ3EdSs33XM1bMpB8x7YX/ljDqvkgz1 8jjdZTKzDNwAD36UIL+wauwPd6+aBpdEItGkQe2L63RbV5oqIQRmJ5vnK/kkf9b6fQYL uFz3kCkELHt7pyg/UV+D00tma/2NL2R22RcMSkt8Zdh1NPWrrjLIcevV6EAERaw2Eyxd p6l4DGnMSLZ2La20UPPQzJ7mptM+GDyk3YUSGsI4bS3CAwU/Q4Mk+wHdy46Sw5CJcxgP 5tnQ== Received: by 10.42.155.135 with SMTP id u7mr2891654icw.25.1346945790978; Thu, 06 Sep 2012 08:36: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 wn5sm3944856igc.7.2012.09.06.08.36.25 (version=SSLv3 cipher=OTHER); Thu, 06 Sep 2012 08:36:28 -0700 (PDT) Message-ID: <5048C2F8.90505@inktank.com> Date: Thu, 06 Sep 2012 10:36:24 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH, v2 06/11] rbd: add read_only rbd map option References: <5037AB20.4000103@inktank.com> <5037AD10.9010203@inktank.com> In-Reply-To: <5037AD10.9010203@inktank.com> X-Gm-Message-State: ALoCoQl6y+1ExfngCjnunwSAHwDGg9qXAPmlVFtGKr3YL+N9FB7/hKFXET8hk6a6bTPgJ68rHy4J 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." Also allow the inverse to be explicitly specified using "read_write" or "rw". Signed-off-by: Alex Elder Reviewed-by: Yehuda Sadeh --- v2: - Made the read_only/ro flag explicitly make the mapping read-only rather than having it toggle. - Added read_write/rw flags to allow a writable mapping to be explicitly requested. Snapshot mappings are silently mapped read-only (even if read_write was requested). drivers/block/rbd.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: b/drivers/block/rbd.c =================================================================== --- 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,21 @@ enum { /* int args above */ Opt_last_string, /* string args above */ + Opt_read_only, + Opt_read_write, + /* 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 */ + {Opt_read_write, "read_write"}, + {Opt_read_write, "rw"}, /* Alternate spelling */ + /* Boolean args above */ {-1, NULL} }; @@ -381,6 +392,8 @@ static int parse_rbd_opts_token(char *c, } 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 +402,12 @@ static int parse_rbd_opts_token(char *c, case Opt_notify_timeout: rbd_opts->notify_timeout = intval; break; + case Opt_read_only: + rbd_opts->read_only = true; + break; + case Opt_read_write: + rbd_opts->read_only = false; + break; default: BUG_ON(token); } @@ -407,6 +426,7 @@ static int rbd_get_client(struct rbd_dev 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, mon_addr + mon_addr_len, @@ -620,7 +640,7 @@ static int rbd_header_set_snap(struct rb 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 { @@ -632,7 +652,7 @@ static int rbd_header_set_snap(struct rb 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;