From patchwork Thu Jul 26 19:09:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1244271 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 988EAE009B for ; Thu, 26 Jul 2012 19:09:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752532Ab2GZTJM (ORCPT ); Thu, 26 Jul 2012 15:09:12 -0400 Received: from mail-gh0-f174.google.com ([209.85.160.174]:34949 "EHLO mail-gh0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752590Ab2GZTJL (ORCPT ); Thu, 26 Jul 2012 15:09:11 -0400 Received: by mail-gh0-f174.google.com with SMTP id r11so2366170ghr.19 for ; Thu, 26 Jul 2012 12:09:11 -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=2ohxHb4yYSKEFG/01ry39OhvvdwUwiDIkB8eSiMG688=; b=Yin33LUV6HKnSuC0QSoE9Gl7dCtbfwF3nT9EAnqjMbkjDlrcbyN+/lqHBbR3GLTH2w jh+Ohue/+49vSvv4eEWPcuj/eg+OVsBMDyj2TBQYyO8G68Sgy0/843aBZEOgR1ODyrJP mQk5CMMkLX7DS5WxkuXwhKV9u3z4DxjgLWRAzfoBRvDYZ5I0zDYCjwJQVHqHfWZoO1kw LB1uorP9M1XFPPWkJQobn0jgzzxPrpoGk5w3kzT21JNJDYe1WJTeQVfEesUyacIK3SFW JvNw/Lw72oS1fesrckRoWEvWU3A9vlzsGitsiFPNt14kd0YPsJ39Xo3hUcZpkfesdCnz HbqA== Received: by 10.236.144.197 with SMTP id n45mr28362137yhj.95.1343329751263; Thu, 26 Jul 2012 12:09:11 -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 j39sm42754ani.3.2012.07.26.12.09.10 (version=SSLv3 cipher=OTHER); Thu, 26 Jul 2012 12:09:10 -0700 (PDT) Message-ID: <501195D6.4000609@inktank.com> Date: Thu, 26 Jul 2012 14:09:10 -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 6/7] rbd: return obj version in __rbd_refresh_header() References: <50119421.1090702@inktank.com> In-Reply-To: <50119421.1090702@inktank.com> X-Gm-Message-State: ALoCoQm1qFjbnc+qXm+opn3Y4r11OSPzwrH39NveHrF3KAP1QCNdbTQp1NrQoe4nrlIZw0yt+9tV Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Add a new parameter to __rbd_refresh_header() through which the version of the header object is passed back to the caller. In most cases this isn't needed. The main motivation is to normalize (almost) all calls to __rbd_refresh_header() so they are all wrapped immediately by mutex_lock()/mutex_unlock(). Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) pr_warning(RBD_DRV_NAME "%d got notification but failed to " @@ -1702,7 +1701,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) +static int __rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver) { int ret; struct rbd_image_header h; @@ -1727,6 +1726,8 @@ static int __rbd_refresh_header(struct rbd_device *rbd_dev) /* osd requests may still refer to snapc */ ceph_put_snap_context(rbd_dev->header.snapc); + if (hver) + *hver = h.obj_version; rbd_dev->header.obj_version = h.obj_version; rbd_dev->header.image_size = h.image_size; rbd_dev->header.total_snaps = h.total_snaps; @@ -1896,17 +1897,13 @@ static ssize_t rbd_image_refresh(struct device *dev, size_t size) { struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); - int rc; - int ret = size; + int ret; mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); - - rc = __rbd_refresh_header(rbd_dev); - if (rc < 0) - ret = rc; - + ret = __rbd_refresh_header(rbd_dev, NULL); mutex_unlock(&ctl_mutex); - return ret; + + return ret < 0 ? ret : size; } static DEVICE_ATTR(size, S_IRUGO, rbd_size_show, NULL); @@ -2195,7 +2192,7 @@ static int rbd_init_watch_dev(struct rbd_device *rbd_dev) ret = rbd_req_sync_watch(rbd_dev); if (ret == -ERANGE) { mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); - rc = __rbd_refresh_header(rbd_dev); + rc = __rbd_refresh_header(rbd_dev, NULL); mutex_unlock(&ctl_mutex); if (rc < 0) return rc; @@ -2645,7 +2642,7 @@ static ssize_t rbd_snap_add(struct device *dev, if (ret < 0) goto err_unlock; - ret = __rbd_refresh_header(rbd_dev); + ret = __rbd_refresh_header(rbd_dev, NULL); if (ret < 0) goto err_unlock; diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 3daf8fb..31be4ca 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -240,7 +240,7 @@ 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); +static int __rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver); static int rbd_open(struct block_device *bdev, fmode_t mode) { @@ -1223,8 +1223,7 @@ static void rbd_watch_cb(u64 ver, u64 notify_id, u8 opcode, void *data) dout("rbd_watch_cb %s notify_id=%lld opcode=%d\n", rbd_dev->header_name, notify_id, (int) opcode); mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); - rc = __rbd_refresh_header(rbd_dev); - hver = rbd_dev->header.obj_version; + rc = __rbd_refresh_header(rbd_dev, &hver); mutex_unlock(&ctl_mutex); if (rc)