From c4a076d2c0508cf30f242462decb342d58f88058 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Wed, 13 Dec 2017 00:12:56 -0600 Subject: [PATCH] Clean-up old systemd prep and allow machinctl to grow This is a backport of: - https://review.openstack.org/527592 - https://review.openstack.org/545801 The machinectl cache is currently set image to 16G by default. If multiple container images are imported into the cache this may be too small by default. This change sets the cache to "64G" by default allowing the cache more room to grow by. This change also disables the quota system once the limit has been set The option `lxc_host_machine_quota_disabled` has been added to disable or enable the quota system as needed. This is done after the default limit has been set so an adequately sized sparce file can be created should it not already exist. > More documentation can be seen here [0] with regard to the set-limit option. Because we support both modern and older systemd, the cache prep tasks for old systemd have been updated so that deployers using earlier versions of systemd can benefit from the ability to grow an existing cache via playbook run. [0] https://www.freedesktop.org/software/systemd/man/machinectl.html#set-limit%20%5BNAME%5D%20BYTES Closes-Bug: #1745361 Change-Id: I85fefc6ce186bb6808ac37a9ea79a50e29671115 Signed-off-by: Kevin Carter --- defaults/main.yml | 8 +- handlers/main.yml | 7 + .../set-limit-disabled-25998f1f12987c12.yaml | 20 +++ tasks/lxc_cache_preparation_systemd_new.yml | 23 ++- tasks/lxc_cache_preparation_systemd_old.yml | 156 +++++++++--------- 5 files changed, 126 insertions(+), 88 deletions(-) create mode 100644 releasenotes/notes/set-limit-disabled-25998f1f12987c12.yaml diff --git a/defaults/main.yml b/defaults/main.yml index 95b41aa6..6e34a68f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -28,8 +28,12 @@ lxc_architecture_mapping: s390x: s390x armv7l: armhf -# Set the volume size in gigabytes for the machine image caches. -lxc_host_machine_volume_size: 16 +# Set the volume size for the machine image caches. +# NOTE: Size is set in Gigabytes. +lxc_host_machine_volume_size: "64" + +# Disable the machinctl quota system. +lxc_host_machine_quota_disabled: true # DefaultTasksMax systemd value. It's not recommended to change this value as it # could prevent new processes from starting on busy containers. diff --git a/handlers/main.yml b/handlers/main.yml index 44dedbaf..018bb275 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -37,6 +37,13 @@ name: "systemd-machined.service" state: "restarted" +- name: Start machines mount + systemd: + daemon_reload: yes + name: "var-lib-machines.mount" + enabled: "yes" + state: "started" + - name: Restart irqbalance service: name: "irqbalance" diff --git a/releasenotes/notes/set-limit-disabled-25998f1f12987c12.yaml b/releasenotes/notes/set-limit-disabled-25998f1f12987c12.yaml new file mode 100644 index 00000000..d9d7b862 --- /dev/null +++ b/releasenotes/notes/set-limit-disabled-25998f1f12987c12.yaml @@ -0,0 +1,20 @@ +--- +upgrade: + - The variable ``lxc_host_machine_volume_size`` now accepts any valid size + modifier acceptable by ``truncate -s`` and ``machinectl set-limit``. + prior to this change the option assumed an integer was set for some value + in gigabytes. All acceptable values can be seen within the + `documentation for machinectl `_ +features: + - An option to disable the ``machinectl`` quota system has been added. The + variable ``lxc_host_machine_quota_disabled`` is a Boolean with a default of + **true**. When this option is set to **true** it will disable the + ``machinectl`` quota system. +other: + - The variable ``lxc_host_machine_volume_size`` is used to set the size of + the default sparse file as well as define a limit within the ``machinectl`` + quota system. When the ``machinectl`` quota system is enabled deployers + should appropriately set this value to the size of the container volume, + even when not using a sparse file. + - The container image cache within machinectl has been set to "64G" by + default. diff --git a/tasks/lxc_cache_preparation_systemd_new.yml b/tasks/lxc_cache_preparation_systemd_new.yml index 874d0fa1..385152ea 100644 --- a/tasks/lxc_cache_preparation_systemd_new.yml +++ b/tasks/lxc_cache_preparation_systemd_new.yml @@ -15,6 +15,21 @@ # NOTE(cloudnull): When modern SystemD is running everywhere this can be # collapsed back into the base preparation task file. +# NOTE(odyssey4me): +# The size is forced to be set in Gigabytes to maintain compatibility +# with the initial implementation done in Pike-Rocky. Do not change +# this without implementing some way of converting any pre-existing +# value properly during a major upgrade. +- name: Set volume size + shell: machinectl set-limit {{ lxc_host_machine_volume_size | regex_replace('\D*$', '') }}G + changed_when: false + args: + executable: /bin/bash + +- name: Disable the machinectl quota system + command: "btrfs quota {{ lxc_host_machine_quota_disabled | bool | ternary('disable', 'enable') }} /var/lib/machines" + changed_when: false + - name: Remove old image cache command: "machinectl remove {{ lxc_container_base_name }}" register: cache_refresh @@ -23,14 +38,6 @@ when: - lxc_image_cache_refresh | bool -# NOTE(cloudnull): When modern SystemD is running everywhere this can be -# collapsed back into the base preparation task file. -- name: Set volume size - shell: machinectl set-limit {{ lxc_host_machine_volume_size }}G - changed_when: false - args: - executable: /bin/bash - - name: Ensure image has been pre-staged async_status: jid: "{{ prestage_image.ansible_job_id }}" diff --git a/tasks/lxc_cache_preparation_systemd_old.yml b/tasks/lxc_cache_preparation_systemd_old.yml index eb532695..1c937619 100644 --- a/tasks/lxc_cache_preparation_systemd_old.yml +++ b/tasks/lxc_cache_preparation_systemd_old.yml @@ -13,98 +13,98 @@ # See the License for the specific language governing permissions and # limitations under the License. - # NOTE(cloudnull): This is only used when running SystemD <= 219 # ============================================================== # In later versions of SystemD this is automatically done for us -# by the machinectl cli on first run. -- name: Create volume +# by the machinectl cli on first run. To ensure we're handling the +# case of a mount point being just offline, we first try and start +# the systemd mount unit and then check for the mount points existance. +- name: Check machinectl mount point shell: | - if [[ "$(ls -lh /var/lib/machines.raw | awk '{print $5}')" != "{{ lxc_host_machine_volume_size }}.0G" ]]; then - if [[ ! -f "/var/lib/machines.raw" ]]; then - truncate -s {{ lxc_host_machine_volume_size }}G /var/lib/machines.raw - exit 3 - fi - fi - register: machines_create - changed_when: machines_create.rc == 3 - failed_when: machines_create.rc not in [0, 3] - args: - executable: /bin/bash - when: - - lxc_image_cache_refresh | bool + mount -a || true + systemctl start var-lib-machines.mount || true + sleep 1 + grep -w '/var/lib/machines' /proc/mounts + failed_when: false + changed_when: false + register: machinectl_mount + tags: + - skip_ansible_lint -# In later versions of SystemD this is automatically done for us -# by the machinectl cli on first run. -- name: Format the machines file - filesystem: - fstype: btrfs - dev: /var/lib/machines.raw - when: - - machines_create | changed +# NOTE(odyssey4me): +# The size is forced to be set in Gigabytes to maintain compatibility +# with the initial implementation done in Pike-Rocky. Do not change +# this without implementing some way of converting any pre-existing +# value properly during a major upgrade. +- name: Create systemd sparse file + shell: | + truncate -s '>{{ lxc_host_machine_volume_size | regex_replace("\D*$", "") }}G' /var/lib/machines.raw -# In later versions of SystemD this is automatically done for us -# by the machinectl cli on first run. -- name: Create machines mount point - file: - path: "/var/lib/machines" - state: "directory" - recurse: true +- name: Old systemd machinectl mount + block: + # In later versions of SystemD this is automatically done for us + # by the machinectl cli on first run. + - name: Format the machines sparse file + filesystem: + fstype: btrfs + dev: /var/lib/machines.raw -# In later versions of SystemD this unit file has been corrected -# and is packaged with systemd proper. -- name: Move machines mount into place - copy: - src: var-lib-machines.mount - dest: /etc/systemd/system/var-lib-machines.mount - register: mount_unit - notify: - - Reload systemd units - when: - - machines_create | changed + # In later versions of SystemD this is automatically done for us + # by the machinectl cli on first run. + - name: Create machines mount point + file: + path: "/var/lib/machines" + state: "directory" -# In later versions of SystemD this is not needed. Referenced in -# the following ML post resolves the bug. -# * https://lists.freedesktop.org/archives/systemd-devel/2015-March/029151.html -- name: Move machined service into place - template: - src: systemd-machined.service.j2 - dest: /etc/systemd/system/systemd-machined.service - register: machined_unit - notify: - - Reload systemd units - - Restart machined - when: - - machines_create | changed + # In later versions of SystemD this unit file has been corrected + # and is packaged with systemd proper. + - name: Move machines mount into place + copy: + src: var-lib-machines.mount + dest: /etc/systemd/system/var-lib-machines.mount + register: mount_unit + notify: + - Start machines mount -# In later versions of SystemD this is not needed. Referenced in -# the following commit resolves the bug. -# * https://cgit.freedesktop.org/systemd/systemd/commit/src/machine/org.freedesktop.machine1.conf?id=72c3897f77a7352618ea76b880a6764f52d6327b -- name: Move machine1 dbus config into place - copy: - src: org.freedesktop.machine1.conf - dest: /etc/dbus-1/system.d/org.freedesktop.machine1.conf - register: machine1_conf - notify: - - Reload systemd units - - Restart dbus + # In later versions of SystemD this is not needed. Referenced in + # the following ML post resolves the bug. + # * https://lists.freedesktop.org/archives/systemd-devel/2015-March/029151.html + - name: Move machined service into place + template: + src: systemd-machined.service.j2 + dest: /etc/systemd/system/systemd-machined.service + register: machined_unit + notify: + - Reload systemd units + - Restart machined + + # In later versions of SystemD this is not needed. Referenced in + # the following commit resolves the bug. + # * https://cgit.freedesktop.org/systemd/systemd/commit/src/machine/org.freedesktop.machine1.conf?id=72c3897f77a7352618ea76b880a6764f52d6327b + - name: Move machine1 dbus config into place + copy: + src: org.freedesktop.machine1.conf + dest: /etc/dbus-1/system.d/org.freedesktop.machine1.conf + register: machine1_conf + notify: + - Reload systemd units + - Restart dbus when: - - machines_create | changed + - machinectl_mount.rc != 0 # Ensure lxc networks are running as they're supposed to - meta: flush_handlers -# Ignore the Ansible warning here about using 'mount' via the shell module -# instead of using the mount Ansible module. -- name: Mount all - shell: "mount | grep '/var/lib/machines' || (systemctl start var-lib-machines.mount && exit 3)" - args: - warn: no - register: mount_machines - changed_when: mount_machines.rc == 3 - failed_when: mount_machines.rc not in [0, 3] - tags: - - skip_ansible_lint +# NOTE(cloudnull): Because the machines mount may be a manually created sparse +# file we run an online resize to ensure the machines mount is +# the size we expect. +- name: Ensure the machines fs is sized correctly + command: "btrfs filesystem resize max /var/lib/machines" + changed_when: false + +- name: Disable the machinectl quota system + command: "btrfs quota {{ lxc_host_machine_quota_disabled | bool | ternary('disable', 'enable') }} /var/lib/machines" + changed_when: false # Because of this post and it's related bug(s) this is adding the container # volumes the old way. The new way would simply be calling `machinectl`.