~aleteoryx/muditaos

1d4ed26f4137ff61bf425ee5858f22063db40f0d — Wiktor S. Ovalle Correa 4 years ago 6916fed
[EGD-5870] Fix filesystem remounting

Skip remounting if a filesystem is already R/W
2 files changed, 20 insertions(+), 9 deletions(-)

M module-services/service-desktop/ServiceDesktop.cpp
M module-utils/microtar
M module-services/service-desktop/ServiceDesktop.cpp => module-services/service-desktop/ServiceDesktop.cpp +19 -8
@@ 30,17 30,27 @@

namespace
{
    auto RemountFS(bool readOnly = false, std::string path = std::string(purefs::dir::getRootDiskPath()))
    bool RemountFS(bool readOnly = false, std::string path = std::string(purefs::dir::getRootDiskPath()))
    {
        struct statvfs stat;
        if (auto ret = statvfs(path.c_str(), &stat))
            return ret;
        if (statvfs(path.c_str(), &stat)) {
            LOG_ERROR("Failed reading statvfs!");
            return false;
        }
        auto flags = stat.f_flag;
        if (readOnly)
        if ((readOnly && (flags & MS_RDONLY)) || (!readOnly && !(flags & MS_RDONLY))) {
            LOG_WARN("Filesystem is already mounted in requested mode!");
            return false;
        }
        if (readOnly) {
            LOG_INFO("Remounting filesystem RO");
            flags |= MS_RDONLY;
        else
        }
        else {
            LOG_INFO("Remounting filesystem R/W");
            flags &= ~MS_RDONLY;
        return mount(NULL, path.c_str(), NULL, flags | MS_REMOUNT, NULL);
        }
        return !mount(NULL, path.c_str(), NULL, flags | MS_REMOUNT, NULL);
    }
} // namespace



@@ 87,9 97,10 @@ sys::ReturnCodes ServiceDesktop::InitHandler()
    connect(sdesktop::BackupMessage(), [&](sys::Message *msg) {
        sdesktop::BackupMessage *backupMessage = dynamic_cast<sdesktop::BackupMessage *>(msg);
        if (backupMessage != nullptr) {
            RemountFS();
            auto remounted = RemountFS();
            BackupRestore::BackupUserFiles(this);
            RemountFS(true);
            if (remounted)
                RemountFS(true);
        }
        return std::make_shared<sys::ResponseMessage>();
    });

M module-utils/microtar => module-utils/microtar +1 -1
@@ 1,1 1,1 @@
Subproject commit 966b5d38f82d68152e08f8b67c04e0dc1249e4e1
Subproject commit fc319e86e4710fa636af06cfdc98235c0088635b