From patchwork Sun Feb 8 14:17:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ding Dinghua X-Patchwork-Id: 5797541 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1FF169F36A for ; Sun, 8 Feb 2015 14:17:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 327A520172 for ; Sun, 8 Feb 2015 14:17:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2C93920166 for ; Sun, 8 Feb 2015 14:17:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752675AbbBHORy (ORCPT ); Sun, 8 Feb 2015 09:17:54 -0500 Received: from mail-la0-f52.google.com ([209.85.215.52]:45637 "EHLO mail-la0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751640AbbBHORx (ORCPT ); Sun, 8 Feb 2015 09:17:53 -0500 Received: by labge10 with SMTP id ge10so8889554lab.12 for ; Sun, 08 Feb 2015 06:17:52 -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=yWXQSQwuJLFJ2b+0/frGFKUta/axxCETQv0iIshwx/U=; b=NvEwfktEnyem+qf3TeGWrY15jJEnvrQtkej8hsVCj0NcjYk+CUIPtKO+3NbKa2njd2 64qTkEWCMKIRjlQmgTIb9B0T7PfPb7xNut3Uo7/6TL8V4KyKw/g/GTAzmxEJiieNj+Uh XgmZa8XVWexcd6nSXU2MFM4leepL8IdNz9i0LEped754WAVe4hU4mvrn2QSBr5H3uyEp Ui4E/wj68bhiLL40YN4BMzw+gub7DMHNmIYZFVBJ/exKQM8q2yLILIgBC89YMSDd6jJh /yfl5c+OOIHDq7/1AmfsSswd1yvGEXFmAnAb5eqKU+lI1afi9MeHKr8dzO48NW2AUsca W6Aw== MIME-Version: 1.0 X-Received: by 10.112.224.133 with SMTP id rc5mr12155499lbc.31.1423405071945; Sun, 08 Feb 2015 06:17:51 -0800 (PST) Received: by 10.25.209.200 with HTTP; Sun, 8 Feb 2015 06:17:51 -0800 (PST) In-Reply-To: References: Date: Sun, 8 Feb 2015 22:17:51 +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 Ping.. 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. > 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. > > 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 : >> 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... > > > > -- > Ding Dinghua 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 12:02 GMT+08:00 Ding Dinghua :