All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@dreamhost.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 1/2] rbd: define helpers for read_only flag
Date: Tue, 28 Feb 2012 20:41:52 -0800	[thread overview]
Message-ID: <4F4DAC90.2000005@dreamhost.com> (raw)
In-Reply-To: <4F4DAC48.7060804@dreamhost.com>

In anticipation of replacing the "read_only" field with a "flags"
field, write some trivial wrapper routines for operating on the
read-only state of an rbd_device.

Change the variable name "dev" in rbd_header_set_snap() to be
"rbd_dev" to follow convention.

Signed-off-by: Alex Elder <elder@dreamhost.com>
---
  drivers/block/rbd.c |   35 ++++++++++++++++++++++++++---------
  1 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 229f974..e7b443a 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -187,6 +187,21 @@ struct rbd_device {
  	struct device		dev;
  };

+static inline bool rbd_dev_is_readonly(struct rbd_device *rbd_dev)
+{
+	return rbd_dev->read_only;
+}
+
+static inline void rbd_dev_set_readonly(struct rbd_device *rbd_dev)
+{
+	rbd_dev->read_only = true;
+}
+
+static inline void rbd_dev_clear_readonly(struct rbd_device *rbd_dev)
+{
+	rbd_dev->read_only = false;
+}
+
  static DEFINE_MUTEX(ctl_mutex);	  /* Serialize 
open/close/setup/teardown */

  static LIST_HEAD(rbd_dev_list);    /* devices */
@@ -245,12 +260,14 @@ static int __rbd_update_snaps(struct rbd_device 
*rbd_dev);
  static int rbd_open(struct block_device *bdev, fmode_t mode)
  {
  	struct rbd_device *rbd_dev = bdev->bd_disk->private_data;
+	bool read_only;

  	rbd_get_dev(rbd_dev);

-	set_device_ro(bdev, rbd_dev->read_only);
+	read_only = rbd_dev_is_readonly(rbd_dev);
+	set_device_ro(bdev, read_only);

-	if ((mode & FMODE_WRITE) && rbd_dev->read_only)
+	if ((mode & FMODE_WRITE) && read_only)
  		return -EROFS;

  	return 0;
@@ -589,11 +606,11 @@ static int snap_by_name(struct rbd_image_header 
*header, const char *snap_name,
  	return -ENOENT;
  }

-static int rbd_header_set_snap(struct rbd_device *dev,
+static int rbd_header_set_snap(struct rbd_device *rbd_dev,
  			       const char *snap_name,
  			       u64 *size)
  {
-	struct rbd_image_header *header = &dev->header;
+	struct rbd_image_header *header = &rbd_dev->header;
  	struct ceph_snap_context *snapc = header->snapc;
  	int ret = -ENOENT;

@@ -604,8 +621,8 @@ static int rbd_header_set_snap(struct rbd_device *dev,
  			snapc->seq = header->snap_seq;
  		else
  			snapc->seq = 0;
-		dev->cur_snap = 0;
-		dev->read_only = 0;
+		rbd_dev->cur_snap = 0;
+		rbd_dev_clear_readonly(rbd_dev);
  		if (size)
  			*size = header->image_size;
  	} else {
@@ -613,8 +630,8 @@ static int rbd_header_set_snap(struct rbd_device *dev,
  		if (ret < 0)
  			goto done;

-		dev->cur_snap = header->total_snaps - ret;
-		dev->read_only = 1;
+		rbd_dev->cur_snap = header->total_snaps - ret;
+		rbd_dev_set_readonly(rbd_dev);
  	}

  	ret = 0;
@@ -1476,7 +1493,7 @@ static void rbd_rq_fn(struct request_queue *q)
  		size = blk_rq_bytes(rq);
  		ofs = blk_rq_pos(rq) * SECTOR_SIZE;
  		rq_bio = rq->bio;
-		if (do_write && rbd_dev->read_only) {
+		if (do_write && rbd_dev_is_readonly(rbd_dev)) {
  			__blk_end_request_all(rq, -EROFS);
  			continue;
  		}
-- 
1.7.5.4


  reply	other threads:[~2012-02-29  4:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-29  4:40 [PATCH 0/2] rbd: support additional Boolean rbd_dev flags Alex Elder
2012-02-29  4:41 ` Alex Elder [this message]
2012-02-29  4:41 ` [PATCH 2/2] rbd: convert to using flags field Alex Elder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F4DAC90.2000005@dreamhost.com \
    --to=elder@dreamhost.com \
    --cc=ceph-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.