Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)    linear.c : Multiple Devices driver for Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 	      Copyright (C) 1994-96 Marc ZYNGIER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 	      <zyngier@ufr-info-p7.ibp.fr> or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 	      <maz@gloups.fdn.fr>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)    Linear mode management functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/raid/md_u.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <trace/events/block.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "md.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "md-linear.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * find which device holds a particular offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static inline struct dev_info *which_dev(struct mddev *mddev, sector_t sector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	int lo, mid, hi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct linear_conf *conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	lo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	hi = mddev->raid_disks - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	conf = mddev->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	 * Binary Search
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	while (hi > lo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		mid = (hi + lo) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		if (sector < conf->disks[mid].end_sector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			hi = mid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			lo = mid + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	return conf->disks + lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static sector_t linear_size(struct mddev *mddev, sector_t sectors, int raid_disks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct linear_conf *conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	sector_t array_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	conf = mddev->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	WARN_ONCE(sectors || raid_disks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		  "%s does not support generic reshape\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	array_sectors = conf->array_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	return array_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static struct linear_conf *linear_conf(struct mddev *mddev, int raid_disks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct linear_conf *conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct md_rdev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	int i, cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	bool discard_supported = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	conf = kzalloc(struct_size(conf, disks, raid_disks), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (!conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	conf->array_sectors = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	rdev_for_each(rdev, mddev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		int j = rdev->raid_disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		struct dev_info *disk = conf->disks + j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		sector_t sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		if (j < 0 || j >= raid_disks || disk->rdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			pr_warn("md/linear:%s: disk numbering problem. Aborting!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				mdname(mddev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		disk->rdev = rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		if (mddev->chunk_sectors) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			sectors = rdev->sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			sector_div(sectors, mddev->chunk_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			rdev->sectors = sectors * mddev->chunk_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		disk_stack_limits(mddev->gendisk, rdev->bdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				  rdev->data_offset << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		conf->array_sectors += rdev->sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		if (blk_queue_discard(bdev_get_queue(rdev->bdev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			discard_supported = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (cnt != raid_disks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		pr_warn("md/linear:%s: not enough drives present. Aborting!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			mdname(mddev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (!discard_supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		blk_queue_flag_clear(QUEUE_FLAG_DISCARD, mddev->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		blk_queue_flag_set(QUEUE_FLAG_DISCARD, mddev->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * Here we calculate the device offsets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	conf->disks[0].end_sector = conf->disks[0].rdev->sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	for (i = 1; i < raid_disks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		conf->disks[i].end_sector =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			conf->disks[i-1].end_sector +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			conf->disks[i].rdev->sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	 * conf->raid_disks is copy of mddev->raid_disks. The reason to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	 * keep a copy of mddev->raid_disks in struct linear_conf is,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	 * mddev->raid_disks may not be consistent with pointers number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	 * conf->disks[] when it is updated in linear_add() and used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	 * iterate old conf->disks[] earray in linear_congested().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	 * Here conf->raid_disks is always consitent with number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	 * pointers in conf->disks[] array, and mddev->private is updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	 * with rcu_assign_pointer() in linear_addr(), such race can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	 * avoided.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	conf->raid_disks = raid_disks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	return conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	kfree(conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static int linear_run (struct mddev *mddev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct linear_conf *conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (md_check_no_bitmap(mddev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	conf = linear_conf(mddev, mddev->raid_disks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (!conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	mddev->private = conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	md_set_array_sectors(mddev, linear_size(mddev, 0, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	ret =  md_integrity_register(mddev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		kfree(conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		mddev->private = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int linear_add(struct mddev *mddev, struct md_rdev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	/* Adding a drive to a linear array allows the array to grow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	 * It is permitted if the new drive has a matching superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	 * already on it, with raid_disk equal to raid_disks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	 * It is achieved by creating a new linear_private_data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	 * and swapping it in in-place of the current one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	 * The current one is never freed until the array is stopped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	 * This avoids races.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	struct linear_conf *newconf, *oldconf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (rdev->saved_raid_disk != mddev->raid_disks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	rdev->raid_disk = rdev->saved_raid_disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	rdev->saved_raid_disk = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	newconf = linear_conf(mddev,mddev->raid_disks+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (!newconf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	/* newconf->raid_disks already keeps a copy of * the increased
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	 * value of mddev->raid_disks, WARN_ONCE() is just used to make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	 * sure of this. It is possible that oldconf is still referenced
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	 * in linear_congested(), therefore kfree_rcu() is used to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	 * oldconf until no one uses it anymore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	mddev_suspend(mddev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	oldconf = rcu_dereference_protected(mddev->private,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			lockdep_is_held(&mddev->reconfig_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	mddev->raid_disks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	WARN_ONCE(mddev->raid_disks != newconf->raid_disks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		"copied raid_disks doesn't match mddev->raid_disks");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	rcu_assign_pointer(mddev->private, newconf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	md_set_array_sectors(mddev, linear_size(mddev, 0, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	set_capacity(mddev->gendisk, mddev->array_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	mddev_resume(mddev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	revalidate_disk_size(mddev->gendisk, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	kfree_rcu(oldconf, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static void linear_free(struct mddev *mddev, void *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	struct linear_conf *conf = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	kfree(conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static bool linear_make_request(struct mddev *mddev, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	char b[BDEVNAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct dev_info *tmp_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	sector_t start_sector, end_sector, data_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	sector_t bio_sector = bio->bi_iter.bi_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	if (unlikely(bio->bi_opf & REQ_PREFLUSH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	    && md_flush_request(mddev, bio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	tmp_dev = which_dev(mddev, bio_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	start_sector = tmp_dev->end_sector - tmp_dev->rdev->sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	end_sector = tmp_dev->end_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	data_offset = tmp_dev->rdev->data_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (unlikely(bio_sector >= end_sector ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		     bio_sector < start_sector))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		goto out_of_bounds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (unlikely(is_mddev_broken(tmp_dev->rdev, "linear"))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		bio_io_error(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (unlikely(bio_end_sector(bio) > end_sector)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		/* This bio crosses a device boundary, so we have to split it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		struct bio *split = bio_split(bio, end_sector - bio_sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 					      GFP_NOIO, &mddev->bio_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		bio_chain(split, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		submit_bio_noacct(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		bio = split;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	bio_set_dev(bio, tmp_dev->rdev->bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	bio->bi_iter.bi_sector = bio->bi_iter.bi_sector -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		start_sector + data_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (unlikely((bio_op(bio) == REQ_OP_DISCARD) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		     !blk_queue_discard(bio->bi_disk->queue))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		/* Just ignore it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		bio_endio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		if (mddev->gendisk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			trace_block_bio_remap(bio->bi_disk->queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 					      bio, disk_devt(mddev->gendisk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 					      bio_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		mddev_check_writesame(mddev, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		mddev_check_write_zeroes(mddev, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		submit_bio_noacct(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) out_of_bounds:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	pr_err("md/linear:%s: make_request: Sector %llu out of bounds on dev %s: %llu sectors, offset %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	       mdname(mddev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	       (unsigned long long)bio->bi_iter.bi_sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	       bdevname(tmp_dev->rdev->bdev, b),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	       (unsigned long long)tmp_dev->rdev->sectors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	       (unsigned long long)start_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	bio_io_error(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static void linear_status (struct seq_file *seq, struct mddev *mddev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	seq_printf(seq, " %dk rounding", mddev->chunk_sectors / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static void linear_quiesce(struct mddev *mddev, int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static struct md_personality linear_personality =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	.name		= "linear",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	.level		= LEVEL_LINEAR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	.make_request	= linear_make_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	.run		= linear_run,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	.free		= linear_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	.status		= linear_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	.hot_add_disk	= linear_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	.size		= linear_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	.quiesce	= linear_quiesce,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static int __init linear_init (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return register_md_personality (&linear_personality);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static void linear_exit (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	unregister_md_personality (&linear_personality);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) module_init(linear_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) module_exit(linear_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) MODULE_DESCRIPTION("Linear device concatenation personality for MD");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) MODULE_ALIAS("md-personality-1"); /* LINEAR - deprecated*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) MODULE_ALIAS("md-linear");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) MODULE_ALIAS("md-level--1");