From patchwork Wed Feb 4 04:02:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ding Dinghua X-Patchwork-Id: 5774401 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C2B54BF440 for ; Wed, 4 Feb 2015 04:02:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C7093201D3 for ; Wed, 4 Feb 2015 04:02:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A6E9A2015E for ; Wed, 4 Feb 2015 04:02:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754632AbbBDECa (ORCPT ); Tue, 3 Feb 2015 23:02:30 -0500 Received: from mail-lb0-f173.google.com ([209.85.217.173]:33789 "EHLO mail-lb0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752875AbbBDECa (ORCPT ); Tue, 3 Feb 2015 23:02:30 -0500 Received: by mail-lb0-f173.google.com with SMTP id p9so42346935lbv.4 for ; Tue, 03 Feb 2015 20:02:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=HSDRtV3SVN1ik0zQ3FOVkbprIbahhaOhv9UQJnEsUv4=; b=yEIOmaBPo5YtngXuj2rLnXOBDYnVuhms7oSE65xKKKWvBD0kJp/tsE5oPR5p7HVs7r tNy6gyiR4xG4sOk4q3mNcJFUUVBpTL65/iyYIfJFzKRnh8fhA32UM9EHvS2of7R0kdxr I1Qy7NaxOutyTW/N4oUKrrABR7GVkGTtUMP4U99BI7WWYuty9Mhf1qPCB/6NeT1P5X1Q teUgl8+GexEGfrnuQUggKR36LL+sObFAWe41j6MitGAPweXfuf2emFxJpAGgfBCrvvgO tAKjLm2C9+3tV+aZg/TTSh1KJSZpfkjs3Rni5/xYJulMjQTdkf3lmS/DqO2A0PRaoGzd PZtA== MIME-Version: 1.0 X-Received: by 10.152.21.167 with SMTP id w7mr21998695lae.14.1423022548887; Tue, 03 Feb 2015 20:02:28 -0800 (PST) Received: by 10.25.209.200 with HTTP; Tue, 3 Feb 2015 20:02:28 -0800 (PST) In-Reply-To: References: Date: Wed, 4 Feb 2015 12:02:28 +0800 Message-ID: Subject: Re: Confused about SnapMapper::get_prefix From: Ding Dinghua To: sjust@redhat.com Cc: Gregory Farnum , "ceph-devel@vger.kernel.org" Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I think so, snap_id is defined and used as uint64_t in ceph, but here static_cast may introduce bug, since two snap_id may get the same prefix, then same key in snap_mapper. > Should probably be cast to long unsigned with lX conversion specifier? > -Sam > > On Tue, Feb 3, 2015 at 9:21 AM, Samuel Just wrote: >> It looks like snapid_t is a uint64_t, but snprintf expects an unsigned there. >> -Sam >> >> On Tue, Feb 3, 2015 at 9:15 AM, Gregory Farnum wrote: >>> On Tue, Feb 3, 2015 at 4:12 AM, Ding Dinghua wrote: >>>> Hi all: >>>> I don't understand why SnapMapper::get_prefix static_cast snap >>>> to unsigned: >>>> >>>> string SnapMapper::get_prefix(snapid_t snap) >>>> { >>>> char buf[100]; >>>> int len = snprintf( >>>> buf, sizeof(buf), >>>> "%.*X_", (int)(sizeof(snap)*2), >>>> static_cast(snap)); >>>> return MAPPING_PREFIX + string(buf, len); >>>> } >>>> >>>> Will this limit snapshot count in pool to 2^32 -1 ? >>>> >>>> Could anyone clarify ? Thanks >>> >>> I think the code base is a little confused about whether snaps should >>> be 32 or 64 bits in various places. :( That said, the size of unsigned >>> can vary across architectures, so this should probably be sized more >>> explicitly as whatever it's supposed to be on the disk... diff --git a/src/osd/SnapMapper.cc b/src/osd/SnapMapper.cc index 315e2e2..27cc2b7 100644 --- a/src/osd/SnapMapper.cc +++ b/src/osd/SnapMapper.cc @@ -72,8 +72,7 @@ string SnapMapper::get_prefix(snapid_ t snap) char buf[100]; int len = snprintf( buf, sizeof(buf), - "%.*X_", (int)(sizeof(snap)*2), - static_cast(snap)); + "%.*llX_", (int)(sizeof(snap)*2), snap); 2015-02-04 1:25 GMT+08:00 Samuel Just :