From patchwork Thu Jul 26 18:45:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1244101 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 3F54E3FC5A for ; Thu, 26 Jul 2012 18:45:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752423Ab2GZSpR (ORCPT ); Thu, 26 Jul 2012 14:45:17 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:43395 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752313Ab2GZSpQ (ORCPT ); Thu, 26 Jul 2012 14:45:16 -0400 Received: by yenl2 with SMTP id l2so2317882yen.19 for ; Thu, 26 Jul 2012 11:45:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=2WEWBElJeKFa52wZt58tqEjUSfrH8H02ItlLrKvM4uk=; b=Nk7hmmiaSRRmZpBjEX7dL6iQFi3JF/zeeAImodNhIG7zQmoITXVgcVCoiV6dbYn/c7 45IQ+E5GdiRPOf6aH7DB/hZjbh2EPgUM10dBamxhCWJpB5edV69gmN2WKs9A4ZUwYBjW ebGsoRDpwoSZHVyyzZt5j2GrU9dU7NFm5/HqitBWn5t9cvedwgCJSIkO1p9hZsXjMl0B qxkrKpRNgY6ROn2YCaJDHz1ay+6a2gwXSymqzc6w4vF0yOE0DketQwpVSRQJdX7gi2ua 9/fXbxlYo4Q3mjupH24ma6Fp7HcWLm+E0qvcpT2psIiO80Jt+TgPGLuGn9a7L5iIG5xz E0dg== Received: by 10.236.182.228 with SMTP id o64mr28297702yhm.85.1343328316177; Thu, 26 Jul 2012 11:45:16 -0700 (PDT) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPS id f68sm43426191yhh.22.2012.07.26.11.45.14 (version=SSLv3 cipher=OTHER); Thu, 26 Jul 2012 11:45:15 -0700 (PDT) Message-ID: <5011903A.2030104@inktank.com> Date: Thu, 26 Jul 2012 13:45:14 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 5/6] rbd: encapsulate header validity test References: <50118F33.7080502@inktank.com> In-Reply-To: <50118F33.7080502@inktank.com> X-Gm-Message-State: ALoCoQmakWP9j7DNFEwMvQWxgPQbHws8ClDJk1gKOllIDSej/Gqt39Miu/8zLHU0n1rNXNh5auPc Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org 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 --- drivers/block/rbd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) snap_count = le32_to_cpu(ondisk->snap_count); 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;