block/blk-integrity.c

Source file repositories/reference/linux-study-clean/block/blk-integrity.c

File Facts

System
Linux kernel
Corpus path
block/blk-integrity.c
Extension
.c
Size
8830 bytes
Lines
343
Domain
Representative Device Path
Bucket
PCIe NVMe Storage Path
Inferred role
Representative Device Path: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.

Dependency Surface

Detected Declarations

Annotated Snippet

if (prev) {
			if (!biovec_phys_mergeable(q, &ivprv, &iv))
				goto new_segment;
			if (seg_size + iv.bv_len > queue_max_segment_size(q))
				goto new_segment;

			seg_size += iv.bv_len;
		} else {
new_segment:
			segments++;
			seg_size = iv.bv_len;
		}

		prev = 1;
		ivprv = iv;
	}

	return segments;
}

int blk_get_meta_cap(struct block_device *bdev, unsigned int cmd,
		     struct logical_block_metadata_cap __user *argp)
{
	struct blk_integrity *bi;
	struct logical_block_metadata_cap meta_cap = {};
	size_t usize = _IOC_SIZE(cmd);

	if (!extensible_ioctl_valid(cmd, FS_IOC_GETLBMD_CAP, LBMD_SIZE_VER0))
		return -ENOIOCTLCMD;

	bi = blk_get_integrity(bdev->bd_disk);
	if (!bi)
		goto out;

	if (bi->flags & BLK_INTEGRITY_DEVICE_CAPABLE)
		meta_cap.lbmd_flags |= LBMD_PI_CAP_INTEGRITY;
	if (bi->flags & BLK_INTEGRITY_REF_TAG)
		meta_cap.lbmd_flags |= LBMD_PI_CAP_REFTAG;
	meta_cap.lbmd_interval = 1 << bi->interval_exp;
	meta_cap.lbmd_size = bi->metadata_size;
	meta_cap.lbmd_pi_size = bi->pi_tuple_size;
	meta_cap.lbmd_pi_offset = bi->pi_offset;
	meta_cap.lbmd_opaque_size = bi->metadata_size - bi->pi_tuple_size;
	if (meta_cap.lbmd_opaque_size && !bi->pi_offset)
		meta_cap.lbmd_opaque_offset = bi->pi_tuple_size;

	switch (bi->csum_type) {
	case BLK_INTEGRITY_CSUM_NONE:
		meta_cap.lbmd_guard_tag_type = LBMD_PI_CSUM_NONE;
		break;
	case BLK_INTEGRITY_CSUM_IP:
		meta_cap.lbmd_guard_tag_type = LBMD_PI_CSUM_IP;
		break;
	case BLK_INTEGRITY_CSUM_CRC:
		meta_cap.lbmd_guard_tag_type = LBMD_PI_CSUM_CRC16_T10DIF;
		break;
	case BLK_INTEGRITY_CSUM_CRC64:
		meta_cap.lbmd_guard_tag_type = LBMD_PI_CSUM_CRC64_NVME;
		break;
	}

	if (bi->csum_type != BLK_INTEGRITY_CSUM_NONE)
		meta_cap.lbmd_app_tag_size = 2;

	if (bi->flags & BLK_INTEGRITY_REF_TAG) {
		switch (bi->csum_type) {
		case BLK_INTEGRITY_CSUM_CRC64:
			meta_cap.lbmd_ref_tag_size =
				sizeof_field(struct crc64_pi_tuple, ref_tag);
			break;
		case BLK_INTEGRITY_CSUM_CRC:
		case BLK_INTEGRITY_CSUM_IP:
			meta_cap.lbmd_ref_tag_size =
				sizeof_field(struct t10_pi_tuple, ref_tag);
			break;
		default:
			break;
		}
	}

out:
	return copy_struct_to_user(argp, usize, &meta_cap, sizeof(meta_cap),
				   NULL);
}

int blk_rq_integrity_map_user(struct request *rq, void __user *ubuf,
			      ssize_t bytes)
{
	int ret;
	struct iov_iter iter;

Annotation

Implementation Notes