6 Star 0 Fork 6

src-openEuler/drbd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
drbd-fix-initialization-of-bitmap-area-for-external-meta-data.patch 5.16 KB
一键复制 编辑 原始数据 按行查看 历史
From e9b58afd7ee90124697fe501bee5ced1fc685f70 Mon Sep 17 00:00:00 2001
From: Lars Ellenberg <lars.ellenberg@linbit.com>
Date: Fri, 10 May 2024 13:40:39 +0200
Subject: [PATCH 041/100] drbd: fix initialization of "bitmap area" for
external meta data
Before, the zeroout bitmap paths would always use bm_bytes(), even for
"flexible external meta data", though in that case with the size of the
external meta data device instead of the backing device, which is not known at
this point.
We should instead initialize the "potential" bitmap area, which for
flexible external meta data is just "the rest of the device".
We have the cfg->bm_bytes member, use it!
cfg->bm_bytes should hold the on disk bitmap area size in bytes, rounded up to 4k.
That is the backing device size dependent bm_bytes() for "flexible internal",
the fixed size for (old and irrelevant now) fixed size internal
and "indexed" external, and just "the rest of the device" for "flexible external".
---
user/shared/drbdmeta.c | 13 ++++++++-----
user/shared/drbdmeta_linux.c | 12 ++++++++++--
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/user/shared/drbdmeta.c b/user/shared/drbdmeta.c
index a896e0d9..917ee5f3 100644
--- a/user/shared/drbdmeta.c
+++ b/user/shared/drbdmeta.c
@@ -1348,24 +1348,28 @@ void re_initialize_md_offsets(struct format *cfg)
cfg->md.md_size_sect = MD_RESERVED_SECT_07;
cfg->md.al_offset = MD_AL_OFFSET_07;
cfg->md.bm_offset = cfg->md.al_offset + al_size_sect;
+ cfg->bm_bytes = 512ULL * (cfg->md.md_size_sect - cfg->md.bm_offset);
break;
case DRBD_MD_INDEX_FLEX_EXT:
/* just occupy the full device; unit: sectors */
cfg->md.md_size_sect = cfg->bd_size >> 9;
cfg->md.al_offset = MD_AL_OFFSET_07;
cfg->md.bm_offset = cfg->md.al_offset + al_size_sect;
+ cfg->bm_bytes = 512ULL * (cfg->md.md_size_sect - cfg->md.bm_offset);
break;
case DRBD_MD_INDEX_INTERNAL: /* only v07 */
cfg->md.md_size_sect = MD_RESERVED_SECT_07;
cfg->md.al_offset = MD_AL_OFFSET_07;
cfg->md.bm_offset = MD_BM_OFFSET_07;
+ cfg->bm_bytes = 512ULL * (cfg->md.md_size_sect - cfg->md.bm_offset);
break;
case DRBD_MD_INDEX_FLEX_INT:
/* al size is still fixed */
cfg->md.al_offset = -al_size_sect;
/* we need (slightly less than) ~ this much bitmap sectors: */
- md_size_sect = bm_bytes(&cfg->md, cfg->bd_size >> 9) >> 9;
+ cfg->bm_bytes = bm_bytes(&cfg->md, cfg->bd_size >> 9);
+ md_size_sect = cfg->bm_bytes >> 9;
md_size_sect = ALIGN(md_size_sect, 8); /* align on 4K blocks */
if (md_size_sect > (MD_BM_MAX_BYTE_FLEX>>9)*cfg->md.max_peers) {
fprintf(stderr, "Bitmap for that device got too large.\n");
@@ -1390,6 +1394,7 @@ void re_initialize_md_offsets(struct format *cfg)
fprintf(stderr,"bm_offset: "U64" (%d)\n", cfg->bm_offset, cfg->md.bm_offset);
fprintf(stderr,"md_size_sect: "U32"\n", cfg->md.md_size_sect);
fprintf(stderr,"max_usable_sect: "U64"\n", cfg->max_usable_sect);
+ fprintf(stderr,"bm_bytes: "U64"\n", cfg->bm_bytes);
}
}
@@ -1430,8 +1435,7 @@ void check_for_existing_data(struct format *cfg);
static void zeroout_bitmap_pwrite(struct format *cfg)
{
- const size_t bitmap_bytes =
- ALIGN(bm_bytes(&cfg->md, cfg->bd_size >> 9), cfg->md_hard_sect_size);
+ const size_t bitmap_bytes = ALIGN(cfg->bm_bytes, cfg->md_hard_sect_size);
/* need to sector-align this for O_DIRECT.
* "sector" here means hard-sect size, which may be != 512.
@@ -1467,8 +1471,7 @@ static void zeroout_bitmap_pwrite(struct format *cfg)
static void initialize_bitmap(struct format *cfg)
{
- const size_t bitmap_kbytes =
- ALIGN(bm_bytes(&cfg->md, cfg->bd_size >> 9), cfg->md_hard_sect_size) >> 10;
+ const size_t bitmap_kbytes = ALIGN(cfg->bm_bytes, cfg->md_hard_sect_size) >> 10;
char ppb[10];
ppsize(ppb, bitmap_kbytes);
diff --git a/user/shared/drbdmeta_linux.c b/user/shared/drbdmeta_linux.c
index 2c9506a4..e0e75ea0 100644
--- a/user/shared/drbdmeta_linux.c
+++ b/user/shared/drbdmeta_linux.c
@@ -186,8 +186,7 @@ int generic_md_close(struct format *cfg)
int zeroout_bitmap_fast(struct format *cfg)
{
- const size_t bitmap_bytes =
- ALIGN(bm_bytes(&cfg->md, cfg->bd_size >> 9), cfg->md_hard_sect_size);
+ const size_t bitmap_bytes = ALIGN(cfg->bm_bytes, cfg->md_hard_sect_size);
off_t bm_on_disk_off = cfg->bm_offset;
unsigned int percent_done = 0;
@@ -204,17 +203,26 @@ int zeroout_bitmap_fast(struct format *cfg)
* Do it in "chunks" per call so this can show progress
* and can be interrupted, if necessary. */
const size_t bytes_per_iteration = 1024*1024*1024;
+
+ if (verbose >= 2)
+ fflush(stdout);
+
for (;;) {
chunk = bytes_per_iteration < bytes_left ? bytes_per_iteration : bytes_left;
range[0] = bm_on_disk_off;
range[1] = chunk; /* len */
+ ++n_writes;
err = ioctl(cfg->md_fd, BLKZEROOUT, &range);
if (err) {
PERROR("ioctl(%s, BLKZEROOUT, [%llu, %llu]) failed", cfg->md_device_name,
(unsigned long long)range[0], (unsigned long long)range[1]);
return -1;
}
+ if (verbose >= 2) {
+ fprintf(stderr, " %-26s: ioctl(%u, BLKZEROOUT, [%"PRIu64", %"PRIu64"])\n",
+ "md_initialize_common:BM", cfg->md_fd, range[0], range[1]);
+ }
bm_on_disk_off += chunk;
bytes_left -= chunk;
if (bytes_left == 0)
--
2.33.1.windows.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/drbd.git
git@gitee.com:src-openeuler/drbd.git
src-openeuler
drbd
drbd
master

搜索帮助