Skip to content

Commit bc98047

Browse files
author
lwhsu
committed
Adjust WALinuxAgent to be more sutiable for FreeBSD:
- Pull in the patch from Azure/WALinuxAgent#1892 - Drop patch to create large swap space, leave some more space for temporarily storage Approved by: maintainer (implicitly) Sponsored by: The FreeBSD Foundation git-svn-id: svn+ssh://svn.freebsd.org/ports/head@536262 35697150-7ecd-e111-bb59-0022644237b5
1 parent 2db0094 commit bc98047

File tree

4 files changed

+349
-5
lines changed

4 files changed

+349
-5
lines changed

sysutils/azure-agent/Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
PORTNAME= azure-agent
44
PORTVERSION= 2.2.45
55
DISTVERSIONPREFIX= v
6-
PORTREVISION= 1
6+
PORTREVISION= 2
77
CATEGORIES= sysutils
88

99
PATCH_SITES= https://github.com/Azure/WALinuxAgent/commit/
10-
PATCHFILES= 14236c2c13e4f8986588b38477812b22240bdbac.patch:-p1
1110

1211
MAINTAINER= [email protected]
1312
COMMENT= Microsoft Azure Linux Agent

sysutils/azure-agent/distinfo

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
TIMESTAMP = 1582362460
1+
TIMESTAMP = 1590110519
22
SHA256 (Azure-WALinuxAgent-v2.2.45_GH0.tar.gz) = ded5ecf2ce17b3e375147a386ba13554b52098475dc06974e9780cc04ca893ee
33
SIZE (Azure-WALinuxAgent-v2.2.45_GH0.tar.gz) = 937466
4-
SHA256 (14236c2c13e4f8986588b38477812b22240bdbac.patch) = be70c35e5dc9d121b3618ef9aa4aef5cd899cd6a03c59bbc860b94858f3da59a
5-
SIZE (14236c2c13e4f8986588b38477812b22240bdbac.patch) = 883
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
1+
--- azurelinuxagent/daemon/resourcedisk/freebsd.py.orig 2020-05-22 12:55:32 UTC
2+
+++ azurelinuxagent/daemon/resourcedisk/freebsd.py
3+
@@ -1,6 +1,7 @@
4+
# Microsoft Azure Linux Agent
5+
#
6+
# Copyright 2018 Microsoft Corporation
7+
+# Copyright 2020 The FreeBSD Foundation
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
@@ -24,6 +25,8 @@ import azurelinuxagent.common.conf as conf
12+
from azurelinuxagent.common.exception import ResourceDiskError
13+
from azurelinuxagent.daemon.resourcedisk.default import ResourceDiskHandler
14+
15+
+# Keeping 1GB sapce if configured swap size is larger than the disk size
16+
+MINIMAL_RESOURCE_PARTITION_SIZE = 1024 ** 3
17+
18+
class FreeBSDResourceDiskHandler(ResourceDiskHandler):
19+
"""
20+
@@ -32,37 +35,45 @@ class FreeBSDResourceDiskHandler(ResourceDiskHandler):
21+
The resource disk locates at following slot:
22+
scbus2 on blkvsc1 bus 0:
23+
<Msft Virtual Disk 1.0> at scbus2 target 1 lun 0 (da1,pass2)
24+
-
25+
- There are 2 variations based on partition table type:
26+
- 1. MBR: The resource disk partition is /dev/da1s1
27+
- 2. GPT: The resource disk partition is /dev/da1p2, /dev/da1p1 is for reserved usage.
28+
"""
29+
30+
def __init__(self):
31+
super(FreeBSDResourceDiskHandler, self).__init__()
32+
33+
@staticmethod
34+
- def parse_gpart_list(data):
35+
+ def parse_gpart_show(data):
36+
dic = {}
37+
for line in data.split('\n'):
38+
- if line.find("Geom name: ") != -1:
39+
- geom_name = line[11:]
40+
- elif line.find("scheme: ") != -1:
41+
- dic[geom_name] = line[8:]
42+
+ if line:
43+
+ l = line.split()
44+
+ dic[l[3]] = l[4]
45+
return dic
46+
47+
+ @staticmethod
48+
+ def parse_mount_list(data):
49+
+ dic = {}
50+
+ for line in data.split('\n'):
51+
+ if line:
52+
+ l = line.split()
53+
+ dic[l[2]] = l[0]
54+
+ return dic
55+
+
56+
+ @staticmethod
57+
+ def get_next_partition(x):
58+
+ return x[:-1] + str(int(x[-1]) + 1)
59+
+
60+
def mount_resource_disk(self, mount_point):
61+
fs = self.fs
62+
if fs != 'ufs':
63+
- raise ResourceDiskError(
64+
- "Unsupported filesystem type:{0}, only ufs is supported.".format(fs))
65+
+ raise ResourceDiskError("Unsupported filesystem type: "
66+
+ "{0}, only ufs is supported.".format(fs))
67+
68+
# 1. Detect device
69+
- err, output = shellutil.run_get_output('gpart list')
70+
+ err, output = shellutil.run_get_output("gpart show | grep '=>'")
71+
if err:
72+
raise ResourceDiskError(
73+
"Unable to detect resource disk device:{0}".format(output))
74+
- disks = self.parse_gpart_list(output)
75+
+ disks = self.parse_gpart_show(output)
76+
77+
device = self.osutil.device_for_ide_port(1)
78+
if device is None or device not in disks:
79+
@@ -90,94 +101,186 @@ class FreeBSDResourceDiskHandler(ResourceDiskHandler):
80+
raise ResourceDiskError("Unable to detect resource disk device.")
81+
logger.info('Resource disk device {0} found.', device)
82+
83+
- # 2. Detect partition
84+
- partition_table_type = disks[device]
85+
+ # 2. Detect/create partition
86+
87+
- if partition_table_type == 'MBR':
88+
- provider_name = device + 's1'
89+
- elif partition_table_type == 'GPT':
90+
- provider_name = device + 'p2'
91+
- else:
92+
- raise ResourceDiskError(
93+
- "Unsupported partition table type:{0}".format(output))
94+
+ # count the target size of each partition
95+
+ err, output = shellutil.run_get_output("diskinfo {0}".format(device))
96+
+ if err:
97+
+ raise ResourceDiskError("Cannot get resource disk size.")
98+
+ disk_info = output.split()
99+
+ block_size = int(disk_info[1])
100+
+ disk_size = int(disk_info[2])
101+
102+
+ swap_size = 0
103+
+ if conf.get_resourcedisk_enable_swap():
104+
+ swap_size_mb = conf.get_resourcedisk_swap_size_mb()
105+
+ swap_size = swap_size_mb * 1024 * 1024
106+
+ resource_size = disk_size - swap_size
107+
+ if resource_size < MINIMAL_RESOURCE_PARTITION_SIZE:
108+
+ resource_size = MINIMAL_RESOURCE_PARTITION_SIZE
109+
+ swap_size = disk_size - resource_size
110+
+
111+
+ # get size of the current swap partition
112+
+ current_swap_size = 0
113+
err, output = shellutil.run_get_output(
114+
- 'gpart show -p {0}'.format(device))
115+
- if err or output.find(provider_name) == -1:
116+
- raise ResourceDiskError("Resource disk partition not found.")
117+
+ "gpart show {0} 2>/dev/null | grep freebsd-swap".format(device),
118+
+ chk_err=False)
119+
+ if output:
120+
+ current_swap_size = int(output.split()[1]) * block_size
121+
122+
- partition = '/dev/' + provider_name
123+
- logger.info('Resource disk partition {0} found.', partition)
124+
+ partition_table_type = disks.get(device)
125+
126+
- # 3. Mount partition
127+
- mount_list = shellutil.run_get_output("mount")[1]
128+
- existing = self.osutil.get_mount_point(mount_list, partition)
129+
+ resource_provider_name = device + 'p1'
130+
+ swap_provider_name = device + 'p2'
131+
132+
+ # re-partition if needed
133+
+ if partition_table_type != 'GPT' or current_swap_size != swap_size:
134+
+ # unmount and swapoff if needed
135+
+ mount_list = shellutil.run_get_output("mount")[1]
136+
+ existing = self.osutil.get_mount_point(mount_list,
137+
+ resource_provider_name)
138+
+ if existing:
139+
+ err, output = shellutil.run_get_output(
140+
+ "umount {0}".format(mount_point), chk_err=False)
141+
+
142+
+ swap_info = shellutil.run_get_output("swapctl -l")[1].split('\n')
143+
+ swap_device = None
144+
+ if len(swap_info) > 2:
145+
+ swap_device = swap_info[1].split()[0]
146+
+ if swap_device:
147+
+ err, output = shellutil.run_get_output(
148+
+ "swapoff {0}".format(swap_device), chk_err=False)
149+
+ if swap_device.endswith('.eli'):
150+
+ err, output = shellutil.run_get_output(
151+
+ "geli detach {0}".format(swap_device), chk_err=False)
152+
+
153+
+ if partition_table_type is not None:
154+
+ gaprt_destroy_cmd = "gpart destroy -F {0}".format(device)
155+
+ err, output = shellutil.run_get_output(gaprt_destroy_cmd,
156+
+ chk_err=False)
157+
+ if err:
158+
+ raise ResourceDiskError("Failed to destroy the "
159+
+ "partitioning scheme on {0}, "
160+
+ "error: {1}".format(device, output))
161+
+ gaprt_create_cmd = "gpart create -s GPT {0}".format(device)
162+
+ err, output = shellutil.run_get_output(gaprt_create_cmd,
163+
+ chk_err=False)
164+
+ if err:
165+
+ raise ResourceDiskError("Failed to create new GPT on {0}, "
166+
+ "error: {1}".format(device, output))
167+
+
168+
+ mount_list = shellutil.run_get_output("mount")[1]
169+
+ existing = self.osutil.get_mount_point(mount_list,
170+
+ resource_provider_name)
171+
if existing:
172+
- logger.info("Resource disk {0} is already mounted", partition)
173+
+ logger.info("Resource disk {0} is already mounted".format(
174+
+ resource_provider_name))
175+
return existing
176+
177+
+ # create resource partition
178+
+ if not os.path.exists("/dev/{0}".format(resource_provider_name)):
179+
+ if swap_size > 0:
180+
+ err, output = shellutil.run_get_output(
181+
+ 'gpart add -t freebsd-ufs -s {0}b {1}'.format(resource_size,
182+
+ device))
183+
+ else:
184+
+ err, output = shellutil.run_get_output(
185+
+ 'gpart add -t freebsd-ufs {0}'.format(device))
186+
+ if err:
187+
+ raise ResourceDiskError(
188+
+ "Failed to add new freebsd-ufs partition to {0}, "
189+
+ "error: {1}" .format(device, output))
190+
+
191+
+ # create swap partition, just use all the space left
192+
+ if swap_size > 0:
193+
+ err, output = shellutil.run_get_output(
194+
+ 'gpart add -t freebsd-swap {0}'.format(device))
195+
+ if err:
196+
+ raise ResourceDiskError(
197+
+ "Failed to add new freebsd-swap partition to {0}, "
198+
+ "error: {1}" .format(device, output))
199+
+
200+
+ # 3. Mount partition
201+
fileutil.mkdir(mount_point, mode=0o755)
202+
- mount_cmd = 'mount -t {0} {1} {2}'.format(fs, partition, mount_point)
203+
- err = shellutil.run(mount_cmd, chk_err=False)
204+
- if err:
205+
- logger.info(
206+
- 'Creating {0} filesystem on partition {1}'.format(
207+
- fs, partition))
208+
+
209+
+ need_newfs = True
210+
+ if current_swap_size == swap_size:
211+
+ # swap size is not adjusted,
212+
+ # i.e., the resource partition is not changed
213+
+ # check if a fs already exists
214+
+ fstyp_cmd = 'fstyp /dev/{0}'.format(resource_provider_name)
215+
+ err, output = shellutil.run_get_output(fstyp_cmd, chk_err=False)
216+
+ if not err and output == fs:
217+
+ need_newfs = False
218+
+ logger.info(
219+
+ "Resource disk partition {0} is found at {1} "
220+
+ "with fstype {2}".format(
221+
+ resource_provider_name, mount_point, fs))
222+
+ elif swap_size < current_swap_size:
223+
+ # resource partition size is increased, try to growfs first
224+
err, output = shellutil.run_get_output(
225+
- 'newfs -U {0}'.format(partition))
226+
+ 'growfs -y {0}'.format(resource_provider_name), chk_err=False)
227+
+ if not err:
228+
+ need_newfs = False
229+
+ logger.info(
230+
+ "Resource disk partition {0} is found and enlarged at {1} "
231+
+ "with fstype {2}".format(
232+
+ resource_provider_name, mount_point, fs))
233+
+ # else
234+
+ # resource partition is shrunk and newfs is needed
235+
+
236+
+ if need_newfs:
237+
+ logger.info('Creating {0} filesystem on partition {1}'.format(
238+
+ fs, resource_provider_name))
239+
+ err, output = shellutil.run_get_output(
240+
+ 'newfs -U {0}'.format(resource_provider_name))
241+
if err:
242+
raise ResourceDiskError(
243+
- "Failed to create new filesystem on partition {0}, error:{1}" .format(
244+
- partition, output))
245+
- err, output = shellutil.run_get_output(mount_cmd, chk_err=False)
246+
- if err:
247+
- raise ResourceDiskError(
248+
- "Failed to mount partition {0}, error {1}".format(
249+
- partition, output))
250+
+ "Failed to create new filesystem on partition {0}, "
251+
+ "error: {1}" .format(resource_provider_name, output))
252+
253+
+ mount_cmd = 'mount -t {0} /dev/{1} {2}'.format(
254+
+ fs, resource_provider_name, mount_point)
255+
+ err, output = shellutil.run_get_output(mount_cmd, chk_err=False)
256+
+ if err:
257+
+ raise ResourceDiskError(
258+
+ "Failed to mount partition {0}, error {1}".format(
259+
+ resource_provider_name, output))
260+
+
261+
logger.info(
262+
- "Resource disk partition {0} is mounted at {1} with fstype {2}",
263+
- partition,
264+
- mount_point,
265+
- fs)
266+
+ "Resource disk partition {0} is mounted at {1} "
267+
+ "with fstype {2}".format(
268+
+ resource_provider_name, mount_point, fs))
269+
return mount_point
270+
271+
def create_swap_space(self, mount_point, size_mb):
272+
- size_kb = size_mb * 1024
273+
- size = size_kb * 1024
274+
- swapfile = os.path.join(mount_point, 'swapfile')
275+
- swaplist = shellutil.run_get_output("swapctl -l")[1]
276+
+ # done in mount_resource_disk()
277+
+ pass
278+
279+
- if self.check_existing_swap_file(swapfile, swaplist, size):
280+
+ def enable_swap(self, mount_point):
281+
+ if conf.get_resourcedisk_swap_size_mb() <=0:
282+
return
283+
284+
- if os.path.isfile(swapfile) and os.path.getsize(swapfile) != size:
285+
- logger.info("Remove old swap file")
286+
- shellutil.run("swapoff -a", chk_err=False)
287+
- os.remove(swapfile)
288+
+ # get swap partition (geom provider)
289+
+ err, output = shellutil.run_get_output('mount')
290+
+ if err:
291+
+ raise ResourceDiskError("Unable to get mount information.")
292+
+ devices = self.parse_mount_list(output)
293+
+ resource_provider_name = devices[mount_point]
294+
+ swap_provider_name = self.get_next_partition(resource_provider_name)
295+
296+
- if not os.path.isfile(swapfile):
297+
- logger.info("Create swap file")
298+
- self.mkfile(swapfile, size_kb * 1024)
299+
+ if conf.get_resourcedisk_enable_swap_encryption():
300+
+ shellutil.run("kldload -n aesni")
301+
+ shellutil.run("kldload -n cryptodev")
302+
+ shellutil.run("kldload -n geom_eli")
303+
+ shellutil.run("geli onetime -e AES-XTS -l 256"
304+
+ " -d {0}".format(swap_provider_name))
305+
+ swap_provider_name += ".eli"
306+
+ shellutil.run("chmod 0600 {0}".format(swap_provider_name))
307+
308+
- mddevice = shellutil.run_get_output(
309+
- "mdconfig -a -t vnode -f {0}".format(swapfile))[1].rstrip()
310+
- shellutil.run("chmod 0600 /dev/{0}".format(mddevice))
311+
+ if shellutil.run("swapon {0}".format(swap_provider_name)):
312+
+ raise ResourceDiskError(swap_provider_name)
313+
314+
- if conf.get_resourcedisk_enable_swap_encryption():
315+
- shellutil.run("kldload aesni")
316+
- shellutil.run("kldload cryptodev")
317+
- shellutil.run("kldload geom_eli")
318+
- shellutil.run(
319+
- "geli onetime -e AES-XTS -l 256 -d /dev/{0}".format(mddevice))
320+
- shellutil.run("chmod 0600 /dev/{0}.eli".format(mddevice))
321+
- if shellutil.run("swapon /dev/{0}.eli".format(mddevice)):
322+
- raise ResourceDiskError("/dev/{0}.eli".format(mddevice))
323+
- logger.info(
324+
- "Enabled {0}KB of swap at /dev/{1}.eli ({2})".format(size_kb, mddevice, swapfile))
325+
- else:
326+
- if shellutil.run("swapon /dev/{0}".format(mddevice)):
327+
- raise ResourceDiskError("/dev/{0}".format(mddevice))
328+
- logger.info(
329+
- "Enabled {0}KB of swap at /dev/{1} ({2})".format(size_kb, mddevice, swapfile))
330+
+ size_mb = shellutil.run_get_output("swapctl -lm")[1].split()[1]
331+
+ logger.info(
332+
+ "Enabled {0}MB of swap at {1}".format(size_mb, swap_provider_name))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--- config/freebsd/waagent.conf.orig 2020-05-22 16:31:32 UTC
2+
+++ config/freebsd/waagent.conf
3+
@@ -48,10 +48,10 @@ ResourceDisk.Filesystem=ufs
4+
ResourceDisk.MountPoint=/mnt/resource
5+
6+
# Create and use swapfile on resource disk.
7+
-ResourceDisk.EnableSwap=n
8+
+ResourceDisk.EnableSwap=y
9+
10+
# Size of the swapfile.
11+
-ResourceDisk.SwapSizeMB=0
12+
+ResourceDisk.SwapSizeMB=2048
13+
14+
# Comma-seperated list of mount options. See man(8) for valid options.
15+
ResourceDisk.MountOptions=None

0 commit comments

Comments
 (0)