All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@inktank.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 5/6] rbd: encapsulate header validity test
Date: Thu, 26 Jul 2012 13:45:14 -0500	[thread overview]
Message-ID: <5011903A.2030104@inktank.com> (raw)
In-Reply-To: <50118F33.7080502@inktank.com>

If an rbd image header is read and it doesn't begin with the
expected magic information, a warning is displayed.  This is
a fairly simple test, but it could be extended at some point.
Fix the comparison so it actually looks at the "text" field
rather than the front of the structure.

In any case, encapsulate the validity test in its own function.

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

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 93b2447..d95d563 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -481,6 +481,12 @@ static void rbd_coll_release(struct kref *kref)
 	kfree(coll);
 }

+static bool rbd_dev_ondisk_valid(struct rbd_image_header_ondisk *ondisk)
+{
+	return !memcmp(&ondisk->text,
+			RBD_HEADER_TEXT, sizeof (RBD_HEADER_TEXT));
+}
+
 /*
  * Create a new header structure, translate header format from the on-disk
  * header.
@@ -492,7 +498,7 @@ static int rbd_header_from_disk(struct
rbd_image_header *header,
 {
 	u32 i, snap_count;

-	if (memcmp(ondisk, RBD_HEADER_TEXT, sizeof(RBD_HEADER_TEXT)))
+	if (!rbd_dev_ondisk_valid(ondisk))
 		return -ENXIO;

 	snap_count = le32_to_cpu(ondisk->snap_count);
-- 
1.7.9.5


  parent reply	other threads:[~2012-07-26 18:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-26 18:40 [PATCH 0/6] ceph: simple cleanups (mostly rbd) Alex Elder
2012-07-26 18:44 ` [PATCH 1/6] rbd: drop extra header_rwsem init Alex Elder
2012-07-26 18:44 ` [PATCH 2/6] rbd: simplify __rbd_remove_all_snaps() Alex Elder
2012-07-26 18:44 ` [PATCH 3/6] rbd: clean up a few dout() calls Alex Elder
2012-07-26 18:45 ` [PATCH 4/6] ceph: define snap counts as u32 everywhere Alex Elder
2012-07-26 18:45 ` Alex Elder [this message]
2012-07-26 18:45 ` [PATCH 6/6] rbd: rename rbd_device->id Alex Elder
2012-07-26 19:31 ` [PATCH 0/6] ceph: simple cleanups (mostly rbd) 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=5011903A.2030104@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 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.