From 67bc92aa54552a08fd1fc30b272915e601993634 Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Thu, 25 Oct 2012 13:00:05 -0700 Subject: [PATCH] client: add ceph_release, ceph_shutdown Notes that ceph_shutdown() is now deprecated. Signed-off-by: Noah Watkins --- src/include/cephfs/libcephfs.h | 25 +++++++++++++-- src/libcephfs.cc | 21 +++++++++++++ src/test/libcephfs/test.cc | 57 ++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 9178e5b3726fb..4776a71109345 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -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 */ diff --git a/src/libcephfs.cc b/src/libcephfs.cc index d589633f5aa65..fb6274f024c64 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -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(); diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index 6d70749563202..85600f98bd7b5 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -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); -- 2.39.5