mirror of https://gitee.com/openkylin/linux.git
IB/srp: Consolidate repetitive sysfs code
Remove sysfs attributes before removing a target instead of testing the target state in every sysfs attribute callback method. Note: it is safe to invoke a sysfs attribute removal method like device_remove_file() twice on the same attribute. Signed-off-by: Bart Van Assche <bvanassche@acm.org> Acked-by: David Dillow <dillowda@ornl.gov> Signed-off-by: Roland Dreier <roland@purestorage.com>
This commit is contained in:
parent
e0bda7d8c3
commit
683b159a2e
|
@ -474,6 +474,21 @@ static void srp_free_req_data(struct srp_target_port *target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* srp_del_scsi_host_attr() - Remove attributes defined in the host template.
|
||||||
|
* @shost: SCSI host whose attributes to remove from sysfs.
|
||||||
|
*
|
||||||
|
* Note: Any attributes defined in the host template and that did not exist
|
||||||
|
* before invocation of this function will be ignored.
|
||||||
|
*/
|
||||||
|
static void srp_del_scsi_host_attr(struct Scsi_Host *shost)
|
||||||
|
{
|
||||||
|
struct device_attribute **attr;
|
||||||
|
|
||||||
|
for (attr = shost->hostt->shost_attrs; attr && *attr; ++attr)
|
||||||
|
device_remove_file(&shost->shost_dev, *attr);
|
||||||
|
}
|
||||||
|
|
||||||
static void srp_remove_work(struct work_struct *work)
|
static void srp_remove_work(struct work_struct *work)
|
||||||
{
|
{
|
||||||
struct srp_target_port *target =
|
struct srp_target_port *target =
|
||||||
|
@ -486,6 +501,7 @@ static void srp_remove_work(struct work_struct *work)
|
||||||
list_del(&target->list);
|
list_del(&target->list);
|
||||||
spin_unlock(&target->srp_host->target_lock);
|
spin_unlock(&target->srp_host->target_lock);
|
||||||
|
|
||||||
|
srp_del_scsi_host_attr(target->scsi_host);
|
||||||
srp_remove_host(target->scsi_host);
|
srp_remove_host(target->scsi_host);
|
||||||
scsi_remove_host(target->scsi_host);
|
scsi_remove_host(target->scsi_host);
|
||||||
ib_destroy_cm_id(target->cm_id);
|
ib_destroy_cm_id(target->cm_id);
|
||||||
|
@ -1678,10 +1694,6 @@ static ssize_t show_id_ext(struct device *dev, struct device_attribute *attr,
|
||||||
{
|
{
|
||||||
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
||||||
|
|
||||||
if (target->state == SRP_TARGET_DEAD ||
|
|
||||||
target->state == SRP_TARGET_REMOVED)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
return sprintf(buf, "0x%016llx\n",
|
return sprintf(buf, "0x%016llx\n",
|
||||||
(unsigned long long) be64_to_cpu(target->id_ext));
|
(unsigned long long) be64_to_cpu(target->id_ext));
|
||||||
}
|
}
|
||||||
|
@ -1691,10 +1703,6 @@ static ssize_t show_ioc_guid(struct device *dev, struct device_attribute *attr,
|
||||||
{
|
{
|
||||||
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
||||||
|
|
||||||
if (target->state == SRP_TARGET_DEAD ||
|
|
||||||
target->state == SRP_TARGET_REMOVED)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
return sprintf(buf, "0x%016llx\n",
|
return sprintf(buf, "0x%016llx\n",
|
||||||
(unsigned long long) be64_to_cpu(target->ioc_guid));
|
(unsigned long long) be64_to_cpu(target->ioc_guid));
|
||||||
}
|
}
|
||||||
|
@ -1704,10 +1712,6 @@ static ssize_t show_service_id(struct device *dev,
|
||||||
{
|
{
|
||||||
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
||||||
|
|
||||||
if (target->state == SRP_TARGET_DEAD ||
|
|
||||||
target->state == SRP_TARGET_REMOVED)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
return sprintf(buf, "0x%016llx\n",
|
return sprintf(buf, "0x%016llx\n",
|
||||||
(unsigned long long) be64_to_cpu(target->service_id));
|
(unsigned long long) be64_to_cpu(target->service_id));
|
||||||
}
|
}
|
||||||
|
@ -1717,10 +1721,6 @@ static ssize_t show_pkey(struct device *dev, struct device_attribute *attr,
|
||||||
{
|
{
|
||||||
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
||||||
|
|
||||||
if (target->state == SRP_TARGET_DEAD ||
|
|
||||||
target->state == SRP_TARGET_REMOVED)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
return sprintf(buf, "0x%04x\n", be16_to_cpu(target->path.pkey));
|
return sprintf(buf, "0x%04x\n", be16_to_cpu(target->path.pkey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1729,10 +1729,6 @@ static ssize_t show_dgid(struct device *dev, struct device_attribute *attr,
|
||||||
{
|
{
|
||||||
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
||||||
|
|
||||||
if (target->state == SRP_TARGET_DEAD ||
|
|
||||||
target->state == SRP_TARGET_REMOVED)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
return sprintf(buf, "%pI6\n", target->path.dgid.raw);
|
return sprintf(buf, "%pI6\n", target->path.dgid.raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1741,10 +1737,6 @@ static ssize_t show_orig_dgid(struct device *dev,
|
||||||
{
|
{
|
||||||
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
||||||
|
|
||||||
if (target->state == SRP_TARGET_DEAD ||
|
|
||||||
target->state == SRP_TARGET_REMOVED)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
return sprintf(buf, "%pI6\n", target->orig_dgid);
|
return sprintf(buf, "%pI6\n", target->orig_dgid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1753,10 +1745,6 @@ static ssize_t show_req_lim(struct device *dev,
|
||||||
{
|
{
|
||||||
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
||||||
|
|
||||||
if (target->state == SRP_TARGET_DEAD ||
|
|
||||||
target->state == SRP_TARGET_REMOVED)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
return sprintf(buf, "%d\n", target->req_lim);
|
return sprintf(buf, "%d\n", target->req_lim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1765,10 +1753,6 @@ static ssize_t show_zero_req_lim(struct device *dev,
|
||||||
{
|
{
|
||||||
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
struct srp_target_port *target = host_to_target(class_to_shost(dev));
|
||||||
|
|
||||||
if (target->state == SRP_TARGET_DEAD ||
|
|
||||||
target->state == SRP_TARGET_REMOVED)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
return sprintf(buf, "%d\n", target->zero_req_lim);
|
return sprintf(buf, "%d\n", target->zero_req_lim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2432,6 +2416,7 @@ static void srp_remove_one(struct ib_device *device)
|
||||||
|
|
||||||
list_for_each_entry_safe(target, tmp_target,
|
list_for_each_entry_safe(target, tmp_target,
|
||||||
&host->target_list, list) {
|
&host->target_list, list) {
|
||||||
|
srp_del_scsi_host_attr(target->scsi_host);
|
||||||
srp_remove_host(target->scsi_host);
|
srp_remove_host(target->scsi_host);
|
||||||
scsi_remove_host(target->scsi_host);
|
scsi_remove_host(target->scsi_host);
|
||||||
srp_disconnect_target(target);
|
srp_disconnect_target(target);
|
||||||
|
|
Loading…
Reference in New Issue