From patchwork Thu Mar 27 18:18:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 3899311 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CCAD29F2E8 for ; Thu, 27 Mar 2014 18:19:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F3B3320253 for ; Thu, 27 Mar 2014 18:19:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1A25920225 for ; Thu, 27 Mar 2014 18:19:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757143AbaC0STQ (ORCPT ); Thu, 27 Mar 2014 14:19:16 -0400 Received: from mail-ee0-f51.google.com ([74.125.83.51]:59405 "EHLO mail-ee0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757142AbaC0STP (ORCPT ); Thu, 27 Mar 2014 14:19:15 -0400 Received: by mail-ee0-f51.google.com with SMTP id c13so3220544eek.38 for ; Thu, 27 Mar 2014 11:19:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=EBEU3sPAzZJA7GjOSv6/UI8VO8H13DV1VlO0AZLwyK0=; b=ki2ocvqm5T7LhmiPsu2ERyGzMGzd3fIg0RsUQNgo0smEJYg3yiowp3oEpCRGcXrB7u +jbbWDegrWQ6OjzG+jqgM/nPfKqFSXC1l8PGusgBNQhJmZ02Amk7Aw6N3hsKBql92Dd9 Puwps3z30ZNtDJ8IQzBCrRSHBphEtCVVCFWK5bM/JZ1W8IcqxcS3Oxud96g6Nlm5pwwI ZG+fnG7slgehWPvJOMSwjmsJBQcAXVvkj0V9JMWjksggi9MDU06xcG6VRXKVcefp6eFv OqW2nA76jLdlpqQm5WFOi59qYS0jkB6vDtX9dxln+afwwYO6r+BCnaG9FVWl6LxWjs0J 67IA== X-Gm-Message-State: ALoCoQl9q1pCVG9rvuluzxkuNltVY6Mn/qlX8HuBmO19Foh//hbZQ8K2VgZ56qUUKwZYoZtX67fV X-Received: by 10.14.203.199 with SMTP id f47mr81671eeo.75.1395944354274; Thu, 27 Mar 2014 11:19:14 -0700 (PDT) Received: from localhost ([109.110.66.7]) by mx.google.com with ESMTPSA id 45sm5985670eeh.9.2014.03.27.11.19.13 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 27 Mar 2014 11:19:13 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 22/33] libceph: primary_affinity decode bits Date: Thu, 27 Mar 2014 20:18:08 +0200 Message-Id: <1395944299-21970-23-git-send-email-ilya.dryomov@inktank.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1395944299-21970-1-git-send-email-ilya.dryomov@inktank.com> References: <1395944299-21970-1-git-send-email-ilya.dryomov@inktank.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Add two helpers to decode primary_affinity (full map, vector) and new_primary_affinity (inc map, map) and switch to them. Signed-off-by: Ilya Dryomov Reviewed-by: Alex Elder --- net/ceph/osdmap.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c index 538b8dd341e8..3ac2098972ea 100644 --- a/net/ceph/osdmap.c +++ b/net/ceph/osdmap.c @@ -959,6 +959,59 @@ static int set_primary_affinity(struct ceph_osdmap *map, int osd, u32 aff) return 0; } +static int decode_primary_affinity(void **p, void *end, + struct ceph_osdmap *map) +{ + u32 len, i; + + ceph_decode_32_safe(p, end, len, e_inval); + if (len == 0) { + kfree(map->osd_primary_affinity); + map->osd_primary_affinity = NULL; + return 0; + } + + ceph_decode_need(p, end, map->max_osd*sizeof(u32), e_inval); + + BUG_ON(len != map->max_osd); + for (i = 0; i < map->max_osd; i++) { + int ret; + + ret = set_primary_affinity(map, i, ceph_decode_32(p)); + if (ret) + return ret; + } + + return 0; + +e_inval: + return -EINVAL; +} + +static int decode_new_primary_affinity(void **p, void *end, + struct ceph_osdmap *map) +{ + u32 n; + + ceph_decode_32_safe(p, end, n, e_inval); + while (n--) { + u32 osd, aff; + int ret; + + ceph_decode_32_safe(p, end, osd, e_inval); + ceph_decode_32_safe(p, end, aff, e_inval); + + ret = set_primary_affinity(map, osd, aff); + if (ret) + return ret; + } + + return 0; + +e_inval: + return -EINVAL; +} + /* * decode a full map. */ @@ -1036,6 +1089,17 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map) goto bad; } + /* primary_affinity */ + if (struct_v >= 2) { + err = decode_primary_affinity(p, end, map); + if (err) + goto bad; + } else { + /* XXX can this happen? */ + kfree(map->osd_primary_affinity); + map->osd_primary_affinity = NULL; + } + /* crush */ ceph_decode_32_safe(p, end, len, e_inval); map->crush = crush_decode(*p, min(*p + len, end)); @@ -1243,6 +1307,13 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, goto bad; } + /* new_primary_affinity */ + if (struct_v >= 2) { + err = decode_new_primary_affinity(p, end, map); + if (err) + goto bad; + } + /* ignore the rest */ *p = end;