Compare commits

...

3 Commits

Author SHA1 Message Date
Dana Olson 639375e0b6 ACCEL_MOUNT_MATRIX for additional Acer Spin model
This fixes the broken rotation on the Acer Spin 1 I recently bought (exact model is SP111-34N-P4BZ).
It is possible that all of the SP111 models would use the same matrix, but to be on the safe side, I added a new entry.
2020-05-24 23:27:26 +02:00
Topi Miettinen cc1c85fbc3 login: limit nr_inodes for /run/user/$UID
Limit number of inodes for tmpfs mounts on /run/user/$UID. Default is
RuntimeDirectorySize= divided by 4096.
2020-05-24 22:54:17 +02:00
Tudor Roman 6a220cdb0b home: respect user record mount flags 2020-05-24 22:48:50 +02:00
14 changed files with 55 additions and 22 deletions

View File

@ -93,6 +93,9 @@ sensor:modalias:acpi:BOSC0200*:dmi:*:svnAcer*:pnSwitchSW312-31:*
sensor:modalias:acpi:BOSC0200*:dmi:*svn*Acer*:*pn*Spin*SP111-33* sensor:modalias:acpi:BOSC0200*:dmi:*svn*Acer*:*pn*Spin*SP111-33*
ACCEL_MOUNT_MATRIX=0, 1, 0; 1, 0, 0; 0, 0, 1 ACCEL_MOUNT_MATRIX=0, 1, 0; 1, 0, 0; 0, 0, 1
sensor:modalias:acpi:BOSC0200*:dmi:*svnAcer*:*pnSpinSP111-34*
ACCEL_MOUNT_MATRIX=0, 1, 0; 1, 0, 0; 0, 0, 1
######################################### #########################################
# Archos # Archos
######################################### #########################################

View File

@ -304,6 +304,19 @@
memory as is needed.</para></listitem> memory as is needed.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><varname>RuntimeDirectoryInodesMax=</varname></term>
<listitem><para>Sets the limit on number of inodes for the
<varname>$XDG_RUNTIME_DIR</varname> runtime directory for each
user who logs in. Takes a number, optionally suffixed with the
usual K, G, M, and T suffixes, to the base 1024 (IEC).
Defaults to <varname>RuntimeDirectorySize=</varname> divided
by 4096. Note that this size is a safety limit only.
As each runtime directory is a tmpfs file system, it will
only consume as much memory as is needed.</para></listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><varname>InhibitorsMax=</varname></term> <term><varname>InhibitorsMax=</varname></term>

View File

@ -217,6 +217,8 @@ node /org/freedesktop/login1 {
@org.freedesktop.DBus.Property.EmitsChangedSignal("const") @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly t RuntimeDirectorySize = ...; readonly t RuntimeDirectorySize = ...;
@org.freedesktop.DBus.Property.EmitsChangedSignal("const") @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly t RuntimeDirectoryInodesMax = ...;
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly t InhibitorsMax = ...; readonly t InhibitorsMax = ...;
@org.freedesktop.DBus.Property.EmitsChangedSignal("false") @org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly t NCurrentInhibitors = ...; readonly t NCurrentInhibitors = ...;
@ -425,6 +427,8 @@ node /org/freedesktop/login1 {
<variablelist class="dbus-property" generated="True" extra-ref="RuntimeDirectorySize"/> <variablelist class="dbus-property" generated="True" extra-ref="RuntimeDirectorySize"/>
<variablelist class="dbus-property" generated="True" extra-ref="RuntimeDirectoryInodesMax"/>
<variablelist class="dbus-property" generated="True" extra-ref="InhibitorsMax"/> <variablelist class="dbus-property" generated="True" extra-ref="InhibitorsMax"/>
<variablelist class="dbus-property" generated="True" extra-ref="NCurrentInhibitors"/> <variablelist class="dbus-property" generated="True" extra-ref="NCurrentInhibitors"/>
@ -623,7 +627,8 @@ node /org/freedesktop/login1 {
<varname>HandleLidSwitchExternalPower</varname>, <varname>HandleLidSwitchDocked</varname>, <varname>HandleLidSwitchExternalPower</varname>, <varname>HandleLidSwitchDocked</varname>,
<varname>IdleActionUSec</varname>, <varname>HoldoffTimeoutUSec</varname>, <varname>IdleActionUSec</varname>, <varname>HoldoffTimeoutUSec</varname>,
<varname>RemoveIPC</varname>, <varname>RuntimeDirectorySize</varname>, <varname>RemoveIPC</varname>, <varname>RuntimeDirectorySize</varname>,
<varname>InhibitorsMax</varname>, and <varname>SessionsMax</varname>. <varname>RuntimeDirectoryInodesMax</varname>, <varname>InhibitorsMax</varname>, and
<varname>SessionsMax</varname>.
</para> </para>
<para>The <varname>IdleHint</varname> property reflects the idle hint state of the system. If the <para>The <varname>IdleHint</varname> property reflects the idle hint state of the system. If the

View File

@ -28,7 +28,7 @@ int home_prepare_cifs(
char **pw; char **pw;
int r; int r;
r = home_unshare_and_mount(NULL, NULL, false); r = home_unshare_and_mount(NULL, NULL, false, user_record_mount_flags(h));
if (r < 0) if (r < 0)
return r; return r;

View File

@ -1156,7 +1156,7 @@ int home_prepare_luks(
if (r < 0) if (r < 0)
goto fail; goto fail;
r = home_unshare_and_mount(setup->dm_node, fstype, user_record_luks_discard(h)); r = home_unshare_and_mount(setup->dm_node, fstype, user_record_luks_discard(h), user_record_mount_flags(h));
if (r < 0) if (r < 0)
goto fail; goto fail;
@ -2079,7 +2079,7 @@ int home_create_luks(
log_info("Formatting file system completed."); log_info("Formatting file system completed.");
r = home_unshare_and_mount(dm_node, fstype, user_record_luks_discard(h)); r = home_unshare_and_mount(dm_node, fstype, user_record_luks_discard(h), user_record_mount_flags(h));
if (r < 0) if (r < 0)
goto fail; goto fail;
@ -2284,7 +2284,7 @@ static int can_resize_fs(int fd, uint64_t old_size, uint64_t new_size) {
return CAN_RESIZE_ONLINE; return CAN_RESIZE_ONLINE;
} }
static int ext4_offline_resize_fs(HomeSetup *setup, uint64_t new_size, bool discard) { static int ext4_offline_resize_fs(HomeSetup *setup, uint64_t new_size, bool discard, unsigned long flags) {
_cleanup_free_ char *size_str = NULL; _cleanup_free_ char *size_str = NULL;
bool re_open = false, re_mount = false; bool re_open = false, re_mount = false;
pid_t resize_pid, fsck_pid; pid_t resize_pid, fsck_pid;
@ -2354,7 +2354,7 @@ static int ext4_offline_resize_fs(HomeSetup *setup, uint64_t new_size, bool disc
/* Re-establish mounts and reopen the directory */ /* Re-establish mounts and reopen the directory */
if (re_mount) { if (re_mount) {
r = home_mount_node(setup->dm_node, "ext4", discard); r = home_mount_node(setup->dm_node, "ext4", discard, flags);
if (r < 0) if (r < 0)
return r; return r;
@ -2774,7 +2774,7 @@ int home_resize_luks(
if (resize_type == CAN_RESIZE_ONLINE) if (resize_type == CAN_RESIZE_ONLINE)
r = resize_fs(setup->root_fd, new_fs_size, NULL); r = resize_fs(setup->root_fd, new_fs_size, NULL);
else else
r = ext4_offline_resize_fs(setup, new_fs_size, user_record_luks_discard(h)); r = ext4_offline_resize_fs(setup, new_fs_size, user_record_luks_discard(h), user_record_mount_flags(h));
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to resize file system: %m"); return log_error_errno(r, "Failed to resize file system: %m");

View File

@ -20,7 +20,7 @@ static const char *mount_options_for_fstype(const char *fstype) {
return NULL; return NULL;
} }
int home_mount_node(const char *node, const char *fstype, bool discard) { int home_mount_node(const char *node, const char *fstype, bool discard, unsigned long flags) {
_cleanup_free_ char *joined = NULL; _cleanup_free_ char *joined = NULL;
const char *options, *discard_option; const char *options, *discard_option;
int r; int r;
@ -38,7 +38,7 @@ int home_mount_node(const char *node, const char *fstype, bool discard) {
} else } else
options = discard_option; options = discard_option;
r = mount_verbose(LOG_ERR, node, "/run/systemd/user-home-mount", fstype, MS_NODEV|MS_NOSUID|MS_RELATIME, strempty(options)); r = mount_verbose(LOG_ERR, node, "/run/systemd/user-home-mount", fstype, flags|MS_RELATIME, strempty(options));
if (r < 0) if (r < 0)
return r; return r;
@ -46,7 +46,7 @@ int home_mount_node(const char *node, const char *fstype, bool discard) {
return 0; return 0;
} }
int home_unshare_and_mount(const char *node, const char *fstype, bool discard) { int home_unshare_and_mount(const char *node, const char *fstype, bool discard, unsigned long flags) {
int r; int r;
if (unshare(CLONE_NEWNS) < 0) if (unshare(CLONE_NEWNS) < 0)
@ -59,7 +59,7 @@ int home_unshare_and_mount(const char *node, const char *fstype, bool discard) {
(void) mkdir_p("/run/systemd/user-home-mount", 0700); (void) mkdir_p("/run/systemd/user-home-mount", 0700);
if (node) if (node)
return home_mount_node(node, fstype, discard); return home_mount_node(node, fstype, discard, flags);
return 0; return 0;
} }

View File

@ -3,6 +3,6 @@
#include <stdbool.h> #include <stdbool.h>
int home_mount_node(const char *node, const char *fstype, bool discard); int home_mount_node(const char *node, const char *fstype, bool discard, unsigned long flags);
int home_unshare_and_mount(const char *node, const char *fstype, bool discard); int home_unshare_and_mount(const char *node, const char *fstype, bool discard, unsigned long flags);
int home_move_mount(const char *user_name_and_realm, const char *target); int home_move_mount(const char *user_name_and_realm, const char *target);

View File

@ -55,6 +55,7 @@ void manager_reset_config(Manager *m) {
m->idle_action = HANDLE_IGNORE; m->idle_action = HANDLE_IGNORE;
m->runtime_dir_size = physical_memory_scale(10U, 100U); /* 10% */ m->runtime_dir_size = physical_memory_scale(10U, 100U); /* 10% */
m->runtime_dir_inodes = DIV_ROUND_UP(m->runtime_dir_size, 4096); /* 4k per inode */
m->sessions_max = 8192; m->sessions_max = 8192;
m->inhibitors_max = 8192; m->inhibitors_max = 8192;

View File

@ -3359,6 +3359,7 @@ static const sd_bus_vtable manager_vtable[] = {
SD_BUS_PROPERTY("OnExternalPower", "b", property_get_on_external_power, 0, 0), SD_BUS_PROPERTY("OnExternalPower", "b", property_get_on_external_power, 0, 0),
SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(Manager, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("RemoveIPC", "b", bus_property_get_bool, offsetof(Manager, remove_ipc), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("RuntimeDirectorySize", "t", NULL, offsetof(Manager, runtime_dir_size), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("RuntimeDirectorySize", "t", NULL, offsetof(Manager, runtime_dir_size), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("RuntimeDirectoryInodesMax", "t", NULL, offsetof(Manager, runtime_dir_inodes), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("InhibitorsMax", "t", NULL, offsetof(Manager, inhibitors_max), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("InhibitorsMax", "t", NULL, offsetof(Manager, inhibitors_max), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("NCurrentInhibitors", "t", property_get_hashmap_size, offsetof(Manager, inhibitors), 0), SD_BUS_PROPERTY("NCurrentInhibitors", "t", property_get_hashmap_size, offsetof(Manager, inhibitors), 0),
SD_BUS_PROPERTY("SessionsMax", "t", NULL, offsetof(Manager, sessions_max), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("SessionsMax", "t", NULL, offsetof(Manager, sessions_max), SD_BUS_VTABLE_PROPERTY_CONST),

View File

@ -38,6 +38,7 @@ Login.HoldoffTimeoutSec, config_parse_sec, 0, offse
Login.IdleAction, config_parse_handle_action, 0, offsetof(Manager, idle_action) Login.IdleAction, config_parse_handle_action, 0, offsetof(Manager, idle_action)
Login.IdleActionSec, config_parse_sec, 0, offsetof(Manager, idle_action_usec) Login.IdleActionSec, config_parse_sec, 0, offsetof(Manager, idle_action_usec)
Login.RuntimeDirectorySize, config_parse_tmpfs_size, 0, offsetof(Manager, runtime_dir_size) Login.RuntimeDirectorySize, config_parse_tmpfs_size, 0, offsetof(Manager, runtime_dir_size)
Login.RuntimeDirectoryInodesMax, config_parse_uint64, 0, offsetof(Manager, runtime_dir_inodes)
Login.RemoveIPC, config_parse_bool, 0, offsetof(Manager, remove_ipc) Login.RemoveIPC, config_parse_bool, 0, offsetof(Manager, remove_ipc)
Login.InhibitorsMax, config_parse_uint64, 0, offsetof(Manager, inhibitors_max) Login.InhibitorsMax, config_parse_uint64, 0, offsetof(Manager, inhibitors_max)
Login.SessionsMax, config_parse_uint64, 0, offsetof(Manager, sessions_max) Login.SessionsMax, config_parse_uint64, 0, offsetof(Manager, sessions_max)

View File

@ -32,6 +32,7 @@
#IdleAction=ignore #IdleAction=ignore
#IdleActionSec=30min #IdleActionSec=30min
#RuntimeDirectorySize=10% #RuntimeDirectorySize=10%
#RuntimeDirectoryInodes=400k
#RemoveIPC=yes #RemoveIPC=yes
#InhibitorsMax=8192 #InhibitorsMax=8192
#SessionsMax=8192 #SessionsMax=8192

View File

@ -120,6 +120,7 @@ struct Manager {
sd_event_source *lid_switch_ignore_event_source; sd_event_source *lid_switch_ignore_event_source;
uint64_t runtime_dir_size; uint64_t runtime_dir_size;
uint64_t runtime_dir_inodes;
uint64_t sessions_max; uint64_t sessions_max;
uint64_t inhibitors_max; uint64_t inhibitors_max;
}; };

View File

@ -22,7 +22,7 @@
#include "strv.h" #include "strv.h"
#include "user-util.h" #include "user-util.h"
static int acquire_runtime_dir_size(uint64_t *ret) { static int acquire_runtime_dir_properties(uint64_t *size, uint64_t *inodes) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r; int r;
@ -31,10 +31,14 @@ static int acquire_runtime_dir_size(uint64_t *ret) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to connect to system bus: %m"); return log_error_errno(r, "Failed to connect to system bus: %m");
r = sd_bus_get_property_trivial(bus, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "RuntimeDirectorySize", &error, 't', ret); r = sd_bus_get_property_trivial(bus, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "RuntimeDirectorySize", &error, 't', size);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to acquire runtime directory size: %s", bus_error_message(&error, r)); return log_error_errno(r, "Failed to acquire runtime directory size: %s", bus_error_message(&error, r));
r = sd_bus_get_property_trivial(bus, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "RuntimeDirectoryInodesMax", &error, 't', inodes);
if (r < 0)
return log_error_errno(r, "Failed to acquire number of inodes for runtime directory: %s", bus_error_message(&error, r));
return 0; return 0;
} }
@ -42,7 +46,8 @@ static int user_mkdir_runtime_path(
const char *runtime_path, const char *runtime_path,
uid_t uid, uid_t uid,
gid_t gid, gid_t gid,
uint64_t runtime_dir_size) { uint64_t runtime_dir_size,
uint64_t runtime_dir_inodes) {
int r; int r;
@ -58,14 +63,15 @@ static int user_mkdir_runtime_path(
if (path_is_mount_point(runtime_path, NULL, 0) >= 0) if (path_is_mount_point(runtime_path, NULL, 0) >= 0)
log_debug("%s is already a mount point", runtime_path); log_debug("%s is already a mount point", runtime_path);
else { else {
char options[sizeof("mode=0700,uid=,gid=,size=,smackfsroot=*") char options[sizeof("mode=0700,uid=,gid=,size=,nr_inodes=,smackfsroot=*")
+ DECIMAL_STR_MAX(uid_t) + DECIMAL_STR_MAX(uid_t)
+ DECIMAL_STR_MAX(gid_t) + DECIMAL_STR_MAX(gid_t)
+ DECIMAL_STR_MAX(uint64_t)
+ DECIMAL_STR_MAX(uint64_t)]; + DECIMAL_STR_MAX(uint64_t)];
xsprintf(options, xsprintf(options,
"mode=0700,uid=" UID_FMT ",gid=" GID_FMT ",size=%" PRIu64 "%s", "mode=0700,uid=" UID_FMT ",gid=" GID_FMT ",size=%" PRIu64 ",nr_inodes=%" PRIu64 "%s",
uid, gid, runtime_dir_size, uid, gid, runtime_dir_size, runtime_dir_inodes,
mac_smack_use() ? ",smackfsroot=*" : ""); mac_smack_use() ? ",smackfsroot=*" : "");
(void) mkdir_label(runtime_path, 0700); (void) mkdir_label(runtime_path, 0700);
@ -127,7 +133,7 @@ static int user_remove_runtime_path(const char *runtime_path) {
static int do_mount(const char *user) { static int do_mount(const char *user) {
char runtime_path[sizeof("/run/user") + DECIMAL_STR_MAX(uid_t)]; char runtime_path[sizeof("/run/user") + DECIMAL_STR_MAX(uid_t)];
uint64_t runtime_dir_size; uint64_t runtime_dir_size, runtime_dir_inodes;
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
int r; int r;
@ -140,14 +146,14 @@ static int do_mount(const char *user) {
: "Failed to look up user \"%s\": %m", : "Failed to look up user \"%s\": %m",
user); user);
r = acquire_runtime_dir_size(&runtime_dir_size); r = acquire_runtime_dir_properties(&runtime_dir_size, &runtime_dir_inodes);
if (r < 0) if (r < 0)
return r; return r;
xsprintf(runtime_path, "/run/user/" UID_FMT, uid); xsprintf(runtime_path, "/run/user/" UID_FMT, uid);
log_debug("Will mount %s owned by "UID_FMT":"GID_FMT, runtime_path, uid, gid); log_debug("Will mount %s owned by "UID_FMT":"GID_FMT, runtime_path, uid, gid);
return user_mkdir_runtime_path(runtime_path, uid, gid, runtime_dir_size); return user_mkdir_runtime_path(runtime_path, uid, gid, runtime_dir_size, runtime_dir_inodes);
} }
static int do_umount(const char *user) { static int do_umount(const char *user) {

View File

@ -865,6 +865,7 @@ RestrictNamespaces=
RestrictRealtime= RestrictRealtime=
RestrictSUIDSGID= RestrictSUIDSGID=
RuntimeDirectory= RuntimeDirectory=
RuntimeDirectoryInodesMax=
RuntimeDirectoryMode= RuntimeDirectoryMode=
RuntimeDirectoryPreserve= RuntimeDirectoryPreserve=
RuntimeDirectorySize= RuntimeDirectorySize=