2018-03-28 22:43:57 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-09-22 19:47:10 +07: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;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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 11:04:17 +07:00
|
|
|
static ssize_t
|
|
|
|
stp_policy_node_masters_show(struct config_item *item, char *page)
|
2015-09-22 19:47:10 +07: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 11:04:17 +07:00
|
|
|
struct stp_policy_node *policy_node = to_stp_policy_node(item);
|
2015-09-22 19:47:10 +07: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 11:04:17 +07:00
|
|
|
stp_policy_node_masters_store(struct config_item *item, const char *page,
|
|
|
|
size_t count)
|
2015-09-22 19:47:10 +07: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 11:04:17 +07:00
|
|
|
struct stp_policy_node *policy_node = to_stp_policy_node(item);
|
2015-09-22 19:47:10 +07: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 14:55:42 +07:00
|
|
|
if (first > last || first < stm->data->sw_start ||
|
2015-09-22 19:47:10 +07: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 11:04:17 +07:00
|
|
|
stp_policy_node_channels_show(struct config_item *item, char *page)
|
2015-09-22 19:47:10 +07: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 11:04:17 +07:00
|
|
|
struct stp_policy_node *policy_node = to_stp_policy_node(item);
|
2015-09-22 19:47:10 +07: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 11:04:17 +07:00
|
|
|
stp_policy_node_channels_store(struct config_item *item, const char *page,
|
|
|
|
size_t count)
|
2015-09-22 19:47:10 +07: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 11:04:17 +07:00
|
|
|
struct stp_policy_node *policy_node = to_stp_policy_node(item);
|
2015-09-22 19:47:10 +07: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)
|
|
|
|
{
|
|
|
|
kfree(to_stp_policy_node(item));
|
|
|
|
}
|
|
|
|
|
|
|
|
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 11:04:17 +07:00
|
|
|
CONFIGFS_ATTR(stp_policy_node_, masters);
|
|
|
|
CONFIGFS_ATTR(stp_policy_node_, channels);
|
2015-09-22 19:47:10 +07: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 11:04:17 +07:00
|
|
|
&stp_policy_node_attr_masters,
|
|
|
|
&stp_policy_node_attr_channels,
|
2015-09-22 19:47:10 +07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2017-10-16 22:18:50 +07:00
|
|
|
static const struct config_item_type stp_policy_type;
|
|
|
|
static const struct config_item_type stp_policy_node_type;
|
2015-09-22 19:47:10 +07:00
|
|
|
|
|
|
|
static struct config_group *
|
|
|
|
stp_policy_node_make(struct config_group *group, const char *name)
|
|
|
|
{
|
|
|
|
struct stp_policy_node *policy_node, *parent_node;
|
|
|
|
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);
|
|
|
|
|
|
|
|
policy_node = kzalloc(sizeof(struct stp_policy_node), GFP_KERNEL);
|
|
|
|
if (!policy_node)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
config_group_init_type_name(&policy_node->group, name,
|
|
|
|
&stp_policy_node_type);
|
|
|
|
|
|
|
|
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 22:18:50 +07:00
|
|
|
static const struct config_item_type stp_policy_node_type = {
|
2015-09-22 19:47:10 +07: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 11:04:17 +07:00
|
|
|
static ssize_t stp_policy_device_show(struct config_item *item,
|
|
|
|
char *page)
|
2015-09-22 19:47:10 +07: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 11:04:17 +07:00
|
|
|
CONFIGFS_ATTR_RO(stp_policy_, device);
|
|
|
|
|
|
|
|
static struct configfs_attribute *stp_policy_attrs[] = {
|
|
|
|
&stp_policy_attr_device,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2015-09-22 19:47:10 +07:00
|
|
|
void stp_policy_unbind(struct stp_policy *policy)
|
|
|
|
{
|
|
|
|
struct stm_device *stm = policy->stm;
|
|
|
|
|
2015-12-22 22:25:18 +07: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 19:47:10 +07:00
|
|
|
if (WARN_ON_ONCE(!policy->stm))
|
|
|
|
return;
|
|
|
|
|
2015-12-22 22:25:18 +07:00
|
|
|
lockdep_assert_held(&stm->policy_mutex);
|
2015-09-22 19:47:10 +07:00
|
|
|
|
2015-12-22 22:25:18 +07:00
|
|
|
stm->policy = NULL;
|
2015-09-22 19:47:10 +07:00
|
|
|
policy->stm = NULL;
|
|
|
|
|
|
|
|
stm_put_device(stm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stp_policy_release(struct config_item *item)
|
|
|
|
{
|
|
|
|
struct stp_policy *policy = to_stp_policy(item);
|
2015-12-22 22:25:18 +07:00
|
|
|
struct stm_device *stm = policy->stm;
|
2015-09-22 19:47:10 +07:00
|
|
|
|
2015-12-22 22:25:18 +07:00
|
|
|
/* a policy *can* be unbound and still exist in configfs tree */
|
|
|
|
if (!stm)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mutex_lock(&stm->policy_mutex);
|
2015-09-22 19:47:10 +07:00
|
|
|
stp_policy_unbind(policy);
|
2015-12-22 22:25:18 +07:00
|
|
|
mutex_unlock(&stm->policy_mutex);
|
|
|
|
|
2015-09-22 19:47:10 +07: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 22:18:50 +07:00
|
|
|
static const struct config_item_type stp_policy_type = {
|
2015-09-22 19:47:10 +07: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 *
|
|
|
|
stp_policies_make(struct config_group *group, const char *name)
|
|
|
|
{
|
|
|
|
struct config_group *ret;
|
|
|
|
struct stm_device *stm;
|
|
|
|
char *devname, *p;
|
|
|
|
|
|
|
|
devname = kasprintf(GFP_KERNEL, "%s", name);
|
|
|
|
if (!devname)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* node must look like <device_name>.<policy_name>, where
|
2016-02-16 00:12:02 +07:00
|
|
|
* <device_name> is the name of an existing stm device; may
|
|
|
|
* contain dots;
|
|
|
|
* <policy_name> is an arbitrary string; may not contain dots
|
2015-09-22 19:47:10 +07:00
|
|
|
*/
|
2016-02-16 00:12:02 +07:00
|
|
|
p = strrchr(devname, '.');
|
2015-09-22 19:47:10 +07:00
|
|
|
if (!p) {
|
|
|
|
kfree(devname);
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
2016-03-04 21:55:12 +07:00
|
|
|
*p = '\0';
|
2015-09-22 19:47:10 +07:00
|
|
|
|
|
|
|
stm = stm_find_device(devname);
|
|
|
|
kfree(devname);
|
|
|
|
|
|
|
|
if (!stm)
|
|
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
ret = ERR_PTR(-ENOMEM);
|
|
|
|
goto unlock_policy;
|
|
|
|
}
|
|
|
|
|
|
|
|
config_group_init_type_name(&stm->policy->group, name,
|
|
|
|
&stp_policy_type);
|
|
|
|
stm->policy->stm = stm;
|
|
|
|
|
|
|
|
ret = &stm->policy->group;
|
|
|
|
|
|
|
|
unlock_policy:
|
|
|
|
mutex_unlock(&stm->policy_mutex);
|
|
|
|
|
|
|
|
if (IS_ERR(ret))
|
|
|
|
stm_put_device(stm);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct configfs_group_operations stp_policies_group_ops = {
|
|
|
|
.make_group = stp_policies_make,
|
|
|
|
};
|
|
|
|
|
2017-10-16 22:18:50 +07:00
|
|
|
static const struct config_item_type stp_policies_type = {
|
2015-09-22 19:47:10 +07:00
|
|
|
.ct_group_ops = &stp_policies_group_ops,
|
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct configfs_subsystem stp_policy_subsys = {
|
|
|
|
.su_group = {
|
|
|
|
.cg_item = {
|
|
|
|
.ci_namebuf = "stp-policy",
|
|
|
|
.ci_type = &stp_policies_type,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 19:42:51 +07:00
|
|
|
struct stp_policy_node *policy_node, *ret = NULL;
|
2015-09-22 19:47:10 +07: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 19:42:51 +07:00
|
|
|
else
|
|
|
|
mutex_unlock(&stp_policy_subsys.su_mutex);
|
2015-09-22 19:47:10 +07: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 19:42:51 +07:00
|
|
|
lockdep_assert_held(&stp_policy_subsys.su_mutex);
|
|
|
|
|
|
|
|
mutex_unlock(&stp_policy_subsys.su_mutex);
|
2015-09-22 19:47:10 +07:00
|
|
|
config_item_put(&policy_node->group.cg_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
int __init stp_configfs_init(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
config_group_init(&stp_policy_subsys.su_group);
|
|
|
|
mutex_init(&stp_policy_subsys.su_mutex);
|
|
|
|
err = configfs_register_subsystem(&stp_policy_subsys);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __exit stp_configfs_exit(void)
|
|
|
|
{
|
|
|
|
configfs_unregister_subsystem(&stp_policy_subsys);
|
|
|
|
}
|