From patchwork Fri Apr 26 18:00:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2494611 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 D3D933FD40 for ; Fri, 26 Apr 2013 18:00:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755738Ab3DZSAj (ORCPT ); Fri, 26 Apr 2013 14:00:39 -0400 Received: from mail-ia0-f169.google.com ([209.85.210.169]:46350 "EHLO mail-ia0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753937Ab3DZSAi (ORCPT ); Fri, 26 Apr 2013 14:00:38 -0400 Received: by mail-ia0-f169.google.com with SMTP id l29so3991191iag.0 for ; Fri, 26 Apr 2013 11:00:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=B2KaXemQD8gQ9unFakMR9sJav+8GvNPqHskUs3gNaoc=; b=ZSUXvuBqt5jTGjP3DRzSiA+Jlmkg21dZuqQOPSr6oCm1HB9BHZV3wH15x3E/WQccP6 4bPx+rLGIfu198wnkO/Bl4BH86FnRFBhs/vE2T+9pCjhk4iJULzyc9gPgIpXs7UmHG7Y OWTeS8zwckEPPcdKQ2K9nzJNmuhlpHt9ca38jaaSSjZJkwIfYjY64ksqO1aaREK9mODV 8jljniBWHA4t4UGk46ZoRAmK/1Trhw1Qvi+Ocm0bWl/wR9eVJ0s/OC4nmnJPxwDG0Ne0 zHdUTVBsKiBewPC1J1GzXgsg81cObzL2v2V09nm1qPWC4S2WBeX1r3B3vjP7uGUMO6Is OZ3g== X-Received: by 10.50.57.116 with SMTP id h20mr2541377igq.49.1366999237833; Fri, 26 Apr 2013 11:00:37 -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 ESMTPSA id fl5sm4340163igb.9.2013.04.26.11.00.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 26 Apr 2013 11:00:37 -0700 (PDT) Message-ID: <517AC0C4.9080403@inktank.com> Date: Fri, 26 Apr 2013 13:00:36 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 4/7] rbd: define rbd snap context routines References: <517AC047.6060000@inktank.com> In-Reply-To: <517AC047.6060000@inktank.com> X-Gm-Message-State: ALoCoQk8I+R3vMhJ5zTboN+sSNzRUTk+BY0NxA9lGo+FCk2eobDVzmL7ihRHFcvRlumEyF6Xz4lT Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Encapsulate the creation of a snapshot context for rbd in a new function rbd_snap_context_create(). Define rbd wrappers for getting and dropping references to them once they're created. Signed-off-by: Alex Elder --- drivers/block/rbd.c | 65 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 26 deletions(-) * it. @@ -789,18 +818,13 @@ static int rbd_header_from_disk(struct rbd_image_header *header, /* Allocate and fill in the snapshot context */ header->image_size = le64_to_cpu(ondisk->image_size); - size = sizeof (struct ceph_snap_context); - size += snap_count * sizeof (header->snapc->snaps[0]); - header->snapc = kzalloc(size, GFP_KERNEL); + + header->snapc = rbd_snap_context_create(snap_count); if (!header->snapc) goto out_err; - - atomic_set(&header->snapc->nref, 1); header->snapc->seq = le64_to_cpu(ondisk->snap_seq); - header->snapc->num_snaps = snap_count; for (i = 0; i < snap_count; i++) - header->snapc->snaps[i] = - le64_to_cpu(ondisk->snaps[i].id); + header->snapc->snaps[i] = le64_to_cpu(ondisk->snaps[i].id); return 0; @@ -870,7 +894,7 @@ static void rbd_header_free(struct rbd_image_header *header) header->snap_sizes = NULL; kfree(header->snap_names); header->snap_names = NULL; - ceph_put_snap_context(header->snapc); + rbd_snap_context_put(header->snapc); header->snapc = NULL; } @@ -1720,7 +1744,6 @@ static struct rbd_img_request *rbd_img_request_create( bool child_request) { struct rbd_img_request *img_request; - struct ceph_snap_context *snapc = NULL; img_request = kmalloc(sizeof (*img_request), GFP_ATOMIC); if (!img_request) @@ -1728,13 +1751,8 @@ static struct rbd_img_request *rbd_img_request_create( if (write_request) { down_read(&rbd_dev->header_rwsem); - snapc = ceph_get_snap_context(rbd_dev->header.snapc); + rbd_snap_context_get(rbd_dev->header.snapc); up_read(&rbd_dev->header_rwsem); - if (WARN_ON(!snapc)) { - kfree(img_request); - return NULL; /* Shouldn't happen */ - } - } img_request->rq = NULL; @@ -1744,7 +1762,7 @@ static struct rbd_img_request *rbd_img_request_create( img_request->flags = 0; if (write_request) { img_request_write_set(img_request); - img_request->snapc = snapc; + img_request->snapc = rbd_dev->header.snapc; } else { img_request->snap_id = rbd_dev->spec->snap_id; } @@ -1785,7 +1803,7 @@ static void rbd_img_request_destroy(struct kref *kref) rbd_assert(img_request->obj_request_count == 0); if (img_request_write_test(img_request)) - ceph_put_snap_context(img_request->snapc); + rbd_snap_context_put(img_request->snapc); if (img_request_child_test(img_request)) rbd_obj_request_put(img_request->obj_request); @@ -3049,7 +3067,7 @@ static int rbd_dev_v1_refresh(struct rbd_device *rbd_dev, u64 *hver) kfree(rbd_dev->header.snap_sizes); kfree(rbd_dev->header.snap_names); /* osd requests may still refer to snapc */ - ceph_put_snap_context(rbd_dev->header.snapc); + rbd_snap_context_put(rbd_dev->header.snapc); if (hver) *hver = h.obj_version; @@ -3889,19 +3907,14 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev, u64 *ver) } if (!ceph_has_room(&p, end, snap_count * sizeof (__le64))) goto out; + ret = 0; - size = sizeof (struct ceph_snap_context) + - snap_count * sizeof (snapc->snaps[0]); - snapc = kmalloc(size, GFP_KERNEL); + snapc = rbd_snap_context_create(snap_count); if (!snapc) { ret = -ENOMEM; goto out; } - ret = 0; - - atomic_set(&snapc->nref, 1); snapc->seq = seq; - snapc->num_snaps = snap_count; for (i = 0; i < snap_count; i++) snapc->snaps[i] = ceph_decode_64(&p); diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index fe84975..63040fd 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -671,6 +671,35 @@ static void rbd_client_release(struct kref *kref) kfree(rbdc); } +/* Caller has to fill in snapc->seq and snapc->snaps[0..snap_count-1] */ + +static struct ceph_snap_context *rbd_snap_context_create(u32 snap_count) +{ + struct ceph_snap_context *snapc; + size_t size; + + size = sizeof (struct ceph_snap_context); + size += snap_count * sizeof (snapc->snaps[0]); + snapc = kzalloc(size, GFP_KERNEL); + if (!snapc) + return NULL; + + atomic_set(&snapc->nref, 1); + snapc->num_snaps = snap_count; + + return snapc; +} + +static inline void rbd_snap_context_get(struct ceph_snap_context *snapc) +{ + (void)ceph_get_snap_context(snapc); +} + +static inline void rbd_snap_context_put(struct ceph_snap_context *snapc) +{ + ceph_put_snap_context(snapc); +} + /* * Drop reference to ceph client node. If it's not referenced anymore, release