CEPH filesystem development
 help / color / mirror / Atom feed
From: Alex Elder <elder@inktank.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 8/9] rbd: define rbd_dev_v2_snapc_refresh()
Date: Fri, 07 Sep 2012 16:15:33 -0500	[thread overview]
Message-ID: <504A63F5.4070307@inktank.com> (raw)
In-Reply-To: <504A6273.7030807@inktank.com>

Define a new function rbd_dev_v2_snapc_refresh() to update/refresh
the snapshot context for a format version 2 rbd image.

Update rbd_refresh_header() so it selects which function to use
based on the image format.

Rename __rbd_refresh_header() to be rbd_dev_v1_snapc_refresh()
to be consistent with the naming of its version 2 counterpart.
Similarly rename rbd_refresh_header to be rbd_dev_snapc_refresh().

Unrelated--we use rbd_image_format_valid() here.  Delete the other
use of it, which was primarily put in place to ensure that function
was referenced at the time it was defined.

Signed-off-by: Alex Elder <elder@inktank.com>
---
 drivers/block/rbd.c |   41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index ad27be2..b466393 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -268,7 +268,8 @@ static void rbd_put_dev(struct rbd_device *rbd_dev)
 	put_device(&rbd_dev->dev);
 }

-static int rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver);
+static int rbd_dev_snapc_refresh(struct rbd_device *rbd_dev, u64 *hver);
+static int rbd_dev_v2_snapc_refresh(struct rbd_device *rbd_dev, u64 *hver);

 static int rbd_open(struct block_device *bdev, fmode_t mode)
 {
@@ -1303,7 +1304,7 @@ static void rbd_watch_cb(u64 ver, u64 notify_id,
u8 opcode, void *data)
 	dout("rbd_watch_cb %s notify_id=%llu opcode=%u\n",
 		rbd_dev->header_name, (unsigned long long) notify_id,
 		(unsigned int) opcode);
-	rc = rbd_refresh_header(rbd_dev, &hver);
+	rc = rbd_dev_snapc_refresh(rbd_dev, &hver);
 	if (rc)
 		pr_warning(RBD_DRV_NAME "%d got notification but failed to "
 			   " update snaps: %d\n", rbd_dev->major, rc);
@@ -1718,7 +1719,7 @@ static void __rbd_remove_all_snaps(struct
rbd_device *rbd_dev)
 /*
  * only read the first part of the ondisk header, without the snaps info
  */
-static int __rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver)
+static int rbd_dev_v1_snapc_refresh(struct rbd_device *rbd_dev, u64 *hver)
 {
 	int ret;
 	struct rbd_image_header h;
@@ -1767,12 +1768,16 @@ static int __rbd_refresh_header(struct
rbd_device *rbd_dev, u64 *hver)
 	return ret;
 }

-static int rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver)
+static int rbd_dev_snapc_refresh(struct rbd_device *rbd_dev, u64 *hver)
 {
 	int ret;

+	rbd_assert(rbd_image_format_valid(rbd_dev->image_format));
 	mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
-	ret = __rbd_refresh_header(rbd_dev, hver);
+	if (rbd_dev->image_format == 1)
+		ret = rbd_dev_v1_snapc_refresh(rbd_dev, hver);
+	else
+		ret = rbd_dev_v2_snapc_refresh(rbd_dev, hver);
 	mutex_unlock(&ctl_mutex);

 	return ret;
@@ -1932,7 +1937,7 @@ static ssize_t rbd_image_refresh(struct device *dev,
 	struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
 	int ret;

-	ret = rbd_refresh_header(rbd_dev, NULL);
+	ret = rbd_dev_snapc_refresh(rbd_dev, NULL);

 	return ret < 0 ? ret : size;
 }
@@ -2389,6 +2394,27 @@ static char *rbd_dev_snap_info(struct rbd_device
*rbd_dev, u32 which,
 	return ERR_PTR(-EINVAL);
 }

+static int rbd_dev_v2_snapc_refresh(struct rbd_device *rbd_dev, u64 *hver)
+{
+	int ret;
+
+	down_write(&rbd_dev->header_rwsem);
+	ret = rbd_dev_v2_snap_context(rbd_dev, hver);
+	dout("rbd_dev_v2_snap_context returned %d\n", ret);
+	if (ret)
+		goto out;
+	ret = rbd_dev_snaps_update(rbd_dev);
+	dout("rbd_dev_snaps_update returned %d\n", ret);
+	if (ret)
+		goto out;
+	ret = rbd_dev_snaps_register(rbd_dev);
+	dout("rbd_dev_snaps_register returned %d\n", ret);
+out:
+	up_write(&rbd_dev->header_rwsem);
+
+	return 0;
+}
+
 /*
  * Scan the rbd device's current snapshot list and compare it to the
  * newly-received snapshot context.  Remove any existing snapshots
@@ -2551,7 +2577,7 @@ static int rbd_init_watch_dev(struct rbd_device
*rbd_dev)
 	do {
 		ret = rbd_req_sync_watch(rbd_dev);
 		if (ret == -ERANGE) {
-			rc = rbd_refresh_header(rbd_dev, NULL);
+			rc = rbd_dev_snapc_refresh(rbd_dev, NULL);
 			if (rc < 0)
 				return rc;
 		}
@@ -3034,7 +3060,6 @@ static ssize_t rbd_add(struct bus_type *bus,
 	rc = rbd_dev_probe(rbd_dev);
 	if (rc < 0)
 		goto err_out_client;
-	rbd_assert(rbd_image_format_valid(rbd_dev->image_format));

 	rc = rbd_dev_snaps_update(rbd_dev);
 	if (rc)
-- 
1.7.9.5


  parent reply	other threads:[~2012-09-07 21:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-07 21:09 [PATCH 0/9] rbd: activate v2 image support Alex Elder
2012-09-07 21:13 ` [PATCH 1/9] rbd: lay out header probe infrastructure Alex Elder
2012-09-19 18:35   ` Josh Durgin
2012-09-07 21:13 ` [PATCH 2/9] rbd: add code to get the size of a v2 rbd image Alex Elder
2012-09-19 18:52   ` Josh Durgin
2012-09-07 21:13 ` [PATCH 3/9] rbd: get the object prefix for " Alex Elder
2012-09-19 18:57   ` Josh Durgin
2012-09-07 21:13 ` [PATCH 4/9] rbd: get image features for a v2 image Alex Elder
2012-09-19 19:02   ` Josh Durgin
2012-09-07 21:13 ` [PATCH 5/9] rbd: get the snapshot context " Alex Elder
2012-09-19 19:17   ` Josh Durgin
2012-09-07 21:14 ` [PATCH 6/9] rbd: get snapshot name " Alex Elder
2012-09-19 19:31   ` Josh Durgin
2012-09-07 21:15 ` [PATCH 7/9] rbd: update remaining header fields for v2 Alex Elder
2012-09-19 19:38   ` Josh Durgin
2012-09-07 21:15 ` Alex Elder [this message]
2012-09-19 21:00   ` [PATCH 8/9] rbd: define rbd_dev_v2_snapc_refresh() Josh Durgin
2012-09-07 21:15 ` [PATCH 9/9] rbd: activate v2 image support Alex Elder
2012-09-19 19:56   ` Josh Durgin
2012-09-19 19:57     ` Josh Durgin

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=504A63F5.4070307@inktank.com \
    --to=elder@inktank.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox