软raid sync_action

控制节点:

/sys/block/md127/md/sync_action

内核是怎么实现的,为什么mdadm管理命令仅支持四种?

[root@gitclient ~]# mdadm --action --help
mdadm: action must be one of idle, frozen, check, repair

内核文档是怎么描述这个节点?

   sync_action
     a text file that can be used to monitor and control the rebuild
     process.  It contains one word which can be one of:

       resync
		redundancy(冗余) is being recalculated after unclean
                shutdown or creation

       recover
		a hot spare is being built to replace a
		failed/missing device

       idle
		nothing is happening
       check
		A full check of redundancy was requested and is
                happening.  This reads all blocks and checks
                them. A repair may also happen for some raid
                levels.

       repair
		A full check and repair is happening.  This is
		similar to ``resync``, but was requested by the
                user, and the write-intent bitmap is NOT used to
		optimise the process.

      This file is writable, and each of the strings that could be
      read are meaningful for writing.

	``idle`` will stop an active resync/recovery etc.  There is no
	guarantee that another resync/recovery may not be automatically
	started again, though some event will be needed to trigger
	this.

	``resync`` or ``recovery`` can be used to restart the
        corresponding operation if it was stopped with ``idle``.

	``check`` and ``repair`` will start the appropriate process
	providing the current state is ``idle``.

      This file responds to select/poll.  Any important change in the value
      triggers a poll event.  Sometimes the value will briefly be
      ``recover`` if a recovery seems to be needed, but cannot be
      achieved. In that case, the transition to ``recover`` isn't
      notified, but the transition away is.

如果单纯做check操作,怎么知道有哪些不同呢?

/sys/block/md127/md/mismatch_cnt

内核中对该字段的描述

   mismatch_count
      When performing ``check`` and ``repair``, and possibly when
      performing ``resync``, md will count the number of errors that are
      found.  The count in ``mismatch_cnt`` is the number of sectors
      that were re-written, or (for ``check``) would have been
      re-written.  As most raid levels work in units of pages rather
      than sectors, this may be larger than the number of actual errors
      by a factor of the number of sectors in a page.

在执行“检查”和“修复”,以及可能在执行“重新同步”时,md 将计算发现的错误数量。在“mismatch_cnt”中的计数是重新写入的扇区数量,或者(对于“检查”)本应该重新写入的扇区数量。由于大多数 RAID 级别以页面为单位工作,而不是以扇区为单位,因此这个数量可能会比实际错误数量大,大约是页面中扇区数量的倍数。

从上述描述来看,这个值也是不准确的?

  • 向某块成员盘数据区写入数据,将raid阵列写坏。

    [root@gitclient ~]# dd if=/dev/urandom of=/dev/sdb bs=512 count=1 seek=4096 oflag=direct
    1+0 records in
    1+0 records out
    512 bytes copied, 0.0148909 s, 34.4 kB/s
    
  • 手动触发raid阵列检查操作。

    [root@gitclient ~]# mdadm --action check /dev/md127
    [root@gitclient ~]# cat /proc/mdstat
    Personalities : [raid1]
    md127 : active raid1 sdb[0] sdc[1]
          1046528 blocks super 1.2 [2/2] [UU]
          [======>..............]  check = 33.4% (350400/1046528) finish=0.0min speed=175200K/sec
          bitmap: 0/1 pages [0KB], 65536KB chunk
    
    unused devices: <none>
    
  • 查看节点的值。

    [root@gitclient ~]# cat /sys/block/md127/md/mismatch_cnt
    128
    

为什么是128个扇区?

数据同步的默认单位是64K,也就是128个扇区,也就是说这个值记录的是某次IO操作尺寸。

到底内核是怎么给这个节点进行计数?这个值什么时候会被清理掉?

// md.c
// 定义文件节点。
static struct md_sysfs_entry md_mismatches = __ATTR_RO(mismatch_cnt);

struct mddev {
    	atomic64_t			resync_mismatches; /* count of sectors where
							    * parity/replica mismatch found
							    */
}

// 节点show方法,读取的是mddev中元素的值。
static ssize_t
mismatch_cnt_show(struct mddev *mddev, char *page)
{
        return sprintf(page, "%llu\n",
                       (unsigned long long)
                       atomic64_read(&mddev->resync_mismatches));
}

// process_checks函数会修改改字段的值。

		if (j >= 0)
			atomic64_add(r1_bio->sectors, &mddev->resync_mismatches);
		if (j < 0 || (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)
			      && !status)) {
			/* No need to write to this device. */
			sbio->bi_end_io = NULL;
			rdev_dec_pending(conf->mirrors[i].rdev, mddev);
			continue;
		}

被清理掉的逻辑发生在md_clean和md_do_sync同步完成后再下check命令的场景下。

如何查看两个设备数据区存在差异呢?存在差异也不一定能够说明存在数据损坏?

sync; echo 3 > /proc/sys/vm/drop_caches
cmp -l /dev/sdb /dev/sdc

进行数据比较时记得清理掉缓存!!cmp有没有办法直接跳过缓存?

除了上述比较方法后也可以在内核驱动中添加打印来标识哪些数据不一致。

  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值