From patchwork Sat Dec 15 09:38:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roald van Loon X-Patchwork-Id: 1882611 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 6D748DF2EF for ; Sat, 15 Dec 2012 09:38:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750992Ab2LOJiO (ORCPT ); Sat, 15 Dec 2012 04:38:14 -0500 Received: from mail-ie0-f174.google.com ([209.85.223.174]:50671 "EHLO mail-ie0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750956Ab2LOJiM (ORCPT ); Sat, 15 Dec 2012 04:38:12 -0500 Received: by mail-ie0-f174.google.com with SMTP id c11so7161452ieb.19 for ; Sat, 15 Dec 2012 01:38:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Grsw6/Ty4Yc8oYfu0gYG7GQb5Dk7x+JceWfl4tojBao=; b=Pwh1E3jUQ/uknFWaEdKgovO+tCHBiZ3ARq62WZVR5jeFURdaCxxVHMYMEWRTg8KDwe BY7f9yWT+vHc69P29grEn5N2hpw9Llxh7cMCM8QRpNlnRxyK4sFyLrCpKVESAeijcl28 wZIBWzBEC6F3ChgHF3iBAUhrIcRlN26fkaqIAj7v7jArLuUYIyCfEfBWfvoM3IsNjSrv 4M6gpPjs0PWOyBzq3vSUxNTny6PHyX8UAaYX0uYGOtPWIlgn9zMpLkDAw29jP7kjwlAF vdompJhHHVNno8JCPdwcihyRYg5KWsik45aJ+qdnLzojch0ErKS8zYORyTibaoDp8QbR KTTA== MIME-Version: 1.0 Received: by 10.50.37.168 with SMTP id z8mr4227217igj.1.1355564292441; Sat, 15 Dec 2012 01:38:12 -0800 (PST) Received: by 10.64.37.7 with HTTP; Sat, 15 Dec 2012 01:38:12 -0800 (PST) Date: Sat, 15 Dec 2012 10:38:12 +0100 Message-ID: Subject: [PATCH] config: replace direct access with macros From: Roald van Loon To: ceph-devel@vger.kernel.org Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org For the new configuration framework, I need some way to be able to move slowly between the 'old' way (md_config_t) and the upcoming 'new' way. I suggest we use macros for this. I've attached this patch as an example of how I think we could accomplish this (that's why I included multiple diffs instead of mailing them separately). First of all, I've included a stripped down config/config.h with the macro definitions. I also forward-included this header in the current common/config.h so I don't have to touch a large number of files. I've also changed some entries in MonMap.cc::build_initial to show how we can use the macros. If this is OK with you guys, I want to slowly replace access to configuration value with these macros. Signed-off-by: Roald van Loon --- src/common/config.h | 2 ++ src/config/config.h | 36 ++++++++++++++++++++++++++++++++++++ src/mon/MonMap.cc | 18 +++++++++--------- 3 files changed, 47 insertions(+), 9 deletions(-) return r; } -- 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 diff --git a/src/common/config.h b/src/common/config.h index 86d240f..c9e2d1c 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -262,4 +262,6 @@ enum config_subsys_id { ceph_subsys_max }; +#include "config/config.h" // forward include this here, to allow easy transition + #endif diff --git a/src/config/config.h b/src/config/config.h new file mode 100644 index 0000000..3eb1c05 --- /dev/null +++ b/src/config/config.h @@ -0,0 +1,36 @@ +#ifndef CEPH_CONFIG_CONFIG_H +#define CEPH_CONFIG_CONFIG_H + +#ifdef CEPH_USE_NEW_CONFIG + + +#else /* CEPH_USE_NEW_CONFIG */ + +#define CEPH_GLOBAL_CFG(type, paramname) \ + g_ceph_context->_conf->paramname +#define CEPH_GLOBAL_CFG_ID \ + g_ceph_context->_conf->name.get_id() + +#define CEPH_GLOBAL_CFG_HAS(paramname) true +#define CEPH_GLOBAL_CFG_STR(paramname) g_ceph_context->_conf->paramname +#define CEPH_GLOBAL_CFG_UUID(paramname) CEPH_CFG(uuid_d, paramname) +#define CEPH_GLOBAL_CFG_ADDR(paramname) CEPH_CFG(entity_addr_t, paramname) +#define CEPH_GLOBAL_CFG_INT(paramname) CEPH_CFG(int, paramname) +#define CEPH_GLOBAL_CFG_BOOL(paramname) CEPH_CFG(bool, paramname) + +#define CEPH_CFG(cct, type, paramname) \ + cct->_conf->paramname +#define CEPH_CFG_ID(cct) \ + cct->_conf->name.get_id() + +#define CEPH_CFG_HAS(cct, paramname) true +#define CEPH_CFG_STR(cct, paramname) cct->_conf->paramname +#define CEPH_CFG_UUID(cct, paramname) CEPH_CFG(cct, uuid_d, paramname) +#define CEPH_CFG_ADDR(cct, paramname) CEPH_CFG(cct, entity_addr_t, paramname) +#define CEPH_CFG_INT(cct, paramname) CEPH_CFG(cct, int, paramname) +#define CEPH_CFG_BOOL(cct, paramname) CEPH_CFG(cct, bool, paramname) + +#endif /* CEPH_USE_NEW_CONFIG */ + + +#endif /* CEPH_CONFIG_CONFIG_H */ diff --git a/src/mon/MonMap.cc b/src/mon/MonMap.cc index 5a9d6ce..e444ba4 100644 --- a/src/mon/MonMap.cc +++ b/src/mon/MonMap.cc @@ -244,31 +244,31 @@ int MonMap::build_initial(CephContext *cct, ostream& errout) { const md_config_t *conf = cct->_conf; // file? - if (!conf->monmap.empty()) { + if (!CEPH_CFG_STR(cct, monmap).empty()) { int r; try { - r = read(conf->monmap.c_str()); + r = read(CEPH_CFG_STR(cct, monmap).c_str()); } catch (const buffer::error &e) { r = -EINVAL; } if (r >= 0) return 0; - errout << "unable to read/decode monmap from " << conf->monmap - << ": " << cpp_strerror(-r) << std::endl; + errout << "unable to read/decode monmap from " << CEPH_CFG_STR(cct, monmap) + << ": " << cpp_strerror(-r) << std::endl; return r; } // fsid from conf? - if (!cct->_conf->fsid.is_zero()) { - fsid = cct->_conf->fsid; + if (!CEPH_CFG_UUID(cct, fsid).is_zero()) { + fsid = CEPH_CFG_UUID(cct, fsid); } // -m foo? - if (!conf->mon_host.empty()) { - int r = build_from_host_list(conf->mon_host, "noname-"); + if (!CEPH_CFG_STR(cct, mon_host).empty()) { + int r = build_from_host_list(CEPH_CFG_STR(cct, mon_host), "noname-"); if (r < 0) { - errout << "unable to parse addrs in '" << conf->mon_host << "'" + errout << "unable to parse addrs in '" << CEPH_CFG_STR(cct, mon_host) << "'" << std::endl;