All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] rbd: support additional Boolean rbd_dev flags
@ 2012-02-29  4:40 Alex Elder
  2012-02-29  4:41 ` [PATCH 1/2] rbd: define helpers for read_only flag Alex Elder
  2012-02-29  4:41 ` [PATCH 2/2] rbd: convert to using flags field Alex Elder
  0 siblings, 2 replies; 3+ messages in thread
From: Alex Elder @ 2012-02-29  4:40 UTC (permalink / raw)
  To: ceph-devel

This series actually added another flag to the rbd_dev, but the
need for that went away.  Still, I thought these two changes
added value so I kept them.

					-Alex

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] rbd: define helpers for read_only flag
  2012-02-29  4:40 [PATCH 0/2] rbd: support additional Boolean rbd_dev flags Alex Elder
@ 2012-02-29  4:41 ` Alex Elder
  2012-02-29  4:41 ` [PATCH 2/2] rbd: convert to using flags field Alex Elder
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Elder @ 2012-02-29  4:41 UTC (permalink / raw)
  To: ceph-devel

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] rbd: convert to using flags field
  2012-02-29  4:40 [PATCH 0/2] rbd: support additional Boolean rbd_dev flags Alex Elder
  2012-02-29  4:41 ` [PATCH 1/2] rbd: define helpers for read_only flag Alex Elder
@ 2012-02-29  4:41 ` Alex Elder
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Elder @ 2012-02-29  4:41 UTC (permalink / raw)
  To: ceph-devel

To allow having more than just read-only as Boolean state associated
with an rbd_device, replace the "read_only" field with a more
general "flags" field.  The non-atomic versions of bit operations
are fine for our purposes.

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

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index e7b443a..da38804 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -176,7 +176,8 @@ struct rbd_device {
  	char                    snap_name[RBD_MAX_SNAP_NAME_LEN];
  	u32 cur_snap;	/* index+1 of current snapshot within snap context
  			   0 - for the head */
-	int read_only;
+
+	unsigned long		flags;

  	struct list_head	node;

@@ -187,19 +188,24 @@ struct rbd_device {
  	struct device		dev;
  };

+/* Bit position definitions for the rbd_device->flags */
+enum {
+	RBD_DEV_FLAG_READ_ONLY,
+};
+
  static inline bool rbd_dev_is_readonly(struct rbd_device *rbd_dev)
  {
-	return rbd_dev->read_only;
+	return test_bit(RBD_DEV_FLAG_READ_ONLY, &rbd_dev->flags);
  }

  static inline void rbd_dev_set_readonly(struct rbd_device *rbd_dev)
  {
-	rbd_dev->read_only = true;
+	__set_bit(RBD_DEV_FLAG_READ_ONLY, &rbd_dev->flags);
  }

  static inline void rbd_dev_clear_readonly(struct rbd_device *rbd_dev)
  {
-	rbd_dev->read_only = false;
+	__clear_bit(RBD_DEV_FLAG_READ_ONLY, &rbd_dev->flags);
  }

  static DEFINE_MUTEX(ctl_mutex);	  /* Serialize 
open/close/setup/teardown */
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-29  4:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-29  4:40 [PATCH 0/2] rbd: support additional Boolean rbd_dev flags Alex Elder
2012-02-29  4:41 ` [PATCH 1/2] rbd: define helpers for read_only flag Alex Elder
2012-02-29  4:41 ` [PATCH 2/2] rbd: convert to using flags field Alex Elder

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.