static int rados_metatile_expire(struct storage_backend * store, const char *xmlconfig, int x, int y, int z) { struct stat_info tile_stat; struct rados_ctx * ctx = (struct rados_ctx *)store->storage_ctx; char meta_path[PATH_MAX]; char tmp[PATH_MAX]; int err; //TODO: deal with options const char *options = ""; rados_xyzo_to_storagekey(xmlconfig, options, x, y, z, meta_path); err = rados_read(ctx->io, meta_path, (char *)&tile_stat, sizeof(struct stat_info), 0); if (err < 0) { if (-err == ENOENT) { log_message(STORE_LOGLVL_DEBUG, "Tile %s does not exist, can't expire", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp)); return -1; } else { log_message(STORE_LOGLVL_ERR, "Failed to read tile metadata for %s: %s", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp), strerror(-err)); } return -2; } tile_stat.expired = 1; err = rados_write(ctx->io, meta_path, (char *)&tile_stat, sizeof(struct stat_info), 0); if (err < 0) { log_message(STORE_LOGLVL_ERR, "failed to write expiry data for %s: %s", rados_tile_storage_id(store, xmlconfig, options, x, y, z, tmp), strerror(-err)); return -3; } return 0; }
static VALUE nogvl_ioctx_write(void *ptr) { struct nogvl_iop_args *args = ptr; return (VALUE)rados_write(*args->ioctx, args->oid, args->buf, args->len, args->offset); }
static int testrados(void) { char tmp[32]; int i, r; rados_t cl; if (rados_create(&cl, NULL) < 0) { printf("error initializing\n"); return 1; } if (rados_conf_read_file(cl, NULL)) { printf("error reading configuration file\n"); return 1; } // Try to set a configuration option that doesn't exist. // This should fail. if (!rados_conf_set(cl, "config option that doesn't exist", "some random value")) { printf("error: succeeded in setting nonexistent config option\n"); return 1; } if (rados_conf_get(cl, "log to stderr", tmp, sizeof(tmp))) { printf("error: failed to read log_to_stderr from config\n"); return 1; } // Can we change it? if (rados_conf_set(cl, "log to stderr", "2")) { printf("error: error setting log_to_stderr\n"); return 1; } if (rados_conf_get(cl, "log to stderr", tmp, sizeof(tmp))) { printf("error: failed to read log_to_stderr from config\n"); return 1; } if (tmp[0] != '2') { printf("error: new setting for log_to_stderr failed to take effect.\n"); return 1; } if (rados_connect(cl)) { printf("error connecting\n"); return 1; } if (rados_connect(cl) == 0) { printf("second connect attempt didn't return an error\n"); return 1; } /* create an io_ctx */ r = rados_pool_create(cl, "foo"); printf("rados_pool_create = %d\n", r); rados_ioctx_t io_ctx; r = rados_ioctx_create(cl, "foo", &io_ctx); printf("rados_ioctx_create = %d, io_ctx = %p\n", r, io_ctx); /* list all pools */ { int buf_sz = rados_pool_list(cl, NULL, 0); printf("need buffer size of %d\n", buf_sz); char buf[buf_sz]; int r = rados_pool_list(cl, buf, buf_sz); if (r != buf_sz) { printf("buffer size mismatch: got %d the first time, but %d " "the second.\n", buf_sz, r); return 1; } const char *b = buf; printf("begin pools.\n"); while (1) { if (b[0] == '\0') break; printf(" pool: '%s'\n", b); b += strlen(b) + 1; }; printf("end pools.\n"); } /* stat */ struct rados_pool_stat_t st; r = rados_ioctx_pool_stat(io_ctx, &st); printf("rados_ioctx_pool_stat = %d, %lld KB, %lld objects\n", r, (long long)st.num_kb, (long long)st.num_objects); /* snapshots */ r = rados_ioctx_snap_create(io_ctx, "snap1"); printf("rados_ioctx_snap_create snap1 = %d\n", r); rados_snap_t snaps[10]; r = rados_ioctx_snap_list(io_ctx, snaps, 10); for (i=0; i<r; i++) { char name[100]; rados_ioctx_snap_get_name(io_ctx, snaps[i], name, sizeof(name)); printf("rados_ioctx_snap_list got snap %lld %s\n", (long long)snaps[i], name); } rados_snap_t snapid; r = rados_ioctx_snap_lookup(io_ctx, "snap1", &snapid); printf("rados_ioctx_snap_lookup snap1 got %lld, result %d\n", (long long)snapid, r); r = rados_ioctx_snap_remove(io_ctx, "snap1"); printf("rados_ioctx_snap_remove snap1 = %d\n", r); /* sync io */ time_t tm; char buf[128], buf2[128]; time(&tm); snprintf(buf, 128, "%s", ctime(&tm)); const char *oid = "foo_object"; r = rados_write(io_ctx, oid, buf, strlen(buf) + 1, 0); printf("rados_write = %d\n", r); r = rados_read(io_ctx, oid, buf2, sizeof(buf2), 0); printf("rados_read = %d\n", r); if (memcmp(buf, buf2, r)) printf("*** content mismatch ***\n"); /* attrs */ if (do_rados_setxattr(io_ctx, oid, "b", "2")) return 1; if (do_rados_setxattr(io_ctx, oid, "a", "1")) return 1; if (do_rados_setxattr(io_ctx, oid, "c", "3")) return 1; if (do_rados_getxattr(io_ctx, oid, "a", "1")) return 1; if (do_rados_getxattr(io_ctx, oid, "b", "2")) return 1; if (do_rados_getxattr(io_ctx, oid, "c", "3")) return 1; const char *exkeys[] = { "a", "b", "c", NULL }; const char *exvals[] = { "1", "2", "3", NULL }; if (do_rados_getxattrs(io_ctx, oid, exkeys, exvals)) return 1; uint64_t size; time_t mtime; r = rados_stat(io_ctx, oid, &size, &mtime); printf("rados_stat size = %lld mtime = %d = %d\n", (long long)size, (int)mtime, r); r = rados_stat(io_ctx, "does_not_exist", NULL, NULL); printf("rados_stat(does_not_exist) = %d\n", r); /* exec */ rados_exec(io_ctx, oid, "crypto", "md5", buf, strlen(buf) + 1, buf, 128); printf("exec result=%s\n", buf); r = rados_read(io_ctx, oid, buf2, 128, 0); printf("read result=%s\n", buf2); printf("size=%d\n", r); /* aio */ rados_completion_t a, b; rados_aio_create_completion(0, 0, 0, &a); rados_aio_create_completion(0, 0, 0, &b); rados_aio_write(io_ctx, "a", a, buf, 100, 0); rados_aio_write(io_ctx, "../b/bb_bb_bb\\foo\\bar", b, buf, 100, 0); rados_aio_wait_for_safe(a); printf("a safe\n"); rados_aio_wait_for_safe(b); printf("b safe\n"); rados_aio_release(a); rados_aio_release(b); /* test flush */ printf("testing aio flush\n"); rados_completion_t c; rados_aio_create_completion(0, 0, 0, &c); rados_aio_write(io_ctx, "c", c, buf, 100, 0); int safe = rados_aio_is_safe(c); printf("a should not yet be safe and ... %s\n", safe ? "is":"is not"); assert(!safe); rados_aio_flush(io_ctx); safe = rados_aio_is_safe(c); printf("a should be safe and ... %s\n", safe ? "is":"is not"); assert(safe); rados_aio_release(c); rados_read(io_ctx, "../b/bb_bb_bb\\foo\\bar", buf2, 128, 0); /* list objects */ rados_list_ctx_t h; r = rados_objects_list_open(io_ctx, &h); printf("rados_list_objects_open = %d, h = %p\n", r, h); const char *poolname; while (rados_objects_list_next(h, &poolname) == 0) printf("rados_list_objects_next got object '%s'\n", poolname); rados_objects_list_close(h); /* stat */ r = rados_ioctx_pool_stat(io_ctx, &st); printf("rados_stat_pool = %d, %lld KB, %lld objects\n", r, (long long)st.num_kb, (long long)st.num_objects); /* delete a pool */ printf("rados_delete_pool = %d\n", r); rados_ioctx_destroy(io_ctx); r = rados_pool_delete(cl, "foo"); printf("rados_ioctx_pool_delete = %d\n", r); rados_shutdown(cl); return 0; }
/* * Bareos is calling us to do the actual I/O */ static bRC pluginIO(bpContext *ctx, struct io_pkt *io) { int io_count; plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext; if (!p_ctx) { return bRC_Error; } switch(io->func) { case IO_OPEN: p_ctx->offset = 0; io->status = 0; io->io_errno = 0; break; case IO_READ: io_count = rados_read(p_ctx->ioctx, p_ctx->object_name, io->buf, io->count, p_ctx->offset); if (io_count >= 0) { p_ctx->offset += io_count; io->status = io_count; io->io_errno = 0; } else { io->io_errno = -io_count; goto bail_out; } break; case IO_WRITE: io_count = rados_write(p_ctx->ioctx, p_ctx->object_name, io->buf, io->count, p_ctx->offset); #if LIBRADOS_VERSION_CODE <= 17408 if (io_count >= 0) { p_ctx->offset += io_count; io->status = io_count; #else if (io_count == 0) { p_ctx->offset += io->count; io->status = io->count; #endif io->io_errno = 0; } else { io->io_errno = -io_count; goto bail_out; } break; case IO_CLOSE: p_ctx->offset = 0; io->status = 0; io->io_errno = 0; break; case IO_SEEK: Jmsg(ctx, M_ERROR, "Illegal Seek request on rados device."); Dmsg(ctx, dbglvl, "Illegal Seek request on rados device."); io->io_errno = EINVAL; goto bail_out; } return bRC_OK; bail_out: io->lerror = 0; io->win32 = false; io->status = -1; return bRC_Error; } /* * See if we need to do any postprocessing after the restore. */ static bRC end_restore_job(bpContext *ctx, void *value) { bRC retval = bRC_OK; plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext; if (!p_ctx) { return bRC_Error; } Dmsg(ctx, dbglvl, "rados-fd: entering end_restore_job\n"); Dmsg(ctx, dbglvl, "rados-fd: leaving end_restore_job\n"); return retval; }
static int uwsgi_rados_put(struct wsgi_request *wsgi_req, rados_ioctx_t ctx, char *key, size_t buffer_size, int timeout) { struct uwsgi_rados_io *urio = &urados.urio[wsgi_req->async_id]; size_t remains = wsgi_req->post_cl; uint64_t off = 0; int ret; const char* method; int truncate = remains == 0; #ifdef HAS_RADOS_POOL_REQUIRES_ALIGNMENT2 if (!truncate && !rados_ioctx_pool_requires_alignment2(ctx, &ret) && ret) { uint64_t alignment; if (rados_ioctx_pool_required_alignment2(ctx, &alignment)) { /* ignore error here */ } else #else if (!truncate && rados_ioctx_pool_requires_alignment(ctx)) { uint64_t alignment = rados_ioctx_pool_required_alignment(ctx); #endif if (buffer_size <= alignment) { buffer_size = alignment; } else if (buffer_size <= alignment * 2) { buffer_size = alignment * 2; } else if (alignment) { buffer_size -= buffer_size % alignment; } } while(truncate || remains > 0) { ssize_t body_len = 0; char *body = "\x00"; if (!truncate) { body = uwsgi_request_body_read(wsgi_req, UMIN(remains, buffer_size) , &body_len); if (!body || body == uwsgi.empty) goto error; } else { truncate = 0; } if (uwsgi.async < 1) { if (off == 0) { ret = rados_write_full(ctx, key, body, body_len); method = "rados_write_full()"; } else { ret = rados_write(ctx, key, body, body_len, off); method = "rados_write()"; } if (ret < 0) { uwsgi_log("uwsgi_rados_put():%s() %s\n", method, strerror(-ret)); return -1; } } else { // increase request counter pthread_mutex_lock(&urio->mutex); urio->rid++; pthread_mutex_unlock(&urio->mutex); struct uwsgi_rados_cb *urcb = uwsgi_malloc(sizeof(struct uwsgi_rados_cb)); // map the current request id to the callback urcb->rid = urio->rid; // map urio to the callback urcb->urio = urio; rados_completion_t comp; // use safe for write if (rados_aio_create_completion(urcb, NULL, uwsgi_rados_read_async_cb, &comp) < 0) { free(urcb); goto error; } if (off == 0) { ret = rados_aio_write_full(ctx, key, comp, body, body_len); method = "rados_aio_write_full"; } else { ret = rados_aio_write(ctx, key, comp, body, body_len, off); method = "rados_aio_write"; } if (ret < 0) { uwsgi_log("uwsgi_rados_put():%s() %s\n", method, strerror(-ret)); free(urcb); rados_aio_release(comp); goto error; } // wait for the callback to be executed if (uwsgi.wait_read_hook(urio->fds[0], timeout) <= 0) { rados_aio_release(comp); goto error; } char ack = 1; if (read(urio->fds[0], &ack, 1) != 1) { rados_aio_release(comp); uwsgi_error("uwsgi_rados_read_async()/read()"); goto error; } if (rados_aio_is_safe_and_cb(comp)) { ret = rados_aio_get_return_value(comp); if (ret < 0) { uwsgi_log("uwsgi_rados_put():%s() %s\n", method, strerror(-ret)); rados_aio_release(comp); goto error; } } rados_aio_release(comp); } remains -= body_len; off += body_len; } return 0; error: return -1; } // async stat static int uwsgi_rados_async_stat(struct uwsgi_rados_io *urio, rados_ioctx_t ctx, const char *key, uint64_t *stat_size, time_t *stat_mtime, int timeout) { int ret = -1; // increase request counter pthread_mutex_lock(&urio->mutex); urio->rid++; pthread_mutex_unlock(&urio->mutex); struct uwsgi_rados_cb *urcb = uwsgi_malloc(sizeof(struct uwsgi_rados_cb)); // map the current request id to the callback urcb->rid = urio->rid; // map urio to the callback urcb->urio = urio; rados_completion_t comp; if (rados_aio_create_completion(urcb, uwsgi_rados_read_async_cb, NULL, &comp) < 0) { free(urcb); goto end; } if (rados_aio_stat(ctx, key, comp, stat_size, stat_mtime) < 0) { free(urcb); rados_aio_release(comp); goto end; } // wait for the callback to be executed if (uwsgi.wait_read_hook(urio->fds[0], timeout) <= 0) { rados_aio_release(comp); goto end; } char ack = 1; if (read(urio->fds[0], &ack, 1) != 1) { rados_aio_release(comp); uwsgi_error("uwsgi_rados_read_async()/read()"); goto end; } if (rados_aio_is_complete_and_cb(comp)) { ret = rados_aio_get_return_value(comp); } rados_aio_release(comp); end: return ret; }