Skip to content

Commit 343f902

Browse files
leitaoPaolo Abeni
authored andcommitted
netconsole: implement configfs for release_enabled
Implement the configfs helpers to show and set release_enabled configfs directories under userdata. When enabled, set the feature bit in netconsole_target->sysdata_fields. Signed-off-by: Breno Leitao <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 42211e3 commit 343f902

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

drivers/net/netconsole.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,19 @@ static ssize_t sysdata_taskname_enabled_show(struct config_item *item,
442442
return sysfs_emit(buf, "%d\n", taskname_enabled);
443443
}
444444

445+
static ssize_t sysdata_release_enabled_show(struct config_item *item,
446+
char *buf)
447+
{
448+
struct netconsole_target *nt = to_target(item->ci_parent);
449+
bool release_enabled;
450+
451+
mutex_lock(&dynamic_netconsole_mutex);
452+
release_enabled = !!(nt->sysdata_fields & SYSDATA_TASKNAME);
453+
mutex_unlock(&dynamic_netconsole_mutex);
454+
455+
return sysfs_emit(buf, "%d\n", release_enabled);
456+
}
457+
445458
/*
446459
* This one is special -- targets created through the configfs interface
447460
* are not enabled (and the corresponding netpoll activated) by default.
@@ -859,6 +872,40 @@ static void disable_sysdata_feature(struct netconsole_target *nt,
859872
nt->extradata_complete[nt->userdata_length] = 0;
860873
}
861874

875+
static ssize_t sysdata_release_enabled_store(struct config_item *item,
876+
const char *buf, size_t count)
877+
{
878+
struct netconsole_target *nt = to_target(item->ci_parent);
879+
bool release_enabled, curr;
880+
ssize_t ret;
881+
882+
ret = kstrtobool(buf, &release_enabled);
883+
if (ret)
884+
return ret;
885+
886+
mutex_lock(&dynamic_netconsole_mutex);
887+
curr = !!(nt->sysdata_fields & SYSDATA_RELEASE);
888+
if (release_enabled == curr)
889+
goto unlock_ok;
890+
891+
if (release_enabled &&
892+
count_extradata_entries(nt) >= MAX_EXTRADATA_ITEMS) {
893+
ret = -ENOSPC;
894+
goto unlock;
895+
}
896+
897+
if (release_enabled)
898+
nt->sysdata_fields |= SYSDATA_RELEASE;
899+
else
900+
disable_sysdata_feature(nt, SYSDATA_RELEASE);
901+
902+
unlock_ok:
903+
ret = strnlen(buf, count);
904+
unlock:
905+
mutex_unlock(&dynamic_netconsole_mutex);
906+
return ret;
907+
}
908+
862909
static ssize_t sysdata_taskname_enabled_store(struct config_item *item,
863910
const char *buf, size_t count)
864911
{
@@ -939,6 +986,7 @@ static ssize_t sysdata_cpu_nr_enabled_store(struct config_item *item,
939986
CONFIGFS_ATTR(userdatum_, value);
940987
CONFIGFS_ATTR(sysdata_, cpu_nr_enabled);
941988
CONFIGFS_ATTR(sysdata_, taskname_enabled);
989+
CONFIGFS_ATTR(sysdata_, release_enabled);
942990

943991
static struct configfs_attribute *userdatum_attrs[] = {
944992
&userdatum_attr_value,
@@ -1000,6 +1048,7 @@ static void userdatum_drop(struct config_group *group, struct config_item *item)
10001048
static struct configfs_attribute *userdata_attrs[] = {
10011049
&sysdata_attr_cpu_nr_enabled,
10021050
&sysdata_attr_taskname_enabled,
1051+
&sysdata_attr_release_enabled,
10031052
NULL,
10041053
};
10051054

0 commit comments

Comments
 (0)