drivers/hv/mshv_debugfs.c

Source file repositories/reference/linux-study-clean/drivers/hv/mshv_debugfs.c

File Facts

System
Linux kernel
Corpus path
drivers/hv/mshv_debugfs.c
Extension
.c
Size
17021 bytes
Lines
730
Domain
Driver Families
Bucket
drivers/hv
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (IS_ERR(pstats[HV_STATS_AREA_PARENT])) {
			err = PTR_ERR(pstats[HV_STATS_AREA_PARENT]);
			goto unmap_self;
		}
		if (!pstats[HV_STATS_AREA_PARENT])
			pstats[HV_STATS_AREA_PARENT] = pstats[HV_STATS_AREA_SELF];
	}

	dentry = debugfs_create_file("stats", 0400, parent,
				     pstats, &partition_stats_fops);
	if (IS_ERR(dentry)) {
		err = PTR_ERR(dentry);
		goto unmap_partition_stats;
	}

	*partition_stats_ptr = dentry;
	return 0;

unmap_partition_stats:
	if (pstats[HV_STATS_AREA_PARENT] != pstats[HV_STATS_AREA_SELF])
		mshv_partition_stats_unmap(partition_id, pstats[HV_STATS_AREA_PARENT],
					   HV_STATS_AREA_PARENT);
unmap_self:
	mshv_partition_stats_unmap(partition_id, pstats[HV_STATS_AREA_SELF],
				   HV_STATS_AREA_SELF);
cleanup:
	kfree(pstats);
	return err;
}

static void partition_debugfs_remove(u64 partition_id, struct dentry *dentry)
{
	struct hv_stats_page **pstats = NULL;

	pstats = dentry->d_inode->i_private;

	debugfs_remove_recursive(dentry->d_parent);

	if (pstats[HV_STATS_AREA_PARENT] != pstats[HV_STATS_AREA_SELF]) {
		mshv_partition_stats_unmap(partition_id,
					   pstats[HV_STATS_AREA_PARENT],
					   HV_STATS_AREA_PARENT);
	}

	mshv_partition_stats_unmap(partition_id,
				   pstats[HV_STATS_AREA_SELF],
				   HV_STATS_AREA_SELF);

	kfree(pstats);
}

static int partition_debugfs_create(u64 partition_id,
				    struct dentry **vp_dir_ptr,
				    struct dentry **partition_stats_ptr,
				    struct dentry *parent)
{
	char part_id_str[U64_BUF_SZ];
	struct dentry *part_id_dir, *vp_dir;
	int err;

	if (is_l1vh_parent(partition_id))
		sprintf(part_id_str, "self");
	else
		sprintf(part_id_str, "%llu", partition_id);

	part_id_dir = debugfs_create_dir(part_id_str, parent);
	if (IS_ERR(part_id_dir))
		return PTR_ERR(part_id_dir);

	vp_dir = debugfs_create_dir("vp", part_id_dir);
	if (IS_ERR(vp_dir)) {
		err = PTR_ERR(vp_dir);
		goto remove_debugfs_partition_id;
	}

	err = mshv_debugfs_partition_stats_create(partition_id,
						  partition_stats_ptr,
						  part_id_dir);
	if (err)
		goto remove_debugfs_partition_id;

	*vp_dir_ptr = vp_dir;

	return 0;

remove_debugfs_partition_id:
	debugfs_remove_recursive(part_id_dir);
	return err;
}

Annotation

Implementation Notes