drivers/nvme/host/sysfs.c

Source file repositories/reference/linux-study-clean/drivers/nvme/host/sysfs.c

File Facts

System
Linux kernel
Corpus path
drivers/nvme/host/sysfs.c
Extension
.c
Size
34815 bytes
Lines
1311
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 (quirks & 1) {
			count += sysfs_emit_at(buf, count, "%s\n",
					nvme_quirk_name(BIT(i)));
		}
		quirks >>= 1;
	}

	return count;
}
static DEVICE_ATTR_RO(quirks);

static ssize_t nvme_admin_timeout_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);

	return sysfs_emit(buf, "%u\n",
				jiffies_to_msecs(ctrl->admin_timeout));
}

static ssize_t nvme_admin_timeout_store(struct device *dev,
		struct device_attribute *attr,
		const char *buf, size_t count)
{
	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
	u32 timeout;
	int err;

	/*
	 * Wait until the controller reaches the LIVE state to be sure that
	 * admin_q and fabrics_q are properly initialized.
	 */
	if (!test_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags))
		return -EBUSY;

	err = kstrtou32(buf, 10, &timeout);
	if (err || !timeout)
		return -EINVAL;

	ctrl->admin_timeout = msecs_to_jiffies(timeout);

	blk_queue_rq_timeout(ctrl->admin_q, ctrl->admin_timeout);
	if (ctrl->fabrics_q)
		blk_queue_rq_timeout(ctrl->fabrics_q, ctrl->admin_timeout);

	return count;
}

static DEVICE_ATTR(admin_timeout, S_IRUGO | S_IWUSR,
	nvme_admin_timeout_show, nvme_admin_timeout_store);

static ssize_t nvme_io_timeout_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);

	return sysfs_emit(buf, "%u\n", jiffies_to_msecs(ctrl->io_timeout));
}

static ssize_t nvme_io_timeout_store(struct device *dev,
		struct device_attribute *attr,
		const char *buf, size_t count)
{
	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
	struct nvme_ns *ns;
	u32 timeout;
	int err;

	/*
	 * Wait until the controller reaches the LIVE state to be sure that
	 * connect_q is properly initialized.
	 */
	if (!test_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags))
		return -EBUSY;

	err = kstrtou32(buf, 10, &timeout);
	if (err || !timeout)
		return -EINVAL;

	/* Take the namespaces_lock to avoid racing against nvme_alloc_ns() */
	mutex_lock(&ctrl->namespaces_lock);

	ctrl->io_timeout = msecs_to_jiffies(timeout);
	list_for_each_entry(ns, &ctrl->namespaces, list)
		blk_queue_rq_timeout(ns->queue, ctrl->io_timeout);

	mutex_unlock(&ctrl->namespaces_lock);

	if (ctrl->connect_q)
		blk_queue_rq_timeout(ctrl->connect_q, ctrl->io_timeout);

Annotation

Implementation Notes