Commit 20540a56 authored by Julian Wiedmann's avatar Julian Wiedmann Committed by Martin K. Petersen
Browse files

scsi: zfcp: Clean up sysfs code for SFP diagnostics

The error path from zfcp_adapter_enqueue() no longer attempts to remove the
diagnostics attributes if they haven't been created yet.

So remove the manual 'sysfs_established' guard for this case, and use
device_add_groups() to add all adapter-related sysfs attributes in one go.

Link: https://lore.kernel.org/r/37a97537f675d643006271f37723c346189b6eec.1618417667.git.bblock@linux.ibm.com


Reviewed-by: default avatarBenjamin Block <bblock@linux.ibm.com>
Reviewed-by: default avatarSteffen Maier <maier@linux.ibm.com>
Signed-off-by: default avatarJulian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: default avatarBenjamin Block <bblock@linux.ibm.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent ab1fa880
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -413,12 +413,8 @@ struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *ccw_device)

	dev_set_drvdata(&ccw_device->dev, adapter);

	if (sysfs_create_group(&ccw_device->dev.kobj,
			       &zfcp_sysfs_adapter_attrs))
		goto failed;

	if (zfcp_diag_sysfs_setup(adapter))
		goto err_diag_sysfs;
	if (device_add_groups(&ccw_device->dev, zfcp_sysfs_adapter_attr_groups))
		goto err_sysfs;

	/* report size limit per scatter-gather segment */
	adapter->ccw_device->dev.dma_parms = &adapter->dma_parms;
@@ -427,8 +423,7 @@ struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *ccw_device)

	return adapter;

err_diag_sysfs:
	sysfs_remove_group(&ccw_device->dev.kobj, &zfcp_sysfs_adapter_attrs);
err_sysfs:
failed:
	/* TODO: make this more fine-granular */
	cancel_delayed_work_sync(&adapter->scan_work);
@@ -460,8 +455,7 @@ void zfcp_adapter_unregister(struct zfcp_adapter *adapter)

	zfcp_fc_wka_ports_force_offline(adapter->gs);
	zfcp_scsi_adapter_unregister(adapter);
	zfcp_diag_sysfs_destroy(adapter);
	sysfs_remove_group(&cdev->dev.kobj, &zfcp_sysfs_adapter_attrs);
	device_remove_groups(&cdev->dev, zfcp_sysfs_adapter_attr_groups);

	zfcp_erp_thread_kill(adapter);
	zfcp_dbf_adapter_unregister(adapter);
+0 −42
Original line number Diff line number Diff line
@@ -10,8 +10,6 @@
#include <linux/spinlock.h>
#include <linux/jiffies.h>
#include <linux/string.h>
#include <linux/kernfs.h>
#include <linux/sysfs.h>
#include <linux/errno.h>
#include <linux/slab.h>

@@ -79,46 +77,6 @@ void zfcp_diag_adapter_free(struct zfcp_adapter *const adapter)
	adapter->diagnostics = NULL;
}

/**
 * zfcp_diag_sysfs_setup() - Setup the sysfs-group for adapter-diagnostics.
 * @adapter: target adapter to which the group should be added.
 *
 * Return: 0 on success; Something else otherwise (see sysfs_create_group()).
 */
int zfcp_diag_sysfs_setup(struct zfcp_adapter *const adapter)
{
	int rc = sysfs_create_group(&adapter->ccw_device->dev.kobj,
				    &zfcp_sysfs_diag_attr_group);
	if (rc == 0)
		adapter->diagnostics->sysfs_established = 1;

	return rc;
}

/**
 * zfcp_diag_sysfs_destroy() - Remove the sysfs-group for adapter-diagnostics.
 * @adapter: target adapter from which the group should be removed.
 */
void zfcp_diag_sysfs_destroy(struct zfcp_adapter *const adapter)
{
	if (adapter->diagnostics == NULL ||
	    !adapter->diagnostics->sysfs_established)
		return;

	/*
	 * We need this state-handling so we can prevent warnings being printed
	 * on the kernel-console in case we have to abort a halfway done
	 * zfcp_adapter_enqueue(), in which the sysfs-group was not yet
	 * established. sysfs_remove_group() does this checking as well, but
	 * still prints a warning in case we try to remove a group that has not
	 * been established before
	 */
	adapter->diagnostics->sysfs_established = 0;
	sysfs_remove_group(&adapter->ccw_device->dev.kobj,
			   &zfcp_sysfs_diag_attr_group);
}


/**
 * zfcp_diag_update_xdata() - Update a diagnostics buffer.
 * @hdr: the meta data to update.
+0 −7
Original line number Diff line number Diff line
@@ -40,8 +40,6 @@ struct zfcp_diag_header {
/**
 * struct zfcp_diag_adapter - central storage for all diagnostics concerning an
 *			      adapter.
 * @sysfs_established: flag showing that the associated sysfs-group was created
 *		       during run of zfcp_adapter_enqueue().
 * @max_age: maximum age of data in diagnostic buffers before they need to be
 *	     refreshed (in ms).
 * @port_data: data retrieved using exchange port data.
@@ -52,8 +50,6 @@ struct zfcp_diag_header {
 * @config_data.data: cached QTCB Bottom of command exchange config data.
 */
struct zfcp_diag_adapter {
	u64	sysfs_established	:1;

	unsigned long	max_age;

	struct zfcp_diag_adapter_port_data {
@@ -69,9 +65,6 @@ struct zfcp_diag_adapter {
int zfcp_diag_adapter_setup(struct zfcp_adapter *const adapter);
void zfcp_diag_adapter_free(struct zfcp_adapter *const adapter);

int zfcp_diag_sysfs_setup(struct zfcp_adapter *const adapter);
void zfcp_diag_sysfs_destroy(struct zfcp_adapter *const adapter);

void zfcp_diag_update_xdata(struct zfcp_diag_header *const hdr,
			    const void *const data, const bool incomplete);

+2 −2
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
#define ZFCP_EXT_H

#include <linux/types.h>
#include <linux/sysfs.h>
#include <scsi/fc/fc_els.h>
#include "zfcp_def.h"
#include "zfcp_fc.h"
@@ -179,13 +180,12 @@ extern void zfcp_scsi_shost_update_port_data(
	const struct fsf_qtcb_bottom_port *const bottom);

/* zfcp_sysfs.c */
extern const struct attribute_group *zfcp_sysfs_adapter_attr_groups[];
extern const struct attribute_group *zfcp_unit_attr_groups[];
extern struct attribute_group zfcp_sysfs_adapter_attrs;
extern const struct attribute_group *zfcp_port_attr_groups[];
extern struct mutex zfcp_sysfs_port_units_mutex;
extern struct device_attribute *zfcp_sysfs_sdev_attrs[];
extern struct device_attribute *zfcp_sysfs_shost_attrs[];
extern const struct attribute_group zfcp_sysfs_diag_attr_group;
bool zfcp_sysfs_port_is_removing(const struct zfcp_port *const port);

/* zfcp_unit.c */
+8 −2
Original line number Diff line number Diff line
@@ -435,7 +435,7 @@ static struct attribute *zfcp_adapter_attrs[] = {
	NULL
};

struct attribute_group zfcp_sysfs_adapter_attrs = {
static const struct attribute_group zfcp_sysfs_adapter_attr_group = {
	.attrs = zfcp_adapter_attrs,
};

@@ -906,7 +906,13 @@ static struct attribute *zfcp_sysfs_diag_attrs[] = {
	NULL,
};

const struct attribute_group zfcp_sysfs_diag_attr_group = {
static const struct attribute_group zfcp_sysfs_diag_attr_group = {
	.name = "diagnostics",
	.attrs = zfcp_sysfs_diag_attrs,
};

const struct attribute_group *zfcp_sysfs_adapter_attr_groups[] = {
	&zfcp_sysfs_adapter_attr_group,
	&zfcp_sysfs_diag_attr_group,
	NULL,
};