Example #1
0
/*
 * Open a CEPHFS mountpoint.
 */
static bRC connect_to_cephfs(bpContext *ctx)
{
   int status;
   plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext;

   status = ceph_create(&p_ctx->cmount, NULL);
   if (status < 0) {
      berrno be;

      Jmsg(ctx, M_ERROR, "ceph_create failed: %s\n", be.bstrerror(-status));
      return bRC_Error;
   }

   status = ceph_conf_read_file(p_ctx->cmount, p_ctx->conffile);
   if (status < 0) {
      berrno be;

      Jmsg(ctx, M_ERROR, "ceph_conf_read_file(%s) failed: %s\n", p_ctx->conffile, be.bstrerror(-status));
      goto bail_out;
   }

   status = ceph_mount(p_ctx->cmount, NULL);
   if (status < 0) {
      berrno be;

      Jmsg(ctx, M_ERROR, "ceph_mount failed: %s\n", be.bstrerror(-status));
      goto bail_out;
   }

   return bRC_OK;

bail_out:

   return bRC_Error;
}
Example #2
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);
}