From 2fde1ec836764e94b2d6406bebde1267b5d6acaa Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Thu, 1 Nov 2018 15:05:44 -0700 Subject: [PATCH] fs_mgr: overlay backing, force filesystem for f2fs Under the condition of an existing, but broken, filesystem on the scratch device, force recreation. Add the -f flag for f2fs, already present for ext4. Test is enhanced. The test needs to check, and if necessary wipe out any existing overrides and reboot before running the remainder of test. Report which overrides are being used, and how they are setup. Fail if they are not as expected. Improve efficiency of checks by reducing the duplication of commands issued to the device. Test: adb-remount-test.sh Bug: 109821005 Change-Id: I9ac4fac952e334c00b089fec0b73b2cd2cc0af5c --- fs_mgr/fs_mgr_overlayfs.cpp | 21 +++++--- fs_mgr/tests/adb-remount-test.sh | 90 ++++++++++++++++++++++++-------- 2 files changed, 82 insertions(+), 29 deletions(-) diff --git a/fs_mgr/fs_mgr_overlayfs.cpp b/fs_mgr/fs_mgr_overlayfs.cpp index f06b81909..49ecc06a2 100644 --- a/fs_mgr/fs_mgr_overlayfs.cpp +++ b/fs_mgr/fs_mgr_overlayfs.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -692,13 +693,21 @@ bool fs_mgr_overlayfs_setup_scratch(const fstab* fstab, bool* change) { errno = 0; } - auto ret = system((mnt_type == "f2fs") - ? ((kMkF2fs + " -d1 " + scratch_device).c_str()) - : ((kMkExt4 + " -b 4096 -t ext4 -m 0 -M " + kScratchMountPoint + - " -O has_journal " + scratch_device) - .c_str())); + // Force mkfs by design for overlay support of adb remount, simplify and + // thus do not rely on fsck to correct problems that could creep in. + auto command = ""s; + if (mnt_type == "f2fs") { + command = kMkF2fs + " -w 4096 -f -d1 -l" + android::base::Basename(kScratchMountPoint); + } else if (mnt_type == "ext4") { + command = kMkExt4 + " -b 4096 -t ext4 -m 0 -O has_journal -M " + kScratchMountPoint; + } else { + LERROR << mnt_type << " has no mkfs cookbook"; + return false; + } + command += " " + scratch_device; + auto ret = system(command.c_str()); if (ret) { - LERROR << "make " << mnt_type << " filesystem on " << scratch_device << " error=" << ret; + LERROR << "make " << mnt_type << " filesystem on " << scratch_device << " return=" << ret; return false; } diff --git a/fs_mgr/tests/adb-remount-test.sh b/fs_mgr/tests/adb-remount-test.sh index b6a8eefed..6b908d3c3 100755 --- a/fs_mgr/tests/adb-remount-test.sh +++ b/fs_mgr/tests/adb-remount-test.sh @@ -198,39 +198,80 @@ isDebuggable || die "device not a debug build" # Do something adb_wait || die "wait for device failed" -adb_sh ls -d /sys/module/overlay /dev/null && + echo "${GREEN}[ OK ]${NORMAL} overlay module present" >&2 || + die "overlay module not present" +adb_su ls /sys/module/overlay/parameters/override_creds /dev/null && + echo "${GREEN}[ OK ]${NORMAL} overlay module supports override_creds" >&2 || die "overlay module can not be used on ANDROID" adb_root && - adb_wait && - D=`adb disable-verity 2>&1` || - die "setup for overlay" + adb_wait || + die "initial setup" +reboot=false +OVERLAYFS_BACKING="cache mnt/scratch" +for d in ${OVERLAYFS_BACKING}; do + if adb_sh ls -d /${d}/overlay /dev/null 2>&1; then + echo "${ORANGE}[ WARNING ]${NORMAL} /${d}/overlay is setup, wiping" >&2 + adb_sh rm -rf /${d}/overlay &2 + adb_reboot && + adb_wait 2m && + adb_root && + adb_wait || + die "reboot after wipe" +fi +D=`adb_sh df -k &2 || + echo "${GREEN}[ OK ]${NORMAL} no overlay present before setup" >&2 + +D=`adb disable-verity 2>&1` || + die "setup for overlay ${D}" echo "${D}" if [ X"${D}" != X"${D##*using overlayfs}" ]; then echo "${GREEN}[ OK ]${NORMAL} using overlayfs" >&2 fi -if adb_sh ls -d /data/overlay /dev/null 2>&1; then - echo "/data/overlay setup, clearing out" >&2 - adb_sh rm -rf /data/overlay /dev/null 2>&1 || - adb_sh ls -d /mnt/scratch/overlay /dev/null 2>&1 || - die "overlay directory setup" adb_reboot && adb_wait && - adb_sh df -k /dev/null || +echo "${D}" | grep "^overlay .* /system\$" >/dev/null || echo "${ORANGE}[ WARNING ]${NORMAL} overlay takeover before remount not complete" >&2 adb_root && adb_wait && adb remount && - adb_sh df -k /dev/null || + D=`adb_sh df -k /dev/null; then + echo "${ORANGE}[ INFO ]${NORMAL} using scratch dynamic partition for overrides" >&2 + H=`adb_sh cat /proc/mounts | sed -n 's@\([^ ]*\) /mnt/scratch \([^ ]*\) .*@\2 on \1@p'` + [ -n "${H}" ] && + echo "${ORANGE}[ INFO ]${NORMAL} scratch filesystem ${H}" +fi +for d in ${OVERLAYFS_BACKING}; do + if adb_sh ls -d /${d}/overlay/system/upper /dev/null 2>&1; then + echo "${ORANGE}[ INFO ]${NORMAL} /${d}/overlay is setup" >&2 + fi +done + +H=`echo "${D}" | head -1` && + D=`echo "${D}" | grep "^overlay "` && + echo "${H}" && + echo "${D}" && + echo "${D}" | grep "^overlay .* /system\$" >/dev/null || die "overlay takeover after remount" !(adb_sh grep "^overlay " /proc/mounts /dev/null || + D=`adb_sh df -k /dev/null || die "overlay system takeover after flash vendor" -adb_sh df -k /dev/null && +echo "${D}" | grep "^overlay .* /vendor\$" >/dev/null && die "overlay minus vendor takeover after flash vendor" B="`adb_cat /system/hello`" || die "re-read system hello after flash vendor"