2018-03-28 23:43:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-09-22 20:47:10 +08:00
|
|
|
/*
|
|
|
|
* System Trace Module (STM) master/channel allocation policy management
|
|
|
|
* Copyright (c) 2014, Intel Corporation.
|
|
|
|
*
|
|
|
|
* A master/channel allocation policy allows mapping string identifiers to
|
|
|
|
* master and channel ranges, where allocation can be done.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/configfs.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/stm.h>
|
|
|
|
#include "stm.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* STP Master/Channel allocation policy configfs layout.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct stp_policy {
|
|
|
|
struct config_group group;
|
|
|
|
struct stm_device *stm;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stp_policy_node {
|
|
|
|
struct config_group group;
|
|
|
|
struct stp_policy *policy;
|
|
|
|
unsigned int first_master;
|
|
|
|
unsigned int last_master;
|
|
|
|
unsigned int first_channel;
|
|
|
|
unsigned int last_channel;
|
2018-10-05 20:42:54 +08:00
|
|
|
/* this is the one that's exposed to the attributes */
|
|
|
|
unsigned char priv[0];
|
2015-09-22 20:47:10 +08:00
|
|
|
};
|
|
|
|
|
2018-10-05 20:42:54 +08:00
|
|
|
void *stp_policy_node_priv(struct stp_policy_node *pn)
|
|
|
|
{
|
|
|
|
if (!pn)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return pn->priv;
|
|
|
|
}
|
|
|
|
|
2015-09-22 20:47:10 +08:00
|
|
|
static struct configfs_subsystem stp_policy_subsys;
|
|
|
|
|
|
|
|
void stp_policy_node_get_ranges(struct stp_policy_node *policy_node,
|
|
|
|
unsigned int *mstart, unsigned int *mend,
|
|
|
|
unsigned int *cstart, unsigned int *cend)
|
|
|
|
{
|
|
|
|
*mstart = policy_node->first_master;
|
|
|
|
*mend = policy_node->last_master;
|
|
|
|
*cstart = policy_node->first_channel;
|
|
|
|
*cend = policy_node->last_channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *stp_policy_node_name(struct stp_policy_node *policy_node)
|
|
|
|
{
|
|
|
|
return policy_node->group.cg_item.ci_name ? : "<none>";
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct stp_policy *to_stp_policy(struct config_item *item)
|
|
|
|
{
|
|
|
|
return item ?
|
|
|
|
container_of(to_config_group(item), struct stp_policy, group) :
|
|
|
|
NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct stp_policy_node *
|
|
|
|
to_stp_policy_node(struct config_item *item)
|
|
|
|
{
|
|
|
|
return item ?
|
|
|
|
container_of(to_config_group(item), struct stp_policy_node,
|
|
|
|
group) :
|
|
|
|
NULL;
|
|
|
|
}
|
|
|
|
|
2018-10-05 20:42:54 +08:00
|
|
|
void *to_pdrv_policy_node(struct config_item *item)
|
|
|
|
{
|
|
|
|
struct stp_policy_node *node = to_stp_policy_node(item);
|
|
|
|
|
|
|
|
return stp_policy_node_priv(node);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(to_pdrv_policy_node);
|
|
|
|
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
static ssize_t
|
|
|
|
stp_policy_node_masters_show(struct config_item *item, char *page)
|
2015-09-22 20:47:10 +08:00
|
|
|
{
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
struct stp_policy_node *policy_node = to_stp_policy_node(item);
|
2015-09-22 20:47:10 +08:00
|
|
|
ssize_t count;
|
|
|
|
|
|
|
|
count = sprintf(page, "%u %u\n", policy_node->first_master,
|
|
|
|
policy_node->last_master);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
stp_policy_node_masters_store(struct config_item *item, const char *page,
|
|
|
|
size_t count)
|
2015-09-22 20:47:10 +08:00
|
|
|
{
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
struct stp_policy_node *policy_node = to_stp_policy_node(item);
|
2015-09-22 20:47:10 +08:00
|
|
|
unsigned int first, last;
|
|
|
|
struct stm_device *stm;
|
|
|
|
char *p = (char *)page;
|
|
|
|
ssize_t ret = -ENODEV;
|
|
|
|
|
|
|
|
if (sscanf(p, "%u %u", &first, &last) != 2)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
mutex_lock(&stp_policy_subsys.su_mutex);
|
|
|
|
stm = policy_node->policy->stm;
|
|
|
|
if (!stm)
|
|
|
|
goto unlock;
|
|
|
|
|
|
|
|
/* must be within [sw_start..sw_end], which is an inclusive range */
|
2016-03-28 15:55:42 +08:00
|
|
|
if (first > last || first < stm->data->sw_start ||
|
2015-09-22 20:47:10 +08:00
|
|
|
last > stm->data->sw_end) {
|
|
|
|
ret = -ERANGE;
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = count;
|
|
|
|
policy_node->first_master = first;
|
|
|
|
policy_node->last_master = last;
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
mutex_unlock(&stp_policy_subsys.su_mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
stp_policy_node_channels_show(struct config_item *item, char *page)
|
2015-09-22 20:47:10 +08:00
|
|
|
{
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
struct stp_policy_node *policy_node = to_stp_policy_node(item);
|
2015-09-22 20:47:10 +08:00
|
|
|
ssize_t count;
|
|
|
|
|
|
|
|
count = sprintf(page, "%u %u\n", policy_node->first_channel,
|
|
|
|
policy_node->last_channel);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
stp_policy_node_channels_store(struct config_item *item, const char *page,
|
|
|
|
size_t count)
|
2015-09-22 20:47:10 +08:00
|
|
|
{
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
struct stp_policy_node *policy_node = to_stp_policy_node(item);
|
2015-09-22 20:47:10 +08:00
|
|
|
unsigned int first, last;
|
|
|
|
struct stm_device *stm;
|
|
|
|
char *p = (char *)page;
|
|
|
|
ssize_t ret = -ENODEV;
|
|
|
|
|
|
|
|
if (sscanf(p, "%u %u", &first, &last) != 2)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
mutex_lock(&stp_policy_subsys.su_mutex);
|
|
|
|
stm = policy_node->policy->stm;
|
|
|
|
if (!stm)
|
|
|
|
goto unlock;
|
|
|
|
|
|
|
|
if (first > INT_MAX || last > INT_MAX || first > last ||
|
|
|
|
last >= stm->data->sw_nchannels) {
|
|
|
|
ret = -ERANGE;
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = count;
|
|
|
|
policy_node->first_channel = first;
|
|
|
|
policy_node->last_channel = last;
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
mutex_unlock(&stp_policy_subsys.su_mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stp_policy_node_release(struct config_item *item)
|
|
|
|
{
|
2018-10-05 20:42:54 +08:00
|
|
|
struct stp_policy_node *node = to_stp_policy_node(item);
|
|
|
|
|
|
|
|
kfree(node);
|
2015-09-22 20:47:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct configfs_item_operations stp_policy_node_item_ops = {
|
|
|
|
.release = stp_policy_node_release,
|
|
|
|
};
|
|
|
|
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
CONFIGFS_ATTR(stp_policy_node_, masters);
|
|
|
|
CONFIGFS_ATTR(stp_policy_node_, channels);
|
2015-09-22 20:47:10 +08:00
|
|
|
|
|
|
|
static struct configfs_attribute *stp_policy_node_attrs[] = {
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
&stp_policy_node_attr_masters,
|
|
|
|
&stp_policy_node_attr_channels,
|
2015-09-22 20:47:10 +08:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2017-10-16 23:18:50 +08:00
|
|
|
static const struct config_item_type stp_policy_type;
|
|
|
|
static const struct config_item_type stp_policy_node_type;
|
2015-09-22 20:47:10 +08:00
|
|
|
|
2018-10-05 20:42:54 +08:00
|
|
|
/* lifted from arch/x86/events/core.c */
|
|
|
|
static struct configfs_attribute **merge_attr(struct configfs_attribute **a, struct configfs_attribute **b)
|
|
|
|
{
|
|
|
|
struct configfs_attribute **new;
|
|
|
|
int j, i;
|
|
|
|
|
|
|
|
for (j = 0; a[j]; j++)
|
|
|
|
;
|
|
|
|
for (i = 0; b[i]; i++)
|
|
|
|
j++;
|
|
|
|
j++;
|
|
|
|
|
|
|
|
new = kmalloc_array(j, sizeof(struct configfs_attribute *),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!new)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; a[i]; i++)
|
|
|
|
new[j++] = a[i];
|
|
|
|
for (i = 0; b[i]; i++)
|
|
|
|
new[j++] = b[i];
|
|
|
|
new[j] = NULL;
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct config_item_type *
|
|
|
|
get_policy_node_type(struct configfs_attribute **attrs)
|
|
|
|
{
|
|
|
|
struct config_item_type *type;
|
|
|
|
struct configfs_attribute **merged;
|
|
|
|
|
|
|
|
type = kmemdup(&stp_policy_node_type, sizeof(stp_policy_node_type),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!type)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
merged = merge_attr(stp_policy_node_attrs, attrs);
|
|
|
|
if (!merged) {
|
|
|
|
kfree(type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
type->ct_attrs = merged;
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2015-09-22 20:47:10 +08:00
|
|
|
static struct config_group *
|
|
|
|
stp_policy_node_make(struct config_group *group, const char *name)
|
|
|
|
{
|
2018-10-05 20:42:54 +08:00
|
|
|
const struct config_item_type *type = &stp_policy_node_type;
|
2015-09-22 20:47:10 +08:00
|
|
|
struct stp_policy_node *policy_node, *parent_node;
|
2018-10-05 20:42:54 +08:00
|
|
|
const struct stm_protocol_driver *pdrv;
|
2015-09-22 20:47:10 +08:00
|
|
|
struct stp_policy *policy;
|
|
|
|
|
|
|
|
if (group->cg_item.ci_type == &stp_policy_type) {
|
|
|
|
policy = container_of(group, struct stp_policy, group);
|
|
|
|
} else {
|
|
|
|
parent_node = container_of(group, struct stp_policy_node,
|
|
|
|
group);
|
|
|
|
policy = parent_node->policy;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!policy->stm)
|
|
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
|
2018-10-05 20:42:54 +08:00
|
|
|
pdrv = policy->stm->pdrv;
|
|
|
|
policy_node =
|
|
|
|
kzalloc(offsetof(struct stp_policy_node, priv[pdrv->priv_sz]),
|
|
|
|
GFP_KERNEL);
|
2015-09-22 20:47:10 +08:00
|
|
|
if (!policy_node)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2018-10-05 20:42:54 +08:00
|
|
|
if (pdrv->policy_node_init)
|
|
|
|
pdrv->policy_node_init((void *)policy_node->priv);
|
|
|
|
|
|
|
|
if (policy->stm->pdrv_node_type)
|
|
|
|
type = policy->stm->pdrv_node_type;
|
|
|
|
|
|
|
|
config_group_init_type_name(&policy_node->group, name, type);
|
2015-09-22 20:47:10 +08:00
|
|
|
|
|
|
|
policy_node->policy = policy;
|
|
|
|
|
|
|
|
/* default values for the attributes */
|
|
|
|
policy_node->first_master = policy->stm->data->sw_start;
|
|
|
|
policy_node->last_master = policy->stm->data->sw_end;
|
|
|
|
policy_node->first_channel = 0;
|
|
|
|
policy_node->last_channel = policy->stm->data->sw_nchannels - 1;
|
|
|
|
|
|
|
|
return &policy_node->group;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
stp_policy_node_drop(struct config_group *group, struct config_item *item)
|
|
|
|
{
|
|
|
|
config_item_put(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct configfs_group_operations stp_policy_node_group_ops = {
|
|
|
|
.make_group = stp_policy_node_make,
|
|
|
|
.drop_item = stp_policy_node_drop,
|
|
|
|
};
|
|
|
|
|
2017-10-16 23:18:50 +08:00
|
|
|
static const struct config_item_type stp_policy_node_type = {
|
2015-09-22 20:47:10 +08:00
|
|
|
.ct_item_ops = &stp_policy_node_item_ops,
|
|
|
|
.ct_group_ops = &stp_policy_node_group_ops,
|
|
|
|
.ct_attrs = stp_policy_node_attrs,
|
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Root group: policies.
|
|
|
|
*/
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
static ssize_t stp_policy_device_show(struct config_item *item,
|
|
|
|
char *page)
|
2015-09-22 20:47:10 +08:00
|
|
|
{
|
|
|
|
struct stp_policy *policy = to_stp_policy(item);
|
|
|
|
ssize_t count;
|
|
|
|
|
|
|
|
count = sprintf(page, "%s\n",
|
|
|
|
(policy && policy->stm) ?
|
|
|
|
policy->stm->data->name :
|
|
|
|
"<none>");
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
CONFIGFS_ATTR_RO(stp_policy_, device);
|
|
|
|
|
2018-10-05 20:42:54 +08:00
|
|
|
static ssize_t stp_policy_protocol_show(struct config_item *item,
|
|
|
|
char *page)
|
|
|
|
{
|
|
|
|
struct stp_policy *policy = to_stp_policy(item);
|
|
|
|
ssize_t count;
|
|
|
|
|
|
|
|
count = sprintf(page, "%s\n",
|
|
|
|
(policy && policy->stm) ?
|
|
|
|
policy->stm->pdrv->name :
|
|
|
|
"<none>");
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
CONFIGFS_ATTR_RO(stp_policy_, protocol);
|
|
|
|
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
static struct configfs_attribute *stp_policy_attrs[] = {
|
|
|
|
&stp_policy_attr_device,
|
2018-10-05 20:42:54 +08:00
|
|
|
&stp_policy_attr_protocol,
|
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger:
"This series contains HCH's changes to absorb configfs attribute
->show() + ->store() function pointer usage from it's original
tree-wide consumers, into common configfs code.
It includes usb-gadget, target w/ drivers, netconsole and ocfs2
changes to realize the improved simplicity, that now renders the
original include/target/configfs_macros.h CPP magic for fabric drivers
and others, unnecessary and obsolete.
And with common code in place, new configfs attributes can be added
easier than ever before.
Note, there are further improvements in-flight from other folks for
v4.5 code in configfs land, plus number of target fixes for post -rc1
code"
In the meantime, a new user of the now-removed old configfs API came in
through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce
an abstraction for System Trace Module devices").
This merge resolution comes from Alexander Shishkin, who updated his stm
class tracing abstraction to account for the removal of the old
show_attribute and store_attribute methods in commit 517982229f78
("configfs: remove old API") from this pull. As Alexander says about
that patch:
"There's no need to keep an extra wrapper structure per item and the
awkward show_attribute/store_attribute item ops are no longer needed.
This patch converts policy code to the new api, all the while making
the code quite a bit smaller and easier on the eyes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>"
That patch was folded into the merge so that the tree should be fully
bisectable.
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits)
configfs: remove old API
ocfs2/cluster: use per-attribute show and store methods
ocfs2/cluster: move locking into attribute store methods
netconsole: use per-attribute show and store methods
target: use per-attribute show and store methods
spear13xx_pcie_gadget: use per-attribute show and store methods
dlm: use per-attribute show and store methods
usb-gadget/f_serial: use per-attribute show and store methods
usb-gadget/f_phonet: use per-attribute show and store methods
usb-gadget/f_obex: use per-attribute show and store methods
usb-gadget/f_uac2: use per-attribute show and store methods
usb-gadget/f_uac1: use per-attribute show and store methods
usb-gadget/f_mass_storage: use per-attribute show and store methods
usb-gadget/f_sourcesink: use per-attribute show and store methods
usb-gadget/f_printer: use per-attribute show and store methods
usb-gadget/f_midi: use per-attribute show and store methods
usb-gadget/f_loopback: use per-attribute show and store methods
usb-gadget/ether: use per-attribute show and store methods
usb-gadget/f_acm: use per-attribute show and store methods
usb-gadget/f_hid: use per-attribute show and store methods
...
2015-11-14 12:04:17 +08:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2015-09-22 20:47:10 +08:00
|
|
|
void stp_policy_unbind(struct stp_policy *policy)
|
|
|
|
{
|
|
|
|
struct stm_device *stm = policy->stm;
|
|
|
|
|
2015-12-22 23:25:18 +08:00
|
|
|
/*
|
|
|
|
* stp_policy_release() will not call here if the policy is already
|
|
|
|
* unbound; other users should not either, as no link exists between
|
|
|
|
* this policy and anything else in that case
|
|
|
|
*/
|
2015-09-22 20:47:10 +08:00
|
|
|
if (WARN_ON_ONCE(!policy->stm))
|
|
|
|
return;
|
|
|
|
|
2015-12-22 23:25:18 +08:00
|
|
|
lockdep_assert_held(&stm->policy_mutex);
|
2015-09-22 20:47:10 +08:00
|
|
|
|
2015-12-22 23:25:18 +08:00
|
|
|
stm->policy = NULL;
|
2015-09-22 20:47:10 +08:00
|
|
|
policy->stm = NULL;
|
|
|
|
|
2018-10-05 20:42:54 +08:00
|
|
|
stm_put_protocol(stm->pdrv);
|
2015-09-22 20:47:10 +08:00
|
|
|
stm_put_device(stm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stp_policy_release(struct config_item *item)
|
|
|
|
{
|
|
|
|
struct stp_policy *policy = to_stp_policy(item);
|
2015-12-22 23:25:18 +08:00
|
|
|
struct stm_device *stm = policy->stm;
|
2015-09-22 20:47:10 +08:00
|
|
|
|
2015-12-22 23:25:18 +08:00
|
|
|
/* a policy *can* be unbound and still exist in configfs tree */
|
|
|
|
if (!stm)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mutex_lock(&stm->policy_mutex);
|
2015-09-22 20:47:10 +08:00
|
|
|
stp_policy_unbind(policy);
|
2015-12-22 23:25:18 +08:00
|
|
|
mutex_unlock(&stm->policy_mutex);
|
|
|
|
|
2015-09-22 20:47:10 +08:00
|
|
|
kfree(policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct configfs_item_operations stp_policy_item_ops = {
|
|
|
|
.release = stp_policy_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct configfs_group_operations stp_policy_group_ops = {
|
|
|
|
.make_group = stp_policy_node_make,
|
|
|
|
};
|
|
|
|
|
2017-10-16 23:18:50 +08:00
|
|
|
static const struct config_item_type stp_policy_type = {
|
2015-09-22 20:47:10 +08:00
|
|
|
.ct_item_ops = &stp_policy_item_ops,
|
|
|
|
.ct_group_ops = &stp_policy_group_ops,
|
|
|
|
.ct_attrs = stp_policy_attrs,
|
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct config_group *
|
2018-10-05 20:42:52 +08:00
|
|
|
stp_policy_make(struct config_group *group, const char *name)
|
2015-09-22 20:47:10 +08:00
|
|
|
{
|
2018-10-05 20:42:54 +08:00
|
|
|
const struct config_item_type *pdrv_node_type;
|
|
|
|
const struct stm_protocol_driver *pdrv;
|
|
|
|
char *devname, *proto, *p;
|
2015-09-22 20:47:10 +08:00
|
|
|
struct config_group *ret;
|
|
|
|
struct stm_device *stm;
|
2018-10-05 20:42:54 +08:00
|
|
|
int err;
|
2015-09-22 20:47:10 +08:00
|
|
|
|
|
|
|
devname = kasprintf(GFP_KERNEL, "%s", name);
|
|
|
|
if (!devname)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* node must look like <device_name>.<policy_name>, where
|
2016-02-16 01:12:02 +08:00
|
|
|
* <device_name> is the name of an existing stm device; may
|
|
|
|
* contain dots;
|
|
|
|
* <policy_name> is an arbitrary string; may not contain dots
|
2018-10-05 20:42:54 +08:00
|
|
|
* <device_name>:<protocol_name>.<policy_name>
|
2015-09-22 20:47:10 +08:00
|
|
|
*/
|
2016-02-16 01:12:02 +08:00
|
|
|
p = strrchr(devname, '.');
|
2015-09-22 20:47:10 +08:00
|
|
|
if (!p) {
|
|
|
|
kfree(devname);
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
2016-03-04 22:55:12 +08:00
|
|
|
*p = '\0';
|
2015-09-22 20:47:10 +08:00
|
|
|
|
2018-10-05 20:42:54 +08:00
|
|
|
/*
|
|
|
|
* look for ":<protocol_name>":
|
|
|
|
* + no protocol suffix: fall back to whatever is available;
|
|
|
|
* + unknown protocol: fail the whole thing
|
|
|
|
*/
|
|
|
|
proto = strrchr(devname, ':');
|
|
|
|
if (proto)
|
|
|
|
*proto++ = '\0';
|
|
|
|
|
2015-09-22 20:47:10 +08:00
|
|
|
stm = stm_find_device(devname);
|
2018-10-05 20:42:54 +08:00
|
|
|
if (!stm) {
|
|
|
|
kfree(devname);
|
|
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = stm_lookup_protocol(proto, &pdrv, &pdrv_node_type);
|
2015-09-22 20:47:10 +08:00
|
|
|
kfree(devname);
|
|
|
|
|
2018-10-05 20:42:54 +08:00
|
|
|
/* We don't have any protocol drivers yet */
|
|
|
|
if (err != -ENOENT) {
|
|
|
|
stm_put_device(stm);
|
2015-09-22 20:47:10 +08:00
|
|
|
return ERR_PTR(-ENODEV);
|
2018-10-05 20:42:54 +08:00
|
|
|
}
|
2015-09-22 20:47:10 +08:00
|
|
|
|
|
|
|
mutex_lock(&stm->policy_mutex);
|
|
|
|
if (stm->policy) {
|
|
|
|
ret = ERR_PTR(-EBUSY);
|
|
|
|
goto unlock_policy;
|
|
|
|
}
|
|
|
|
|
|
|
|
stm->policy = kzalloc(sizeof(*stm->policy), GFP_KERNEL);
|
|
|
|
if (!stm->policy) {
|
2018-10-05 20:42:54 +08:00
|
|
|
mutex_unlock(&stm->policy_mutex);
|
|
|
|
stm_put_protocol(pdrv);
|
|
|
|
stm_put_device(stm);
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2015-09-22 20:47:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
config_group_init_type_name(&stm->policy->group, name,
|
|
|
|
&stp_policy_type);
|
|
|
|
|
2018-10-05 20:42:54 +08:00
|
|
|
stm->pdrv = pdrv;
|
|
|
|
stm->pdrv_node_type = pdrv_node_type;
|
|
|
|
stm->policy->stm = stm;
|
2015-09-22 20:47:10 +08:00
|
|
|
ret = &stm->policy->group;
|
|
|
|
|
|
|
|
unlock_policy:
|
|
|
|
mutex_unlock(&stm->policy_mutex);
|
|
|
|
|
2018-10-05 20:42:54 +08:00
|
|
|
if (IS_ERR(ret)) {
|
|
|
|
stm_put_protocol(stm->pdrv);
|
2015-09-22 20:47:10 +08:00
|
|
|
stm_put_device(stm);
|
2018-10-05 20:42:54 +08:00
|
|
|
}
|
2015-09-22 20:47:10 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-05 20:42:52 +08:00
|
|
|
static struct configfs_group_operations stp_policy_root_group_ops = {
|
|
|
|
.make_group = stp_policy_make,
|
2015-09-22 20:47:10 +08:00
|
|
|
};
|
|
|
|
|
2018-10-05 20:42:52 +08:00
|
|
|
static const struct config_item_type stp_policy_root_type = {
|
|
|
|
.ct_group_ops = &stp_policy_root_group_ops,
|
2015-09-22 20:47:10 +08:00
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct configfs_subsystem stp_policy_subsys = {
|
|
|
|
.su_group = {
|
|
|
|
.cg_item = {
|
|
|
|
.ci_namebuf = "stp-policy",
|
2018-10-05 20:42:52 +08:00
|
|
|
.ci_type = &stp_policy_root_type,
|
2015-09-22 20:47:10 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock the policy mutex from the outside
|
|
|
|
*/
|
|
|
|
static struct stp_policy_node *
|
|
|
|
__stp_policy_node_lookup(struct stp_policy *policy, char *s)
|
|
|
|
{
|
stm class: Rework policy node fallback
Currently, if no matching policy node can be found for a trace source,
we'll try to use "default" policy node, then, if that doesn't exist,
we'll pick the first node, in order of creation. If that also fails,
we'll allocate M/C range from the beginning of the device's M/C range.
This makes it difficult to know which node (if any) was used in any
particular case.
In order to make things more deterministic, the new order is as follows:
* if they supply ID string, use that and nothing else,
* if they are a task, use their task name (comm),
* use "default", if it exists,
* return failure, to let them know there is no suitable rule.
This should provide enough convenience with the "default" catch-all node,
while not leaving *everything* to chance. As a side effect, this relaxes
the requirement of using ioctl() for identification with the possibility of
using task names as policy nodes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Tested-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-05 20:42:51 +08:00
|
|
|
struct stp_policy_node *policy_node, *ret = NULL;
|
2015-09-22 20:47:10 +08:00
|
|
|
struct list_head *head = &policy->group.cg_children;
|
|
|
|
struct config_item *item;
|
|
|
|
char *start, *end = s;
|
|
|
|
|
|
|
|
if (list_empty(head))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
next:
|
|
|
|
for (;;) {
|
|
|
|
start = strsep(&end, "/");
|
|
|
|
if (!start)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!*start)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
list_for_each_entry(item, head, ci_entry) {
|
|
|
|
policy_node = to_stp_policy_node(item);
|
|
|
|
|
|
|
|
if (!strcmp(start,
|
|
|
|
policy_node->group.cg_item.ci_name)) {
|
|
|
|
ret = policy_node;
|
|
|
|
|
|
|
|
if (!end)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
head = &policy_node->group.cg_children;
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct stp_policy_node *
|
|
|
|
stp_policy_node_lookup(struct stm_device *stm, char *s)
|
|
|
|
{
|
|
|
|
struct stp_policy_node *policy_node = NULL;
|
|
|
|
|
|
|
|
mutex_lock(&stp_policy_subsys.su_mutex);
|
|
|
|
|
|
|
|
mutex_lock(&stm->policy_mutex);
|
|
|
|
if (stm->policy)
|
|
|
|
policy_node = __stp_policy_node_lookup(stm->policy, s);
|
|
|
|
mutex_unlock(&stm->policy_mutex);
|
|
|
|
|
|
|
|
if (policy_node)
|
|
|
|
config_item_get(&policy_node->group.cg_item);
|
stm class: Rework policy node fallback
Currently, if no matching policy node can be found for a trace source,
we'll try to use "default" policy node, then, if that doesn't exist,
we'll pick the first node, in order of creation. If that also fails,
we'll allocate M/C range from the beginning of the device's M/C range.
This makes it difficult to know which node (if any) was used in any
particular case.
In order to make things more deterministic, the new order is as follows:
* if they supply ID string, use that and nothing else,
* if they are a task, use their task name (comm),
* use "default", if it exists,
* return failure, to let them know there is no suitable rule.
This should provide enough convenience with the "default" catch-all node,
while not leaving *everything* to chance. As a side effect, this relaxes
the requirement of using ioctl() for identification with the possibility of
using task names as policy nodes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Tested-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-05 20:42:51 +08:00
|
|
|
else
|
|
|
|
mutex_unlock(&stp_policy_subsys.su_mutex);
|
2015-09-22 20:47:10 +08:00
|
|
|
|
|
|
|
return policy_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void stp_policy_node_put(struct stp_policy_node *policy_node)
|
|
|
|
{
|
stm class: Rework policy node fallback
Currently, if no matching policy node can be found for a trace source,
we'll try to use "default" policy node, then, if that doesn't exist,
we'll pick the first node, in order of creation. If that also fails,
we'll allocate M/C range from the beginning of the device's M/C range.
This makes it difficult to know which node (if any) was used in any
particular case.
In order to make things more deterministic, the new order is as follows:
* if they supply ID string, use that and nothing else,
* if they are a task, use their task name (comm),
* use "default", if it exists,
* return failure, to let them know there is no suitable rule.
This should provide enough convenience with the "default" catch-all node,
while not leaving *everything* to chance. As a side effect, this relaxes
the requirement of using ioctl() for identification with the possibility of
using task names as policy nodes.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Tested-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-10-05 20:42:51 +08:00
|
|
|
lockdep_assert_held(&stp_policy_subsys.su_mutex);
|
|
|
|
|
|
|
|
mutex_unlock(&stp_policy_subsys.su_mutex);
|
2015-09-22 20:47:10 +08:00
|
|
|
config_item_put(&policy_node->group.cg_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
int __init stp_configfs_init(void)
|
|
|
|
{
|
|
|
|
config_group_init(&stp_policy_subsys.su_group);
|
|
|
|
mutex_init(&stp_policy_subsys.su_mutex);
|
2018-10-05 20:42:53 +08:00
|
|
|
return configfs_register_subsystem(&stp_policy_subsys);
|
2015-09-22 20:47:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __exit stp_configfs_exit(void)
|
|
|
|
{
|
|
|
|
configfs_unregister_subsystem(&stp_policy_subsys);
|
|
|
|
}
|