/* * update_poolset_uuids -- (internal) update poolset uuid in recreated parts */ static int update_poolset_uuids(struct pool_set *set, unsigned repn, struct poolset_health_status *set_hs) { LOG(3, "set %p, repn %u, set_hs %p", set, repn, set_hs); struct pool_replica *rep = REP(set, repn); for (unsigned p = 0; p < rep->nparts; ++p) { struct pool_hdr *hdrp = HDR(rep, p); memcpy(hdrp->poolset_uuid, set->uuid, POOL_HDR_UUID_LEN); util_checksum(hdrp, sizeof(*hdrp), &hdrp->checksum, 1); /* store pool's header */ util_persist(PART(rep, p).is_dev_dax, hdrp, sizeof(*hdrp)); } return 0; }
/* * fill_struct_part_uuids -- (internal) set part uuids in pool_set structure */ static void fill_struct_part_uuids(struct pool_set *set, unsigned repn, struct poolset_health_status *set_hs) { LOG(3, "set %p, repn %u, set_hs %p", set, repn, set_hs); struct pool_replica *rep = REP(set, repn); struct pool_hdr *hdrp; for (unsigned p = 0; p < rep->nparts; ++p) { /* skip broken parts */ if (replica_is_part_broken(repn, p, set_hs)) continue; hdrp = HDR(rep, p); memcpy(rep->part[p].uuid, hdrp->uuid, POOL_HDR_UUID_LEN); } }
// return the edges of each bcc; vector<vector<pii>> solve() { vector<vector<pii>> res; for (int i=0; i<n; i++) { dfn[i] = low[i] = -1; } ap.clear(); for (int i=0; i<n; i++) { if (dfn[i] == -1) { top = 0; root = i; DFS(i,i); } } REP(i,nBcc) res.PB(bcc[i]); return res; }
value arc_mkregexp(arc *c, value s, unsigned int flags) { value regexp; struct regexp_t *rxdata; regexp = arc_mkobject(c, sizeof(struct regexp_t), T_REGEXP); rxdata = (struct regexp_t *)REP(regexp); rxdata->rxstr = s; rxdata->rp = regcomp(c, s); rxdata->flags = flags; if (rxdata->rp == NULL) { arc_err_cstrfmt(c, __arc_regex_error); return(CNIL); } return(regexp); }
pair<Weight, Edges> minimumSpanningForest(const Graph &g) { int n = g.size(); UnionFind uf(n); priority_queue<Edge> Q; REP(u, n) EACH(e, g[u]) if (u < e->dst) Q.push(*e); Weight total = 0; Edges F; while (F.size() < n-1 && !Q.empty()) { Edge e = Q.top(); Q.pop(); if (uf.unionSet(e.src, e.dst)) { F.push_back(e); total += e.weight; } } return pair<Weight, Edges>(total, F); }
/* * replica_remove_part -- unlink part from replica */ int replica_remove_part(struct pool_set *set, unsigned repn, unsigned partn) { struct pool_set_part *part = &PART(REP(set, repn), partn); if (part->fd != -1) close(part->fd); if (unlink(part->path)) { if (errno != ENOENT) { ERR("removing part %u from replica %u failed", partn, repn); return -1; } } LOG(1, "Removed part %s number %u from replica %u", part->path, partn, repn); return 0; }
int maxArea(vector<int>& height) { auto comp = [&height](int a, int b) -> bool {return height[a] < height[b]; }; priority_queue<int, vector<int>, decltype(comp)> xs(comp); REP(i, height.size()) xs.push(i); int minx = xs.top(); int maxx = xs.top(); int ret = 0; xs.pop(); while (!xs.empty()) { minx = min(minx, xs.top()); maxx = max(maxx, xs.top()); ret = max(ret, (maxx - minx)*height[xs.top()]); // cout << xs.top() << ' ' << ret << endl; xs.pop(); } return ret; }
int main() { while(1) { scanf("%d%d%d",&n,&k,&l); if(!n) break; REP(i,1,MAX) dp[i][0]=l+1; rep(i,n) { t=i%2; scanf("%d%d",&f,&d); rep(j,MAX) { dp[j][1-t]=l+1; if(dp[j][t]<=l) dp[j][1-t]=min(dp[j][1-t],max(0,dp[j][t]-k)); if(j>=f) dp[j][1-t]=min(dp[j][1-t],dp[j-f][t]+d); } }
int CBitmap::Save(LPCSTR pszFileName) { int width = m_image.width; int height = m_image.height; int bytesPerPixel = m_bmpInfoHeader.biBitCount / 8; int bytesPerLine = ( (width + (m_bmpInfoHeader.biBitCount % 32 != 0) ) * bytesPerPixel >> 2) << 2; int writeSize = bytesPerLine * height; BitmapFileHeader header = {}; header.bfType = 0x4D42; header.bfSize = sizeof(BitmapFileHeader) + m_bmpInfoHeader.biSize + writeSize; header.bfOffBits = sizeof(BitmapFileHeader) + m_bmpInfoHeader.biSize; //m_bmpInfoHeader.biBitCount = 24; m_bmpInfoHeader.biClrUsed = 0; m_bmpInfoHeader.biClrImportant = 0; m_bmpInfoHeader.biSizeImage = bytesPerLine*height; FILE *fp = fopen(pszFileName, "wb"); if(!fp) return -1; fwrite(&header, sizeof(header), 1, fp); fwrite(&m_bmpInfoHeader, m_bmpInfoHeader.biSize, 1, fp); u32 *pBuf = (u32 *)&m_image.buf[0]; std::vector<BYTE> imgData(writeSize + 4); printf("SaveSize:%d, %d\n", width, height); switch(m_bmpInfoHeader.biBitCount) { case 24: { if(m_bmpInfoHeader.biHeight < 0) // Top to bottom REP(y, height) REP(x, width) *(u32 *)&imgData[bytesPerLine*y + 3*x] = pBuf[width*y+x]; else // Bottom to top REV(y, height) REP(x, width) *(u32 *)&imgData[bytesPerLine*y + 3*x] = pBuf[width*y+x]; } break; case 32: { if(m_bmpInfoHeader.biHeight < 0) // Top to bottom REP(y, height) REP(x, width) *(u32 *)&imgData[(width*y+x)*4] = pBuf[y * width + x]; else // Bottom to top REV(y, height) REP(x, width) *(u32 *)&imgData[(width*y+x)*4] = pBuf[y * width + x]; } break; } fwrite(&imgData[0], writeSize, 1, fp); fclose(fp); printf("Saved!\n", width, height); return 0; }
vec4 paint(s_res res, vec4 lastcol) { s_liret light; s_texmod mod; light.cam.pos = (res.dst - 0.1) * res.cam.ray + res.cam.pos; mod = get_texture(res.mat, light.cam.pos, res.normal); light.diffuse = VEC4(0); light.specular = VEC4(0); res.mat.color = mod.color; res.normal = mod.normal; res.mat.smoothness = mod.smoothness; res.mat.metallic = mod.metallic; REP(LINUM, light, iter_light, lights, light, res); return (max(mix(light.diffuse * mod.color, lastcol * res.mat.metallic + light.specular, mix((1 - abs(dot(res.cam.ray, res.normal))) * res.mat.smoothness, 1, res.mat.metallic)), AMBIENT * res.mat.color)); }
/* * pool_set_type -- get pool type of a poolset */ enum pool_type pool_set_type(struct pool_set *set) { struct pool_hdr hdr; /* open the first part file to read the pool header values */ const struct pool_set_part *part = &PART(REP(set, 0), 0); if (util_file_pread(part->path, &hdr, sizeof(hdr), 0) != sizeof(hdr)) { ERR("cannot read pool header from poolset"); return POOL_TYPE_UNKNOWN; } util_convert2h_hdr_nocheck(&hdr); enum pool_type type = pool_hdr_get_type(&hdr); return type; }
/* * create_missing_headers -- (internal) create headers for all parts but the * first one */ static int create_missing_headers(struct pool_set *set, unsigned repn) { LOG(3, "set %p, repn %u", set, repn); struct pool_hdr *src_hdr = HDR(REP(set, repn), 0); for (unsigned p = 1; p < set->replica[repn]->nhdrs; ++p) { struct pool_attr attr; util_pool_hdr2attr(&attr, src_hdr); attr.incompat_features &= (uint32_t)(~POOL_FEAT_SINGLEHDR); if (util_header_create(set, repn, p, &attr, 1) != 0) { LOG(1, "part headers create failed for" " replica %u part %u", repn, p); errno = EINVAL; return -1; } } return 0; }
/* * replica_check_local_part_dir -- check if directory for the part file * exists */ int replica_check_local_part_dir(struct pool_set *set, unsigned repn, unsigned partn) { LOG(3, "set %p, repn %u, partn %u", set, repn, partn); char *path = Strdup(PART(REP(set, repn), partn).path); const char *dir = dirname(path); util_stat_t sb; if (util_stat(dir, &sb) != 0 || !(sb.st_mode & S_IFDIR)) { ERR("a directory %s for part %u in replica %u" " does not exist or is not accessible", path, partn, repn); Free(path); return -1; } Free(path); return 0; }
// StoerWagner (Verified: POJ2914) Weight global_minimum_cut(Matrix h) { int N = h.size(); vector<int> V(N); REP(u, N) V[u] = u; Weight cut = INF; for(int m = N; m > 1; m--) { vector<Weight> ws(m, 0); int u, v = -1; Weight w; REP(k, m) { u = v; v = max_element(ws.begin(), ws.end()) - ws.begin(); w = ws[v]; ws[v] = -1; REP(i, m) if (ws[i] >= 0) ws[i] += h[V[v]][V[i]]; } REP(i, m) { h[V[i]][V[u]] += h[V[i]][V[v]]; h[V[u]][V[i]] += h[V[v]][V[i]]; }
/* * delete_replicas -- (internal) delete replicas which do not have their * counterpart set in the helping status structure */ static int delete_replicas(struct pool_set *set, struct poolset_compare_status *set_s) { LOG(3, "set %p, set_s %p", set, set_s); for (unsigned r = 0; r < set->nreplicas; ++r) { struct pool_replica *rep = REP(set, r); if (replica_counterpart(r, set_s) == UNDEF_REPLICA) { if (!rep->remote) { if (util_replica_close_local(rep, r, DELETE_ALL_PARTS)) return -1; } else { if (util_replica_close_remote(rep, r, DELETE_ALL_PARTS)) return -1; } } } return 0; }
string run(int x, int y, vector<int> jumpLengths) { double dest = sqrt(x * x + y * y); int N = jumpLengths.size(); int maxR = 0; REP(i, N) maxR += jumpLengths[i]; // P(maxR); int minR = jumpLengths[0]; for(int i = 1; i < N; i++) { minR = abs(minR - jumpLengths[i]); } // destをsqrtせずに整数で扱うために、以下の判定が正しい // minR * minR <= D <= maxR * maxR if (minR <= dest && dest <= maxR) return "Able"; return "Not able"; }
/* * fill_struct_uuids -- (internal) fill fields in pool_set needed for further * altering of uuids */ static int fill_struct_uuids(struct pool_set *set, unsigned src_replica, struct poolset_health_status *set_hs, unsigned flags) { /* set poolset uuid */ struct pool_hdr *src_hdr0 = HDR(REP(set, src_replica), 0); memcpy(set->uuid, src_hdr0->poolset_uuid, POOL_HDR_UUID_LEN); /* set unbroken parts' uuids */ for (unsigned r = 0; r < set->nreplicas; ++r) { fill_struct_part_uuids(set, r, set_hs); } /* set broken parts' uuids */ for (unsigned r = 0; r < set->nreplicas; ++r) { if (fill_struct_broken_part_uuids(set, r, set_hs, flags)) return -1; } return 0; }
/* * update_parts_linkage -- (internal) set uuids linking recreated parts within * a replica */ static int update_parts_linkage(struct pool_set *set, unsigned repn, struct poolset_health_status *set_hs) { LOG(3, "set %p, repn %u, set_hs %p", set, repn, set_hs); struct pool_replica *rep = REP(set, repn); for (unsigned p = 0; p < rep->nhdrs; ++p) { struct pool_hdr *hdrp = HDR(rep, p); struct pool_hdr *prev_hdrp = HDRP(rep, p); struct pool_hdr *next_hdrp = HDRN(rep, p); /* set uuids in the current part */ memcpy(hdrp->prev_part_uuid, PARTP(rep, p).uuid, POOL_HDR_UUID_LEN); memcpy(hdrp->next_part_uuid, PARTN(rep, p).uuid, POOL_HDR_UUID_LEN); util_checksum(hdrp, sizeof(*hdrp), &hdrp->checksum, 1, POOL_HDR_CSUM_END_OFF); /* set uuids in the previous part */ memcpy(prev_hdrp->next_part_uuid, PART(rep, p).uuid, POOL_HDR_UUID_LEN); util_checksum(prev_hdrp, sizeof(*prev_hdrp), &prev_hdrp->checksum, 1, POOL_HDR_CSUM_END_OFF); /* set uuids in the next part */ memcpy(next_hdrp->prev_part_uuid, PART(rep, p).uuid, POOL_HDR_UUID_LEN); util_checksum(next_hdrp, sizeof(*next_hdrp), &next_hdrp->checksum, 1, POOL_HDR_CSUM_END_OFF); /* store pool's header */ util_persist(PART(rep, p).is_dev_dax, hdrp, sizeof(*hdrp)); util_persist(PARTP(rep, p).is_dev_dax, prev_hdrp, sizeof(*prev_hdrp)); util_persist(PARTN(rep, p).is_dev_dax, next_hdrp, sizeof(*next_hdrp)); } return 0; }
void recession(const Graph &g, vector<int> &res) { assert(g.size() == res.size()); int n = g.size(); vector<vector<int>> rg(n); for (int i = 0; i < n; ++i) for (auto e: g[i]) rg[e.dest].push_back(i); vector<int> cnt(n); REP(i,n) cnt[i] = g[i].size(); queue<int> que; REP(i,n) if (cnt[i] == 0) que.push(i); while (!que.empty()) { int v = que.front(); que.pop(); int c = update(g, res, v); for (int i: rg[v]) { if (res[i] != 0) continue; if (cnt[i] <= 0) continue; cnt[i] -= c; if (cnt[i] <= 0) que.push(i); } } }
I solve(I W, I* v) { printf("%d\n",W); I k; REP(k,n) printf("%d ", v[k]); NEWLINE; if(W<0) return 0; if(W==0) return 1; I i,j,m=0; REP(i,n) { if(!v[i]) { v[i]=1; m+=solve(W-w[i],v); v[i]=0; for(j=i+1; w[j]==w[i]; j++); j--; i=j; } } return (m>1?m:1); }
/* * check_poolset_uuids -- (internal) check if poolset_uuid fields are consistent * among all internally consistent replicas */ static int check_poolset_uuids(struct pool_set *set, struct poolset_health_status *set_hs) { unsigned r_h = replica_find_healthy_replica(set_hs); if (r_h == UNDEF_REPLICA) { ERR("no healthy replica. Cannot synchronize."); return -1; } uuid_t poolset_uuid; memcpy(poolset_uuid, HDR(REP(set, r_h), 0)->poolset_uuid, POOL_HDR_UUID_LEN); for (unsigned r = 0; r < set->nreplicas; ++r) { /* skip inconsistent replicas */ if (!replica_is_replica_consistent(r, set_hs) || r == r_h) continue; check_replica_poolset_uuids(set, r, poolset_uuid, set_hs); } return 0; }
/* * update_uuids -- (internal) update uuids in all headers in the replica */ static void update_uuids(struct pool_set *set, unsigned repn) { LOG(3, "set %p, repn %u", set, repn); struct pool_replica *rep = REP(set, repn); struct pool_hdr *hdr0 = HDR(rep, 0); for (unsigned p = 0; p < rep->nhdrs; ++p) { struct pool_hdr *hdrp = HDR(rep, p); memcpy(hdrp->next_part_uuid, PARTN(rep, p)->uuid, POOL_HDR_UUID_LEN); memcpy(hdrp->prev_part_uuid, PARTP(rep, p)->uuid, POOL_HDR_UUID_LEN); memcpy(hdrp->next_repl_uuid, hdr0->next_repl_uuid, POOL_HDR_UUID_LEN); memcpy(hdrp->prev_repl_uuid, hdr0->prev_repl_uuid, POOL_HDR_UUID_LEN); memcpy(hdrp->poolset_uuid, hdr0->poolset_uuid, POOL_HDR_UUID_LEN); util_checksum(hdrp, sizeof(*hdrp), &hdrp->checksum, 1, POOL_HDR_CSUM_END_OFF); util_persist(PART(rep, p)->is_dev_dax, hdrp, sizeof(*hdrp)); } }
/* * update_parts_linkage -- (internal) set uuids linking recreated parts within * a replica */ static int update_parts_linkage(struct pool_set *set, unsigned repn, struct poolset_health_status *set_hs) { struct pool_replica *rep = REP(set, repn); for (unsigned p = 0; p < rep->nparts; ++p) { struct pool_hdr *hdrp = HDR(rep, p); struct pool_hdr *prev_hdrp = HDR(rep, p - 1); struct pool_hdr *next_hdrp = HDR(rep, p + 1); /* set uuids in the current part */ memcpy(hdrp->prev_part_uuid, PART(rep, p - 1).uuid, POOL_HDR_UUID_LEN); memcpy(hdrp->next_part_uuid, PART(rep, p + 1).uuid, POOL_HDR_UUID_LEN); util_checksum(hdrp, sizeof(*hdrp), &hdrp->checksum, 1); /* set uuids in the previous part */ memcpy(prev_hdrp->next_part_uuid, PART(rep, p).uuid, POOL_HDR_UUID_LEN); util_checksum(prev_hdrp, sizeof(*prev_hdrp), &prev_hdrp->checksum, 1); /* set uuids in the next part */ memcpy(next_hdrp->prev_part_uuid, PART(rep, p).uuid, POOL_HDR_UUID_LEN); util_checksum(next_hdrp, sizeof(*next_hdrp), &next_hdrp->checksum, 1); /* store pool's header */ pmem_msync(hdrp, sizeof(*hdrp)); pmem_msync(prev_hdrp, sizeof(*prev_hdrp)); pmem_msync(next_hdrp, sizeof(*next_hdrp)); } return 0; }
// @param th > 0 u levenshteinDistance(const char *a, const char *b, int th) { static int dp[2][N]; int m = (int)strlen(a), n = (int)strlen(b); //while (m > 0 && n > 0 && a[0] == b[0]) //a++, b++, m--, n--; //while (m > 0 && n > 0 && a[m-1] == b[n-1]) //m--, n--; if (m < n) swap(a, b), swap(m, n); if (m-n > th) return th; if (n <= 64) return levenshtein_bit_vector<uint64_t>(a, m, b, n); if (n <= 128) return levenshtein_bit_vector<unsigned __int128>(a, m, b, n); #if 0 REP(j, n+1) dp[0][j] = j; REP1(i, m) { dp[i&1][0] = i; REP1(j, n) dp[i&1][j] = a[i-1] == b[j-1] ? dp[i-1&1][j-1] : min(min(dp[i-1&1][j], dp[i&1][j-1]), dp[i-1&1][j-1]) + 1; }
// n! の計算はすぐにオーバーフローするので注意 double run(string word){ WORD = word; N = word.size(); int sum2 = N; set<char> s; REP(i, N) s.insert(word[i]); // N!の計算 vector<double> PN(50, 1); for(int i = 2; i < PN.size(); i++){ PN[i] = i * PN[i - 1]; } set<char>::iterator it; int n_odd = 0; int sum1 = 0; double ret = 1; for (it = s.begin(); it != s.end(); it++){ char c = *it; int n = count(word.begin(), word.end(), c); if (n % 2 != 0){ n_odd++; if (n_odd >= 2) return 0; sum1++; } else { ret *= PN[n]; ret /= PN[n/2]; sum1 += n/2; } } return ret = ret * PN[sum1] / PN[sum2]; // 最後にこれを評価することで、nが正しい場合意外は排除できる // (odd > 1) || (odd != n % 2) }
// returns the N-th term of Fibonacci sequence int fib(int N) { // create vector F1 vector<ll> F1(K); F1[0] = 1; F1[1] = 1; // create matrix T matrix T(K, vector<ll>(K)); T[0][0] = 0, T[0][1] = 1; T[1][0] = 1, T[1][1] = 1; // raise T to the (N-1)th power if (N == 1) return F1[0]; T = pow(T, N-1); // the answer is the first row of T . F1 ll res = 0; REP(i, K) res = (res + T[0][i] * F1[i]) % MOD; if(res < 0) res += MOD; return res; }
int main() { //筛法求素数 CLR(prime, 1); prime[0] = prime[1] = false; for ( int i = 2; i < MAX; ++i ) if ( prime[i] ) for ( int j = 2 * i; j < MAX; j += i ) prime[j] = false; //求欧拉函数 rep(i, MAX) E[i] = i; for ( int i = 2; i < MAX; ++i ) if ( prime[i] ) { for ( int j = 2 * i; j < MAX; j += i ) E[j] = E[j] / i * ( i - 1 ); E[i] = i - 1; } int a, b; while ( scanf("%d %d", &a, &b) != EOF ) { LL sum = 0; REP(i, a, b + 1) sum += E[i]; cout << sum << endl; } }
/* * replica_remove_part -- unlink part from replica */ int replica_remove_part(struct pool_set *set, unsigned repn, unsigned partn) { LOG(3, "set %p, repn %u, partn %u", set, repn, partn); struct pool_set_part *part = &PART(REP(set, repn), partn); if (part->fd != -1) { close(part->fd); part->fd = -1; } int olderrno = errno; if (util_unlink(part->path)) { if (errno != ENOENT) { ERR("removing part %u from replica %u failed", partn, repn); return -1; } } errno = olderrno; LOG(1, "Removed part %s number %u from replica %u", part->path, partn, repn); return 0; }
int CBitmap::SetClipboard() { HANDLE hGMem = GlobalAlloc(GHND, m_bmpInfoHeader.biSize + m_image.buf.size()); BITMAPINFOHEADER *pBih = (BITMAPINFOHEADER *)GlobalLock(hGMem); *pBih = *(BITMAPINFOHEADER *)&m_bmpInfoHeader; //pBih->biBitCount = 32; //pBih->biCompression = BI_RGB; int width = m_image.width; int height = m_image.height; int bytesPerPixel = m_bmpInfoHeader.biBitCount / 8; int bytesPerLine = ( (width + (m_bmpInfoHeader.biBitCount % 32 != 0) ) * bytesPerPixel >> 2) << 2; // int writeSize = bytesPerLine * height; printf("Setting... w=%d, h=%d", width, height); int offset = pBih->biSize + pBih->biClrUsed * (pBih->biBitCount > 24 ? sizeof(RGBQuad) : sizeof(RGBTriple)); u8 *imgData = (u8 *)pBih + offset; u32 *pBuf = (u32 *)&m_image.buf[0]; switch(m_bmpInfoHeader.biBitCount) { case 24: { if(m_bmpInfoHeader.biHeight < 0) // Top to bottom REP(y, height) REP(x, width) *(RGBTriple *)&imgData[bytesPerLine*y + 3*x] = *(RGBTriple *)&pBuf[width*y+x]; else // Bottom to top REV(y, height) REP(x, width) *(RGBTriple *)&imgData[bytesPerLine*y + 3*x] = *(RGBTriple *)&pBuf[width*y+x]; } break; case 32: { if(m_bmpInfoHeader.biHeight < 0) // Top to bottom REP(y, height) REP(x, width) *(u32 *)&imgData[(width*y+x)*4] = pBuf[width*y+x]; else // Bottom to top REV(y, height) REP(x, width) *(u32 *)&imgData[(width*y+x)*4] = pBuf[width*y+x]; } break; } GlobalUnlock(hGMem); if( !OpenClipboard(NULL) ) return -1; EmptyClipboard(); SetClipboardData(CF_DIB, hGMem); CloseClipboard(); puts("OK"); return 0; }
/* * copy_data_to_broken_parts -- (internal) copy data to all parts created * in place of the broken ones */ static int copy_data_to_broken_parts(struct pool_set *set, unsigned healthy_replica, unsigned flags, struct poolset_health_status *set_hs) { /* get pool size from healthy replica */ size_t poolsize = set->poolsize; for (unsigned r = 0; r < set_hs->nreplicas; ++r) { /* skip unbroken and consistent replicas */ if (replica_is_replica_healthy(r, set_hs)) continue; struct pool_replica *rep = REP(set, r); struct pool_replica *rep_h = REP(set, healthy_replica); for (unsigned p = 0; p < rep->nparts; ++p) { /* skip unbroken parts from consistent replicas */ if (!replica_is_part_broken(r, p, set_hs) && replica_is_replica_consistent(r, set_hs)) continue; const struct pool_set_part *part = &rep->part[p]; size_t off = replica_get_part_data_offset(set, r, p); size_t len = replica_get_part_data_len(set, r, p); if (rep->remote) len = poolsize - off; /* do not allow copying too much data */ if (off >= poolsize) continue; /* * First part of replica is mapped * with header */ size_t fpoff = (p == 0) ? POOL_HDR_SIZE : 0; void *dst_addr = ADDR_SUM(part->addr, fpoff); if (rep->remote) { int ret = Rpmem_persist(rep->remote->rpp, off - POOL_HDR_SIZE, len, 0); if (ret) { LOG(1, "Copying data to remote node " "failed -- '%s' on '%s'", rep->remote->pool_desc, rep->remote->node_addr); return -1; } } else if (rep_h->remote) { int ret = Rpmem_read(rep_h->remote->rpp, dst_addr, off - POOL_HDR_SIZE, len); if (ret) { LOG(1, "Reading data from remote node " "failed -- '%s' on '%s'", rep_h->remote->pool_desc, rep_h->remote->node_addr); return -1; } } else { if (off + len > poolsize) len = poolsize - off; void *src_addr = ADDR_SUM(rep_h->part[0].addr, off); /* copy all data */ memcpy(dst_addr, src_addr, len); pmem_msync(dst_addr, len); } } } return 0; }