diff --git a/sysutils/azure-agent/Makefile b/sysutils/azure-agent/Makefile index 0b895a31742b..6d8c48229ace 100644 --- a/sysutils/azure-agent/Makefile +++ b/sysutils/azure-agent/Makefile @@ -1,60 +1,58 @@ PORTNAME= azure-agent -PORTVERSION= 2.2.45 +PORTVERSION= 2.2.54.2 DISTVERSIONPREFIX= v -PORTREVISION= 2 CATEGORIES= sysutils PATCH_SITES= https://github.com/Azure/WALinuxAgent/commit/ MAINTAINER= weh@microsoft.com COMMENT= Microsoft Azure Linux Agent LICENSE= APACHE20 RUN_DEPENDS= sudo:security/sudo \ bash:shells/bash \ - base64:converters/base64 \ dmidecode:sysutils/dmidecode \ ${PYTHON_PKGNAMEPREFIX}pyasn1>=0:devel/py-pyasn1@${PY_FLAVOR} \ - ${LOCALBASE}/share/certs/ca-root-nss.crt:security/ca_root_nss + ca_root_nss>0:security/ca_root_nss NO_BUILD= yes -USES= python:3.5+ shebangfix +USES= python shebangfix SHEBANG_FILES= bin/waagent bin/waagent2.0 USE_GITHUB= yes GH_ACCOUNT= Azure GH_PROJECT= WALinuxAgent USE_PYTHON= autoplist distutils noflavors post-patch: ${REINPLACE_CMD} -e "s,/etc/waagent,${PREFIX}/etc/waagent,g" \ ${WRKSRC}/azurelinuxagent/common/osutil/default.py ${REINPLACE_CMD} -e "s,/etc/rc.d/waagent,${PREFIX}/etc/rc.d/waagent,g" \ -e "s,/etc/waagent,${PREFIX}/etc/waagent,g" \ -e "s,#!/usr/bin/env python,#!${PYTHON_CMD},g" \ -e "/command_interpreter/ s,/usr/local/bin/python,${PYTHON_CMD}," \ -e "s,/usr/sbin/waagent,${PREFIX}/sbin/waagent,g" \ ${WRKSRC}/bin/waagent2.0 ${REINPLACE_CMD} -e "s,:/usr/local/bin,:/usr/local/bin:/usr/local/sbin,g" \ - -e "s,python,${PYTHON_VERSION},g" \ + -e "s,python,${PYTHON_CMD},g" \ ${WRKSRC}/init/freebsd/waagent ${REINPLACE_CMD} -e "s,/usr/sbin,${PREFIX}/sbin,g" \ ${WRKSRC}/init/waagent ${REINPLACE_CMD} -e "s,/etc/waagent,${PREFIX}/etc/waagent,g" \ -e "s,/usr/bin/python,${PYTHON_CMD},g" \ -e "s,/usr/sbin,${PREFIX}/sbin,g" \ ${WRKSRC}/init/waagent.service ${REINPLACE_CMD} -e "s,/etc,${PREFIX}/etc,g" \ -e "/set_conf_files.*freebsd\/waagent.conf/ s/^/#/" \ -e "s,/usr/sbin,${PREFIX}/sbin,g" \ ${WRKSRC}/setup.py post-install: ${MKDIR} ${STAGEDIR}${PREFIX}/etc ${INSTALL_DATA} ${WRKSRC}/config/freebsd/waagent.conf \ ${STAGEDIR}${PREFIX}/etc/waagent.conf.sample .include diff --git a/sysutils/azure-agent/distinfo b/sysutils/azure-agent/distinfo index ace22c2cc6de..686bcb239916 100644 --- a/sysutils/azure-agent/distinfo +++ b/sysutils/azure-agent/distinfo @@ -1,3 +1,3 @@ -TIMESTAMP = 1590110519 -SHA256 (Azure-WALinuxAgent-v2.2.45_GH0.tar.gz) = ded5ecf2ce17b3e375147a386ba13554b52098475dc06974e9780cc04ca893ee -SIZE (Azure-WALinuxAgent-v2.2.45_GH0.tar.gz) = 937466 +TIMESTAMP = 1621586743 +SHA256 (Azure-WALinuxAgent-v2.2.54.2_GH0.tar.gz) = 2c047d262ca55718268a0921c7bd04b6c1ab1032bd885e3e0949107f493e7b7c +SIZE (Azure-WALinuxAgent-v2.2.54.2_GH0.tar.gz) = 1814212 diff --git a/sysutils/azure-agent/files/patch-azurelinuxagent_daemon_resourcedisk_freebsd.py b/sysutils/azure-agent/files/patch-azurelinuxagent_daemon_resourcedisk_freebsd.py index 9d8853e89142..347ba8ab5641 100644 --- a/sysutils/azure-agent/files/patch-azurelinuxagent_daemon_resourcedisk_freebsd.py +++ b/sysutils/azure-agent/files/patch-azurelinuxagent_daemon_resourcedisk_freebsd.py @@ -1,332 +1,341 @@ ---- azurelinuxagent/daemon/resourcedisk/freebsd.py.orig 2020-05-22 12:55:32 UTC +--- azurelinuxagent/daemon/resourcedisk/freebsd.py.orig 2021-05-18 18:30:52 UTC +++ azurelinuxagent/daemon/resourcedisk/freebsd.py @@ -1,6 +1,7 @@ # Microsoft Azure Linux Agent # # Copyright 2018 Microsoft Corporation -+# Copyright 2020 The FreeBSD Foundation ++# Copyright 2020-2021 The FreeBSD Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,6 +25,8 @@ import azurelinuxagent.common.conf as conf from azurelinuxagent.common.exception import ResourceDiskError from azurelinuxagent.daemon.resourcedisk.default import ResourceDiskHandler +# Keeping 1GB sapce if configured swap size is larger than the disk size +MINIMAL_RESOURCE_PARTITION_SIZE = 1024 ** 3 class FreeBSDResourceDiskHandler(ResourceDiskHandler): """ @@ -32,37 +35,45 @@ class FreeBSDResourceDiskHandler(ResourceDiskHandler): The resource disk locates at following slot: scbus2 on blkvsc1 bus 0: at scbus2 target 1 lun 0 (da1,pass2) - - There are 2 variations based on partition table type: - 1. MBR: The resource disk partition is /dev/da1s1 - 2. GPT: The resource disk partition is /dev/da1p2, /dev/da1p1 is for reserved usage. """ - def __init__(self): + def __init__(self): # pylint: disable=W0235 super(FreeBSDResourceDiskHandler, self).__init__() @staticmethod - def parse_gpart_list(data): + def parse_gpart_show(data): dic = {} for line in data.split('\n'): - if line.find("Geom name: ") != -1: - geom_name = line[11:] - elif line.find("scheme: ") != -1: - dic[geom_name] = line[8:] + if line: + l = line.split() + dic[l[3]] = l[4] return dic + @staticmethod + def parse_mount_list(data): + dic = {} + for line in data.split('\n'): + if line: + l = line.split() + dic[l[2]] = l[0] + return dic + + @staticmethod + def get_next_partition(x): + return x[:-1] + str(int(x[-1]) + 1) + def mount_resource_disk(self, mount_point): fs = self.fs if fs != 'ufs': - raise ResourceDiskError( - "Unsupported filesystem type:{0}, only ufs is supported.".format(fs)) + raise ResourceDiskError("Unsupported filesystem type: " + "{0}, only ufs is supported.".format(fs)) # 1. Detect device - err, output = shellutil.run_get_output('gpart list') + err, output = shellutil.run_get_output("gpart show | grep '=>'") if err: raise ResourceDiskError( "Unable to detect resource disk device:{0}".format(output)) - disks = self.parse_gpart_list(output) + disks = self.parse_gpart_show(output) device = self.osutil.device_for_ide_port(1) if device is None or device not in disks: -@@ -90,94 +101,186 @@ class FreeBSDResourceDiskHandler(ResourceDiskHandler): +@@ -90,94 +101,195 @@ class FreeBSDResourceDiskHandler(ResourceDiskHandler): raise ResourceDiskError("Unable to detect resource disk device.") logger.info('Resource disk device {0} found.', device) - # 2. Detect partition - partition_table_type = disks[device] + # 2. Detect/create partition - if partition_table_type == 'MBR': - provider_name = device + 's1' - elif partition_table_type == 'GPT': - provider_name = device + 'p2' - else: - raise ResourceDiskError( - "Unsupported partition table type:{0}".format(output)) + # count the target size of each partition + err, output = shellutil.run_get_output("diskinfo {0}".format(device)) + if err: + raise ResourceDiskError("Cannot get resource disk size.") + disk_info = output.split() + block_size = int(disk_info[1]) -+ disk_size = int(disk_info[2]) ++ err, output = shellutil.run_get_output("gpart show {0} | grep '=>'".format(device)) ++ if err: ++ raise ResourceDiskError("Cannot get resource disk partition information.") ++ disk_info = output.split() ++ partition_size = int(disk_info[2]) * block_size ++ + swap_size = 0 + if conf.get_resourcedisk_enable_swap(): + swap_size_mb = conf.get_resourcedisk_swap_size_mb() + swap_size = swap_size_mb * 1024 * 1024 -+ resource_size = disk_size - swap_size ++ resource_size = partition_size - swap_size + if resource_size < MINIMAL_RESOURCE_PARTITION_SIZE: + resource_size = MINIMAL_RESOURCE_PARTITION_SIZE -+ swap_size = disk_size - resource_size ++ swap_size = partition_size - resource_size + + # get size of the current swap partition + current_swap_size = 0 err, output = shellutil.run_get_output( - 'gpart show -p {0}'.format(device)) - if err or output.find(provider_name) == -1: - raise ResourceDiskError("Resource disk partition not found.") + "gpart show {0} 2>/dev/null | grep freebsd-swap".format(device), + chk_err=False) + if output: + current_swap_size = int(output.split()[1]) * block_size - partition = '/dev/' + provider_name - logger.info('Resource disk partition {0} found.', partition) + partition_table_type = disks.get(device) - # 3. Mount partition - mount_list = shellutil.run_get_output("mount")[1] - existing = self.osutil.get_mount_point(mount_list, partition) + resource_provider_name = device + 'p1' + swap_provider_name = device + 'p2' + # re-partition if needed + if partition_table_type != 'GPT' or current_swap_size != swap_size: + # unmount and swapoff if needed + mount_list = shellutil.run_get_output("mount")[1] + existing = self.osutil.get_mount_point(mount_list, + resource_provider_name) + if existing: + err, output = shellutil.run_get_output( + "umount {0}".format(mount_point), chk_err=False) + + swap_info = shellutil.run_get_output("swapctl -l")[1].split('\n') + swap_device = None + if len(swap_info) > 2: + swap_device = swap_info[1].split()[0] + if swap_device: + err, output = shellutil.run_get_output( + "swapoff {0}".format(swap_device), chk_err=False) + if swap_device.endswith('.eli'): + err, output = shellutil.run_get_output( + "geli detach {0}".format(swap_device), chk_err=False) + + if partition_table_type is not None: + gaprt_destroy_cmd = "gpart destroy -F {0}".format(device) + err, output = shellutil.run_get_output(gaprt_destroy_cmd, + chk_err=False) + if err: + raise ResourceDiskError("Failed to destroy the " + "partitioning scheme on {0}, " + "error: {1}".format(device, output)) + gaprt_create_cmd = "gpart create -s GPT {0}".format(device) + err, output = shellutil.run_get_output(gaprt_create_cmd, + chk_err=False) + if err: + raise ResourceDiskError("Failed to create new GPT on {0}, " + "error: {1}".format(device, output)) + + mount_list = shellutil.run_get_output("mount")[1] + existing = self.osutil.get_mount_point(mount_list, + resource_provider_name) if existing: - logger.info("Resource disk {0} is already mounted", partition) + logger.info("Resource disk {0} is already mounted".format( + resource_provider_name)) return existing + # create resource partition + if not os.path.exists("/dev/{0}".format(resource_provider_name)): + if swap_size > 0: + err, output = shellutil.run_get_output( + 'gpart add -t freebsd-ufs -s {0}b {1}'.format(resource_size, + device)) + else: + err, output = shellutil.run_get_output( + 'gpart add -t freebsd-ufs {0}'.format(device)) + if err: + raise ResourceDiskError( + "Failed to add new freebsd-ufs partition to {0}, " + "error: {1}" .format(device, output)) + + # create swap partition, just use all the space left + if swap_size > 0: + err, output = shellutil.run_get_output( + 'gpart add -t freebsd-swap {0}'.format(device)) + if err: + raise ResourceDiskError( + "Failed to add new freebsd-swap partition to {0}, " + "error: {1}" .format(device, output)) + + # 3. Mount partition fileutil.mkdir(mount_point, mode=0o755) - mount_cmd = 'mount -t {0} {1} {2}'.format(fs, partition, mount_point) - err = shellutil.run(mount_cmd, chk_err=False) - if err: - logger.info( - 'Creating {0} filesystem on partition {1}'.format( - fs, partition)) + + need_newfs = True + if current_swap_size == swap_size: + # swap size is not adjusted, + # i.e., the resource partition is not changed + # check if a fs already exists + fstyp_cmd = 'fstyp /dev/{0}'.format(resource_provider_name) + err, output = shellutil.run_get_output(fstyp_cmd, chk_err=False) + if not err and output == fs: + need_newfs = False + logger.info( + "Resource disk partition {0} is found at {1} " + "with fstype {2}".format( + resource_provider_name, mount_point, fs)) + elif swap_size < current_swap_size: + # resource partition size is increased, try to growfs first err, output = shellutil.run_get_output( - 'newfs -U {0}'.format(partition)) + 'growfs -y {0}'.format(resource_provider_name), chk_err=False) + if not err: + need_newfs = False + logger.info( + "Resource disk partition {0} is found and enlarged at {1} " + "with fstype {2}".format( + resource_provider_name, mount_point, fs)) + # else + # resource partition is shrunk and newfs is needed + + if need_newfs: + logger.info('Creating {0} filesystem on partition {1}'.format( + fs, resource_provider_name)) + err, output = shellutil.run_get_output( + 'newfs -U {0}'.format(resource_provider_name)) if err: raise ResourceDiskError( - "Failed to create new filesystem on partition {0}, error:{1}" .format( - partition, output)) - err, output = shellutil.run_get_output(mount_cmd, chk_err=False) - if err: - raise ResourceDiskError( - "Failed to mount partition {0}, error {1}".format( - partition, output)) + "Failed to create new filesystem on partition {0}, " + "error: {1}" .format(resource_provider_name, output)) + mount_cmd = 'mount -t {0} /dev/{1} {2}'.format( + fs, resource_provider_name, mount_point) + err, output = shellutil.run_get_output(mount_cmd, chk_err=False) + if err: + raise ResourceDiskError( + "Failed to mount partition {0}, error {1}".format( + resource_provider_name, output)) + logger.info( - "Resource disk partition {0} is mounted at {1} with fstype {2}", - partition, - mount_point, - fs) + "Resource disk partition {0} is mounted at {1} " + "with fstype {2}".format( + resource_provider_name, mount_point, fs)) return mount_point def create_swap_space(self, mount_point, size_mb): - size_kb = size_mb * 1024 - size = size_kb * 1024 - swapfile = os.path.join(mount_point, 'swapfile') - swaplist = shellutil.run_get_output("swapctl -l")[1] + # done in mount_resource_disk() + pass - if self.check_existing_swap_file(swapfile, swaplist, size): + def enable_swap(self, mount_point): + if conf.get_resourcedisk_swap_size_mb() <=0: return - if os.path.isfile(swapfile) and os.path.getsize(swapfile) != size: - logger.info("Remove old swap file") -- shellutil.run("swapoff -a", chk_err=False) +- shellutil.run("swapoff {0}".format(swapfile), chk_err=False) - os.remove(swapfile) + # get swap partition (geom provider) + err, output = shellutil.run_get_output('mount') + if err: + raise ResourceDiskError("Unable to get mount information.") + devices = self.parse_mount_list(output) + resource_provider_name = devices[mount_point] + swap_provider_name = self.get_next_partition(resource_provider_name) - if not os.path.isfile(swapfile): - logger.info("Create swap file") - self.mkfile(swapfile, size_kb * 1024) + if conf.get_resourcedisk_enable_swap_encryption(): + shellutil.run("kldload -n aesni") + shellutil.run("kldload -n cryptodev") + shellutil.run("kldload -n geom_eli") + shellutil.run("geli onetime -e AES-XTS -l 256" + " -d {0}".format(swap_provider_name)) + swap_provider_name += ".eli" + shellutil.run("chmod 0600 {0}".format(swap_provider_name)) - mddevice = shellutil.run_get_output( - "mdconfig -a -t vnode -f {0}".format(swapfile))[1].rstrip() - shellutil.run("chmod 0600 /dev/{0}".format(mddevice)) -+ if shellutil.run("swapon {0}".format(swap_provider_name)): -+ raise ResourceDiskError(swap_provider_name) ++ err, output = shellutil.run_get_output( ++ "swapctl -l | grep {0}".format(swap_provider_name)) ++ if not output: ++ if shellutil.run("swapon {0}".format(swap_provider_name)): ++ raise ResourceDiskError(swap_provider_name) - if conf.get_resourcedisk_enable_swap_encryption(): - shellutil.run("kldload aesni") - shellutil.run("kldload cryptodev") - shellutil.run("kldload geom_eli") - shellutil.run( - "geli onetime -e AES-XTS -l 256 -d /dev/{0}".format(mddevice)) - shellutil.run("chmod 0600 /dev/{0}.eli".format(mddevice)) - if shellutil.run("swapon /dev/{0}.eli".format(mddevice)): - raise ResourceDiskError("/dev/{0}.eli".format(mddevice)) - logger.info( - "Enabled {0}KB of swap at /dev/{1}.eli ({2})".format(size_kb, mddevice, swapfile)) - else: - if shellutil.run("swapon /dev/{0}".format(mddevice)): - raise ResourceDiskError("/dev/{0}".format(mddevice)) - logger.info( - "Enabled {0}KB of swap at /dev/{1} ({2})".format(size_kb, mddevice, swapfile)) -+ size_mb = shellutil.run_get_output("swapctl -lm")[1].split()[1] ++ size_mb = shellutil.run_get_output( ++ "swapctl -lm | grep {0}".format(swap_provider_name))[1].split()[1] + logger.info( + "Enabled {0}MB of swap at {1}".format(size_mb, swap_provider_name)) diff --git a/sysutils/azure-agent/files/patch-config_freebsd_waagent.conf b/sysutils/azure-agent/files/patch-config_freebsd_waagent.conf index 95dd7a1d0379..9dd22728d4b4 100644 --- a/sysutils/azure-agent/files/patch-config_freebsd_waagent.conf +++ b/sysutils/azure-agent/files/patch-config_freebsd_waagent.conf @@ -1,15 +1,11 @@ ---- config/freebsd/waagent.conf.orig 2020-05-22 16:31:32 UTC +--- config/freebsd/waagent.conf.orig 2021-05-21 08:58:28 UTC +++ config/freebsd/waagent.conf -@@ -48,10 +48,10 @@ ResourceDisk.Filesystem=ufs - ResourceDisk.MountPoint=/mnt/resource - - # Create and use swapfile on resource disk. --ResourceDisk.EnableSwap=n -+ResourceDisk.EnableSwap=y +@@ -49,7 +49,7 @@ ResourceDisk.MountPoint=/mnt/resource + ResourceDisk.EnableSwap=y # Size of the swapfile. --ResourceDisk.SwapSizeMB=0 +-ResourceDisk.SwapSizeMB=16384 +ResourceDisk.SwapSizeMB=2048 - # Comma-seperated list of mount options. See man(8) for valid options. + # Comma-separated list of mount options. See mount(8) for valid options. ResourceDisk.MountOptions=None