int main(int argc, char **argv) { rados_t cluster; char cluster_name[] = "ceph"; char user_name[] = "client.admin"; APPNAME = &argv[0][2]; uint64_t flags; int err; /* Initialize the cluster handle */ err = rados_create2(&cluster, cluster_name, user_name, flags); // err = rados_create(&cluster, NULL); error_print(err, "Couldn't create the cluster handle!", "Created a cluster handle."); /* Read a Ceph configuration file to configure the cluster handle. */ err = rados_conf_read_file(cluster, "/etc/ceph/ceph.conf"); error_print(err, "Cannot read config file!", "Read the config file."); /* Connect to the cluster */ err = rados_connect(cluster); error_print(err, "Cannot connect to cluster!", "Connected to the cluster."); /* List pools. */ char buf[1024]; err = rados_pool_list(cluster, buf, 1024); split_str(buf, 1024); error_print(err, "Cannot list pools!", buf); /* List pool stats */ char *poolname = strtok(buf, ","); while(poolname != NULL) { rados_ioctx_t io; struct rados_pool_stat_t stats; err = rados_ioctx_create(cluster, poolname, &io); error_print(err, "Cannot create IO context!", "IO context created."); err = rados_ioctx_pool_stat(io, &stats); error_print(err, "Cannot list pool stats!", "Pool stats listed."); printf("[%s][%s]: Number of read: %"PRIu64"\n", APPNAME, poolname, stats.num_rd); printf("[%s][%s]: Number of read in kb: %"PRIu64"\n", APPNAME, poolname, stats.num_rd_kb); printf("[%s][%s]: Number of write: %"PRIu64"\n", APPNAME, poolname, stats.num_wr); printf("[%s][%s]: Number of write in kb: %"PRIu64"\n", APPNAME, poolname, stats.num_wr_kb); rados_ioctx_destroy(io); poolname = strtok(NULL, ","); } /* Shut down the cluster */ rados_shutdown(cluster); printf("[%s]: Cluster shut down.\n", APPNAME); }
int main(int argc, const char **argv) { /* Declare the cluster handle and required arguments. */ rados_t cluster; char cluster_name[] = "ceph"; char user_name[] = "client.admin"; uint64_t flags; /* Initialize the cluster handle with the "ceph" cluster name and the "client.admin" user */ int err; err = rados_create2(&cluster, cluster_name, user_name, flags); //err = rados_create(&cluster, cluster_name); //err = rados_create(&cluster, "admin"); if (err < 0) { fprintf(stderr, "%s: Couldn't create the cluster handle! %s\n", argv[0], strerror(-err)); exit(-1); } else { printf("\nCreated a cluster handle.\n"); } /* Read a Ceph configuration file to configure the cluster handle. */ err = rados_conf_read_file(cluster, "/etc/ceph/ceph.conf"); if (err < 0) { fprintf(stderr, "%s: cannot read config file: %s\n", argv[0], strerror(-err)); exit(-1); } else { printf("\nRead the config file.\n"); } #if 0 /* Read command line arguments */ err = rados_conf_parse_argv(cluster, argc, argv); if (err < 0) { fprintf(stderr, "%s: cannot parse command line arguments: %s\n", argv[0], strerror(-err)); exit(EXIT_FAILURE); } else { printf("\nRead the command line arguments.\n"); } #endif /* Connect to the cluster */ err = rados_connect(cluster); if (err < 0) { fprintf(stderr, "%s: cannot connect to cluster: %s\n", argv[0], strerror(-err)); exit(EXIT_FAILURE); } else { printf("\nConnected to the cluster.\n"); } }
static int ctdb_mutex_rados_ctx_create(const char *ceph_cluster_name, const char *ceph_auth_name, const char *pool_name, rados_t *_ceph_cluster, rados_ioctx_t *_ioctx) { rados_t ceph_cluster = NULL; rados_ioctx_t ioctx = NULL; int ret; ret = rados_create2(&ceph_cluster, ceph_cluster_name, ceph_auth_name, 0); if (ret < 0) { fprintf(stderr, "%s: failed to initialise Ceph cluster %s as %s" " - (%s)\n", progname, ceph_cluster_name, ceph_auth_name, strerror(-ret)); return ret; } /* path=NULL tells librados to use default locations */ ret = rados_conf_read_file(ceph_cluster, NULL); if (ret < 0) { fprintf(stderr, "%s: failed to parse Ceph cluster config" " - (%s)\n", progname, strerror(-ret)); rados_shutdown(ceph_cluster); return ret; } ret = rados_connect(ceph_cluster); if (ret < 0) { fprintf(stderr, "%s: failed to connect to Ceph cluster %s as %s" " - (%s)\n", progname, ceph_cluster_name, ceph_auth_name, strerror(-ret)); rados_shutdown(ceph_cluster); return ret; } ret = rados_ioctx_create(ceph_cluster, pool_name, &ioctx); if (ret < 0) { fprintf(stderr, "%s: failed to create Ceph ioctx for pool %s" " - (%s)\n", progname, pool_name, strerror(-ret)); rados_shutdown(ceph_cluster); return ret; } *_ceph_cluster = ceph_cluster; *_ioctx = ioctx; return 0; }