]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados, rados.py: add rados_create2/init2
authorDan Mick <dan.mick@inktank.com>
Tue, 4 Jun 2013 20:13:02 +0000 (13:13 -0700)
committerDan Mick <dan.mick@inktank.com>
Tue, 4 Jun 2013 20:13:02 +0000 (13:13 -0700)
librados clients, particularly the ceph tool, need to be able
to specify a full 'name'; rados_create enforced 'client.<param>'
with no workaround.  New interface.  Python Rados().__init__ selects
appropriate create function depending on whether name or id is
supplied.

Signed-off-by: Dan Mick <dan.mick@inktank.com>
src/ceph
src/include/rados/librados.h
src/include/rados/librados.hpp
src/librados/librados.cc
src/pybind/rados.py

index c34438ac4d80b70a3b2ec837d5c6535377b3c685..92492c6c91c2b9bf8fcbda4c20f821a23ba2e644 100755 (executable)
--- a/src/ceph
+++ b/src/ceph
@@ -1337,7 +1337,7 @@ def main():
 
     # handle any 'generic' ceph arguments that we didn't parse here
     global cluster
-    cluster = rados.Rados(rados_id=name, conffile='')
+    cluster = rados.Rados(name=name, conffile='')
 
     retargs = cluster.conf_parse_argv(childargs)
     #tmp = childargs
index d22f3a13ff80e0bde102a54bf9a493ef809af274..bb86d5b4a49eff4f30054ea5792b634278af207a 100644 (file)
@@ -197,6 +197,12 @@ void rados_version(int *major, int *minor, int *extra);
  */
 int rados_create(rados_t *cluster, const char * const id);
 
+/**
+ * As in rados_create, but don't assume 'client.'+id; allow full
+ * specification of name
+ */
+int rados_create2(rados_t *cluster, const char * const name);
+
 /**
  * Initialize a cluster handle from an existing configuration.
  *
index fc837c6c15f4e72d6885dd13b9caae12d399b229..8ed8c5ddcfcc5e8ef65092b6a37fb54de14e30ec 100644 (file)
@@ -649,6 +649,7 @@ namespace librados
     ~Rados();
 
     int init(const char * const id);
+    int init2(const char * const name);
     int init_with_context(config_t cct_);
     config_t cct();
     int connect();
index 34b964a3bd15dcbdf39e4040f4581044b6543c60..6901a0c5b1a3a66dd385204a73b95f822042ae9d 100644 (file)
@@ -1203,6 +1203,11 @@ int librados::Rados::init(const char * const id)
   return rados_create((rados_t *)&client, id);
 }
 
+int librados::Rados::init2(const char * const name)
+{
+  return rados_create2((rados_t *)&client, name);
+}
+
 int librados::Rados::init_with_context(config_t cct_)
 {
   return rados_create_with_context((rados_t *)&client, (rados_config_t)cct_);
@@ -1457,14 +1462,10 @@ librados::ObjectOperation::~ObjectOperation()
 }
 
 ///////////////////////////// C API //////////////////////////////
-extern "C" int rados_create(rados_t *pcluster, const char * const id)
+static
+int rados_create_common(rados_t *pcluster, CephInitParameters *iparams)
 {
-  CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
-  if (id) {
-    iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id);
-  }
-
-  CephContext *cct = common_preinit(iparams, CODE_ENVIRONMENT_LIBRARY, 0);
+  CephContext *cct = common_preinit(*iparams, CODE_ENVIRONMENT_LIBRARY, 0);
   cct->_conf->parse_env(); // environment variables override
   cct->_conf->apply_changes(NULL);
 
@@ -1475,6 +1476,27 @@ extern "C" int rados_create(rados_t *pcluster, const char * const id)
   return 0;
 }
 
+extern "C" int rados_create(rados_t *pcluster, const char * const id)
+{
+  CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
+  if (id) {
+    iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id);
+  }
+  return rados_create_common(pcluster, &iparams);
+}
+
+// as above, but don't assume 'client.'; name is a full type.id namestr
+extern "C" int rados_create2(rados_t *pcluster, const char * const name)
+{
+  // client is assumed, but from_str will override
+  CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
+  if (name) {
+    iparams.name.from_str(name);
+  }
+  return rados_create_common(pcluster, &iparams);
+}
+
+
 /* This function is intended for use by Ceph daemons. These daemons have
  * already called global_init and want to use that particular configuration for
  * their cluster.
index 7602aebb4749b2f9e21e9b4c78d3a74ca65d7e0a..02e0969b5ab584f02fbe39dffe056a6741007938 100644 (file)
@@ -182,16 +182,21 @@ class Rados(object):
         raise RadosStateError("You cannot perform that operation on a \
 Rados object in state %s." % (self.state))
 
-    def __init__(self, rados_id=None, conf=None, conffile=None):
+    def __init__(self, rados_id=None, conf=None, conffile=None, name=None):
         self.librados = CDLL('librados.so.2')
         self.cluster = c_void_p()
         self.rados_id = rados_id
-        if rados_id is not None and not isinstance(rados_id, str):
+        if rados_id and not isinstance(rados_id, str):
             raise TypeError('rados_id must be a string or None')
-        if conffile is not None and not isinstance(conffile, str):
+        if conffile and not isinstance(conffile, str):
             raise TypeError('conffile must be a string or None')
-        ret = run_in_thread(self.librados.rados_create,
-                           (byref(self.cluster), c_char_p(rados_id)))
+        if rados_id and name:
+            raise Error("Rados(): can't supply both rados_id and name")
+        fn = self.librados.rados_create
+        if name:
+            fn = self.librados.rados_create2
+        ret = run_in_thread(fn, (byref(self.cluster), c_char_p(rados_id)))
+
         if ret != 0:
             raise Error("rados_initialize failed with error code: %d" % ret)
         self.state = "configuring"