static void cephwrap_disconnect(struct vfs_handle_struct *handle) { int ret; if (!cmount) { DBG_ERR("[CEPH] Error, ceph not mounted\n"); return; } /* Should we unmount/shutdown? Only if the last disconnect? */ if (--cmount_cnt) { DBG_DEBUG("[CEPH] Not shuting down CEPH because still more connections\n"); return; } ret = ceph_unmount(cmount); if (ret < 0) { DBG_ERR("[CEPH] failed to unmount: %s\n", strerror(-ret)); } ret = ceph_release(cmount); if (ret < 0) { DBG_ERR("[CEPH] failed to release: %s\n", strerror(-ret)); } cmount = NULL; /* Make it safe */ }
struct ceph_mount_info* cfs_mount(const char* _mons, const char* _id, const char* _keyring_file, const char* _root) { struct ceph_mount_info* ret = NULL; if (unlikely(ceph_create(&ret, _id) != 0)) goto out; if (unlikely(ceph_conf_set(ret, "mon_host", _mons) != 0)) goto err_release; if (unlikely(ceph_conf_set(ret, "keyring", _keyring_file) != 0)) goto err_release; if (unlikely(ceph_init(ret) != 0)) goto err_release; if (unlikely(ceph_mount(ret, _root) != 0)) goto err_release; goto out; err_release: ceph_release(ret); ret = NULL; out: return ret; }
int cfs_unmount(struct ceph_mount_info* _fs) { int ret = -1; if (unlikely(ceph_unmount(_fs) != 0)) return ret; if (unlikely(ceph_release(_fs) != 0)) return ret; return 0; }
static int cephwrap_connect(struct vfs_handle_struct *handle, const char *service, const char *user) { int ret; char buf[256]; int snum = SNUM(handle->conn); const char *conf_file; const char *user_id; if (cmount) { handle->data = cmount; /* We have been here before */ cmount_cnt++; return 0; } /* if config_file and/or user_id are NULL, ceph will use defaults */ conf_file = lp_parm_const_string(snum, "ceph", "config_file", NULL); user_id = lp_parm_const_string(snum, "ceph", "user_id", NULL); DBG_DEBUG("[CEPH] calling: ceph_create\n"); ret = ceph_create(&cmount, user_id); if (ret) { goto err_out; } DBG_DEBUG("[CEPH] calling: ceph_conf_read_file with %s\n", (conf_file == NULL ? "default path" : conf_file)); ret = ceph_conf_read_file(cmount, conf_file); if (ret) { goto err_cm_release; } DBG_DEBUG("[CEPH] calling: ceph_conf_get\n"); ret = ceph_conf_get(cmount, "log file", buf, sizeof(buf)); if (ret < 0) { goto err_cm_release; } DBG_DEBUG("[CEPH] calling: ceph_mount\n"); ret = ceph_mount(cmount, NULL); if (ret < 0) { goto err_cm_release; } /* * encode mount context/state into our vfs/connection holding structure * cmount is a ceph_mount_t* */ handle->data = cmount; cmount_cnt++; return 0; err_cm_release: ceph_release(cmount); cmount = NULL; err_out: /* * Handle the error correctly. Ceph returns -errno. */ DBG_DEBUG("[CEPH] Error return: %s\n", strerror(-ret)); WRAP_RETURN(ret); }