]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados-config: added a command line tool to dump librados version
authorYehuda Sadeh <yehuda@hq.newdream.net>
Thu, 6 Jan 2011 23:04:07 +0000 (15:04 -0800)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Fri, 7 Jan 2011 18:45:36 +0000 (10:45 -0800)
src/Makefile.am
src/include/librados.h
src/librados-config.cc [new file with mode: 0644]
src/librados.cc

index 95c7db997ae3c201f7085e5c312bf337d404ba90..b7207379da27e46a28f3963247fc090c78269860 100644 (file)
@@ -88,12 +88,16 @@ sbin_PROGRAMS += mount.ceph
 cephfs_SOURCES = cephfs.cc
 bin_PROGRAMS += cephfs
 
+librados_config_SOURCES = librados-config.cc
+librados_config_LDADD = librados.la
+bin_PROGRAMS += librados-config
+
 # synthetic client
 csyn_SOURCES = csyn.cc msg/SimpleMessenger.cc
 csyn_LDADD = libclient.a libosdc.a libcrush.a libcommon.a -lpthread -lm $(CRYPTOPP_LIBS)
 bin_PROGRAMS += csyn
 
-core: cmon cosd cmds ceph cephfs cconf monmaptool osdmaptool crushtool csyn
+core: cmon cosd cmds ceph cephfs librados-config cconf monmaptool osdmaptool crushtool csyn
 
 
 # fuse targets?
@@ -868,7 +872,7 @@ noinst_HEADERS = \
        tools/gui.h\
        tools/gui_resources.h
 
-all_sources = $(cmon_SOURCES) $(ceph_SOURCES) $(cephfs_SOURCES) $(cauthtool_SOURCES) $(monmaptool_SOURCES) \
+all_sources = $(cmon_SOURCES) $(ceph_SOURCES) $(cephfs_SOURCES) $(librados_config_SOURCES) $(cauthtool_SOURCES) $(monmaptool_SOURCES) \
        $(crushtool_SOURCES) $(osdmaptool_SOURCES) $(cconf_SOURCES) $(mount_ceph_SOURCES) $(cmds_SOURCES) \
        $(dumpjournal_SOURCES) $(cosd_SOURCES) $(dupstore_SOURCES) $(streamtest_SOURCES) $(csyn_SOURCES)  \
        $(testmsgr_SOURCES) $(cfuse_SOURCES) $(fakefuse_SOURCES) $(psim_SOURCES) \
index a83d682316b85ed80890b6837ecd5c5ffd7db95f..c237cadc86fcf98210cbcb34bc10d35a2b7ad81e 100644 (file)
@@ -17,16 +17,17 @@ extern "C" {
 
 #define LIBRADOS_VER_MAJOR 0
 #define LIBRADOS_VER_MINOR 25
+#define LIBRADOS_VER_EXTRA 0
 
-#define LIBRADOS_VERSION(maj, min) ((maj << 16) + min)
+#define LIBRADOS_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
 
-#define LIBRADOS_VERSION_CODE LIBRADOS_VERSION(LIBRADOS_VER_MAJOR, LIBRADOS_VER_MINOR)
+#define LIBRADOS_VERSION_CODE LIBRADOS_VERSION(LIBRADOS_VER_MAJOR, LIBRADOS_VER_MINOR, LIBRADOS_VER_EXTRA)
 
 /* initialization */
 int rados_initialize(int argc, const char **argv); /* arguments are optional */
 void rados_deinitialize();
 
-void librados_version(int *major, int *minor);
+void librados_version(int *major, int *minor, int *extra);
 
 /* pools */
 typedef void *rados_pool_t;
diff --git a/src/librados-config.cc b/src/librados-config.cc
new file mode 100644 (file)
index 0000000..fd3a4df
--- /dev/null
@@ -0,0 +1,71 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License version 2, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#define __STDC_FORMAT_MACROS
+#include "config.h"
+
+#include "common/common_init.h"
+#include "include/librados.h"
+
+void usage()
+{
+  cout << "usage: librados-config [option]\n"
+       << "where options are:\n"
+       << "  --version                    library version\n"
+       << "  --vernum                     library version code\n";
+}
+
+void usage_exit()
+{
+  assert(1);
+  usage();
+  exit(1);
+}
+int main(int argc, const char **argv) 
+{
+  vector<const char*> args;
+  DEFINE_CONF_VARS(usage_exit);
+  argv_to_vec(argc, argv, args);
+  env_to_vec(args);
+
+  common_set_defaults(false);
+  // common_init(args, "librados-config", false);  /* this overrides --version.. */
+  set_foreground_logging();
+
+  bool opt_version = false;
+  bool opt_vernum = false;
+
+  FOR_EACH_ARG(args) {
+    if (CONF_ARG_EQ("version", '\0')) {
+      CONF_SAFE_SET_ARG_VAL(&opt_version, OPT_BOOL);
+    } else if (CONF_ARG_EQ("vernum", '\0')) {
+      CONF_SAFE_SET_ARG_VAL(&opt_vernum, OPT_BOOL);
+    } else {
+      usage_exit();
+    }
+  }
+  if (!opt_version && !opt_vernum)
+    usage_exit();
+
+  if (opt_version) {
+    int maj, min, ext;
+    librados_version(&maj, &min, &ext);
+    cout << maj << "." << min << "." << ext << std::endl;
+  } else if (opt_vernum) {
+    cout << hex << LIBRADOS_VERSION_CODE << dec << std::endl;
+  }
+
+  return 0;
+}
+
index bdfa2b6e76dec89a068ee2bce3cebbcbea0e52a6..7604124c03f766a764f49c069f80046cce2e32a8 100644 (file)
@@ -2300,12 +2300,14 @@ extern "C" void rados_deinitialize()
   rados_init_mutex.Unlock();
 }
 
-extern "C" void librados_version(int *major, int *minor)
+extern "C" void librados_version(int *major, int *minor, int *extra)
 {
   if (major)
     *major = LIBRADOS_VER_MAJOR;
   if (minor)
     *minor = LIBRADOS_VER_MINOR;
+  if (extra)
+    *extra = LIBRADOS_VER_EXTRA;
 }
 
 extern "C" int rados_lookup_pool(const char *name)