From patchwork Mon Aug 6 18:17:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1280661 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 4969FDF288 for ; Mon, 6 Aug 2012 18:17:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932327Ab2HFSRp (ORCPT ); Mon, 6 Aug 2012 14:17:45 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:53282 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932114Ab2HFSRp (ORCPT ); Mon, 6 Aug 2012 14:17:45 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr13so2921462pbb.19 for ; Mon, 06 Aug 2012 11:17:44 -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=XNbMLiIK5CYfR6bn1ndkXXXW9BGhgxfXNjaSB/HCCNE=; b=j+j15q8iCiHdDjZbMr0TJV3hUHmoYDYDWIhXTzKz9+nBvaUHlZJ6nGFi5ULO5PvMFW NuBBBBQbTtG2aFUJOq7+/kY9pigkXsjYyEY3O3izVIISSv7xxP7x+mdt9D/fnJ0KNoFZ eRA0hNF89BcrrMxb3VNMIXnPdtHsIHtMmkat/3X80Hjcrdmmn4E47jhX0K20wFYhSTaM rGpWHttwZQruqmiZOcEGZgCMiGZg7obRwOxVJapy423omS+6dNdW93d7s4RvLDg/1qV8 n5SXn3ANn0GoNhrqmeUB5YTfbmdpizBaVtibCTny0AKTd5ee33BrAgUfHM2c3ie1WqKh okfQ== Received: by 10.68.212.70 with SMTP id ni6mr20875656pbc.22.1344277064761; Mon, 06 Aug 2012 11:17:44 -0700 (PDT) Received: from ?IPv6:2607:f298:a:607:3c9c:52cb:843e:71a9? ([2607:f298:a:607:3c9c:52cb:843e:71a9]) by mx.google.com with ESMTPS id iq1sm5822865pbc.37.2012.08.06.11.17.43 (version=SSLv3 cipher=OTHER); Mon, 06 Aug 2012 11:17:44 -0700 (PDT) Message-ID: <50200A46.3070508@inktank.com> Date: Mon, 06 Aug 2012 11:17:42 -0700 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 2/4] rbd: return earlier in rbd_header_from_disk() References: <502009D1.7090005@inktank.com> In-Reply-To: <502009D1.7090005@inktank.com> X-Gm-Message-State: ALoCoQkI7uzuBu1ujfkbJusROkMWC62Ep867tNqBvcalpgbRjQh/R8tqJo7Q7uOOmvR2iNYsE9GO Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org The only caller of rbd_header_from_disk() is rbd_read_header(). It passes as allocated_snaps the number of snapshots it will have received from the server for the snapshot context that rbd_header_from_disk() is to interpret. The first time through it provides 0--mainly to extract the number of snapshots from the snapshot context header--so that it can allocate an appropriately-sized buffer to receive the entire snapshot context from the server in a second request. rbd_header_from_disk() will not fill in the array of snapshot ids unless the number in the snapshot matches the number the caller had allocated. This patch adjusts that logic a little further to be more efficient. rbd_read_header() doesn't even examine the snapshot context unless the snapshot count (stored in header->total_snaps) matches the number of snapshots allocated. So rbd_header_from_disk() doesn't need to allocate or fill in the snapshot context field at all in that case. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: b/drivers/block/rbd.c =================================================================== --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -541,7 +541,14 @@ static int rbd_header_from_disk(struct r header->comp_type = ondisk->options.comp_type; header->total_snaps = snap_count; - /* Set up the snapshot context */ + /* + * If the number of snapshot ids provided by the caller + * doesn't match the number in the entire context there's + * no point in going further. Caller will try again after + * getting an updated snapshot context from the server. + */ + if (allocated_snaps != snap_count) + return 0; size = sizeof (struct ceph_snap_context); size += snap_count * sizeof (header->snapc->snaps[0]); @@ -553,8 +560,10 @@ static int rbd_header_from_disk(struct r header->snapc->seq = le64_to_cpu(ondisk->snap_seq); header->snapc->num_snaps = snap_count; - if (snap_count && allocated_snaps == snap_count) { - int i; + /* Fill in the snapshot information */ + + if (snap_count) { + u32 i; for (i = 0; i < snap_count; i++) { header->snapc->snaps[i] =