From patchwork Fri Sep 7 21:13:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1425131 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 C8AEC3FC71 for ; Fri, 7 Sep 2012 21:13:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756514Ab2IGVNc (ORCPT ); Fri, 7 Sep 2012 17:13:32 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:59251 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756189Ab2IGVNc (ORCPT ); Fri, 7 Sep 2012 17:13:32 -0400 Received: by iahk25 with SMTP id k25so21774iah.19 for ; Fri, 07 Sep 2012 14:13:31 -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=XHiUEHNroCrbNArwrZdAnBs15+vM2kFWOCceefR8Bmc=; b=mSyTGFo3ZzjAIk3aKt3l6XSy9XPhprvp99sQJoY9jGGYGqh+BpWn0cAwLcZ50CrNgO IgaFMnBmJ9qE7l+GEEXEg88S8L+vzyER93ZXakeE1PyEPwW2mgnSa971rqL62czxYizE NPCn5fT5rhl4WvtphupJfoyhZOBDOdpIZImVNdAlSwCuqU1j8hJdQw2M8o4GABEHXAlN 7J1pLVro2KqbOYZAexBS5ZJtGCzpZRCC3gdJSHST2cEAkCXFoFWhVWqNaK+SESn43HDh LmhJp6Ns8T8jpeGj4ozWmA/h6oStBoeTNKij8hhTEWdpWeQmnwcKZicUZ/nF+MiRapW+ /cSQ== Received: by 10.43.16.67 with SMTP id px3mr94798icb.17.1347052411396; Fri, 07 Sep 2012 14:13:31 -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 p8sm453212igl.16.2012.09.07.14.13.30 (version=SSLv3 cipher=OTHER); Fri, 07 Sep 2012 14:13:30 -0700 (PDT) Message-ID: <504A6379.7010308@inktank.com> Date: Fri, 07 Sep 2012 16:13:29 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 2/9] rbd: add code to get the size of a v2 rbd image References: <504A6273.7030807@inktank.com> In-Reply-To: <504A6273.7030807@inktank.com> X-Gm-Message-State: ALoCoQkAc/YiZuf+7axuuTzKf+4MM//Ee7gAOrYZ9g3vSfq1y75B7Xuf5CD/e6Lx19zzfXn8UEL+ Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org The size of an rbd format 2 image is fetched from the server using a "get_size" method. The same method is used for getting the size of a snapshot, so structure this addition with a generic helper routine that we can get this information for either. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) * not present in the new snapshot context. Add a new snapshot for @@ -2631,6 +2672,7 @@ out_err: static int rbd_dev_v2_probe(struct rbd_device *rbd_dev) { size_t size; + int ret; /* * Image id was filled in by the caller. Record the header @@ -2642,12 +2684,23 @@ static int rbd_dev_v2_probe(struct rbd_device *rbd_dev) return -ENOMEM; sprintf(rbd_dev->header_name, "%s%s", RBD_HEADER_PREFIX, rbd_dev->image_id); + + /* Get the size and object order for the image */ + + ret = rbd_dev_v2_image_size(rbd_dev); + if (ret < 0) + goto out_err; rbd_dev->image_format = 2; dout("discovered version 2 image, header name is %s\n", rbd_dev->header_name); return -ENOTSUPP; +out_err: + kfree(rbd_dev->header_name); + rbd_dev->header_name = NULL; + + return ret; } /* diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 019e695..24d12e3 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -2123,6 +2123,47 @@ static char *rbd_dev_v1_snap_info(struct rbd_device *rbd_dev, u32 which, } /* + * Get the size and object order for an image snapshot, or if + * snap_id is CEPH_NOSNAP, gets this information for the base + * image. + */ +static int _rbd_dev_v2_snap_size(struct rbd_device *rbd_dev, u64 snap_id, + u8 *order, u64 *snap_size) +{ + __le64 snapid = cpu_to_le64(snap_id); + int ret; + struct { + u8 order; + __le64 size; + } __attribute__ ((packed)) size_buf = { 0 }; + + ret = rbd_req_sync_exec(rbd_dev, rbd_dev->header_name, + "rbd", "get_size", + (char *) &snapid, sizeof (snapid), + (char *) &size_buf, sizeof (size_buf), + CEPH_OSD_FLAG_READ, NULL); + dout("%s: rbd_req_sync_exec returned %d\n", __func__, ret); + if (ret < 0) + return ret; + + *order = size_buf.order; + *snap_size = le64_to_cpu(size_buf.size); + + dout(" snap_id 0x%016llx order = %u, snap_size = %llu\n", + (unsigned long long) snap_id, (unsigned int) *order, + (unsigned long long) *snap_size); + + return 0; +} + +static int rbd_dev_v2_image_size(struct rbd_device *rbd_dev) +{ + return _rbd_dev_v2_snap_size(rbd_dev, CEPH_NOSNAP, + &rbd_dev->header.obj_order, + &rbd_dev->header.image_size); +} + +/* * Scan the rbd device's current snapshot list and compare it to the * newly-received snapshot context. Remove any existing snapshots