Skip to contentSkip to conversation

rbd: support additional Boolean rbd_dev flags

PATCH New Alex Elder 1 participant 3 messages Feb 29, 2012

Subsystems (2)
lore
Share & tools
lore

Alex Elder

author
#0 lore raw

cover rbd: support additional Boolean rbd_dev flags

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

author
#1 lore raw

PATCH 1/2 rbd: define helpers for read_only flag

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.

---
 drivers/block/rbd.c |   35 ++++++++++++++++++++++++++---------
 1 files changed, 26 insertions(+), 9 deletions(-)
drivers/block/rbd.c +15 -0
index 229f974..e7b443a 100644
@@ -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;
}

Signature · 1 line
1.7.5.4
author
#2 lore raw

PATCH 2/2 rbd: convert to using flags field

In reply to Alex Elder

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.

---
 drivers/block/rbd.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
drivers/block/rbd.c +10 -4
index e7b443a..da38804 100644
@@ -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 */

Signature · 1 line
1.7.5.4