]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: add ceph_release, ceph_shutdown
authorNoah Watkins <noahwatkins@gmail.com>
Thu, 25 Oct 2012 20:00:05 +0000 (13:00 -0700)
committerNoah Watkins <noahwatkins@gmail.com>
Fri, 26 Oct 2012 15:38:26 +0000 (08:38 -0700)
Notes that ceph_shutdown() is now deprecated.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
src/include/cephfs/libcephfs.h
src/libcephfs.cc
src/test/libcephfs/test.cc

index 9178e5b3726fb336dceb5a7394a3efb566b6d555..4776a71109345be98790c98a1694b1b6534d80eb 100644 (file)
@@ -108,8 +108,29 @@ int ceph_create_with_context(struct ceph_mount_info **cmount, struct CephContext
 int ceph_mount(struct ceph_mount_info *cmount, const char *root);
 
 /**
- * Destroy the ceph mount handle.  This should be called on completion of all
- * libcephfs functions.
+ * Unmount a mount handle.
+ *
+ * @param cmount the mount handle
+ * @return 0 on success, negative error code on failure
+ */
+int ceph_unmount(struct ceph_mount_info *cmount);
+
+/**
+ * Destroy the mount handle.
+ *
+ * The handle should not be mounted. This should be called on completion of
+ * all libcephfs functions.
+ *
+ * @param cmount the mount handle
+ * @return 0 on success, negative error code on failure.
+ */
+int ceph_release(struct ceph_mount_info *cmount);
+
+/**
+ * Deprecated. Unmount and destroy the ceph mount handle. This should be
+ * called on completion of all libcephfs functions.
+ *
+ * Equivalent to ceph_unmount() + ceph_release() without error handling.
  *
  * @param cmount the mount handle to shutdown
  */
index d589633f5aa651e9e8305d030ec57cd389ca0c43..fb6274f024c64cf07e51900bf650c24df762ca57 100644 (file)
@@ -106,6 +106,14 @@ public:
     return ret;
   }
 
+  int unmount()
+  {
+    if (!mounted)
+      return -ENOTCONN;
+    shutdown();
+    return 0;
+  }
+
   void shutdown()
   {
     if (mounted) {
@@ -235,6 +243,19 @@ extern "C" int ceph_create(struct ceph_mount_info **cmount, const char * const i
   return ceph_create_with_context(cmount, cct);
 }
 
+extern "C" int ceph_unmount(struct ceph_mount_info *cmount)
+{
+  return cmount->unmount();
+}
+
+extern "C" int ceph_release(struct ceph_mount_info *cmount)
+{
+  if (cmount->is_mounted())
+    return -EISCONN;
+  delete cmount;
+  return 0;
+}
+
 extern "C" void ceph_shutdown(struct ceph_mount_info *cmount)
 {
   cmount->shutdown();
index 6d707495632024d84e111573b2fba8b376a40741..85600f98bd7b57cdd71b41229dc9a8b8f73e4259 100644 (file)
@@ -79,6 +79,63 @@ TEST(LibCephFS, Mount_double) {
   ceph_shutdown(cmount);
 }
 
+TEST(LibCephFS, Mount_remount) {
+
+  struct ceph_mount_info *cmount;
+
+  ASSERT_EQ(0, ceph_create(&cmount, NULL));
+  ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
+
+  CephContext *cct = ceph_get_mount_context(cmount);
+  ASSERT_EQ(0, ceph_mount(cmount, "/"));
+  ASSERT_EQ(0, ceph_unmount(cmount));
+
+  ASSERT_EQ(0, ceph_mount(cmount, "/"));
+  ASSERT_EQ(cct, ceph_get_mount_context(cmount));
+
+  ceph_shutdown(cmount);
+}
+
+TEST(LibCephFS, Unmount_unmounted) {
+
+  struct ceph_mount_info *cmount;
+
+  ASSERT_EQ(0, ceph_create(&cmount, NULL));
+  ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
+  ASSERT_EQ(-ENOTCONN, ceph_unmount(cmount));
+}
+
+TEST(LibCephFS, Release_unmounted) {
+
+  struct ceph_mount_info *cmount;
+
+  ASSERT_EQ(0, ceph_create(&cmount, NULL));
+  ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
+  ASSERT_EQ(0, ceph_release(cmount));
+}
+
+TEST(LibCephFS, Release_mounted) {
+
+  struct ceph_mount_info *cmount;
+
+  ASSERT_EQ(0, ceph_create(&cmount, NULL));
+  ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
+  ASSERT_EQ(0, ceph_mount(cmount, "/"));
+  ASSERT_EQ(-EISCONN, ceph_release(cmount));
+  ceph_shutdown(cmount);
+}
+
+TEST(LibCephFS, Unmount_release) {
+
+  struct ceph_mount_info *cmount;
+
+  ASSERT_EQ(0, ceph_create(&cmount, NULL));
+  ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
+  ASSERT_EQ(0, ceph_mount(cmount, "/"));
+  ASSERT_EQ(0, ceph_unmount(cmount));
+  ASSERT_EQ(0, ceph_release(cmount));
+}
+
 TEST(LibCephFS, Mount) {
   struct ceph_mount_info *cmount;
   ASSERT_EQ(ceph_create(&cmount, NULL), 0);