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"