struct containerMeta* retrieve_container_meta_by_id(containerid id) { struct containerMeta* cm = NULL; /* First, we find it in the buffer */ cm = sync_queue_find(container_buffer, container_check_id, &id, container_meta_duplicate); if (cm) return cm; cm = (struct containerMeta*) malloc(sizeof(struct containerMeta)); init_container_meta(cm); unsigned char buf[CONTAINER_META_SIZE]; pthread_mutex_lock(&mutex); if (destor.simulation_level >= SIMULATION_APPEND) fseek(fp, id * CONTAINER_META_SIZE + 8, SEEK_SET); else fseek(fp, (id + 1) * CONTAINER_SIZE - CONTAINER_META_SIZE + 8, SEEK_SET); fread(buf, CONTAINER_META_SIZE, 1, fp); pthread_mutex_unlock(&mutex); unser_declare; unser_begin(buf, CONTAINER_META_SIZE); unser_int64(cm->id); unser_int32(cm->chunk_num); unser_int32(cm->data_size); if(cm->id != id){ WARNING("expect %lld, but read %lld", id, cm->id); assert(cm->id == id); } int i; for (i = 0; i < cm->chunk_num; i++) { struct metaEntry* me = (struct metaEntry*) malloc( sizeof(struct metaEntry)); unser_bytes(&me->fp, sizeof(fingerprint)); unser_bytes(&me->len, sizeof(int32_t)); unser_bytes(&me->off, sizeof(int32_t)); g_hash_table_insert(cm->map, &me->fp, me); } return cm; }
static bRC setAcl(bpContext *ctx, acl_pkt *ap) { int status; unser_declare; uint32_t acl_name_length; uint32_t xattr_value_length; POOL_MEM xattr_value(PM_MESSAGE), acl_name(PM_MESSAGE); plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext; if (!p_ctx) { return bRC_Error; } unser_begin(ap->content, ap->content_length); while (unser_length(ap->content) < ap->content_length) { unser_uint32(acl_name_length); /* * Decode the ACL name including the \0 */ acl_name.check_size(acl_name_length); unser_bytes(acl_name.c_str(), acl_name_length); unser_uint32(xattr_value_length); /* * Decode the actual ACL data as stored as XATTR. */ xattr_value.check_size(xattr_value_length); unser_bytes(xattr_value.c_str(), xattr_value_length); status = ceph_lsetxattr(p_ctx->cmount, ap->fname, acl_name.c_str(), xattr_value.c_str(), xattr_value_length, 0); if (status < 0) { berrno be; Jmsg(ctx, M_ERROR, "ceph_lsetxattr(%s) failed: %s\n", ap->fname, be.bstrerror(-status)); return bRC_Error; } } unser_end(ap->content, ap->content_length); return bRC_OK; }
struct container* retrieve_container_by_id(containerid id) { struct container *c = (struct container*) malloc(sizeof(struct container)); init_container_meta(&c->meta); unsigned char *cur = 0; if (destor.simulation_level >= SIMULATION_RESTORE) { c->data = malloc(CONTAINER_META_SIZE); pthread_mutex_lock(&mutex); if (destor.simulation_level >= SIMULATION_APPEND) fseek(fp, id * CONTAINER_META_SIZE + 8, SEEK_SET); else fseek(fp, (id + 1) * CONTAINER_SIZE - CONTAINER_META_SIZE + 8, SEEK_SET); fread(c->data, CONTAINER_META_SIZE, 1, fp); pthread_mutex_unlock(&mutex); cur = c->data; } else { c->data = malloc(CONTAINER_SIZE); pthread_mutex_lock(&mutex); fseek(fp, id * CONTAINER_SIZE + 8, SEEK_SET); fread(c->data, CONTAINER_SIZE, 1, fp); pthread_mutex_unlock(&mutex); cur = &c->data[CONTAINER_SIZE - CONTAINER_META_SIZE]; } unser_declare; unser_begin(cur, CONTAINER_META_SIZE); unser_int64(c->meta.id); unser_int32(c->meta.chunk_num); unser_int32(c->meta.data_size); if(c->meta.id != id){ WARNING("expect %lld, but read %lld", id, c->meta.id); assert(c->meta.id == id); } int i; for (i = 0; i < c->meta.chunk_num; i++) { struct metaEntry* me = (struct metaEntry*) malloc( sizeof(struct metaEntry)); unser_bytes(&me->fp, sizeof(fingerprint)); unser_bytes(&me->len, sizeof(int32_t)); unser_bytes(&me->off, sizeof(int32_t)); g_hash_table_insert(c->meta.map, &me->fp, me); } unser_end(cur, CONTAINER_META_SIZE); if (destor.simulation_level >= SIMULATION_RESTORE) { free(c->data); c->data = 0; } return c; }