summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2012-03-21 14:32:18 -0400
committerScott Moser <smoser@ubuntu.com>2012-03-21 14:32:18 -0400
commit6e1547d093f975b18722ad94083dda4dc3753c3f (patch)
tree214ee88591582fc7a80ea943680b079405690eb2
parentaa6726ebd6c8499a7457a98000515b08f2f8f160 (diff)
downloadvyos-cloud-init-6e1547d093f975b18722ad94083dda4dc3753c3f.tar.gz
vyos-cloud-init-6e1547d093f975b18722ad94083dda4dc3753c3f.zip
cc_resizefs: run resizefs in the background during boot.
LP: #961226
-rw-r--r--ChangeLog1
-rw-r--r--cloudinit/CloudConfig/cc_resizefs.py31
2 files changed, 24 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index ce51629e..0cf93c2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -37,6 +37,7 @@
- add option 'apt_pipelining' to address issue with S3 mirrors
(LP: #948461) [Ben Howard]
- warn on non-multipart, non-handled user-data [Martin Packman]
+ - run resizefs in the background in order to not block boot (LP: #961226)
0.6.2:
- fix bug where update was not done unless update was explicitly set.
It would not be run if 'upgrade' or packages were set to be installed
diff --git a/cloudinit/CloudConfig/cc_resizefs.py b/cloudinit/CloudConfig/cc_resizefs.py
index c76cc664..e829f362 100644
--- a/cloudinit/CloudConfig/cc_resizefs.py
+++ b/cloudinit/CloudConfig/cc_resizefs.py
@@ -22,6 +22,8 @@ import cloudinit.util as util
import subprocess
import os
import stat
+import sys
+import time
import tempfile
from cloudinit.CloudConfig import per_always
@@ -39,10 +41,9 @@ def handle(_name, cfg, _cloud, log, args):
if not resize_root:
return
- # this really only uses the filename from mktemp, then we mknod into it
- (fd, devpth) = tempfile.mkstemp()
- os.unlink(devpth)
- os.close(fd)
+ # we use mktemp rather than mkstemp because early in boot nothing
+ # else should be able to race us for this, and we need to mknod.
+ devpth = tempfile.mktemp(prefix="cloudinit.resizefs.", dir="/run")
try:
st_dev = os.stat("/").st_dev
@@ -65,9 +66,6 @@ def handle(_name, cfg, _cloud, log, args):
os.unlink(devpth)
raise
- log.debug("resizing root filesystem (type=%s, maj=%i, min=%i)" %
- (str(fstype).rstrip("\n"), os.major(st_dev), os.minor(st_dev)))
-
if str(fstype).startswith("ext"):
resize_cmd = ['resize2fs', devpth]
elif fstype == "xfs":
@@ -77,7 +75,24 @@ def handle(_name, cfg, _cloud, log, args):
log.debug("not resizing unknown filesystem %s" % fstype)
return
+ fid = os.fork()
+ if fid == 0:
+ try:
+ do_resize(resize_cmd, devpth, log)
+ os._exit(0) # pylint: disable=W0212
+ except Exception as exc:
+ sys.stderr.write("Failed: %s" % exc)
+ os._exit(1) # pylint: disable=W0212
+
+ log.debug("resizing root filesystem (type=%s, maj=%i, min=%i). pid=%s" %
+ (str(fstype).rstrip("\n"), os.major(st_dev), os.minor(st_dev), fid))
+
+ return
+
+
+def do_resize(resize_cmd, devpth, log):
try:
+ start = time.time()
util.subp(resize_cmd)
except subprocess.CalledProcessError as e:
log.warn("Failed to resize filesystem (%s)" % resize_cmd)
@@ -86,4 +101,4 @@ def handle(_name, cfg, _cloud, log, args):
raise
os.unlink(devpth)
- return
+ log.debug("resize took %s seconds" % (time.time() - start))